/ Check-in [1d1d13b8]
Login

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

Overview
Comment:On the --summary output of wordcount, add the a PRAGMA integrity_check and a 64-bit checksum of the entire table.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1d1d13b89056903543c909b094030d205473fa82
User & Date: drh 2013-11-08 00:16:58
Context
2013-11-08
01:09
Optimize out a NotExists/NotFound opcode that occurs in UPDATE processing after constraint checks if there is no possiblity that the constraint checking code might have moved the cursor. check-in: 74e3ee2e user: drh tags: trunk
00:16
On the --summary output of wordcount, add the a PRAGMA integrity_check and a 64-bit checksum of the entire table. check-in: 1d1d13b8 user: drh tags: trunk
2013-11-07
23:23
Add many new options to the wordcount test program: --delete, --pagesize, --cachesize, --commit, --nosync, and --journal. check-in: e938112d user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/wordcount.c.

    89     89     printf("%s;\n", zSql);
    90     90   }
    91     91   
    92     92   /* An sqlite3_exec() callback that prints results on standard output,
    93     93   ** each column separated by a single space. */
    94     94   static int printResult(void *NotUsed, int nArg, char **azArg, char **azNm){
    95     95     int i;
    96         -  const char *zFormat = "%s";
           96  +  printf("--");
    97     97     for(i=0; i<nArg; i++){
    98         -    printf(zFormat, azArg[i]);
    99         -    zFormat = " %s";
           98  +    printf(" %s", azArg[i]);
   100     99     }
   101    100     printf("\n");
   102    101     return 0;
   103    102   }
   104    103   
          104  +
          105  +/*
          106  +** Add one character to a hash
          107  +*/
          108  +static void addCharToHash(unsigned int *a, unsigned char x){
          109  +  if( a[0]<4 ){
          110  +    a[1] = (a[1]<<8) | x;
          111  +    a[0]++;
          112  +  }else{
          113  +    a[2] = (a[2]<<8) | x;
          114  +    a[0]++;
          115  +    if( a[0]==8 ){
          116  +      a[3] += a[1] + a[4];
          117  +      a[4] += a[2] + a[3];
          118  +      a[0] = a[1] = a[2] = 0;
          119  +    }
          120  +  }    
          121  +}
          122  +
          123  +/*
          124  +** Compute the final hash value.
          125  +*/
          126  +static void finalHash(unsigned int *a, char *z){
          127  +  a[3] += a[1] + a[4] + a[0];
          128  +  a[4] += a[2] + a[3];
          129  +  sqlite3_snprintf(17, z, "%08x%08x", a[3], a[4]);
          130  +}
          131  +
          132  +
          133  +/*
          134  +** Implementation of a checksum() aggregate SQL function
          135  +*/
          136  +static void checksumStep(
          137  +  sqlite3_context *context,
          138  +  int argc,
          139  +  sqlite3_value **argv
          140  +){
          141  +  const unsigned char *zVal;
          142  +  int nVal, i, j;
          143  +  unsigned int *a;
          144  +  a = (unsigned*)sqlite3_aggregate_context(context, sizeof(unsigned int)*5);
          145  +
          146  +  if( a ){
          147  +    for(i=0; i<argc; i++){
          148  +      nVal = sqlite3_value_bytes(argv[i]);
          149  +      zVal = (const unsigned char*)sqlite3_value_text(argv[i]);
          150  +      if( zVal ) for(j=0; j<nVal; j++) addCharToHash(a, zVal[j]);
          151  +      addCharToHash(a, '|');
          152  +    }
          153  +    addCharToHash(a, '\n');
          154  +  }
          155  +}
          156  +static void checksumFinalize(sqlite3_context *context){
          157  +  unsigned int *a;
          158  +  char zResult[24];
          159  +  a = sqlite3_aggregate_context(context, 0);
          160  +  if( a ){
          161  +    finalHash(a, zResult);
          162  +    sqlite3_result_text(context, zResult, -1, SQLITE_TRANSIENT);
          163  +  }
          164  +}
          165  +
   105    166   
   106    167   /* Define operating modes */
   107    168   #define MODE_INSERT     0
   108    169   #define MODE_REPLACE    1
   109    170   #define MODE_SELECT     2
   110    171   #define MODE_UPDATE     3
   111    172   #define MODE_DELETE     4
................................................................................
   353    414     if( zFileToRead ) fclose(in);
   354    415     sqlite3_finalize(pInsert);
   355    416     sqlite3_finalize(pUpdate);
   356    417     sqlite3_finalize(pSelect);
   357    418     sqlite3_finalize(pDelete);
   358    419   
   359    420     if( showSummary ){
          421  +    sqlite3_create_function(db, "checksum", -1, SQLITE_UTF8, 0,
          422  +                            0, checksumStep, checksumFinalize);
   360    423       sqlite3_exec(db, 
   361         -      "SELECT '-- count(*):  ', count(*) FROM wordcount;\n"
   362         -      "SELECT '-- sum(cnt):  ', sum(cnt) FROM wordcount;\n"
   363         -      "SELECT '-- avg(cnt):  ', avg(cnt) FROM wordcount;\n"
   364         -      "SELECT '-- sum(cnt=1):', sum(cnt=1) FROM wordcount;\n"
   365         -      "SELECT '-- top 10:    ', group_concat(word, ', ') FROM "
   366         -         "(SELECT word FROM wordcount ORDER BY cnt DESC LIMIT 10);\n",
          424  +      "SELECT 'count(*):  ', count(*) FROM wordcount;\n"
          425  +      "SELECT 'sum(cnt):  ', sum(cnt) FROM wordcount;\n"
          426  +      "SELECT 'max(cnt):  ', max(cnt) FROM wordcount;\n"
          427  +      "SELECT 'avg(cnt):  ', avg(cnt) FROM wordcount;\n"
          428  +      "SELECT 'sum(cnt=1):', sum(cnt=1) FROM wordcount;\n"
          429  +      "SELECT 'top 10:    ', group_concat(word, ', ') FROM "
          430  +         "(SELECT word FROM wordcount ORDER BY cnt DESC LIMIT 10);\n"
          431  +      "SELECT 'checksum:  ', checksum(word, cnt) FROM "
          432  +         "(SELECT word, cnt FROM wordcount ORDER BY word);\n"
          433  +      "PRAGMA integrity_check;\n",
   367    434         printResult, 0, 0);
   368    435     }
   369    436   
   370    437     /* Database connection statistics printed after both prepared statements
   371    438     ** have been finalized */
   372    439     if( showStats ){
   373    440       sqlite3_db_status(db, SQLITE_DBSTATUS_LOOKASIDE_USED, &iCur, &iHiwtr, 0);