~ubuntu-branches/ubuntu/precise/sqlite3/precise-updates

« back to all changes in this revision

Viewing changes to test/analyze2.test

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2009-12-11 14:34:09 UTC
  • mfrom: (9.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091211143409-o29fahwmcmyd0vq1
Tags: 3.6.21-2
Run autoreconf to prevent FTBFS with new libtool (closes: #560660).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# 2009 August 06
 
2
#
 
3
# The author disclaims copyright to this source code.  In place of
 
4
# a legal notice, here is a blessing:
 
5
#
 
6
#    May you do good and not evil.
 
7
#    May you find forgiveness for yourself and forgive others.
 
8
#    May you share freely, never taking more than you give.
 
9
#
 
10
#***********************************************************************
 
11
#
 
12
# This file implements regression tests for SQLite library. This file 
 
13
# implements tests for the extra functionality provided by the ANALYZE 
 
14
# command when the library is compiled with SQLITE_ENABLE_STAT2 defined.
 
15
#
 
16
 
 
17
set testdir [file dirname $argv0]
 
18
source $testdir/tester.tcl
 
19
 
 
20
ifcapable !stat2 {
 
21
  finish_test
 
22
  return
 
23
}
 
24
 
 
25
#--------------------------------------------------------------------
 
26
# Test organization:
 
27
#
 
28
# analyze2-1.*: Tests to verify that ANALYZE creates and populates the
 
29
#               sqlite_stat2 table as expected.
 
30
#
 
31
# analyze2-2.*: Test that when a table has two indexes on it and either
 
32
#               index may be used for the scan, the index suggested by
 
33
#               the contents of sqlite_stat2 table is prefered.
 
34
 
35
# analyze2-3.*: Similar to the previous block of tests, but using tables
 
36
#               that contain a mixture of NULL, numeric, text and blob
 
37
#               values.
 
38
#
 
39
# analyze2-4.*: Check that when an indexed column uses a collation other
 
40
#               than BINARY, the collation is taken into account when
 
41
#               using the contents of sqlite_stat2 to estimate the cost
 
42
#               of a range scan.
 
43
#
 
44
# analyze2-5.*: Check that collation sequences are used as described above
 
45
#               even when the only available version of the collation 
 
46
#               function require UTF-16 encoded arguments.
 
47
#
 
48
# analyze2-6.*: Check that the library behaves correctly when one of the
 
49
#               sqlite_stat2 or sqlite_stat1 tables are missing.
 
50
#
 
51
# analyze2-7.*: Check that in a shared-schema situation, nothing goes
 
52
#               wrong if sqlite_stat2 data is read by one connection,
 
53
#               and freed by another.
 
54
 
55
 
 
56
proc eqp {sql {db db}} {
 
57
  uplevel execsql [list "EXPLAIN QUERY PLAN $sql"] $db
 
58
}
 
59
 
 
60
do_test analyze2-1.1 {
 
61
  execsql { CREATE TABLE t1(x PRIMARY KEY) }
 
62
  for {set i 0} {$i < 1000} {incr i} {
 
63
    execsql { INSERT INTO t1 VALUES($i) }
 
64
  }
 
65
  execsql { 
 
66
    ANALYZE;
 
67
    SELECT * FROM sqlite_stat2;
 
68
  }
 
69
} [list t1 sqlite_autoindex_t1_1 0 50  \
 
70
        t1 sqlite_autoindex_t1_1 1 149 \
 
71
        t1 sqlite_autoindex_t1_1 2 249 \
 
72
        t1 sqlite_autoindex_t1_1 3 349 \
 
73
        t1 sqlite_autoindex_t1_1 4 449 \
 
74
        t1 sqlite_autoindex_t1_1 5 549 \
 
75
        t1 sqlite_autoindex_t1_1 6 649 \
 
76
        t1 sqlite_autoindex_t1_1 7 749 \
 
77
        t1 sqlite_autoindex_t1_1 8 849 \
 
78
        t1 sqlite_autoindex_t1_1 9 949 \
 
79
]
 
80
 
 
81
do_test analyze2-1.2 {
 
82
  execsql {
 
83
    DELETE FROM t1 WHERe x>9;
 
84
    ANALYZE;
 
85
    SELECT tbl, idx, group_concat(sample, ' ') FROM sqlite_stat2;
 
86
  }
 
87
} {t1 sqlite_autoindex_t1_1 {0 1 2 3 4 5 6 7 8 9}}
 
88
do_test analyze2-1.3 {
 
89
  execsql {
 
90
    DELETE FROM t1 WHERE x>8;
 
91
    ANALYZE;
 
92
    SELECT * FROM sqlite_stat2;
 
93
  }
 
94
} {}
 
95
do_test analyze2-1.4 {
 
96
  execsql {
 
97
    DELETE FROM t1;
 
98
    ANALYZE;
 
99
    SELECT * FROM sqlite_stat2;
 
100
  }
 
101
} {}
 
102
 
 
103
do_test analyze2-2.1 {
 
104
  execsql { 
 
105
    BEGIN;
 
106
    DROP TABLE t1;
 
107
    CREATE TABLE t1(x, y);
 
108
    CREATE INDEX t1_x ON t1(x);
 
109
    CREATE INDEX t1_y ON t1(y);
 
110
  }
 
111
  for {set i 0} {$i < 1000} {incr i} {
 
112
    execsql { INSERT INTO t1 VALUES($i, $i) }
 
113
  }
 
114
  execsql COMMIT
 
115
  execsql ANALYZE
 
116
} {}
 
117
do_test analyze2-2.2 {
 
118
  eqp "SELECT * FROM t1 WHERE x>500 AND y>700"
 
119
} {0 0 {TABLE t1 WITH INDEX t1_y}}
 
120
do_test analyze2-2.3 {
 
121
  eqp "SELECT * FROM t1 WHERE x>700 AND y>500"
 
122
} {0 0 {TABLE t1 WITH INDEX t1_x}}
 
123
do_test analyze2-2.3 {
 
124
  eqp "SELECT * FROM t1 WHERE y>700 AND x>500"
 
125
} {0 0 {TABLE t1 WITH INDEX t1_y}}
 
126
do_test analyze2-2.4 {
 
127
  eqp "SELECT * FROM t1 WHERE y>500 AND x>700"
 
128
} {0 0 {TABLE t1 WITH INDEX t1_x}}
 
129
do_test analyze2-2.5 {
 
130
  eqp "SELECT * FROM t1 WHERE x BETWEEN 100 AND 200 AND y BETWEEN 400 AND 700"
 
131
} {0 0 {TABLE t1 WITH INDEX t1_x}}
 
132
do_test analyze2-2.6 {
 
133
  eqp "SELECT * FROM t1 WHERE x BETWEEN 100 AND 500 AND y BETWEEN 400 AND 700"
 
134
} {0 0 {TABLE t1 WITH INDEX t1_y}}
 
135
do_test analyze2-2.7 {
 
136
  eqp "SELECT * FROM t1 WHERE x BETWEEN -400 AND -300 AND y BETWEEN 100 AND 300"
 
137
} {0 0 {TABLE t1 WITH INDEX t1_x}}
 
138
do_test analyze2-2.8 {
 
139
  eqp "SELECT * FROM t1 WHERE x BETWEEN 100 AND 300 AND y BETWEEN -400 AND -300"
 
140
} {0 0 {TABLE t1 WITH INDEX t1_y}}
 
141
do_test analyze2-2.9 {
 
142
  eqp "SELECT * FROM t1 WHERE x BETWEEN 500 AND 100 AND y BETWEEN 100 AND 300"
 
143
} {0 0 {TABLE t1 WITH INDEX t1_x}}
 
144
do_test analyze2-2.10 {
 
145
  eqp "SELECT * FROM t1 WHERE x BETWEEN 100 AND 300 AND y BETWEEN 500 AND 100"
 
146
} {0 0 {TABLE t1 WITH INDEX t1_y}}
 
147
 
 
148
do_test analyze2-3.1 {
 
149
  set alphabet [list a b c d e f g h i j]
 
150
  execsql BEGIN
 
151
  for {set i 0} {$i < 1000} {incr i} {
 
152
    set str    [lindex $alphabet [expr ($i/100)%10]] 
 
153
    append str [lindex $alphabet [expr ($i/ 10)%10]]
 
154
    append str [lindex $alphabet [expr ($i/  1)%10]]
 
155
    execsql { INSERT INTO t1 VALUES($str, $str) }
 
156
  }
 
157
  execsql COMMIT
 
158
  execsql ANALYZE
 
159
  execsql { 
 
160
    SELECT tbl,idx,group_concat(sample,' ') 
 
161
    FROM sqlite_stat2 
 
162
    WHERE idx = 't1_x' 
 
163
    GROUP BY tbl,idx
 
164
  }
 
165
} {t1 t1_x {100 299 499 699 899 ajj cjj ejj gjj ijj}}
 
166
do_test analyze2-3.2 {
 
167
  execsql { 
 
168
    SELECT tbl,idx,group_concat(sample,' ') 
 
169
    FROM sqlite_stat2 
 
170
    WHERE idx = 't1_y' 
 
171
    GROUP BY tbl,idx
 
172
  }
 
173
} {t1 t1_y {100 299 499 699 899 ajj cjj ejj gjj ijj}}
 
174
 
 
175
do_test analyze2-3.3 {
 
176
  eqp "SELECT * FROM t1 WHERE x BETWEEN 100 AND 500 AND y BETWEEN 'a' AND 'b'"
 
177
} {0 0 {TABLE t1 WITH INDEX t1_y}}
 
178
do_test analyze2-3.4 {
 
179
  eqp "SELECT * FROM t1 WHERE x BETWEEN 100 AND 400 AND y BETWEEN 'a' AND 'h'"
 
180
} {0 0 {TABLE t1 WITH INDEX t1_x}}
 
181
do_test analyze2-3.5 {
 
182
  eqp "SELECT * FROM t1 WHERE x<'a' AND y>'h'"
 
183
} {0 0 {TABLE t1 WITH INDEX t1_y}}
 
184
do_test analyze2-3.6 {
 
185
  eqp "SELECT * FROM t1 WHERE x<444 AND y>'h'"
 
186
} {0 0 {TABLE t1 WITH INDEX t1_y}}
 
187
do_test analyze2-3.7 {
 
188
  eqp "SELECT * FROM t1 WHERE x<221 AND y>'g'"
 
189
} {0 0 {TABLE t1 WITH INDEX t1_x}}
 
190
 
 
191
do_test analyze2-4.1 {
 
192
  execsql { CREATE TABLE t3(a COLLATE nocase, b) }
 
193
  execsql { CREATE INDEX t3a ON t3(a) }
 
194
  execsql { CREATE INDEX t3b ON t3(b) }
 
195
  set alphabet [list A b C d E f G h I j]
 
196
  execsql BEGIN
 
197
  for {set i 0} {$i < 1000} {incr i} {
 
198
    set str    [lindex $alphabet [expr ($i/100)%10]] 
 
199
    append str [lindex $alphabet [expr ($i/ 10)%10]]
 
200
    append str [lindex $alphabet [expr ($i/  1)%10]]
 
201
    execsql { INSERT INTO t3 VALUES($str, $str) }
 
202
  }
 
203
  execsql COMMIT
 
204
  execsql ANALYZE
 
205
} {}
 
206
do_test analyze2-4.2 {
 
207
  execsql { 
 
208
    SELECT tbl,idx,group_concat(sample,' ') 
 
209
    FROM sqlite_stat2 
 
210
    WHERE idx = 't3a' 
 
211
    GROUP BY tbl,idx
 
212
  }
 
213
} {t3 t3a {AfA bEj CEj dEj EEj fEj GEj hEj IEj jEj}}
 
214
do_test analyze2-4.3 {
 
215
  execsql { 
 
216
    SELECT tbl,idx,group_concat(sample,' ') 
 
217
    FROM sqlite_stat2 
 
218
    WHERE idx = 't3b' 
 
219
    GROUP BY tbl,idx
 
220
  }
 
221
} {t3 t3b {AbA CIj EIj GIj IIj bIj dIj fIj hIj jIj}}
 
222
 
 
223
do_test analyze2-4.4 {
 
224
  eqp "SELECT * FROM t3 WHERE a > 'A' AND a < 'C' AND b > 'A' AND b < 'C'"
 
225
} {0 0 {TABLE t3 WITH INDEX t3b}}
 
226
do_test analyze2-4.5 {
 
227
  eqp "SELECT * FROM t3 WHERE a > 'A' AND a < 'c' AND b > 'A' AND b < 'c'"
 
228
} {0 0 {TABLE t3 WITH INDEX t3a}}
 
229
 
 
230
ifcapable utf16 {
 
231
  proc test_collate {enc lhs rhs} {
 
232
    # puts $enc
 
233
    return [string compare $lhs $rhs]
 
234
  }
 
235
  do_test analyze2-5.1 {
 
236
    add_test_collate db 0 0 1
 
237
    execsql { CREATE TABLE t4(x COLLATE test_collate) }
 
238
    execsql { CREATE INDEX t4x ON t4(x) }
 
239
    set alphabet [list a b c d e f g h i j]
 
240
    execsql BEGIN
 
241
    for {set i 0} {$i < 1000} {incr i} {
 
242
      set str    [lindex $alphabet [expr ($i/100)%10]] 
 
243
      append str [lindex $alphabet [expr ($i/ 10)%10]]
 
244
      append str [lindex $alphabet [expr ($i/  1)%10]]
 
245
      execsql { INSERT INTO t4 VALUES($str) }
 
246
    }
 
247
    execsql COMMIT
 
248
    execsql ANALYZE
 
249
  } {}
 
250
  do_test analyze2-5.2 {
 
251
    execsql { 
 
252
      SELECT tbl,idx,group_concat(sample,' ') 
 
253
      FROM sqlite_stat2 
 
254
      WHERE tbl = 't4' 
 
255
      GROUP BY tbl,idx
 
256
    }
 
257
  } {t4 t4x {afa bej cej dej eej fej gej hej iej jej}}
 
258
  do_test analyze2-5.3 {
 
259
    eqp "SELECT * FROM t4 WHERE x>'ccc'"
 
260
  } {0 0 {TABLE t4 WITH INDEX t4x}}
 
261
  do_test analyze2-5.4 {
 
262
    eqp "SELECT * FROM t4 AS t41, t4 AS t42 WHERE t41.x>'ccc' AND t42.x>'ggg'"
 
263
  } {0 1 {TABLE t4 AS t42 WITH INDEX t4x} 1 0 {TABLE t4 AS t41 WITH INDEX t4x}}
 
264
  do_test analyze2-5.5 {
 
265
    eqp "SELECT * FROM t4 AS t41, t4 AS t42 WHERE t41.x>'ddd' AND t42.x>'ccc'"
 
266
  } {0 0 {TABLE t4 AS t41 WITH INDEX t4x} 1 1 {TABLE t4 AS t42 WITH INDEX t4x}}
 
267
}
 
268
 
 
269
#--------------------------------------------------------------------
 
270
# These tests, analyze2-6.*, verify that the library behaves correctly
 
271
# when one of the sqlite_stat1 and sqlite_stat2 tables is missing.
 
272
#
 
273
# If the sqlite_stat1 table is not present, then the sqlite_stat2
 
274
# table is not read. However, if it is the sqlite_stat2 table that
 
275
# is missing, the data in the sqlite_stat1 table is still used.
 
276
#
 
277
# Tests analyze2-6.1.* test the libary when the sqlite_stat2 table
 
278
# is missing. Tests analyze2-6.2.* test the library when sqlite_stat1
 
279
# is not present.
 
280
#
 
281
do_test analyze2-6.0 {
 
282
  execsql {
 
283
    DROP TABLE IF EXISTS t4;
 
284
    CREATE TABLE t5(a, b); CREATE INDEX t5i ON t5(a, b);
 
285
    CREATE TABLE t6(a, b); CREATE INDEX t6i ON t6(a, b);
 
286
  }
 
287
  for {set ii 0} {$ii < 20} {incr ii} {
 
288
    execsql {
 
289
      INSERT INTO t5 VALUES($ii, $ii);
 
290
      INSERT INTO t6 VALUES($ii/10, $ii/10);
 
291
    }
 
292
  }
 
293
  execsql { 
 
294
    CREATE TABLE master AS 
 
295
    SELECT * FROM sqlite_master WHERE name LIKE 'sqlite_stat%' 
 
296
  }
 
297
} {}
 
298
 
 
299
do_test analyze2-6.1.1 {
 
300
  eqp {SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
301
       t5.a = 1 AND
 
302
       t6.a = 1 AND t6.b = 1
 
303
  }
 
304
} {0 1 {TABLE t6 WITH INDEX t6i} 1 0 {TABLE t5 USING PRIMARY KEY}}
 
305
do_test analyze2-6.1.2 {
 
306
  db cache flush
 
307
  execsql ANALYZE
 
308
  eqp {SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
309
       t5.a = 1 AND
 
310
       t6.a = 1 AND t6.b = 1
 
311
  }
 
312
} {0 0 {TABLE t5 WITH INDEX t5i} 1 1 {TABLE t6 USING PRIMARY KEY}}
 
313
do_test analyze2-6.1.3 {
 
314
  sqlite3 db test.db
 
315
  eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
316
       t5.a = 1 AND
 
317
       t6.a = 1 AND t6.b = 1
 
318
  }
 
319
} {0 0 {TABLE t5 WITH INDEX t5i} 1 1 {TABLE t6 USING PRIMARY KEY}}
 
320
do_test analyze2-6.1.4 {
 
321
  execsql { 
 
322
    PRAGMA writable_schema = 1;
 
323
    DELETE FROM sqlite_master WHERE tbl_name = 'sqlite_stat2';
 
324
  }
 
325
  sqlite3 db test.db
 
326
  eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
327
       t5.a = 1 AND
 
328
       t6.a = 1 AND t6.b = 1
 
329
  }
 
330
} {0 0 {TABLE t5 WITH INDEX t5i} 1 1 {TABLE t6 USING PRIMARY KEY}}
 
331
do_test analyze2-6.1.5 {
 
332
  execsql { 
 
333
    PRAGMA writable_schema = 1;
 
334
    DELETE FROM sqlite_master WHERE tbl_name = 'sqlite_stat1';
 
335
  }
 
336
  sqlite3 db test.db
 
337
  eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
338
       t5.a = 1 AND
 
339
       t6.a = 1 AND t6.b = 1
 
340
  }
 
341
} {0 1 {TABLE t6 WITH INDEX t6i} 1 0 {TABLE t5 USING PRIMARY KEY}}
 
342
do_test analyze2-6.1.6 {
 
343
  execsql { 
 
344
    PRAGMA writable_schema = 1;
 
345
    INSERT INTO sqlite_master SELECT * FROM master;
 
346
  }
 
347
  sqlite3 db test.db
 
348
  eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
349
       t5.a = 1 AND
 
350
       t6.a = 1 AND t6.b = 1
 
351
  }
 
352
} {0 0 {TABLE t5 WITH INDEX t5i} 1 1 {TABLE t6 USING PRIMARY KEY}}
 
353
 
 
354
do_test analyze2-6.2.1 {
 
355
  execsql { 
 
356
    DELETE FROM sqlite_stat1;
 
357
    DELETE FROM sqlite_stat2;
 
358
  }
 
359
  sqlite3 db test.db
 
360
  eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
361
        t5.a>1 AND t5.a<15 AND
 
362
        t6.a>1
 
363
  }
 
364
} {0 0 {TABLE t5 WITH INDEX t5i} 1 1 {TABLE t6 USING PRIMARY KEY}}
 
365
do_test analyze2-6.2.2 {
 
366
  db cache flush
 
367
  execsql ANALYZE
 
368
  eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
369
        t5.a>1 AND t5.a<15 AND
 
370
        t6.a>1
 
371
  }
 
372
} {0 1 {TABLE t6 WITH INDEX t6i} 1 0 {TABLE t5 USING PRIMARY KEY}}
 
373
do_test analyze2-6.2.3 {
 
374
  sqlite3 db test.db
 
375
  eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
376
        t5.a>1 AND t5.a<15 AND
 
377
        t6.a>1
 
378
  }
 
379
} {0 1 {TABLE t6 WITH INDEX t6i} 1 0 {TABLE t5 USING PRIMARY KEY}}
 
380
do_test analyze2-6.2.4 {
 
381
  execsql { 
 
382
    PRAGMA writable_schema = 1;
 
383
    DELETE FROM sqlite_master WHERE tbl_name = 'sqlite_stat1';
 
384
  }
 
385
  sqlite3 db test.db
 
386
  eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
387
        t5.a>1 AND t5.a<15 AND
 
388
        t6.a>1
 
389
  }
 
390
} {0 0 {TABLE t5 WITH INDEX t5i} 1 1 {TABLE t6 USING PRIMARY KEY}}
 
391
do_test analyze2-6.2.5 {
 
392
  execsql { 
 
393
    PRAGMA writable_schema = 1;
 
394
    DELETE FROM sqlite_master WHERE tbl_name = 'sqlite_stat2';
 
395
  }
 
396
  sqlite3 db test.db
 
397
  eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
398
        t5.a>1 AND t5.a<15 AND
 
399
        t6.a>1
 
400
  }
 
401
} {0 0 {TABLE t5 WITH INDEX t5i} 1 1 {TABLE t6 USING PRIMARY KEY}}
 
402
do_test analyze2-6.2.6 {
 
403
  execsql { 
 
404
    PRAGMA writable_schema = 1;
 
405
    INSERT INTO sqlite_master SELECT * FROM master;
 
406
  }
 
407
  sqlite3 db test.db
 
408
  execsql ANALYZE
 
409
  eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
410
        t5.a>1 AND t5.a<15 AND
 
411
        t6.a>1
 
412
  }
 
413
} {0 1 {TABLE t6 WITH INDEX t6i} 1 0 {TABLE t5 USING PRIMARY KEY}}
 
414
 
 
415
#--------------------------------------------------------------------
 
416
# These tests, analyze2-7.*, test that the sqlite_stat2 functionality
 
417
# works in shared-cache mode. Note that these tests reuse the database
 
418
# created for the analyze2-6.* tests.
 
419
#
 
420
ifcapable shared_cache {
 
421
  db close
 
422
  set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
 
423
 
 
424
  proc incr_schema_cookie {zDb} {
 
425
    foreach iOffset {24 40} {
 
426
      set cookie [hexio_get_int [hexio_read $zDb $iOffset 4]]
 
427
      incr cookie
 
428
      hexio_write $zDb $iOffset [hexio_render_int32 $cookie]
 
429
    }
 
430
  }
 
431
 
 
432
  do_test analyze2-7.1 {
 
433
    sqlite3 db1 test.db
 
434
    sqlite3 db2 test.db
 
435
    db1 cache size 0
 
436
    db2 cache size 0
 
437
    execsql { SELECT count(*) FROM t5 } db1
 
438
  } {20}
 
439
  do_test analyze2-7.2 {
 
440
    incr_schema_cookie test.db
 
441
    execsql { SELECT count(*) FROM t5 } db2
 
442
  } {20}
 
443
  do_test analyze2-7.3 {
 
444
    incr_schema_cookie test.db
 
445
    execsql { SELECT count(*) FROM t5 } db1
 
446
  } {20}
 
447
  do_test analyze2-7.4 {
 
448
    incr_schema_cookie test.db
 
449
    execsql { SELECT count(*) FROM t5 } db2
 
450
  } {20}
 
451
 
 
452
  do_test analyze2-7.5 {
 
453
    eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
454
          t5.a>1 AND t5.a<15 AND
 
455
          t6.a>1
 
456
    } db1
 
457
  } {0 1 {TABLE t6 WITH INDEX t6i} 1 0 {TABLE t5 USING PRIMARY KEY}}
 
458
  do_test analyze2-7.6 {
 
459
    incr_schema_cookie test.db
 
460
    execsql { SELECT * FROM sqlite_master } db2
 
461
    eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
462
          t5.a>1 AND t5.a<15 AND
 
463
          t6.a>1
 
464
    } db2
 
465
  } {0 1 {TABLE t6 WITH INDEX t6i} 1 0 {TABLE t5 USING PRIMARY KEY}}
 
466
  do_test analyze2-7.7 {
 
467
    incr_schema_cookie test.db
 
468
    execsql { SELECT * FROM sqlite_master } db1
 
469
    eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
470
          t5.a>1 AND t5.a<15 AND
 
471
          t6.a>1
 
472
    } db1
 
473
  } {0 1 {TABLE t6 WITH INDEX t6i} 1 0 {TABLE t5 USING PRIMARY KEY}}
 
474
 
 
475
  do_test analyze2-7.8 {
 
476
    execsql { DELETE FROM sqlite_stat2 } db2
 
477
    execsql { SELECT * FROM sqlite_master } db1
 
478
    eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
479
          t5.a>1 AND t5.a<15 AND
 
480
          t6.a>1
 
481
    } db1
 
482
  } {0 1 {TABLE t6 WITH INDEX t6i} 1 0 {TABLE t5 USING PRIMARY KEY}}
 
483
  do_test analyze2-7.9 {
 
484
    execsql { SELECT * FROM sqlite_master } db2
 
485
    eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
486
          t5.a>1 AND t5.a<15 AND
 
487
          t6.a>1
 
488
    } db2
 
489
  } {0 1 {TABLE t6 WITH INDEX t6i} 1 0 {TABLE t5 USING PRIMARY KEY}}
 
490
 
 
491
  do_test analyze2-7.10 {
 
492
    incr_schema_cookie test.db
 
493
    execsql { SELECT * FROM sqlite_master } db1
 
494
    eqp { SELECT * FROM t5,t6 WHERE t5.rowid=t6.rowid AND 
 
495
          t5.a>1 AND t5.a<15 AND
 
496
          t6.a>1
 
497
    } db1
 
498
  } {0 0 {TABLE t5 WITH INDEX t5i} 1 1 {TABLE t6 USING PRIMARY KEY}}
 
499
 
 
500
  db1 close
 
501
  db2 close
 
502
  sqlite3_enable_shared_cache $::enable_shared_cache
 
503
}
 
504
 
 
505
finish_test