Top Banner
An XML Document’s Life – Dr. Node! Donna Di Carlo Terri Grissom, Michael Murley BMC Software, Inc.
43

An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Aug 06, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

An XML Document’s Life – Dr. Node!

Donna Di Carlo

Terri Grissom, Michael Murley

BMC Software, Inc.

Page 2: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

Agenda – Meet Dr. Node!

• Overview of XML Data Type

• Parse document into a tree of nodes

• Examine nodes in a Parsed Document

• DB2 V10 XML features

• Multi-Versioning

• XMLMODIFY

• XML Index Considerations

• DB2 V10 DATE and TIMESTAMP Index types

2

Page 3: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

Acknowledgements / Disclaimers

IBM®, DB2®, z/OS® are registered service marks and trademarks of International Business Machines Corporation, in the United States and/or other countries

DSN1PRNT output references contained are also of IBM.

The information contained in this presentation has not been submitted to any formal review and is distributed on an “As Is” basis.

3

Page 4: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

XML Data Type

• XML Data type introduced in DB2 V9, enhanced in V10

• pureXML is DB2 implementation

• Part of ANSI SQL Standard

• SQL/XML extension

• Handling functions – XMLQUERY, XMLTABLE, XMLEXISTS

• Conversion functions – XMLCAST, XMLPARSE, XMLSERIALIZE

• XML indexes to improve performance

• Optional Schema Validation

4

Page 5: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

Create Table with XML Data Type

Create Table IDUG.SCHEDULE

( IDUGID Integer,

SCHEDULE XML)

In XMLIDUG.CONF;

Or

Alter Table IDUG.SCHEDULE

Add Column SCHEDULE XML;

5

Base Ts XMLIDUG.CONF

Docid Ix XMLIDUG.IRDOCIDC

XML Ts XMLIDUG.XCON0000

Nodeid Ix XMLIDUG.IRNODEID

ZPARM IMPDSDEF

Yes All objects materialized

No Only Base Ts materialized

Page 6: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

SYSXMLRELS relates Base and XML table

Select XMLTBOWNER, XMLTBNAME

From SYSIBM.SYSXMLRELS

Where TBOWNER = ‘IDUG’ AND

TBNAME = ‘CONFERENCE’ AND

COLNAME = ‘SCHEDULE’

6

XMLTBOWNER XMLTBNAME

IDUG XCONFERENCE

Reference

Base table

with SQL -

not the XML

table

Page 7: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

Detail of Implicitly Created Objects

7

Xml Table:IDUG.XConference

Docid Bigint

Min_NodeID Varbin(128)

Xmldata Varbin(15850)

Start_Ts* Binary(8)*

End_Ts* Binary(8)*

Base Table: IDUG.Conference

IDUGID Integer

Schedule Varchar(14)*

DB2_Generated

_Docid_for_Xml

Bigint

Create Table IDUG.Conference

(IDUGID Integer

Schedule XML)

* Indicates DB2 V10 Multi-Versioned lengths and columns

Docid

Index

Docid

NodeID

Index

Docid

Xmldata

End_Ts*

Start_Ts*

Page 8: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

XML Space Determined by Base Space

Base

Simple

Segmented

Partition By Growth

UTS

XML

Partition by Growth

UTS

8

Base

Classic Partitioned

Range Partitioned

UTS

XML

Range Partitioned

UTS

XML document in partition

number corresponding to

base row partition number.

XML tablespace and base

tablespace grow

independently.

Page 9: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

XML Basics – Elements and Attributes

9

<name>John Doe</name>

<patient>

<id>1050</id>

<name prefix=“MR”>

<last>Doe</last>

<first>John</first>

<middle></middle>

</name>

</patient>

Empty

Element

last, first, and

middle are

siblings

id and name

are siblings

Root

Element

Start

Tag

End

Tag

Attribute

Elements can contain:

1) Text

2) Other Elements

3) Attributes

Page 10: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

XML Document with all statement types <?xml version=“1.0” encoding=“IBM037”?>

<!DOCTYPE patient [

<!ENTITY doctor “Dr Node”> ]>

<?xml-stylesheet type="text/xsl" href="style.xsl"?>

<patient xmlns=“http://patient.org”>

<id>1050</id>

<name prefix="MR">

<last>Doe</last>

<first>John</first>

<!-- No middle name for John -->

<!-- <middle></middle> -->

</name>

<doc>&doctor;</doc>

</patient>

10

Declaration

Document Type Definition

Processing Instruction

Comments

Namespace

Entity Reference

Elements with Text

Attribute

This slide represents every type of XML statement that can make up a document,

but not necessarily all of the syntax for each statement.

Page 11: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

Mapping of Statement Type to Node Type <?xml version=“1.0” encoding=“IBM037”?>

<!DOCTYPE patient [

<!ENTITY doctor “Dr Node”> ]>

<?xml-stylesheet type="text/xsl" href="style.xsl"?>

<patient xmlns=“http://patient.org”>

<id>1050</id>

<name prefix="MR">

<last>Doe</last>

<first>John</first>

<!-- No middle name for John -->

<!-- <middle></middle> -->

</name>

<doc>&doctor;</doc>

</patient>

11

Declaration

Document Type Defn

Processing Instr

Comments

Namespace

Elements & Text

Attribute

Document x’44’

Doctype x’42’

Processing Instr x’50’

Namespace x’4E’

Attribute x’41’

Element x’45’

Text x’54’

Comment x’43’

Node Type

Example:

<first>John</first>

Element x’45’ – stores element ‘first’*

Text x’54’ – stores text ‘John’

*SYSXMLSTRINGS stores element names and assigns a 4 byte stringid

Page 12: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

Document ‘Skeleton’ – Nodes

• Document x’44’ Ascii D

• Namespace x’4E’ Ascii N

• Doctype x’42’ Ascii B

• Element x’45’ Ascii E

• Attribute x’41’ Ascii A

• Text x’54’ Ascii T

• Comment x’43’ Ascii C

• Processing

Instruction x’50’ Ascii P

• Continue x’55’ Ascii U

• Range Proxy x’52’ Ascii R

12

Stored in all Nodes:

Node Type byte

Flags:

Proxy Flag

Continued Flag

Spanned Flag

No Escape Flag

Node Length

Local Node id Length

Local Node id Value

Node Types that correspond to your XML:

Node Types to span documents across records:

Every Node is

assigned an ID

Page 13: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

Initial Node ID Assignment Rules

• Each node is assigned an ID:

• Variable length, 1 to 8 bytes

• Rightmost byte is always even; other bytes are odd

• Ex: 02 is valid node id; 01 is invalid

• Ex: A102 is valid node id; A1 is invalid

• Starts at “02” and ascends by 2 for sibling nodes

• Example: 02, 04… 9C, 9E, A0, A102, A104…A2…

• At each subsequent branch of the tree, the ID starts over at “02”

13

02

02

02 04 06

04

Local Id: 04

Absolute Id: 020204

02

02

02 04 06 08

04

02

ID of sibling

added after

020206?

ID of child

added to

0204?

Page 14: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

An Example – Meet the Patient

14

<?xml version=“1.0” encoding=“IBM037”?>

<IDUG>

<conf>EMEA 2012</conf>

<session day=“Monday”>

<id>J12</id>

<speaker>Terri Grissom</speaker>

</session>

</IDUG>

Element

x’45’

1) IDUG

2) conf

3) session

4) id

5) speaker

Attribute

x’41’

1) day=

“Monday”

Text

x’54’

1) EMEA 2012

2) J12

3) Terri

Grissom

Document

x’44’

1.0

IBM037

10 nodes

Node

Type

Byte

Quiz:

What is the Root Element?

IDUG has how many children? IDUG

2

Page 15: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

Surgery (Parsing)

02

Document

02 Element IDUG

02 Element conf

02 Text EMEA 2012

04 Element session

02 Attribute day=Monday

04 Element

id

02 Text

J12

06 Element Speaker

02 Text

Terri Grissom

15

<?xml version=“1.0” encoding=“IBM037”?>

<IDUG>

<conf>EMEA 2012</conf>

<session day=“Monday”>

<id>J12</id>

<speaker>Terri Grissom</speaker>

</session>

</IDUG> Root Node

Node ID

Page 16: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

Surgery Assistant - SYSXMLSTRINGS

Select STRINGID, HEX(STRINGID), STRING

From SYSIBM.SYSXMLSTRINGS

Where STRINGID in (1261,1341,1342,1343,1011,1346,1348);

16

SYSIBM.SYSXMLSTRINGS

STRINGID HEX(STRINGID) STRING

1261 000004ED IBM037 Encoding Scheme

1341 0000053D IDUG Element

1342 0000053E conf Element

1343 0000053F session Element

1011 000003F3 id Element

1346 00000542 speaker Element

1348 00000544 day Attribute

Stringid

stored

in node

in XML

table

Page 17: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

day=

Monday

Node type x’41’

session

Node type x’45’ Node type x’45’

Emea

2012

Node type x’54’

conf

02 Document

02 Element IDUG

02 Element conf

02 Text EMEA 2012

04 Element session

02 Attribute day=Monday

04 Element id

02 Text J12

06 Element Speaker

02 Text Terri

Grissom

IDUG

Node type x’45’

DSN1PRNT – 10 nodes

RECORD: XOFFSET='0014'X PGSFLAGS='02'X PGSLTH=251 PGSLTH='00FB'X PGSOBD='0000'X PGSBID='01'X

00800000 00000000 01C9C8A7 0A421AEE A4FFFFFF FFFFFFFF FF001D00 1E020010 .............B..................

00010000 00000000 00000000 440000C9 01020001 00000000 31000004 ED780000 ............D...........1....x..

00000000 00450000 B0010200 02000000 00000005 3D000000 00450000 25010200 .....E..............=....E..%...

01000000 00000005 3E000000 00541000 11010200 09454D45 41203230 31324500 ........>....T.......EMEA 2012E.

00770104 00030000 00000000 053F0000 00004110 001A0102 00000000 00000544 .w...........?....A............D

00000000 00064D6F 6E646179 4500001F 01040001 00000000 000003F3 00000000 ......MondayE...................

5410000B 01020003 4A313245 00002A01 06000100 00000000 00054200 00000054 T.......J12E..*...........B....T

10001601 02000E54 65727269 20477269 73736F6D 20 .......Terri Grissom

17

Node type x’44’

Node type x’45’

Node type x’54’

Document IDUG conf

Emea

2012

Node type x’45’

session

Page 18: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

Nodes Under a Microscope

18

Document Node: 44 00 00C9 01 02 0001 0000000031 000004ED 7800000000000000

Element Node: 45 00 00B0 01 02 0002 00000000 0000053D 00000000

02 Document

02 Element IDUG

02 Element conf

02 Text EMEA 2012

04 Element session

Element Node: 45 00 0025 01 02 0001 00000000 0000053E 00000000

Text Node: 54 10 0011 01 02 0009 454D4541 20323031 32

Node

Type

Node

Lgth

Node id

Lgth/

Value

#

Child

ren

Stringid

Sysxmlstrings

Txt Lgth Text: EMEA 2012

IBM037 Xml Version 1

IDUG

conf

RECORD: XOFFSET='0014'X PGSFLAGS='02'X PGSLTH=251 PGSLTH='00FB'X

00800000 00000000 01C9C8A7 0A421AEE A4FFFFFF FFFFFFFF FF001D00 1E020010

00010000 00000000 00000000 440000C9 01020001 00000000 31000004 ED780000

00000000 00450000 B0010200 02000000 00000005 3D000000 00450000 25010200

01000000 00000005 3E000000 00541000 11010200 09454D45 41203230 31324500

00770104 00030000 00000000 053F0000 00004110 001A0102 00000000 00000544

00000000 00064D6F 6E646179 4500001F 01040001 00000000 000003F3 00000000

5410000B 01020003 4A313245 00002A01 06000100 00000000 00054200 00000054

10001601 02000E54 65727269 20477269 73736F6D 20

Page 19: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

Nodes Under a Microscope

19

Element Node: 45 00 0077 01 04 0003 00000000 0000053F 00000000

Attribute Node: 41 10 001A 01 02 00000000 00000544 00000000 0006 4D6F6E646179

Element Node: 45 00 001F 01 04 0001 00000000 000003F3 00000000

Text Node: 54 10 000B 01 02 0003 4A3132

Node

Type

Node

Lgth

Node id

Lgth/

Value

#

Child

ren

Stringid

Sysxmlstrings

Txt Lgth Value: J12

04 Element session

02 Attribute day=Monday

04 Element id

02 Text

J12

06 Element speaker

02 Text Terri Grissom

Stringid : day Lgth Value : Monday

session

id

RECORD: XOFFSET='0014'X PGSFLAGS='02'X PGSLTH=251 PGSLTH='00FB'X

00800000 00000000 01C9C8A7 0A421AEE A4FFFFFF FFFFFFFF FF001D00 1E020010

00010000 00000000 00000000 440000C9 01020001 00000000 31000004 ED780000

00000000 00450000 B0010200 02000000 00000005 3D000000 00450000 25010200

01000000 00000005 3E000000 00541000 11010200 09454D45 41203230 31324500

00770104 00030000 00000000 053F0000 00004110 001A0102 00000000 00000544

00000000 00064D6F 6E646179 4500001F 01040001 00000000 000003F3 00000000

5410000B 01020003 4A313245 00002A01 06000100 00000000 00054200 00000054

10001601 02000E54 65727269 20477269 73736F6D 20

Page 20: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

Summary of how sample document was stored

• Document was parsed into 10 nodes

• Order of nodes reflects a hierarchy

• Document Node first

• Root Element Node (IDUG) next

• Tree of nodes stored top-down, left to right

• Children nodes stored before Siblings

• Ex: Text of conf (EMEA 2012) before conf sibling (session)

• Each node is assigned an id based on its tree position

• Element and Attribute names stored in

SYSIBM.SYSXMLSTRINGS

• Values assigned a 4 byte Stringid

• 4 byte Stringid is stored in Element & Attribute Nodes

20

Page 21: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

Multi-Versioning – more versions of Dr. Node! • What is it?

• New in V10 - supports multiple versions of an XML document

• Benefits?

• Improves concurrency thru lock avoidance

• Allows sub-document update via XMLMODIFY

• Prerequisites?

• Automatic if V10 and Base table is a Universal Tablespace

• How is it implemented?

• Base table

• XML column increases from Varchar(6) to Varchar(14)

• Extra 8 bytes used to point to current version in XML table

• XML table

• Addition of Start_ts and End_ts fields

21

Page 22: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

Introduction to Versioning

22

XML Tablespace

Docid 008000000000000001

Start_Ts x’C9C8A70A421AEEA4’

End_Ts x’FFFFFFFFFFFFFFFF’

Min Node

ID

02

RECORD: XOFFSET='0014'X PGSFLAGS='02'X PGSLTH=251 PGSLTH='00FB'X PGSOBD='0000'X PGSBID='01'X

00800000 00000000 01C9C8A7 0A421AEE A4FFFFFF FFFFFFFF FF001D00 1E020010

00010000 00000000 00000000 440000C9 01020001 00000000 31000004 ED780000

DSN1PRNT of XML Tablespace:

Base Tablespace

Docid 008000000000000001

XML

Indicator,

offset x’02’

X’0000’

# times XML document

was updated

XML

Indicator,

offset x’06’

x’C9C8A70A421AEEA4’

Points to current version

in the xml ts.

Currently only 1 version of the XML document in the XML tablespace.

END_TS of all x’FF’ in the XML table indicates the current version.

Page 23: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

XMLMODIFY – Update

23

Replace value of id from J12 to K13:

Update IDUG.CONFERENCE

Set SCHEDULE = XMLMODIFY (

‘replace value of node /IDUG/session/id with “K13” ’)

Where IDUGID = 1000;

04 Element session

02 Attribute day=Monday

04 Element id

02 Text J12

06 Element speaker

02 Text

Terri Grissom

02 Text K13

Page 24: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

XMLMODIFY – Insert

Insert node company:

Update IDUG.CONFERENCE

Set SCHEDULE = XMLMODIFY (

‘insert node $co after /IDUG/session/id’,

XMLPARSE (document ‘<company>BMC Software</company>’)

as “co”)

Where IDUGID = 1000;

24

02 Element IDUG

02 Element conf

04 Element session

02 Attribute day=Monday

04 Element Id

02 Text

K13

06 Element Speaker

02 Text

Terri Grissom

0580 Element company

02 Text BMC

Software

Insert Before/After - -> Create sibling

Insert Into - -> Create child

session now has 4 children

Node id 0580

between 04

and 06

Page 25: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

XMLMODIFY - Delete

Delete attribute day node:

Update IDUG.CONFERENCE

Set SCHEDULE = XMLMODIFY (

‘delete nodes /IDUG/session/@day’)

Where IDUGID = 1000;

25

04 Element session

02 Attribute day=Monday

04 Element id

02 Text K13

0580 Element company

02 Text BMC Software

06 Element speaker

02 Text

Terri Grissom

@ is a

shortcut for

attribute::day

Page 26: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

XML TS after Original Insert

26

Original XML document

RECORD: XOFFSET='0014'X PGSFLAGS='02'X PGSLTH=251 PGSLTH='00FB'X

00800000 00000000 01C9C8A7 0A421AEE A4FFFFFF FFFFFFFF FF001D00 1E020010

00010000 00000000 00000000 440000C9 01020001 00000000 31000004 ED780000

START_TS END_TS

Document Node Length

Page 27: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

XML TS after 1 XMLMODIFY command

27

Original XML document

RECORD: XOFFSET='0014'X PGSFLAGS='02'X PGSLTH=251 PGSLTH='00FB'X

00800000 00000000 01C9C8A7 0A421AEE A4C9C8A7 4326026F 2A001D00 1E020010

00010000 00000000 00000000 440000C9 01020001 00000000 31000004 ED780000

After XMLMODIFY – Update id to K13

RECORD: XOFFSET='010F'X PGSFLAGS='02'X PGSLTH=251 PGSLTH='00FB'X PG

00800000 00000000 01C9C8A7 4326026F 2AFFFFFF FFFFFFFF FF001D00 1E020010

00010000 00000000 00000000 440000C9 01020001 00000000 31000004 ED780000

START_TS END_TS

Document Node Length

Page 28: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

XML TS after 2 XMLMODIFY commands

28

Original XML document

RECORD: XOFFSET='0014'X PGSFLAGS='02'X PGSLTH=251 PGSLTH='00FB'X

00800000 00000000 01C9C8A7 0A421AEE A4C9C8A7 4326026F 2A001D00 1E020010

00010000 00000000 00000000 440000C9 01020001 00000000 31000004 ED780000

After XMLMODIFY – Update id to K13

RECORD: XOFFSET='010F'X PGSFLAGS='02'X PGSLTH=251 PGSLTH='00FB'X

00800000 00000000 01C9C8A7 4326026F 2AC9C8A7 587FA5E5 A6001D00 1E020010

00010000 00000000 00000000 440000C9 01020001 00000000 31000004 ED780000

After XMLMODIFY – Insert company

RECORD: XOFFSET='020A'X PGSFLAGS='02'X PGSLTH=292 PGSLTH='0124'X

00800000 00000000 01C9C8A7 587FA5E5 A6FFFFFF FFFFFFFF FF001D00 1E020010

00010000 00000000 00000000 440000F2 01020001 00000000 31000004 ED780000

START_TS END_TS

Document Node Length

Document Node Length

Page 29: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

XML TS after 3 XMLMODIFY commands

29

Original XML document

RECORD: XOFFSET='0014'X PGSFLAGS='02'X PGSLTH=251 PGSLTH='00FB'X

00800000 00000000 01C9C8A7 0A421AEE A4C9C8A7 4326026F 2A001D00 1E020010

00010000 00000000 00000000 440000C9 01020001 00000000 31000004 ED780000

After XMLMODIFY – Update id to K13

RECORD: XOFFSET='010F'X PGSFLAGS='02'X PGSLTH=251 PGSLTH='00FB'X

00800000 00000000 01C9C8A7 4326026F 2AC9C8A7 587FA5E5 A6001D00 1E020010

00010000 00000000 00000000 440000C9 01020001 00000000 31000004 ED780000

After XMLMODIFY – Insert company

RECORD: XOFFSET='020A'X PGSFLAGS='02'X PGSLTH=292 PGSLTH='0124'X

00800000 00000000 01C9C8A7 587FA5E5 A6C9C8A7 6EF923E8 A3001D00 1E020010

00010000 00000000 00000000 440000F2 01020001 00000000 31000004 ED780000

After XMLMODIFY – Delete attribute

RECORD: XOFFSET='032E'X PGSFLAGS='02'X PGSLTH=266 PGSLTH='010A'X

00800000 00000000 01C9C8A7 6EF923E8 A3FFFFFF FFFFFFFF FF001D00 1E020010

00010000 00000000 00000000 440000D8 01020001 00000000 31000004 ED780000

START_TS END_TS

Document Node Length

Document Node Length

Document Node Length

Page 30: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

Base Table Points to Current Version

XML Ind offset x’06’ # upd

x’C9C8A76EF923E8A3’ 0003

30

Start_ts End_ts

x’C9C8A70A421AEEA4’ x’C9C8A74326026F2A’ Original

x’C9C8A74326026F2A’ x’C9C8A7587FA5E5A6’ K13 update

x’C9C8A7587FA5E5A6’ X’C9C8A76EF923E8A3’ Insert company

x’C9C8A76EF923E8A3’ X’FFFFFFFFFFFFFFFF’ Delete attribute

Base Table XML Table

Page 31: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

DSN1PRNT Before Reorg – 4 records

31

RECORD: XOFFSET='0014'X PGSFLAGS='00'X PGSLTH=251 PGSLTH='00FB'X

00800000 00000000 01C9C8A7 0A421AEE A4C9C8A7 4326026F 2A001D00 1E020010

00010000 00000000 00000000 440000C9 01020001 00000000 31000004 ED780000

00000000 00450000 B0010200 02000000 00000005 3D000000 00450000 25010200

01000000 00000005 3E000000 00541000 11010200 09454D45 41203230 31324500

00770104 00030000 00000000 053F0000 00004110 001A0102 00000000 00000544

00000000 00064D6F 6E646179 4500001F 01040001 00000000 000003F3 00000000

5410000B 01020003 4A313245 00002A01 06000100 00000000 00054200 00000054

10001601 02000E54 65727269 20477269 73736F6D 20

RECORD: XOFFSET='010F'X PGSFLAGS='00'X PGSLTH=251 PGSLTH='00FB'X

00800000 00000000 01C9C8A7 4326026F 2AC9C8A7 587FA5E5 A6001D00 1E020010

00010000 00000000 00000000 440000C9 01020001 00000000 31000004 ED780000

00000000 00450000 B0010200 02000000 00000005 3D000000 00450000 25010200

01000000 00000005 3E000000 00541000 11010200 09454D45 41203230 31324500

00770104 00030000 00000000 053F0000 00004110 001A0102 00000000 00000544

00000000 00064D6F 6E646179 4500001F 01040001 00000000 000003F3 00000000

5410000B 01020003 4B313345 00002A01 06000100 00000000 00054200 00000054

10001601 02000E54 65727269 20477269 73736F6D 20

RECORD: XOFFSET='020A'X PGSFLAGS='02'X PGSLTH=292 PGSLTH='0124'X

00800000 00000000 01C9C8A7 587FA5E5 A6C9C8A7 6EF923E8 A3001D00 1E020010

00010000 00000000 00000000 440000F2 01020001 00000000 31000004 ED780000

00000000 00450000 D9010200 02000000 00000005 3D000000 00450000 25010200

01000000 00000005 3E000000 00541000 11010200 09454D45 41203230 31324500

00A00104 00040000 00000000 053F0000 00004110 001A0102 00000000 00000544

00000000 00064D6F 6E646179 4500001F 01040001 00000000 000003F3 00000000

5410000B 01020003 4B313345 00002902 05800001 00000000 00000543 00000000

54100014 0102000C 424D4320 536F6674 77617265 4500002A 01060001 00000000

00000542 00000000 54100016 0102000E 54657272 69204772 6973736F 6D20

RECORD: XOFFSET='032E'X PGSFLAGS='02'X PGSLTH=266 PGSLTH='010A'X

00800000 00000000 01C9C8A7 6EF923E8 A3FFFFFF FFFFFFFF FF001D00 1E020010

00010000 00000000 00000000 440000D8 01020001 00000000 31000004 ED780000

00000000 00450000 BF010200 02000000 00000005 3D000000 00450000 25010200

01000000 00000005 3E000000 00541000 11010200 09454D45 41203230 31324500

00860104 00030000 00000000 053F0000 00004500 001F0104 00010000 00000000

03F30000 00005410 000B0102 00034B31 33450000 29020580 00010000 00000000

05430000 00005410 00140102 000C424D 4320536F 66747761 72654500 002A0106

00010000 00000000 05420000 00005410 00160102 000E5465 72726920 47726973

736F6D20

Current Version

Page 32: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

DSN1PRNT After Reorg

32

RECORD: XOFFSET='0014'X PGSFLAGS='00'X PGSLTH=251 PGSLTH='00FB'X

00800000 00000000 01C9C8A7 0A421AEE A4C9C8A7 4326026F 2A001D00 1E020010

00010000 00000000 00000000 440000C9 01020001 00000000 31000004 ED780000

00000000 00450000 B0010200 02000000 00000005 3D000000 00450000 25010200

01000000 00000005 3E000000 00541000 11010200 09454D45 41203230 31324500

00770104 00030000 00000000 053F0000 00004110 001A0102 00000000 00000544

00000000 00064D6F 6E646179 4500001F 01040001 00000000 000003F3 00000000

5410000B 01020003 4A313245 00002A01 06000100 00000000 00054200 00000054

10001601 02000E54 65727269 20477269 73736F6D 20

RECORD: XOFFSET='010F'X PGSFLAGS='00'X PGSLTH=251 PGSLTH='00FB'X

00800000 00000000 01C9C8A7 4326026F 2AC9C8A7 587FA5E5 A6001D00 1E020010

00010000 00000000 00000000 440000C9 01020001 00000000 31000004 ED780000

00000000 00450000 B0010200 02000000 00000005 3D000000 00450000 25010200

01000000 00000005 3E000000 00541000 11010200 09454D45 41203230 31324500

00770104 00030000 00000000 053F0000 00004110 001A0102 00000000 00000544

00000000 00064D6F 6E646179 4500001F 01040001 00000000 000003F3 00000000

5410000B 01020003 4B313345 00002A01 06000100 00000000 00054200 00000054

10001601 02000E54 65727269 20477269 73736F6D 20

RECORD: XOFFSET='020A'X PGSFLAGS='02'X PGSLTH=292 PGSLTH='0124'X

00800000 00000000 01C9C8A7 587FA5E5 A6C9C8A7 6EF923E8 A3001D00 1E020010

00010000 00000000 00000000 440000F2 01020001 00000000 31000004 ED780000

00000000 00450000 D9010200 02000000 00000005 3D000000 00450000 25010200

01000000 00000005 3E000000 00541000 11010200 09454D45 41203230 31324500

00A00104 00040000 00000000 053F0000 00004110 001A0102 00000000 00000544

00000000 00064D6F 6E646179 4500001F 01040001 00000000 000003F3 00000000

5410000B 01020003 4B313345 00002902 05800001 00000000 00000543 00000000

54100014 0102000C 424D4320 536F6674 77617265 4500002A 01060001 00000000

00000542 00000000 54100016 0102000E 54657272 69204772 6973736F 6D20

RECORD: XOFFSET='032E'X PGSFLAGS='02'X PGSLTH=266 PGSLTH='010A'X

00800000 00000000 01C9C8A7 6EF923E8 A3FFFFFF FFFFFFFF FF001D00 1E020010

00010000 00000000 00000000 440000D8 01020001 00000000 31000004 ED780000

00000000 00450000 BF010200 02000000 00000005 3D000000 00450000 25010200

01000000 00000005 3E000000 00541000 11010200 09454D45 41203230 31324500

00860104 00030000 00000000 053F0000 00004500 001F0104 00010000 00000000

03F30000 00005410 000B0102 00034B31 33450000 29020580 00010000 00000000

05430000 00005410 00140102 000C424D 4320536F 66747761 72654500 002A0106

00010000 00000000 05420000 00005410 00160102 000E5465 72726920 47726973

736F6D20

Current Version

Reorg does

not always

delete old

versions

Page 33: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

V10 is Date and Time friendly

• Native XML date and Time support:

• Data types: ex: xs:date, xs:time, xs:duration

• Comparison operators: ex: op:date-equal, op:duration-equal

• Functions: fn:current-date, fn:current-time, fn:day-from-date

• Arithmetic operators: op:subtract-dates

• XML Index types added for date and timestamp

• Generate Key Using Xmlpattern … As SQL DATE

• Generate Key Using Xmlpattern … As SQL TIMESTAMP

33

Create Index IDUG.PO_ORDERDT

On IDUG.PURCHASEORD(PO)

Generate Key Using Xmlpattern

‘/PO/order/orderdt’ AS SQL DATE;

Prior to V10 only had:

As SQL VARCHAR(x)

As SQL DECFLOAT

Page 34: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

Document with Date and Timestamps

<?xml version=“1.0” encoding=“IBM037”?>

<PO>

<order>

<orderno>1000</orderno>

<custno>GR320</custno>

<orderdt>2012-06-24</orderdt>

<items>

<item part=“2360”>

<qty>3</qty>

<shipdt>2012-07-02T14:00:00</shipdt>

</item>

<item part=“2370”>

<qty>5</qty>

<shipdt>2012-07-03T10:40:00</shipdt>

</item>

</items>

</order>

</PO>

34

Valid Date Format:

yyyy-mm-dd

Valid Timestamp format:

yyyy-mm-ddThh:mm:ss

Page 35: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

XML DATE Index

35

Example of <orderdt> that

would not be included in

Index:

2012-31-01

01-31-2012

2012-01-31T08:00:00

Included in Index:

2012-01-31

Create Index IDUG.PO_ORDERDT

On IDUG.PURCHASEORD(PO)

Generate Key Using Xmlpattern

‘/PO/order/orderdt’ AS SQL DATE;

<PO>

<order>

<orderno>1000</orderno>

<custno>GR320</custno>

<orderdt>2012-01-31</orderdt>

….

Format for SQL Date must be yyyy-mm-dd

Page 36: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

QUERYNO QBLOCKNO PLANNO TNAME ACCESSTYPE ACCESSNAME

1 1 1 PURCHASEORD R

EXPLAIN Access Path using DATE Index

36

Explain Plan Set Queryno = 1 For

Select ORDERNO

From IDUG.PURCHASEORD

WHERE

XMLEXISTS('/PO/order[orderdt>xs:date("2012-06-25")]‘ Passing PO);

Explain Results Before Index:

Table

Scan

XMLEXISTS:

Enclose compare in

brackets to avoid

Boolean predicate

Page 37: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

QUERYNO QBLOCKNO PLANNO TNAME ACCESSTYPE ACCESSNAME

1 1 1 PURCHASEORD R

EXPLAIN Access Path using DATE Index

37

Create Index IDUG.PO_ORDERDT

On IDUG.PURCHASEORD(PO)

Generate Key Using Xmlpattern

‘/PO/order/orderdt’ AS SQL DATE;

Explain Plan Set Queryno = 1 For

Select ORDERNO

From IDUG.PURCHASEORD

WHERE

XMLEXISTS('/PO/order[orderdt>xs:date("2012-06-25")]‘ Passing PO);

QUERYNO QBLOCKNO PLANNO TNAME ACCESSTYPE ACCESSNAME

1 1 1 PURCHASEORD DX PO_ORDERDT

Explain Results Before Index:

Explain Results After Index:

Index

Access

Table

Scan

XMLEXISTS:

Enclose compare in

brackets to avoid

Boolean predicate

Page 38: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

XML Timestamp format

• Valid Timestamp format:

yyyy-mm-ddThh:mm:ss.sssssssssssszzzzzz

Example: 2012-07-02T08:00:00.123456789012+06:00

Where:

yyyy four digit year

mm two digit month

dd two digit day

T Time-of-day separator

hh two digit hours

mm two digit minutes

ss two digit seconds

ssssssssssss 12 digit fractional seconds (optional)

zzzzzz time zone ((‘+’ or ‘-‘)hh:mm) or ‘Z’ (optional)

38

Minimum required value:

yyyy-mm-ddThh:mm:ss

Ex: 2012-07-01T08:15:00

Page 39: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

XML TIMESTAMP Index

39

Example of <shipdt> that

would not be included in

Index:

2012-07-02

2012-07-02T14

2012-07-02T14:00:123456789

Included in Index:

2012-07-02T14:00:00

2012-07-02T14:00:00-06:00

2012-07-02T14:00:00Z

2012-07-02T14:00:00.1234

Create Index IDUG.PO_ORDERDT

On IDUG.PURCHASEORD(PO)

Generate Key Using Xmlpattern

‘/PO/order/items/item/shipdt’

AS SQL TIMESTAMP;

<item part=“2360”>

<qty>3</qty>

<shipdt>2012-07-02T14:00:00

</shipdt>

</item>

….

Format is yyyy-mm-ddThh:mm:ss.sssssssssssszzzzzz

Page 40: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

QUERYNO QBLOCKNO PLANNO TNAME ACCESSTYPE ACCESSNAME

1 1 1 PURCHASEORD R

EXPLAIN Access Path Using Timestamp Index

40

Explain Plan Set Queryno = 1 For

Select ORDERNO

From IDUG.PURCHASEORD

WHERE

XMLEXISTS('/PO/order/items/item

[shipdt>xs:dateTime("2011-12-31T24:00:00")]‘ Passing PO);

Explain Results Before Index:

Table

Scan

XMLEXISTS:

Enclose compare in

brackets to avoid

Boolean predicate

Page 41: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

QUERYNO QBLOCKNO PLANNO TNAME ACCESSTYPE ACCESSNAME

1 1 1 PURCHASEORD R

EXPLAIN Access Path Using Timestamp Index

41

Create Index IDUG.PO_SHIPDT

On IDUG.PURCHASEORD(PO)

Generate Key Using Xmlpattern

‘/PO/order/items/item/shipdt’ AS SQL TIMESTAMP;

Explain Plan Set Queryno = 1 For

Select ORDERNO

From IDUG.PURCHASEORD

WHERE

XMLEXISTS('/PO/order/items/item

[shipdt>xs:dateTime("2011-12-31T24:00:00")]‘ Passing PO);

QUERYNO QBLOCKNO PLANNO TNAME ACCESSTYPE ACCESSNAME

1 1 1 PURCHASEORD DX PO_SHIPDT

Explain Results Before Index:

Explain Results After Index:

Index

Access

Table

Scan

XMLEXISTS:

Enclose compare in

brackets to avoid

Boolean predicate

Page 42: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Click to edit Master title style

XML Index Tips • “Lean” or fully qualified indexes perform better than “heavy” indexes

• Use /IDUG/session/speaker instead of //speaker

• XML Index may be used to evaluate XPath predicates in the

XMLEXISTS and XMLTABLE functions.

• XML Index will NOT be exploited with XMLQUERY function

• XMLEXISTS – enclose comparison in square brackets to avoid

Boolean comparison

• XML index is eligible to evaluate XMLEXISTS if type match and Node

containment.

• For a DECFLOAT, DATE, or TIMESTAMP index:

• String from document ignored if it cannot be converted into the

index data type.

• For a VARCHAR index:

• If key value exceeds limit, INSERT or CREATE INDEX will fail.

42

Page 43: An XML Document's Life - Dr. Node!neodbug.org/201308/dicarlo_anxmldocumentslifedrnode.pdfDSN1PRNT of XML Tablespace: Base Tablespace Docid 008000000000000001 XML Indicator, offset

Terri Grissom

BMC Software, Inc. [email protected]