You are on page 1of 44

CS 522 - Database Administration Storage Structure and Manage Tables

http://class.svuca.edu/~d.liang/
(dongming.liang@svuca.edu) Silicon Valley University Dr. Dongming Liang

Agenda
Segment types Control block space usage Manage table data Structure of a row

Overview

Segments

Types of Segments - Table


The most commonly used form of storing user data (Heap table) DBA has a very limited control over the distribution of rows Rows can be stored in any order depending on the activity on the table
5

Types of Segments Table Partition


Enable the building of scalable application A partitioned table has one or more partitions Rows can be partitioned using
Range partitioning Hash partitioning, or List partitioning
6

Types of Segments - Cluster


Provides an optional method to store table data A cluster is made up of group of tables that share the same data blocks Share common columns and are often used together
7

Types of Segments - Index


All the entries for a particular index are stored with one index segment. If a table has three indexes, three index segments are used

Types of Segments - IOT


Index-Organized Table (IOT): data is stored within the index based on the key value. An IOT does not need a table lookup, because all the data can be retrieved directly from the index tree Provides fast key-based access to table data
For queries involving exact matches and range searches
9

Types of Segments Index Partitions


An index can be partitioned and spread across several tablespaces. The primary use of a partitioned index is to minimize contention by spreading index I/O.
10

Types of Segments Undo


Used by a transaction that is making changes to a database Before changing the data or index blocks, the old value is stored in the undo segment This allows a user to undo changes made
11

Types of Segments Temporary


When a user executes commands such as CREATE INDEX, SELECT DISTINCT, and SELECT GROUP BY, the Oracle server tries to perform sorts in memory When a sort needs more space than the space available in memory, intermediate results are written to the disk Temporary segments are used to store these intermediate results
12

Types of Segments - LOB


One or more columns in a table can be used to store large objects (LOBs)
Text documents, images, videos

If the column is large, the Oracle server stores these values in separate segments known as LOB segments The table contains only a locator or a pointer to the location of the corresponding LOB data
13

Types of Segments - Bootstrap


Created by sql.bsq script when a database is created
Also known as a cache segment

This segments helps to initialize the data dictionary cache when the database is opened by an instance Bootstrap segment cannot be queried or updated
Does not need any maintenance by DBA
14

Question
Given a table created by Create Table T(
ID number Primary Key, name varchar2(100), phone number, addr varchar2(50), video CLOB); Question: How many segments do you have for this table?
15

Extents

16

Extent Allocation and Deallocation


Allocated when the segment is
Created Extended Altered

Deallocated when the segment is


Dropped Altered Truncated
17

Used and Free Extents


Header: first block in the file Contiguous space used by segment is referred to as a used extent Released extents are added to the pool of free extents
18

Blocks

19

Database Block
Minimum unit of I/O Consists of one or more OS blocks Set at tablespace creation DB_BLOCK_SIZE is the default block size

20

Database Block Contents


Header: block address, table directory, row directory, etc Data: row data Free space: in the middle of the block

21

Manual Data Block Management


Allow you to configure data blocks manually using parameters such as
PCTFREE PCTUSED FREELIST

Only method available in previous Oracle versions


22

Block Space Usage

23

Obtain Storage Information


Data dictionary views
DBA_TABLESPACES DBA_DATA_FILES DBA_SEGMENTS DBA_EXTENTS DBA_FREE_SPACE

24

Example: DBA_Segments
Get # of extents and blocks allocated to a segment

25

Example: DBA_Extents
Check the extents for a given segment

26

Tables

27

Storing User Data


Use different ways to store user data
Regular tables Partitioned tables Index-organized tables Clustered tables

28

Oracle Data Types

29

Long and Lob

30

ROWID
ROWID is a unique identifier for each row in the database ROWID is not stored explicitly as a column value ROWID can be queried along with other columns in a table ROWID provides the fastest means of accessing a row in a table
31

ROWID Format

Data object number is assigned to each data object, such as table or index (unique within the database) Relative file number is unique to each file within a tablespace Block number represents block position Row number identifies row position in a block
32

ROWID Example

33

Structure of a Row
Row data is stored in DB blocks as variable-length records Row header: number of columns, chaining info, and row lock status Row data: column length and value
34

Create a Table

35

Change Storage Parameters

PCTFREE: reserve 30% of each block for updates and allows inserts of new rows to fill a maximum of 70% of each block PCTUSED: a block becomes a candidate for row insertion when its used space falls below 50%
36

Create Temporary Table

Tables retain data only for the duration of a transaction or session DML locks are not acquired on the data DMLs do not generate redo logs Can create indexes, views, and triggers on temporary tables
37

Truncate a Table
Truncate Table employees; Truncating a table deletes all rows in a table and release used space Corresponding indexes are truncated No undo data is generated (it is a DDL)
38

Drop a Table
DROP TABLE departments A table may be dropped if it is no longer needed or if it is to be reorganized

39

Drop a Column
Remove a column from a table

Remove the column length and data from each row, freeing space in the data block Dropping a column in a large table takes a considerable amount of time A checkpoint occurs every 1000 rows
40

Obtain Table Information


Information about tables can be obtained by querying the data dictionary DBA_TABLES DBA_OBJECTS

41

Example: DBA_TABLES

42

Example: DBA_OBJECTS

43

Summary
Segments types Create regular and temporary tables Outline the structure of a row Create/drop/truncate table

44

You might also like