<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5812558148803847895</id><updated>2025-07-03T17:53:49.692-07:00</updated><category term="T-SQL"/><category term="SQL Performance"/><category term="MDS.MDM"/><category term="Mirroring"/><category term="SSMS Tip"/><category term="TFS"/><category term="Deadlocks"/><category term="Interview Questions"/><category term="Linked Server"/><category term="Locks"/><category term="Log Shipping"/><category term="MySQL"/><category term="SQL Humor"/><category term="Temp Table vs Table Variable"/><category term="Tips"/><category term="Dynamic SQL"/><category term="Identity"/><category term="Internals"/><category term="Parameter Sniffing"/><category term="Red Gate"/><category term="AutoNumber"/><category term="Azure Data Studio"/><category term="BI"/><category term="Bulk Insert"/><category term="COALESCE vs. ISNULL"/><category term="CRecordset DBException"/><category term="Cardinality"/><category term="Change Tracking"/><category term="Check SP`s Input params for NULL"/><category term="Cross Apply"/><category term="Cursors"/><category term="Data Exploration"/><category term="Data Visualization"/><category term="Database Deployment"/><category term="Default Trace"/><category term="Disk Partition Alignment"/><category term="Estimations"/><category term="FILESTREAM"/><category term="Get SP Name dynamically"/><category term="Git"/><category term="GitHub"/><category term="How Differential Backup Works"/><category term="Impersonation"/><category term="Logical Query Processing Phases"/><category term="Master Data Services"/><category term="Multiple files for TempDB"/><category term="NULL Storage Space"/><category term="Profiler"/><category term="Query Tuning"/><category term="SQL Mail"/><category term="SQL Server 2012"/><category term="SQL Server 2019"/><category term="SQL Server 2019 Setup"/><category term="SQLCMD"/><category term="SSIS"/><category term="Snapshot"/><category term="Statistics"/><category term="Stop Script/T-SQL batch execution"/><category term="T-SQL batch seperator"/><category term="TOP 100 PERCENT + ORDER BY"/><category term="VARCHAR Storage Size"/><title type='text'>Made By SQL</title><subtitle type='html'>Knowledge is a treasure, but practice is the key to it.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>116</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-8880766250291405270</id><published>2023-07-24T10:00:00.004-07:00</published><updated>2023-09-14T13:01:59.955-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL Performance"/><title type='text'>NonParallelPlanReason=&quot;CouldNotGenerateValidParallelPlan&quot; - one of the possible reasons</title><content type='html'>&lt;p&gt;When you see your query doesn&#39;t go parallel and in the execution&lt;br /&gt;plan XML you see&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;NonParallelPlanReason&lt;/span&gt;=&lt;span style=&quot;color: #2b00fe;&quot;&gt;&quot;CouldNotGenerateValidParallelPlan&quot;.&lt;br /&gt;&lt;/span&gt;Until SQL Server 2022 there is no indication why and what is the reason.&lt;/p&gt;&lt;p&gt;One of the possible reasons can be that you are querying a table which has &lt;br /&gt;scalar function (UDF) in a check constraint or in a computed column.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;b&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjcFze7KwGSLdoGkQFJkLY9rTeZsjW2gXWfVssIT9NEU54DWmEqNqSJuNToPcYVhrd1VLzZjWPnVN0cb3oiKQzSimWBtPbUFP6S-LFVsb86PyPGe2ttW2eRYdl0PN_0s2bcnfG-h4WyOoYaLN1MvPwZJRlAykyUPMDUotkHidxm86stBveBhA71tq-URMk&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img data-original-height=&quot;71&quot; data-original-width=&quot;162&quot; height=&quot;76&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjcFze7KwGSLdoGkQFJkLY9rTeZsjW2gXWfVssIT9NEU54DWmEqNqSJuNToPcYVhrd1VLzZjWPnVN0cb3oiKQzSimWBtPbUFP6S-LFVsb86PyPGe2ttW2eRYdl0PN_0s2bcnfG-h4WyOoYaLN1MvPwZJRlAykyUPMDUotkHidxm86stBveBhA71tq-URMk=w175-h76&quot; width=&quot;175&quot; /&gt;&lt;/a&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;Scalar UDFs in check constraints and in computed columns prevent parallelism (even for&amp;nbsp; SELECT Queries)&lt;/b&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Try to disable the check constrain and check if it goes parallel.&amp;nbsp;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/8880766250291405270/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2023/07/nonparallelplanreasoncouldnotgenerateva.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/8880766250291405270'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/8880766250291405270'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2023/07/nonparallelplanreasoncouldnotgenerateva.html' title='NonParallelPlanReason=&quot;CouldNotGenerateValidParallelPlan&quot; - one of the possible reasons'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEjcFze7KwGSLdoGkQFJkLY9rTeZsjW2gXWfVssIT9NEU54DWmEqNqSJuNToPcYVhrd1VLzZjWPnVN0cb3oiKQzSimWBtPbUFP6S-LFVsb86PyPGe2ttW2eRYdl0PN_0s2bcnfG-h4WyOoYaLN1MvPwZJRlAykyUPMDUotkHidxm86stBveBhA71tq-URMk=s72-w175-h76-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-7570124347504754257</id><published>2022-11-28T17:22:00.001-08:00</published><updated>2022-11-28T17:22:27.695-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Deadlocks"/><title type='text'>Minimizing deadlocks</title><content type='html'>&lt;br /&gt;A deadlock occurs when two or more sessions permanently block each other&lt;br /&gt;by each session having a lock on a resource that the other session(s) are trying to lock.&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;Transaction A acquires a shared lock on row 1.&lt;br /&gt;Transaction B acquires a shared lock on row 2.&lt;br /&gt;&lt;br /&gt;Transaction A now requests an exclusive lock on row 2, &lt;br /&gt;and is blocked until transaction B finishes and releases the shared lock it has on row 2.&lt;br /&gt;&lt;br /&gt;Transaction B now requests an exclusive lock on row 1, &lt;br /&gt;and is blocked until transaction A finishes and releases the shared lock it has on row 1.&lt;br /&gt;&lt;br /&gt;We can group the deadlocks into the following categories:&lt;br /&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Reader-Writer deadlocks&lt;/li&gt;&lt;li&gt;Writer-Writer Deadlocks&lt;/li&gt;&lt;li&gt;Key Lookup Deadlocks&lt;/li&gt;&lt;li&gt;Parallelism-related deadlocks&lt;/li&gt;&lt;li&gt;Range Scans and serializable deadlocks&lt;/li&gt;&lt;li&gt;Partition escalation deadlocks&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Now let`s see what we can do to minimize and/or completely prevent the deadlocks:&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;1) &lt;b&gt;Access the shared objects/tables in the same order.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; Ensure that all the resources are accessed in the same order all the time.&lt;br /&gt;&amp;nbsp; &amp;nbsp; For example, if two concurrent transactions both started by requesting&lt;br /&gt;&amp;nbsp; &amp;nbsp; the lock for row 1 and later on&amp;nbsp;requesting the lock for row 2.&lt;br /&gt;&amp;nbsp; &amp;nbsp; This will simply be a blocking situation rather than a deadlock because&lt;br /&gt;&amp;nbsp; &amp;nbsp; transaction 1 will never be deadlocking transaction 2 as resource locks &lt;br /&gt;&amp;nbsp; &amp;nbsp; will never be held out of order. &lt;br /&gt;&lt;br /&gt;2) &lt;b&gt;Reduce a query&#39;s lock footprint by making the query as efficient as possible. &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Make sure the involved queries use row lock and not page/table locks.&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Try to read less data, avoid index scans.&lt;br /&gt;&lt;br /&gt;3) &lt;b&gt;In case of Key Lookups deadlocks&lt;/b&gt;,&lt;br /&gt;&amp;nbsp; &amp;nbsp; there are 2 possible solutions:&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; a) Include columns to the existing non-clustered index, which will eliminate the lookup.&lt;br /&gt;&amp;nbsp; &amp;nbsp; b) In case the clustered index is small enough,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Use &lt;span style=&quot;color: #2b00fe;&quot;&gt;FORCESCAN &lt;/span&gt;hint on the SELECT to force a clustered index scan&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; Key Lookup deadlocks are the most common ones, here is an example:&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; The SELECT uses the NC index to find a qualifying row(s)&lt;br /&gt;&amp;nbsp; &amp;nbsp; While holding a Shared lock on the NC index, it needs to jump over&lt;br /&gt;&amp;nbsp; &amp;nbsp; to the clustered index and retrieve some columns that aren&#39;t part of the NC index.&lt;br /&gt;&amp;nbsp; &amp;nbsp; While it&#39;s doing this, the UPDATE is busy doing a seek on the CL index.&lt;br /&gt;&amp;nbsp; &amp;nbsp; It finds a row, locks it and modifies it. But because one of the columns &lt;br /&gt;&amp;nbsp; &amp;nbsp; being modified is a key column in the NC index, it then has to move to the NC index&lt;br /&gt;&amp;nbsp; &amp;nbsp; and update that index, too. This requires a second X key lock on the NC index. &lt;br /&gt;&amp;nbsp; &amp;nbsp; So, the SELECT ends up blocked waiting for the UPDATE to release his X lock &lt;br /&gt;&amp;nbsp; &amp;nbsp; on the clustered index, while the UPDATE winds up blocked and waiting for the&lt;br /&gt;&amp;nbsp; &amp;nbsp; SELECT to release his S lock on the NC index.&lt;br /&gt;&lt;br /&gt;4) &lt;b&gt;Force the blocking to occur at an earlier point&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;Sometimes the best way to prevent a deadlock is to force the blocking to occur&lt;br /&gt;&amp;nbsp; &amp;nbsp;at an earlier point in one of the two transactions. &lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;For example, if you force process&amp;nbsp; A to be blocked by process B at the very &lt;br /&gt;&amp;nbsp; &amp;nbsp;beginning of A’s transaction, it may not have a chance to acquire the lock &lt;br /&gt;&amp;nbsp; &amp;nbsp;resource that later ends up blocking process B. &lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: #2b00fe;&quot;&gt;HOLDLOCK&lt;/span&gt; and &lt;span style=&quot;color: #2b00fe;&quot;&gt;UPDLOCK&lt;/span&gt; hints can be useful for this.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;5) &lt;b&gt;Deadlock caused by&amp;nbsp;parallelism&lt;/b&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; Happens on parallel query plan executions,&lt;br /&gt;&amp;nbsp; &amp;nbsp; you will see &quot;parallelism exchange event&quot; in the deadlock graph/xml.&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; One of the possible solution here is to add MAXDOP 1 hint to force the queries go serial,&lt;br /&gt;&amp;nbsp; &amp;nbsp; Another solution is to see if add an index can help to reduce the query cost&lt;br /&gt;&amp;nbsp; &amp;nbsp; and make the query to be executed in a single thread.&lt;br /&gt;&lt;br /&gt;6) &lt;b&gt;Deadlock between two MERGE statements&lt;br /&gt;&lt;/b&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Try to add HOLDLOCK hint to the MERGE statement,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;If it doesn&#39;t help, try to rewrite the MERGE to INSERT/UPDATE statements&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;7)&amp;nbsp;&lt;b&gt;Use a lower isolation level&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;Check if the transaction can run at a lower isolation level and&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp;use the minimum necessary transaction isolation level.&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;Under read committed, SQL Server will hold shared locks for a shorter duration than&lt;br /&gt;&amp;nbsp; &amp;nbsp;a higher isolation level, such as repeatable read/serializable.&lt;br /&gt;&lt;br /&gt;8)&amp;nbsp;&lt;b&gt;Use RCSI&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; Snapshot isolation uses row versioning, which does not use shared locks during read operations. &lt;br /&gt;&amp;nbsp; &amp;nbsp; Snapshot&amp;nbsp;isolation levels can minimize deadlocks that occur between read and write operations.&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;9) &lt;b&gt;Implement your own manual locking (sp_getapplock)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; If possible, consider to&amp;nbsp;lock/unlock objects manually by yourself,&lt;br /&gt;&amp;nbsp; &amp;nbsp; This can be done by using &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/ms189823.aspx&quot;&gt;sp_getapplock&lt;/a&gt; procedure.&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; Add sp_getapplock&amp;nbsp;to the 2 involved stored procedures or queries&lt;br /&gt;&amp;nbsp; &amp;nbsp; Something like below:&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; begin tran&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sp_getapplock @Resource = &#39;MyTran&#39;, @LockMode = &#39;Exclusive&#39;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;... your code ...&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; commit&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp;Only one client will be able to run this code at a time and it will be&amp;nbsp;serialized.&lt;br /&gt;&amp;nbsp; &amp;nbsp;Don&#39;t forget to use&amp;nbsp;sp_releaseapplock &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/7570124347504754257/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2022/11/minimizing-deadlocks.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/7570124347504754257'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/7570124347504754257'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2022/11/minimizing-deadlocks.html' title='Minimizing deadlocks'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-4298696238088004879</id><published>2022-09-09T12:51:00.002-07:00</published><updated>2022-09-09T13:01:28.291-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Change Tracking"/><title type='text'>Change Tracking cleanup doesn&#39;t work - negative cleanup_version / change_tracking_hardened_cleanup_version </title><content type='html'>So you have enabled the Change Tracking with AUTO_CLEANUP = ON,&lt;br /&gt;but the CT cleanup doesn&#39;t work, no records deleted from the side tables&lt;br /&gt;and from sys.syscommittab system table after the retention period passed.&lt;br /&gt;&lt;br /&gt;When you run:&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;-- Delete the data in sys.committab&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;exec &lt;/span&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;sys&lt;/span&gt;.sp_flush_commit_table_on_demand @numrows&amp;nbsp; = 1000&lt;br /&gt;&lt;br /&gt;you get negative value/number in change_tracking_hardened_cleanup_version&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;The value returned by change_tracking_hardened_cleanup_version() is -XXXXXXXXX&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Or you can see that the cleanup_version is negative from this query:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;select&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;sc.name as tracked_schema_name,&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;so.name as tracked_table_name,&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;ctt.cleanup_version&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;from&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #6aa84f;&quot;&gt;sys.change_tracking_tables&lt;/span&gt; as ctt&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;inner join &lt;span style=&quot;color: #6aa84f;&quot;&gt;sys.objects&lt;/span&gt; as so on ctt.[object_id]=so.[object_id]&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;inner join &lt;span style=&quot;color: #6aa84f;&quot;&gt;sys.schemas&lt;/span&gt; as sc on so.schema_id=sc.schema_id&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;where&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/span&gt;so.name =&#39;XXX-your-table-name-XXX&#39;&lt;/div&gt;&lt;div&gt;go&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;Also when you run:&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;exec &lt;/span&gt;sp_flush_CT_internal_table_on_demand&amp;nbsp;&lt;br /&gt;&lt;br /&gt;you see&amp;nbsp;&lt;i&gt;Total rows deleted: 0. &lt;/i&gt;in the output&lt;br /&gt;&lt;br /&gt;If so, there is a fix from Microsoft, see it &lt;a href=&quot;https://support.microsoft.com/en-us/topic/kb4538365-fix-change-tracking-cleanup-does-not-work-when-invalid-cleanup-and-hardened-cleanup-version-are-negative-in-sql-server-2017-and-2019-f186bd92-622c-89f2-a6c2-739c250593f2&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;Also you will need to enable trace flag 8290 and let the auto cleanup process run.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;DBCC &lt;/span&gt;TRACEON( 8290, -1)&lt;/div&gt;&lt;div&gt;go&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;DBCC &lt;/span&gt;TRACESTATUS(8290)&lt;/div&gt;&lt;/div&gt;&lt;div&gt;go&lt;/div&gt;&lt;div&gt;&lt;br /&gt;Finally, you can see history of Change Tracking&amp;nbsp;cleanups in the table below:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;select &lt;/span&gt;* &lt;span style=&quot;color: #0b5394;&quot;&gt;from &lt;/span&gt;dbo.MSchange_tracking_history&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/4298696238088004879/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2022/09/change-tracking-cleanup-doesnt-work.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/4298696238088004879'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/4298696238088004879'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2022/09/change-tracking-cleanup-doesnt-work.html' title='Change Tracking cleanup doesn&#39;t work - negative cleanup_version / change_tracking_hardened_cleanup_version '/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-1928898870513644720</id><published>2021-01-15T18:15:00.009-08:00</published><updated>2021-01-16T11:33:35.955-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="MySQL"/><title type='text'>How to identify MySQL replication slave lag</title><content type='html'>&lt;p&gt;Let&#39;s first understand how the standard asynchronous &lt;br /&gt;MySQL replication works at a high level.&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOCNGozECcEWBSavQp_7Wp5kt8Y38pP-4XETdqUwjwg-oLdmzSM2F_70u8_a18rFgYdSgA0cgUELvP869ZAXf_5dahkmnOHmoejExp9z8ErDWtuWAiz9uLr9QJc3-8S1sbcg4bFdt-LJ4/s1507/MySQl+replica.jpg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;559&quot; data-original-width=&quot;1507&quot; height=&quot;208&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOCNGozECcEWBSavQp_7Wp5kt8Y38pP-4XETdqUwjwg-oLdmzSM2F_70u8_a18rFgYdSgA0cgUELvP869ZAXf_5dahkmnOHmoejExp9z8ErDWtuWAiz9uLr9QJc3-8S1sbcg4bFdt-LJ4/w562-h208/MySQl+replica.jpg&quot; width=&quot;562&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;For simplicity, let&#39;s assume that there is a Master and one Slave node.&lt;br /&gt;And MySQL version 5.6&lt;br /&gt;&lt;br /&gt;Thus, the master maintains a special log called &lt;b&gt;binary log&lt;/b&gt; which stores replication events.&lt;br /&gt;This binary log file stores data that the replication slave will be reading later.&lt;br /&gt;&lt;br /&gt;MySQL can use 3 formats for writing data to the binary log:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Statement-based &lt;/b&gt;- the SQL query itself is written to the binary log.&lt;br /&gt;&lt;b&gt;Row-based &lt;/b&gt;- the row changes are logged in the binary log.&lt;/div&gt;&lt;b&gt;Mixed&lt;/b&gt;&amp;nbsp;- statement-based logging is used by default, but the logging mode&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;switches automatically to row-based in certain cases.&lt;p&gt;The slave node has 2 processes/threads that are responsible for the replication:&lt;/p&gt;&lt;b&gt;IO Thread&lt;/b&gt;&amp;nbsp; - a process that pulls data from Master&#39;s binary log over the network&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and writes the data/changes to a local file called a &lt;b&gt;relay log&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;SQL Thread -&amp;nbsp;&lt;/b&gt;a process that continuously reads the &lt;b&gt;relay log &lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;and applies the changes to the slave database.&lt;br /&gt;&lt;br /&gt;So, in asynchronous replication, the slave node requests a packet from the master, &lt;br /&gt;the master sends the packet and doesn&#39;t check if the slave received the data packet or not.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;Also as you can see there is only one thread that reads the binary log from the master.&lt;div&gt;&lt;br /&gt;The slave node keeps track of the position in the master&#39;s binlog of the last event applied on the slave. This allows the slave server to re-connect and resume from where it left off after replication has been temporarily stopped.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;When you see a replication lag, the first thing you need to understand is which of the two &lt;br /&gt;replication threads(IO Thread or SQL Thread) is behind&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For this, execute the commands below :&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;On the master: &lt;b&gt;show master status;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;On the slave:&amp;nbsp; &amp;nbsp;&lt;b&gt;show slave status;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To check where IO Thread currently is, compare the values from the following fields:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;From the output of the&amp;nbsp;&lt;b&gt;show master status;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; File -&amp;nbsp; &lt;/b&gt;for example:&amp;nbsp;mysql-bin-changelog.549445&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;From the output of the&amp;nbsp;&lt;b&gt;show slave status;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Master_Log_File&lt;/b&gt; – last file copied from the master &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for example:&amp;nbsp;mysql-bin-changelog.549440&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;b&gt;Compare the numeric value from the &quot;File&quot; field from master status and &lt;br /&gt;the value of &quot;master_log_file&quot; from slave status. &lt;br /&gt;The difference will be how many binlogs the salve is behind.(IO Thread)&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To get the current status of the SQL Thread check the following values:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Read_Master_Log_Pos&lt;/b&gt;&amp;nbsp;– holds until what position the binary log from master&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; is copied over to the relay log on the slave.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Exec_Master_Log_Pos&lt;/b&gt; – holds position from master binary log is being &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;executed by SQL thread.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;You can calculate the lag of SQL_Thread like this:&lt;br /&gt;&lt;b&gt;Read_Master_Log_Pos -&amp;nbsp;&lt;/b&gt;&lt;b&gt;Exec_Master_Log_Pos&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Also, the &quot;&lt;b&gt;Seconds_Behind_Master&quot; &lt;/b&gt;field should give you some sort of indication.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Possible reasons for IO_Thread lag:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;div&gt;&lt;b&gt; - Slow network between master/slave&lt;/b&gt;&amp;nbsp; - See if enabling &#39;slave_compressed_protocol&#39; helps&lt;/div&gt;&lt;div&gt;- &lt;b&gt;Binary logging on the slave -&lt;/b&gt;&amp;nbsp;It is IO intensive, you can disable it unless you need&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;it for a point in time recovery.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Possible reasons for SQL Thread lag:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;-  &lt;b&gt;Tables without PK/Unique key&lt;/b&gt; when you use row based binlog format&lt;/div&gt;&lt;div&gt;- &lt;b&gt;Long-running queries&lt;/b&gt; on the primary DB instance&lt;br /&gt;&lt;p&gt;Reference:&lt;br /&gt;&lt;a href=&quot;https://aws.amazon.com/premiumsupport/knowledge-center/rds-mysql-high-replica-lag/#Resolution&quot;&gt;https://aws.amazon.com/premiumsupport/knowledge-center/rds-mysql-high-replica-lag/&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Image credit:&lt;br /&gt;&lt;a href=&quot;https://medium.com/swlh/zero-downtime-master-slave-replication-4f2814138edf&quot;&gt;https://medium.com/swlh/zero-downtime-master-slave-replication-4f2814138edf&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/1928898870513644720/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2021/01/how-o-identify-mysql-replication-slave.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/1928898870513644720'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/1928898870513644720'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2021/01/how-o-identify-mysql-replication-slave.html' title='How to identify MySQL replication slave lag'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOCNGozECcEWBSavQp_7Wp5kt8Y38pP-4XETdqUwjwg-oLdmzSM2F_70u8_a18rFgYdSgA0cgUELvP869ZAXf_5dahkmnOHmoejExp9z8ErDWtuWAiz9uLr9QJc3-8S1sbcg4bFdt-LJ4/s72-w562-h208-c/MySQl+replica.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-5402788951809339658</id><published>2020-10-28T15:32:00.007-07:00</published><updated>2021-02-12T15:15:57.871-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="MySQL"/><title type='text'>MySQL guide for SQL Server developers/DBAs - Part 1</title><content type='html'>&lt;p&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLKAWgLsMhFIzIqFDZPHqcIQJKs-mhKvaDruhad1DJ4C1tEDsFQhOeI5_qLZOkQQ7kWE7IAZM6ipm2pw2hDCJU_tMaEIjJPfVStNPSX68JdzVBQ1WWHJ4BoyJiQ-W-v_L44pahTaRofAs/s245/SQL+Server+vs+MYSQL.jpg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;245&quot; data-original-width=&quot;231&quot; height=&quot;85&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLKAWgLsMhFIzIqFDZPHqcIQJKs-mhKvaDruhad1DJ4C1tEDsFQhOeI5_qLZOkQQ7kWE7IAZM6ipm2pw2hDCJU_tMaEIjJPfVStNPSX68JdzVBQ1WWHJ4BoyJiQ-W-v_L44pahTaRofAs/w80-h85/SQL+Server+vs+MYSQL.jpg&quot; width=&quot;80&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Do you know what &quot;My&quot; means in MySQL?&lt;br /&gt;&quot;My&quot; is the name of one of the co-founders Michael Widenius’s daughter.&lt;p&gt;&lt;/p&gt;&lt;p&gt;If you are a SQL Server developer/DBA and need to switch to MySQL,&lt;br /&gt;here are some useful gotchas:&lt;/p&gt;&lt;google-sheets-html-origin&gt;&lt;br /&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; dir=&quot;ltr&quot; style=&quot;border-collapse: collapse; border: none; font-family: Arial; font-size: 10pt; table-layout: fixed; width: 0px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;colgroup&gt;&lt;col width=&quot;137&quot;&gt;&lt;/col&gt;&lt;col width=&quot;199&quot;&gt;&lt;/col&gt;&lt;col width=&quot;245&quot;&gt;&lt;/col&gt;&lt;/colgroup&gt;&lt;tbody&gt;&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(0, 0, 0); overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;SQL Server&amp;quot;}&quot; style=&quot;border-color: rgb(0, 0, 0) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-weight: bold; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;SQL Server&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;MySQL&amp;quot;}&quot; style=&quot;border-color: rgb(0, 0, 0) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-weight: bold; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;MySQL&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Last inserted\nidentity value&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;Last inserted&lt;br /&gt;identity value&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;@@IDENTITY\nSCOPE_IDENTITY() \n\nReturns the last \nautomatically generated value&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;@@IDENTITY&lt;br /&gt;SCOPE_IDENTITY()&lt;br /&gt;&lt;br /&gt;Returns the &lt;b&gt;last&lt;/b&gt;&lt;br /&gt;automatically generated value&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;LAST_INSERT_ID() \n\n\nReturns the first(NOT LAST) \nautomatically generated value&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;LAST_INSERT_ID()&lt;br /&gt;&lt;br /&gt;Returns the &lt;b&gt;first&amp;nbsp;&amp;nbsp;&lt;/b&gt;(NOT LAST)&lt;br /&gt;automatically generated value.&lt;br /&gt;so, be careful when you insert multiple rows.&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Nested transactions&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;Nested transactions&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Supported&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;Supported&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Not supported.\nSTART TRANSACTION statement will implicitly \ncommit any current transaction&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;&lt;b&gt;Not &lt;/b&gt;supported.&lt;br /&gt;START TRANSACTION statement will implicitly&lt;br /&gt;commit any current transaction&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Local variables&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;Local variables&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;supported in SPs and in batches/scripts&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;Supported &lt;b&gt;everywhere:&lt;br /&gt;&lt;/b&gt;in SPs and in batches/scripts&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;There are local variables and system variables.\nLocal variables can be used only inside SPs,\nyou cannot use them in script/batch.&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;There are local variables and system variables.&lt;br /&gt;Local variables can be used &lt;b&gt;only &lt;/b&gt;inside SPs,&lt;br /&gt;you &lt;b&gt;cannot &lt;/b&gt;use them in script/batch.&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;if / while statements&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;if / while statements&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Supported anywhere&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;Supported everywhere&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;IF / WHILE statements are not supported in \nscripts/batches.\nThey can be used only in SPs/Functions/Triggers&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;IF / WHILE statements are &lt;b&gt;not &lt;/b&gt;supported in&lt;br /&gt;scripts/batches.&lt;br /&gt;They can be used &lt;b&gt;only &lt;/b&gt;in SPs/Functions/Triggers&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Alter stored procedure&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;Alter stored procedure&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;alter stored procedure statement\n is supported&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;alter stored procedure statement&lt;br /&gt;is supported&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;not supported, if you need to alter SP, \nyou need to drop it and recreate it&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;&lt;b&gt;not supported,&lt;/b&gt; if you need to alter SP,&lt;br /&gt;you need to drop it and recreate it&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Stored procedures\nparameters&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;Stored procedures&lt;br /&gt;parameters&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Supports default values \nand can be named referenced&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;Supports default values&lt;br /&gt;and can be named referenced&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;no default values\nand cannot be named referenced&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;no default values&lt;br /&gt;and cannot be named referenced&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;PRINT statement&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;PRINT statement&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Supported&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;Supported&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Not supported&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;&lt;b&gt;Not &lt;/b&gt;supported&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Division by zero&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;Division by zero&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;select 1/0 will return an error&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;select 1/0 will return an error&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;select 1/0 will return NULL&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;select 1/0 will return NULL&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Temp table&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;Temp tables&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;a temp table can be refferenced\nas much as you want in a query&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;a temp table can be referenced&lt;br /&gt;as much as you want in a query&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;You cannot refer to a TEMPORARY table\nmore than once in the same query&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;You &lt;b&gt;cannot &lt;/b&gt;refer to a TEMPORARY table&lt;br /&gt;more than once in the same query&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Row_Number()&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;Row_Number()&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;windows functions supported&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;Windows functions supported&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;not supported until ver 8, can be emulated as\nSET @row_number = 0; \r\nSELECT \r\n    (@row_number:=@row_number + 1) RowId&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;&lt;b&gt;not &lt;/b&gt;supported until version 8, can be emulated as&lt;br /&gt;SET @row_number = 0;&lt;br /&gt;SELECT&lt;br /&gt;(@row_number:=@row_number + 1) RowId&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Row_Number()&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;&lt;span face=&quot;Roboto, RobotoDraft, Helvetica, Arial, sans-serif&quot; style=&quot;background-color: white; font-size: 13px; white-space: pre-wrap;&quot;&gt;Activity monitoring&lt;/span&gt;&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;windows functions supported&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 12px; white-space: pre-wrap;&quot;&gt;sp_who2, sp_whoisactive,
sys.dm_exec_sessions,
sys.dm_exec_requests &lt;/span&gt;&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;not supported until ver 8, can be emulated as\nSET @row_number = 0; \r\nSELECT \r\n    (@row_number:=@row_number + 1) RowId&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 11px; white-space: pre-wrap;&quot;&gt;show processlist, show full processlist;

SELECT * 
FROM information_schema.processlist;

Tables under performance_schema:
 -events_statements_history_long
- events_statements_history
- events_statements_current,
mysql.slow_log&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Row_Number()&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 13px; white-space: pre-wrap;&quot;&gt;Open Transactions&lt;/span&gt;&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;windows functions supported&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 8pt; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;&lt;span style=&quot;background-color: white; font-size: 12px; white-space: pre-wrap;&quot;&gt;dbcc opentran 

or

SELECT * 
FROM sys.sysprocesses 
WHERE open_tran = 1  &lt;/span&gt;&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;not supported until ver 8, can be emulated as\nSET @row_number = 0; \r\nSELECT \r\n    (@row_number:=@row_number + 1) RowId&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; vertical-align: middle;&quot;&gt;&lt;span&gt;&lt;span style=&quot;background-color: white; font-size: 11px; white-space: pre-wrap;&quot;&gt;
select * 
from INFORMATION_SCHEMA.INNODB_TRX;

&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;Use this query to see which transactions are waiting and which transactions are blocking them:&lt;/span&gt;&lt;span&gt;&lt;span style=&quot;background-color: white; font-size: 11px; white-space: pre-wrap;&quot;&gt;

&lt;/span&gt;&lt;span style=&quot;background-color: white; font-size: xx-small; white-space: pre-wrap;&quot;&gt;SELECT  r.trx_id waiting_trx_id,
        r.trx_mysql_thread_id waiting_thread,
        r.trx_query waiting_query,
        b.trx_id blocking_trx_id,
        b.trx_mysql_thread_id blocking_thread,
        b.trx_query blocking_query
FROM    information_schema.innodb_lock_waits w INNER JOIN 
        information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id INNER JOIN 
        information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id;  &lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/google-sheets-html-origin&gt;&lt;p&gt;&amp;nbsp;Enjoy :)&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/5402788951809339658/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2020/10/mysql-guide-for-sql-server.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/5402788951809339658'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/5402788951809339658'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2020/10/mysql-guide-for-sql-server.html' title='MySQL guide for SQL Server developers/DBAs - Part 1'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLKAWgLsMhFIzIqFDZPHqcIQJKs-mhKvaDruhad1DJ4C1tEDsFQhOeI5_qLZOkQQ7kWE7IAZM6ipm2pw2hDCJU_tMaEIjJPfVStNPSX68JdzVBQ1WWHJ4BoyJiQ-W-v_L44pahTaRofAs/s72-w80-h85-c/SQL+Server+vs+MYSQL.jpg" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-848780592957794753</id><published>2020-10-23T15:16:00.005-07:00</published><updated>2020-12-22T18:31:31.237-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Git"/><category scheme="http://www.blogger.com/atom/ns#" term="GitHub"/><title type='text'>Fork-and-Branch Git Workflow(GitHub)</title><content type='html'>&lt;div&gt;Some companies use GitHub and Fork-and-Branch Git Workflow.&lt;/div&gt;Let&#39;s see how it works in detail.&lt;div&gt;&lt;br /&gt;Each developer will have 2 server-side Git repositories:&amp;nbsp;&lt;br /&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;private(origin)&amp;nbsp;&lt;/li&gt;&lt;li&gt;public(upstream)&lt;/li&gt;&lt;/ul&gt;The diagram below shows the high level&lt;br /&gt;of the Fork-and-Branch Git Workflow:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGtK2ybbzLJoexyoV4O_qn_3ztPWQFY1fKqlxo8jEjXJhAAsMHMSOF0fo0vkBx_17D-srNcsBgMHKfk0nRHnF5NSTbWgulbezQzpWKn9Ii8a7ETNyBKGXNPzT10bnYn077G6ufZJKL38o/s1000/Git+Flow.jpg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;749&quot; data-original-width=&quot;1000&quot; height=&quot;372&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGtK2ybbzLJoexyoV4O_qn_3ztPWQFY1fKqlxo8jEjXJhAAsMHMSOF0fo0vkBx_17D-srNcsBgMHKfk0nRHnF5NSTbWgulbezQzpWKn9Ii8a7ETNyBKGXNPzT10bnYn077G6ufZJKL38o/w495-h372/Git+Flow.jpg&quot; width=&quot;495&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The “fork and branch” workflow:&lt;br /&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Fork the central GitHub repository.&lt;/li&gt;&lt;li&gt;Clone the forked repository to your local system.&lt;/li&gt;&lt;li&gt;Add a Git remote (upstream) for the original central repository.&lt;/li&gt;&lt;li&gt;Create a feature branch in which to place your changes.&lt;/li&gt;&lt;li&gt;Make your changes to the new branch.&lt;/li&gt;&lt;li&gt;Commit the changes to the branch.&lt;/li&gt;&lt;li&gt;Push the branch to GitHub.&lt;/li&gt;&lt;li&gt;Open a pull request from the new branch to the original central repository.&lt;/li&gt;&lt;li&gt;Clean up after your pull request is merged.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;b&gt;Forking Company GitHub Repository&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;The first step is to fork the company&#39;s central GitHub repository. &lt;br /&gt;Forking it is basically making a copy of the repository, &lt;br /&gt;but with a link back to the original.&lt;br /&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Login into GitHub with your account.&lt;/li&gt;&lt;li&gt;Chose the central GitHub repository, for example: &quot;CompanyName/RepoName&quot;.&lt;/li&gt;&lt;li&gt;Click the Fork button on the upper right-hand side of the repository’s page.&lt;/li&gt;&lt;li&gt;You should have now &quot;YourName/RepoName&quot; server-side repository.&lt;/li&gt;&lt;/ul&gt;&lt;b&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;Clone the forked repository&lt;/b&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;Navigate to the forked repository and look on the right-hand side of the web page. &lt;br /&gt;You should see a button labeled as &quot;Code&quot;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO7VLrNZd494b9CiUoILajDvXuGYRB42U_jR4YqtWeK9UXK10TuP4OHpxOFppghwh24aBZlZEDXhCu7gMYtBGqWPuIds7hMknRA4YpX-GpjaaA5Nkryhi0jJj96Qd19wOpFzcmRWIlLB4/s559/1.jpg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;270&quot; data-original-width=&quot;559&quot; height=&quot;134&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO7VLrNZd494b9CiUoILajDvXuGYRB42U_jR4YqtWeK9UXK10TuP4OHpxOFppghwh24aBZlZEDXhCu7gMYtBGqWPuIds7hMknRA4YpX-GpjaaA5Nkryhi0jJj96Qd19wOpFzcmRWIlLB4/w277-h134/1.jpg&quot; width=&quot;277&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;Copy the URL there, and then use it with&amp;nbsp;&lt;span class=&quot;md-pair-s&quot; face=&quot;&amp;quot;Open Sans&amp;quot;, &amp;quot;Clear Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif&quot; md-inline=&quot;code&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: border-box; color: #333333; font-size: 16px; orphans: 4; white-space: pre-wrap;&quot;&gt;&lt;code style=&quot;background-color: #f3f4f4; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; font-family: var(--monospace); font-size: 0.9em; padding: 0px 2px; vertical-align: initial;&quot;&gt;git clone&lt;/code&gt;&lt;/span&gt;&lt;span class=&quot;md-plain&quot; face=&quot;&amp;quot;Open Sans&amp;quot;, &amp;quot;Clear Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif&quot; md-inline=&quot;plain&quot; style=&quot;background-color: white; box-sizing: border-box; color: #333333; font-size: 16px; orphans: 4; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;like this:&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;pre cid=&quot;n45&quot; class=&quot;md-fences md-end-block ty-contain-cm modeLoaded&quot; lang=&quot;&quot; mdtype=&quot;fences&quot; spellcheck=&quot;false&quot; style=&quot;background-attachment: inherit; background-clip: inherit; background-color: #f8f8f8; background-image: inherit; background-origin: inherit; background-position: inherit; background-repeat: inherit; background-size: inherit; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; break-inside: avoid; color: #333333; font-family: var(--monospace); margin-bottom: 15px; margin-top: 15px; overflow: visible; padding: 8px 4px 6px; position: relative; white-space: normal; width: inherit;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;git clone git@github.com:YourNameHere/RepoName.git&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;b&gt;Adding the remote (upstream)&lt;/b&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;Now the server-side forked repository acts as Git remote and named as origin. &lt;br /&gt;To use the “fork and branch” workflow, you’ll need to add a Git remote(upstream) &lt;br /&gt;pointing back to the original central repository.&lt;pre cid=&quot;n43&quot; class=&quot;md-fences md-end-block ty-contain-cm modeLoaded&quot; lang=&quot;&quot; mdtype=&quot;fences&quot; spellcheck=&quot;false&quot; style=&quot;background-attachment: inherit; background-clip: inherit; background-color: #f8f8f8; background-image: inherit; background-origin: inherit; background-position: inherit; background-repeat: inherit; background-size: inherit; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; break-inside: avoid; color: #333333; font-family: var(--monospace); font-size: 0.9em; margin-bottom: 15px; margin-top: 15px; overflow: visible; padding: 8px 4px 6px; position: relative; white-space: normal; width: inherit;&quot;&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;cd &quot;YourLocalFolderWhereYouClonedTheRepo&quot;&lt;/span&gt;&lt;br /&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;git remote add upstream git@github.com:CompanyName/RepoName.git&lt;/span&gt;&lt;/pre&gt;Now to test if everything is configured correctly, run the following&amp;nbsp;&lt;/div&gt;&lt;div&gt;command and you should see the output as below&lt;pre cid=&quot;n45&quot; class=&quot;md-fences md-end-block ty-contain-cm modeLoaded&quot; lang=&quot;&quot; mdtype=&quot;fences&quot; spellcheck=&quot;false&quot; style=&quot;background-attachment: inherit; background-clip: inherit; background-color: #f8f8f8; background-image: inherit; background-origin: inherit; background-position: inherit; background-repeat: inherit; background-size: inherit; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; break-inside: avoid; color: #333333; font-family: var(--monospace); font-size: 0.9em; margin-bottom: 15px; margin-top: 15px; overflow: visible; padding: 8px 4px 6px; position: relative; white-space: normal; width: inherit;&quot;&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;git remote -v&lt;/span&gt;&lt;/pre&gt;&lt;p cid=&quot;n46&quot; class=&quot;md-end-block md-p&quot; mdtype=&quot;paragraph&quot; style=&quot;box-sizing: border-box; color: #333333; font-family: &amp;quot;Open Sans&amp;quot;, &amp;quot;Clear Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; line-height: inherit; margin: 0.8em 0px; orphans: 4; position: relative; white-space: pre-wrap;&quot;&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOGqSm3VkfpvduqXHpOKQVcyE0XykF-tbd8lF0TZ-p1ilaoPlke2nTjGDHjeDYKvN7McsUSZRFFT2lyBhmVMOluF8_X7_kjx5MBagVc4fTb5Jbn-mRRSUaZH3SJor9OefJ5gI70QMnW28/s754/2.jpg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;142&quot; data-original-width=&quot;754&quot; height=&quot;97&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOGqSm3VkfpvduqXHpOKQVcyE0XykF-tbd8lF0TZ-p1ilaoPlke2nTjGDHjeDYKvN7McsUSZRFFT2lyBhmVMOluF8_X7_kjx5MBagVc4fTb5Jbn-mRRSUaZH3SJor9OefJ5gI70QMnW28/w516-h97/2.jpg&quot; width=&quot;516&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;h2 cid=&quot;n49&quot; class=&quot;md-end-block md-heading md-focus&quot; mdtype=&quot;heading&quot; style=&quot;border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; break-after: avoid-page; break-inside: avoid; cursor: text; line-height: 1.225; margin-bottom: 1rem; margin-top: 1rem; position: relative;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/h2&gt;&lt;h2 cid=&quot;n49&quot; class=&quot;md-end-block md-heading md-focus&quot; mdtype=&quot;heading&quot; style=&quot;border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; break-after: avoid-page; break-inside: avoid; cursor: text; line-height: 1.225; margin-bottom: 1rem; margin-top: 1rem; position: relative;&quot;&gt;&lt;div&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Creating a Branch&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;So far, you’ve forked a central repository, cloned it down to your local system,&lt;br /&gt;and added a Git remote(upstream) to your clone that points to the original&lt;br /&gt; central repository on GitHub.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Now to make changes we need to create a Branch from the local repository.&lt;br /&gt; &lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;After adding commit(s) to the new created branch,&lt;br /&gt; &lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;we will need to push the created branch to GitHub and create a Pull Request&lt;br /&gt; &lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;to merge the changes to the central repository.&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;To create a new branch and check it out, use this command:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/h2&gt;&lt;h2 cid=&quot;n49&quot; class=&quot;md-end-block md-heading&quot; mdtype=&quot;heading&quot; style=&quot;border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; break-after: avoid-page; break-inside: avoid; cursor: text; line-height: 1.225; margin-bottom: 1rem; margin-top: 1rem; position: relative;&quot;&gt;&lt;pre cid=&quot;n53&quot; class=&quot;md-fences md-end-block ty-contain-cm modeLoaded&quot; lang=&quot;&quot; mdtype=&quot;fences&quot; spellcheck=&quot;false&quot; style=&quot;background-attachment: inherit; background-clip: inherit; background-color: #f8f8f8; background-image: inherit; background-origin: inherit; background-position: inherit; background-repeat: inherit; background-size: inherit; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; break-inside: avoid; color: #333333; font-family: var(--monospace); font-weight: 400; margin-bottom: 15px; margin-top: 15px; orphans: 2; overflow: visible; padding: 8px 4px 6px; position: relative; text-align: left; white-space: normal; width: inherit;&quot;&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;git checkout -b &amp;lt;new branch name&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;If you are creating a new branch not right after creating a new fork, &lt;br /&gt;you should sync the fork with upstream before creating a new branch from the fork.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre cid=&quot;n55&quot; class=&quot;md-fences md-end-block ty-contain-cm modeLoaded&quot; lang=&quot;&quot; mdtype=&quot;fences&quot; spellcheck=&quot;false&quot; style=&quot;background-attachment: inherit; background-clip: inherit; background-color: #f8f8f8; background-image: inherit; background-origin: inherit; background-position: inherit; background-repeat: inherit; background-size: inherit; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; break-inside: avoid; color: #333333; font-family: var(--monospace); font-weight: 400; margin-bottom: 15px; margin-top: 15px; orphans: 2; overflow: visible; padding: 8px 4px 6px; position: relative; white-space: normal; width: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;git checkout master&lt;/span&gt;&lt;br /&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;git pull upstream master&lt;/span&gt;&lt;br /&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;git push origin master&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/h2&gt;&lt;b&gt;Commit the changes to the local repo&lt;/b&gt;&lt;h2 cid=&quot;n49&quot; class=&quot;md-end-block md-heading&quot; mdtype=&quot;heading&quot; style=&quot;border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; break-after: avoid-page; break-inside: avoid; cursor: text; line-height: 1.225; margin-bottom: 1rem; margin-top: 1rem; position: relative;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-size: small; font-weight: normal;&quot;&gt;Once you are done with the changes, use&lt;/span&gt;&lt;span class=&quot;md-plain&quot; face=&quot;&amp;quot;Open Sans&amp;quot;, &amp;quot;Clear Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif&quot; md-inline=&quot;plain&quot; style=&quot;box-sizing: border-box; color: #333333; font-size: 16px; font-weight: 400; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;md-pair-s&quot; face=&quot;&amp;quot;Open Sans&amp;quot;, &amp;quot;Clear Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif&quot; md-inline=&quot;code&quot; spellcheck=&quot;false&quot; style=&quot;box-sizing: border-box; color: #333333; font-size: 16px; font-weight: 400; white-space: pre-wrap;&quot;&gt;&lt;code style=&quot;background-color: #f3f4f4; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; font-family: var(--monospace); font-size: 0.9em; padding: 0px 2px; vertical-align: initial;&quot;&gt;git add .&lt;/code&gt;&lt;/span&gt;&lt;span class=&quot;md-plain&quot; face=&quot;&amp;quot;Open Sans&amp;quot;, &amp;quot;Clear Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif&quot; md-inline=&quot;plain&quot; style=&quot;box-sizing: border-box; color: #333333; font-size: 16px; font-weight: 400; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;command to stage all the changes,&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;it tells Git that you want to include updates to file(s) in the next commit.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre cid=&quot;n58&quot; class=&quot;md-fences md-end-block ty-contain-cm modeLoaded&quot; lang=&quot;&quot; mdtype=&quot;fences&quot; spellcheck=&quot;false&quot; style=&quot;background-attachment: inherit; background-clip: inherit; background-color: #f8f8f8; background-image: inherit; background-origin: inherit; background-position: inherit; background-repeat: inherit; background-size: inherit; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; break-inside: avoid; color: #333333; font-family: var(--monospace); font-weight: 400; margin-bottom: 15px; margin-top: 15px; orphans: 2; overflow: visible; padding: 8px 4px 6px; position: relative; text-align: left; white-space: normal; width: inherit;&quot;&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;git add .&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Execute git commit -m &quot;Your Comments&quot; to apply the changes to your local repository.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre cid=&quot;n60&quot; class=&quot;md-fences md-end-block ty-contain-cm modeLoaded&quot; lang=&quot;&quot; mdtype=&quot;fences&quot; spellcheck=&quot;false&quot; style=&quot;background-attachment: inherit; background-clip: inherit; background-color: #f8f8f8; background-image: inherit; background-origin: inherit; background-position: inherit; background-repeat: inherit; background-size: inherit; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; break-inside: avoid; color: #333333; font-family: var(--monospace); font-weight: 400; margin-bottom: 15px; margin-top: 15px; orphans: 2; overflow: visible; padding: 8px 4px 6px; position: relative; white-space: normal; width: inherit;&quot;&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;git commit -m &quot;Your Comments&quot;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/h2&gt;&lt;h2 cid=&quot;n61&quot; class=&quot;md-end-block md-heading&quot; mdtype=&quot;heading&quot; style=&quot;border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; break-after: avoid-page; break-inside: avoid; cursor: text; line-height: 1.225; margin-bottom: 1rem; margin-top: 1rem; position: relative;&quot;&gt;&lt;div&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Pushing changes to GitHub&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Once you’ve committed the changes to your local repository.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;The next step is to push those changes back up to GitHub.&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;If you were working in a branch called&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;md-pair-s&quot; face=&quot;&amp;quot;Open Sans&amp;quot;, &amp;quot;Clear Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif&quot; md-inline=&quot;code&quot; spellcheck=&quot;false&quot; style=&quot;box-sizing: border-box; color: #333333; font-size: 16px; font-weight: 400; orphans: 4; white-space: pre-wrap;&quot;&gt;&lt;code style=&quot;background-color: #f3f4f4; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; font-family: var(--monospace); font-size: 0.9em; padding: 0px 2px; vertical-align: initial;&quot;&gt;TestBranch&lt;/code&gt;&lt;/span&gt;&lt;span class=&quot;md-plain&quot; face=&quot;&amp;quot;Open Sans&amp;quot;, &amp;quot;Clear Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif&quot; md-inline=&quot;plain&quot; style=&quot;box-sizing: border-box; color: #333333; font-size: 16px; font-weight: 400; orphans: 4; white-space: pre-wrap;&quot;&gt;, &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;then pushing the changes you made in that branch back to GitHub would look like this:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/h2&gt;&lt;h2 cid=&quot;n49&quot; class=&quot;md-end-block md-heading&quot; mdtype=&quot;heading&quot; style=&quot;border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; break-after: avoid-page; break-inside: avoid; color: #333333; cursor: text; font-family: &amp;quot;Open Sans&amp;quot;, &amp;quot;Clear Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; line-height: 1.225; margin-bottom: 1rem; margin-top: 1rem; orphans: 4; position: relative; white-space: pre-wrap;&quot;&gt;&lt;pre cid=&quot;n63&quot; class=&quot;md-fences md-end-block ty-contain-cm modeLoaded&quot; lang=&quot;&quot; mdtype=&quot;fences&quot; spellcheck=&quot;false&quot; style=&quot;background-attachment: inherit; background-clip: inherit; background-color: #f8f8f8; background-image: inherit; background-origin: inherit; background-position: inherit; background-repeat: inherit; background-size: inherit; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; break-inside: avoid; font-family: var(--monospace); font-weight: 400; margin-bottom: 15px; margin-top: 15px; orphans: 2; overflow: visible; padding: 8px 4px 6px; position: relative; white-space: normal; width: inherit;&quot;&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;git push origin TestBranch&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/h2&gt;&lt;h2 cid=&quot;n64&quot; class=&quot;md-end-block md-heading&quot; mdtype=&quot;heading&quot; style=&quot;border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; break-after: avoid-page; break-inside: avoid; cursor: text; line-height: 1.225; margin-bottom: 1rem; margin-top: 1rem; position: relative;&quot;&gt;&lt;div&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Opening a Pull Request&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;After you push the new branch up to your GitHub server-side repository,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;you need to create a pull request.&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;This can be done on the GitHub website.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/h2&gt;&lt;h2 cid=&quot;n49&quot; class=&quot;md-end-block md-heading&quot; mdtype=&quot;heading&quot; style=&quot;border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; break-after: avoid-page; break-inside: avoid; cursor: text; line-height: 1.225; margin-bottom: 1rem; margin-top: 1rem; position: relative;&quot;&gt;&lt;p cid=&quot;n66&quot; class=&quot;md-end-block md-p&quot; mdtype=&quot;paragraph&quot; style=&quot;box-sizing: border-box; color: #333333; font-family: &amp;quot;Open Sans&amp;quot;, &amp;quot;Clear Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 400; line-height: inherit; margin: 0.8em 0px; position: relative; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;md-image md-img-loaded&quot; data-is-data-src=&quot;true&quot; data-ref=&quot;image_ref_8cissbfh&quot; md-inline=&quot;refimg&quot; style=&quot;box-sizing: border-box; font-family: monospace; min-height: 10px; min-width: 10px; position: relative; vertical-align: top; word-break: break-all;&quot;&gt;&lt;img height=&quot;43&quot; referrerpolicy=&quot;no-referrer&quot; src=&quot;data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAeAB4AAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCABjBIIDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD3+iiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKA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VdUhWG8vGkjVtwUKqjPrwBmmpxUV/XUKdSEKSv56HWwaVaH4iahbGxhNqlvuWMxDYPlXkDGOuf1qXSv9V4P+s/8AI1y//CZeINqj+0GwowP3acj345/GqcWu6lALMR3OPse7yPkX5M9e3P40e0ilZFLEUoyul3/G3+Q28AOv3AIyDdNkH/fruLm10u58ZR6INLtIoEAmkdIwHchc4BHRenFeePPI9w07NmRn3lsd85qzNq9/PqQ1F7lvtgIIlUBTxx24qKUlGKTMYVoxcm1u19x2Tp4f1Q/YjHEJxcooa2sTBsG7BVjk+45xViwNlc+Kb7Sn0KwS3tkfY32cbuMYJPfOc1x174m1jUYliub1mRWDgKir8w6HgCtzQfGd0dQ/4nOoE2wiYD90OW7Z2jJ79atVIs6Y4ilKaW23T/gkF7YQnQvDbw2sfmzuVkZYxmQ5GAT3rcbStLg1fX7yS3gVLTyhGht/MjjBQEnYMZ/ya42z8S6xp9mLS1vWjgBJC7VOM+hIyKSPxHq8WpTagl4y3MwAkcIuGwMDK4x+lP2kL7GUa1JNO3b8EzqluPC7XlvcvDEMwuhlNkywb8jaxT8x1q5o6TWXi+BHs9MWO5ti0c1pFhWAycr6ZBGfoK47/hK9b+1faftx83Z5efKTG3OcYxioX8Q6rJqUeoveObqMbUfAwo9MYx+lCqxVivrNO9/NPb/glfU7r7ZqEs3kQQ5ONkCbV49qqVZvr+51K6a5u5PMmYAFtoXp7Diq1c5x1JKU20XtF/5D+mf9fkP/AKGte6V4Xov/ACH9N/6+4f8A0MV7pVw2Payr4H6kc/8Ax7y/7h/lVqqs/wDx7y/7h/lVquqj1PTkFFFFbkhUNz/qh/vr/wChCpqhuf8AVf8AA1/9CFTLZggooorjNAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKBBRRRQMKKKKACiiigAooooAKKKKACiiigQUUUUDCiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKBHm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&quot; style=&quot;border-bottom-color: initial; border-bottom-style: initial; border-image: initial; border-left-color: transparent; border-left-style: solid; border-right-color: transparent; border-right-style: solid; border-top-color: initial; border-top-style: initial; border-width: 0px 4px 0px 2px; box-sizing: border-box; cursor: default; image-orientation: from-image; max-width: 100%; vertical-align: middle;&quot; width=&quot;511&quot; /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;After pushing the branch, browse the GitHub website &lt;br /&gt;and you will see an option to create a pull request.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/h2&gt;&lt;h2 cid=&quot;n68&quot; class=&quot;md-end-block md-heading&quot; mdtype=&quot;heading&quot; style=&quot;border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; break-after: avoid-page; break-inside: avoid; cursor: text; line-height: 1.225; margin-bottom: 1rem; margin-top: 1rem; position: relative; text-align: left;&quot;&gt;&lt;div&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;br /&gt;Merge Pull Request&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/h2&gt;&lt;h2 cid=&quot;n70&quot; class=&quot;md-end-block md-heading&quot; mdtype=&quot;heading&quot; style=&quot;border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; break-after: avoid-page; break-inside: avoid; cursor: text; line-height: 1.225; margin-bottom: 1rem; margin-top: 1rem; position: relative;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;md-plain&quot; md-inline=&quot;plain&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Once your Pull Request is approved, you need to merge it to the central repository (upstream).&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span class=&quot;md-plain&quot; md-inline=&quot;plain&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Cleaning up After a Merged Pull Request&lt;/span&gt;&lt;/div&gt;&lt;/h2&gt;&lt;h2 cid=&quot;n49&quot; class=&quot;md-end-block md-heading&quot; mdtype=&quot;heading&quot; style=&quot;border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; break-after: avoid-page; break-inside: avoid; cursor: text; line-height: 1.225; margin-bottom: 1rem; margin-top: 1rem; position: relative;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;First, you should update your local clone by using&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;p cid=&quot;n71&quot; class=&quot;md-end-block md-p&quot; mdtype=&quot;paragraph&quot; style=&quot;box-sizing: border-box; color: #333333; font-family: &amp;quot;Open Sans&amp;quot;, &amp;quot;Clear Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-size: 16px; font-weight: 400; line-height: inherit; margin: 0.8em 0px; position: relative; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;md-plain&quot; md-inline=&quot;plain&quot; style=&quot;box-sizing: border-box;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;md-pair-s&quot; md-inline=&quot;code&quot; spellcheck=&quot;false&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;code style=&quot;background-color: #f3f4f4; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; font-family: var(--monospace); font-size: 0.9em; padding: 0px 2px; vertical-align: initial;&quot;&gt;git pull upstream master&lt;/code&gt;&lt;/span&gt;&lt;span class=&quot;md-plain&quot; md-inline=&quot;plain&quot; style=&quot;box-sizing: border-box;&quot;&gt;. &lt;/span&gt;&lt;/p&gt;&lt;pre cid=&quot;n72&quot; class=&quot;md-fences md-end-block ty-contain-cm modeLoaded&quot; lang=&quot;&quot; mdtype=&quot;fences&quot; spellcheck=&quot;false&quot; style=&quot;background-attachment: inherit; background-clip: inherit; background-color: #f8f8f8; background-image: inherit; background-origin: inherit; background-position: inherit; background-repeat: inherit; background-size: inherit; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; break-inside: avoid; color: #333333; font-family: var(--monospace); font-weight: 400; margin-bottom: 15px; margin-top: 15px; orphans: 2; overflow: visible; padding: 8px 4px 6px; position: relative; white-space: normal; width: inherit;&quot;&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;git pull upstream master&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;This pulls the changes from the original central repository’s (indicated by upstream) master branch (indicated by master in that command) to your local cloned repository. Afterward, you can delete the feature branch (because the changes are already in the master branch):&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre cid=&quot;n74&quot; class=&quot;md-fences md-end-block ty-contain-cm modeLoaded&quot; lang=&quot;&quot; mdtype=&quot;fences&quot; spellcheck=&quot;false&quot; style=&quot;background-attachment: inherit; background-clip: inherit; background-color: #f8f8f8; background-image: inherit; background-origin: inherit; background-position: inherit; background-repeat: inherit; background-size: inherit; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; break-inside: avoid; color: #333333; font-family: var(--monospace); font-weight: 400; margin-bottom: 15px; margin-top: 15px; orphans: 2; overflow: visible; padding: 8px 4px 6px; position: relative; white-space: normal; width: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;git checkout master&lt;/span&gt;&lt;br /&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;git branch -d &amp;lt;branch name&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Then you can update the master branch in your forked repository:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre cid=&quot;n76&quot; class=&quot;md-fences md-end-block ty-contain-cm modeLoaded&quot; lang=&quot;&quot; mdtype=&quot;fences&quot; spellcheck=&quot;false&quot; style=&quot;background-attachment: inherit; background-clip: inherit; background-color: #f8f8f8; background-image: inherit; background-origin: inherit; background-position: inherit; background-repeat: inherit; background-size: inherit; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; break-inside: avoid; color: #333333; font-family: var(--monospace); font-weight: 400; margin-bottom: 15px; margin-top: 15px; orphans: 2; overflow: visible; padding: 8px 4px 6px; position: relative; white-space: normal; width: inherit;&quot;&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;git push origin master&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;And push the deletion of the feature branch to your GitHub repository&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre cid=&quot;n78&quot; class=&quot;md-fences md-end-block ty-contain-cm modeLoaded&quot; lang=&quot;&quot; mdtype=&quot;fences&quot; spellcheck=&quot;false&quot; style=&quot;background-attachment: inherit; background-clip: inherit; background-color: #f8f8f8; background-image: inherit; background-origin: inherit; background-position: inherit; background-repeat: inherit; background-size: inherit; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; break-inside: avoid; color: #333333; font-family: var(--monospace); font-weight: 400; margin-bottom: 15px; margin-top: 15px; orphans: 2; overflow: visible; padding: 8px 4px 6px; position: relative; white-space: normal; width: inherit;&quot;&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;git push --delete origin &amp;lt;branch name&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/h2&gt;&lt;h2 cid=&quot;n79&quot; class=&quot;md-end-block md-heading&quot; mdtype=&quot;heading&quot; style=&quot;border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; break-after: avoid-page; break-inside: avoid; cursor: text; line-height: 1.225; margin-bottom: 1rem; margin-top: 1rem; position: relative;&quot;&gt;&lt;div&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Keeping Your Fork in Sync&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;The forked repository doesn’t automatically stay in sync with the original repository.&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;To keep your fork in sync with the original repository, use these commands:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/h2&gt;&lt;h2 cid=&quot;n49&quot; class=&quot;md-end-block md-heading&quot; mdtype=&quot;heading&quot; style=&quot;border-bottom: 1px solid rgb(238, 238, 238); box-sizing: border-box; break-after: avoid-page; break-inside: avoid; cursor: text; line-height: 1.225; margin-bottom: 1rem; margin-top: 1rem; position: relative;&quot;&gt;&lt;pre cid=&quot;n81&quot; class=&quot;md-fences md-end-block ty-contain-cm modeLoaded&quot; lang=&quot;&quot; mdtype=&quot;fences&quot; spellcheck=&quot;false&quot; style=&quot;background-attachment: inherit; background-clip: inherit; background-color: #f8f8f8; background-image: inherit; background-origin: inherit; background-position: inherit; background-repeat: inherit; background-size: inherit; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; break-inside: avoid; color: #333333; font-family: var(--monospace); font-weight: 400; margin-bottom: 15px; margin-top: 15px; orphans: 2; overflow: visible; padding: 8px 4px 6px; position: relative; text-align: left; white-space: normal; width: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;git checkout master&lt;/span&gt;&lt;br /&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;git pull upstream master&lt;/span&gt;&lt;br /&gt;&lt;span role=&quot;presentation&quot; style=&quot;box-sizing: border-box; padding-right: 0.1px;&quot;&gt;git push origin master&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;This pulls the changes from the original repository&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;(the one pointed to by the&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;md-plain&quot; face=&quot;&amp;quot;Open Sans&amp;quot;, &amp;quot;Clear Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif&quot; md-inline=&quot;plain&quot; style=&quot;box-sizing: border-box; color: #333333; font-size: 16px; font-weight: 400; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;md-pair-s&quot; face=&quot;&amp;quot;Open Sans&amp;quot;, &amp;quot;Clear Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif&quot; md-inline=&quot;code&quot; spellcheck=&quot;false&quot; style=&quot;box-sizing: border-box; color: #333333; font-size: 16px; font-weight: 400; white-space: pre-wrap;&quot;&gt;&lt;code style=&quot;background-color: #f3f4f4; border-radius: 3px; border: 1px solid rgb(231, 234, 237); box-sizing: border-box; font-family: var(--monospace); font-size: 0.9em; padding: 0px 2px; vertical-align: initial;&quot;&gt;upstream&lt;/code&gt;&lt;/span&gt;&lt;span class=&quot;md-plain&quot; face=&quot;&amp;quot;Open Sans&amp;quot;, &amp;quot;Clear Sans&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif&quot; md-inline=&quot;plain&quot; style=&quot;box-sizing: border-box; color: #333333; font-size: 16px; font-weight: 400; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-size: small; font-weight: normal;&quot;&gt;Git remote&lt;/span&gt;&lt;span style=&quot;font-size: medium; font-weight: normal;&quot;&gt;) and&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;pushes them to your forked repository (the one pointed to by the origin remote).&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/h2&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/848780592957794753/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2020/10/fork-and-branch-git-workflow.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/848780592957794753'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/848780592957794753'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2020/10/fork-and-branch-git-workflow.html' title='Fork-and-Branch Git Workflow(GitHub)'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGtK2ybbzLJoexyoV4O_qn_3ztPWQFY1fKqlxo8jEjXJhAAsMHMSOF0fo0vkBx_17D-srNcsBgMHKfk0nRHnF5NSTbWgulbezQzpWKn9Ii8a7ETNyBKGXNPzT10bnYn077G6ufZJKL38o/s72-w495-h372-c/Git+Flow.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-3831186346221673205</id><published>2020-08-24T12:20:00.003-07:00</published><updated>2020-08-24T12:23:45.431-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="MySQL"/><title type='text'>MySQL - ERROR 1298 (HY000): Unknown or incorrect time zone: &#39;UTC&#39;</title><content type='html'>Let`s assume have a MySQL 5.6 Server installed on a Windows machine.&lt;div&gt;and you get the error below when trying to set&amp;nbsp;time_zone to &#39;UTC&#39;&amp;nbsp;&lt;/div&gt;&lt;div&gt;or a different time zone, follow the steps below to resolve this issue.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span style=&quot;color: #2b00fe;&quot;&gt;SET time_zone&lt;/span&gt; = &lt;span style=&quot;color: red;&quot;&gt;&#39;UTC&lt;/span&gt;&#39;;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: red;&quot;&gt;ERROR 1298 (HY000): Unknown or incorrect time zone: &#39;UTC&#39;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;The issue is you do not have the time zones data installed,&lt;/div&gt;&lt;div&gt;to install the time zones on a Windows machine, you will need:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;1) Download &quot;&lt;a href=&quot;https://downloads.mysql.com/general/timezone_2020a_posix.zip&quot; style=&quot;background: rgb(255, 255, 255); box-sizing: inherit; color: #0074a3; font-family: &amp;quot;Open Sans&amp;quot;, Arial, Helvetica, sans-serif; font-size: 13.68px; margin: 0px; padding: 0px; text-decoration-line: none; vertical-align: baseline;&quot;&gt;timezone_2020a_posix.zip&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #555555; font-family: &amp;quot;Open Sans&amp;quot;, Arial, Helvetica, sans-serif; font-size: 13.68px;&quot;&gt;&amp;nbsp;- POSIX standard&quot;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;from&amp;nbsp;&lt;a href=&quot;https://dev.mysql.com/downloads/timezones.html&quot; style=&quot;font-family: inherit; font-size: 13px; font-style: inherit; font-variant-caps: inherit; font-variant-ligatures: inherit; font-weight: inherit; white-space: inherit;&quot;&gt;https://dev.mysql.com/downloads/timezones.html&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;2) Stop the MySQL service&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;3) Extract the files from the downloaded file&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; and copy them with overwrite&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; to&amp;nbsp;&lt;b&gt;C:\ProgramData\MySQL\MySQL Server 5.6\data\mysql&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; Yes, to&amp;nbsp;&lt;/span&gt;C:\ProgramData\.. and not to C:\Program Files (x86)\MySQL\...&lt;br /&gt;&lt;br /&gt;4) Start the MySQL service&lt;/div&gt;&lt;div&gt;&lt;br /&gt;Enjoy:)&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/3831186346221673205/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2020/08/mysql-error-1298-hy000-unknown-or.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/3831186346221673205'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/3831186346221673205'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2020/08/mysql-error-1298-hy000-unknown-or.html' title='MySQL - ERROR 1298 (HY000): Unknown or incorrect time zone: &#39;UTC&#39;'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-6986876907860440369</id><published>2020-07-15T15:31:00.006-07:00</published><updated>2020-07-16T06:21:07.862-07:00</updated><title type='text'>PowerShell: Getting an access token with a client ID and client secret as part of OAuth 2.0 authentication</title><content type='html'>&lt;p style=&quot;margin: 0px;&quot;&gt;When using a REST API, most probably you will perform the&amp;nbsp;authentication&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;and authorization using the OAuth 2.0 protocol.&lt;/p&gt;&lt;div&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;The first step is to get an access token and use it in all subsequent calls,&lt;/p&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;what is called Bearer Authentication (token authentication).&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;p style=&quot;margin: 0px;&quot;&gt;Here is an example of how you can do it in PowerShell script.&lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;font color=&quot;#38761d&quot;&gt;#region Declare variables&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#ff0000&quot;&gt;$Url &lt;/font&gt;= &lt;font color=&quot;#ff00fe&quot;&gt;&quot;https://api.xxxxxxxxxxxxxxx.com/oauth/token&quot;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#ff0000&quot;&gt;$Method &lt;/font&gt;= &lt;font color=&quot;#ff00fe&quot;&gt;&quot;Post&quot;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#ff0000&quot;&gt;$Client_id &lt;/font&gt;= &lt;font color=&quot;#ff00fe&quot;&gt;&quot;XXXXXXXXXXXXXXXX&quot;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#ff0000&quot;&gt;$Client_secret&lt;/font&gt; = &lt;font color=&quot;#ff00fe&quot;&gt;&quot;YYYYYYYYYYYYYYYY&quot;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#ff0000&quot;&gt;$Body&lt;/font&gt; = @{&lt;font color=&quot;#ff00fe&quot;&gt;&quot;grant_type&quot; = &quot;client_credentials&quot;&lt;/font&gt;}&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#ff0000&quot;&gt;$Content &lt;/font&gt;= &quot;&lt;font color=&quot;#ff00fe&quot;&gt;application/x-www-form-urlencoded&lt;/font&gt;&quot;&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#ff0000&quot;&gt;$CombinedCredentials&lt;/font&gt; = &lt;font color=&quot;#6aa84f&quot;&gt;[System.Text.Encoding]&lt;/font&gt;::UTF8.GetBytes(&lt;font color=&quot;#ff0000&quot;&gt;$Client_id&lt;/font&gt; + &quot;:&quot; + &lt;font color=&quot;#ff0000&quot;&gt;$Client_secret&lt;/font&gt;)&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#ff0000&quot;&gt;$Base64Credentials&lt;/font&gt; = &lt;font color=&quot;#6aa84f&quot;&gt;[System.Convert]&lt;/font&gt;::ToBase64String(&lt;font color=&quot;#ff0000&quot;&gt;$CombinedCredentials&lt;/font&gt;)&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#ff0000&quot;&gt;$Headers&lt;/font&gt; = @{&quot;&lt;font color=&quot;#ff00fe&quot;&gt;Authorization&quot; = &quot;Basic &quot;&lt;/font&gt; + &lt;font color=&quot;#ff0000&quot;&gt;$Base64Credentials&lt;/font&gt;} &lt;font color=&quot;#38761d&quot; size=&quot;2&quot;&gt;# Use basic authorization header&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#38761d&quot;&gt;#endregion&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#38761d&quot;&gt;# Get access token by OAuth 2.0 authentication through client ID and client secret&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#ff0000&quot;&gt;$Response&lt;/font&gt; = Invoke-WebRequest -Uri &lt;font color=&quot;#ff0000&quot;&gt;$Url&lt;/font&gt; -Method &lt;font color=&quot;#ff0000&quot;&gt;$Method&lt;/font&gt; -Body &lt;font color=&quot;#ff0000&quot;&gt;$Body&lt;/font&gt; -Headers &lt;font color=&quot;#ff0000&quot;&gt;$Headers&lt;/font&gt; -ContentType &lt;font color=&quot;#ff0000&quot;&gt;$Content&lt;/font&gt; -UseBasicParsing&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#6aa84f&quot; size=&quot;2&quot;&gt;# -UseBasicParsing is used to solve the following issue: The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer&#39;s first-launch configuration is not complete&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#ff0000&quot;&gt;$Response &lt;/font&gt;= &lt;font color=&quot;#ff0000&quot;&gt;$Response&lt;/font&gt;.Content | ConvertFrom-Json&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#ff0000&quot;&gt;$Accesstoken&lt;/font&gt; =&lt;font color=&quot;#ff0000&quot;&gt;$Response&lt;/font&gt;.&lt;font color=&quot;#ff00fe&quot;&gt;&quot;access_token&quot;&lt;/font&gt;&lt;font color=&quot;#c27ba0&quot;&gt;&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#c27ba0&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;Set the variables below with your values:&lt;br /&gt;&lt;span style=&quot;color: red;&quot;&gt;$Url&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;font color=&quot;#ff0000&quot;&gt;$Client_id&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#ff0000&quot;&gt;$Client_secret&lt;/font&gt;&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;font color=&quot;#c27ba0&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;In case you get the error &lt;font color=&quot;#ff0000&quot;&gt;&quot;The request was aborted: Could not create SSL/TLS secure channel.&quot;&lt;/font&gt;&lt;div&gt;Add this at the beginning of the script.&lt;br /&gt;&lt;br /&gt;&lt;font size=&quot;1&quot;&gt;[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls, [Net.SecurityProtocolType]::Tls11, [Net.SecurityProtocolType]::Tls12, [Net.SecurityProtocolType]::Ssl3&lt;br /&gt;[Net.ServicePointManager]::SecurityProtocol = &quot;Tls, Tls11, Tls12, Ssl3&quot;&lt;/font&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/6986876907860440369/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2020/07/powershell-how-to-get-access-token.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/6986876907860440369'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/6986876907860440369'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2020/07/powershell-how-to-get-access-token.html' title='PowerShell: Getting an access token with a client ID and client secret as part of OAuth 2.0 authentication'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-6257017768747778191</id><published>2020-05-08T18:54:00.001-07:00</published><updated>2020-05-16T16:42:59.148-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Azure Data Studio"/><category scheme="http://www.blogger.com/atom/ns#" term="Data Exploration"/><category scheme="http://www.blogger.com/atom/ns#" term="Data Visualization"/><title type='text'>Data Exploration and Visualization in Azure Data Studio</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfI2f-HCdcHHDyC_uCaOvK1_greFUZmRGGJsRuGRZvqyXDDwUWYM5VDSfABpdO1i0hluLbRNpORoqr6klGrFs0qw_L-wC78rBkJ0qoeSkWLeqG3cURzEb9zeNDtG5TbL-_WvJJVU2-Rhw/s1600/Data+Visualization.jpg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;317&quot; data-original-width=&quot;490&quot; height=&quot;207&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfI2f-HCdcHHDyC_uCaOvK1_greFUZmRGGJsRuGRZvqyXDDwUWYM5VDSfABpdO1i0hluLbRNpORoqr6klGrFs0qw_L-wC78rBkJ0qoeSkWLeqG3cURzEb9zeNDtG5TbL-_WvJJVU2-Rhw/s320/Data+Visualization.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
If you need to do some data &lt;br /&gt;
exploration in fast and&lt;br /&gt;
&lt;div&gt;
interactive way or maybe you&lt;/div&gt;
&lt;div&gt;
want to find a pattern, a trend,&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
and anomalies from the data,&lt;/div&gt;
&lt;div&gt;
How you do that?&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Well, I would like to recommend&lt;br /&gt;
this powerful free tool named&lt;/div&gt;
&lt;div&gt;
&lt;a href=&quot;https://docs.microsoft.com/en-us/sql/azure-data-studio/sanddance-extension?view=sql-server-ver15&amp;amp;WT.mc_id=dataexposed-c9-niner&quot; target=&quot;_blank&quot;&gt;SandDance&lt;/a&gt;!&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
You can install it as an add-on to Azure Data Studio or VSCode/PowerBI&lt;br /&gt;
and visualize your data from a query or table in a very efficient way.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
Just check it out and you will see it for yourself.&lt;br /&gt;
Watch the video to the end to see how to do it against a query result.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;a href=&quot;https://channel9.msdn.com/Shows/Data-Exposed/Introducing-SandDance-Data-Visualization-in-Azure-Data-Studio&quot; target=&quot;_blank&quot;&gt;Introducing SandDance: Data Visualization in Azure Data Studio&lt;/a&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
Enjoy!&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/6257017768747778191/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2020/05/data-exploration-and-visualization-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/6257017768747778191'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/6257017768747778191'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2020/05/data-exploration-and-visualization-in.html' title='Data Exploration and Visualization in Azure Data Studio'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfI2f-HCdcHHDyC_uCaOvK1_greFUZmRGGJsRuGRZvqyXDDwUWYM5VDSfABpdO1i0hluLbRNpORoqr6klGrFs0qw_L-wC78rBkJ0qoeSkWLeqG3cURzEb9zeNDtG5TbL-_WvJJVU2-Rhw/s72-c/Data+Visualization.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-4349141875656564733</id><published>2020-05-01T15:19:00.000-07:00</published><updated>2020-05-04T11:22:22.890-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Cardinality"/><category scheme="http://www.blogger.com/atom/ns#" term="Estimations"/><category scheme="http://www.blogger.com/atom/ns#" term="Statistics"/><title type='text'>How SQL Server Optimizer calculates the Estimated Number of Rows</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_K_fW1ofV74BzBIJw45VfkEnHuK5amUjdOOIJg9BXylRx29EPoCaxBL0TOi_fNo8ihJ321r835YmHS4DDDOJCoM8wWowXh7DvctZ-JRci-ygqe2hblumXQa3FLH7OIya4mBr0vNT2pfY/s1600/Estimated+Number+of+rows.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;519&quot; data-original-width=&quot;402&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_K_fW1ofV74BzBIJw45VfkEnHuK5amUjdOOIJg9BXylRx29EPoCaxBL0TOi_fNo8ihJ321r835YmHS4DDDOJCoM8wWowXh7DvctZ-JRci-ygqe2hblumXQa3FLH7OIya4mBr0vNT2pfY/s200/Estimated+Number+of+rows.jpg&quot; width=&quot;154&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Have you ever wondered how SQL Server Optimizer &lt;br /&gt;
calculates the &quot;Estimated Number of Rows&quot; &lt;br /&gt;
when you have multiple predicates/filters &amp;amp; joins?&lt;br /&gt;
&lt;br /&gt;
Well, you can find a brief summary below.&lt;br /&gt;
I assume that you are already familiar with the Statistics&lt;br /&gt;
(Density Vector, Histogram).&lt;br /&gt;
The algorithms depend if you use local variables, &lt;br /&gt;
parameters, multiple predicates &lt;br /&gt;
or a single predicate legacy CE, new CE, and more.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It is important to note when the SQL Server optimizer uses Density Vector &lt;br /&gt;
and when histogram.&lt;br /&gt;
&lt;br /&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;i&gt;Density is the ratio of unique values within the given column or a set of columns. &lt;br /&gt;Density&amp;nbsp; = 1 / (Number of distinct values for a column or set of column)&lt;/i&gt;&lt;/span&gt;&lt;div&gt;
&lt;br /&gt;The Density vector is used when the optimizer&lt;b&gt; cannot sniff&lt;/b&gt; the predicate value,&lt;br /&gt;
for example:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;1) When you use local variables as predicates/filters in a stored procedure&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;or in a batch query&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; 2) When you use&amp;nbsp;&lt;span style=&quot;color: blue; font-size: x-small;&quot;&gt;OPTION&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;(OPTIMIZE FOR UNKNOWN)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; 3) When the parameter sniffing feature is disabled&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The Histogram is used when the optimizer&lt;b&gt;&amp;nbsp;is able to&amp;nbsp;sniff &lt;/b&gt;the predicate value,&lt;br /&gt;
for example:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
1) When you use input parameters as predicates/filters in a stored procedure&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
2) When you use sp_executesql with parameters&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
3) When you use local variables with &lt;span style=&quot;color: blue;&quot;&gt;OPTION&lt;/span&gt;(RECOMPILE)&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So let`s review common use cases:&lt;br /&gt;
&lt;br /&gt;
1) The table below refers to the use case when you use one filter&lt;br /&gt;
&amp;nbsp; &amp;nbsp; as a&amp;nbsp;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;u&gt;local variable&lt;/u&gt;&lt;/span&gt;&amp;nbsp;&lt;/b&gt;and the statistics exist on the filtered column/index.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; This also&amp;nbsp;applies when you use&amp;nbsp;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;OPTION &lt;/span&gt;(OPTIMIZE FOR UNKNOWN)&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; or when the parameter sniffing feature is disabled.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; DECLARE &lt;/span&gt;@CustomerId INT =123&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; SELECT&amp;nbsp;&amp;nbsp;&lt;/span&gt;*&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; FROM&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;dbo.Customers&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; WHERE&amp;nbsp;&amp;nbsp;&lt;/span&gt;CustomerId = @CustomerId&lt;br /&gt;
&lt;google-sheets-html-origin&gt;&lt;/google-sheets-html-origin&gt;&lt;br /&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; dir=&quot;ltr&quot; style=&quot;border-collapse: collapse; border: none; font-family: Arial; font-size: 10pt; table-layout: fixed; width: 0px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;colgroup&gt;&lt;col width=&quot;176&quot;&gt;&lt;/col&gt;&lt;col width=&quot;149&quot;&gt;&lt;/col&gt;&lt;col width=&quot;219&quot;&gt;&lt;/col&gt;&lt;/colgroup&gt;&lt;tbody&gt;
&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(204, 204, 204) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Local Variables&amp;quot;}&quot; rowspan=&quot;1&quot; style=&quot;border-color: rgb(0, 0, 0) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-weight: bold; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;Local Variables&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;Filter&lt;/b&gt;&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;New CE&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-weight: bold; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;New CE&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Old CE&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-weight: bold; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;Old/Legacy CE&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Column = @Value&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; color: black; font-family: &amp;quot;Times New Roman&amp;quot;; font-weight: bold; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;Column = @Value&lt;/td&gt;&lt;td colspan=&quot;2&quot; data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Density Vector x Number Of Rows In Table&amp;quot;}&quot; rowspan=&quot;1&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; color: black; font-family: &amp;quot;Times New Roman&amp;quot;; font-size: 11pt; font-weight: normal; overflow-wrap: break-word; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: middle; white-space: normal;&quot;&gt;Density Vector x Number of Rows In Table&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Col &amp;gt;, &amp;gt;=, &amp;lt;, &amp;lt;= @Value&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; font-weight: bold; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;Col &amp;gt;, &amp;gt;=, &amp;lt;, &amp;lt;= @Value&lt;/td&gt;&lt;td colspan=&quot;2&quot; data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;30% of Number of Rows In Table&amp;quot;}&quot; rowspan=&quot;1&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;30% of Number of Rows In Table&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Between&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; color: black; font-family: &amp;quot;Times New Roman&amp;quot;; font-weight: bold; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;Between&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;0.3 * SQRT(0.3)&amp;quot;}&quot; style=&quot;background-color: white; border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; color: #333333; font-family: Vollkorn; font-weight: normal; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;0.3 * SQRT(0.3)&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;TableCardinality * 0.09&amp;quot;}&quot; style=&quot;background-color: white; border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; color: #333333; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;TableCardinality * 0.09&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Like&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; color: black; font-family: &amp;quot;Times New Roman&amp;quot;; font-weight: bold; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;Like&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;TableCardinality * 0.09&amp;quot;}&quot; style=&quot;background-color: white; border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; color: #333333; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;TableCardinality * 0.09&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;TableCardinality * (0.09 / 6 * LOG(D))&amp;quot;}&quot; style=&quot;background-color: white; border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; color: #333333; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;TableCardinality*(0.09 / 6 * LOG(D))&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;Table Cardinality - Total Number of Rows In Table&lt;br /&gt;Density = 1 / ( # distinct values for column(s) )&lt;br /&gt;D - Average length rounded down to integer (Average data length is taken from statistics density vector)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
2) For use case, when you use one parameterized filter or literal,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; The estimated number of rows &lt;b&gt;&lt;u&gt;will be selected from the histogram.&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; For example: Input parameters in a stored procedure or sp_executesql&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; SELECT &lt;/span&gt;* &lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; FROM&amp;nbsp; &amp;nbsp;&lt;/span&gt; dbo.Customers&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; WHERE&amp;nbsp;&amp;nbsp;&lt;/span&gt;CustomerId = 123&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3) When you have a query that uses more than one column predicate/filter:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; SELECT&amp;nbsp;&amp;nbsp;&lt;/span&gt;*&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; FROM&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;dbo.Customers&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; WHERE&amp;nbsp;&amp;nbsp;&lt;/span&gt;CustomerId = 123&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;AND &lt;/span&gt;Name =&#39;XYZ&#39;&lt;br /&gt;
&lt;br /&gt;
&lt;google-sheets-html-origin&gt;&lt;/google-sheets-html-origin&gt;&lt;br /&gt;
&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; dir=&quot;ltr&quot; style=&quot;border-collapse: collapse; border: none; font-family: Arial; font-size: 10pt; table-layout: fixed; width: 0px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;colgroup&gt;&lt;col width=&quot;100&quot;&gt;&lt;/col&gt;&lt;col width=&quot;140&quot;&gt;&lt;/col&gt;&lt;col width=&quot;302&quot;&gt;&lt;/col&gt;&lt;/colgroup&gt;&lt;tbody&gt;
&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Filter&amp;quot;}&quot; style=&quot;border: 1px solid rgb(0, 0, 0); overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;Filter&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;New CE&amp;quot;}&quot; style=&quot;border-color: rgb(0, 0, 0) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-weight: bold; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;New CE&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Old CE&amp;quot;}&quot; style=&quot;border-color: rgb(0, 0, 0) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-weight: bold; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;Old/Legacy CE&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;AND &amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; font-weight: bold; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;AND&lt;/td&gt;&lt;td colspan=&quot;1&quot; data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Table Cardinality * S1 * SQRT(S2) * SQRT(SQRT(S3)) * SQRT(SQRT(SQRT(S4)))&amp;quot;}&quot; rowspan=&quot;2&quot; style=&quot;background-color: white; border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; color: #333333; font-size: 7pt; overflow-wrap: break-word; overflow: hidden; padding: 2px 3px; vertical-align: middle; white-space: normal;&quot;&gt;&lt;span style=&quot;font-size: 7pt;&quot;&gt;Table Cardinality * S1 * SQRT(S2) * SQRT(SQRT(S3)) * SQRT(SQRT(SQRT(S4)))&lt;/span&gt;&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Table Cardinality * (S1 * S2 * S3)&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 9pt; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;Table Cardinality * (S1 * S2 * S3)&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;OR&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; font-weight: bold; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;OR&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Table Cardinality (TotalRows) * ( (S1 + S2) – (S1 * S2) )&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-size: 9pt; overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;Table Cardinality * ( (S1 + S2) – (S1 * S2) )&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
&lt;ul style=&quot;background: rgb(255, 255, 255); border: 0px; color: #333333; font-family: Vollkorn, serif; font-size: 16px; list-style: square; margin: 0px 0px 24px 1.5em; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;Table Cardinality - Total Number of Rows In Table&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;Selectivity(S) = (# rows that pass the predicate) / (# rows in the table)&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;S1 means selectivity of the first filter, S2 - selectivity of the second filter and etc&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Let`s see what was has changed in the new cardinality estimator compared&lt;br /&gt;
to the legacy estimator:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;google-sheets-html-origin&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; dir=&quot;ltr&quot; style=&quot;border-collapse: collapse; border: none; font-family: Arial; font-size: 10pt; table-layout: fixed; width: 0px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;colgroup&gt;&lt;col width=&quot;194&quot;&gt;&lt;/col&gt;&lt;col width=&quot;186&quot;&gt;&lt;/col&gt;&lt;col width=&quot;166&quot;&gt;&lt;/col&gt;&lt;/colgroup&gt;&lt;tbody&gt;
&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(0, 0, 0); overflow: hidden; padding: 2px 3px; vertical-align: bottom;&quot;&gt;&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;New CE&amp;quot;}&quot; style=&quot;border-color: rgb(0, 0, 0) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-weight: bold; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;New CE&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Legacy CE&amp;quot;}&quot; style=&quot;border-color: rgb(0, 0, 0) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; font-weight: bold; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: bottom;&quot;&gt;Legacy CE&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-textstyleruns=&quot;{&amp;quot;1&amp;quot;:0}{&amp;quot;1&amp;quot;:32,&amp;quot;2&amp;quot;:{&amp;quot;4&amp;quot;:8.25,&amp;quot;5&amp;quot;:0}}&quot; data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Correlation for multi-predicate\nHow the estimates calculated when\nyou have multiple predicates on a table&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: middle;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-weight: bold;&quot;&gt;Correlation for multi-predicate&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 8pt;&quot;&gt;How the estimates calculated when&lt;br /&gt;you have multiple predicates on a table&lt;/span&gt;&lt;/td&gt;&lt;td data-sheets-textstyleruns=&quot;{&amp;quot;1&amp;quot;:0}{&amp;quot;1&amp;quot;:58,&amp;quot;2&amp;quot;:{&amp;quot;4&amp;quot;:8.25,&amp;quot;5&amp;quot;:1}}&quot; data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Assumes there is some correlation between the predicates:\nTable Cardinality * S1 * SQRT(S2) * SQRT(SQRT(S3)) * SQRT(SQRT(SQRT(S4)))&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; overflow-wrap: break-word; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: middle;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;Assumes there is some correlation between the predicates:&lt;/span&gt;&lt;span style=&quot;font-size: 8pt; font-weight: bold;&quot;&gt;&lt;br /&gt;Table Cardinality * S1 * SQRT(S2) * SQRT(SQRT(S3)) * SQRT(SQRT(SQRT(S4)))&lt;/span&gt;&lt;/td&gt;&lt;td data-sheets-textstyleruns=&quot;{&amp;quot;1&amp;quot;:0}{&amp;quot;1&amp;quot;:96,&amp;quot;2&amp;quot;:{&amp;quot;4&amp;quot;:8.25,&amp;quot;5&amp;quot;:1}}&quot; data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Selectivity of multiple predicates computed as the multiplication of individual selectivities: \nTable Cardinality * (S1 * S2 * S3)&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; overflow-wrap: break-word; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: middle;&quot;&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;Selectivity of multiple predicates computed as the multiplication of individual sensitivities&lt;/span&gt;&lt;span style=&quot;font-size: 8pt; font-weight: bold;&quot;&gt;Table Cardinality * (S1 * S2 * S3)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-textstyleruns=&quot;{&amp;quot;1&amp;quot;:0}{&amp;quot;1&amp;quot;:30,&amp;quot;2&amp;quot;:{&amp;quot;4&amp;quot;:9,&amp;quot;5&amp;quot;:0}}&quot; data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Out-of-range value estimation\nWhen the filtered value is \nnot in range in the histogram&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: middle;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-weight: bold;&quot;&gt;Out-of-range value estimation&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 9pt;&quot;&gt;When the filtered value is&lt;br /&gt;not in range in the histogram&lt;/span&gt;&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Table cardinality * Density&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; overflow-wrap: break-word; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: middle;&quot;&gt;Table cardinality * Density&lt;/td&gt;&lt;td data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Estimation is 1 row&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; overflow-wrap: break-word; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: middle;&quot;&gt;Estimation is 1 row&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;height: 21px;&quot;&gt;&lt;td data-sheets-textstyleruns=&quot;{&amp;quot;1&amp;quot;:0}{&amp;quot;1&amp;quot;:15,&amp;quot;2&amp;quot;:{&amp;quot;5&amp;quot;:0}}&quot; data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Join Estimates\nHow to estimate the JOIN result&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: middle;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-weight: bold;&quot;&gt;Join Estimates&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;How to estimate the JOIN result&lt;/span&gt;&lt;/td&gt;&lt;td data-sheets-textstyleruns=&quot;{&amp;quot;1&amp;quot;:0}{&amp;quot;1&amp;quot;:17,&amp;quot;2&amp;quot;:{&amp;quot;5&amp;quot;:0}}{&amp;quot;1&amp;quot;:166}&quot; data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Base containment\nCalculate the JOIN selectivity \nby two histograms \nwithout applying the predicates,\nThen multiple the JOIN selectivity with Predicate selectivities.\nMeaning filter predicates are independent from the join selectivity&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; overflow-wrap: break-word; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: middle;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-weight: bold;&quot;&gt;Base containment&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;Calculate the JOIN selectivity&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;by two histograms&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;without applying the predicates,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;Then multiple the JOIN selectivity with Predicate &lt;/span&gt;&lt;span style=&quot;font-size: 13.3333px;&quot;&gt;sensitivities&lt;/span&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 10pt; font-weight: bold;&quot;&gt;Meaning filter predicates are independent of the join selectivity&lt;/span&gt;&lt;/td&gt;&lt;td data-sheets-textstyleruns=&quot;{&amp;quot;1&amp;quot;:0}{&amp;quot;1&amp;quot;:19,&amp;quot;2&amp;quot;:{&amp;quot;5&amp;quot;:0}}{&amp;quot;1&amp;quot;:107}&quot; data-sheets-value=&quot;{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Simple containment\nAfter applying filters\nThe two histograms,\n are merged together,\n assuming containment.\nMeaning JOIN selectivity \nis dependant on the filters&amp;quot;}&quot; style=&quot;border-color: rgb(204, 204, 204) rgb(0, 0, 0) rgb(0, 0, 0) rgb(204, 204, 204); border-image: initial; border-style: solid; border-width: 1px; overflow: hidden; padding: 2px 3px; text-align: center; vertical-align: middle;&quot;&gt;&lt;span style=&quot;font-size: 10pt; font-weight: bold;&quot;&gt;Simple containment&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;After applying filters&lt;br /&gt;The two histograms,&lt;br /&gt;are merged together,&lt;br /&gt;assuming containment.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;b&gt;Meaning JOIN selectivity&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;b&gt;is &lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 13.3333px;&quot;&gt;&lt;b&gt;dependent&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;b&gt;&amp;nbsp;on the filters&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/google-sheets-html-origin&gt;&lt;/div&gt;
&lt;div&gt;
&lt;google-sheets-html-origin&gt;&lt;br /&gt;According to Microsoft, regrading the JOIN Estimates:&lt;/google-sheets-html-origin&gt;&lt;/div&gt;
&lt;div&gt;
&lt;google-sheets-html-origin&gt;&lt;br /&gt;&lt;/google-sheets-html-origin&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;i&gt;The Legacy CE model assumes that users always query for data that exists. &lt;br /&gt;This means that, for a join predicate that involves an equijoin operation for two tables, &lt;br /&gt;the joined columns exist on both sides of the join. &lt;br /&gt;In the presence of additional non-join filter predicates against the join table, &lt;br /&gt;the Legacy CE assumes some level of correlation for the join predicates &lt;br /&gt;and non-join filter predicates. This implied correlation is called Simple Containment.&lt;br /&gt;&lt;br /&gt;Alternatively, the New CE uses Base Containment as the correlation. &lt;br /&gt;The New CE model assumes that users might query for data that does not exist. &lt;br /&gt;This means that the filter predicates on separate tables may not be correlated with each other. &lt;br /&gt;Therefore, we use a probabilistic approach&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/4349141875656564733/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2020/05/how-sql-server-optimizer-calculates.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/4349141875656564733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/4349141875656564733'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2020/05/how-sql-server-optimizer-calculates.html' title='How SQL Server Optimizer calculates the Estimated Number of Rows'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_K_fW1ofV74BzBIJw45VfkEnHuK5amUjdOOIJg9BXylRx29EPoCaxBL0TOi_fNo8ihJ321r835YmHS4DDDOJCoM8wWowXh7DvctZ-JRci-ygqe2hblumXQa3FLH7OIya4mBr0vNT2pfY/s72-c/Estimated+Number+of+rows.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-6850518998013365699</id><published>2020-04-21T16:21:00.001-07:00</published><updated>2023-07-17T12:50:06.949-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Query Tuning"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Performance"/><title type='text'>A practical SQL query performance tuning checklist (23 Steps)</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpkjldIXLRVsxi06I_irV6Pm_crWSQMcc7Chd28KwNp-jzycAmxcLE18TJkZts3kDRs2L1rWrB7mQvHhn38629bIg_S3NoXoTJ8mJsDB0k7u0CmxyBHBJ64vNszkqvGZqOSSkeEGKEv6o/s1600/SQL+Query+Performance.jpg&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;b&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;120&quot; data-original-width=&quot;234&quot; height=&quot;102&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpkjldIXLRVsxi06I_irV6Pm_crWSQMcc7Chd28KwNp-jzycAmxcLE18TJkZts3kDRs2L1rWrB7mQvHhn38629bIg_S3NoXoTJ8mJsDB0k7u0CmxyBHBJ64vNszkqvGZqOSSkeEGKEv6o/s200/SQL+Query+Performance.jpg&quot; width=&quot;200&quot; /&gt;&lt;/b&gt;&lt;/a&gt;&lt;/div&gt;
Row Goals, Residual Predicate, Batch Mode,&lt;br /&gt;
Filtered Statistics, Legacy vs New CE,&lt;br /&gt;
Trace flag 4199...&lt;br /&gt;
&lt;br /&gt;
Do you know these words?&lt;br /&gt;
If not, continue reading.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you are stuck with a SQL query that doesn`t perform well,&lt;br /&gt;
here is a checklist of things that may help you to get ideas.&lt;br /&gt;
This is a high-level checklist without deep details, just to give you some options to try.&lt;br /&gt;
Please note: &lt;b&gt;&lt;i&gt;there is no magic that can fix a crappy query&lt;/i&gt;&lt;/b&gt;, so the first step&lt;br /&gt;
you should take is to check if you can rewrite the query.&lt;br /&gt;
&lt;br /&gt;
1) Search for &lt;b&gt;&lt;u&gt;Non-SARGable filters&lt;/u&gt;&amp;nbsp;&lt;/b&gt;that prevent usage of existing index(es)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Like &lt;span style=&quot;color: magenta;&quot;&gt;&lt;b&gt;COLLATE &lt;/b&gt;&lt;/span&gt;function, &lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;DATE/STRING/ISNULL&lt;/b&gt;&lt;/span&gt;&lt;/span&gt; functions on table columns&lt;br /&gt;
&amp;nbsp; &amp;nbsp; or using &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;LIKE &lt;/b&gt;&lt;/span&gt;‘&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;%&lt;/span&gt;&lt;/b&gt;SearchString’&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
2) Check &lt;b&gt;&lt;u&gt;Estimated vs Actual&lt;/u&gt; &lt;/b&gt;number of rows&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Search for a big difference between the actual and estimated number of rows.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Your goal is to have the same number of actual and estimated rows as much as possible.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Possible reasons for mismatch: usage of table variables and/or local variables,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; parameter sniffing, not indexed fields, not updated statistics, non-SARGable filters,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; implicit conversion.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
3) Look for&amp;nbsp;&lt;b&gt;&lt;u&gt;thick data arrows&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; They indicate a high number of data/rows passing from an operator to an operator.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Search for table/index scans, see if adding an index on filtered/joined fields can help.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;o:p&gt;4)&amp;nbsp;&lt;/o:p&gt;See if there is &lt;b&gt;&lt;u&gt;Index Seek with Residual Predicate&lt;/u&gt;&lt;/b&gt; (Seek predicate vs Predicate)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; When you have an index seek operator with a predicate (not “seek predicate”), &lt;br /&gt;
&amp;nbsp; &amp;nbsp; it means the filtering is done after the seek operation.&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; Compare “Number of Rows Read” vs “Actual Number of Rows”.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Also, you can use &lt;span style=&quot;color: blue;&quot;&gt;OPTION &lt;/span&gt;(QUERYTRACEON 9130)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; It will add a “Filter” operator to the execution plan after index seek operator.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
5) Search for &lt;u&gt;&lt;b&gt;Spool operators&lt;/b&gt; &lt;/u&gt;like Eager/Lazy/Table spools&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Spools used to save intermediate results for later reuse in TempDB.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; They are hidden tables in the TempDB and they are often caused by&lt;br /&gt;
&amp;nbsp; &amp;nbsp; a lack of information about the uniqueness of data.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; What can help is to create PK/Unique Key for involved tables/inner results.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Try to add DISTINCT to involved tables/inner queries.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; And of course, see if adding an index or saving intermediate&lt;br /&gt;
&amp;nbsp; &amp;nbsp; results to a temp table helps.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Try to break a big query to small parts,&amp;nbsp;use «divide et impera» method&lt;br /&gt;
&amp;nbsp; &amp;nbsp; (Divide and rule, or divide and conquer strategy)&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;You can run the query with &lt;span style=&quot;font-size: x-small;&quot;&gt;&quot;&lt;span style=&quot;color: blue;&quot;&gt;OPTION &lt;/span&gt;(QUERYTRACEON 8690)&quot;&amp;nbsp;&lt;/span&gt;to test how&lt;br /&gt;
&amp;nbsp; &amp;nbsp; the query will run without the spool. This option disables the usage of Spools.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
6) Search for “&lt;b&gt;&lt;u&gt;Implicit conversion&lt;/u&gt;&lt;/b&gt;” warnings&lt;br /&gt;
&amp;nbsp; &amp;nbsp; They may prevent index usage and proper rows estimation/cardinality.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
7)&amp;nbsp;See if &lt;b&gt;&lt;u&gt;UDFs (scalar/table-valued functions)&lt;/u&gt;&lt;/b&gt; are used &lt;br /&gt;
&amp;nbsp; &amp;nbsp; You can easily spot them checking the “Estimated” execution plan&lt;br /&gt;
&amp;nbsp; &amp;nbsp; or you can find UDF execution times in the actual execution plan&lt;br /&gt;
&amp;nbsp; &amp;nbsp; See UdfElapsedTime/UdfCpuTime.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Try to rewrite the query, inline the UDF logic directly into the query.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
8) If you use a CTE, see if you reference the &lt;b&gt;&lt;u&gt;CTE multiple times&lt;/u&gt;&lt;/b&gt;.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; CTE is not materialized and it will access all tables involved in CTE&lt;br /&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; each time you reference the CTE.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
9) &lt;b&gt;&lt;u&gt;Parallelism &lt;/u&gt;&lt;/b&gt;– Check if the query uses Parallelism&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Usage of UDFs and table variable modifications can force the query to&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; be executed in a serial way.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; 1.       Try to execute the query with Parallelism &lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;OPTION(USE &lt;/span&gt;HINT(&#39;&lt;span style=&quot;color: red;&quot;&gt;ENABLE_PARALLEL_PLAN_PREFERENCE&#39;&lt;/span&gt;)) &lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; 2.       Try to execute the query in a serial way, &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; See if there is a difference &lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;OPTION(MAXDOP&lt;/span&gt; 1)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
10)&amp;nbsp;&lt;b&gt;&lt;u&gt;Legacy vs New Cardinality Estimator (CE)&lt;/u&gt;&lt;/b&gt; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If you have multiple predicates and JOINs to other tables/views&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;it is worth to see if there is a difference between Legacy Cardinality Estimator (CE)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;and &lt;a href=&quot;https://madebysql.blogspot.com/2020/05/how-sql-server-optimizer-calculates.html&quot; target=&quot;_blank&quot;&gt;New Cardinality Estimator (CE)&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;OPTION&lt;/span&gt;(QUERYTRACEON 9481) &lt;span style=&quot;color: #38761d;&quot;&gt;-– Legacy CE&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;OPTION&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(QUERYTRACEON 2312)&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;-–&amp;nbsp; New CE&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: lime;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;o:p&gt;&amp;nbsp;11)&amp;nbsp;&lt;/o:p&gt;&lt;b&gt;&lt;u&gt;Compatibility Level&amp;nbsp;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Try to execute the query with lower or higher compatibility level

&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 0.5in; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;OPTION
&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;USE&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;;&quot;&gt; HINT&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;&#39;QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_110&#39;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: xx-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: xx-small;&quot;&gt;-- SQL 2012&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: xx-small;&quot;&gt;--&amp;gt; OLD CE&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;OPTION&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;USE&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;&amp;nbsp;HINT&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;&#39;QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_120&#39;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: xx-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: xx-small;&quot;&gt;-- SQL 2014 --&amp;gt; New CE&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;OPTION&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;USE&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;&amp;nbsp;HINT&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;&#39;QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_130&#39;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: xx-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: xx-small;&quot;&gt;-- SQL 2016&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;OPTION&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;USE&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;&amp;nbsp;HINT&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;&#39;QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_140&#39;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: xx-small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: xx-small;&quot;&gt;-- SQL 2017&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 0.5in; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 0.5in; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;OPTION
&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;USE&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt; HINT&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;&#39;QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_150&#39;&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;;&quot;&gt;)) -- SQL 2019&lt;/span&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 0.5in; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
12)&amp;nbsp;&lt;b&gt;&lt;u&gt;Trace Flag 4199 &lt;/u&gt;(Enable Optimizer Fixes) &lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Try to execute the query with&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;OPTION&lt;/span&gt;(QUERYTRACEON 4199)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; It will instruct SQL Server to enable query optimizer fixes that are disabled by default.&lt;br /&gt;
&lt;br /&gt;
13) &lt;b&gt;&lt;u&gt;Batch Mode vs Row Mode&lt;/u&gt;&lt;/b&gt; processing &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; If the query processes many rows, &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; It is worth to see if Batch Mode will be helpful. &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; To enable Batch Mode on a Rowstore table you can try one of the following: &lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Create an empty  temp table with columnstore clustered index &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; and add to the query LEFT JOIN to the temp table&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 56.25pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;TABLE&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; #tmp&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;id &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;INDEX&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; Tmp_id &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;CLUSTERED&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;COLUMNSTORE&lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 56.25pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;....&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div style=&quot;margin-left: 56.25pt;&quot;&gt;
&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;LEFT&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; #tmp &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; 1 &lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; 0&lt;/span&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;    Create a dummy filtered ColumnStore index on the existing table involved &lt;br /&gt;in the query, something like:&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;CREATE NONCLUSTERED COLUMNSTORE INDEX&lt;/span&gt; ix_dummy_nc ON dbo.tablename(Col1) &lt;span style=&quot;color: blue;&quot;&gt;WHERE &lt;/span&gt;col1 = -1&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
14) &lt;u&gt;&lt;b&gt;Parameter Sniffing&lt;/b&gt;, &lt;b&gt;Table Variables&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Stored procedures with input parameters and&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;sp_executesql&lt;/span&gt; with parameters&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; will sniff the values of the parameters at the first execution&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; and use the statistics histogram and build the execution plan according to it.&lt;/div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Try &lt;span style=&quot;color: blue; font-size: x-small;&quot;&gt;OPTION(RECOMPILE)&lt;/span&gt;, if you have parameters and/or table variables in the query&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; or use other known&amp;nbsp;techniques to handle parameter sniffing issues.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
15)&lt;b&gt; &lt;u&gt;Order of JOINS, Reduce estimated number of rows, Increase estimated number of rows&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; See if existing order of joins in the execution plan makes sense, &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; If not, you can control it by using &lt;a href=&quot;http://madebysql.blogspot.com/2019/10/control-join-order-of-tables.html&quot; target=&quot;_blank&quot;&gt;ROW GOALS&lt;/a&gt;, &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Add &lt;span style=&quot;color: blue;&quot;&gt;TOP &lt;/span&gt;(2147483648) to CTE or inner queries that you want them to be executed first.&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; To reduce the number of estimated rows, try &lt;span style=&quot;color: #2b00fe;&quot;&gt;using top(@i)&amp;nbsp; with option(optimize for @i=1)&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; To increase the number of estimated rows, try using Adam Machanic &lt;span style=&quot;color: #2b00fe;&quot;&gt;dbo.Many&lt;/span&gt; function&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
16)&lt;b&gt;&amp;nbsp;&lt;u&gt;Filtered Statistics &lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; With 200 steps, the statistics can be inaccurate, especially when you have skew data.&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; When you have joins to lookup tables or when you join fact to dimension tables &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Filtered statistics can help to improve the cardinality estimation.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; In SPs you might add &lt;span style=&quot;color: blue;&quot;&gt;option(recompile),&lt;/span&gt; so the optimizer will pickup &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; the filtered statistics.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; You can see the statistics that have been used in the actual execution plan.&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;o:p&gt;&amp;nbsp;17)&amp;nbsp;&lt;/o:p&gt;&lt;b&gt;&lt;u&gt;SET OPTIONS&lt;/u&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Compare application connection settings with SSMS connection settings.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; For example, check if your application connects with &lt;span style=&quot;color: blue;&quot;&gt;ARITHABORT &lt;/span&gt;OFF.&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; and other set options like&amp;nbsp;&lt;span style=&quot;font-size: x-small;&quot;&gt;SET ANSI_NULLS, SET ANSI_PADDING.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; By default, ADO.NET sets arithabort to false and SSMS to true.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;o:p&gt;&amp;nbsp;18)&amp;nbsp;&lt;/o:p&gt;&lt;b&gt;&lt;u&gt;Views (Nested Views)&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;How to optimize views? Or how to optimize queries that use Views?&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If your query uses view(s) or nested view(s), you may have a problem&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;with predicates/filters push down.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;In case you have queries that use views and these queries cannot be changed,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;meaning the views objects cannot be dropped and your only option is to &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;change the view definition, you can try to use Table-valued functions(TVF).&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;The TVFs can push down the filters and as the result allow the optimizer to build&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a more optimal execution plan.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;For example, you have a view named vw_MyView,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;you can create TVF with the code of the vw_MyView and change the view definition&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;to do SELECT from the newly created TVF.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Another option is to use Row Goals (TOP Clauses) in the view/TVF to control&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;the execution order of subqueries/CTEs.&lt;br /&gt;
&lt;br /&gt;
19)&lt;u&gt;&amp;nbsp;&lt;b&gt;Compare Duration and CPU Duration &lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Duration(query time overall) is the total time including SQL Server CPU, &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; network and an application getting the data. &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; If you see a big difference between them&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; (e.g: CPU is much less than the query duration) &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; It can indicate blocking or network issues &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; or the way how the application consumes the data&lt;span style=&quot;font-size: x-small;&quot;&gt;(RBAR: Row By Agonizing Row)&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;b&gt;&amp;nbsp;20) &lt;u&gt;HASH - Join Hint&lt;/u&gt;&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If there are many rows processed and NESTED LOOP is used and it is not&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reasonable to you, and you cannot find a way how to make the estimation&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;to be more accurate, try to add HASH join hint,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;like INNER &lt;span style=&quot;color: blue;&quot;&gt;HASH &lt;/span&gt;JOIN dbo.table&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
21) &lt;b&gt;&lt;u&gt;IN / OR Clauses&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; 1. If you have &lt;span style=&quot;color: blue;&quot;&gt;IN &lt;/span&gt;(Value1,Value2) clause in the query or you have &lt;span style=&quot;color: blue;&quot;&gt;OR&lt;/span&gt; filter&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Try to rewrite the &lt;span style=&quot;color: blue;&quot;&gt;IN &lt;/span&gt;(Value1,Value2) to &lt;span style=&quot;color: blue;&quot;&gt;UNION&lt;/span&gt;.&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Same with OR filters.&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; It may help the optimizer to build a more correct execution plan&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and use individual index seeks.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;2. If you have something like&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;IN (SELECT&lt;/span&gt; Col &lt;span style=&quot;color: blue;&quot;&gt;FROM &lt;/span&gt;@Tbl)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Try to convert the &lt;span style=&quot;color: blue;&quot;&gt;IN&lt;/span&gt; to &lt;span style=&quot;color: blue;&quot;&gt;INNER JOIN,&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;especially when you have a high number of rows in @Tbl&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
22) &lt;b&gt;&lt;u&gt;Small hints/tricks&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1) To remove spilling to TempDB of a sort operator,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;you can add&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;OPTION&lt;/span&gt;(min_grant_percent = 1)&lt;/div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SQL Server will grant&amp;nbsp; memory to the query in the following way:&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(Maximum SQL Server memory * 90%) * 25% * (min_grant_percent value)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;2) If you have windows function with OVER clause&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Try to use &lt;span style=&quot;color: blue;&quot;&gt;ROWS UNBOUNDED PRECEDING&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; it will do the work in memory.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3)&amp;nbsp; To check existence, try to use &lt;span style=&quot;color: blue;&quot;&gt;NOT EXISTS&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;instead of&lt;span style=&quot;color: blue;&quot;&gt; LEFT JOIN. &lt;/span&gt;In most cases, it will perform better by&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;stopping at first existing value.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;COUNT_BIG&lt;/span&gt;(u.Id) &lt;span style=&quot;color: blue;&quot;&gt;AS &lt;/span&gt;records&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;FROM&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;dbo.Users AS u&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;WHERE &lt;/span&gt;NOT EXISTS ( &lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;1/0 &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;FROM&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;dbo.Posts AS p &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;WHERE &lt;/span&gt;p.OwnerUserId = u.Id )&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4)  &lt;b&gt;ISNULL vs COALESCE&lt;/b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;If you use &lt;span style=&quot;color: blue;&quot;&gt;ISNULL/&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;COALESCE&lt;/span&gt;&amp;nbsp;on the filtered column,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;like &lt;span style=&quot;color: blue;&quot;&gt;WHERE ISNULL&lt;/span&gt;(Column,10) = 10&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;or&amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;W&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;HERE&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;COALESCE&lt;/span&gt;(Column,10) = 10&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;and the column in a table is &lt;u&gt;not &lt;/u&gt;null-able, then use &lt;span style=&quot;color: blue;&quot;&gt;ISNULL&lt;/span&gt;,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;because&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;ISNULL&lt;/span&gt; can detect that the column in the table is not null-able&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;and as a result can use index seek.&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;COALESCE &lt;/span&gt;will do an index scan.&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;/div&gt;
23)&amp;nbsp;&lt;b&gt;As the last resort &lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; Try to execute the query with various query hints&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: grey; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;sys&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;dm_exec_valid_use_hints&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-left: 0.5in; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;&quot;&gt;
&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: lime; font-family: &amp;quot;consolas&amp;quot;; font-size: 9.5pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;b&gt;Note: You must be very careful with the hints, &lt;br /&gt;you may hurt the performance if you&amp;nbsp;&lt;/b&gt;&lt;b&gt;do not understand how it works &lt;br /&gt;and you are not taking into account your data, workload,&lt;/b&gt;&lt;br /&gt;
&lt;div&gt;
&lt;b&gt;production environment.&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/6850518998013365699/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2020/04/a-practical-sql-query-performance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/6850518998013365699'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/6850518998013365699'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2020/04/a-practical-sql-query-performance.html' title='A practical SQL query performance tuning checklist (23 Steps)'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpkjldIXLRVsxi06I_irV6Pm_crWSQMcc7Chd28KwNp-jzycAmxcLE18TJkZts3kDRs2L1rWrB7mQvHhn38629bIg_S3NoXoTJ8mJsDB0k7u0CmxyBHBJ64vNszkqvGZqOSSkeEGKEv6o/s72-c/SQL+Query+Performance.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-3396811933212314378</id><published>2020-02-17T15:45:00.000-08:00</published><updated>2020-02-17T15:45:13.399-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Cursors"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Performance"/><title type='text'>Interesting SQL Server Cursors locking observation</title><content type='html'>If you are using SQL Server cursors,&lt;br /&gt;you should be aware of the following locking behavior of a cursor.&amp;nbsp;&lt;div&gt;
&lt;br /&gt;Lets take a simple example of a cursor in SQL Server, &lt;br /&gt;we will use the cursor just to iterate through rows in a table. &lt;br /&gt;&lt;br /&gt;&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;DECLARE &lt;/span&gt;@CustomerID &lt;span style=&quot;color: blue;&quot;&gt;INT&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;DECLARE &lt;/span&gt;Customers_Cursor &lt;span style=&quot;color: blue;&quot;&gt;CURSOR FOR&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;CustomerID&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;dbo.Customers&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;OPEN &lt;/span&gt;Account_Cursor&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;FETCH NEXT FROM &lt;/span&gt;Customers_Cursor &lt;span style=&quot;color: blue;&quot;&gt;INTO &lt;/span&gt;@CustomerID&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;WHILE &lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;@@FETCH_STATUS&lt;/span&gt; = 0&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: x-small;&quot;&gt;BEGIN&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;@CustomerID&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;FETCH NEXT FROM&lt;/span&gt; Customers_Cursor &lt;span style=&quot;color: blue;&quot;&gt;INTO &lt;/span&gt;@CustomerID&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: x-small;&quot;&gt;END&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;CLOSE &lt;/span&gt;Customers_Cursor&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;DEALLOCATE &lt;/span&gt;Customers_Cursor&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;What we want to check is what locks are acquired and how many times. &lt;br /&gt;Let`s assume that the “Customers” table has PK on CustomerID column.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;If you set an extended events session that captures  “lock_acquired” &lt;br /&gt;and “lock_released“ events, you will see that&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;b&gt;For the same key/row, Shared Lock acquired and released &lt;u&gt;twice&lt;/u&gt;: &lt;br /&gt;The first time upon OPEN statement&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;and the second time upon FETCH statement. &lt;/b&gt;&lt;br /&gt;&lt;br /&gt;So if you have deadlocks involving cursors and shared locks,&lt;br /&gt;keep this behavior in mind. &lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
If all you want  to do is just to iterate through the rows &lt;br /&gt;without jumping back and forward &lt;br /&gt;and without updating rows in the cursor`s table&lt;br /&gt;You can use FAST FORWARD cursor type. &lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;DECLARE &lt;/span&gt;Customers_Cursor &lt;span style=&quot;color: blue;&quot;&gt;CURSOR FAST_FORWARD FOR&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/3396811933212314378/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2020/02/interesting-sql-server-cursors-locking.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/3396811933212314378'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/3396811933212314378'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2020/02/interesting-sql-server-cursors-locking.html' title='Interesting SQL Server Cursors locking observation'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-4411685054439966770</id><published>2020-01-13T13:56:00.002-08:00</published><updated>2020-04-21T13:51:15.362-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="MDS.MDM"/><title type='text'>&quot;The number is not valid&quot; error - SQL Server 2019 Master Data Services (MDM 2019 Web UI)</title><content type='html'>In Master Data Services/MDM 2019 version &lt;br /&gt;
You cannot filter on a Number type attribute &lt;br /&gt;
within an Entity view on the MDM web interface &lt;br /&gt;
&lt;br /&gt;
You will get &lt;span style=&quot;color: red;&quot;&gt;&quot;The number is not valid.&quot;&lt;/span&gt; error message in red &lt;br /&gt;
Once you have selected an attribute filter that has Numeric data type. &lt;br /&gt;
You can type a value in the Criteria box, but the “Apply” button &lt;br /&gt;
Is not clickable.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4al9UjHpkE4ZSvLbPkjjsun2FDmp26rmFbRilA3jHDDqSc5T2ROrW2KqaKREreSSVeEt5farJAwsemKzzDX-HbizMcgavkwACEwXxWaYNjz3sLVx_xYh1MQpahEmvlx5ZZM-2-Z1fe2M/s1600/Unable+to+filter+on+a+Number+Type+Attribute+within+an+Entity+view+on+the+MDM+web+interface.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;73&quot; data-original-width=&quot;638&quot; height=&quot;45&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4al9UjHpkE4ZSvLbPkjjsun2FDmp26rmFbRilA3jHDDqSc5T2ROrW2KqaKREreSSVeEt5farJAwsemKzzDX-HbizMcgavkwACEwXxWaYNjz3sLVx_xYh1MQpahEmvlx5ZZM-2-Z1fe2M/s400/Unable+to+filter+on+a+Number+Type+Attribute+within+an+Entity+view+on+the+MDM+web+interface.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;If you press F12 in Chrome and enter a numeric value in the&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
Criteria text box and press tab, you will see the exception below:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div&gt;
KoFilterView.js:459 &lt;span style=&quot;color: red;&quot;&gt;Uncaught ReferenceError: isInteger is not defined&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; at filterLine.checkValue (&lt;/span&gt;KoFilterView.js:459)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;at dbaPicker.self.onfocusout &lt;/span&gt;(KoDbaPicker.js:555)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;at HTMLInputElement.&lt;/span&gt;&lt;anonymous&gt; (knockout.js:79)&lt;/anonymous&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;at HTMLInputElement.dispatch &lt;/span&gt;(jquery.js:4409)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;at HTMLInputElement.elemData.handle&lt;/span&gt; (jquery.js:4095)&lt;/div&gt;
&lt;div&gt;
filterLine.checkValue @ &lt;span style=&quot;color: blue;&quot;&gt;KoFilterView.js:459&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
self.onfocusout @ &lt;span style=&quot;color: blue;&quot;&gt;KoDbaPicker.js:555&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
(anonymous) @ &lt;span style=&quot;color: blue;&quot;&gt;knockout.js:79&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
dispatch @ &lt;span style=&quot;color: blue;&quot;&gt;jquery.js:4409&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
elemData.handle @ &lt;span style=&quot;color: blue;&quot;&gt;jquery.js:4095&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
To overcome this issue you can edit the file below &lt;br /&gt;
&lt;b&gt;...\Master Data Services\Web Application\Scripts\UserControls\KoFilterView.js &lt;/b&gt;&lt;br /&gt;
Replace &lt;br /&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (isInteger(value - 0)) {&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
with &lt;br /&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;&amp;nbsp;if (Number.isInteger(value - 0)) { &lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #666666;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
afterward, clear the browser cache.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;The fix &lt;/b&gt;&lt;b&gt;works only for Chrome and doesn&#39;t work in Internet Explorer&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
In my case, you will still see the red error message &lt;br /&gt;
but the “Apply” button will become clickable and you will be able &lt;br /&gt;
to filter on numeric values.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Enjoy :)&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/4411685054439966770/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2020/01/the-number-is-not-valid-error-sql.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/4411685054439966770'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/4411685054439966770'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2020/01/the-number-is-not-valid-error-sql.html' title='&quot;The number is not valid&quot; error - SQL Server 2019 Master Data Services (MDM 2019 Web UI)'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4al9UjHpkE4ZSvLbPkjjsun2FDmp26rmFbRilA3jHDDqSc5T2ROrW2KqaKREreSSVeEt5farJAwsemKzzDX-HbizMcgavkwACEwXxWaYNjz3sLVx_xYh1MQpahEmvlx5ZZM-2-Z1fe2M/s72-c/Unable+to+filter+on+a+Number+Type+Attribute+within+an+Entity+view+on+the+MDM+web+interface.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-8504675289126437276</id><published>2020-01-09T16:38:00.001-08:00</published><updated>2020-04-21T13:51:41.247-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Tips"/><title type='text'>How to check progress / estimated percentage done for a SELECT query / statement in SQL Server</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtL0lUQPIAoK4At-5BdUQfpuyj4DoS9UCxdyOZq9aedihpnhF_wOoKSljEgnKSraniBHtEMCJe7EjrAM-7C8wONMTi686rNmVFVSii40FV8L94OpxHgx2FEO6aoWJt6f7A63ZJVJ_VQMU/s1600/Select+percentage+complete.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;292&quot; data-original-width=&quot;560&quot; height=&quot;103&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtL0lUQPIAoK4At-5BdUQfpuyj4DoS9UCxdyOZq9aedihpnhF_wOoKSljEgnKSraniBHtEMCJe7EjrAM-7C8wONMTi686rNmVFVSii40FV8L94OpxHgx2FEO6aoWJt6f7A63ZJVJ_VQMU/s200/Select+percentage+complete.jpg&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Assuming you have a long-running SELECT statement&lt;br /&gt;
or SELECT query and you want to see its progress,&lt;br /&gt;
like how many percents already done&lt;br /&gt;
(percentage done/the percentage of work completed&lt;br /&gt;
/Progress (% Complete)).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;Is there a way to see the progress of a SELECT statement&lt;br /&gt;
in SQL Server? &lt;br /&gt;
&lt;br /&gt;
I will say it again, we are talking about a SELECT query and &lt;b&gt;not &lt;/b&gt;operations that &lt;br /&gt;
populate the “percent_complete” field in sys.dm_exec_requests &lt;br /&gt;
&lt;br /&gt;
Like below: &lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;ALTER INDEX REORGANIZE&lt;br /&gt; AUTO_SHRINK option with ALTER DATABASE&lt;br /&gt; BACKUP DATABASE&lt;br /&gt; DBCC CHECKDB&lt;br /&gt; DBCC CHECKFILEGROUP&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;
DBCC CHECKTABLE&lt;br /&gt; DBCC INDEXDEFRAG&lt;br /&gt; DBCC SHRINKDATABASE&lt;br /&gt; DBCC SHRINKFILE&lt;br /&gt; RECOVERY&lt;br /&gt; RESTORE DATABASE&lt;br /&gt; ROLLBACK&lt;br /&gt; TDE ENCRYPTION &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Well, there is a way (with some limitations, of course:)). &lt;br /&gt;
it is not perfect, but it will definitely give you some visibility. &lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
The approach is to compare the estimate row counts &lt;br /&gt;
vs the actual row counts for each node in the execution plan. &lt;br /&gt;
&lt;br /&gt;
It will not work accurately in case you have an incorrect estimated number of rows &lt;br /&gt;
Also if there are some lock waits (blocking), they will break the calculations. &lt;br /&gt;
&lt;br /&gt;
To use this query/approach you need to be on SQL Server 2019 (15.x) &lt;br /&gt;
Or to enable trace flag 7412 (lightweight profiling) starting from SQL 2016 (13.x) SP1 &lt;br /&gt;
This trace flag will tell SQL Server to expose additional information &lt;br /&gt;
For each node in the execution plan, like how many rows already processed. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note&lt;/b&gt;: Lightweight profiling is enabled by default in SQL Server 2019 (15.x) &lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;er.session_id,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;er.start_time,&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;DATEDIFF&lt;/span&gt;(ms,er.start_time,GETDATE()) AS elapsed_time_ms,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;DATEDIFF&lt;/span&gt;(ss,er.start_time,GETDATE()) AS elapsed_time_Sec,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;er.wait_type, er.wait_time,&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;SUBSTRING&lt;/span&gt;(st.TEXT, (er.statement_start_offset / 2) + 1,((CASE er.statement_end_offset&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;WHEN -1 THEN &lt;span style=&quot;color: magenta;&quot;&gt;DATALENGTH&lt;/span&gt;(st.TEXT) ELSE er.statement_end_offset END - er.statement_start_offset) / 2) + 1) AS statement_text,&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;CONVERT&lt;/span&gt;(XML, qp.query_plan) query_plan,&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;CASE WHEN &lt;/span&gt;sum(eqp.estimate_row_count) &amp;gt; 0 &lt;span style=&quot;color: blue;&quot;&gt;THEN &lt;/span&gt;100 * SUM(eqp.row_count) / &lt;span style=&quot;color: magenta;&quot;&gt;SUM&lt;/span&gt;(eqp.estimate_row_count) ELSE NULL END AS percent_done&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;sys.dm_exec_requests&lt;/span&gt; er&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;INNER JOIN&lt;/span&gt; &lt;span style=&quot;color: #6aa84f;&quot;&gt;sys.dm_exec_query_profiles&lt;/span&gt; eqp ON er.session_id = eqp.session_id AND er.request_id = eqp.request_id&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;CROSS APPLY&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt; sys.dm_exec_sql_text&lt;/span&gt;(er.sql_handle) st&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;CROSS APPLY&lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt; sys.dm_exec_text_query_plan&lt;/span&gt;(er.plan_handle, er.statement_start_offset, er.statement_end_offset) qp&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;WHERE&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;er.session_id &amp;gt; 50&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;AND &lt;/span&gt;er.session_id != &lt;span style=&quot;color: magenta;&quot;&gt;@@spid&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;GROUP BY&lt;/span&gt; er.start_time, er.session_id, er.wait_type, er.wait_time, st.TEXT, er.statement_start_offset, er.statement_end_offset, qp.query_plan&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;HAVING &lt;/span&gt;&lt;span style=&quot;color: magenta;&quot;&gt;SUM&lt;/span&gt;(eqp.estimate_row_count) &amp;gt; 0&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
Try it 😊 &lt;br /&gt;
Of course, it works also for SELECT statements with multiple JOINs.&lt;br /&gt;
&lt;br /&gt;
Source:&lt;br /&gt;
&lt;a href=&quot;http://blog.sqlgrease.com/how-to-view-percent-done-of-a-long-executing-query/?unapproved=27776&amp;amp;moderation-hash=d582e3993f3b1f9ed5a1e1c3dc012222#comment-27776&quot;&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;http://blog.sqlgrease.com/how-to-view-percent-done-of-a-long-executing-query/?unapproved=27776&amp;amp;moderation-hash=d582e3993f3b1f9ed5a1e1c3dc012222#comment-27776&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/8504675289126437276/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2020/01/how-to-check-progress-estimated.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/8504675289126437276'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/8504675289126437276'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2020/01/how-to-check-progress-estimated.html' title='How to check progress / estimated percentage done for a SELECT query / statement in SQL Server'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtL0lUQPIAoK4At-5BdUQfpuyj4DoS9UCxdyOZq9aedihpnhF_wOoKSljEgnKSraniBHtEMCJe7EjrAM-7C8wONMTi686rNmVFVSii40FV8L94OpxHgx2FEO6aoWJt6f7A63ZJVJ_VQMU/s72-c/Select+percentage+complete.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-1311509272051933239</id><published>2020-01-03T10:15:00.002-08:00</published><updated>2020-04-21T13:52:15.936-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="MDS.MDM"/><title type='text'>Cannot create a business rule in MDM (Master Data Services) 2019</title><content type='html'>If you have upgraded your MDM(Master Data Services)&lt;br /&gt;
to SQL Server 2019 with compatibility level 150,&lt;br /&gt;
For example from version 2017.&lt;br /&gt;
and you have user-defined scripts(functions / stored procedures) that you use,&lt;br /&gt;
most probably you will not be able to add a new business rule via the MDM website.&lt;br /&gt;
&lt;br /&gt;
In my case, I get disabled dropdowns as below without any errors in UI,&lt;br /&gt;
The &quot;Attribute&quot; drop-down is not accessible and completely disabled&lt;br /&gt;
and the &quot;Operator&quot; drop-down is empty:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglB7cFw2POYhy31leBq3-4b6UY2OdPr0F3U-SS4lpXSGV_0fQznFS8aEozNGgXEGpXGZDLR-mX8VH-uo1ShUEgs2vGIWXe3h39hDiYcReeaODZaoafUZXd7ULey2lGaUc5WK_5AILWmek/s1600/MDM+Business+rule+disabled+dropdowns.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;664&quot; data-original-width=&quot;790&quot; height=&quot;335&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglB7cFw2POYhy31leBq3-4b6UY2OdPr0F3U-SS4lpXSGV_0fQznFS8aEozNGgXEGpXGZDLR-mX8VH-uo1ShUEgs2vGIWXe3h39hDiYcReeaODZaoafUZXd7ULey2lGaUc5WK_5AILWmek/s400/MDM+Business+rule+disabled+dropdowns.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;The reason for this is bugs in the SQL Server 2019,&lt;br /&gt;
&lt;a href=&quot;http://madebysql.blogspot.com/2020/01/sql-server-2019-function-and-error.html?_sm_au_=iVVMZMvWvZWMtWqP2HMVvK3Lvc364&quot; target=&quot;_blank&quot;&gt;see my post&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
A quick solution will be to switch back to compatibility level 140 or lower&lt;br /&gt;
or to adjust the &lt;b&gt;[mdm].[udfScriptExists] &lt;/b&gt;function not to return the error&lt;br /&gt;
&lt;i style=&quot;background-color: white; color: red; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14.85px;&quot;&gt;&lt;br /&gt;&lt;/i&gt;
&lt;i style=&quot;background-color: white; color: red; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14.85px;&quot;&gt;Subquery returned more than 1 value.&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i style=&quot;background-color: white; color: red; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14.85px;&quot;&gt;This is not permitted when the subquery follows =, !=, &amp;lt;, &amp;lt;= , &amp;gt;, &amp;gt;=&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i style=&quot;background-color: white; color: red; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14.85px;&quot;&gt;or when the subquery is used as an expression.&lt;/i&gt;&lt;br /&gt;
&lt;i style=&quot;background-color: white; color: red; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 14.85px;&quot;&gt;&lt;br /&gt;&lt;/i&gt;
&lt;a href=&quot;http://madebysql.blogspot.com/2020/01/sql-server-2019-function-and-error.html?_sm_au_=iVVMZMvWvZWMtWqP2HMVvK3Lvc364&quot; target=&quot;_blank&quot;&gt;See my post on how to.&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
The issue is the following code in the&amp;nbsp;&lt;b&gt;[mdm].[udfScriptExists]&amp;nbsp;&lt;/b&gt;&amp;nbsp;function&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;@Result = 0&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;FROM &lt;/span&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;sys.parameters&amp;nbsp; &amp;nbsp;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;WHERE &lt;/span&gt;object_id = @ScriptObjectId&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AND ((is_output = 1 AND user_type_id &amp;lt;&amp;gt; TYPE_ID(&#39;bit&#39;))&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; OR (is_output = 0 AND&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ( user_type_id NOT IN (TYPE_ID(&#39;nvarchar&#39;),TYPE_ID(&#39;datetime2&#39;), TYPE_ID(&#39;decimal&#39;)) -&lt;span style=&quot;color: #6aa84f;&quot;&gt;- ONLY SUPPORT TYPE NVARCHAR, DATETIME2, AND DECIMAL&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; OR (user_type_id = TYPE_ID(&#39;decimal&#39;) AND ([precision] &amp;lt;&amp;gt;38 OR scale&amp;gt;7)))))&amp;nbsp; &lt;span style=&quot;color: #6aa84f;&quot;&gt;-- IF TYPE IS DECIMAL, PRECISION SHOULD BE 38 WHICH IS THE DEFAULT ONE ,AND SCALE SHOULD BE IN THE ARRANGE OF 0 TO 7&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #6aa84f;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;@Result = 0  &lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;FROM &lt;/span&gt;sys.parameters &lt;span style=&quot;color: blue;&quot;&gt;WHERE &lt;/span&gt;object_id = @ScriptObjectId  &lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;AND&lt;/span&gt; (&lt;br /&gt;(parameter_id = 1 AND (TYPE_NAME(user_type_id) &amp;lt;&amp;gt; &#39;MemberId&#39; OR name &amp;lt;&amp;gt;N&#39;@MemberIdList&#39; COLLATE DATABASE_DEFAULT))  &lt;br /&gt;OR(parameter_id = 2 AND (TYPE_NAME(user_type_id) &amp;lt;&amp;gt;&#39;nvarchar&#39; OR max_length &amp;lt;&amp;gt; -1 OR name &amp;lt;&amp;gt;N&#39;@ModelName&#39; COLLATE DATABASE_DEFAULT))&lt;br /&gt;OR(parameter_id = 3 AND (TYPE_NAME(user_type_id) &amp;lt;&amp;gt;&#39;nvarchar&#39; OR max_length &amp;lt;&amp;gt; -1 OR name &amp;lt;&amp;gt;N&#39;@VersionName&#39; COLLATE DATABASE_DEFAULT))&lt;br /&gt;OR(parameter_id = 4 AND (TYPE_NAME(user_type_id) &amp;lt;&amp;gt;&#39;nvarchar&#39; OR max_length &amp;lt;&amp;gt; -1 OR name &amp;lt;&amp;gt;N&#39;@EntityName&#39; COLLATE DATABASE_DEFAULT))&lt;br /&gt;OR(parameter_id = 5 AND (TYPE_NAME(user_type_id) &amp;lt;&amp;gt;&#39;nvarchar&#39; OR max_length &amp;lt;&amp;gt; -1 OR name &amp;lt;&amp;gt;N&#39;@BusinessRuleName&#39; COLLATE DATABASE_DEFAULT))&lt;br /&gt;)   &lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/1311509272051933239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2020/01/cannot-create-business-rule-in-mdm-2019.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/1311509272051933239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/1311509272051933239'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2020/01/cannot-create-business-rule-in-mdm-2019.html' title='Cannot create a business rule in MDM (Master Data Services) 2019'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglB7cFw2POYhy31leBq3-4b6UY2OdPr0F3U-SS4lpXSGV_0fQznFS8aEozNGgXEGpXGZDLR-mX8VH-uo1ShUEgs2vGIWXe3h39hDiYcReeaODZaoafUZXd7ULey2lGaUc5WK_5AILWmek/s72-c/MDM+Business+rule+disabled+dropdowns.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-2303315656712983324</id><published>2020-01-03T09:42:00.000-08:00</published><updated>2020-01-03T09:42:28.570-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2019"/><title type='text'>SQL Server 2019, a function and the error “Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, &lt;, &lt;= , &gt;, &gt;= or when the subquery is used as an expression.”</title><content type='html'>&lt;br /&gt;I have encountered additional errors in SQL Server 2019. &lt;br /&gt;Consider a function with following code: &lt;br /&gt;  &lt;br /&gt;&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;CREATE OR ALTER FUNCTION&lt;/span&gt; dbo.fn_Test()&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;RETURNS INT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;AS&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;BEGIN&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; DECLARE&lt;/span&gt; @Result &lt;span style=&quot;color: blue;&quot;&gt;INT &lt;/span&gt;= 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;SELECT&amp;nbsp; &lt;/span&gt;@Result = 0&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;FROM&amp;nbsp; &amp;nbsp; &lt;/span&gt;(&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;1 &lt;span style=&quot;color: blue;&quot;&gt;as &lt;/span&gt;abc&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt; UNION ALL&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;0 &lt;span style=&quot;color: blue;&quot;&gt;as &lt;/span&gt;abc&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ) &lt;span style=&quot;color: blue;&quot;&gt;as &lt;/span&gt;a&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;RETURN &lt;/span&gt;@Result&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;END&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;GO&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;dbo.fn_Test()&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
In SQL Server 2019 with compatibility level 150 &lt;br /&gt;You will get the error below:&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;i&gt;Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, &amp;lt;, &amp;lt;= , &amp;gt;, &amp;gt;= or when the subquery is used as an expression. &lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To fix it you can do one of the following:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Add &lt;span style=&quot;color: blue;&quot;&gt;TOP&lt;/span&gt;(1)&amp;nbsp; :&amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;SELECT&amp;nbsp;&amp;nbsp;TOP(1)&amp;nbsp;&lt;/span&gt;@Result = 0&lt;/li&gt;
&lt;li&gt;Add cast as INT : &lt;span style=&quot;color: blue;&quot;&gt;SELECT&amp;nbsp;&amp;nbsp;&lt;/span&gt;@Result = &lt;span style=&quot;color: blue;&quot;&gt;CAST&lt;/span&gt;(0 AS &lt;span style=&quot;color: blue;&quot;&gt;INT&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;Switch to compatibility level 140 &lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;Another bug is also a function related,&lt;br /&gt;Consider the following code, &lt;br /&gt;&lt;br /&gt;&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;CREATE OR ALTER FUNCTION&lt;/span&gt; dbo.fn_Test2()&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;RETURNS BIT&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;AS&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;BEGIN&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp; &amp;nbsp; DECLARE&lt;/span&gt; @Result &lt;span style=&quot;color: blue;&quot;&gt;BIT &lt;/span&gt;= 1&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;@Result = 0&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;WHERE &lt;/span&gt;1 = 0&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;RETURN &lt;/span&gt;@Result&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;END&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;GO&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;SELECT&amp;nbsp;&lt;/span&gt;dbo.fn_Test2()&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
What we except is that the @Result value will be 1 &lt;br /&gt;But it is returned as NULL in SQL Server 2019.&lt;br /&gt;&lt;br /&gt;To fix it you can do one of the following :&lt;br /&gt;  &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Add cast as BIT:&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;SELECT&amp;nbsp;&amp;nbsp;&lt;/span&gt;@Result =&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;CAST&lt;/span&gt;(0 AS&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;BIT&lt;/span&gt;)&lt;/li&gt;
&lt;li&gt;Switch to compatibility level 140&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt; </content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/2303315656712983324/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2020/01/sql-server-2019-function-and-error.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/2303315656712983324'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/2303315656712983324'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2020/01/sql-server-2019-function-and-error.html' title='SQL Server 2019, a function and the error “Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, &lt;, &lt;= , &gt;, &gt;= or when the subquery is used as an expression.”'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-3000136746972293252</id><published>2019-12-12T14:08:00.000-08:00</published><updated>2020-04-21T13:52:44.928-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="MDS.MDM"/><title type='text'>An error on upgrading Master Data Services (MDM) from 2017 to 2019 on the website</title><content type='html'>If you have used Master Data Services (MDM) version 2017&lt;br /&gt;
&lt;div&gt;
and you upgraded it to version 2019 by doing an in-place upgrade&lt;/div&gt;
&lt;div&gt;
or by using the same MDM website URL for the new version as for old version,&lt;/div&gt;
&lt;div&gt;
you might get the error below when you click on &quot;Explorer&quot; on the website.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAMmCyDz_q2PNjGDlgg2Ozt9cYuyVH6r4lEPq0C1hQzB47f0zHJAMOrfoIKramwYbF0s2K06uihUyBDFI4W_SwOHu51cNwDP8y6djebn7mx8oG5ecJGHeekkw5jy8lyxS74bt8v3EjRkM/s1600/SQL+Server+2019+Master+Data+Services.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;450&quot; data-original-width=&quot;624&quot; height=&quot;287&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAMmCyDz_q2PNjGDlgg2Ozt9cYuyVH6r4lEPq0C1hQzB47f0zHJAMOrfoIKramwYbF0s2K06uihUyBDFI4W_SwOHu51cNwDP8y6djebn7mx8oG5ecJGHeekkw5jy8lyxS74bt8v3EjRkM/s400/SQL+Server+2019+Master+Data+Services.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;i style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;background: white; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;Oops! Something went wrong.&lt;/span&gt;&lt;/i&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 2.0pt; margin-left: 0in; margin-right: 0in; margin-top: 2.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;i&gt;&lt;span style=&quot;background: white; color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The view &#39;Index&#39; or its master
was not found or no view engine supports the searched locations. The following
locations were searched:&lt;br /&gt;
~/Views/Explore/Index.aspx&lt;br /&gt;
~/Views/Explore/Index.ascx&lt;br /&gt;
~/Views/Shared/Index.aspx&lt;br /&gt;
~/Views/Shared/Index.ascx&lt;br /&gt;
~/Views/Explore/Index.cshtml&lt;br /&gt;
~/Views/Explore/Index.vbhtml&lt;br /&gt;
~/Views/Shared/Index.cshtml&lt;br /&gt;
~/Views/Shared/Index.vbhtml&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 2.0pt; margin-left: 0in; margin-right: 0in; margin-top: 2.0pt; text-autospace: none;&quot;&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;i&gt;&lt;span style=&quot;background: white; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Click Email Microsoft, to
report this issue to Microsoft Master Data Service team.&lt;/span&gt;&lt;span style=&quot;color: navy; font-family: &amp;quot;arial&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpYYqYrhLmtJ23oMF56lQsCtym1pgcwom7GgMAFkrs2j6DlO8Izjm9xm9SnZcpA1-d2SBhZy9uLhwmYLkp_b3c5nurGtHzQ8x5h8I3GAhKQ7AdFMraoOS01Y67eCi5UQtl8nj77a-ExGg/s1600/SQL+Server+2019+Master+Data+Services+error.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;332&quot; data-original-width=&quot;935&quot; height=&quot;140&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpYYqYrhLmtJ23oMF56lQsCtym1pgcwom7GgMAFkrs2j6DlO8Izjm9xm9SnZcpA1-d2SBhZy9uLhwmYLkp_b3c5nurGtHzQ8x5h8I3GAhKQ7AdFMraoOS01Y67eCi5UQtl8nj77a-ExGg/s400/SQL+Server+2019+Master+Data+Services+error.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
In my case, what helped is cleaning the local browser cache (IE or Chrome)&lt;br /&gt;
by clicking Ctrl+Shift+Del once the browser is opened.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Good Luck&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/3000136746972293252/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2019/12/an-error-on-upgrading-master-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/3000136746972293252'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/3000136746972293252'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2019/12/an-error-on-upgrading-master-data.html' title='An error on upgrading Master Data Services (MDM) from 2017 to 2019 on the website'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAMmCyDz_q2PNjGDlgg2Ozt9cYuyVH6r4lEPq0C1hQzB47f0zHJAMOrfoIKramwYbF0s2K06uihUyBDFI4W_SwOHu51cNwDP8y6djebn7mx8oG5ecJGHeekkw5jy8lyxS74bt8v3EjRkM/s72-c/SQL+Server+2019+Master+Data+Services.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-5884874814036272922</id><published>2019-11-22T11:06:00.000-08:00</published><updated>2019-11-22T11:06:57.146-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL Performance"/><category scheme="http://www.blogger.com/atom/ns#" term="Temp Table vs Table Variable"/><title type='text'>Table Variables  - Serial plan upon data modification statements and OPTION(RECOMPILE)</title><content type='html'>Here is something to be aware of: &lt;br /&gt;When you have data modification statements&lt;div&gt;
(like, &lt;span style=&quot;color: blue;&quot;&gt;INSERT,UPDATE,DELETE&lt;/span&gt;) against a table variable, &lt;br /&gt;The SQL Server will not use a parallel plan, it will use a serial plan. &lt;br /&gt;This can affect the performance, so keep it in mind. &lt;br /&gt;&lt;br /&gt;Although, there is a workaround: &lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;INSERT INTO&lt;/span&gt; @Table&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;EXEC&lt;/span&gt;(&#39;&lt;span style=&quot;color: blue;&quot;&gt;SELECT .. FROM&lt;/span&gt; ...&#39;) &lt;br /&gt;&lt;br /&gt;Additionally, &lt;br /&gt;Until SQL Server 2019 which has &quot;Table variable deferred compilation&quot; feature, &lt;br /&gt;the estimated number of rows of table variables was always 1. &lt;br /&gt;Why? When a query/SP/batch is compiled and optimized, the table variable is empty.&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
If you wanted to have proper estimations then you need to use&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;OPTION(RECOMPILE)&lt;/span&gt;  hint or use &lt;span style=&quot;color: blue;&quot;&gt;trace flag 2453&lt;/span&gt;,&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
so the optimize will use real row count.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;Note, &lt;span style=&quot;color: blue;&quot;&gt;OPTION(RECOMPILE)&lt;/span&gt; hint will not always work when&lt;/div&gt;
&lt;div&gt;
you join the table variable to a table and have 1 to many relationship.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;See &lt;a href=&quot;https://www.sqlservercentral.com/blogs/should-i-use-optionrecompile&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;https://www.sqlservercentral.com/blogs/should-i-use-optionrecompile&lt;/span&gt;&lt;/a&gt; for more details. &lt;br /&gt;&lt;br /&gt;Also, the situation is different when you have some filters on your table variable.&lt;br /&gt;Because there are no statistics on the table variables,&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
SQL Server will use the following rules for the estimation of rows: &lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;- When there is equal filter the estimates will be 10 % out of total rows, &lt;br /&gt;- When there are inequality filters, like &amp;lt;, &amp;gt;, &amp;lt;&amp;gt;  the estimates will be 30 % out of total rows &lt;br /&gt;- When there is an equal filter on a bit field the estimates will be 50 % out of total rows &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Source articles: &lt;br /&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;a href=&quot;https://www.brentozar.com/archive/2017/02/using-trace-flag-2453-improve-table-variable-performance/&quot;&gt;https://www.brentozar.com/archive/2017/02/using-trace-flag-2453-improve-table-variable-performance/&lt;/a&gt; &lt;br /&gt;&lt;a href=&quot;https://support.microsoft.com/en-us/help/2952444/fix-poor-performance-when-you-use-table-variables-in-sql-server-2012-o&quot;&gt;https://support.microsoft.com/en-us/help/2952444/fix-poor-performance-when-you-use-table-variables-in-sql-server-2012-o&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/5884874814036272922/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2019/11/table-variables-serial-plan-upon-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/5884874814036272922'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/5884874814036272922'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2019/11/table-variables-serial-plan-upon-data.html' title='Table Variables  - Serial plan upon data modification statements and OPTION(RECOMPILE)'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-6711727526971760872</id><published>2019-11-15T08:51:00.001-08:00</published><updated>2019-11-20T12:54:38.797-08:00</updated><title type='text'>Bug in SQL Server 2019: SET IDENTITY_INSERT ON a temp table in nested/inner SP/scope</title><content type='html'>Consider the following use case:&lt;br /&gt;
&lt;br /&gt;
You have 2 stored procedures, one is calling another.&lt;br /&gt;
In the outer SP you define a temp table with an Identity field. &lt;br /&gt;
And in the second SP you do insert to this temp table with&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;SET IDENTITY_INSERT ON &lt;/span&gt;option.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
In Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64)&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
it throws following exception: &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;i&gt;Cannot insert explicit value for identity column in table&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;i&gt;&#39;#TempTable&#39; when IDENTITY_INSERT is set to OFF. &lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
Sample Code:&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;CREATE PROCEDURE &lt;/span&gt;dbo.uspTestIdenityInsert_Outer&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;AS&lt;br /&gt;SET NOCOUNT ON&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #6aa84f;&quot;&gt;-- Create temp table &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt; CREATE TABLE&lt;/span&gt; #TempTable&lt;br /&gt;
(&lt;br /&gt;
RowID &lt;span style=&quot;color: blue;&quot;&gt;INT IDENTITY&lt;/span&gt;(1,1) NOT NULL,&lt;br /&gt;
FName &lt;span style=&quot;color: blue;&quot;&gt;VARCHAR(&lt;/span&gt;50) NOT NULL&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #6aa84f;&quot;&gt;-- exec inner SP that inserts data to the temp table.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt; EXEC &lt;/span&gt;dbo.uspTestIdenityInsert_Inner&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;CREATE PROCEDURE&lt;/span&gt; dbo.uspTestIdenityInsert_Inner&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;AS&lt;br /&gt;SET NOCOUNT ON&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;SET IDENTITY_INSERT&lt;/span&gt; #TempTable &lt;span style=&quot;color: blue;&quot;&gt;ON&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;INSERT INTO &lt;/span&gt;#TempTable(RowID,FName)&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;1 &lt;span style=&quot;color: blue;&quot;&gt;as &lt;/span&gt;RowID,&#39;&lt;span style=&quot;color: #cc0000;&quot;&gt;Dan&lt;/span&gt;&#39; &lt;span style=&quot;color: blue;&quot;&gt;as&lt;/span&gt; FName&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;GO&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;--------------------------------------------------------------------------&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
EXEC dbo.uspTestIdenityInsert_Outer&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red; font-size: x-small;&quot;&gt;Msg 544, Level 16, State 1, Procedure dbo.uspTestIdenityInsert_Inner, Line 8 [Batch Start Line 26]&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red; font-size: x-small;&quot;&gt;Cannot insert explicit value for identity column in table &#39;#TempTable&#39; when IDENTITY_INSERT is set to OFF.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
Looks like this bug exist from CTP 2.3 &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;a href=&quot;https://feedback.azure.com/forums/908035-sql-server/suggestions/37092100-sql-server-2019-ctp-2-3-issue-with-scope-of-set&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;https://feedback.azure.com/forums/908035-sql-server/suggestions/37092100-sql-server-2019-ctp-2-3-issue-with-scope-of-set&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;This bug is due to the implementation of  the new feature &lt;br /&gt;&lt;b&gt;“Reduced recompilations for workloads using temporary tables across multiple scopes”&amp;nbsp;&lt;/b&gt;&lt;div&gt;
that was introduced in SQL Server 2019 &lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;a href=&quot;https://blogs.msdn.microsoft.com/sqlserverstorageengine/2019/03/04/reduced-recompilations-for-workloads-using-temporary-tables-across-multiple-scopes/&quot;&gt;https://blogs.msdn.microsoft.com/sqlserverstorageengine/2019/03/04/reduced-recompilations-for-workloads-using-temporary-tables-across-multiple-scopes/&lt;/a&gt; &lt;/span&gt;&lt;br /&gt;The workaround is to disable this new feature by using trace flags 11036, 11048 &lt;br /&gt;that can be added as SQL startup parameters&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0B0XL2m8Mc7ZQ852vCqz0vY_ImlnyUeRfb62XkS_Q0PZa-3lKacGKSnJHSNy5hyphenhyphengv0R_z_39HiHwP_BBwell8mTUQe20hMuLgvYUp4xm3HHsrf-O64W6pX954Bz4PqJMhsX12ATjsTFI/s1600/Trace+Flags.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;267&quot; data-original-width=&quot;410&quot; height=&quot;260&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0B0XL2m8Mc7ZQ852vCqz0vY_ImlnyUeRfb62XkS_Q0PZa-3lKacGKSnJHSNy5hyphenhyphengv0R_z_39HiHwP_BBwell8mTUQe20hMuLgvYUp4xm3HHsrf-O64W6pX954Bz4PqJMhsX12ATjsTFI/s400/Trace+Flags.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;Calibri&amp;quot;,sans-serif; font-size: 11.0pt; mso-ansi-language: EN-US; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: &amp;quot;Times New Roman&amp;quot;; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;&quot;&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shapetype id=&quot;_x0000_t75&quot;
 coordsize=&quot;21600,21600&quot; o:spt=&quot;75&quot; o:preferrelative=&quot;t&quot; path=&quot;m@4@5l@4@11@9@11@9@5xe&quot;
 filled=&quot;f&quot; stroked=&quot;f&quot;&gt;
 &lt;v:stroke joinstyle=&quot;miter&quot;/&gt;
 &lt;v:formulas&gt;
  &lt;v:f eqn=&quot;if lineDrawn pixelLineWidth 0&quot;/&gt;
  &lt;v:f eqn=&quot;sum @0 1 0&quot;/&gt;
  &lt;v:f eqn=&quot;sum 0 0 @1&quot;/&gt;
  &lt;v:f eqn=&quot;prod @2 1 2&quot;/&gt;
  &lt;v:f eqn=&quot;prod @3 21600 pixelWidth&quot;/&gt;
  &lt;v:f eqn=&quot;prod @3 21600 pixelHeight&quot;/&gt;
  &lt;v:f eqn=&quot;sum @0 0 1&quot;/&gt;
  &lt;v:f eqn=&quot;prod @6 1 2&quot;/&gt;
  &lt;v:f eqn=&quot;prod @7 21600 pixelWidth&quot;/&gt;
  &lt;v:f eqn=&quot;sum @8 21600 0&quot;/&gt;
  &lt;v:f eqn=&quot;prod @7 21600 pixelHeight&quot;/&gt;
  &lt;v:f eqn=&quot;sum @10 21600 0&quot;/&gt;
 &lt;/v:formulas&gt;
 &lt;v:path o:extrusionok=&quot;f&quot; gradientshapeok=&quot;t&quot; o:connecttype=&quot;rect&quot;/&gt;
 &lt;o:lock v:ext=&quot;edit&quot; aspectratio=&quot;t&quot;/&gt;
&lt;/v:shapetype&gt;&lt;v:shape id=&quot;Picture_x0020_3&quot; o:spid=&quot;_x0000_i1025&quot; type=&quot;#_x0000_t75&quot;
 alt=&quot;&quot; style=&#39;width:307.5pt;height:200.25pt&#39;&gt;
 &lt;v:imagedata src=&quot;file:///C:/Users/DPRETS~1/AppData/Local/Temp/1/msohtmlclip1/01/clip_image001.jpg&quot;
  o:href=&quot;cid:image002.jpg@01D59DF3.58599FA0&quot;/&gt;
&lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/6711727526971760872/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2019/11/bug-in-sql-server-2019-set.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/6711727526971760872'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/6711727526971760872'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2019/11/bug-in-sql-server-2019-set.html' title='Bug in SQL Server 2019: SET IDENTITY_INSERT ON a temp table in nested/inner SP/scope'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0B0XL2m8Mc7ZQ852vCqz0vY_ImlnyUeRfb62XkS_Q0PZa-3lKacGKSnJHSNy5hyphenhyphengv0R_z_39HiHwP_BBwell8mTUQe20hMuLgvYUp4xm3HHsrf-O64W6pX954Bz4PqJMhsX12ATjsTFI/s72-c/Trace+Flags.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-5433200236204580607</id><published>2019-11-11T08:57:00.000-08:00</published><updated>2019-12-05T10:54:55.653-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL Server 2019 Setup"/><title type='text'>SQL Server 2019 install/setup failed</title><content type='html'>&lt;br /&gt;
When trying to install the SQL Server 2019, &lt;br /&gt;
The installation/setup failed with the following errors: &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;Feature: Database Engine Services &lt;br /&gt;Status: &lt;span style=&quot;color: red;&quot;&gt;Failed &lt;/span&gt;&lt;br /&gt;Reason for failure: &lt;span style=&quot;color: red;&quot;&gt;An error occurred for a dependency of the feature causing the setup process for the feature to fail. &lt;/span&gt;&lt;br /&gt;Next Step: Use the following information to resolve the error, and then try the setup process again. &lt;br /&gt;&lt;br /&gt;Feature: SQL Client Connectivity SDK &lt;br /&gt;Status: &lt;span style=&quot;color: red;&quot;&gt;Failed &lt;/span&gt;&lt;br /&gt;Reason for failure: &lt;span style=&quot;color: red;&quot;&gt;An error occurred during the setup process of the feature. &lt;/span&gt;&lt;br /&gt;Next Step: Use the following information to resolve the error, and then try the setup process again. &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrWGo5sNSDwDAwKs7OI9IOnRUJh4Ti9gqWajp9hAxJgOgcxJmaknD7qeQNcHF0OeHsAF9fl_WaKCPg72MUPjFRHX7_Qj0PzoG3L7mLrKKJh33FyGYMIrM4UlUS5vJUoNdIA2ZFnYJVcak/s1600/SQL+2019+Setup+Error.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;626&quot; data-original-width=&quot;1035&quot; height=&quot;241&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrWGo5sNSDwDAwKs7OI9IOnRUJh4Ti9gqWajp9hAxJgOgcxJmaknD7qeQNcHF0OeHsAF9fl_WaKCPg72MUPjFRHX7_Qj0PzoG3L7mLrKKJh33FyGYMIrM4UlUS5vJUoNdIA2ZFnYJVcak/s400/SQL+2019+Setup+Error.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
In the summary file there was the following error: &lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;Exit code (Decimal):           -2068643839 &lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In the detail.txt file the first error/failure mentioned was: &lt;br /&gt;
&lt;span style=&quot;color: red; font-size: x-small;&quot;&gt;&lt;br /&gt;InstallPackage: MsiInstallProduct returned the result code 1602. &lt;br /&gt;Slp: No retry-able MSI return code detected. &lt;br /&gt;Slp: ExecuteActionWithRetryHelper.Failed actionToExecute is &#39;Install_sqlncli_Cpu64_Action&#39;, &lt;br /&gt;stack trace    at Microsoft.SqlServer.Setup.Chainer.Workflow.ActionInvocation.&amp;lt;&amp;gt;c__DisplayClass2_0.&lt;executeactionwithretryhelper&gt;b__0() &lt;/executeactionwithretryhelper&gt;&lt;/span&gt;&lt;br /&gt;
In my case what helped is to uninstall the SQL Server Native Client via&lt;/div&gt;
&lt;div&gt;
Add/Remove Programs and reboot.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
Apparently, this is documented by Microsoft&lt;br /&gt;
&lt;a href=&quot;https://techcommunity.microsoft.com/t5/SQL-Server-Support/SQL-Server-2019-Installation-Error-An-error-occurred-for-a/ba-p/998033&quot;&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;https://techcommunity.microsoft.com/t5/SQL-Server-Support/SQL-Server-2019-Installation-Error-An-error-occurred-for-a/ba-p/998033&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Here how to find all the installation-related logs of SQL Server:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://docs.microsoft.com/en-us/sql/database-engine/install-windows/view-and-read-sql-server-setup-log-files?view=sql-server-2017&quot;&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;https://docs.microsoft.com/en-us/sql/database-engine/install-windows/view-and-read-sql-server-setup-log-files?view=sql-server-2017&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/5433200236204580607/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2019/11/sql-server-2019-installsetup-failed.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/5433200236204580607'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/5433200236204580607'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2019/11/sql-server-2019-installsetup-failed.html' title='SQL Server 2019 install/setup failed'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrWGo5sNSDwDAwKs7OI9IOnRUJh4Ti9gqWajp9hAxJgOgcxJmaknD7qeQNcHF0OeHsAF9fl_WaKCPg72MUPjFRHX7_Qj0PzoG3L7mLrKKJh33FyGYMIrM4UlUS5vJUoNdIA2ZFnYJVcak/s72-c/SQL+2019+Setup+Error.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-1540730847204758382</id><published>2019-10-28T15:32:00.000-07:00</published><updated>2020-05-30T17:35:21.875-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL Performance"/><title type='text'>Control the join order of tables</title><content type='html'>Have you ever been in a situation where you need to optimize a complex query&lt;br /&gt;
&lt;div&gt;
with multiple joins or a view with multiple joins? &lt;br /&gt;
And the query plan that SQL Server builds could be better 😊 &lt;br /&gt;
&lt;br /&gt;
If the query in a stored procedure, you are lucky, and you can change&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
it completely by breaking the query into small pieces &lt;br /&gt;
And saving the intermediate results into a temp table(s).&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
It will give you a better plan, better statistics and there is no need to use any hints. &lt;br /&gt;
And by this, you can reduce the number of rows that each part of the query will process. &lt;br /&gt;
&lt;br /&gt;
But what if your query is not inside a stored procedure and/or you cannot use&lt;/div&gt;
&lt;div&gt;
the technique of splitting it to smaller joins and using temp tables&lt;/div&gt;
&lt;div&gt;
for keeping intermediate results?&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;u&gt;&lt;b&gt;Yet, you want a way to control the join order of the tables? &lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
For example, you have 3 tables participated in INNER joins(Table1, Table2 &amp;amp; Table3)&lt;br /&gt;
And you want to control the ORDER in which SQL Server will do the joins: &lt;br /&gt;
Maybe first to do join between Table3 and Table1 and then join the result to Table2. &lt;br /&gt;
&lt;br /&gt;
As you are aware, when you have INNER/CROSS joins (NOT LEFT/RIGHT Joins)&lt;/div&gt;
&lt;div&gt;
in your query, the order in which you write the Joins doesn’t make any difference,&lt;/div&gt;
&lt;div&gt;
because the query optimizer will decide how to do it. &lt;br /&gt;
&lt;br /&gt;
The SQL Server doesn’t take into account the order of tables that you have&lt;/div&gt;
&lt;div&gt;
in FROM clause(Inner joins) &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Either, rewriting the query to use CTE or inline Subqueries&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;or to use parentheses probably will not help,&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;because SQL Server will decide on its own how to get the data. &lt;/b&gt;&lt;br /&gt;
If you already did all the right work(statistics, indexes) and you can see&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
a better plan for your query than the SQL Server creates, &lt;br /&gt;
The below options can be helpful: &lt;br /&gt;
&lt;br /&gt;
One &lt;b&gt;(not attractive and not recommended) &lt;/b&gt;way is to use&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;OPTION(FORCE ORDER)&lt;/span&gt; hint. &lt;br /&gt;
One of the drawbacks of &lt;span style=&quot;color: blue;&quot;&gt;OPTION(FORCE ORDER)&lt;/span&gt; hint is that&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
all joins between the listed table will be affected, &lt;br /&gt;
&lt;br /&gt;
Meaning all joins will be performed in the order how they show in the query &lt;br /&gt;
And you cannot control just specific 2-3 joins order. &lt;br /&gt;
&lt;br /&gt;
The second option is more delicate. &lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;You can use the TOP clause in your CTE or inline Subquery. &lt;/span&gt;&lt;/b&gt;This will force the optimizer to do the joins first, in order to satisfy the TOP condition, &lt;br /&gt;
Meaning SQL server will have to perform the JOINs first and/or together as a group. &lt;br /&gt;
&lt;br /&gt;
You can specify a larger number like below not to limit the actual number of rows &lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;TOP(2147483647) &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The source of this ‘trick’/technique comes from Adam Machanic &lt;br /&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;a href=&quot;https://sqlbits.com/Sessions/Event14/Query_Tuning_Mastery_Clash_of_the_Row_Goals&quot;&gt;https://sqlbits.com/Sessions/Event14/Query_Tuning_Mastery_Clash_of_the_Row_Goals&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/1540730847204758382/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2019/10/control-join-order-of-tables.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/1540730847204758382'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/1540730847204758382'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2019/10/control-join-order-of-tables.html' title='Control the join order of tables'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-7869142953357072083</id><published>2019-10-02T08:57:00.000-07:00</published><updated>2019-10-03T08:33:15.680-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Locks"/><title type='text'>Lock escalation: Multiple batches inside a transaction</title><content type='html'>As you know, &lt;br /&gt;
The Lock Escalation can happen from Keys/Rows level to the Table/Partition level&lt;br /&gt;
or from Pages level to the Table/Partition level, but not from rows to pages.&lt;br /&gt;
&lt;br /&gt;
SQL Server decides to do the escalation when any of the following conditions met: &lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;- The number of locks (including intent locks) held by a single statement &lt;br /&gt;&amp;nbsp; &amp;nbsp; on an index or a heap within a statement exceeds the threshold &lt;b&gt;(Approximately &amp;gt;5000 locks).&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;-&amp;nbsp; The memory taken by lock resources is more than 40% &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now consider a situation when you have multiple INSERTs or UPDATEs statements&lt;/div&gt;
&lt;div&gt;
of a table inside a transaction. &lt;/div&gt;
&lt;div&gt;
So my question was:&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
When SQL Server decides to do the lock escalation is it takes into account/counts&lt;/div&gt;
&lt;div&gt;
all locks acquired for the specific table of all statements in the transaction &lt;br /&gt;
Or it counts only locks for a single statement? &lt;br /&gt;
&lt;br /&gt;
For example, if I want to update/insert high amount of rows in a table, &lt;br /&gt;
if I do it in one statement it will escalate the locks to table level, &lt;br /&gt;
But if I do it in batches/chunks under a transaction, will it count each batch/statement&lt;/div&gt;
&lt;div&gt;
separately or it will count all locks acquired by all batches because we do it&lt;/div&gt;
&lt;div&gt;
in the transaction and the X locks are held until the end of the transaction&lt;/div&gt;
&lt;div&gt;
in read committed isolation mode. &lt;br /&gt;
&lt;br /&gt;
Well, the answer is: &lt;br /&gt;
The escalation will occur if the threshold is exceeded for a single statement&lt;/div&gt;
&lt;div&gt;
on a single resource. Meaning if you have multiple UPDATE/INSERT&lt;/div&gt;
&lt;div&gt;
statements for a specific table inside a transaction, &lt;br /&gt;
SQL server will treat each statement individually/separately &lt;br /&gt;
and will not count X locks held by previously executed statements in this transaction.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/7869142953357072083/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2019/10/lock-escalation-multiple-batches-inside.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/7869142953357072083'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/7869142953357072083'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2019/10/lock-escalation-multiple-batches-inside.html' title='Lock escalation: Multiple batches inside a transaction'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-2356740629186656182</id><published>2019-09-11T15:54:00.002-07:00</published><updated>2019-11-20T13:01:41.046-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="FILESTREAM"/><category scheme="http://www.blogger.com/atom/ns#" term="Impersonation"/><title type='text'>SQL Server FILESTREAM with SQL Server Authentication </title><content type='html'>&lt;br /&gt;
If you have an application that connects to SQL Server using SQL Server Authentication&lt;br /&gt;
And you want to use the FILESTREAM feature in your .NET application utilizing the SqlFileStream Class like below: &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;SqlFileStream &lt;span style=&quot;color: #3d85c6;&quot;&gt;sqlFileStream1 &lt;/span&gt;= &lt;span style=&quot;color: blue;&quot;&gt;new &lt;/span&gt;SqlFileStream(filePath1, transactionContext1, &lt;span style=&quot;color: #0b5394;&quot;&gt;FileAccess&lt;/span&gt;.Write); &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
You will probably get an error saying &lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;“Access is denied“ &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In all documentation it is mentioned that &lt;br /&gt;
&lt;i&gt;“FILESTREAM requires integrated security. SQL Server authentication is not supported.” &lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
But there is a workaround that will allow you still to use the SQL Authentication in your connection string. &lt;br /&gt;
&lt;br /&gt;
To use the FILESTREAM in your application you need to do 2 steps:&lt;br /&gt;
First, you need to get from the DB the Logical Path Name and Transaction Context.&lt;br /&gt;
&lt;div&gt;
(Like a token or file handler) &lt;br /&gt;
&lt;br /&gt;
FileStreamColumn.&lt;span style=&quot;color: magenta;&quot;&gt;PathName()&lt;/span&gt; As [Path] &lt;br /&gt;
&lt;span style=&quot;color: magenta;&quot;&gt;GET_FILESTREAM_TRANSACTION_CONTEXT() &lt;/span&gt;As TransactionContext &lt;br /&gt;
&lt;br /&gt;
The second step, using the path and transaction context initialize the SqlFileStream object. &lt;/div&gt;
&lt;div&gt;
These both steps should be done in a transaction scope and under the same user. &lt;br /&gt;
Meaning, if the application runs under Windows Account “User1” &lt;br /&gt;
then the first step of getting the logical path and transaction context should&lt;/div&gt;
&lt;div&gt;
be also done with the same “User1”. &lt;br /&gt;
&lt;br /&gt;
What we can do is to use impersonation in SQL Server. &lt;br /&gt;
If the application runs with Windows Account “User1”,&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
we should create this Windows Account “User1” in SQL Server as Login and DB user. &lt;br /&gt;
&lt;br /&gt;
Impersonate it as below and grant to it relevant permission to the table&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
with FileStream columns and execute the relevant&lt;/div&gt;
&lt;div&gt;
Stored Procedures/SQL Queries &lt;span style=&quot;color: blue;&quot;&gt;with EXECUTE AS &lt;/span&gt;[User1] &lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue;&quot;&gt;Use Master &lt;br /&gt;Go &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;GRANT &lt;/span&gt;IMPERSONATE &lt;span style=&quot;color: blue;&quot;&gt;ON LOGIN&lt;/span&gt;::[User1] &lt;span style=&quot;color: blue;&quot;&gt;TO &lt;/span&gt;SQL_Login_of_App; &lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;Go &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
According to the POC we did, this workaround allows you to stay with SQL authentication in your connection string to a database.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
Note, the impersonation cannot be granted to a windows group, only to a single account.&lt;br /&gt;
&lt;br /&gt;
Source reference:&lt;/div&gt;
&lt;div&gt;
&lt;a href=&quot;https://www.sqlskills.com/blogs/bobb/using-filestream-streaming-io-and-sql-logins-with-impersonation/&quot;&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;https://www.sqlskills.com/blogs/bobb/using-filestream-streaming-io-and-sql-logins-with-impersonation/&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/2356740629186656182/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2019/09/sql-server-filestream-with-sql-server.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/2356740629186656182'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/2356740629186656182'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2019/09/sql-server-filestream-with-sql-server.html' title='SQL Server FILESTREAM with SQL Server Authentication '/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-1229742699165109854</id><published>2019-09-11T15:11:00.001-07:00</published><updated>2019-09-11T15:45:47.872-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Master Data Services"/><category scheme="http://www.blogger.com/atom/ns#" term="MDS.MDM"/><title type='text'>Master Data Services Add-in for Microsoft Excel, error on connecting to MDS Repository/Server</title><content type='html'>&lt;br /&gt;
The Master Data Service is configured to have access via https protocol.&lt;br /&gt;
The MDS website is working with https without any issues.&lt;br /&gt;
&lt;br /&gt;
But, when you try to connect to MDS Server(MDM Repository) in Excel&lt;br /&gt;
&lt;div&gt;
you get the error below: &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red; font-size: x-small;&quot;&gt;TITLE: Master Data Services Add-in for Excel &lt;br /&gt;------------------------------ &lt;br /&gt;An error occurred while making the HTTP request to https://[ServerName]/MDS/service/service.svc/bhb. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server. &lt;br /&gt;------------------------------ &lt;br /&gt;ADDITIONAL INFORMATION: &lt;br /&gt;The underlying connection was closed: An unexpected error occurred on a send. (System) &lt;br /&gt;------------------------------ &lt;br /&gt;Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. (System) &lt;br /&gt;------------------------------ &lt;br /&gt;An existing connection was forcibly closed by the remote host (System) &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
This issue was related to TSL 1.2 settings.&lt;br /&gt;
To solve it, you need to set the .Net to work with strong cryptography &lt;br /&gt;
By setting/adding the &lt;b&gt;SchUseStrongCrypto &lt;/b&gt;registry setting to DWORD:00000001 &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #38761d;&quot;&gt;[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319] &lt;br /&gt;&quot;SystemDefaultTlsVersions&quot; = dword:00000001 &lt;br /&gt;&quot;SchUseStrongCrypto&quot; = dword:00000001&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The software versions in our case:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Windows Server 2019&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Excel 2019&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Microsoft SQL Server 2017 (RTM-CU15)&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Master Data Services 14.0.10000.169&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
The source reference:&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;a href=&quot;https://social.msdn.microsoft.com/Forums/vstudio/en-US/ba004936-df44-4184-bd1a-9e059a866e48/master-data-service-with-excel-2013-error?forum=sqlmds&quot;&gt;https://social.msdn.microsoft.com/Forums/vstudio/en-US/ba004936-df44-4184-bd1a-9e059a866e48/master-data-service-with-excel-2013-error?forum=sqlmds&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: xx-small;&quot;&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/sccm/core/plan-design/security/enable-tls-1-2&quot;&gt;https://docs.microsoft.com/en-us/sccm/core/plan-design/security/enable-tls-1-2&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/1229742699165109854/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2019/09/master-data-services-add-in-for.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/1229742699165109854'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/1229742699165109854'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2019/09/master-data-services-add-in-for.html' title='Master Data Services Add-in for Microsoft Excel, error on connecting to MDS Repository/Server'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5812558148803847895.post-7883516134094967268</id><published>2019-08-29T15:30:00.000-07:00</published><updated>2020-04-21T13:53:25.237-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Deadlocks"/><category scheme="http://www.blogger.com/atom/ns#" term="Locks"/><title type='text'>UPDATE (U) locks behavior in MERGE statement vs UPDATE statement</title><content type='html'>When analyzing deadlocks with &lt;span style=&quot;color: blue;&quot;&gt;MERGE &lt;/span&gt;and &lt;span style=&quot;color: blue;&quot;&gt;UPDATE &lt;/span&gt;statements,&lt;br /&gt;
I have noticed that &lt;span style=&quot;color: blue;&quot;&gt;UPDATE &lt;/span&gt;(U) Locks behave in a different way in&lt;br /&gt;
&lt;div&gt;
an &lt;span style=&quot;color: blue;&quot;&gt;UPDATE &lt;/span&gt;statement and in a &lt;span style=&quot;background-color: white;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;MERGE &lt;/span&gt;&lt;/span&gt;statement.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicojR-756W2HP025ctL4KNSLKRV8dfQYQmgVONCdtZnpUV7VNVD24TQ4-HGOnyd9sch0O22N2WuKmyjZjW0jtWZpqHvqqJOT1aWs0DZ5hi84CYAUpqQIxakC1wKEZzX7JHeEbjwBOyYuk/s1600/Deadlock+with+U+and+X+Locks.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;681&quot; data-original-width=&quot;1035&quot; height=&quot;263&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicojR-756W2HP025ctL4KNSLKRV8dfQYQmgVONCdtZnpUV7VNVD24TQ4-HGOnyd9sch0O22N2WuKmyjZjW0jtWZpqHvqqJOT1aWs0DZ5hi84CYAUpqQIxakC1wKEZzX7JHeEbjwBOyYuk/s400/Deadlock+with+U+and+X+Locks.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Deadlock graph between MERGE and UPDATE statements on the same PK value&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;Let`s assume you want to update 2 rows in a table&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
and the search for these rows using NC index,&lt;br /&gt;
the question is whether SQL Server will apply U locks one by one&lt;/div&gt;
&lt;div&gt;
and release each U lock after each row or it will apply U locks&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
for all matched rows and only after the update will release them. &lt;br /&gt;
&lt;br /&gt;
Let`s create a test table that will have 3 fields with CL and NC index:&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;CREATE TABLE&lt;/span&gt; dbo.Customers&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;(&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;CustomerID&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;INT &lt;/span&gt;NOT NULL &lt;span style=&quot;color: blue;&quot;&gt;IDENTITY&lt;/span&gt;(1,1) &lt;span style=&quot;color: blue;&quot;&gt;PRIMARY KEY,&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;EmailAddress&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;VARCHAR&lt;/span&gt;(50) NOT NULL,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;FullName&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;VARCHAR&lt;/span&gt;(50) NOT NULL&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: x-small;&quot;&gt;GO&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;CREATE UNIQUE NONCLUSTERED INDEX&lt;/span&gt; IX_Customers_EmailAddress &lt;span style=&quot;color: blue;&quot;&gt;ON &lt;/span&gt;dbo.Customers(EmailAddress)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: x-small;&quot;&gt;GO&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;INSERT INTO&lt;/span&gt; dbo.Customers (EmailAddress,FullName)&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;dan@gmail.com&#39;&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS &lt;/span&gt;EmailAddress,&lt;span style=&quot;color: red;&quot;&gt;&#39;Dan&#39;&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS &lt;/span&gt;FullName&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;UNION ALL&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;rita@gmail.com&#39;&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; EmailAddress,&lt;span style=&quot;color: red;&quot;&gt;&#39;Rita&#39;&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS &lt;/span&gt;FullName&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;UNION ALL&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;greg@gmail.com&#39;&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS &lt;/span&gt;EmailAddress,&lt;span style=&quot;color: red;&quot;&gt;&#39;Greg&#39;&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS &lt;/span&gt;FullName&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;UNION ALL&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;mike@gmail.com&#39;&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS &lt;/span&gt;EmailAddress,&lt;span style=&quot;color: red;&quot;&gt;&#39;Mike&#39;&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS &lt;/span&gt;FullName&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;UNION ALL&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT &lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&#39;bob@gmail.com&#39;&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS &lt;/span&gt;EmailAddress,&lt;span style=&quot;color: red;&quot;&gt;&#39;Bob&#39;&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;AS &lt;/span&gt;FullName&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWmi3kWR61hSQg_MTKPK6qkAP2AQZ_tWeOwGswGbb-7s8NRfvqp0j6p1L4urZo-K69Mjb1gklsTc_fezNWQdlnIwu3e45jGwAeRS7UJ3go8fmpnvXu5qVmUbltxZhTBqm2Qw2rDx8mWbM/s1600/Customers+table.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;190&quot; data-original-width=&quot;243&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWmi3kWR61hSQg_MTKPK6qkAP2AQZ_tWeOwGswGbb-7s8NRfvqp0j6p1L4urZo-K69Mjb1gklsTc_fezNWQdlnIwu3e45jGwAeRS7UJ3go8fmpnvXu5qVmUbltxZhTBqm2Qw2rDx8mWbM/s1600/Customers+table.jpg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Customers Table&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
So we have the table with CL index on CustomerID and NC index on EmailAddress.&lt;/div&gt;
&lt;div&gt;
What we want to do is to update the FullName field of 2 rows that&lt;/div&gt;
&lt;div&gt;
will be filtered by EmailAddress column.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
One way to do it is to use a simple &lt;span style=&quot;color: blue;&quot;&gt;UPDATE &lt;/span&gt;statement as below:&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;UPDATE&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;c&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;SET&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;/span&gt;c.FullName=&lt;span style=&quot;color: red;&quot;&gt;&#39;N/A&#39;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;dbo.Customers &lt;span style=&quot;color: blue;&quot;&gt;AS &lt;/span&gt;c&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;WHERE&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;c.EmailAddress IN (&lt;span style=&quot;color: red;&quot;&gt;&#39;rita@gmail.com&#39;,&#39;mike@gmail.com&#39;&lt;/span&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: x-small;&quot;&gt;GO&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
The second way we can use &lt;span style=&quot;color: blue;&quot;&gt;MERGE &lt;/span&gt;statement as below:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;MERGE INTO&lt;/span&gt; dbo.Customers &lt;span style=&quot;color: blue;&quot;&gt;AS &lt;/span&gt;TGT &lt;span style=&quot;color: blue;&quot;&gt;USING &lt;/span&gt;( &lt;span style=&quot;color: blue;&quot;&gt;VALUES&lt;/span&gt;(&lt;span style=&quot;color: red;&quot;&gt; &#39;rita@gmail.com&#39;),(&#39;mike@gmail.com&#39;&lt;/span&gt;))&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;AS&lt;/span&gt; SRC (EmailAddress)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;ON &lt;/span&gt;SRC.EmailAddress= TGT.EmailAddress&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: x-small;&quot;&gt;WHEN MATCHED THEN&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: magenta;&quot;&gt;UPDATE &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;SET &lt;/span&gt;TGT.FullName=&lt;span style=&quot;color: red;&quot;&gt;&#39;N/A&#39;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: blue; font-size: x-small;&quot;&gt;WHEN NOT MATCHED THEN&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;INSERT VALUES&lt;/span&gt;( &lt;span style=&quot;color: red;&quot;&gt;&#39;rita@gmail.com&#39;,&#39;N/A&#39;&lt;/span&gt;);&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
Now let`s see what locks are acquired and when they released &lt;br /&gt;
if we run the UPDATE statement (only &#39;X&#39; and &#39;U&#39; locks shown in the screenshot).&lt;br /&gt;
SQL Server will first go to NC index to search by EmailAddress,&lt;br /&gt;
apply U locks for our 2 records and then go to CL index for the UPDATE.&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGMpEtgOOrh8_nbQytk0l3s0_EaPc9yPUbbJjGLW5LpM3nRXNW66GG_R_mQkXSAx8HIQgqt7V8Qp08_HGCsizxW50m9tIJWbNyiSAziq6LExwON11orDiOB_tmnimlyFIaEPEViJi_fYU/s1600/Locks+aquired+by+UPDATE+statement.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;329&quot; data-original-width=&quot;472&quot; height=&quot;278&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGMpEtgOOrh8_nbQytk0l3s0_EaPc9yPUbbJjGLW5LpM3nRXNW66GG_R_mQkXSAx8HIQgqt7V8Qp08_HGCsizxW50m9tIJWbNyiSAziq6LExwON11orDiOB_tmnimlyFIaEPEViJi_fYU/s400/Locks+aquired+by+UPDATE+statement.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
In the screenshot above we have value 99 in Res0 column representing NC index&lt;br /&gt;
&lt;div&gt;
and value 98 representing CL index.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
According to the locks sequence above,&lt;br /&gt;
We can see is that U lock applied to the first NC index key (Row #1, ID =4),&lt;br /&gt;
then U lock applied to CL index key(Row #2, ID =6),&lt;br /&gt;
then U lock converted to X lock on the CL key (Row #3, ID =8),&lt;br /&gt;
and finally, U lock released on NC index key (Row #4, ID =11).&lt;br /&gt;
&lt;div&gt;
Then the same order for the second row.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Now let`s see the locks sequence in case of the MERGE statement:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSDbU6r2ZSpIWOsux6Xky3fqwQEIG94za2R0PsiHbewnXP4cIn25XsQLlD1fE-2oxD0EnN36OZ-1LWnWPr3py_Fc-CAxECO6rKQrRZ9kZMZu7PIh6D4-gRCcUeBNgCHbZWpwR3i3Tb9Ro/s1600/Locks+aquired+by+MERGE+statement.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;375&quot; data-original-width=&quot;507&quot; height=&quot;295&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSDbU6r2ZSpIWOsux6Xky3fqwQEIG94za2R0PsiHbewnXP4cIn25XsQLlD1fE-2oxD0EnN36OZ-1LWnWPr3py_Fc-CAxECO6rKQrRZ9kZMZu7PIh6D4-gRCcUeBNgCHbZWpwR3i3Tb9Ro/s400/Locks+aquired+by+MERGE+statement.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
We can see that SQL Server first acquired U locks on the both NC keys&lt;br /&gt;
(2 keys, one after other), Rows #1,2,3,4 with Res0 =99.&lt;br /&gt;
Then applied U lock on CL index key(Row #5, ID =14)&lt;br /&gt;
Then converted the U lock to X lock of that CL index key(Row #6, ID =16)&lt;br /&gt;
and then applied U lock for the second key on CL index and converted it to an X lock&lt;br /&gt;
(Rows #7,8, IDs =20,22)&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
In summary, in the case of the UPDATE statement, SQL Server&lt;br /&gt;
acquired U locks on NC index one by one, first for 1 record&lt;br /&gt;
and then for the second record and released the U lock on NC index&lt;br /&gt;
after updating the CL index.&lt;br /&gt;
And in case of the MERGE statement, SQL server first acquired U locks&lt;br /&gt;
&lt;u&gt;for both records in the NC index&lt;/u&gt; and did not release them until and of the transaction.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://madebysql.blogspot.com/feeds/7883516134094967268/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://madebysql.blogspot.com/2019/08/update-u-locks-behavior-in-merge.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/7883516134094967268'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5812558148803847895/posts/default/7883516134094967268'/><link rel='alternate' type='text/html' href='http://madebysql.blogspot.com/2019/08/update-u-locks-behavior-in-merge.html' title='UPDATE (U) locks behavior in MERGE statement vs UPDATE statement'/><author><name>Dan Pretselman</name><uri>http://www.blogger.com/profile/15931530494260744354</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='23' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnLaVOoED6yN5E0Y-ntknDOAHHUenmIJgStisl9IAW8R0TXTsdvcbMJds_2FGFRu617xKO3G5rePUHs4d-KEDIbU1RXGuo1YnRoQUgkGmgraH-oOoZsb-0LLtfCMqCNA/s220/DanPretselman.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicojR-756W2HP025ctL4KNSLKRV8dfQYQmgVONCdtZnpUV7VNVD24TQ4-HGOnyd9sch0O22N2WuKmyjZjW0jtWZpqHvqqJOT1aWs0DZ5hi84CYAUpqQIxakC1wKEZzX7JHeEbjwBOyYuk/s72-c/Deadlock+with+U+and+X+Locks.jpg" height="72" width="72"/><thr:total>0</thr:total></entry></feed>