Hi all,

I was recently debugging performance of a query with an exact string
comparison and discovered that it seems the query was only rewritten to use
the text index [1] if I explicitly added `/text()` to the path I was
comparing.

My data looks like this:

<data>
  <element><id>123</id></element>
</data>

And my original query was:

for $el in db:open('DatabaseName')/data/element
where $el/id = '123'
return $el

With 3 million <element> nodes in the database, this query took about 4
seconds, which made me question whether the text index was being used. I
then changed the query to add `/text()` to the `where` clause, like so:

for $el in db:open('DatabaseName')/data/element
where $el/id/text() = '123'
return $el

With this change, the query only takes 0.4 seconds. Is it expected that
`/text()` is required to get the text index to kick in?

Thanks in advance,
Matt

[1] https://docs.basex.org/wiki/Indexes#Text_Index

Reply via email to