Igor's Blog

I've been doing SQL optimisation for some of the services at work recently and saw that we've been using EXTRACTVALUE in a number of places. This is not bad in itself, however the Oracle 12c documentation states that EXTRACTVALUE is deprecated and should be replaced with XMLTABLE.
The EXTRACTVALUE function is deprecated. It is still supported for backward compatibility. However, Oracle recommends that you use the XMLTABLE function, or the XMLCAST and XMLQUERY functions instead. See XMLTABLE, XMLCAST, and XMLQUERY for more information.

Now I knew that the particular query I was looking at wasn't performing terribly great so I decided to try out XMLTABLE in it and got some amazing results. In my case the SQL execution time was 4.5 times faster when I switched to XMLTABLE!

When I did some further investigation I found that the performance of EXTRACTVALUE depends on the number of values you get from your XMLType. This seems to scale linearly, so having two values extracted roughly doubles the time for the SQL to complete, and so on. I experimented with extracting 1 value, then 2, all the way up to 5 values with the following results...

The XMLTABLE approach always had constant performance, no matter whether it was extracting 1 or 5 XPATHs. With EXTRACTVALUE the performance varied as described earlier - the more XPATHs the slower it was.

The format of my EXTRACTVALUE based SQL was like this...
extractvalue(XMLType(t.document), '/Document/Some/Xpath[@expression]',
'http://igorkromin.net/') column1,
extractvalue(XMLType(t.document), '/Document/Some/Xpath[@expression]',
'http://igorkromin.net/') column2,
extractvalue(XMLType(t.document), '/Document/Some/Xpath[@expression]',
'http://igorkromin.net/') column3,
extractvalue(XMLType(t.document), '/Document/Some/Xpath[@expression]',
'http://igorkromin.net/') column4,
extractvalue(XMLType(t.document), '/Document/Some/Xpath[@expression]',
'http://igorkromin.net/') column5
my_table t
where my_id = '123'
order by 1

When converted to use XMLTABLE, the SQL had this format...
select x.*
my_table t,
xmlnamespaces(default 'http://igorkromin.net/'), '/Document'
PASSING XMLType(t.document)
COLUMNS column1 varchar2(100) PATH '/Some/Xpath[@expression]',
column2 varchar2(100) PATH '/Some/Xpath[@expression]',
column3 varchar2(100) PATH '/Some/Xpath[@expression]',
column4 varchar2(100) PATH '/Some/Xpath[@expression]',
column5 varchar2(100) PATH '/Some/Xpath[@expression]'
) x
where my_id = '123'
order by 1

Both of the SQLs return the same results, however the XMLTABLE based query runs significantly faster.

The tests were done when selecting a 1000 XML document result set from the database. The ORDER BY clause is present to force the whole result set to be processed to give accurate timing information.

So there you go, if you are still using EXTRACTVALUE and are pulling out more than 1 XPATH from your XML then it is worth switching to the new XMLTABLE approach!


comments powered by Disqus
Other posts you may like...
Programming, DIY, Games, Hacks, and Tech

Recent Blog Posts

Converting a CSV file containing commas in quotes to a pipe separated file using Awk and Bash

How to get Facybox gallery popup to work for images with dynamic URLs

jQuery UI Photoboxr plugin updated to version 0.2

Learn How to Add Disclaimer to All Outgoing Emails in Office 365

How to securely host your web site for free with Google Cloud and CloudFlare (part 3)

How to securely host your web site for free with Google Cloud and CloudFlare (part 2)

How to securely host your web site for free with Google Cloud and CloudFlare (part 1)

Beware of the subtle difference in date format strings between MySQL and SQLite

Postman reporting Unexpected 'N' error in response body

Adding extra shelves to the Ikea Detolf display cabinet

Recent Galleries

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

DIY spare parts computer build with a RAIDMAX Anura case

Fake 'Lepin' brand Lego packaging

Hardwood garden bench with clear resin void filler

Fixing a 3D printer extruder that stopped heating up

Easily increase disk space in a Lenovo Ideapad 100S 14" laptop with an M.2 SSD

Making a multi-piece 3D printed solder spool holder stand

DIY indoor apartment grow light wiring

Good Friday Electronics fun Easter Bunny LED PCB Kit IBEABU-01.0

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
300 George St Blogumentary

My Online Tools

UUID to OID Converter
Guru JSON-RPC Tester
Extrudifier Object Designer
Travel ┬ÁBlog

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Please follow me for more great content!
Don't show this again