[ 
https://issues.apache.org/jira/browse/OAK-12327?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18106307#comment-18106307
 ] 

Julian Sedding commented on OAK-12327:
--------------------------------------

[~reschke] alerted me to the following risk. Fixing this properly would require 
more changes, for which I currently don't have the time. I'll therefore abandon 
work on this issue.

I think that {{PropertyExistenceImpl.getPropertyExistenceConditions()}} would 
need to return two instances if the propertyType is restricted: the one 
restricted by {{propertyType}} and one with {{{}propertyType=UNDEFINED{}}}. 
Otherwise a valid existence condition could be dropped due to an {{equals()}} 
mismatch.

*What Changed:*
{{PropertyExistenceImpl.hashCode()}} and {{equals() }}now delegate to 
{{{}PropertyValueImpl.hashCode()/equals(){}}}, which includes {{propertyType}} 
and {{selector}} in the comparison. Previously, equality was based only on 
{{selectorName}} and {{{}normalizePropertyName(propertyName){}}}.

*Why It Is Risky:*
{{OrImpl.getPropertyExistenceConditions()}} uses {{Set.retainAll()}} to find 
common property existence conditions across OR branches. If one branch uses 
{{property([test], 'String') = 'x' }}and another uses {{{}[test] = 'y'{}}}, the 
derived PropertyExistenceImpl objects will have different propertyType values 
(STRING vs UNDEFINED) and will NOT be considered equal. Previously, both would 
have produced equal {{PropertyExistenceImpl}} objects (same selector, same 
property name), allowing the optimizer to derive a {{[test] IS NOT NULL}} 
restriction for index selection.

> PropertyValueImpl with type restriction lost when "is not null"
> ---------------------------------------------------------------
>
>                 Key: OAK-12327
>                 URL: https://issues.apache.org/jira/browse/OAK-12327
>             Project: Jackrabbit Oak
>          Issue Type: Bug
>          Components: query
>    Affects Versions: 2.4.0
>            Reporter: Julian Sedding
>            Priority: Major
>
> When using a query on a multi-value property for pagination, it is desirable 
> to use the {{first([prop])}} function to order the results.
> However, if the property is expected to by of type "String[]", but it cannot 
> be ruled out that a property of the same name exists, but with the wrong 
> type, then results become somewhat unexpected.
> In SLING-13248 it happened that a "String[]", but there was also a property 
> of type "Date". The query returned the "Date" property  starting with "2025-" 
> before a "String[]" property containing "/acs-commons". However, the 
> (expected) lexicographic sorting results in the "/" getting sorted before 
> "2025-".
> In an attempt to fix SLING-13248, the idea was to use a query similar to the 
> one below. I.e. make sure the property is both of type "String" and present 
> (not null).
> {noformat}
> select [jcr:path] from [nt:base] where property([test], 'String') is not null 
> order by first([test])
> {noformat}
> Unexpectedly, this query returns the property of type "Date", just as if the 
> query was using the constraint "where [test] is not null".
> I traced this back to where the [SQL2Parser creates 
> {{PropertyExistenceImpl}}|https://github.com/apache/jackrabbit-oak/blob/b9b83ed38968c4d9ae04c8d8f62d2986aeedea17/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java#L546]
>  and does not pass on the "type" information.
> cc [~joerghoh], [~thomasm]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to