SQLite

Check-in [6765ea52b3]
Login

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

Overview
Comment:Add the -overwrite option to speedtest8.c. (CVS 5022)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6765ea52b33270a323c620b060cffd4f59004db1
User & Date: drh 2008-04-16 23:50:24.000
Context
2008-04-17
14:16
In exclusive locking mode, commit by zeroing the first 28 bytes of the journal file, not by truncating the journal. Overwriting is much faster than truncating. (CVS 5023) (check-in: 8efb7f4ffb user: drh tags: trunk)
2008-04-16
23:50
Add the -overwrite option to speedtest8.c. (CVS 5022) (check-in: 6765ea52b3 user: drh tags: trunk)
23:39
Clear a global variable in the incrblob.test script. Ticket #3062. (CVS 5021) (check-in: 1c19854ae7 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to tool/speedtest8.c.
76
77
78
79
80
81
82



















































































83
84
85
86
87
88
89
90
91
92
93
94

95
96
97
98
99
100

101
102
103
104
105

106


107
108
109
110

111
112







113
114
115
116
117
118
119
120
121
122
123
124
125
126
    iStart = hwtime();
    rc = sqlite3_finalize(pStmt);
    iElapse = hwtime() - iStart;
    finalizeTime += iElapse;
    printf("sqlite3_finalize() returns %d in %llu cycles\n", rc, iElapse);
  }
}




















































































int main(int argc, char **argv){
  sqlite3 *db;
  int rc;
  int nSql;
  char *zSql;
  int i, j;
  FILE *in;
  unsigned long long int iStart, iElapse;
  unsigned long long int iSetup = 0;
  int nStmt = 0;
  int nByte = 0;


#ifdef HAVE_OSINST
  extern sqlite3_vfs *sqlite3_instvfs_binarylog(char *, char *, char *);
  extern void sqlite3_instvfs_destroy(sqlite3_vfs *);

  sqlite3_vfs *pVfs = 0;

  if( argc!=3 && (argc!=5 || strcmp("-log", argv[1])) ){
    fprintf(stderr, "Usage: %s ?-log LOGFILE? FILENAME SQL-SCRIPT\n"
                    "Runs SQL-SCRIPT against a UTF8 database\n",
                    argv[0]);
    exit(1);

  }


  if( argc==5 ){
    pVfs = sqlite3_instvfs_binarylog("oslog", 0, argv[2]);
    sqlite3_vfs_register(pVfs, 1);
    argv += 2;

  }
#else







  if( argc!=3 ){
    fprintf(stderr, "Usage: %s FILENAME SQL-SCRIPT\n"
                    "Runs SQL-SCRIPT against a UTF8 database\n",
                    argv[0]);
    exit(1);
  }
#endif

  in = fopen(argv[2], "r");
  fseek(in, 0L, SEEK_END);
  nSql = ftell(in);
  zSql = malloc( nSql+1 );
  fseek(in, 0L, SEEK_SET);
  nSql = fread(zSql, 1, nSql, in);







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>












>




<

>
|
|
|
|
<
>

>
>
|



>

|
>
>
>
>
>
>
>

|

|


<







76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182

183
184
185
186
187
188

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

213
214
215
216
217
218
219
    iStart = hwtime();
    rc = sqlite3_finalize(pStmt);
    iElapse = hwtime() - iStart;
    finalizeTime += iElapse;
    printf("sqlite3_finalize() returns %d in %llu cycles\n", rc, iElapse);
  }
}

/***************************************************************************
** The "overwrite" VFS is an overlay over the default VFS.  It modifies
** the xTruncate operation on journal files so that xTruncate merely
** writes zeros into the first 50 bytes of the file rather than truely
** truncating the file.
**
** The following variables are initialized to be the virtual function
** tables for the overwrite VFS.
*/
static sqlite3_vfs overwrite_vfs;
static sqlite3_io_methods overwrite_methods;

/*
** The truncate method for journal files in the overwrite VFS.
*/
static int overwriteTruncate(sqlite3_file *pFile, sqlite_int64 size){
  int rc;
  static const char buf[50];
  if( size ){
    return SQLITE_IOERR;
  }
  rc = pFile->pMethods->xWrite(pFile, buf, sizeof(buf), 0);
  if( rc==SQLITE_OK ){
    rc = pFile->pMethods->xSync(pFile, SQLITE_SYNC_NORMAL);
  }
  return rc;
}

/*
** The delete method for journal files in the overwrite VFS.
*/
static int overwriteDelete(sqlite3_file *pFile){
  return overwriteTruncate(pFile, 0);
}

/*
** The open method for overwrite VFS.  If the file being opened is
** a journal file then substitute the alternative xTruncate method.
*/
static int overwriteOpen(
  sqlite3_vfs *pVfs,
  const char *zName,
  sqlite3_file *pFile,
  int flags,
  int *pOutFlags
){
  int rc;
  sqlite3_vfs *pRealVfs;
  int isJournal;

  isJournal = (flags & (SQLITE_OPEN_MAIN_JOURNAL|SQLITE_OPEN_TEMP_JOURNAL))!=0;
  pRealVfs = (sqlite3_vfs*)pVfs->pAppData;
  rc = pRealVfs->xOpen(pRealVfs, zName, pFile, flags, pOutFlags);
  if( rc==SQLITE_OK && isJournal ){
    if( overwrite_methods.xTruncate==0 ){
      sqlite3_io_methods temp;
      memcpy(&temp, pFile->pMethods, sizeof(temp));
      temp.xTruncate = overwriteTruncate;
      memcpy(&overwrite_methods, &temp, sizeof(temp));
    }
    pFile->pMethods = &overwrite_methods;
  }
  return rc;
}

/*
** Overlay the overwrite VFS over top of the current default VFS
** and make the overlay VFS the new default.
**
** This routine can only be evaluated once.  On second and subsequent
** executions it becomes a no-op.
*/
static void registerOverwriteVfs(void){
  sqlite3_vfs *pBase;
  if( overwrite_vfs.iVersion ) return;
  pBase = sqlite3_vfs_find(0);
  memcpy(&overwrite_vfs, pBase, sizeof(overwrite_vfs));
  overwrite_vfs.pAppData = pBase;
  overwrite_vfs.xOpen = overwriteOpen;
  overwrite_vfs.zName = "overwriteVfs";
  sqlite3_vfs_register(&overwrite_vfs, 1);
}

int main(int argc, char **argv){
  sqlite3 *db;
  int rc;
  int nSql;
  char *zSql;
  int i, j;
  FILE *in;
  unsigned long long int iStart, iElapse;
  unsigned long long int iSetup = 0;
  int nStmt = 0;
  int nByte = 0;
  const char *zArgv0 = argv[0];

#ifdef HAVE_OSINST
  extern sqlite3_vfs *sqlite3_instvfs_binarylog(char *, char *, char *);
  extern void sqlite3_instvfs_destroy(sqlite3_vfs *);

  sqlite3_vfs *pVfs = 0;
#endif

  if( argc>=4 && strcmp(argv[1], "-overwrite")==0 ){
    registerOverwriteVfs();
    argv++;

    argc--;
  }

#ifdef HAVE_OSINST
  if( argc>=5 && strcmp(argv[1], "-log")==0 ){
    pVfs = sqlite3_instvfs_binarylog("oslog", 0, argv[2]);
    sqlite3_vfs_register(pVfs, 1);
    argv += 2;
    argc -= 2;
  }
#endif

  if( argc>=4 && strcmp(argv[1], "-overwrite")==0 ){
    registerOverwriteVfs();
    argv++;
    argc--;
  }

  if( argc!=3 ){
    fprintf(stderr, "Usage: %s [options] FILENAME SQL-SCRIPT\n"
                    "Runs SQL-SCRIPT against a UTF8 database\n",
                    zArgv0);
    exit(1);
  }


  in = fopen(argv[2], "r");
  fseek(in, 0L, SEEK_END);
  nSql = ftell(in);
  zSql = malloc( nSql+1 );
  fseek(in, 0L, SEEK_SET);
  nSql = fread(zSql, 1, nSql, in);
140
141
142
143
144
145
146


147
148
149
150
151
152
153
154
155
      zSql[j+1] = 0;
      isComplete = sqlite3_complete(&zSql[i]);
      zSql[j+1] = c;
      if( isComplete ){
        zSql[j] = 0;
        while( i<j && isspace(zSql[i]) ){ i++; }
        if( i<j ){


          nStmt++;
          nByte += j-i;
          prepareAndRun(db, &zSql[i]);
        }
        zSql[j] = ';';
        i = j+1;
      }
    }
  }







>
>

|







233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
      zSql[j+1] = 0;
      isComplete = sqlite3_complete(&zSql[i]);
      zSql[j+1] = c;
      if( isComplete ){
        zSql[j] = 0;
        while( i<j && isspace(zSql[i]) ){ i++; }
        if( i<j ){
          int n = j - i;
          if( n>=6 && memcmp(&zSql[i], ".crash",6)==0 ) exit(1);
          nStmt++;
          nByte += n;
          prepareAndRun(db, &zSql[i]);
        }
        zSql[j] = ';';
        i = j+1;
      }
    }
  }