Candidate fix for ticket #3082. Test cases needed. (CVS 5047)
FossilOrigin-Name: f6313311ddfb1ee2d6660b9be99afe721a8a9aff
This commit is contained in:
parent
ce3d5cf0c7
commit
b287f4b646
12
manifest
12
manifest
@ -1,5 +1,5 @@
|
||||
C Remove\stwo\smore\sunused\sfiles.\s(CVS\s5046)
|
||||
D 2008-04-24T22:57:29
|
||||
C Candidate\sfix\sfor\sticket\s#3082.\sTest\scases\sneeded.\s(CVS\s5047)
|
||||
D 2008-04-25T00:08:38
|
||||
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
|
||||
F Makefile.in 25b3282a4ac39388632c2fb0e044ff494d490952
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
@ -94,7 +94,7 @@ F src/callback.c 77b302b0d41468dcda78c70e706e5b84577f0fa0
|
||||
F src/complete.c 4cf68fd75d60257524cbe74f87351b9848399131
|
||||
F src/date.c e41ce4513fb0e359dc678d6bddb4ace135fe365d
|
||||
F src/delete.c e4bd53c46969c9fb05cfbba4abc0c93a923f8072
|
||||
F src/expr.c d5733edd985926fd94e7d51b3763084f7915e2c3
|
||||
F src/expr.c 6a6f37005921314b1ae7c3ed4fab03c58fd5e647
|
||||
F src/fault.c 83057e86815d473e526f7df0b0108dfdd022ff23
|
||||
F src/func.c c9e8c7ff4c45027edee89bde7adbf86a3a3b2afe
|
||||
F src/hash.c 522a8f5a23cf18fe5845afee7263c5be76c25ca2
|
||||
@ -630,7 +630,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
|
||||
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
|
||||
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
|
||||
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
|
||||
P 0d04ccd97841bbbda564cc6ae5da057ee3888fa3
|
||||
R d5c9fc7dffd786a749d8abc27197263d
|
||||
P a400faf51970b312e9d8c8b4fa099558cc620b69
|
||||
R 38bfb0a4f4b6d7e46cc483b5953eff78
|
||||
U drh
|
||||
Z 7362658de5fb5aa041e57c1c0e6c3d9d
|
||||
Z b2d1f6c45fdfbcc2b1867a8bfdc2ffb0
|
||||
|
@ -1 +1 @@
|
||||
a400faf51970b312e9d8c8b4fa099558cc620b69
|
||||
f6313311ddfb1ee2d6660b9be99afe721a8a9aff
|
51
src/expr.c
51
src/expr.c
@ -12,7 +12,7 @@
|
||||
** This file contains routines used for analyzing expressions and
|
||||
** for generating VDBE code that evaluates expressions in SQLite.
|
||||
**
|
||||
** $Id: expr.c,v 1.368 2008/04/24 12:36:35 danielk1977 Exp $
|
||||
** $Id: expr.c,v 1.369 2008/04/25 00:08:38 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
@ -1576,6 +1576,45 @@ struct QueryCoder {
|
||||
#define sqlite3_enable_in_opt 1
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Return true if the IN operator optimization is enabled and
|
||||
** the SELECT statement p exists and is of the
|
||||
** simple form:
|
||||
**
|
||||
** SELECT <column> FROM <table>
|
||||
**
|
||||
** If this is the case, it may be possible to use an existing table
|
||||
** or index instead of generating an epheremal table.
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_SUBQUERY
|
||||
static int isCandidateForInOpt(Select *p){
|
||||
SrcList *pSrc;
|
||||
ExprList *pEList;
|
||||
Table *pTab;
|
||||
if( !sqlite3_enable_in_opt ) return 0; /* IN optimization must be enabled */
|
||||
if( p==0 ) return 0; /* right-hand side of IN is SELECT */
|
||||
if( p->pPrior ) return 0; /* Not a compound SELECT */
|
||||
if( p->isDistinct ) return 0; /* No DISTINCT keyword */
|
||||
if( p->isAgg ) return 0; /* Contains no aggregate functions */
|
||||
if( p->pGroupBy ) return 0; /* Has no GROUP BY clause */
|
||||
if( p->pLimit ) return 0; /* Has no LIMIT clause */
|
||||
if( p->pOffset ) return 0;
|
||||
if( p->pWhere ) return 0; /* Has no WHERE clause */
|
||||
pSrc = p->pSrc;
|
||||
if( pSrc==0 ) return 0; /* A single table in the FROM clause */
|
||||
if( pSrc->nSrc!=1 ) return 0;
|
||||
if( pSrc->a[0].pSelect ) return 0; /* FROM clause is not a subquery */
|
||||
pTab = pSrc->a[0].pTab;
|
||||
if( pTab==0 ) return 0;
|
||||
if( pTab->pSelect ) return 0; /* FROM clause is not a view */
|
||||
if( IsVirtual(pTab) ) return 0; /* FROM clause not a virtual table */
|
||||
pEList = p->pEList;
|
||||
if( pEList->nExpr!=1 ) return 0; /* One column in the result set */
|
||||
if( pEList->a[0].pExpr->op!=TK_COLUMN ) return 0; /* Result is a column */
|
||||
return 1;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_SUBQUERY */
|
||||
|
||||
/*
|
||||
** This function is used by the implementation of the IN (...) operator.
|
||||
** It's job is to find or create a b-tree structure that may be used
|
||||
@ -1621,14 +1660,8 @@ int sqlite3FindInIndex(Parse *pParse, Expr *pX, int mustBeUnique){
|
||||
** If this is the case, it may be possible to use an existing table
|
||||
** or index instead of generating an epheremal table.
|
||||
*/
|
||||
if( sqlite3_enable_in_opt
|
||||
&& (p=pX->pSelect)!=0 && !p->pPrior
|
||||
&& !p->isDistinct && !p->isAgg && !p->pGroupBy
|
||||
&& p->pSrc && p->pSrc->nSrc==1 && !p->pSrc->a[0].pSelect
|
||||
&& p->pSrc->a[0].pTab && !p->pSrc->a[0].pTab->pSelect
|
||||
&& p->pEList->nExpr==1 && p->pEList->a[0].pExpr->op==TK_COLUMN
|
||||
&& !p->pLimit && !p->pOffset && !p->pWhere
|
||||
){
|
||||
p = pX->pSelect;
|
||||
if( isCandidateForInOpt(p) ){
|
||||
sqlite3 *db = pParse->db;
|
||||
Index *pIdx;
|
||||
Expr *pExpr = p->pEList->a[0].pExpr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user