xiangfu0 commented on code in PR #18759: URL: https://github.com/apache/pinot/pull/18759#discussion_r3415880476
########## pinot-perf/src/main/java/org/apache/pinot/perf/FstTraversalLimitExperiment.java: ########## @@ -0,0 +1,196 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.perf; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.SortedMap; +import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.apache.commons.io.FileUtils; +import org.apache.lucene.store.OutputStreamDataOutput; +import org.apache.lucene.util.fst.FST; +import org.apache.pinot.segment.local.segment.index.readers.LuceneFSTIndexReader; +import org.apache.pinot.segment.local.utils.fst.FSTBuilder; +import org.apache.pinot.segment.spi.index.reader.FSTTraversalLimitExceededException; +import org.apache.pinot.segment.spi.memory.PinotDataBuffer; +import org.roaringbitmap.buffer.ImmutableRoaringBitmap; +import org.roaringbitmap.buffer.MutableRoaringBitmap; + + +/** + * Exploratory experiment (not a JMH benchmark) to choose a default for {@code fstRegexpTraversalLimit}. + * + * <p>For a range of column cardinalities it reports, per regexp pattern: the number of matches, the exact number of + * FST paths visited (the unit the cap is expressed in), the FST {@code getDictIds} latency, and the equivalent + * dictionary-scan latency. The path counts tell us where to set the cap so that selective queries never trip it while + * broad queries fall back to scan; the latencies tell us whether tripping at that point is actually a win.</p> + * + * <p>Run: {@code java -cp 'pinot-perf/target/pinot-perf-pkg/lib/*' + * org.apache.pinot.perf.FstTraversalLimitExperiment}</p> + */ +public final class FstTraversalLimitExperiment { Review Comment: Removed `FstTraversalLimitExperiment` from the PR. ########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/fst/RegexpMatcher.java: ########## @@ -93,6 +112,10 @@ public void regexMatchOnFST(IntConsumer dictIdConsumer) Transition t = new Transition(); int numPathsProcessed = 0; while (!stack.isEmpty()) { + if (numPathsProcessed >= pathLimit) { + throw new FSTTraversalLimitExceededException( Review Comment: Reworked to not throw: the matcher now returns a boolean (`false` = stopped at the limit), `TextIndexReader.getDictIds(query, maxPaths)` returns `null` in that case, and `PredicateEvaluatorProvider` falls back to the dictionary-scan evaluator on `null`. Deleted `FSTTraversalLimitExceededException` entirely. The end-to-end test confirms a tripped cap returns results identical to the FST path. -- 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]
