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

Attribute range index produces incorrect results when used with ft:query. #3114

Open
paulmer opened this issue Nov 15, 2019 · 5 comments
Open
Labels
bug issue confirmed as bug investigate issues being looked at Lucene issue is related to Lucene or its integration needs XQSuite test XQSuite test required to reproduce

Comments

@paulmer
Copy link
Contributor

paulmer commented Nov 15, 2019

What is the problem

An XPath expression of the form

//record[ft:query(.//field[@attr="value"], <phrase>text</phrase>)

ignores the [@attr="value"] predicate if a range index is defined on @attr. The result of the expression is equivalent to:

//record[ft:query(.//field, <phrase>text</phrase>)

If the range index is removed, the xpath works as expected.

What did you expect

See above.

Describe how to reproduce or add a test

Describe how we can can reproduce the problem.

The attached test demonstrates the difference in behavior when a range index is and is not present.

rft-test.zip

Context information

Exist 5.1.0 snapshot built from source. Confirmed on both Linux and Mac platforms, Java 1.8

@triage-new-issues triage-new-issues bot added the triage issue needs to be investigated label Nov 15, 2019
@joewiz
Copy link
Member

joewiz commented Jan 17, 2020

@paulmer As a workaround, could you try this?

//field[@attr="value"][ft:query(., <phrase>text</phrase>)]/ancestor::record

@paulmer
Copy link
Contributor Author

paulmer commented Jan 17, 2020

@joewiz That actually works, as does pretty much any variation I've found that doesn't include the '@attr' expression within the ft:query call, but alas, my real use cases are much more complex with the entire XPath expression being assembled from a number of pieces of configuration that can vary. I suppose I'm being stubborn, but I'd rather tackle the bug than try to code around it. I was kind of hoping someone would think "Aha! I know what's causing that.", but no such luck.

@joewiz
Copy link
Member

joewiz commented Jan 17, 2020

@paulmer My guess is that the predicate is being blown away in the query optimization surrounding ft:query - somewhere here: https://github.com/eXist-db/exist/blob/develop/extensions/indexes/lucene/src/main/java/org/exist/xquery/modules/lucene/Query.java#L160-L177.

@duncdrum duncdrum added the investigate issues being looked at label Jan 17, 2020
@triage-new-issues triage-new-issues bot removed the triage issue needs to be investigated label Jan 17, 2020
@dizzzz
Copy link
Member

dizzzz commented Jan 17, 2020

you could try switching off the optimisation AFAIK;

declare option exist:optimize "enable=yes|no";

(source: org.exist.xquery.Optimizer)

@paulmer
Copy link
Contributor Author

paulmer commented Jan 20, 2020

@dizzzz @joewiz Thank you both for the suggestions. Optimization is fairly important to my queries given the size of my database. I dug into this issue far enough to understand that there isn't going to be an easy fix in the Java code, at least, not for me without a great deal of research into the code. My impression with only a couple of hours of studying the code is that the result of the ft:query lookup is being used to filter not the set of fields passed to it, but the set of records in the outer expression. I thought some more about Joe's suggestion and found that for all the current use cases I have, it is possible to mechanically generate a different expression of the form //record[.//field[@name='name'][ft:query(., )]] that doesn't confuse the optimizer, so I'm going that route for now. One little oddity I found that someone looking at this problem might want to know is that when I added a logging statement to the beginning of org.exist.xquery.modules.lucene.Query.preSelect() that evaluated contextSequence.getItemCount(), the problem went away. I didn't track down what side-effect was causing that behavior, though.

@line-o line-o added bug issue confirmed as bug needs XQSuite test XQSuite test required to reproduce Lucene issue is related to Lucene or its integration labels Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issue confirmed as bug investigate issues being looked at Lucene issue is related to Lucene or its integration needs XQSuite test XQSuite test required to reproduce
Projects
None yet
Development

No branches or pull requests

5 participants