Database Reference
In-Depth Information
To show the differences between indexed and nonindexed searches
more clearly (on modern, fast hardware), all searches are repeated
multiple times. If your system is slower or faster than our test sys‐
tem, then it could be that the search is too slow or too fast for you.
You can change the number of iterations performed at the top of
the script.
Here is the code fragment that performs the test of the range index:
{
let
$
starttime
as
xs:time
:=
util:system-time
()
let
$
result
:=
for
$
i
in
1
to
$
repeats-range
return
for
$
n
in
doc
(
$
doc-with-indexes
)//
tei:name
[.
eq
$
phrase-range
]
return
$
n
let
$
endtime
as
xs:time
:=
util:system-time
()
return
<Result
type
=
"
indexed
"
time
=
"{
seconds-from-duration
(
$
endtime
-
$
starttime
)}
s
"
/>
}
{
let
$
starttime
as
xs:time
:=
util:system-time
()
let
$
result
:=
for
$
i
in
1
to
$
repeats-range
return
for
$
n
in
doc
(
$
doc-without-indexes
)//
name
[.
eq
$
phrase-range
]
return
$
n
let
$
endtime
as
xs:time
:=
util:system-time
()
return
<Result
type
=
"
non-indexed
"
time
=
"{
seconds-from-duration
(
$
endtime
-
$
starttime
)}
s
"
/>
}
Notice that we use
util:system-time
, not
fn:current-time
, to
get the start and end time of a piece of code. The XQuery specifica‐
tion states that the value of
current-time
is deterministic through‐
out the execution of an XQuery. This means that it will not change
during execution. As we want to measure the difference between
two times to determine how long the query took, we instead use
util:system-time
, which is nondeterministic and will always
return the point in time. It is worth noting that all of the date/time
functions within the
XPath and XQuery Functions and Operators
specification
are deterministic.
If you look at the output from one of our systems for this fragment, the differences
between the indexed and nonindexed versions are rather dramatic:
<Result
type=
"indexed"
time=
"0.011s"
/>
<Result
type=
"non-indexed"
time=
"0.782s"
/>
Performance with an index is a factor of 71 times faster, and the difference will likely
only increase as more data is added to the system!
Search WWH ::
Custom Search