Skip to content

SQLite: Support NOT GLOB and NOT MATCH - #3043

Merged
LucaCappelletti94 merged 1 commit into
mainfrom
sqlite-not-glob
Dec 1, 2026
Merged

LucaCappelletti94 merged 1 commit into
mainfrom
sqlite-not-glob

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

SQLiteDialect parses a GLOB b and a MATCH b but rejects their negated forms, which SQLite accepts.

CREATE INDEX i ON t(id) WHERE id NOT GLOB 'h-*';
-- Expected: IN or BETWEEN after NOT, found: GLOB

The SQLite infix hook now also reads NOT GLOB and NOT MATCH as the new BinaryOperator::NotGlob and BinaryOperator::NotMatch, at the precedence the plain operators already have.

@LucaCappelletti94 LucaCappelletti94 added enhancement New feature or request api change fuzzer A bug found by the fuzzer SQLite labels Nov 24, 2026
@codecov-commenter

codecov-commenter commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.65%. Comparing base (6ac24a8) to head (cc68a65).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3043   +/-   ##
=======================================
  Coverage   83.64%   83.65%           
=======================================
  Files          42       42           
  Lines       35833    35837    +4     
  Branches    35833    35837    +4     
=======================================
+ Hits        29974    29980    +6     
  Misses       2418     2418           
+ Partials     3441     3439    -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zommiommy

Copy link
Copy Markdown

there's a precedence issue:

SELECT 'a' NOT GLOB 'a' = 1
-- this PR:  'a' NOT GLOB ('a' = 1)
-- SQLite:   ('a' NOT GLOB 'a') = 1   -- sqlite3 3.53.3 returns 0; the right-grouped form returns 1

in SQLite's docs (https://www.sqlite.org/lang_expr.html#operators_and_parse_affecting_attributes), =, ==, <>, !=, IS [NOT] [DISTINCT FROM], BETWEEN, IN, MATCH, LIKE, REGEXP and
GLOB share one cell, so they have the same precedence and are left-associative.
note 5 says NOT keeps the bare operator's precedence.
SQLiteDialect maps Precedence::Like to 19 and Eq/Between to 20, so they are not on the same level.

#[test]
fn parse_negated_glob_and_match_binds_like_comparison() {
   for (operator, expected) in [
       ("NOT GLOB", BinaryOperator::NotGlob),
       ("NOT MATCH", BinaryOperator::NotMatch),
   ] {
       assert_eq!(
           sqlite().verified_expr(&format!("a {operator} 'p' = 1")),
           Expr::BinaryOp {
               left: Box::new(Expr::BinaryOp {
                   left: Box::new(Expr::Identifier(Ident::new("a"))),
                   op: expected,
                   right: Box::new(Expr::Value(
                       (Value::SingleQuotedString("p".to_string())).with_empty_span()
                   )),
               }),
               op: BinaryOperator::Eq,
               right: Box::new(Expr::value(number("1"))),
           }
       );
   }
}

GLOB / MATCH already have this problem on main

a nit: NotGlob/NotMatch should be inserted at the end; otherwise, it will BinaryOperator's serialized versions. serde formats like bincode use the enum variant position as discriminant, so changing the order of variants breaks file compatibility. idk if this is important for this crate tho.

@LucaCappelletti94

Copy link
Copy Markdown
Contributor Author

@zommiommy the misgrouping comes from the preexistent SQLiteDialect::prec_value, which ranks Precedence::Like at 19 below Eq and Between at 20. GLOB, MATCH, REGEXP, LIKE and their NOT forms all take that level, so a GLOB 'p' = 1 and a LIKE 'p' = 1 misgroup on main as well.

I will fix the level in a separate PR from main, with your test extended to all of them.

@LucaCappelletti94

Copy link
Copy Markdown
Contributor Author

Thanks @zommiommy for the review, I will be merging this now.

cc @alamb

@LucaCappelletti94
LucaCappelletti94 added this pull request to the merge queue Dec 1, 2026
Merged via the queue into main with commit 20a8c47 Dec 1, 2026
10 checks passed
@LucaCappelletti94
LucaCappelletti94 deleted the sqlite-not-glob branch December 1, 2026 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api change enhancement New feature or request fuzzer A bug found by the fuzzer SQLite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants