SQLite

Check-in [ec3ffb1748]
Login

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

Overview
Comment:Fix a bug in calculating the average number of entries for keys not present in the sqlite_stat4 table.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | sqlite_stat4
Files: files | file ages | folders
SHA1: ec3ffb174844406a6186c3dcc41b76d0331b502c
User & Date: dan 2013-08-12 11:21:10.969
Context
2013-08-12
16:34
Re-enable reading from the sqlite_stat3 table (as well as sqlite_stat4). (check-in: 6d45078e62 user: dan tags: sqlite_stat4)
11:21
Fix a bug in calculating the average number of entries for keys not present in the sqlite_stat4 table. (check-in: ec3ffb1748 user: dan tags: sqlite_stat4)
09:29
Fix minor problems caused by adding the rowid to the records in stat4. (check-in: 088d1ff948 user: dan tags: sqlite_stat4)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/analyze.c.
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
  sqlite3DbFree(db, zSql);
  if( rc ) return rc;

  while( sqlite3_step(pStmt)==SQLITE_ROW ){
    char *zIndex;   /* Index name */
    Index *pIdx;    /* Pointer to the index object */
    int i;          /* Loop counter */
    tRowcnt sumEq;  /* Sum of the nEq values */
    int nCol;       /* Number of columns in index */

    zIndex = (char *)sqlite3_column_text(pStmt, 0);
    if( zIndex==0 ) continue;
    pIdx = sqlite3FindIndex(db, zIndex, zDb);
    if( pIdx==0 ) continue;
    if( pIdx==pPrevIdx ){







<







1278
1279
1280
1281
1282
1283
1284

1285
1286
1287
1288
1289
1290
1291
  sqlite3DbFree(db, zSql);
  if( rc ) return rc;

  while( sqlite3_step(pStmt)==SQLITE_ROW ){
    char *zIndex;   /* Index name */
    Index *pIdx;    /* Pointer to the index object */
    int i;          /* Loop counter */

    int nCol;       /* Number of columns in index */

    zIndex = (char *)sqlite3_column_text(pStmt, 0);
    if( zIndex==0 ) continue;
    pIdx = sqlite3FindIndex(db, zIndex, zDb);
    if( pIdx==0 ) continue;
    if( pIdx==pPrevIdx ){
1300
1301
1302
1303
1304
1305
1306

1307
1308


1309
1310












1311
1312
1313
1314
1315
1316
1317
1318
1319
1320

    nCol = pIdx->nColumn+1;
    decodeIntArray((char*)sqlite3_column_text(pStmt,1), nCol, pSample->anEq, 0);
    decodeIntArray((char*)sqlite3_column_text(pStmt,2), nCol, pSample->anLt, 0);
    decodeIntArray((char*)sqlite3_column_text(pStmt,3), nCol, pSample->anDLt,0);

    if( idx==pIdx->nSample-1 ){

      int iCol;
      for(iCol=0; iCol<pIdx->nColumn; iCol++){


        tRowcnt avgEq = 0;
        tRowcnt nDLt = pSample->anDLt[iCol];












        if( nDLt>idx ){
          for(i=0, sumEq=0; i<idx; i++) sumEq += pIdx->aSample[i].anEq[iCol];
          avgEq = (pSample->anLt[iCol] - sumEq)/(nDLt - idx);
        }
        if( avgEq==0 ) avgEq = 1;
        pIdx->aAvgEq[iCol] = avgEq;
      }
    }

    pSample->n = sqlite3_column_bytes(pStmt, 4);







>


>
>


>
>
>
>
>
>
>
>
>
>
>
>
|
<
|







1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325

1326
1327
1328
1329
1330
1331
1332
1333

    nCol = pIdx->nColumn+1;
    decodeIntArray((char*)sqlite3_column_text(pStmt,1), nCol, pSample->anEq, 0);
    decodeIntArray((char*)sqlite3_column_text(pStmt,2), nCol, pSample->anLt, 0);
    decodeIntArray((char*)sqlite3_column_text(pStmt,3), nCol, pSample->anDLt,0);

    if( idx==pIdx->nSample-1 ){
      IndexSample *aSample = pIdx->aSample;
      int iCol;
      for(iCol=0; iCol<pIdx->nColumn; iCol++){
        tRowcnt sumEq = 0;        /* Sum of the nEq values */
        int nSum = 0;             /* Number of terms contributing to sumEq */
        tRowcnt avgEq = 0;
        tRowcnt nDLt = pSample->anDLt[iCol];

        /* Set nSum to the number of distinct (iCol+1) field prefixes that
        ** occur in the stat4 table for this index before pSample. Set
        ** sumEq to the sum of the nEq values for column iCol for the same
        ** set (adding the value only once where there exist dupicate 
        ** prefixes).  */
        for(i=0; i<(pIdx->nSample-1); i++){
          if( aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol] ){
            sumEq += aSample[i].anEq[iCol];
            nSum++;
          }
        }
        if( nDLt>nSum ){

          avgEq = (pSample->anLt[iCol] - sumEq)/(nDLt - nSum);
        }
        if( avgEq==0 ) avgEq = 1;
        pIdx->aAvgEq[iCol] = avgEq;
      }
    }

    pSample->n = sqlite3_column_bytes(pStmt, 4);