mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-11 01:42:22 +03:00
Remove an incorrect NEVER() reported at
[forum:/forumpost/5bbabfb7ce|forum post 5bbabfb7ce]. Also use this opportunity to improve the isSimpleCount() function with better formatting, an expanded header comment, and some extra assert() and textcase() macros. FossilOrigin-Name: 2927185be81a5aa0dce70dd06040d05c2816a4d18b5094a6f709732cfd6968dc
This commit is contained in:
26
src/select.c
26
src/select.c
@@ -4948,7 +4948,13 @@ static u8 minMaxQuery(sqlite3 *db, Expr *pFunc, ExprList **ppMinMax){
|
||||
**
|
||||
** where table is a database table, not a sub-select or view. If the query
|
||||
** does match this pattern, then a pointer to the Table object representing
|
||||
** <tbl> is returned. Otherwise, 0 is returned.
|
||||
** <tbl> is returned. Otherwise, NULL is returned.
|
||||
**
|
||||
** This routine a condition for the count optimization. A correct answer
|
||||
** is obtained (though perhaps more slowly) if this routine returns NULL when
|
||||
** it could have returned a table pointer. But returning the pointer when
|
||||
** NULL should have been returned can result in incorrect answers and/or
|
||||
** crashes. So, when in doubt, return NULL.
|
||||
*/
|
||||
static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){
|
||||
Table *pTab;
|
||||
@@ -4956,19 +4962,25 @@ static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){
|
||||
|
||||
assert( !p->pGroupBy );
|
||||
|
||||
if( p->pWhere || p->pEList->nExpr!=1
|
||||
|| p->pSrc->nSrc!=1 || p->pSrc->a[0].pSelect
|
||||
if( p->pWhere
|
||||
|| p->pEList->nExpr!=1
|
||||
|| p->pSrc->nSrc!=1
|
||||
|| p->pSrc->a[0].pSelect
|
||||
|| pAggInfo->nFunc!=1
|
||||
){
|
||||
return 0;
|
||||
}
|
||||
pTab = p->pSrc->a[0].pTab;
|
||||
assert( pTab!=0 );
|
||||
assert( !IsView(pTab) );
|
||||
if( !IsOrdinaryTable(pTab) ) return 0;
|
||||
pExpr = p->pEList->a[0].pExpr;
|
||||
assert( pTab && !IsView(pTab) && pExpr );
|
||||
|
||||
if( IsVirtual(pTab) ) return 0;
|
||||
assert( pExpr!=0 );
|
||||
if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
|
||||
if( NEVER(pAggInfo->nFunc==0) ) return 0;
|
||||
if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0;
|
||||
assert( pAggInfo->aFunc[0].pFExpr==pExpr );
|
||||
testcase( ExprHasProperty(pExpr, EP_Distinct) );
|
||||
testcase( ExprHasProperty(pExpr, EP_WinFunc) );
|
||||
if( ExprHasProperty(pExpr, EP_Distinct|EP_WinFunc) ) return 0;
|
||||
|
||||
return pTab;
|
||||
|
||||
Reference in New Issue
Block a user