Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Range Indexes are ignored #2363

Open
adamretter opened this issue Jan 3, 2019 · 0 comments
Open

Range Indexes are ignored #2363

adamretter opened this issue Jan 3, 2019 · 0 comments
Assignees
Labels
bug issue confirmed as bug
Milestone

Comments

@adamretter
Copy link
Member

adamretter commented Jan 3, 2019

The following XQuery shows 3 different formulations of the same simple query expression. The two most obvious formulations fail to use the configured Range Index. The least obvious and most complex formulation correctly uses the Range Index.

Occurs on both eXist-db 4.5.0 and 5.0.0-RC5.
This was originally reported by KevinBrown on StackOverflow: https://stackoverflow.com/questions/53858401/issue-in-index-upgrading-exist-db-version-2-to-4-5

The query below can simply be stored in the database as /db/test-range-index.xq, and monitored from Monex Profiler whilst called from http://localhost:8080/exist/rest/db/test-range-index.xq. Commenting in and out the different formulations at the bottom of the query, clearly shows that Range Indexes are not always used, when they absolutely should be!

(: setup the stuff needed for the query further below... :)
declare variable $local:test-col-name := "test-range-index";
declare variable $local:test-col-config := document {
   <collection xmlns="http://exist-db.org/collection-config/1.0">
    <index>
        <fulltext default="none" attributes="false"/>
        <range>
        	  <create qname="foo" type="xs:string"/>
        	  <create qname="bar" type="xs:string"/>
        </range>
    </index>
</collection>
};
declare variable $local:test-doc-name := "test-range-index.xml";
declare variable $local:test-doc := document {
    <data>
    	<foo>hello</foo>
    	<foo>goodbye</foo>
    	<bar>say hello</bar>
    	<bar>say good day</bar>
    </data>
};
let $test-col-config-col := xmldb:create-collection("/db/system/config/db", $local:test-col-name)
let $_ := xmldb:store($test-col-config-col, "collection.xconf", $local:test-col-config)
let $test-col := xmldb:create-collection("/db", $local:test-col-name)
let $_ := xmldb:store($test-col, $local:test-doc-name, $local:test-doc)
let $collection := collection($test-col)
return


        (: THE actual interesting query... :)
	let $string := "hello"
	return

		(: Formulation 1 - Correctly uses the new-range index for full-optimisation :)
		$collection//foo[fn:contains(., $string)] | $collection//bar[fn:contains(., $string)]

		(: Formulation 2 - FAILS to use the new range index :)
		(:
		($collection//foo | $collection//bar)[fn:contains(., $string)]
		:)

		(: Formulation 3 - FAILS to use the new range index :)
                (:
		$collection//(foo|bar)[fn:contains(., $string)]
                :)

I also obtained query traces from the Java Admin Client, that clearly show index optimisations are only applied to the first formulation. Also, significantly worrying is that formulation 1 and 2 appear to use the wrong axis too, i.e. descendant and not descendant-or-self.

Formulation 1 Query Trace

$collection
(# exist:optimize-field #)
(# exist:optimize #)
{
    descendant::{}foo[range:contains(self::node(), $string)]
}
 union $collection
(# exist:optimize-field #)
(# exist:optimize #)
{
    descendant::{}bar[range:contains(self::node(), $string)]
}

Formulation 2 Query Trace

$collection/descendant::{}foo union $collection/descendant::{}bar[contains(self::node(), $string)]

Formulation 3 Query Trace

$collection
descendant-or-self::{}foo union descendant-or-self::{}bar[contains(self::node(), $string)]
@adamretter adamretter added the bug issue confirmed as bug label Jan 3, 2019
@adamretter adamretter added this to the eXist-4.5.1 milestone Jan 3, 2019
@joewiz joewiz modified the milestones: eXist-4.5.1, eXist-4.6.2 Apr 6, 2019
@joewiz joewiz modified the milestones: eXist-4.6.2, eXist 4.7.1 May 24, 2019
@adamretter adamretter modified the milestones: eXist-4.7.1, eXist-4.7.2 Aug 14, 2019
@adamretter adamretter modified the milestones: eXist 4.8.1, eXist-4.10.1 Feb 14, 2022
@adamretter adamretter modified the milestones: eXist-4.10.1, eXist-4.11.1 Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issue confirmed as bug
Projects
None yet
Development

No branches or pull requests

3 participants