


SQL 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
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:
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!

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

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

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

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

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'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

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

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


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
