gortiz opened a new issue, #20465:
URL: https://github.com/apache/pinot/issues/20465

   ## Summary
   
   A filter predicate on an expression over one dictionary-encoded column, such 
as `BITAND(flags, 33) = 0` or `SUBSTR(code, 0, 3) = 'C50'`, runs the transform 
once per candidate row today, in `ExpressionFilterOperator`. Many such columns 
have few distinct values per segment, so running the expression once per 
dictionary value is much cheaper. This issue tracks that work. It has five 
parts, each in its own PR.
   
   ## 1. Evaluate the expression once per dictionary value
   
   PR: [apache/pinot#20464](https://github.com/apache/pinot/pull/20464)
   
   `FilterPlanNode` runs the transform over the dictionary of the column and 
keeps the dictionary ids that match the predicate. It then filters the column 
with those ids like a predicate on the column itself, so the filter can use the 
sorted index, the inverted index or a scan of dictionary ids. When the 
predicate is true or false for every dictionary value, the filter reads no 
rows. The path applies only to single-value columns, deterministic and 
null-intolerant functions, dictionaries up to a threshold (10,000 values by 
default) and immutable segments. The query option `expressionDictFilterMode` 
and the threshold turn it off.
   
   On the benchmark in the PR, the gain goes up to 500 times for a predicate 
that is true for every value, and the cost of the fallback above the threshold 
is not visible.
   
   ## 2. Make the scan skip null rows by itself
   
   Under null handling, `BaseColumnFilterOperator.excludeNulls` wraps the 
result of a `ScanBasedFilterOperator` in an inner `AndDocIdSet(scan, non-null 
rows)`. When the AND restriction push-down is off (the default), a parent AND 
cannot restrict that inner AND to its own candidate rows, so the scan reads the 
whole segment. In the benchmark of #20464 this scan takes 18 to 45 ms per 
query, where the per-row path takes 2 to 21 ms.
   
   This also affects plain predicates on nullable columns without an index, 
today. The fix: `ScanBasedFilterOperator` gives the null bitmap to 
`SVScanDocIdSet` and `MVScanDocIdSet`, and their iterators skip null rows in 
`next`, `advance`, `applyAnd` and `matchDocIds`. After this change, #20464 can 
remove its fallback to the per-row path for a nullable column without an index.
   
   ## 3. Restrict the inverted-index child of an AND to the candidate rows
   
   `AndDocIdSet` materializes every index-based child over the whole segment 
before it intersects them. For a predicate that matches many dictionary values, 
the inverted-index child is an OR of many bitmaps, and its cost does not depend 
on how many rows the other children keep. The AND restriction push-down only 
restricts the scan-based children.
   
   With a very selective sibling, a scan of dictionary ids restricted to the 
candidate rows is faster: 2.6 ms against 4.0 ms with 20,000 candidate rows on 
2.5M-row segments. With 200,000 candidate rows the inverted index is faster 
(6.4 ms against 10.5 ms). The plan does not know the number of candidate rows, 
so `AndDocIdSet` must decide at execution time: intersect each bitmap with the 
candidates, or switch to the dictionary-id scan when the candidates are few.
   
   ## 4. Build the result bitmap of `ExpressionScanDocIdIterator` in order
   
   `ExpressionScanDocIdIterator.processProjectionBlock` calls 
`MutableRoaringBitmap.add` once per matching row. The document ids arrive in 
ascending order, so the iterator can collect them in an `int[]` per block and 
call `addN`, or use a `RoaringBitmapWriter`. This helps every expression filter 
that keeps the per-row path.
   
   ## 5. Multi-value columns
   
   #20464 accepts only single-value columns. For a multi-value column, the 
function must apply element by element, and only the inclusive form of the 
predicate is correct ("any value matches"). The exclusive form (`NOT_IN`) 
cannot be derived from the matching ids. `DictIdSetPredicateEvaluator` already 
supports the multi-value form.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to