SQL Server in STATISTICS IO read physical and logical read errors

SQL Server in STATISTICS IO read physical and logical read errors

 

As we all know, SQL Server can use the following command to view the situation a statement read IO

SET STATISTICS IO ON

Then read the results of a physical display of the command, logical read IO unit size is the number, such as results showed

Physical read 1 times

Was a delegate to the hard drive to do it once a physical IO?


Before answering this question, we need to popularize a few common sense

In general default

Windows memory page size is 4KB units

The minimum unit of reading and writing database is 8K page

Windows operating system NTFS file system read and write the smallest unit (assignment unit / cluster) is 4KB

The minimum mechanical hard disk read unit (logical sector and a physical sector) is 512 bytes

Advanced Format: operating system for file system drive is formatted, planning each allocation unit / cluster size, default 4KB

Low-level formatting of: storing the physical storage hardware manufacturers to make low-level format, such as mechanical hard disk, each planning sector size, typically 512 bytes

 

Why is there a disk block / cluster / allocation unit?

Easy to read: Due to a relatively small number of sectors, the number of many difficult when addressed, the operating system will be a combination of adjacent sectors together to form a block, then the overall operation of the block,

Separation dependence on the underlying operating system design ignores the underlying physical storage structure, the concept of virtual disk out blocks, the file system is part of the operating system, file system operations so that the smallest unit is the block file / cluster / dispensing unit

The disk blocks in the Linux file system called ext4 block, called allocation units or clusters in Windows NTFS file system

 

What is paging?

Operating systems often communicate with both memory and hard disk storage device, similar in concept to "block", we need a virtual base unit. So, with the memory operation, it is the concept of a virtual page as the smallest unit. And hard to deal with, is the smallest unit in blocks

SSD because there is no concept of a sector, with the block / page, one block / page typically 4KB, so SSDs do not discuss

 

Let me talk about the conclusion, in fact STATISTICS IO read in the physical and logical reading of the statistics object from beginning to end 8K database page, for example, logical reads 1, physical reads 1, in fact according to 8KB page as a unit, this is the SQL Server statistically software

This will cause misunderstanding, doubt

If the physical read is 1, then the database is to do a disk read and write IO once, right?

If the logic is read once, then the in-memory database is a read-write memory pages once IO, right?

 

The reality is that what is it?

For the case of physical reads

SQL Server is a software running on a Windows system, then this software is stored on the file system data is still in accordance with the rules of the NTFS file system, a storage 8K page needs to occupy two distribution unit

Winhex can use this software to view database mdf file size by 8K can view the complete data of a database page

For the file system, read and write 8KB page requires a database to read and write two distribution unit that is 2 file system IO

Inside the mechanical hard disk, a file system 4KB allocation unit is written to a mechanical hard disk, it is necessary to read and write eight sectors, that is, the IO eight hard disks, and an 8KB pages are written to the database mechanical hard disk, it is necessary to read write 16 sectors, which is actually written to a database page requires 16 hard disk IO

Then there will be some problems, if a system failure or hardware failure, it is not a complete picture of a database page written to the storage hardware that may arise, such as 16 hard disk IO to complete a write 8KB page, and if the writing section 10 IO when a system crash or hardware crashes, data is written to the hard disk only 5KB page, this time the database has incomplete data, and then develop the various database vendors only write [page] integrity checking mechanism, for example,

MySQL InnoDB的Double Write机制(innodb_doublewrite = 1) + page checksum

The checking mechanism MSSQL PAGE

Note: Even with a solid state hard drive, please do not close the page integrity checking function!

Only in the case where the database page, file system allocation unit size consistent mechanical hard disk sector

That is, database , file system , storage devices with minimal reading and writing unit of the same size, the so-called [alignment], you can close the page integrity detection, this time you can get maximum performance

Some file systems, storage devices claim to support so-called atom [write], please keep their eyes open ^ _ ^ check if support is really complete, for some cases, support is indeed true atomic write, for example,

1, the database uses raw device, so that no file system

2, in order to save precious PCIE flash memory as an example, the minimum write unit is its Nand Flash page, the current page Nand Flash size is 32kb, this basically is greater than most common database block size or page size, 32kb can store 4 a MSSQL pages (non-advertising)

 


For the case of logical reads

Windows memory page size units of 4KB, a database page 8KB, then the database to read and write a page in memory actually need to read and write two memory paging

In memory, read and write 8KB page requires a database to read and write two pages of memory, which is memory IO 2

Then 8KB 8KB database pages in memory database page with the file system is one to one, otherwise, the use of B + tree index structure and the binary search method to find the data could take place


to sum up

For the file system, read and write 8KB page requires a database to read and write two distribution unit that is 2 file system IO

For mechanical hard disk, read and write 8KB page requires a database to read and write 16 hard disk sectors that is 16 hard disk IO

For memory, read and write 8KB page requires a database to read and write two pages of memory that is two memory IO

 


SQL Server only run on a Windows operating system software, it can not know nor do they need to know to read and write it the smallest unit in the file system and can not know nor do they need to know the smallest unit of storage devices read and write,

In fact the operating system to read from the file system 8KB page data fed database, then the database will receive STATISTICS IO read as statistical physics 1, logical reads is the same reason as for

Most Finally, put a picture, do more ugly

 

 

 

Reference article
http://www.dostor.com/article/111637957.html
https://blog.csdn.net/qq_34228570/article/details/80209748

 

 

This article belongs to the author, without the author's consent shall not be reproduced.

Guess you like

Origin www.cnblogs.com/lyhabc/p/12670802.html