Skip to content

Commit

Permalink
{176689231}: Porting SQLite fix for LEFT-JOIN using OR that matches n…
Browse files Browse the repository at this point in the history
…o rows

This patch backports https://www.sqlite.org/src/info/f02030b3403d6773

Signed-off-by: Rivers Zhang <[email protected]>
  • Loading branch information
riverszhang89 committed Sep 28, 2024
1 parent fac6c02 commit 875ca8c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sqlite/src/vdbeaux.c
Original file line number Diff line number Diff line change
Expand Up @@ -3637,7 +3637,7 @@ int sqlite3VdbeCursorMoveto(VdbeCursor **pp, int *piCol){
assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO );
if( p->deferredMoveto ){
int iMap;
if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 ){
if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 && !p->nullRow ){
*pp = p->pAltCursor;
*piCol = iMap - 1;
return SQLITE_OK;
Expand Down
14 changes: 14 additions & 0 deletions tests/yast.test/whereD.test
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,18 @@ do_searchcount_test 6.6.4 {
SELECT c FROM x1 WHERE b=6 OR c=11 OR a=1
} {7 11 3 search 0}

# 2020-02-22 ticket aa4378693018aa99
# In the OP_Column opcode, if a cursor is marked with OP_NullRow
# (because it is the right table of a LEFT JOIN that does not match)
# then do not substitute index cursors, as the index cursors do not
# have the VdbeCursor.nullRow flag set.
#
do_execsql_test 6.7 {
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;
CREATE TABLE t1(a UNIQUE, b UNIQUE);
INSERT INTO t1(a,b) VALUES(null,2);
CREATE VIEW t2 AS SELECT * FROM t1 WHERE b<10 OR a<7 ORDER BY b;
SELECT t1.* FROM t1 LEFT JOIN t2 ON abs(t1.a)=abs(t2.b);
} {{} 2}
finish_test

0 comments on commit 875ca8c

Please sign in to comment.