Home Database Mysql Tutorial Oracle 碎片 优化 一例

Oracle 碎片 优化 一例

Jun 07, 2016 pm 05:11 PM
database

一个客户打过来的,说是碰到一个很奇怪的问题。在一张上千万记录的大表里,做一个SELECT * FROM lt;TAB_NAMEgt; WHERE ROWNUM

一个客户打过来的,说是碰到一个很奇怪的问题。在一张上千万记录的大表里,做一个SELECT * FROM WHERE ROWNUM10分钟后,他通过QQ把TRACE发过来了: SELECT * FROM ttt where rownum

 

call count cpu elapsed disk query currentrows

 ------- ------ -------- ---------- -------------------- ---------- ----------

Parse 1 0.14 0.17 44 198 0 0

Execute 1 0.00 0.00 0 0 0 0

Fetch 8 3.71 5.86 67489 68340 0 99

------- ------ -------- -------------------- ---------- ---------- ----------

total 10 3.85 6.03 67533 68538 0 99

 

从这上面看,确实产生了67533个物理读和68538个逻辑读。执行时间为6.03秒。从等待事件来看:

BINDS #39:

EXEC #39:c=0,e=88,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=1422207486718

WAIT #39: nam='SQL*Net message to client'ela= 7 driver id=1650815232 #bytes=1 p3=0 obj#=206418 tim=1422207486810

WAIT #39: nam='SQL*Net more data to client'ela= 203 driver id=1650815232 #bytes=2002 p3=0 obj#=206418 tim=1422207487071

WAIT #39: nam='SQL*Net more data to client'ela= 66 driver id=1650815232 #bytes=2020 p3=0 obj#=206418 tim=1422207487175

WAIT #39: nam='db file scattered read' ela=515 file#=146 block#=92900 blocks=5 obj#=206418 tim=1422207488208

WAIT #39: nam='db file scattered read' ela=918 file#=146 block#=92905 blocks=8 obj#=206418 tim=1422207489579

WAIT #39: nam='db file scattered read' ela=2121 file#=146 block#=92914 blocks=7 obj#=206418 tim=1422207492091

WAIT #39: nam='db file scattered read' ela=617 file#=146 block#=92921 blocks=8 obj#=206418 tim=1422207493135

WAIT #39: nam='db file scattered read' ela=493 file#=146 block#=92930 blocks=7 obj#=206418 tim=1422207494016

WAIT #39: nam='db file scattered read' ela=1666 file#=147 block#=897417 blocks=8 obj#=206418 tim=1422207496049

WAIT #39: nam='db file scattered read' ela=1026 file#=147 block#=897426 blocks=7 obj#=206418 tim=1422207497350

WAIT #39: nam='db file scattered read' ela=378 file#=147 block#=897433 blocks=8 obj#=206418 tim=1422207498049

WAIT #39: nam='db file scattered read' ela=1075 file#=147 block#=897442 blocks=7 obj#=206418 tim=1422207499416

WAIT #39: nam='db file scattered read' ela=1649 file#=147 block#=897449 blocks=3 obj#=206418 tim=1422207501237

WAIT #39: nam='db file scattered read' ela=2768 file#=147 block#=897453 blocks=4 obj#=206418 tim=1422207504191

WAIT #39: nam='db file scattered read' ela=653 file#=147 block#=897458 blocks=7 obj#=206418 tim=1422207505141

WAIT #39: nam='db file scattered read' ela=1588 file#=147 block#=897465 blocks=8 obj#=206418 tim=1422207507029

WAIT #39: nam='db file scattered read' ela=460 file#=147 block#=897474 blocks=7 obj#=206418 tim=1422207507787

WAIT #39: nam='db file scattered read' ela=608 file#=147 block#=897481 blocks=8 obj#=206418 tim=1422207508697

WAIT #39: nam='db file scattered read' ela=564 file#=147 block#=897490 blocks=7 obj#=206418 tim=1422207509571

WAIT #39: nam='db file scattered read' ela=832 file#=147 block#=897497 blocks=8 obj#=206418 tim=1422207510668

WAIT #39: nam='db file scattered read' ela=846 file#=148 block#=102411 blocks=16 obj#=206418 tim=1422207512030

WAIT #39: nam='db file scattered read' ela=4872 file#=148 block#=102427 blocks=16 obj#=206418 tim=1422207517488

WAIT #39: nam='db file scattered read' ela=1624 file#=148 block#=102443 blocks=16 obj#=206418 tim=1422207520062

确实存在大量的DB FILE SCATTERD READ。这更加坚信了我的观点,表里存在大量的碎片。找第一个SCATTERD READ的参数 file#=146 block#=92900,让客户执行alter system dump datafile 146 block min 92900 block max 92904。

获得的结果如下:

data_block_dump,data header at0x6000000000208e64

===============

tsiz: 0x1f98

hsiz: 0x4c

pbl: 0x6000000000208e64

bdba: 0x24816ae4 76543210

flag=--------

ntab=1

nrow=29

frre=0

fsbo=0x4c

fseo=0xf7

avsp=0x1f4c

tosp=0x1f4c

0xe:pti[0] nrow=29 offs=0

0x12:pri[0] sfll=1

0x14:pri[1] sfll=2

0x16:pri[2] sfll=3

0x18:pri[3] sfll=4

0x1a:pri[4] sfll=5

0x1c:pri[5] sfll=6

0x1e:pri[6] sfll=7

0x20:pri[7] sfll=8

0x22:pri[8] sfll=9

0x24:pri[9] sfll=10

0x26:pri[10] sfll=11

0x28:pri[11] sfll=12

0x2a:pri[12] sfll=13

0x2c:pri[13] sfll=14

0x2e:pri[14] sfll=15

0x30:pri[15] sfll=16

0x32:pri[16] sfll=17

0x34:pri[17] sfll=18

0x36:pri[18] sfll=19

0x38:pri[19] sfll=20

0x3a:pri[20] sfll=21

0x3c:pri[21] sfll=22

0x3e:pri[22] sfll=23

0x40:pri[23] sfll=24

0x42:pri[24] sfll=25

0x44:pri[25] sfll=26

0x46:pri[26] sfll=27

0x48:pri[27] sfll=28

0x4a:pri[28] sfll=-1

block_row_dump:

end_of_block_dump

 

里面全部是空块。建议客户做一个ALTER TABLE

MOVE;表重组后,发现原来12G的表只剩下800M了。再执行这个SQL,只有12个BUFFER GET了:


Statistics

----------------------------------------------------------

1 recursive calls

0 db block gets

12 consistent gets

1 physical reads

0 redo size

18921 bytes sent via SQL*Net to client

558 bytes received via SQL*Net from client

8 SQL*Net roundtrips to/from client

老白的这个小例子很简单,但是从这个例子里可以看到优化的一个流程。遇到SQL 的问题,可以做10046 事件,获取详细的信息,通过trace,分析原因,找到原因后,就可以解决问题,这里发现是碎片的问题,通过Move table 后,表从原来的12G 变成了800M,解决了碎片的问题,SQL 的性能得到提高。

linux

Statement of this Website
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

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

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1670
14
PHP Tutorial
1274
29
C# Tutorial
1256
24
iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to save JSON data to database in Golang? How to save JSON data to database in Golang? Jun 06, 2024 am 11:24 AM

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

How to connect to remote database using Golang? How to connect to remote database using Golang? Jun 01, 2024 pm 08:31 PM

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

See all articles