2 ** A program for performance testing.
4 ** The available command-line options are described below:
6 static const char zHelp
[] =
7 "Usage: %s [--options] DATABASE\n"
9 " --autovacuum Enable AUTOVACUUM mode\n"
10 " --big-transactions Add BEGIN/END around all large tests\n"
11 " --cachesize N Set PRAGMA cache_size=N. Note: N is pages, not bytes\n"
12 " --checkpoint Run PRAGMA wal_checkpoint after each test case\n"
13 " --exclusive Enable locking_mode=EXCLUSIVE\n"
14 " --explain Like --sqlonly but with added EXPLAIN keywords\n"
15 " --fullfsync Enable fullfsync=TRUE\n"
16 " --heap SZ MIN Memory allocator uses SZ bytes & min allocation MIN\n"
17 " --incrvacuum Enable incremenatal vacuum mode\n"
18 " --journal M Set the journal_mode to M\n"
19 " --key KEY Set the encryption key to KEY\n"
20 " --lookaside N SZ Configure lookaside for N slots of SZ bytes each\n"
21 " --memdb Use an in-memory database\n"
22 " --mmap SZ MMAP the first SZ bytes of the database file\n"
23 " --multithread Set multithreaded mode\n"
24 " --nomemstat Disable memory statistics\n"
25 " --nomutex Open db with SQLITE_OPEN_NOMUTEX\n"
26 " --nosync Set PRAGMA synchronous=OFF\n"
27 " --notnull Add NOT NULL constraints to table columns\n"
28 " --output FILE Store SQL output in FILE\n"
29 " --pagesize N Set the page size to N\n"
30 " --pcache N SZ Configure N pages of pagecache each of size SZ bytes\n"
31 " --primarykey Use PRIMARY KEY instead of UNIQUE where appropriate\n"
32 " --repeat N Repeat each SELECT N times (default: 1)\n"
33 " --reprepare Reprepare each statement upon every invocation\n"
34 " --reserve N Reserve N bytes on each database page\n"
35 " --script FILE Write an SQL script for the test into FILE\n"
36 " --serialized Set serialized threading mode\n"
37 " --singlethread Set single-threaded mode - disables all mutexing\n"
38 " --sqlonly No-op. Only show the SQL that would have been run.\n"
39 " --shrink-memory Invoke sqlite3_db_release_memory() frequently.\n"
40 " --size N Relative test size. Default=100\n"
41 " --strict Use STRICT table where appropriate\n"
42 " --stats Show statistics at the end\n"
43 " --stmtscanstatus Activate SQLITE_DBCONFIG_STMT_SCANSTATUS\n"
44 " --temp N N from 0 to 9. 0: no temp table. 9: all temp tables\n"
45 " --testset T Run test-set T (main, cte, rtree, orm, fp, debug)\n"
46 " --trace Turn on SQL tracing\n"
47 " --threads N Use up to N threads for sorting\n"
48 " --utf16be Set text encoding to UTF-16BE\n"
49 " --utf16le Set text encoding to UTF-16LE\n"
50 " --verify Run additional verification steps\n"
51 " --vfs NAME Use the given (preinstalled) VFS\n"
52 " --without-rowid Use WITHOUT ROWID where appropriate\n"
67 #define ISSPACE(X) isspace((unsigned char)(X))
68 #define ISDIGIT(X) isdigit((unsigned char)(X))
70 #if SQLITE_VERSION_NUMBER<3005000
71 # define sqlite3_int64 sqlite_int64
74 typedef sqlite3_uint64 u64
;
77 ** State structure for a Hash hash in progress
79 typedef struct HashContext HashContext
;
81 unsigned char isInit
; /* True if initialized */
82 unsigned char i
, j
; /* State variables */
83 unsigned char s
[256]; /* State variables */
84 unsigned char r
[32]; /* Result */
88 /* All global state is held in this structure */
89 static struct Global
{
90 sqlite3
*db
; /* The open database connection */
91 sqlite3_stmt
*pStmt
; /* Current SQL statement */
92 sqlite3_int64 iStart
; /* Start-time for the current test */
93 sqlite3_int64 iTotal
; /* Total time */
94 int bWithoutRowid
; /* True for --without-rowid */
95 int bReprepare
; /* True to reprepare the SQL on each rerun */
96 int bSqlOnly
; /* True to print the SQL once only */
97 int bExplain
; /* Print SQL with EXPLAIN prefix */
98 int bVerify
; /* Try to verify that results are correct */
99 int bMemShrink
; /* Call sqlite3_db_release_memory() often */
100 int eTemp
; /* 0: no TEMP. 9: always TEMP. */
101 int szTest
; /* Scale factor for test iterations */
102 int nRepeat
; /* Repeat selects this many times */
103 int doCheckpoint
; /* Run PRAGMA wal_checkpoint after each trans */
104 int nReserve
; /* Reserve bytes */
105 int stmtScanStatus
; /* True to activate Stmt ScanStatus reporting */
106 int doBigTransactions
; /* Enable transactions on tests 410 and 510 */
107 const char *zWR
; /* Might be WITHOUT ROWID */
108 const char *zNN
; /* Might be NOT NULL */
109 const char *zPK
; /* Might be UNIQUE or PRIMARY KEY */
110 unsigned int x
, y
; /* Pseudo-random number generator state */
111 u64 nResByte
; /* Total number of result bytes */
112 int nResult
; /* Size of the current result */
113 char zResult
[3000]; /* Text of the current result */
114 FILE *pScript
; /* Write an SQL script into this file */
115 #ifndef SPEEDTEST_OMIT_HASH
116 FILE *hashFile
; /* Store all hash results in this file */
117 HashContext hash
; /* Hash of all output */
121 /* Return " TEMP" or "", as appropriate for creating a table.
123 static const char *isTemp(int N
){
124 return g
.eTemp
>=N
? " TEMP" : "";
127 /* Print an error message and exit */
128 static void fatal_error(const char *zMsg
, ...){
131 vfprintf(stderr
, zMsg
, ap
);
136 #ifndef SPEEDTEST_OMIT_HASH
137 /****************************************************************************
138 ** Hash algorithm used to verify that compilation is not miscompiled
139 ** in such a was as to generate an incorrect result.
143 ** Initialize a new hash. iSize determines the size of the hash
144 ** in bits and should be one of 224, 256, 384, or 512. Or iSize
145 ** can be zero to use the default hash size of 256 bits.
147 static void HashInit(void){
151 for(k
=0; k
<256; k
++) g
.hash
.s
[k
] = k
;
155 ** Make consecutive calls to the HashUpdate function to add new content
158 static void HashUpdate(
159 const unsigned char *aData
,
163 unsigned char i
= g
.hash
.i
;
164 unsigned char j
= g
.hash
.j
;
166 if( g
.hashFile
) fwrite(aData
, 1, nData
, g
.hashFile
);
167 for(k
=0; k
<nData
; k
++){
168 j
+= g
.hash
.s
[i
] + aData
[k
];
170 g
.hash
.s
[j
] = g
.hash
.s
[i
];
179 ** After all content has been added, invoke HashFinal() to compute
180 ** the final hash. The hash result is stored in g.hash.r[].
182 static void HashFinal(void){
184 unsigned char t
, i
, j
;
191 g
.hash
.s
[i
] = g
.hash
.s
[j
];
194 g
.hash
.r
[k
] = g
.hash
.s
[t
];
198 /* End of the Hash hashing logic
199 *****************************************************************************/
200 #endif /* SPEEDTEST_OMIT_HASH */
203 ** Return the value of a hexadecimal digit. Return -1 if the input
204 ** is not a hex digit.
206 static int hexDigitValue(char c
){
207 if( c
>='0' && c
<='9' ) return c
- '0';
208 if( c
>='a' && c
<='f' ) return c
- 'a' + 10;
209 if( c
>='A' && c
<='F' ) return c
- 'A' + 10;
213 /* Provide an alternative to sqlite3_stricmp() in older versions of
215 #if SQLITE_VERSION_NUMBER<3007011
216 # define sqlite3_stricmp strcmp
220 ** Interpret zArg as an integer value, possibly with suffixes.
222 static int integerValue(const char *zArg
){
224 static const struct { char *zSuffix
; int iMult
; } aMult
[] = {
226 { "MiB", 1024*1024 },
227 { "GiB", 1024*1024*1024 },
230 { "GB", 1000000000 },
240 }else if( zArg
[0]=='+' ){
243 if( zArg
[0]=='0' && zArg
[1]=='x' ){
246 while( (x
= hexDigitValue(zArg
[0]))>=0 ){
251 while( isdigit(zArg
[0]) ){
252 v
= v
*10 + zArg
[0] - '0';
256 for(i
=0; i
<sizeof(aMult
)/sizeof(aMult
[0]); i
++){
257 if( sqlite3_stricmp(aMult
[i
].zSuffix
, zArg
)==0 ){
262 if( v
>0x7fffffff ) fatal_error("parameter too large - max 2147483648");
263 return (int)(isNeg
? -v
: v
);
266 /* Return the current wall-clock time, in milliseconds */
267 sqlite3_int64
speedtest1_timestamp(void){
268 #if SQLITE_VERSION_NUMBER<3005000
271 static sqlite3_vfs
*clockVfs
= 0;
273 if( clockVfs
==0 ) clockVfs
= sqlite3_vfs_find(0);
274 #if SQLITE_VERSION_NUMBER>=3007000
275 if( clockVfs
->iVersion
>=2 && clockVfs
->xCurrentTimeInt64
!=0 ){
276 clockVfs
->xCurrentTimeInt64(clockVfs
, &t
);
281 clockVfs
->xCurrentTime(clockVfs
, &r
);
282 t
= (sqlite3_int64
)(r
*86400000.0);
288 /* Return a pseudo-random unsigned integer */
289 unsigned int speedtest1_random(void){
290 g
.x
= (g
.x
>>1) ^ ((1+~(g
.x
&1)) & 0xd0000001);
291 g
.y
= g
.y
*1103515245 + 12345;
295 /* Map the value in within the range of 1...limit into another
296 ** number in a way that is chatic and invertable.
298 unsigned swizzle(unsigned in
, unsigned limit
){
301 out
= (out
<<1) | (in
&1);
308 /* Round up a number so that it is a power of two minus one
310 unsigned roundup_allones(unsigned limit
){
312 while( m
<limit
) m
= (m
<<1)+1;
316 /* The speedtest1_numbername procedure below converts its argment (an integer)
317 ** into a string which is the English-language name for that number.
318 ** The returned string should be freed with sqlite3_free().
322 ** speedtest1_numbername(123) -> "one hundred twenty three"
324 int speedtest1_numbername(unsigned int n
, char *zOut
, int nOut
){
325 static const char *ones
[] = { "zero", "one", "two", "three", "four", "five",
326 "six", "seven", "eight", "nine", "ten", "eleven", "twelve",
327 "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
328 "eighteen", "nineteen" };
329 static const char *tens
[] = { "", "ten", "twenty", "thirty", "forty",
330 "fifty", "sixty", "seventy", "eighty", "ninety" };
334 i
+= speedtest1_numbername(n
/1000000000, zOut
+i
, nOut
-i
);
335 sqlite3_snprintf(nOut
-i
, zOut
+i
, " billion");
336 i
+= (int)strlen(zOut
+i
);
340 if( i
&& i
<nOut
-1 ) zOut
[i
++] = ' ';
341 i
+= speedtest1_numbername(n
/1000000, zOut
+i
, nOut
-i
);
342 sqlite3_snprintf(nOut
-i
, zOut
+i
, " million");
343 i
+= (int)strlen(zOut
+i
);
347 if( i
&& i
<nOut
-1 ) zOut
[i
++] = ' ';
348 i
+= speedtest1_numbername(n
/1000, zOut
+i
, nOut
-i
);
349 sqlite3_snprintf(nOut
-i
, zOut
+i
, " thousand");
350 i
+= (int)strlen(zOut
+i
);
354 if( i
&& i
<nOut
-1 ) zOut
[i
++] = ' ';
355 sqlite3_snprintf(nOut
-i
, zOut
+i
, "%s hundred", ones
[n
/100]);
356 i
+= (int)strlen(zOut
+i
);
360 if( i
&& i
<nOut
-1 ) zOut
[i
++] = ' ';
361 sqlite3_snprintf(nOut
-i
, zOut
+i
, "%s", tens
[n
/10]);
362 i
+= (int)strlen(zOut
+i
);
366 if( i
&& i
<nOut
-1 ) zOut
[i
++] = ' ';
367 sqlite3_snprintf(nOut
-i
, zOut
+i
, "%s", ones
[n
]);
368 i
+= (int)strlen(zOut
+i
);
371 sqlite3_snprintf(nOut
-i
, zOut
+i
, "zero");
372 i
+= (int)strlen(zOut
+i
);
378 /* Start a new test case */
380 static const char zDots
[] =
381 ".......................................................................";
382 static int iTestNumber
= 0; /* Current test # for begin/end_test(). */
383 void speedtest1_begin_test(int iTestNum
, const char *zTestName
, ...){
384 int n
= (int)strlen(zTestName
);
387 iTestNumber
= iTestNum
;
388 va_start(ap
, zTestName
);
389 zName
= sqlite3_vmprintf(zTestName
, ap
);
391 n
= (int)strlen(zName
);
393 zName
[NAMEWIDTH
] = 0;
397 fprintf(g
.pScript
,"-- begin test %d %.*s\n", iTestNumber
, n
, zName
)
398 /* maintenance reminder: ^^^ code in ext/wasm expects %d to be
399 ** field #4 (as in: cut -d' ' -f4). */;
402 printf("/* %4d - %s%.*s */\n", iTestNum
, zName
, NAMEWIDTH
-n
, zDots
);
404 printf("%4d - %s%.*s ", iTestNum
, zName
, NAMEWIDTH
-n
, zDots
);
409 g
.iStart
= speedtest1_timestamp();
414 /* Forward reference */
415 void speedtest1_exec(const char*,...);
417 /* Complete a test case */
418 void speedtest1_end_test(void){
419 sqlite3_int64 iElapseTime
= speedtest1_timestamp() - g
.iStart
;
420 if( g
.doCheckpoint
) speedtest1_exec("PRAGMA wal_checkpoint;");
421 assert( iTestNumber
> 0 );
423 fprintf(g
.pScript
,"-- end test %d\n", iTestNumber
);
426 g
.iTotal
+= iElapseTime
;
427 printf("%4d.%03ds\n", (int)(iElapseTime
/1000), (int)(iElapseTime
%1000));
430 sqlite3_finalize(g
.pStmt
);
436 /* Report end of testing */
437 void speedtest1_final(void){
439 printf(" TOTAL%.*s %4d.%03ds\n", NAMEWIDTH
-5, zDots
,
440 (int)(g
.iTotal
/1000), (int)(g
.iTotal
%1000));
443 #ifndef SPEEDTEST_OMIT_HASH
446 printf("Verification Hash: %llu ", g
.nResByte
);
447 #ifndef SPEEDTEST_OMIT_HASH
448 HashUpdate((const unsigned char*)"\n", 1);
451 printf("%02x", g
.hash
.r
[i
]);
453 if( g
.hashFile
&& g
.hashFile
!=stdout
) fclose(g
.hashFile
);
459 /* Print an SQL statement to standard output */
460 static void printSql(const char *zSql
){
461 int n
= (int)strlen(zSql
);
462 while( n
>0 && (zSql
[n
-1]==';' || ISSPACE(zSql
[n
-1])) ){ n
--; }
463 if( g
.bExplain
) printf("EXPLAIN ");
464 printf("%.*s;\n", n
, zSql
);
466 #if SQLITE_VERSION_NUMBER>=3007017
467 && ( sqlite3_strglob("CREATE *", zSql
)==0
468 || sqlite3_strglob("DROP *", zSql
)==0
469 || sqlite3_strglob("ALTER *", zSql
)==0
473 printf("%.*s;\n", n
, zSql
);
477 /* Shrink memory used, if appropriate and if the SQLite version is capable
480 void speedtest1_shrink_memory(void){
481 #if SQLITE_VERSION_NUMBER>=3007010
482 if( g
.bMemShrink
) sqlite3_db_release_memory(g
.db
);
487 void speedtest1_exec(const char *zFormat
, ...){
490 va_start(ap
, zFormat
);
491 zSql
= sqlite3_vmprintf(zFormat
, ap
);
499 fprintf(g
.pScript
,"%s;\n",zSql
);
501 rc
= sqlite3_exec(g
.db
, zSql
, 0, 0, &zErrMsg
);
502 if( zErrMsg
) fatal_error("SQL error: %s\n%s\n", zErrMsg
, zSql
);
503 if( rc
!=SQLITE_OK
) fatal_error("exec error: %s\n", sqlite3_errmsg(g
.db
));
506 speedtest1_shrink_memory();
509 /* Run SQL and return the first column of the first row as a string. The
510 ** returned string is obtained from sqlite_malloc() and must be freed by
513 char *speedtest1_once(const char *zFormat
, ...){
518 va_start(ap
, zFormat
);
519 zSql
= sqlite3_vmprintf(zFormat
, ap
);
524 int rc
= sqlite3_prepare_v2(g
.db
, zSql
, -1, &pStmt
, 0);
526 fatal_error("SQL error: %s\n", sqlite3_errmsg(g
.db
));
529 char *z
= sqlite3_expanded_sql(pStmt
);
530 fprintf(g
.pScript
,"%s\n",z
);
533 if( sqlite3_step(pStmt
)==SQLITE_ROW
){
534 const char *z
= (const char*)sqlite3_column_text(pStmt
, 0);
535 if( z
) zResult
= sqlite3_mprintf("%s", z
);
537 sqlite3_finalize(pStmt
);
540 speedtest1_shrink_memory();
544 /* Prepare an SQL statement */
545 void speedtest1_prepare(const char *zFormat
, ...){
548 va_start(ap
, zFormat
);
549 zSql
= sqlite3_vmprintf(zFormat
, ap
);
555 if( g
.pStmt
) sqlite3_finalize(g
.pStmt
);
556 rc
= sqlite3_prepare_v2(g
.db
, zSql
, -1, &g
.pStmt
, 0);
558 fatal_error("SQL error: %s\n", sqlite3_errmsg(g
.db
));
564 /* Run an SQL statement previously prepared */
565 void speedtest1_run(void){
567 if( g
.bSqlOnly
) return;
571 char *z
= sqlite3_expanded_sql(g
.pStmt
);
572 fprintf(g
.pScript
,"%s\n",z
);
575 while( sqlite3_step(g
.pStmt
)==SQLITE_ROW
){
576 n
= sqlite3_column_count(g
.pStmt
);
578 const char *z
= (const char*)sqlite3_column_text(g
.pStmt
, i
);
579 if( z
==0 ) z
= "nil";
580 len
= (int)strlen(z
);
581 #ifndef SPEEDTEST_OMIT_HASH
583 int eType
= sqlite3_column_type(g
.pStmt
, i
);
584 unsigned char zPrefix
[2];
586 zPrefix
[1] = "-IFTBN"[eType
];
588 HashUpdate(zPrefix
, 2);
590 HashUpdate(zPrefix
+1, 1);
592 if( eType
==SQLITE_FLOAT
){
593 /* Omit the value of floating-point results from the verification
594 ** hash. The only thing we record is the fact that the result was
595 ** a floating-point value. */
597 }else if( eType
==SQLITE_BLOB
){
598 int nBlob
= sqlite3_column_bytes(g
.pStmt
, i
);
600 unsigned char zChar
[2];
601 const unsigned char *aBlob
= sqlite3_column_blob(g
.pStmt
, i
);
602 for(iBlob
=0; iBlob
<nBlob
; iBlob
++){
603 zChar
[0] = "0123456789abcdef"[aBlob
[iBlob
]>>4];
604 zChar
[1] = "0123456789abcdef"[aBlob
[iBlob
]&15];
607 g
.nResByte
+= nBlob
*2 + 2;
609 HashUpdate((unsigned char*)z
, len
);
610 g
.nResByte
+= len
+ 2;
614 if( g
.nResult
+len
<sizeof(g
.zResult
)-2 ){
615 if( g
.nResult
>0 ) g
.zResult
[g
.nResult
++] = ' ';
616 memcpy(g
.zResult
+ g
.nResult
, z
, len
+1);
621 #if SQLITE_VERSION_NUMBER>=3006001
624 sqlite3_prepare_v2(g
.db
, sqlite3_sql(g
.pStmt
), -1, &pNew
, 0);
625 sqlite3_finalize(g
.pStmt
);
630 sqlite3_reset(g
.pStmt
);
632 speedtest1_shrink_memory();
635 #ifndef SQLITE_OMIT_DEPRECATED
636 /* The sqlite3_trace() callback function */
637 static void traceCallback(void *NotUsed
, const char *zSql
){
638 int n
= (int)strlen(zSql
);
639 while( n
>0 && (zSql
[n
-1]==';' || ISSPACE(zSql
[n
-1])) ) n
--;
640 fprintf(stderr
,"%.*s;\n", n
, zSql
);
642 #endif /* SQLITE_OMIT_DEPRECATED */
644 /* Substitute random() function that gives the same random
645 ** sequence on each run, for repeatability. */
646 static void randomFunc(
647 sqlite3_context
*context
,
649 sqlite3_value
**NotUsed2
651 sqlite3_result_int64(context
, (sqlite3_int64
)speedtest1_random());
654 /* Estimate the square root of an integer */
655 static int est_square_root(int x
){
659 for(n
=0; y0
>0 && n
<10; n
++){
668 #if SQLITE_VERSION_NUMBER<3005004
670 ** An implementation of group_concat(). Used only when testing older
671 ** versions of SQLite that lack the built-in group_concat().
678 static void groupAppend(struct groupConcat
*p
, const char *z
, int n
){
679 if( p
->nUsed
+n
>= p
->nAlloc
){
680 int n2
= (p
->nAlloc
+n
+1)*2;
681 char *z2
= sqlite3_realloc(p
->z
, n2
);
686 memcpy(p
->z
+p
->nUsed
, z
, n
);
689 static void groupStep(
690 sqlite3_context
*context
,
695 struct groupConcat
*p
;
698 assert( argc
==1 || argc
==2 );
699 if( sqlite3_value_type(argv
[0])==SQLITE_NULL
) return;
700 p
= (struct groupConcat
*)sqlite3_aggregate_context(context
, sizeof(*p
));
703 int firstTerm
= p
->nUsed
==0;
706 zSep
= (char*)sqlite3_value_text(argv
[1]);
707 nSep
= sqlite3_value_bytes(argv
[1]);
712 if( nSep
) groupAppend(p
, zSep
, nSep
);
714 zVal
= (char*)sqlite3_value_text(argv
[0]);
715 nVal
= sqlite3_value_bytes(argv
[0]);
716 if( zVal
) groupAppend(p
, zVal
, nVal
);
719 static void groupFinal(sqlite3_context
*context
){
720 struct groupConcat
*p
;
721 p
= sqlite3_aggregate_context(context
, 0);
724 sqlite3_result_text(context
, p
->z
, p
->nUsed
, sqlite3_free
);
730 ** The main and default testset
732 void testset_main(void){
733 int i
; /* Loop counter */
734 int n
; /* iteration count */
735 int sz
; /* Size of the tables */
736 int maxb
; /* Maximum swizzled value */
737 unsigned x1
= 0, x2
= 0; /* Parameters */
738 int len
= 0; /* Length of the zNum[] string */
739 char zNum
[2000]; /* A number name */
741 sz
= n
= g
.szTest
*500;
743 maxb
= roundup_allones(sz
);
744 speedtest1_begin_test(100, "%d INSERTs into table with no index", n
);
745 speedtest1_exec("BEGIN");
746 speedtest1_exec("CREATE%s TABLE z1(a INTEGER %s, b INTEGER %s, c TEXT %s);",
747 isTemp(9), g
.zNN
, g
.zNN
, g
.zNN
);
748 speedtest1_prepare("INSERT INTO z1 VALUES(?1,?2,?3); -- %d times", n
);
750 x1
= swizzle(i
,maxb
);
751 speedtest1_numbername(x1
, zNum
, sizeof(zNum
));
752 sqlite3_bind_int64(g
.pStmt
, 1, (sqlite3_int64
)x1
);
753 sqlite3_bind_int(g
.pStmt
, 2, i
);
754 sqlite3_bind_text(g
.pStmt
, 3, zNum
, -1, SQLITE_STATIC
);
757 speedtest1_exec("COMMIT");
758 speedtest1_end_test();
762 speedtest1_begin_test(110, "%d ordered INSERTS with one index/PK", n
);
763 speedtest1_exec("BEGIN");
765 "CREATE%s TABLE z2(a INTEGER %s %s, b INTEGER %s, c TEXT %s) %s",
766 isTemp(5), g
.zNN
, g
.zPK
, g
.zNN
, g
.zNN
, g
.zWR
);
767 speedtest1_prepare("INSERT INTO z2 VALUES(?1,?2,?3); -- %d times", n
);
769 x1
= swizzle(i
,maxb
);
770 speedtest1_numbername(x1
, zNum
, sizeof(zNum
));
771 sqlite3_bind_int(g
.pStmt
, 1, i
);
772 sqlite3_bind_int64(g
.pStmt
, 2, (sqlite3_int64
)x1
);
773 sqlite3_bind_text(g
.pStmt
, 3, zNum
, -1, SQLITE_STATIC
);
776 speedtest1_exec("COMMIT");
777 speedtest1_end_test();
781 speedtest1_begin_test(120, "%d unordered INSERTS with one index/PK", n
);
782 speedtest1_exec("BEGIN");
784 "CREATE%s TABLE t3(a INTEGER %s %s, b INTEGER %s, c TEXT %s) %s",
785 isTemp(3), g
.zNN
, g
.zPK
, g
.zNN
, g
.zNN
, g
.zWR
);
786 speedtest1_prepare("INSERT INTO t3 VALUES(?1,?2,?3); -- %d times", n
);
788 x1
= swizzle(i
,maxb
);
789 speedtest1_numbername(x1
, zNum
, sizeof(zNum
));
790 sqlite3_bind_int(g
.pStmt
, 2, i
);
791 sqlite3_bind_int64(g
.pStmt
, 1, (sqlite3_int64
)x1
);
792 sqlite3_bind_text(g
.pStmt
, 3, zNum
, -1, SQLITE_STATIC
);
795 speedtest1_exec("COMMIT");
796 speedtest1_end_test();
798 #if SQLITE_VERSION_NUMBER<3005004
799 sqlite3_create_function(g
.db
, "group_concat", 1, SQLITE_UTF8
, 0,
800 0, groupStep
, groupFinal
);
804 speedtest1_begin_test(130, "%d SELECTS, numeric BETWEEN, unindexed", n
);
805 speedtest1_exec("BEGIN");
807 "SELECT count(*), avg(b), sum(length(c)), group_concat(c) FROM z1\n"
808 " WHERE b BETWEEN ?1 AND ?2; -- %d times", n
811 if( (i
-1)%g
.nRepeat
==0 ){
812 x1
= speedtest1_random()%maxb
;
813 x2
= speedtest1_random()%10 + sz
/5000 + x1
;
815 sqlite3_bind_int(g
.pStmt
, 1, x1
);
816 sqlite3_bind_int(g
.pStmt
, 2, x2
);
819 speedtest1_exec("COMMIT");
820 speedtest1_end_test();
824 speedtest1_begin_test(140, "%d SELECTS, LIKE, unindexed", n
);
825 speedtest1_exec("BEGIN");
827 "SELECT count(*), avg(b), sum(length(c)), group_concat(c) FROM z1\n"
828 " WHERE c LIKE ?1; -- %d times", n
831 if( (i
-1)%g
.nRepeat
==0 ){
832 x1
= speedtest1_random()%maxb
;
834 len
= speedtest1_numbername(i
, zNum
+1, sizeof(zNum
)-2);
838 sqlite3_bind_text(g
.pStmt
, 1, zNum
, len
+1, SQLITE_STATIC
);
841 speedtest1_exec("COMMIT");
842 speedtest1_end_test();
846 speedtest1_begin_test(142, "%d SELECTS w/ORDER BY, unindexed", n
);
847 speedtest1_exec("BEGIN");
849 "SELECT a, b, c FROM z1 WHERE c LIKE ?1\n"
850 " ORDER BY a; -- %d times", n
853 if( (i
-1)%g
.nRepeat
==0 ){
854 x1
= speedtest1_random()%maxb
;
856 len
= speedtest1_numbername(i
, zNum
+1, sizeof(zNum
)-2);
860 sqlite3_bind_text(g
.pStmt
, 1, zNum
, len
+1, SQLITE_STATIC
);
863 speedtest1_exec("COMMIT");
864 speedtest1_end_test();
866 n
= 10; /* g.szTest/5; */
867 speedtest1_begin_test(145, "%d SELECTS w/ORDER BY and LIMIT, unindexed", n
);
868 speedtest1_exec("BEGIN");
870 "SELECT a, b, c FROM z1 WHERE c LIKE ?1\n"
871 " ORDER BY a LIMIT 10; -- %d times", n
874 if( (i
-1)%g
.nRepeat
==0 ){
875 x1
= speedtest1_random()%maxb
;
877 len
= speedtest1_numbername(i
, zNum
+1, sizeof(zNum
)-2);
881 sqlite3_bind_text(g
.pStmt
, 1, zNum
, len
+1, SQLITE_STATIC
);
884 speedtest1_exec("COMMIT");
885 speedtest1_end_test();
888 speedtest1_begin_test(150, "CREATE INDEX five times");
889 speedtest1_exec("BEGIN;");
890 speedtest1_exec("CREATE UNIQUE INDEX t1b ON z1(b);");
891 speedtest1_exec("CREATE INDEX t1c ON z1(c);");
892 speedtest1_exec("CREATE UNIQUE INDEX t2b ON z2(b);");
893 speedtest1_exec("CREATE INDEX t2c ON z2(c DESC);");
894 speedtest1_exec("CREATE INDEX t3bc ON t3(b,c);");
895 speedtest1_exec("COMMIT;");
896 speedtest1_end_test();
900 speedtest1_begin_test(160, "%d SELECTS, numeric BETWEEN, indexed", n
);
901 speedtest1_exec("BEGIN");
903 "SELECT count(*), avg(b), sum(length(c)), group_concat(a) FROM z1\n"
904 " WHERE b BETWEEN ?1 AND ?2; -- %d times", n
907 if( (i
-1)%g
.nRepeat
==0 ){
908 x1
= speedtest1_random()%maxb
;
909 x2
= speedtest1_random()%10 + sz
/5000 + x1
;
911 sqlite3_bind_int(g
.pStmt
, 1, x1
);
912 sqlite3_bind_int(g
.pStmt
, 2, x2
);
915 speedtest1_exec("COMMIT");
916 speedtest1_end_test();
920 speedtest1_begin_test(161, "%d SELECTS, numeric BETWEEN, PK", n
);
921 speedtest1_exec("BEGIN");
923 "SELECT count(*), avg(b), sum(length(c)), group_concat(a) FROM z2\n"
924 " WHERE a BETWEEN ?1 AND ?2; -- %d times", n
927 if( (i
-1)%g
.nRepeat
==0 ){
928 x1
= speedtest1_random()%maxb
;
929 x2
= speedtest1_random()%10 + sz
/5000 + x1
;
931 sqlite3_bind_int(g
.pStmt
, 1, x1
);
932 sqlite3_bind_int(g
.pStmt
, 2, x2
);
935 speedtest1_exec("COMMIT");
936 speedtest1_end_test();
940 speedtest1_begin_test(170, "%d SELECTS, text BETWEEN, indexed", n
);
941 speedtest1_exec("BEGIN");
943 "SELECT count(*), avg(b), sum(length(c)), group_concat(a) FROM z1\n"
944 " WHERE c BETWEEN ?1 AND (?1||'~'); -- %d times", n
947 if( (i
-1)%g
.nRepeat
==0 ){
948 x1
= swizzle(i
, maxb
);
949 len
= speedtest1_numbername(x1
, zNum
, sizeof(zNum
)-1);
951 sqlite3_bind_text(g
.pStmt
, 1, zNum
, len
, SQLITE_STATIC
);
954 speedtest1_exec("COMMIT");
955 speedtest1_end_test();
958 speedtest1_begin_test(180, "%d INSERTS with three indexes", n
);
959 speedtest1_exec("BEGIN");
961 "CREATE%s TABLE t4(\n"
962 " a INTEGER %s %s,\n"
966 isTemp(1), g
.zNN
, g
.zPK
, g
.zNN
, g
.zNN
, g
.zWR
);
967 speedtest1_exec("CREATE INDEX t4b ON t4(b)");
968 speedtest1_exec("CREATE INDEX t4c ON t4(c)");
969 speedtest1_exec("INSERT INTO t4 SELECT * FROM z1");
970 speedtest1_exec("COMMIT");
971 speedtest1_end_test();
974 speedtest1_begin_test(190, "DELETE and REFILL one table", n
);
975 speedtest1_exec("DELETE FROM z2;");
976 speedtest1_exec("INSERT INTO z2 SELECT * FROM z1;");
977 speedtest1_end_test();
980 speedtest1_begin_test(200, "VACUUM");
981 speedtest1_exec("VACUUM");
982 speedtest1_end_test();
985 speedtest1_begin_test(210, "ALTER TABLE ADD COLUMN, and query");
986 speedtest1_exec("ALTER TABLE z2 ADD COLUMN d INT DEFAULT 123");
987 speedtest1_exec("SELECT sum(d) FROM z2");
988 speedtest1_end_test();
992 speedtest1_begin_test(230, "%d UPDATES, numeric BETWEEN, indexed", n
);
993 speedtest1_exec("BEGIN");
995 "UPDATE z2 SET d=b*2 WHERE b BETWEEN ?1 AND ?2; -- %d times", n
998 x1
= speedtest1_random()%maxb
;
999 x2
= speedtest1_random()%10 + sz
/5000 + x1
;
1000 sqlite3_bind_int(g
.pStmt
, 1, x1
);
1001 sqlite3_bind_int(g
.pStmt
, 2, x2
);
1004 speedtest1_exec("COMMIT");
1005 speedtest1_end_test();
1009 speedtest1_begin_test(240, "%d UPDATES of individual rows", n
);
1010 speedtest1_exec("BEGIN");
1012 "UPDATE z2 SET d=b*3 WHERE a=?1; -- %d times", n
1014 for(i
=1; i
<=n
; i
++){
1015 x1
= speedtest1_random()%sz
+ 1;
1016 sqlite3_bind_int(g
.pStmt
, 1, x1
);
1019 speedtest1_exec("COMMIT");
1020 speedtest1_end_test();
1022 speedtest1_begin_test(250, "One big UPDATE of the whole %d-row table", sz
);
1023 speedtest1_exec("UPDATE z2 SET d=b*4");
1024 speedtest1_end_test();
1027 speedtest1_begin_test(260, "Query added column after filling");
1028 speedtest1_exec("SELECT sum(d) FROM z2");
1029 speedtest1_end_test();
1034 speedtest1_begin_test(270, "%d DELETEs, numeric BETWEEN, indexed", n
);
1035 speedtest1_exec("BEGIN");
1037 "DELETE FROM z2 WHERE b BETWEEN ?1 AND ?2; -- %d times", n
1039 for(i
=1; i
<=n
; i
++){
1040 x1
= speedtest1_random()%maxb
+ 1;
1041 x2
= speedtest1_random()%10 + sz
/5000 + x1
;
1042 sqlite3_bind_int(g
.pStmt
, 1, x1
);
1043 sqlite3_bind_int(g
.pStmt
, 2, x2
);
1046 speedtest1_exec("COMMIT");
1047 speedtest1_end_test();
1051 speedtest1_begin_test(280, "%d DELETEs of individual rows", n
);
1052 speedtest1_exec("BEGIN");
1054 "DELETE FROM t3 WHERE a=?1; -- %d times", n
1056 for(i
=1; i
<=n
; i
++){
1057 x1
= speedtest1_random()%sz
+ 1;
1058 sqlite3_bind_int(g
.pStmt
, 1, x1
);
1061 speedtest1_exec("COMMIT");
1062 speedtest1_end_test();
1065 speedtest1_begin_test(290, "Refill two %d-row tables using REPLACE", sz
);
1066 speedtest1_exec("REPLACE INTO z2(a,b,c) SELECT a,b,c FROM z1");
1067 speedtest1_exec("REPLACE INTO t3(a,b,c) SELECT a,b,c FROM z1");
1068 speedtest1_end_test();
1070 speedtest1_begin_test(300, "Refill a %d-row table using (b&1)==(a&1)", sz
);
1071 speedtest1_exec("DELETE FROM z2;");
1072 speedtest1_exec("INSERT INTO z2(a,b,c)\n"
1073 " SELECT a,b,c FROM z1 WHERE (b&1)==(a&1);");
1074 speedtest1_exec("INSERT INTO z2(a,b,c)\n"
1075 " SELECT a,b,c FROM z1 WHERE (b&1)<>(a&1);");
1076 speedtest1_end_test();
1080 speedtest1_begin_test(310, "%d four-ways joins", n
);
1081 speedtest1_exec("BEGIN");
1083 "SELECT z1.c FROM z1, z2, t3, t4\n"
1084 " WHERE t4.a BETWEEN ?1 AND ?2\n"
1089 for(i
=1; i
<=n
; i
++){
1090 x1
= speedtest1_random()%sz
+ 1;
1091 x2
= speedtest1_random()%10 + x1
+ 4;
1092 sqlite3_bind_int(g
.pStmt
, 1, x1
);
1093 sqlite3_bind_int(g
.pStmt
, 2, x2
);
1096 speedtest1_exec("COMMIT");
1097 speedtest1_end_test();
1099 speedtest1_begin_test(320, "subquery in result set", n
);
1101 "SELECT sum(a), max(c),\n"
1102 " avg((SELECT a FROM z2 WHERE 5+z2.b=z1.b) AND rowid<?1), max(c)\n"
1103 " FROM z1 WHERE rowid<?1;"
1105 sqlite3_bind_int(g
.pStmt
, 1, est_square_root(g
.szTest
)*50);
1107 speedtest1_end_test();
1109 sz
= n
= g
.szTest
*700;
1111 maxb
= roundup_allones(sz
/3);
1112 speedtest1_begin_test(400, "%d REPLACE ops on an IPK", n
);
1113 speedtest1_exec("BEGIN");
1114 speedtest1_exec("CREATE%s TABLE t5(a INTEGER PRIMARY KEY, b %s);",
1116 speedtest1_prepare("REPLACE INTO t5 VALUES(?1,?2); -- %d times",n
);
1117 for(i
=1; i
<=n
; i
++){
1118 x1
= swizzle(i
,maxb
);
1119 speedtest1_numbername(i
, zNum
, sizeof(zNum
));
1120 sqlite3_bind_int(g
.pStmt
, 1, (sqlite3_int64
)x1
);
1121 sqlite3_bind_text(g
.pStmt
, 2, zNum
, -1, SQLITE_STATIC
);
1124 speedtest1_exec("COMMIT");
1125 speedtest1_end_test();
1126 speedtest1_begin_test(410, "%d SELECTS on an IPK", n
);
1127 if( g
.doBigTransactions
){
1128 /* Historical note: tests 410 and 510 have historically not used
1129 ** explicit transactions. The --big-transactions flag was added
1130 ** 2022-09-08 to support the WASM/OPFS build, as the run-times
1131 ** approach 1 minute for each of these tests if they're not in an
1132 ** explicit transaction. The run-time effect of --big-transaciions
1133 ** on native builds is negligible. */
1134 speedtest1_exec("BEGIN");
1136 speedtest1_prepare("SELECT b FROM t5 WHERE a=?1; -- %d times",n
);
1137 for(i
=1; i
<=n
; i
++){
1138 x1
= swizzle(i
,maxb
);
1139 sqlite3_bind_int(g
.pStmt
, 1, (sqlite3_int64
)x1
);
1142 if( g
.doBigTransactions
){
1143 speedtest1_exec("COMMIT");
1145 speedtest1_end_test();
1147 sz
= n
= g
.szTest
*700;
1149 maxb
= roundup_allones(sz
/3);
1150 speedtest1_begin_test(500, "%d REPLACE on TEXT PK", n
);
1151 speedtest1_exec("BEGIN");
1152 speedtest1_exec("CREATE%s TABLE t6(a TEXT PRIMARY KEY, b %s)%s;",
1154 sqlite3_libversion_number()>=3008002 ? "WITHOUT ROWID" : "");
1155 speedtest1_prepare("REPLACE INTO t6 VALUES(?1,?2); -- %d times",n
);
1156 for(i
=1; i
<=n
; i
++){
1157 x1
= swizzle(i
,maxb
);
1158 speedtest1_numbername(x1
, zNum
, sizeof(zNum
));
1159 sqlite3_bind_int(g
.pStmt
, 2, i
);
1160 sqlite3_bind_text(g
.pStmt
, 1, zNum
, -1, SQLITE_STATIC
);
1163 speedtest1_exec("COMMIT");
1164 speedtest1_end_test();
1165 speedtest1_begin_test(510, "%d SELECTS on a TEXT PK", n
);
1166 if( g
.doBigTransactions
){
1167 /* See notes for test 410. */
1168 speedtest1_exec("BEGIN");
1170 speedtest1_prepare("SELECT b FROM t6 WHERE a=?1; -- %d times",n
);
1171 for(i
=1; i
<=n
; i
++){
1172 x1
= swizzle(i
,maxb
);
1173 speedtest1_numbername(x1
, zNum
, sizeof(zNum
));
1174 sqlite3_bind_text(g
.pStmt
, 1, zNum
, -1, SQLITE_STATIC
);
1177 if( g
.doBigTransactions
){
1178 speedtest1_exec("COMMIT");
1180 speedtest1_end_test();
1181 speedtest1_begin_test(520, "%d SELECT DISTINCT", n
);
1182 speedtest1_exec("SELECT DISTINCT b FROM t5;");
1183 speedtest1_exec("SELECT DISTINCT b FROM t6;");
1184 speedtest1_end_test();
1187 speedtest1_begin_test(980, "PRAGMA integrity_check");
1188 speedtest1_exec("PRAGMA integrity_check");
1189 speedtest1_end_test();
1192 speedtest1_begin_test(990, "ANALYZE");
1193 speedtest1_exec("ANALYZE");
1194 speedtest1_end_test();
1198 ** A testset for common table expressions. This exercises code
1199 ** for views, subqueries, co-routines, etc.
1201 void testset_cte(void){
1202 static const char *azPuzzle
[] = {
1242 }else if( g
.szTest
<70 ){
1247 speedtest1_begin_test(100, "Sudoku with recursive 'digits'");
1250 " input(sud) AS (VALUES(?1)),\n"
1251 " digits(z,lp) AS (\n"
1254 " SELECT CAST(lp+1 AS TEXT), lp+1 FROM digits WHERE lp<9\n"
1257 " SELECT sud, instr(sud, '.') FROM input\n"
1260 " substr(s, 1, ind-1) || z || substr(s, ind+1),\n"
1261 " instr( substr(s, 1, ind-1) || z || substr(s, ind+1), '.' )\n"
1262 " FROM x, digits AS z\n"
1264 " AND NOT EXISTS (\n"
1266 " FROM digits AS lp\n"
1267 " WHERE z.z = substr(s, ((ind-1)/9)*9 + lp, 1)\n"
1268 " OR z.z = substr(s, ((ind-1)%%9) + (lp-1)*9 + 1, 1)\n"
1269 " OR z.z = substr(s, (((ind-1)/3) %% 3) * 3\n"
1270 " + ((ind-1)/27) * 27 + lp\n"
1271 " + ((lp-1) / 3) * 6, 1)\n"
1274 "SELECT s FROM x WHERE ind=0;"
1276 sqlite3_bind_text(g
.pStmt
, 1, zPuz
, -1, SQLITE_STATIC
);
1278 speedtest1_end_test();
1280 speedtest1_begin_test(200, "Sudoku with VALUES 'digits'");
1283 " input(sud) AS (VALUES(?1)),\n"
1284 " digits(z,lp) AS (VALUES('1',1),('2',2),('3',3),('4',4),('5',5),\n"
1285 " ('6',6),('7',7),('8',8),('9',9)),\n"
1287 " SELECT sud, instr(sud, '.') FROM input\n"
1290 " substr(s, 1, ind-1) || z || substr(s, ind+1),\n"
1291 " instr( substr(s, 1, ind-1) || z || substr(s, ind+1), '.' )\n"
1292 " FROM x, digits AS z\n"
1294 " AND NOT EXISTS (\n"
1296 " FROM digits AS lp\n"
1297 " WHERE z.z = substr(s, ((ind-1)/9)*9 + lp, 1)\n"
1298 " OR z.z = substr(s, ((ind-1)%%9) + (lp-1)*9 + 1, 1)\n"
1299 " OR z.z = substr(s, (((ind-1)/3) %% 3) * 3\n"
1300 " + ((ind-1)/27) * 27 + lp\n"
1301 " + ((lp-1) / 3) * 6, 1)\n"
1304 "SELECT s FROM x WHERE ind=0;"
1306 sqlite3_bind_text(g
.pStmt
, 1, zPuz
, -1, SQLITE_STATIC
);
1308 speedtest1_end_test();
1310 rSpacing
= 5.0/g
.szTest
;
1311 speedtest1_begin_test(300, "Mandelbrot Set with spacing=%f", rSpacing
);
1314 " xaxis(x) AS (VALUES(-2.0) UNION ALL SELECT x+?1 FROM xaxis WHERE x<1.2),\n"
1315 " yaxis(y) AS (VALUES(-1.0) UNION ALL SELECT y+?2 FROM yaxis WHERE y<1.0),\n"
1316 " m(iter, cx, cy, x, y) AS (\n"
1317 " SELECT 0, x, y, 0.0, 0.0 FROM xaxis, yaxis\n"
1319 " SELECT iter+1, cx, cy, x*x-y*y + cx, 2.0*x*y + cy FROM m \n"
1320 " WHERE (x*x + y*y) < 4.0 AND iter<28\n"
1322 " m2(iter, cx, cy) AS (\n"
1323 " SELECT max(iter), cx, cy FROM m GROUP BY cx, cy\n"
1326 " SELECT group_concat( substr(' .+*#', 1+min(iter/7,4), 1), '') \n"
1327 " FROM m2 GROUP BY cy\n"
1329 "SELECT group_concat(rtrim(t),x'0a') FROM a;"
1331 sqlite3_bind_double(g
.pStmt
, 1, rSpacing
*.05);
1332 sqlite3_bind_double(g
.pStmt
, 2, rSpacing
);
1334 speedtest1_end_test();
1336 nElem
= 10000*g
.szTest
;
1337 speedtest1_begin_test(400, "EXCEPT operator on %d-element tables", nElem
);
1340 " z1(x) AS (VALUES(2) UNION ALL SELECT x+2 FROM z1 WHERE x<%d),\n"
1341 " z2(y) AS (VALUES(3) UNION ALL SELECT y+3 FROM z2 WHERE y<%d)\n"
1342 "SELECT count(x), avg(x) FROM (\n"
1343 " SELECT x FROM z1 EXCEPT SELECT y FROM z2 ORDER BY 1\n"
1348 speedtest1_end_test();
1352 ** Compute a pseudo-random floating point ascii number.
1354 void speedtest1_random_ascii_fp(char *zFP
){
1355 int x
= speedtest1_random();
1356 int y
= speedtest1_random();
1361 sqlite3_snprintf(100,zFP
,"%d.%de%d",y
,z
,x
%200);
1365 ** A testset for floating-point numbers.
1367 void testset_fp(void){
1374 speedtest1_begin_test(100, "Fill a table with %d FP values", n
*2);
1375 speedtest1_exec("BEGIN");
1376 speedtest1_exec("CREATE%s TABLE z1(a REAL %s, b REAL %s);",
1377 isTemp(1), g
.zNN
, g
.zNN
);
1378 speedtest1_prepare("INSERT INTO z1 VALUES(?1,?2); -- %d times", n
);
1379 for(i
=1; i
<=n
; i
++){
1380 speedtest1_random_ascii_fp(zFP1
);
1381 speedtest1_random_ascii_fp(zFP2
);
1382 sqlite3_bind_text(g
.pStmt
, 1, zFP1
, -1, SQLITE_STATIC
);
1383 sqlite3_bind_text(g
.pStmt
, 2, zFP2
, -1, SQLITE_STATIC
);
1386 speedtest1_exec("COMMIT");
1387 speedtest1_end_test();
1389 n
= g
.szTest
/25 + 2;
1390 speedtest1_begin_test(110, "%d range queries", n
);
1391 speedtest1_prepare("SELECT sum(b) FROM z1 WHERE a BETWEEN ?1 AND ?2");
1392 for(i
=1; i
<=n
; i
++){
1393 speedtest1_random_ascii_fp(zFP1
);
1394 speedtest1_random_ascii_fp(zFP2
);
1395 sqlite3_bind_text(g
.pStmt
, 1, zFP1
, -1, SQLITE_STATIC
);
1396 sqlite3_bind_text(g
.pStmt
, 2, zFP2
, -1, SQLITE_STATIC
);
1399 speedtest1_end_test();
1401 speedtest1_begin_test(120, "CREATE INDEX three times");
1402 speedtest1_exec("BEGIN;");
1403 speedtest1_exec("CREATE INDEX t1a ON z1(a);");
1404 speedtest1_exec("CREATE INDEX t1b ON z1(b);");
1405 speedtest1_exec("CREATE INDEX t1ab ON z1(a,b);");
1406 speedtest1_exec("COMMIT;");
1407 speedtest1_end_test();
1410 speedtest1_begin_test(130, "%d indexed range queries", n
);
1411 speedtest1_prepare("SELECT sum(b) FROM z1 WHERE a BETWEEN ?1 AND ?2");
1412 for(i
=1; i
<=n
; i
++){
1413 speedtest1_random_ascii_fp(zFP1
);
1414 speedtest1_random_ascii_fp(zFP2
);
1415 sqlite3_bind_text(g
.pStmt
, 1, zFP1
, -1, SQLITE_STATIC
);
1416 sqlite3_bind_text(g
.pStmt
, 2, zFP2
, -1, SQLITE_STATIC
);
1419 speedtest1_end_test();
1422 speedtest1_begin_test(140, "%d calls to round()", n
);
1423 speedtest1_exec("SELECT sum(round(a,2)+round(b,4)) FROM z1;");
1424 speedtest1_end_test();
1427 speedtest1_begin_test(150, "%d printf() calls", n
*4);
1429 "WITH c(fmt) AS (VALUES('%%g'),('%%e'),('%%!g'),('%%.20f'))"
1430 "SELECT sum(printf(fmt,a)) FROM z1, c"
1432 speedtest1_end_test();
1435 #ifdef SQLITE_ENABLE_RTREE
1436 /* Generate two numbers between 1 and mx. The first number is less than
1437 ** the second. Usually the numbers are near each other but can sometimes
1440 static void twoCoords(
1441 int p1
, int p2
, /* Parameters adjusting sizes */
1442 unsigned mx
, /* Range of 1..mx */
1443 unsigned *pX0
, unsigned *pX1
/* OUT: write results here */
1445 unsigned d
, x0
, x1
, span
;
1448 if( speedtest1_random()%3==0 ) span
*= p1
;
1449 if( speedtest1_random()%p2
==0 ) span
= mx
/2;
1450 d
= speedtest1_random()%span
+ 1;
1451 x0
= speedtest1_random()%(mx
-d
) + 1;
1458 #ifdef SQLITE_ENABLE_RTREE
1459 /* The following routine is an R-Tree geometry callback. It returns
1460 ** true if the object overlaps a slice on the Y coordinate between the
1461 ** two values given as arguments. In other words
1463 ** SELECT count(*) FROM rt1 WHERE id MATCH xslice(10,20);
1465 ** Is the same as saying:
1467 ** SELECT count(*) FROM rt1 WHERE y1>=10 AND y0<=20;
1469 static int xsliceGeometryCallback(
1470 sqlite3_rtree_geometry
*p
,
1475 *pRes
= aCoord
[3]>=p
->aParam
[0] && aCoord
[2]<=p
->aParam
[1];
1478 #endif /* SQLITE_ENABLE_RTREE */
1480 #ifdef SQLITE_ENABLE_RTREE
1482 ** A testset for the R-Tree virtual table
1484 void testset_rtree(int p1
, int p2
){
1487 unsigned x0
, x1
, y0
, y1
, z0
, z1
;
1490 int *aCheck
= sqlite3_malloc( sizeof(int)*g
.szTest
*500 );
1493 mxRowid
= n
= g
.szTest
*500;
1494 speedtest1_begin_test(100, "%d INSERTs into an r-tree", n
);
1495 speedtest1_exec("BEGIN");
1496 speedtest1_exec("CREATE VIRTUAL TABLE rt1 USING rtree(id,x0,x1,y0,y1,z0,z1)");
1497 speedtest1_prepare("INSERT INTO rt1(id,x0,x1,y0,y1,z0,z1)"
1498 "VALUES(?1,?2,?3,?4,?5,?6,?7)");
1499 for(i
=1; i
<=n
; i
++){
1500 twoCoords(p1
, p2
, mxCoord
, &x0
, &x1
);
1501 twoCoords(p1
, p2
, mxCoord
, &y0
, &y1
);
1502 twoCoords(p1
, p2
, mxCoord
, &z0
, &z1
);
1503 sqlite3_bind_int(g
.pStmt
, 1, i
);
1504 sqlite3_bind_int(g
.pStmt
, 2, x0
);
1505 sqlite3_bind_int(g
.pStmt
, 3, x1
);
1506 sqlite3_bind_int(g
.pStmt
, 4, y0
);
1507 sqlite3_bind_int(g
.pStmt
, 5, y1
);
1508 sqlite3_bind_int(g
.pStmt
, 6, z0
);
1509 sqlite3_bind_int(g
.pStmt
, 7, z1
);
1512 speedtest1_exec("COMMIT");
1513 speedtest1_end_test();
1515 speedtest1_begin_test(101, "Copy from rtree to a regular table");
1516 speedtest1_exec("CREATE TABLE z1(id INTEGER PRIMARY KEY,x0,x1,y0,y1,z0,z1)");
1517 speedtest1_exec("INSERT INTO z1 SELECT * FROM rt1");
1518 speedtest1_end_test();
1521 speedtest1_begin_test(110, "%d one-dimensional intersect slice queries", n
);
1522 speedtest1_prepare("SELECT count(*) FROM rt1 WHERE x0>=?1 AND x1<=?2");
1525 sqlite3_bind_int(g
.pStmt
, 1, i
*iStep
);
1526 sqlite3_bind_int(g
.pStmt
, 2, (i
+1)*iStep
);
1528 aCheck
[i
] = atoi(g
.zResult
);
1530 speedtest1_end_test();
1534 speedtest1_begin_test(111, "Verify result from 1-D intersect slice queries");
1535 speedtest1_prepare("SELECT count(*) FROM z1 WHERE x0>=?1 AND x1<=?2");
1538 sqlite3_bind_int(g
.pStmt
, 1, i
*iStep
);
1539 sqlite3_bind_int(g
.pStmt
, 2, (i
+1)*iStep
);
1541 if( aCheck
[i
]!=atoi(g
.zResult
) ){
1542 fatal_error("Count disagree step %d: %d..%d. %d vs %d",
1543 i
, i
*iStep
, (i
+1)*iStep
, aCheck
[i
], atoi(g
.zResult
));
1546 speedtest1_end_test();
1550 speedtest1_begin_test(120, "%d one-dimensional overlap slice queries", n
);
1551 speedtest1_prepare("SELECT count(*) FROM rt1 WHERE y1>=?1 AND y0<=?2");
1554 sqlite3_bind_int(g
.pStmt
, 1, i
*iStep
);
1555 sqlite3_bind_int(g
.pStmt
, 2, (i
+1)*iStep
);
1557 aCheck
[i
] = atoi(g
.zResult
);
1559 speedtest1_end_test();
1563 speedtest1_begin_test(121, "Verify result from 1-D overlap slice queries");
1564 speedtest1_prepare("SELECT count(*) FROM z1 WHERE y1>=?1 AND y0<=?2");
1567 sqlite3_bind_int(g
.pStmt
, 1, i
*iStep
);
1568 sqlite3_bind_int(g
.pStmt
, 2, (i
+1)*iStep
);
1570 if( aCheck
[i
]!=atoi(g
.zResult
) ){
1571 fatal_error("Count disagree step %d: %d..%d. %d vs %d",
1572 i
, i
*iStep
, (i
+1)*iStep
, aCheck
[i
], atoi(g
.zResult
));
1575 speedtest1_end_test();
1580 speedtest1_begin_test(125, "%d custom geometry callback queries", n
);
1581 sqlite3_rtree_geometry_callback(g
.db
, "xslice", xsliceGeometryCallback
, 0);
1582 speedtest1_prepare("SELECT count(*) FROM rt1 WHERE id MATCH xslice(?1,?2)");
1585 sqlite3_bind_int(g
.pStmt
, 1, i
*iStep
);
1586 sqlite3_bind_int(g
.pStmt
, 2, (i
+1)*iStep
);
1588 if( aCheck
[i
]!=atoi(g
.zResult
) ){
1589 fatal_error("Count disagree step %d: %d..%d. %d vs %d",
1590 i
, i
*iStep
, (i
+1)*iStep
, aCheck
[i
], atoi(g
.zResult
));
1593 speedtest1_end_test();
1596 speedtest1_begin_test(130, "%d three-dimensional intersect box queries", n
);
1597 speedtest1_prepare("SELECT count(*) FROM rt1 WHERE x1>=?1 AND x0<=?2"
1598 " AND y1>=?1 AND y0<=?2 AND z1>=?1 AND z0<=?2");
1601 sqlite3_bind_int(g
.pStmt
, 1, i
*iStep
);
1602 sqlite3_bind_int(g
.pStmt
, 2, (i
+1)*iStep
);
1604 aCheck
[i
] = atoi(g
.zResult
);
1606 speedtest1_end_test();
1609 speedtest1_begin_test(140, "%d rowid queries", n
);
1610 speedtest1_prepare("SELECT * FROM rt1 WHERE id=?1");
1611 for(i
=1; i
<=n
; i
++){
1612 sqlite3_bind_int(g
.pStmt
, 1, i
);
1615 speedtest1_end_test();
1618 speedtest1_begin_test(150, "%d UPDATEs using rowid", n
);
1619 speedtest1_prepare("UPDATE rt1 SET x0=x0+100, x1=x1+100 WHERE id=?1");
1620 for(i
=1; i
<=n
; i
++){
1621 sqlite3_bind_int(g
.pStmt
, 1, (i
*251)%mxRowid
+ 1);
1624 speedtest1_end_test();
1627 speedtest1_begin_test(155, "%d UPDATEs using one-dimensional overlap", n
);
1628 speedtest1_prepare("UPDATE rt1 SET x0=x0-100, x1=x1-100"
1629 " WHERE y1>=?1 AND y0<=?1+5");
1632 sqlite3_bind_int(g
.pStmt
, 1, i
*iStep
);
1634 aCheck
[i
] = atoi(g
.zResult
);
1636 speedtest1_end_test();
1639 speedtest1_begin_test(160, "%d DELETEs using rowid", n
);
1640 speedtest1_prepare("DELETE FROM rt1 WHERE id=?1");
1641 for(i
=1; i
<=n
; i
++){
1642 sqlite3_bind_int(g
.pStmt
, 1, (i
*257)%mxRowid
+ 1);
1645 speedtest1_end_test();
1649 speedtest1_begin_test(165, "%d DELETEs using one-dimensional overlap", n
);
1650 speedtest1_prepare("DELETE FROM rt1 WHERE y1>=?1 AND y0<=?1+5");
1653 sqlite3_bind_int(g
.pStmt
, 1, i
*iStep
);
1655 aCheck
[i
] = atoi(g
.zResult
);
1657 speedtest1_end_test();
1659 speedtest1_begin_test(170, "Restore deleted entries using INSERT OR IGNORE");
1660 speedtest1_exec("INSERT OR IGNORE INTO rt1 SELECT * FROM z1");
1661 speedtest1_end_test();
1663 #endif /* SQLITE_ENABLE_RTREE */
1666 ** A testset that does key/value storage on tables with many columns.
1667 ** This is the kind of workload generated by ORMs such as CoreData.
1669 void testset_orm(void){
1673 char zNum
[2000]; /* A number name */
1674 static const char zType
[] = /* Types for all non-PK columns, in order */
1675 "IBBIIITIVVITBTBFBFITTFBTBVBVIFTBBFITFFVBIFIVBVVVBTVTIBBFFIVIBTB"
1676 "TVTTFTVTVFFIITIFBITFTTFFFVBIIBTTITFTFFVVVFIIITVBBVFFTVVB";
1678 nRow
= n
= g
.szTest
*250;
1679 speedtest1_begin_test(100, "Fill %d rows", n
);
1682 "CREATE TABLE ZLOOKSLIKECOREDATA ("
1683 " ZPK INTEGER PRIMARY KEY,"
1684 " ZTERMFITTINGHOUSINGCOMMAND INTEGER,"
1685 " ZBRIEFGOBYDODGERHEIGHT BLOB,"
1686 " ZCAPABLETRIPDOORALMOND BLOB,"
1687 " ZDEPOSITPAIRCOLLEGECOMET INTEGER,"
1688 " ZFRAMEENTERSIMPLEMOUTH INTEGER,"
1689 " ZHOPEFULGATEHOLECHALK INTEGER,"
1690 " ZSLEEPYUSERGRANDBOWL TIMESTAMP,"
1691 " ZDEWPEACHCAREERCELERY INTEGER,"
1692 " ZHANGERLITHIUMDINNERMEET VARCHAR,"
1693 " ZCLUBRELEASELIZARDADVICE VARCHAR,"
1694 " ZCHARGECLICKHUMANEHIRE INTEGER,"
1695 " ZFINGERDUEPIZZAOPTION TIMESTAMP,"
1696 " ZFLYINGDOCTORTABLEMELODY BLOB,"
1697 " ZLONGFINLEAVEIMAGEOIL TIMESTAMP,"
1698 " ZFAMILYVISUALOWNERMATTER BLOB,"
1699 " ZGOLDYOUNGINITIALNOSE FLOAT,"
1700 " ZCAUSESALAMITERMCYAN BLOB,"
1701 " ZSPREADMOTORBISCUITBACON FLOAT,"
1702 " ZGIFTICEFISHGLUEHAIR INTEGER,"
1703 " ZNOTICEPEARPOLICYJUICE TIMESTAMP,"
1704 " ZBANKBUFFALORECOVERORBIT TIMESTAMP,"
1705 " ZLONGDIETESSAYNATURE FLOAT,"
1706 " ZACTIONRANGEELEGANTNEUTRON BLOB,"
1707 " ZCADETBRIGHTPLANETBANK TIMESTAMP,"
1708 " ZAIRFORGIVEHEADFROG BLOB,"
1709 " ZSHARKJUSTFRUITMOVIE VARCHAR,"
1710 " ZFARMERMORNINGMIRRORCONCERN BLOB,"
1711 " ZWOODPOETRYCOBBLERBENCH VARCHAR,"
1712 " ZHAFNIUMSCRIPTSALADMOTOR INTEGER,"
1713 " ZPROBLEMCLUBPOPOVERJELLY FLOAT,"
1714 " ZEIGHTLEADERWORKERMOST TIMESTAMP,"
1715 " ZGLASSRESERVEBARIUMMEAL BLOB,"
1716 " ZCLAMBITARUGULAFAJITA BLOB,"
1717 " ZDECADEJOYOUSWAVEHABIT FLOAT,"
1718 " ZCOMPANYSUMMERFIBERELF INTEGER,"
1719 " ZTREATTESTQUILLCHARGE TIMESTAMP,"
1720 " ZBROWBALANCEKEYCHOWDER FLOAT,"
1721 " ZPEACHCOPPERDINNERLAKE FLOAT,"
1722 " ZDRYWALLBEYONDBROWNBOWL VARCHAR,"
1723 " ZBELLYCRASHITEMLACK BLOB,"
1724 " ZTENNISCYCLEBILLOFFICER INTEGER,"
1725 " ZMALLEQUIPTHANKSGLUE FLOAT,"
1726 " ZMISSREPLYHUMANLIVING INTEGER,"
1727 " ZKIWIVISUALPRIDEAPPLE VARCHAR,"
1728 " ZWISHHITSKINMOTOR BLOB,"
1729 " ZCALMRACCOONPROGRAMDEBIT VARCHAR,"
1730 " ZSHINYASSISTLIVINGCRAB VARCHAR,"
1731 " ZRESOLVEWRISTWRAPAPPLE VARCHAR,"
1732 " ZAPPEALSIMPLESECONDHOUSING BLOB,"
1733 " ZCORNERANCHORTAPEDIVER TIMESTAMP,"
1734 " ZMEMORYREQUESTSOURCEBIG VARCHAR,"
1735 " ZTRYFACTKEEPMILK TIMESTAMP,"
1736 " ZDIVERPAINTLEATHEREASY INTEGER,"
1737 " ZSORTMISTYQUOTECABBAGE BLOB,"
1738 " ZTUNEGASBUFFALOCAPITAL BLOB,"
1739 " ZFILLSTOPLAWJOYFUL FLOAT,"
1740 " ZSTEELCAREFULPLATENUMBER FLOAT,"
1741 " ZGIVEVIVIDDIVINEMEANING INTEGER,"
1742 " ZTREATPACKFUTURECONVERT VARCHAR,"
1743 " ZCALMLYGEMFINISHEFFECT INTEGER,"
1744 " ZCABBAGESOCKEASEMINUTE BLOB,"
1745 " ZPLANETFAMILYPUREMEMORY TIMESTAMP,"
1746 " ZMERRYCRACKTRAINLEADER BLOB,"
1747 " ZMINORWAYPAPERCLASSY TIMESTAMP,"
1748 " ZEAGLELINEMINEMAIL VARCHAR,"
1749 " ZRESORTYARDGREENLET TIMESTAMP,"
1750 " ZYARDOREGANOVIVIDJEWEL TIMESTAMP,"
1751 " ZPURECAKEVIVIDNEATLY FLOAT,"
1752 " ZASKCONTACTMONITORFUN TIMESTAMP,"
1753 " ZMOVEWHOGAMMAINCH VARCHAR,"
1754 " ZLETTUCEBIRDMEETDEBATE TIMESTAMP,"
1755 " ZGENENATURALHEARINGKITE VARCHAR,"
1756 " ZMUFFINDRYERDRAWFORTUNE FLOAT,"
1757 " ZGRAYSURVEYWIRELOVE FLOAT,"
1758 " ZPLIERSPRINTASKOREGANO INTEGER,"
1759 " ZTRAVELDRIVERCONTESTLILY INTEGER,"
1760 " ZHUMORSPICESANDKIDNEY TIMESTAMP,"
1761 " ZARSENICSAMPLEWAITMUON INTEGER,"
1762 " ZLACEADDRESSGROUNDCAREFUL FLOAT,"
1763 " ZBAMBOOMESSWASABIEVENING BLOB,"
1764 " ZONERELEASEAVERAGENURSE INTEGER,"
1765 " ZRADIANTWHENTRYCARD TIMESTAMP,"
1766 " ZREWARDINSIDEMANGOINTENSE FLOAT,"
1767 " ZNEATSTEWPARTIRON TIMESTAMP,"
1768 " ZOUTSIDEPEAHENCOUNTICE TIMESTAMP,"
1769 " ZCREAMEVENINGLIPBRANCH FLOAT,"
1770 " ZWHALEMATHAVOCADOCOPPER FLOAT,"
1771 " ZLIFEUSELEAFYBELL FLOAT,"
1772 " ZWEALTHLINENGLEEFULDAY VARCHAR,"
1773 " ZFACEINVITETALKGOLD BLOB,"
1774 " ZWESTAMOUNTAFFECTHEARING INTEGER,"
1775 " ZDELAYOUTCOMEHORNAGENCY INTEGER,"
1776 " ZBIGTHINKCONVERTECONOMY BLOB,"
1777 " ZBASEGOUDAREGULARFORGIVE TIMESTAMP,"
1778 " ZPATTERNCLORINEGRANDCOLBY TIMESTAMP,"
1779 " ZCYANBASEFEEDADROIT INTEGER,"
1780 " ZCARRYFLOORMINNOWDRAGON TIMESTAMP,"
1781 " ZIMAGEPENCILOTHERBOTTOM FLOAT,"
1782 " ZXENONFLIGHTPALEAPPLE TIMESTAMP,"
1783 " ZHERRINGJOKEFEATUREHOPEFUL FLOAT,"
1784 " ZCAPYEARLYRIVETBRUSH FLOAT,"
1785 " ZAGEREEDFROGBASKET VARCHAR,"
1786 " ZUSUALBODYHALIBUTDIAMOND VARCHAR,"
1787 " ZFOOTTAPWORDENTRY VARCHAR,"
1788 " ZDISHKEEPBLESTMONITOR FLOAT,"
1789 " ZBROADABLESOLIDCASUAL INTEGER,"
1790 " ZSQUAREGLEEFULCHILDLIGHT INTEGER,"
1791 " ZHOLIDAYHEADPONYDETAIL INTEGER,"
1792 " ZGENERALRESORTSKYOPEN TIMESTAMP,"
1793 " ZGLADSPRAYKIDNEYGUPPY VARCHAR,"
1794 " ZSWIMHEAVYMENTIONKIND BLOB,"
1795 " ZMESSYSULFURDREAMFESTIVE BLOB,"
1796 " ZSKYSKYCLASSICBRIEF VARCHAR,"
1797 " ZDILLASKHOKILEMON FLOAT,"
1798 " ZJUNIORSHOWPRESSNOVA FLOAT,"
1799 " ZSIZETOEAWARDFRESH TIMESTAMP,"
1800 " ZKEYFAILAPRICOTMETAL VARCHAR,"
1801 " ZHANDYREPAIRPROTONAIRPORT VARCHAR,"
1802 " ZPOSTPROTEINHANDLEACTOR BLOB"
1806 "INSERT INTO ZLOOKSLIKECOREDATA(ZPK,ZAIRFORGIVEHEADFROG,"
1807 "ZGIFTICEFISHGLUEHAIR,ZDELAYOUTCOMEHORNAGENCY,ZSLEEPYUSERGRANDBOWL,"
1808 "ZGLASSRESERVEBARIUMMEAL,ZBRIEFGOBYDODGERHEIGHT,"
1809 "ZBAMBOOMESSWASABIEVENING,ZFARMERMORNINGMIRRORCONCERN,"
1810 "ZTREATPACKFUTURECONVERT,ZCAUSESALAMITERMCYAN,ZCALMRACCOONPROGRAMDEBIT,"
1811 "ZHOLIDAYHEADPONYDETAIL,ZWOODPOETRYCOBBLERBENCH,ZHAFNIUMSCRIPTSALADMOTOR,"
1812 "ZUSUALBODYHALIBUTDIAMOND,ZOUTSIDEPEAHENCOUNTICE,ZDIVERPAINTLEATHEREASY,"
1813 "ZWESTAMOUNTAFFECTHEARING,ZSIZETOEAWARDFRESH,ZDEWPEACHCAREERCELERY,"
1814 "ZSTEELCAREFULPLATENUMBER,ZCYANBASEFEEDADROIT,ZCALMLYGEMFINISHEFFECT,"
1815 "ZHANDYREPAIRPROTONAIRPORT,ZGENENATURALHEARINGKITE,ZBROADABLESOLIDCASUAL,"
1816 "ZPOSTPROTEINHANDLEACTOR,ZLACEADDRESSGROUNDCAREFUL,ZIMAGEPENCILOTHERBOTTOM,"
1817 "ZPROBLEMCLUBPOPOVERJELLY,ZPATTERNCLORINEGRANDCOLBY,ZNEATSTEWPARTIRON,"
1818 "ZAPPEALSIMPLESECONDHOUSING,ZMOVEWHOGAMMAINCH,ZTENNISCYCLEBILLOFFICER,"
1819 "ZSHARKJUSTFRUITMOVIE,ZKEYFAILAPRICOTMETAL,ZCOMPANYSUMMERFIBERELF,"
1820 "ZTERMFITTINGHOUSINGCOMMAND,ZRESORTYARDGREENLET,ZCABBAGESOCKEASEMINUTE,"
1821 "ZSQUAREGLEEFULCHILDLIGHT,ZONERELEASEAVERAGENURSE,ZBIGTHINKCONVERTECONOMY,"
1822 "ZPLIERSPRINTASKOREGANO,ZDECADEJOYOUSWAVEHABIT,ZDRYWALLBEYONDBROWNBOWL,"
1823 "ZCLUBRELEASELIZARDADVICE,ZWHALEMATHAVOCADOCOPPER,ZBELLYCRASHITEMLACK,"
1824 "ZLETTUCEBIRDMEETDEBATE,ZCAPABLETRIPDOORALMOND,ZRADIANTWHENTRYCARD,"
1825 "ZCAPYEARLYRIVETBRUSH,ZAGEREEDFROGBASKET,ZSWIMHEAVYMENTIONKIND,"
1826 "ZTRAVELDRIVERCONTESTLILY,ZGLADSPRAYKIDNEYGUPPY,ZBANKBUFFALORECOVERORBIT,"
1827 "ZFINGERDUEPIZZAOPTION,ZCLAMBITARUGULAFAJITA,ZLONGFINLEAVEIMAGEOIL,"
1828 "ZLONGDIETESSAYNATURE,ZJUNIORSHOWPRESSNOVA,ZHOPEFULGATEHOLECHALK,"
1829 "ZDEPOSITPAIRCOLLEGECOMET,ZWEALTHLINENGLEEFULDAY,ZFILLSTOPLAWJOYFUL,"
1830 "ZTUNEGASBUFFALOCAPITAL,ZGRAYSURVEYWIRELOVE,ZCORNERANCHORTAPEDIVER,"
1831 "ZREWARDINSIDEMANGOINTENSE,ZCADETBRIGHTPLANETBANK,ZPLANETFAMILYPUREMEMORY,"
1832 "ZTREATTESTQUILLCHARGE,ZCREAMEVENINGLIPBRANCH,ZSKYSKYCLASSICBRIEF,"
1833 "ZARSENICSAMPLEWAITMUON,ZBROWBALANCEKEYCHOWDER,ZFLYINGDOCTORTABLEMELODY,"
1834 "ZHANGERLITHIUMDINNERMEET,ZNOTICEPEARPOLICYJUICE,ZSHINYASSISTLIVINGCRAB,"
1835 "ZLIFEUSELEAFYBELL,ZFACEINVITETALKGOLD,ZGENERALRESORTSKYOPEN,"
1836 "ZPURECAKEVIVIDNEATLY,ZKIWIVISUALPRIDEAPPLE,ZMESSYSULFURDREAMFESTIVE,"
1837 "ZCHARGECLICKHUMANEHIRE,ZHERRINGJOKEFEATUREHOPEFUL,ZYARDOREGANOVIVIDJEWEL,"
1838 "ZFOOTTAPWORDENTRY,ZWISHHITSKINMOTOR,ZBASEGOUDAREGULARFORGIVE,"
1839 "ZMUFFINDRYERDRAWFORTUNE,ZACTIONRANGEELEGANTNEUTRON,ZTRYFACTKEEPMILK,"
1840 "ZPEACHCOPPERDINNERLAKE,ZFRAMEENTERSIMPLEMOUTH,ZMERRYCRACKTRAINLEADER,"
1841 "ZMEMORYREQUESTSOURCEBIG,ZCARRYFLOORMINNOWDRAGON,ZMINORWAYPAPERCLASSY,"
1842 "ZDILLASKHOKILEMON,ZRESOLVEWRISTWRAPAPPLE,ZASKCONTACTMONITORFUN,"
1843 "ZGIVEVIVIDDIVINEMEANING,ZEIGHTLEADERWORKERMOST,ZMISSREPLYHUMANLIVING,"
1844 "ZXENONFLIGHTPALEAPPLE,ZSORTMISTYQUOTECABBAGE,ZEAGLELINEMINEMAIL,"
1845 "ZFAMILYVISUALOWNERMATTER,ZSPREADMOTORBISCUITBACON,ZDISHKEEPBLESTMONITOR,"
1846 "ZMALLEQUIPTHANKSGLUE,ZGOLDYOUNGINITIALNOSE,ZHUMORSPICESANDKIDNEY)"
1847 "VALUES(?1,?26,?20,?93,?8,?33,?3,?81,?28,?60,?18,?47,?109,?29,?30,?104,?86,"
1848 "?54,?92,?117,?9,?58,?97,?61,?119,?73,?107,?120,?80,?99,?31,?96,?85,?50,?71,"
1849 "?42,?27,?118,?36,?2,?67,?62,?108,?82,?94,?76,?35,?40,?11,?88,?41,?72,?4,"
1850 "?83,?102,?103,?112,?77,?111,?22,?13,?34,?15,?23,?116,?7,?5,?90,?57,?56,"
1851 "?75,?51,?84,?25,?63,?37,?87,?114,?79,?38,?14,?10,?21,?48,?89,?91,?110,"
1852 "?69,?45,?113,?12,?101,?68,?105,?46,?95,?74,?24,?53,?39,?6,?64,?52,?98,"
1853 "?65,?115,?49,?70,?59,?32,?44,?100,?55,?66,?16,?19,?106,?43,?17,?78);"
1856 x1
= speedtest1_random();
1857 speedtest1_numbername(x1
%1000, zNum
, sizeof(zNum
));
1858 len
= (int)strlen(zNum
);
1859 sqlite3_bind_int(g
.pStmt
, 1, i
^0xf);
1860 for(j
=0; zType
[j
]; j
++){
1864 sqlite3_bind_int64(g
.pStmt
, j
+2, x1
);
1867 sqlite3_bind_double(g
.pStmt
, j
+2, (double)x1
);
1871 sqlite3_bind_text64(g
.pStmt
, j
+2, zNum
, len
,
1872 SQLITE_STATIC
, SQLITE_UTF8
);
1878 speedtest1_exec("COMMIT;");
1879 speedtest1_end_test();
1882 speedtest1_begin_test(110, "Query %d rows by rowid", n
);
1884 "SELECT ZCYANBASEFEEDADROIT,ZJUNIORSHOWPRESSNOVA,ZCAUSESALAMITERMCYAN,"
1885 "ZHOPEFULGATEHOLECHALK,ZHUMORSPICESANDKIDNEY,ZSWIMHEAVYMENTIONKIND,"
1886 "ZMOVEWHOGAMMAINCH,ZAPPEALSIMPLESECONDHOUSING,ZHAFNIUMSCRIPTSALADMOTOR,"
1887 "ZNEATSTEWPARTIRON,ZLONGFINLEAVEIMAGEOIL,ZDEWPEACHCAREERCELERY,"
1888 "ZXENONFLIGHTPALEAPPLE,ZCALMRACCOONPROGRAMDEBIT,ZUSUALBODYHALIBUTDIAMOND,"
1889 "ZTRYFACTKEEPMILK,ZWEALTHLINENGLEEFULDAY,ZLONGDIETESSAYNATURE,"
1890 "ZLIFEUSELEAFYBELL,ZTREATPACKFUTURECONVERT,ZMEMORYREQUESTSOURCEBIG,"
1891 "ZYARDOREGANOVIVIDJEWEL,ZDEPOSITPAIRCOLLEGECOMET,ZSLEEPYUSERGRANDBOWL,"
1892 "ZBRIEFGOBYDODGERHEIGHT,ZCLUBRELEASELIZARDADVICE,ZCAPABLETRIPDOORALMOND,"
1893 "ZDRYWALLBEYONDBROWNBOWL,ZASKCONTACTMONITORFUN,ZKIWIVISUALPRIDEAPPLE,"
1894 "ZNOTICEPEARPOLICYJUICE,ZPEACHCOPPERDINNERLAKE,ZSTEELCAREFULPLATENUMBER,"
1895 "ZGLADSPRAYKIDNEYGUPPY,ZCOMPANYSUMMERFIBERELF,ZTENNISCYCLEBILLOFFICER,"
1896 "ZIMAGEPENCILOTHERBOTTOM,ZWESTAMOUNTAFFECTHEARING,ZDIVERPAINTLEATHEREASY,"
1897 "ZSKYSKYCLASSICBRIEF,ZMESSYSULFURDREAMFESTIVE,ZMERRYCRACKTRAINLEADER,"
1898 "ZBROADABLESOLIDCASUAL,ZGLASSRESERVEBARIUMMEAL,ZTUNEGASBUFFALOCAPITAL,"
1899 "ZBANKBUFFALORECOVERORBIT,ZTREATTESTQUILLCHARGE,ZBAMBOOMESSWASABIEVENING,"
1900 "ZREWARDINSIDEMANGOINTENSE,ZEAGLELINEMINEMAIL,ZCALMLYGEMFINISHEFFECT,"
1901 "ZKEYFAILAPRICOTMETAL,ZFINGERDUEPIZZAOPTION,ZCADETBRIGHTPLANETBANK,"
1902 "ZGOLDYOUNGINITIALNOSE,ZMISSREPLYHUMANLIVING,ZEIGHTLEADERWORKERMOST,"
1903 "ZFRAMEENTERSIMPLEMOUTH,ZBIGTHINKCONVERTECONOMY,ZFACEINVITETALKGOLD,"
1904 "ZPOSTPROTEINHANDLEACTOR,ZHERRINGJOKEFEATUREHOPEFUL,ZCABBAGESOCKEASEMINUTE,"
1905 "ZMUFFINDRYERDRAWFORTUNE,ZPROBLEMCLUBPOPOVERJELLY,ZGIVEVIVIDDIVINEMEANING,"
1906 "ZGENENATURALHEARINGKITE,ZGENERALRESORTSKYOPEN,ZLETTUCEBIRDMEETDEBATE,"
1907 "ZBASEGOUDAREGULARFORGIVE,ZCHARGECLICKHUMANEHIRE,ZPLANETFAMILYPUREMEMORY,"
1908 "ZMINORWAYPAPERCLASSY,ZCAPYEARLYRIVETBRUSH,ZSIZETOEAWARDFRESH,"
1909 "ZARSENICSAMPLEWAITMUON,ZSQUAREGLEEFULCHILDLIGHT,ZSHINYASSISTLIVINGCRAB,"
1910 "ZCORNERANCHORTAPEDIVER,ZDECADEJOYOUSWAVEHABIT,ZTRAVELDRIVERCONTESTLILY,"
1911 "ZFLYINGDOCTORTABLEMELODY,ZSHARKJUSTFRUITMOVIE,ZFAMILYVISUALOWNERMATTER,"
1912 "ZFARMERMORNINGMIRRORCONCERN,ZGIFTICEFISHGLUEHAIR,ZOUTSIDEPEAHENCOUNTICE,"
1913 "ZSPREADMOTORBISCUITBACON,ZWISHHITSKINMOTOR,ZHOLIDAYHEADPONYDETAIL,"
1914 "ZWOODPOETRYCOBBLERBENCH,ZAIRFORGIVEHEADFROG,ZBROWBALANCEKEYCHOWDER,"
1915 "ZDISHKEEPBLESTMONITOR,ZCLAMBITARUGULAFAJITA,ZPLIERSPRINTASKOREGANO,"
1916 "ZRADIANTWHENTRYCARD,ZDELAYOUTCOMEHORNAGENCY,ZPURECAKEVIVIDNEATLY,"
1917 "ZPATTERNCLORINEGRANDCOLBY,ZHANDYREPAIRPROTONAIRPORT,ZAGEREEDFROGBASKET,"
1918 "ZSORTMISTYQUOTECABBAGE,ZFOOTTAPWORDENTRY,ZRESOLVEWRISTWRAPAPPLE,"
1919 "ZDILLASKHOKILEMON,ZFILLSTOPLAWJOYFUL,ZACTIONRANGEELEGANTNEUTRON,"
1920 "ZRESORTYARDGREENLET,ZCREAMEVENINGLIPBRANCH,ZWHALEMATHAVOCADOCOPPER,"
1921 "ZGRAYSURVEYWIRELOVE,ZBELLYCRASHITEMLACK,ZHANGERLITHIUMDINNERMEET,"
1922 "ZCARRYFLOORMINNOWDRAGON,ZMALLEQUIPTHANKSGLUE,ZTERMFITTINGHOUSINGCOMMAND,"
1923 "ZONERELEASEAVERAGENURSE,ZLACEADDRESSGROUNDCAREFUL"
1924 " FROM ZLOOKSLIKECOREDATA WHERE ZPK=?1;"
1927 x1
= speedtest1_random()%nRow
;
1928 sqlite3_bind_int(g
.pStmt
, 1, x1
);
1931 speedtest1_end_test();
1936 void testset_trigger(void){
1938 char zNum
[2000]; /* A number name */
1940 const int NROW
= 500*g
.szTest
;
1941 const int NROW2
= 100*g
.szTest
;
1945 "CREATE TABLE z1(rowid INTEGER PRIMARY KEY, i INTEGER, t TEXT);"
1946 "CREATE TABLE z2(rowid INTEGER PRIMARY KEY, i INTEGER, t TEXT);"
1947 "CREATE TABLE t3(rowid INTEGER PRIMARY KEY, i INTEGER, t TEXT);"
1948 "CREATE VIEW v1 AS SELECT rowid, i, t FROM z1;"
1949 "CREATE VIEW v2 AS SELECT rowid, i, t FROM z2;"
1950 "CREATE VIEW v3 AS SELECT rowid, i, t FROM t3;"
1952 for(jj
=1; jj
<=3; jj
++){
1953 speedtest1_prepare("INSERT INTO t%d VALUES(NULL,?1,?2)", jj
);
1954 for(ii
=0; ii
<NROW
; ii
++){
1955 int x1
= speedtest1_random() % NROW
;
1956 speedtest1_numbername(x1
, zNum
, sizeof(zNum
));
1957 sqlite3_bind_int(g
.pStmt
, 1, x1
);
1958 sqlite3_bind_text(g
.pStmt
, 2, zNum
, -1, SQLITE_STATIC
);
1963 "CREATE INDEX i1 ON z1(t);"
1964 "CREATE INDEX i2 ON z2(t);"
1965 "CREATE INDEX i3 ON t3(t);"
1969 speedtest1_begin_test(100, "speed4p-join1");
1971 "SELECT * FROM z1, z2, t3 WHERE z1.oid = z2.oid AND z2.oid = t3.oid"
1974 speedtest1_end_test();
1976 speedtest1_begin_test(110, "speed4p-join2");
1978 "SELECT * FROM z1, z2, t3 WHERE z1.t = z2.t AND z2.t = t3.t"
1981 speedtest1_end_test();
1983 speedtest1_begin_test(120, "speed4p-view1");
1984 for(jj
=1; jj
<=3; jj
++){
1985 speedtest1_prepare("SELECT * FROM v%d WHERE rowid = ?", jj
);
1986 for(ii
=0; ii
<NROW2
; ii
+=3){
1987 sqlite3_bind_int(g
.pStmt
, 1, ii
*3);
1991 speedtest1_end_test();
1993 speedtest1_begin_test(130, "speed4p-table1");
1994 for(jj
=1; jj
<=3; jj
++){
1995 speedtest1_prepare("SELECT * FROM t%d WHERE rowid = ?", jj
);
1996 for(ii
=0; ii
<NROW2
; ii
+=3){
1997 sqlite3_bind_int(g
.pStmt
, 1, ii
*3);
2001 speedtest1_end_test();
2003 speedtest1_begin_test(140, "speed4p-table1");
2004 for(jj
=1; jj
<=3; jj
++){
2005 speedtest1_prepare("SELECT * FROM t%d WHERE rowid = ?", jj
);
2006 for(ii
=0; ii
<NROW2
; ii
+=3){
2007 sqlite3_bind_int(g
.pStmt
, 1, ii
*3);
2011 speedtest1_end_test();
2013 speedtest1_begin_test(150, "speed4p-subselect1");
2014 speedtest1_prepare("SELECT "
2015 "(SELECT t FROM z1 WHERE rowid = ?1),"
2016 "(SELECT t FROM z2 WHERE rowid = ?1),"
2017 "(SELECT t FROM t3 WHERE rowid = ?1)"
2019 for(jj
=0; jj
<NROW2
; jj
++){
2020 sqlite3_bind_int(g
.pStmt
, 1, jj
*3);
2023 speedtest1_end_test();
2025 speedtest1_begin_test(160, "speed4p-rowid-update");
2026 speedtest1_exec("BEGIN");
2027 speedtest1_prepare("UPDATE z1 SET i=i+1 WHERE rowid=?1");
2028 for(jj
=0; jj
<NROW2
; jj
++){
2029 sqlite3_bind_int(g
.pStmt
, 1, jj
);
2032 speedtest1_exec("COMMIT");
2033 speedtest1_end_test();
2035 speedtest1_exec("CREATE TABLE t5(t TEXT PRIMARY KEY, i INTEGER);");
2036 speedtest1_begin_test(170, "speed4p-insert-ignore");
2037 speedtest1_exec("INSERT OR IGNORE INTO t5 SELECT t, i FROM z1");
2038 speedtest1_end_test();
2041 "CREATE TABLE log(op TEXT, r INTEGER, i INTEGER, t TEXT);"
2042 "CREATE TABLE t4(rowid INTEGER PRIMARY KEY, i INTEGER, t TEXT);"
2043 "CREATE TRIGGER t4_trigger1 AFTER INSERT ON t4 BEGIN"
2044 " INSERT INTO log VALUES('INSERT INTO t4', new.rowid, new.i, new.t);"
2046 "CREATE TRIGGER t4_trigger2 AFTER UPDATE ON t4 BEGIN"
2047 " INSERT INTO log VALUES('UPDATE OF t4', new.rowid, new.i, new.t);"
2049 "CREATE TRIGGER t4_trigger3 AFTER DELETE ON t4 BEGIN"
2050 " INSERT INTO log VALUES('DELETE OF t4', old.rowid, old.i, old.t);"
2055 speedtest1_begin_test(180, "speed4p-trigger1");
2056 speedtest1_prepare("INSERT INTO t4 VALUES(NULL, ?1, ?2)");
2057 for(jj
=0; jj
<NROW2
; jj
++){
2058 speedtest1_numbername(jj
, zNum
, sizeof(zNum
));
2059 sqlite3_bind_int(g
.pStmt
, 1, jj
);
2060 sqlite3_bind_text(g
.pStmt
, 2, zNum
, -1, SQLITE_STATIC
);
2063 speedtest1_end_test();
2066 ** Note: Of the queries, only half actually update a row. This property
2067 ** was copied over from speed4p.test, where it was probably introduced
2070 speedtest1_begin_test(190, "speed4p-trigger2");
2071 speedtest1_prepare("UPDATE t4 SET i = ?1, t = ?2 WHERE rowid = ?3");
2072 for(jj
=1; jj
<=NROW2
*2; jj
+=2){
2073 speedtest1_numbername(jj
*2, zNum
, sizeof(zNum
));
2074 sqlite3_bind_int(g
.pStmt
, 1, jj
*2);
2075 sqlite3_bind_text(g
.pStmt
, 2, zNum
, -1, SQLITE_STATIC
);
2076 sqlite3_bind_int(g
.pStmt
, 3, jj
);
2079 speedtest1_end_test();
2082 ** Note: Same again.
2084 speedtest1_begin_test(200, "speed4p-trigger3");
2085 speedtest1_prepare("DELETE FROM t4 WHERE rowid = ?1");
2086 for(jj
=1; jj
<=NROW2
*2; jj
+=2){
2087 sqlite3_bind_int(g
.pStmt
, 1, jj
*2);
2090 speedtest1_end_test();
2091 speedtest1_exec("COMMIT");
2094 ** The following block contains the same tests as the above block that
2095 ** tests triggers, with one crucial difference: no triggers are defined.
2096 ** So the difference in speed between these tests and the preceding ones
2097 ** is the amount of time taken to compile and execute the trigger programs.
2103 "CREATE TABLE t4(rowid INTEGER PRIMARY KEY, i INTEGER, t TEXT);"
2106 speedtest1_begin_test(210, "speed4p-notrigger1");
2107 speedtest1_prepare("INSERT INTO t4 VALUES(NULL, ?1, ?2)");
2108 for(jj
=0; jj
<NROW2
; jj
++){
2109 speedtest1_numbername(jj
, zNum
, sizeof(zNum
));
2110 sqlite3_bind_int(g
.pStmt
, 1, jj
);
2111 sqlite3_bind_text(g
.pStmt
, 2, zNum
, -1, SQLITE_STATIC
);
2114 speedtest1_end_test();
2115 speedtest1_begin_test(210, "speed4p-notrigger2");
2116 speedtest1_prepare("UPDATE t4 SET i = ?1, t = ?2 WHERE rowid = ?3");
2117 for(jj
=1; jj
<=NROW2
*2; jj
+=2){
2118 speedtest1_numbername(jj
*2, zNum
, sizeof(zNum
));
2119 sqlite3_bind_int(g
.pStmt
, 1, jj
*2);
2120 sqlite3_bind_text(g
.pStmt
, 2, zNum
, -1, SQLITE_STATIC
);
2121 sqlite3_bind_int(g
.pStmt
, 3, jj
);
2124 speedtest1_end_test();
2125 speedtest1_begin_test(220, "speed4p-notrigger3");
2126 speedtest1_prepare("DELETE FROM t4 WHERE rowid = ?1");
2127 for(jj
=1; jj
<=NROW2
*2; jj
+=2){
2128 sqlite3_bind_int(g
.pStmt
, 1, jj
*2);
2131 speedtest1_end_test();
2132 speedtest1_exec("COMMIT");
2136 ** A testset used for debugging speedtest1 itself.
2138 void testset_debug1(void){
2141 char zNum
[2000]; /* A number name */
2144 for(i
=1; i
<=n
; i
++){
2146 x2
= swizzle(x1
, n
);
2147 speedtest1_numbername(x1
, zNum
, sizeof(zNum
));
2148 printf("%5d %5d %5d %s\n", i
, x1
, x2
, zNum
);
2153 #include <sys/types.h>
2157 ** Attempt to display I/O stats on Linux using /proc/PID/io
2159 static void displayLinuxIoStats(FILE *out
){
2162 sqlite3_snprintf(sizeof(z
), z
, "/proc/%d/io", getpid());
2163 in
= fopen(z
, "rb");
2165 while( fgets(z
, sizeof(z
), in
)!=0 ){
2166 static const struct {
2167 const char *zPattern
;
2170 { "rchar: ", "Bytes received by read():" },
2171 { "wchar: ", "Bytes sent to write():" },
2172 { "syscr: ", "Read() system calls:" },
2173 { "syscw: ", "Write() system calls:" },
2174 { "read_bytes: ", "Bytes rcvd from storage:" },
2175 { "write_bytes: ", "Bytes sent to storage:" },
2176 { "cancelled_write_bytes: ", "Cancelled write bytes:" },
2179 for(i
=0; i
<sizeof(aTrans
)/sizeof(aTrans
[0]); i
++){
2180 int n
= (int)strlen(aTrans
[i
].zPattern
);
2181 if( strncmp(aTrans
[i
].zPattern
, z
, n
)==0 ){
2182 fprintf(out
, "-- %-28s %s", aTrans
[i
].zDesc
, &z
[n
]);
2191 #if SQLITE_VERSION_NUMBER<3006018
2192 # define sqlite3_sourceid(X) "(before 3.6.18)"
2195 #if SQLITE_CKSUMVFS_STATIC
2196 int sqlite3_register_cksumvfs(const char*);
2199 static int xCompileOptions(void *pCtx
, int nVal
, char **azVal
, char **azCol
){
2200 printf("-- Compile option: %s\n", azVal
[0]);
2203 int main(int argc
, char **argv
){
2204 int doAutovac
= 0; /* True for --autovacuum */
2205 int cacheSize
= 0; /* Desired cache size. 0 means default */
2206 int doExclusive
= 0; /* True for --exclusive */
2207 int doFullFSync
= 0; /* True for --fullfsync */
2208 int nHeap
= 0, mnHeap
= 0; /* Heap size from --heap */
2209 int doIncrvac
= 0; /* True for --incrvacuum */
2210 const char *zJMode
= 0; /* Journal mode */
2211 const char *zKey
= 0; /* Encryption key */
2212 int nLook
= -1, szLook
= 0; /* --lookaside configuration */
2213 int noSync
= 0; /* True for --nosync */
2214 int pageSize
= 0; /* Desired page size. 0 means default */
2215 int nPCache
= 0, szPCache
= 0;/* --pcache configuration */
2216 int doPCache
= 0; /* True if --pcache is seen */
2217 int showStats
= 0; /* True for --stats */
2218 int nThread
= 0; /* --threads value */
2219 int mmapSize
= 0; /* How big of a memory map to use */
2220 int memDb
= 0; /* --memdb. Use an in-memory database */
2221 int openFlags
= SQLITE_OPEN_READWRITE
| SQLITE_OPEN_CREATE
2222 ; /* SQLITE_OPEN_xxx flags. */
2223 char *zTSet
= "main"; /* Which --testset torun */
2224 const char * zVfs
= 0; /* --vfs NAME */
2225 int doTrace
= 0; /* True for --trace */
2226 const char *zEncoding
= 0; /* --utf16be or --utf16le */
2227 const char *zDbName
= 0; /* Name of the test database */
2229 void *pHeap
= 0; /* Allocated heap space */
2230 void *pLook
= 0; /* Allocated lookaside space */
2231 void *pPCache
= 0; /* Allocated storage for pcache */
2232 int iCur
, iHi
; /* Stats values, current and "highwater" */
2233 int i
; /* Loop counter */
2234 int rc
; /* API return code */
2236 #ifdef SQLITE_SPEEDTEST1_WASM
2237 /* Resetting all state is important for the WASM build, which may
2238 ** call main() multiple times. */
2239 memset(&g
, 0, sizeof(g
));
2242 #ifdef SQLITE_CKSUMVFS_STATIC
2243 sqlite3_register_cksumvfs(0);
2246 ** Confirms that argc has at least N arguments following argv[i]. */
2247 #define ARGC_VALUE_CHECK(N) \
2248 if( i>=argc-(N) ) fatal_error("missing argument on %s\n", argv[i])
2249 /* Display the version of SQLite being tested */
2250 printf("-- Speedtest1 for SQLite %s %.48s\n",
2251 sqlite3_libversion(), sqlite3_sourceid());
2253 /* Process command-line arguments */
2259 for(i
=1; i
<argc
; i
++){
2260 const char *z
= argv
[i
];
2262 do{ z
++; }while( z
[0]=='-' );
2263 if( strcmp(z
,"autovacuum")==0 ){
2265 }else if( strcmp(z
,"big-transactions")==0 ){
2266 g
.doBigTransactions
= 1;
2267 }else if( strcmp(z
,"cachesize")==0 ){
2268 ARGC_VALUE_CHECK(1);
2269 cacheSize
= integerValue(argv
[++i
]);
2270 }else if( strcmp(z
,"exclusive")==0 ){
2272 }else if( strcmp(z
,"fullfsync")==0 ){
2274 }else if( strcmp(z
,"checkpoint")==0 ){
2276 }else if( strcmp(z
,"explain")==0 ){
2279 }else if( strcmp(z
,"heap")==0 ){
2280 ARGC_VALUE_CHECK(2);
2281 nHeap
= integerValue(argv
[i
+1]);
2282 mnHeap
= integerValue(argv
[i
+2]);
2284 }else if( strcmp(z
,"incrvacuum")==0 ){
2286 }else if( strcmp(z
,"journal")==0 ){
2287 ARGC_VALUE_CHECK(1);
2289 }else if( strcmp(z
,"key")==0 ){
2290 ARGC_VALUE_CHECK(1);
2292 }else if( strcmp(z
,"lookaside")==0 ){
2293 ARGC_VALUE_CHECK(2);
2294 nLook
= integerValue(argv
[i
+1]);
2295 szLook
= integerValue(argv
[i
+2]);
2297 }else if( strcmp(z
,"memdb")==0 ){
2299 #if SQLITE_VERSION_NUMBER>=3006000
2300 }else if( strcmp(z
,"multithread")==0 ){
2301 sqlite3_config(SQLITE_CONFIG_MULTITHREAD
);
2302 }else if( strcmp(z
,"nomemstat")==0 ){
2303 sqlite3_config(SQLITE_CONFIG_MEMSTATUS
, 0);
2305 #if SQLITE_VERSION_NUMBER>=3007017
2306 }else if( strcmp(z
, "mmap")==0 ){
2307 ARGC_VALUE_CHECK(1);
2308 mmapSize
= integerValue(argv
[++i
]);
2310 }else if( strcmp(z
,"nomutex")==0 ){
2311 openFlags
|= SQLITE_OPEN_NOMUTEX
;
2312 }else if( strcmp(z
,"nosync")==0 ){
2314 }else if( strcmp(z
,"notnull")==0 ){
2316 }else if( strcmp(z
,"output")==0 ){
2317 #ifdef SPEEDTEST_OMIT_HASH
2318 fatal_error("The --output option is not supported with"
2319 " -DSPEEDTEST_OMIT_HASH\n");
2321 ARGC_VALUE_CHECK(1);
2323 if( strcmp(argv
[i
],"-")==0 ){
2324 g
.hashFile
= stdout
;
2326 g
.hashFile
= fopen(argv
[i
], "wb");
2327 if( g
.hashFile
==0 ){
2328 fatal_error("cannot open \"%s\" for writing\n", argv
[i
]);
2332 }else if( strcmp(z
,"pagesize")==0 ){
2333 ARGC_VALUE_CHECK(1);
2334 pageSize
= integerValue(argv
[++i
]);
2335 }else if( strcmp(z
,"pcache")==0 ){
2336 ARGC_VALUE_CHECK(2);
2337 nPCache
= integerValue(argv
[i
+1]);
2338 szPCache
= integerValue(argv
[i
+2]);
2341 }else if( strcmp(z
,"primarykey")==0 ){
2342 g
.zPK
= "PRIMARY KEY";
2343 }else if( strcmp(z
,"repeat")==0 ){
2344 ARGC_VALUE_CHECK(1);
2345 g
.nRepeat
= integerValue(argv
[++i
]);
2346 }else if( strcmp(z
,"reprepare")==0 ){
2348 #if SQLITE_VERSION_NUMBER>=3006000
2349 }else if( strcmp(z
,"serialized")==0 ){
2350 sqlite3_config(SQLITE_CONFIG_SERIALIZED
);
2351 }else if( strcmp(z
,"singlethread")==0 ){
2352 sqlite3_config(SQLITE_CONFIG_SINGLETHREAD
);
2354 }else if( strcmp(z
,"script")==0 ){
2355 ARGC_VALUE_CHECK(1);
2356 if( g
.pScript
) fclose(g
.pScript
);
2357 g
.pScript
= fopen(argv
[++i
], "wb");
2359 fatal_error("unable to open output file \"%s\"\n", argv
[i
]);
2361 }else if( strcmp(z
,"sqlonly")==0 ){
2363 }else if( strcmp(z
,"shrink-memory")==0 ){
2365 }else if( strcmp(z
,"size")==0 ){
2366 ARGC_VALUE_CHECK(1);
2367 g
.szTest
= integerValue(argv
[++i
]);
2368 }else if( strcmp(z
,"stats")==0 ){
2370 }else if( strcmp(z
,"temp")==0 ){
2371 ARGC_VALUE_CHECK(1);
2373 if( argv
[i
][0]<'0' || argv
[i
][0]>'9' || argv
[i
][1]!=0 ){
2374 fatal_error("argument to --temp should be integer between 0 and 9");
2376 g
.eTemp
= argv
[i
][0] - '0';
2377 }else if( strcmp(z
,"testset")==0 ){
2378 ARGC_VALUE_CHECK(1);
2380 }else if( strcmp(z
,"trace")==0 ){
2382 }else if( strcmp(z
,"threads")==0 ){
2383 ARGC_VALUE_CHECK(1);
2384 nThread
= integerValue(argv
[++i
]);
2385 }else if( strcmp(z
,"utf16le")==0 ){
2386 zEncoding
= "utf16le";
2387 }else if( strcmp(z
,"utf16be")==0 ){
2388 zEncoding
= "utf16be";
2389 }else if( strcmp(z
,"verify")==0 ){
2391 #ifndef SPEEDTEST_OMIT_HASH
2394 }else if( strcmp(z
,"vfs")==0 ){
2395 ARGC_VALUE_CHECK(1);
2397 }else if( strcmp(z
,"reserve")==0 ){
2398 ARGC_VALUE_CHECK(1);
2399 g
.nReserve
= atoi(argv
[++i
]);
2400 }else if( strcmp(z
,"stmtscanstatus")==0 ){
2401 g
.stmtScanStatus
= 1;
2402 }else if( strcmp(z
,"without-rowid")==0 ){
2403 if( strstr(g
.zWR
,"WITHOUT")!=0 ){
2405 }else if( strstr(g
.zWR
,"STRICT")!=0 ){
2406 g
.zWR
= "WITHOUT ROWID,STRICT";
2408 g
.zWR
= "WITHOUT ROWID";
2410 g
.zPK
= "PRIMARY KEY";
2411 }else if( strcmp(z
,"strict")==0 ){
2412 if( strstr(g
.zWR
,"STRICT")!=0 ){
2414 }else if( strstr(g
.zWR
,"WITHOUT")!=0 ){
2415 g
.zWR
= "WITHOUT ROWID,STRICT";
2419 }else if( strcmp(z
, "help")==0 || strcmp(z
,"?")==0 ){
2420 printf(zHelp
, argv
[0]);
2423 fatal_error("unknown option: %s\nUse \"%s -?\" for help\n",
2426 }else if( zDbName
==0 ){
2429 fatal_error("surplus argument: %s\nUse \"%s -?\" for help\n",
2433 #undef ARGC_VALUE_CHECK
2434 #if SQLITE_VERSION_NUMBER>=3006001
2436 pHeap
= malloc( nHeap
);
2437 if( pHeap
==0 ) fatal_error("cannot allocate %d-byte heap\n", nHeap
);
2438 rc
= sqlite3_config(SQLITE_CONFIG_HEAP
, pHeap
, nHeap
, mnHeap
);
2439 if( rc
) fatal_error("heap configuration failed: %d\n", rc
);
2442 if( nPCache
>0 && szPCache
>0 ){
2443 pPCache
= malloc( nPCache
*(sqlite3_int64
)szPCache
);
2444 if( pPCache
==0 ) fatal_error("cannot allocate %lld-byte pcache\n",
2445 nPCache
*(sqlite3_int64
)szPCache
);
2447 rc
= sqlite3_config(SQLITE_CONFIG_PAGECACHE
, pPCache
, szPCache
, nPCache
);
2448 if( rc
) fatal_error("pcache configuration failed: %d\n", rc
);
2451 sqlite3_config(SQLITE_CONFIG_LOOKASIDE
, 0, 0);
2454 sqlite3_initialize();
2457 sqlite3_vfs
*pVfs
= sqlite3_vfs_find(zVfs
);
2458 /* For some VFSes, e.g. opfs, unlink() is not sufficient. Use the
2459 ** selected (or default) VFS's xDelete method to delete the
2460 ** database. This is specifically important for the "opfs" VFS
2461 ** when running from a WASM build of speedtest1, so that the db
2462 ** can be cleaned up properly. For historical compatibility, we'll
2463 ** also simply unlink(). */
2465 pVfs
->xDelete(pVfs
, zDbName
, 1);
2470 /* Open the database and the input file */
2471 if( sqlite3_open_v2(memDb
? ":memory:" : zDbName
, &g
.db
,
2473 fatal_error("Cannot open database file: %s\n", zDbName
);
2475 #if SQLITE_VERSION_NUMBER>=3006001
2476 if( nLook
>0 && szLook
>0 ){
2477 pLook
= malloc( nLook
*szLook
);
2478 rc
= sqlite3_db_config(g
.db
, SQLITE_DBCONFIG_LOOKASIDE
,pLook
,szLook
,nLook
);
2479 if( rc
) fatal_error("lookaside configuration failed: %d\n", rc
);
2483 sqlite3_file_control(g
.db
, 0, SQLITE_FCNTL_RESERVE_BYTES
, &g
.nReserve
);
2485 if( g
.stmtScanStatus
){
2486 sqlite3_db_config(g
.db
, SQLITE_DBCONFIG_STMT_SCANSTATUS
, 1, 0);
2489 /* Set database connection options */
2490 sqlite3_create_function(g
.db
, "random", 0, SQLITE_UTF8
, 0, randomFunc
, 0, 0);
2491 #ifndef SQLITE_OMIT_DEPRECATED
2492 if( doTrace
) sqlite3_trace(g
.db
, traceCallback
, 0);
2495 speedtest1_exec("PRAGMA temp_store=memory");
2498 speedtest1_exec("PRAGMA mmap_size=%d", mmapSize
);
2500 speedtest1_exec("PRAGMA threads=%d", nThread
);
2502 speedtest1_exec("PRAGMA key('%s')", zKey
);
2505 speedtest1_exec("PRAGMA encoding=%s", zEncoding
);
2508 speedtest1_exec("PRAGMA auto_vacuum=FULL");
2509 }else if( doIncrvac
){
2510 speedtest1_exec("PRAGMA auto_vacuum=INCREMENTAL");
2513 speedtest1_exec("PRAGMA page_size=%d", pageSize
);
2516 speedtest1_exec("PRAGMA cache_size=%d", cacheSize
);
2519 speedtest1_exec("PRAGMA synchronous=OFF");
2520 }else if( doFullFSync
){
2521 speedtest1_exec("PRAGMA fullfsync=ON");
2524 speedtest1_exec("PRAGMA locking_mode=EXCLUSIVE");
2527 speedtest1_exec("PRAGMA journal_mode=%s", zJMode
);
2530 if( g
.bExplain
) printf(".explain\n.echo on\n");
2532 char *zThisTest
= zTSet
;
2533 char *zComma
= strchr(zThisTest
,',');
2540 if( g
.iTotal
>0 || zComma
!=0 ){
2541 printf(" Begin testset \"%s\"\n", zThisTest
);
2543 if( strcmp(zThisTest
,"main")==0 ){
2545 }else if( strcmp(zThisTest
,"debug1")==0 ){
2547 }else if( strcmp(zThisTest
,"orm")==0 ){
2549 }else if( strcmp(zThisTest
,"cte")==0 ){
2551 }else if( strcmp(zThisTest
,"fp")==0 ){
2553 }else if( strcmp(zThisTest
,"trigger")==0 ){
2555 }else if( strcmp(zThisTest
,"rtree")==0 ){
2556 #ifdef SQLITE_ENABLE_RTREE
2557 testset_rtree(6, 147);
2559 fatal_error("compile with -DSQLITE_ENABLE_RTREE to enable "
2560 "the R-Tree tests\n");
2563 fatal_error("unknown testset: \"%s\"\n"
2564 "Choices: cte debug1 fp main orm rtree trigger\n",
2569 speedtest1_begin_test(999, "Reset the database");
2571 zObj
= speedtest1_once(
2572 "SELECT name FROM main.sqlite_master"
2573 " WHERE sql LIKE 'CREATE %%TABLE%%'");
2574 if( zObj
==0 ) break;
2575 zSql
= sqlite3_mprintf("DROP TABLE main.\"%w\"", zObj
);
2576 speedtest1_exec(zSql
);
2581 zObj
= speedtest1_once(
2582 "SELECT name FROM temp.sqlite_master"
2583 " WHERE sql LIKE 'CREATE %%TABLE%%'");
2584 if( zObj
==0 ) break;
2585 zSql
= sqlite3_mprintf("DROP TABLE main.\"%w\"", zObj
);
2586 speedtest1_exec(zSql
);
2590 speedtest1_end_test();
2596 sqlite3_exec(g
.db
, "PRAGMA compile_options", xCompileOptions
, 0, 0);
2599 /* Database connection statistics printed after both prepared statements
2600 ** have been finalized */
2601 #if SQLITE_VERSION_NUMBER>=3007009
2603 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_LOOKASIDE_USED
, &iCur
, &iHi
, 0);
2604 printf("-- Lookaside Slots Used: %d (max %d)\n", iCur
,iHi
);
2605 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_LOOKASIDE_HIT
, &iCur
, &iHi
, 0);
2606 printf("-- Successful lookasides: %d\n", iHi
);
2607 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE
, &iCur
,&iHi
,0);
2608 printf("-- Lookaside size faults: %d\n", iHi
);
2609 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL
, &iCur
,&iHi
,0);
2610 printf("-- Lookaside OOM faults: %d\n", iHi
);
2611 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_CACHE_USED
, &iCur
, &iHi
, 0);
2612 printf("-- Pager Heap Usage: %d bytes\n", iCur
);
2613 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_CACHE_HIT
, &iCur
, &iHi
, 1);
2614 printf("-- Page cache hits: %d\n", iCur
);
2615 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_CACHE_MISS
, &iCur
, &iHi
, 1);
2616 printf("-- Page cache misses: %d\n", iCur
);
2617 #if SQLITE_VERSION_NUMBER>=3007012
2618 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_CACHE_WRITE
, &iCur
, &iHi
, 1);
2619 printf("-- Page cache writes: %d\n", iCur
);
2621 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_SCHEMA_USED
, &iCur
, &iHi
, 0);
2622 printf("-- Schema Heap Usage: %d bytes\n", iCur
);
2623 sqlite3_db_status(g
.db
, SQLITE_DBSTATUS_STMT_USED
, &iCur
, &iHi
, 0);
2624 printf("-- Statement Heap Usage: %d bytes\n", iCur
);
2628 sqlite3_close(g
.db
);
2630 #if SQLITE_VERSION_NUMBER>=3006001
2631 /* Global memory usage statistics printed after the database connection
2632 ** has closed. Memory usage should be zero at this point. */
2634 sqlite3_status(SQLITE_STATUS_MEMORY_USED
, &iCur
, &iHi
, 0);
2635 printf("-- Memory Used (bytes): %d (max %d)\n", iCur
,iHi
);
2636 #if SQLITE_VERSION_NUMBER>=3007000
2637 sqlite3_status(SQLITE_STATUS_MALLOC_COUNT
, &iCur
, &iHi
, 0);
2638 printf("-- Outstanding Allocations: %d (max %d)\n", iCur
,iHi
);
2640 sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW
, &iCur
, &iHi
, 0);
2641 printf("-- Pcache Overflow Bytes: %d (max %d)\n", iCur
,iHi
);
2642 sqlite3_status(SQLITE_STATUS_MALLOC_SIZE
, &iCur
, &iHi
, 0);
2643 printf("-- Largest Allocation: %d bytes\n",iHi
);
2644 sqlite3_status(SQLITE_STATUS_PAGECACHE_SIZE
, &iCur
, &iHi
, 0);
2645 printf("-- Largest Pcache Allocation: %d bytes\n",iHi
);
2651 displayLinuxIoStats(stdout
);
2658 /* Release memory */
2665 #ifdef SQLITE_SPEEDTEST1_WASM
2667 ** A workaround for some inconsistent behaviour with how
2668 ** main() does (or does not) get exported to WASM.
2670 int wasm_main(int argc
, char **argv
){
2671 return main(argc
, argv
);