Professional Documents
Culture Documents
Management Systems
Lecture 5
Algorithms for Query Processing and
Optimization
- Prerequisites
• Database Architecture
• Working with External Data
– Error Handling
– Loading Data
– External Table
2
Oracle Database Architecture
• An Oracle database
server consists of a
database and at least
one database
instance
• Database:
– Physical files
• Instance
– Process and Memory
Management
3
https://docs.oracle.com/en/database/oracle/oracle-database/21/cncpt/introduction-to-oracle-database.html
Multitenant Architecture
• The multitenant architecture enables
an Oracle database to be a CDB
• Every Oracle database must contain or
be able to be contained by another
database.
• CDBs
– contains one or more user-created PDBs
and application containers.
• PDBs
– a portable collection of schemas, schema
objects, and nonschema objects that
appears to an application as a separate
database.
• Application Containers
– An application container is an optional,
user-created container within a CDB that
stores data and metadata for one or more
applications.
4
Sharding Architecture
• Oracle Sharding is a database
scaling technique based on
horizontal partitioning of data
across multiple PDBs. Applications
perceive the pool of PDBs as a
single logical database
• Benefit for OLTP:
– linear scalability
– fault containment
– geographical data distribution
5
Oracle Database (1)
• A collection of data that is treated as a unit
• Consists of Data Files and System Files
• Datafiles: physical files that store the data
• Oracle uses the storage in logical structure
6
https://www.oracle.com/webfolder/technetwork/tutorials/architecture-diagrams/18/technical-architecture/database-technical-architecture.html
Oracle Database (2)
• System files are files that are used during the
operation on an Oracle Database
• Reside on database server
• Belong to the containers
7
Oracle Instance
8
Oracle Process
A process is a mechanism in an operating system
that can run a series of steps.
• Client Process:
– runs the application or Oracle tool code
• Oracle Process
– Server Process:
• Connects to the Oracle instance and is started
when a user establishes a session
– Background Process:
• Started when an Oracle instance is started
9
Oracle Server Process
10
Oracle Background Process
12
Log Writer (LGWR)
• Responsible for:
– Signaling DBWn at
checkpoints
– Updating datafile
headers with
checkpoint
information
– Updating control
files with checkpoint
information (SCN)
14
Memory Structure
15
System Global Area
• The SGA serves various purposes, including the
following:
– Maintaining internal data structures that are accessed by
many processes and threads concurrently
– Caching data blocks read from disk
– Buffering redo data before writing it to the online redo log
files
– Storing SQL execution plans
• The SGA is shared by the Oracle processes,
which include server processes and background
processes
16
SGA components
• Database Buffer Cache
• Redo Log Buffer
• Shared Pool
• Large Pool
• Java Pool
• Fixed SGA
17
Database Buffer Cache
• The memory area that stores
copies of data blocks read from
data files
• Enables great performance gains
when you obtain and update data
• Managed through an LRU
algorithm
• All users concurrently connected
to a database instance share
access to the buffer cache.
• Has 3 states:
– Unused
– Clean
– Dirty
18
Redo Log Buffer
21
Oracle Architecture - Summary
• Oracle Server components
– Database
• Collection of physical files to store the data
• Use Logical structure to use the storage
• Consists of 4 common types:
– Permanent
– Temporary
– Undo
– System
– Instance
• Memory Management
– Shared (SGA) & Private (PGA)
• Process Management
– Client Process and Oracle Process (Server & background)
22
Working with External Data
• External data is data originated from other
resources
• External data access:
– Read externally
– Imported / Loaded internally
• Problems might occur during the reading
process
– Different format
– Low quality of data
– Error
23
External Data Error and Handling (1)
• Data Type
– ‘2’ is this Number of String?
• Data Format
– ’Aug 09 18 09:34:55 PM’ is this a standard format?
• Incompatible Format
– ’Aug 09 18 09:34:55.00 PM’ Unrecognized format
– $95.76 Number that is stored as a text
24
External Data Error and Handling (2)
• Missing Value
• Column Identifier
• Special Characters
25
External Data Error and Handling (3)
• Some preprocessing steps:
– Replace incorrect characters
– Replace the column identifier
– Reformat the data
– Fill the missing values
26
Loading External Data
• Temporarily
– Using External Table
• Permanently
– SQL*Loader
– Oracle Export/Import Utility
27
External Table
• External tables are created using the SQL
CREATE TABLE...ORGANIZATION EXTERNAL
statement.
• Read only
• Can be used in normal SQL statement
• The following attributes must be configured:
– TYPE
– DEFAULT DIRECTORY
– ACCESS PARAMETERS
– LOCATION
https://docs.oracle.com/en/database/oracle/oracle-database/12.2/sutil/oracle-external-tables-concepts.html
28
External Table Example
CREATE DIRECTORY mydir AS 'C:/dataset/dms/';
CREATE TABLE extemp
( employeeid NUMBER(3),
firstname VARCHAR2(30),
lastname VARCHAR2(30),
email VARCHAR2(50),
phone VARCHAR2(20),
hire_date DATE
)
ORGANIZATION EXTERNAL
(TYPE ORACLE_LOADER
DEFAULT DIRECTORY mydir
ACCESS PARAMETERS
(RECORDS DELIMITED BY NEWLINE
SKIP 1
FIELDS TERMINATED BY ","
( employeeid CHAR(3),
firstname CHAR(30),
lastname CHAR(30),
email CHAR(50),
phone CHAR(20),
hire_date CHAR(10) date_format DATE mask "mm/dd/yyyy"
)
)
LOCATION ('extdata.csv') 29
)REJECT LIMIT 5;
External Table Example
30
SQL*Loader
32
SQL*Loader Control File Example
33
SQL*Loader Example
34
SQL Developer - Import Utility
35
Insertion methods (1)
• Insert
– For new tables, the table will be created
• Insert Script
– DML INSERT
• External Table
– DDL for External Table
• Staging External Table
– DDL for External Table with DML
• SQL*Loader
– Script for SQL*Loader
36
Data Import Wizard
37
38
39
40
41
Summary
• Oracle Architecture for performance
• Work with external data source
– Read Only
• External Table
– Permanent
• SQL*Loader
• Import utility
42