简单分析Oracle的数据存储
在数据库的存储结构中,我们知道一般来说一个表都存储在对应的数据文件里,数据文件可以分为多个段,一般来说一个表会对应一个数据
在数据库的存储结构中,我们知道一般来说一个表都存储在对应的数据文件里,数据文件可以分为多个段,一般来说一个表会对应一个数据段,单纯考虑数据段的时候,,数据段又可以分为多个区,每个区都可以分为若干个数据块,在操作系统层面,有对应的数据块和数据库层面的数据块有一个映射,可以打个比方来说,一栋大楼里面可以有很多的楼层,每个楼层可能都有不同的公司,这样来考虑,这栋大楼就类似数据文件,楼的每一层就类似一个数据段,每一层比方最多可以有4家公司,一家公司有40个人,有的公司大一点,占用两层,那么就是8个区,320个数据块,有的公司小一点,就占用一层里面的一块,那么这个公司就类似一个较小的数据段,占用1个区,包含40个数据块。
从存储层面来说,目前数据库中只能够查询到区这一级别的信息了。
在user_extents中只能够查看到最基本的区的信息,user_segment里面可以得到一个大体的信息
SQL> desc user_extents
Name Null? Type
----------------------------------------- -------- ----------------------------
SEGMENT_NAME VARCHAR2(81)
PARTITION_NAME VARCHAR2(30)
SEGMENT_TYPE VARCHAR2(18)
TABLESPACE_NAME VARCHAR2(30)
EXTENT_ID NUMBER
BYTES NUMBER
BLOCKS NUMBER
SQL> select extent_id,blocks from user_extents where segment_name='DATA';
EXTENT_ID BLOCKS
---------- ----------
0 8
1 8
2 8
3 8
4 8
5 8
SQL> select extents,blocks from user_segments where segment_name='DATA';
EXTENTS BLOCKS
---------- ----------
6 48
如果想查看每个区中包含哪些数据块,就无能为力了。这个时候dba_extents可以作为一个补充。可以看到哪些区包含哪些数据块。
SQL> select block_id,extent_id,BLOCKS from dba_extents where owner='N1' and segment_name='DATA';
BLOCK_ID EXTENT_ID BLOCKS
---------- ---------- ----------
12800 0 8
12808 5 8
3600 4 8
5224 3 8
12672 2 8
12672 1 8
当然了这个也不能让热满意,有时候想看看一些记录大概占有多大的空间,就可以使用rowid来辅助了。
目前我们得到表data的数据类型如下:
DATA_LENGTH DATA_TYPE
----------- ------------------------------
10 VARCHAR2
22 NUMBER
22 NUMBER
22 NUMBER
22 NUMBER
22 NUMBER
22 NUMBER
22 NUMBER
22 NUMBER
22 NUMBER
SQL> select sum(data_length) from user_tab_cols where table_name='DATA';
SUM(DATA_LENGTH)
----------------
208
那么这些数据类型的数据占用的空间是否是按照最大字节208来存储的呢,换句话说就是表里存放着一条记录,可能长度只有number(2),但是是否会依旧占用22个字节来存储呢。
我们随机抽取一个数据块来简单的测试一下。
可以看到如下两条记录是从0开始计数的,都在12803这个数据块中。
select dbms_rowid.ROWID_OBJECT(rowid) object_id,
dbms_rowid.ROWID_RELATIVE_FNO(rowid) file_no,
dbms_rowid.rowid_row_number(rowid) row_no,
dbms_rowid.rowid_block_number(rowid) blk_number
from data where rownum OBJECT_ID FILE_NO ROW_NO BLK_NUMBER
---------- ---------- ---------- ----------
18993 11 0 12803
18993 11 1 12803
我们来进一步查看12803这个数据块中含有哪些记录。不考虑数据块的其他存储参数。按照默认的值来看。
里面含有约148条记录。

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

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.

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

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

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())

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.

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u

Analysis of the basic principles of the MySQL database management system MySQL is a commonly used relational database management system that uses structured query language (SQL) for data storage and management. This article will introduce the basic principles of the MySQL database management system, including database creation, data table design, data addition, deletion, modification, and other operations, and provide specific code examples. 1. Database Creation In MySQL, you first need to create a database instance to store data. The following code can create a file named "my
