Repository navigation
fix(storage): match purge topics literally in LIKE (escape % and _) - #298
loveRhythm1990 merged 2 commits into
Conversation
Signed-off-by: MatrixAdventurer <85048713+MatrixAdventurer@users.noreply.github.com>
ReviewI pulled the branch into a worktree, ran the tests, and probed LIKE/ESCAPE semantics directly against two MatrixOne instances (4.1.2 and 4.2.5). 1. Is the reported problem real? — Yes, both halves reproduce
2. Is the code correct? — Right direction, verified on MO ≥ 4.2.0, but three things to addressP1 (main): On MO 4.1.2,
The case quoted in the PR body returns 0 even when ESCAPE is ignored (the content holds no literal Consequence: on 4.1.x, purging a topic containing P2: the The new comment promises the pattern "matches The pattern is a bind parameter, so there is no injection risk and P3: the test misses the dangerous path. Only the Nits
What I ran
VerdictGood to merge, but I'd fix P1 (either switch to backslash escaping or document the ≥ 4.2.0 requirement) and drop the stale doc line first. P2 and P3 would fit naturally in this PR too, since they are exactly the "literal match" promise it sets out to deliver. |
Address review on matrixorigin#298: - Escape \, % and _ with the default backslash instead of ESCAPE '!', which MatrixOne 4.1.x silently ignores. - Pass ' and \ through verbatim (the pattern is a bind parameter), so ab'cd no longer over-matches "ab cd". - Add LIKE-fallback-only regressions (cfg_key vs cfgXkey, quote and backslash topics), move the unit test after the use block, drop the stale doc line and add the closing println.
|
Thanks @loveRhythm1990, all points taken. Pushed f37746c (still only
Verification (
|
Re-review of f37746c — LGTMPulled the new head into a clean worktree and re-verified against two fresh containers, MO 4.2.5 and MO 4.1.2. All four points are correctly addressed
Also: One upstream MatrixOne bug found, filed as matrixorigin/matrixone#29951A LIKE pattern that ends with an escaped backslash followed by the trailing It is a genuine MO deviation, not something this PR introduced — MySQL 8.0.46 gets all of these right:
Root cause is the Why this isn't a blocker here: in this code path MO degrades to Worth a one-line note in the One alternative I checked and would not recommend: Nits (non-blocking)
Nothing left that should hold this up. |
What type of PR is this?
Which issue(s) this PR fixes
N/A: no existing issue. I found this while reviewing the code (same bug class as the LIKE-escaping fixes in matrixflow).
What this PR does / why we need it
SqlMemoryStore::find_ids_by_topicbackspurge_by_topic, so it decides which memories get deleted. Its doc says "exact substring match", but the LIKE pattern fromsanitize_like_patterndid not keep that promise:_(e.g.cfg_key)_is a LIKE wildcard: in the LIKE-only fallback path,cfg_keyalso matches (and purges)cfgXkeycfg_key%(e.g.50%)%was replaced by a space, so50%never matcheddiscount 50% applied(purged 0)Changes:
sanitize_like_patternnow escapes!,%and_with!. Both LIKE clauses infind_ids_by_topic(the fulltext+LIKE fast path and the LIKE fallback) useESCAPE '!'. NUL,'and\keep their existing handling.test_purge_by_topic_treats_like_wildcards_literally_verify_db.Verification
Against MatrixOne
8.0.30-MatrixOne-v4.2.5(dockermatrixorigin/matrixone:latest):SELECT 'aXb' LIKE '%a!_b%' ESCAPE '!'returns 0, and'a_b','50%'and'a!b'against their escaped patterns return 1. So MO honorsESCAPE '!'.cargo test -p memoria-api --test api_db_verify purge_by_topic -- --test-threads=1: 5/5 pass, including the existing special-characters and no-match tests.topic "50%" must match literally: left 0, right 1) and passes with the fix. The_case passed before only because the fulltext fast path happened to filtercfgXkey. The over-match happens when the topic falls through to the LIKE-only fallback.make test-unitpasses.cargo test -p memoria-storage --lib: 52 passed.cargo fmt --checkreports nothing in the changed hunks. Pre-existing fmt drift elsewhere and a clippy failure inmemoria-coreunder the box's newer Rust 1.99 are unrelated.