SQLite

Check-in [2927185b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remove an incorrect NEVER() reported at 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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2927185be81a5aa0dce70dd06040d05c2816a4d18b5094a6f709732cfd6968dc
User & Date: drh 2021-11-05 11:52:33
Context
2021-11-05
12:34
Use the FTS_CORRUPT_VTAB macro rather than a direct call to sqlite3Fts3Corrupt() in [2fad2a89527757b3] so that the build works in all cases. (check-in: 029c59cd user: drh tags: trunk)
11:52
Remove an incorrect NEVER() reported at 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. (check-in: 2927185b user: drh tags: trunk)
11:26
Fix vacuum3.test so that it works with SQLITE_OMIT_ALTERTABLE builds. (check-in: 07cca2fa user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/select.c.
4944
4945
4946
4947
4948
4949
4950
4951






4952
4953
4954
4955
4956
4957
4958
4959

4960


4961
4962
4963
4964
4965
4966
4967
4968


4969
4970
4971



4972
4973
4974
4975
4976
4977
4978
** The second argument is the associated aggregate-info object. This 
** function tests if the SELECT is of the form:
**
**   SELECT count(*) FROM <tbl>
**
** 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.






*/
static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){
  Table *pTab;
  Expr *pExpr;

  assert( !p->pGroupBy );

  if( p->pWhere || p->pEList->nExpr!=1 

   || p->pSrc->nSrc!=1 || p->pSrc->a[0].pSelect


  ){
    return 0;
  }
  pTab = p->pSrc->a[0].pTab;
  pExpr = p->pEList->a[0].pExpr;
  assert( pTab && !IsView(pTab) && pExpr );

  if( IsVirtual(pTab) ) return 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;



  if( ExprHasProperty(pExpr, EP_Distinct|EP_WinFunc) ) return 0;

  return pTab;
}

/*
** If the source-list item passed as an argument was augmented with an







|
>
>
>
>
>
>







|
>
|
>
>




<
|
|
|
>
>

<

>
>
>







4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973

4974
4975
4976
4977
4978
4979

4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
** The second argument is the associated aggregate-info object. This 
** function tests if the SELECT is of the form:
**
**   SELECT count(*) FROM <tbl>
**
** 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, 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;
  Expr *pExpr;

  assert( !p->pGroupBy );

  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( pExpr!=0 );
  if( pExpr->op!=TK_AGG_FUNCTION ) 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;
}

/*
** If the source-list item passed as an argument was augmented with an