SQL Server execution plan with convert implicit 2

Copyright: copy, please indicate the source https://blog.csdn.net/weixin_39392627/article/details/87918304

env: Windows Server 2016

        SQL Server 2016 SP2

 

The encounter problems as implicit conversion, and the last is to compare different:

Last variable table is declared field data types cause, the cause is physical Table.

The problems encountered in addition to the implicit conversion, as well as the problem of CPU usage.

The largest table has nearly 20 million transactions. On the same server across DB join 4 tables.

 

1. Adjust before execution

message:

Type conversion in expression ([XXXX].[dbo].[XXXX].[XXXX]=CONVERT(nvarchar(512),[XXXX].[dbo].[XXXX].[XXXX],0)) may affect "SeekPlan" in query plan choice, Type conversion in expression ([XXXX].[dbo].[XXXX].[XXXX]=CONVERT(nvarchar(512),[XXXX].[dbo].[XXXX].[XXXX],0)) may affect "SeekPlan" in query plan choice

 

Although the syntax of the query have to use MAXDOP = 4, but you can also lose a lot of the discovery process CPU

 

2. Adjust the table column data type, will be changed to VARCHAR NVARCHAR

command:

ALTER TABLE dbo.TESTTB01 ALTER COLUMN Token NVARCHAR(512) NULL
GO
ALTER TABLE dbo.TESTTB02 ALTER COLUMN Token NVARCHAR(512) NULL
GO

3. Perform syntax again

We only execute select portions will be removed insert into statement.

 

We can find Adjusted CPU no longer need to do a lot of typed conversion. But there is a doubt, the execution time is slightly elongated?

But users can also accept

 

4. that the following data types from the official website of priorities

Data type precedence (Transact-SQL)

NVARCHAR priority than VARCHAR, it will move to VARCHAR NVARCHAR.

Also personally feel can also optimize part is nvarchar (512), which put data is less than nvarchar (100).

 

SQL Server uses the following precedence order for data types:

  1. user-defined data types (highest)
  2. sql_variant
  3. xml
  4. datetimeoffset
  5. datetime2
  6. datetime
  7. smalldatetime
  8. date
  9. time
  10. float
  11. real
  12. decimal
  13. money
  14. smallmoney
  15. bigint
  16. int
  17. smallint
  18. tinyint
  19. bit
  20. ntext
  21. text
  22. image
  23. timestamp
  24. uniqueidentifier
  25. nvarchar (including nvarchar(max) )
  26. nchar
  27. varchar (including varchar(max) )
  28. char
  29. varbinary (including varbinary(max) )
  30. binary (lowest)

 

Guess you like

Origin blog.csdn.net/weixin_39392627/article/details/87918304