diff options
author | dan <Dan Kennedy> | 2024-04-20 19:19:30 +0000 |
---|---|---|
committer | dan <Dan Kennedy> | 2024-04-20 19:19:30 +0000 |
commit | 5749e1ee4386a2a6c436dfeb45770f8352abdb65 (patch) | |
tree | 0be014b587b959997f2a5db555e56c636ad9f94c /src | |
parent | d737feeacfdbf6ea5d44e383647ea6ced390c3ab (diff) | |
download | sqlite-5749e1ee4386a2a6c436dfeb45770f8352abdb65.tar.gz sqlite-5749e1ee4386a2a6c436dfeb45770f8352abdb65.zip |
Slight performance improvement for the new code on this branch.
FossilOrigin-Name: 500c67f1341fe2a7e7333d525c90df201cc73a683b943ad5c1e41d4a4f639043
Diffstat (limited to 'src')
-rw-r--r-- | src/where.c | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/where.c b/src/where.c index f6b0990e6..96a6df9de 100644 --- a/src/where.c +++ b/src/where.c @@ -302,15 +302,25 @@ static Expr *whereRightSubexprIsColumn(Expr *p){ return 0; } -static int SQLITE_NOINLINE indexInAffinityOk( +/* +** Term pTerm is guaranteed to be a WO_IN term. It may be a component term +** of a vector IN expression of the form "(x, y, ...) IN (SELECT ...)". +** This function checks to see if the term is compatible with an index +** column with affinity idxaff (one of the SQLITE_AFF_XYZ values). If so, +** it returns a pointer to the name of the collation sequence (e.g. "BINARY" +** or "NOCASE") used by the comparison in pTerm. If it is not compatible +** with affinity idxaff, NULL is returned. +*/ +static SQLITE_NOINLINE const char *indexInAffinityOk( Parse *pParse, WhereTerm *pTerm, - u8 idxaff, - CollSeq **ppColl + u8 idxaff ){ Expr *pX = pTerm->pExpr; Expr inexpr; + assert( pTerm->eOperator & WO_IN ); + if( sqlite3ExprIsVector(pX->pLeft) ){ int iField = pTerm->u.x.iField - 1; inexpr.op = TK_EQ; @@ -320,8 +330,11 @@ static int SQLITE_NOINLINE indexInAffinityOk( pX = &inexpr; } - *ppColl = sqlite3ExprCompareCollSeq(pParse, pX); - return sqlite3IndexAffinityOk(pX, idxaff); + if( sqlite3IndexAffinityOk(pX, idxaff) ){ + CollSeq *pRet = sqlite3ExprCompareCollSeq(pParse, pX); + return pRet ? pRet->zName : sqlite3StrBINARY; + } + return 0; } /* @@ -374,24 +387,24 @@ static WhereTerm *whereScanNext(WhereScan *pScan){ if( (pTerm->eOperator & pScan->opMask)!=0 ){ /* Verify the affinity and collating sequence match */ if( pScan->zCollName && (pTerm->eOperator & WO_ISNULL)==0 ){ - CollSeq *pColl; + const char *zCollName; Parse *pParse = pWC->pWInfo->pParse; pX = pTerm->pExpr; if( (pTerm->eOperator & WO_IN) ){ - if( !indexInAffinityOk(pParse, pTerm, pScan->idxaff, &pColl) ){ - continue; - } + zCollName = indexInAffinityOk(pParse, pTerm, pScan->idxaff); + if( !zCollName ) continue; }else{ + CollSeq *pColl; if( !sqlite3IndexAffinityOk(pX, pScan->idxaff) ){ continue; } assert(pX->pLeft); pColl = sqlite3ExprCompareCollSeq(pParse, pX); + zCollName = pColl ? pColl->zName : sqlite3StrBINARY; } - if( pColl==0 ) pColl = pParse->db->pDfltColl; - if( sqlite3StrICmp(pColl->zName, pScan->zCollName) ){ + if( sqlite3StrICmp(zCollName, pScan->zCollName) ){ continue; } } |