basex icon indicating copy to clipboard operation
basex copied to clipboard

XQuery: Optimizations on namespaced databases

Open ChristianGruen opened this issue 6 years ago • 1 comments

In the database storage of BaseX, element and attribute names are indexed by their prefix:local representation, and the namespace is retrieved at runtime. This is why some compile-time query optimizations are skipped if a database has namespaces.

There are cases, though, in which a more fine-grained namespace detection would be possible and desirable. For example, if a document only has non-default namespace declarations…

<a xmlns:pre='URI'><b>B</b></a>

…and if an element/attribute name in an XPath step has no namespace (e.g. //b), it can safely be associated with elements of the accessed database. Steps with non-existing elements can then be replaced with empty sequences, or a text() step can be attached to a path expression that may later be rewritten for index access.

Code: https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/query/util/index/IndexInfo.java#L83

Script:

create db simple <a xmlns:x='X'><b>B</b></a>
xquery /a[b = 'B']
close

ChristianGruen avatar Nov 29 '19 04:11 ChristianGruen

Related: If namespace detection is improved, . can be rewritten to text().

<commands>
  <create-db name='db'>
    <a xmlns='ns'>A</a>
  </create-db>
  <xquery>*:a[. = 'A']</xquery>
</commands>

ChristianGruen avatar May 08 '20 12:05 ChristianGruen