📄 sqliteint.h
字号:
** Additional columns are used only as parameters to ** aggregate functions */ struct AggInfo_func { /* For each aggregate function */ Expr *pExpr; /* Expression encoding the function */ FuncDef *pFunc; /* The aggregate function implementation */ int iMem; /* Memory location that acts as accumulator */ int iDistinct; /* Ephermeral table used to enforce DISTINCT */ } *aFunc; int nFunc; /* Number of entries in aFunc[] */ int nFuncAlloc; /* Number of slots allocated for aFunc[] */};/*** Each node of an expression in the parse tree is an instance** of this structure.**** Expr.op is the opcode. The integer parser token codes are reused** as opcodes here. For example, the parser defines TK_GE to be an integer** code representing the ">=" operator. This same integer code is reused** to represent the greater-than-or-equal-to operator in the expression** tree.**** Expr.pRight and Expr.pLeft are subexpressions. Expr.pList is a list** of argument if the expression is a function.**** Expr.token is the operator token for this node. For some expressions** that have subexpressions, Expr.token can be the complete text that gave** rise to the Expr. In the latter case, the token is marked as being** a compound token.**** An expression of the form ID or ID.ID refers to a column in a table.** For such expressions, Expr.op is set to TK_COLUMN and Expr.iTable is** the integer cursor number of a VDBE cursor pointing to that table and** Expr.iColumn is the column number for the specific column. If the** expression is used as a result in an aggregate SELECT, then the** value is also stored in the Expr.iAgg column in the aggregate so that** it can be accessed after all aggregates are computed.**** If the expression is a function, the Expr.iTable is an integer code** representing which function. If the expression is an unbound variable** marker (a question mark character '?' in the original SQL) then the** Expr.iTable holds the index number for that variable.**** If the expression is a subquery then Expr.iColumn holds an integer** register number containing the result of the subquery. If the** subquery gives a constant result, then iTable is -1. If the subquery** gives a different answer at different times during statement processing** then iTable is the address of a subroutine that computes the subquery.**** The Expr.pSelect field points to a SELECT statement. The SELECT might** be the right operand of an IN operator. Or, if a scalar SELECT appears** in an expression the opcode is TK_SELECT and Expr.pSelect is the only** operand.**** If the Expr is of type OP_Column, and the table it is selecting from** is a disk table or the "old.*" pseudo-table, then pTab points to the** corresponding table definition.*/struct Expr { u8 op; /* Operation performed by this node */ char affinity; /* The affinity of the column or 0 if not a column */ u16 flags; /* Various flags. See below */ CollSeq *pColl; /* The collation type of the column or 0 */ Expr *pLeft, *pRight; /* Left and right subnodes */ ExprList *pList; /* A list of expressions used as function arguments ** or in "<expr> IN (<expr-list)" */ Token token; /* An operand token */ Token span; /* Complete text of the expression */ int iTable, iColumn; /* When op==TK_COLUMN, then this expr node means the ** iColumn-th field of the iTable-th table. */ AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ int iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ int iRightJoinTable; /* If EP_FromJoin, the right table of the join */ Select *pSelect; /* When the expression is a sub-select. Also the ** right side of "<expr> IN (<select>)" */ Table *pTab; /* Table for TK_COLUMN expressions. */#if SQLITE_MAX_EXPR_DEPTH>0 int nHeight; /* Height of the tree headed by this node */#endif};/*** The following are the meanings of bits in the Expr.flags field.*/#define EP_FromJoin 0x0001 /* Originated in ON or USING clause of a join */#define EP_Agg 0x0002 /* Contains one or more aggregate functions */#define EP_Resolved 0x0004 /* IDs have been resolved to COLUMNs */#define EP_Error 0x0008 /* Expression contains one or more errors */#define EP_Distinct 0x0010 /* Aggregate function with DISTINCT keyword */#define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */#define EP_Dequoted 0x0040 /* True if the string has been dequoted */#define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */#define EP_ExpCollate 0x0100 /* Collating sequence specified explicitly */#define EP_AnyAff 0x0200 /* Can take a cached column of any affinity */#define EP_FixedDest 0x0400 /* Result needed in a specific register */#define EP_IntValue 0x0800 /* Integer value contained in iTable *//*** These macros can be used to test, set, or clear bits in the ** Expr.flags field.*/#define ExprHasProperty(E,P) (((E)->flags&(P))==(P))#define ExprHasAnyProperty(E,P) (((E)->flags&(P))!=0)#define ExprSetProperty(E,P) (E)->flags|=(P)#define ExprClearProperty(E,P) (E)->flags&=~(P)/*** A list of expressions. Each expression may optionally have a** name. An expr/name combination can be used in several ways, such** as the list of "expr AS ID" fields following a "SELECT" or in the** list of "ID = expr" items in an UPDATE. A list of expressions can** also be used as the argument to a function, in which case the a.zName** field is not used.*/struct ExprList { int nExpr; /* Number of expressions on the list */ int nAlloc; /* Number of entries allocated below */ int iECursor; /* VDBE Cursor associated with this ExprList */ struct ExprList_item { Expr *pExpr; /* The list of expressions */ char *zName; /* Token associated with this expression */ u8 sortOrder; /* 1 for DESC or 0 for ASC */ u8 done; /* A flag to indicate when processing is finished */ u16 iCol; /* For ORDER BY, column number in result set */ u16 iAlias; /* Index into Parse.aAlias[] for zName */ } *a; /* One entry for each expression */};/*** An instance of this structure can hold a simple list of identifiers,** such as the list "a,b,c" in the following statements:**** INSERT INTO t(a,b,c) VALUES ...;** CREATE INDEX idx ON t(a,b,c);** CREATE TRIGGER trig BEFORE UPDATE ON t(a,b,c) ...;**** The IdList.a.idx field is used when the IdList represents the list of** column names after a table name in an INSERT statement. In the statement**** INSERT INTO t(a,b,c) ...**** If "a" is the k-th column of table "t", then IdList.a[0].idx==k.*/struct IdList { struct IdList_item { char *zName; /* Name of the identifier */ int idx; /* Index in some Table.aCol[] of a column named zName */ } *a; int nId; /* Number of identifiers on the list */ int nAlloc; /* Number of entries allocated for a[] below */};/*** The bitmask datatype defined below is used for various optimizations.**** Changing this from a 64-bit to a 32-bit type limits the number of** tables in a join to 32 instead of 64. But it also reduces the size** of the library by 738 bytes on ix86.*/typedef u64 Bitmask;/*** The following structure describes the FROM clause of a SELECT statement.** Each table or subquery in the FROM clause is a separate element of** the SrcList.a[] array.**** With the addition of multiple database support, the following structure** can also be used to describe a particular table such as the table that** is modified by an INSERT, DELETE, or UPDATE statement. In standard SQL,** such a table must be a simple name: ID. But in SQLite, the table can** now be identified by a database name, a dot, then the table name: ID.ID.**** The jointype starts out showing the join type between the current table** and the next table on the list. The parser builds the list this way.** But sqlite3SrcListShiftJoinType() later shifts the jointypes so that each** jointype expresses the join between the table and the previous table.*/struct SrcList { i16 nSrc; /* Number of tables or subqueries in the FROM clause */ i16 nAlloc; /* Number of entries allocated in a[] below */ struct SrcList_item { char *zDatabase; /* Name of database holding this table */ char *zName; /* Name of the table */ char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */ Table *pTab; /* An SQL table corresponding to zName */ Select *pSelect; /* A SELECT statement used in place of a table name */ u8 isPopulated; /* Temporary table associated with SELECT is populated */ u8 jointype; /* Type of join between this able and the previous */ int iCursor; /* The VDBE cursor number used to access this table */ Expr *pOn; /* The ON clause of a join */ IdList *pUsing; /* The USING clause of a join */ Bitmask colUsed; /* Bit N (1<<N) set if column N or pTab is used */ } a[1]; /* One entry for each identifier on the list */};/*** Permitted values of the SrcList.a.jointype field*/#define JT_INNER 0x0001 /* Any kind of inner or cross join */#define JT_CROSS 0x0002 /* Explicit use of the CROSS keyword */#define JT_NATURAL 0x0004 /* True for a "natural" join */#define JT_LEFT 0x0008 /* Left outer join */#define JT_RIGHT 0x0010 /* Right outer join */#define JT_OUTER 0x0020 /* The "OUTER" keyword is present */#define JT_ERROR 0x0040 /* unknown or unsupported join type *//*** For each nested loop in a WHERE clause implementation, the WhereInfo** structure contains a single instance of this structure. This structure** is intended to be private the the where.c module and should not be** access or modified by other modules.**** The pIdxInfo and pBestIdx fields are used to help pick the best** index on a virtual table. The pIdxInfo pointer contains indexing** information for the i-th table in the FROM clause before reordering.** All the pIdxInfo pointers are freed by whereInfoFree() in where.c.** The pBestIdx pointer is a copy of pIdxInfo for the i-th table after** FROM clause ordering. This is a little confusing so I will repeat** it in different words. WhereInfo.a[i].pIdxInfo is index information ** for WhereInfo.pTabList.a[i]. WhereInfo.a[i].pBestInfo is the** index information for the i-th loop of the join. pBestInfo is always** either NULL or a copy of some pIdxInfo. So for cleanup it is ** sufficient to free all of the pIdxInfo pointers.** */struct WhereLevel { int iFrom; /* Which entry in the FROM clause */ int flags; /* Flags associated with this level */ int iMem; /* First memory cell used by this level */ int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */ Index *pIdx; /* Index used. NULL if no index */ int iTabCur; /* The VDBE cursor used to access the table */ int iIdxCur; /* The VDBE cursor used to acesss pIdx */ int brk; /* Jump here to break out of the loop */ int nxt; /* Jump here to start the next IN combination */ int cont; /* Jump here to continue with the next loop cycle */ int top; /* First instruction of interior of the loop */ int op, p1, p2; /* Opcode used to terminate the loop */ int nEq; /* Number of == or IN constraints on this loop */ int nIn; /* Number of IN operators constraining this loop */ struct InLoop { int iCur; /* The VDBE cursor used by this IN operator */ int topAddr; /* Top of the IN loop */ } *aInLoop; /* Information about each nested IN operator */ sqlite3_index_info *pBestIdx; /* Index information for this level */ /* The following field is really not part of the current level. But ** we need a place to cache index information for each table in the ** FROM clause and the WhereLevel structure is a convenient place. */ sqlite3_index_info *pIdxInfo; /* Index info for n-th source table */};/*** Flags appropriate for the wflags parameter of sqlite3WhereBegin().*/#define WHERE_ORDERBY_NORMAL 0 /* No-op */#define WHERE_ORDERBY_MIN 1 /* ORDER BY processing for min() func */#define WHERE_ORDERBY_MAX 2 /* ORDER BY processing for max() func */#define WHERE_ONEPASS_DESIRED 4 /* Want to do one-pass UPDATE/DELETE *//*** The WHERE clause processing routine has two halves. The** first part does the start of the WHERE loop and the second** half does the tail of the WHERE loop. An instance of** this structure is returned by the first half and passed** into the second half to give some continuity.*/struct WhereInfo { Parse *pParse; /* Parsing and code generating context */ u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE or DELETE */ SrcList *pTabList; /* List of tables in the join */ int iTop; /* The very beginning of the WHERE loop */ int iContinue; /* Jump here to continue with next record */ int iBreak; /* Jump here to break out of the loop */ int nLevel; /* Number of nested loop */ sqlite3_index_info **apInfo; /* Array of pointers to index info structures */ WhereLevel a[1]; /* Information about each nest loop in the WHERE */};/*** A NameContext defines a context in which to resolve table and column** names. The context consists of a list of tables (the pSrcList) field and** a list of named expression (pEList). The named expression list may** be NULL. The pSrc corresponds to the FROM clause of a SELECT or** to the table being operated on by INSERT, UPDATE, or DELETE. The** pEList corresponds to the result set of a SELECT and is NULL for** other statements.**** NameContexts can be nested. When resolving names, the inner-most ** context is searched first. If no match is found, the next outer** context is checked. If there is still no match, the next context** is checked. This process continues until either a match is found** or all contexts are check. When a match is found, the nRef member of** the context containing the match is incremented. **** Each subquery gets a new NameContext. The pNext field points to the** NameContext in the parent query. Thus the process of scanning the** NameContext list corresponds to searching through successively outer** subqueries looking for a match.*/struct NameContext { Parse *pParse; /* The parser */ SrcList *pSrcList; /* One or more tables used to resolve names */ ExprList *pEList; /* Optional list of named expressions */ int nRef; /* Number of names resolved by this context */ int nErr; /* Number of errors encou
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -