where.c File Reference

Go to the source code of this file.

Classes

struct  WhereTerm
struct  WhereClause
struct  ExprMaskSet

Defines

#define BMS   (sizeof(Bitmask)*8)
#define WHERETRACE(X)
#define TERM_DYNAMIC   0x01
#define TERM_VIRTUAL   0x02
#define TERM_CODED   0x04
#define TERM_COPIED   0x08
#define TERM_OR_OK   0x10
#define WO_IN   1
#define WO_EQ   2
#define WO_LT   (WO_EQ<<(TK_LT-TK_EQ))
#define WO_LE   (WO_EQ<<(TK_LE-TK_EQ))
#define WO_GT   (WO_EQ<<(TK_GT-TK_EQ))
#define WO_GE   (WO_EQ<<(TK_GE-TK_EQ))
#define WO_MATCH   64
#define WO_ISNULL   128
#define WHERE_ROWID_EQ   0x000100
#define WHERE_ROWID_RANGE   0x000200
#define WHERE_COLUMN_EQ   0x001000
#define WHERE_COLUMN_RANGE   0x002000
#define WHERE_COLUMN_IN   0x004000
#define WHERE_TOP_LIMIT   0x010000
#define WHERE_BTM_LIMIT   0x020000
#define WHERE_IDX_ONLY   0x080000
#define WHERE_ORDERBY   0x100000
#define WHERE_REVERSE   0x200000
#define WHERE_UNIQUE   0x400000
#define WHERE_VIRTUALTABLE   0x800000
#define initMaskSet(P)   memset(P, 0, sizeof(*P))
#define SWAP(TYPE, A, B)   {TYPE t=A; A=B; B=t;}
#define TRACE_IDX_INPUTS(A)
#define TRACE_IDX_OUTPUTS(A)

Typedefs

typedef struct WhereClause WhereClause
typedef struct ExprMaskSet ExprMaskSet
typedef struct WhereTerm WhereTerm

Functions

static void whereClauseInit (WhereClause *pWC, Parse *pParse, ExprMaskSet *pMaskSet)
static void whereClauseClear (WhereClause *pWC)
static int whereClauseInsert (WhereClause *pWC, Expr *p, int flags)
static void whereSplit (WhereClause *pWC, Expr *pExpr, int op)
static Bitmask getMask (ExprMaskSet *pMaskSet, int iCursor)
static void createMask (ExprMaskSet *pMaskSet, int iCursor)
static Bitmask exprListTableUsage (ExprMaskSet *, ExprList *)
static Bitmask exprSelectTableUsage (ExprMaskSet *, Select *)
static Bitmask exprTableUsage (ExprMaskSet *pMaskSet, Expr *p)
static int allowedOp (int op)
static void exprCommute (Parse *pParse, Expr *pExpr)
static int operatorMask (int op)
static WhereTermfindTerm (WhereClause *pWC, int iCur, int iColumn, Bitmask notReady, u16 op, Index *pIdx)
static void exprAnalyze (SrcList *, WhereClause *, int)
static void exprAnalyzeAll (SrcList *pTabList, WhereClause *pWC)
static int isLikeOrGlob (Parse *pParse, Expr *pExpr, int *pnPattern, int *pisComplete, int *pnoCase)
static int isMatchOfColumn (Expr *pExpr)
static void transferJoinMarkings (Expr *pDerived, Expr *pBase)
static int orTermIsOptCandidate (WhereTerm *pOrTerm, int iCursor, int iColumn)
static int orTermHasOkDuplicate (WhereClause *pOr, WhereTerm *pOrTerm)
static int referencesOtherTables (ExprList *pList, ExprMaskSet *pMaskSet, int iFirst, int iBase)
static int isSortingIndex (Parse *pParse, ExprMaskSet *pMaskSet, Index *pIdx, int base, ExprList *pOrderBy, int nEqCol, int *pbRev)
static int sortableByRowid (int base, ExprList *pOrderBy, ExprMaskSet *pMaskSet, int *pbRev)
static double estLog (double N)
static double bestVirtualIndex (Parse *pParse, WhereClause *pWC, struct SrcList_item *pSrc, Bitmask notReady, ExprList *pOrderBy, int orderByUsable, sqlite3_index_info **ppIdxInfo)
static double bestIndex (Parse *pParse, WhereClause *pWC, struct SrcList_item *pSrc, Bitmask notReady, ExprList *pOrderBy, Index **ppIndex, int *pFlags, int *pnEq)
static void disableTerm (WhereLevel *pLevel, WhereTerm *pTerm)
static void codeApplyAffinity (Parse *pParse, int base, int n, Index *pIdx)
static int codeEqualityTerm (Parse *pParse, WhereTerm *pTerm, WhereLevel *pLevel, int iTarget)
static int codeAllEqualityTerms (Parse *pParse, WhereLevel *pLevel, WhereClause *pWC, Bitmask notReady, int nExtraReg)
static void whereInfoFree (sqlite3 *db, WhereInfo *pWInfo)
WhereInfosqlite3WhereBegin (Parse *pParse, SrcList *pTabList, Expr *pWhere, ExprList **ppOrderBy, u8 wflags)
void sqlite3WhereEnd (WhereInfo *pWInfo)

Define Documentation

#define BMS   (sizeof(Bitmask)*8)

Definition at line 26 of file where.c.

Referenced by bestIndex(), and sqlite3WhereBegin().

#define initMaskSet (  )     memset(P, 0, sizeof(*P))

Definition at line 288 of file where.c.

Referenced by sqlite3WhereBegin().

#define SWAP ( TYPE,
A,
 )     {TYPE t=A; A=B; B=t;}

Definition at line 385 of file where.c.

#define TERM_CODED   0x04

Definition at line 97 of file where.c.

Referenced by codeAllEqualityTerms(), disableTerm(), and sqlite3WhereBegin().

#define TERM_COPIED   0x08

Definition at line 98 of file where.c.

Referenced by exprAnalyze(), and orTermHasOkDuplicate().

#define TERM_DYNAMIC   0x01

Definition at line 95 of file where.c.

Referenced by exprAnalyze(), whereClauseClear(), and whereClauseInsert().

#define TERM_OR_OK   0x10

Definition at line 99 of file where.c.

Referenced by exprAnalyze(), and orTermHasOkDuplicate().

#define TERM_VIRTUAL   0x02

Definition at line 96 of file where.c.

Referenced by exprAnalyze(), orTermHasOkDuplicate(), and sqlite3WhereBegin().

#define TRACE_IDX_INPUTS (  ) 

Definition at line 1234 of file where.c.

Referenced by bestVirtualIndex().

#define TRACE_IDX_OUTPUTS (  ) 

Definition at line 1235 of file where.c.

Referenced by bestVirtualIndex().

#define WHERE_BTM_LIMIT   0x020000

Definition at line 177 of file where.c.

Referenced by bestIndex(), and sqlite3WhereBegin().

#define WHERE_COLUMN_EQ   0x001000

Definition at line 173 of file where.c.

Referenced by bestIndex(), and sqlite3WhereBegin().

#define WHERE_COLUMN_IN   0x004000

Definition at line 175 of file where.c.

Referenced by bestIndex().

#define WHERE_COLUMN_RANGE   0x002000

Definition at line 174 of file where.c.

Referenced by bestIndex(), and sqlite3WhereBegin().

#define WHERE_IDX_ONLY   0x080000

Definition at line 178 of file where.c.

Referenced by bestIndex(), sqlite3WhereBegin(), and sqlite3WhereEnd().

#define WHERE_ORDERBY   0x100000

Definition at line 179 of file where.c.

Referenced by bestIndex(), and sqlite3WhereBegin().

#define WHERE_REVERSE   0x200000

Definition at line 180 of file where.c.

Referenced by bestIndex(), and sqlite3WhereBegin().

#define WHERE_ROWID_EQ   0x000100

Definition at line 171 of file where.c.

Referenced by bestIndex(), and sqlite3WhereBegin().

#define WHERE_ROWID_RANGE   0x000200

Definition at line 172 of file where.c.

Referenced by bestIndex(), and sqlite3WhereBegin().

#define WHERE_TOP_LIMIT   0x010000

Definition at line 176 of file where.c.

Referenced by bestIndex(), and sqlite3WhereBegin().

#define WHERE_UNIQUE   0x400000

Definition at line 181 of file where.c.

Referenced by bestIndex(), and sqlite3WhereBegin().

#define WHERE_VIRTUALTABLE   0x800000

Definition at line 182 of file where.c.

Referenced by sqlite3WhereBegin().

#define WHERETRACE (  ) 

Definition at line 37 of file where.c.

Referenced by bestIndex(), bestVirtualIndex(), and sqlite3WhereBegin().

#define WO_EQ   2
#define WO_GE   (WO_EQ<<(TK_GE-TK_EQ))

Definition at line 156 of file where.c.

Referenced by bestIndex(), bestVirtualIndex(), operatorMask(), and sqlite3WhereBegin().

#define WO_GT   (WO_EQ<<(TK_GT-TK_EQ))

Definition at line 155 of file where.c.

Referenced by bestIndex(), bestVirtualIndex(), operatorMask(), and sqlite3WhereBegin().

#define WO_IN   1
#define WO_ISNULL   128

Definition at line 158 of file where.c.

Referenced by bestIndex(), bestVirtualIndex(), codeAllEqualityTerms(), findTerm(), and operatorMask().

#define WO_LE   (WO_EQ<<(TK_LE-TK_EQ))

Definition at line 154 of file where.c.

Referenced by bestIndex(), bestVirtualIndex(), operatorMask(), and sqlite3WhereBegin().

#define WO_LT   (WO_EQ<<(TK_LT-TK_EQ))

Definition at line 153 of file where.c.

Referenced by bestIndex(), bestVirtualIndex(), operatorMask(), and sqlite3WhereBegin().

#define WO_MATCH   64

Definition at line 157 of file where.c.

Referenced by bestVirtualIndex(), and exprAnalyze().


Typedef Documentation

typedef struct ExprMaskSet ExprMaskSet

Definition at line 43 of file where.c.

typedef struct WhereClause WhereClause

Definition at line 42 of file where.c.

typedef struct WhereTerm WhereTerm

Definition at line 78 of file where.c.


Function Documentation

static int allowedOp ( int  op  )  [static]

Definition at line 374 of file where.c.

References TK_EQ, TK_GE, TK_GT, TK_IN, TK_ISNULL, TK_LE, and TK_LT.

Referenced by exprAnalyze(), exprCommute(), and operatorMask().

static double bestIndex ( Parse pParse,
WhereClause pWC,
struct SrcList_item *  pSrc,
Bitmask  notReady,
ExprList pOrderBy,
Index **  ppIndex,
int *  pFlags,
int *  pnEq 
) [static]
static double bestVirtualIndex ( Parse pParse,
WhereClause pWC,
struct SrcList_item *  pSrc,
Bitmask  notReady,
ExprList pOrderBy,
int  orderByUsable,
sqlite3_index_info **  ppIdxInfo 
) [static]
static int codeAllEqualityTerms ( Parse pParse,
WhereLevel pLevel,
WhereClause pWC,
Bitmask  notReady,
int  nExtraReg 
) [static]
static void codeApplyAffinity ( Parse pParse,
int  base,
int  n,
Index pIdx 
) [static]
static int codeEqualityTerm ( Parse pParse,
WhereTerm pTerm,
WhereLevel pLevel,
int  iTarget 
) [static]
static void createMask ( ExprMaskSet pMaskSet,
int  iCursor 
) [static]

Definition at line 312 of file where.c.

References ArraySize, ExprMaskSet::ix, and ExprMaskSet::n.

Referenced by sqlite3WhereBegin().

static void disableTerm ( WhereLevel pLevel,
WhereTerm pTerm 
) [static]
static double estLog ( double  N  )  [static]

Definition at line 1184 of file where.c.

Referenced by bestIndex().

static void exprAnalyze ( SrcList pSrc,
WhereClause pWC,
int  idxTerm 
) [static]
static void exprAnalyzeAll ( SrcList pTabList,
WhereClause pWC 
) [static]

Definition at line 504 of file where.c.

References exprAnalyze(), and WhereClause::nTerm.

Referenced by exprAnalyze(), and sqlite3WhereBegin().

static void exprCommute ( Parse pParse,
Expr pExpr 
) [static]
static Bitmask exprListTableUsage ( ExprMaskSet pMaskSet,
ExprList pList 
) [static]
static Bitmask exprSelectTableUsage ( ExprMaskSet pMaskSet,
Select pS 
) [static]
static Bitmask exprTableUsage ( ExprMaskSet pMaskSet,
Expr p 
) [static]
static WhereTerm* findTerm ( WhereClause pWC,
int  iCur,
int  iColumn,
Bitmask  notReady,
u16  op,
Index pIdx 
) [static]
static Bitmask getMask ( ExprMaskSet pMaskSet,
int  iCursor 
) [static]

Definition at line 294 of file where.c.

References ExprMaskSet::ix, and ExprMaskSet::n.

Referenced by exprAnalyze(), exprTableUsage(), referencesOtherTables(), and sqlite3WhereBegin().

static int isLikeOrGlob ( Parse pParse,
Expr pExpr,
int *  pnPattern,
int *  pisComplete,
int *  pnoCase 
) [static]
static int isMatchOfColumn ( Expr pExpr  )  [static]
static int isSortingIndex ( Parse pParse,
ExprMaskSet pMaskSet,
Index pIdx,
int  base,
ExprList pOrderBy,
int  nEqCol,
int *  pbRev 
) [static]
static int operatorMask ( int  op  )  [static]

Definition at line 422 of file where.c.

References allowedOp(), TK_EQ, TK_GE, TK_GT, TK_IN, TK_ISNULL, TK_LE, TK_LT, WO_EQ, WO_GE, WO_GT, WO_IN, WO_ISNULL, WO_LE, and WO_LT.

Referenced by exprAnalyze().

static int orTermHasOkDuplicate ( WhereClause pOr,
WhereTerm pOrTerm 
) [static]

Definition at line 689 of file where.c.

References WhereClause::a, WhereTerm::flags, WhereTerm::iParent, TERM_COPIED, TERM_OR_OK, and TERM_VIRTUAL.

Referenced by exprAnalyze().

static int orTermIsOptCandidate ( WhereTerm pOrTerm,
int  iCursor,
int  iColumn 
) [static]
static int referencesOtherTables ( ExprList pList,
ExprMaskSet pMaskSet,
int  iFirst,
int  iBase 
) [static]

Definition at line 1001 of file where.c.

References ExprList::a, exprTableUsage(), getMask(), and ExprList::ExprList_item::pExpr.

Referenced by isSortingIndex(), and sortableByRowid().

static int sortableByRowid ( int  base,
ExprList pOrderBy,
ExprMaskSet pMaskSet,
int *  pbRev 
) [static]
WhereInfo* sqlite3WhereBegin ( Parse pParse,
SrcList pTabList,
Expr pWhere,
ExprList **  ppOrderBy,
u8  wflags 
)

Definition at line 2037 of file where.c.

References ExprList::a, WhereClause::a, WhereInfo::a, SrcList::a, sqlite3_index_info::aConstraint, sqlite3_index_info::aConstraintUsage, Index::aiColumn, WhereLevel::aInLoop, Index::aSortOrder, bestIndex(), bestVirtualIndex(), BMS, WhereLevel::brk, codeAllEqualityTerms(), codeApplyAffinity(), codeEqualityTerm(), WhereLevel::cont, createMask(), Parse::db, db, Parse::disableColCache, disableTerm(), WhereTerm::eOperator, EP_FromJoin, Parse::explain, exprAnalyzeAll(), ExprHasProperty, findTerm(), WhereTerm::flags, WhereLevel::flags, getMask(), WhereInfo::iBreak, Expr::iColumn, WhereInfo::iContinue, SrcList::SrcList_item::iCursor, sqlite3_index_info::idxNum, sqlite3_index_info::idxStr, WhereLevel::iFrom, WhereLevel::iIdxCur, WhereLevel::iLeftJoin, WhereLevel::iMem, initMaskSet, IsVirtual, WhereLevel::iTabCur, WhereInfo::iTop, JT_CROSS, JT_LEFT, WhereTerm::leftCursor, sqlite3::mallocFailed, Table::nCol, Index::nColumn, sqlite3_index_info::nConstraint, sqlite3_index_info::needToFreeIdxStr, WhereLevel::nEq, ExprList::nExpr, WhereLevel::nIn, WhereInfo::nLevel, Parse::nMem, SrcList::nSrc, Parse::nTab, WhereClause::nTerm, WhereLevel::nxt, WhereInfo::okOnePass, Expr::op, WhereLevel::op, OP_Column, OP_Explain, OP_ForceInt, OP_Ge, OP_Gt, OP_IdxGE, OP_IdxLT, OP_IdxRowid, OP_Integer, OP_IsNull, OP_Last, OP_Le, OP_Lt, OP_MoveGe, OP_MoveGt, OP_MoveLe, OP_MoveLt, OP_MustBeInt, OP_Next, OP_Noop, OP_NotExists, OP_Null, OP_OpenRead, OP_OpenWrite, OP_Prev, OP_Rewind, OP_Rowid, OP_SetNumColumns, OP_VFilter, OP_VNext, OP_VOpen, sqlite3_index_info::orderByConsumed, WhereLevel::p1, WhereLevel::p2, P4_DYNAMIC, P4_INT32, P4_KEYINFO_HANDOFF, P4_MPRINTF, P4_STATIC, P4_VTAB, WhereLevel::p5, WhereLevel::pBestIdx, ExprList::ExprList_item::pExpr, WhereTerm::pExpr, WhereLevel::pIdx, WhereLevel::pIdxInfo, SrcList::SrcList_item::pIndex, WhereInfo::pParse, WhereTerm::prereqAll, Expr::pRight, Index::pSchema, Table::pSchema, Table::pSelect, WhereInfo::pTabList, Parse::pVdbe, Table::pVtab, sqlite3CodeVerifySchema(), sqlite3DbMallocZero(), sqlite3ErrorMsg(), sqlite3ExprClearColumnCache(), sqlite3ExprCode(), sqlite3ExprCodeConstants(), sqlite3ExprIfFalse(), sqlite3ExprIsConstantNotJoin(), sqlite3GetTempRange(), sqlite3GetTempReg(), sqlite3IndexKeyinfo(), sqlite3MAppendf(), sqlite3MPrintf(), sqlite3OpenTable(), sqlite3ReleaseTempRange(), sqlite3ReleaseTempReg(), sqlite3SchemaToIndex(), sqlite3TableLock(), sqlite3VdbeAddOp2(), sqlite3VdbeAddOp3(), sqlite3VdbeAddOp4(), sqlite3VdbeChangeP2(), sqlite3VdbeChangeP5(), sqlite3VdbeCurrentAddr(), sqlite3VdbeMakeLabel(), SQLITE_AFF_NUMERIC, SQLITE_BIG_DBL, SQLITE_INT_TO_PTR, SQLITE_JUMPIFNULL, SQLITE_SO_ASC, SQLITE_STMTSTATUS_FULLSCAN_STEP, SWAP, Table::tabFlags, TERM_CODED, TERM_VIRTUAL, testcase, TF_Ephemeral, TK_AND, TK_GT, TK_LE, TK_LT, Index::tnum, Table::tnum, WhereLevel::top, VdbeComment, WHERE_BTM_LIMIT, WHERE_COLUMN_EQ, WHERE_COLUMN_RANGE, WHERE_IDX_ONLY, WHERE_ONEPASS_DESIRED, WHERE_ORDERBY, WHERE_ORDERBY_MIN, WHERE_REVERSE, WHERE_ROWID_EQ, WHERE_ROWID_RANGE, WHERE_TOP_LIMIT, WHERE_UNIQUE, WHERE_VIRTUALTABLE, whereClauseClear(), whereClauseInit(), whereInfoFree(), whereSplit(), WHERETRACE, WO_EQ, WO_GE, WO_GT, WO_IN, WO_LE, WO_LT, SrcList::SrcList_item::zAlias, Table::zName, and Index::zName.

Referenced by sqlite3DeleteFrom(), sqlite3Select(), and sqlite3Update().

void sqlite3WhereEnd ( WhereInfo pWInfo  ) 
static void transferJoinMarkings ( Expr pDerived,
Expr pBase 
) [static]

Definition at line 615 of file where.c.

References EP_FromJoin, Expr::flags, and Expr::iRightJoinTable.

Referenced by exprAnalyze().

static void whereClauseClear ( WhereClause pWC  )  [static]
static void whereClauseInit ( WhereClause pWC,
Parse pParse,
ExprMaskSet pMaskSet 
) [static]
static int whereClauseInsert ( WhereClause pWC,
Expr p,
int  flags 
) [static]
static void whereInfoFree ( sqlite3 db,
WhereInfo pWInfo 
) [static]
static void whereSplit ( WhereClause pWC,
Expr pExpr,
int  op 
) [static]

Definition at line 275 of file where.c.

References Expr::op, Expr::pLeft, Expr::pRight, and whereClauseInsert().

Referenced by exprAnalyze(), and sqlite3WhereBegin().


ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:50:03 2011 by Doxygen 1.6.1