| | @@ -456,11 +456,11 @@ |
| 456 | 456 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 457 | 457 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 458 | 458 | */ |
| 459 | 459 | #define SQLITE_VERSION "3.42.0" |
| 460 | 460 | #define SQLITE_VERSION_NUMBER 3042000 |
| 461 | | -#define SQLITE_SOURCE_ID "2023-05-05 14:16:31 fece588b186c4f9f76d626313e35336fd5681e966e9bd0fa1053b147c4e3c315" |
| 461 | +#define SQLITE_SOURCE_ID "2023-05-12 10:52:12 469718f106e1cfa7f8f4714a9e743108c361af81e0258061c2b76880a7c352ae" |
| 462 | 462 | |
| 463 | 463 | /* |
| 464 | 464 | ** CAPI3REF: Run-Time Library Version Numbers |
| 465 | 465 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 466 | 466 | ** |
| | @@ -20506,11 +20506,11 @@ |
| 20506 | 20506 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*); |
| 20507 | 20507 | SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*); |
| 20508 | 20508 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8); |
| 20509 | 20509 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*); |
| 20510 | 20510 | SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int); |
| 20511 | | -SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr*,const SrcItem*); |
| 20511 | +SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr*,const SrcItem*); |
| 20512 | 20512 | #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 20513 | 20513 | SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*); |
| 20514 | 20514 | #endif |
| 20515 | 20515 | SQLITE_PRIVATE int sqlite3ExprIsInteger(const Expr*, int*); |
| 20516 | 20516 | SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); |
| | @@ -30763,11 +30763,11 @@ |
| 30763 | 30763 | nsd = 16 + flag_altform2*10; |
| 30764 | 30764 | bufpt = buf; |
| 30765 | 30765 | { |
| 30766 | 30766 | i64 szBufNeeded; /* Size of a temporary buffer needed */ |
| 30767 | 30767 | szBufNeeded = MAX(e2,0)+(i64)precision+(i64)width+15; |
| 30768 | | - if( cThousand ) szBufNeeded += (e2+2)/3; |
| 30768 | + if( cThousand && e2>0 ) szBufNeeded += (e2+2)/3; |
| 30769 | 30769 | if( szBufNeeded > etBUFSIZE ){ |
| 30770 | 30770 | bufpt = zExtra = printfTempBuf(pAccum, szBufNeeded); |
| 30771 | 30771 | if( bufpt==0 ) return; |
| 30772 | 30772 | } |
| 30773 | 30773 | } |
| | @@ -63217,17 +63217,19 @@ |
| 63217 | 63217 | ** Attempt to take an exclusive lock on the database file. If a PENDING lock |
| 63218 | 63218 | ** is obtained instead, immediately release it. |
| 63219 | 63219 | */ |
| 63220 | 63220 | static int pagerExclusiveLock(Pager *pPager){ |
| 63221 | 63221 | int rc; /* Return code */ |
| 63222 | + u8 eOrigLock; /* Original lock */ |
| 63222 | 63223 | |
| 63223 | | - assert( pPager->eLock==SHARED_LOCK || pPager->eLock==EXCLUSIVE_LOCK ); |
| 63224 | + assert( pPager->eLock>=SHARED_LOCK ); |
| 63225 | + eOrigLock = pPager->eLock; |
| 63224 | 63226 | rc = pagerLockDb(pPager, EXCLUSIVE_LOCK); |
| 63225 | 63227 | if( rc!=SQLITE_OK ){ |
| 63226 | 63228 | /* If the attempt to grab the exclusive lock failed, release the |
| 63227 | 63229 | ** pending lock that may have been obtained instead. */ |
| 63228 | | - pagerUnlockDb(pPager, SHARED_LOCK); |
| 63230 | + pagerUnlockDb(pPager, eOrigLock); |
| 63229 | 63231 | } |
| 63230 | 63232 | |
| 63231 | 63233 | return rc; |
| 63232 | 63234 | } |
| 63233 | 63235 | |
| | @@ -76408,11 +76410,11 @@ |
| 76408 | 76410 | int nTail = pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray); |
| 76409 | 76411 | assert( nCell>=nTail ); |
| 76410 | 76412 | nCell -= nTail; |
| 76411 | 76413 | } |
| 76412 | 76414 | |
| 76413 | | - pData = &aData[get2byteNotZero(&aData[hdr+5])]; |
| 76415 | + pData = &aData[get2byte(&aData[hdr+5])]; |
| 76414 | 76416 | if( pData<pBegin ) goto editpage_fail; |
| 76415 | 76417 | if( NEVER(pData>pPg->aDataEnd) ) goto editpage_fail; |
| 76416 | 76418 | |
| 76417 | 76419 | /* Add cells to the start of the page */ |
| 76418 | 76420 | if( iNew<iOld ){ |
| | @@ -93137,11 +93139,11 @@ |
| 93137 | 93139 | } |
| 93138 | 93140 | |
| 93139 | 93141 | /* Opcode: Jump P1 P2 P3 * * |
| 93140 | 93142 | ** |
| 93141 | 93143 | ** Jump to the instruction at address P1, P2, or P3 depending on whether |
| 93142 | | -** in the most recent OP_Compare instruction the P1 vector was less than |
| 93144 | +** in the most recent OP_Compare instruction the P1 vector was less than, |
| 93143 | 93145 | ** equal to, or greater than the P2 vector, respectively. |
| 93144 | 93146 | ** |
| 93145 | 93147 | ** This opcode must immediately follow an OP_Compare opcode. |
| 93146 | 93148 | */ |
| 93147 | 93149 | case OP_Jump: { /* jump */ |
| | @@ -99991,11 +99993,11 @@ |
| 99991 | 99993 | *ppBlob = (sqlite3_blob *)pBlob; |
| 99992 | 99994 | }else{ |
| 99993 | 99995 | if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt); |
| 99994 | 99996 | sqlite3DbFree(db, pBlob); |
| 99995 | 99997 | } |
| 99996 | | - sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr); |
| 99998 | + sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : (char*)0), zErr); |
| 99997 | 99999 | sqlite3DbFree(db, zErr); |
| 99998 | 100000 | sqlite3ParseObjectReset(&sParse); |
| 99999 | 100001 | rc = sqlite3ApiExit(db, rc); |
| 100000 | 100002 | sqlite3_mutex_leave(db->mutex); |
| 100001 | 100003 | return rc; |
| | @@ -100150,11 +100152,11 @@ |
| 100150 | 100152 | }else{ |
| 100151 | 100153 | char *zErr; |
| 100152 | 100154 | ((Vdbe*)p->pStmt)->rc = SQLITE_OK; |
| 100153 | 100155 | rc = blobSeekToRow(p, iRow, &zErr); |
| 100154 | 100156 | if( rc!=SQLITE_OK ){ |
| 100155 | | - sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr); |
| 100157 | + sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : (char*)0), zErr); |
| 100156 | 100158 | sqlite3DbFree(db, zErr); |
| 100157 | 100159 | } |
| 100158 | 100160 | assert( rc!=SQLITE_SCHEMA ); |
| 100159 | 100161 | } |
| 100160 | 100162 | |
| | @@ -108613,16 +108615,20 @@ |
| 108613 | 108615 | SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){ |
| 108614 | 108616 | return exprIsConst(p, 3, iCur); |
| 108615 | 108617 | } |
| 108616 | 108618 | |
| 108617 | 108619 | /* |
| 108618 | | -** Check pExpr to see if it is an invariant constraint on data source pSrc. |
| 108620 | +** Check pExpr to see if it is an constraint on the single data source pSrc. |
| 108621 | +** In other words, check to see if pExpr constrains pSrc but does not depend |
| 108622 | +** on any other tables or data sources anywhere else in the query. Return |
| 108623 | +** true (non-zero) if pExpr is a constraint on pSrc only. |
| 108624 | +** |
| 108619 | 108625 | ** This is an optimization. False negatives will perhaps cause slower |
| 108620 | 108626 | ** queries, but false positives will yield incorrect answers. So when in |
| 108621 | 108627 | ** doubt, return 0. |
| 108622 | 108628 | ** |
| 108623 | | -** To be an invariant constraint, the following must be true: |
| 108629 | +** To be an single-source constraint, the following must be true: |
| 108624 | 108630 | ** |
| 108625 | 108631 | ** (1) pExpr cannot refer to any table other than pSrc->iCursor. |
| 108626 | 108632 | ** |
| 108627 | 108633 | ** (2) pExpr cannot use subqueries or non-deterministic functions. |
| 108628 | 108634 | ** |
| | @@ -108635,11 +108641,11 @@ |
| 108635 | 108641 | ** |
| 108636 | 108642 | ** (5) If pSrc is not the right operand of a LEFT JOIN or the left |
| 108637 | 108643 | ** operand of a RIGHT JOIN, then pExpr must be from the WHERE |
| 108638 | 108644 | ** clause, not an ON clause. |
| 108639 | 108645 | */ |
| 108640 | | -SQLITE_PRIVATE int sqlite3ExprIsTableConstraint(Expr *pExpr, const SrcItem *pSrc){ |
| 108646 | +SQLITE_PRIVATE int sqlite3ExprIsSingleTableConstraint(Expr *pExpr, const SrcItem *pSrc){ |
| 108641 | 108647 | if( pSrc->fg.jointype & JT_LTORJ ){ |
| 108642 | 108648 | return 0; /* rule (3) */ |
| 108643 | 108649 | } |
| 108644 | 108650 | if( pSrc->fg.jointype & JT_LEFT ){ |
| 108645 | 108651 | if( !ExprHasProperty(pExpr, EP_OuterON) ) return 0; /* rule (4a) */ |
| | @@ -124015,10 +124021,11 @@ |
| 124015 | 124021 | db->enc = enc; |
| 124016 | 124022 | /* EVIDENCE-OF: R-08308-17224 The default collating function for all |
| 124017 | 124023 | ** strings is BINARY. |
| 124018 | 124024 | */ |
| 124019 | 124025 | db->pDfltColl = sqlite3FindCollSeq(db, enc, sqlite3StrBINARY, 0); |
| 124026 | + sqlite3ExpirePreparedStatements(db, 1); |
| 124020 | 124027 | } |
| 124021 | 124028 | |
| 124022 | 124029 | /* |
| 124023 | 124030 | ** This function is responsible for invoking the collation factory callback |
| 124024 | 124031 | ** or substituting a collation sequence of a different encoding when the |
| | @@ -144061,25 +144068,49 @@ |
| 144061 | 144068 | ** |
| 144062 | 144069 | ** (8) If the subquery is a compound that uses UNION, INTERSECT, |
| 144063 | 144070 | ** or EXCEPT, then all of the result set columns for all arms of |
| 144064 | 144071 | ** the compound must use the BINARY collating sequence. |
| 144065 | 144072 | ** |
| 144073 | +** (9) All three of the following are true: |
| 144074 | +** |
| 144075 | +** (9a) The WHERE clause expression originates in the ON or USING clause |
| 144076 | +** of a join (either an INNER or an OUTER join), and |
| 144077 | +** |
| 144078 | +** (9b) The subquery is to the right of the ON/USING clause |
| 144079 | +** |
| 144080 | +** (9c) There is a RIGHT JOIN (or FULL JOIN) in between the ON/USING |
| 144081 | +** clause and the subquery. |
| 144082 | +** |
| 144083 | +** Without this restriction, the push-down optimization might move |
| 144084 | +** the ON/USING filter expression from the left side of a RIGHT JOIN |
| 144085 | +** over to the right side, which leads to incorrect answers. |
| 144086 | +** |
| 144087 | +** (10) The inner query is not the right-hand table of a RIGHT JOIN. |
| 144088 | +** |
| 144089 | +** (11) The subquery is not a VALUES clause |
| 144066 | 144090 | ** |
| 144067 | 144091 | ** Return 0 if no changes are made and non-zero if one or more WHERE clause |
| 144068 | 144092 | ** terms are duplicated into the subquery. |
| 144069 | 144093 | */ |
| 144070 | 144094 | static int pushDownWhereTerms( |
| 144071 | 144095 | Parse *pParse, /* Parse context (for malloc() and error reporting) */ |
| 144072 | 144096 | Select *pSubq, /* The subquery whose WHERE clause is to be augmented */ |
| 144073 | 144097 | Expr *pWhere, /* The WHERE clause of the outer query */ |
| 144074 | | - SrcItem *pSrc /* The subquery term of the outer FROM clause */ |
| 144098 | + SrcList *pSrcList, /* The complete from clause of the outer query */ |
| 144099 | + int iSrc /* Which FROM clause term to try to push into */ |
| 144075 | 144100 | ){ |
| 144076 | 144101 | Expr *pNew; |
| 144102 | + SrcItem *pSrc; /* The subquery FROM term into which WHERE is pushed */ |
| 144077 | 144103 | int nChng = 0; |
| 144104 | + pSrc = &pSrcList->a[iSrc]; |
| 144078 | 144105 | if( pWhere==0 ) return 0; |
| 144079 | | - if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ) return 0; |
| 144080 | | - if( pSrc->fg.jointype & (JT_LTORJ|JT_RIGHT) ) return 0; |
| 144106 | + if( pSubq->selFlags & (SF_Recursive|SF_MultiPart) ){ |
| 144107 | + return 0; /* restrictions (2) and (11) */ |
| 144108 | + } |
| 144109 | + if( pSrc->fg.jointype & (JT_LTORJ|JT_RIGHT) ){ |
| 144110 | + return 0; /* restrictions (10) */ |
| 144111 | + } |
| 144081 | 144112 | |
| 144082 | 144113 | if( pSubq->pPrior ){ |
| 144083 | 144114 | Select *pSel; |
| 144084 | 144115 | int notUnionAll = 0; |
| 144085 | 144116 | for(pSel=pSubq; pSel; pSel=pSel->pPrior){ |
| | @@ -144130,15 +144161,33 @@ |
| 144130 | 144161 | |
| 144131 | 144162 | if( pSubq->pLimit!=0 ){ |
| 144132 | 144163 | return 0; /* restriction (3) */ |
| 144133 | 144164 | } |
| 144134 | 144165 | while( pWhere->op==TK_AND ){ |
| 144135 | | - nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, pSrc); |
| 144166 | + nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, pSrcList, iSrc); |
| 144136 | 144167 | pWhere = pWhere->pLeft; |
| 144137 | 144168 | } |
| 144138 | 144169 | |
| 144139 | | -#if 0 /* Legacy code. Checks now done by sqlite3ExprIsTableConstraint() */ |
| 144170 | + if( ExprHasProperty(pWhere, EP_OuterON|EP_InnerON) /* (9a) */ |
| 144171 | + && (pSrcList->a[0].fg.jointype & JT_LTORJ)!=0 /* Fast pre-test of (9c) */ |
| 144172 | + ){ |
| 144173 | + int jj; |
| 144174 | + for(jj=0; jj<iSrc; jj++){ |
| 144175 | + if( pWhere->w.iJoin==pSrcList->a[jj].iCursor ){ |
| 144176 | + /* If we reach this point, both (9a) and (9b) are satisfied. |
| 144177 | + ** The following loop checks (9c): |
| 144178 | + */ |
| 144179 | + for(jj++; jj<iSrc; jj++){ |
| 144180 | + if( (pSrcList->a[jj].fg.jointype & JT_RIGHT)!=0 ){ |
| 144181 | + return 0; /* restriction (9) */ |
| 144182 | + } |
| 144183 | + } |
| 144184 | + } |
| 144185 | + } |
| 144186 | + } |
| 144187 | + |
| 144188 | +#if 0 /* These checks now done by sqlite3ExprIsSingleTableConstraint() */ |
| 144140 | 144189 | if( isLeftJoin |
| 144141 | 144190 | && (ExprHasProperty(pWhere,EP_OuterON)==0 |
| 144142 | 144191 | || pWhere->w.iJoin!=iCursor) |
| 144143 | 144192 | ){ |
| 144144 | 144193 | return 0; /* restriction (4) */ |
| | @@ -144148,11 +144197,11 @@ |
| 144148 | 144197 | ){ |
| 144149 | 144198 | return 0; /* restriction (5) */ |
| 144150 | 144199 | } |
| 144151 | 144200 | #endif |
| 144152 | 144201 | |
| 144153 | | - if( sqlite3ExprIsTableConstraint(pWhere, pSrc) ){ |
| 144202 | + if( sqlite3ExprIsSingleTableConstraint(pWhere, pSrc) ){ |
| 144154 | 144203 | nChng++; |
| 144155 | 144204 | pSubq->selFlags |= SF_PushDown; |
| 144156 | 144205 | while( pSubq ){ |
| 144157 | 144206 | SubstContext x; |
| 144158 | 144207 | pNew = sqlite3ExprDup(pParse->db, pWhere, 0); |
| | @@ -146146,11 +146195,11 @@ |
| 146146 | 146195 | assert( pItem->iCursor>=0 ); |
| 146147 | 146196 | unsetJoinExpr(p->pWhere, pItem->iCursor, |
| 146148 | 146197 | pTabList->a[0].fg.jointype & JT_LTORJ); |
| 146149 | 146198 | } |
| 146150 | 146199 | |
| 146151 | | - /* No futher action if this term of the FROM clause is no a subquery */ |
| 146200 | + /* No futher action if this term of the FROM clause is not a subquery */ |
| 146152 | 146201 | if( pSub==0 ) continue; |
| 146153 | 146202 | |
| 146154 | 146203 | /* Catch mismatch in the declared columns of a view and the number of |
| 146155 | 146204 | ** columns in the SELECT on the RHS */ |
| 146156 | 146205 | if( pTab->nCol!=pSub->pEList->nExpr ){ |
| | @@ -146343,11 +146392,11 @@ |
| 146343 | 146392 | ** inside the subquery. This can help the subquery to run more efficiently. |
| 146344 | 146393 | */ |
| 146345 | 146394 | if( OptimizationEnabled(db, SQLITE_PushDown) |
| 146346 | 146395 | && (pItem->fg.isCte==0 |
| 146347 | 146396 | || (pItem->u2.pCteUse->eM10d!=M10d_Yes && pItem->u2.pCteUse->nUse<2)) |
| 146348 | | - && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem) |
| 146397 | + && pushDownWhereTerms(pParse, pSub, p->pWhere, pTabList, i) |
| 146349 | 146398 | ){ |
| 146350 | 146399 | #if TREETRACE_ENABLED |
| 146351 | 146400 | if( sqlite3TreeTrace & 0x4000 ){ |
| 146352 | 146401 | TREETRACE(0x4000,pParse,p, |
| 146353 | 146402 | ("After WHERE-clause push-down into subquery %d:\n", pSub->selId)); |
| | @@ -158620,11 +158669,11 @@ |
| 158620 | 158669 | Expr *pExpr = pTerm->pExpr; |
| 158621 | 158670 | /* Make the automatic index a partial index if there are terms in the |
| 158622 | 158671 | ** WHERE clause (or the ON clause of a LEFT join) that constrain which |
| 158623 | 158672 | ** rows of the target table (pSrc) that can be used. */ |
| 158624 | 158673 | if( (pTerm->wtFlags & TERM_VIRTUAL)==0 |
| 158625 | | - && sqlite3ExprIsTableConstraint(pExpr, pSrc) |
| 158674 | + && sqlite3ExprIsSingleTableConstraint(pExpr, pSrc) |
| 158626 | 158675 | ){ |
| 158627 | 158676 | pPartial = sqlite3ExprAnd(pParse, pPartial, |
| 158628 | 158677 | sqlite3ExprDup(pParse->db, pExpr, 0)); |
| 158629 | 158678 | } |
| 158630 | 158679 | if( termCanDriveIndex(pTerm, pSrc, notReady) ){ |
| | @@ -158881,11 +158930,11 @@ |
| 158881 | 158930 | addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, iCur); VdbeCoverage(v); |
| 158882 | 158931 | pWCEnd = &pWInfo->sWC.a[pWInfo->sWC.nTerm]; |
| 158883 | 158932 | for(pTerm=pWInfo->sWC.a; pTerm<pWCEnd; pTerm++){ |
| 158884 | 158933 | Expr *pExpr = pTerm->pExpr; |
| 158885 | 158934 | if( (pTerm->wtFlags & TERM_VIRTUAL)==0 |
| 158886 | | - && sqlite3ExprIsTableConstraint(pExpr, pItem) |
| 158935 | + && sqlite3ExprIsSingleTableConstraint(pExpr, pItem) |
| 158887 | 158936 | ){ |
| 158888 | 158937 | sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL); |
| 158889 | 158938 | } |
| 158890 | 158939 | } |
| 158891 | 158940 | if( pLoop->wsFlags & WHERE_IPK ){ |
| | @@ -163220,10 +163269,17 @@ |
| 163220 | 163269 | ** 3) Either the query must be DISTINCT, or else the ON or USING clause |
| 163221 | 163270 | ** must contain a constraint that limits the scan of the table to |
| 163222 | 163271 | ** at most a single row. |
| 163223 | 163272 | ** 4) The table must not be referenced by any part of the query apart |
| 163224 | 163273 | ** from its own USING or ON clause. |
| 163274 | +** 5) The table must not have an inner-join ON or USING clause if there is |
| 163275 | +** a RIGHT JOIN anywhere in the query. Otherwise the ON/USING clause |
| 163276 | +** might move from the right side to the left side of the RIGHT JOIN. |
| 163277 | +** Note: Due to (2), this condition can only arise if the table is |
| 163278 | +** the right-most table of a subquery that was flattened into the |
| 163279 | +** main query and that subquery was the right-hand operand of an |
| 163280 | +** inner join that held an ON or USING clause. |
| 163225 | 163281 | ** |
| 163226 | 163282 | ** For example, given: |
| 163227 | 163283 | ** |
| 163228 | 163284 | ** CREATE TABLE t1(ipk INTEGER PRIMARY KEY, v1); |
| 163229 | 163285 | ** CREATE TABLE t2(ipk INTEGER PRIMARY KEY, v2); |
| | @@ -163245,10 +163301,11 @@ |
| 163245 | 163301 | WhereInfo *pWInfo, |
| 163246 | 163302 | Bitmask notReady |
| 163247 | 163303 | ){ |
| 163248 | 163304 | int i; |
| 163249 | 163305 | Bitmask tabUsed; |
| 163306 | + int hasRightJoin; |
| 163250 | 163307 | |
| 163251 | 163308 | /* Preconditions checked by the caller */ |
| 163252 | 163309 | assert( pWInfo->nLevel>=2 ); |
| 163253 | 163310 | assert( OptimizationEnabled(pWInfo->pParse->db, SQLITE_OmitNoopJoin) ); |
| 163254 | 163311 | |
| | @@ -163259,10 +163316,11 @@ |
| 163259 | 163316 | |
| 163260 | 163317 | tabUsed = sqlite3WhereExprListUsage(&pWInfo->sMaskSet, pWInfo->pResultSet); |
| 163261 | 163318 | if( pWInfo->pOrderBy ){ |
| 163262 | 163319 | tabUsed |= sqlite3WhereExprListUsage(&pWInfo->sMaskSet, pWInfo->pOrderBy); |
| 163263 | 163320 | } |
| 163321 | + hasRightJoin = (pWInfo->pTabList->a[0].fg.jointype & JT_LTORJ)!=0; |
| 163264 | 163322 | for(i=pWInfo->nLevel-1; i>=1; i--){ |
| 163265 | 163323 | WhereTerm *pTerm, *pEnd; |
| 163266 | 163324 | SrcItem *pItem; |
| 163267 | 163325 | WhereLoop *pLoop; |
| 163268 | 163326 | pLoop = pWInfo->a[i].pWLoop; |
| | @@ -163281,10 +163339,16 @@ |
| 163281 | 163339 | || pTerm->pExpr->w.iJoin!=pItem->iCursor |
| 163282 | 163340 | ){ |
| 163283 | 163341 | break; |
| 163284 | 163342 | } |
| 163285 | 163343 | } |
| 163344 | + if( hasRightJoin |
| 163345 | + && ExprHasProperty(pTerm->pExpr, EP_InnerON) |
| 163346 | + && pTerm->pExpr->w.iJoin==pItem->iCursor |
| 163347 | + ){ |
| 163348 | + break; /* restriction (5) */ |
| 163349 | + } |
| 163286 | 163350 | } |
| 163287 | 163351 | if( pTerm<pEnd ) continue; |
| 163288 | 163352 | WHERETRACE(0xffffffff, ("-> drop loop %c not used\n", pLoop->cId)); |
| 163289 | 163353 | notReady &= ~pLoop->maskSelf; |
| 163290 | 163354 | for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){ |
| | @@ -199762,14 +199826,14 @@ |
| 199762 | 199826 | |
| 199763 | 199827 | /* |
| 199764 | 199828 | ** Maximum nesting depth of JSON for this implementation. |
| 199765 | 199829 | ** |
| 199766 | 199830 | ** This limit is needed to avoid a stack overflow in the recursive |
| 199767 | | -** descent parser. A depth of 2000 is far deeper than any sane JSON |
| 199768 | | -** should go. |
| 199831 | +** descent parser. A depth of 1000 is far deeper than any sane JSON |
| 199832 | +** should go. Historical note: This limit was 2000 prior to version 3.42.0 |
| 199769 | 199833 | */ |
| 199770 | | -#define JSON_MAX_DEPTH 2000 |
| 199834 | +#define JSON_MAX_DEPTH 1000 |
| 199771 | 199835 | |
| 199772 | 199836 | /************************************************************************** |
| 199773 | 199837 | ** Utility routines for dealing with JsonString objects |
| 199774 | 199838 | **************************************************************************/ |
| 199775 | 199839 | |
| | @@ -200703,10 +200767,11 @@ |
| 200703 | 200767 | if( ++pParse->iDepth > JSON_MAX_DEPTH ){ |
| 200704 | 200768 | pParse->iErr = i; |
| 200705 | 200769 | return -1; |
| 200706 | 200770 | } |
| 200707 | 200771 | for(j=i+1;;j++){ |
| 200772 | + u32 nNode = pParse->nNode; |
| 200708 | 200773 | x = jsonParseValue(pParse, j); |
| 200709 | 200774 | if( x<=0 ){ |
| 200710 | 200775 | if( x==(-2) ){ |
| 200711 | 200776 | j = pParse->iErr; |
| 200712 | 200777 | if( pParse->nNode!=(u32)iThis+1 ) pParse->hasNonstd = 1; |
| | @@ -200729,11 +200794,11 @@ |
| 200729 | 200794 | if( x!=-1 ) pParse->iErr = j; |
| 200730 | 200795 | return -1; |
| 200731 | 200796 | } |
| 200732 | 200797 | } |
| 200733 | 200798 | if( pParse->oom ) return -1; |
| 200734 | | - pNode = &pParse->aNode[pParse->nNode-1]; |
| 200799 | + pNode = &pParse->aNode[nNode]; |
| 200735 | 200800 | if( pNode->eType!=JSON_STRING ){ |
| 200736 | 200801 | pParse->iErr = j; |
| 200737 | 200802 | return -1; |
| 200738 | 200803 | } |
| 200739 | 200804 | pNode->jnFlags |= JNODE_LABEL; |
| | @@ -214042,15 +214107,22 @@ |
| 214042 | 214107 | static int rbuLockDatabase(sqlite3 *db){ |
| 214043 | 214108 | int rc = SQLITE_OK; |
| 214044 | 214109 | sqlite3_file *fd = 0; |
| 214045 | 214110 | |
| 214046 | 214111 | sqlite3_file_control(db, "main", RBU_ZIPVFS_CTRL_FILE_POINTER, &fd); |
| 214047 | | - if( fd==0 ){ |
| 214112 | + if( fd ){ |
| 214113 | + sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &fd); |
| 214114 | + rc = fd->pMethods->xLock(fd, SQLITE_LOCK_SHARED); |
| 214115 | + if( rc==SQLITE_OK ){ |
| 214116 | + rc = fd->pMethods->xUnlock(fd, SQLITE_LOCK_NONE); |
| 214117 | + } |
| 214118 | + sqlite3_file_control(db, "main", RBU_ZIPVFS_CTRL_FILE_POINTER, &fd); |
| 214119 | + }else{ |
| 214048 | 214120 | sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &fd); |
| 214049 | 214121 | } |
| 214050 | 214122 | |
| 214051 | | - if( fd->pMethods ){ |
| 214123 | + if( rc==SQLITE_OK && fd->pMethods ){ |
| 214052 | 214124 | rc = fd->pMethods->xLock(fd, SQLITE_LOCK_SHARED); |
| 214053 | 214125 | if( rc==SQLITE_OK ){ |
| 214054 | 214126 | rc = fd->pMethods->xLock(fd, SQLITE_LOCK_EXCLUSIVE); |
| 214055 | 214127 | } |
| 214056 | 214128 | } |
| | @@ -242473,11 +242545,11 @@ |
| 242473 | 242545 | int nArg, /* Number of args */ |
| 242474 | 242546 | sqlite3_value **apUnused /* Function arguments */ |
| 242475 | 242547 | ){ |
| 242476 | 242548 | assert( nArg==0 ); |
| 242477 | 242549 | UNUSED_PARAM2(nArg, apUnused); |
| 242478 | | - sqlite3_result_text(pCtx, "fts5: 2023-05-05 14:16:31 fece588b186c4f9f76d626313e35336fd5681e966e9bd0fa1053b147c4e3c315", -1, SQLITE_TRANSIENT); |
| 242550 | + sqlite3_result_text(pCtx, "fts5: 2023-05-11 21:15:55 3e9c9bbdb59b9d500ff218db538c047c83da7ac18ebb95c3ee7629ab15e0b43a", -1, SQLITE_TRANSIENT); |
| 242479 | 242551 | } |
| 242480 | 242552 | |
| 242481 | 242553 | /* |
| 242482 | 242554 | ** Return true if zName is the extension on one of the shadow tables used |
| 242483 | 242555 | ** by this module. |
| 242484 | 242556 | |