When we ran the explain plan for the following query, we found out that the operator Filter_Full_Scan is executed before FILTER_INVERTED_INDEX, which causes the failure on applying docIdSet (the output of OR) on ScanBasedDocIdIterator ahead of time and thus the query is slowed down.
SQL
explain plan for
SELECT id,metadatas FROM rta_m3poc9proportioned WHERE env = 'production' AND (tags_prefixes = 'foo' OR tags_entries = 'bar') AND REGEXP_LIKE(tags_entries, 'bar(a.*\|b[^\.]*)') LIMIT 5000
It turns out that the existing reorderAndFilterChildOperators brutally assign a static priority value to the AND, OR operator. We should have recursively visit the child operators and use the lowest priority (largest value) of children as the priority of the current operator. In order to avoid walking through the tree twice, the reorder and priority evaluation should get done in the same recursive function. Reorder AND's children only. The PR is on the way.
When we ran the explain plan for the following query, we found out that the operator Filter_Full_Scan is executed before FILTER_INVERTED_INDEX, which causes the failure on applying docIdSet (the output of OR) on ScanBasedDocIdIterator ahead of time and thus the query is slowed down.
SQL
It turns out that the existing reorderAndFilterChildOperators brutally assign a static priority value to the AND, OR operator. We should have recursively visit the child operators and use the lowest priority (largest value) of children as the priority of the current operator. In order to avoid walking through the tree twice, the reorder and priority evaluation should get done in the same recursive function. Reorder AND's children only. The PR is on the way.