perf(fsst): push down '%suffix' LIKE without decompression - #9728
Open
jackylee-ch wants to merge 1 commit into
Open
perf(fsst): push down '%suffix' LIKE without decompression#9728jackylee-ch wants to merge 1 commit into
jackylee-ch wants to merge 1 commit into
Conversation
Contributor
|
Do you have any benchmarks using real world or synthetic data? |
LikeKind::parse handled prefix% and %needle% but not %suffix, so those patterns fell through FsstMatcher::try_new and the kernel decompressed the whole column. vortex-duckdb already lowers suffix(col, 'x') to LIKE '%x', so on one column prefix() and contains() match on the code stream while suffix() does not. Adds SuffixMatcher, taking the backward-scan route the module TODO sketched. A forward DFA cannot exit early, because a suffix match is only decided at the last code, and it measured slower than decompressing. Walking backward makes the row's last byte the first one compared, so a non-matching row is usually rejected on one symbol. The reverse parsing that needs is local: escape ambiguity propagates only through a run of consecutive ESCAPE_CODE bytes, and that run's parity decides whether the byte left of a token boundary is an escaped literal or a symbol code. Every per-code table is sized to the whole code space rather than to the symbol count, so a code byte past the symbol table -- which only a corrupt file produces -- reads padding and answers "no match" instead of indexing out of bounds. The prefix and contains DFAs already absorb that byte in the padding of their 256-wide tables. Also adds fsst_suffix and fsst_suffix_canonicalize bench arms, so the comparison against decompress-and-compare runs from a clean checkout. Six of the seven datasets are 1.4-4.9x faster even taking each arm's worst sample; the email dataset is a wash (0.97x), and is the noisiest case in the set. Signed-off-by: jackylee <qcsd2011@gmail.com>
jackylee-ch
force-pushed
the
fsst-suffix-pushdown
branch
from
September 4, 2026 08:23
0185d8b to
d7dd77a
Compare
Contributor
Author
|
Yes — Two things the rewrite also fixed: a code byte past the symbol table used to index out of bounds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LikeKind::parsehandledprefix%and%needle%but not%suffix, so the kernel decompressed thewhole column for those — even though
vortex-duckdblowerssuffix(col, 'x')to LIKE%x.Takes the TODO's backward-scan route: a forward DFA cannot exit early, since a suffix match is only
decided at the last code. The reverse parsing that needs is local; the module doc has the argument.
Benchmarks
fsst_suffixagainstfsst_suffix_canonicalize, both in one bench binary so this reproduces from aclean checkout. divan median of 100 samples, 8 repeats; match rates 0–100%.
worstis thecanonicalize arm's fastest sample over the pushdown arm's slowest.
emailis a wash, and the noisiest case (6.42–8.75 µs across repeats). Its 9-byte suffix exceedsFSST's 8-byte symbol cap, so the last symbol never settles the match and every row walks 2–3 tokens,
with only 21.9 B/row to amortise it. Deciding on one symbol would be 4.3x, so this is headroom rather
than a floor — say if you would rather gate on row length than carry it.
Tests
91 → 109.
run_likenow asserts the kernel returnedSomebefore comparing booleans, since thefallback returns the same answers: unhooking
parse_suffixfails 13 tests. Three more mutations eachfail one new test.
AI assistance
Agentic AI assistance; I derived the parity argument by hand and checked the mutations fail.