From 6df7be90c5d639940084023a04b3897538cd8b0e Mon Sep 17 00:00:00 2001 From: RumovZ Date: Mon, 9 Jan 2023 23:49:35 +0100 Subject: [PATCH] Fix negated `introduced:x` search (#2306) 1. Add outer brackets. 2. Coalesce aggregate, because `null and true` is `null` in SQL land, so cards that were not introduced, but manually rescheduled in the period of interest, would not show up in a negated search. --- rslib/src/search/sqlwriter.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rslib/src/search/sqlwriter.rs b/rslib/src/search/sqlwriter.rs index 92d4adb29..afd86f915 100644 --- a/rslib/src/search/sqlwriter.rs +++ b/rslib/src/search/sqlwriter.rs @@ -578,11 +578,11 @@ impl SqlWriter<'_> { write!( self.sql, concat!( - "(SELECT min(id) > {cutoff} FROM revlog WHERE cid = c.id ", + "((SELECT coalesce(min(id) > {cutoff}, false) FROM revlog WHERE cid = c.id ", // Exclude manual reschedulings "AND ease != 0) ", // Logically redundant, speeds up query - "AND c.id IN (SELECT cid FROM revlog WHERE id > {cutoff})" + "AND c.id IN (SELECT cid FROM revlog WHERE id > {cutoff}))" ), cutoff = cutoff, ) @@ -785,8 +785,8 @@ mod test { s(ctx, "introduced:3").0, format!( concat!( - "((SELECT min(id) > {cutoff} FROM revlog WHERE cid = c.id AND ease != 0) ", - "AND c.id IN (SELECT cid FROM revlog WHERE id > {cutoff}))" + "(((SELECT coalesce(min(id) > {cutoff}, false) FROM revlog WHERE cid = c.id AND ease != 0) ", + "AND c.id IN (SELECT cid FROM revlog WHERE id > {cutoff})))" ), cutoff = (timing.next_day_at.0 - (86_400 * 3)) * 1_000, )