1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Constant propagation is now restricted to just the WHERE clause. The

mechanism is changed to take affinity and collation into account.  This
seems to give correct answers.  But the search for constant propagation
costs 4 million cycles in the speed test.

FossilOrigin-Name: 82c67efb723dba387964f690cd459b420e59e3367d9589016597a76531596391
This commit is contained in:
drh
2018-07-27 16:57:11 +00:00
parent 7de7602eb7
commit efad2e2366
8 changed files with 94 additions and 41 deletions

View File

@@ -328,6 +328,15 @@ CollSeq *sqlite3BinaryCompareCollSeq(
return pColl;
}
/*
** Return true if CollSeq is the default built-in BINARY.
*/
int sqlite3IsBinary(const CollSeq *p){
if( p==0 ) return 1;
if( sqlite3_stricmp(p->zName,"BINARY")==0 ) return 1;
return 0;
}
/*
** Generate code for a comparison operator.
*/
@@ -1839,6 +1848,9 @@ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
testcase( pExpr->op==TK_COLUMN );
testcase( pExpr->op==TK_AGG_FUNCTION );
testcase( pExpr->op==TK_AGG_COLUMN );
if( ExprHasProperty(pExpr, EP_FixedCol) ){
return WRC_Continue;
}
if( pWalker->eCode==3 && pExpr->iTable==pWalker->u.iCur ){
return WRC_Continue;
}
@@ -1927,7 +1939,7 @@ static int exprNodeIsConstantOrGroupBy(Walker *pWalker, Expr *pExpr){
Expr *p = pGroupBy->a[i].pExpr;
if( sqlite3ExprCompare(0, pExpr, p, -1)<2 ){
CollSeq *pColl = sqlite3ExprNNCollSeq(pWalker->pParse, p);
if( sqlite3_stricmp("BINARY", pColl->zName)==0 ){
if( sqlite3IsBinary(pColl) ){
return WRC_Prune;
}
}
@@ -3581,6 +3593,10 @@ expr_code_doover:
}
case TK_COLUMN: {
int iTab = pExpr->iTable;
if( ExprHasProperty(pExpr, EP_FixedCol) ){
pExpr = pExpr->pLeft;
goto expr_code_doover;
}
if( iTab<0 ){
if( pParse->iSelfTab<0 ){
/* Generating CHECK constraints or inserting into partial index */
@@ -4935,14 +4951,15 @@ int sqlite3ExprCompare(Parse *pParse, Expr *pA, Expr *pB, int iTab){
if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
}else if( pA->op==TK_COLLATE ){
if( sqlite3_stricmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
}else if( pA->op!=TK_UPLUS && strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
}else if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
return 2;
}
}
if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
if( ALWAYS((combinedFlags & EP_TokenOnly)==0) ){
if( combinedFlags & EP_xIsSelect ) return 2;
if( sqlite3ExprCompare(pParse, pA->pLeft, pB->pLeft, iTab) ) return 2;
if( (combinedFlags & EP_FixedCol)==0
&& sqlite3ExprCompare(pParse, pA->pLeft, pB->pLeft, iTab) ) return 2;
if( sqlite3ExprCompare(pParse, pA->pRight, pB->pRight, iTab) ) return 2;
if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
assert( (combinedFlags & EP_Reduced)==0 );