From f55cc785fd8ecaa4960e1b2537ce12fb5c925027 Mon Sep 17 00:00:00 2001 From: Dan Kennedy Date: Fri, 26 Apr 2024 14:32:58 +0000 Subject: [PATCH] Fix a problem allowing a LIMIT constraint to be passed to a virtual table in cases where there exist WHERE terms that cannot also be passed. --- src/whereexpr.c | 1 + test/bestindexC.test | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/whereexpr.c b/src/whereexpr.c index ff6f753b5a..d25bce5f08 100644 --- a/src/whereexpr.c +++ b/src/whereexpr.c @@ -1638,6 +1638,7 @@ void SQLITE_NOINLINE sqlite3WhereAddLimit(WhereClause *pWC, Select *p){ continue; } if( pWC->a[ii].leftCursor!=iCsr ) return; + if( pWC->a[ii].prereqRight!=0 ) return; } /* Check condition (5). Return early if it is not met. */ diff --git a/test/bestindexC.test b/test/bestindexC.test index 91b8f027eb..769f1601db 100644 --- a/test/bestindexC.test +++ b/test/bestindexC.test @@ -134,4 +134,24 @@ do_execsql_test 2.1 { LIMIT 3 } {c d} +#------------------------------------------------------------------------- +reset_db +register_tcl_module db +do_execsql_test 3.0 { + CREATE VIRTUAL TABLE y1 USING tcl(vtab_command "1 2 3 4 5 6 7 8 9 10"); +} {} + +do_execsql_test 3.1 { + SELECT * FROM y1 WHERE a = COALESCE('8', a) LIMIT 3 +} {8} + +do_execsql_test 3.2 { + SELECT * FROM y1 WHERE a = '2' LIMIT 3 +} {2} + +load_static_extension db series +do_execsql_test 3.3 { + SELECT * FROM generate_series(1, 5) WHERE value = (value & 14) LIMIT 3 +} {2 4} + finish_test -- 2.11.4.GIT