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!
xmltablevsextractval2.png




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...
xmltablevsextractval1.png


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...
 SQL
select
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
from
my_table t
where my_id = '123'
order by 1



When converted to use XMLTABLE, the SQL had this format...
 SQL
select x.*
from
my_table t,
XMLTABLE(
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!

-i

, , ,
About — I'm an enthusiastic software engineer and consultant interested in many fields including J2EE, programming, electronics, 3D printing, video games, wood working and gardening.
See my Resume for more information.
The views expressed in this blog are my own and not those of my employer.
comments powered by Disqus
My other posts you may like...
Programming, DIY, Games, Hacks, Tech and more.
Follow me on...
Current and Past Projects
See my Resume

Subscribe


RSS Feed

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
StrFunc() Online
300 George St Blogumentary
Guru JSON-RPC Tester
Extrudifier Object Designer

Recent Blog Posts

Binding extra variables with PHP PDO returns no results

New Nintendo 3DS XL, R4i SDHC RTS Lite and DSDoom

Older versions of JD-GUI crashing on macOS Sierra

How does Seeed Fusion stack up as a low budget PCB fab

Where to find the last item (Robbie's lost lyrics) in GravityFalls Lake level

Detecting print requests to print contents of a DIV with JavaScript

Using Google DFP with AdSense on responsive pages

How to change the email subject line in Gmail

Force PHP GD library to load JPEG images that have invalid data

How to uninstall Samsung Smart Switch from your Mac

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

Top Categories

Blogs I follow

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth

Friends

RAWS Parts Online
Alpha Dimensions Hosting
Kristensen Photography
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Follow me on... 
     
...or subscribe for updates!

Don't show this again