1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-16 23:02:26 +03:00

Make sure left joins still work even when the OR clause optimization fires.

Ticket #1537. (CVS 2788)

FossilOrigin-Name: cbbeb9de0019a0b81318158711590078fcb7e98a
This commit is contained in:
drh
2005-11-26 14:08:07 +00:00
parent d86959f588
commit 54a167d1fe
4 changed files with 137 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
C Remove\ssome\svestiges\sof\sthe\sold\sOS_TEST\sdriver.\s(CVS\s2787)
D 2005-11-26T03:51:19
C Make\ssure\sleft\sjoins\sstill\swork\seven\swhen\sthe\sOR\sclause\soptimization\sfires.\nTicket\s#1537.\s(CVS\s2788)
D 2005-11-26T14:08:08
F Makefile.in 28a2772cd9e03ba758c2a052813092cdb9da73bf
F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -90,7 +90,7 @@ F src/vdbeapi.c 85bbe1d0243a89655433d60711b4bd71979b59cd
F src/vdbeaux.c 3dca9c04c07dda17f0cb06b3a552e1e23106232f
F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
F src/vdbemem.c cd9609c1e7f71ec76d9840c84c3a57ebfa6539cf
F src/where.c 9c260db859047a44fe8219716ee5f0d2bd647420
F src/where.c 1d144279883a6a2498ac8773e723582bca8254ad
F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
F test/all.test 7f0988442ab811dfa41793b5b550f5828ce316f3
F test/alter.test 9d6837a3d946b73df692b7cef2a7644d2e2f6bc6
@@ -232,6 +232,7 @@ F test/tkt1501.test 0cf859299f0052ecfaf7db6f0984f122c7db5d15
F test/tkt1512.test 8efd8d07e27e99d7462f75b5711de65eb7708baf
F test/tkt1514.test baa587a69fa2e8d575ebdaf1460f711281dcba49
F test/tkt1536.test 83ff7a7b6e248016f8d682d4f7a4ae114070d466
F test/tkt1537.test 8e6c8399b5be8abeaac18ca17133990806b175fa
F test/trace.test 9fd28695c463b90c2d32c387a432e01eb26e8ccf
F test/trans.test 10506dc30305cfb8c4098359f7f6f64786f69c5e
F test/trigger1.test 152aed5a1fa90709fe171f2ca501a6b7f7901479
@@ -322,7 +323,7 @@ F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 57a674fc71512f11393b8eb595961ec9465ba4e1
R ecb19a3d611238047de996f8008f2591
P 008f676f20c690255e5cb8ae01df47c5094ac240
R b34d323b79ba342c39e80a4df57b4fa0
U drh
Z 7a1835ca619ef377195f89e0fda27e67
Z 2ac6d09fb843357ed1a6d0af5f42251a

View File

@@ -1 +1 @@
008f676f20c690255e5cb8ae01df47c5094ac240
cbbeb9de0019a0b81318158711590078fcb7e98a

View File

@@ -16,7 +16,7 @@
** so is applicable. Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
**
** $Id: where.c,v 1.183 2005/11/21 12:48:24 drh Exp $
** $Id: where.c,v 1.184 2005/11/26 14:08:08 drh Exp $
*/
#include "sqliteInt.h"
@@ -532,6 +532,16 @@ static int isLikeOrGlob(
}
#endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
/*
** If the pBase expression originated in the ON or USING clause of
** a join, then transfer the appropriate markings over to derived.
*/
static void transferJoinMarkings(Expr *pDerived, Expr *pBase){
pDerived->flags |= pBase->flags & EP_FromJoin;
pDerived->iRightJoinTable = pBase->iRightJoinTable;
}
/*
** The input to this routine is an WhereTerm structure with only the
** "pExpr" field filled in. The job of this routine is to analyze the
@@ -690,6 +700,7 @@ static void exprAnalyze(
}
pNew = sqlite3Expr(TK_IN, pDup, 0, 0);
if( pNew ){
transferJoinMarkings(pNew, pExpr);
pNew->pList = pList;
}else{
sqlite3ExprListDelete(pList);

117
test/tkt1537.test Normal file
View File

@@ -0,0 +1,117 @@
# 2005 November 26
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to verify that ticket #1537 is
# fixed.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_test tkt1537-1.1 {
execsql {
CREATE TABLE t1(id, a1, a2);
INSERT INTO t1 VALUES(1, NULL, NULL);
INSERT INTO t1 VALUES(2, 1, 3);
CREATE TABLE t2(id, b);
INSERT INTO t2 VALUES(3, 1);
INSERT INTO t2 VALUES(4, NULL);
SELECT * FROM t1 LEFT JOIN t2 ON a1=b OR a2=+b;
}
} {1 {} {} {} {} 2 1 3 3 1}
do_test tkt1537-1.2 {
execsql {
SELECT * FROM t1 LEFT JOIN t2 ON a1=b OR a2=b;
}
} {1 {} {} {} {} 2 1 3 3 1}
do_test tkt1537-1.3 {
execsql {
SELECT * FROM t2 LEFT JOIN t1 ON a1=b OR a2=b;
}
} {3 1 2 1 3 4 {} {} {} {}}
do_test tkt1537-1.4 {
execsql {
SELECT * FROM t1 LEFT JOIN t2 ON b IN (a1,a2);
}
} {1 {} {} {} {} 2 1 3 3 1}
do_test tkt1537-1.5 {
execsql {
SELECT * FROM t2 LEFT JOIN t1 ON b IN (a2,a1);
}
} {3 1 2 1 3 4 {} {} {} {}}
do_test tkt1537-1.6 {
execsql {
CREATE INDEX t1a1 ON t1(a1);
CREATE INDEX t1a2 ON t1(a2);
CREATE INDEX t2b ON t2(b);
SELECT * FROM t1 LEFT JOIN t2 ON a1=b OR a2=b;
}
} {1 {} {} {} {} 2 1 3 3 1}
do_test tkt1537-1.7 {
execsql {
SELECT * FROM t2 LEFT JOIN t1 ON a1=b OR a2=b;
}
} {3 1 2 1 3 4 {} {} {} {}}
do_test tkt1537-1.8 {
execsql {
SELECT * FROM t1 LEFT JOIN t2 ON b IN (a1,a2);
}
} {1 {} {} {} {} 2 1 3 3 1}
do_test tkt1537-1.9 {
execsql {
SELECT * FROM t2 LEFT JOIN t1 ON b IN (a2,a1);
}
} {3 1 2 1 3 4 {} {} {} {}}
execsql {
DROP INDEX t1a1;
DROP INDEX t1a2;
DROP INDEX t2b;
}
do_test tkt1537-2.1 {
execsql {
SELECT * FROM t1 LEFT JOIN t2 ON b BETWEEN a1 AND a2;
}
} {1 {} {} {} {} 2 1 3 3 1}
do_test tkt1537-2.2 {
execsql {
CREATE INDEX t2b ON t2(b);
SELECT * FROM t1 LEFT JOIN t2 ON b BETWEEN a1 AND a2;
}
} {1 {} {} {} {} 2 1 3 3 1}
do_test tkt1537-2.3 {
execsql {
SELECT * FROM t2 LEFT JOIN t1 ON b BETWEEN a1 AND a2;
}
} {3 1 2 1 3 4 {} {} {} {}}
do_test tkt1537-2.4 {
execsql {
CREATE INDEX t1a1 ON t1(a1);
CREATE INDEX t1a2 ON t1(a2);
SELECT * FROM t2 LEFT JOIN t1 ON b BETWEEN a1 AND a2;
}
} {3 1 2 1 3 4 {} {} {} {}}
do_test tkt1537-3.1 {
execsql {
SELECT * FROM t1 LEFT JOIN t2 ON b GLOB 'abc*' WHERE t1.id=1;
}
} {1 {} {} {} {}}
do_test tkt1537-3.2 {
execsql {
SELECT * FROM t2 LEFT JOIN t1 ON a1 GLOB 'abc*' WHERE t2.id=3;
}
} {3 1 {} {} {}}
finish_test