mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-11 01:42:22 +03:00
Fix the count-of-view optimization so that it is (correctly) disabled for
a query that includes a WHERE clause or a GROUP BY clause. FossilOrigin-Name: 05897ca48a40c6771ff83ba8ecc3a5c60dafddf58651c222dd8cf89b9fc7b077
This commit is contained in:
@@ -5508,7 +5508,8 @@ static struct SrcList_item *isSelfJoinView(
|
||||
** * The subquery is a UNION ALL of two or more terms
|
||||
** * The subquery does not have a LIMIT clause
|
||||
** * There is no WHERE or GROUP BY or HAVING clauses on the subqueries
|
||||
** * The outer query is a simple count(*)
|
||||
** * The outer query is a simple count(*) with no WHERE clause or other
|
||||
** extraneous syntax.
|
||||
**
|
||||
** Return TRUE if the optimization is undertaken.
|
||||
*/
|
||||
@@ -5519,6 +5520,8 @@ static int countOfViewOptimization(Parse *pParse, Select *p){
|
||||
sqlite3 *db;
|
||||
if( (p->selFlags & SF_Aggregate)==0 ) return 0; /* This is an aggregate */
|
||||
if( p->pEList->nExpr!=1 ) return 0; /* Single result column */
|
||||
if( p->pWhere ) return 0;
|
||||
if( p->pGroupBy ) return 0;
|
||||
pExpr = p->pEList->a[0].pExpr;
|
||||
if( pExpr->op!=TK_AGG_FUNCTION ) return 0; /* Result is an aggregate */
|
||||
if( sqlite3_stricmp(pExpr->u.zToken,"count") ) return 0; /* Is count() */
|
||||
|
||||
Reference in New Issue
Block a user