Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Simplify the where.c logic by flipping expression over so that the controlling variable is always on the left. (CVS 1838) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
ec8bfa3891dbf0f3172e31cf322974c0 |
User & Date: | drh 2004-07-20 18:23:15.000 |
Context
2004-07-21
| ||
02:53 | Minor coding enhancements. (CVS 1839) (check-in: 65c3af74c1 user: drh tags: trunk) | |
2004-07-20
| ||
18:23 | Simplify the where.c logic by flipping expression over so that the controlling variable is always on the left. (CVS 1838) (check-in: ec8bfa3891 user: drh tags: trunk) | |
14:06 | Lemon collapses common destructors and reduce actions into a single case. (CVS 1837) (check-in: 3c5aa850ee user: drh tags: trunk) | |
Changes
Changes to src/where.c.
︙ | ︙ | |||
8 9 10 11 12 13 14 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This module contains C code that generates VDBE code used to process ** the WHERE clause of SQL statements. ** | | | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This module contains C code that generates VDBE code used to process ** the WHERE clause of SQL statements. ** ** $Id: where.c,v 1.111 2004/07/20 18:23:15 drh Exp $ */ #include "sqliteInt.h" /* ** The query generator uses an array of instances of this structure to ** help it analyze the subexpressions of the WHERE clause. Each WHERE ** clause subexpression is separated from the others by an AND operator. |
︙ | ︙ | |||
156 157 158 159 160 161 162 163 164 165 166 167 168 169 | case TK_EQ: case TK_IN: return 1; default: return 0; } } /* ** The input to this routine is an ExprInfo structure with only the ** "p" field filled in. The job of this routine is to analyze the ** subexpression and populate all the other fields of the ExprInfo ** structure. */ | > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | case TK_EQ: case TK_IN: return 1; default: return 0; } } /* ** Swap two integers. */ #define SWAP(TYPE,A,B) {TYPE t=A; A=B; B=t;} /* ** Return the index in the SrcList that uses cursor iCur. If iCur is ** used by the first entry in SrcList return 0. If iCur is used by ** the second entry return 1. And so forth. ** ** SrcList is the set of tables in the FROM clause in the order that ** they will be processed. The value returned here gives us an index ** of which tables will be processed first. */ static int tableOrder(SrcList *pList, int iCur){ int i; for(i=0; i<pList->nSrc; i++){ if( pList->a[i].iCursor==iCur ) return i; } return -1; } /* ** The input to this routine is an ExprInfo structure with only the ** "p" field filled in. The job of this routine is to analyze the ** subexpression and populate all the other fields of the ExprInfo ** structure. */ static void exprAnalyze(SrcList *pSrc, ExprMaskSet *pMaskSet, ExprInfo *pInfo){ Expr *pExpr = pInfo->p; pInfo->prereqLeft = exprTableUsage(pMaskSet, pExpr->pLeft); pInfo->prereqRight = exprTableUsage(pMaskSet, pExpr->pRight); pInfo->prereqAll = exprTableUsage(pMaskSet, pExpr); pInfo->indexable = 0; pInfo->idxLeft = -1; pInfo->idxRight = -1; if( allowedOp(pExpr->op) && (pInfo->prereqRight & pInfo->prereqLeft)==0 ){ if( pExpr->pRight && pExpr->pRight->op==TK_COLUMN ){ pInfo->idxRight = pExpr->pRight->iTable; pInfo->indexable = 1; } if( pExpr->pLeft->op==TK_COLUMN ){ pInfo->idxLeft = pExpr->pLeft->iTable; pInfo->indexable = 1; } } if( pInfo->indexable ){ assert( pInfo->idxLeft!=pInfo->idxRight ); /* We want the expression to be of the form "X = expr", not "expr = X". ** So flip it over if necessary. If the expression is "X = Y", then ** we want Y to come from an earlier table than X. ** ** The collating sequence rule is to always choose the left expression. ** So if we do a flip, we also have to move the collating sequence. */ if( tableOrder(pSrc,pInfo->idxLeft)<tableOrder(pSrc,pInfo->idxRight) ){ assert( pExpr->op!=TK_IN ); SWAP(CollSeq*,pExpr->pRight->pColl,pExpr->pLeft->pColl); SWAP(Expr*,pExpr->pRight,pExpr->pLeft); switch( pExpr->op ){ case TK_LT: pExpr->op = TK_GT; break; case TK_LE: pExpr->op = TK_GE; break; case TK_GT: pExpr->op = TK_LT; break; case TK_GE: pExpr->op = TK_LE; break; default: break; } SWAP(unsigned, pInfo->prereqLeft, pInfo->prereqRight); SWAP(short int, pInfo->idxLeft, pInfo->idxRight); } } } /* ** pOrderBy is an ORDER BY clause from a SELECT statement. pTab is the ** left-most table in the FROM clause of that same SELECT statement and ** the table has a cursor number of "base". ** |
︙ | ︙ | |||
396 397 398 399 400 401 402 403 404 405 406 | int i; /* Loop counter */ WhereInfo *pWInfo; /* Will become the return value of this function */ Vdbe *v = pParse->pVdbe; /* The virtual database engine */ int brk, cont = 0; /* Addresses used during code generation */ int nExpr; /* Number of subexpressions in the WHERE clause */ int loopMask; /* One bit set for each outer loop */ int haveKey = 0; /* True if KEY is on the stack */ ExprMaskSet maskSet; /* The expression mask set */ int iDirectEq[32]; /* Term of the form ROWID==X for the N-th table */ int iDirectLt[32]; /* Term of the form ROWID<X or ROWID<=X */ int iDirectGt[32]; /* Term of the form ROWID>X or ROWID>=X */ | > | | 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | int i; /* Loop counter */ WhereInfo *pWInfo; /* Will become the return value of this function */ Vdbe *v = pParse->pVdbe; /* The virtual database engine */ int brk, cont = 0; /* Addresses used during code generation */ int nExpr; /* Number of subexpressions in the WHERE clause */ int loopMask; /* One bit set for each outer loop */ int haveKey = 0; /* True if KEY is on the stack */ ExprInfo *pTerm; /* A single term in the WHERE clause; ptr to aExpr[] */ ExprMaskSet maskSet; /* The expression mask set */ int iDirectEq[32]; /* Term of the form ROWID==X for the N-th table */ int iDirectLt[32]; /* Term of the form ROWID<X or ROWID<=X */ int iDirectGt[32]; /* Term of the form ROWID>X or ROWID>=X */ ExprInfo aExpr[101]; /* The WHERE clause is divided into these terms */ /* pushKey is only allowed if there is a single table (as in an INSERT or ** UPDATE statement) */ assert( pushKey==0 || pTabList->nSrc==1 ); /* Split the WHERE clause into separate subexpressions where each |
︙ | ︙ | |||
426 427 428 429 430 431 432 | } /* Allocate and initialize the WhereInfo structure that will become the ** return value. */ pWInfo = sqliteMalloc( sizeof(WhereInfo) + pTabList->nSrc*sizeof(WhereLevel)); if( sqlite3_malloc_failed ){ | | | > | | | | | | | | | | | 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | } /* Allocate and initialize the WhereInfo structure that will become the ** return value. */ pWInfo = sqliteMalloc( sizeof(WhereInfo) + pTabList->nSrc*sizeof(WhereLevel)); if( sqlite3_malloc_failed ){ /* sqliteFree(pWInfo); // Leak memory when malloc fails */ return 0; } pWInfo->pParse = pParse; pWInfo->pTabList = pTabList; pWInfo->peakNTab = pWInfo->savedNTab = pParse->nTab; pWInfo->iBreak = sqlite3VdbeMakeLabel(v); /* Special case: a WHERE clause that is constant. Evaluate the ** expression and either jump over all of the code or fall thru. */ if( pWhere && (pTabList->nSrc==0 || sqlite3ExprIsConstant(pWhere)) ){ sqlite3ExprIfFalse(pParse, pWhere, pWInfo->iBreak, 1); pWhere = 0; } /* Analyze all of the subexpressions. */ for(pTerm=aExpr, i=0; i<nExpr; i++, pTerm++){ TriggerStack *pStack; exprAnalyze(pTabList, &maskSet, pTerm); /* If we are executing a trigger body, remove all references to ** new.* and old.* tables from the prerequisite masks. */ if( (pStack = pParse->trigStack)!=0 ){ int x; if( (x=pStack->newIdx) >= 0 ){ int mask = ~getMask(&maskSet, x); pTerm->prereqRight &= mask; pTerm->prereqLeft &= mask; pTerm->prereqAll &= mask; } if( (x=pStack->oldIdx) >= 0 ){ int mask = ~getMask(&maskSet, x); pTerm->prereqRight &= mask; pTerm->prereqLeft &= mask; pTerm->prereqAll &= mask; } } } /* Figure out what index to use (if any) for each nested loop. ** Make pWInfo->a[i].pIdx point to the index to use for the i-th nested ** loop where i==0 is the outer loop and i==pTabList->nSrc-1 is the inner |
︙ | ︙ | |||
505 506 507 508 509 510 511 | ** ** (Added:) Treat ROWID IN expr like ROWID=expr. */ pWInfo->a[i].iCur = -1; iDirectEq[i] = -1; iDirectLt[i] = -1; iDirectGt[i] = -1; | | > | | | < < < < < < < < < < | 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | ** ** (Added:) Treat ROWID IN expr like ROWID=expr. */ pWInfo->a[i].iCur = -1; iDirectEq[i] = -1; iDirectLt[i] = -1; iDirectGt[i] = -1; for(pTerm=aExpr, j=0; j<nExpr; j++, pTerm++){ Expr *pX = pTerm->p; if( pTerm->idxLeft==iCur && pX->pLeft->iColumn<0 && (pTerm->prereqRight & loopMask)==pTerm->prereqRight ){ switch( pX->op ){ case TK_IN: case TK_EQ: iDirectEq[i] = j; break; case TK_LE: case TK_LT: iDirectLt[i] = j; break; case TK_GE: case TK_GT: iDirectGt[i] = j; break; } } } if( iDirectEq[i]>=0 ){ loopMask |= mask; pWInfo->a[i].pIdx = 0; continue; } |
︙ | ︙ | |||
567 568 569 570 571 572 573 | int eqMask = 0; /* Index columns covered by an x=... term */ int ltMask = 0; /* Index columns covered by an x<... term */ int gtMask = 0; /* Index columns covered by an x>... term */ int inMask = 0; /* Index columns covered by an x IN .. term */ int nEq, m, score; if( pIdx->nColumn>32 ) continue; /* Ignore indices too many columns */ | | | > | | | | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | int eqMask = 0; /* Index columns covered by an x=... term */ int ltMask = 0; /* Index columns covered by an x<... term */ int gtMask = 0; /* Index columns covered by an x>... term */ int inMask = 0; /* Index columns covered by an x IN .. term */ int nEq, m, score; if( pIdx->nColumn>32 ) continue; /* Ignore indices too many columns */ for(pTerm=aExpr, j=0; j<nExpr; j++, pTerm++){ CollSeq *pColl = sqlite3ExprCollSeq(pParse, pTerm->p->pLeft); Expr *pX = pTerm->p; if( !pColl && pX->pRight ){ pColl = sqlite3ExprCollSeq(pParse, pX->pRight); } if( !pColl ){ pColl = pParse->db->pDfltColl; } if( pTerm->idxLeft==iCur && (pTerm->prereqRight & loopMask)==pTerm->prereqRight ){ int iColumn = pX->pLeft->iColumn; int k; char idxaff = pIdx->pTable->aCol[iColumn].affinity; for(k=0; k<pIdx->nColumn; k++){ /* If the collating sequences or affinities don't match, ** ignore this index. */ if( pColl!=pIdx->keyInfo.aColl[k] ) continue; if( !sqlite3IndexAffinityOk(pX, idxaff) ) continue; if( pIdx->aiColumn[k]==iColumn ){ switch( pX->op ){ case TK_IN: { if( k==0 ) inMask |= 1; break; } case TK_EQ: { eqMask |= 1<<k; break; } case TK_LE: case TK_LT: { ltMask |= 1<<k; break; } case TK_GE: case TK_GT: { gtMask |= 1<<k; break; } default: { /* CANT_HAPPEN */ assert( 0 ); break; } } break; |
︙ | ︙ | |||
766 767 768 769 770 771 772 773 774 | pLevel->inOp = OP_Noop; if( i<ARRAYSIZE(iDirectEq) && iDirectEq[i]>=0 ){ /* Case 1: We can directly reference a single row using an ** equality comparison against the ROWID field. Or ** we reference multiple rows using a "rowid IN (...)" ** construct. */ k = iDirectEq[i]; assert( k<nExpr ); | > | > | > | < | | | | | | | | | < < < | | | | | | | > | < < < < < < < < < < < < | 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 | pLevel->inOp = OP_Noop; if( i<ARRAYSIZE(iDirectEq) && iDirectEq[i]>=0 ){ /* Case 1: We can directly reference a single row using an ** equality comparison against the ROWID field. Or ** we reference multiple rows using a "rowid IN (...)" ** construct. */ Expr *pX; k = iDirectEq[i]; assert( k<nExpr ); pTerm = &aExpr[k]; assert( pTerm->p!=0 ); assert( pTerm->idxLeft==iCur || pTerm->idxRight==iCur ); brk = pLevel->brk = sqlite3VdbeMakeLabel(v); pX = pTerm->p; assert( pTerm->idxLeft==iCur ); if( pX->op!=TK_IN ){ sqlite3ExprCode(pParse, pTerm->p->pRight); }else{ sqlite3VdbeAddOp(v, OP_Rewind, pX->iTable, brk); sqlite3VdbeAddOp(v, OP_KeyAsData, pX->iTable, 1); pLevel->inP2 = sqlite3VdbeAddOp(v, OP_IdxColumn, pX->iTable, 0); pLevel->inOp = OP_Next; pLevel->inP1 = pX->iTable; } disableTerm(pLevel, &pTerm->p); cont = pLevel->cont = sqlite3VdbeMakeLabel(v); sqlite3VdbeAddOp(v, OP_MustBeInt, 1, brk); haveKey = 0; sqlite3VdbeAddOp(v, OP_NotExists, iCur, brk); pLevel->op = OP_Noop; }else if( pIdx!=0 && pLevel->score>0 && pLevel->score%4==0 ){ /* Case 2: There is an index and all terms of the WHERE clause that ** refer to the index use the "==" or "IN" operators. */ int start; int nColumn = (pLevel->score+4)/8; brk = pLevel->brk = sqlite3VdbeMakeLabel(v); /* For each column of the index, find the term of the WHERE clause that ** constraints that column. If the WHERE clause term is X=expr, then ** evaluation expr and leave the result on the stack */ for(j=0; j<nColumn; j++){ for(pTerm=aExpr, k=0; k<nExpr; k++, pTerm++){ Expr *pX = pTerm->p; if( pX==0 ) continue; if( pTerm->idxLeft==iCur && (pTerm->prereqRight & loopMask)==pTerm->prereqRight && pX->pLeft->iColumn==pIdx->aiColumn[j] ){ char idxaff = pIdx->pTable->aCol[pX->pLeft->iColumn].affinity; if( sqlite3IndexAffinityOk(pTerm->p, idxaff) ){ if( pX->op==TK_EQ ){ sqlite3ExprCode(pParse, pX->pRight); disableTerm(pLevel, &pTerm->p); break; } assert( pX->op==TK_IN && nColumn==1 ); if( pX->op==TK_IN && nColumn==1 ){ sqlite3VdbeAddOp(v, OP_Rewind, pX->iTable, brk); sqlite3VdbeAddOp(v, OP_KeyAsData, pX->iTable, 1); pLevel->inP2 = sqlite3VdbeAddOp(v, OP_IdxColumn, pX->iTable, 0); pLevel->inOp = OP_Next; pLevel->inP1 = pX->iTable; disableTerm(pLevel, &pTerm->p); break; } } } } } pLevel->iMem = pParse->nMem++; cont = pLevel->cont = sqlite3VdbeMakeLabel(v); |
︙ | ︙ | |||
898 899 900 901 902 903 904 | int start; brk = pLevel->brk = sqlite3VdbeMakeLabel(v); cont = pLevel->cont = sqlite3VdbeMakeLabel(v); if( iDirectGt[i]>=0 ){ k = iDirectGt[i]; assert( k<nExpr ); | | | | < < | < | | | | | < < | < | | | 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 | int start; brk = pLevel->brk = sqlite3VdbeMakeLabel(v); cont = pLevel->cont = sqlite3VdbeMakeLabel(v); if( iDirectGt[i]>=0 ){ k = iDirectGt[i]; assert( k<nExpr ); pTerm = &aExpr[k]; assert( pTerm->p!=0 ); assert( pTerm->idxLeft==iCur ); sqlite3ExprCode(pParse, pTerm->p->pRight); sqlite3VdbeAddOp(v, OP_ForceInt, pTerm->p->op==TK_LT || pTerm->p->op==TK_GT, brk); sqlite3VdbeAddOp(v, OP_MoveGe, iCur, brk); disableTerm(pLevel, &pTerm->p); }else{ sqlite3VdbeAddOp(v, OP_Rewind, iCur, brk); } if( iDirectLt[i]>=0 ){ k = iDirectLt[i]; assert( k<nExpr ); pTerm = &aExpr[k]; assert( pTerm->p!=0 ); assert( pTerm->idxLeft==iCur ); sqlite3ExprCode(pParse, pTerm->p->pRight); /* sqlite3VdbeAddOp(v, OP_MustBeInt, 0, sqlite3VdbeCurrentAddr(v)+1); */ pLevel->iMem = pParse->nMem++; sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iMem, 1); if( pTerm->p->op==TK_LT || pTerm->p->op==TK_GT ){ testOp = OP_Ge; }else{ testOp = OP_Gt; } disableTerm(pLevel, &pTerm->p); } start = sqlite3VdbeCurrentAddr(v); pLevel->op = OP_Next; pLevel->p1 = iCur; pLevel->p2 = start; if( testOp!=OP_Noop ){ sqlite3VdbeAddOp(v, OP_Recno, iCur, 0); |
︙ | ︙ | |||
977 978 979 980 981 982 983 | int start; int leFlag=0, geFlag=0; int testOp; /* Evaluate the equality constraints */ for(j=0; j<nEqColumn; j++){ | | | | | | | < < < < < < < < < | | | 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 | int start; int leFlag=0, geFlag=0; int testOp; /* Evaluate the equality constraints */ for(j=0; j<nEqColumn; j++){ for(pTerm=aExpr, k=0; k<nExpr; k++, pTerm++){ if( pTerm->p==0 ) continue; if( pTerm->idxLeft==iCur && pTerm->p->op==TK_EQ && (pTerm->prereqRight & loopMask)==pTerm->prereqRight && pTerm->p->pLeft->iColumn==pIdx->aiColumn[j] ){ sqlite3ExprCode(pParse, pTerm->p->pRight); disableTerm(pLevel, &pTerm->p); break; } } } /* Duplicate the equality term values because they will all be ** used twice: once to make the termination key and once to make the |
︙ | ︙ | |||
1021 1022 1023 1024 1025 1026 1027 | ** will end the search. There is no termination key if there ** are no equality terms and no "X<..." term. ** ** 2002-Dec-04: On a reverse-order scan, the so-called "termination" ** key computed here really ends up being the start key. */ if( (score & 1)!=0 ){ | | | | | | < < < < < < < < < < | 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 | ** will end the search. There is no termination key if there ** are no equality terms and no "X<..." term. ** ** 2002-Dec-04: On a reverse-order scan, the so-called "termination" ** key computed here really ends up being the start key. */ if( (score & 1)!=0 ){ for(pTerm=aExpr, k=0; k<nExpr; k++, pTerm++){ Expr *pExpr = pTerm->p; if( pExpr==0 ) continue; if( pTerm->idxLeft==iCur && (pExpr->op==TK_LT || pExpr->op==TK_LE) && (pTerm->prereqRight & loopMask)==pTerm->prereqRight && pExpr->pLeft->iColumn==pIdx->aiColumn[j] ){ sqlite3ExprCode(pParse, pExpr->pRight); leFlag = pExpr->op==TK_LE; disableTerm(pLevel, &pTerm->p); break; } } testOp = OP_IdxGE; }else{ testOp = nEqColumn>0 ? OP_IdxGE : OP_Noop; leFlag = 1; |
︙ | ︙ | |||
1078 1079 1080 1081 1082 1083 1084 | ** that case, generate a "Rewind" instruction in place of the ** start key search. ** ** 2002-Dec-04: In the case of a reverse-order search, the so-called ** "start" key really ends up being used as the termination key. */ if( (score & 2)!=0 ){ | | | | | | < < < < < < < < < < | 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 | ** that case, generate a "Rewind" instruction in place of the ** start key search. ** ** 2002-Dec-04: In the case of a reverse-order search, the so-called ** "start" key really ends up being used as the termination key. */ if( (score & 2)!=0 ){ for(pTerm=aExpr, k=0; k<nExpr; k++, pTerm++){ Expr *pExpr = pTerm->p; if( pExpr==0 ) continue; if( pTerm->idxLeft==iCur && (pExpr->op==TK_GT || pExpr->op==TK_GE) && (pTerm->prereqRight & loopMask)==pTerm->prereqRight && pExpr->pLeft->iColumn==pIdx->aiColumn[j] ){ sqlite3ExprCode(pParse, pExpr->pRight); geFlag = pExpr->op==TK_GE; disableTerm(pLevel, &pTerm->p); break; } } }else{ geFlag = 1; } if( nEqColumn>0 || (score&2)!=0 ){ |
︙ | ︙ | |||
1159 1160 1161 1162 1163 1164 1165 | pLevel->p2 = start; } loopMask |= getMask(&maskSet, iCur); /* Insert code to test every subexpression that can be completely ** computed using the current set of tables. */ | | | | | | | | | | | | | 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 | pLevel->p2 = start; } loopMask |= getMask(&maskSet, iCur); /* Insert code to test every subexpression that can be completely ** computed using the current set of tables. */ for(pTerm=aExpr, j=0; j<nExpr; j++, pTerm++){ if( pTerm->p==0 ) continue; if( (pTerm->prereqAll & loopMask)!=pTerm->prereqAll ) continue; if( pLevel->iLeftJoin && !ExprHasProperty(pTerm->p,EP_FromJoin) ){ continue; } if( haveKey ){ haveKey = 0; sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0); } sqlite3ExprIfFalse(pParse, pTerm->p, cont, 1); pTerm->p = 0; } brk = cont; /* For a LEFT OUTER JOIN, generate code that will record the fact that ** at least one row of the right table has matched the left table. */ if( pLevel->iLeftJoin ){ pLevel->top = sqlite3VdbeCurrentAddr(v); sqlite3VdbeAddOp(v, OP_Integer, 1, 0); sqlite3VdbeAddOp(v, OP_MemStore, pLevel->iLeftJoin, 1); for(pTerm=aExpr, j=0; j<nExpr; j++, pTerm++){ if( pTerm->p==0 ) continue; if( (pTerm->prereqAll & loopMask)!=pTerm->prereqAll ) continue; if( haveKey ){ /* Cannot happen. "haveKey" can only be true if pushKey is true ** an pushKey can only be true for DELETE and UPDATE and there are ** no outer joins with DELETE and UPDATE. */ haveKey = 0; sqlite3VdbeAddOp(v, OP_MoveGe, iCur, 0); } sqlite3ExprIfFalse(pParse, pTerm->p, cont, 1); pTerm->p = 0; } } } pWInfo->iContinue = cont; if( pushKey && !haveKey ){ sqlite3VdbeAddOp(v, OP_Recno, pTabList->a[0].iCursor, 0); } |
︙ | ︙ |