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, )