aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/select.c11
-rw-r--r--src/sqliteInt.h2
2 files changed, 11 insertions, 2 deletions
diff --git a/src/select.c b/src/select.c
index 69a07528f..e546a664c 100644
--- a/src/select.c
+++ b/src/select.c
@@ -7421,7 +7421,14 @@ static void existsToJoin(Parse *pParse, Select *p, Expr *pWhere){
pSub->pWhere = 0;
pSub->pSrc = 0;
- sqlite3SelectDelete(pParse->db, pSub);
+ sqlite3ParserAddCleanup(pParse, sqlite3SelectDeleteGeneric, pSub);
+#if TREETRACE_ENABLED
+ if( sqlite3TreeTrace & 0x100000 ){
+ TREETRACE(0x100000,pParse,p,
+ ("After EXISTS-to-JOIN optimization:\n"));
+ sqlite3TreeViewSelect(0, p, 0);
+ }
+#endif
}
}
}
@@ -7756,7 +7763,7 @@ int sqlite3Select(
/* If there may be an "EXISTS (SELECT ...)" in the WHERE clause, attempt
** to change it into a join. */
- if( pParse->bHasExists ){
+ if( pParse->bHasExists && OptimizationEnabled(db,SQLITE_ExistsToJoin) ){
existsToJoin(pParse, p, p->pWhere);
pTabList = p->pSrc;
}
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index c976b928d..6a1b22f92 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -1126,6 +1126,7 @@ extern u32 sqlite3TreeTrace;
** 0x00020000 Transform DISTINCT into GROUP BY
** 0x00040000 SELECT tree dump after all code has been generated
** 0x00080000 NOT NULL strength reduction
+** 0x00100000 EXISTS-to-JOIN optimization
*/
/*
@@ -1924,6 +1925,7 @@ struct sqlite3 {
#define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
#define SQLITE_NullUnusedCols 0x04000000 /* NULL unused columns in subqueries */
#define SQLITE_OnePass 0x08000000 /* Single-pass DELETE and UPDATE */
+#define SQLITE_ExistsToJoin 0x10000000 /* The EXISTS-to-JOIN optimization */
#define SQLITE_AllOpts 0xffffffff /* All optimizations */
/*