mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-11 01:42:22 +03:00
Merge recent changes from trunk.
FossilOrigin-Name: 5962921fceaf2ec645379a5f1d18e2c2c13abbf92cf64606caee69f45a21c500
This commit is contained in:
50
src/select.c
50
src/select.c
@@ -4146,15 +4146,28 @@ struct WhereConst {
|
||||
|
||||
/*
|
||||
** Add a new entry to the pConst object. Except, do not add duplicate
|
||||
** pColumn entires.
|
||||
** pColumn entires. Also, do not add if doing so would not be appropriate.
|
||||
**
|
||||
** The caller guarantees the pColumn is a column and pValue is a constant.
|
||||
** This routine has to do some additional checks before completing the
|
||||
** insert.
|
||||
*/
|
||||
static void constInsert(
|
||||
WhereConst *pConst, /* The WhereConst into which we are inserting */
|
||||
Expr *pColumn, /* The COLUMN part of the constraint */
|
||||
Expr *pValue /* The VALUE part of the constraint */
|
||||
WhereConst *pConst, /* The WhereConst into which we are inserting */
|
||||
Expr *pColumn, /* The COLUMN part of the constraint */
|
||||
Expr *pValue, /* The VALUE part of the constraint */
|
||||
Expr *pExpr /* Overall expression: COLUMN=VALUE or VALUE=COLUMN */
|
||||
){
|
||||
int i;
|
||||
assert( pColumn->op==TK_COLUMN );
|
||||
assert( sqlite3ExprIsConstant(pValue) );
|
||||
|
||||
if( !ExprHasProperty(pValue, EP_FixedCol) && sqlite3ExprAffinity(pValue)!=0 ){
|
||||
return;
|
||||
}
|
||||
if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) ){
|
||||
return;
|
||||
}
|
||||
|
||||
/* 2018-10-25 ticket [cf5ed20f]
|
||||
** Make sure the same pColumn is not inserted more than once */
|
||||
@@ -4174,7 +4187,9 @@ static void constInsert(
|
||||
if( pConst->apExpr==0 ){
|
||||
pConst->nConst = 0;
|
||||
}else{
|
||||
if( ExprHasProperty(pValue, EP_FixedCol) ) pValue = pValue->pLeft;
|
||||
if( ExprHasProperty(pValue, EP_FixedCol) ){
|
||||
pValue = pValue->pLeft;
|
||||
}
|
||||
pConst->apExpr[pConst->nConst*2-2] = pColumn;
|
||||
pConst->apExpr[pConst->nConst*2-1] = pValue;
|
||||
}
|
||||
@@ -4200,19 +4215,11 @@ static void findConstInWhere(WhereConst *pConst, Expr *pExpr){
|
||||
pLeft = pExpr->pLeft;
|
||||
assert( pRight!=0 );
|
||||
assert( pLeft!=0 );
|
||||
if( pRight->op==TK_COLUMN
|
||||
&& !ExprHasProperty(pRight, EP_FixedCol)
|
||||
&& sqlite3ExprIsConstant(pLeft)
|
||||
&& sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr))
|
||||
){
|
||||
constInsert(pConst, pRight, pLeft);
|
||||
}else
|
||||
if( pLeft->op==TK_COLUMN
|
||||
&& !ExprHasProperty(pLeft, EP_FixedCol)
|
||||
&& sqlite3ExprIsConstant(pRight)
|
||||
&& sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr))
|
||||
){
|
||||
constInsert(pConst, pLeft, pRight);
|
||||
if( pRight->op==TK_COLUMN && sqlite3ExprIsConstant(pLeft) ){
|
||||
constInsert(pConst,pRight,pLeft,pExpr);
|
||||
}
|
||||
if( pLeft->op==TK_COLUMN && sqlite3ExprIsConstant(pRight) ){
|
||||
constInsert(pConst,pLeft,pRight,pExpr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4248,10 +4255,9 @@ static int propagateConstantExprRewrite(Walker *pWalker, Expr *pExpr){
|
||||
** The WHERE-clause constant propagation optimization.
|
||||
**
|
||||
** If the WHERE clause contains terms of the form COLUMN=CONSTANT or
|
||||
** CONSTANT=COLUMN that must be tree (in other words, if the terms top-level
|
||||
** AND-connected terms that are not part of a ON clause from a LEFT JOIN)
|
||||
** then throughout the query replace all other occurrences of COLUMN
|
||||
** with CONSTANT within the WHERE clause.
|
||||
** CONSTANT=COLUMN that are top-level AND-connected terms that are not
|
||||
** part of a ON clause from a LEFT JOIN, then throughout the query
|
||||
** replace all other occurrences of COLUMN with CONSTANT.
|
||||
**
|
||||
** For example, the query:
|
||||
**
|
||||
|
||||
Reference in New Issue
Block a user