Getting to Know Oracle DatabaseObjects IOT, Mviews, Clusters andmore…Aaron Shilo, CEOaaron@DBCS.co.ilOracle Certified Prof...
* 34 years old* Married + 3* 10 years AS a dba consultant instructor architect.* Was cto @ johnbryce israel* Oracle certif...
Agenda• What are segments ?• IOT – What are Index-Organized Tables?• Virtual Indexes• LOB• Materialized Views - Also known...
Data Storage StructuresCluster Index-organizedtableHeap tablePartitionedtable
What are database objects ?Database objects as we know them are a logical mapping for a segmentsSegments are space-occupyi...
Types of segmentsTableA table is the most common means of storing data within a database. A table segment stores thatdata ...
Types of Segments(continued)ClusterA cluster, like a table, is a type of data segment. Rows in a cluster are stored based ...
Types of Segments(continued)Index-Organized TableIn an index-organized table, data is stored within the index based on the...
Types of Segments(continued)Materialized Views (AKA snapshots)A materialized view (MV) stores both the definition of a vie...
Why use different segment types?Im often asked "when or why should I use an IOT ,MVIEWS ,CLUSTERS etc… ?".Well all of the ...
Index organized table (IOT)Compared to heap tables, IOTs have:Faster key-based access to table dataReduced storage require...
Why IOT ?Faster Index AccessIndex-organized tables provide faster access to table rows by the primary key. Also, since row...
Increased ScalabilityIndex-organized tables are highly scalable because of their support for partitioning and parallel ope...
Demo IOT
Virtual IndexesVirtual Indexes are another undocumented feature used by Oracle. Virtual indexes, as the name suggests are ...
A virtual index is created in a slightly different manner than the normal indexes. A virtual index has no segmentpegged to...
1. These are permanent and continue to exist unless we drop them.2. Their creation will not affect existing and new sessio...
Virtual IndexesConsider the following analysed tableCREATE TABLE t1 ASSELECT * FROM dba_objectsWHERE ROWNUM < 1000;ANALYZE...
Virtual IndexesThe statementSELECT object_id FROM t1WHERE owner = USER AND object_name = T1;ALTER SESSION SET "_use_nosegm...
Demo Virtual Indexes
Table clusterA cluster is a group of one or more tables that share the same data blocks because they share commoncolumns a...
Performance and clustersPerformance Benefits of ClustersDisk I/O is reduced and access time improved for joins of clustere...
guidelines for clustersChoose Appropriate Tables for the ClusterUse clusters for tables for which the following conditions...
Creating ClustersYou create a cluster using the CREATE CLUSTER statement. The following statement creates a clusternamed e...
Demo clusters
Table partitionsPartitioning addresses key issues in supporting very large tables and indexes by letting you decomposethem...
Partitioning advantagesPartitioning enables data management operations such data loads, index creation and rebuilding, and...
Range PartitioningRange partitioning maps data to partitions based on ranges of partition key values that youestablish for...
List PartitioningList partitioning enables you to explicitly control how rows map to partitions. You do this byspecifying ...
Hash PartitioningHash partitioning enables easy partitioning of data that does not lend itself to range or listpartitionin...
Partitioned IndexesJust like partitioned tables, partitioned indexes improve manageability, availability, performance, and...
Local Partitioned IndexesLocal partitioned indexes are easier to manage than other types of partitioned indexes. They also...
Global Partitioned IndexesGlobal partitioned indexesare flexible in that the degree of partitioning and the partitioning k...
Global Nonpartitioned IndexesGlobal nonpartitioned indexesbehave just like a nonpartitioned index.They are commonly used i...
partition pruningThe Oracle server explicitly recognizes partitions and subpartitions. It then optimizes SQL statements to...
Demo Partitions
External Tables ConceptsThe Oracle9i external tables feature is a complement to existing SQL*Loaderfunctionality. It allow...
Benefits of External TablesProvide a valuable means for performing basic extraction, transformation, and loading (ETL)Are ...
External TablesSELECT *FROM ex_table;OS fileExternaltable
External Table Population: OverviewUnload data to external flat filesHandle complex ETL situationsFlat files(Proprietary f...
External Table Population OperationUses the ORACLE_DATAPUMP access driverData cannot be modified.Resulting files can be re...
External Table Parallel PopulateOperationMultiple files can be created.Exactly one parallel execution server per fileThe P...
External Table Population: ExampleCREATE TABLE emp_ext(first_name, last_name, department_name)ORGANIZATION EXTERNAL(TYPE O...
External Table Projected Columns2355,1,2289,46,2002355,A,2264,50,100SELECT COUNT(order_id)FROM order_items_ext;SELECT COUN...
ALTER TABLE order_items_extPROJECT COLUMN {ALL|REFERENCED};SELECT propertyFROM DBA_EXTERNAL_TABLESWHERE table_name = ORDER...
Demo externaltable
Materialized ViewsMaterialized views are schema objects that can be used to summarize, compute, replicate, anddistribute d...
query rewriteMaterialized views improve query performance by precalculating expensive join and aggregationoperations on th...
Query rewrite requirementsEven though a materialized view is defined, it will not automatically be used by the query rewri...
Refresh mviewWhen you define a materialized view, you can specify two refresh options: how to refresh and what type of ref...
Mview logWhen DML changes are made to master table data, Oracle Database stores rows describing thosechanges in the materi...
Create Materialized viewSimple mview : is a mview that is used for direct query and has no fast refresh option or query re...
DimensionsA dimension object defines hierarchical (parent/child) relationships between pairs of column sets, where all the...
DimensionsData dictionary structuresDefine hierarchies between pairs of column setsSuperset of referential constraints:Nor...
Dimensions and HierarchiesHierarchyDay nameMonth nameQuarterdescriptionDays in quarterDayAllAttributes:YearQuarterMonthFis...
Dimensions: Example TableSQL> SELECT time_id day2 , calendar_month_desc month3 , calendar_quarter_desc quarter4 , calendar...
Dimensions and Hierarchies- YEAR- QUARTER- MONTH- DAYTIMES table columns TIMES_DIM dimension- DAY_NAME- CALENDAR_MONTH_NAM...
Creating Dimensions and HierarchiesSQL> CREATE DIMENSION times_dim2 LEVEL day IS TIMES.TIME_ID3 LEVEL month IS TIMES.CALEN...
Demo materialized view
Large Objects - LOBAs applications evolve to encompass increasingly richer semantics, they encounter the need to deal with...
Unstructured DataUnstructured Data Cannot be Decomposed Into Standard ComponentsUnstructured data cannot be decomposed int...
Large Objects - LOBBLOB - binary data that can be extended to 4 GBCLOB - character data up to 4 GBNCLOB - stores CLOB data...
Demo LOB
A TipShrinking Segments
Shrinking Segments: Considerations• Online and in-place operation• Applicable only to segments residing in ASSM tablespace...
Shrinking Segments: OverviewHWMHWMShrinkoperationDataUnusedspaceDataUnusedspaceReclaimed space
Shrinking Segments Using SQLALTER TABLE employees SHRINK SPACE CASCADE;ALTER … SHRINK SPACE [CASCADE]TABLE INDEX MATERIALI...
Segment Shrink: Basic ExecutionHWMALTER TABLE employees SHRINK SPACE COMPACT;HWMHWMALTER TABLE employees SHRINK SPACE;12
Segment Shrink:Execution Considerations•Use compaction only:•Avoid unnecessary cursor invalidation•During peak hours•DML o...
Demo Shrink
Aaron Shilo, CEOOracle Certified ProfessionalMicrosoft certified technology specialistContact Me :Aaron@DBCS.co.ilwww.DBCS...
Getting to know oracle database objects iot, mviews, clusters and more…
Upcoming SlideShare
Loading in …5
×

Getting to know oracle database objects iot, mviews, clusters and more…

785 views

Published on

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
785
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
37
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Getting to know oracle database objects iot, mviews, clusters and more…

  1. 1. Getting to Know Oracle DatabaseObjects IOT, Mviews, Clusters andmore…Aaron Shilo, CEOaaron@DBCS.co.ilOracle Certified ProfessionalMicrosoft certified technologyspecialist
  2. 2. * 34 years old* Married + 3* 10 years AS a dba consultant instructor architect.* Was cto @ johnbryce israel* Oracle certified professional* Microsoft sql server certified professional* Today I lead a Database solution service company, DBCS LTD.* Consultant for Tapuz , bezeq int, cbs , pontis , traffilog, Super-Sal and more.
  3. 3. Agenda• What are segments ?• IOT – What are Index-Organized Tables?• Virtual Indexes• LOB• Materialized Views - Also known as snapshots in prior releases• Clusters• External Tables• Partitions• Partition Pruning• Partition-wise Joins• Manageability• Oracle11g New Features• External tables (ETL)• Segment space management (Shrink and defragment)
  4. 4. Data Storage StructuresCluster Index-organizedtableHeap tablePartitionedtable
  5. 5. What are database objects ?Database objects as we know them are a logical mapping for a segmentsSegments are space-occupying objects in a database.They use space in the data files of a database.Segments are made out of extentsExtents are made out of blocksBlocks are the smallest unit of I/O in the databaseA segment is a database object physical storage facilityOf a table/index/cluster etc…Dba uses the segments in order to managegood space utilization of data.
  6. 6. Types of segmentsTableA table is the most common means of storing data within a database. A table segment stores thatdata for a table. Data within a table segment is stored in no particular order, and the databaseadministrator (DBA) has very little control over the location of rows within the blocks in a table. Allthe data in a table segment must be stored in one tablespace.Table partitionScalability and availability are major concerns when there is a table in a database with highconcurrent usage. In such cases, data within a table may be stored in several partitions, each ofwhich resides in a different tablespace. If a table is partitioned, each partition is a segment, andthe storage parameters can be specified to control them independently.TableTablepartition
  7. 7. Types of Segments(continued)ClusterA cluster, like a table, is a type of data segment. Rows in a cluster are stored based on key columnvalues. A cluster may contain one or more tables. Tables in a cluster belong to the same segmentand share the same storage characteristics. The rows in a clustered table can be accessed with anindex or hashing algorithm.IndexAll the entries for a particular index are stored within one index segment. If a table has threeindexes, three index segments are used. The purpose of this segment is to look up the location ofrows in a table based on a specified key.ClusterIndex
  8. 8. Types of Segments(continued)Index-Organized TableIn an index-organized table, data is stored within the index based on the key value. An index-organized table does not need a table lookup, because all the data can be retrieved directly fromthe index tree.Index-organizedtable
  9. 9. Types of Segments(continued)Materialized Views (AKA snapshots)A materialized view (MV) stores both the definition of a view and the rows resulting from theexecution of the view. Like a view, it uses a query as the basis, but the query is executed at thetime the view is created and the results are stored in a table. You can define the table with thesame storage parameters as any other table and place it in the tablespace of your choice.When a query can be satisfied with data in a materialized view, the server transforms the query toreference the view rather than the base tables. By using a materialized view, expensive operationssuch as joins and aggregations do not need to be re-executed; instead the statement is rewrittento query the materialized view.Materialized view
  10. 10. Why use different segment types?Im often asked "when or why should I use an IOT ,MVIEWS ,CLUSTERS etc… ?".Well all of the above are used to reduce I/O (consistent gets and physical reads) by making the SQL moreefficient.For example The SQL become more efficient on an IOT and a cluster table because less access is required to gatall of the data to satisfy the request.Experienced Oracle DBAs know that I/O is often the single greatest component of response time and regularlywork to reduce I/O. Disk I/O is expensive because when Oracle retrieves a block from a data file on disk, thereading process must wait for the physical I/O operation to complete.Disk operations are about 10,000 times slower than a rows access in the data buffers (in Oracle, about 100xfaster due to latch overhead). Consequently, anything you can do to minimize I/O or reduce bottlenecks causedby contention for files on disk-greatly improves the performance of any Oracle database.
  11. 11. Index organized table (IOT)Compared to heap tables, IOTs have:Faster key-based access to table dataReduced storage requirementsSecondary indexes and logical rowidsIOTs have the following restrictions:Must have a primary keyCannot be clusteredcreate table country( country_id char(2) constraintcountry_id_nn not null,country_name varchar2(40),currency_namevarchar2(25),currency_symbol varchar2(3),map blob, flagblob,constraint country_c_id_pk primary key(country_id))organization index tablespace index ;Non-key columnsKey columnRow header
  12. 12. Why IOT ?Faster Index AccessIndex-organized tables provide faster access to table rows by the primary key. Also, since rows are storedin primary key order, range access by the primary key involves minimum block accesses. In order to alloweven faster access to frequently accessed columns, the row overflow storage option can be used to pushout infrequently accessed non-key columns from the B-tree leaf bloc k to an optional overflow storagearea. This limits the size and content of the row portion actually stored in the B-tree leaf block, resultingin a smaller B-tree and faster access.Reduced StorageIndex-organized tables maintain a single storage structure -- the B-tree index. Primary key column valuesare stored only in the B-tree ind ex and not duplicated in the table and index as happens in aconventional heap-organized table. Because rows of an index-organized table are stored in primary keyorder, a significant amount of additional storage space savings can be obtained throug h the use of keycompression.Increased 24x7 AvailabilityIndex-organized tables identify rows using logical ROWIDs based on the primary key. The use of logicalROWIDs enables online reorganization and also does not affect the secondary indexes which remain validand usable after the reorganization. This capability reduces or eliminates the downtime forreorganization of secondary indexes, making index-organized tables beneficial for 24x7 applications.
  13. 13. Increased ScalabilityIndex-organized tables are highly scalable because of their support for partitioning and parallel operations.Range partitioned and hash partitioned index-organized tables as well as LOB columns in partitioned index-organized tables are supported. Parallel query and parallel DML are also supported. Queries on index-organizedtables including partitioned ones use the cost-based optimizer for generating optimal execution flow.Easy to Use AND Fully FunctionalApplications manipulate the index-organized table just like an ordinary table via standard SQL statements. AllOracle programmatic interfaces including PL/SQL, OCI, and JDBC can access index-organized tables. The fullcomplement of Oracle utilities and tools are supported including the SQL*Loader (both conventional and directpath), IMPORT/EXPORT, and transportable tablespace support for point-in-time recovery operations using theOracle Recovery Manager (RMAN).Index organized tables support the standard features available with conventional tables -- secondary indexes,constraints, triggers, composite columns, object and REF columns, and LOB columns. Key compression issupported on secondary indexes and the index-organized table as it is itself stored in an in dex. An index-organized table can also be used as an object table and can be replicated. From the perspective of security,administration, and tools, index-organized tables are treated in the same fashion as conventional tables.Why IOT ?
  14. 14. Demo IOT
  15. 15. Virtual IndexesVirtual Indexes are another undocumented feature used by Oracle. Virtual indexes, as the name suggests are pseudo-indexes that will not behave the same way that normal indexes behave, and are meant for a very specific purpose.The virtual index wizard functionality allows the user to test a potential new index prior to actually building the newindex in the database. It allows the CBO to evaluate the potential new index for a selected SQL statement by buildingan explain plan that is aware of the potential new index. This allows the user to determine if the optimizer would usethe index, once implemented.I do not see much use of Virtual Indexes in a development area where we can create and drop indexes while testing.However, this feature could prove handy if a query or group of queries have to be tested in production (for want ofsimulation or urgency!), to determine if a new index will improve the performance, without impacting existing or newsessions.
  16. 16. A virtual index is created in a slightly different manner than the normal indexes. A virtual index has no segmentpegged to it, i.e., the DBA_SEGMENTS view will not show an entry for this. Oracle handles such indexes internally andfew required dictionary tables are updated so that the optimizer can be made aware of its presence and generate anexecution plan considering such indexes.Effectiveness of new indexes can be tested by generating theoretical execution plansThe CBO will consider virtual indexes if the hidden parameter _use_nosegment_indexes is set to true
  17. 17. 1. These are permanent and continue to exist unless we drop them.2. Their creation will not affect existing and new sessions. Only sessions marked forVirtual Index usage will become aware of their existence.3. Such indexes will be used only when the hidden parameter "_use_nosegment_indexes"is set to true.4. The Rule based optimizer did not recognize Virtual Indexes when I tested, however,CBO recognizes them. In all of my examples, I have used CBO. However, I did not carryout intensive testing in RBO and you may come across exceptions to this view.5. Dictionary view DBA_SEGMENTS will not show an entry for Virtual Indexes. The tableDBA_INDEXES and DBA_OBJECTS will have an entry for them in Oracle 8i; in Oracle 9ionwards, DBA_INDEXES no longer show Virtual Indexes.6. Virtual Indexes cannot be altered and throw a "fake index" error!7. Virtual Indexes can be analyzed, using the ANALYZE command or DBMS_STATS package,but the statistics cannot be viewed (in Oracle 8i, DBA_INDEXES will not show thiseither). Oracle may be generating artificial statistics and storing it somewhere forreferring it later.attributes of the Virtual Indexes.
  18. 18. Virtual IndexesConsider the following analysed tableCREATE TABLE t1 ASSELECT * FROM dba_objectsWHERE ROWNUM < 1000;ANALYZE TABLE t1 COMPUTE STATISTICS;CREATE INDEX i1 ON t1 (owner, object_name) NOSEGMENT;EXECUTE DBMS_STATS.GENERATE_STATS (USER,I1);• A virtual index can be created using the NOSEGMENT keyword• Statistics must be generated for the new index based on the existing statistics forthe table
  19. 19. Virtual IndexesThe statementSELECT object_id FROM t1WHERE owner = USER AND object_name = T1;ALTER SESSION SET "_use_nosegment_indexes" = TRUE;SELECT STATEMENT Optimizer = CHOOSETABLE ACCESS (FULL) OF T1SELECT STATEMENT Optimizer = CHOOSETABLE ACCESS (BY INDEX ROWID)INDEX (RANGE SCAN) OF I1• generates the plan• the same statement generates a different plan• With the hidden parameter enabled
  20. 20. Demo Virtual Indexes
  21. 21. Table clusterA cluster is a group of one or more tables that share the same data blocks because they share commoncolumns and are often used together in join queries. Storing tables in clusters offers the DBA a method todenormalize data. Clusters are transparent to the end user and programmer.If this customer has eight orders, each on a different data block, we must perform nine blockfetches to return the query rows. Even if these blocks are already cached in the data buffers, westill have at least nine consistent gets:If we re-define the table as a index cluster table, Oracle will physically store the orders rows on thesame data block as the parent customer row,thereby reducing I/O by a factor of eight:
  22. 22. Performance and clustersPerformance Benefits of ClustersDisk I/O is reduced and access time improved for joins of clustered tables.Each cluster key value is stored only once for all the rows of the same key value; it thereforeuses less storage space.When Not to Use ClustersIf a full scan is executed often on one of the clustered tables: This table is stored on moreblocks than if it had been created alone.If the data for all rows of a cluster key value exceeds one or two Oracle blocks: To access anindividual row in a clustered key table, the Oracle server reads all blocks containing rowswith the same value.Full table scans are generally slower on clustered tables than on nonclustered tables.
  23. 23. guidelines for clustersChoose Appropriate Tables for the ClusterUse clusters for tables for which the following conditions are trueThe tables are primarily queried--that is, tables that are not predominantly inserted into orupdatedRecords from the tables are frequently queried together or joinedChoose Appropriate Columns for the Cluster KeyChoose cluster key columns carefully. If multiple columns are used in queries that join the tables,make the cluster key a composite key. In general, the characteristics that indicate a good clusterindex are the same as those for any index.A good cluster key has enough unique values so that the group of rows corresponding to each keyvalue fills approximately one data block. Having too few rows for each cluster key value can wastespace and result in negligible performance gains.Cluster keys that are so specific that only a few rows share a common value can cause wastedspace in blocks, unless a small SIZE was specified at cluster creation time.Too many rows for each cluster key value can cause extra searching to find rows for that key.Cluster keys on values that are too general (for example, male and female) result in excessivesearching and can result in worse performance than with no clustering.
  24. 24. Creating ClustersYou create a cluster using the CREATE CLUSTER statement. The following statement creates a clusternamed emp_dept which stores the emp and dept tables, clustered by the deptno columnYou create a table in a cluster using the CREATE TABLE statement with the CLUSTER option. The emp anddept tables can be created in the emp_dept cluster using the following statements:A cluster index must be created before any rows can be inserted into any clustered table. The followingstatement creates a cluster index for the emp_dept cluster:CREATE CLUSTER emp_dept (deptno NUMBER(3)) TABLESPACEusers;CREATE TABLE emp( empno NUMBER(5) PRIMARY KEY, ename VARCHAR2(15) NOTNULL,. . .deptno NUMBER(3) REFERENCES dept)CLUSTER emp_dept (deptno);CREATE TABLE dept( deptno NUMBER(3) PRIMARY KEY, . . . )CLUSTER emp_dept (deptno);CREATE INDEX emp_dept_indexON CLUSTER emp_dept TABLESPACE users
  25. 25. Demo clusters
  26. 26. Table partitionsPartitioning addresses key issues in supporting very large tables and indexes by letting you decomposethem into smaller and more manageable pieces called partitions SQL queries and DML statements donot need to be modified in order to access partitioned tables. However, after partitions are defined, DDLstatements can access and manipulate individuals partitions rather than entire tables or indexes. This ishow partitioning can simplify the manageability of large database objects. Also, partitioning is entirelytransparent to applicationsEach partition of a table or index must have the same logical attributes, such as column names,datatypes, and constraints, but each partition can have separate physical attributes such as pctfree,pctused, and tablespacesPartitioning is useful for many different types of applications, particularly applications that manage largevolumes of data. OLTP systems often benefit from improvements in manageability and availability, whiledata warehousing systems benefit from performance and manageability
  27. 27. Partitioning advantagesPartitioning enables data management operations such data loads, index creation and rebuilding, andbackup/recovery at the partition level, rather than on the entire table. This results in significantlyreduced times for these operationsPartitioning improves query performance. In many cases, the results of a query can be achieved byaccessing a subset of partitions, rather than the entire table. For some queries, this technique calledpartition pruning can provide order-of-magnitude gains in performancePartitioning can significantly reduce the impact of scheduled downtime for maintenance operationsPartition independence for partition maintenance operations lets you perform concurrent maintenanceoperations on different partitions of the same table or index. You can also run concurrent SELECT andDML operations against partitions that are unaffected by maintenance operationsPartitioning increases the availability of mission-critical databases if critical tables and indexes aredivided into partitions to reduce the maintenance windows, recovery times, and impact of failures.Partitioning can be implemented without requiring any modifications to your applications. For example,you could convert a nonpartitioned table to a partitioned table without needing to modify any of theSELECT statements or DML statements which access that table. You do not need to rewrite yourapplication code to take advantage of partitioning
  28. 28. Range PartitioningRange partitioning maps data to partitions based on ranges of partition key values that youestablish for each partition. It is the most common type of partitioning and is often used withdates. For example, you might want to partition sales data into monthly partitions.A typical example is given in the following section.The statement creates a table (sales_range) that is range partitioned on thesales_date field.create table sales_range( salesman_id number(5), salesman_name varchar2(30), sales_amount number(10),sales_date date)partition by range(sales_date)( partition sales_jan2000 values less than( to_date(02/01/2000,dd/mm/yyyy )),partition sales_feb2000 values less than( to_date(03/01/2000,dd/mm/yyyy )),partition sales_mar2000 values less than( to_date(04/01/2000,dd/mm/yyyy )),partition sales_apr2000 values less than( to_date(05/01/2000,dd/mm/yyyy )));
  29. 29. List PartitioningList partitioning enables you to explicitly control how rows map to partitions. You do this byspecifying a list of discrete values for the partitioning key in the description for each partition. Thisis different from range partitioning, where a range of values is associated with a partition andfrom hash partitioning, where a hash function controls the row-to-partition mapping. Theadvantage of list partitioning is that you can group and organize unordered and unrelated sets ofdata in a natural way.The details of list partitioning can best be described with an example. In this case, lets say youwant to partition a sales table by region. That means grouping states together according to theirgeographical location as in the following example.create table sales_list(salesman_id number(5), salesman_name varchar2(30),sales_state varchar2(20),sales_amount number(10),sales_date date)partition by list(sales_state)(partition sales_west values(california, hawaii),partition sales_east values (new york, virginia, florida),partition sales_central values(texas, illinois),partition sales_other values(default));
  30. 30. Hash PartitioningHash partitioning enables easy partitioning of data that does not lend itself to range or listpartitioning. It does this with a simple syntax and is easy to implement. It is a better choice thanrange partitioning when:You do not know beforehand how much data maps into a given rangeThe sizes of range partitions would differ quite substantially or would be difficult to balance manuallyRange partitioning would cause the data to be undesirably clusteredNote: The concepts of splitting, dropping or merging partitions do not apply to hashpartitions. Instead, hash partitions can be added and coalesced.create table sales_hash(salesman_id number(5), salesman_name varchar2(30),sales_amount number(10), week_no number(2))partition by hash(salesman_id)partitions 4 store in (data1, data2, data3, data4);The preceding statement creates a table sales_hash, which is hash partitioned on salesman_id field.The tablespace names are data1, data2, data3, and data4
  31. 31. Partitioned IndexesJust like partitioned tables, partitioned indexes improve manageability, availability, performance, andscalability.They can either be partitioned independently (global indexes) or automatically linked to a tablespartitioning method (local indexes .
  32. 32. Local Partitioned IndexesLocal partitioned indexes are easier to manage than other types of partitioned indexes. They also offergreater availability and are common in DSS environments. The reason for this is equipartitioning: eachpartition of a local index is associated with exactly one partition of the table. This enables Oracle toautomatically keep the index partitions in sync with the table partitions, and makes each table-index pairindependent. Any actions that make one partitions data invalid or unavailable only affect a singlepartitionYou cannot explicitly add a partition to a local index. Instead, new partitions are added to local indexesonly when you add a partition to the underlying table. Likewise, you cannot explicitly drop a partitionfrom a local index. Instead, local index partitions are dropped only when you drop a partition from theunderlying tableA local index can be unique. However, in order for a local index to be unique, the partitioning key of thetable must be part of the indexs key columns. Unique local indexes are useful for OLTP environmentsLocal Partitioned Indexcreate index employees_local_idxon employees (employee_id) local;
  33. 33. Global Partitioned IndexesGlobal partitioned indexesare flexible in that the degree of partitioning and the partitioning key are independent fromthe tables partitioning method.They are commonly used for OLTP environments and offer efficient access to anyindividual record.partitioned indexcreate index employees_global_part_idxon employees(employee_id)global partition by range(employee_id)(partition p1 values less than(5000),partition p2 values less han(maxvalue));
  34. 34. Global Nonpartitioned IndexesGlobal nonpartitioned indexesbehave just like a nonpartitioned index.They are commonly used in OLTP environments and offer efficient accessto any individual record.Global nonpartitioned indexcreate index employees_global_idxon employees(employee_id);
  35. 35. partition pruningThe Oracle server explicitly recognizes partitions and subpartitions. It then optimizes SQL statements tomark the partitions or subpartitions that need to be accessed and eliminates (prunes) unnecessarypartitions or subpartitions from access by those SQL statements. In other words, partition pruning is theskipping of unnecessary index and data partitions or subpartitions in a query.For each SQL statement, depending on the selection criteria specified, unneeded partitions orsubpartitions can be eliminated. For example, if a query only involves March sales data, then there is noneed to retrieve data for the remaining eleven months. Such intelligent pruning can dramatically reducethe data volume, resulting in substantial improvements in query performance.If the optimizer determines that the selection criteria used for pruning are satisfied by all the rows in theaccessed partition or subpartition, it removes those criteria from the predicate list (WHERE clause)during evaluation in order to improve performance.Equality, range, LIKE, and IN-list predicates are considered for partition pruning with range or listpartitioning, and equality and IN-list predicates are considered for partition pruning with hashpartitioning.
  36. 36. Demo Partitions
  37. 37. External Tables ConceptsThe Oracle9i external tables feature is a complement to existing SQL*Loaderfunctionality. It allows you to access data in external sources as if it were in a table in the database.External tables are read-only. No data manipulation language (DML) operations or index creation isallowed on an external table.However, as of Oracle Database 10g, external tables can also be written to. Although neither datamanipulation language (DML) operations nor index creation is allowed on an external table, it is possibleto use the CREATE TABLE AS SELECT command to populate an external table composed of proprietaryformat (Direct Path API) flat files that are operating system independent.
  38. 38. Benefits of External TablesProvide a valuable means for performing basic extraction, transformation, and loading (ETL)Are transparent to users and applicationsAre a complement to the existing SQL*Loader functionalityAre especially useful for environments in which:The complete external source must be joined with existing database objects andtransformed in a complex mannerThe external data volume is large and used only once
  39. 39. External TablesSELECT *FROM ex_table;OS fileExternaltable
  40. 40. External Table Population: OverviewUnload data to external flat filesHandle complex ETL situationsFlat files(Proprietary format)CREATE TABLE… AS SELECTTablesUnloadingTablesLoadingINSERT … SELECT
  41. 41. External Table Population OperationUses the ORACLE_DATAPUMP access driverData cannot be modified.Resulting files can be read only with theORACLE_DATAPUMP access driver.You can combine generated files from different sources forloading purposes.ORACLE_DATAPUMPOracle DatabaseDPAPIflat files
  42. 42. External Table Parallel PopulateOperationMultiple files can be created.Exactly one parallel execution server per fileThe PARALLEL and LOCATION clauses influence the degreeof parallelism.CoordinatorParallelexecutionserversGeneratedfilesemp1.exp emp2.exp emp3.exp
  43. 43. External Table Population: ExampleCREATE TABLE emp_ext(first_name, last_name, department_name)ORGANIZATION EXTERNAL(TYPE ORACLE_DATAPUMPDEFAULT DIRECTORY ext_dirLOCATION (emp1.exp,emp2.exp,emp3.exp))PARALLELASSELECT e.first_name,e.last_name,d.department_nameFROM employees e, departments dWHERE e.department_id = d.department_id ANDd.department_name in(Marketing, Purchasing);
  44. 44. External Table Projected Columns2355,1,2289,46,2002355,A,2264,50,100SELECT COUNT(order_id)FROM order_items_ext;SELECT COUNT(line_id)FROM order_items_ext;order_items1.datREFERENCEDALLAccessdriver2 1 1 1
  45. 45. ALTER TABLE order_items_extPROJECT COLUMN {ALL|REFERENCED};SELECT propertyFROM DBA_EXTERNAL_TABLESWHERE table_name = ORDER_ITEMS_EXT;External Table Projected Column:ExamplesThe default value is ALL.REFERENCED is useful for performance when data is knownto be safe.
  46. 46. Demo externaltable
  47. 47. Materialized ViewsMaterialized views are schema objects that can be used to summarize, compute, replicate, anddistribute data. They are suitable in various computing environments such as data warehousing, decisionsupport, and distributed or mobile computingIn data warehouses, materialized views are used to compute and store aggregated data such as sumsand averages. Materialized views in these environments are typically referred to as summaries becausethey store summarized data. They can also be used to compute joins with or without aggregations.Cost-based optimization can use materialized views to improve query performance by automaticallyrecognizing when a materialized view can and should be used to satisfy a request. The optimizertransparently rewrites the request to use the materialized view. Queries are then directed to thematerialized view and not to the underlying detail tables or viewsMaterialized views are similar to indexes in several waysThey consume storage spaceThey must be refreshed when the data in their master tables changesThey improve the performance of SQL execution when they are used for query rewritesTheir existence is transparent to SQL applications and usersUnlike indexes, materialized views can be accessed directly using a SELECT statement. Depending on the types ofrefresh that are required, they can also be accessed directly in an INSERT UPDATE or DELETE statement
  48. 48. query rewriteMaterialized views improve query performance by precalculating expensive join and aggregationoperations on the database prior to execution and storing the results in the database.The query optimizer automatically recognizes when an existing materialized view can and should be usedto satisfy a request. It then transparently rewrites the request to use the materialized view.Queries go directly to the materialized view and not to the underlying detail tables. In general, rewritingqueries to use materialized views rather than detail tables improves response
  49. 49. Query rewrite requirementsEven though a materialized view is defined, it will not automatically be used by the query rewrite facility.You must set the QUERY_REWRITE_ENABLED initialization parameter to TRUE before using queryrewrite.You also must specify the ENABLE QUERY REWRITE clause if the materialized view is to be consideredavailable for rewriting queriesAlter system set QUERY_REWRITE_ENABLED = trueAlter session set QUERY_REWRITE_ENABLED = true
  50. 50. Refresh mviewWhen you define a materialized view, you can specify two refresh options: how to refresh and what type of refresh. Ifunspecified, the defaults are assumed as ON DEMAND and FORCEYou can specify how you want your materialized views to be refreshed from the detail tables by selecting one of fouroptions: COMPLETE, FAST, FORCE, and NEVERDescriptionRefresh ModeRefresh occurs automatically when a transaction that modified one of the materialized views detail tables commits.This can be specified as long as the materialized view is fast refreshable (in other words, not complex). The ONCOMMIT privilege is necessary to use this modeOn commitRefresh occurs when a user manually executes one of the available refresh procedures contained in theDBMS_MVIEW package (REFRESH, REFRESH_ALL_MVIEWS, REFRESH_DEPENDENT)On demandRefreshes by recalculating the materialized views defining queryCOMPLETEApplies incremental changes to refresh the materialized view using the information logged in thematerialized view logs, or from a SQL*Loader direct-path or a partition maintenance operationFASTApplies FAST refresh if possible; otherwise, it applies COMPLETE refreshFORCEIndicates that the materialized view will not be refreshed with the Oracle refresh mechanismsNEVER
  51. 51. Mview logWhen DML changes are made to master table data, Oracle Database stores rows describing thosechanges in the materialized view log and then uses the materialized view log to refresh materializedviews based on the master table.This process is called incremental or fast refresh. Without a materialized view log, Oracle Database mustre-execute the materialized view query to refresh the materialized view.This process is called a complete refresh. Usually, a fast refresh takes less time than a complete refreshCREATE MATERIALIZED VIEW LOG ON serversTABLESPACE data_smlWITH PRIMARY KEY, ROWID;
  52. 52. Create Materialized viewSimple mview : is a mview that is used for direct query and has no fast refresh option or query rewriteabilityComplex mview : has query rewrite enabled, refresh fast, and accesses multiple tablesCREATE MATERIALIZED VIEW mv_simpleTABLESPACE data_sml ASSelect * from servers;CREATE MATERIALIZED VIEW mv_prebuiltRefresh fast on commitENABLE QUERY REWRITEAS SELECT t.calendar_month_desc AS month,c.cust_state_province AS state, SUM(s.amount_sold) AS salesFROM times t, customers c, sales sWHERE s.time_id = t.time_id AND s.cust_id = c.cust_idGROUP BY t.calendar_month_desc, c.cust_state_province;
  53. 53. DimensionsA dimension object defines hierarchical (parent/child) relationships between pairs of column sets, where all thecolumns of a column set must come from the same table. A dimension is a superset of the referential integrityconstraints defined in the Oracle Server.Normalized dimensions are globally equivalent to the relationship between primary keys and not-null foreign keys.For denormalized dimensions, the established relation is for column sets of the same table, and this relationshipdetermines whether any child-side columns value has one and only one corresponding parent-side columns value.Dimensions are more general than traditional referential integrity constraints because you can define a relationbetween n columns and m columns, or you can define a relation between two columns with different data types.Another significant difference between dimensions and constraints is that dimensions are never enforced.Dimensions (in the context of Oracle9i) are data dictionary structures that define the hierarchies based on columns inexisting database tables. Declaring dimensions:Enables additional rewrite possibilities without the use of constraints (Implementation of constraints may notbe desirable in a data warehouse for performance reasons.)Helps document dimensions and hierarchies explicitly
  54. 54. DimensionsData dictionary structuresDefine hierarchies between pairs of column setsSuperset of referential constraints:Normalized dimensionsDenormalized dimensionsNever enforcedOptional but highly recommended because they:Enable additional query rewrites without the use of constraintsCan be used by OLAP tools
  55. 55. Dimensions and HierarchiesHierarchyDay nameMonth nameQuarterdescriptionDays in quarterDayAllAttributes:YearQuarterMonthFiscal yearFiscal quarterFiscal monthFiscal week
  56. 56. Dimensions: Example TableSQL> SELECT time_id day2 , calendar_month_desc month3 , calendar_quarter_desc quarter4 , calendar_year year5 FROM times;DAY MONTH QUARTER YEAR--------- -------- ------- ----------01-JAN-98 1998-01 1998-Q1 199802-JAN-98 1998-01 1998-Q1 199803-JAN-98 1998-01 1998-Q1 199804-JAN-98 1998-01 1998-Q1 199805-JAN-98 1998-01 1998-Q1 199806-JAN-98 1998-01 1998-Q1 1998...30-DEC-01 2001-12 2001-Q4 200131-DEC-01 2001-12 2001-Q4 2001
  57. 57. Dimensions and Hierarchies- YEAR- QUARTER- MONTH- DAYTIMES table columns TIMES_DIM dimension- DAY_NAME- CALENDAR_MONTH_NAME- DAYS_IN_CAL_QUARTERAttributes- CALENDAR_YEAR- CALENDAR_QUARTER_DESC- CALENDAR_MONTH_DESC- TIME_ID
  58. 58. Creating Dimensions and HierarchiesSQL> CREATE DIMENSION times_dim2 LEVEL day IS TIMES.TIME_ID3 LEVEL month IS TIMES.CALENDAR_MONTH_DESC4 LEVEL quarter IS TIMES.CALENDAR_QUARTER_DESC5 LEVEL year IS TIMES.CALENDAR_YEAR6 HIERARCHY cal_rollup (7 day CHILD OF8 month CHILD OF9 quarter CHILD OF10 year11 )12 ATTRIBUTE day DETERMINES (day_name)13 ATTRIBUTE month DETERMINES (calendar_month_name)14 ATTRIBUTE quarter DETERMINES15 (days_in_cal_quarter);
  59. 59. Demo materialized view
  60. 60. Large Objects - LOBAs applications evolve to encompass increasingly richer semantics, they encounter the need to deal with thefollowing kinds of data:• Simple structured data• Complex structured data• Semi-structured data• Unstructured dataTraditionally, the Relational model has been very successful at dealing with simple structured data -- the kind whichcan be fit into simple tables. Oracle has added Object-Relational features so that applications can deal with complexstructured data -- collections, references, user-defined types and so on. Our queuing technologies, such as AdvancedQueuing, deal with Messages and other semi-structured data.LOBs are designed to support the last kind of data -- unstructured data.
  61. 61. Unstructured DataUnstructured Data Cannot be Decomposed Into Standard ComponentsUnstructured data cannot be decomposed into standard components. Data about an Employee can be structured intoa Name (probably a character string), an identification (likely a number), a Salary and so on. But if you are given aPhoto, you find that the data really consists of a long stream of 0s and 1s. These 0s and 1s are used to switch pixels onor off so that you will see the Photo on a display, but they cant be broken down into any finer structure in terms ofdatabase storage.Unstructured Data is LargeAlso interesting is that unstructured data such as text, graphic images, still video clips, full motion video, and soundwaveforms tend to be large -- a typical employee record may be a few hundred bytes, but even small amounts ofmultimedia data can be thousands of times larger.Two Type of LOBs SupportedOracle supports the following two types of LOBs• Those stored in the database either in-line in the table or in a separate segment or tablespace, such asBLOB, CLOB, and NCLOB.• Those stored as operating system files, such as BFILEs.
  62. 62. Large Objects - LOBBLOB - binary data that can be extended to 4 GBCLOB - character data up to 4 GBNCLOB - stores CLOB data for multibyte character setsStored inside database, can be single rowBFILE - pointer to external file. (File exists on O/S)
  63. 63. Demo LOB
  64. 64. A TipShrinking Segments
  65. 65. Shrinking Segments: Considerations• Online and in-place operation• Applicable only to segments residing in ASSM tablespaces• Candidate segment types:• Heap-organized tables and index-organized tables• Indexes• Partitions and subpartitions• Materialized views and materialized view logs• Indexes are maintained.• Triggers are not fired.
  66. 66. Shrinking Segments: OverviewHWMHWMShrinkoperationDataUnusedspaceDataUnusedspaceReclaimed space
  67. 67. Shrinking Segments Using SQLALTER TABLE employees SHRINK SPACE CASCADE;ALTER … SHRINK SPACE [CASCADE]TABLE INDEX MATERIALIZED VIEW MATERIALIZED VIEW LOGMODIFY PARTITIONALTER TABLE employees ENABLE ROW MOVEMENT;12MODIFY SUBPARTITION
  68. 68. Segment Shrink: Basic ExecutionHWMALTER TABLE employees SHRINK SPACE COMPACT;HWMHWMALTER TABLE employees SHRINK SPACE;12
  69. 69. Segment Shrink:Execution Considerations•Use compaction only:•Avoid unnecessary cursor invalidation•During peak hours•DML operations and queries can be issued duringcompaction.•DML operations are blocked when HWM is adjusted.
  70. 70. Demo Shrink
  71. 71. Aaron Shilo, CEOOracle Certified ProfessionalMicrosoft certified technology specialistContact Me :Aaron@DBCS.co.ilwww.DBCS.co.il0504-477117http://il.linkedin.com/in/aaronshilo

×