Fossil SCM

Merge in latest changes from trunk

mgagnon 2022-05-11 15:06 fix_remote_url_overwrite_with_proxy merge
Commit 5605aef9b968e65326b3316ca53a816ec7fc1257c6fa67394db1d7e078b93a4a
+271 -100
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.39.0"
456456
#define SQLITE_VERSION_NUMBER 3039000
457
-#define SQLITE_SOURCE_ID "2022-04-26 19:16:11 b1bec72043f798f4d4d30e6b60a45ed4dc521115c8a9f97bb8228e3f089deefb"
457
+#define SQLITE_SOURCE_ID "2022-05-10 00:24:01 c6c3115f3a008cf9b0d7c5c812f17e38c8a75a904032c5f05f0bea03a7340527"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -17054,10 +17054,11 @@
1705417054
#define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */
1705517055
#define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */
1705617056
#define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
1705717057
#define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
1705817058
#define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
17059
+ /* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
1705917060
#define SQLITE_AllOpts 0xffffffff /* All optimizations */
1706017061
1706117062
/*
1706217063
** Macros for testing whether or not optimizations are enabled or disabled.
1706317064
*/
@@ -17399,10 +17400,11 @@
1739917400
#define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
1740017401
#define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */
1740117402
#define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
1740217403
#define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
1740317404
#define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */
17405
+#define COLFLAG_NOEXPAND 0x0400 /* Omit this column when expanding "*" */
1740417406
#define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
1740517407
#define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
1740617408
1740717409
/*
1740817410
** A "Collating Sequence" is defined by an instance of the following
@@ -18272,17 +18274,22 @@
1827218274
int nExpr; /* Number of expressions on the list */
1827318275
int nAlloc; /* Number of a[] slots allocated */
1827418276
struct ExprList_item { /* For each expression in the list */
1827518277
Expr *pExpr; /* The parse tree for this expression */
1827618278
char *zEName; /* Token associated with this expression */
18277
- u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18278
- unsigned eEName :2; /* Meaning of zEName */
18279
- unsigned done :1; /* A flag to indicate when processing is finished */
18280
- unsigned reusable :1; /* Constant expression is reusable */
18281
- unsigned bSorterRef :1; /* Defer evaluation until after sorting */
18282
- unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
18283
- 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;
1828418291
union {
1828518292
struct { /* Used by any ExprList other than Parse.pConsExpr */
1828618293
u16 iOrderByCol; /* For ORDER BY, column number in result set */
1828718294
u16 iAlias; /* Index into Parse.aAlias[] for zName */
1828818295
} x;
@@ -19732,10 +19739,11 @@
1973219739
SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
1973319740
SQLITE_PRIVATE void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*);
1973419741
SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
1973519742
SQLITE_PRIVATE void sqlite3TreeViewBareIdList(TreeView*, const IdList*, const char*);
1973619743
SQLITE_PRIVATE void sqlite3TreeViewIdList(TreeView*, const IdList*, u8, const char*);
19744
+SQLITE_PRIVATE void sqlite3TreeViewColumnList(TreeView*, const Column*, int, u8);
1973719745
SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*);
1973819746
SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
1973919747
SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8);
1974019748
SQLITE_PRIVATE void sqlite3TreeViewUpsert(TreeView*, const Upsert*, u8);
1974119749
SQLITE_PRIVATE void sqlite3TreeViewDelete(const With*, const SrcList*, const Expr*,
@@ -20587,10 +20595,11 @@
2058720595
** Allowed flags for the 3rd parameter to sqlite3FindInIndex().
2058820596
*/
2058920597
#define IN_INDEX_NOOP_OK 0x0001 /* OK to return IN_INDEX_NOOP */
2059020598
#define IN_INDEX_MEMBERSHIP 0x0002 /* IN operator used for membership test */
2059120599
#define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */
20600
+#define IN_INDEX_REUSE_CUR 0x0008 /* Reuse prior table cursor */
2059220601
SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*, int*);
2059320602
2059420603
SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
2059520604
SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *);
2059620605
#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
@@ -31057,10 +31066,57 @@
3105731066
*/
3105831067
static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){
3105931068
sqlite3TreeViewPush(&p, moreFollows);
3106031069
sqlite3TreeViewLine(p, "%s", zLabel);
3106131070
}
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
+}
3106231118
3106331119
/*
3106431120
** Generate a human-readable description of a WITH clause.
3106531121
*/
3106631122
SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){
@@ -31113,10 +31169,11 @@
3111331169
int i;
3111431170
if( pSrc==0 ) return;
3111531171
for(i=0; i<pSrc->nSrc; i++){
3111631172
const SrcItem *pItem = &pSrc->a[i];
3111731173
StrAccum x;
31174
+ int n = 0;
3111831175
char zLine[100];
3111931176
sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
3112031177
x.printfFlags |= SQLITE_PRINTF_INTERNAL;
3112131178
sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
3112231179
if( pItem->pTab ){
@@ -31141,13 +31198,24 @@
3114131198
if( pItem->fg.isCte ){
3114231199
sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
3114331200
}
3114431201
sqlite3StrAccumFinish(&x);
3114531202
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
+ }
3114631210
if( pItem->pSelect ){
31211
+ if( pItem->pTab ){
31212
+ Table *pTab = pItem->pTab;
31213
+ sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1);
31214
+ }
3114731215
assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
31148
- sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
31216
+ sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0);
3114931217
}
3115031218
if( pItem->fg.isTabFunc ){
3115131219
sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
3115231220
}
3115331221
sqlite3TreeViewPop(&pView);
@@ -31310,10 +31378,11 @@
3131031378
/*
3131131379
** Generate a human-readable explanation for a Window object
3131231380
*/
3131331381
SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
3131431382
int nElement = 0;
31383
+ if( pWin==0 ) return;
3131531384
if( pWin->pFilter ){
3131631385
sqlite3TreeViewItem(pView, "FILTER", 1);
3131731386
sqlite3TreeViewExpr(pView, pWin->pFilter, 0);
3131831387
sqlite3TreeViewPop(&pView);
3131931388
}
@@ -31374,10 +31443,11 @@
3137431443
#ifndef SQLITE_OMIT_WINDOWFUNC
3137531444
/*
3137631445
** Generate a human-readable explanation for a Window Function object
3137731446
*/
3137831447
SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){
31448
+ if( pWin==0 ) return;
3137931449
sqlite3TreeViewPush(&pView, more);
3138031450
sqlite3TreeViewLine(pView, "WINFUNC %s(%d)",
3138131451
pWin->pWFunc->zName, pWin->pWFunc->nArg);
3138231452
sqlite3TreeViewWindow(pView, pWin, 0);
3138331453
sqlite3TreeViewPop(&pView);
@@ -31625,11 +31695,21 @@
3162531695
sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
3162631696
sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
3162731697
break;
3162831698
}
3162931699
case TK_IN: {
31630
- 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);
3163131711
sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
3163231712
if( ExprUseXSelect(pExpr) ){
3163331713
sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
3163431714
}else{
3163531715
sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
@@ -31776,17 +31856,19 @@
3177631856
if( j || zName ){
3177731857
sqlite3TreeViewPush(&pView, moreToFollow);
3177831858
moreToFollow = 0;
3177931859
sqlite3TreeViewLine(pView, 0);
3178031860
if( zName ){
31781
- switch( pList->a[i].eEName ){
31861
+ switch( pList->a[i].fg.eEName ){
3178231862
default:
3178331863
fprintf(stdout, "AS %s ", zName);
3178431864
break;
3178531865
case ENAME_TAB:
3178631866
fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
31787
- 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) ");
3178831870
break;
3178931871
case ENAME_SPAN:
3179031872
fprintf(stdout, "SPAN(\"%s\") ", zName);
3179131873
break;
3179231874
}
@@ -89252,10 +89334,12 @@
8925289334
if( pOp->p2==0 ) break;
8925389335
8925489336
/* Most jump operations do a goto to this spot in order to update
8925589337
** the pOp pointer. */
8925689338
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 */
8925789341
pOp = &aOp[pOp->p2 - 1];
8925889342
break;
8925989343
}
8926089344
8926189345
/* Opcode: EndCoroutine P1 * * * *
@@ -101463,11 +101547,11 @@
101463101547
const char *zTab,
101464101548
const char *zDb
101465101549
){
101466101550
int n;
101467101551
const char *zSpan;
101468
- if( pItem->eEName!=ENAME_TAB ) return 0;
101552
+ if( pItem->fg.eEName!=ENAME_TAB ) return 0;
101469101553
zSpan = pItem->zEName;
101470101554
for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
101471101555
if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
101472101556
return 0;
101473101557
}
@@ -101692,12 +101776,13 @@
101692101776
}
101693101777
cnt++;
101694101778
cntTab = 2;
101695101779
pMatch = pItem;
101696101780
pExpr->iColumn = j;
101697
- pEList->a[j].bUsed = 1;
101781
+ pEList->a[j].fg.bUsed = 1;
101698101782
hit = 1;
101783
+ if( pEList->a[j].fg.bUsingTerm ) break;
101699101784
}
101700101785
if( hit || zTab==0 ) continue;
101701101786
}
101702101787
assert( zDb==0 || zTab!=0 );
101703101788
if( zTab ){
@@ -101916,11 +102001,11 @@
101916102001
){
101917102002
pEList = pNC->uNC.pEList;
101918102003
assert( pEList!=0 );
101919102004
for(j=0; j<pEList->nExpr; j++){
101920102005
char *zAs = pEList->a[j].zEName;
101921
- if( pEList->a[j].eEName==ENAME_NAME
102006
+ if( pEList->a[j].fg.eEName==ENAME_NAME
101922102007
&& sqlite3_stricmp(zAs, zCol)==0
101923102008
){
101924102009
Expr *pOrig;
101925102010
assert( pExpr->pLeft==0 && pExpr->pRight==0 );
101926102011
assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
@@ -102669,11 +102754,11 @@
102669102754
if( pE->op==TK_ID ){
102670102755
const char *zCol;
102671102756
assert( !ExprHasProperty(pE, EP_IntValue) );
102672102757
zCol = pE->u.zToken;
102673102758
for(i=0; i<pEList->nExpr; i++){
102674
- if( pEList->a[i].eEName==ENAME_NAME
102759
+ if( pEList->a[i].fg.eEName==ENAME_NAME
102675102760
&& sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
102676102761
){
102677102762
return i+1;
102678102763
}
102679102764
}
@@ -102790,11 +102875,11 @@
102790102875
if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
102791102876
sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
102792102877
return 1;
102793102878
}
102794102879
for(i=0; i<pOrderBy->nExpr; i++){
102795
- pOrderBy->a[i].done = 0;
102880
+ pOrderBy->a[i].fg.done = 0;
102796102881
}
102797102882
pSelect->pNext = 0;
102798102883
while( pSelect->pPrior ){
102799102884
pSelect->pPrior->pNext = pSelect;
102800102885
pSelect = pSelect->pPrior;
@@ -102805,11 +102890,11 @@
102805102890
pEList = pSelect->pEList;
102806102891
assert( pEList!=0 );
102807102892
for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
102808102893
int iCol = -1;
102809102894
Expr *pE, *pDup;
102810
- if( pItem->done ) continue;
102895
+ if( pItem->fg.done ) continue;
102811102896
pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
102812102897
if( NEVER(pE==0) ) continue;
102813102898
if( sqlite3ExprIsInteger(pE, &iCol) ){
102814102899
if( iCol<=0 || iCol>pEList->nExpr ){
102815102900
resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE);
@@ -102858,19 +102943,19 @@
102858102943
pParent->pLeft = pNew;
102859102944
}
102860102945
sqlite3ExprDelete(db, pE);
102861102946
pItem->u.x.iOrderByCol = (u16)iCol;
102862102947
}
102863
- pItem->done = 1;
102948
+ pItem->fg.done = 1;
102864102949
}else{
102865102950
moreToDo = 1;
102866102951
}
102867102952
}
102868102953
pSelect = pSelect->pNext;
102869102954
}
102870102955
for(i=0; i<pOrderBy->nExpr; i++){
102871
- if( pOrderBy->a[i].done==0 ){
102956
+ if( pOrderBy->a[i].fg.done==0 ){
102872102957
sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any "
102873102958
"column in the result set", i+1);
102874102959
return 1;
102875102960
}
102876102961
}
@@ -105110,16 +105195,12 @@
105110105195
}
105111105196
pNewExpr->pLeft = pPriorSelectColNew;
105112105197
}
105113105198
}
105114105199
pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
105115
- pItem->sortFlags = pOldItem->sortFlags;
105116
- pItem->eEName = pOldItem->eEName;
105117
- pItem->done = 0;
105118
- pItem->bNulls = pOldItem->bNulls;
105119
- pItem->bUsed = pOldItem->bUsed;
105120
- pItem->bSorterRef = pOldItem->bSorterRef;
105200
+ pItem->fg = pOldItem->fg;
105201
+ pItem->fg.done = 0;
105121105202
pItem->u = pOldItem->u;
105122105203
}
105123105204
return pNew;
105124105205
}
105125105206
@@ -105415,20 +105496,20 @@
105415105496
|| eNulls==SQLITE_SO_ASC
105416105497
|| eNulls==SQLITE_SO_DESC
105417105498
);
105418105499
105419105500
pItem = &p->a[p->nExpr-1];
105420
- assert( pItem->bNulls==0 );
105501
+ assert( pItem->fg.bNulls==0 );
105421105502
if( iSortOrder==SQLITE_SO_UNDEFINED ){
105422105503
iSortOrder = SQLITE_SO_ASC;
105423105504
}
105424
- pItem->sortFlags = (u8)iSortOrder;
105505
+ pItem->fg.sortFlags = (u8)iSortOrder;
105425105506
105426105507
if( eNulls!=SQLITE_SO_UNDEFINED ){
105427
- pItem->bNulls = 1;
105508
+ pItem->fg.bNulls = 1;
105428105509
if( iSortOrder!=eNulls ){
105429
- pItem->sortFlags |= KEYINFO_ORDER_BIGNULL;
105510
+ pItem->fg.sortFlags |= KEYINFO_ORDER_BIGNULL;
105430105511
}
105431105512
}
105432105513
}
105433105514
105434105515
/*
@@ -105450,11 +105531,11 @@
105450105531
if( pList ){
105451105532
struct ExprList_item *pItem;
105452105533
assert( pList->nExpr>0 );
105453105534
pItem = &pList->a[pList->nExpr-1];
105454105535
assert( pItem->zEName==0 );
105455
- assert( pItem->eEName==ENAME_NAME );
105536
+ assert( pItem->fg.eEName==ENAME_NAME );
105456105537
pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
105457105538
if( dequote ){
105458105539
/* If dequote==0, then pName->z does not point to part of a DDL
105459105540
** statement handled by the parser. And so no token need be added
105460105541
** to the token-map. */
@@ -105485,11 +105566,11 @@
105485105566
if( pList ){
105486105567
struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
105487105568
assert( pList->nExpr>0 );
105488105569
if( pItem->zEName==0 ){
105489105570
pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd);
105490
- pItem->eEName = ENAME_SPAN;
105571
+ pItem->fg.eEName = ENAME_SPAN;
105491105572
}
105492105573
}
105493105574
}
105494105575
105495105576
/*
@@ -105782,11 +105863,11 @@
105782105863
105783105864
/*
105784105865
** Check pExpr to see if it is an invariant constraint on data source pSrc.
105785105866
** This is an optimization. False negatives will perhaps cause slower
105786105867
** queries, but false positives will yield incorrect answers. So when in
105787
-** double, return 0.
105868
+** doubt, return 0.
105788105869
**
105789105870
** To be an invariant constraint, the following must be true:
105790105871
**
105791105872
** (1) pExpr cannot refer to any table other than pSrc->iCursor.
105792105873
**
@@ -106141,11 +106222,11 @@
106141106222
** The job of this routine is to find or create a b-tree object that can
106142106223
** be used either to test for membership in the RHS set or to iterate through
106143106224
** all members of the RHS set, skipping duplicates.
106144106225
**
106145106226
** A cursor is opened on the b-tree object that is the RHS of the IN operator
106146
-** and pX->iTable is set to the index of that cursor.
106227
+** and the *piTab parameter is set to the index of that cursor.
106147106228
**
106148106229
** The returned value of this function indicates the b-tree type, as follows:
106149106230
**
106150106231
** IN_INDEX_ROWID - The cursor was opened on a database table.
106151106232
** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index.
@@ -106161,11 +106242,14 @@
106161106242
** SELECT <column1>, <column2>... FROM <table>
106162106243
**
106163106244
** If the RHS of the IN operator is a list or a more complex subquery, then
106164106245
** an ephemeral table might need to be generated from the RHS and then
106165106246
** pX->iTable made to point to the ephemeral table instead of an
106166
-** 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.
106167106251
**
106168106252
** The inFlags parameter must contain, at a minimum, one of the bits
106169106253
** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
106170106254
** IN_INDEX_MEMBERSHIP, then the generated table will be used for a fast
106171106255
** membership test. When the IN_INDEX_LOOP bit is set, the IN index will
@@ -106222,16 +106306,21 @@
106222106306
int *aiMap, /* Mapping from Index fields to RHS fields */
106223106307
int *piTab /* OUT: index to use */
106224106308
){
106225106309
Select *p; /* SELECT to the right of IN operator */
106226106310
int eType = 0; /* Type of RHS table. IN_INDEX_* */
106227
- int iTab = pParse->nTab++; /* Cursor of the RHS table */
106311
+ int iTab; /* Cursor of the RHS table */
106228106312
int mustBeUnique; /* True if RHS must be unique */
106229106313
Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */
106230106314
106231106315
assert( pX->op==TK_IN );
106232106316
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
+ }
106233106322
106234106323
/* If the RHS of this IN(...) operator is a SELECT, and if it matters
106235106324
** whether or not the SELECT result contains NULL values, check whether
106236106325
** or not NULL is actually possible (it may not be, for example, due
106237106326
** to NOT NULL constraints in the schema). If no NULL values are possible,
@@ -106393,10 +106482,12 @@
106393106482
if( eType==0
106394106483
&& (inFlags & IN_INDEX_NOOP_OK)
106395106484
&& ExprUseXList(pX)
106396106485
&& (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
106397106486
){
106487
+ pParse->nTab--; /* Back out the allocation of the unused cursor */
106488
+ iTab = -1; /* Cursor is not allocated */
106398106489
eType = IN_INDEX_NOOP;
106399106490
}
106400106491
106401106492
if( eType==0 ){
106402106493
/* Could not find an existing table or index to use as the RHS b-tree.
@@ -106559,11 +106650,13 @@
106559106650
pExpr->x.pSelect->selId));
106560106651
}
106561106652
assert( ExprUseYSub(pExpr) );
106562106653
sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
106563106654
pExpr->y.sub.iAddr);
106564
- sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
106655
+ if( iTab!=pExpr->iTable ){
106656
+ sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
106657
+ }
106565106658
sqlite3VdbeJumpHere(v, addrOnce);
106566106659
return;
106567106660
}
106568106661
106569106662
/* Begin coding the subroutine */
@@ -108299,11 +108392,13 @@
108299108392
p = pParse->pConstExpr;
108300108393
if( regDest<0 && p ){
108301108394
struct ExprList_item *pItem;
108302108395
int i;
108303108396
for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
108304
- if( pItem->reusable && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0 ){
108397
+ if( pItem->fg.reusable
108398
+ && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0
108399
+ ){
108305108400
return pItem->u.iConstExprReg;
108306108401
}
108307108402
}
108308108403
}
108309108404
pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
@@ -108322,11 +108417,11 @@
108322108417
sqlite3VdbeJumpHere(v, addr);
108323108418
}else{
108324108419
p = sqlite3ExprListAppend(pParse, p, pExpr);
108325108420
if( p ){
108326108421
struct ExprList_item *pItem = &p->a[p->nExpr-1];
108327
- pItem->reusable = regDest<0;
108422
+ pItem->fg.reusable = regDest<0;
108328108423
if( regDest<0 ) regDest = ++pParse->nMem;
108329108424
pItem->u.iConstExprReg = regDest;
108330108425
}
108331108426
pParse->pConstExpr = p;
108332108427
}
@@ -108456,11 +108551,11 @@
108456108551
n = pList->nExpr;
108457108552
if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
108458108553
for(pItem=pList->a, i=0; i<n; i++, pItem++){
108459108554
Expr *pExpr = pItem->pExpr;
108460108555
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
108461
- if( pItem->bSorterRef ){
108556
+ if( pItem->fg.bSorterRef ){
108462108557
i--;
108463108558
n--;
108464108559
}else
108465108560
#endif
108466108561
if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
@@ -109081,11 +109176,11 @@
109081109176
if( pA->nExpr!=pB->nExpr ) return 1;
109082109177
for(i=0; i<pA->nExpr; i++){
109083109178
int res;
109084109179
Expr *pExprA = pA->a[i].pExpr;
109085109180
Expr *pExprB = pB->a[i].pExpr;
109086
- 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;
109087109182
if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
109088109183
}
109089109184
return 0;
109090109185
}
109091109186
@@ -110770,11 +110865,11 @@
110770110865
return WRC_Prune;
110771110866
}
110772110867
if( ALWAYS(p->pEList) ){
110773110868
ExprList *pList = p->pEList;
110774110869
for(i=0; i<pList->nExpr; i++){
110775
- if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){
110870
+ if( pList->a[i].zEName && pList->a[i].fg.eEName==ENAME_NAME ){
110776110871
sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
110777110872
}
110778110873
}
110779110874
}
110780110875
if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
@@ -110819,11 +110914,11 @@
110819110914
memset(&sWalker, 0, sizeof(Walker));
110820110915
sWalker.pParse = pParse;
110821110916
sWalker.xExprCallback = renameUnmapExprCb;
110822110917
sqlite3WalkExprList(&sWalker, pEList);
110823110918
for(i=0; i<pEList->nExpr; i++){
110824
- if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) ){
110919
+ if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME) ){
110825110920
sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
110826110921
}
110827110922
}
110828110923
}
110829110924
}
@@ -110977,11 +111072,11 @@
110977111072
){
110978111073
if( pEList ){
110979111074
int i;
110980111075
for(i=0; i<pEList->nExpr; i++){
110981111076
const char *zName = pEList->a[i].zEName;
110982
- if( ALWAYS(pEList->a[i].eEName==ENAME_NAME)
111077
+ if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME)
110983111078
&& ALWAYS(zName!=0)
110984111079
&& 0==sqlite3_stricmp(zName, zOld)
110985111080
){
110986111081
renameTokenFind(pParse, pCtx, (const void*)zName);
110987111082
}
@@ -113002,13 +113097,18 @@
113002113097
** * the index contains 100 rows,
113003113098
** * "WHERE a=?" matches 10 rows, and
113004113099
** * "WHERE a=? AND b=?" matches 2 rows.
113005113100
**
113006113101
** If D is the count of distinct values and K is the total number of
113007
- ** rows, then each estimate is computed as:
113102
+ ** rows, then each estimate is usually computed as:
113008113103
**
113009113104
** 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.
113010113110
*/
113011113111
sqlite3_str sStat; /* Text of the constructed "stat" line */
113012113112
int i; /* Loop counter */
113013113113
113014113114
sqlite3StrAccumInit(&sStat, 0, 0, 0, (p->nKeyCol+1)*100);
@@ -113015,10 +113115,11 @@
113015113115
sqlite3_str_appendf(&sStat, "%llu",
113016113116
p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow);
113017113117
for(i=0; i<p->nKeyCol; i++){
113018113118
u64 nDistinct = p->current.anDLt[i] + 1;
113019113119
u64 iVal = (p->nRow + nDistinct - 1) / nDistinct;
113120
+ if( iVal==2 && p->nRow*10 <= nDistinct*11 ) iVal = 1;
113020113121
sqlite3_str_appendf(&sStat, " %llu", iVal);
113021113122
assert( p->current.anEq[i] );
113022113123
}
113023113124
sqlite3ResultStrAccum(context, &sStat);
113024113125
}
@@ -116854,11 +116955,11 @@
116854116955
}
116855116956
pTab->iPKey = iCol;
116856116957
pTab->keyConf = (u8)onError;
116857116958
assert( autoInc==0 || autoInc==1 );
116858116959
pTab->tabFlags |= autoInc*TF_Autoincrement;
116859
- if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags;
116960
+ if( pList ) pParse->iPkSortOrder = pList->a[0].fg.sortFlags;
116860116961
(void)sqlite3HasExplicitNulls(pParse, pList);
116861116962
}else if( autoInc ){
116862116963
#ifndef SQLITE_OMIT_AUTOINCREMENT
116863116964
sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
116864116965
"INTEGER PRIMARY KEY");
@@ -117348,11 +117449,11 @@
117348117449
return;
117349117450
}
117350117451
if( IN_RENAME_OBJECT ){
117351117452
sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
117352117453
}
117353
- pList->a[0].sortFlags = pParse->iPkSortOrder;
117454
+ pList->a[0].fg.sortFlags = pParse->iPkSortOrder;
117354117455
assert( pParse->pNewTable==pTab );
117355117456
pTab->iPKey = -1;
117356117457
sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
117357117458
SQLITE_IDXTYPE_PRIMARYKEY);
117358117459
if( pParse->nErr ){
@@ -118836,12 +118937,12 @@
118836118937
*/
118837118938
SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
118838118939
if( pList ){
118839118940
int i;
118840118941
for(i=0; i<pList->nExpr; i++){
118841
- if( pList->a[i].bNulls ){
118842
- u8 sf = pList->a[i].sortFlags;
118942
+ if( pList->a[i].fg.bNulls ){
118943
+ u8 sf = pList->a[i].fg.sortFlags;
118843118944
sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s",
118844118945
(sf==0 || sf==3) ? "FIRST" : "LAST"
118845118946
);
118846118947
return 1;
118847118948
}
@@ -119190,11 +119291,11 @@
119190119291
if( !zColl ) zColl = sqlite3StrBINARY;
119191119292
if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
119192119293
goto exit_create_index;
119193119294
}
119194119295
pIndex->azColl[i] = zColl;
119195
- requestedSortOrder = pListItem->sortFlags & sortOrderMask;
119296
+ requestedSortOrder = pListItem->fg.sortFlags & sortOrderMask;
119196119297
pIndex->aSortOrder[i] = (u8)requestedSortOrder;
119197119298
}
119198119299
119199119300
/* Append the table key to the end of the index. For WITHOUT ROWID
119200119301
** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
@@ -130512,15 +130613,23 @@
130512130613
sqlite3_total_changes64,
130513130614
/* Version 3.37.0 and later */
130514130615
sqlite3_autovacuum_pages,
130515130616
/* Version 3.38.0 and later */
130516130617
sqlite3_error_offset,
130618
+#ifndef SQLITE_OMIT_VIRTUALTABLE
130517130619
sqlite3_vtab_rhs_value,
130518130620
sqlite3_vtab_distinct,
130519130621
sqlite3_vtab_in,
130520130622
sqlite3_vtab_in_first,
130521130623
sqlite3_vtab_in_next,
130624
+#else
130625
+ 0,
130626
+ 0,
130627
+ 0,
130628
+ 0,
130629
+ 0,
130630
+#endif
130522130631
/* Version 3.39.0 and later */
130523130632
#ifndef SQLITE_OMIT_DESERIALIZE
130524130633
sqlite3_deserialize,
130525130634
sqlite3_serialize
130526130635
#else
@@ -134960,10 +135069,18 @@
134960135069
db->pParse = pParse;
134961135070
pParse->db = db;
134962135071
if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory");
134963135072
}
134964135073
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
+
134965135082
/*
134966135083
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
134967135084
*/
134968135085
static int sqlite3Prepare(
134969135086
sqlite3 *db, /* Database handle. */
@@ -135134,11 +135251,11 @@
135134135251
** or encounters a permanent error. A schema problem after one schema
135135135252
** reset is considered a permanent error. */
135136135253
rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
135137135254
assert( rc==SQLITE_OK || *ppStmt==0 );
135138135255
if( rc==SQLITE_OK || db->mallocFailed ) break;
135139
- }while( rc==SQLITE_ERROR_RETRY
135256
+ }while( (rc==SQLITE_ERROR_RETRY && (cnt++)<SQLITE_MAX_PREPARE_RETRY)
135140135257
|| (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
135141135258
sqlite3BtreeLeaveAll(db);
135142135259
rc = sqlite3ApiExit(db, rc);
135143135260
assert( (rc&db->errMask)==rc );
135144135261
db->busyHandler.nBusy = 0;
@@ -135685,11 +135802,11 @@
135685135802
ExprList *pResults;
135686135803
assert( pItem->pSelect!=0 );
135687135804
pResults = pItem->pSelect->pEList;
135688135805
assert( pResults!=0 );
135689135806
assert( iCol>=0 && iCol<pResults->nExpr );
135690
- pResults->a[iCol].bUsed = 1;
135807
+ pResults->a[iCol].fg.bUsed = 1;
135691135808
}
135692135809
}
135693135810
135694135811
/*
135695135812
** Search the tables iStart..iEnd (inclusive) in pSrc, looking for a
@@ -136353,11 +136470,11 @@
136353136470
** the row from table t1 is stored instead. Then, as records are extracted from
136354136471
** the sorter to return to the user, the required value of bigblob is
136355136472
** retrieved directly from table t1. If the values are very large, this
136356136473
** can be more efficient than storing them directly in the sorter records.
136357136474
**
136358
-** 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
136359136476
** for which the sorter-reference optimization should be enabled.
136360136477
** Additionally, the pSort->aDefer[] array is populated with entries
136361136478
** for all cursors required to evaluate all selected expressions. Finally.
136362136479
** output variable (*ppExtra) is set to an expression list containing
136363136480
** expressions for all extra PK values that should be stored in the
@@ -136413,11 +136530,11 @@
136413136530
pSort->aDefer[nDefer].iCsr = pExpr->iTable;
136414136531
pSort->aDefer[nDefer].nKey = nKey;
136415136532
nDefer++;
136416136533
}
136417136534
}
136418
- pItem->bSorterRef = 1;
136535
+ pItem->fg.bSorterRef = 1;
136419136536
}
136420136537
}
136421136538
}
136422136539
pSort->nDefer = (u8)nDefer;
136423136540
*ppExtra = pExtra;
@@ -136544,11 +136661,11 @@
136544136661
** from the sorter by the optimizations in this branch */
136545136662
pEList = p->pEList;
136546136663
for(i=0; i<pEList->nExpr; i++){
136547136664
if( pEList->a[i].u.x.iOrderByCol>0
136548136665
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
136549
- || pEList->a[i].bSorterRef
136666
+ || pEList->a[i].fg.bSorterRef
136550136667
#endif
136551136668
){
136552136669
nResultCol--;
136553136670
regOrig = 0;
136554136671
}
@@ -136906,11 +137023,11 @@
136906137023
pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
136907137024
if( pInfo ){
136908137025
assert( sqlite3KeyInfoIsWriteable(pInfo) );
136909137026
for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
136910137027
pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr);
136911
- pInfo->aSortFlags[i-iStart] = pItem->sortFlags;
137028
+ pInfo->aSortFlags[i-iStart] = pItem->fg.sortFlags;
136912137029
}
136913137030
}
136914137031
return pInfo;
136915137032
}
136916137033
@@ -137045,11 +137162,11 @@
137045137162
iSortTab = iTab;
137046137163
bSeq = 1;
137047137164
}
137048137165
for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
137049137166
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
137050
- if( aOutEx[i].bSorterRef ) continue;
137167
+ if( aOutEx[i].fg.bSorterRef ) continue;
137051137168
#endif
137052137169
if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
137053137170
}
137054137171
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
137055137172
if( pSort->nDefer ){
@@ -137082,11 +137199,11 @@
137082137199
sqlite3ReleaseTempRange(pParse, regKey, nRefKey);
137083137200
}
137084137201
#endif
137085137202
for(i=nColumn-1; i>=0; i--){
137086137203
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
137087
- if( aOutEx[i].bSorterRef ){
137204
+ if( aOutEx[i].fg.bSorterRef ){
137088137205
sqlite3ExprCode(pParse, aOutEx[i].pExpr, regRow+i);
137089137206
}else
137090137207
#endif
137091137208
{
137092137209
int iRead;
@@ -137448,11 +137565,11 @@
137448137565
137449137566
assert( p!=0 );
137450137567
assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
137451137568
assert( p->op!=TK_COLUMN
137452137569
|| (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
137453
- if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){
137570
+ if( pEList->a[i].zEName && pEList->a[i].fg.eEName==ENAME_NAME ){
137454137571
/* An AS clause always takes first priority */
137455137572
char *zName = pEList->a[i].zEName;
137456137573
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
137457137574
}else if( srcName && p->op==TK_COLUMN ){
137458137575
char *zCol;
@@ -137534,13 +137651,14 @@
137534137651
*pnCol = nCol;
137535137652
*paCol = aCol;
137536137653
137537137654
for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
137538137655
struct ExprList_item *pX = &pEList->a[i];
137656
+ struct ExprList_item *pCollide;
137539137657
/* Get an appropriate name for the column
137540137658
*/
137541
- if( (zName = pX->zEName)!=0 && pX->eEName==ENAME_NAME ){
137659
+ if( (zName = pX->zEName)!=0 && pX->fg.eEName==ENAME_NAME ){
137542137660
/* If the column contains an "AS <name>" phrase, use <name> as the name */
137543137661
}else{
137544137662
Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pX->pExpr);
137545137663
while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
137546137664
pColExpr = pColExpr->pRight;
@@ -137570,11 +137688,14 @@
137570137688
137571137689
/* Make sure the column name is unique. If the name is not unique,
137572137690
** append an integer to the name so that it becomes unique.
137573137691
*/
137574137692
cnt = 0;
137575
- 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
+ }
137576137697
nName = sqlite3Strlen30(zName);
137577137698
if( nName>0 ){
137578137699
for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
137579137700
if( zName[j]==':' ) nName = j;
137580137701
}
@@ -137581,12 +137702,15 @@
137581137702
zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
137582137703
if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
137583137704
}
137584137705
pCol->zCnName = zName;
137585137706
pCol->hName = sqlite3StrIHash(zName);
137707
+ if( pX->fg.bNoExpand ){
137708
+ pCol->colFlags |= COLFLAG_NOEXPAND;
137709
+ }
137586137710
sqlite3ColumnPropertiesFromName(0, pCol);
137587
- if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
137711
+ if( zName && sqlite3HashInsert(&ht, zName, pX)==pX ){
137588137712
sqlite3OomFault(db);
137589137713
}
137590137714
}
137591137715
sqlite3HashClear(&ht);
137592137716
if( db->mallocFailed ){
@@ -137839,11 +137963,11 @@
137839137963
pOrderBy->a[i].pExpr =
137840137964
sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
137841137965
}
137842137966
assert( sqlite3KeyInfoIsWriteable(pRet) );
137843137967
pRet->aColl[i] = pColl;
137844
- pRet->aSortFlags[i] = pOrderBy->a[i].sortFlags;
137968
+ pRet->aSortFlags[i] = pOrderBy->a[i].fg.sortFlags;
137845137969
}
137846137970
}
137847137971
137848137972
return pRet;
137849137973
}
@@ -140445,11 +140569,11 @@
140445140569
}else{
140446140570
return eRet;
140447140571
}
140448140572
*ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
140449140573
assert( pOrderBy!=0 || db->mallocFailed );
140450
- if( pOrderBy ) pOrderBy->a[0].sortFlags = sortFlags;
140574
+ if( pOrderBy ) pOrderBy->a[0].fg.sortFlags = sortFlags;
140451140575
return eRet;
140452140576
}
140453140577
140454140578
/*
140455140579
** The select statement passed as the first argument is an aggregate query.
@@ -141152,11 +141276,11 @@
141152141276
/* This particular expression does not need to be expanded.
141153141277
*/
141154141278
pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
141155141279
if( pNew ){
141156141280
pNew->a[pNew->nExpr-1].zEName = a[k].zEName;
141157
- pNew->a[pNew->nExpr-1].eEName = a[k].eEName;
141281
+ pNew->a[pNew->nExpr-1].fg.eEName = a[k].fg.eEName;
141158141282
a[k].zEName = 0;
141159141283
}
141160141284
a[k].pExpr = 0;
141161141285
}else{
141162141286
/* This expression is a "*" or a "TABLE.*" and needs to be
@@ -141172,10 +141296,11 @@
141172141296
Table *pTab = pFrom->pTab; /* Table for this data source */
141173141297
ExprList *pNestedFrom; /* Result-set of a nested FROM clause */
141174141298
char *zTabName; /* AS name for this data source */
141175141299
const char *zSchemaName = 0; /* Schema name for this data source */
141176141300
int iDb; /* Schema index for this data src */
141301
+ IdList *pUsing; /* USING clause for pFrom[1] */
141177141302
141178141303
if( (zTabName = pFrom->zAlias)==0 ){
141179141304
zTabName = pTab->zName;
141180141305
}
141181141306
if( db->mallocFailed ) break;
@@ -141190,10 +141315,31 @@
141190141315
continue;
141191141316
}
141192141317
pNestedFrom = 0;
141193141318
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
141194141319
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;
141195141341
}
141196141342
for(j=0; j<pTab->nCol; j++){
141197141343
char *zName = pTab->aCol[j].zCnName;
141198141344
struct ExprList_item *pX; /* Newly added ExprList term */
141199141345
@@ -141211,14 +141357,20 @@
141211141357
*/
141212141358
if( (p->selFlags & SF_IncludeHidden)==0
141213141359
&& IsHiddenColumn(&pTab->aCol[j])
141214141360
){
141215141361
continue;
141362
+ }
141363
+ if( (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
141364
+ && zTName==0
141365
+ && (selFlags & (SF_NestedFrom))==0
141366
+ ){
141367
+ continue;
141216141368
}
141217141369
tableSeen = 1;
141218141370
141219
- if( i>0 && zTName==0 ){
141371
+ if( i>0 && zTName==0 && (selFlags & SF_NestedFrom)==0 ){
141220141372
if( pFrom->fg.isUsing
141221141373
&& sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0
141222141374
){
141223141375
/* In a join with a USING clause, omit columns in the
141224141376
** using clause from the table on the right. */
@@ -141226,10 +141378,11 @@
141226141378
}
141227141379
}
141228141380
pRight = sqlite3Expr(db, TK_ID, zName);
141229141381
if( (pTabList->nSrc>1
141230141382
&& ( (pFrom->fg.jointype & JT_LTORJ)==0
141383
+ || (selFlags & SF_NestedFrom)!=0
141231141384
|| !inAnyUsingClause(zName,pFrom,pTabList->nSrc-i-1)
141232141385
)
141233141386
)
141234141387
|| IN_RENAME_OBJECT
141235141388
){
@@ -141259,17 +141412,24 @@
141259141412
}else{
141260141413
pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
141261141414
zSchemaName, zTabName, zName);
141262141415
testcase( pX->zEName==0 );
141263141416
}
141264
- 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
+ }
141265141425
}else if( longNames ){
141266141426
pX->zEName = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
141267
- pX->eEName = ENAME_NAME;
141427
+ pX->fg.eEName = ENAME_NAME;
141268141428
}else{
141269141429
pX->zEName = sqlite3DbStrDup(db, zName);
141270
- pX->eEName = ENAME_NAME;
141430
+ pX->fg.eEName = ENAME_NAME;
141271141431
}
141272141432
}
141273141433
}
141274141434
if( !tableSeen ){
141275141435
if( zTName ){
@@ -142393,17 +142553,17 @@
142393142553
if( pDest->eDest==SRT_EphemTab ){
142394142554
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr);
142395142555
if( p->selFlags & SF_NestedFrom ){
142396142556
/* Delete or NULL-out result columns that will never be used */
142397142557
int ii;
142398
- 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--){
142399142559
sqlite3ExprDelete(db, pEList->a[ii].pExpr);
142400142560
sqlite3DbFree(db, pEList->a[ii].zEName);
142401142561
pEList->nExpr--;
142402142562
}
142403142563
for(ii=0; ii<pEList->nExpr; ii++){
142404
- 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;
142405142565
}
142406142566
}
142407142567
}
142408142568
142409142569
/* Set the limiter.
@@ -142551,12 +142711,13 @@
142551142711
** ASC or DESC order - only that each group is returned contiguously.
142552142712
** So set the ASC/DESC flags in the GROUP BY to match those in the
142553142713
** ORDER BY to maximize the chances of rows being delivered in an
142554142714
** order that makes the ORDER BY redundant. */
142555142715
for(ii=0; ii<pGroupBy->nExpr; ii++){
142556
- u8 sortFlags = sSort.pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_DESC;
142557
- 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;
142558142719
}
142559142720
if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
142560142721
orderByGrp = 1;
142561142722
}
142562142723
}
@@ -144207,20 +144368,20 @@
144207144368
pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zCnName);
144208144369
pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144209144370
if( !db->mallocFailed ){
144210144371
struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144211144372
pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName);
144212
- pItem->eEName = ENAME_NAME;
144373
+ pItem->fg.eEName = ENAME_NAME;
144213144374
}
144214144375
}
144215144376
}else{
144216144377
Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
144217144378
pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144218144379
if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){
144219144380
struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144220144381
pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName);
144221
- pItem->eEName = pList->a[i].eEName;
144382
+ pItem->fg.eEName = pList->a[i].fg.eEName;
144222144383
}
144223144384
}
144224144385
}
144225144386
return pNew;
144226144387
}
@@ -146789,10 +146950,11 @@
146789146950
#endif
146790146951
}
146791146952
146792146953
assert( rc==SQLITE_OK );
146793146954
if( pOut==0 ){
146955
+ nRes = sqlite3BtreeGetRequestedReserve(pTemp);
146794146956
rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
146795146957
}
146796146958
146797146959
end_of_vacuum:
146798146960
/* Restore the original value of db->flags */
@@ -149443,20 +149605,26 @@
149443149605
149444149606
iTab = 0;
149445149607
if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
149446149608
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
149447149609
}else{
149448
- sqlite3 *db = pParse->db;
149449
- pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
149450
-
149451
- 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{
149452149621
aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
149453
- eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
149454
- pTerm->pExpr->iTable = iTab;
149622
+ eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP|IN_INDEX_REUSE_CUR, 0, aiMap,&iTab);
149623
+ iTab = pExpr->iTable;
149455149624
}
149456
- sqlite3ExprDelete(db, pX);
149457
- pX = pTerm->pExpr;
149625
+ pX = pExpr;
149458149626
}
149459149627
149460149628
if( eType==IN_INDEX_INDEX_DESC ){
149461149629
testcase( bRev );
149462149630
bRev = !bRev;
@@ -150079,16 +150247,16 @@
150079150247
** that contains the value of pExpr.
150080150248
*/
150081150249
static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
150082150250
IdxExprTrans *pX = p->u.pIdxTrans;
150083150251
if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
150252
+ pExpr = sqlite3ExprSkipCollate(pExpr);
150084150253
preserveExpr(pX, pExpr);
150085150254
pExpr->affExpr = sqlite3ExprAffinity(pExpr);
150086150255
pExpr->op = TK_COLUMN;
150087150256
pExpr->iTable = pX->iIdxCur;
150088150257
pExpr->iColumn = pX->iIdxCol;
150089
- testcase( ExprHasProperty(pExpr, EP_Skip) );
150090150258
testcase( ExprHasProperty(pExpr, EP_Unlikely) );
150091150259
ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn);
150092150260
pExpr->y.pTab = 0;
150093150261
return WRC_Prune;
150094150262
}else{
@@ -150238,10 +150406,12 @@
150238150406
if( pLevel->regFilter==0 ) continue;
150239150407
if( pLevel->pWLoop->nSkip ) continue;
150240150408
/* ,--- Because sqlite3ConstructBloomFilter() has will not have set
150241150409
** vvvvv--' pLevel->regFilter if this were true. */
150242150410
if( NEVER(pLoop->prereq & notReady) ) continue;
150411
+ assert( pLevel->addrBrk==0 );
150412
+ pLevel->addrBrk = addrNxt;
150243150413
if( pLoop->wsFlags & WHERE_IPK ){
150244150414
WhereTerm *pTerm = pLoop->aLTerm[0];
150245150415
int regRowid;
150246150416
assert( pTerm!=0 );
150247150417
assert( pTerm->pExpr!=0 );
@@ -150264,10 +150434,11 @@
150264150434
sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
150265150435
addrNxt, r1, nEq);
150266150436
VdbeCoverage(pParse->pVdbe);
150267150437
}
150268150438
pLevel->regFilter = 0;
150439
+ pLevel->addrBrk = 0;
150269150440
}
150270150441
}
150271150442
150272150443
/*
150273150444
** Generate code for the start of the iLevel-th loop in the WHERE clause
@@ -151444,11 +151615,11 @@
151444151615
continue;
151445151616
}
151446151617
pE = pTerm->pExpr;
151447151618
assert( pE!=0 );
151448151619
if( (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ))
151449
- && !ExprHasProperty(pE,EP_FromJoin)
151620
+ && !ExprHasProperty(pE,EP_FromJoin|EP_InnerJoin)
151450151621
){
151451151622
continue;
151452151623
}
151453151624
151454151625
if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
@@ -153335,11 +153506,11 @@
153335153506
if( pOrderBy ){
153336153507
for(ii=0; ii<pOrderBy->nExpr; ii++){
153337153508
Expr *pExpr = pOrderBy->a[ii].pExpr;
153338153509
if( pExpr->op!=TK_COLUMN ) return;
153339153510
if( pExpr->iTable!=iCsr ) return;
153340
- if( pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_BIGNULL ) return;
153511
+ if( pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) return;
153341153512
}
153342153513
}
153343153514
153344153515
/* All conditions are met. Add the terms to the where-clause object. */
153345153516
assert( p->pLimit->op==TK_LIMIT );
@@ -154765,11 +154936,11 @@
154765154936
if( sqlite3ExprIsConstant(pExpr) ){
154766154937
continue;
154767154938
}
154768154939
154769154940
/* Virtual tables are unable to deal with NULLS FIRST */
154770
- if( pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL ) break;
154941
+ if( pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) break;
154771154942
154772154943
/* First case - a direct column references without a COLLATE operator */
154773154944
if( pExpr->op==TK_COLUMN && pExpr->iTable==pSrc->iCursor ){
154774154945
assert( pExpr->iColumn>=XN_ROWID && pExpr->iColumn<pTab->nCol );
154775154946
continue;
@@ -154877,11 +155048,11 @@
154877155048
if( sqlite3ExprIsConstant(pExpr) ) continue;
154878155049
assert( pExpr->op==TK_COLUMN
154879155050
|| (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN
154880155051
&& pExpr->iColumn==pExpr->pLeft->iColumn) );
154881155052
pIdxOrderBy[j].iColumn = pExpr->iColumn;
154882
- pIdxOrderBy[j].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC;
155053
+ pIdxOrderBy[j].desc = pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC;
154883155054
j++;
154884155055
}
154885155056
pIdxInfo->nOrderBy = j;
154886155057
154887155058
*pmNoOmit = mNoOmit;
@@ -156395,11 +156566,11 @@
156395156566
/* tag-20191211-001: Do not allow constraints from the WHERE clause to
156396156567
** be used by the right table of a LEFT JOIN nor by the left table of a
156397156568
** RIGHT JOIN. Only constraints in the
156398156569
** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
156399156570
if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
156400
- && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
156571
+ && !ExprHasProperty(pTerm->pExpr, EP_FromJoin|EP_InnerJoin)
156401156572
){
156402156573
continue;
156403156574
}
156404156575
156405156576
if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
@@ -157703,13 +157874,11 @@
157703157874
pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
157704157875
pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
157705157876
if( (pItem->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
157706157877
/* This condition is true when pItem is the FROM clause term on the
157707157878
** right-hand-side of a OUTER or CROSS JOIN. */
157708
- mPrereq = mPrior;
157709
- }else{
157710
- mPrereq = 0;
157879
+ mPrereq |= mPrior;
157711157880
}
157712157881
#ifndef SQLITE_OMIT_VIRTUALTABLE
157713157882
if( IsVirtual(pItem->pTab) ){
157714157883
SrcItem *p;
157715157884
for(p=&pItem[1]; p<pEnd; p++){
@@ -158016,20 +158185,22 @@
158016158185
}
158017158186
if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
158018158187
/* Make sure the sort order is compatible in an ORDER BY clause.
158019158188
** Sort order is irrelevant for a GROUP BY clause. */
158020158189
if( revSet ){
158021
- if( (rev ^ revIdx)!=(pOrderBy->a[i].sortFlags&KEYINFO_ORDER_DESC) ){
158190
+ if( (rev ^ revIdx)
158191
+ != (pOrderBy->a[i].fg.sortFlags&KEYINFO_ORDER_DESC)
158192
+ ){
158022158193
isMatch = 0;
158023158194
}
158024158195
}else{
158025
- rev = revIdx ^ (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC);
158196
+ rev = revIdx ^ (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC);
158026158197
if( rev ) *pRevMask |= MASKBIT(iLoop);
158027158198
revSet = 1;
158028158199
}
158029158200
}
158030
- if( isMatch && (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL) ){
158201
+ if( isMatch && (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL) ){
158031158202
if( j==pLoop->u.btree.nEq ){
158032158203
pLoop->wsFlags |= WHERE_BIGNULL_SORT;
158033158204
}else{
158034158205
isMatch = 0;
158035158206
}
@@ -160789,11 +160960,11 @@
160789160960
pSub->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
160790160961
pSub->u.zToken = 0;
160791160962
}
160792160963
}
160793160964
pList = sqlite3ExprListAppend(pParse, pList, pDup);
160794
- 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;
160795160966
}
160796160967
}
160797160968
return pList;
160798160969
}
160799160970
@@ -161990,11 +162161,11 @@
161990162161
windowReadPeerValues(p, csr1, reg1);
161991162162
windowReadPeerValues(p, csr2, reg2);
161992162163
161993162164
assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
161994162165
assert( pOrderBy && pOrderBy->nExpr==1 );
161995
- if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
162166
+ if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_DESC ){
161996162167
switch( op ){
161997162168
case OP_Ge: op = OP_Le; break;
161998162169
case OP_Gt: op = OP_Lt; break;
161999162170
default: assert( op==OP_Le ); op = OP_Ge; break;
162000162171
}
@@ -162023,11 +162194,11 @@
162023162194
** }
162024162195
**
162025162196
** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is
162026162197
** not taken, control jumps over the comparison operator coded below this
162027162198
** block. */
162028
- if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_BIGNULL ){
162199
+ if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_BIGNULL ){
162029162200
/* This block runs if reg1 contains a NULL. */
162030162201
int addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v);
162031162202
switch( op ){
162032162203
case OP_Ge:
162033162204
sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl);
@@ -226807,11 +226978,11 @@
226807226978
/* State used by the fts5DataXXX() functions. */
226808226979
sqlite3_blob *pReader; /* RO incr-blob open on %_data table */
226809226980
sqlite3_stmt *pWriter; /* "INSERT ... %_data VALUES(?,?)" */
226810226981
sqlite3_stmt *pDeleter; /* "DELETE FROM %_data ... id>=? AND id<=?" */
226811226982
sqlite3_stmt *pIdxWriter; /* "INSERT ... %_idx VALUES(?,?,?,?)" */
226812
- sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=? */
226983
+ sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=?" */
226813226984
sqlite3_stmt *pIdxSelect;
226814226985
int nRead; /* Total number of blocks read */
226815226986
226816226987
sqlite3_stmt *pDataVersion;
226817226988
i64 iStructVersion; /* data_version when pStruct read */
@@ -236124,11 +236295,11 @@
236124236295
int nArg, /* Number of args */
236125236296
sqlite3_value **apUnused /* Function arguments */
236126236297
){
236127236298
assert( nArg==0 );
236128236299
UNUSED_PARAM2(nArg, apUnused);
236129
- sqlite3_result_text(pCtx, "fts5: 2022-04-26 19:16:11 b1bec72043f798f4d4d30e6b60a45ed4dc521115c8a9f97bb8228e3f089deefb", -1, SQLITE_TRANSIENT);
236300
+ sqlite3_result_text(pCtx, "fts5: 2022-05-10 00:24:01 c6c3115f3a008cf9b0d7c5c812f17e38c8a75a904032c5f05f0bea03a7340527", -1, SQLITE_TRANSIENT);
236130236301
}
236131236302
236132236303
/*
236133236304
** Return true if zName is the extension on one of the shadow tables used
236134236305
** by this module.
236135236306
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.39.0"
456 #define SQLITE_VERSION_NUMBER 3039000
457 #define SQLITE_SOURCE_ID "2022-04-26 19:16:11 b1bec72043f798f4d4d30e6b60a45ed4dc521115c8a9f97bb8228e3f089deefb"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -17054,10 +17054,11 @@
17054 #define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */
17055 #define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */
17056 #define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
17057 #define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
17058 #define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
 
17059 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
17060
17061 /*
17062 ** Macros for testing whether or not optimizations are enabled or disabled.
17063 */
@@ -17399,10 +17400,11 @@
17399 #define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
17400 #define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */
17401 #define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
17402 #define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
17403 #define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */
 
17404 #define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
17405 #define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
17406
17407 /*
17408 ** A "Collating Sequence" is defined by an instance of the following
@@ -18272,17 +18274,22 @@
18272 int nExpr; /* Number of expressions on the list */
18273 int nAlloc; /* Number of a[] slots allocated */
18274 struct ExprList_item { /* For each expression in the list */
18275 Expr *pExpr; /* The parse tree for this expression */
18276 char *zEName; /* Token associated with this expression */
18277 u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18278 unsigned eEName :2; /* Meaning of zEName */
18279 unsigned done :1; /* A flag to indicate when processing is finished */
18280 unsigned reusable :1; /* Constant expression is reusable */
18281 unsigned bSorterRef :1; /* Defer evaluation until after sorting */
18282 unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
18283 unsigned bUsed: 1; /* This column used in a SF_NestedFrom subquery */
 
 
 
 
 
18284 union {
18285 struct { /* Used by any ExprList other than Parse.pConsExpr */
18286 u16 iOrderByCol; /* For ORDER BY, column number in result set */
18287 u16 iAlias; /* Index into Parse.aAlias[] for zName */
18288 } x;
@@ -19732,10 +19739,11 @@
19732 SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
19733 SQLITE_PRIVATE void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*);
19734 SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
19735 SQLITE_PRIVATE void sqlite3TreeViewBareIdList(TreeView*, const IdList*, const char*);
19736 SQLITE_PRIVATE void sqlite3TreeViewIdList(TreeView*, const IdList*, u8, const char*);
 
19737 SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*);
19738 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
19739 SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8);
19740 SQLITE_PRIVATE void sqlite3TreeViewUpsert(TreeView*, const Upsert*, u8);
19741 SQLITE_PRIVATE void sqlite3TreeViewDelete(const With*, const SrcList*, const Expr*,
@@ -20587,10 +20595,11 @@
20587 ** Allowed flags for the 3rd parameter to sqlite3FindInIndex().
20588 */
20589 #define IN_INDEX_NOOP_OK 0x0001 /* OK to return IN_INDEX_NOOP */
20590 #define IN_INDEX_MEMBERSHIP 0x0002 /* IN operator used for membership test */
20591 #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */
 
20592 SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*, int*);
20593
20594 SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
20595 SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *);
20596 #if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
@@ -31057,10 +31066,57 @@
31057 */
31058 static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){
31059 sqlite3TreeViewPush(&p, moreFollows);
31060 sqlite3TreeViewLine(p, "%s", zLabel);
31061 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31062
31063 /*
31064 ** Generate a human-readable description of a WITH clause.
31065 */
31066 SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){
@@ -31113,10 +31169,11 @@
31113 int i;
31114 if( pSrc==0 ) return;
31115 for(i=0; i<pSrc->nSrc; i++){
31116 const SrcItem *pItem = &pSrc->a[i];
31117 StrAccum x;
 
31118 char zLine[100];
31119 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
31120 x.printfFlags |= SQLITE_PRINTF_INTERNAL;
31121 sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
31122 if( pItem->pTab ){
@@ -31141,13 +31198,24 @@
31141 if( pItem->fg.isCte ){
31142 sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
31143 }
31144 sqlite3StrAccumFinish(&x);
31145 sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
 
 
 
 
 
 
 
31146 if( pItem->pSelect ){
 
 
 
 
31147 assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
31148 sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
31149 }
31150 if( pItem->fg.isTabFunc ){
31151 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
31152 }
31153 sqlite3TreeViewPop(&pView);
@@ -31310,10 +31378,11 @@
31310 /*
31311 ** Generate a human-readable explanation for a Window object
31312 */
31313 SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
31314 int nElement = 0;
 
31315 if( pWin->pFilter ){
31316 sqlite3TreeViewItem(pView, "FILTER", 1);
31317 sqlite3TreeViewExpr(pView, pWin->pFilter, 0);
31318 sqlite3TreeViewPop(&pView);
31319 }
@@ -31374,10 +31443,11 @@
31374 #ifndef SQLITE_OMIT_WINDOWFUNC
31375 /*
31376 ** Generate a human-readable explanation for a Window Function object
31377 */
31378 SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){
 
31379 sqlite3TreeViewPush(&pView, more);
31380 sqlite3TreeViewLine(pView, "WINFUNC %s(%d)",
31381 pWin->pWFunc->zName, pWin->pWFunc->nArg);
31382 sqlite3TreeViewWindow(pView, pWin, 0);
31383 sqlite3TreeViewPop(&pView);
@@ -31625,11 +31695,21 @@
31625 sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
31626 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
31627 break;
31628 }
31629 case TK_IN: {
31630 sqlite3TreeViewLine(pView, "IN flags=0x%x", pExpr->flags);
 
 
 
 
 
 
 
 
 
 
31631 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
31632 if( ExprUseXSelect(pExpr) ){
31633 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
31634 }else{
31635 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
@@ -31776,17 +31856,19 @@
31776 if( j || zName ){
31777 sqlite3TreeViewPush(&pView, moreToFollow);
31778 moreToFollow = 0;
31779 sqlite3TreeViewLine(pView, 0);
31780 if( zName ){
31781 switch( pList->a[i].eEName ){
31782 default:
31783 fprintf(stdout, "AS %s ", zName);
31784 break;
31785 case ENAME_TAB:
31786 fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
31787 if( pList->a[i].bUsed==0 ) fprintf(stdout, "(unused) ");
 
 
31788 break;
31789 case ENAME_SPAN:
31790 fprintf(stdout, "SPAN(\"%s\") ", zName);
31791 break;
31792 }
@@ -89252,10 +89334,12 @@
89252 if( pOp->p2==0 ) break;
89253
89254 /* Most jump operations do a goto to this spot in order to update
89255 ** the pOp pointer. */
89256 jump_to_p2:
 
 
89257 pOp = &aOp[pOp->p2 - 1];
89258 break;
89259 }
89260
89261 /* Opcode: EndCoroutine P1 * * * *
@@ -101463,11 +101547,11 @@
101463 const char *zTab,
101464 const char *zDb
101465 ){
101466 int n;
101467 const char *zSpan;
101468 if( pItem->eEName!=ENAME_TAB ) return 0;
101469 zSpan = pItem->zEName;
101470 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
101471 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
101472 return 0;
101473 }
@@ -101692,12 +101776,13 @@
101692 }
101693 cnt++;
101694 cntTab = 2;
101695 pMatch = pItem;
101696 pExpr->iColumn = j;
101697 pEList->a[j].bUsed = 1;
101698 hit = 1;
 
101699 }
101700 if( hit || zTab==0 ) continue;
101701 }
101702 assert( zDb==0 || zTab!=0 );
101703 if( zTab ){
@@ -101916,11 +102001,11 @@
101916 ){
101917 pEList = pNC->uNC.pEList;
101918 assert( pEList!=0 );
101919 for(j=0; j<pEList->nExpr; j++){
101920 char *zAs = pEList->a[j].zEName;
101921 if( pEList->a[j].eEName==ENAME_NAME
101922 && sqlite3_stricmp(zAs, zCol)==0
101923 ){
101924 Expr *pOrig;
101925 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
101926 assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
@@ -102669,11 +102754,11 @@
102669 if( pE->op==TK_ID ){
102670 const char *zCol;
102671 assert( !ExprHasProperty(pE, EP_IntValue) );
102672 zCol = pE->u.zToken;
102673 for(i=0; i<pEList->nExpr; i++){
102674 if( pEList->a[i].eEName==ENAME_NAME
102675 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
102676 ){
102677 return i+1;
102678 }
102679 }
@@ -102790,11 +102875,11 @@
102790 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
102791 sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
102792 return 1;
102793 }
102794 for(i=0; i<pOrderBy->nExpr; i++){
102795 pOrderBy->a[i].done = 0;
102796 }
102797 pSelect->pNext = 0;
102798 while( pSelect->pPrior ){
102799 pSelect->pPrior->pNext = pSelect;
102800 pSelect = pSelect->pPrior;
@@ -102805,11 +102890,11 @@
102805 pEList = pSelect->pEList;
102806 assert( pEList!=0 );
102807 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
102808 int iCol = -1;
102809 Expr *pE, *pDup;
102810 if( pItem->done ) continue;
102811 pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
102812 if( NEVER(pE==0) ) continue;
102813 if( sqlite3ExprIsInteger(pE, &iCol) ){
102814 if( iCol<=0 || iCol>pEList->nExpr ){
102815 resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE);
@@ -102858,19 +102943,19 @@
102858 pParent->pLeft = pNew;
102859 }
102860 sqlite3ExprDelete(db, pE);
102861 pItem->u.x.iOrderByCol = (u16)iCol;
102862 }
102863 pItem->done = 1;
102864 }else{
102865 moreToDo = 1;
102866 }
102867 }
102868 pSelect = pSelect->pNext;
102869 }
102870 for(i=0; i<pOrderBy->nExpr; i++){
102871 if( pOrderBy->a[i].done==0 ){
102872 sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any "
102873 "column in the result set", i+1);
102874 return 1;
102875 }
102876 }
@@ -105110,16 +105195,12 @@
105110 }
105111 pNewExpr->pLeft = pPriorSelectColNew;
105112 }
105113 }
105114 pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
105115 pItem->sortFlags = pOldItem->sortFlags;
105116 pItem->eEName = pOldItem->eEName;
105117 pItem->done = 0;
105118 pItem->bNulls = pOldItem->bNulls;
105119 pItem->bUsed = pOldItem->bUsed;
105120 pItem->bSorterRef = pOldItem->bSorterRef;
105121 pItem->u = pOldItem->u;
105122 }
105123 return pNew;
105124 }
105125
@@ -105415,20 +105496,20 @@
105415 || eNulls==SQLITE_SO_ASC
105416 || eNulls==SQLITE_SO_DESC
105417 );
105418
105419 pItem = &p->a[p->nExpr-1];
105420 assert( pItem->bNulls==0 );
105421 if( iSortOrder==SQLITE_SO_UNDEFINED ){
105422 iSortOrder = SQLITE_SO_ASC;
105423 }
105424 pItem->sortFlags = (u8)iSortOrder;
105425
105426 if( eNulls!=SQLITE_SO_UNDEFINED ){
105427 pItem->bNulls = 1;
105428 if( iSortOrder!=eNulls ){
105429 pItem->sortFlags |= KEYINFO_ORDER_BIGNULL;
105430 }
105431 }
105432 }
105433
105434 /*
@@ -105450,11 +105531,11 @@
105450 if( pList ){
105451 struct ExprList_item *pItem;
105452 assert( pList->nExpr>0 );
105453 pItem = &pList->a[pList->nExpr-1];
105454 assert( pItem->zEName==0 );
105455 assert( pItem->eEName==ENAME_NAME );
105456 pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
105457 if( dequote ){
105458 /* If dequote==0, then pName->z does not point to part of a DDL
105459 ** statement handled by the parser. And so no token need be added
105460 ** to the token-map. */
@@ -105485,11 +105566,11 @@
105485 if( pList ){
105486 struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
105487 assert( pList->nExpr>0 );
105488 if( pItem->zEName==0 ){
105489 pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd);
105490 pItem->eEName = ENAME_SPAN;
105491 }
105492 }
105493 }
105494
105495 /*
@@ -105782,11 +105863,11 @@
105782
105783 /*
105784 ** Check pExpr to see if it is an invariant constraint on data source pSrc.
105785 ** This is an optimization. False negatives will perhaps cause slower
105786 ** queries, but false positives will yield incorrect answers. So when in
105787 ** double, return 0.
105788 **
105789 ** To be an invariant constraint, the following must be true:
105790 **
105791 ** (1) pExpr cannot refer to any table other than pSrc->iCursor.
105792 **
@@ -106141,11 +106222,11 @@
106141 ** The job of this routine is to find or create a b-tree object that can
106142 ** be used either to test for membership in the RHS set or to iterate through
106143 ** all members of the RHS set, skipping duplicates.
106144 **
106145 ** A cursor is opened on the b-tree object that is the RHS of the IN operator
106146 ** and pX->iTable is set to the index of that cursor.
106147 **
106148 ** The returned value of this function indicates the b-tree type, as follows:
106149 **
106150 ** IN_INDEX_ROWID - The cursor was opened on a database table.
106151 ** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index.
@@ -106161,11 +106242,14 @@
106161 ** SELECT <column1>, <column2>... FROM <table>
106162 **
106163 ** If the RHS of the IN operator is a list or a more complex subquery, then
106164 ** an ephemeral table might need to be generated from the RHS and then
106165 ** pX->iTable made to point to the ephemeral table instead of an
106166 ** existing table.
 
 
 
106167 **
106168 ** The inFlags parameter must contain, at a minimum, one of the bits
106169 ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
106170 ** IN_INDEX_MEMBERSHIP, then the generated table will be used for a fast
106171 ** membership test. When the IN_INDEX_LOOP bit is set, the IN index will
@@ -106222,16 +106306,21 @@
106222 int *aiMap, /* Mapping from Index fields to RHS fields */
106223 int *piTab /* OUT: index to use */
106224 ){
106225 Select *p; /* SELECT to the right of IN operator */
106226 int eType = 0; /* Type of RHS table. IN_INDEX_* */
106227 int iTab = pParse->nTab++; /* Cursor of the RHS table */
106228 int mustBeUnique; /* True if RHS must be unique */
106229 Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */
106230
106231 assert( pX->op==TK_IN );
106232 mustBeUnique = (inFlags & IN_INDEX_LOOP)!=0;
 
 
 
 
 
106233
106234 /* If the RHS of this IN(...) operator is a SELECT, and if it matters
106235 ** whether or not the SELECT result contains NULL values, check whether
106236 ** or not NULL is actually possible (it may not be, for example, due
106237 ** to NOT NULL constraints in the schema). If no NULL values are possible,
@@ -106393,10 +106482,12 @@
106393 if( eType==0
106394 && (inFlags & IN_INDEX_NOOP_OK)
106395 && ExprUseXList(pX)
106396 && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
106397 ){
 
 
106398 eType = IN_INDEX_NOOP;
106399 }
106400
106401 if( eType==0 ){
106402 /* Could not find an existing table or index to use as the RHS b-tree.
@@ -106559,11 +106650,13 @@
106559 pExpr->x.pSelect->selId));
106560 }
106561 assert( ExprUseYSub(pExpr) );
106562 sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
106563 pExpr->y.sub.iAddr);
106564 sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
 
 
106565 sqlite3VdbeJumpHere(v, addrOnce);
106566 return;
106567 }
106568
106569 /* Begin coding the subroutine */
@@ -108299,11 +108392,13 @@
108299 p = pParse->pConstExpr;
108300 if( regDest<0 && p ){
108301 struct ExprList_item *pItem;
108302 int i;
108303 for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
108304 if( pItem->reusable && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0 ){
 
 
108305 return pItem->u.iConstExprReg;
108306 }
108307 }
108308 }
108309 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
@@ -108322,11 +108417,11 @@
108322 sqlite3VdbeJumpHere(v, addr);
108323 }else{
108324 p = sqlite3ExprListAppend(pParse, p, pExpr);
108325 if( p ){
108326 struct ExprList_item *pItem = &p->a[p->nExpr-1];
108327 pItem->reusable = regDest<0;
108328 if( regDest<0 ) regDest = ++pParse->nMem;
108329 pItem->u.iConstExprReg = regDest;
108330 }
108331 pParse->pConstExpr = p;
108332 }
@@ -108456,11 +108551,11 @@
108456 n = pList->nExpr;
108457 if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
108458 for(pItem=pList->a, i=0; i<n; i++, pItem++){
108459 Expr *pExpr = pItem->pExpr;
108460 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
108461 if( pItem->bSorterRef ){
108462 i--;
108463 n--;
108464 }else
108465 #endif
108466 if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
@@ -109081,11 +109176,11 @@
109081 if( pA->nExpr!=pB->nExpr ) return 1;
109082 for(i=0; i<pA->nExpr; i++){
109083 int res;
109084 Expr *pExprA = pA->a[i].pExpr;
109085 Expr *pExprB = pB->a[i].pExpr;
109086 if( pA->a[i].sortFlags!=pB->a[i].sortFlags ) return 1;
109087 if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
109088 }
109089 return 0;
109090 }
109091
@@ -110770,11 +110865,11 @@
110770 return WRC_Prune;
110771 }
110772 if( ALWAYS(p->pEList) ){
110773 ExprList *pList = p->pEList;
110774 for(i=0; i<pList->nExpr; i++){
110775 if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){
110776 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
110777 }
110778 }
110779 }
110780 if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
@@ -110819,11 +110914,11 @@
110819 memset(&sWalker, 0, sizeof(Walker));
110820 sWalker.pParse = pParse;
110821 sWalker.xExprCallback = renameUnmapExprCb;
110822 sqlite3WalkExprList(&sWalker, pEList);
110823 for(i=0; i<pEList->nExpr; i++){
110824 if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) ){
110825 sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
110826 }
110827 }
110828 }
110829 }
@@ -110977,11 +111072,11 @@
110977 ){
110978 if( pEList ){
110979 int i;
110980 for(i=0; i<pEList->nExpr; i++){
110981 const char *zName = pEList->a[i].zEName;
110982 if( ALWAYS(pEList->a[i].eEName==ENAME_NAME)
110983 && ALWAYS(zName!=0)
110984 && 0==sqlite3_stricmp(zName, zOld)
110985 ){
110986 renameTokenFind(pParse, pCtx, (const void*)zName);
110987 }
@@ -113002,13 +113097,18 @@
113002 ** * the index contains 100 rows,
113003 ** * "WHERE a=?" matches 10 rows, and
113004 ** * "WHERE a=? AND b=?" matches 2 rows.
113005 **
113006 ** If D is the count of distinct values and K is the total number of
113007 ** rows, then each estimate is computed as:
113008 **
113009 ** I = (K+D-1)/D
 
 
 
 
 
113010 */
113011 sqlite3_str sStat; /* Text of the constructed "stat" line */
113012 int i; /* Loop counter */
113013
113014 sqlite3StrAccumInit(&sStat, 0, 0, 0, (p->nKeyCol+1)*100);
@@ -113015,10 +113115,11 @@
113015 sqlite3_str_appendf(&sStat, "%llu",
113016 p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow);
113017 for(i=0; i<p->nKeyCol; i++){
113018 u64 nDistinct = p->current.anDLt[i] + 1;
113019 u64 iVal = (p->nRow + nDistinct - 1) / nDistinct;
 
113020 sqlite3_str_appendf(&sStat, " %llu", iVal);
113021 assert( p->current.anEq[i] );
113022 }
113023 sqlite3ResultStrAccum(context, &sStat);
113024 }
@@ -116854,11 +116955,11 @@
116854 }
116855 pTab->iPKey = iCol;
116856 pTab->keyConf = (u8)onError;
116857 assert( autoInc==0 || autoInc==1 );
116858 pTab->tabFlags |= autoInc*TF_Autoincrement;
116859 if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags;
116860 (void)sqlite3HasExplicitNulls(pParse, pList);
116861 }else if( autoInc ){
116862 #ifndef SQLITE_OMIT_AUTOINCREMENT
116863 sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
116864 "INTEGER PRIMARY KEY");
@@ -117348,11 +117449,11 @@
117348 return;
117349 }
117350 if( IN_RENAME_OBJECT ){
117351 sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
117352 }
117353 pList->a[0].sortFlags = pParse->iPkSortOrder;
117354 assert( pParse->pNewTable==pTab );
117355 pTab->iPKey = -1;
117356 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
117357 SQLITE_IDXTYPE_PRIMARYKEY);
117358 if( pParse->nErr ){
@@ -118836,12 +118937,12 @@
118836 */
118837 SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
118838 if( pList ){
118839 int i;
118840 for(i=0; i<pList->nExpr; i++){
118841 if( pList->a[i].bNulls ){
118842 u8 sf = pList->a[i].sortFlags;
118843 sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s",
118844 (sf==0 || sf==3) ? "FIRST" : "LAST"
118845 );
118846 return 1;
118847 }
@@ -119190,11 +119291,11 @@
119190 if( !zColl ) zColl = sqlite3StrBINARY;
119191 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
119192 goto exit_create_index;
119193 }
119194 pIndex->azColl[i] = zColl;
119195 requestedSortOrder = pListItem->sortFlags & sortOrderMask;
119196 pIndex->aSortOrder[i] = (u8)requestedSortOrder;
119197 }
119198
119199 /* Append the table key to the end of the index. For WITHOUT ROWID
119200 ** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
@@ -130512,15 +130613,23 @@
130512 sqlite3_total_changes64,
130513 /* Version 3.37.0 and later */
130514 sqlite3_autovacuum_pages,
130515 /* Version 3.38.0 and later */
130516 sqlite3_error_offset,
 
130517 sqlite3_vtab_rhs_value,
130518 sqlite3_vtab_distinct,
130519 sqlite3_vtab_in,
130520 sqlite3_vtab_in_first,
130521 sqlite3_vtab_in_next,
 
 
 
 
 
 
 
130522 /* Version 3.39.0 and later */
130523 #ifndef SQLITE_OMIT_DESERIALIZE
130524 sqlite3_deserialize,
130525 sqlite3_serialize
130526 #else
@@ -134960,10 +135069,18 @@
134960 db->pParse = pParse;
134961 pParse->db = db;
134962 if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory");
134963 }
134964
 
 
 
 
 
 
 
 
134965 /*
134966 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
134967 */
134968 static int sqlite3Prepare(
134969 sqlite3 *db, /* Database handle. */
@@ -135134,11 +135251,11 @@
135134 ** or encounters a permanent error. A schema problem after one schema
135135 ** reset is considered a permanent error. */
135136 rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
135137 assert( rc==SQLITE_OK || *ppStmt==0 );
135138 if( rc==SQLITE_OK || db->mallocFailed ) break;
135139 }while( rc==SQLITE_ERROR_RETRY
135140 || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
135141 sqlite3BtreeLeaveAll(db);
135142 rc = sqlite3ApiExit(db, rc);
135143 assert( (rc&db->errMask)==rc );
135144 db->busyHandler.nBusy = 0;
@@ -135685,11 +135802,11 @@
135685 ExprList *pResults;
135686 assert( pItem->pSelect!=0 );
135687 pResults = pItem->pSelect->pEList;
135688 assert( pResults!=0 );
135689 assert( iCol>=0 && iCol<pResults->nExpr );
135690 pResults->a[iCol].bUsed = 1;
135691 }
135692 }
135693
135694 /*
135695 ** Search the tables iStart..iEnd (inclusive) in pSrc, looking for a
@@ -136353,11 +136470,11 @@
136353 ** the row from table t1 is stored instead. Then, as records are extracted from
136354 ** the sorter to return to the user, the required value of bigblob is
136355 ** retrieved directly from table t1. If the values are very large, this
136356 ** can be more efficient than storing them directly in the sorter records.
136357 **
136358 ** The ExprList_item.bSorterRef flag is set for each expression in pEList
136359 ** for which the sorter-reference optimization should be enabled.
136360 ** Additionally, the pSort->aDefer[] array is populated with entries
136361 ** for all cursors required to evaluate all selected expressions. Finally.
136362 ** output variable (*ppExtra) is set to an expression list containing
136363 ** expressions for all extra PK values that should be stored in the
@@ -136413,11 +136530,11 @@
136413 pSort->aDefer[nDefer].iCsr = pExpr->iTable;
136414 pSort->aDefer[nDefer].nKey = nKey;
136415 nDefer++;
136416 }
136417 }
136418 pItem->bSorterRef = 1;
136419 }
136420 }
136421 }
136422 pSort->nDefer = (u8)nDefer;
136423 *ppExtra = pExtra;
@@ -136544,11 +136661,11 @@
136544 ** from the sorter by the optimizations in this branch */
136545 pEList = p->pEList;
136546 for(i=0; i<pEList->nExpr; i++){
136547 if( pEList->a[i].u.x.iOrderByCol>0
136548 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
136549 || pEList->a[i].bSorterRef
136550 #endif
136551 ){
136552 nResultCol--;
136553 regOrig = 0;
136554 }
@@ -136906,11 +137023,11 @@
136906 pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
136907 if( pInfo ){
136908 assert( sqlite3KeyInfoIsWriteable(pInfo) );
136909 for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
136910 pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr);
136911 pInfo->aSortFlags[i-iStart] = pItem->sortFlags;
136912 }
136913 }
136914 return pInfo;
136915 }
136916
@@ -137045,11 +137162,11 @@
137045 iSortTab = iTab;
137046 bSeq = 1;
137047 }
137048 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
137049 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137050 if( aOutEx[i].bSorterRef ) continue;
137051 #endif
137052 if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
137053 }
137054 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137055 if( pSort->nDefer ){
@@ -137082,11 +137199,11 @@
137082 sqlite3ReleaseTempRange(pParse, regKey, nRefKey);
137083 }
137084 #endif
137085 for(i=nColumn-1; i>=0; i--){
137086 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137087 if( aOutEx[i].bSorterRef ){
137088 sqlite3ExprCode(pParse, aOutEx[i].pExpr, regRow+i);
137089 }else
137090 #endif
137091 {
137092 int iRead;
@@ -137448,11 +137565,11 @@
137448
137449 assert( p!=0 );
137450 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
137451 assert( p->op!=TK_COLUMN
137452 || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
137453 if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){
137454 /* An AS clause always takes first priority */
137455 char *zName = pEList->a[i].zEName;
137456 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
137457 }else if( srcName && p->op==TK_COLUMN ){
137458 char *zCol;
@@ -137534,13 +137651,14 @@
137534 *pnCol = nCol;
137535 *paCol = aCol;
137536
137537 for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
137538 struct ExprList_item *pX = &pEList->a[i];
 
137539 /* Get an appropriate name for the column
137540 */
137541 if( (zName = pX->zEName)!=0 && pX->eEName==ENAME_NAME ){
137542 /* If the column contains an "AS <name>" phrase, use <name> as the name */
137543 }else{
137544 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pX->pExpr);
137545 while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
137546 pColExpr = pColExpr->pRight;
@@ -137570,11 +137688,14 @@
137570
137571 /* Make sure the column name is unique. If the name is not unique,
137572 ** append an integer to the name so that it becomes unique.
137573 */
137574 cnt = 0;
137575 while( zName && sqlite3HashFind(&ht, zName)!=0 ){
 
 
 
137576 nName = sqlite3Strlen30(zName);
137577 if( nName>0 ){
137578 for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
137579 if( zName[j]==':' ) nName = j;
137580 }
@@ -137581,12 +137702,15 @@
137581 zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
137582 if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
137583 }
137584 pCol->zCnName = zName;
137585 pCol->hName = sqlite3StrIHash(zName);
 
 
 
137586 sqlite3ColumnPropertiesFromName(0, pCol);
137587 if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
137588 sqlite3OomFault(db);
137589 }
137590 }
137591 sqlite3HashClear(&ht);
137592 if( db->mallocFailed ){
@@ -137839,11 +137963,11 @@
137839 pOrderBy->a[i].pExpr =
137840 sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
137841 }
137842 assert( sqlite3KeyInfoIsWriteable(pRet) );
137843 pRet->aColl[i] = pColl;
137844 pRet->aSortFlags[i] = pOrderBy->a[i].sortFlags;
137845 }
137846 }
137847
137848 return pRet;
137849 }
@@ -140445,11 +140569,11 @@
140445 }else{
140446 return eRet;
140447 }
140448 *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
140449 assert( pOrderBy!=0 || db->mallocFailed );
140450 if( pOrderBy ) pOrderBy->a[0].sortFlags = sortFlags;
140451 return eRet;
140452 }
140453
140454 /*
140455 ** The select statement passed as the first argument is an aggregate query.
@@ -141152,11 +141276,11 @@
141152 /* This particular expression does not need to be expanded.
141153 */
141154 pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
141155 if( pNew ){
141156 pNew->a[pNew->nExpr-1].zEName = a[k].zEName;
141157 pNew->a[pNew->nExpr-1].eEName = a[k].eEName;
141158 a[k].zEName = 0;
141159 }
141160 a[k].pExpr = 0;
141161 }else{
141162 /* This expression is a "*" or a "TABLE.*" and needs to be
@@ -141172,10 +141296,11 @@
141172 Table *pTab = pFrom->pTab; /* Table for this data source */
141173 ExprList *pNestedFrom; /* Result-set of a nested FROM clause */
141174 char *zTabName; /* AS name for this data source */
141175 const char *zSchemaName = 0; /* Schema name for this data source */
141176 int iDb; /* Schema index for this data src */
 
141177
141178 if( (zTabName = pFrom->zAlias)==0 ){
141179 zTabName = pTab->zName;
141180 }
141181 if( db->mallocFailed ) break;
@@ -141190,10 +141315,31 @@
141190 continue;
141191 }
141192 pNestedFrom = 0;
141193 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
141194 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141195 }
141196 for(j=0; j<pTab->nCol; j++){
141197 char *zName = pTab->aCol[j].zCnName;
141198 struct ExprList_item *pX; /* Newly added ExprList term */
141199
@@ -141211,14 +141357,20 @@
141211 */
141212 if( (p->selFlags & SF_IncludeHidden)==0
141213 && IsHiddenColumn(&pTab->aCol[j])
141214 ){
141215 continue;
 
 
 
 
 
 
141216 }
141217 tableSeen = 1;
141218
141219 if( i>0 && zTName==0 ){
141220 if( pFrom->fg.isUsing
141221 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0
141222 ){
141223 /* In a join with a USING clause, omit columns in the
141224 ** using clause from the table on the right. */
@@ -141226,10 +141378,11 @@
141226 }
141227 }
141228 pRight = sqlite3Expr(db, TK_ID, zName);
141229 if( (pTabList->nSrc>1
141230 && ( (pFrom->fg.jointype & JT_LTORJ)==0
 
141231 || !inAnyUsingClause(zName,pFrom,pTabList->nSrc-i-1)
141232 )
141233 )
141234 || IN_RENAME_OBJECT
141235 ){
@@ -141259,17 +141412,24 @@
141259 }else{
141260 pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
141261 zSchemaName, zTabName, zName);
141262 testcase( pX->zEName==0 );
141263 }
141264 pX->eEName = ENAME_TAB;
 
 
 
 
 
 
 
141265 }else if( longNames ){
141266 pX->zEName = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
141267 pX->eEName = ENAME_NAME;
141268 }else{
141269 pX->zEName = sqlite3DbStrDup(db, zName);
141270 pX->eEName = ENAME_NAME;
141271 }
141272 }
141273 }
141274 if( !tableSeen ){
141275 if( zTName ){
@@ -142393,17 +142553,17 @@
142393 if( pDest->eDest==SRT_EphemTab ){
142394 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr);
142395 if( p->selFlags & SF_NestedFrom ){
142396 /* Delete or NULL-out result columns that will never be used */
142397 int ii;
142398 for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].bUsed==0; ii--){
142399 sqlite3ExprDelete(db, pEList->a[ii].pExpr);
142400 sqlite3DbFree(db, pEList->a[ii].zEName);
142401 pEList->nExpr--;
142402 }
142403 for(ii=0; ii<pEList->nExpr; ii++){
142404 if( pEList->a[ii].bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL;
142405 }
142406 }
142407 }
142408
142409 /* Set the limiter.
@@ -142551,12 +142711,13 @@
142551 ** ASC or DESC order - only that each group is returned contiguously.
142552 ** So set the ASC/DESC flags in the GROUP BY to match those in the
142553 ** ORDER BY to maximize the chances of rows being delivered in an
142554 ** order that makes the ORDER BY redundant. */
142555 for(ii=0; ii<pGroupBy->nExpr; ii++){
142556 u8 sortFlags = sSort.pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_DESC;
142557 pGroupBy->a[ii].sortFlags = sortFlags;
 
142558 }
142559 if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
142560 orderByGrp = 1;
142561 }
142562 }
@@ -144207,20 +144368,20 @@
144207 pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zCnName);
144208 pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144209 if( !db->mallocFailed ){
144210 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144211 pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName);
144212 pItem->eEName = ENAME_NAME;
144213 }
144214 }
144215 }else{
144216 Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
144217 pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144218 if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){
144219 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144220 pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName);
144221 pItem->eEName = pList->a[i].eEName;
144222 }
144223 }
144224 }
144225 return pNew;
144226 }
@@ -146789,10 +146950,11 @@
146789 #endif
146790 }
146791
146792 assert( rc==SQLITE_OK );
146793 if( pOut==0 ){
 
146794 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
146795 }
146796
146797 end_of_vacuum:
146798 /* Restore the original value of db->flags */
@@ -149443,20 +149605,26 @@
149443
149444 iTab = 0;
149445 if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
149446 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
149447 }else{
149448 sqlite3 *db = pParse->db;
149449 pX = removeUnindexableInClauseTerms(pParse, iEq, pLoop, pX);
149450
149451 if( !db->mallocFailed ){
 
 
 
 
 
 
 
149452 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
149453 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap, &iTab);
149454 pTerm->pExpr->iTable = iTab;
149455 }
149456 sqlite3ExprDelete(db, pX);
149457 pX = pTerm->pExpr;
149458 }
149459
149460 if( eType==IN_INDEX_INDEX_DESC ){
149461 testcase( bRev );
149462 bRev = !bRev;
@@ -150079,16 +150247,16 @@
150079 ** that contains the value of pExpr.
150080 */
150081 static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
150082 IdxExprTrans *pX = p->u.pIdxTrans;
150083 if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
 
150084 preserveExpr(pX, pExpr);
150085 pExpr->affExpr = sqlite3ExprAffinity(pExpr);
150086 pExpr->op = TK_COLUMN;
150087 pExpr->iTable = pX->iIdxCur;
150088 pExpr->iColumn = pX->iIdxCol;
150089 testcase( ExprHasProperty(pExpr, EP_Skip) );
150090 testcase( ExprHasProperty(pExpr, EP_Unlikely) );
150091 ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn);
150092 pExpr->y.pTab = 0;
150093 return WRC_Prune;
150094 }else{
@@ -150238,10 +150406,12 @@
150238 if( pLevel->regFilter==0 ) continue;
150239 if( pLevel->pWLoop->nSkip ) continue;
150240 /* ,--- Because sqlite3ConstructBloomFilter() has will not have set
150241 ** vvvvv--' pLevel->regFilter if this were true. */
150242 if( NEVER(pLoop->prereq & notReady) ) continue;
 
 
150243 if( pLoop->wsFlags & WHERE_IPK ){
150244 WhereTerm *pTerm = pLoop->aLTerm[0];
150245 int regRowid;
150246 assert( pTerm!=0 );
150247 assert( pTerm->pExpr!=0 );
@@ -150264,10 +150434,11 @@
150264 sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
150265 addrNxt, r1, nEq);
150266 VdbeCoverage(pParse->pVdbe);
150267 }
150268 pLevel->regFilter = 0;
 
150269 }
150270 }
150271
150272 /*
150273 ** Generate code for the start of the iLevel-th loop in the WHERE clause
@@ -151444,11 +151615,11 @@
151444 continue;
151445 }
151446 pE = pTerm->pExpr;
151447 assert( pE!=0 );
151448 if( (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ))
151449 && !ExprHasProperty(pE,EP_FromJoin)
151450 ){
151451 continue;
151452 }
151453
151454 if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
@@ -153335,11 +153506,11 @@
153335 if( pOrderBy ){
153336 for(ii=0; ii<pOrderBy->nExpr; ii++){
153337 Expr *pExpr = pOrderBy->a[ii].pExpr;
153338 if( pExpr->op!=TK_COLUMN ) return;
153339 if( pExpr->iTable!=iCsr ) return;
153340 if( pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_BIGNULL ) return;
153341 }
153342 }
153343
153344 /* All conditions are met. Add the terms to the where-clause object. */
153345 assert( p->pLimit->op==TK_LIMIT );
@@ -154765,11 +154936,11 @@
154765 if( sqlite3ExprIsConstant(pExpr) ){
154766 continue;
154767 }
154768
154769 /* Virtual tables are unable to deal with NULLS FIRST */
154770 if( pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL ) break;
154771
154772 /* First case - a direct column references without a COLLATE operator */
154773 if( pExpr->op==TK_COLUMN && pExpr->iTable==pSrc->iCursor ){
154774 assert( pExpr->iColumn>=XN_ROWID && pExpr->iColumn<pTab->nCol );
154775 continue;
@@ -154877,11 +155048,11 @@
154877 if( sqlite3ExprIsConstant(pExpr) ) continue;
154878 assert( pExpr->op==TK_COLUMN
154879 || (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN
154880 && pExpr->iColumn==pExpr->pLeft->iColumn) );
154881 pIdxOrderBy[j].iColumn = pExpr->iColumn;
154882 pIdxOrderBy[j].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC;
154883 j++;
154884 }
154885 pIdxInfo->nOrderBy = j;
154886
154887 *pmNoOmit = mNoOmit;
@@ -156395,11 +156566,11 @@
156395 /* tag-20191211-001: Do not allow constraints from the WHERE clause to
156396 ** be used by the right table of a LEFT JOIN nor by the left table of a
156397 ** RIGHT JOIN. Only constraints in the
156398 ** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
156399 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
156400 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
156401 ){
156402 continue;
156403 }
156404
156405 if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
@@ -157703,13 +157874,11 @@
157703 pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
157704 pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
157705 if( (pItem->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
157706 /* This condition is true when pItem is the FROM clause term on the
157707 ** right-hand-side of a OUTER or CROSS JOIN. */
157708 mPrereq = mPrior;
157709 }else{
157710 mPrereq = 0;
157711 }
157712 #ifndef SQLITE_OMIT_VIRTUALTABLE
157713 if( IsVirtual(pItem->pTab) ){
157714 SrcItem *p;
157715 for(p=&pItem[1]; p<pEnd; p++){
@@ -158016,20 +158185,22 @@
158016 }
158017 if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
158018 /* Make sure the sort order is compatible in an ORDER BY clause.
158019 ** Sort order is irrelevant for a GROUP BY clause. */
158020 if( revSet ){
158021 if( (rev ^ revIdx)!=(pOrderBy->a[i].sortFlags&KEYINFO_ORDER_DESC) ){
 
 
158022 isMatch = 0;
158023 }
158024 }else{
158025 rev = revIdx ^ (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC);
158026 if( rev ) *pRevMask |= MASKBIT(iLoop);
158027 revSet = 1;
158028 }
158029 }
158030 if( isMatch && (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL) ){
158031 if( j==pLoop->u.btree.nEq ){
158032 pLoop->wsFlags |= WHERE_BIGNULL_SORT;
158033 }else{
158034 isMatch = 0;
158035 }
@@ -160789,11 +160960,11 @@
160789 pSub->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
160790 pSub->u.zToken = 0;
160791 }
160792 }
160793 pList = sqlite3ExprListAppend(pParse, pList, pDup);
160794 if( pList ) pList->a[nInit+i].sortFlags = pAppend->a[i].sortFlags;
160795 }
160796 }
160797 return pList;
160798 }
160799
@@ -161990,11 +162161,11 @@
161990 windowReadPeerValues(p, csr1, reg1);
161991 windowReadPeerValues(p, csr2, reg2);
161992
161993 assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
161994 assert( pOrderBy && pOrderBy->nExpr==1 );
161995 if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
161996 switch( op ){
161997 case OP_Ge: op = OP_Le; break;
161998 case OP_Gt: op = OP_Lt; break;
161999 default: assert( op==OP_Le ); op = OP_Ge; break;
162000 }
@@ -162023,11 +162194,11 @@
162023 ** }
162024 **
162025 ** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is
162026 ** not taken, control jumps over the comparison operator coded below this
162027 ** block. */
162028 if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_BIGNULL ){
162029 /* This block runs if reg1 contains a NULL. */
162030 int addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v);
162031 switch( op ){
162032 case OP_Ge:
162033 sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl);
@@ -226807,11 +226978,11 @@
226807 /* State used by the fts5DataXXX() functions. */
226808 sqlite3_blob *pReader; /* RO incr-blob open on %_data table */
226809 sqlite3_stmt *pWriter; /* "INSERT ... %_data VALUES(?,?)" */
226810 sqlite3_stmt *pDeleter; /* "DELETE FROM %_data ... id>=? AND id<=?" */
226811 sqlite3_stmt *pIdxWriter; /* "INSERT ... %_idx VALUES(?,?,?,?)" */
226812 sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=? */
226813 sqlite3_stmt *pIdxSelect;
226814 int nRead; /* Total number of blocks read */
226815
226816 sqlite3_stmt *pDataVersion;
226817 i64 iStructVersion; /* data_version when pStruct read */
@@ -236124,11 +236295,11 @@
236124 int nArg, /* Number of args */
236125 sqlite3_value **apUnused /* Function arguments */
236126 ){
236127 assert( nArg==0 );
236128 UNUSED_PARAM2(nArg, apUnused);
236129 sqlite3_result_text(pCtx, "fts5: 2022-04-26 19:16:11 b1bec72043f798f4d4d30e6b60a45ed4dc521115c8a9f97bb8228e3f089deefb", -1, SQLITE_TRANSIENT);
236130 }
236131
236132 /*
236133 ** Return true if zName is the extension on one of the shadow tables used
236134 ** by this module.
236135
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.39.0"
456 #define SQLITE_VERSION_NUMBER 3039000
457 #define SQLITE_SOURCE_ID "2022-05-10 00:24:01 c6c3115f3a008cf9b0d7c5c812f17e38c8a75a904032c5f05f0bea03a7340527"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -17054,10 +17054,11 @@
17054 #define SQLITE_BloomFilter 0x00080000 /* Use a Bloom filter on searches */
17055 #define SQLITE_BloomPulldown 0x00100000 /* Run Bloom filters early */
17056 #define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
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 */
17060 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
17061
17062 /*
17063 ** Macros for testing whether or not optimizations are enabled or disabled.
17064 */
@@ -17399,10 +17400,11 @@
17400 #define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
17401 #define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */
17402 #define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
17403 #define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
17404 #define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */
17405 #define COLFLAG_NOEXPAND 0x0400 /* Omit this column when expanding "*" */
17406 #define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
17407 #define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
17408
17409 /*
17410 ** A "Collating Sequence" is defined by an instance of the following
@@ -18272,17 +18274,22 @@
18274 int nExpr; /* Number of expressions on the list */
18275 int nAlloc; /* Number of a[] slots allocated */
18276 struct ExprList_item { /* For each expression in the list */
18277 Expr *pExpr; /* The parse tree for this expression */
18278 char *zEName; /* Token associated with this expression */
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;
18291 union {
18292 struct { /* Used by any ExprList other than Parse.pConsExpr */
18293 u16 iOrderByCol; /* For ORDER BY, column number in result set */
18294 u16 iAlias; /* Index into Parse.aAlias[] for zName */
18295 } x;
@@ -19732,10 +19739,11 @@
19739 SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8);
19740 SQLITE_PRIVATE void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*);
19741 SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*);
19742 SQLITE_PRIVATE void sqlite3TreeViewBareIdList(TreeView*, const IdList*, const char*);
19743 SQLITE_PRIVATE void sqlite3TreeViewIdList(TreeView*, const IdList*, u8, const char*);
19744 SQLITE_PRIVATE void sqlite3TreeViewColumnList(TreeView*, const Column*, int, u8);
19745 SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*);
19746 SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8);
19747 SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8);
19748 SQLITE_PRIVATE void sqlite3TreeViewUpsert(TreeView*, const Upsert*, u8);
19749 SQLITE_PRIVATE void sqlite3TreeViewDelete(const With*, const SrcList*, const Expr*,
@@ -20587,10 +20595,11 @@
20595 ** Allowed flags for the 3rd parameter to sqlite3FindInIndex().
20596 */
20597 #define IN_INDEX_NOOP_OK 0x0001 /* OK to return IN_INDEX_NOOP */
20598 #define IN_INDEX_MEMBERSHIP 0x0002 /* IN operator used for membership test */
20599 #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */
20600 #define IN_INDEX_REUSE_CUR 0x0008 /* Reuse prior table cursor */
20601 SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*, int*);
20602
20603 SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
20604 SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *);
20605 #if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
@@ -31057,10 +31066,57 @@
31066 */
31067 static void sqlite3TreeViewItem(TreeView *p, const char *zLabel,u8 moreFollows){
31068 sqlite3TreeViewPush(&p, moreFollows);
31069 sqlite3TreeViewLine(p, "%s", zLabel);
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 }
31118
31119 /*
31120 ** Generate a human-readable description of a WITH clause.
31121 */
31122 SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 moreToFollow){
@@ -31113,10 +31169,11 @@
31169 int i;
31170 if( pSrc==0 ) return;
31171 for(i=0; i<pSrc->nSrc; i++){
31172 const SrcItem *pItem = &pSrc->a[i];
31173 StrAccum x;
31174 int n = 0;
31175 char zLine[100];
31176 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
31177 x.printfFlags |= SQLITE_PRINTF_INTERNAL;
31178 sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
31179 if( pItem->pTab ){
@@ -31141,13 +31198,24 @@
31198 if( pItem->fg.isCte ){
31199 sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
31200 }
31201 sqlite3StrAccumFinish(&x);
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 }
31210 if( pItem->pSelect ){
31211 if( pItem->pTab ){
31212 Table *pTab = pItem->pTab;
31213 sqlite3TreeViewColumnList(pView, pTab->aCol, pTab->nCol, 1);
31214 }
31215 assert( pItem->fg.isNestedFrom == IsNestedFrom(pItem->pSelect) );
31216 sqlite3TreeViewSelect(pView, pItem->pSelect, (--n)>0);
31217 }
31218 if( pItem->fg.isTabFunc ){
31219 sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:");
31220 }
31221 sqlite3TreeViewPop(&pView);
@@ -31310,10 +31378,11 @@
31378 /*
31379 ** Generate a human-readable explanation for a Window object
31380 */
31381 SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
31382 int nElement = 0;
31383 if( pWin==0 ) return;
31384 if( pWin->pFilter ){
31385 sqlite3TreeViewItem(pView, "FILTER", 1);
31386 sqlite3TreeViewExpr(pView, pWin->pFilter, 0);
31387 sqlite3TreeViewPop(&pView);
31388 }
@@ -31374,10 +31443,11 @@
31443 #ifndef SQLITE_OMIT_WINDOWFUNC
31444 /*
31445 ** Generate a human-readable explanation for a Window Function object
31446 */
31447 SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView *pView, const Window *pWin, u8 more){
31448 if( pWin==0 ) return;
31449 sqlite3TreeViewPush(&pView, more);
31450 sqlite3TreeViewLine(pView, "WINFUNC %s(%d)",
31451 pWin->pWFunc->zName, pWin->pWFunc->nArg);
31452 sqlite3TreeViewWindow(pView, pWin, 0);
31453 sqlite3TreeViewPop(&pView);
@@ -31625,11 +31695,21 @@
31695 sqlite3TreeViewLine(pView, "subquery-expr flags=0x%x", pExpr->flags);
31696 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
31697 break;
31698 }
31699 case TK_IN: {
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);
31711 sqlite3TreeViewExpr(pView, pExpr->pLeft, 1);
31712 if( ExprUseXSelect(pExpr) ){
31713 sqlite3TreeViewSelect(pView, pExpr->x.pSelect, 0);
31714 }else{
31715 sqlite3TreeViewExprList(pView, pExpr->x.pList, 0, 0);
@@ -31776,17 +31856,19 @@
31856 if( j || zName ){
31857 sqlite3TreeViewPush(&pView, moreToFollow);
31858 moreToFollow = 0;
31859 sqlite3TreeViewLine(pView, 0);
31860 if( zName ){
31861 switch( pList->a[i].fg.eEName ){
31862 default:
31863 fprintf(stdout, "AS %s ", zName);
31864 break;
31865 case ENAME_TAB:
31866 fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
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) ");
31870 break;
31871 case ENAME_SPAN:
31872 fprintf(stdout, "SPAN(\"%s\") ", zName);
31873 break;
31874 }
@@ -89252,10 +89334,12 @@
89334 if( pOp->p2==0 ) break;
89335
89336 /* Most jump operations do a goto to this spot in order to update
89337 ** the pOp pointer. */
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 */
89341 pOp = &aOp[pOp->p2 - 1];
89342 break;
89343 }
89344
89345 /* Opcode: EndCoroutine P1 * * * *
@@ -101463,11 +101547,11 @@
101547 const char *zTab,
101548 const char *zDb
101549 ){
101550 int n;
101551 const char *zSpan;
101552 if( pItem->fg.eEName!=ENAME_TAB ) return 0;
101553 zSpan = pItem->zEName;
101554 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
101555 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
101556 return 0;
101557 }
@@ -101692,12 +101776,13 @@
101776 }
101777 cnt++;
101778 cntTab = 2;
101779 pMatch = pItem;
101780 pExpr->iColumn = j;
101781 pEList->a[j].fg.bUsed = 1;
101782 hit = 1;
101783 if( pEList->a[j].fg.bUsingTerm ) break;
101784 }
101785 if( hit || zTab==0 ) continue;
101786 }
101787 assert( zDb==0 || zTab!=0 );
101788 if( zTab ){
@@ -101916,11 +102001,11 @@
102001 ){
102002 pEList = pNC->uNC.pEList;
102003 assert( pEList!=0 );
102004 for(j=0; j<pEList->nExpr; j++){
102005 char *zAs = pEList->a[j].zEName;
102006 if( pEList->a[j].fg.eEName==ENAME_NAME
102007 && sqlite3_stricmp(zAs, zCol)==0
102008 ){
102009 Expr *pOrig;
102010 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
102011 assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
@@ -102669,11 +102754,11 @@
102754 if( pE->op==TK_ID ){
102755 const char *zCol;
102756 assert( !ExprHasProperty(pE, EP_IntValue) );
102757 zCol = pE->u.zToken;
102758 for(i=0; i<pEList->nExpr; i++){
102759 if( pEList->a[i].fg.eEName==ENAME_NAME
102760 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
102761 ){
102762 return i+1;
102763 }
102764 }
@@ -102790,11 +102875,11 @@
102875 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
102876 sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
102877 return 1;
102878 }
102879 for(i=0; i<pOrderBy->nExpr; i++){
102880 pOrderBy->a[i].fg.done = 0;
102881 }
102882 pSelect->pNext = 0;
102883 while( pSelect->pPrior ){
102884 pSelect->pPrior->pNext = pSelect;
102885 pSelect = pSelect->pPrior;
@@ -102805,11 +102890,11 @@
102890 pEList = pSelect->pEList;
102891 assert( pEList!=0 );
102892 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
102893 int iCol = -1;
102894 Expr *pE, *pDup;
102895 if( pItem->fg.done ) continue;
102896 pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
102897 if( NEVER(pE==0) ) continue;
102898 if( sqlite3ExprIsInteger(pE, &iCol) ){
102899 if( iCol<=0 || iCol>pEList->nExpr ){
102900 resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE);
@@ -102858,19 +102943,19 @@
102943 pParent->pLeft = pNew;
102944 }
102945 sqlite3ExprDelete(db, pE);
102946 pItem->u.x.iOrderByCol = (u16)iCol;
102947 }
102948 pItem->fg.done = 1;
102949 }else{
102950 moreToDo = 1;
102951 }
102952 }
102953 pSelect = pSelect->pNext;
102954 }
102955 for(i=0; i<pOrderBy->nExpr; i++){
102956 if( pOrderBy->a[i].fg.done==0 ){
102957 sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any "
102958 "column in the result set", i+1);
102959 return 1;
102960 }
102961 }
@@ -105110,16 +105195,12 @@
105195 }
105196 pNewExpr->pLeft = pPriorSelectColNew;
105197 }
105198 }
105199 pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
105200 pItem->fg = pOldItem->fg;
105201 pItem->fg.done = 0;
 
 
 
 
105202 pItem->u = pOldItem->u;
105203 }
105204 return pNew;
105205 }
105206
@@ -105415,20 +105496,20 @@
105496 || eNulls==SQLITE_SO_ASC
105497 || eNulls==SQLITE_SO_DESC
105498 );
105499
105500 pItem = &p->a[p->nExpr-1];
105501 assert( pItem->fg.bNulls==0 );
105502 if( iSortOrder==SQLITE_SO_UNDEFINED ){
105503 iSortOrder = SQLITE_SO_ASC;
105504 }
105505 pItem->fg.sortFlags = (u8)iSortOrder;
105506
105507 if( eNulls!=SQLITE_SO_UNDEFINED ){
105508 pItem->fg.bNulls = 1;
105509 if( iSortOrder!=eNulls ){
105510 pItem->fg.sortFlags |= KEYINFO_ORDER_BIGNULL;
105511 }
105512 }
105513 }
105514
105515 /*
@@ -105450,11 +105531,11 @@
105531 if( pList ){
105532 struct ExprList_item *pItem;
105533 assert( pList->nExpr>0 );
105534 pItem = &pList->a[pList->nExpr-1];
105535 assert( pItem->zEName==0 );
105536 assert( pItem->fg.eEName==ENAME_NAME );
105537 pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
105538 if( dequote ){
105539 /* If dequote==0, then pName->z does not point to part of a DDL
105540 ** statement handled by the parser. And so no token need be added
105541 ** to the token-map. */
@@ -105485,11 +105566,11 @@
105566 if( pList ){
105567 struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
105568 assert( pList->nExpr>0 );
105569 if( pItem->zEName==0 ){
105570 pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd);
105571 pItem->fg.eEName = ENAME_SPAN;
105572 }
105573 }
105574 }
105575
105576 /*
@@ -105782,11 +105863,11 @@
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 **
@@ -106141,11 +106222,11 @@
106222 ** The job of this routine is to find or create a b-tree object that can
106223 ** be used either to test for membership in the RHS set or to iterate through
106224 ** all members of the RHS set, skipping duplicates.
106225 **
106226 ** A cursor is opened on the b-tree object that is the RHS of the IN operator
106227 ** and the *piTab parameter is set to the index of that cursor.
106228 **
106229 ** The returned value of this function indicates the b-tree type, as follows:
106230 **
106231 ** IN_INDEX_ROWID - The cursor was opened on a database table.
106232 ** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index.
@@ -106161,11 +106242,14 @@
106242 ** SELECT <column1>, <column2>... FROM <table>
106243 **
106244 ** If the RHS of the IN operator is a list or a more complex subquery, then
106245 ** an ephemeral table might need to be generated from the RHS and then
106246 ** pX->iTable made to point to the ephemeral table instead of an
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.
106251 **
106252 ** The inFlags parameter must contain, at a minimum, one of the bits
106253 ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains
106254 ** IN_INDEX_MEMBERSHIP, then the generated table will be used for a fast
106255 ** membership test. When the IN_INDEX_LOOP bit is set, the IN index will
@@ -106222,16 +106306,21 @@
106306 int *aiMap, /* Mapping from Index fields to RHS fields */
106307 int *piTab /* OUT: index to use */
106308 ){
106309 Select *p; /* SELECT to the right of IN operator */
106310 int eType = 0; /* Type of RHS table. IN_INDEX_* */
106311 int iTab; /* Cursor of the RHS table */
106312 int mustBeUnique; /* True if RHS must be unique */
106313 Vdbe *v = sqlite3GetVdbe(pParse); /* Virtual machine being coded */
106314
106315 assert( pX->op==TK_IN );
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 }
106322
106323 /* If the RHS of this IN(...) operator is a SELECT, and if it matters
106324 ** whether or not the SELECT result contains NULL values, check whether
106325 ** or not NULL is actually possible (it may not be, for example, due
106326 ** to NOT NULL constraints in the schema). If no NULL values are possible,
@@ -106393,10 +106482,12 @@
106482 if( eType==0
106483 && (inFlags & IN_INDEX_NOOP_OK)
106484 && ExprUseXList(pX)
106485 && (!sqlite3InRhsIsConstant(pX) || pX->x.pList->nExpr<=2)
106486 ){
106487 pParse->nTab--; /* Back out the allocation of the unused cursor */
106488 iTab = -1; /* Cursor is not allocated */
106489 eType = IN_INDEX_NOOP;
106490 }
106491
106492 if( eType==0 ){
106493 /* Could not find an existing table or index to use as the RHS b-tree.
@@ -106559,11 +106650,13 @@
106650 pExpr->x.pSelect->selId));
106651 }
106652 assert( ExprUseYSub(pExpr) );
106653 sqlite3VdbeAddOp2(v, OP_Gosub, pExpr->y.sub.regReturn,
106654 pExpr->y.sub.iAddr);
106655 if( iTab!=pExpr->iTable ){
106656 sqlite3VdbeAddOp2(v, OP_OpenDup, iTab, pExpr->iTable);
106657 }
106658 sqlite3VdbeJumpHere(v, addrOnce);
106659 return;
106660 }
106661
106662 /* Begin coding the subroutine */
@@ -108299,11 +108392,13 @@
108392 p = pParse->pConstExpr;
108393 if( regDest<0 && p ){
108394 struct ExprList_item *pItem;
108395 int i;
108396 for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
108397 if( pItem->fg.reusable
108398 && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0
108399 ){
108400 return pItem->u.iConstExprReg;
108401 }
108402 }
108403 }
108404 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
@@ -108322,11 +108417,11 @@
108417 sqlite3VdbeJumpHere(v, addr);
108418 }else{
108419 p = sqlite3ExprListAppend(pParse, p, pExpr);
108420 if( p ){
108421 struct ExprList_item *pItem = &p->a[p->nExpr-1];
108422 pItem->fg.reusable = regDest<0;
108423 if( regDest<0 ) regDest = ++pParse->nMem;
108424 pItem->u.iConstExprReg = regDest;
108425 }
108426 pParse->pConstExpr = p;
108427 }
@@ -108456,11 +108551,11 @@
108551 n = pList->nExpr;
108552 if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
108553 for(pItem=pList->a, i=0; i<n; i++, pItem++){
108554 Expr *pExpr = pItem->pExpr;
108555 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
108556 if( pItem->fg.bSorterRef ){
108557 i--;
108558 n--;
108559 }else
108560 #endif
108561 if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
@@ -109081,11 +109176,11 @@
109176 if( pA->nExpr!=pB->nExpr ) return 1;
109177 for(i=0; i<pA->nExpr; i++){
109178 int res;
109179 Expr *pExprA = pA->a[i].pExpr;
109180 Expr *pExprB = pB->a[i].pExpr;
109181 if( pA->a[i].fg.sortFlags!=pB->a[i].fg.sortFlags ) return 1;
109182 if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
109183 }
109184 return 0;
109185 }
109186
@@ -110770,11 +110865,11 @@
110865 return WRC_Prune;
110866 }
110867 if( ALWAYS(p->pEList) ){
110868 ExprList *pList = p->pEList;
110869 for(i=0; i<pList->nExpr; i++){
110870 if( pList->a[i].zEName && pList->a[i].fg.eEName==ENAME_NAME ){
110871 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
110872 }
110873 }
110874 }
110875 if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
@@ -110819,11 +110914,11 @@
110914 memset(&sWalker, 0, sizeof(Walker));
110915 sWalker.pParse = pParse;
110916 sWalker.xExprCallback = renameUnmapExprCb;
110917 sqlite3WalkExprList(&sWalker, pEList);
110918 for(i=0; i<pEList->nExpr; i++){
110919 if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME) ){
110920 sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
110921 }
110922 }
110923 }
110924 }
@@ -110977,11 +111072,11 @@
111072 ){
111073 if( pEList ){
111074 int i;
111075 for(i=0; i<pEList->nExpr; i++){
111076 const char *zName = pEList->a[i].zEName;
111077 if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME)
111078 && ALWAYS(zName!=0)
111079 && 0==sqlite3_stricmp(zName, zOld)
111080 ){
111081 renameTokenFind(pParse, pCtx, (const void*)zName);
111082 }
@@ -113002,13 +113097,18 @@
113097 ** * the index contains 100 rows,
113098 ** * "WHERE a=?" matches 10 rows, and
113099 ** * "WHERE a=? AND b=?" matches 2 rows.
113100 **
113101 ** If D is the count of distinct values and K is the total number of
113102 ** rows, then each estimate is usually computed as:
113103 **
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.
113110 */
113111 sqlite3_str sStat; /* Text of the constructed "stat" line */
113112 int i; /* Loop counter */
113113
113114 sqlite3StrAccumInit(&sStat, 0, 0, 0, (p->nKeyCol+1)*100);
@@ -113015,10 +113115,11 @@
113115 sqlite3_str_appendf(&sStat, "%llu",
113116 p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow);
113117 for(i=0; i<p->nKeyCol; i++){
113118 u64 nDistinct = p->current.anDLt[i] + 1;
113119 u64 iVal = (p->nRow + nDistinct - 1) / nDistinct;
113120 if( iVal==2 && p->nRow*10 <= nDistinct*11 ) iVal = 1;
113121 sqlite3_str_appendf(&sStat, " %llu", iVal);
113122 assert( p->current.anEq[i] );
113123 }
113124 sqlite3ResultStrAccum(context, &sStat);
113125 }
@@ -116854,11 +116955,11 @@
116955 }
116956 pTab->iPKey = iCol;
116957 pTab->keyConf = (u8)onError;
116958 assert( autoInc==0 || autoInc==1 );
116959 pTab->tabFlags |= autoInc*TF_Autoincrement;
116960 if( pList ) pParse->iPkSortOrder = pList->a[0].fg.sortFlags;
116961 (void)sqlite3HasExplicitNulls(pParse, pList);
116962 }else if( autoInc ){
116963 #ifndef SQLITE_OMIT_AUTOINCREMENT
116964 sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
116965 "INTEGER PRIMARY KEY");
@@ -117348,11 +117449,11 @@
117449 return;
117450 }
117451 if( IN_RENAME_OBJECT ){
117452 sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
117453 }
117454 pList->a[0].fg.sortFlags = pParse->iPkSortOrder;
117455 assert( pParse->pNewTable==pTab );
117456 pTab->iPKey = -1;
117457 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
117458 SQLITE_IDXTYPE_PRIMARYKEY);
117459 if( pParse->nErr ){
@@ -118836,12 +118937,12 @@
118937 */
118938 SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
118939 if( pList ){
118940 int i;
118941 for(i=0; i<pList->nExpr; i++){
118942 if( pList->a[i].fg.bNulls ){
118943 u8 sf = pList->a[i].fg.sortFlags;
118944 sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s",
118945 (sf==0 || sf==3) ? "FIRST" : "LAST"
118946 );
118947 return 1;
118948 }
@@ -119190,11 +119291,11 @@
119291 if( !zColl ) zColl = sqlite3StrBINARY;
119292 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
119293 goto exit_create_index;
119294 }
119295 pIndex->azColl[i] = zColl;
119296 requestedSortOrder = pListItem->fg.sortFlags & sortOrderMask;
119297 pIndex->aSortOrder[i] = (u8)requestedSortOrder;
119298 }
119299
119300 /* Append the table key to the end of the index. For WITHOUT ROWID
119301 ** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
@@ -130512,15 +130613,23 @@
130613 sqlite3_total_changes64,
130614 /* Version 3.37.0 and later */
130615 sqlite3_autovacuum_pages,
130616 /* Version 3.38.0 and later */
130617 sqlite3_error_offset,
130618 #ifndef SQLITE_OMIT_VIRTUALTABLE
130619 sqlite3_vtab_rhs_value,
130620 sqlite3_vtab_distinct,
130621 sqlite3_vtab_in,
130622 sqlite3_vtab_in_first,
130623 sqlite3_vtab_in_next,
130624 #else
130625 0,
130626 0,
130627 0,
130628 0,
130629 0,
130630 #endif
130631 /* Version 3.39.0 and later */
130632 #ifndef SQLITE_OMIT_DESERIALIZE
130633 sqlite3_deserialize,
130634 sqlite3_serialize
130635 #else
@@ -134960,10 +135069,18 @@
135069 db->pParse = pParse;
135070 pParse->db = db;
135071 if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory");
135072 }
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
135082 /*
135083 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
135084 */
135085 static int sqlite3Prepare(
135086 sqlite3 *db, /* Database handle. */
@@ -135134,11 +135251,11 @@
135251 ** or encounters a permanent error. A schema problem after one schema
135252 ** reset is considered a permanent error. */
135253 rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
135254 assert( rc==SQLITE_OK || *ppStmt==0 );
135255 if( rc==SQLITE_OK || db->mallocFailed ) break;
135256 }while( (rc==SQLITE_ERROR_RETRY && (cnt++)<SQLITE_MAX_PREPARE_RETRY)
135257 || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
135258 sqlite3BtreeLeaveAll(db);
135259 rc = sqlite3ApiExit(db, rc);
135260 assert( (rc&db->errMask)==rc );
135261 db->busyHandler.nBusy = 0;
@@ -135685,11 +135802,11 @@
135802 ExprList *pResults;
135803 assert( pItem->pSelect!=0 );
135804 pResults = pItem->pSelect->pEList;
135805 assert( pResults!=0 );
135806 assert( iCol>=0 && iCol<pResults->nExpr );
135807 pResults->a[iCol].fg.bUsed = 1;
135808 }
135809 }
135810
135811 /*
135812 ** Search the tables iStart..iEnd (inclusive) in pSrc, looking for a
@@ -136353,11 +136470,11 @@
136470 ** the row from table t1 is stored instead. Then, as records are extracted from
136471 ** the sorter to return to the user, the required value of bigblob is
136472 ** retrieved directly from table t1. If the values are very large, this
136473 ** can be more efficient than storing them directly in the sorter records.
136474 **
136475 ** The ExprList_item.fg.bSorterRef flag is set for each expression in pEList
136476 ** for which the sorter-reference optimization should be enabled.
136477 ** Additionally, the pSort->aDefer[] array is populated with entries
136478 ** for all cursors required to evaluate all selected expressions. Finally.
136479 ** output variable (*ppExtra) is set to an expression list containing
136480 ** expressions for all extra PK values that should be stored in the
@@ -136413,11 +136530,11 @@
136530 pSort->aDefer[nDefer].iCsr = pExpr->iTable;
136531 pSort->aDefer[nDefer].nKey = nKey;
136532 nDefer++;
136533 }
136534 }
136535 pItem->fg.bSorterRef = 1;
136536 }
136537 }
136538 }
136539 pSort->nDefer = (u8)nDefer;
136540 *ppExtra = pExtra;
@@ -136544,11 +136661,11 @@
136661 ** from the sorter by the optimizations in this branch */
136662 pEList = p->pEList;
136663 for(i=0; i<pEList->nExpr; i++){
136664 if( pEList->a[i].u.x.iOrderByCol>0
136665 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
136666 || pEList->a[i].fg.bSorterRef
136667 #endif
136668 ){
136669 nResultCol--;
136670 regOrig = 0;
136671 }
@@ -136906,11 +137023,11 @@
137023 pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
137024 if( pInfo ){
137025 assert( sqlite3KeyInfoIsWriteable(pInfo) );
137026 for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
137027 pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr);
137028 pInfo->aSortFlags[i-iStart] = pItem->fg.sortFlags;
137029 }
137030 }
137031 return pInfo;
137032 }
137033
@@ -137045,11 +137162,11 @@
137162 iSortTab = iTab;
137163 bSeq = 1;
137164 }
137165 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
137166 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137167 if( aOutEx[i].fg.bSorterRef ) continue;
137168 #endif
137169 if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
137170 }
137171 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137172 if( pSort->nDefer ){
@@ -137082,11 +137199,11 @@
137199 sqlite3ReleaseTempRange(pParse, regKey, nRefKey);
137200 }
137201 #endif
137202 for(i=nColumn-1; i>=0; i--){
137203 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137204 if( aOutEx[i].fg.bSorterRef ){
137205 sqlite3ExprCode(pParse, aOutEx[i].pExpr, regRow+i);
137206 }else
137207 #endif
137208 {
137209 int iRead;
@@ -137448,11 +137565,11 @@
137565
137566 assert( p!=0 );
137567 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
137568 assert( p->op!=TK_COLUMN
137569 || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
137570 if( pEList->a[i].zEName && pEList->a[i].fg.eEName==ENAME_NAME ){
137571 /* An AS clause always takes first priority */
137572 char *zName = pEList->a[i].zEName;
137573 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
137574 }else if( srcName && p->op==TK_COLUMN ){
137575 char *zCol;
@@ -137534,13 +137651,14 @@
137651 *pnCol = nCol;
137652 *paCol = aCol;
137653
137654 for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
137655 struct ExprList_item *pX = &pEList->a[i];
137656 struct ExprList_item *pCollide;
137657 /* Get an appropriate name for the column
137658 */
137659 if( (zName = pX->zEName)!=0 && pX->fg.eEName==ENAME_NAME ){
137660 /* If the column contains an "AS <name>" phrase, use <name> as the name */
137661 }else{
137662 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pX->pExpr);
137663 while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
137664 pColExpr = pColExpr->pRight;
@@ -137570,11 +137688,14 @@
137688
137689 /* Make sure the column name is unique. If the name is not unique,
137690 ** append an integer to the name so that it becomes unique.
137691 */
137692 cnt = 0;
137693 while( zName && (pCollide = sqlite3HashFind(&ht, zName))!=0 ){
137694 if( pCollide->fg.bUsingTerm ){
137695 pCol->colFlags |= COLFLAG_NOEXPAND;
137696 }
137697 nName = sqlite3Strlen30(zName);
137698 if( nName>0 ){
137699 for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
137700 if( zName[j]==':' ) nName = j;
137701 }
@@ -137581,12 +137702,15 @@
137702 zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
137703 if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
137704 }
137705 pCol->zCnName = zName;
137706 pCol->hName = sqlite3StrIHash(zName);
137707 if( pX->fg.bNoExpand ){
137708 pCol->colFlags |= COLFLAG_NOEXPAND;
137709 }
137710 sqlite3ColumnPropertiesFromName(0, pCol);
137711 if( zName && sqlite3HashInsert(&ht, zName, pX)==pX ){
137712 sqlite3OomFault(db);
137713 }
137714 }
137715 sqlite3HashClear(&ht);
137716 if( db->mallocFailed ){
@@ -137839,11 +137963,11 @@
137963 pOrderBy->a[i].pExpr =
137964 sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
137965 }
137966 assert( sqlite3KeyInfoIsWriteable(pRet) );
137967 pRet->aColl[i] = pColl;
137968 pRet->aSortFlags[i] = pOrderBy->a[i].fg.sortFlags;
137969 }
137970 }
137971
137972 return pRet;
137973 }
@@ -140445,11 +140569,11 @@
140569 }else{
140570 return eRet;
140571 }
140572 *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
140573 assert( pOrderBy!=0 || db->mallocFailed );
140574 if( pOrderBy ) pOrderBy->a[0].fg.sortFlags = sortFlags;
140575 return eRet;
140576 }
140577
140578 /*
140579 ** The select statement passed as the first argument is an aggregate query.
@@ -141152,11 +141276,11 @@
141276 /* This particular expression does not need to be expanded.
141277 */
141278 pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
141279 if( pNew ){
141280 pNew->a[pNew->nExpr-1].zEName = a[k].zEName;
141281 pNew->a[pNew->nExpr-1].fg.eEName = a[k].fg.eEName;
141282 a[k].zEName = 0;
141283 }
141284 a[k].pExpr = 0;
141285 }else{
141286 /* This expression is a "*" or a "TABLE.*" and needs to be
@@ -141172,10 +141296,11 @@
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 ){
141304 zTabName = pTab->zName;
141305 }
141306 if( db->mallocFailed ) break;
@@ -141190,10 +141315,31 @@
141315 continue;
141316 }
141317 pNestedFrom = 0;
141318 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
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;
141341 }
141342 for(j=0; j<pTab->nCol; j++){
141343 char *zName = pTab->aCol[j].zCnName;
141344 struct ExprList_item *pX; /* Newly added ExprList term */
141345
@@ -141211,14 +141357,20 @@
141357 */
141358 if( (p->selFlags & SF_IncludeHidden)==0
141359 && IsHiddenColumn(&pTab->aCol[j])
141360 ){
141361 continue;
141362 }
141363 if( (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
141364 && zTName==0
141365 && (selFlags & (SF_NestedFrom))==0
141366 ){
141367 continue;
141368 }
141369 tableSeen = 1;
141370
141371 if( i>0 && zTName==0 && (selFlags & SF_NestedFrom)==0 ){
141372 if( pFrom->fg.isUsing
141373 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0
141374 ){
141375 /* In a join with a USING clause, omit columns in the
141376 ** using clause from the table on the right. */
@@ -141226,10 +141378,11 @@
141378 }
141379 }
141380 pRight = sqlite3Expr(db, TK_ID, zName);
141381 if( (pTabList->nSrc>1
141382 && ( (pFrom->fg.jointype & JT_LTORJ)==0
141383 || (selFlags & SF_NestedFrom)!=0
141384 || !inAnyUsingClause(zName,pFrom,pTabList->nSrc-i-1)
141385 )
141386 )
141387 || IN_RENAME_OBJECT
141388 ){
@@ -141259,17 +141412,24 @@
141412 }else{
141413 pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
141414 zSchemaName, zTabName, zName);
141415 testcase( pX->zEName==0 );
141416 }
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 }
141425 }else if( longNames ){
141426 pX->zEName = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
141427 pX->fg.eEName = ENAME_NAME;
141428 }else{
141429 pX->zEName = sqlite3DbStrDup(db, zName);
141430 pX->fg.eEName = ENAME_NAME;
141431 }
141432 }
141433 }
141434 if( !tableSeen ){
141435 if( zTName ){
@@ -142393,17 +142553,17 @@
142553 if( pDest->eDest==SRT_EphemTab ){
142554 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr);
142555 if( p->selFlags & SF_NestedFrom ){
142556 /* Delete or NULL-out result columns that will never be used */
142557 int ii;
142558 for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].fg.bUsed==0; ii--){
142559 sqlite3ExprDelete(db, pEList->a[ii].pExpr);
142560 sqlite3DbFree(db, pEList->a[ii].zEName);
142561 pEList->nExpr--;
142562 }
142563 for(ii=0; ii<pEList->nExpr; ii++){
142564 if( pEList->a[ii].fg.bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL;
142565 }
142566 }
142567 }
142568
142569 /* Set the limiter.
@@ -142551,12 +142711,13 @@
142711 ** ASC or DESC order - only that each group is returned contiguously.
142712 ** So set the ASC/DESC flags in the GROUP BY to match those in the
142713 ** ORDER BY to maximize the chances of rows being delivered in an
142714 ** order that makes the ORDER BY redundant. */
142715 for(ii=0; ii<pGroupBy->nExpr; ii++){
142716 u8 sortFlags;
142717 sortFlags = sSort.pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_DESC;
142718 pGroupBy->a[ii].fg.sortFlags = sortFlags;
142719 }
142720 if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
142721 orderByGrp = 1;
142722 }
142723 }
@@ -144207,20 +144368,20 @@
144368 pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zCnName);
144369 pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144370 if( !db->mallocFailed ){
144371 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144372 pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName);
144373 pItem->fg.eEName = ENAME_NAME;
144374 }
144375 }
144376 }else{
144377 Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
144378 pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144379 if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){
144380 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144381 pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName);
144382 pItem->fg.eEName = pList->a[i].fg.eEName;
144383 }
144384 }
144385 }
144386 return pNew;
144387 }
@@ -146789,10 +146950,11 @@
146950 #endif
146951 }
146952
146953 assert( rc==SQLITE_OK );
146954 if( pOut==0 ){
146955 nRes = sqlite3BtreeGetRequestedReserve(pTemp);
146956 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
146957 }
146958
146959 end_of_vacuum:
146960 /* Restore the original value of db->flags */
@@ -149443,20 +149605,26 @@
149605
149606 iTab = 0;
149607 if( !ExprUseXSelect(pX) || pX->x.pSelect->pEList->nExpr==1 ){
149608 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0, &iTab);
149609 }else{
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{
149621 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int)*nEq);
149622 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP|IN_INDEX_REUSE_CUR, 0, aiMap,&iTab);
149623 iTab = pExpr->iTable;
149624 }
149625 pX = pExpr;
 
149626 }
149627
149628 if( eType==IN_INDEX_INDEX_DESC ){
149629 testcase( bRev );
149630 bRev = !bRev;
@@ -150079,16 +150247,16 @@
150247 ** that contains the value of pExpr.
150248 */
150249 static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
150250 IdxExprTrans *pX = p->u.pIdxTrans;
150251 if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
150252 pExpr = sqlite3ExprSkipCollate(pExpr);
150253 preserveExpr(pX, pExpr);
150254 pExpr->affExpr = sqlite3ExprAffinity(pExpr);
150255 pExpr->op = TK_COLUMN;
150256 pExpr->iTable = pX->iIdxCur;
150257 pExpr->iColumn = pX->iIdxCol;
 
150258 testcase( ExprHasProperty(pExpr, EP_Unlikely) );
150259 ExprClearProperty(pExpr, EP_Skip|EP_Unlikely|EP_WinFunc|EP_Subrtn);
150260 pExpr->y.pTab = 0;
150261 return WRC_Prune;
150262 }else{
@@ -150238,10 +150406,12 @@
150406 if( pLevel->regFilter==0 ) continue;
150407 if( pLevel->pWLoop->nSkip ) continue;
150408 /* ,--- Because sqlite3ConstructBloomFilter() has will not have set
150409 ** vvvvv--' pLevel->regFilter if this were true. */
150410 if( NEVER(pLoop->prereq & notReady) ) continue;
150411 assert( pLevel->addrBrk==0 );
150412 pLevel->addrBrk = addrNxt;
150413 if( pLoop->wsFlags & WHERE_IPK ){
150414 WhereTerm *pTerm = pLoop->aLTerm[0];
150415 int regRowid;
150416 assert( pTerm!=0 );
150417 assert( pTerm->pExpr!=0 );
@@ -150264,10 +150434,11 @@
150434 sqlite3VdbeAddOp4Int(pParse->pVdbe, OP_Filter, pLevel->regFilter,
150435 addrNxt, r1, nEq);
150436 VdbeCoverage(pParse->pVdbe);
150437 }
150438 pLevel->regFilter = 0;
150439 pLevel->addrBrk = 0;
150440 }
150441 }
150442
150443 /*
150444 ** Generate code for the start of the iLevel-th loop in the WHERE clause
@@ -151444,11 +151615,11 @@
151615 continue;
151616 }
151617 pE = pTerm->pExpr;
151618 assert( pE!=0 );
151619 if( (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ))
151620 && !ExprHasProperty(pE,EP_FromJoin|EP_InnerJoin)
151621 ){
151622 continue;
151623 }
151624
151625 if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
@@ -153335,11 +153506,11 @@
153506 if( pOrderBy ){
153507 for(ii=0; ii<pOrderBy->nExpr; ii++){
153508 Expr *pExpr = pOrderBy->a[ii].pExpr;
153509 if( pExpr->op!=TK_COLUMN ) return;
153510 if( pExpr->iTable!=iCsr ) return;
153511 if( pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) return;
153512 }
153513 }
153514
153515 /* All conditions are met. Add the terms to the where-clause object. */
153516 assert( p->pLimit->op==TK_LIMIT );
@@ -154765,11 +154936,11 @@
154936 if( sqlite3ExprIsConstant(pExpr) ){
154937 continue;
154938 }
154939
154940 /* Virtual tables are unable to deal with NULLS FIRST */
154941 if( pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) break;
154942
154943 /* First case - a direct column references without a COLLATE operator */
154944 if( pExpr->op==TK_COLUMN && pExpr->iTable==pSrc->iCursor ){
154945 assert( pExpr->iColumn>=XN_ROWID && pExpr->iColumn<pTab->nCol );
154946 continue;
@@ -154877,11 +155048,11 @@
155048 if( sqlite3ExprIsConstant(pExpr) ) continue;
155049 assert( pExpr->op==TK_COLUMN
155050 || (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN
155051 && pExpr->iColumn==pExpr->pLeft->iColumn) );
155052 pIdxOrderBy[j].iColumn = pExpr->iColumn;
155053 pIdxOrderBy[j].desc = pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC;
155054 j++;
155055 }
155056 pIdxInfo->nOrderBy = j;
155057
155058 *pmNoOmit = mNoOmit;
@@ -156395,11 +156566,11 @@
156566 /* tag-20191211-001: Do not allow constraints from the WHERE clause to
156567 ** be used by the right table of a LEFT JOIN nor by the left table of a
156568 ** RIGHT JOIN. Only constraints in the
156569 ** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
156570 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
156571 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin|EP_InnerJoin)
156572 ){
156573 continue;
156574 }
156575
156576 if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
@@ -157703,13 +157874,11 @@
157874 pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
157875 pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
157876 if( (pItem->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
157877 /* This condition is true when pItem is the FROM clause term on the
157878 ** right-hand-side of a OUTER or CROSS JOIN. */
157879 mPrereq |= mPrior;
 
 
157880 }
157881 #ifndef SQLITE_OMIT_VIRTUALTABLE
157882 if( IsVirtual(pItem->pTab) ){
157883 SrcItem *p;
157884 for(p=&pItem[1]; p<pEnd; p++){
@@ -158016,20 +158185,22 @@
158185 }
158186 if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
158187 /* Make sure the sort order is compatible in an ORDER BY clause.
158188 ** Sort order is irrelevant for a GROUP BY clause. */
158189 if( revSet ){
158190 if( (rev ^ revIdx)
158191 != (pOrderBy->a[i].fg.sortFlags&KEYINFO_ORDER_DESC)
158192 ){
158193 isMatch = 0;
158194 }
158195 }else{
158196 rev = revIdx ^ (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC);
158197 if( rev ) *pRevMask |= MASKBIT(iLoop);
158198 revSet = 1;
158199 }
158200 }
158201 if( isMatch && (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL) ){
158202 if( j==pLoop->u.btree.nEq ){
158203 pLoop->wsFlags |= WHERE_BIGNULL_SORT;
158204 }else{
158205 isMatch = 0;
158206 }
@@ -160789,11 +160960,11 @@
160960 pSub->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
160961 pSub->u.zToken = 0;
160962 }
160963 }
160964 pList = sqlite3ExprListAppend(pParse, pList, pDup);
160965 if( pList ) pList->a[nInit+i].fg.sortFlags = pAppend->a[i].fg.sortFlags;
160966 }
160967 }
160968 return pList;
160969 }
160970
@@ -161990,11 +162161,11 @@
162161 windowReadPeerValues(p, csr1, reg1);
162162 windowReadPeerValues(p, csr2, reg2);
162163
162164 assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
162165 assert( pOrderBy && pOrderBy->nExpr==1 );
162166 if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_DESC ){
162167 switch( op ){
162168 case OP_Ge: op = OP_Le; break;
162169 case OP_Gt: op = OP_Lt; break;
162170 default: assert( op==OP_Le ); op = OP_Ge; break;
162171 }
@@ -162023,11 +162194,11 @@
162194 ** }
162195 **
162196 ** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is
162197 ** not taken, control jumps over the comparison operator coded below this
162198 ** block. */
162199 if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_BIGNULL ){
162200 /* This block runs if reg1 contains a NULL. */
162201 int addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v);
162202 switch( op ){
162203 case OP_Ge:
162204 sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl);
@@ -226807,11 +226978,11 @@
226978 /* State used by the fts5DataXXX() functions. */
226979 sqlite3_blob *pReader; /* RO incr-blob open on %_data table */
226980 sqlite3_stmt *pWriter; /* "INSERT ... %_data VALUES(?,?)" */
226981 sqlite3_stmt *pDeleter; /* "DELETE FROM %_data ... id>=? AND id<=?" */
226982 sqlite3_stmt *pIdxWriter; /* "INSERT ... %_idx VALUES(?,?,?,?)" */
226983 sqlite3_stmt *pIdxDeleter; /* "DELETE FROM %_idx WHERE segid=?" */
226984 sqlite3_stmt *pIdxSelect;
226985 int nRead; /* Total number of blocks read */
226986
226987 sqlite3_stmt *pDataVersion;
226988 i64 iStructVersion; /* data_version when pStruct read */
@@ -236124,11 +236295,11 @@
236295 int nArg, /* Number of args */
236296 sqlite3_value **apUnused /* Function arguments */
236297 ){
236298 assert( nArg==0 );
236299 UNUSED_PARAM2(nArg, apUnused);
236300 sqlite3_result_text(pCtx, "fts5: 2022-05-10 00:24:01 c6c3115f3a008cf9b0d7c5c812f17e38c8a75a904032c5f05f0bea03a7340527", -1, SQLITE_TRANSIENT);
236301 }
236302
236303 /*
236304 ** Return true if zName is the extension on one of the shadow tables used
236305 ** by this module.
236306
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.39.0"
150150
#define SQLITE_VERSION_NUMBER 3039000
151
-#define SQLITE_SOURCE_ID "2022-04-26 19:16:11 b1bec72043f798f4d4d30e6b60a45ed4dc521115c8a9f97bb8228e3f089deefb"
151
+#define SQLITE_SOURCE_ID "2022-05-10 00:24:01 c6c3115f3a008cf9b0d7c5c812f17e38c8a75a904032c5f05f0bea03a7340527"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
157157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.39.0"
150 #define SQLITE_VERSION_NUMBER 3039000
151 #define SQLITE_SOURCE_ID "2022-04-26 19:16:11 b1bec72043f798f4d4d30e6b60a45ed4dc521115c8a9f97bb8228e3f089deefb"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.39.0"
150 #define SQLITE_VERSION_NUMBER 3039000
151 #define SQLITE_SOURCE_ID "2022-05-10 00:24:01 c6c3115f3a008cf9b0d7c5c812f17e38c8a75a904032c5f05f0bea03a7340527"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
157
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -1178,5 +1178,19 @@
11781178
wellknown_notfound:
11791179
fossil_free(zPath);
11801180
webpage_notfound_error(0);
11811181
return;
11821182
}
1183
+
1184
+/*
1185
+** Return the OpenSSL version number being used. Space to hold
1186
+** this name is obtained from fossil_malloc() and should be
1187
+** freed by the caller.
1188
+*/
1189
+char *fossil_openssl_version(void){
1190
+#if defined(FOSSIL_ENABLE_SSL)
1191
+ return mprintf("%s (0x%09x)\n",
1192
+ SSLeay_version(SSLEAY_VERSION), OPENSSL_VERSION_NUMBER);
1193
+#else
1194
+ return mprintf("none");
1195
+#endif
1196
+}
11831197
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -1178,5 +1178,19 @@
1178 wellknown_notfound:
1179 fossil_free(zPath);
1180 webpage_notfound_error(0);
1181 return;
1182 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1183
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -1178,5 +1178,19 @@
1178 wellknown_notfound:
1179 fossil_free(zPath);
1180 webpage_notfound_error(0);
1181 return;
1182 }
1183
1184 /*
1185 ** Return the OpenSSL version number being used. Space to hold
1186 ** this name is obtained from fossil_malloc() and should be
1187 ** freed by the caller.
1188 */
1189 char *fossil_openssl_version(void){
1190 #if defined(FOSSIL_ENABLE_SSL)
1191 return mprintf("%s (0x%09x)\n",
1192 SSLeay_version(SSLEAY_VERSION), OPENSSL_VERSION_NUMBER);
1193 #else
1194 return mprintf("none");
1195 #endif
1196 }
1197
+2 -1
--- src/main.c
+++ src/main.c
@@ -138,11 +138,12 @@
138138
139139
struct Global {
140140
int argc; char **argv; /* Command-line arguments to the program */
141141
char *nameOfExe; /* Full path of executable. */
142142
const char *zErrlog; /* Log errors to this file, if not NULL */
143
- const char *zPhase; /* Phase of operation, for use by the error log */
143
+ const char *zPhase; /* Phase of operation, for use by the error log
144
+ ** and for deriving $canonical_page TH1 variable */
144145
int isConst; /* True if the output is unchanging & cacheable */
145146
const char *zVfsName; /* The VFS to use for database connections */
146147
sqlite3 *db; /* The connection to the databases */
147148
sqlite3 *dbConfig; /* Separate connection for global_config table */
148149
char *zAuxSchema; /* Main repository aux-schema */
149150
--- src/main.c
+++ src/main.c
@@ -138,11 +138,12 @@
138
139 struct Global {
140 int argc; char **argv; /* Command-line arguments to the program */
141 char *nameOfExe; /* Full path of executable. */
142 const char *zErrlog; /* Log errors to this file, if not NULL */
143 const char *zPhase; /* Phase of operation, for use by the error log */
 
144 int isConst; /* True if the output is unchanging & cacheable */
145 const char *zVfsName; /* The VFS to use for database connections */
146 sqlite3 *db; /* The connection to the databases */
147 sqlite3 *dbConfig; /* Separate connection for global_config table */
148 char *zAuxSchema; /* Main repository aux-schema */
149
--- src/main.c
+++ src/main.c
@@ -138,11 +138,12 @@
138
139 struct Global {
140 int argc; char **argv; /* Command-line arguments to the program */
141 char *nameOfExe; /* Full path of executable. */
142 const char *zErrlog; /* Log errors to this file, if not NULL */
143 const char *zPhase; /* Phase of operation, for use by the error log
144 ** and for deriving $canonical_page TH1 variable */
145 int isConst; /* True if the output is unchanging & cacheable */
146 const char *zVfsName; /* The VFS to use for database connections */
147 sqlite3 *db; /* The connection to the databases */
148 sqlite3 *dbConfig; /* Separate connection for global_config table */
149 char *zAuxSchema; /* Main repository aux-schema */
150
+8
--- src/stat.c
+++ src/stat.c
@@ -280,10 +280,18 @@
280280
@ (%h(RELEASE_VERSION)) <a href='version?verbose'>(details)</a>
281281
@ </td></tr>
282282
@ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(sqlite3_sourceid())
283283
@ [%.10s(&sqlite3_sourceid()[20])] (%s(sqlite3_libversion()))
284284
@ <a href='version?verbose'>(details)</a></td></tr>
285
+ if( g.perm.Admin ){
286
+ const char *zCgi = P("SERVER_SOFTWARE");
287
+ @ <tr><th>OpenSSL&nbsp;Version:</th>
288
+ @ <td>%z(fossil_openssl_version())</td></tr>
289
+ if( zCgi ){
290
+ @ <tr><th>Web&nbsp;Server:</th><td>%s(zCgi)</td></tr>
291
+ }
292
+ }
285293
if( g.eHashPolicy!=HPOLICY_AUTO ){
286294
@ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema),
287295
@ %s(hpolicy_name())</td></tr>
288296
}else{
289297
@ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema)</td></tr>
290298
--- src/stat.c
+++ src/stat.c
@@ -280,10 +280,18 @@
280 @ (%h(RELEASE_VERSION)) <a href='version?verbose'>(details)</a>
281 @ </td></tr>
282 @ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(sqlite3_sourceid())
283 @ [%.10s(&sqlite3_sourceid()[20])] (%s(sqlite3_libversion()))
284 @ <a href='version?verbose'>(details)</a></td></tr>
 
 
 
 
 
 
 
 
285 if( g.eHashPolicy!=HPOLICY_AUTO ){
286 @ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema),
287 @ %s(hpolicy_name())</td></tr>
288 }else{
289 @ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema)</td></tr>
290
--- src/stat.c
+++ src/stat.c
@@ -280,10 +280,18 @@
280 @ (%h(RELEASE_VERSION)) <a href='version?verbose'>(details)</a>
281 @ </td></tr>
282 @ <tr><th>SQLite&nbsp;Version:</th><td>%.19s(sqlite3_sourceid())
283 @ [%.10s(&sqlite3_sourceid()[20])] (%s(sqlite3_libversion()))
284 @ <a href='version?verbose'>(details)</a></td></tr>
285 if( g.perm.Admin ){
286 const char *zCgi = P("SERVER_SOFTWARE");
287 @ <tr><th>OpenSSL&nbsp;Version:</th>
288 @ <td>%z(fossil_openssl_version())</td></tr>
289 if( zCgi ){
290 @ <tr><th>Web&nbsp;Server:</th><td>%s(zCgi)</td></tr>
291 }
292 }
293 if( g.eHashPolicy!=HPOLICY_AUTO ){
294 @ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema),
295 @ %s(hpolicy_name())</td></tr>
296 }else{
297 @ <tr><th>Schema&nbsp;Version:</th><td>%h(g.zAuxSchema)</td></tr>
298
+10 -3
--- src/style.c
+++ src/style.c
@@ -647,20 +647,20 @@
647647
** prepended.
648648
*/
649649
static const char zDfltHeader[] =
650650
@ <html>
651651
@ <head>
652
-@ <base href="$baseurl/$current_page" />
653652
@ <meta charset="UTF-8">
653
+@ <base href="$baseurl/$current_page" />
654654
@ <meta http-equiv="Content-Security-Policy" content="$default_csp" />
655655
@ <meta name="viewport" content="width=device-width, initial-scale=1.0">
656656
@ <title>$<project_name>: $<title></title>
657657
@ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
658658
@ href="$home/timeline.rss" />
659659
@ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
660660
@ </head>
661
-@ <body class="$current_feature">
661
+@ <body class="$current_feature rpage-$requested_page cpage-$canonical_page">
662662
;
663663
664664
/*
665665
** Returns the default page header.
666666
*/
@@ -749,11 +749,11 @@
749749
/*
750750
** Initialize all the default TH1 variables
751751
*/
752752
static void style_init_th1_vars(const char *zTitle){
753753
const char *zNonce = style_nonce();
754
- char *zDfltCsp;
754
+ char *zDfltCsp, *zSlash = 0;
755755
756756
zDfltCsp = style_csp(1);
757757
/*
758758
** Do not overwrite the TH1 variable "default_csp" if it exists, as this
759759
** allows it to be properly overridden via the TH1 setup script (i.e. it
@@ -769,10 +769,17 @@
769769
Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
770770
Th_Store("home", g.zTop);
771771
Th_Store("index_page", db_get("index-page","/home"));
772772
if( local_zCurrentPage==0 ) style_set_current_page("%T", g.zPath);
773773
Th_Store("current_page", local_zCurrentPage);
774
+ /* store the first segment of a path; make a temporary cut if necessary */
775
+ if( g.zPath && (zSlash = strchr(g.zPath,'/'))!=0 ){
776
+ *zSlash = 0;
777
+ Th_Store("requested_page", escape_quotes(g.zPath));
778
+ *zSlash = '/';
779
+ }
780
+ Th_Store("canonical_page", escape_quotes(g.zPhase+1));
774781
Th_Store("csrf_token", g.zCsrfToken);
775782
Th_Store("release_version", RELEASE_VERSION);
776783
Th_Store("manifest_version", MANIFEST_VERSION);
777784
Th_Store("manifest_date", MANIFEST_DATE);
778785
Th_Store("compiler_name", COMPILER_NAME);
779786
--- src/style.c
+++ src/style.c
@@ -647,20 +647,20 @@
647 ** prepended.
648 */
649 static const char zDfltHeader[] =
650 @ <html>
651 @ <head>
652 @ <base href="$baseurl/$current_page" />
653 @ <meta charset="UTF-8">
 
654 @ <meta http-equiv="Content-Security-Policy" content="$default_csp" />
655 @ <meta name="viewport" content="width=device-width, initial-scale=1.0">
656 @ <title>$<project_name>: $<title></title>
657 @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
658 @ href="$home/timeline.rss" />
659 @ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
660 @ </head>
661 @ <body class="$current_feature">
662 ;
663
664 /*
665 ** Returns the default page header.
666 */
@@ -749,11 +749,11 @@
749 /*
750 ** Initialize all the default TH1 variables
751 */
752 static void style_init_th1_vars(const char *zTitle){
753 const char *zNonce = style_nonce();
754 char *zDfltCsp;
755
756 zDfltCsp = style_csp(1);
757 /*
758 ** Do not overwrite the TH1 variable "default_csp" if it exists, as this
759 ** allows it to be properly overridden via the TH1 setup script (i.e. it
@@ -769,10 +769,17 @@
769 Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
770 Th_Store("home", g.zTop);
771 Th_Store("index_page", db_get("index-page","/home"));
772 if( local_zCurrentPage==0 ) style_set_current_page("%T", g.zPath);
773 Th_Store("current_page", local_zCurrentPage);
 
 
 
 
 
 
 
774 Th_Store("csrf_token", g.zCsrfToken);
775 Th_Store("release_version", RELEASE_VERSION);
776 Th_Store("manifest_version", MANIFEST_VERSION);
777 Th_Store("manifest_date", MANIFEST_DATE);
778 Th_Store("compiler_name", COMPILER_NAME);
779
--- src/style.c
+++ src/style.c
@@ -647,20 +647,20 @@
647 ** prepended.
648 */
649 static const char zDfltHeader[] =
650 @ <html>
651 @ <head>
 
652 @ <meta charset="UTF-8">
653 @ <base href="$baseurl/$current_page" />
654 @ <meta http-equiv="Content-Security-Policy" content="$default_csp" />
655 @ <meta name="viewport" content="width=device-width, initial-scale=1.0">
656 @ <title>$<project_name>: $<title></title>
657 @ <link rel="alternate" type="application/rss+xml" title="RSS Feed" \
658 @ href="$home/timeline.rss" />
659 @ <link rel="stylesheet" href="$stylesheet_url" type="text/css" />
660 @ </head>
661 @ <body class="$current_feature rpage-$requested_page cpage-$canonical_page">
662 ;
663
664 /*
665 ** Returns the default page header.
666 */
@@ -749,11 +749,11 @@
749 /*
750 ** Initialize all the default TH1 variables
751 */
752 static void style_init_th1_vars(const char *zTitle){
753 const char *zNonce = style_nonce();
754 char *zDfltCsp, *zSlash = 0;
755
756 zDfltCsp = style_csp(1);
757 /*
758 ** Do not overwrite the TH1 variable "default_csp" if it exists, as this
759 ** allows it to be properly overridden via the TH1 setup script (i.e. it
@@ -769,10 +769,17 @@
769 Th_Store("secureurl", fossil_wants_https(1)? g.zHttpsURL: g.zBaseURL);
770 Th_Store("home", g.zTop);
771 Th_Store("index_page", db_get("index-page","/home"));
772 if( local_zCurrentPage==0 ) style_set_current_page("%T", g.zPath);
773 Th_Store("current_page", local_zCurrentPage);
774 /* store the first segment of a path; make a temporary cut if necessary */
775 if( g.zPath && (zSlash = strchr(g.zPath,'/'))!=0 ){
776 *zSlash = 0;
777 Th_Store("requested_page", escape_quotes(g.zPath));
778 *zSlash = '/';
779 }
780 Th_Store("canonical_page", escape_quotes(g.zPhase+1));
781 Th_Store("csrf_token", g.zCsrfToken);
782 Th_Store("release_version", RELEASE_VERSION);
783 Th_Store("manifest_version", MANIFEST_VERSION);
784 Th_Store("manifest_date", MANIFEST_DATE);
785 Th_Store("compiler_name", COMPILER_NAME);
786
+4 -3
--- src/timeline.c
+++ src/timeline.c
@@ -524,13 +524,14 @@
524524
@ Added wiki page "%z(href("%R/wiki?name=%t",zCom+1))%h(zCom+1)</a>"
525525
}else if( zCom[0]==':' ){
526526
@ Changes to wiki page "%z(href("%R/wiki?name=%t",zCom+1))\
527527
@ %h(zCom+1)</a>"
528528
}else{
529
- /* Legacy EVENT table entry that needs to be rebuilt */
530
- @ Changes to a wiki page &rarr; Obsolete EVENT table information.
531
- @ Run "fossil rebuild" on the repository.
529
+ /* Assume this is an attachment message. It _might_ also
530
+ ** be a legacy-format wiki log entry, in which case it
531
+ ** will simply be rendered in the older format. */
532
+ wiki_convert(&comment, 0, WIKI_INLINE);
532533
}
533534
wiki_hyperlink_override(0);
534535
}else{
535536
wiki_convert(&comment, 0, WIKI_INLINE);
536537
}
537538
--- src/timeline.c
+++ src/timeline.c
@@ -524,13 +524,14 @@
524 @ Added wiki page "%z(href("%R/wiki?name=%t",zCom+1))%h(zCom+1)</a>"
525 }else if( zCom[0]==':' ){
526 @ Changes to wiki page "%z(href("%R/wiki?name=%t",zCom+1))\
527 @ %h(zCom+1)</a>"
528 }else{
529 /* Legacy EVENT table entry that needs to be rebuilt */
530 @ Changes to a wiki page &rarr; Obsolete EVENT table information.
531 @ Run "fossil rebuild" on the repository.
 
532 }
533 wiki_hyperlink_override(0);
534 }else{
535 wiki_convert(&comment, 0, WIKI_INLINE);
536 }
537
--- src/timeline.c
+++ src/timeline.c
@@ -524,13 +524,14 @@
524 @ Added wiki page "%z(href("%R/wiki?name=%t",zCom+1))%h(zCom+1)</a>"
525 }else if( zCom[0]==':' ){
526 @ Changes to wiki page "%z(href("%R/wiki?name=%t",zCom+1))\
527 @ %h(zCom+1)</a>"
528 }else{
529 /* Assume this is an attachment message. It _might_ also
530 ** be a legacy-format wiki log entry, in which case it
531 ** will simply be rendered in the older format. */
532 wiki_convert(&comment, 0, WIKI_INLINE);
533 }
534 wiki_hyperlink_override(0);
535 }else{
536 wiki_convert(&comment, 0, WIKI_INLINE);
537 }
538

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button