using oracle xml db to optimize performance and manage...

46
13/11/2017 Optimize Performance and Manage XML Data http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?prin… 1/46 Using Oracle XML DB to Optimize Performance and Manage Structured XML Data This tutorial contains the following sections: Purpose Time to Complete Overview Software Requirements Prerequisites Reviewing XML Schema and XML Documents in a Web Browser Using XQuery and SQL/XML to Query XML Documents Using XQuery Pragma ora:defaultTable to Improve Repository Query Performance Equi-Partitioning of Object-Relational Storage Improving Query Performance of Partitioned XMLType Table through Index Creation Using Parallelism in Query Execution Summary Resources Purpose In this tutorial, you use Oracle XML DB to Optimize Performance and Manage Structured XML Data. Time to Complete Approximately 1 hour. Overview XML schemas are used by many industries to define the XML structures used for information exchange. XML documents conforming to these XML schemas are highly structured. This tutorial will show you how the rich capabilities of Oracle XML DB enable storage, indexing, query, optimized performance, and management of structured XML data. It covers the following topics: Using the object-relational storage model to store, index, and query structured XML data Using the Oracle ConText full-text index to improve full-text query performance Using equi-partitioning and parallelism on the object-relational storage model to improve performance and scalability Software Requirements The following is a list of software requirements: Oracle Database 11g Release 2 (11.2.0.2.0) Enterprise Edition for linux Oracle SQL Developer version 2.1 or higher Mozilla Firefox Web browser A linux text editor such as gedit Prerequisites Before starting this tutorial, you should first complete the following steps: 1. Install Oracle Database 11g Release 2 (11.2.0.2.0) Enterprise Edition for linux 2. Install Oracle SQL Developer 3. Download the files.zip file which contains the script files used in this OBE to your local drive

Upload: others

Post on 26-Jul-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?prin… 1/46

Using Oracle XML DB to Optimize Performance and Manage Structured XML Data

This tutorial contains the following sections:

PurposeTime to CompleteOverviewSoftware RequirementsPrerequisitesReviewing XML Schema and XML Documents in a WebBrowserUsing XQuery and SQL/XML to Query XML DocumentsUsing XQuery Pragma ora:defaultTable to Improve RepositoryQuery PerformanceEqui-Partitioning of Object-Relational StorageImproving Query Performance of Partitioned XMLType Tablethrough Index CreationUsing Parallelism in Query ExecutionSummaryResources

PurposeIn this tutorial, you use Oracle XML DB to Optimize Performance and Manage Structured XML Data.

Time to CompleteApproximately 1 hour.

OverviewXML schemas are used by many industries to define the XML structures used for information exchange. XML documents conformingto these XML schemas are highly structured. This tutorial will show you how the rich capabilities of Oracle XML DB enable storage,indexing, query, optimized performance, and management of structured XML data. It covers the following topics:

Using the object-relational storage model to store, index, and query structured XML dataUsing the Oracle ConText full-text index to improve full-text query performanceUsing equi-partitioning and parallelism on the object-relational storage model to improve performance and scalability

Software RequirementsThe following is a list of software requirements:

Oracle Database 11g Release 2 (11.2.0.2.0) Enterprise Edition for linuxOracle SQL Developer version 2.1 or higherMozilla Firefox Web browserA linux text editor such as gedit

PrerequisitesBefore starting this tutorial, you should first complete the following steps:

1. Install Oracle Database 11g Release 2 (11.2.0.2.0) Enterprise Edition for linux

2. Install Oracle SQL Developer

3. Download the files.zip file which contains the script files used in this OBE to your local drive

Page 2: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?prin… 2/46

4. Ensure you have access to the Order Entry (oe) sample schema

Reviewing XML Schema and XML Documents in a Web BrowserAn XML Schema and over a hundred sample XML documents have been supplied as part of the OE sample schema in OracleDatabase 11g Release 2. In this section, you will review their content using a web browser.

Setting the HTTP Port and Configuring the ListenerViewing the PURCHASEORDER XML Schema and a Conforming XML Document

Setting the HTTP Port and Configuring the Listener

1. Start up SQL*Plus.

a. In your linux environment, start a terminal window. Double-click the Terminal icon on your desktop.

b. A terminal window is displayed.

c. Start SQL*Plus. Enter system as the username and your valid system password.

Note: In the above screen capture, subsitute <your_password> with your valid system password.

2. Set the HTTP port to the standard port 8080.

a. Use the PL/SQL procedure DBMS_XDB.sethtpport to set the HTTP(S) port number to port_number in theOracle XML DB configuration file /xdbconfig.xml, where port_number is 8080 for HTTP or 443 for HTTPS:

Page 3: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?prin… 3/46

b. Confirm that the HTTP has been set.

3. Now force the database to reregister with the listener, using this SQL statement below:

Your configuration has been set. Check that the listener is correctly configured. Enter the lsnrctl STATUScommand at the operating system prompt (%):

Page 4: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?prin… 4/46

Viewing the PURCHASEORDER XML Schema and a Conforming XML Document

1. Open a browser and enter the URL for the OE folder in the XML DB repository.

2. Enter oe for the User Name and oe for the Password in the Authentication dialog box, and then click OK.

3. Now click the purchaseOrder.xsd hyperlink in the browser window to view the XML schema.

Page 5: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?prin… 5/46

4. The XML schema is displayed in the browser window as follows. Notice the highlighted annotationxdb:defaultTable=”PURCHASEORDER”, which specifies that all XML documents conforming to this schema willbe physically stored in the PURCHASEORDER table.

5. You can also view XML documents that are stored in the XML DB repository using a Web browser. Return to the/home/OE/ folder, and then click the PurchaseOrders folder link.

Page 6: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?prin… 6/46

6. The 2002/ link is displayed. Click the link.

7. A number of sub-folders links are displayed. Click the Dec/ link.

Page 7: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?prin… 7/46

8. A number of the purchase orders XML documents are displayed. Click one of the XML documents links to view itscontent.

Page 8: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?prin… 8/46

9. Review the partial formatted purchase order XML document below. Notice the highlighted annotationxsi:noNamespaceSchemaLocation=“http://localhost:8080/source/schemas/poSource/xsd/purchaseOrder.xsd” specifying the XML schema locationURI. This is referencing the xsd file that we have reviewed earlier in a browser window.

Page 9: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?prin… 9/46

. . .

Using XQuery and SQL/XML to Query XML DocumentsIn the last topic, you browsed XML documents stored in the XML repository using- a Web browser. Since each of these XMLdocuments is physically stored as a row of an XMLType table, queries can be executed against either the XMLType storage table orthe repository. In this section, you will use XQuery and SQL/XML to query XML documents stored in the PURCHASEORDER table.

Start SQL Developer to Examine the Storage Table for the Purchase Order XML DocumentsRun SQL/XML and XQuery Queries against the PURCHASEORDER XMLTypeCreate Indexes to Improve XML Query Performance

Start SQL Developer to Examine the Storage Table for the Purchase Order XML Documents

1. Click the SQL Developer icon on your desktop to start SQL Developer.

Page 10: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 10/46

The SQL Developer window is displayed.

2. Create a new database connection as user "system" by performing the following steps.

a. In the Connections tab, right-click the Connections node, and then select New Connection from the pop-upmenu.

The New/Select Database Connection window is displayed.

Page 11: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 11/46

b. Enter the following details in the New/Select Database Connection window.

Connection Name: System UserName: system

Password:<your_system_password> Save Password checkbox: Enabled

Hostname: localhost Port: 1521

SID: <your_SID>

c. Click Test. If the connection has been set correctly, the Status in the lower left corner of the window is Success.

Page 12: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 12/46

d. Click Save to save the newly created database connection, and then click Connect. The new System databaseconnection is displayed in the Connections tab.

e. Click the Files tab, and then double-click the 1_0_setup.sql script from the location where you saved the contentsof the downloaded files.zip file . The contents of the script file is displayed in the SQL Worksheet area.

Note: In this tutorial, the contents of the files.zip are saved in the /home/oracle/OBE1 folder as follows:

Page 13: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 13/46

Page 14: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 14/46

Note: The above script contains a section starting with the highlighted comment "Run I/O calibration". You can runthis code which calibrates I/O so that you can better statistics for the cost based optimizer. If you decide to run the I/Ocalibration, you must perform the steps:

Log in to SQL*Plus as sysdba as follows: sqlplus system/<your_password> as sysdba;

Set the timed_statistics parameter to TRUE as follows: ALTER SYSTEM SET timed_statistics = TRUE;

Set the timed_statistics parameter to TRUE as follows: ALTER SYETEM SET filesystemio_options = SETALL scope=spfile;

Enable asynchronous I/O by setting the FILESYSTEMIO_OPTIONS initialization parameter to SETALL as follows: ALTER SYETEM SET filesystemio_options = SETALL scope=spfile;

Restart the database instance as follows: CONNECT SYSTEM/<your_password> AS SYSDBA;

SHUTDOWN IMMEDIATE STARTUP

Ensure that the asynchronous I/O is enabled for data files by running the following query: COLUMN NAME FORMAT A50

SELECT NAME,ASYNCH_IO FROM V$DATAFILE F,V$IOSTAT_FILE I

WHERE F.FILE#=I.FILE_NO AND FILETYPE_NAME='Data File';

Page 15: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 15/46

f. Select the System database connection from the Choose Db Connection drop-down list, and then click the RunScript icon (or press the F5 key) to grant access to the oe user.

The output is displayed in the Script Output tab.

Page 16: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 16/46

g. In the Connections tab, right-click Connections from the pop-up menu, and then select New Connection.

h. The New / Select Database Connection window is displayed. Enter the following details for the new databaseconnection. Click Test to make sure that the connection has been set correctly. If the test status is Success, save thenew database connection, and then click Connect.

Connection Name: OE Schema UserName: oe

Password: <your_oe_password> Save Password checkbox: Enabled

Hostname: localhost Port: 1521

SID:<your_SID>

3. Set the Autotrace parameters. Perform the following steps:

a. Navigate to Tools > Preferences.

Page 17: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 17/46

The Preferences window is displayed.

b. Expand Database, and then select Autotrace/Explain Plan. Make sure to select the following check boxes, andthen click OK.

Object_Name Cost

Cardinality Predicates

Page 18: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 18/46

4. Examine the OE Schema. Perform the following steps:

a. Click the plus (+) icon to the left of the oe connection to expand it.

b. Expand Tables, and then select PURCHASEORDER. On the right window pane, select the Details tab to examine thevalues of the NUM_ROWS and the TABLE_TYPE parameters. Notice the highlighted TABLE_TYPE parameter withvalue XMLTYPE.

Page 19: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 19/46

c. Click the Files tab in the left window pane to open the SQL script 1_3_queries.sql and display it in the SQLWorksheet area. Select the OE Schema from the Choose Db Connection drop-down list, select the Q0 query, andthen click the Run Statement icon to execute a query against the USER_XML_TABLES data dictionary view.

Page 20: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 20/46

Notice the following:

The PURCHASEORDER XMLType table is stored with the OBJECT-RELATIONAL storage option.The XMLSCHEMA is http://localhost:8080/source/schemas/poSource/xsd/purchaseOrder.xsd (It is the same asspecified in a conforming XML document that we reviewed earlier).

Run SQL/XML and XQuery Queries against the PURCHASEORDER XMLType

1. On the left window pane, use the Files tab to open the 1_3_queries.sql script. On the right window pane, select theQ1 query and click the Run Statement icon to execute the query. The Query Result tab below displays the results.Notice XMLSerialize(), XMLQueru(), and XMLExists() SQL/XML functions along with XQuery expressions astheir parameters in the query.

Page 21: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 21/46

2. Scroll down the 1_3_queries.sql script to find the Q11 query which uses the XMLTable() SQL/XML function tomap structured data in the purchase order XML documents into a master-detail table for ROLLUP calculations.Notice the output in the Query Result tab to find a sub-total calculated for the A10 cost center in row 5.

Page 22: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 22/46

3. You can now run Autotrace on these queries to see of their execution plans are optimal. Using Q1 as an example,The following execution plan involved an inefficient TABLE ACCESS FULL operation.

Page 23: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 23/46

Create Indexes to Improve XML Query Performance

1. On the left window pane, click the Files tab to open the 1_2_createIndexes.sql script. Select the OE Schemafrom the Choose Db Connection drop-down list, and then click the Run Script icon to create B-tree indexes. Noticehow the CREATE INDEX statements below used the XMLCast() and XMLQuery() SQL/XML functions along withXPath expressions to create B-tree indexes on the leaf nodes. Two composite indexes and one full-text index arealso created for the columns of the LINEITEM_TABLE nested table.

Page 24: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 24/46

Page 25: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 25/46

2. To examine the created indexes, scroll to the bottom of the 1_2_createIndexes.sql script to select the queryshown below. Click the Run Statement icon to see that you have successfully created B-tree indexes and one full-text index (the “DOMAIN” index) on the PURCHASEORDER table and its associated LINEITEM_TABLE.

3. Check the execution plan again. Select the Q1 query in 1_3_queries.sql file, select the OE Schema from theChoose Db Connection drop-down list, and then click the Autotrace… icon. You can see below how the queryexecution plan has improved where TABLE ACCESS FULL operation has been replaced by more efficient TABLEACCESS BY INDEX ROWID and INDEX RANGE SCAN operations.

Page 26: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 26/46

4. Similarly, the query execution plan for Q5 also used more efficient INDEX RANGE SCAN operations. Notice that theDOMAIN INDEX (i.e., the full-text index on the purchase order item description) is also used to execute theora:contains() XQuery function in the XMLExists() SQL/XML function.

Page 27: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 27/46

Using XQuery Pragma ora:defaultTable to Improve Repository Query PerformanceIn prior releases of the Oracle Database, in order to obtain optimal performance for XQuery expressions that use the fn:doc andfn:collection over Oracle XML DB Repository resources, you needed to write explicit joins with RESOURCE_VIEW. In the OracleDatabase 11g Release 2 (11.2.0.2.0) , the new XQuery pragma ora:defaultTable will perform the necessary joinsautomatically. In the following steps you will learn how to use this new pragma.

1. On the left window pane, click the Files tab, and then double-click the 1_4_defaultTableQueries.sql script.On the right window pane, select the OE Schema from the Choose Db Connection, select the CASE 1 query, andthen click the Autotrace… icon to check the execution plan. Since XQuery fn:collection() function is used tospecify an XML document as an XM LDB repository resource, the query execution engine has no immediateknowledge that the physical storage of this document is object-relational with applicable indexes. As a result, thequery plan uses the very inefficient COLLECTION ITERATOR PICKLER FETCH operations.

Page 28: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 28/46

2. Prior to Oracle Database 11g Release 2 ( 11.2.0.2.0), you had to manually rewrite the query to explicitly relate theXML DB repository resource to the underlying physical storage table as shown in CASE 2 of the same SQL scriptfile. Notice how the query execution plan has improved to use INDEX RANGE SCAN operations.

Page 29: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 29/46

3. In the new Oracle Database 11g Release 2 ( 11.2.0.2.0), instead of manually rewriting the query, you can simply usethe new ora:defaultTable pragma in your XQuery expression to give a hint about the underlying physicalstorage table (such as the PURCHASEORDER table in this example) to the query processing engine. Notice how theexecution plan is now as good as the manually rewritten query in the previous step.

Page 30: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 30/46

Equi-Partitioning of Object-Relational Storage

Equi-partitioning for object-relational storage was introduced in Oracle Database 11g Release 2 to help simplify XML data life-cyclemanagement and performance. In this section, you will learn how the object-relational storage table can be equi-partitioned.

Create New Tablespaces for XMLType Table PartitionsCreate Partitioned XMLType Table

Create New Tablespaces for XMLType Table Partitions

1. Click the Files tab, and then double-click the 2_0_setup.sql script. Next, click the Run Script icon to create thetablespaces.

Page 31: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 31/46

2. Scroll down the 2_0_setup.sql script to view the highlighted query against the DBA_TABLESPACES datadictionary view. Scroll down in the Script Output tab to see the highlighted created tablespaces.

Page 32: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 32/46

Create Partitioned XMLType Table

1. Create an XMLType table with partitioned object-relational storage, and populate the table with data selected fromthe PURCHASEORDERS table. Run the script 2_1_createTable.sql. Perform the following steps:

a. Click the Files tab.

Page 33: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 33/46

b. Browse to the location of your working directory \files, and then double-click the 2_1_createTable.sql file.The code is displayed in the SQL Worksheet area.

c. Select the OE Schema database connection from the drop-down list on the right.

Page 34: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 34/46

d. Click the Run Script (F5) icon. Note that three list partitions are specified based on the partitioning keyCOST_CENTER, which corresponds to the value of /PurchaseOrder/CostCenter node in the purchaseorder XMLdocument. Note also the table partitions for the ordered collection table (OCT) LINEITEM_PT_TABLE are equi-partitioned in the same way as their base table and given their own partition names (i.e., lineitem_a10,lineitem_r20, lineitem_s30).

e. Right click the Tables folder, and then select Refresh from the pop-up menu.

Page 35: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 35/46

f. Click the newly created XMLType table PARTITIONED_PO to find more information on the right pane of the OracleSQL Developer window

g. Click the Partitions tab to display table partitions.

Note: If after clicking the Partitions tab above, you don't see the partitions details, click the Refresh icon on thePartitions sub-tab toolbar as follows:

h. Notice the partition names as you have specified. Click the Actions… icon, and then navigate to Statistics >Gather Statistics. The Gather Statistics window is displayed.

Page 36: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 36/46

i. In the Gather Statistics popup dialog, click Apply. A Confirmation window is displayed. Click OK.

j. Once statistics are gathered, you can see that the 132 rows of the purchase orders are now distributed amongthree partitions with 32, 43, and 57 rows each.

Page 37: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 37/46

k. To run a test query on the partitioned XMLType table, open 2_3_queries.sql script. Select the Q1 query, andthen click the Autotrace… icon to examine the query's execution plan. Notice the PARTITION LIST SINGLEoperation, PARTITION_START and PARTITION_STOP of 2 as a result of the partition pruning optimization toaccess only the R20 partition.

l. In the Connections tab, click the newly created XMLType table LINEITEM_PT_TABLE to display more informationon the table in the right window pane.

Page 38: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 38/46

m. Click the Partitions tab to display table partitions for the ordered collection table (OCT) LINEITEM_PT_TABLE.With equi-partitioning support, OCTs are partitioned in the same way as their base table.

In the above topic, you learned how to create a list partitioned XMLType table with object-relational storage,populated data into this table, and checked the query execution plan for partitioning-specific optimizations.

Improving Query Performance of Partitioned XMLType Table through Index CreationAs you have learned earlier in this OBE, you can improve the performance of your queries by creating indexes. In this section, youwill create locally managed B-Tree indexes and a globally managed full-text index on the partitioned XMLType table. You will then

Page 39: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 39/46

run the SQL/XML, XQuery queries against the partitioned object-relational table to see the autotrace result and note theperformance improvement with more efficient query execution operations. Perform the following steps:

1. In your SQL Developer session, connect as the OE Schema user, and then execute the 2_2_createIndexes.sqlscript. Note the use of keyword LOCAL to create B-tree indexes that are local to each partition. Note also theabsence of the LOCAL keyword for the ConText Full-Text index (i.e., iPT_DESCRIPTION_TEXT) to create aglobally managed index.

Page 40: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 40/46

Page 41: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 41/46

Once the indexes are created, scroll down to the bottom of the 2_2_createIndexes.sql script. Highlight the Selectstatement that queries the created indexes, and then click the Run Statement icon. Notice that the indexes createdwith the LOCAL keyword display YES in the PARTITIONED column.

2. Now that you have created indexes, you can observe the improved query execution plan with INDEX RANGE SCANoperations for a specific partition. Open the 2_3_queries.sql script file using the OE Schema databaseconnection and highlight the Q2 query. Click the Autotrace… icon to generate a query execution plan. Note theusage of the index IPT_PARTNUMBER and that the values of PARTITION_START and PARTITION_STOP columnswhich are highlighted, point to a single partition. Note also the highlighted query execution operation TABLEACCESS BY LOCAL INDEX ROWID.

Page 42: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 42/46

3. View the execution plan of the query that lists the references for LineItem 20 with a description containing “picnic”on a particular purchase order. Select query Q5 in 2_3_queries.sql script, and then click the Autotrace… icon.Notice the usage of IPT_DESCRIPTION_TEXT index in the query execution plan. However, you can see there arenow two TABLE ACCESS BY GLOBAL INDEX ROWID operations because the IPT_DESCRIPTION_TEXT index isa globally managed index.

Page 43: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 43/46

In the above section, you learned how to create B-Tree indexes on partitioned object-relational storage. You alsolearned how to observe the improved query performance by viewing the query execution plan.

Using Parallelism in Query ExecutionEqui-partitioning and local indexes allow parallel queries and DMLs to further improve performance. Perform the following steps:

1. In Oracle SQL Developer, open the 2_4_alterTable.sql script. Choose the OE Schema as the DatabaseConnection, and then click the Run Script icon to execute the ALTER TABLE command. This enables parallel queryand DML on the PARTITIONED_PO table.

ALTER TABLE PARTITIONED_PO PARALLEL;

Page 44: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 44/46

2. Parallel query execution can make a tremendous difference in business intelligence calculations. Query Q11 in the2_3_queries.sql file is such an example that aggregates total dollar amount for each cost center and requestor.Once you selected the Q11 query and click the Autotrace… icon, you can use the scroll bar to see the completequery execution plan with extensive use of parallel query operators (i.e., PX operators).

Page 45: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 45/46

Summary

Page 46: Using Oracle XML DB to Optimize Performance and Manage ...rms.koenig-solutions.com/Sync_data/Trainer/QMS/508... · the repository. In this section, you will use XQuery and SQL/XML

13/11/2017 Optimize Performance and Manage XML Data

http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r2/prod/appdev/xmldb/xmldb_structured/optimizeandmanageXMLdata_v4.htm?pri… 46/46

In this tutorial, you have learned how to:

Review an XML Schema and XML documents in a Web browserUse XQuery and SQL/XML to query XML documentsUse XQuery pragma ora:defaultTable to improve repository query performanceEqui-partition of XMLType table stored in the object-relational formatImprove XML query performance through Index creationUse parallelism in query execution

ResourcesFor additional information on Oracle XML DB:

Attend the Oracle Database 11g: Use XML DB 4-day course.See the Oracle XML DB Developer's Guide 11g Release 2 (11.2) documentation reference.

For additional information on the pre-requisites to calibrate I/O, see the Oracle Database Performance Tuning Guide 11gRelease 2 (11.2) documentation reference.For useful XML DB white papers, technical presentations, demos, and hands-on practices, access Oracle XML DB Home PageTo learn more about XML DB , refer to the additional OBEs in the Oracle Learning Library OLL Web site

Credits

Lead Curriculum Developer: Lauran K. SerhalContent Contributor: Geoff LeeOther Contributor: Nancy Greenberg

About Oracle |Oracle and Sun | | Careers | Contact Us | Site Maps | LegalNotices | Terms of Use | Your Privacy Rights