BaseXdb / basex

BaseX Main Repository.
http://basex.org
BSD 3-Clause "New" or "Revised" License
661 stars 267 forks source link

XQuery: Incorrect result count with multiple sequence operators #2225

Closed Twilight-Shuxin closed 1 year ago

Twilight-Shuxin commented 1 year ago

Description of the Problem

Given this XML document:

<I><A/><B/></I>

and XPath Query

//B/reverse(tail(reverse(subsequence(//*/has-children(), 3))))

BaseX returns one element false.

Expected Behavior

Should return empty result set. For node B, //*/has-children() selects the result of I, A, B three nodes. Applying subsequence(s, 3) selects only the last element, and after application of tail function no result should be selected. In terms of number of results returned, the two reverse() operations seems redundant in this case. If deleted BaseX returns the expected results.

Steps to Reproduce the Behavior

  1. Create database create database db <I><A/><B/></I>
  2. Execute XPath query xquery //B/reverse(tail(reverse(subsequence(//*/has-children(), 3))))

This is a reduced test case from:

  1. Create database create database db <I><A><B><C/></B></A><D/></I>
  2. Execute XPath query xquery //D/reverse(tail(reverse(subsequence(./preceding::*/has-children(), 3))))

Do you have an idea how to solve the issue?

No response

What is your configuration?

BaseX version: BaseX 10.7 beta latest commit 564bd39 on Windows

ChristianGruen commented 1 year ago

Thanks as always! reverse(tail(reverse(...))) is rewritten to a function that will be introduced with XQuery 4.0 – fn:trunk – and the optimization rules of that function contained a bug.

Twilight-Shuxin commented 1 year ago

Thanks also for the response speed always so impressive!