Repository navigation
Conversation
grep() treated a pattern with no regular expression metacharacters as a case-insensitive substring search, and a computed pattern as one even when it had metacharacters. Treat every pattern as a regular expression, so matching is case-sensitive unless the pattern starts with (?i). Plain and (?i) literal patterns skip the regexp engine and keep the BSUP search filter. Fixes #6200
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.
As discussed in #7718,
grep()now always treats its pattern as a regular expression, as #6115 described. A pattern with no metacharacters, like"BAR", used to be a case-insensitive substring search, as in a keyword search. It's now case-sensitive, like any other regular expression,regexp()andLIKE. To ignore case, start the pattern with(?i). A pattern computed from the input, as ingrep(p, this), used to be a case-insensitive substring search even when it had metacharacters, so apof"foo|baz"didn't match"baz". It's now a regular expression too, and an invalid one gives an error value. Keyword search (search fooor? foo) still ignores case, so thesearchdocs now give itsgrepequivalent asgrep("(?i)foo", this).Fixes #6200
Trying it out
On current tip of
main, commit 431a0c4:On this branch, commit 74c90c9:
Performance
A plain-string pattern, or one that is just
(?i)and a plain string, now skips the regexp engine, and both still let a BSUP scan skip frames that can't match, as a plain-stringgrep()did before. Other regular expressions andLIKEwork as before. Median wall times, MacBook M5 Pro, the gha dataset (4.4M records) as BSUP:maingrep('in case you have any feedback 😊', payload.pull_request.body)thisgrep('github', this)grep('(?i)github', this), vs.main's case-insensitivegrep('github', this)grep('feedback.*😊', this)(unchanged path)This also fixes three wrong results. A constant pattern like
"^foo$"was treated as a substring search forfoo, so it matched"xfooy". A plain-stringgrep()over a computed value that includesthis, e.g.,grep('zzz', [this, 'zzz']), gave no results on a BSUP file, because the scan skipped every frame that didn't containzzz; the frame filter now applies only whengrep()searches stored data. And an anchored case-insensitive pattern, e.g.,grep('(?i)^bar', s), could drop matching rows on a BSUP file, because its min/max filter compared case-sensitively.A computed pattern is now compiled as a regular expression whenever it differs from the previous row's. When every row has a different pattern, that costs about 0.45 µs per row (200,000 rows: 21 ms on
main, 109 ms here).Testing
grep.yamlcover constant and computed patterns, case sensitivity, anchors, a non-ASCII letter in a(?i)pattern and invalid computed patterns. The newbsup/ztests/grep-pushdown.yamlcovers frame skipping for plain and(?i)patterns, and none for a computed value. A new case inpruner-regexp.yamlcovers the(?i)^min/max filter. All of them fail onmain. ALIKEcase without wildcards inlike.yamland the newgrep-nfc.yaml(a decomposed pattern read from CSV) guard behaviormainalready has. Inswitch.yaml, the DAG output now showsregexp_search(...)forgrep().make test-unit,make test-systemand the book's mdtests pass.