oracle database 12c new features for...

77
© Oren Nakdimon 1 Seminar: Oracle Database Objects Internals Presenter: Oren Nakdimon www.db-oriented.com [email protected] 054-4393763 @DBoriented © Oren Nakdimon

Upload: tranquynh

Post on 10-Mar-2018

219 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

1

Seminar:

Oracle Database Objects Internals

Presenter:

Oren Nakdimon www.db-oriented.com

[email protected]

054-4393763

@DBoriented

© Oren Nakdimon

Page 2: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

2

Who Am I? • Chronology by “Oracle years”

• Today: – Freelance database expert

• Database Administration • Development • Courses

When What Where

Oracle 6/7 1991-1997 Developer IAF

Oracle 8 1997-1998 Server group manager Golden Screens

Oracle 8i/9i 1998-2003 DBA group manager TELEknowledge

Oracle 10g/11g

2004-2011 VP R&D and Israel Site Manager

Olista

“An expert is a person

who has made all the

mistakes that can be

made in a very narrow

field” Niels Bohr (1885-1962)

Page 3: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

3

Agenda

• Database objects and segments

• The storage hierarchy

• Most common segment types

• Other types of tables

• Other types of indexes

• Partitioning

• Advanced features

Page 4: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

4

Segments The Building Blocks

Page 5: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

5

Segments • Segments are objects that consume storage • Segment types

– Table – Table partition – Index – Undo – Temporary – And more…

• A segment may be created as soon as the corresponding object is created (IMMEDIATE) or when it gets data for the first time (DEFERRED, new in version 11.2)

@seg

Page 6: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

6

Oracle Storage Hierarchy The Building Blocks

Page 7: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

7

Storage Hierarchy

• A database contains tablespaces

• Tablespace

– A logical container of segments

– Composed of one or more data files

Page 8: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

8

Storage Hierarchy • A segment is composed of one or more extents • Extent

– A logically contiguous space in a data file – Composed of blocks

• Block – The smallest unit of space allocation in Oracle – Block size is usually 2KB, 4KB, 8KB, 16KB or 32KB – All the blocks within a specific tablespace have the

same size

Page 9: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

9

Storage Hierarchy

Page 10: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

10

Block Structure • Block overhead

– Header • Block type

• Transaction information

• Block address

– Table directory

– Row directory

• Data

• Free space

Page 11: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

11

Heap Organized Tables Most Common Segment Types

Page 12: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

12

Tables

• A table may contain up to 1000 columns and virtually infinite number of rows

• Data (rows) are stored in blocks

• Controlling block usage

– PCTFREE

– PCTUSED

– FREELISTS

– INITRANS @ssm @pct @fl @itl

Page 13: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

13

Tables

• There are 9 major types of tables

• The most common type is Heap Organized Table

Page 14: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

14

Heap Organized Tables

• The default table type

• The location of rows is “random”

• Data is returned in “random” order

• Good for Insert/Update/Delete operations

• What about data retrieval?

@heap

Page 15: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

15

B*Tree Indexes Most Common Segment Types

Page 16: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

16

Indexes

• Supportive objects aimed to quickly locate the data

• There are different types of indexes

• The most common type is B*Tree

Page 17: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

17

B*Tree Indexes

Page 18: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

18

B*Tree Indexes

• 2 kinds of blocks: Branch and Leaf

• Always balanced

• The leaf blocks are doubly linked list

• Controlling block usage

– PCTFREE (relevant only to index creation)

– FREELISTS

– COMPRESS

@ind

Page 19: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

19

Let’s See Some Use Cases Other Types of Tables

Page 20: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

20

Use Case 1a

• PROJECT_EMPLOYEES

– Classic many-to-many relationship

– Usually retrieving all the employees of a specific project

@uc1a1

Page 21: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

21

Index Organized Tables

• IOT is a table stored in an index structure

• Data is sorted by the Primary Key

@uc1a2

Page 22: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

22

Use Case 1b

• PROJECT_EMPLOYEES

– With additional columns

Page 23: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

23

Index Organized Tables

• Some (or all) of the non-primary-key columns may be located in a different segment

– OVERFLOW

• PCTTHRESHOLD

• INCLUDING

@uc1b

Page 24: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

24

Use Case 1c

• PROJECT_EMPLOYEES

– Querying from both sides

Page 25: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

25

Index Organized Tables

• Secondary indexes may be defined

– Using logical rowid

@uc1c

Page 26: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

26

Use Case 2

• PROJ_PROGRESS

– Rows for the same project are added over time

– All rows for the same project are retrieved together

@uc2

Page 27: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

27

Index Organized Tables • IOT is advantageous when

– All the columns are in the primary key

– The table is always accessed by (the leading part of) the primary key

– Co-location of data that arrive randomly is needed

• Disadvantages – Maintaining a B*Tree is more expensive than

maintaining a Heap

– Secondary indexes are somewhat less efficient than on Heap Organized Tables

Page 28: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

28

Use Case 3

• DEPT and EMP

– Department and its employees are usually retrieved together

Page 29: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

29

Cluster Segments

• A cluster stores related data, from one or more tables, in the same block

Page 30: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

30

Cluster Segments

• The storage parameters are defined in the cluster level, not the tables’ level

• SIZE defines the expected size of each cluster key value

• Blocks are chained if the data of a single cluster key value requires more than one block

• Note: in a cluster, rows of different tables may have the same ROWID

Page 31: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

31

Cluster Segments

• Limitations

– No TRUNCATE TABLE

– No partitioning

• There are 3 types of clustered tables

– Index Clustered Tables

– Hash Clustered Tables

– Sorted Hash Clustered Tables

Page 32: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

32

Index Clustered Tables

• The cluster key is indexed by a B*Tree (it’s like the cluster’s primary key)

• The creation order is:

– CREATE CLUSTER with key column(s)

– CREATE INDEX ON CLUSTER

– CREATE TABLE in the cluster

– Optionally, CREATE additional TABLEs in the cluster

@uc3

Page 33: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

33

Index Clustered Tables

• Advantageous when

– Data is mostly read, via indexes, joined frequently

• Disadvantages

– Full table scans read more data than needed

– Wrong SIZE estimation will lead to inefficient storage and/or bad performance

Page 34: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

34

Use Case 4

• PRODUCTS

– Maximum number of products is known

– A product is usually accessed by its ID

Page 35: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

35

Hash Clustered Tables

• The cluster key is hashed to determine the data location

• You can write your own hash function, or use the default one

• Advantages

– Less I/O to get to the data (no index!)

@uc4

Page 36: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

36

Hash Clustered Tables • Restrictions:

– Access by hash works only for equality, not range – Number of hash keys must be set when creating the

cluster (HASHKEYS) – Space is pre-allocated

[HASHKEYS/trunc(blocksize/SIZE) blocks]

• Advantageous when – Maximum number of final rows is known, not many

INSERTs, no UPDATEs of the hash key, access mainly by the hash key value

– For example: lookup tables

Page 37: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

37

Use Case 2b

• PROJ_PROGRESS

– Rows for the same project are added over time

– All rows for the same project are retrieved together ordered by day

Page 38: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

38

Sorted Hash Clustered Tables

• Data is clustered by one key

• Within each cluster key, the data is stored ordered by some other key

• Advantageous when

– Data is usually retrieved by one column value and ordered by another column

– Data arrives sorted over time (by the SORTed column)

@uc2b

Page 39: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

39

Global Temporary Tables Other Types of Tables

Page 40: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

40

Temporary Tables • Hold intermediate resultsets

• Defined once, not in runtime

• The lifetime of the data is either a transaction or a session – ON COMMIT PRESERVE ROWS

– ON COMMIT DELETE ROWS

• The data is visible only to the current session

• Each session has its own temporary segment

@gtt1

Page 41: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

41

Temporary Tables • Temporary tables can have:

– Indexes – Check constraints – Triggers

• Temporary tables cannot: – Have foreign key constraints – Have NESTED TABLE columns – Be Index Organized Tables – Be in a cluster – Be partitioned

Page 42: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

42

Temporary Undo (12c)

• In 12c, undo for temporary tables can be stored in the temporary tablespace

• As a result:

– No redo for undo of DML on temporary tables

– Increased “real” undo retention

– Ability to use temporary tables for read and write in read-only Active Data Guard

• TEMP_UNDO_ENABLED = true | false @utmp

Page 43: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

43

Session Level Sequences (12c)

• A new type of sequence

• Returns a range of numbers which is unique within a session

• Non persistent

@seq

Page 44: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

44

External Tables Other Types of Tables

Page 45: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

45

External Tables

• External tables allow querying from flat files (outside the database)

• The CREATE TABLE statement:

– Defines how to read and parse the file

– Maps the file structure to table columns

• Can be SELECTed just like a regular table (including joins, aggregation, sorting, etc.)

• As of 11g, a preprocessor can be defined @ext1

Page 46: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

46

SQL*Loader Express Mode (12c)

• No need to create a control file

• A log file is generated for future use, including:

– Control file

– CREATE EXTERNAL TABLE statement

– INSERT statement

• Data types of all table columns should be numeric, string or datetime

Page 47: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

47

Bitmap Indexes Other Types of Indexes

Page 48: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

48

Bitmap Indexes • Each index key stores pointers to multiple rows

• Each row is represented as a bit in every indexed value

• Efficient bitwise operations

• Advantageous when

– Low DML activity

– Low/medium cardinality

– High ad-hoc query activity

@bmi

Page 49: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

49

Bitmap-Join Indexes Other Types of Indexes

Page 50: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

50

Bitmap-Join Indexes

• Allows to index one table using columns from another table

@bmj

Page 51: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

51

Partitioning Overview Partitioning

Page 52: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

52

Partitioning

• Partitioning allows to physically break a table or index into many smaller, more manageable pieces

• There is no segment for the table/index itself – each partition has a segment

• Partition Key – used to segregate data based on its values

Page 53: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

53

Partitioning – Advantages

• Increased data availability

• Easier administration of large objects

• Performance improvement of certain queries

• Improved scalability in certain cases

Page 54: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

54

Partitioning Schemes Partitioning

Page 55: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

55

Table Partitioning Schemes

• Range (8)

• Hash (8i)

• List (9i)

• Interval (11g)

Page 56: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

56

Table Partitioning Schemes

• Reference (11g) – the problem

Page 57: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

57

Table Partitioning Schemes

• Reference (11g) – the solution

Page 58: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

58

Table Partitioning Schemes

• Reference + Interval (12c)

Page 59: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

59

Table Partitioning Schemes

• Composite – 2-level partitioning:

– Range-Hash (8i)

– Range-List (9i)

– The other combinations (11g)

• There is no segment for the partition itself – each subpartition has a segment

Page 60: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

60

Partitioning – Composite

Page 61: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

61

Partitioning Indexing Partitioning

Page 62: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

62

Index Partitioning

• Local index

– Each table partition has a corresponding index partition

– Unique local indexes must include the partitioning key

Page 63: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

63

Index Partitioning

• Globally partitioned index

– The index is partitioned by range or hash

– Each index partition may point to several table partitions

Page 64: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

64

Index Partitioning

• Global (non-partitioned) indexes

– May be defined on partitioned tables as well

Page 65: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

65

New Partitioning Features in 12c Partitioning

Page 66: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

66

New Partitioning Features in 12c

• New scheme: reference + Interval

• Asynchronous global index maintenance

• Truncate/exchange partition cascade

• Multiple (sub)partitions in single DDL operations

• Partial indexes

Page 67: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

67

Virtual Columns Advanced Features

Page 68: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

68

Virtual Columns

• Virtual columns are not stored on disk

• Their values are derived on demand by computing expressions or functions

• Can be used in queries and DML statements, but cannot be set in INSERT and UPDATE

• Can be indexed (function based index)

• Can be used as partitioning key

@vc

Page 69: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

69

Invisible Columns Advanced Features

Page 70: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

70

Invisible Columns (12c)

• Invisible columns are invisible, unless explicitly specified

• For example, they will not appear in:

– SELECT * FROM…

– INSERT with no column list

– %ROWTYPE

Page 71: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

71

Invisible Columns

• May be created as invisible

• May be modified from visible to invisible and vice versa

• When an invisible column becomes visible, it appears as the last column of the table

@icol1

Page 72: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

72

Invisible Columns • In SQL*Plus

– SET COLINVISIBLE controls inclusion or exclusion of invisible columns in DESCRIBE

• Invisible columns can be also: – Virtual – Partitioning key

• Cannot contain invisible columns: – External tables – Temporary tables – Clustered tables

@icol2

Page 73: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

73

Virtual Indexes Advanced Features

Page 74: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

74

Virtual Indexes

• A virtual index:

– Has no segment

– Is not maintained by DML

– Is invisible to the optimizer

• Unless “_use_nosegment_indexes” is true

Page 75: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

75

Invisible Indexes Advanced Features

Page 76: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

76

Invisible Indexes

• An invisible index is:

– Maintained by DML

– Invisible to the optimizer

• Unless optimizer_use_invisible_indexes is true

@iind

Page 77: Oracle Database 12c New Features for Developersnakdimon.com/db-oriented/wp-content/uploads/2013/12/Oren...–Table –Table partition –Index –Undo –Temporary –And more… •A

© Oren Nakdimon

80