From 3ec55f548b00f950ec1a9c3d5d57a547b07836c7 Mon Sep 17 00:00:00 2001 From: "D. Richard Hipp" Date: Fri, 17 Nov 2017 17:32:40 +0000 Subject: [PATCH] New assert() statements in the rowvalue IN expression processing. --- src/wherecode.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/wherecode.c b/src/wherecode.c index da5c686a95..cc2759eeaf 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -377,6 +377,27 @@ static void updateRangeAffinityStr( } } +#ifdef SQLITE_DEBUG +/* Return true if the pSub ExprList is a subset of pMain. The terms +** of pSub can be in a different order from pMain. The only requirement +** is that every term in pSub must exist somewhere in pMain. +** +** Return false if pSub contains any term that is not found in pMain. +*/ +static int exprListSubset(ExprList *pSub, ExprList *pMain){ + int i, j; + for(i=0; inExpr; i++){ + Expr *p = pSub->a[i].pExpr; + for(j=0; jnExpr; j++){ + if( sqlite3ExprCompare(0, p, pMain->a[j].pExpr, 0)==0 ) break; + } + if( j>=pMain->nExpr ) return 0; + } + return 1; +} +#endif /* SQLITE_DEBUG */ + + /* ** Generate code for a single equality term of the WHERE clause. An equality ** term can be either X=expr or X IN (...). pTerm is the term to be @@ -463,6 +484,14 @@ static int codeEqualityTerm( pLhs = sqlite3ExprListAppend(pParse, pLhs, pNewLhs); } } + + /* pRhs should be a subset of pOrigRhs (though possibly in a different + ** order). And pLhs should be a subset of pOrigLhs. To put it + ** another way: Every term of pRhs should exist in pOrigRhs and + ** every term of pLhs should exist in pOrigLhs. */ + assert( db->mallocFailed || exprListSubset(pRhs, pOrigRhs) ); + assert( db->mallocFailed || exprListSubset(pLhs, pOrigLhs) ); + if( !db->mallocFailed ){ Expr *pLeft = pX->pLeft; -- 2.11.4.GIT