Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: third_party/sqlite/src/src/whereInt.h

Issue 2751253002: [sql] Import SQLite 3.17.0. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 ** 2013-11-12 2 ** 2013-11-12
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */ 63 int iLeftJoin; /* Memory cell used to implement LEFT OUTER JOIN */
64 int iTabCur; /* The VDBE cursor used to access the table */ 64 int iTabCur; /* The VDBE cursor used to access the table */
65 int iIdxCur; /* The VDBE cursor used to access pIdx */ 65 int iIdxCur; /* The VDBE cursor used to access pIdx */
66 int addrBrk; /* Jump here to break out of the loop */ 66 int addrBrk; /* Jump here to break out of the loop */
67 int addrNxt; /* Jump here to start the next IN combination */ 67 int addrNxt; /* Jump here to start the next IN combination */
68 int addrSkip; /* Jump here for next iteration of skip-scan */ 68 int addrSkip; /* Jump here for next iteration of skip-scan */
69 int addrCont; /* Jump here to continue with the next loop cycle */ 69 int addrCont; /* Jump here to continue with the next loop cycle */
70 int addrFirst; /* First instruction of interior of the loop */ 70 int addrFirst; /* First instruction of interior of the loop */
71 int addrBody; /* Beginning of the body of this loop */ 71 int addrBody; /* Beginning of the body of this loop */
72 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS 72 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
73 int iLikeRepCntr; /* LIKE range processing counter register */ 73 u32 iLikeRepCntr; /* LIKE range processing counter register (times 2) */
74 int addrLikeRep; /* LIKE range processing address */ 74 int addrLikeRep; /* LIKE range processing address */
75 #endif 75 #endif
76 u8 iFrom; /* Which entry in the FROM clause */ 76 u8 iFrom; /* Which entry in the FROM clause */
77 u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */ 77 u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
78 int p1, p2; /* Operands of the opcode used to ends the loop */ 78 int p1, p2; /* Operands of the opcode used to ends the loop */
79 union { /* Information that depends on pWLoop->wsFlags */ 79 union { /* Information that depends on pWLoop->wsFlags */
80 struct { 80 struct {
81 int nIn; /* Number of entries in aInLoop[] */ 81 int nIn; /* Number of entries in aInLoop[] */
82 struct InLoop { 82 struct InLoop {
83 int iCur; /* The VDBE cursor used by this IN operator */ 83 int iCur; /* The VDBE cursor used by this IN operator */
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 char cId; /* Symbolic ID of this loop for debugging use */ 115 char cId; /* Symbolic ID of this loop for debugging use */
116 #endif 116 #endif
117 u8 iTab; /* Position in FROM clause of table for this loop */ 117 u8 iTab; /* Position in FROM clause of table for this loop */
118 u8 iSortIdx; /* Sorting index number. 0==None */ 118 u8 iSortIdx; /* Sorting index number. 0==None */
119 LogEst rSetup; /* One-time setup cost (ex: create transient index) */ 119 LogEst rSetup; /* One-time setup cost (ex: create transient index) */
120 LogEst rRun; /* Cost of running each loop */ 120 LogEst rRun; /* Cost of running each loop */
121 LogEst nOut; /* Estimated number of output rows */ 121 LogEst nOut; /* Estimated number of output rows */
122 union { 122 union {
123 struct { /* Information for internal btree tables */ 123 struct { /* Information for internal btree tables */
124 u16 nEq; /* Number of equality constraints */ 124 u16 nEq; /* Number of equality constraints */
125 u16 nBtm; /* Size of BTM vector */
126 u16 nTop; /* Size of TOP vector */
125 Index *pIndex; /* Index used, or NULL */ 127 Index *pIndex; /* Index used, or NULL */
126 } btree; 128 } btree;
127 struct { /* Information for virtual tables */ 129 struct { /* Information for virtual tables */
128 int idxNum; /* Index number */ 130 int idxNum; /* Index number */
129 u8 needFree; /* True if sqlite3_free(idxStr) is needed */ 131 u8 needFree; /* True if sqlite3_free(idxStr) is needed */
130 i8 isOrdered; /* True if satisfies ORDER BY */ 132 i8 isOrdered; /* True if satisfies ORDER BY */
131 u16 omitMask; /* Terms that may be omitted */ 133 u16 omitMask; /* Terms that may be omitted */
132 char *idxStr; /* Index identifier string */ 134 char *idxStr; /* Index identifier string */
133 } vtab; 135 } vtab;
134 } u; 136 } u;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 ** beginning with 0 in order to make the best possible use of the available 239 ** beginning with 0 in order to make the best possible use of the available
238 ** bits in the Bitmask. So, in the example above, the cursor numbers 240 ** bits in the Bitmask. So, in the example above, the cursor numbers
239 ** would be mapped into integers 0 through 7. 241 ** would be mapped into integers 0 through 7.
240 ** 242 **
241 ** The number of terms in a join is limited by the number of bits 243 ** The number of terms in a join is limited by the number of bits
242 ** in prereqRight and prereqAll. The default is 64 bits, hence SQLite 244 ** in prereqRight and prereqAll. The default is 64 bits, hence SQLite
243 ** is only able to process joins with 64 or fewer tables. 245 ** is only able to process joins with 64 or fewer tables.
244 */ 246 */
245 struct WhereTerm { 247 struct WhereTerm {
246 Expr *pExpr; /* Pointer to the subexpression that is this term */ 248 Expr *pExpr; /* Pointer to the subexpression that is this term */
249 WhereClause *pWC; /* The clause this term is part of */
250 LogEst truthProb; /* Probability of truth for this expression */
251 u16 wtFlags; /* TERM_xxx bit flags. See below */
252 u16 eOperator; /* A WO_xx value describing <op> */
253 u8 nChild; /* Number of children that must disable us */
254 u8 eMatchOp; /* Op for vtab MATCH/LIKE/GLOB/REGEXP terms */
247 int iParent; /* Disable pWC->a[iParent] when this term disabled */ 255 int iParent; /* Disable pWC->a[iParent] when this term disabled */
248 int leftCursor; /* Cursor number of X in "X <op> <expr>" */ 256 int leftCursor; /* Cursor number of X in "X <op> <expr>" */
257 int iField; /* Field in (?,?,?) IN (SELECT...) vector */
249 union { 258 union {
250 int leftColumn; /* Column number of X in "X <op> <expr>" */ 259 int leftColumn; /* Column number of X in "X <op> <expr>" */
251 WhereOrInfo *pOrInfo; /* Extra information if (eOperator & WO_OR)!=0 */ 260 WhereOrInfo *pOrInfo; /* Extra information if (eOperator & WO_OR)!=0 */
252 WhereAndInfo *pAndInfo; /* Extra information if (eOperator& WO_AND)!=0 */ 261 WhereAndInfo *pAndInfo; /* Extra information if (eOperator& WO_AND)!=0 */
253 } u; 262 } u;
254 LogEst truthProb; /* Probability of truth for this expression */
255 u16 eOperator; /* A WO_xx value describing <op> */
256 u16 wtFlags; /* TERM_xxx bit flags. See below */
257 u8 nChild; /* Number of children that must disable us */
258 u8 eMatchOp; /* Op for vtab MATCH/LIKE/GLOB/REGEXP terms */
259 WhereClause *pWC; /* The clause this term is part of */
260 Bitmask prereqRight; /* Bitmask of tables used by pExpr->pRight */ 263 Bitmask prereqRight; /* Bitmask of tables used by pExpr->pRight */
261 Bitmask prereqAll; /* Bitmask of tables referenced by pExpr */ 264 Bitmask prereqAll; /* Bitmask of tables referenced by pExpr */
262 }; 265 };
263 266
264 /* 267 /*
265 ** Allowed values of WhereTerm.wtFlags 268 ** Allowed values of WhereTerm.wtFlags
266 */ 269 */
267 #define TERM_DYNAMIC 0x01 /* Need to call sqlite3ExprDelete(db, pExpr) */ 270 #define TERM_DYNAMIC 0x01 /* Need to call sqlite3ExprDelete(db, pExpr) */
268 #define TERM_VIRTUAL 0x02 /* Added by the optimizer. Do not code */ 271 #define TERM_VIRTUAL 0x02 /* Added by the optimizer. Do not code */
269 #define TERM_CODED 0x04 /* This term is already coded */ 272 #define TERM_CODED 0x04 /* This term is already coded */
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 ** this structure is returned by the first half and passed 404 ** this structure is returned by the first half and passed
402 ** into the second half to give some continuity. 405 ** into the second half to give some continuity.
403 ** 406 **
404 ** An instance of this object holds the complete state of the query 407 ** An instance of this object holds the complete state of the query
405 ** planner. 408 ** planner.
406 */ 409 */
407 struct WhereInfo { 410 struct WhereInfo {
408 Parse *pParse; /* Parsing and code generating context */ 411 Parse *pParse; /* Parsing and code generating context */
409 SrcList *pTabList; /* List of tables in the join */ 412 SrcList *pTabList; /* List of tables in the join */
410 ExprList *pOrderBy; /* The ORDER BY clause or NULL */ 413 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
411 ExprList *pResultSet; /* Result set. DISTINCT operates on these */ 414 ExprList *pDistinctSet; /* DISTINCT over all these values */
412 WhereLoop *pLoops; /* List of all WhereLoop objects */ 415 LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
413 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */ 416 int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
414 LogEst nRowOut; /* Estimated number of output rows */ 417 int iContinue; /* Jump here to continue with next record */
418 int iBreak; /* Jump here to break out of the loop */
419 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
415 u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */ 420 u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
421 u8 nLevel; /* Number of nested loop */
416 i8 nOBSat; /* Number of ORDER BY terms satisfied by indices */ 422 i8 nOBSat; /* Number of ORDER BY terms satisfied by indices */
417 u8 sorted; /* True if really sorted (not just grouped) */ 423 u8 sorted; /* True if really sorted (not just grouped) */
418 u8 eOnePass; /* ONEPASS_OFF, or _SINGLE, or _MULTI */ 424 u8 eOnePass; /* ONEPASS_OFF, or _SINGLE, or _MULTI */
419 u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */ 425 u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */
420 u8 eDistinct; /* One of the WHERE_DISTINCT_* values below */ 426 u8 eDistinct; /* One of the WHERE_DISTINCT_* values */
421 u8 nLevel; /* Number of nested loop */ 427 u8 bOrderedInnerLoop; /* True if only the inner-most loop is ordered */
422 int iTop; /* The very beginning of the WHERE loop */ 428 int iTop; /* The very beginning of the WHERE loop */
423 int iContinue; /* Jump here to continue with next record */ 429 WhereLoop *pLoops; /* List of all WhereLoop objects */
424 int iBreak; /* Jump here to break out of the loop */ 430 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
425 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */ 431 LogEst nRowOut; /* Estimated number of output rows */
426 int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */ 432 WhereClause sWC; /* Decomposition of the WHERE clause */
427 WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */ 433 WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */
428 WhereClause sWC; /* Decomposition of the WHERE clause */
429 WhereLevel a[1]; /* Information about each nest loop in WHERE */ 434 WhereLevel a[1]; /* Information about each nest loop in WHERE */
430 }; 435 };
431 436
432 /* 437 /*
433 ** Private interfaces - callable only by other where.c routines. 438 ** Private interfaces - callable only by other where.c routines.
434 ** 439 **
435 ** where.c: 440 ** where.c:
436 */ 441 */
437 Bitmask sqlite3WhereGetMask(WhereMaskSet*,int); 442 Bitmask sqlite3WhereGetMask(WhereMaskSet*,int);
443 #ifdef WHERETRACE_ENABLED
444 void sqlite3WhereClausePrint(WhereClause *pWC);
445 #endif
438 WhereTerm *sqlite3WhereFindTerm( 446 WhereTerm *sqlite3WhereFindTerm(
439 WhereClause *pWC, /* The WHERE clause to be searched */ 447 WhereClause *pWC, /* The WHERE clause to be searched */
440 int iCur, /* Cursor number of LHS */ 448 int iCur, /* Cursor number of LHS */
441 int iColumn, /* Column number of LHS */ 449 int iColumn, /* Column number of LHS */
442 Bitmask notReady, /* RHS must not overlap with this mask */ 450 Bitmask notReady, /* RHS must not overlap with this mask */
443 u32 op, /* Mask of WO_xx values describing operator */ 451 u32 op, /* Mask of WO_xx values describing operator */
444 Index *pIdx /* Must be compatible with this index, if not NULL */ 452 Index *pIdx /* Must be compatible with this index, if not NULL */
445 ); 453 );
446 454
447 /* wherecode.c: */ 455 /* wherecode.c: */
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 492
485 493
486 494
487 495
488 496
489 /* 497 /*
490 ** Bitmasks for the operators on WhereTerm objects. These are all 498 ** Bitmasks for the operators on WhereTerm objects. These are all
491 ** operators that are of interest to the query planner. An 499 ** operators that are of interest to the query planner. An
492 ** OR-ed combination of these values can be used when searching for 500 ** OR-ed combination of these values can be used when searching for
493 ** particular WhereTerms within a WhereClause. 501 ** particular WhereTerms within a WhereClause.
502 **
503 ** Value constraints:
504 ** WO_EQ == SQLITE_INDEX_CONSTRAINT_EQ
505 ** WO_LT == SQLITE_INDEX_CONSTRAINT_LT
506 ** WO_LE == SQLITE_INDEX_CONSTRAINT_LE
507 ** WO_GT == SQLITE_INDEX_CONSTRAINT_GT
508 ** WO_GE == SQLITE_INDEX_CONSTRAINT_GE
509 ** WO_MATCH == SQLITE_INDEX_CONSTRAINT_MATCH
494 */ 510 */
495 #define WO_IN 0x0001 511 #define WO_IN 0x0001
496 #define WO_EQ 0x0002 512 #define WO_EQ 0x0002
497 #define WO_LT (WO_EQ<<(TK_LT-TK_EQ)) 513 #define WO_LT (WO_EQ<<(TK_LT-TK_EQ))
498 #define WO_LE (WO_EQ<<(TK_LE-TK_EQ)) 514 #define WO_LE (WO_EQ<<(TK_LE-TK_EQ))
499 #define WO_GT (WO_EQ<<(TK_GT-TK_EQ)) 515 #define WO_GT (WO_EQ<<(TK_GT-TK_EQ))
500 #define WO_GE (WO_EQ<<(TK_GE-TK_EQ)) 516 #define WO_GE (WO_EQ<<(TK_GE-TK_EQ))
501 #define WO_MATCH 0x0040 517 #define WO_MATCH 0x0040
502 #define WO_IS 0x0080 518 #define WO_IS 0x0080
503 #define WO_ISNULL 0x0100 519 #define WO_ISNULL 0x0100
(...skipping 22 matching lines...) Expand all
526 #define WHERE_IPK 0x00000100 /* x is the INTEGER PRIMARY KEY */ 542 #define WHERE_IPK 0x00000100 /* x is the INTEGER PRIMARY KEY */
527 #define WHERE_INDEXED 0x00000200 /* WhereLoop.u.btree.pIndex is valid */ 543 #define WHERE_INDEXED 0x00000200 /* WhereLoop.u.btree.pIndex is valid */
528 #define WHERE_VIRTUALTABLE 0x00000400 /* WhereLoop.u.vtab is valid */ 544 #define WHERE_VIRTUALTABLE 0x00000400 /* WhereLoop.u.vtab is valid */
529 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */ 545 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
530 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */ 546 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
531 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */ 547 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
532 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */ 548 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
533 #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */ 549 #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
534 #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/ 550 #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
535 #define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */ 551 #define WHERE_PARTIALIDX 0x00020000 /* The automatic index is partial */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698