Welcome!

Industrial IoT Authors: Pat Romanski, William Schmarzo, Elizabeth White, Stackify Blog, Yeshim Deniz

Related Topics: Industrial IoT

Industrial IoT: Article

Use a Native XML Database for Your XML Data

Deciding when an XQuery-based native XML database is better than an SQL database


dbxml> putDocument "" "for $i in (0 to 2999) return
<part number='{$i}'>
<description>Description of {$i}</description><category>
{$i mod 10}</category>
{if (($i mod 10) = 0) then <parent-part>{$i mod 3}</
parent-part> else ''}</part>" q
A single output line for each document will be printed as confirmation. The generated content looks like this:

<part number="999">
<description>Description of 999</description>
<category>9</category>
</part>
Every 10th document of the 3,000 generated will look something like this:

<part number="990">
<description>Description of 990</description>
<category>0</category>
<parent-part>0</parent-part>
</part>
The numbers vary to allow more complex queries later. Let's dive in. First, let's find all part records that contain a parent-part, or "from the container named parts select all part elements that also contain a parent-part as a direct child of that element" (see Listing 3).

If you're only interested in the parent-part element, try the following:


dbxml> query collection("parts")/part/parent-part
300 objects returned for eager expression 'collection
("parts")/part/parent-part'
dbxml> print
<parent-part>0</parent-part>
<parent-part>0</parent-part>
...
<parent-part>2</parent-part>
<parent-part>2</parent-part>
Or if you simply need the value of the parent-part element, execute this query:

dbxml> query collection("parts")/part/parent-part/text()
300 objects returned for eager expression 'collection("parts")/
part/parent-part/text()'
dbxml> print
0
0
...
2
2
To find documents without parent-part elements, see Listing 4. To find two specific parts by part number try the following:

dbxml> query 'collection("parts")/part[@number =
1070 or @number = 1032]'
2 objects returned for eager expression 'collection("parts")/
part[@number = 1070 or @number = 1032]'
dbxml> print
<part number="1070"><description>Description of 1070</
description><category>0</category><parent-part>2</
parent-part></part>
<part number="1032"><description>Description of 1032</
description><category>2</category></part>
Listing 5 shows it's equally simple to find a range of parts.

Now let's explore the effect of indices. Your query times may differ as your machine is likely different from ours, but the improvement should be somewhat comparable.


dbxml> setVerbose 1
dbxml> query collection("parts")/part[parent-part]
Query - Finished eager query execution,
time taken = 2399.15ms
300 objects returned for eager expression 'collection("parts")/
part[parent-part]'
Spending 2.4 seconds to examine 3,000 documents and find the matching 300 isn't bad for a file system, but this is a database engine. Indices should improve performance. Berkeley DB XML indices are specified in four parts: path type, node type, key type, and uniqueness. In this case we need to index the node elements to determine if something is present or not, and we won't expect this pattern to be unique. Let's try the query again, but this time with an index to optimize searches for documents containing a parent-part element, a "node-element-presence-none" index.

dbxml> addIndex "" parent-part node-element-presence-none
Adding index type: node-element-presence-none to node:
{}:parent-part
dbxml> query collection("parts")/part[parent-part]
Query - Finished eager query execution,
time taken = 176.925ms
300 objects returned for eager expression 'collection("parts")/
part[parent-part]'
From 2.4 seconds to just under 1/5th of a second seems like a worthwhile improvement. Let's try another query.

dbxml> query 'collection("parts")/part[parent-part = 1]'
Query - Finished eager query execution,
time taken = 215.387ms
100 objects returned for eager expression 'collection("parts")/
part[parent-part = 1]'
The query executed in just over 1/5th of a second without an index. Since this query searches for a specific node's number, a "node-element-equality-decimal" index should help speed things up.

dbxml> addIndex "" parent-part node-element-equality-decimal
Adding index type: node-element-equality-decimal to node: {}:parent-part
dbxml> query 'collection("parts")/part[parent-part = 1]'
Query - Finished eager query execution,
time taken = 79.973ms
100 objects returned for eager expression 'collection("parts")/
part[parent-part = 1]'
Wonderful, query execution time has been reduced by more than half, to under 1/10th of a second by adding that second index. Let's try one final example - the range query we tried earlier.

dbxml> query 'collection("parts")/part[@number >
100 and @number < 105]'
Query - Finished eager query execution,
time taken = 5917.83ms
4 objects returned for eager expression 'collection("parts")/
part[@number > 100 and @number < 105]'
Six seconds is an eternity in database terms, so let's create another and try again.

dbxml> addIndex "" number node-attribute-equality-decimal
Adding index type: node-attribute-equality-decimal to node:
{}:number
dbxml> query 'collection("parts")/part[@number >
100 and @number < 105]'
Query - Finished eager query execution,
time taken = 85.99ms
4 objects returned for eager expression 'collection("parts")/
part[@number > 100 and @number < 105]'
The index reduced the query time back down to less than a 1/10th of a second.

Conclusion
Pick the right tool for the job. An XML-centric design will benefit from a native XML database. Managing XML content can be easy, predictable, flexible, secure, and fast. Save yourself the headaches, time, and expense of solutions that are less suited to the task.

More Stories By Gregory Burd

Gregory Burd is the Product Manager for Sleepycat Software, now a part of Oracle. Prior to Sleepycat, he was on the business team at KnowNow, a Kleiner Perkins startup in the San Francisco Bay Area. He has many years of software development and product leadership within companies such as JavaSoft, a division of Sun Microsystems, Marble Associates, a consulting company, and NeXT Computer, now part of Apple Computer.

More Stories By Kimbro Staken

Kimbro Staken is an independent consultant, author, and open source developer specializing in technologies for XML data management. He is one of the primary developers of the dbXML Core Open Source native XML database and a cofounder of the XML:DB Initiative.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


IoT & Smart Cities Stories
Moroccanoil®, the global leader in oil-infused beauty, is thrilled to announce the NEW Moroccanoil Color Depositing Masks, a collection of dual-benefit hair masks that deposit pure pigments while providing the treatment benefits of a deep conditioning mask. The collection consists of seven curated shades for commitment-free, beautifully-colored hair that looks and feels healthy.
The textured-hair category is inarguably the hottest in the haircare space today. This has been driven by the proliferation of founder brands started by curly and coily consumers and savvy consumers who increasingly want products specifically for their texture type. This trend is underscored by the latest insights from NaturallyCurly's 2018 TextureTrends report, released today. According to the 2018 TextureTrends Report, more than 80 percent of women with curly and coily hair say they purcha...
The textured-hair category is inarguably the hottest in the haircare space today. This has been driven by the proliferation of founder brands started by curly and coily consumers and savvy consumers who increasingly want products specifically for their texture type. This trend is underscored by the latest insights from NaturallyCurly's 2018 TextureTrends report, released today. According to the 2018 TextureTrends Report, more than 80 percent of women with curly and coily hair say they purcha...
We all love the many benefits of natural plant oils, used as a deap treatment before shampooing, at home or at the beach, but is there an all-in-one solution for everyday intensive nutrition and modern styling?I am passionate about the benefits of natural extracts with tried-and-tested results, which I have used to develop my own brand (lemon for its acid ph, wheat germ for its fortifying action…). I wanted a product which combined caring and styling effects, and which could be used after shampo...
The platform combines the strengths of Singtel's extensive, intelligent network capabilities with Microsoft's cloud expertise to create a unique solution that sets new standards for IoT applications," said Mr Diomedes Kastanis, Head of IoT at Singtel. "Our solution provides speed, transparency and flexibility, paving the way for a more pervasive use of IoT to accelerate enterprises' digitalisation efforts. AI-powered intelligent connectivity over Microsoft Azure will be the fastest connected pat...
There are many examples of disruption in consumer space – Uber disrupting the cab industry, Airbnb disrupting the hospitality industry and so on; but have you wondered who is disrupting support and operations? AISERA helps make businesses and customers successful by offering consumer-like user experience for support and operations. We have built the world’s first AI-driven IT / HR / Cloud / Customer Support and Operations solution.
Codete accelerates their clients growth through technological expertise and experience. Codite team works with organizations to meet the challenges that digitalization presents. Their clients include digital start-ups as well as established enterprises in the IT industry. To stay competitive in a highly innovative IT industry, strong R&D departments and bold spin-off initiatives is a must. Codete Data Science and Software Architects teams help corporate clients to stay up to date with the mod...
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
Druva is the global leader in Cloud Data Protection and Management, delivering the industry's first data management-as-a-service solution that aggregates data from endpoints, servers and cloud applications and leverages the public cloud to offer a single pane of glass to enable data protection, governance and intelligence-dramatically increasing the availability and visibility of business critical information, while reducing the risk, cost and complexity of managing and protecting it. Druva's...
BMC has unmatched experience in IT management, supporting 92 of the Forbes Global 100, and earning recognition as an ITSM Gartner Magic Quadrant Leader for five years running. Our solutions offer speed, agility, and efficiency to tackle business challenges in the areas of service management, automation, operations, and the mainframe.