/ Check-in [959bb5ac]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:In the ANALYZE command implementation make statInit() a 2-value function since the 3rd parameter was always the same constant.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 959bb5acdc3b4e2b481e3c38f20867131bfc9dbc
User & Date: drh 2013-08-27 14:14:14
Context
2013-08-27
15:41
Update sqlite3.pc.in to use @PACKAGE_VERSION@ instead of @RELEASE@. check-in: 2460dfd8 user: dan tags: trunk
14:14
In the ANALYZE command implementation make statInit() a 2-value function since the 3rd parameter was always the same constant. check-in: 959bb5ac user: drh tags: trunk
2013-08-26
23:18
Merge the STAT4 capability into trunk. check-in: a32af0ab user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/analyze.c.

   281    281     int iMin;                 /* Index in a[] of entry with minimum score */
   282    282     int nSample;              /* Current number of samples */
   283    283     int iGet;                 /* Index of current sample accessed by stat_get() */
   284    284     Stat4Sample *a;           /* Array of mxSample Stat4Sample objects */
   285    285   };
   286    286   
   287    287   /*
   288         -** Implementation of the stat_init(C,N,S) SQL function. The three parameters
   289         -** are the number of rows in the table or index (C), the number of columns
   290         -** in the index (N) and the number of samples to accumulate (S).
          288  +** Implementation of the stat_init(C,N) SQL function. The two parameters
          289  +** are the number of rows in the table or index (C) and the number of columns
          290  +** in the index (N).
   291    291   **
   292    292   ** This routine allocates the Stat4Accum object in heap memory. The return 
   293    293   ** value is a pointer to the the Stat4Accum object encoded as a blob (i.e. 
   294    294   ** the size of the blob is sizeof(void*) bytes). 
   295    295   */
   296    296   static void statInit(
   297    297     sqlite3_context *context,
................................................................................
   305    305     int nCol;                       /* Number of columns in index being sampled */
   306    306     int n;                          /* Bytes of space to allocate */
   307    307     int i;                          /* Used to iterate through p->aSample[] */
   308    308   
   309    309     /* Decode the three function arguments */
   310    310     UNUSED_PARAMETER(argc);
   311    311     nRow = (tRowcnt)sqlite3_value_int64(argv[0]);
   312         -  mxSample = sqlite3_value_int(argv[2]);
          312  +  mxSample = SQLITE_STAT4_SAMPLES;
   313    313     nCol = sqlite3_value_int(argv[1]);
   314    314     assert( nCol>1 );               /* >1 because it includes the rowid column */
   315    315   
   316    316     /* Allocate the space required for the Stat4Accum object */
   317    317     n = sizeof(*p) 
   318    318       + sizeof(tRowcnt)*nCol                    /* Stat4Accum.anEq */
   319    319       + sizeof(tRowcnt)*nCol                    /* Stat4Accum.anLt */
................................................................................
   352    352       p->aBest[i].iCol = i;
   353    353     }
   354    354   
   355    355     /* Return a pointer to the allocated object to the caller */
   356    356     sqlite3_result_blob(context, p, sizeof(p), sqlite3_free);
   357    357   }
   358    358   static const FuncDef statInitFuncdef = {
   359         -  3,               /* nArg */
          359  +  2,               /* nArg */
   360    360     SQLITE_UTF8,     /* iPrefEnc */
   361    361     0,               /* flags */
   362    362     0,               /* pUserData */
   363    363     0,               /* pNext */
   364    364     statInit,        /* xFunc */
   365    365     0,               /* xStep */
   366    366     0,               /* xFinalize */
................................................................................
   907    907       ** 
   908    908       **     * the number of rows in the index,
   909    909       **     * the number of columns in the index including the rowid,
   910    910       **     * the recommended number of samples for the stat3/stat4 table.
   911    911       */
   912    912       sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regStat4+1);
   913    913       sqlite3VdbeAddOp2(v, OP_Integer, nCol+1, regStat4+2);
   914         -    sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_STAT4_SAMPLES, regStat4+3);
   915    914       sqlite3VdbeAddOp3(v, OP_Function, 0, regStat4+1, regStat4);
   916    915       sqlite3VdbeChangeP4(v, -1, (char*)&statInitFuncdef, P4_FUNCDEF);
   917         -    sqlite3VdbeChangeP5(v, 3);
          916  +    sqlite3VdbeChangeP5(v, 2);
   918    917   
   919    918       /* Implementation of the following:
   920    919       **
   921    920       **   Rewind csr
   922    921       **   if eof(csr) goto end_of_scan;
   923    922       **   regChng = 0
   924    923       **   goto next_push_0;