search
HomeDatabaseMysql TutorialSQL Server 2008 Enhancements to Handling Implicit Data Type Conversions in Execution Plans

Verified by the following test, first establish a test table with uneven data distribution.

USE tempdb
GOCREATE TABLE _t(
    c varchar(50)
);CREATE INDEX IX_c ON _t( c );GO-- 加入 10000 条数据INSERT _tSELECT (9999 + id) FROM(    SELECT TOP 10000 id = ROW_NUMBER() OVER( ORDER BY GETDATE() )    FROM sys.all_columns a, sys.all_columns
)ID
-- 将 100 - 10000 的数据变成相同值UPDATE _t SET c = '' WHERE c >= '10100'

Then use the varhcar and nvarchar values ​​to test the estimated number of rows in the execution plan that satisfy 1 condition and 8900 conditions respectively.

ALTER INDEX IX_c ON _t REBUILD;GOSET SHOWPLAN_ALL ONGOSELECT * FROM _t WHERE c = '10005';     -- 实际1条GOSET SHOWPLAN_ALL OFF;GOALTER INDEX IX_c ON _t REBUILD;GOSET SHOWPLAN_ALL ONGOSELECT * FROM _t WHERE c = N'10005';     -- 实际1条GOSET SHOWPLAN_ALL OFF;GOALTER INDEX IX_c ON _t REBUILD;GOSET SHOWPLAN_ALL ONGOSELECT * FROM _t WHERE c = '';          -- 实际9900条GOSET SHOWPLAN_ALL OFF;GOALTER INDEX IX_c ON _t REBUILD;GOSET SHOWPLAN_ALL ONGOSELECT * FROM _t WHERE c = N'';         -- 实际9900条GOSET SHOWPLAN_ALL OFF;GO

The estimated number of rows in the obtained query plan is shown in the figure below

SQL Server 2008 Enhancements to Handling Implicit Data Type Conversions in Execution Plans

It can be seen from the estimated number of data rows displayed in the figure , for varchar values ​​(no hidden data type conversion required), the estimated results are accurate. But for the nvarchar value, no matter whether the specified value has only one piece of data or 8900 data matching, the estimated result is 99.0099, which shows that the estimate does not take into account the value we specified.
Further testing with variables

ALTER INDEX IX_c ON _t REBUILD;GOSET SHOWPLAN_ALL ONGODECLARE @v varchar;SELECT * FROM _t WHERE c = @v; -- varcharGOSET SHOWPLAN_ALL OFF;GOALTER INDEX IX_c ON _t REBUILD;GOSET SHOWPLAN_ALL ONGODECLARE @nv nvarchar;SELECT * FROM _t WHERE c = @nv; -- nvarcharGOSET SHOWPLAN_ALL OFF;GO

The results are as shown below:
SQL Server 2008 Enhancements to Handling Implicit Data Type Conversions in Execution Plans

Whether it is a varchar or nvarchar variable, the estimated number of rows is It is 99.0099. This value is the same as the result of using nvarchar constant value. It seems that the SQL Server query optimizer should indeed treat the result of GetRangeThroughConvert as a variable. This should be a poorly considered design consideration. After all, a fixed constant value is specified. When , the result of GetRangeThroughConvert should also be a certain value.

This article explains the relevant content of SQL Server. For more related content, please pay attention to the php Chinese website.

Related recommendations:

How to implement infinite-level parent-child relationship query in a single sentence in MySQL

SQL Server FileStream with progress How to access

What to do if you forget your SQL Server administrator password


The above is the detailed content of SQL Server 2008 Enhancements to Handling Implicit Data Type Conversions in Execution Plans. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment