Indexing strategy for JCR-SQL2 statement with "OR" operator
Anyone has any experience creating AEM oak index for two properties that are combined in an OR statement? I have created oak indexes for both properties (lastReviewed is a custom property) but none of them are being used for this statement:
SELECT * FROM [cq:PageContent] AS s WHERE ISDESCENDANTNODE([/content]) AND ((s.[cq:lastReplicated] IS NOT NULL AND s.[cq:lastReplicated] <= CAST('2015-11-25T14:15:00.363+08:00' AS DATE)) OR (s.[lastReviewed] IS NOT NULL AND s.[lastReviewed] <= CAST('2015-11-25T14:15:00.363+08:00' AS DATE)))
After searching on the internet, seems like OR statements make a SQL statement not use index. From this page: http://stackoverflow.com/questions/13894064/mysql-or-operator-not-using-index
"An OR expression can't be used to look something up in an index"
Tried to split up the statement into two select statements combined with UNION instead which uses the index. My preliminary test seems to show that the UNION method is alot slower than the original version.
Here is what the new SQL statement look like:
SELECT * FROM [cq:PageContent] AS s WHERE ISDESCENDANTNODE([/content]) AND (s.[cq:lastReplicated] IS NOT NULL AND s.[cq:lastReplicated] <= CAST('2015-11-25T14:15:00.363+08:00' AS DATE))
UNION
SELECT * FROM [cq:PageContent] AS s WHERE ISDESCENDANTNODE([/content]) AND (s.[lastReviewed] IS NOT NULL AND s.[lastReviewed] <= CAST('2015-11-25T14:15:00.363+08:00' AS DATE))
Anyone knows of a better idea of solving this? Any help would be appreciated.