Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
XML Programming in PL/SQL (Part 2)“An Introduction to the Oracle XML Database”<br />Marco Gralike<br />
Agenda<br />
Agenda<br />
“The foundation is there; So why not use it?”<br />…referring to the Relational Model…<br />Chris Date- Hotsos keynote, 20...
Relational…<br />
XML…?<br />
Evolution…<br />
If you’re a performance nerd, <br />	this is actually cool…<br />No one figured out XML yet…<br />Solving the customer pro...
Agenda<br />
Free Format…”XML is cool”… <br />(aka no design effort)<br />Have to Uphold the “Coding Granny Argument”…<br />Everyone fo...
Different data models<br />XPath models an XML document as <br />	a tree while most general purpose <br />	programming lan...
Effects, Costs<br />Unnecessary CPU and Memory <br />Overhead <br />A lot of expensive type and <br />	encoding conversion...
Agenda<br />
Containerization<br />
The “Dimensions” in 1 XML doc.<br />1<br />3<br />4<br />5<br />2<br />X<br />Y<br />6<br />Z<br />nx<br />rows <br />Elem...
Multi Dimensional Issues…<br />Its a database…<br />Its Row based<br />Its Column based<br />Its multiple databases…<br />...
Complexities of a database<br />“Relations”<br />“Redundancy”<br />“Nullology”<br />Design, etc…<br />It can contain a dat...
Checked on<br />XML Well-Formedness<br />One root element<br />Begin & End tags<br />If XML Schema reference<br />XOB meth...
What you want in access…<br />Fast DDL<br />Selects<br />Inserts, Deletes, Updates<br />Specific / Smart<br />Small XML Fr...
Mistakes are very, very Painful!<br />Inserts, Updates & Deletes<br />Fast <br />Efficient<br />Selects<br />Precise<br />...
Agenda<br />
Oracle XMLType<br />“Containers”<br />
XOB<br />DOM<br />XMLType Memory<br />
Object Relational<br />Binary<br />CLOB<br />XMLType<br />
Physical<br />Design<br />Logical<br />Design<br />XMLType Solutions<br />
Document contra Data Driven<br />
Structured / Semi-Structured<br />Structured<br />Semi<br />Structured<br />
Common XML Parsers<br />Often DOM or Infoset based<br />CPU intensive<br />Memory intensive<br />Serializing, parsing, tre...
In Memory: Common XML Parsers<br />Often handle XML tree traversals only via <br />ONEmethod<br />It is not structured, se...
XMLType Physical Storage<br />CLOB<br />LOB<br />LOB index<br />Object Relational<br />Varray, Types, Nested Tables<br />I...
Hybrid<br />CLOB<br />Mixed<br />complex[n]<br />un/structured<br />XSD [y]<br />B-Tree, IOT<br />Document<br />na<br />un...
Choosing a Storage Model<br />
Agenda<br />
Index Quick Sheet<br />
Unstructured XMLIndex (UXI), 11.1<br />PathTable<br />UsePath Subsetting<br />FullBlown XMLIndex canbe BIG <br />Token Tab...
Structured XMLIndex (SXI), 11.2<br />Content Table(s)<br />BasedonXMLTABLE syntax<br />XMLTable construct canbe<br />neste...
Driving access on CONTENT<br />BTree Index<br />bookstore<br />Secondary Oracle Text Index<br />Function based Index (XPat...
There can be only one XMLIndex…<br />
Agenda<br />
Design<br />
XML Schema will be parsed only once<br />XML Schema will be cached in memory (SGA)<br />No additional parsing<br />No addi...
XML Document structure is known, therefore<br />No parsing is needed when loaded from disk into memory<br />XML OBject (XO...
XDB Annotations<br />Hybrid: CLOB withinOR<br />
XDB Annotations (OR/Binary XML)<br />Levels<br />Root, Simpletype, Complextype<br />xmlns:xdb="http://xmlns.oracle.com/xdb...
Mixing Logical and Physical Design<br />
XDB Utilities Toolset<br />Object Relational Storage<br />And a bit regarding Binary XML<br />Makes xdb:annotation easy<br...
XML Schema - Query Rewrite<br />String<br />CHAR<br />String<br />Float<br />bookstore<br />CLOB<br />VARCHAR2<br />(20)<b...
XML Design<br />Avoid Cyclic References in XML Schemata<br />For ease of Maintenance: xdb:annotations<br />Is DOM validati...
Be aware of what you are doing !<br />Avoid unneeded (full) XML Schema validation<br />During Storage (Inserts), Generatin...
Agenda<br />
Keep XML small<br />Do not use / enforce Pretty Print if not needed<br />Avoid namespace reference “Overkill”<br />Most us...
Keep XML small (OR specific)<br />Don’t use “meaning full element names”<br />64Kb DDL “create table” buffer<br />ORA 0179...
Holistic Approach & DEMO<br />
Customer Use Case<br />Memory<br />/ DOM<br />Memory<br />/ DOM<br />CLOB<br /> Oracle <br />Advanced Queue<br />XMLType<b...
New XML Approach<br />Rewrite on Disk <br />/ XOB <br />(Relational)<br />CLOB<br /> Oracle <br />Advanced Queue<br />BLOB...
Using the CBO as an XML Parser…<br />ORA-31186<br />ORA-31186<br />ORA-31186<br />ORA-31186: 	Document contains too many n...
Demonstration<br />XDB Utilities<br />JDeveloper<br />XML Schema <br />xdb:annotations<br />Effect on Queries<br />
Recap<br />
Using the (XML) Relational Mindset<br />Design XSD as you would with E(E)R<br />Design for proper physical access, perform...
So in short: Balanced Design<br />Inserts, Updates & Deletes<br />XML Future Changes <br />Index Maintenance<br />Selects<...
Reward<br />Optimal performance<br />Out performing standard <br />XML solutions<br />PL/SQL, SQL access optimized <br />f...
References (1)<br />Oracle XML DB <br />http://download.oracle.com/docs/cd/E11882_01/appdev.112/e16659/toc.htm<br />XML DB...
Upcoming SlideShare
Loading in …5
×

OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2

2,603 views

Published on

Published in: Technology
  • Be the first to comment

OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2

  1. 1. XML Programming in PL/SQL (Part 2)“An Introduction to the Oracle XML Database”<br />Marco Gralike<br />
  2. 2.
  3. 3. Agenda<br />
  4. 4.
  5. 5.
  6. 6. Agenda<br />
  7. 7. “The foundation is there; So why not use it?”<br />…referring to the Relational Model…<br />Chris Date- Hotsos keynote, 2009<br />
  8. 8. Relational…<br />
  9. 9. XML…?<br />
  10. 10. Evolution…<br />
  11. 11. If you’re a performance nerd, <br /> this is actually cool…<br />No one figured out XML yet…<br />Solving the customer problem…<br />Back to basics…<br />Deeper understanding of<br /> the data handling issues…<br />So why the “….” XML…?<br />
  12. 12. Agenda<br />
  13. 13. Free Format…”XML is cool”… <br />(aka no design effort)<br />Have to Uphold the “Coding Granny Argument”…<br />Everyone for themselves…<br />Waiting for “Codd, Date”…<br />Square wheels…<br />What’s spoiling the soup…?<br />
  14. 14. Different data models<br />XPath models an XML document as <br /> a tree while most general purpose <br /> programming languages <br /> have no native data types for a tree.<br />Different programming paradigms <br />XSLT is a functional language, while Java <br /> is object-oriented and Perl is a procedural one.<br />Impedance Mismatch<br />
  15. 15. Effects, Costs<br />Unnecessary CPU and Memory <br />Overhead <br />A lot of expensive type and <br /> encoding conversions<br />Impedance Mismatch<br />
  16. 16. Agenda<br />
  17. 17.
  18. 18.
  19. 19.
  20. 20.
  21. 21.
  22. 22. Containerization<br />
  23. 23. The “Dimensions” in 1 XML doc.<br />1<br />3<br />4<br />5<br />2<br />X<br />Y<br />6<br />Z<br />nx<br />rows <br />Elements with maxoccurs=“unbounded”<br />
  24. 24. Multi Dimensional Issues…<br />Its a database…<br />Its Row based<br />Its Column based<br />Its multiple databases…<br />More then 1 XML doc<br />Not uncommon 1 Mb >><br />
  25. 25. Complexities of a database<br />“Relations”<br />“Redundancy”<br />“Nullology”<br />Design, etc…<br />It can contain a database<br />10 Mb or bigger nowadays<br />More often than less…<br />Enormous complex XSD’s <br />XMLType – Not just a “Container”<br />
  26. 26. Checked on<br />XML Well-Formedness<br />One root element<br />Begin & End tags<br />If XML Schema reference<br />XOB methods will be used if an XML Schema is available<br />DOM methods will be used if registered <br /> XML Schema information is not available <br />XMLType – Not just a “Datatype”<br />
  27. 27. What you want in access…<br />Fast DDL<br />Selects<br />Inserts, Deletes, Updates<br />Specific / Smart<br />Small XML Fragments<br />Direct Access<br />
  28. 28. Mistakes are very, very Painful!<br />Inserts, Updates & Deletes<br />Fast <br />Efficient<br />Selects<br />Precise<br />Via Indexes ?<br />XML Validation<br />Strict, Lazy, really needed ?<br />Client Side Possibilities<br />
  29. 29. Agenda<br />
  30. 30. Oracle XMLType<br />“Containers”<br />
  31. 31. XOB<br />DOM<br />XMLType Memory<br />
  32. 32. Object Relational<br />Binary<br />CLOB<br />XMLType<br />
  33. 33. Physical<br />Design<br />Logical<br />Design<br />XMLType Solutions<br />
  34. 34. Document contra Data Driven<br />
  35. 35. Structured / Semi-Structured<br />Structured<br />Semi<br />Structured<br />
  36. 36. Common XML Parsers<br />Often DOM or Infoset based<br />CPU intensive<br />Memory intensive<br />Serializing, parsing, tree traversals, happen in memory…<br />
  37. 37. In Memory: Common XML Parsers<br />Often handle XML tree traversals only via <br />ONEmethod<br />It is not structured, semi-structured or unstructured XML content aware<br />It is not very “smart” / “content aware” regarding XMLhandling based on its XML tree’s and/or XML data content<br />
  38. 38. XMLType Physical Storage<br />CLOB<br />LOB<br />LOB index<br />Object Relational<br />Varray, Types, Nested Tables<br />IOT, B-Tree, XML Schema<br />Binary XML<br />LOB, LOB Index<br />Stored in Post Parse Representation<br />
  39. 39. Hybrid<br />CLOB<br />Mixed<br />complex[n]<br />un/structured<br />XSD [y]<br />B-Tree, IOT<br />Document<br />na<br />unstructured<br />XSD [n]<br />XMLIndex<br />Relational World<br />XMLDB World<br />XML Data Storage<br />XMLType<br />column/tables<br />XMLType<br />Views<br />Obj.Rel.<br />Binary XML<br />Content<br />complex[n]<br />structured<br />XSD [y]<br />B-Tree, IOT<br />(Object) <br />Relational <br />Objects<br />Mixed<br />complex[y]<br />un/structured<br />XSD [y/n]<br />XMLIndex<br />Relational <br />Tables<br />
  40. 40. Choosing a Storage Model<br />
  41. 41. Agenda<br />
  42. 42. Index Quick Sheet<br />
  43. 43. Unstructured XMLIndex (UXI), 11.1<br />PathTable<br />UsePath Subsetting<br />FullBlown XMLIndex canbe BIG <br />Token Tables (XDB.X$......)<br />Query re-writeonTokens<br />Fuzzy Searches, //<br />Optimizer Statistics<br />CanbemaintainedManually<br />Recorded inPending Table<br />Secondairyindexespossible<br />Unstructured<br />XMLIndex<br />f (x)<br />Path Table<br />
  44. 44. Structured XMLIndex (SXI), 11.2<br />Content Table(s)<br />BasedonXMLTABLE syntax<br />XMLTable construct canbe<br />nestedbut:<br />Only 1 extra XMLType allowed<br />VIRTUAL column is passed<br />CanbemaintainedManually<br />Secondairyindexespossible<br />Structured<br />XMLIndex<br />f (x)<br />Content<br />Tables<br />
  45. 45. Driving access on CONTENT<br />BTree Index<br />bookstore<br />Secondary Oracle Text Index<br />Function based Index (XPath)<br />B-Tree<br />Index<br />book<br />whitepaper<br /> StructuredXMLIndex<br />Unstructured<br />XMLIndex<br />title<br />author<br />author<br />chapter<br />title<br />author<br />id<br />paragraph<br />content<br />structured<br />content<br />
  46. 46. There can be only one XMLIndex…<br />
  47. 47. Agenda<br />
  48. 48. Design<br />
  49. 49. XML Schema will be parsed only once<br />XML Schema will be cached in memory (SGA)<br />No additional parsing<br />No additional validation<br />XML Schema registration doesn’t <br />have to be creating types/tables…<br />Binary XML has part of the solution<br />XML Schema Advantages<br />
  50. 50. XML Document structure is known, therefore<br />No parsing is needed when loaded from disk into memory<br />XML OBject (XOB) structures can be applied<br />Memory footprint is much less compared to DOM structure<br />Needed specific nodes can now be handled efficiently in memory<br />XML Schema Advantages<br />
  51. 51. XDB Annotations<br />Hybrid: CLOB withinOR<br />
  52. 52. XDB Annotations (OR/Binary XML)<br />Levels<br />Root, Simpletype, Complextype<br />xmlns:xdb="http://xmlns.oracle.com/xdb"<br />xdb:storeVarrayAsTable<br />xdb:defaultTable<br />xdb:maintainDom<br />xdb:maintainOrder<br />xdb:SQLInline<br />Oracle V.11.1.0.7.0 - Partitioning <br />xdb:tableprops<br />
  53. 53. Mixing Logical and Physical Design<br />
  54. 54. XDB Utilities Toolset<br />Object Relational Storage<br />And a bit regarding Binary XML<br />Makes xdb:annotation easy<br />Helper Packages for index creation<br />Whitepaper on “best practices”<br />Not a Replacement for <br />proper XML (Schema) Design<br />
  55. 55. XML Schema - Query Rewrite<br />String<br />CHAR<br />String<br />Float<br />bookstore<br />CLOB<br />VARCHAR2<br />(20)<br />book<br />whitepaper<br />title<br />author<br />author<br />chapter<br />title<br />author<br />id<br />paragraph<br />NUMBER<br />(15)<br />content<br />content<br />
  56. 56. XML Design<br />Avoid Cyclic References in XML Schemata<br />For ease of Maintenance: xdb:annotations<br />Is DOM validation, fidelity needed ?<br />CPU / XML parsing: <br /> XML Schema validation “overhead” ?<br />Index maintenance overhead, <br /> when using “disk” solutions<br />Y<br />X<br />
  57. 57. Be aware of what you are doing !<br />Avoid unneeded (full) XML Schema validation<br />During Storage (Inserts), Generating XML<br />xdb:MaintainDOM=false<br />Avoid Impedance mismatch<br />Java  XML  Java  XML  Relational  XML  Java (“All In One Go Objective”)<br />Avoid XML fragments<br />// and/or via XMLEXISTS<br />Use Indexes <br />Y<br />X<br />
  58. 58. Agenda<br />
  59. 59. Keep XML small<br />Do not use / enforce Pretty Print if not needed<br />Avoid namespace reference “Overkill”<br />Most used Namespace is Leading <br />Use short Namespace References<br />Make XML data as “sparse” as possible<br /><employee><name>Marco</name></employee><br /><employee name=“Marco”/><br />XML Data Partitioning<br />Binary XML if needed<br />Y<br />X<br />
  60. 60. Keep XML small (OR specific)<br />Don’t use “meaning full element names”<br />64Kb DDL “create table” buffer<br />ORA 01792 maximum number of columns in a table or view is 100<br />Break XML up<br />Out of Line<br />CLOB (unstructured)<br />Not Accessed Data<br />Don’t create objects if you don’t need it<br />Use xdb:defaultTable=“” for global types<br />
  61. 61. Holistic Approach & DEMO<br />
  62. 62. Customer Use Case<br />Memory<br />/ DOM<br />Memory<br />/ DOM<br />CLOB<br /> Oracle <br />Advanced Queue<br />XMLType<br />BLOB<br />Process <br />Checks<br />Validation<br />XML Schema<br />(JAVA)<br />Store in <br />ETL Tables<br />Shred Elements<br />Via XMLDOM<br />
  63. 63. New XML Approach<br />Rewrite on Disk <br />/ XOB <br />(Relational)<br />CLOB<br /> Oracle <br />Advanced Queue<br />BLOB<br />Store in <br />ETL Tables<br />Oracle <br />Workflow<br />Validation<br />Against <br />XML Schema<br />Checks<br />XMLType Table<br />(O.R)<br />
  64. 64. Using the CBO as an XML Parser…<br />ORA-31186<br />ORA-31186<br />ORA-31186<br />ORA-31186: Document contains too many nodes<br />Cause: Unable to load the document because it has exceeded the maximum allocated number of DOM nodes.<br />
  65. 65. Demonstration<br />XDB Utilities<br />JDeveloper<br />XML Schema <br />xdb:annotations<br />Effect on Queries<br />
  66. 66. Recap<br />
  67. 67. Using the (XML) Relational Mindset<br />Design XSD as you would with E(E)R<br />Design for proper physical access, performance:<br />Storage, Index<br />Content Awareness<br />Partitioning <br />Overkill of “meaning full” data parsing<br />Avoid Redundancy, whitespace, “Pretty Print”<br />Design with the future in mind<br />
  68. 68. So in short: Balanced Design<br />Inserts, Updates & Deletes<br />XML Future Changes <br />Index Maintenance<br />Selects<br />In Memory<br />Via Indexes<br />XML Validation<br />Strict, Lazy<br />Client Side Possibilities<br />
  69. 69. Reward<br />Optimal performance<br />Out performing standard <br />XML solutions<br />PL/SQL, SQL access optimized <br />for best performance on XML<br />PL/SQL, SQL, Design, Access:<br />Efficient<br />Fast<br />
  70. 70.
  71. 71. References (1)<br />Oracle XML DB <br />http://download.oracle.com/docs/cd/E11882_01/appdev.112/e16659/toc.htm<br />XML DB OTN / FAQ Thread<br />http://forums.oracle.com/forums/forum.jspa?forumID=34<br />http://forums.oracle.com/forums/thread.jspa?threadID=410714<br />
  72. 72. References (2)<br />Oracle Whitepapers<br />Oracle XML DB : Choosing the Best XMLType Storage Option for Your Use Case (PDF)<br />Oracle XML DB : Best Practices to Get Optimal Performance out of XML Queries (PDF)<br />Blog<br />http://technology.amis.nl/blog<br />http://blog.gralike.com (Dedicated XMLDB blog)<br />

×