/ Check-in [94ac51cc]
Login

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

Overview
Comment:Remove incorrect ALWAYS() macros from the window function logic.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 94ac51cc4e7fdf484214e1936fc96104b96134632a8eb99558b3af743ac8bb8b
User & Date: drh 2018-07-10 23:31:17
Context
2018-07-11
03:27
Adjustments to VdbeCoverage macros to deal with byte-code branches that can never be taken in some directions. check-in: b170c009 user: drh tags: trunk
2018-07-10
23:31
Remove incorrect ALWAYS() macros from the window function logic. check-in: 94ac51cc user: drh tags: trunk
22:24
Add VdbeModuleComment()s on the three main code generators for window functions. check-in: f7c239e9 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/window.c.

   146    146   */
   147    147   static void row_numberStepFunc(
   148    148     sqlite3_context *pCtx, 
   149    149     int nArg,
   150    150     sqlite3_value **apArg
   151    151   ){
   152    152     i64 *p = (i64*)sqlite3_aggregate_context(pCtx, sizeof(*p));
   153         -  /* row_numberValueFunc() is always called first, so the aggregate context
   154         -  ** is guaranteed to already exist. */
   155         -  if( ALWAYS(p) ) (*p)++;
          153  +  if( p ) (*p)++;
   156    154     UNUSED_PARAMETER(nArg);
   157    155     UNUSED_PARAMETER(apArg);
   158    156   }
   159    157   static void row_numberValueFunc(sqlite3_context *pCtx){
   160    158     i64 *p = (i64*)sqlite3_aggregate_context(pCtx, sizeof(*p));
   161    159     sqlite3_result_int64(pCtx, (p ? *p : 0));
   162    160   }
................................................................................
   180    178   static void dense_rankStepFunc(
   181    179     sqlite3_context *pCtx, 
   182    180     int nArg,
   183    181     sqlite3_value **apArg
   184    182   ){
   185    183     struct CallCount *p;
   186    184     p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
   187         -  /* p is not NULL because dense_rankValueFunc() will have been called first */
   188         -  if( ALWAYS(p) ) p->nStep = 1;
          185  +  if( p ) p->nStep = 1;
   189    186     UNUSED_PARAMETER(nArg);
   190    187     UNUSED_PARAMETER(apArg);
   191    188   }
   192    189   static void dense_rankValueFunc(sqlite3_context *pCtx){
   193    190     struct CallCount *p;
   194    191     p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
   195    192     if( p ){
................................................................................
   210    207   static void rankStepFunc(
   211    208     sqlite3_context *pCtx, 
   212    209     int nArg,
   213    210     sqlite3_value **apArg
   214    211   ){
   215    212     struct CallCount *p;
   216    213     p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
   217         -  /* p is not NULL because rankValueFunc() will have been called first */
   218         -  if( ALWAYS(p) ){
          214  +  if( p ){
   219    215       p->nStep++;
   220    216       if( p->nValue==0 ){
   221    217         p->nValue = p->nStep;
   222    218       }
   223    219     }
   224    220     UNUSED_PARAMETER(nArg);
   225    221     UNUSED_PARAMETER(apArg);
................................................................................
   244    240     int nArg,
   245    241     sqlite3_value **apArg
   246    242   ){
   247    243     struct CallCount *p;
   248    244     UNUSED_PARAMETER(nArg); assert( nArg==1 );
   249    245   
   250    246     p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
   251         -  /* p is not NULL because percent_rankValueFunc() will have been called */
   252         -  if( ALWAYS(p) ){
          247  +  if( p ){
   253    248       if( p->nTotal==0 ){
   254    249         p->nTotal = sqlite3_value_int64(apArg[0]);
   255    250       }
   256    251       p->nStep++;
   257    252       if( p->nValue==0 ){
   258    253         p->nValue = p->nStep;
   259    254       }
................................................................................
   284    279     int nArg,
   285    280     sqlite3_value **apArg
   286    281   ){
   287    282     struct CallCount *p;
   288    283     assert( nArg==1 ); UNUSED_PARAMETER(nArg);
   289    284   
   290    285     p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
   291         -  /* p is not NULL because cume_distValueFunc() will have been called first */
   292         -  if( ALWAYS(p) ){
          286  +  if( p ){
   293    287       if( p->nTotal==0 ){
   294    288         p->nTotal = sqlite3_value_int64(apArg[0]);
   295    289       }
   296    290       p->nStep++;
   297    291     }
   298    292   }
   299    293   static void cume_distValueFunc(sqlite3_context *pCtx){
................................................................................
   324    318     sqlite3_context *pCtx, 
   325    319     int nArg,
   326    320     sqlite3_value **apArg
   327    321   ){
   328    322     struct NtileCtx *p;
   329    323     assert( nArg==2 ); UNUSED_PARAMETER(nArg);
   330    324     p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
   331         -  /* p is not NULL because ntimeValueFunc() will have been called first */
   332         -  if( ALWAYS(p) ){
          325  +  if( p ){
   333    326       if( p->nTotal==0 ){
   334    327         p->nParam = sqlite3_value_int64(apArg[0]);
   335    328         p->nTotal = sqlite3_value_int64(apArg[1]);
   336    329         if( p->nParam<=0 ){
   337    330           sqlite3_result_error(
   338    331               pCtx, "argument of ntile must be a positive integer", -1
   339    332           );