Question

i am trying to query a subtree for a given node type by a this query:

SELECT * FROM [my:Type] AS my WHERE PATH(my) LIKE '/content/subtree/%'

somehow it does not give any results - using ISDESCENDANTNODE works - but query performance is terrible as soon as i have >5k elements total - no matter if inside or outside my subtree.

Was it helpful?

Solution

I don't think that PATH(my) is valid JCR SQL or JCR 2.0 SQL-2 grammar. You should use SQL-2:

select * from [my:Type] where isdescendantnode('/content/subtree')

or XPath

/jcr:root/content//element(*, my:Type)

This may be slow because it will only use the index on the node type (the path is not indexed). If you need it to be faster, you could (for example) store the path as a property and then add the corresponding condition; however this will prevent fast move operations.

OTHER TIPS

If you use SQL2, just correct your query like that

SELECT * FROM [my:type] WHERE PATH([my:type]) LIKE '/content/subtree/%'

For SQL, you should use :

SELECT * FROM my:Type WHERE jcr:path like '/content/subtree/%'

this query will search all node in all level under "/content/subtree/" but if you only need to search on one level under "subtree", you should to add another option to your query in order to increase the performance :

SELECT * FROM my:Type WHERE jcr:path like '/content/subtree/%' and not jcr:path like 'content/subtree/%/%'

You can found more detail here : http://docs.jboss.org/exojcr/1.12.13-GA/developer/en-US/html/ch-jcr-query-usecases.html#JCR.ChildNodeConstraint

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top