mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
When flattening a query of the form "SELECT * FROM (SELECT * FROM tbl WHERE x=?) WHERE y=?", ensure that the final WHERE clause is "x=? AND y=?" instead of "y=? AND x=?". Although it is still not guaranteed, this makes the order in which WHERE clause terms are processed comport more closely to users expectations.
FossilOrigin-Name: cf7f9e6d5abff273dd2f8a8dce27d52e1449b3be
This commit is contained in:
@@ -3695,12 +3695,13 @@ static int flattenSubquery(
|
||||
assert( pParent->pHaving==0 );
|
||||
pParent->pHaving = pParent->pWhere;
|
||||
pParent->pWhere = pWhere;
|
||||
pParent->pHaving = sqlite3ExprAnd(db, pParent->pHaving,
|
||||
sqlite3ExprDup(db, pSub->pHaving, 0));
|
||||
pParent->pHaving = sqlite3ExprAnd(db,
|
||||
sqlite3ExprDup(db, pSub->pHaving, 0), pParent->pHaving
|
||||
);
|
||||
assert( pParent->pGroupBy==0 );
|
||||
pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
|
||||
}else{
|
||||
pParent->pWhere = sqlite3ExprAnd(db, pParent->pWhere, pWhere);
|
||||
pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere);
|
||||
}
|
||||
substSelect(db, pParent, iParent, pSub->pEList, 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user