Upload
truongthuthuy47
View
222
Download
0
Embed Size (px)
Citation preview
7/27/2019 A09 Tables
1/44
CS 522 - Database Administration
Storage Structure and Manage
Tables
Dr. Dongming Liang
http://class.svuca.edu/~d.liang/([email protected])
Silicon Valley University
7/27/2019 A09 Tables
2/44
2
Agenda
Segment types
Control block space usage
Manage table data
Structure of a row
7/27/2019 A09 Tables
3/44
3
Overview
7/27/2019 A09 Tables
4/44
4
Segments
7/27/2019 A09 Tables
5/44
5
Types of Segments - Table
The most commonly used formof storing user data (Heap table)
DBA has a very limited controlover the distribution of rows
Rows can be stored in any order
depending on the activity on thetable
7/27/2019 A09 Tables
6/44
6
Types of Segments Table Partition
Enable the building of scalableapplication
A partitioned table has one or
more partitionsRows can be partitioned using Range partitioning
Hash partitioning, or
List partitioning
7/27/2019 A09 Tables
7/44
7
Types of Segments - Cluster
Provides an optional method tostore table data
A cluster is made up of groupof tables that share the samedata blocks
Share common columns andare often used together
7/27/2019 A09 Tables
8/44
8
Types of Segments - Index
All the entries for aparticular index are storedwith one index segment.
If a table has three indexes,three index segments are
used
7/27/2019 A09 Tables
9/44
9
Types of Segments - IOT
Index-Organized Table (IOT): datais stored within the index based onthe key value.
An IOT does not need a tablelookup, because all the data can beretrieved directly from the index tree
Provides fast key-based access to
table data For queries involving exact matches
and range searches
7/27/2019 A09 Tables
10/44
10
Types of Segments Index Partitions
An index can be partitioned andspread across severaltablespaces.
The primary use of apartitioned index is to minimize
contention by spreading indexI/O.
7/27/2019 A09 Tables
11/44
11
Types of Segments Undo
Used by a transaction that is makingchanges to a database
Before changing the data or index
blocks, the old value is stored in theundo segment
This allows a user to undo changesmade
7/27/2019 A09 Tables
12/44
12
Types of Segments Temporary
When a user executes commands suchas CREATE INDEX, SELECT DISTINCT,and SELECT GROUP BY, the Oracle
server tries to perform sorts in memoryWhen a sort needs more space than the
space available in memory, intermediate
results are written to the diskTemporary segments are used to store
these intermediate results
7/27/2019 A09 Tables
13/44
13
Types of Segments - LOB
One or more columns in a table can beused to store large objects (LOBs) Text documents, images, videos
If the column is large, the Oracleserver stores these values in separatesegments known as LOB segments
The table contains only a locator or apointer to the location of thecorresponding LOB data
7/27/2019 A09 Tables
14/44
14
Types of Segments - Bootstrap
Created by sql.bsq script when a database iscreatedAlso known as a cache segment
This segments helps to initialize the datadictionary cache when the database isopened by an instance
Bootstrap segment cannot be queried or
updated Does not need any maintenance by DBA
7/27/2019 A09 Tables
15/44
15
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?
7/27/2019 A09 Tables
16/44
16
Extents
7/27/2019 A09 Tables
17/44
17
Extent Allocation andDeallocation
Allocated when the segment is Created
Extended
AlteredDeallocated when the segment is Dropped
Altered
Truncated
7/27/2019 A09 Tables
18/44
18
Used and Free Extents
Header: first block inthe file
Contiguous space
used by segment isreferred to as aused extent
Released extents areadded to the pool offree extents
7/27/2019 A09 Tables
19/44
19
Blocks
7/27/2019 A09 Tables
20/44
20
Database Block
Minimum unit of I/OConsists of one or more OS blocks
Set at tablespace creation
DB_BLOCK_SIZE is the default blocksize
7/27/2019 A09 Tables
21/44
21
Database Block Contents
Header: block address,table directory, rowdirectory, etc
Data: row data
Free space: in the
middle of the block
7/27/2019 A09 Tables
22/44
22
Manual Data Block Management
Allow you to configure data blocksmanually using parameters such as
PCTFREE
PCTUSED
FREELIST
Only method available in previousOracle versions
7/27/2019 A09 Tables
23/44
23
Block Space Usage
7/27/2019 A09 Tables
24/44
24
Obtain Storage Information
Data dictionary views DBA_TABLESPACES
DBA_DATA_FILES
DBA_SEGMENTS
DBA_EXTENTS
DBA_FREE_SPACE
7/27/2019 A09 Tables
25/44
25
Example: DBA_Segments
Get # of extents and blocks allocatedto a segment
7/27/2019 A09 Tables
26/44
26
Example: DBA_Extents
Check the extents for a given segment
7/27/2019 A09 Tables
27/44
7/27/2019 A09 Tables
28/44
28
Storing User Data
Use different ways tostore user data
Regular tables
Partitioned tables Index-organized tables
Clustered tables
7/27/2019 A09 Tables
29/44
29
Oracle Data Types
7/27/2019 A09 Tables
30/44
30
Long and Lob
7/27/2019 A09 Tables
31/44
31
ROWID
ROWID is a unique identifier for eachrow in the database
ROWID is not stored explicitly as a
column valueROWID can be queried along with
other columns in a table
ROWID provides the fastest means ofaccessing a row in a table
7/27/2019 A09 Tables
32/44
32
ROWID Format
Data object number is assigned to each dataobject, such as table or index (unique withinthe database)
Relative file number is unique to each file
within a tablespaceBlock number represents block positionRow number identifies row position in a block
7/27/2019 A09 Tables
33/44
33
ROWID Example
7/27/2019 A09 Tables
34/44
34
Structure of a Row
Row data is stored in DBblocks as variable-lengthrecords
Row header: number ofcolumns, chaining info,and row lock status
Row data: columnlength and value
7/27/2019 A09 Tables
35/44
35
Create a Table
7/27/2019 A09 Tables
36/44
36
Change Storage Parameters
PCTFREE: reserve 30% of each block forupdates and allows inserts of new rows to filla maximum of 70% of each block
PCTUSED: a block becomes a candidate forrow insertion when its used space falls below50%
7/27/2019 A09 Tables
37/44
37
Create Temporary Table
Tables retain data only for the duration of atransaction or session
DML locks are not acquired on the data
DMLs do not generate redo logs
Can create indexes, views, and triggers ontemporary tables
7/27/2019 A09 Tables
38/44
38
Truncate a Table
Truncate Table employees;
Truncating a table deletes all rows in atable and release used space
Corresponding indexes are truncated
No undo data is generated (it is a DDL)
7/27/2019 A09 Tables
39/44
39
Drop a Table
DROP TABLE departments
A table may be dropped if it is nolonger needed or if it is to bereorganized
7/27/2019 A09 Tables
40/44
40
Drop a Column
Remove a column from a table
Remove the column length and data fromeach row, freeing space in the data block
Dropping a column in a large table takes aconsiderable amount of time
A checkpoint occurs every 1000 rows
7/27/2019 A09 Tables
41/44
41
Obtain Table Information
Information about tables can beobtained by querying the datadictionary
DBA_TABLES
DBA_OBJECTS
7/27/2019 A09 Tables
42/44
42
Example: DBA_TABLES
7/27/2019 A09 Tables
43/44
43
Example: DBA_OBJECTS
7/27/2019 A09 Tables
44/44
44
Summary
Segments typesCreate regular and temporary tables
Outline the structure of a row
Create/drop/truncate table