Fossil SCM

Update the built-in SQLite to the latest 3.39.0 alpha for testing.

drh 2022-05-10 11:54 trunk
Commit 0833f7225b3d6c9bbf003be7a48370cdfd073e1f0b9f25458bf3312b10063680
2 files changed +142 -82 +1 -1
+142 -82
--- 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-05-03 14:01:48 6eda9b1a7784cf6d58c8876551f67ab98e78a08e726a0579d4def5ba881985bb"
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
**
@@ -17400,10 +17400,11 @@
1740017400
#define COLFLAG_VIRTUAL 0x0020 /* GENERATED ALWAYS AS ... VIRTUAL */
1740117401
#define COLFLAG_STORED 0x0040 /* GENERATED ALWAYS AS ... STORED */
1740217402
#define COLFLAG_NOTAVAIL 0x0080 /* STORED column not yet calculated */
1740317403
#define COLFLAG_BUSY 0x0100 /* Blocks recursion on GENERATED columns */
1740417404
#define COLFLAG_HASCOLL 0x0200 /* Has collating sequence name in zCnName */
17405
+#define COLFLAG_NOEXPAND 0x0400 /* Omit this column when expanding "*" */
1740517406
#define COLFLAG_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
1740617407
#define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
1740717408
1740817409
/*
1740917410
** A "Collating Sequence" is defined by an instance of the following
@@ -18273,17 +18274,22 @@
1827318274
int nExpr; /* Number of expressions on the list */
1827418275
int nAlloc; /* Number of a[] slots allocated */
1827518276
struct ExprList_item { /* For each expression in the list */
1827618277
Expr *pExpr; /* The parse tree for this expression */
1827718278
char *zEName; /* Token associated with this expression */
18278
- u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18279
- unsigned eEName :2; /* Meaning of zEName */
18280
- unsigned done :1; /* A flag to indicate when processing is finished */
18281
- unsigned reusable :1; /* Constant expression is reusable */
18282
- unsigned bSorterRef :1; /* Defer evaluation until after sorting */
18283
- unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
18284
- 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;
1828518291
union {
1828618292
struct { /* Used by any ExprList other than Parse.pConsExpr */
1828718293
u16 iOrderByCol; /* For ORDER BY, column number in result set */
1828818294
u16 iAlias; /* Index into Parse.aAlias[] for zName */
1828918295
} x;
@@ -31850,17 +31856,19 @@
3185031856
if( j || zName ){
3185131857
sqlite3TreeViewPush(&pView, moreToFollow);
3185231858
moreToFollow = 0;
3185331859
sqlite3TreeViewLine(pView, 0);
3185431860
if( zName ){
31855
- switch( pList->a[i].eEName ){
31861
+ switch( pList->a[i].fg.eEName ){
3185631862
default:
3185731863
fprintf(stdout, "AS %s ", zName);
3185831864
break;
3185931865
case ENAME_TAB:
3186031866
fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
31861
- 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) ");
3186231870
break;
3186331871
case ENAME_SPAN:
3186431872
fprintf(stdout, "SPAN(\"%s\") ", zName);
3186531873
break;
3186631874
}
@@ -101539,11 +101547,11 @@
101539101547
const char *zTab,
101540101548
const char *zDb
101541101549
){
101542101550
int n;
101543101551
const char *zSpan;
101544
- if( pItem->eEName!=ENAME_TAB ) return 0;
101552
+ if( pItem->fg.eEName!=ENAME_TAB ) return 0;
101545101553
zSpan = pItem->zEName;
101546101554
for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
101547101555
if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
101548101556
return 0;
101549101557
}
@@ -101768,12 +101776,13 @@
101768101776
}
101769101777
cnt++;
101770101778
cntTab = 2;
101771101779
pMatch = pItem;
101772101780
pExpr->iColumn = j;
101773
- pEList->a[j].bUsed = 1;
101781
+ pEList->a[j].fg.bUsed = 1;
101774101782
hit = 1;
101783
+ if( pEList->a[j].fg.bUsingTerm ) break;
101775101784
}
101776101785
if( hit || zTab==0 ) continue;
101777101786
}
101778101787
assert( zDb==0 || zTab!=0 );
101779101788
if( zTab ){
@@ -101992,11 +102001,11 @@
101992102001
){
101993102002
pEList = pNC->uNC.pEList;
101994102003
assert( pEList!=0 );
101995102004
for(j=0; j<pEList->nExpr; j++){
101996102005
char *zAs = pEList->a[j].zEName;
101997
- if( pEList->a[j].eEName==ENAME_NAME
102006
+ if( pEList->a[j].fg.eEName==ENAME_NAME
101998102007
&& sqlite3_stricmp(zAs, zCol)==0
101999102008
){
102000102009
Expr *pOrig;
102001102010
assert( pExpr->pLeft==0 && pExpr->pRight==0 );
102002102011
assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
@@ -102745,11 +102754,11 @@
102745102754
if( pE->op==TK_ID ){
102746102755
const char *zCol;
102747102756
assert( !ExprHasProperty(pE, EP_IntValue) );
102748102757
zCol = pE->u.zToken;
102749102758
for(i=0; i<pEList->nExpr; i++){
102750
- if( pEList->a[i].eEName==ENAME_NAME
102759
+ if( pEList->a[i].fg.eEName==ENAME_NAME
102751102760
&& sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
102752102761
){
102753102762
return i+1;
102754102763
}
102755102764
}
@@ -102866,11 +102875,11 @@
102866102875
if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
102867102876
sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
102868102877
return 1;
102869102878
}
102870102879
for(i=0; i<pOrderBy->nExpr; i++){
102871
- pOrderBy->a[i].done = 0;
102880
+ pOrderBy->a[i].fg.done = 0;
102872102881
}
102873102882
pSelect->pNext = 0;
102874102883
while( pSelect->pPrior ){
102875102884
pSelect->pPrior->pNext = pSelect;
102876102885
pSelect = pSelect->pPrior;
@@ -102881,11 +102890,11 @@
102881102890
pEList = pSelect->pEList;
102882102891
assert( pEList!=0 );
102883102892
for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
102884102893
int iCol = -1;
102885102894
Expr *pE, *pDup;
102886
- if( pItem->done ) continue;
102895
+ if( pItem->fg.done ) continue;
102887102896
pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
102888102897
if( NEVER(pE==0) ) continue;
102889102898
if( sqlite3ExprIsInteger(pE, &iCol) ){
102890102899
if( iCol<=0 || iCol>pEList->nExpr ){
102891102900
resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE);
@@ -102934,19 +102943,19 @@
102934102943
pParent->pLeft = pNew;
102935102944
}
102936102945
sqlite3ExprDelete(db, pE);
102937102946
pItem->u.x.iOrderByCol = (u16)iCol;
102938102947
}
102939
- pItem->done = 1;
102948
+ pItem->fg.done = 1;
102940102949
}else{
102941102950
moreToDo = 1;
102942102951
}
102943102952
}
102944102953
pSelect = pSelect->pNext;
102945102954
}
102946102955
for(i=0; i<pOrderBy->nExpr; i++){
102947
- if( pOrderBy->a[i].done==0 ){
102956
+ if( pOrderBy->a[i].fg.done==0 ){
102948102957
sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any "
102949102958
"column in the result set", i+1);
102950102959
return 1;
102951102960
}
102952102961
}
@@ -105186,16 +105195,12 @@
105186105195
}
105187105196
pNewExpr->pLeft = pPriorSelectColNew;
105188105197
}
105189105198
}
105190105199
pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
105191
- pItem->sortFlags = pOldItem->sortFlags;
105192
- pItem->eEName = pOldItem->eEName;
105193
- pItem->done = 0;
105194
- pItem->bNulls = pOldItem->bNulls;
105195
- pItem->bUsed = pOldItem->bUsed;
105196
- pItem->bSorterRef = pOldItem->bSorterRef;
105200
+ pItem->fg = pOldItem->fg;
105201
+ pItem->fg.done = 0;
105197105202
pItem->u = pOldItem->u;
105198105203
}
105199105204
return pNew;
105200105205
}
105201105206
@@ -105491,20 +105496,20 @@
105491105496
|| eNulls==SQLITE_SO_ASC
105492105497
|| eNulls==SQLITE_SO_DESC
105493105498
);
105494105499
105495105500
pItem = &p->a[p->nExpr-1];
105496
- assert( pItem->bNulls==0 );
105501
+ assert( pItem->fg.bNulls==0 );
105497105502
if( iSortOrder==SQLITE_SO_UNDEFINED ){
105498105503
iSortOrder = SQLITE_SO_ASC;
105499105504
}
105500
- pItem->sortFlags = (u8)iSortOrder;
105505
+ pItem->fg.sortFlags = (u8)iSortOrder;
105501105506
105502105507
if( eNulls!=SQLITE_SO_UNDEFINED ){
105503
- pItem->bNulls = 1;
105508
+ pItem->fg.bNulls = 1;
105504105509
if( iSortOrder!=eNulls ){
105505
- pItem->sortFlags |= KEYINFO_ORDER_BIGNULL;
105510
+ pItem->fg.sortFlags |= KEYINFO_ORDER_BIGNULL;
105506105511
}
105507105512
}
105508105513
}
105509105514
105510105515
/*
@@ -105526,11 +105531,11 @@
105526105531
if( pList ){
105527105532
struct ExprList_item *pItem;
105528105533
assert( pList->nExpr>0 );
105529105534
pItem = &pList->a[pList->nExpr-1];
105530105535
assert( pItem->zEName==0 );
105531
- assert( pItem->eEName==ENAME_NAME );
105536
+ assert( pItem->fg.eEName==ENAME_NAME );
105532105537
pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
105533105538
if( dequote ){
105534105539
/* If dequote==0, then pName->z does not point to part of a DDL
105535105540
** statement handled by the parser. And so no token need be added
105536105541
** to the token-map. */
@@ -105561,11 +105566,11 @@
105561105566
if( pList ){
105562105567
struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
105563105568
assert( pList->nExpr>0 );
105564105569
if( pItem->zEName==0 ){
105565105570
pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd);
105566
- pItem->eEName = ENAME_SPAN;
105571
+ pItem->fg.eEName = ENAME_SPAN;
105567105572
}
105568105573
}
105569105574
}
105570105575
105571105576
/*
@@ -108387,11 +108392,13 @@
108387108392
p = pParse->pConstExpr;
108388108393
if( regDest<0 && p ){
108389108394
struct ExprList_item *pItem;
108390108395
int i;
108391108396
for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
108392
- if( pItem->reusable && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0 ){
108397
+ if( pItem->fg.reusable
108398
+ && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0
108399
+ ){
108393108400
return pItem->u.iConstExprReg;
108394108401
}
108395108402
}
108396108403
}
108397108404
pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
@@ -108410,11 +108417,11 @@
108410108417
sqlite3VdbeJumpHere(v, addr);
108411108418
}else{
108412108419
p = sqlite3ExprListAppend(pParse, p, pExpr);
108413108420
if( p ){
108414108421
struct ExprList_item *pItem = &p->a[p->nExpr-1];
108415
- pItem->reusable = regDest<0;
108422
+ pItem->fg.reusable = regDest<0;
108416108423
if( regDest<0 ) regDest = ++pParse->nMem;
108417108424
pItem->u.iConstExprReg = regDest;
108418108425
}
108419108426
pParse->pConstExpr = p;
108420108427
}
@@ -108544,11 +108551,11 @@
108544108551
n = pList->nExpr;
108545108552
if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
108546108553
for(pItem=pList->a, i=0; i<n; i++, pItem++){
108547108554
Expr *pExpr = pItem->pExpr;
108548108555
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
108549
- if( pItem->bSorterRef ){
108556
+ if( pItem->fg.bSorterRef ){
108550108557
i--;
108551108558
n--;
108552108559
}else
108553108560
#endif
108554108561
if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
@@ -109169,11 +109176,11 @@
109169109176
if( pA->nExpr!=pB->nExpr ) return 1;
109170109177
for(i=0; i<pA->nExpr; i++){
109171109178
int res;
109172109179
Expr *pExprA = pA->a[i].pExpr;
109173109180
Expr *pExprB = pB->a[i].pExpr;
109174
- 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;
109175109182
if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
109176109183
}
109177109184
return 0;
109178109185
}
109179109186
@@ -110858,11 +110865,11 @@
110858110865
return WRC_Prune;
110859110866
}
110860110867
if( ALWAYS(p->pEList) ){
110861110868
ExprList *pList = p->pEList;
110862110869
for(i=0; i<pList->nExpr; i++){
110863
- if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){
110870
+ if( pList->a[i].zEName && pList->a[i].fg.eEName==ENAME_NAME ){
110864110871
sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
110865110872
}
110866110873
}
110867110874
}
110868110875
if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
@@ -110907,11 +110914,11 @@
110907110914
memset(&sWalker, 0, sizeof(Walker));
110908110915
sWalker.pParse = pParse;
110909110916
sWalker.xExprCallback = renameUnmapExprCb;
110910110917
sqlite3WalkExprList(&sWalker, pEList);
110911110918
for(i=0; i<pEList->nExpr; i++){
110912
- if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) ){
110919
+ if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME) ){
110913110920
sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
110914110921
}
110915110922
}
110916110923
}
110917110924
}
@@ -111065,11 +111072,11 @@
111065111072
){
111066111073
if( pEList ){
111067111074
int i;
111068111075
for(i=0; i<pEList->nExpr; i++){
111069111076
const char *zName = pEList->a[i].zEName;
111070
- if( ALWAYS(pEList->a[i].eEName==ENAME_NAME)
111077
+ if( ALWAYS(pEList->a[i].fg.eEName==ENAME_NAME)
111071111078
&& ALWAYS(zName!=0)
111072111079
&& 0==sqlite3_stricmp(zName, zOld)
111073111080
){
111074111081
renameTokenFind(pParse, pCtx, (const void*)zName);
111075111082
}
@@ -116948,11 +116955,11 @@
116948116955
}
116949116956
pTab->iPKey = iCol;
116950116957
pTab->keyConf = (u8)onError;
116951116958
assert( autoInc==0 || autoInc==1 );
116952116959
pTab->tabFlags |= autoInc*TF_Autoincrement;
116953
- if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags;
116960
+ if( pList ) pParse->iPkSortOrder = pList->a[0].fg.sortFlags;
116954116961
(void)sqlite3HasExplicitNulls(pParse, pList);
116955116962
}else if( autoInc ){
116956116963
#ifndef SQLITE_OMIT_AUTOINCREMENT
116957116964
sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
116958116965
"INTEGER PRIMARY KEY");
@@ -117442,11 +117449,11 @@
117442117449
return;
117443117450
}
117444117451
if( IN_RENAME_OBJECT ){
117445117452
sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
117446117453
}
117447
- pList->a[0].sortFlags = pParse->iPkSortOrder;
117454
+ pList->a[0].fg.sortFlags = pParse->iPkSortOrder;
117448117455
assert( pParse->pNewTable==pTab );
117449117456
pTab->iPKey = -1;
117450117457
sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
117451117458
SQLITE_IDXTYPE_PRIMARYKEY);
117452117459
if( pParse->nErr ){
@@ -118930,12 +118937,12 @@
118930118937
*/
118931118938
SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
118932118939
if( pList ){
118933118940
int i;
118934118941
for(i=0; i<pList->nExpr; i++){
118935
- if( pList->a[i].bNulls ){
118936
- u8 sf = pList->a[i].sortFlags;
118942
+ if( pList->a[i].fg.bNulls ){
118943
+ u8 sf = pList->a[i].fg.sortFlags;
118937118944
sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s",
118938118945
(sf==0 || sf==3) ? "FIRST" : "LAST"
118939118946
);
118940118947
return 1;
118941118948
}
@@ -119284,11 +119291,11 @@
119284119291
if( !zColl ) zColl = sqlite3StrBINARY;
119285119292
if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
119286119293
goto exit_create_index;
119287119294
}
119288119295
pIndex->azColl[i] = zColl;
119289
- requestedSortOrder = pListItem->sortFlags & sortOrderMask;
119296
+ requestedSortOrder = pListItem->fg.sortFlags & sortOrderMask;
119290119297
pIndex->aSortOrder[i] = (u8)requestedSortOrder;
119291119298
}
119292119299
119293119300
/* Append the table key to the end of the index. For WITHOUT ROWID
119294119301
** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
@@ -135062,10 +135069,18 @@
135062135069
db->pParse = pParse;
135063135070
pParse->db = db;
135064135071
if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory");
135065135072
}
135066135073
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
+
135067135082
/*
135068135083
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
135069135084
*/
135070135085
static int sqlite3Prepare(
135071135086
sqlite3 *db, /* Database handle. */
@@ -135236,11 +135251,11 @@
135236135251
** or encounters a permanent error. A schema problem after one schema
135237135252
** reset is considered a permanent error. */
135238135253
rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
135239135254
assert( rc==SQLITE_OK || *ppStmt==0 );
135240135255
if( rc==SQLITE_OK || db->mallocFailed ) break;
135241
- }while( rc==SQLITE_ERROR_RETRY
135256
+ }while( (rc==SQLITE_ERROR_RETRY && (cnt++)<SQLITE_MAX_PREPARE_RETRY)
135242135257
|| (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
135243135258
sqlite3BtreeLeaveAll(db);
135244135259
rc = sqlite3ApiExit(db, rc);
135245135260
assert( (rc&db->errMask)==rc );
135246135261
db->busyHandler.nBusy = 0;
@@ -135787,11 +135802,11 @@
135787135802
ExprList *pResults;
135788135803
assert( pItem->pSelect!=0 );
135789135804
pResults = pItem->pSelect->pEList;
135790135805
assert( pResults!=0 );
135791135806
assert( iCol>=0 && iCol<pResults->nExpr );
135792
- pResults->a[iCol].bUsed = 1;
135807
+ pResults->a[iCol].fg.bUsed = 1;
135793135808
}
135794135809
}
135795135810
135796135811
/*
135797135812
** Search the tables iStart..iEnd (inclusive) in pSrc, looking for a
@@ -136455,11 +136470,11 @@
136455136470
** the row from table t1 is stored instead. Then, as records are extracted from
136456136471
** the sorter to return to the user, the required value of bigblob is
136457136472
** retrieved directly from table t1. If the values are very large, this
136458136473
** can be more efficient than storing them directly in the sorter records.
136459136474
**
136460
-** 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
136461136476
** for which the sorter-reference optimization should be enabled.
136462136477
** Additionally, the pSort->aDefer[] array is populated with entries
136463136478
** for all cursors required to evaluate all selected expressions. Finally.
136464136479
** output variable (*ppExtra) is set to an expression list containing
136465136480
** expressions for all extra PK values that should be stored in the
@@ -136515,11 +136530,11 @@
136515136530
pSort->aDefer[nDefer].iCsr = pExpr->iTable;
136516136531
pSort->aDefer[nDefer].nKey = nKey;
136517136532
nDefer++;
136518136533
}
136519136534
}
136520
- pItem->bSorterRef = 1;
136535
+ pItem->fg.bSorterRef = 1;
136521136536
}
136522136537
}
136523136538
}
136524136539
pSort->nDefer = (u8)nDefer;
136525136540
*ppExtra = pExtra;
@@ -136646,11 +136661,11 @@
136646136661
** from the sorter by the optimizations in this branch */
136647136662
pEList = p->pEList;
136648136663
for(i=0; i<pEList->nExpr; i++){
136649136664
if( pEList->a[i].u.x.iOrderByCol>0
136650136665
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
136651
- || pEList->a[i].bSorterRef
136666
+ || pEList->a[i].fg.bSorterRef
136652136667
#endif
136653136668
){
136654136669
nResultCol--;
136655136670
regOrig = 0;
136656136671
}
@@ -137008,11 +137023,11 @@
137008137023
pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
137009137024
if( pInfo ){
137010137025
assert( sqlite3KeyInfoIsWriteable(pInfo) );
137011137026
for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
137012137027
pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr);
137013
- pInfo->aSortFlags[i-iStart] = pItem->sortFlags;
137028
+ pInfo->aSortFlags[i-iStart] = pItem->fg.sortFlags;
137014137029
}
137015137030
}
137016137031
return pInfo;
137017137032
}
137018137033
@@ -137147,11 +137162,11 @@
137147137162
iSortTab = iTab;
137148137163
bSeq = 1;
137149137164
}
137150137165
for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
137151137166
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
137152
- if( aOutEx[i].bSorterRef ) continue;
137167
+ if( aOutEx[i].fg.bSorterRef ) continue;
137153137168
#endif
137154137169
if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
137155137170
}
137156137171
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
137157137172
if( pSort->nDefer ){
@@ -137184,11 +137199,11 @@
137184137199
sqlite3ReleaseTempRange(pParse, regKey, nRefKey);
137185137200
}
137186137201
#endif
137187137202
for(i=nColumn-1; i>=0; i--){
137188137203
#ifdef SQLITE_ENABLE_SORTER_REFERENCES
137189
- if( aOutEx[i].bSorterRef ){
137204
+ if( aOutEx[i].fg.bSorterRef ){
137190137205
sqlite3ExprCode(pParse, aOutEx[i].pExpr, regRow+i);
137191137206
}else
137192137207
#endif
137193137208
{
137194137209
int iRead;
@@ -137550,11 +137565,11 @@
137550137565
137551137566
assert( p!=0 );
137552137567
assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
137553137568
assert( p->op!=TK_COLUMN
137554137569
|| (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
137555
- if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){
137570
+ if( pEList->a[i].zEName && pEList->a[i].fg.eEName==ENAME_NAME ){
137556137571
/* An AS clause always takes first priority */
137557137572
char *zName = pEList->a[i].zEName;
137558137573
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
137559137574
}else if( srcName && p->op==TK_COLUMN ){
137560137575
char *zCol;
@@ -137636,13 +137651,14 @@
137636137651
*pnCol = nCol;
137637137652
*paCol = aCol;
137638137653
137639137654
for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
137640137655
struct ExprList_item *pX = &pEList->a[i];
137656
+ struct ExprList_item *pCollide;
137641137657
/* Get an appropriate name for the column
137642137658
*/
137643
- if( (zName = pX->zEName)!=0 && pX->eEName==ENAME_NAME ){
137659
+ if( (zName = pX->zEName)!=0 && pX->fg.eEName==ENAME_NAME ){
137644137660
/* If the column contains an "AS <name>" phrase, use <name> as the name */
137645137661
}else{
137646137662
Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pX->pExpr);
137647137663
while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
137648137664
pColExpr = pColExpr->pRight;
@@ -137672,11 +137688,14 @@
137672137688
137673137689
/* Make sure the column name is unique. If the name is not unique,
137674137690
** append an integer to the name so that it becomes unique.
137675137691
*/
137676137692
cnt = 0;
137677
- 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
+ }
137678137697
nName = sqlite3Strlen30(zName);
137679137698
if( nName>0 ){
137680137699
for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
137681137700
if( zName[j]==':' ) nName = j;
137682137701
}
@@ -137683,12 +137702,15 @@
137683137702
zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
137684137703
if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
137685137704
}
137686137705
pCol->zCnName = zName;
137687137706
pCol->hName = sqlite3StrIHash(zName);
137707
+ if( pX->fg.bNoExpand ){
137708
+ pCol->colFlags |= COLFLAG_NOEXPAND;
137709
+ }
137688137710
sqlite3ColumnPropertiesFromName(0, pCol);
137689
- if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
137711
+ if( zName && sqlite3HashInsert(&ht, zName, pX)==pX ){
137690137712
sqlite3OomFault(db);
137691137713
}
137692137714
}
137693137715
sqlite3HashClear(&ht);
137694137716
if( db->mallocFailed ){
@@ -137941,11 +137963,11 @@
137941137963
pOrderBy->a[i].pExpr =
137942137964
sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
137943137965
}
137944137966
assert( sqlite3KeyInfoIsWriteable(pRet) );
137945137967
pRet->aColl[i] = pColl;
137946
- pRet->aSortFlags[i] = pOrderBy->a[i].sortFlags;
137968
+ pRet->aSortFlags[i] = pOrderBy->a[i].fg.sortFlags;
137947137969
}
137948137970
}
137949137971
137950137972
return pRet;
137951137973
}
@@ -140547,11 +140569,11 @@
140547140569
}else{
140548140570
return eRet;
140549140571
}
140550140572
*ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
140551140573
assert( pOrderBy!=0 || db->mallocFailed );
140552
- if( pOrderBy ) pOrderBy->a[0].sortFlags = sortFlags;
140574
+ if( pOrderBy ) pOrderBy->a[0].fg.sortFlags = sortFlags;
140553140575
return eRet;
140554140576
}
140555140577
140556140578
/*
140557140579
** The select statement passed as the first argument is an aggregate query.
@@ -141254,11 +141276,11 @@
141254141276
/* This particular expression does not need to be expanded.
141255141277
*/
141256141278
pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
141257141279
if( pNew ){
141258141280
pNew->a[pNew->nExpr-1].zEName = a[k].zEName;
141259
- pNew->a[pNew->nExpr-1].eEName = a[k].eEName;
141281
+ pNew->a[pNew->nExpr-1].fg.eEName = a[k].fg.eEName;
141260141282
a[k].zEName = 0;
141261141283
}
141262141284
a[k].pExpr = 0;
141263141285
}else{
141264141286
/* This expression is a "*" or a "TABLE.*" and needs to be
@@ -141274,10 +141296,11 @@
141274141296
Table *pTab = pFrom->pTab; /* Table for this data source */
141275141297
ExprList *pNestedFrom; /* Result-set of a nested FROM clause */
141276141298
char *zTabName; /* AS name for this data source */
141277141299
const char *zSchemaName = 0; /* Schema name for this data source */
141278141300
int iDb; /* Schema index for this data src */
141301
+ IdList *pUsing; /* USING clause for pFrom[1] */
141279141302
141280141303
if( (zTabName = pFrom->zAlias)==0 ){
141281141304
zTabName = pTab->zName;
141282141305
}
141283141306
if( db->mallocFailed ) break;
@@ -141292,10 +141315,31 @@
141292141315
continue;
141293141316
}
141294141317
pNestedFrom = 0;
141295141318
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
141296141319
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;
141297141341
}
141298141342
for(j=0; j<pTab->nCol; j++){
141299141343
char *zName = pTab->aCol[j].zCnName;
141300141344
struct ExprList_item *pX; /* Newly added ExprList term */
141301141345
@@ -141313,14 +141357,20 @@
141313141357
*/
141314141358
if( (p->selFlags & SF_IncludeHidden)==0
141315141359
&& IsHiddenColumn(&pTab->aCol[j])
141316141360
){
141317141361
continue;
141362
+ }
141363
+ if( (pTab->aCol[j].colFlags & COLFLAG_NOEXPAND)!=0
141364
+ && zTName==0
141365
+ && (selFlags & (SF_NestedFrom))==0
141366
+ ){
141367
+ continue;
141318141368
}
141319141369
tableSeen = 1;
141320141370
141321
- if( i>0 && zTName==0 ){
141371
+ if( i>0 && zTName==0 && (selFlags & SF_NestedFrom)==0 ){
141322141372
if( pFrom->fg.isUsing
141323141373
&& sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0
141324141374
){
141325141375
/* In a join with a USING clause, omit columns in the
141326141376
** using clause from the table on the right. */
@@ -141328,10 +141378,11 @@
141328141378
}
141329141379
}
141330141380
pRight = sqlite3Expr(db, TK_ID, zName);
141331141381
if( (pTabList->nSrc>1
141332141382
&& ( (pFrom->fg.jointype & JT_LTORJ)==0
141383
+ || (selFlags & SF_NestedFrom)!=0
141333141384
|| !inAnyUsingClause(zName,pFrom,pTabList->nSrc-i-1)
141334141385
)
141335141386
)
141336141387
|| IN_RENAME_OBJECT
141337141388
){
@@ -141361,17 +141412,24 @@
141361141412
}else{
141362141413
pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
141363141414
zSchemaName, zTabName, zName);
141364141415
testcase( pX->zEName==0 );
141365141416
}
141366
- 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
+ }
141367141425
}else if( longNames ){
141368141426
pX->zEName = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
141369
- pX->eEName = ENAME_NAME;
141427
+ pX->fg.eEName = ENAME_NAME;
141370141428
}else{
141371141429
pX->zEName = sqlite3DbStrDup(db, zName);
141372
- pX->eEName = ENAME_NAME;
141430
+ pX->fg.eEName = ENAME_NAME;
141373141431
}
141374141432
}
141375141433
}
141376141434
if( !tableSeen ){
141377141435
if( zTName ){
@@ -142495,17 +142553,17 @@
142495142553
if( pDest->eDest==SRT_EphemTab ){
142496142554
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr);
142497142555
if( p->selFlags & SF_NestedFrom ){
142498142556
/* Delete or NULL-out result columns that will never be used */
142499142557
int ii;
142500
- 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--){
142501142559
sqlite3ExprDelete(db, pEList->a[ii].pExpr);
142502142560
sqlite3DbFree(db, pEList->a[ii].zEName);
142503142561
pEList->nExpr--;
142504142562
}
142505142563
for(ii=0; ii<pEList->nExpr; ii++){
142506
- 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;
142507142565
}
142508142566
}
142509142567
}
142510142568
142511142569
/* Set the limiter.
@@ -142653,12 +142711,13 @@
142653142711
** ASC or DESC order - only that each group is returned contiguously.
142654142712
** So set the ASC/DESC flags in the GROUP BY to match those in the
142655142713
** ORDER BY to maximize the chances of rows being delivered in an
142656142714
** order that makes the ORDER BY redundant. */
142657142715
for(ii=0; ii<pGroupBy->nExpr; ii++){
142658
- u8 sortFlags = sSort.pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_DESC;
142659
- 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;
142660142719
}
142661142720
if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
142662142721
orderByGrp = 1;
142663142722
}
142664142723
}
@@ -144309,20 +144368,20 @@
144309144368
pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zCnName);
144310144369
pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144311144370
if( !db->mallocFailed ){
144312144371
struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144313144372
pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName);
144314
- pItem->eEName = ENAME_NAME;
144373
+ pItem->fg.eEName = ENAME_NAME;
144315144374
}
144316144375
}
144317144376
}else{
144318144377
Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
144319144378
pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144320144379
if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){
144321144380
struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144322144381
pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName);
144323
- pItem->eEName = pList->a[i].eEName;
144382
+ pItem->fg.eEName = pList->a[i].fg.eEName;
144324144383
}
144325144384
}
144326144385
}
144327144386
return pNew;
144328144387
}
@@ -146891,10 +146950,11 @@
146891146950
#endif
146892146951
}
146893146952
146894146953
assert( rc==SQLITE_OK );
146895146954
if( pOut==0 ){
146955
+ nRes = sqlite3BtreeGetRequestedReserve(pTemp);
146896146956
rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
146897146957
}
146898146958
146899146959
end_of_vacuum:
146900146960
/* Restore the original value of db->flags */
@@ -151555,11 +151615,11 @@
151555151615
continue;
151556151616
}
151557151617
pE = pTerm->pExpr;
151558151618
assert( pE!=0 );
151559151619
if( (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ))
151560
- && !ExprHasProperty(pE,EP_FromJoin)
151620
+ && !ExprHasProperty(pE,EP_FromJoin|EP_InnerJoin)
151561151621
){
151562151622
continue;
151563151623
}
151564151624
151565151625
if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
@@ -153446,11 +153506,11 @@
153446153506
if( pOrderBy ){
153447153507
for(ii=0; ii<pOrderBy->nExpr; ii++){
153448153508
Expr *pExpr = pOrderBy->a[ii].pExpr;
153449153509
if( pExpr->op!=TK_COLUMN ) return;
153450153510
if( pExpr->iTable!=iCsr ) return;
153451
- if( pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_BIGNULL ) return;
153511
+ if( pOrderBy->a[ii].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) return;
153452153512
}
153453153513
}
153454153514
153455153515
/* All conditions are met. Add the terms to the where-clause object. */
153456153516
assert( p->pLimit->op==TK_LIMIT );
@@ -154876,11 +154936,11 @@
154876154936
if( sqlite3ExprIsConstant(pExpr) ){
154877154937
continue;
154878154938
}
154879154939
154880154940
/* Virtual tables are unable to deal with NULLS FIRST */
154881
- if( pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL ) break;
154941
+ if( pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL ) break;
154882154942
154883154943
/* First case - a direct column references without a COLLATE operator */
154884154944
if( pExpr->op==TK_COLUMN && pExpr->iTable==pSrc->iCursor ){
154885154945
assert( pExpr->iColumn>=XN_ROWID && pExpr->iColumn<pTab->nCol );
154886154946
continue;
@@ -154988,11 +155048,11 @@
154988155048
if( sqlite3ExprIsConstant(pExpr) ) continue;
154989155049
assert( pExpr->op==TK_COLUMN
154990155050
|| (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN
154991155051
&& pExpr->iColumn==pExpr->pLeft->iColumn) );
154992155052
pIdxOrderBy[j].iColumn = pExpr->iColumn;
154993
- pIdxOrderBy[j].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC;
155053
+ pIdxOrderBy[j].desc = pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC;
154994155054
j++;
154995155055
}
154996155056
pIdxInfo->nOrderBy = j;
154997155057
154998155058
*pmNoOmit = mNoOmit;
@@ -156506,11 +156566,11 @@
156506156566
/* tag-20191211-001: Do not allow constraints from the WHERE clause to
156507156567
** be used by the right table of a LEFT JOIN nor by the left table of a
156508156568
** RIGHT JOIN. Only constraints in the
156509156569
** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
156510156570
if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
156511
- && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
156571
+ && !ExprHasProperty(pTerm->pExpr, EP_FromJoin|EP_InnerJoin)
156512156572
){
156513156573
continue;
156514156574
}
156515156575
156516156576
if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
@@ -157814,13 +157874,11 @@
157814157874
pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
157815157875
pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
157816157876
if( (pItem->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
157817157877
/* This condition is true when pItem is the FROM clause term on the
157818157878
** right-hand-side of a OUTER or CROSS JOIN. */
157819
- mPrereq = mPrior;
157820
- }else{
157821
- mPrereq = 0;
157879
+ mPrereq |= mPrior;
157822157880
}
157823157881
#ifndef SQLITE_OMIT_VIRTUALTABLE
157824157882
if( IsVirtual(pItem->pTab) ){
157825157883
SrcItem *p;
157826157884
for(p=&pItem[1]; p<pEnd; p++){
@@ -158127,20 +158185,22 @@
158127158185
}
158128158186
if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
158129158187
/* Make sure the sort order is compatible in an ORDER BY clause.
158130158188
** Sort order is irrelevant for a GROUP BY clause. */
158131158189
if( revSet ){
158132
- if( (rev ^ revIdx)!=(pOrderBy->a[i].sortFlags&KEYINFO_ORDER_DESC) ){
158190
+ if( (rev ^ revIdx)
158191
+ != (pOrderBy->a[i].fg.sortFlags&KEYINFO_ORDER_DESC)
158192
+ ){
158133158193
isMatch = 0;
158134158194
}
158135158195
}else{
158136
- rev = revIdx ^ (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC);
158196
+ rev = revIdx ^ (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_DESC);
158137158197
if( rev ) *pRevMask |= MASKBIT(iLoop);
158138158198
revSet = 1;
158139158199
}
158140158200
}
158141
- if( isMatch && (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL) ){
158201
+ if( isMatch && (pOrderBy->a[i].fg.sortFlags & KEYINFO_ORDER_BIGNULL) ){
158142158202
if( j==pLoop->u.btree.nEq ){
158143158203
pLoop->wsFlags |= WHERE_BIGNULL_SORT;
158144158204
}else{
158145158205
isMatch = 0;
158146158206
}
@@ -160900,11 +160960,11 @@
160900160960
pSub->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
160901160961
pSub->u.zToken = 0;
160902160962
}
160903160963
}
160904160964
pList = sqlite3ExprListAppend(pParse, pList, pDup);
160905
- 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;
160906160966
}
160907160967
}
160908160968
return pList;
160909160969
}
160910160970
@@ -162101,11 +162161,11 @@
162101162161
windowReadPeerValues(p, csr1, reg1);
162102162162
windowReadPeerValues(p, csr2, reg2);
162103162163
162104162164
assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
162105162165
assert( pOrderBy && pOrderBy->nExpr==1 );
162106
- if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
162166
+ if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_DESC ){
162107162167
switch( op ){
162108162168
case OP_Ge: op = OP_Le; break;
162109162169
case OP_Gt: op = OP_Lt; break;
162110162170
default: assert( op==OP_Le ); op = OP_Ge; break;
162111162171
}
@@ -162134,11 +162194,11 @@
162134162194
** }
162135162195
**
162136162196
** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is
162137162197
** not taken, control jumps over the comparison operator coded below this
162138162198
** block. */
162139
- if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_BIGNULL ){
162199
+ if( pOrderBy->a[0].fg.sortFlags & KEYINFO_ORDER_BIGNULL ){
162140162200
/* This block runs if reg1 contains a NULL. */
162141162201
int addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v);
162142162202
switch( op ){
162143162203
case OP_Ge:
162144162204
sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl);
@@ -236235,11 +236295,11 @@
236235236295
int nArg, /* Number of args */
236236236296
sqlite3_value **apUnused /* Function arguments */
236237236297
){
236238236298
assert( nArg==0 );
236239236299
UNUSED_PARAM2(nArg, apUnused);
236240
- sqlite3_result_text(pCtx, "fts5: 2022-05-03 14:01:48 6eda9b1a7784cf6d58c8876551f67ab98e78a08e726a0579d4def5ba881985bb", -1, SQLITE_TRANSIENT);
236300
+ sqlite3_result_text(pCtx, "fts5: 2022-05-10 00:24:01 c6c3115f3a008cf9b0d7c5c812f17e38c8a75a904032c5f05f0bea03a7340527", -1, SQLITE_TRANSIENT);
236241236301
}
236242236302
236243236303
/*
236244236304
** Return true if zName is the extension on one of the shadow tables used
236245236305
** by this module.
236246236306
--- 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-03 14:01:48 6eda9b1a7784cf6d58c8876551f67ab98e78a08e726a0579d4def5ba881985bb"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -17400,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_GENERATED 0x0060 /* Combo: _STORED, _VIRTUAL */
17406 #define COLFLAG_NOINSERT 0x0062 /* Combo: _HIDDEN, _STORED, _VIRTUAL */
17407
17408 /*
17409 ** A "Collating Sequence" is defined by an instance of the following
@@ -18273,17 +18274,22 @@
18273 int nExpr; /* Number of expressions on the list */
18274 int nAlloc; /* Number of a[] slots allocated */
18275 struct ExprList_item { /* For each expression in the list */
18276 Expr *pExpr; /* The parse tree for this expression */
18277 char *zEName; /* Token associated with this expression */
18278 u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */
18279 unsigned eEName :2; /* Meaning of zEName */
18280 unsigned done :1; /* A flag to indicate when processing is finished */
18281 unsigned reusable :1; /* Constant expression is reusable */
18282 unsigned bSorterRef :1; /* Defer evaluation until after sorting */
18283 unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */
18284 unsigned bUsed: 1; /* This column used in a SF_NestedFrom subquery */
 
 
 
 
 
18285 union {
18286 struct { /* Used by any ExprList other than Parse.pConsExpr */
18287 u16 iOrderByCol; /* For ORDER BY, column number in result set */
18288 u16 iAlias; /* Index into Parse.aAlias[] for zName */
18289 } x;
@@ -31850,17 +31856,19 @@
31850 if( j || zName ){
31851 sqlite3TreeViewPush(&pView, moreToFollow);
31852 moreToFollow = 0;
31853 sqlite3TreeViewLine(pView, 0);
31854 if( zName ){
31855 switch( pList->a[i].eEName ){
31856 default:
31857 fprintf(stdout, "AS %s ", zName);
31858 break;
31859 case ENAME_TAB:
31860 fprintf(stdout, "TABLE-ALIAS-NAME(\"%s\") ", zName);
31861 if( pList->a[i].bUsed==0 ) fprintf(stdout, "(unused) ");
 
 
31862 break;
31863 case ENAME_SPAN:
31864 fprintf(stdout, "SPAN(\"%s\") ", zName);
31865 break;
31866 }
@@ -101539,11 +101547,11 @@
101539 const char *zTab,
101540 const char *zDb
101541 ){
101542 int n;
101543 const char *zSpan;
101544 if( pItem->eEName!=ENAME_TAB ) return 0;
101545 zSpan = pItem->zEName;
101546 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
101547 if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
101548 return 0;
101549 }
@@ -101768,12 +101776,13 @@
101768 }
101769 cnt++;
101770 cntTab = 2;
101771 pMatch = pItem;
101772 pExpr->iColumn = j;
101773 pEList->a[j].bUsed = 1;
101774 hit = 1;
 
101775 }
101776 if( hit || zTab==0 ) continue;
101777 }
101778 assert( zDb==0 || zTab!=0 );
101779 if( zTab ){
@@ -101992,11 +102001,11 @@
101992 ){
101993 pEList = pNC->uNC.pEList;
101994 assert( pEList!=0 );
101995 for(j=0; j<pEList->nExpr; j++){
101996 char *zAs = pEList->a[j].zEName;
101997 if( pEList->a[j].eEName==ENAME_NAME
101998 && sqlite3_stricmp(zAs, zCol)==0
101999 ){
102000 Expr *pOrig;
102001 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
102002 assert( ExprUseXList(pExpr)==0 || pExpr->x.pList==0 );
@@ -102745,11 +102754,11 @@
102745 if( pE->op==TK_ID ){
102746 const char *zCol;
102747 assert( !ExprHasProperty(pE, EP_IntValue) );
102748 zCol = pE->u.zToken;
102749 for(i=0; i<pEList->nExpr; i++){
102750 if( pEList->a[i].eEName==ENAME_NAME
102751 && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0
102752 ){
102753 return i+1;
102754 }
102755 }
@@ -102866,11 +102875,11 @@
102866 if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
102867 sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
102868 return 1;
102869 }
102870 for(i=0; i<pOrderBy->nExpr; i++){
102871 pOrderBy->a[i].done = 0;
102872 }
102873 pSelect->pNext = 0;
102874 while( pSelect->pPrior ){
102875 pSelect->pPrior->pNext = pSelect;
102876 pSelect = pSelect->pPrior;
@@ -102881,11 +102890,11 @@
102881 pEList = pSelect->pEList;
102882 assert( pEList!=0 );
102883 for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
102884 int iCol = -1;
102885 Expr *pE, *pDup;
102886 if( pItem->done ) continue;
102887 pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
102888 if( NEVER(pE==0) ) continue;
102889 if( sqlite3ExprIsInteger(pE, &iCol) ){
102890 if( iCol<=0 || iCol>pEList->nExpr ){
102891 resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr, pE);
@@ -102934,19 +102943,19 @@
102934 pParent->pLeft = pNew;
102935 }
102936 sqlite3ExprDelete(db, pE);
102937 pItem->u.x.iOrderByCol = (u16)iCol;
102938 }
102939 pItem->done = 1;
102940 }else{
102941 moreToDo = 1;
102942 }
102943 }
102944 pSelect = pSelect->pNext;
102945 }
102946 for(i=0; i<pOrderBy->nExpr; i++){
102947 if( pOrderBy->a[i].done==0 ){
102948 sqlite3ErrorMsg(pParse, "%r ORDER BY term does not match any "
102949 "column in the result set", i+1);
102950 return 1;
102951 }
102952 }
@@ -105186,16 +105195,12 @@
105186 }
105187 pNewExpr->pLeft = pPriorSelectColNew;
105188 }
105189 }
105190 pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName);
105191 pItem->sortFlags = pOldItem->sortFlags;
105192 pItem->eEName = pOldItem->eEName;
105193 pItem->done = 0;
105194 pItem->bNulls = pOldItem->bNulls;
105195 pItem->bUsed = pOldItem->bUsed;
105196 pItem->bSorterRef = pOldItem->bSorterRef;
105197 pItem->u = pOldItem->u;
105198 }
105199 return pNew;
105200 }
105201
@@ -105491,20 +105496,20 @@
105491 || eNulls==SQLITE_SO_ASC
105492 || eNulls==SQLITE_SO_DESC
105493 );
105494
105495 pItem = &p->a[p->nExpr-1];
105496 assert( pItem->bNulls==0 );
105497 if( iSortOrder==SQLITE_SO_UNDEFINED ){
105498 iSortOrder = SQLITE_SO_ASC;
105499 }
105500 pItem->sortFlags = (u8)iSortOrder;
105501
105502 if( eNulls!=SQLITE_SO_UNDEFINED ){
105503 pItem->bNulls = 1;
105504 if( iSortOrder!=eNulls ){
105505 pItem->sortFlags |= KEYINFO_ORDER_BIGNULL;
105506 }
105507 }
105508 }
105509
105510 /*
@@ -105526,11 +105531,11 @@
105526 if( pList ){
105527 struct ExprList_item *pItem;
105528 assert( pList->nExpr>0 );
105529 pItem = &pList->a[pList->nExpr-1];
105530 assert( pItem->zEName==0 );
105531 assert( pItem->eEName==ENAME_NAME );
105532 pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
105533 if( dequote ){
105534 /* If dequote==0, then pName->z does not point to part of a DDL
105535 ** statement handled by the parser. And so no token need be added
105536 ** to the token-map. */
@@ -105561,11 +105566,11 @@
105561 if( pList ){
105562 struct ExprList_item *pItem = &pList->a[pList->nExpr-1];
105563 assert( pList->nExpr>0 );
105564 if( pItem->zEName==0 ){
105565 pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd);
105566 pItem->eEName = ENAME_SPAN;
105567 }
105568 }
105569 }
105570
105571 /*
@@ -108387,11 +108392,13 @@
108387 p = pParse->pConstExpr;
108388 if( regDest<0 && p ){
108389 struct ExprList_item *pItem;
108390 int i;
108391 for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
108392 if( pItem->reusable && sqlite3ExprCompare(0,pItem->pExpr,pExpr,-1)==0 ){
 
 
108393 return pItem->u.iConstExprReg;
108394 }
108395 }
108396 }
108397 pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
@@ -108410,11 +108417,11 @@
108410 sqlite3VdbeJumpHere(v, addr);
108411 }else{
108412 p = sqlite3ExprListAppend(pParse, p, pExpr);
108413 if( p ){
108414 struct ExprList_item *pItem = &p->a[p->nExpr-1];
108415 pItem->reusable = regDest<0;
108416 if( regDest<0 ) regDest = ++pParse->nMem;
108417 pItem->u.iConstExprReg = regDest;
108418 }
108419 pParse->pConstExpr = p;
108420 }
@@ -108544,11 +108551,11 @@
108544 n = pList->nExpr;
108545 if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
108546 for(pItem=pList->a, i=0; i<n; i++, pItem++){
108547 Expr *pExpr = pItem->pExpr;
108548 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
108549 if( pItem->bSorterRef ){
108550 i--;
108551 n--;
108552 }else
108553 #endif
108554 if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
@@ -109169,11 +109176,11 @@
109169 if( pA->nExpr!=pB->nExpr ) return 1;
109170 for(i=0; i<pA->nExpr; i++){
109171 int res;
109172 Expr *pExprA = pA->a[i].pExpr;
109173 Expr *pExprB = pB->a[i].pExpr;
109174 if( pA->a[i].sortFlags!=pB->a[i].sortFlags ) return 1;
109175 if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res;
109176 }
109177 return 0;
109178 }
109179
@@ -110858,11 +110865,11 @@
110858 return WRC_Prune;
110859 }
110860 if( ALWAYS(p->pEList) ){
110861 ExprList *pList = p->pEList;
110862 for(i=0; i<pList->nExpr; i++){
110863 if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){
110864 sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
110865 }
110866 }
110867 }
110868 if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */
@@ -110907,11 +110914,11 @@
110907 memset(&sWalker, 0, sizeof(Walker));
110908 sWalker.pParse = pParse;
110909 sWalker.xExprCallback = renameUnmapExprCb;
110910 sqlite3WalkExprList(&sWalker, pEList);
110911 for(i=0; i<pEList->nExpr; i++){
110912 if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) ){
110913 sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
110914 }
110915 }
110916 }
110917 }
@@ -111065,11 +111072,11 @@
111065 ){
111066 if( pEList ){
111067 int i;
111068 for(i=0; i<pEList->nExpr; i++){
111069 const char *zName = pEList->a[i].zEName;
111070 if( ALWAYS(pEList->a[i].eEName==ENAME_NAME)
111071 && ALWAYS(zName!=0)
111072 && 0==sqlite3_stricmp(zName, zOld)
111073 ){
111074 renameTokenFind(pParse, pCtx, (const void*)zName);
111075 }
@@ -116948,11 +116955,11 @@
116948 }
116949 pTab->iPKey = iCol;
116950 pTab->keyConf = (u8)onError;
116951 assert( autoInc==0 || autoInc==1 );
116952 pTab->tabFlags |= autoInc*TF_Autoincrement;
116953 if( pList ) pParse->iPkSortOrder = pList->a[0].sortFlags;
116954 (void)sqlite3HasExplicitNulls(pParse, pList);
116955 }else if( autoInc ){
116956 #ifndef SQLITE_OMIT_AUTOINCREMENT
116957 sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
116958 "INTEGER PRIMARY KEY");
@@ -117442,11 +117449,11 @@
117442 return;
117443 }
117444 if( IN_RENAME_OBJECT ){
117445 sqlite3RenameTokenRemap(pParse, pList->a[0].pExpr, &pTab->iPKey);
117446 }
117447 pList->a[0].sortFlags = pParse->iPkSortOrder;
117448 assert( pParse->pNewTable==pTab );
117449 pTab->iPKey = -1;
117450 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
117451 SQLITE_IDXTYPE_PRIMARYKEY);
117452 if( pParse->nErr ){
@@ -118930,12 +118937,12 @@
118930 */
118931 SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse *pParse, ExprList *pList){
118932 if( pList ){
118933 int i;
118934 for(i=0; i<pList->nExpr; i++){
118935 if( pList->a[i].bNulls ){
118936 u8 sf = pList->a[i].sortFlags;
118937 sqlite3ErrorMsg(pParse, "unsupported use of NULLS %s",
118938 (sf==0 || sf==3) ? "FIRST" : "LAST"
118939 );
118940 return 1;
118941 }
@@ -119284,11 +119291,11 @@
119284 if( !zColl ) zColl = sqlite3StrBINARY;
119285 if( !db->init.busy && !sqlite3LocateCollSeq(pParse, zColl) ){
119286 goto exit_create_index;
119287 }
119288 pIndex->azColl[i] = zColl;
119289 requestedSortOrder = pListItem->sortFlags & sortOrderMask;
119290 pIndex->aSortOrder[i] = (u8)requestedSortOrder;
119291 }
119292
119293 /* Append the table key to the end of the index. For WITHOUT ROWID
119294 ** tables (when pPk!=0) this will be the declared PRIMARY KEY. For
@@ -135062,10 +135069,18 @@
135062 db->pParse = pParse;
135063 pParse->db = db;
135064 if( db->mallocFailed ) sqlite3ErrorMsg(pParse, "out of memory");
135065 }
135066
 
 
 
 
 
 
 
 
135067 /*
135068 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
135069 */
135070 static int sqlite3Prepare(
135071 sqlite3 *db, /* Database handle. */
@@ -135236,11 +135251,11 @@
135236 ** or encounters a permanent error. A schema problem after one schema
135237 ** reset is considered a permanent error. */
135238 rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
135239 assert( rc==SQLITE_OK || *ppStmt==0 );
135240 if( rc==SQLITE_OK || db->mallocFailed ) break;
135241 }while( rc==SQLITE_ERROR_RETRY
135242 || (rc==SQLITE_SCHEMA && (sqlite3ResetOneSchema(db,-1), cnt++)==0) );
135243 sqlite3BtreeLeaveAll(db);
135244 rc = sqlite3ApiExit(db, rc);
135245 assert( (rc&db->errMask)==rc );
135246 db->busyHandler.nBusy = 0;
@@ -135787,11 +135802,11 @@
135787 ExprList *pResults;
135788 assert( pItem->pSelect!=0 );
135789 pResults = pItem->pSelect->pEList;
135790 assert( pResults!=0 );
135791 assert( iCol>=0 && iCol<pResults->nExpr );
135792 pResults->a[iCol].bUsed = 1;
135793 }
135794 }
135795
135796 /*
135797 ** Search the tables iStart..iEnd (inclusive) in pSrc, looking for a
@@ -136455,11 +136470,11 @@
136455 ** the row from table t1 is stored instead. Then, as records are extracted from
136456 ** the sorter to return to the user, the required value of bigblob is
136457 ** retrieved directly from table t1. If the values are very large, this
136458 ** can be more efficient than storing them directly in the sorter records.
136459 **
136460 ** The ExprList_item.bSorterRef flag is set for each expression in pEList
136461 ** for which the sorter-reference optimization should be enabled.
136462 ** Additionally, the pSort->aDefer[] array is populated with entries
136463 ** for all cursors required to evaluate all selected expressions. Finally.
136464 ** output variable (*ppExtra) is set to an expression list containing
136465 ** expressions for all extra PK values that should be stored in the
@@ -136515,11 +136530,11 @@
136515 pSort->aDefer[nDefer].iCsr = pExpr->iTable;
136516 pSort->aDefer[nDefer].nKey = nKey;
136517 nDefer++;
136518 }
136519 }
136520 pItem->bSorterRef = 1;
136521 }
136522 }
136523 }
136524 pSort->nDefer = (u8)nDefer;
136525 *ppExtra = pExtra;
@@ -136646,11 +136661,11 @@
136646 ** from the sorter by the optimizations in this branch */
136647 pEList = p->pEList;
136648 for(i=0; i<pEList->nExpr; i++){
136649 if( pEList->a[i].u.x.iOrderByCol>0
136650 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
136651 || pEList->a[i].bSorterRef
136652 #endif
136653 ){
136654 nResultCol--;
136655 regOrig = 0;
136656 }
@@ -137008,11 +137023,11 @@
137008 pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);
137009 if( pInfo ){
137010 assert( sqlite3KeyInfoIsWriteable(pInfo) );
137011 for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
137012 pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr);
137013 pInfo->aSortFlags[i-iStart] = pItem->sortFlags;
137014 }
137015 }
137016 return pInfo;
137017 }
137018
@@ -137147,11 +137162,11 @@
137147 iSortTab = iTab;
137148 bSeq = 1;
137149 }
137150 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
137151 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137152 if( aOutEx[i].bSorterRef ) continue;
137153 #endif
137154 if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
137155 }
137156 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137157 if( pSort->nDefer ){
@@ -137184,11 +137199,11 @@
137184 sqlite3ReleaseTempRange(pParse, regKey, nRefKey);
137185 }
137186 #endif
137187 for(i=nColumn-1; i>=0; i--){
137188 #ifdef SQLITE_ENABLE_SORTER_REFERENCES
137189 if( aOutEx[i].bSorterRef ){
137190 sqlite3ExprCode(pParse, aOutEx[i].pExpr, regRow+i);
137191 }else
137192 #endif
137193 {
137194 int iRead;
@@ -137550,11 +137565,11 @@
137550
137551 assert( p!=0 );
137552 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
137553 assert( p->op!=TK_COLUMN
137554 || (ExprUseYTab(p) && p->y.pTab!=0) ); /* Covering idx not yet coded */
137555 if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){
137556 /* An AS clause always takes first priority */
137557 char *zName = pEList->a[i].zEName;
137558 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
137559 }else if( srcName && p->op==TK_COLUMN ){
137560 char *zCol;
@@ -137636,13 +137651,14 @@
137636 *pnCol = nCol;
137637 *paCol = aCol;
137638
137639 for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
137640 struct ExprList_item *pX = &pEList->a[i];
 
137641 /* Get an appropriate name for the column
137642 */
137643 if( (zName = pX->zEName)!=0 && pX->eEName==ENAME_NAME ){
137644 /* If the column contains an "AS <name>" phrase, use <name> as the name */
137645 }else{
137646 Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pX->pExpr);
137647 while( ALWAYS(pColExpr!=0) && pColExpr->op==TK_DOT ){
137648 pColExpr = pColExpr->pRight;
@@ -137672,11 +137688,14 @@
137672
137673 /* Make sure the column name is unique. If the name is not unique,
137674 ** append an integer to the name so that it becomes unique.
137675 */
137676 cnt = 0;
137677 while( zName && sqlite3HashFind(&ht, zName)!=0 ){
 
 
 
137678 nName = sqlite3Strlen30(zName);
137679 if( nName>0 ){
137680 for(j=nName-1; j>0 && sqlite3Isdigit(zName[j]); j--){}
137681 if( zName[j]==':' ) nName = j;
137682 }
@@ -137683,12 +137702,15 @@
137683 zName = sqlite3MPrintf(db, "%.*z:%u", nName, zName, ++cnt);
137684 if( cnt>3 ) sqlite3_randomness(sizeof(cnt), &cnt);
137685 }
137686 pCol->zCnName = zName;
137687 pCol->hName = sqlite3StrIHash(zName);
 
 
 
137688 sqlite3ColumnPropertiesFromName(0, pCol);
137689 if( zName && sqlite3HashInsert(&ht, zName, pCol)==pCol ){
137690 sqlite3OomFault(db);
137691 }
137692 }
137693 sqlite3HashClear(&ht);
137694 if( db->mallocFailed ){
@@ -137941,11 +137963,11 @@
137941 pOrderBy->a[i].pExpr =
137942 sqlite3ExprAddCollateString(pParse, pTerm, pColl->zName);
137943 }
137944 assert( sqlite3KeyInfoIsWriteable(pRet) );
137945 pRet->aColl[i] = pColl;
137946 pRet->aSortFlags[i] = pOrderBy->a[i].sortFlags;
137947 }
137948 }
137949
137950 return pRet;
137951 }
@@ -140547,11 +140569,11 @@
140547 }else{
140548 return eRet;
140549 }
140550 *ppMinMax = pOrderBy = sqlite3ExprListDup(db, pEList, 0);
140551 assert( pOrderBy!=0 || db->mallocFailed );
140552 if( pOrderBy ) pOrderBy->a[0].sortFlags = sortFlags;
140553 return eRet;
140554 }
140555
140556 /*
140557 ** The select statement passed as the first argument is an aggregate query.
@@ -141254,11 +141276,11 @@
141254 /* This particular expression does not need to be expanded.
141255 */
141256 pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
141257 if( pNew ){
141258 pNew->a[pNew->nExpr-1].zEName = a[k].zEName;
141259 pNew->a[pNew->nExpr-1].eEName = a[k].eEName;
141260 a[k].zEName = 0;
141261 }
141262 a[k].pExpr = 0;
141263 }else{
141264 /* This expression is a "*" or a "TABLE.*" and needs to be
@@ -141274,10 +141296,11 @@
141274 Table *pTab = pFrom->pTab; /* Table for this data source */
141275 ExprList *pNestedFrom; /* Result-set of a nested FROM clause */
141276 char *zTabName; /* AS name for this data source */
141277 const char *zSchemaName = 0; /* Schema name for this data source */
141278 int iDb; /* Schema index for this data src */
 
141279
141280 if( (zTabName = pFrom->zAlias)==0 ){
141281 zTabName = pTab->zName;
141282 }
141283 if( db->mallocFailed ) break;
@@ -141292,10 +141315,31 @@
141292 continue;
141293 }
141294 pNestedFrom = 0;
141295 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
141296 zSchemaName = iDb>=0 ? db->aDb[iDb].zDbSName : "*";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141297 }
141298 for(j=0; j<pTab->nCol; j++){
141299 char *zName = pTab->aCol[j].zCnName;
141300 struct ExprList_item *pX; /* Newly added ExprList term */
141301
@@ -141313,14 +141357,20 @@
141313 */
141314 if( (p->selFlags & SF_IncludeHidden)==0
141315 && IsHiddenColumn(&pTab->aCol[j])
141316 ){
141317 continue;
 
 
 
 
 
 
141318 }
141319 tableSeen = 1;
141320
141321 if( i>0 && zTName==0 ){
141322 if( pFrom->fg.isUsing
141323 && sqlite3IdListIndex(pFrom->u3.pUsing, zName)>=0
141324 ){
141325 /* In a join with a USING clause, omit columns in the
141326 ** using clause from the table on the right. */
@@ -141328,10 +141378,11 @@
141328 }
141329 }
141330 pRight = sqlite3Expr(db, TK_ID, zName);
141331 if( (pTabList->nSrc>1
141332 && ( (pFrom->fg.jointype & JT_LTORJ)==0
 
141333 || !inAnyUsingClause(zName,pFrom,pTabList->nSrc-i-1)
141334 )
141335 )
141336 || IN_RENAME_OBJECT
141337 ){
@@ -141361,17 +141412,24 @@
141361 }else{
141362 pX->zEName = sqlite3MPrintf(db, "%s.%s.%s",
141363 zSchemaName, zTabName, zName);
141364 testcase( pX->zEName==0 );
141365 }
141366 pX->eEName = ENAME_TAB;
 
 
 
 
 
 
 
141367 }else if( longNames ){
141368 pX->zEName = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
141369 pX->eEName = ENAME_NAME;
141370 }else{
141371 pX->zEName = sqlite3DbStrDup(db, zName);
141372 pX->eEName = ENAME_NAME;
141373 }
141374 }
141375 }
141376 if( !tableSeen ){
141377 if( zTName ){
@@ -142495,17 +142553,17 @@
142495 if( pDest->eDest==SRT_EphemTab ){
142496 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pDest->iSDParm, pEList->nExpr);
142497 if( p->selFlags & SF_NestedFrom ){
142498 /* Delete or NULL-out result columns that will never be used */
142499 int ii;
142500 for(ii=pEList->nExpr-1; ii>0 && pEList->a[ii].bUsed==0; ii--){
142501 sqlite3ExprDelete(db, pEList->a[ii].pExpr);
142502 sqlite3DbFree(db, pEList->a[ii].zEName);
142503 pEList->nExpr--;
142504 }
142505 for(ii=0; ii<pEList->nExpr; ii++){
142506 if( pEList->a[ii].bUsed==0 ) pEList->a[ii].pExpr->op = TK_NULL;
142507 }
142508 }
142509 }
142510
142511 /* Set the limiter.
@@ -142653,12 +142711,13 @@
142653 ** ASC or DESC order - only that each group is returned contiguously.
142654 ** So set the ASC/DESC flags in the GROUP BY to match those in the
142655 ** ORDER BY to maximize the chances of rows being delivered in an
142656 ** order that makes the ORDER BY redundant. */
142657 for(ii=0; ii<pGroupBy->nExpr; ii++){
142658 u8 sortFlags = sSort.pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_DESC;
142659 pGroupBy->a[ii].sortFlags = sortFlags;
 
142660 }
142661 if( sqlite3ExprListCompare(pGroupBy, sSort.pOrderBy, -1)==0 ){
142662 orderByGrp = 1;
142663 }
142664 }
@@ -144309,20 +144368,20 @@
144309 pNewExpr = sqlite3Expr(db, TK_ID, pTab->aCol[jj].zCnName);
144310 pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144311 if( !db->mallocFailed ){
144312 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144313 pItem->zEName = sqlite3DbStrDup(db, pTab->aCol[jj].zCnName);
144314 pItem->eEName = ENAME_NAME;
144315 }
144316 }
144317 }else{
144318 Expr *pNewExpr = sqlite3ExprDup(db, pOldExpr, 0);
144319 pNew = sqlite3ExprListAppend(pParse, pNew, pNewExpr);
144320 if( !db->mallocFailed && ALWAYS(pList->a[i].zEName!=0) ){
144321 struct ExprList_item *pItem = &pNew->a[pNew->nExpr-1];
144322 pItem->zEName = sqlite3DbStrDup(db, pList->a[i].zEName);
144323 pItem->eEName = pList->a[i].eEName;
144324 }
144325 }
144326 }
144327 return pNew;
144328 }
@@ -146891,10 +146950,11 @@
146891 #endif
146892 }
146893
146894 assert( rc==SQLITE_OK );
146895 if( pOut==0 ){
 
146896 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
146897 }
146898
146899 end_of_vacuum:
146900 /* Restore the original value of db->flags */
@@ -151555,11 +151615,11 @@
151555 continue;
151556 }
151557 pE = pTerm->pExpr;
151558 assert( pE!=0 );
151559 if( (pTabItem->fg.jointype & (JT_LEFT|JT_LTORJ))
151560 && !ExprHasProperty(pE,EP_FromJoin)
151561 ){
151562 continue;
151563 }
151564
151565 if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
@@ -153446,11 +153506,11 @@
153446 if( pOrderBy ){
153447 for(ii=0; ii<pOrderBy->nExpr; ii++){
153448 Expr *pExpr = pOrderBy->a[ii].pExpr;
153449 if( pExpr->op!=TK_COLUMN ) return;
153450 if( pExpr->iTable!=iCsr ) return;
153451 if( pOrderBy->a[ii].sortFlags & KEYINFO_ORDER_BIGNULL ) return;
153452 }
153453 }
153454
153455 /* All conditions are met. Add the terms to the where-clause object. */
153456 assert( p->pLimit->op==TK_LIMIT );
@@ -154876,11 +154936,11 @@
154876 if( sqlite3ExprIsConstant(pExpr) ){
154877 continue;
154878 }
154879
154880 /* Virtual tables are unable to deal with NULLS FIRST */
154881 if( pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL ) break;
154882
154883 /* First case - a direct column references without a COLLATE operator */
154884 if( pExpr->op==TK_COLUMN && pExpr->iTable==pSrc->iCursor ){
154885 assert( pExpr->iColumn>=XN_ROWID && pExpr->iColumn<pTab->nCol );
154886 continue;
@@ -154988,11 +155048,11 @@
154988 if( sqlite3ExprIsConstant(pExpr) ) continue;
154989 assert( pExpr->op==TK_COLUMN
154990 || (pExpr->op==TK_COLLATE && pExpr->pLeft->op==TK_COLUMN
154991 && pExpr->iColumn==pExpr->pLeft->iColumn) );
154992 pIdxOrderBy[j].iColumn = pExpr->iColumn;
154993 pIdxOrderBy[j].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC;
154994 j++;
154995 }
154996 pIdxInfo->nOrderBy = j;
154997
154998 *pmNoOmit = mNoOmit;
@@ -156506,11 +156566,11 @@
156506 /* tag-20191211-001: Do not allow constraints from the WHERE clause to
156507 ** be used by the right table of a LEFT JOIN nor by the left table of a
156508 ** RIGHT JOIN. Only constraints in the
156509 ** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
156510 if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
156511 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
156512 ){
156513 continue;
156514 }
156515
156516 if( IsUniqueIndex(pProbe) && saved_nEq==pProbe->nKeyCol-1 ){
@@ -157814,13 +157874,11 @@
157814 pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
157815 pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
157816 if( (pItem->fg.jointype & (JT_OUTER|JT_CROSS))!=0 ){
157817 /* This condition is true when pItem is the FROM clause term on the
157818 ** right-hand-side of a OUTER or CROSS JOIN. */
157819 mPrereq = mPrior;
157820 }else{
157821 mPrereq = 0;
157822 }
157823 #ifndef SQLITE_OMIT_VIRTUALTABLE
157824 if( IsVirtual(pItem->pTab) ){
157825 SrcItem *p;
157826 for(p=&pItem[1]; p<pEnd; p++){
@@ -158127,20 +158185,22 @@
158127 }
158128 if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
158129 /* Make sure the sort order is compatible in an ORDER BY clause.
158130 ** Sort order is irrelevant for a GROUP BY clause. */
158131 if( revSet ){
158132 if( (rev ^ revIdx)!=(pOrderBy->a[i].sortFlags&KEYINFO_ORDER_DESC) ){
 
 
158133 isMatch = 0;
158134 }
158135 }else{
158136 rev = revIdx ^ (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC);
158137 if( rev ) *pRevMask |= MASKBIT(iLoop);
158138 revSet = 1;
158139 }
158140 }
158141 if( isMatch && (pOrderBy->a[i].sortFlags & KEYINFO_ORDER_BIGNULL) ){
158142 if( j==pLoop->u.btree.nEq ){
158143 pLoop->wsFlags |= WHERE_BIGNULL_SORT;
158144 }else{
158145 isMatch = 0;
158146 }
@@ -160900,11 +160960,11 @@
160900 pSub->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse);
160901 pSub->u.zToken = 0;
160902 }
160903 }
160904 pList = sqlite3ExprListAppend(pParse, pList, pDup);
160905 if( pList ) pList->a[nInit+i].sortFlags = pAppend->a[i].sortFlags;
160906 }
160907 }
160908 return pList;
160909 }
160910
@@ -162101,11 +162161,11 @@
162101 windowReadPeerValues(p, csr1, reg1);
162102 windowReadPeerValues(p, csr2, reg2);
162103
162104 assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
162105 assert( pOrderBy && pOrderBy->nExpr==1 );
162106 if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_DESC ){
162107 switch( op ){
162108 case OP_Ge: op = OP_Le; break;
162109 case OP_Gt: op = OP_Lt; break;
162110 default: assert( op==OP_Le ); op = OP_Ge; break;
162111 }
@@ -162134,11 +162194,11 @@
162134 ** }
162135 **
162136 ** Additionally, if either reg1 or reg2 are NULL but the jump to lbl is
162137 ** not taken, control jumps over the comparison operator coded below this
162138 ** block. */
162139 if( pOrderBy->a[0].sortFlags & KEYINFO_ORDER_BIGNULL ){
162140 /* This block runs if reg1 contains a NULL. */
162141 int addr = sqlite3VdbeAddOp1(v, OP_NotNull, reg1); VdbeCoverage(v);
162142 switch( op ){
162143 case OP_Ge:
162144 sqlite3VdbeAddOp2(v, OP_Goto, 0, lbl);
@@ -236235,11 +236295,11 @@
236235 int nArg, /* Number of args */
236236 sqlite3_value **apUnused /* Function arguments */
236237 ){
236238 assert( nArg==0 );
236239 UNUSED_PARAM2(nArg, apUnused);
236240 sqlite3_result_text(pCtx, "fts5: 2022-05-03 14:01:48 6eda9b1a7784cf6d58c8876551f67ab98e78a08e726a0579d4def5ba881985bb", -1, SQLITE_TRANSIENT);
236241 }
236242
236243 /*
236244 ** Return true if zName is the extension on one of the shadow tables used
236245 ** by this module.
236246
--- 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 **
@@ -17400,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
@@ -18273,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;
@@ -31850,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 }
@@ -101539,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 }
@@ -101768,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 ){
@@ -101992,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 );
@@ -102745,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 }
@@ -102866,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;
@@ -102881,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);
@@ -102934,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 }
@@ -105186,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
@@ -105491,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 /*
@@ -105526,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. */
@@ -105561,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 /*
@@ -108387,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);
@@ -108410,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 }
@@ -108544,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 ){
@@ -109169,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
@@ -110858,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 */
@@ -110907,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 }
@@ -111065,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 }
@@ -116948,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");
@@ -117442,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 ){
@@ -118930,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 }
@@ -119284,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
@@ -135062,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. */
@@ -135236,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;
@@ -135787,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
@@ -136455,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
@@ -136515,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;
@@ -136646,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 }
@@ -137008,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
@@ -137147,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 ){
@@ -137184,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;
@@ -137550,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;
@@ -137636,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;
@@ -137672,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 }
@@ -137683,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 ){
@@ -137941,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 }
@@ -140547,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.
@@ -141254,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
@@ -141274,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;
@@ -141292,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
@@ -141313,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. */
@@ -141328,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 ){
@@ -141361,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 ){
@@ -142495,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.
@@ -142653,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 }
@@ -144309,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 }
@@ -146891,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 */
@@ -151555,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) ){
@@ -153446,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 );
@@ -154876,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;
@@ -154988,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;
@@ -156506,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 ){
@@ -157814,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++){
@@ -158127,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 }
@@ -160900,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
@@ -162101,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 }
@@ -162134,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);
@@ -236235,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-05-03 14:01:48 6eda9b1a7784cf6d58c8876551f67ab98e78a08e726a0579d4def5ba881985bb"
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-05-03 14:01:48 6eda9b1a7784cf6d58c8876551f67ab98e78a08e726a0579d4def5ba881985bb"
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

Keyboard Shortcuts

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