Physical read 比 Logical read還影響效能嗎? - SQL Server

Posted by: Max Chen | in SQL Server | 1 year, 9 months ago |

Physical Read VS Logical Read

The I/O from an instance of the SQL Server Database Engine includes logical and physical reads.

A logical read occurs every time the Database Engine requests a page from the buffer cache.

If the page is not currently in the buffer cache, a physical read first copies the page from disk into the cache.


在算buffer pool命中率的時候有個最一般的公式:

1-physical reads/(db block gets+consistent gets)

這個不是很理解,難道物理讀是邏輯讀的一部分?

我的回答是: 在讀取數據塊的時候,肯定是要對buffer操作,而且要在buffer中尋找這個塊是否存在。

但是要知道有的時候我們要查找的數據塊並不在buffer中,那麼我們就要從磁盤讀取,這個時候就會發生物理讀,即physical reads計數的增加。

在物理讀完成後,只是將我們的所需要的數據塊map到了內存中,Oracle要操作這個塊還是需要進行邏輯讀的。

因此呢,我們可以這樣理解,是邏輯讀帶動了物理讀,邏輯讀包含了物理讀。

所以我们的公式是:

buffer hit=1-physical reads/(db block gets+consistent gets)。

究竟誰比較耗效能?

PhysicalReads:從磁盤讀到Buffer cache數據塊的數量

物理讀是由於在DB_BLOCK_BUFFER中沒有找到需要的數據,需要進行緩衝區的數據置換,物理讀操作是非常消耗系統資源的,應當盡量避免。

所以結論是:

都會耗效能, 但同樣一次讀取, 肯定是Physical比較耗效能, 因為他是從磁碟提取資料.


遇到的狀況是這樣:

  1. 查看活動監視器發現有很多語法使用了大量Physical read 與Logical read(Physical數量 < Logical數量)
  2. 同時間資料庫CPU,IO狀態都非常不好

我知道Physical read直接讀取I/O肯定非常吃效能,但是什麼原因導致的呢?

可能為以下:

  1. buffer cache太小
  2. 執行計劃走直接路徑讀.
  3. 再執行多幾次看看

所以針對Physical read可能的解決方法有可能為:

  1. 調校語法
  2. 增加記憶體
  3. 清除execution plan

為什麼調校語法/加入適當的Index也能改善Physical read呢?

只要加入正確的Index/調校語法…,總之盡可能讓query成本更小,就可以使SQL Server要成功執行此query使用更少的data,因此可以將它完全catche到buffer裡。

如果成本太大,執行query只用catche buffer裡的data不夠用,所以仍然需要到disk去找資料,完成此句query!

Physical read VS Logical read
今天被问到一个问题:在算buffer pool命中率的时候有个最一般的公式: 1-physical reads/(db block gets+consistent gets) 这个不时很理解,难道物理读是逻辑读的一部分? 我的回答是…blog.itpub.net
Physical and Logical Reads in SQL Server
In this article we learn about Query Plan, Physical and Logical Operators, Physical and Logical Reads.vaishaligoilkar3322.medium.com
第二次读为什么physical read 不下降。 - Oracle数据库管理 - ITPUB论坛-中国专业的IT技术社区
第二次读为什么physical read 不下降。 ,ITPUB论坛-中国专业的IT技术社区www.itpub.net
Physical Reads(物理读)和Logical Reads(逻辑读)(转)
现在没得时间去总结,记录一下别人写的有关文章了 这个是关于oracle里的物理读和逻辑读比较清楚的文章 physicalreads> " physicalreads direct + physicalreads cache" Total…blog.csdn.net
How to Reduce the Logical Reads, to imporve the Performance of the Query - SQLServerCentral
How to Reduce the Logical Reads, to imporve the Performance of the Query - Learn more on the SQLServerCentral forumswww.sqlservercentral.com
Why Index-seek is the most costly operator and not the Filter in this plan?
From right to left. SQL Server creates an execution plan, to start at the right hand side. (The side where the data is)…stackoverflow.com
IO Statistics for Index Seek
Does Statistics IO (Logical/Physical Reads) include index pages that are not leaf-level?dba.stackexchange.com
what is logical reads in sql server? how to reduce no of logical?
From Microsoft SQL Server Documentation (Pages and Extents Architecture -> Reading Pages) has a good definition: The…stackoverflow.com
https://dba.stackexchange.com/questions/211700/does-index-rebuild-reduces-physical-read-from-disk

Currently unrated
 or 

Subscribe

* indicates required

Recent Posts

Archive

2023
2022
2021

Categories

Apache 1

Data Science 2

Dbfit 1

Design Pattern 1

Devops 4

DigitalOcean 1

Django 1

English 3

Excel 5

FUN 4

Flask 3

Git 1

HackMD 1

Heroku 1

Html/Css 1

Linux 4

MDX 1

Machine Learning 2

Manufacture 1

Master Data Service 1

Mezzanine 18

Oracle 1

Postgresql 7

PowerBI 4

Powershell 4

Python 22

SEO 2

SQL Server 53

SQL Server Analytics Service 1

SQLite 1

Windows 1

database 8

work-experience 1

其他 1

投資入門 1

投資心得 2

時間管理 1

總體經濟 2

自我成長 3

資料工程 1

Tags

SEO(1) Github(2) Title Tag(2) ML(1) 李宏毅(1) SQL Server(18) Tempdb(1) SSMS(1) Windows(1) 自我成長(2) Excel(1) python Flask(1) python(5) Flask(2)

Authors

Max Chen (159)

Feeds

RSS / Atom

Physical read 比 Logical read還影響效能嗎? - SQL Server

© COPYRIGHT 2011-2022. Max的文藝復興. ALL RIGHT RESERVED.