#ifndef SQLITE_WHEREINT_H
#define SQLITE_WHEREINT_H
typedef struct WhereClause WhereClause;
typedef struct WhereMaskSet WhereMaskSet;
typedef struct WhereOrInfo WhereOrInfo;
typedef struct WhereAndInfo WhereAndInfo;
typedef struct WhereLevel WhereLevel;
typedef struct WhereLoop WhereLoop;
typedef struct WherePath WherePath;
typedef struct WhereTerm WhereTerm;
typedef struct WhereLoopBuilder WhereLoopBuilder;
typedef struct WhereScan WhereScan;
typedef struct WhereOrCost WhereOrCost;
typedef struct WhereOrSet WhereOrSet;
typedef struct WhereMemBlock WhereMemBlock;
typedef struct WhereRightJoin WhereRightJoin;
struct WhereMemBlock {
WhereMemBlock *pNext;
u64 sz;
};
struct WhereRightJoin {
int iMatch;
int regBloom;
int regReturn;
int addrSubrtn;
int endSubrtn;
};
struct WhereLevel {
int iLeftJoin;
int iTabCur;
int iIdxCur;
int addrBrk;
int addrNxt;
int addrSkip;
int addrCont;
int addrFirst;
int addrBody;
int regBignull;
int addrBignull;
#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
u32 iLikeRepCntr;
int addrLikeRep;
#endif
int regFilter;
WhereRightJoin *pRJ;
u8 iFrom;
u8 op, p3, p5;
int p1, p2;
union {
struct {
int nIn;
struct InLoop {
int iCur;
int addrInTop;
int iBase;
int nPrefix;
u8 eEndLoopOp;
} *aInLoop;
} in;
Index *pCoveringIdx;
} u;
struct WhereLoop *pWLoop;
Bitmask notReady;
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
int addrVisit;
#endif
};
struct WhereLoop {
Bitmask prereq;
Bitmask maskSelf;
#ifdef SQLITE_DEBUG
char cId;
#endif
u8 iTab;
u8 iSortIdx;
LogEst rSetup;
LogEst rRun;
LogEst nOut;
union {
struct {
u16 nEq;
u16 nBtm;
u16 nTop;
u16 nDistinctCol;
Index *pIndex;
} btree;
struct {
int idxNum;
u32 needFree : 1;
u32 bOmitOffset : 1;
i8 isOrdered;
u16 omitMask;
char *idxStr;
u32 mHandleIn;
} vtab;
} u;
u32 wsFlags;
u16 nLTerm;
u16 nSkip;
# define WHERE_LOOP_XFER_SZ offsetof(WhereLoop,nLSlot)
u16 nLSlot;
WhereTerm **aLTerm;
WhereLoop *pNextLoop;
WhereTerm *aLTermSpace[3];
};
struct WhereOrCost {
Bitmask prereq;
LogEst rRun;
LogEst nOut;
};
#define N_OR_COST 3
struct WhereOrSet {
u16 n;
WhereOrCost a[N_OR_COST];
};
struct WherePath {
Bitmask maskLoop;
Bitmask revLoop;
LogEst nRow;
LogEst rCost;
LogEst rUnsorted;
i8 isOrdered;
WhereLoop **aLoop;
};
struct WhereTerm {
Expr *pExpr;
WhereClause *pWC;
LogEst truthProb;
u16 wtFlags;
u16 eOperator;
u8 nChild;
u8 eMatchOp;
int iParent;
int leftCursor;
union {
struct {
int leftColumn;
int iField;
} x;
WhereOrInfo *pOrInfo;
WhereAndInfo *pAndInfo;
} u;
Bitmask prereqRight;
Bitmask prereqAll;
};
#define TERM_DYNAMIC 0x0001
#define TERM_VIRTUAL 0x0002
#define TERM_CODED 0x0004
#define TERM_COPIED 0x0008
#define TERM_ORINFO 0x0010
#define TERM_ANDINFO 0x0020
#define TERM_OK 0x0040
#define TERM_VNULL 0x0080
#define TERM_LIKEOPT 0x0100
#define TERM_LIKECOND 0x0200
#define TERM_LIKE 0x0400
#define TERM_IS 0x0800
#define TERM_VARSELECT 0x1000
#define TERM_HEURTRUTH 0x2000
#ifdef SQLITE_ENABLE_STAT4
# define TERM_HIGHTRUTH 0x4000
#else
# define TERM_HIGHTRUTH 0
#endif
#define TERM_SLICE 0x8000
struct WhereScan {
WhereClause *pOrigWC;
WhereClause *pWC;
const char *zCollName;
Expr *pIdxExpr;
int k;
u32 opMask;
char idxaff;
unsigned char iEquiv;
unsigned char nEquiv;
int aiCur[11];
i16 aiColumn[11];
};
struct WhereClause {
WhereInfo *pWInfo;
WhereClause *pOuter;
u8 op;
u8 hasOr;
int nTerm;
int nSlot;
int nBase;
WhereTerm *a;
#if defined(SQLITE_SMALL_STACK)
WhereTerm aStatic[1];
#else
WhereTerm aStatic[8];
#endif
};
struct WhereOrInfo {
WhereClause wc;
Bitmask indexable;
};
struct WhereAndInfo {
WhereClause wc;
};
struct WhereMaskSet {
int bVarSelect;
int n;
int ix[BMS];
};
struct WhereLoopBuilder {
WhereInfo *pWInfo;
WhereClause *pWC;
WhereLoop *pNew;
WhereOrSet *pOrSet;
#ifdef SQLITE_ENABLE_STAT4
UnpackedRecord *pRec;
int nRecValid;
#endif
unsigned char bldFlags1;
unsigned char bldFlags2;
unsigned int iPlanLimit;
};
#define SQLITE_BLDF1_INDEXED 0x0001
#define SQLITE_BLDF1_UNIQUE 0x0002
#define SQLITE_BLDF2_2NDPASS 0x0004
#ifndef SQLITE_QUERY_PLANNER_LIMIT
# define SQLITE_QUERY_PLANNER_LIMIT 20000
#endif
#ifndef SQLITE_QUERY_PLANNER_LIMIT_INCR
# define SQLITE_QUERY_PLANNER_LIMIT_INCR 1000
#endif
struct WhereInfo {
Parse *pParse;
SrcList *pTabList;
ExprList *pOrderBy;
ExprList *pResultSet;
#if WHERETRACE_ENABLED
Expr *pWhere;
#endif
Select *pSelect;
int aiCurOnePass[2];
int iContinue;
int iBreak;
int savedNQueryLoop;
u16 wctrlFlags;
LogEst iLimit;
u8 nLevel;
i8 nOBSat;
u8 eOnePass;
u8 eDistinct;
unsigned bDeferredSeek :1;
unsigned untestedTerms :1;
unsigned bOrderedInnerLoop:1;
unsigned sorted :1;
LogEst nRowOut;
int iTop;
int iEndWhere;
WhereLoop *pLoops;
WhereMemBlock *pMemToFree;
Bitmask revMask;
WhereClause sWC;
WhereMaskSet sMaskSet;
WhereLevel a[1];
};
Bitmask sqlite3WhereGetMask(WhereMaskSet*,int);
#ifdef WHERETRACE_ENABLED
void sqlite3WhereClausePrint(WhereClause *pWC);
void sqlite3WhereTermPrint(WhereTerm *pTerm, int iTerm);
void sqlite3WhereLoopPrint(WhereLoop *p, WhereClause *pWC);
#endif
WhereTerm *sqlite3WhereFindTerm(
WhereClause *pWC,
int iCur,
int iColumn,
Bitmask notReady,
u32 op,
Index *pIdx
);
void *sqlite3WhereMalloc(WhereInfo *pWInfo, u64 nByte);
void *sqlite3WhereRealloc(WhereInfo *pWInfo, void *pOld, u64 nByte);
#ifndef SQLITE_OMIT_EXPLAIN
int sqlite3WhereExplainOneScan(
Parse *pParse,
SrcList *pTabList,
WhereLevel *pLevel,
u16 wctrlFlags
);
int sqlite3WhereExplainBloomFilter(
const Parse *pParse,
const WhereInfo *pWInfo,
const WhereLevel *pLevel
);
#else
# define sqlite3WhereExplainOneScan(u,v,w,x) 0
# define sqlite3WhereExplainBloomFilter(u,v,w) 0
#endif
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
void sqlite3WhereAddScanStatus(
Vdbe *v,
SrcList *pSrclist,
WhereLevel *pLvl,
int addrExplain
);
#else
# define sqlite3WhereAddScanStatus(a, b, c, d) ((void)d)
#endif
Bitmask sqlite3WhereCodeOneLoopStart(
Parse *pParse,
Vdbe *v,
WhereInfo *pWInfo,
int iLevel,
WhereLevel *pLevel,
Bitmask notReady
);
SQLITE_NOINLINE void sqlite3WhereRightJoinLoop(
WhereInfo *pWInfo,
int iLevel,
WhereLevel *pLevel
);
void sqlite3WhereClauseInit(WhereClause*,WhereInfo*);
void sqlite3WhereClauseClear(WhereClause*);
void sqlite3WhereSplit(WhereClause*,Expr*,u8);
void sqlite3WhereAddLimit(WhereClause*, Select*);
Bitmask sqlite3WhereExprUsage(WhereMaskSet*, Expr*);
Bitmask sqlite3WhereExprUsageNN(WhereMaskSet*, Expr*);
Bitmask sqlite3WhereExprListUsage(WhereMaskSet*, ExprList*);
void sqlite3WhereExprAnalyze(SrcList*, WhereClause*);
void sqlite3WhereTabFuncArgs(Parse*, SrcItem*, WhereClause*);
#define WO_IN 0x0001
#define WO_EQ 0x0002
#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_AUX 0x0040
#define WO_IS 0x0080
#define WO_ISNULL 0x0100
#define WO_OR 0x0200
#define WO_AND 0x0400
#define WO_EQUIV 0x0800
#define WO_NOOP 0x1000
#define WO_ROWVAL 0x2000
#define WO_ALL 0x3fff
#define WO_SINGLE 0x01ff
#define WHERE_COLUMN_EQ 0x00000001
#define WHERE_COLUMN_RANGE 0x00000002
#define WHERE_COLUMN_IN 0x00000004
#define WHERE_COLUMN_NULL 0x00000008
#define WHERE_CONSTRAINT 0x0000000f
#define WHERE_TOP_LIMIT 0x00000010
#define WHERE_BTM_LIMIT 0x00000020
#define WHERE_BOTH_LIMIT 0x00000030
#define WHERE_IDX_ONLY 0x00000040
#define WHERE_IPK 0x00000100
#define WHERE_INDEXED 0x00000200
#define WHERE_VIRTUALTABLE 0x00000400
#define WHERE_IN_ABLE 0x00000800
#define WHERE_ONEROW 0x00001000
#define WHERE_MULTI_OR 0x00002000
#define WHERE_AUTO_INDEX 0x00004000
#define WHERE_SKIPSCAN 0x00008000
#define WHERE_UNQ_WANTED 0x00010000
#define WHERE_PARTIALIDX 0x00020000
#define WHERE_IN_EARLYOUT 0x00040000
#define WHERE_BIGNULL_SORT 0x00080000
#define WHERE_IN_SEEKSCAN 0x00100000
#define WHERE_TRANSCONS 0x00200000
#define WHERE_BLOOMFILTER 0x00400000
#define WHERE_SELFCULL 0x00800000
#define WHERE_OMIT_OFFSET 0x01000000
#define WHERE_VIEWSCAN 0x02000000
#define WHERE_EXPRIDX 0x04000000
#endif