Comparison of database primary keys INT and STR type efficiency

xiaoxiao2021-03-06  23

Seeing such a word: The primary key will greatly improve the query efficiency, while the comparison overhead of the character type is much larger than the intersive, and the characteristic data is the master key to make the data insert, update and query. The efficiency is reduced. When the amount of data is small, this reduction may not be noted, but when the amount of data is large, the small improvement can improve the response speed of the system. I made an experiment, build two tables Tint and TSTR, Tint {int primary key intValue int} Tstr {Strid Varchar (20)} Both table data respectively For intid = intValue = 1 ~ 300000, strid = strValue = '1' ~ '300000'. The ODBC packaged by MFC is then performed separately, "Select * from tint where intid," select * from tint where intid = 123456 ", crecordset :: readonly; and strrslt.open (CRecordset :: Dynaset," SELECT * from TSTR WHERE Strid = '123456' ", CRecordset :: readonly; one thousand times. Time is 1392 milliseconds and 1452 milliseconds, INTRSLT.OPEN (CRecordset :: Dynaset, "Select * from Tint Where INTVALUE = 123456", CRecordset :: readonly); and Strrslt.open (CRecordset :: Dynaset, "SELECT * FROM Tstr where strval = '123456' ", crecordset :: readonly); one thousand times. Time is 58955 milliseconds and 172227 milliseconds If you create a primary key with MS SQLServer, SQL Server defaults to establish a clustered index, which is rare to locate a data needed to locate a data requirement. Insert or updated operations may result in a large number of data, but this is the same for the INT type and STR. Why is the author say? Now I don't think it is the key to improving the STR-type master key to the INT type is the key to improving the efficiency of the database, which is insignificant than using the database connection pool or optimizes the SQL statement.

转载请注明原文地址:https://www.9cbs.com/read-66207.html

New Post(0)