mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
If a query uses an index where one or more of the columns of the index is
an expression and if the corresponding expression is used elsewhere in the query, then strive to read the value of the expression out of the index, rather than recomputing it. This is the "Indexed Expression Optimizations". FossilOrigin-Name: 3da1032878bdc93f69b02926fb7243b31fe6b1a0ee93af68df52b203b0603dad
This commit is contained in:
@@ -1078,6 +1078,7 @@ typedef struct FuncDef FuncDef;
|
||||
typedef struct FuncDefHash FuncDefHash;
|
||||
typedef struct IdList IdList;
|
||||
typedef struct Index Index;
|
||||
typedef struct IndexedExpr IndexedExpr;
|
||||
typedef struct IndexSample IndexSample;
|
||||
typedef struct KeyClass KeyClass;
|
||||
typedef struct KeyInfo KeyInfo;
|
||||
@@ -2255,6 +2256,8 @@ struct Index {
|
||||
unsigned noSkipScan:1; /* Do not try to use skip-scan if true */
|
||||
unsigned hasStat1:1; /* aiRowLogEst values come from sqlite_stat1 */
|
||||
unsigned bNoQuery:1; /* Do not use this index to optimize queries */
|
||||
unsigned bHasExpr:1; /* Index contains an expression, either a literal
|
||||
** expression, or a reference to a VIRTUAL column */
|
||||
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
|
||||
int nSample; /* Number of elements in aSample[] */
|
||||
int nSampleCol; /* Size of IndexSample.anEq[] and so on */
|
||||
@@ -3048,6 +3051,28 @@ struct TriggerPrg {
|
||||
# define DbMaskNonZero(M) (M)!=0
|
||||
#endif
|
||||
|
||||
/*
|
||||
** For each index X that has as one of its arguments either an expression
|
||||
** or the name of a virtual generated column, and if X is in scope such that
|
||||
** the value of the expression can simply be read from the index, then
|
||||
** there is an instance of this object on the Parse.pIdxExpr list.
|
||||
**
|
||||
** During code generation, while generating code to evaluate expressions,
|
||||
** this list is consulted and if a matching expression is found, the value
|
||||
** is read from the index rather than being recomputed.
|
||||
*/
|
||||
struct IndexedExpr {
|
||||
Expr *pExpr; /* The expression contained in the index */
|
||||
int iDataCur; /* The data cursor associated with the index */
|
||||
int iIdxCur; /* The index cursor */
|
||||
int iIdxCol; /* The index column that contains value of pExpr */
|
||||
u8 bMaybeNullRow; /* True if we need an OP_IfNullRow check */
|
||||
IndexedExpr *pIENext; /* Next in a list of all indexed expressions */
|
||||
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
|
||||
const char *zIdxName; /* Name of index, used only for bytecode comments */
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
** An SQL parser context. A copy of this structure is passed through
|
||||
** the parser and down into all the parser action routine in order to
|
||||
@@ -3091,6 +3116,7 @@ struct Parse {
|
||||
int nLabelAlloc; /* Number of slots in aLabel */
|
||||
int *aLabel; /* Space to hold the labels */
|
||||
ExprList *pConstExpr;/* Constant expressions */
|
||||
IndexedExpr *pIdxExpr;/* List of expressions used by active indexes */
|
||||
Token constraintName;/* Name of the constraint currently being parsed */
|
||||
yDbMask writeMask; /* Start a write transaction on these databases */
|
||||
yDbMask cookieMask; /* Bitmask of schema verified databases */
|
||||
|
Reference in New Issue
Block a user