| | @@ -452,11 +452,11 @@ |
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | 455 | #define SQLITE_VERSION "3.39.0" |
| 456 | 456 | #define SQLITE_VERSION_NUMBER 3039000 |
| 457 | | -#define SQLITE_SOURCE_ID "2022-04-21 19:38:17 f766dff012af0ea3c28a8ce4db850cd0205729a8283bce1e442992aded7c734b" |
| 457 | +#define SQLITE_SOURCE_ID "2022-05-10 00:24:01 c6c3115f3a008cf9b0d7c5c812f17e38c8a75a904032c5f05f0bea03a7340527" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -15790,12 +15790,14 @@ |
| 15790 | 15790 | # define sqlite3VdbeVerifyNoMallocRequired(A,B) |
| 15791 | 15791 | # define sqlite3VdbeVerifyNoResultRow(A) |
| 15792 | 15792 | #endif |
| 15793 | 15793 | #if defined(SQLITE_DEBUG) |
| 15794 | 15794 | SQLITE_PRIVATE void sqlite3VdbeVerifyAbortable(Vdbe *p, int); |
| 15795 | +SQLITE_PRIVATE void sqlite3VdbeNoJumpsOutsideSubrtn(Vdbe*,int,int,int); |
| 15795 | 15796 | #else |
| 15796 | 15797 | # define sqlite3VdbeVerifyAbortable(A,B) |
| 15798 | +# define sqlite3VdbeNoJumpsOutsideSubrtn(A,B,C,D) |
| 15797 | 15799 | #endif |
| 15798 | 15800 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno); |
| 15799 | 15801 | #ifndef SQLITE_OMIT_EXPLAIN |
| 15800 | 15802 | SQLITE_PRIVATE void sqlite3VdbeExplain(Parse*,u8,const char*,...); |
| 15801 | 15803 | SQLITE_PRIVATE void sqlite3VdbeExplainPop(Parse*); |
| | @@ -17051,10 +17053,12 @@ |
| 17051 | 17053 | /* TH3 expects this value ^^^^^^^^^^ to be 0x40000. Coordinate any change */ |
| 17052 | 17054 | #define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */ |
| 17053 | 17055 | #define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */ |
| 17054 | 17056 | #define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */ |
| 17055 | 17057 | #define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */ |
| 17058 | +#define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */ |
| 17059 | + /* TH3 expects this value ^^^^^^^^^^ See flatten04.test */ |
| 17056 | 17060 | #define SQLITE_AllOpts 0xffffffff /* All optimizations */ |
| 17057 | 17061 | |
| 17058 | 17062 | /* |
| 17059 | 17063 | ** Macros for testing whether or not optimizations are enabled or disabled. |
| 17060 | 17064 | */ |
| | @@ -17396,10 +17400,11 @@ |
| 17396 | 17400 | #define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */ |
| 17397 | 17401 | #define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */ |
| 17398 | 17402 | #define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */ |
| 17399 | 17403 | #define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */ |
| 17400 | 17404 | #define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */ |
| 17405 | +#define COLFLAG_NOEXPAND 0x0400 /* Omit this column when expanding "*" */ |
| 17401 | 17406 | #define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */ |
| 17402 | 17407 | #define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */ |
| 17403 | 17408 | |
| 17404 | 17409 | /* |
| 17405 | 17410 | ** A "Collating Sequence" is defined by an instance of the following |
| | @@ -18269,17 +18274,22 @@ |
| 18269 | 18274 | int nExpr; /* Number of expressions on the list */ |
| 18270 | 18275 | int nAlloc; /* Number of a[] slots allocated */ |
| 18271 | 18276 | struct ExprList_item { /* For each expression in the list */ |
| 18272 | 18277 | Expr *pExpr; /* The parse tree for this expression */ |
| 18273 | 18278 | char *zEName; /* Token associated with this expression */ |
| 18274 | | - u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */ |
| 18275 | | - unsigned eEName :2; /* Meaning of zEName */ |
| 18276 | | - unsigned done :1; /* A flag to indicate when processing is finished */ |
| 18277 | | - unsigned reusable :1; /* Constant expression is reusable */ |
| 18278 | | - unsigned bSorterRef :1; /* Defer evaluation until after sorting */ |
| 18279 | | - unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */ |
| 18280 | | - unsigned bUsed: 1; /* This column used in a SF_NestedFrom subquery */ |
| 18279 | + struct { |
| 18280 | + u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */ |
| 18281 | + unsigned eEName :2; /* Meaning of zEName */ |
| 18282 | + unsigned done :1; /* Indicates when processing is finished */ |
| 18283 | + unsigned reusable :1; /* Constant expression is reusable */ |
| 18284 | + unsigned bSorterRef :1; /* Defer evaluation until after sorting */ |
| 18285 | + unsigned bNulls :1; /* True if explicit "NULLS FIRST/LAST" */ |
| 18286 | + unsigned bUsed :1; /* This column used in a SF_NestedFrom subquery */ |
| 18287 | + unsigned bUsingTerm:1; /* Term from the USING clause of a NestedFrom */ |
| 18288 | + unsigned bNoExpand: 1; /* Term is an auxiliary in NestedFrom and should |
| 18289 | + ** not be expanded by "*" in parent queries */ |
| 18290 | + } fg; |
| 18281 | 18291 | union { |
| 18282 | 18292 | struct { /* Used by any ExprList other than Parse.pConsExpr */ |
| 18283 | 18293 | u16 iOrderByCol; /* For ORDER BY, column number in result set */ |
| 18284 | 18294 | u16 iAlias; /* Index into Parse.aAlias[] for zName */ |
| 18285 | 18295 | } x; |
| | @@ -19729,10 +19739,11 @@ |
| 19729 | 19739 | SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8); |
| 19730 | 19740 | SQLITE_PRIVATE void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*); |
| 19731 | 19741 | SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*); |
| 19732 | 19742 | SQLITE_PRIVATE void sqlite3TreeViewBareIdList(TreeView*, const IdList*, const char*); |
| 19733 | 19743 | SQLITE_PRIVATE void sqlite3TreeViewIdList(TreeView*, const IdList*, u8, const char*); |
| 19744 | +SQLITE_PRIVATE void sqlite3TreeViewColumnList(TreeView*, const Column*, int, u8); |
| 19734 | 19745 | SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*); |
| 19735 | 19746 | SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8); |
| 19736 | 19747 | SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8); |
| 19737 | 19748 | SQLITE_PRIVATE void sqlite3TreeViewUpsert(TreeView*, const Upsert*, u8); |
| 19738 | 19749 | SQLITE_PRIVATE void sqlite3TreeViewDelete(const With*, const SrcList*, const Expr*, |
| | @@ -20022,10 +20033,11 @@ |
| 20022 | 20033 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*); |
| 20023 | 20034 | SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*); |
| 20024 | 20035 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8); |
| 20025 | 20036 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*); |
| 20026 | 20037 | SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int); |
| 20038 | +SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr*,const SrcItem*); |
| 20027 | 20039 | #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 20028 | 20040 | SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*); |
| 20029 | 20041 | #endif |
| 20030 | 20042 | SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*); |
| 20031 | 20043 | SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); |
| | @@ -20583,10 +20595,11 @@ |
| 20583 | 20595 | ** Allowed flags for the 3rd parameter to sqlite3FindInIndex(). |
| 20584 | 20596 | */ |
| 20585 | 20597 | #define IN_INDEX_NOOP_OK 0x0001 /* OK to return IN_INDEX_NOOP */ |
| 20586 | 20598 | #define IN_INDEX_MEMBERSHIP 0x0002 /* IN operator used for membership test */ |
| 20587 | 20599 | #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */ |
| 20600 | +#define IN_INDEX_REUSE_CUR 0x0008 /* Reuse prior table cursor */ |
| 20588 | 20601 | SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*, int*); |
| 20589 | 20602 | |
| 20590 | 20603 | SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int); |
| 20591 | 20604 | SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *); |
| 20592 | 20605 | #if defined(SQLITE_ENABLE_ATOMIC_WRITE) \ |
| | @@ -30462,12 +30475,18 @@ |
| 30462 | 30475 | sqlite3_str_append(pAccum, ".", 1); |
| 30463 | 30476 | } |
| 30464 | 30477 | sqlite3_str_appendall(pAccum, pItem->zName); |
| 30465 | 30478 | }else if( pItem->zAlias ){ |
| 30466 | 30479 | sqlite3_str_appendall(pAccum, pItem->zAlias); |
| 30467 | | - }else if( ALWAYS(pItem->pSelect) ){ |
| 30468 | | - sqlite3_str_appendf(pAccum, "SUBQUERY %u", pItem->pSelect->selId); |
| 30480 | + }else{ |
| 30481 | + Select *pSel = pItem->pSelect; |
| 30482 | + assert( pSel!=0 ); |
| 30483 | + if( pSel->selFlags & SF_NestedFrom ){ |
| 30484 | + sqlite3_str_appendf(pAccum, "(join-%u)", pSel->selId); |
| 30485 | + }else{ |
| 30486 | + sqlite3_str_appendf(pAccum, "(subquery-%u)", pSel->selId); |
| 30487 | + } |
| 30469 | 30488 | } |
| 30470 | 30489 | length = width = 0; |
| 30471 | 30490 | break; |
| 30472 | 30491 | } |
| 30473 | 30492 | default: { |
| | @@ -31047,10 +31066,57 @@ |
| 31047 | 31066 | */ |
| 31048 | 31067 | static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){ |
| 31049 | 31068 | sqlite3TreeViewPush(&p, moreFollows); |
| 31050 | 31069 | sqlite3TreeViewLine(p, "%s", zLabel); |
| 31051 | 31070 | } |
| 31071 | + |
| 31072 | +/* |
| 31073 | +** Show a list of Column objects in tree format. |
| 31074 | +*/ |
| 31075 | +SQLITE_PRIVATE void sqlite3TreeViewColumnList( |
| 31076 | + TreeView *pView, |
| 31077 | + const Column *aCol, |
| 31078 | + int nCol, |
| 31079 | + u8 moreToFollow |
| 31080 | +){ |
| 31081 | + int i; |
| 31082 | + sqlite3TreeViewPush(&pView, moreToFollow); |
| 31083 | + sqlite3TreeViewLine(pView, "COLUMNS"); |
| 31084 | + for(i=0; i<nCol; i++){ |
| 31085 | + u16 flg = aCol[i].colFlags; |
| 31086 | + int moreToFollow = i<(nCol - 1); |
| 31087 | + sqlite3TreeViewPush(&pView, moreToFollow); |
| 31088 | + sqlite3TreeViewLine(pView, 0); |
| 31089 | + printf(" %s", aCol[i].zCnName); |
| 31090 | + switch( aCol[i].eCType ){ |
| 31091 | + case COLTYPE_ANY: printf(" ANY"); break; |
| 31092 | + case COLTYPE_BLOB: printf(" BLOB"); break; |
| 31093 | + case COLTYPE_INT: printf(" INT"); break; |
| 31094 | + case COLTYPE_INTEGER: printf(" INTEGER"); break; |
| 31095 | + case COLTYPE_REAL: printf(" REAL"); break; |
| 31096 | + case COLTYPE_TEXT: printf(" TEXT"); break; |
| 31097 | + case COLTYPE_CUSTOM: { |
| 31098 | + if( flg & COLFLAG_HASTYPE ){ |
| 31099 | + const char *z = aCol[i].zCnName; |
| 31100 | + z += strlen(z)+1; |
| 31101 | + printf(" X-%s", z); |
| 31102 | + break; |
| 31103 | + } |
| 31104 | + } |
| 31105 | + } |
| 31106 | + if( flg & COLFLAG_PRIMKEY ) printf(" PRIMARY KEY"); |
| 31107 | + if( flg & COLFLAG_HIDDEN ) printf(" HIDDEN"); |
| 31108 | +#ifdef COLFLAG_NOEXPAND |
| 31109 | + if( flg & COLFLAG_NOEXPAND ) printf(" NO-EXPAND"); |
| 31110 | +#endif |
| 31111 | + if( flg ) printf(" flags=%04x", flg); |
| 31112 | + printf("\n"); |
| 31113 | + fflush(stdout); |
| 31114 | + sqlite3TreeViewPop(&pView); |
| 31115 | + } |
| 31116 | + sqlite3TreeViewPop(&pView); |
| 31117 | +} |
| 31052 | 31118 | |
| 31053 | 31119 | /* |
| 31054 | 31120 | ** Generate a human-readable description of a WITH clause. |
| 31055 | 31121 | */ |
| 31056 | 31122 | SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){ |
| | @@ -31077,10 +31143,14 @@ |
| 31077 | 31143 | sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zEName); |
| 31078 | 31144 | cSep = ','; |
| 31079 | 31145 | } |
| 31080 | 31146 | sqlite3_str_appendf(&x, ")"); |
| 31081 | 31147 | } |
| 31148 | + if( pCte->eM10d!=M10d_Any ){ |
| 31149 | + sqlite3_str_appendf(&x, " %sMATERIALIZED", |
| 31150 | + pCte->eM10d==M10d_No ? "NOT " : ""); |
| 31151 | + } |
| 31082 | 31152 | if( pCte->pUse ){ |
| 31083 | 31153 | sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse, |
| 31084 | 31154 | pCte->pUse->nUse); |
| 31085 | 31155 | } |
| 31086 | 31156 | sqlite3StrAccumFinish(&x); |
| | @@ -31099,10 +31169,11 @@ |
| 31099 | 31169 | int i; |
| 31100 | 31170 | if( pSrc==0 ) return; |
| 31101 | 31171 | for(i=0; i<pSrc->nSrc; i++){ |
| 31102 | 31172 | const SrcItem *pItem = &pSrc->a[i]; |
| 31103 | 31173 | StrAccum x; |
| 31174 | + int n = 0; |
| 31104 | 31175 | char zLine[100]; |
| 31105 | 31176 | sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); |
| 31106 | 31177 | x.printfFlags |= SQLITE_PRINTF_INTERNAL; |
| 31107 | 31178 | sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem); |
| 31108 | 31179 | if( pItem->pTab ){ |
| | @@ -31127,13 +31198,24 @@ |
| 31127 | 31198 | if( pItem->fg.isCte ){ |
| 31128 | 31199 | sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse); |
| 31129 | 31200 | } |
| 31130 | 31201 | sqlite3StrAccumFinish(&x); |
| 31131 | 31202 | sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1); |
| 31203 | + n = 0; |
| 31204 | + if( pItem->pSelect ) n++; |
| 31205 | + if( pItem->fg.isTabFunc ) n++; |
| 31206 | + if( pItem->fg.isUsing ) n++; |
| 31207 | + if( pItem->fg.isUsing ){ |
| 31208 | + sqlite3TreeViewIdList(pView, pItem->u3.pUsing, (--n)>0, "USING"); |
| 31209 | + } |
| 31132 | 31210 | if( pItem->pSelect ){ |
| 31211 | + if( pItem->pTab ){ |
| 31212 | + Table *pTab = pItem->pTab; |
| 31213 | + sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1); |
| 31214 | + } |
| 31133 | 31215 | assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) ); |
| 31134 | | - sqlite3TreeViewSelect(pView, pItem->pSelect, 0); |
| 31216 | + sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0); |
| 31135 | 31217 | } |
| 31136 | 31218 | if( pItem->fg.isTabFunc ){ |
| 31137 | 31219 | sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:"); |
| 31138 | 31220 | } |
| 31139 | 31221 | sqlite3TreeViewPop(&pView); |
| | @@ -31296,10 +31378,11 @@ |
| 31296 | 31378 | /* |
| 31297 | 31379 | ** Generate a human-readable explanation for a Window object |
| 31298 | 31380 | */ |
| 31299 | 31381 | SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){ |
| 31300 | 31382 | int nElement = 0; |
| 31383 | + if( pWin==0 ) return; |
| 31301 | 31384 | if( pWin->pFilter ){ |
| 31302 | 31385 | sqlite3TreeViewItem(pView, "FILTER", 1); |
| 31303 | 31386 | sqlite3TreeViewExpr(pView, pWin->pFilter, 0); |
| 31304 | 31387 | sqlite3TreeViewPop(&pView); |
| 31305 | 31388 | } |
| | @@ -31360,10 +31443,11 @@ |
| 31360 | 31443 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 31361 | 31444 | /* |
| 31362 | 31445 | ** Generate a human-readable explanation for a Window Function object |
| 31363 | 31446 | */ |
| 31364 | 31447 | SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){ |
| 31448 | + if( pWin==0 ) return; |
| 31365 | 31449 | sqlite3TreeViewPush(&pView, more); |
| 31366 | 31450 | sqlite3TreeViewLine(pView, "WINFUNC %s(%d)", |
| 31367 | 31451 | pWin->pWFunc->zName, pWin->pWFunc->nArg); |
| 31368 | 31452 | sqlite3TreeViewWindow(pView, pWin, 0); |
| 31369 | 31453 | sqlite3TreeViewPop(&pView); |
| | @@ -31611,11 +31695,21 @@ |
| 31611 | 31695 | sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags); |
| 31612 | 31696 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 31613 | 31697 | break; |
| 31614 | 31698 | } |
| 31615 | 31699 | case TK_IN: { |
| 31616 | | - sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags); |
| 31700 | + sqlite3_str *pStr = sqlite3_str_new(0); |
| 31701 | + char *z; |
| 31702 | + sqlite3_str_appendf(pStr, "IN flags=0x%x", pExpr->flags); |
| 31703 | + if( pExpr->iTable ) sqlite3_str_appendf(pStr, " iTable=%d",pExpr->iTable); |
| 31704 | + if( ExprHasProperty(pExpr, EP_Subrtn) ){ |
| 31705 | + sqlite3_str_appendf(pStr, " subrtn(%d,%d)", |
| 31706 | + pExpr->y.sub.regReturn, pExpr->y.sub.iAddr); |
| 31707 | + } |
| 31708 | + z = sqlite3_str_finish(pStr); |
| 31709 | + sqlite3TreeViewLine(pView, z); |
| 31710 | + sqlite3_free(z); |
| 31617 | 31711 | sqlite3TreeViewExpr(pView, pExpr->pLeft, 1); |
| 31618 | 31712 | if( ExprUseXSelect(pExpr) ){ |
| 31619 | 31713 | sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0); |
| 31620 | 31714 | }else{ |
| 31621 | 31715 | sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0); |
| | @@ -31762,17 +31856,19 @@ |
| 31762 | 31856 | if( j || zName ){ |
| 31763 | 31857 | sqlite3TreeViewPush(&pView, moreToFollow); |
| 31764 | 31858 | moreToFollow = 0; |
| 31765 | 31859 | sqlite3TreeViewLine(pView, 0); |
| 31766 | 31860 | if( zName ){ |
| 31767 | | - switch( pList->a[i].eEName ){ |
| 31861 | + switch( pList->a[i].fg.eEName ){ |
| 31768 | 31862 | default: |
| 31769 | 31863 | fprintf(stdout, "AS %s ", zName); |
| 31770 | 31864 | break; |
| 31771 | 31865 | case ENAME_TAB: |
| 31772 | 31866 | fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName); |
| 31773 | | - if( pList->a[i].bUsed==0 ) fprintf(stdout, "(unused) "); |
| 31867 | + if( pList->a[i].fg.bUsed ) fprintf(stdout, "(used) "); |
| 31868 | + if( pList->a[i].fg.bUsingTerm ) fprintf(stdout, "(USING-term) "); |
| 31869 | + if( pList->a[i].fg.bNoExpand ) fprintf(stdout, "(NoExpand) "); |
| 31774 | 31870 | break; |
| 31775 | 31871 | case ENAME_SPAN: |
| 31776 | 31872 | fprintf(stdout, "SPAN(\"%s\") ", zName); |
| 31777 | 31873 | break; |
| 31778 | 31874 | } |
| | @@ -81423,10 +81519,94 @@ |
| 81423 | 81519 | pParse->nLabel = 0; |
| 81424 | 81520 | *pMaxFuncArgs = nMaxArgs; |
| 81425 | 81521 | assert( p->bIsReader!=0 || DbMaskAllZero(p->btreeMask) ); |
| 81426 | 81522 | } |
| 81427 | 81523 | |
| 81524 | +#ifdef SQLITE_DEBUG |
| 81525 | +/* |
| 81526 | +** Check to see if a subroutine contains a jump to a location outside of |
| 81527 | +** the subroutine. If a jump outside the subroutine is detected, add code |
| 81528 | +** that will cause the program to halt with an error message. |
| 81529 | +** |
| 81530 | +** The subroutine consists of opcodes between iFirst and iLast. Jumps to |
| 81531 | +** locations within the subroutine are acceptable. iRetReg is a register |
| 81532 | +** that contains the return address. Jumps to outside the range of iFirst |
| 81533 | +** through iLast are also acceptable as long as the jump destination is |
| 81534 | +** an OP_Return to iReturnAddr. |
| 81535 | +** |
| 81536 | +** A jump to an unresolved label means that the jump destination will be |
| 81537 | +** beyond the current address. That is normally a jump to an early |
| 81538 | +** termination and is consider acceptable. |
| 81539 | +** |
| 81540 | +** This routine only runs during debug builds. The purpose is (of course) |
| 81541 | +** to detect invalid escapes out of a subroutine. The OP_Halt opcode |
| 81542 | +** is generated rather than an assert() or other error, so that ".eqp full" |
| 81543 | +** will still work to show the original bytecode, to aid in debugging. |
| 81544 | +*/ |
| 81545 | +SQLITE_PRIVATE void sqlite3VdbeNoJumpsOutsideSubrtn( |
| 81546 | + Vdbe *v, /* The byte-code program under construction */ |
| 81547 | + int iFirst, /* First opcode of the subroutine */ |
| 81548 | + int iLast, /* Last opcode of the subroutine */ |
| 81549 | + int iRetReg /* Subroutine return address register */ |
| 81550 | +){ |
| 81551 | + VdbeOp *pOp; |
| 81552 | + Parse *pParse; |
| 81553 | + int i; |
| 81554 | + sqlite3_str *pErr = 0; |
| 81555 | + assert( v!=0 ); |
| 81556 | + pParse = v->pParse; |
| 81557 | + assert( pParse!=0 ); |
| 81558 | + if( pParse->nErr ) return; |
| 81559 | + assert( iLast>=iFirst ); |
| 81560 | + assert( iLast<v->nOp ); |
| 81561 | + pOp = &v->aOp[iFirst]; |
| 81562 | + for(i=iFirst; i<=iLast; i++, pOp++){ |
| 81563 | + if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 ){ |
| 81564 | + int iDest = pOp->p2; /* Jump destination */ |
| 81565 | + if( iDest==0 ) continue; |
| 81566 | + if( pOp->opcode==OP_Gosub ) continue; |
| 81567 | + if( iDest<0 ){ |
| 81568 | + int j = ADDR(iDest); |
| 81569 | + assert( j>=0 ); |
| 81570 | + if( j>=-pParse->nLabel || pParse->aLabel[j]<0 ){ |
| 81571 | + continue; |
| 81572 | + } |
| 81573 | + iDest = pParse->aLabel[j]; |
| 81574 | + } |
| 81575 | + if( iDest<iFirst || iDest>iLast ){ |
| 81576 | + int j = iDest; |
| 81577 | + for(; j<v->nOp; j++){ |
| 81578 | + VdbeOp *pX = &v->aOp[j]; |
| 81579 | + if( pX->opcode==OP_Return ){ |
| 81580 | + if( pX->p1==iRetReg ) break; |
| 81581 | + continue; |
| 81582 | + } |
| 81583 | + if( pX->opcode==OP_Noop ) continue; |
| 81584 | + if( pX->opcode==OP_Explain ) continue; |
| 81585 | + if( pErr==0 ){ |
| 81586 | + pErr = sqlite3_str_new(0); |
| 81587 | + }else{ |
| 81588 | + sqlite3_str_appendchar(pErr, 1, '\n'); |
| 81589 | + } |
| 81590 | + sqlite3_str_appendf(pErr, |
| 81591 | + "Opcode at %d jumps to %d which is outside the " |
| 81592 | + "subroutine at %d..%d", |
| 81593 | + i, iDest, iFirst, iLast); |
| 81594 | + break; |
| 81595 | + } |
| 81596 | + } |
| 81597 | + } |
| 81598 | + } |
| 81599 | + if( pErr ){ |
| 81600 | + char *zErr = sqlite3_str_finish(pErr); |
| 81601 | + sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_INTERNAL, OE_Abort, 0, zErr, 0); |
| 81602 | + sqlite3_free(zErr); |
| 81603 | + sqlite3MayAbort(pParse); |
| 81604 | + } |
| 81605 | +} |
| 81606 | +#endif /* SQLITE_DEBUG */ |
| 81607 | + |
| 81428 | 81608 | /* |
| 81429 | 81609 | ** Return the address of the next instruction to be inserted. |
| 81430 | 81610 | */ |
| 81431 | 81611 | SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){ |
| 81432 | 81612 | assert( p->eVdbeState==VDBE_INIT_STATE ); |
| | @@ -89154,10 +89334,12 @@ |
| 89154 | 89334 | if( pOp->p2==0 ) break; |
| 89155 | 89335 | |
| 89156 | 89336 | /* Most jump operations do a goto to this spot in order to update |
| 89157 | 89337 | ** the pOp pointer. */ |
| 89158 | 89338 | jump_to_p2: |
| 89339 | + assert( pOp->p2>0 ); /* There are never any jumps to instruction 0 */ |
| 89340 | + assert( pOp->p2<p->nOp ); /* Jumps must be in range */ |
| 89159 | 89341 | pOp = &aOp[pOp->p2 - 1]; |
| 89160 | 89342 | break; |
| 89161 | 89343 | } |
| 89162 | 89344 | |
| 89163 | 89345 | /* Opcode: EndCoroutine P1 * * * * |
| | @@ -101365,11 +101547,11 @@ |
| 101365 | 101547 | const char *zTab, |
| 101366 | 101548 | const char *zDb |
| 101367 | 101549 | ){ |
| 101368 | 101550 | int n; |
| 101369 | 101551 | const char *zSpan; |
| 101370 | | - if( pItem->eEName!=ENAME_TAB ) return 0; |
| 101552 | + if( pItem->fg.eEName!=ENAME_TAB ) return 0; |
| 101371 | 101553 | zSpan = pItem->zEName; |
| 101372 | 101554 | for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){} |
| 101373 | 101555 | if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){ |
| 101374 | 101556 | return 0; |
| 101375 | 101557 | } |
| | @@ -101594,12 +101776,13 @@ |
| 101594 | 101776 | } |
| 101595 | 101777 | cnt++; |
| 101596 | 101778 | cntTab = 2; |
| 101597 | 101779 | pMatch = pItem; |
| 101598 | 101780 | pExpr->iColumn = j; |
| 101599 | | - pEList->a[j].bUsed = 1; |
| 101781 | + pEList->a[j].fg.bUsed = 1; |
| 101600 | 101782 | hit = 1; |
| 101783 | + if( pEList->a[j].fg.bUsingTerm ) break; |
| 101601 | 101784 | } |
| 101602 | 101785 | if( hit || zTab==0 ) continue; |
| 101603 | 101786 | } |
| 101604 | 101787 | assert( zDb==0 || zTab!=0 ); |
| 101605 | 101788 | if( zTab ){ |
| | @@ -101818,11 +102001,11 @@ |
| 101818 | 102001 | ){ |
| 101819 | 102002 | pEList = pNC->uNC.pEList; |
| 101820 | 102003 | assert( pEList!=0 ); |
| 101821 | 102004 | for(j=0; j<pEList->nExpr; j++){ |
| 101822 | 102005 | char *zAs = pEList->a[j].zEName; |
| 101823 | | - if( pEList->a[j].eEName==ENAME_NAME |
| 102006 | + if( pEList->a[j].fg.eEName==ENAME_NAME |
| 101824 | 102007 | && sqlite3_stricmp(zAs, zCol)==0 |
| 101825 | 102008 | ){ |
| 101826 | 102009 | Expr *pOrig; |
| 101827 | 102010 | assert( pExpr->pLeft==0 && pExpr->pRight==0 ); |
| 101828 | 102011 | assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 ); |
| | @@ -102571,11 +102754,11 @@ |
| 102571 | 102754 | if( pE->op==TK_ID ){ |
| 102572 | 102755 | const char *zCol; |
| 102573 | 102756 | assert( !ExprHasProperty(pE, EP_IntValue) ); |
| 102574 | 102757 | zCol = pE->u.zToken; |
| 102575 | 102758 | for(i=0; i<pEList->nExpr; i++){ |
| 102576 | | - if( pEList->a[i].eEName==ENAME_NAME |
| 102759 | + if( pEList->a[i].fg.eEName==ENAME_NAME |
| 102577 | 102760 | && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0 |
| 102578 | 102761 | ){ |
| 102579 | 102762 | return i+1; |
| 102580 | 102763 | } |
| 102581 | 102764 | } |
| | @@ -102692,11 +102875,11 @@ |
| 102692 | 102875 | if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){ |
| 102693 | 102876 | sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause"); |
| 102694 | 102877 | return 1; |
| 102695 | 102878 | } |
| 102696 | 102879 | for(i=0; i<pOrderBy->nExpr; i++){ |
| 102697 | | - pOrderBy->a[i].done = 0; |
| 102880 | + pOrderBy->a[i].fg.done = 0; |
| 102698 | 102881 | } |
| 102699 | 102882 | pSelect->pNext = 0; |
| 102700 | 102883 | while( pSelect->pPrior ){ |
| 102701 | 102884 | pSelect->pPrior->pNext = pSelect; |
| 102702 | 102885 | pSelect = pSelect->pPrior; |
| | @@ -102707,11 +102890,11 @@ |
| 102707 | 102890 | pEList = pSelect->pEList; |
| 102708 | 102891 | assert( pEList!=0 ); |
| 102709 | 102892 | for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){ |
| 102710 | 102893 | int iCol = -1; |
| 102711 | 102894 | Expr *pE, *pDup; |
| 102712 | | - if( pItem->done ) continue; |
| 102895 | + if( pItem->fg.done ) continue; |
| 102713 | 102896 | pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr); |
| 102714 | 102897 | if( NEVER(pE==0) ) continue; |
| 102715 | 102898 | if( sqlite3ExprIsInteger(pE, &iCol) ){ |
| 102716 | 102899 | if( iCol<=0 || iCol>pEList->nExpr ){ |
| 102717 | 102900 | resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE); |
| | @@ -102760,19 +102943,19 @@ |
| 102760 | 102943 | pParent->pLeft = pNew; |
| 102761 | 102944 | } |
| 102762 | 102945 | sqlite3ExprDelete(db, pE); |
| 102763 | 102946 | pItem->u.x.iOrderByCol = (u16)iCol; |
| 102764 | 102947 | } |
| 102765 | | - pItem->done = 1; |
| 102948 | + pItem->fg.done = 1; |
| 102766 | 102949 | }else{ |
| 102767 | 102950 | moreToDo = 1; |
| 102768 | 102951 | } |
| 102769 | 102952 | } |
| 102770 | 102953 | pSelect = pSelect->pNext; |
| 102771 | 102954 | } |
| 102772 | 102955 | for(i=0; i<pOrderBy->nExpr; i++){ |
| 102773 | | - if( pOrderBy->a[i].done==0 ){ |
| 102956 | + if( pOrderBy->a[i].fg.done==0 ){ |
| 102774 | 102957 | sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any " |
| 102775 | 102958 | "column in the result set", i+1); |
| 102776 | 102959 | return 1; |
| 102777 | 102960 | } |
| 102778 | 102961 | } |
| | @@ -104911,10 +105094,11 @@ |
| 104911 | 105094 | pRet->nCte = p->nCte; |
| 104912 | 105095 | for(i=0; i<p->nCte; i++){ |
| 104913 | 105096 | pRet->a[i].pSelect = sqlite3SelectDup(db, p->a[i].pSelect, 0); |
| 104914 | 105097 | pRet->a[i].pCols = sqlite3ExprListDup(db, p->a[i].pCols, 0); |
| 104915 | 105098 | pRet->a[i].zName = sqlite3DbStrDup(db, p->a[i].zName); |
| 105099 | + pRet->a[i].eM10d = p->a[i].eM10d; |
| 104916 | 105100 | } |
| 104917 | 105101 | } |
| 104918 | 105102 | } |
| 104919 | 105103 | return pRet; |
| 104920 | 105104 | } |
| | @@ -105011,16 +105195,12 @@ |
| 105011 | 105195 | } |
| 105012 | 105196 | pNewExpr->pLeft = pPriorSelectColNew; |
| 105013 | 105197 | } |
| 105014 | 105198 | } |
| 105015 | 105199 | pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName); |
| 105016 | | - pItem->sortFlags = pOldItem->sortFlags; |
| 105017 | | - pItem->eEName = pOldItem->eEName; |
| 105018 | | - pItem->done = 0; |
| 105019 | | - pItem->bNulls = pOldItem->bNulls; |
| 105020 | | - pItem->bUsed = pOldItem->bUsed; |
| 105021 | | - pItem->bSorterRef = pOldItem->bSorterRef; |
| 105200 | + pItem->fg = pOldItem->fg; |
| 105201 | + pItem->fg.done = 0; |
| 105022 | 105202 | pItem->u = pOldItem->u; |
| 105023 | 105203 | } |
| 105024 | 105204 | return pNew; |
| 105025 | 105205 | } |
| 105026 | 105206 | |
| | @@ -105316,20 +105496,20 @@ |
| 105316 | 105496 | || eNulls==SQLITE_SO_ASC |
| 105317 | 105497 | || eNulls==SQLITE_SO_DESC |
| 105318 | 105498 | ); |
| 105319 | 105499 | |
| 105320 | 105500 | pItem = &p->a[p->nExpr-1]; |
| 105321 | | - assert( pItem->bNulls==0 ); |
| 105501 | + assert( pItem->fg.bNulls==0 ); |
| 105322 | 105502 | if( iSortOrder==SQLITE_SO_UNDEFINED ){ |
| 105323 | 105503 | iSortOrder = SQLITE_SO_ASC; |
| 105324 | 105504 | } |
| 105325 | | - pItem->sortFlags = (u8)iSortOrder; |
| 105505 | + pItem->fg.sortFlags = (u8)iSortOrder; |
| 105326 | 105506 | |
| 105327 | 105507 | if( eNulls!=SQLITE_SO_UNDEFINED ){ |
| 105328 | | - pItem->bNulls = 1; |
| 105508 | + pItem->fg.bNulls = 1; |
| 105329 | 105509 | if( iSortOrder!=eNulls ){ |
| 105330 | | - pItem->sortFlags |= KEYINFO_ORDER_BIGNULL; |
| 105510 | + pItem->fg.sortFlags |= KEYINFO_ORDER_BIGNULL; |
| 105331 | 105511 | } |
| 105332 | 105512 | } |
| 105333 | 105513 | } |
| 105334 | 105514 | |
| 105335 | 105515 | /* |
| | @@ -105351,11 +105531,11 @@ |
| 105351 | 105531 | if( pList ){ |
| 105352 | 105532 | struct ExprList_item *pItem; |
| 105353 | 105533 | assert( pList->nExpr>0 ); |
| 105354 | 105534 | pItem = &pList->a[pList->nExpr-1]; |
| 105355 | 105535 | assert( pItem->zEName==0 ); |
| 105356 | | - assert( pItem->eEName==ENAME_NAME ); |
| 105536 | + assert( pItem->fg.eEName==ENAME_NAME ); |
| 105357 | 105537 | pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n); |
| 105358 | 105538 | if( dequote ){ |
| 105359 | 105539 | /* If dequote==0, then pName->z does not point to part of a DDL |
| 105360 | 105540 | ** statement handled by the parser. And so no token need be added |
| 105361 | 105541 | ** to the token-map. */ |
| | @@ -105386,11 +105566,11 @@ |
| 105386 | 105566 | if( pList ){ |
| 105387 | 105567 | struct ExprList_item *pItem = &pList->a[pList->nExpr-1]; |
| 105388 | 105568 | assert( pList->nExpr>0 ); |
| 105389 | 105569 | if( pItem->zEName==0 ){ |
| 105390 | 105570 | pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd); |
| 105391 | | - pItem->eEName = ENAME_SPAN; |
| 105571 | + pItem->fg.eEName = ENAME_SPAN; |
| 105392 | 105572 | } |
| 105393 | 105573 | } |
| 105394 | 105574 | } |
| 105395 | 105575 | |
| 105396 | 105576 | /* |
| | @@ -105678,10 +105858,46 @@ |
| 105678 | 105858 | ** table other than iCur. |
| 105679 | 105859 | */ |
| 105680 | 105860 | SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){ |
| 105681 | 105861 | return exprIsConst(p, 3, iCur); |
| 105682 | 105862 | } |
| 105863 | + |
| 105864 | +/* |
| 105865 | +** Check pExpr to see if it is an invariant constraint on data source pSrc. |
| 105866 | +** This is an optimization. False negatives will perhaps cause slower |
| 105867 | +** queries, but false positives will yield incorrect answers. So when in |
| 105868 | +** doubt, return 0. |
| 105869 | +** |
| 105870 | +** To be an invariant constraint, the following must be true: |
| 105871 | +** |
| 105872 | +** (1) pExpr cannot refer to any table other than pSrc->iCursor. |
| 105873 | +** |
| 105874 | +** (2) pExpr cannot use subqueries or non-deterministic functions. |
| 105875 | +** |
| 105876 | +** (3) pSrc cannot be part of the left operand for a RIGHT JOIN. |
| 105877 | +** (Is there some way to relax this constraint?) |
| 105878 | +** |
| 105879 | +** (4) If pSrc is the right operand of a LEFT JOIN, then... |
| 105880 | +** (4a) pExpr must come from an ON clause.. |
| 105881 | + (4b) and specifically the ON clause associated with the LEFT JOIN. |
| 105882 | +** |
| 105883 | +** (5) If pSrc is not the right operand of a LEFT JOIN or the left |
| 105884 | +** operand of a RIGHT JOIN, then pExpr must be from the WHERE |
| 105885 | +** clause, not an ON clause. |
| 105886 | +*/ |
| 105887 | +SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr *pExpr, const SrcItem *pSrc){ |
| 105888 | + if( pSrc->fg.jointype & JT_LTORJ ){ |
| 105889 | + return 0; /* rule (3) */ |
| 105890 | + } |
| 105891 | + if( pSrc->fg.jointype & JT_LEFT ){ |
| 105892 | + if( !ExprHasProperty(pExpr, EP_FromJoin) ) return 0; /* rule (4a) */ |
| 105893 | + if( pExpr->w.iJoin!=pSrc->iCursor ) return 0; /* rule (4b) */ |
| 105894 | + }else{ |
| 105895 | + if( ExprHasProperty(pExpr, EP_FromJoin) ) return 0; /* rule (5) */ |
| 105896 | + } |
| 105897 | + return sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor); /* rules (1), (2) */ |
| 105898 | +} |
| 105683 | 105899 | |
| 105684 | 105900 | |
| 105685 | 105901 | /* |
| 105686 | 105902 | ** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy(). |
| 105687 | 105903 | */ |
| | @@ -106006,11 +106222,11 @@ |
| 106006 | 106222 | ** The job of this routine is to find or create a b-tree object that can |
| 106007 | 106223 | ** be used either to test for membership in the RHS set or to iterate through |
| 106008 | 106224 | ** all members of the RHS set, skipping duplicates. |
| 106009 | 106225 | ** |
| 106010 | 106226 | ** A cursor is opened on the b-tree object that is the RHS of the IN operator |
| 106011 | | -** and pX->iTable is set to the index of that cursor. |
| 106227 | +** and the *piTab parameter is set to the index of that cursor. |
| 106012 | 106228 | ** |
| 106013 | 106229 | ** The returned value of this function indicates the b-tree type, as follows: |
| 106014 | 106230 | ** |
| 106015 | 106231 | ** IN_INDEX_ROWID - The cursor was opened on a database table. |
| 106016 | 106232 | ** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index. |
| | @@ -106026,11 +106242,14 @@ |
| 106026 | 106242 | ** SELECT <column1>, <column2>... FROM <table> |
| 106027 | 106243 | ** |
| 106028 | 106244 | ** If the RHS of the IN operator is a list or a more complex subquery, then |
| 106029 | 106245 | ** an ephemeral table might need to be generated from the RHS and then |
| 106030 | 106246 | ** pX->iTable made to point to the ephemeral table instead of an |
| 106031 | | -** existing table. |
| 106247 | +** existing table. In this case, the creation and initialization of the |
| 106248 | +** ephmeral table might be put inside of a subroutine, the EP_Subrtn flag |
| 106249 | +** will be set on pX and the pX->y.sub fields will be set to show where |
| 106250 | +** the subroutine is coded. |
| 106032 | 106251 | ** |
| 106033 | 106252 | ** The inFlags parameter must contain, at a minimum, one of the bits |
| 106034 | 106253 | ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains |
| 106035 | 106254 | ** IN_INDEX_MEMBERSHIP, then the generated table will be used for a fast |
| 106036 | 106255 | ** membership test. When the IN_INDEX_LOOP bit is set, the IN index will |
| | @@ -106087,16 +106306,21 @@ |
| 106087 | 106306 | int *aiMap, /* Mapping from Index fields to RHS fields */ |
| 106088 | 106307 | int *piTab /* OUT: index to use */ |
| 106089 | 106308 | ){ |
| 106090 | 106309 | Select *p; /* SELECT to the right of IN operator */ |
| 106091 | 106310 | int eType = 0; /* Type of RHS table. IN_INDEX_* */ |
| 106092 | | - int iTab = pParse->nTab++; /* Cursor of the RHS table */ |
| 106311 | + int iTab; /* Cursor of the RHS table */ |
| 106093 | 106312 | int mustBeUnique; /* True if RHS must be unique */ |
| 106094 | 106313 | Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */ |
| 106095 | 106314 | |
| 106096 | 106315 | assert( pX->op==TK_IN ); |
| 106097 | 106316 | mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0; |
| 106317 | + if( pX->iTable && (inFlags & IN_INDEX_REUSE_CUR)!=0 ){ |
| 106318 | + iTab = pX->iTable; |
| 106319 | + }else{ |
| 106320 | + iTab = pParse->nTab++; |
| 106321 | + } |
| 106098 | 106322 | |
| 106099 | 106323 | /* If the RHS of this IN(...) operator is a SELECT, and if it matters |
| 106100 | 106324 | ** whether or not the SELECT result contains NULL values, check whether |
| 106101 | 106325 | ** or not NULL is actually possible (it may not be, for example, due |
| 106102 | 106326 | ** to NOT NULL constraints in the schema). If no NULL values are possible, |
| | @@ -106258,10 +106482,12 @@ |
| 106258 | 106482 | if( eType==0 |
| 106259 | 106483 | && (inFlags & IN_INDEX_NOOP_OK) |
| 106260 | 106484 | && ExprUseXList(pX) |
| 106261 | 106485 | && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2) |
| 106262 | 106486 | ){ |
| 106487 | + pParse->nTab--; /* Back out the allocation of the unused cursor */ |
| 106488 | + iTab = -1; /* Cursor is not allocated */ |
| 106263 | 106489 | eType = IN_INDEX_NOOP; |
| 106264 | 106490 | } |
| 106265 | 106491 | |
| 106266 | 106492 | if( eType==0 ){ |
| 106267 | 106493 | /* Could not find an existing table or index to use as the RHS b-tree. |
| | @@ -106424,11 +106650,13 @@ |
| 106424 | 106650 | pExpr->x.pSelect->selId)); |
| 106425 | 106651 | } |
| 106426 | 106652 | assert( ExprUseYSub(pExpr) ); |
| 106427 | 106653 | sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn, |
| 106428 | 106654 | pExpr->y.sub.iAddr); |
| 106429 | | - sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable); |
| 106655 | + if( iTab!=pExpr->iTable ){ |
| 106656 | + sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable); |
| 106657 | + } |
| 106430 | 106658 | sqlite3VdbeJumpHere(v, addrOnce); |
| 106431 | 106659 | return; |
| 106432 | 106660 | } |
| 106433 | 106661 | |
| 106434 | 106662 | /* Begin coding the subroutine */ |
| | @@ -108164,11 +108392,13 @@ |
| 108164 | 108392 | p = pParse->pConstExpr; |
| 108165 | 108393 | if( regDest<0 && p ){ |
| 108166 | 108394 | struct ExprList_item *pItem; |
| 108167 | 108395 | int i; |
| 108168 | 108396 | for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){ |
| 108169 | | - if( pItem->reusable && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0 ){ |
| 108397 | + if( pItem->fg.reusable |
| 108398 | + && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0 |
| 108399 | + ){ |
| 108170 | 108400 | return pItem->u.iConstExprReg; |
| 108171 | 108401 | } |
| 108172 | 108402 | } |
| 108173 | 108403 | } |
| 108174 | 108404 | pExpr = sqlite3ExprDup(pParse->db, pExpr, 0); |
| | @@ -108187,11 +108417,11 @@ |
| 108187 | 108417 | sqlite3VdbeJumpHere(v, addr); |
| 108188 | 108418 | }else{ |
| 108189 | 108419 | p = sqlite3ExprListAppend(pParse, p, pExpr); |
| 108190 | 108420 | if( p ){ |
| 108191 | 108421 | struct ExprList_item *pItem = &p->a[p->nExpr-1]; |
| 108192 | | - pItem->reusable = regDest<0; |
| 108422 | + pItem->fg.reusable = regDest<0; |
| 108193 | 108423 | if( regDest<0 ) regDest = ++pParse->nMem; |
| 108194 | 108424 | pItem->u.iConstExprReg = regDest; |
| 108195 | 108425 | } |
| 108196 | 108426 | pParse->pConstExpr = p; |
| 108197 | 108427 | } |
| | @@ -108321,11 +108551,11 @@ |
| 108321 | 108551 | n = pList->nExpr; |
| 108322 | 108552 | if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR; |
| 108323 | 108553 | for(pItem=pList->a, i=0; i<n; i++, pItem++){ |
| 108324 | 108554 | Expr *pExpr = pItem->pExpr; |
| 108325 | 108555 | #ifdef SQLITE_ENABLE_SORTER_REFERENCES |
| 108326 | | - if( pItem->bSorterRef ){ |
| 108556 | + if( pItem->fg.bSorterRef ){ |
| 108327 | 108557 | i--; |
| 108328 | 108558 | n--; |
| 108329 | 108559 | }else |
| 108330 | 108560 | #endif |
| 108331 | 108561 | if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){ |
| | @@ -108946,11 +109176,11 @@ |
| 108946 | 109176 | if( pA->nExpr!=pB->nExpr ) return 1; |
| 108947 | 109177 | for(i=0; i<pA->nExpr; i++){ |
| 108948 | 109178 | int res; |
| 108949 | 109179 | Expr *pExprA = pA->a[i].pExpr; |
| 108950 | 109180 | Expr *pExprB = pB->a[i].pExpr; |
| 108951 | | - if( pA->a[i].sortFlags!=pB->a[i].sortFlags ) return 1; |
| 109181 | + if( pA->a[i].fg.sortFlags!=pB->a[i].fg.sortFlags ) return 1; |
| 108952 | 109182 | if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res; |
| 108953 | 109183 | } |
| 108954 | 109184 | return 0; |
| 108955 | 109185 | } |
| 108956 | 109186 | |
| | @@ -110635,11 +110865,11 @@ |
| 110635 | 110865 | return WRC_Prune; |
| 110636 | 110866 | } |
| 110637 | 110867 | if( ALWAYS(p->pEList) ){ |
| 110638 | 110868 | ExprList *pList = p->pEList; |
| 110639 | 110869 | for(i=0; i<pList->nExpr; i++){ |
| 110640 | | - if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){ |
| 110870 | + if( pList->a[i].zEName && pList->a[i].fg.eEName==ENAME_NAME ){ |
| 110641 | 110871 | sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName); |
| 110642 | 110872 | } |
| 110643 | 110873 | } |
| 110644 | 110874 | } |
| 110645 | 110875 | if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */ |
| | @@ -110684,11 +110914,11 @@ |
| 110684 | 110914 | memset(&sWalker, 0, sizeof(Walker)); |
| 110685 | 110915 | sWalker.pParse = pParse; |
| 110686 | 110916 | sWalker.xExprCallback = renameUnmapExprCb; |
| 110687 | 110917 | sqlite3WalkExprList(&sWalker, pEList); |
| 110688 | 110918 | for(i=0; i<pEList->nExpr; i++){ |
| 110689 | | - if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) ){ |
| 110919 | + if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME) ){ |
| 110690 | 110920 | sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName); |
| 110691 | 110921 | } |
| 110692 | 110922 | } |
| 110693 | 110923 | } |
| 110694 | 110924 | } |
| | @@ -110842,11 +111072,11 @@ |
| 110842 | 111072 | ){ |
| 110843 | 111073 | if( pEList ){ |
| 110844 | 111074 | int i; |
| 110845 | 111075 | for(i=0; i<pEList->nExpr; i++){ |
| 110846 | 111076 | const char *zName = pEList->a[i].zEName; |
| 110847 | | - if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) |
| 111077 | + if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME) |
| 110848 | 111078 | && ALWAYS(zName!=0) |
| 110849 | 111079 | && 0==sqlite3_stricmp(zName, zOld) |
| 110850 | 111080 | ){ |
| 110851 | 111081 | renameTokenFind(pParse, pCtx, (const void*)zName); |
| 110852 | 111082 | } |
| | @@ -112867,13 +113097,18 @@ |
| 112867 | 113097 | ** * the index contains 100 rows, |
| 112868 | 113098 | ** * "WHERE a=?" matches 10 rows, and |
| 112869 | 113099 | ** * "WHERE a=? AND b=?" matches 2 rows. |
| 112870 | 113100 | ** |
| 112871 | 113101 | ** If D is the count of distinct values and K is the total number of |
| 112872 | | - ** rows, then each estimate is computed as: |
| 113102 | + ** rows, then each estimate is usually computed as: |
| 112873 | 113103 | ** |
| 112874 | 113104 | ** I = (K+D-1)/D |
| 113105 | + ** |
| 113106 | + ** In other words, I is K/D rounded up to the next whole integer. |
| 113107 | + ** However, if I is between 1.0 and 1.1 (in other words if I is |
| 113108 | + ** close to 1.0 but just a little larger) then do not round up but |
| 113109 | + ** instead keep the I value at 1.0. |
| 112875 | 113110 | */ |
| 112876 | 113111 | sqlite3_str sStat; /* Text of the constructed "stat" line */ |
| 112877 | 113112 | int i; /* Loop counter */ |
| 112878 | 113113 | |
| 112879 | 113114 | sqlite3StrAccumInit(&sStat, 0, 0, 0, (p->nKeyCol+1)*100); |
| | @@ -112880,10 +113115,11 @@ |
| 112880 | 113115 | sqlite3_str_appendf(&sStat, "%llu", |
| 112881 | 113116 | p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow); |
| 112882 | 113117 | for(i=0; i<p->nKeyCol; i++){ |
| 112883 | 113118 | u64 nDistinct = p->current.anDLt[i] + 1; |
| 112884 | 113119 | u64 iVal = (p->nRow + nDistinct - 1) / nDistinct; |
| 113120 | + if( iVal==2 && p->nRow*10 <= nDistinct*11 ) iVal = 1; |
| 112885 | 113121 | sqlite3_str_appendf(&sStat, " %llu", iVal); |
| 112886 | 113122 | assert( p->current.anEq[i] ); |
| 112887 | 113123 | } |
| 112888 | 113124 | sqlite3ResultStrAccum(context, &sStat); |
| 112889 | 113125 | } |
| | @@ -115001,13 +115237,11 @@ |
| 115001 | 115237 | Returning *pReturning = pParse->u1.pReturning; |
| 115002 | 115238 | int addrRewind; |
| 115003 | 115239 | int i; |
| 115004 | 115240 | int reg; |
| 115005 | 115241 | |
| 115006 | | - if( NEVER(pReturning->nRetCol==0) ){ |
| 115007 | | - assert( CORRUPT_DB ); |
| 115008 | | - }else{ |
| 115242 | + if( pReturning->nRetCol ){ |
| 115009 | 115243 | sqlite3VdbeAddOp0(v, OP_FkCheck); |
| 115010 | 115244 | addrRewind = |
| 115011 | 115245 | sqlite3VdbeAddOp1(v, OP_Rewind, pReturning->iRetCur); |
| 115012 | 115246 | VdbeCoverage(v); |
| 115013 | 115247 | reg = pReturning->iRetReg; |
| | @@ -115099,13 +115333,11 @@ |
| 115099 | 115333 | } |
| 115100 | 115334 | } |
| 115101 | 115335 | |
| 115102 | 115336 | if( pParse->bReturning ){ |
| 115103 | 115337 | Returning *pRet = pParse->u1.pReturning; |
| 115104 | | - if( NEVER(pRet->nRetCol==0) ){ |
| 115105 | | - assert( CORRUPT_DB ); |
| 115106 | | - }else{ |
| 115338 | + if( pRet->nRetCol ){ |
| 115107 | 115339 | sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pRet->iRetCur, pRet->nRetCol); |
| 115108 | 115340 | } |
| 115109 | 115341 | } |
| 115110 | 115342 | |
| 115111 | 115343 | /* Finally, jump back to the beginning of the executable code. */ |
| | @@ -116723,11 +116955,11 @@ |
| 116723 | 116955 | } |
| 116724 | 116956 | pTab->iPKey = iCol; |
| 116725 | 116957 | pTab->keyConf = (u8)onError; |
| 116726 | 116958 | assert( autoInc==0 || autoInc==1 ); |
| 116727 | 116959 | pTab->tabFlags |= autoInc*TF_Autoincrement; |
| 116728 | | - if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags; |
| 116960 | + if( pList ) pParse->iPkSortOrder = pList->a[0].fg.sortFlags; |
| 116729 | 116961 | (void)sqlite3HasExplicitNulls(pParse, pList); |
| 116730 | 116962 | }else if( autoInc ){ |
| 116731 | 116963 | #ifndef SQLITE_OMIT_AUTOINCREMENT |
| 116732 | 116964 | sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an " |
| 116733 | 116965 | "INTEGER PRIMARY KEY"); |
| | @@ -117217,11 +117449,11 @@ |
| 117217 | 117449 | return; |
| 117218 | 117450 | } |
| 117219 | 117451 | if( IN_RENAME_OBJECT ){ |
| 117220 | 117452 | sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey); |
| 117221 | 117453 | } |
| 117222 | | - pList->a[0].sortFlags = pParse->iPkSortOrder; |
| 117454 | + pList->a[0].fg.sortFlags = pParse->iPkSortOrder; |
| 117223 | 117455 | assert( pParse->pNewTable==pTab ); |
| 117224 | 117456 | pTab->iPKey = -1; |
| 117225 | 117457 | sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0, |
| 117226 | 117458 | SQLITE_IDXTYPE_PRIMARYKEY); |
| 117227 | 117459 | if( pParse->nErr ){ |
| | @@ -117888,11 +118120,10 @@ |
| 117888 | 118120 | */ |
| 117889 | 118121 | SQLITE_PRIVATE int sqlite3ViewGetColumnNames(Parse *pParse, Table *pTable){ |
| 117890 | 118122 | Table *pSelTab; /* A fake table from which we get the result set */ |
| 117891 | 118123 | Select *pSel; /* Copy of the SELECT that implements the view */ |
| 117892 | 118124 | int nErr = 0; /* Number of errors encountered */ |
| 117893 | | - int n; /* Temporarily holds the number of cursors assigned */ |
| 117894 | 118125 | sqlite3 *db = pParse->db; /* Database connection for malloc errors */ |
| 117895 | 118126 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 117896 | 118127 | int rc; |
| 117897 | 118128 | #endif |
| 117898 | 118129 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| | @@ -117946,12 +118177,13 @@ |
| 117946 | 118177 | */ |
| 117947 | 118178 | assert( IsView(pTable) ); |
| 117948 | 118179 | pSel = sqlite3SelectDup(db, pTable->u.view.pSelect, 0); |
| 117949 | 118180 | if( pSel ){ |
| 117950 | 118181 | u8 eParseMode = pParse->eParseMode; |
| 118182 | + int nTab = pParse->nTab; |
| 118183 | + int nSelect = pParse->nSelect; |
| 117951 | 118184 | pParse->eParseMode = PARSE_MODE_NORMAL; |
| 117952 | | - n = pParse->nTab; |
| 117953 | 118185 | sqlite3SrcListAssignCursors(pParse, pSel->pSrc); |
| 117954 | 118186 | pTable->nCol = -1; |
| 117955 | 118187 | DisableLookaside; |
| 117956 | 118188 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| 117957 | 118189 | xAuth = db->xAuth; |
| | @@ -117959,11 +118191,12 @@ |
| 117959 | 118191 | pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE); |
| 117960 | 118192 | db->xAuth = xAuth; |
| 117961 | 118193 | #else |
| 117962 | 118194 | pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE); |
| 117963 | 118195 | #endif |
| 117964 | | - pParse->nTab = n; |
| 118196 | + pParse->nTab = nTab; |
| 118197 | + pParse->nSelect = nSelect; |
| 117965 | 118198 | if( pSelTab==0 ){ |
| 117966 | 118199 | pTable->nCol = 0; |
| 117967 | 118200 | nErr++; |
| 117968 | 118201 | }else if( pTable->pCheck ){ |
| 117969 | 118202 | /* CREATE VIEW name(arglist) AS ... |
| | @@ -118704,12 +118937,12 @@ |
| 118704 | 118937 | */ |
| 118705 | 118938 | SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){ |
| 118706 | 118939 | if( pList ){ |
| 118707 | 118940 | int i; |
| 118708 | 118941 | for(i=0; i<pList->nExpr; i++){ |
| 118709 | | - if( pList->a[i].bNulls ){ |
| 118710 | | - u8 sf = pList->a[i].sortFlags; |
| 118942 | + if( pList->a[i].fg.bNulls ){ |
| 118943 | + u8 sf = pList->a[i].fg.sortFlags; |
| 118711 | 118944 | sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s", |
| 118712 | 118945 | (sf==0 || sf==3) ? "FIRST" : "LAST" |
| 118713 | 118946 | ); |
| 118714 | 118947 | return 1; |
| 118715 | 118948 | } |
| | @@ -119058,11 +119291,11 @@ |
| 119058 | 119291 | if( !zColl ) zColl = sqlite3StrBINARY; |
| 119059 | 119292 | if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){ |
| 119060 | 119293 | goto exit_create_index; |
| 119061 | 119294 | } |
| 119062 | 119295 | pIndex->azColl[i] = zColl; |
| 119063 | | - requestedSortOrder = pListItem->sortFlags & sortOrderMask; |
| 119296 | + requestedSortOrder = pListItem->fg.sortFlags & sortOrderMask; |
| 119064 | 119297 | pIndex->aSortOrder[i] = (u8)requestedSortOrder; |
| 119065 | 119298 | } |
| 119066 | 119299 | |
| 119067 | 119300 | /* Append the table key to the end of the index. For WITHOUT ROWID |
| 119068 | 119301 | ** tables (when pPk!=0) this will be the declared PRIMARY KEY. For |
| | @@ -130380,15 +130613,23 @@ |
| 130380 | 130613 | sqlite3_total_changes64, |
| 130381 | 130614 | /* Version 3.37.0 and later */ |
| 130382 | 130615 | sqlite3_autovacuum_pages, |
| 130383 | 130616 | /* Version 3.38.0 and later */ |
| 130384 | 130617 | sqlite3_error_offset, |
| 130618 | +#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 130385 | 130619 | sqlite3_vtab_rhs_value, |
| 130386 | 130620 | sqlite3_vtab_distinct, |
| 130387 | 130621 | sqlite3_vtab_in, |
| 130388 | 130622 | sqlite3_vtab_in_first, |
| 130389 | 130623 | sqlite3_vtab_in_next, |
| 130624 | +#else |
| 130625 | + 0, |
| 130626 | + 0, |
| 130627 | + 0, |
| 130628 | + 0, |
| 130629 | + 0, |
| 130630 | +#endif |
| 130390 | 130631 | /* Version 3.39.0 and later */ |
| 130391 | 130632 | #ifndef SQLITE_OMIT_DESERIALIZE |
| 130392 | 130633 | sqlite3_deserialize, |
| 130393 | 130634 | sqlite3_serialize |
| 130394 | 130635 | #else |
| | @@ -134828,10 +135069,18 @@ |
| 134828 | 135069 | db->pParse = pParse; |
| 134829 | 135070 | pParse->db = db; |
| 134830 | 135071 | if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory"); |
| 134831 | 135072 | } |
| 134832 | 135073 | |
| 135074 | +/* |
| 135075 | +** Maximum number of times that we will try again to prepare a statement |
| 135076 | +** that returns SQLITE_ERROR_RETRY. |
| 135077 | +*/ |
| 135078 | +#ifndef SQLITE_MAX_PREPARE_RETRY |
| 135079 | +# define SQLITE_MAX_PREPARE_RETRY 25 |
| 135080 | +#endif |
| 135081 | + |
| 134833 | 135082 | /* |
| 134834 | 135083 | ** Compile the UTF-8 encoded SQL statement zSql into a statement handle. |
| 134835 | 135084 | */ |
| 134836 | 135085 | static int sqlite3Prepare( |
| 134837 | 135086 | sqlite3 *db, /* Database handle. */ |
| | @@ -135002,11 +135251,11 @@ |
| 135002 | 135251 | ** or encounters a permanent error. A schema problem after one schema |
| 135003 | 135252 | ** reset is considered a permanent error. */ |
| 135004 | 135253 | rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail); |
| 135005 | 135254 | assert( rc==SQLITE_OK || *ppStmt==0 ); |
| 135006 | 135255 | if( rc==SQLITE_OK || db->mallocFailed ) break; |
| 135007 | | - }while( rc==SQLITE_ERROR_RETRY |
| 135256 | + }while( (rc==SQLITE_ERROR_RETRY && (cnt++)<SQLITE_MAX_PREPARE_RETRY) |
| 135008 | 135257 | || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) ); |
| 135009 | 135258 | sqlite3BtreeLeaveAll(db); |
| 135010 | 135259 | rc = sqlite3ApiExit(db, rc); |
| 135011 | 135260 | assert( (rc&db->errMask)==rc ); |
| 135012 | 135261 | db->busyHandler.nBusy = 0; |
| | @@ -135553,11 +135802,11 @@ |
| 135553 | 135802 | ExprList *pResults; |
| 135554 | 135803 | assert( pItem->pSelect!=0 ); |
| 135555 | 135804 | pResults = pItem->pSelect->pEList; |
| 135556 | 135805 | assert( pResults!=0 ); |
| 135557 | 135806 | assert( iCol>=0 && iCol<pResults->nExpr ); |
| 135558 | | - pResults->a[iCol].bUsed = 1; |
| 135807 | + pResults->a[iCol].fg.bUsed = 1; |
| 135559 | 135808 | } |
| 135560 | 135809 | } |
| 135561 | 135810 | |
| 135562 | 135811 | /* |
| 135563 | 135812 | ** Search the tables iStart..iEnd (inclusive) in pSrc, looking for a |
| | @@ -136221,11 +136470,11 @@ |
| 136221 | 136470 | ** the row from table t1 is stored instead. Then, as records are extracted from |
| 136222 | 136471 | ** the sorter to return to the user, the required value of bigblob is |
| 136223 | 136472 | ** retrieved directly from table t1. If the values are very large, this |
| 136224 | 136473 | ** can be more efficient than storing them directly in the sorter records. |
| 136225 | 136474 | ** |
| 136226 | | -** The ExprList_item.bSorterRef flag is set for each expression in pEList |
| 136475 | +** The ExprList_item.fg.bSorterRef flag is set for each expression in pEList |
| 136227 | 136476 | ** for which the sorter-reference optimization should be enabled. |
| 136228 | 136477 | ** Additionally, the pSort->aDefer[] array is populated with entries |
| 136229 | 136478 | ** for all cursors required to evaluate all selected expressions. Finally. |
| 136230 | 136479 | ** output variable (*ppExtra) is set to an expression list containing |
| 136231 | 136480 | ** expressions for all extra PK values that should be stored in the |
| | @@ -136281,11 +136530,11 @@ |
| 136281 | 136530 | pSort->aDefer[nDefer].iCsr = pExpr->iTable; |
| 136282 | 136531 | pSort->aDefer[nDefer].nKey = nKey; |
| 136283 | 136532 | nDefer++; |
| 136284 | 136533 | } |
| 136285 | 136534 | } |
| 136286 | | - pItem->bSorterRef = 1; |
| 136535 | + pItem->fg.bSorterRef = 1; |
| 136287 | 136536 | } |
| 136288 | 136537 | } |
| 136289 | 136538 | } |
| 136290 | 136539 | pSort->nDefer = (u8)nDefer; |
| 136291 | 136540 | *ppExtra = pExtra; |
| | @@ -136412,11 +136661,11 @@ |
| 136412 | 136661 | ** from the sorter by the optimizations in this branch */ |
| 136413 | 136662 | pEList = p->pEList; |
| 136414 | 136663 | for(i=0; i<pEList->nExpr; i++){ |
| 136415 | 136664 | if( pEList->a[i].u.x.iOrderByCol>0 |
| 136416 | 136665 | #ifdef SQLITE_ENABLE_SORTER_REFERENCES |
| 136417 | | - || pEList->a[i].bSorterRef |
| 136666 | + || pEList->a[i].fg.bSorterRef |
| 136418 | 136667 | #endif |
| 136419 | 136668 | ){ |
| 136420 | 136669 | nResultCol--; |
| 136421 | 136670 | regOrig = 0; |
| 136422 | 136671 | } |
| | @@ -136774,11 +137023,11 @@ |
| 136774 | 137023 | pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1); |
| 136775 | 137024 | if( pInfo ){ |
| 136776 | 137025 | assert( sqlite3KeyInfoIsWriteable(pInfo) ); |
| 136777 | 137026 | for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){ |
| 136778 | 137027 | pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr); |
| 136779 | | - pInfo->aSortFlags[i-iStart] = pItem->sortFlags; |
| 137028 | + pInfo->aSortFlags[i-iStart] = pItem->fg.sortFlags; |
| 136780 | 137029 | } |
| 136781 | 137030 | } |
| 136782 | 137031 | return pInfo; |
| 136783 | 137032 | } |
| 136784 | 137033 | |
| | @@ -136913,11 +137162,11 @@ |
| 136913 | 137162 | iSortTab = iTab; |
| 136914 | 137163 | bSeq = 1; |
| 136915 | 137164 | } |
| 136916 | 137165 | for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){ |
| 136917 | 137166 | #ifdef SQLITE_ENABLE_SORTER_REFERENCES |
| 136918 | | - if( aOutEx[i].bSorterRef ) continue; |
| 137167 | + if( aOutEx[i].fg.bSorterRef ) continue; |
| 136919 | 137168 | #endif |
| 136920 | 137169 | if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++; |
| 136921 | 137170 | } |
| 136922 | 137171 | #ifdef SQLITE_ENABLE_SORTER_REFERENCES |
| 136923 | 137172 | if( pSort->nDefer ){ |
| | @@ -136950,11 +137199,11 @@ |
| 136950 | 137199 | sqlite3ReleaseTempRange(pParse, regKey, nRefKey); |
| 136951 | 137200 | } |
| 136952 | 137201 | #endif |
| 136953 | 137202 | for(i=nColumn-1; i>=0; i--){ |
| 136954 | 137203 | #ifdef SQLITE_ENABLE_SORTER_REFERENCES |
| 136955 | | - if( aOutEx[i].bSorterRef ){ |
| 137204 | + if( aOutEx[i].fg.bSorterRef ){ |
| 136956 | 137205 | sqlite3ExprCode(pParse, aOutEx[i].pExpr, regRow+i); |
| 136957 | 137206 | }else |
| 136958 | 137207 | #endif |
| 136959 | 137208 | { |
| 136960 | 137209 | int iRead; |
| | @@ -137316,11 +137565,11 @@ |
| 137316 | 137565 | |
| 137317 | 137566 | assert( p!=0 ); |
| 137318 | 137567 | assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */ |
| 137319 | 137568 | assert( p->op!=TK_COLUMN |
| 137320 | 137569 | || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */ |
| 137321 | | - if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){ |
| 137570 | + if( pEList->a[i].zEName && pEList->a[i].fg.eEName==ENAME_NAME ){ |
| 137322 | 137571 | /* An AS clause always takes first priority */ |
| 137323 | 137572 | char *zName = pEList->a[i].zEName; |
| 137324 | 137573 | sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT); |
| 137325 | 137574 | }else if( srcName && p->op==TK_COLUMN ){ |
| 137326 | 137575 | char *zCol; |
| | @@ -137402,13 +137651,14 @@ |
| 137402 | 137651 | *pnCol = nCol; |
| 137403 | 137652 | *paCol = aCol; |
| 137404 | 137653 | |
| 137405 | 137654 | for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){ |
| 137406 | 137655 | struct ExprList_item *pX = &pEList->a[i]; |
| 137656 | + struct ExprList_item *pCollide; |
| 137407 | 137657 | /* Get an appropriate name for the column |
| 137408 | 137658 | */ |
| 137409 | | - if( (zName = pX->zEName)!=0 && pX->eEName==ENAME_NAME ){ |
| 137659 | + if( (zName = pX->zEName)!=0 && pX->fg.eEName==ENAME_NAME ){ |
| 137410 | 137660 | /* If the column contains an "AS <name>" phrase, use <name> as the name */ |
| 137411 | 137661 | }else{ |
| 137412 | 137662 | Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pX->pExpr); |
| 137413 | 137663 | while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){ |
| 137414 | 137664 | pColExpr = pColExpr->pRight; |
| | @@ -137438,11 +137688,14 @@ |
| 137438 | 137688 | |
| 137439 | 137689 | /* Make sure the column name is unique. If the name is not unique, |
| 137440 | 137690 | ** append an integer to the name so that it becomes unique. |
| 137441 | 137691 | */ |
| 137442 | 137692 | cnt = 0; |
| 137443 | | - while( zName && sqlite3HashFind(&ht, zName)!=0 ){ |
| 137693 | + while( zName && (pCollide = sqlite3HashFind(&ht, zName))!=0 ){ |
| 137694 | + if( pCollide->fg.bUsingTerm ){ |
| 137695 | + pCol->colFlags |= COLFLAG_NOEXPAND; |
| 137696 | + } |
| 137444 | 137697 | nName = sqlite3Strlen30(zName); |
| 137445 | 137698 | if( nName>0 ){ |
| 137446 | 137699 | for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){} |
| 137447 | 137700 | if( zName[j]==':' ) nName = j; |
| 137448 | 137701 | } |
| | @@ -137449,12 +137702,15 @@ |
| 137449 | 137702 | zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt); |
| 137450 | 137703 | if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt); |
| 137451 | 137704 | } |
| 137452 | 137705 | pCol->zCnName = zName; |
| 137453 | 137706 | pCol->hName = sqlite3StrIHash(zName); |
| 137707 | + if( pX->fg.bNoExpand ){ |
| 137708 | + pCol->colFlags |= COLFLAG_NOEXPAND; |
| 137709 | + } |
| 137454 | 137710 | sqlite3ColumnPropertiesFromName(0, pCol); |
| 137455 | | - if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){ |
| 137711 | + if( zName && sqlite3HashInsert(&ht, zName, pX)==pX ){ |
| 137456 | 137712 | sqlite3OomFault(db); |
| 137457 | 137713 | } |
| 137458 | 137714 | } |
| 137459 | 137715 | sqlite3HashClear(&ht); |
| 137460 | 137716 | if( db->mallocFailed ){ |
| | @@ -137707,11 +137963,11 @@ |
| 137707 | 137963 | pOrderBy->a[i].pExpr = |
| 137708 | 137964 | sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName); |
| 137709 | 137965 | } |
| 137710 | 137966 | assert( sqlite3KeyInfoIsWriteable(pRet) ); |
| 137711 | 137967 | pRet->aColl[i] = pColl; |
| 137712 | | - pRet->aSortFlags[i] = pOrderBy->a[i].sortFlags; |
| 137968 | + pRet->aSortFlags[i] = pOrderBy->a[i].fg.sortFlags; |
| 137713 | 137969 | } |
| 137714 | 137970 | } |
| 137715 | 137971 | |
| 137716 | 137972 | return pRet; |
| 137717 | 137973 | } |
| | @@ -139375,10 +139631,12 @@ |
| 139375 | 139631 | ** See also (3) for restrictions on LEFT JOIN. |
| 139376 | 139632 | ** |
| 139377 | 139633 | ** (27) The subquery may not contain a FULL or RIGHT JOIN unless it |
| 139378 | 139634 | ** is the first element of the parent query. |
| 139379 | 139635 | ** |
| 139636 | +** (28) The subquery is not a MATERIALIZED CTE. |
| 139637 | +** |
| 139380 | 139638 | ** |
| 139381 | 139639 | ** In this routine, the "p" parameter is a pointer to the outer query. |
| 139382 | 139640 | ** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query |
| 139383 | 139641 | ** uses aggregates. |
| 139384 | 139642 | ** |
| | @@ -139498,10 +139756,13 @@ |
| 139498 | 139756 | |
| 139499 | 139757 | assert( pSubSrc->nSrc>0 ); /* True by restriction (7) */ |
| 139500 | 139758 | if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){ |
| 139501 | 139759 | return 0; /* Restriction (27) */ |
| 139502 | 139760 | } |
| 139761 | + if( pSubitem->fg.isCte && pSubitem->u2.pCteUse->eM10d==M10d_Yes ){ |
| 139762 | + return 0; /* (28) */ |
| 139763 | + } |
| 139503 | 139764 | |
| 139504 | 139765 | /* Restriction (17): If the sub-query is a compound SELECT, then it must |
| 139505 | 139766 | ** use only the UNION ALL operator. And none of the simple select queries |
| 139506 | 139767 | ** that make up the compound SELECT are allowed to be aggregate or distinct |
| 139507 | 139768 | ** queries. |
| | @@ -139542,10 +139803,11 @@ |
| 139542 | 139803 | /* Restriction (23) */ |
| 139543 | 139804 | if( (p->selFlags & SF_Recursive) ) return 0; |
| 139544 | 139805 | |
| 139545 | 139806 | if( pSrc->nSrc>1 ){ |
| 139546 | 139807 | if( pParse->nSelect>500 ) return 0; |
| 139808 | + if( OptimizationDisabled(db, SQLITE_FlttnUnionAll) ) return 0; |
| 139547 | 139809 | aCsrMap = sqlite3DbMallocZero(db, ((i64)pParse->nTab+1)*sizeof(int)); |
| 139548 | 139810 | if( aCsrMap ) aCsrMap[0] = pParse->nTab; |
| 139549 | 139811 | } |
| 139550 | 139812 | } |
| 139551 | 139813 | |
| | @@ -140170,17 +140432,17 @@ |
| 140170 | 140432 | */ |
| 140171 | 140433 | static int pushDownWhereTerms( |
| 140172 | 140434 | Parse *pParse, /* Parse context (for malloc() and error reporting) */ |
| 140173 | 140435 | Select *pSubq, /* The subquery whose WHERE clause is to be augmented */ |
| 140174 | 140436 | Expr *pWhere, /* The WHERE clause of the outer query */ |
| 140175 | | - int iCursor, /* Cursor number of the subquery */ |
| 140176 | | - int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */ |
| 140437 | + SrcItem *pSrc /* The subquery term of the outer FROM clause */ |
| 140177 | 140438 | ){ |
| 140178 | 140439 | Expr *pNew; |
| 140179 | 140440 | int nChng = 0; |
| 140180 | 140441 | if( pWhere==0 ) return 0; |
| 140181 | 140442 | if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ) return 0; |
| 140443 | + if( pSrc->fg.jointype & (JT_LTORJ|JT_RIGHT) ) return 0; |
| 140182 | 140444 | |
| 140183 | 140445 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 140184 | 140446 | if( pSubq->pPrior ){ |
| 140185 | 140447 | Select *pSel; |
| 140186 | 140448 | for(pSel=pSubq; pSel; pSel=pSel->pPrior){ |
| | @@ -140206,14 +140468,15 @@ |
| 140206 | 140468 | |
| 140207 | 140469 | if( pSubq->pLimit!=0 ){ |
| 140208 | 140470 | return 0; /* restriction (3) */ |
| 140209 | 140471 | } |
| 140210 | 140472 | while( pWhere->op==TK_AND ){ |
| 140211 | | - nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, |
| 140212 | | - iCursor, isLeftJoin); |
| 140473 | + nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, pSrc); |
| 140213 | 140474 | pWhere = pWhere->pLeft; |
| 140214 | 140475 | } |
| 140476 | + |
| 140477 | +#if 0 /* Legacy code. Checks now done by sqlite3ExprIsTableConstraint() */ |
| 140215 | 140478 | if( isLeftJoin |
| 140216 | 140479 | && (ExprHasProperty(pWhere,EP_FromJoin)==0 |
| 140217 | 140480 | || pWhere->w.iJoin!=iCursor) |
| 140218 | 140481 | ){ |
| 140219 | 140482 | return 0; /* restriction (4) */ |
| | @@ -140221,20 +140484,22 @@ |
| 140221 | 140484 | if( ExprHasProperty(pWhere,EP_FromJoin) |
| 140222 | 140485 | && pWhere->w.iJoin!=iCursor |
| 140223 | 140486 | ){ |
| 140224 | 140487 | return 0; /* restriction (5) */ |
| 140225 | 140488 | } |
| 140226 | | - if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){ |
| 140489 | +#endif |
| 140490 | + |
| 140491 | + if( sqlite3ExprIsTableConstraint(pWhere, pSrc) ){ |
| 140227 | 140492 | nChng++; |
| 140228 | 140493 | pSubq->selFlags |= SF_PushDown; |
| 140229 | 140494 | while( pSubq ){ |
| 140230 | 140495 | SubstContext x; |
| 140231 | 140496 | pNew = sqlite3ExprDup(pParse->db, pWhere, 0); |
| 140232 | 140497 | unsetJoinExpr(pNew, -1); |
| 140233 | 140498 | x.pParse = pParse; |
| 140234 | | - x.iTable = iCursor; |
| 140235 | | - x.iNewTable = iCursor; |
| 140499 | + x.iTable = pSrc->iCursor; |
| 140500 | + x.iNewTable = pSrc->iCursor; |
| 140236 | 140501 | x.isOuterJoin = 0; |
| 140237 | 140502 | x.pEList = pSubq->pEList; |
| 140238 | 140503 | pNew = substExpr(&x, pNew); |
| 140239 | 140504 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 140240 | 140505 | if( pSubq->pWin && 0==pushDownWindowCheck(pParse, pSubq, pNew) ){ |
| | @@ -140304,11 +140569,11 @@ |
| 140304 | 140569 | }else{ |
| 140305 | 140570 | return eRet; |
| 140306 | 140571 | } |
| 140307 | 140572 | *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0); |
| 140308 | 140573 | assert( pOrderBy!=0 || db->mallocFailed ); |
| 140309 | | - if( pOrderBy ) pOrderBy->a[0].sortFlags = sortFlags; |
| 140574 | + if( pOrderBy ) pOrderBy->a[0].fg.sortFlags = sortFlags; |
| 140310 | 140575 | return eRet; |
| 140311 | 140576 | } |
| 140312 | 140577 | |
| 140313 | 140578 | /* |
| 140314 | 140579 | ** The select statement passed as the first argument is an aggregate query. |
| | @@ -140773,11 +141038,11 @@ |
| 140773 | 141038 | if( pTab==0 ) return SQLITE_NOMEM; |
| 140774 | 141039 | pTab->nTabRef = 1; |
| 140775 | 141040 | if( pFrom->zAlias ){ |
| 140776 | 141041 | pTab->zName = sqlite3DbStrDup(pParse->db, pFrom->zAlias); |
| 140777 | 141042 | }else{ |
| 140778 | | - pTab->zName = sqlite3MPrintf(pParse->db, "subquery_%u", pSel->selId); |
| 141043 | + pTab->zName = sqlite3MPrintf(pParse->db, "%!S", pFrom); |
| 140779 | 141044 | } |
| 140780 | 141045 | while( pSel->pPrior ){ pSel = pSel->pPrior; } |
| 140781 | 141046 | sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol); |
| 140782 | 141047 | pTab->iPKey = -1; |
| 140783 | 141048 | pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) ); |
| | @@ -141011,11 +141276,11 @@ |
| 141011 | 141276 | /* This particular expression does not need to be expanded. |
| 141012 | 141277 | */ |
| 141013 | 141278 | pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr); |
| 141014 | 141279 | if( pNew ){ |
| 141015 | 141280 | pNew->a[pNew->nExpr-1].zEName = a[k].zEName; |
| 141016 | | - pNew->a[pNew->nExpr-1].eEName = a[k].eEName; |
| 141281 | + pNew->a[pNew->nExpr-1].fg.eEName = a[k].fg.eEName; |
| 141017 | 141282 | a[k].zEName = 0; |
| 141018 | 141283 | } |
| 141019 | 141284 | a[k].pExpr = 0; |
| 141020 | 141285 | }else{ |
| 141021 | 141286 | /* This expression is a "*" or a "TABLE.*" and needs to be |
| | @@ -141026,39 +141291,64 @@ |
| 141026 | 141291 | assert( pE->pLeft!=0 ); |
| 141027 | 141292 | assert( !ExprHasProperty(pE->pLeft, EP_IntValue) ); |
| 141028 | 141293 | zTName = pE->pLeft->u.zToken; |
| 141029 | 141294 | } |
| 141030 | 141295 | for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){ |
| 141031 | | - Table *pTab = pFrom->pTab; |
| 141032 | | - Select *pSub; |
| 141033 | | - char *zTabName = pFrom->zAlias; |
| 141034 | | - const char *zSchemaName = 0; |
| 141035 | | - int iDb; |
| 141036 | | - if( zTabName==0 ){ |
| 141296 | + Table *pTab = pFrom->pTab; /* Table for this data source */ |
| 141297 | + ExprList *pNestedFrom; /* Result-set of a nested FROM clause */ |
| 141298 | + char *zTabName; /* AS name for this data source */ |
| 141299 | + const char *zSchemaName = 0; /* Schema name for this data source */ |
| 141300 | + int iDb; /* Schema index for this data src */ |
| 141301 | + IdList *pUsing; /* USING clause for pFrom[1] */ |
| 141302 | + |
| 141303 | + if( (zTabName = pFrom->zAlias)==0 ){ |
| 141037 | 141304 | zTabName = pTab->zName; |
| 141038 | 141305 | } |
| 141039 | 141306 | if( db->mallocFailed ) break; |
| 141040 | 141307 | assert( pFrom->fg.isNestedFrom == IsNestedFrom(pFrom->pSelect) ); |
| 141041 | 141308 | if( pFrom->fg.isNestedFrom ){ |
| 141042 | | - pSub = pFrom->pSelect; |
| 141043 | | - assert( pSub->pEList!=0 ); |
| 141044 | | - assert( pSub->pEList->nExpr==pTab->nCol ); |
| 141309 | + assert( pFrom->pSelect!=0 ); |
| 141310 | + pNestedFrom = pFrom->pSelect->pEList; |
| 141311 | + assert( pNestedFrom!=0 ); |
| 141312 | + assert( pNestedFrom->nExpr==pTab->nCol ); |
| 141045 | 141313 | }else{ |
| 141046 | | - pSub = 0; |
| 141047 | 141314 | if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){ |
| 141048 | 141315 | continue; |
| 141049 | 141316 | } |
| 141317 | + pNestedFrom = 0; |
| 141050 | 141318 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 141051 | 141319 | zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*"; |
| 141320 | + } |
| 141321 | + if( i+1<pTabList->nSrc |
| 141322 | + && pFrom[1].fg.isUsing |
| 141323 | + && (selFlags & SF_NestedFrom)!=0 |
| 141324 | + ){ |
| 141325 | + int ii; |
| 141326 | + pUsing = pFrom[1].u3.pUsing; |
| 141327 | + for(ii=0; ii<pUsing->nId; ii++){ |
| 141328 | + const char *zUName = pUsing->a[ii].zName; |
| 141329 | + pRight = sqlite3Expr(db, TK_ID, zUName); |
| 141330 | + pNew = sqlite3ExprListAppend(pParse, pNew, pRight); |
| 141331 | + if( pNew ){ |
| 141332 | + struct ExprList_item *pX = &pNew->a[pNew->nExpr-1]; |
| 141333 | + assert( pX->zEName==0 ); |
| 141334 | + pX->zEName = sqlite3MPrintf(db,"..%s", zUName); |
| 141335 | + pX->fg.eEName = ENAME_TAB; |
| 141336 | + pX->fg.bUsingTerm = 1; |
| 141337 | + } |
| 141338 | + } |
| 141339 | + }else{ |
| 141340 | + pUsing = 0; |
| 141052 | 141341 | } |
| 141053 | 141342 | for(j=0; j<pTab->nCol; j++){ |
| 141054 | 141343 | char *zName = pTab->aCol[j].zCnName; |
| 141055 | 141344 | struct ExprList_item *pX; /* Newly added ExprList term */ |
| 141056 | 141345 | |
| 141057 | 141346 | assert( zName ); |
| 141058 | | - if( zTName && pSub |
| 141059 | | - && sqlite3MatchEName(&pSub->pEList->a[j], 0, zTName, 0)==0 |
| 141347 | + if( zTName |
| 141348 | + && pNestedFrom |
| 141349 | + && sqlite3MatchEName(&pNestedFrom->a[j], 0, zTName, 0)==0 |
| 141060 | 141350 | ){ |
| 141061 | 141351 | continue; |
| 141062 | 141352 | } |
| 141063 | 141353 | |
| 141064 | 141354 | /* If a column is marked as 'hidden', omit it from the expanded |
| | @@ -141067,14 +141357,20 @@ |
| 141067 | 141357 | */ |
| 141068 | 141358 | if( (p->selFlags & SF_IncludeHidden)==0 |
| 141069 | 141359 | && IsHiddenColumn(&pTab->aCol[j]) |
| 141070 | 141360 | ){ |
| 141071 | 141361 | continue; |
| 141362 | + } |
| 141363 | + if( (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0 |
| 141364 | + && zTName==0 |
| 141365 | + && (selFlags & (SF_NestedFrom))==0 |
| 141366 | + ){ |
| 141367 | + continue; |
| 141072 | 141368 | } |
| 141073 | 141369 | tableSeen = 1; |
| 141074 | 141370 | |
| 141075 | | - if( i>0 && zTName==0 ){ |
| 141371 | + if( i>0 && zTName==0 && (selFlags & SF_NestedFrom)==0 ){ |
| 141076 | 141372 | if( pFrom->fg.isUsing |
| 141077 | 141373 | && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0 |
| 141078 | 141374 | ){ |
| 141079 | 141375 | /* In a join with a USING clause, omit columns in the |
| 141080 | 141376 | ** using clause from the table on the right. */ |
| | @@ -141082,10 +141378,11 @@ |
| 141082 | 141378 | } |
| 141083 | 141379 | } |
| 141084 | 141380 | pRight = sqlite3Expr(db, TK_ID, zName); |
| 141085 | 141381 | if( (pTabList->nSrc>1 |
| 141086 | 141382 | && ( (pFrom->fg.jointype & JT_LTORJ)==0 |
| 141383 | + || (selFlags & SF_NestedFrom)!=0 |
| 141087 | 141384 | || !inAnyUsingClause(zName,pFrom,pTabList->nSrc-i-1) |
| 141088 | 141385 | ) |
| 141089 | 141386 | ) |
| 141090 | 141387 | || IN_RENAME_OBJECT |
| 141091 | 141388 | ){ |
| | @@ -141107,25 +141404,32 @@ |
| 141107 | 141404 | break; /* OOM */ |
| 141108 | 141405 | } |
| 141109 | 141406 | pX = &pNew->a[pNew->nExpr-1]; |
| 141110 | 141407 | assert( pX->zEName==0 ); |
| 141111 | 141408 | if( (selFlags & SF_NestedFrom)!=0 && !IN_RENAME_OBJECT ){ |
| 141112 | | - if( pSub ){ |
| 141113 | | - pX->zEName = sqlite3DbStrDup(db, pSub->pEList->a[j].zEName); |
| 141409 | + if( pNestedFrom ){ |
| 141410 | + pX->zEName = sqlite3DbStrDup(db, pNestedFrom->a[j].zEName); |
| 141114 | 141411 | testcase( pX->zEName==0 ); |
| 141115 | 141412 | }else{ |
| 141116 | 141413 | pX->zEName = sqlite3MPrintf(db, "%s.%s.%s", |
| 141117 | 141414 | zSchemaName, zTabName, zName); |
| 141118 | 141415 | testcase( pX->zEName==0 ); |
| 141119 | 141416 | } |
| 141120 | | - pX->eEName = ENAME_TAB; |
| 141417 | + pX->fg.eEName = ENAME_TAB; |
| 141418 | + if( (pFrom->fg.isUsing |
| 141419 | + && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0) |
| 141420 | + || (pUsing && sqlite3IdListIndex(pUsing, zName)>=0) |
| 141421 | + || (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0 |
| 141422 | + ){ |
| 141423 | + pX->fg.bNoExpand = 1; |
| 141424 | + } |
| 141121 | 141425 | }else if( longNames ){ |
| 141122 | 141426 | pX->zEName = sqlite3MPrintf(db, "%s.%s", zTabName, zName); |
| 141123 | | - pX->eEName = ENAME_NAME; |
| 141427 | + pX->fg.eEName = ENAME_NAME; |
| 141124 | 141428 | }else{ |
| 141125 | 141429 | pX->zEName = sqlite3DbStrDup(db, zName); |
| 141126 | | - pX->eEName = ENAME_NAME; |
| 141430 | + pX->fg.eEName = ENAME_NAME; |
| 141127 | 141431 | } |
| 141128 | 141432 | } |
| 141129 | 141433 | } |
| 141130 | 141434 | if( !tableSeen ){ |
| 141131 | 141435 | if( zTName ){ |
| | @@ -142053,13 +142357,11 @@ |
| 142053 | 142357 | ** inside the subquery. This can help the subquery to run more efficiently. |
| 142054 | 142358 | */ |
| 142055 | 142359 | if( OptimizationEnabled(db, SQLITE_PushDown) |
| 142056 | 142360 | && (pItem->fg.isCte==0 |
| 142057 | 142361 | || (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2)) |
| 142058 | | - && (pItem->fg.jointype & JT_RIGHT)==0 |
| 142059 | | - && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor, |
| 142060 | | - (pItem->fg.jointype & JT_OUTER)!=0) |
| 142362 | + && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem) |
| 142061 | 142363 | ){ |
| 142062 | 142364 | #if TREETRACE_ENABLED |
| 142063 | 142365 | if( sqlite3TreeTrace & 0x100 ){ |
| 142064 | 142366 | SELECTTRACE(0x100,pParse,p, |
| 142065 | 142367 | ("After WHERE-clause push-down into subquery %d:\n", pSub->selId)); |
| | @@ -142251,17 +142553,17 @@ |
| 142251 | 142553 | if( pDest->eDest==SRT_EphemTab ){ |
| 142252 | 142554 | sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr); |
| 142253 | 142555 | if( p->selFlags & SF_NestedFrom ){ |
| 142254 | 142556 | /* Delete or NULL-out result columns that will never be used */ |
| 142255 | 142557 | int ii; |
| 142256 | | - for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].bUsed==0; ii--){ |
| 142558 | + for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].fg.bUsed==0; ii--){ |
| 142257 | 142559 | sqlite3ExprDelete(db, pEList->a[ii].pExpr); |
| 142258 | 142560 | sqlite3DbFree(db, pEList->a[ii].zEName); |
| 142259 | 142561 | pEList->nExpr--; |
| 142260 | 142562 | } |
| 142261 | 142563 | for(ii=0; ii<pEList->nExpr; ii++){ |
| 142262 | | - if( pEList->a[ii].bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL; |
| 142564 | + if( pEList->a[ii].fg.bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL; |
| 142263 | 142565 | } |
| 142264 | 142566 | } |
| 142265 | 142567 | } |
| 142266 | 142568 | |
| 142267 | 142569 | /* Set the limiter. |
| | @@ -142409,12 +142711,13 @@ |
| 142409 | 142711 | ** ASC or DESC order - only that each group is returned contiguously. |
| 142410 | 142712 | ** So set the ASC/DESC flags in the GROUP BY to match those in the |
| 142411 | 142713 | ** ORDER BY to maximize the chances of rows being delivered in an |
| 142412 | 142714 | ** order that makes the ORDER BY redundant. */ |
| 142413 | 142715 | for(ii=0; ii<pGroupBy->nExpr; ii++){ |
| 142414 | | - u8 sortFlags = sSort.pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_DESC; |
| 142415 | | - pGroupBy->a[ii].sortFlags = sortFlags; |
| 142716 | + u8 sortFlags; |
| 142717 | + sortFlags = sSort.pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_DESC; |
| 142718 | + pGroupBy->a[ii].fg.sortFlags = sortFlags; |
| 142416 | 142719 | } |
| 142417 | 142720 | if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){ |
| 142418 | 142721 | orderByGrp = 1; |
| 142419 | 142722 | } |
| 142420 | 142723 | } |
| | @@ -144065,20 +144368,20 @@ |
| 144065 | 144368 | pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zCnName); |
| 144066 | 144369 | pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr); |
| 144067 | 144370 | if( !db->mallocFailed ){ |
| 144068 | 144371 | struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1]; |
| 144069 | 144372 | pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName); |
| 144070 | | - pItem->eEName = ENAME_NAME; |
| 144373 | + pItem->fg.eEName = ENAME_NAME; |
| 144071 | 144374 | } |
| 144072 | 144375 | } |
| 144073 | 144376 | }else{ |
| 144074 | 144377 | Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0); |
| 144075 | 144378 | pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr); |
| 144076 | 144379 | if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){ |
| 144077 | 144380 | struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1]; |
| 144078 | 144381 | pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName); |
| 144079 | | - pItem->eEName = pList->a[i].eEName; |
| 144382 | + pItem->fg.eEName = pList->a[i].fg.eEName; |
| 144080 | 144383 | } |
| 144081 | 144384 | } |
| 144082 | 144385 | } |
| 144083 | 144386 | return pNew; |
| 144084 | 144387 | } |
| | @@ -146647,10 +146950,11 @@ |
| 146647 | 146950 | #endif |
| 146648 | 146951 | } |
| 146649 | 146952 | |
| 146650 | 146953 | assert( rc==SQLITE_OK ); |
| 146651 | 146954 | if( pOut==0 ){ |
| 146955 | + nRes = sqlite3BtreeGetRequestedReserve(pTemp); |
| 146652 | 146956 | rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1); |
| 146653 | 146957 | } |
| 146654 | 146958 | |
| 146655 | 146959 | end_of_vacuum: |
| 146656 | 146960 | /* Restore the original value of db->flags */ |
| | @@ -148109,10 +148413,11 @@ |
| 148109 | 148413 | struct WhereRightJoin { |
| 148110 | 148414 | int iMatch; /* Cursor used to determine prior matched rows */ |
| 148111 | 148415 | int regBloom; /* Bloom filter for iRJMatch */ |
| 148112 | 148416 | int regReturn; /* Return register for the interior subroutine */ |
| 148113 | 148417 | int addrSubrtn; /* Starting address for the interior subroutine */ |
| 148418 | + int endSubrtn; /* The last opcode in the interior subroutine */ |
| 148114 | 148419 | }; |
| 148115 | 148420 | |
| 148116 | 148421 | /* |
| 148117 | 148422 | ** This object contains information needed to implement a single nested |
| 148118 | 148423 | ** loop in WHERE clause. |
| | @@ -149300,20 +149605,26 @@ |
| 149300 | 149605 | |
| 149301 | 149606 | iTab = 0; |
| 149302 | 149607 | if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){ |
| 149303 | 149608 | eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab); |
| 149304 | 149609 | }else{ |
| 149305 | | - sqlite3 *db = pParse->db; |
| 149306 | | - pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX); |
| 149307 | | - |
| 149308 | | - if( !db->mallocFailed ){ |
| 149610 | + Expr *pExpr = pTerm->pExpr; |
| 149611 | + if( pExpr->iTable==0 || !ExprHasProperty(pExpr, EP_Subrtn) ){ |
| 149612 | + sqlite3 *db = pParse->db; |
| 149613 | + pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX); |
| 149614 | + if( !db->mallocFailed ){ |
| 149615 | + aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq); |
| 149616 | + eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap,&iTab); |
| 149617 | + pExpr->iTable = iTab; |
| 149618 | + } |
| 149619 | + sqlite3ExprDelete(db, pX); |
| 149620 | + }else{ |
| 149309 | 149621 | aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq); |
| 149310 | | - eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab); |
| 149311 | | - pTerm->pExpr->iTable = iTab; |
| 149622 | + eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP|IN_INDEX_REUSE_CUR, 0, aiMap,&iTab); |
| 149623 | + iTab = pExpr->iTable; |
| 149312 | 149624 | } |
| 149313 | | - sqlite3ExprDelete(db, pX); |
| 149314 | | - pX = pTerm->pExpr; |
| 149625 | + pX = pExpr; |
| 149315 | 149626 | } |
| 149316 | 149627 | |
| 149317 | 149628 | if( eType==IN_INDEX_INDEX_DESC ){ |
| 149318 | 149629 | testcase( bRev ); |
| 149319 | 149630 | bRev = !bRev; |
| | @@ -149936,16 +150247,16 @@ |
| 149936 | 150247 | ** that contains the value of pExpr. |
| 149937 | 150248 | */ |
| 149938 | 150249 | static int whereIndexExprTransNode(Walker *p, Expr *pExpr){ |
| 149939 | 150250 | IdxExprTrans *pX = p->u.pIdxTrans; |
| 149940 | 150251 | if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){ |
| 150252 | + pExpr = sqlite3ExprSkipCollate(pExpr); |
| 149941 | 150253 | preserveExpr(pX, pExpr); |
| 149942 | 150254 | pExpr->affExpr = sqlite3ExprAffinity(pExpr); |
| 149943 | 150255 | pExpr->op = TK_COLUMN; |
| 149944 | 150256 | pExpr->iTable = pX->iIdxCur; |
| 149945 | 150257 | pExpr->iColumn = pX->iIdxCol; |
| 149946 | | - testcase( ExprHasProperty(pExpr, EP_Skip) ); |
| 149947 | 150258 | testcase( ExprHasProperty(pExpr, EP_Unlikely) ); |
| 149948 | 150259 | ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn); |
| 149949 | 150260 | pExpr->y.pTab = 0; |
| 149950 | 150261 | return WRC_Prune; |
| 149951 | 150262 | }else{ |
| | @@ -150095,10 +150406,12 @@ |
| 150095 | 150406 | if( pLevel->regFilter==0 ) continue; |
| 150096 | 150407 | if( pLevel->pWLoop->nSkip ) continue; |
| 150097 | 150408 | /* ,--- Because sqlite3ConstructBloomFilter() has will not have set |
| 150098 | 150409 | ** vvvvv--' pLevel->regFilter if this were true. */ |
| 150099 | 150410 | if( NEVER(pLoop->prereq & notReady) ) continue; |
| 150411 | + assert( pLevel->addrBrk==0 ); |
| 150412 | + pLevel->addrBrk = addrNxt; |
| 150100 | 150413 | if( pLoop->wsFlags & WHERE_IPK ){ |
| 150101 | 150414 | WhereTerm *pTerm = pLoop->aLTerm[0]; |
| 150102 | 150415 | int regRowid; |
| 150103 | 150416 | assert( pTerm!=0 ); |
| 150104 | 150417 | assert( pTerm->pExpr!=0 ); |
| | @@ -150121,10 +150434,11 @@ |
| 150121 | 150434 | sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter, |
| 150122 | 150435 | addrNxt, r1, nEq); |
| 150123 | 150436 | VdbeCoverage(pParse->pVdbe); |
| 150124 | 150437 | } |
| 150125 | 150438 | pLevel->regFilter = 0; |
| 150439 | + pLevel->addrBrk = 0; |
| 150126 | 150440 | } |
| 150127 | 150441 | } |
| 150128 | 150442 | |
| 150129 | 150443 | /* |
| 150130 | 150444 | ** Generate code for the start of the iLevel-th loop in the WHERE clause |
| | @@ -151301,11 +151615,11 @@ |
| 151301 | 151615 | continue; |
| 151302 | 151616 | } |
| 151303 | 151617 | pE = pTerm->pExpr; |
| 151304 | 151618 | assert( pE!=0 ); |
| 151305 | 151619 | if( (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ)) |
| 151306 | | - && !ExprHasProperty(pE,EP_FromJoin) |
| 151620 | + && !ExprHasProperty(pE,EP_FromJoin|EP_InnerJoin) |
| 151307 | 151621 | ){ |
| 151308 | 151622 | continue; |
| 151309 | 151623 | } |
| 151310 | 151624 | |
| 151311 | 151625 | if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){ |
| | @@ -151508,10 +151822,12 @@ |
| 151508 | 151822 | SrcList sFrom; |
| 151509 | 151823 | Bitmask mAll = 0; |
| 151510 | 151824 | int k; |
| 151511 | 151825 | |
| 151512 | 151826 | ExplainQueryPlan((pParse, 1, "RIGHT-JOIN %s", pTabItem->pTab->zName)); |
| 151827 | + sqlite3VdbeNoJumpsOutsideSubrtn(v, pRJ->addrSubrtn, pRJ->endSubrtn, |
| 151828 | + pRJ->regReturn); |
| 151513 | 151829 | for(k=0; k<iLevel; k++){ |
| 151514 | 151830 | int iIdxCur; |
| 151515 | 151831 | mAll |= pWInfo->a[k].pWLoop->maskSelf; |
| 151516 | 151832 | sqlite3VdbeAddOp1(v, OP_NullRow, pWInfo->a[k].iTabCur); |
| 151517 | 151833 | iIdxCur = pWInfo->a[k].iIdxCur; |
| | @@ -153190,11 +153506,11 @@ |
| 153190 | 153506 | if( pOrderBy ){ |
| 153191 | 153507 | for(ii=0; ii<pOrderBy->nExpr; ii++){ |
| 153192 | 153508 | Expr *pExpr = pOrderBy->a[ii].pExpr; |
| 153193 | 153509 | if( pExpr->op!=TK_COLUMN ) return; |
| 153194 | 153510 | if( pExpr->iTable!=iCsr ) return; |
| 153195 | | - if( pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_BIGNULL ) return; |
| 153511 | + if( pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) return; |
| 153196 | 153512 | } |
| 153197 | 153513 | } |
| 153198 | 153514 | |
| 153199 | 153515 | /* All conditions are met. Add the terms to the where-clause object. */ |
| 153200 | 153516 | assert( p->pLimit->op==TK_LIMIT ); |
| | @@ -153516,11 +153832,11 @@ |
| 153516 | 153832 | ** continuation of the inner-most loop. */ |
| 153517 | 153833 | return pWInfo->iContinue; |
| 153518 | 153834 | } |
| 153519 | 153835 | pInner = &pWInfo->a[pWInfo->nLevel-1]; |
| 153520 | 153836 | assert( pInner->addrNxt!=0 ); |
| 153521 | | - return pInner->addrNxt; |
| 153837 | + return pInner->pRJ ? pWInfo->iContinue : pInner->addrNxt; |
| 153522 | 153838 | } |
| 153523 | 153839 | |
| 153524 | 153840 | /* |
| 153525 | 153841 | ** While generating code for the min/max optimization, after handling |
| 153526 | 153842 | ** the aggregate-step call to min() or max(), check to see if any |
| | @@ -154246,13 +154562,11 @@ |
| 154246 | 154562 | Expr *pExpr = pTerm->pExpr; |
| 154247 | 154563 | /* Make the automatic index a partial index if there are terms in the |
| 154248 | 154564 | ** WHERE clause (or the ON clause of a LEFT join) that constrain which |
| 154249 | 154565 | ** rows of the target table (pSrc) that can be used. */ |
| 154250 | 154566 | if( (pTerm->wtFlags & TERM_VIRTUAL)==0 |
| 154251 | | - && ((pSrc->fg.jointype&(JT_LEFT|JT_LTORJ))==0 |
| 154252 | | - || ExprHasProperty(pExpr,EP_FromJoin)) |
| 154253 | | - && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) |
| 154567 | + && sqlite3ExprIsTableConstraint(pExpr, pSrc) |
| 154254 | 154568 | ){ |
| 154255 | 154569 | pPartial = sqlite3ExprAnd(pParse, pPartial, |
| 154256 | 154570 | sqlite3ExprDup(pParse->db, pExpr, 0)); |
| 154257 | 154571 | } |
| 154258 | 154572 | if( termCanDriveIndex(pTerm, pSrc, notReady) ){ |
| | @@ -154487,11 +154801,11 @@ |
| 154487 | 154801 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v); |
| 154488 | 154802 | pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm]; |
| 154489 | 154803 | for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){ |
| 154490 | 154804 | Expr *pExpr = pTerm->pExpr; |
| 154491 | 154805 | if( (pTerm->wtFlags & TERM_VIRTUAL)==0 |
| 154492 | | - && sqlite3ExprIsTableConstant(pExpr, iCur) |
| 154806 | + && sqlite3ExprIsTableConstraint(pExpr, pItem) |
| 154493 | 154807 | ){ |
| 154494 | 154808 | sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL); |
| 154495 | 154809 | } |
| 154496 | 154810 | } |
| 154497 | 154811 | if( pLoop->wsFlags & WHERE_IPK ){ |
| | @@ -154622,11 +154936,11 @@ |
| 154622 | 154936 | if( sqlite3ExprIsConstant(pExpr) ){ |
| 154623 | 154937 | continue; |
| 154624 | 154938 | } |
| 154625 | 154939 | |
| 154626 | 154940 | /* Virtual tables are unable to deal with NULLS FIRST */ |
| 154627 | | - if( pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL ) break; |
| 154941 | + if( pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) break; |
| 154628 | 154942 | |
| 154629 | 154943 | /* First case - a direct column references without a COLLATE operator */ |
| 154630 | 154944 | if( pExpr->op==TK_COLUMN && pExpr->iTable==pSrc->iCursor ){ |
| 154631 | 154945 | assert( pExpr->iColumn>=XN_ROWID && pExpr->iColumn<pTab->nCol ); |
| 154632 | 154946 | continue; |
| | @@ -154734,11 +155048,11 @@ |
| 154734 | 155048 | if( sqlite3ExprIsConstant(pExpr) ) continue; |
| 154735 | 155049 | assert( pExpr->op==TK_COLUMN |
| 154736 | 155050 | || (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN |
| 154737 | 155051 | && pExpr->iColumn==pExpr->pLeft->iColumn) ); |
| 154738 | 155052 | pIdxOrderBy[j].iColumn = pExpr->iColumn; |
| 154739 | | - pIdxOrderBy[j].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC; |
| 155053 | + pIdxOrderBy[j].desc = pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC; |
| 154740 | 155054 | j++; |
| 154741 | 155055 | } |
| 154742 | 155056 | pIdxInfo->nOrderBy = j; |
| 154743 | 155057 | |
| 154744 | 155058 | *pmNoOmit = mNoOmit; |
| | @@ -156252,11 +156566,11 @@ |
| 156252 | 156566 | /* tag-20191211-001: Do not allow constraints from the WHERE clause to |
| 156253 | 156567 | ** be used by the right table of a LEFT JOIN nor by the left table of a |
| 156254 | 156568 | ** RIGHT JOIN. Only constraints in the |
| 156255 | 156569 | ** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */ |
| 156256 | 156570 | if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0 |
| 156257 | | - && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) |
| 156571 | + && !ExprHasProperty(pTerm->pExpr, EP_FromJoin|EP_InnerJoin) |
| 156258 | 156572 | ){ |
| 156259 | 156573 | continue; |
| 156260 | 156574 | } |
| 156261 | 156575 | |
| 156262 | 156576 | if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){ |
| | @@ -157560,13 +157874,11 @@ |
| 157560 | 157874 | pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR; |
| 157561 | 157875 | pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor); |
| 157562 | 157876 | if( (pItem->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){ |
| 157563 | 157877 | /* This condition is true when pItem is the FROM clause term on the |
| 157564 | 157878 | ** right-hand-side of a OUTER or CROSS JOIN. */ |
| 157565 | | - mPrereq = mPrior; |
| 157566 | | - }else{ |
| 157567 | | - mPrereq = 0; |
| 157879 | + mPrereq |= mPrior; |
| 157568 | 157880 | } |
| 157569 | 157881 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 157570 | 157882 | if( IsVirtual(pItem->pTab) ){ |
| 157571 | 157883 | SrcItem *p; |
| 157572 | 157884 | for(p=&pItem[1]; p<pEnd; p++){ |
| | @@ -157873,20 +158185,22 @@ |
| 157873 | 158185 | } |
| 157874 | 158186 | if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){ |
| 157875 | 158187 | /* Make sure the sort order is compatible in an ORDER BY clause. |
| 157876 | 158188 | ** Sort order is irrelevant for a GROUP BY clause. */ |
| 157877 | 158189 | if( revSet ){ |
| 157878 | | - if( (rev ^ revIdx)!=(pOrderBy->a[i].sortFlags&KEYINFO_ORDER_DESC) ){ |
| 158190 | + if( (rev ^ revIdx) |
| 158191 | + != (pOrderBy->a[i].fg.sortFlags&KEYINFO_ORDER_DESC) |
| 158192 | + ){ |
| 157879 | 158193 | isMatch = 0; |
| 157880 | 158194 | } |
| 157881 | 158195 | }else{ |
| 157882 | | - rev = revIdx ^ (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC); |
| 158196 | + rev = revIdx ^ (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC); |
| 157883 | 158197 | if( rev ) *pRevMask |= MASKBIT(iLoop); |
| 157884 | 158198 | revSet = 1; |
| 157885 | 158199 | } |
| 157886 | 158200 | } |
| 157887 | | - if( isMatch && (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL) ){ |
| 158201 | + if( isMatch && (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL) ){ |
| 157888 | 158202 | if( j==pLoop->u.btree.nEq ){ |
| 157889 | 158203 | pLoop->wsFlags |= WHERE_BIGNULL_SORT; |
| 157890 | 158204 | }else{ |
| 157891 | 158205 | isMatch = 0; |
| 157892 | 158206 | } |
| | @@ -159438,10 +159752,11 @@ |
| 159438 | 159752 | /* Terminate the subroutine that forms the interior of the loop of |
| 159439 | 159753 | ** the RIGHT JOIN table */ |
| 159440 | 159754 | WhereRightJoin *pRJ = pLevel->pRJ; |
| 159441 | 159755 | sqlite3VdbeResolveLabel(v, pLevel->addrCont); |
| 159442 | 159756 | pLevel->addrCont = 0; |
| 159757 | + pRJ->endSubrtn = sqlite3VdbeCurrentAddr(v); |
| 159443 | 159758 | sqlite3VdbeAddOp3(v, OP_Return, pRJ->regReturn, pRJ->addrSubrtn, 1); |
| 159444 | 159759 | VdbeCoverage(v); |
| 159445 | 159760 | assert( pParse->withinRJSubrtn>0 ); |
| 159446 | 159761 | pParse->withinRJSubrtn--; |
| 159447 | 159762 | } |
| | @@ -160645,11 +160960,11 @@ |
| 160645 | 160960 | pSub->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse); |
| 160646 | 160961 | pSub->u.zToken = 0; |
| 160647 | 160962 | } |
| 160648 | 160963 | } |
| 160649 | 160964 | pList = sqlite3ExprListAppend(pParse, pList, pDup); |
| 160650 | | - if( pList ) pList->a[nInit+i].sortFlags = pAppend->a[i].sortFlags; |
| 160965 | + if( pList ) pList->a[nInit+i].fg.sortFlags = pAppend->a[i].fg.sortFlags; |
| 160651 | 160966 | } |
| 160652 | 160967 | } |
| 160653 | 160968 | return pList; |
| 160654 | 160969 | } |
| 160655 | 160970 | |
| | @@ -161846,11 +162161,11 @@ |
| 161846 | 162161 | windowReadPeerValues(p, csr1, reg1); |
| 161847 | 162162 | windowReadPeerValues(p, csr2, reg2); |
| 161848 | 162163 | |
| 161849 | 162164 | assert( op==OP_Ge || op==OP_Gt || op==OP_Le ); |
| 161850 | 162165 | assert( pOrderBy && pOrderBy->nExpr==1 ); |
| 161851 | | - if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){ |
| 162166 | + if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_DESC ){ |
| 161852 | 162167 | switch( op ){ |
| 161853 | 162168 | case OP_Ge: op = OP_Le; break; |
| 161854 | 162169 | case OP_Gt: op = OP_Lt; break; |
| 161855 | 162170 | default: assert( op==OP_Le ); op = OP_Ge; break; |
| 161856 | 162171 | } |
| | @@ -161879,11 +162194,11 @@ |
| 161879 | 162194 | ** } |
| 161880 | 162195 | ** |
| 161881 | 162196 | ** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is |
| 161882 | 162197 | ** not taken, control jumps over the comparison operator coded below this |
| 161883 | 162198 | ** block. */ |
| 161884 | | - if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_BIGNULL ){ |
| 162199 | + if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_BIGNULL ){ |
| 161885 | 162200 | /* This block runs if reg1 contains a NULL. */ |
| 161886 | 162201 | int addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v); |
| 161887 | 162202 | switch( op ){ |
| 161888 | 162203 | case OP_Ge: |
| 161889 | 162204 | sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl); |
| | @@ -226663,11 +226978,11 @@ |
| 226663 | 226978 | /* State used by the fts5DataXXX() functions. */ |
| 226664 | 226979 | sqlite3_blob *pReader; /* RO incr-blob open on %_data table */ |
| 226665 | 226980 | sqlite3_stmt *pWriter; /* "INSERT ... %_data VALUES(?,?)" */ |
| 226666 | 226981 | sqlite3_stmt *pDeleter; /* "DELETE FROM %_data ... id>=? AND id<=?" */ |
| 226667 | 226982 | sqlite3_stmt *pIdxWriter; /* "INSERT ... %_idx VALUES(?,?,?,?)" */ |
| 226668 | | - sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=? */ |
| 226983 | + sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=?" */ |
| 226669 | 226984 | sqlite3_stmt *pIdxSelect; |
| 226670 | 226985 | int nRead; /* Total number of blocks read */ |
| 226671 | 226986 | |
| 226672 | 226987 | sqlite3_stmt *pDataVersion; |
| 226673 | 226988 | i64 iStructVersion; /* data_version when pStruct read */ |
| | @@ -235980,11 +236295,11 @@ |
| 235980 | 236295 | int nArg, /* Number of args */ |
| 235981 | 236296 | sqlite3_value **apUnused /* Function arguments */ |
| 235982 | 236297 | ){ |
| 235983 | 236298 | assert( nArg==0 ); |
| 235984 | 236299 | UNUSED_PARAM2(nArg, apUnused); |
| 235985 | | - sqlite3_result_text(pCtx, "fts5: 2022-04-19 15:56:03 b966d52437f08a6759a83a45cafb0d706a8933a8e55dee38ae78166d1a5b3ba4", -1, SQLITE_TRANSIENT); |
| 236300 | + sqlite3_result_text(pCtx, "fts5: 2022-05-10 00:24:01 c6c3115f3a008cf9b0d7c5c812f17e38c8a75a904032c5f05f0bea03a7340527", -1, SQLITE_TRANSIENT); |
| 235986 | 236301 | } |
| 235987 | 236302 | |
| 235988 | 236303 | /* |
| 235989 | 236304 | ** Return true if zName is the extension on one of the shadow tables used |
| 235990 | 236305 | ** by this module. |
| 235991 | 236306 | |