To close the thread the issue is related to a bug OAK-1035 and is fixed by Thomas. With bug fixed the query uses the right index Chetan Mehrotra
On Mon, Sep 23, 2013 at 12:50 PM, Chetan Mehrotra <chetan.mehro...@gmail.com> wrote: > Hi, > > While trying to execute a query like > > select [jcr:path], [jcr:score], * from [nt:unstructured] as a where > [sling:resourceType] = 'dam/smartcollection' and isdescendantnode(a, > '/content/dam') > > where index does exist for sling:resourceType the explain shows that > its using the NodeType index for jcr:primaryType > > [nt:unstructured] as [a] /* Filter(query=explain select [jcr:path], > [jcr:score], * > from [nt:unstructured] as a > where [sling:resourceType] = 'dam/smartcollection' > and isdescendantnode(a, '/content/dam') > , path=/content/dam//*, > property=[sling:resourceType=dam/smartcollection]) where > ([a].[sling:resourceType] = cast('dam/smartcollection' as string)) and > (isdescendantnode([a], [/content/dam])) */ > > The problem I think is the way cost is determined in [1]. Current > implementation returns cost as zero if count returned by the > IndexStoreStrategy is zero. This forces the query engine to use this > index. I think it should return a value less than > Double.POSITIVE_INFINITY but greater than zero probably MAX_COST to > indicate that it can participate but there is some cost > > - return store.count(indexMeta, encode(value), MAX_COST); > + long count = store.count(indexMeta, encode(value), MAX_COST); > + return (count == 0) ? MAX_COST : count; > > With the logic changed above the plan changes to > > [nt:unstructured] as [a] /* property > sling:resourceType=dam/smartcollection where ([a].[sling:resourceType] > = cast('dam/smartcollection' as string)) and (isdescendantnode([a], > [/content/dam])) */ > > Any pointers? > > Chetan Mehrotra > [1] > https://github.com/apache/jackrabbit-oak/blob/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexLookup.java#L110