/ Hex Artifact Content
Login

Artifact 3a9d8618a3107166530c447e808f8992372e0415:


0000: 23 20 32 30 30 39 20 44 65 63 65 6d 62 65 72 20  # 2009 December 
0010: 30 33 0a 23 0a 23 20 20 20 20 4d 61 79 20 79 6f  03.#.#    May yo
0020: 75 20 64 6f 20 67 6f 6f 64 20 61 6e 64 20 6e 6f  u do good and no
0030: 74 20 65 76 69 6c 2e 0a 23 20 20 20 20 4d 61 79  t evil..#    May
0040: 20 79 6f 75 20 66 69 6e 64 20 66 6f 72 67 69 76   you find forgiv
0050: 65 6e 65 73 73 20 66 6f 72 20 79 6f 75 72 73 65  eness for yourse
0060: 6c 66 20 61 6e 64 20 66 6f 72 67 69 76 65 20 6f  lf and forgive o
0070: 74 68 65 72 73 2e 0a 23 20 20 20 20 4d 61 79 20  thers..#    May 
0080: 79 6f 75 20 73 68 61 72 65 20 66 72 65 65 6c 79  you share freely
0090: 2c 20 6e 65 76 65 72 20 74 61 6b 69 6e 67 20 6d  , never taking m
00a0: 6f 72 65 20 74 68 61 6e 20 79 6f 75 20 67 69 76  ore than you giv
00b0: 65 2e 0a 23 0a 23 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  e..#.#**********
00c0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
00d0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
00e0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
00f0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 23 0a  *************.#.
0100: 23 20 54 68 65 20 74 65 73 74 73 20 69 6e 20 74  # The tests in t
0110: 68 69 73 20 66 69 6c 65 20 61 72 65 20 73 74 72  his file are str
0120: 75 63 74 75 72 61 6c 20 63 6f 76 65 72 61 67 65  uctural coverage
0130: 20 74 65 73 74 73 2e 20 54 68 65 79 20 61 72 65   tests. They are
0140: 20 64 65 73 69 67 6e 65 64 0a 23 20 74 6f 20 63   designed.# to c
0150: 6f 6d 70 6c 65 6d 65 6e 74 20 74 68 65 20 74 65  omplement the te
0160: 73 74 73 20 69 6e 20 66 74 73 33 72 6e 64 2e 74  sts in fts3rnd.t
0170: 65 73 74 20 61 6e 64 20 66 74 73 33 64 6f 63 2e  est and fts3doc.
0180: 74 65 73 74 2e 20 42 65 74 77 65 65 6e 20 74 68  test. Between th
0190: 65 6d 2c 0a 23 20 74 68 65 20 74 68 72 65 65 20  em,.# the three 
01a0: 66 69 6c 65 73 20 73 68 6f 75 6c 64 20 70 72 6f  files should pro
01b0: 76 69 64 65 20 66 75 6c 6c 20 63 6f 76 65 72 61  vide full covera
01c0: 67 65 20 6f 66 20 74 68 65 20 66 74 73 33 20 65  ge of the fts3 e
01d0: 78 74 65 6e 73 69 6f 6e 20 63 6f 64 65 2e 0a 23  xtension code..#
01e0: 0a 0a 73 65 74 20 74 65 73 74 64 69 72 20 5b 66  ..set testdir [f
01f0: 69 6c 65 20 64 69 72 6e 61 6d 65 20 24 61 72 67  ile dirname $arg
0200: 76 30 5d 0a 73 6f 75 72 63 65 20 24 74 65 73 74  v0].source $test
0210: 64 69 72 2f 74 65 73 74 65 72 2e 74 63 6c 0a 0a  dir/tester.tcl..
0220: 23 20 49 66 20 74 68 69 73 20 62 75 69 6c 64 20  # If this build 
0230: 64 6f 65 73 20 6e 6f 74 20 69 6e 63 6c 75 64 65  does not include
0240: 20 46 54 53 33 2c 20 73 6b 69 70 20 74 68 65 20   FTS3, skip the 
0250: 74 65 73 74 73 20 69 6e 20 74 68 69 73 20 66 69  tests in this fi
0260: 6c 65 2e 0a 23 0a 69 66 63 61 70 61 62 6c 65 20  le..#.ifcapable 
0270: 21 66 74 73 33 20 7b 20 66 69 6e 69 73 68 5f 74  !fts3 { finish_t
0280: 65 73 74 20 3b 20 72 65 74 75 72 6e 20 7d 0a 73  est ; return }.s
0290: 6f 75 72 63 65 20 24 74 65 73 74 64 69 72 2f 66  ource $testdir/f
02a0: 74 73 33 5f 63 6f 6d 6d 6f 6e 2e 74 63 6c 0a 73  ts3_common.tcl.s
02b0: 6f 75 72 63 65 20 24 74 65 73 74 64 69 72 2f 6d  ource $testdir/m
02c0: 61 6c 6c 6f 63 5f 63 6f 6d 6d 6f 6e 2e 74 63 6c  alloc_common.tcl
02d0: 0a 0a 73 65 74 20 44 4f 5f 4d 41 4c 4c 4f 43 5f  ..set DO_MALLOC_
02e0: 54 45 53 54 20 30 0a 0a 23 2d 2d 2d 2d 2d 2d 2d  TEST 0..#-------
02f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0300: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0310: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0320: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0330: 2d 2d 2d 0a 23 20 57 68 65 6e 20 69 74 20 66 69  ---.# When it fi
0340: 72 73 74 20 6e 65 65 64 73 20 74 6f 20 72 65 61  rst needs to rea
0350: 64 20 61 20 62 6c 6f 63 6b 20 66 72 6f 6d 20 74  d a block from t
0360: 68 65 20 25 5f 73 65 67 6d 65 6e 74 73 20 74 61  he %_segments ta
0370: 62 6c 65 2c 20 74 68 65 20 46 54 53 33 20 0a 23  ble, the FTS3 .#
0380: 20 6d 6f 64 75 6c 65 20 63 6f 6d 70 69 6c 65 73   module compiles
0390: 20 61 6e 20 53 51 4c 20 73 74 61 74 65 6d 65 6e   an SQL statemen
03a0: 74 20 66 6f 72 20 74 68 61 74 20 70 75 72 70 6f  t for that purpo
03b0: 73 65 2e 20 54 68 65 20 73 74 61 74 65 6d 65 6e  se. The statemen
03c0: 74 20 69 73 20 0a 23 20 73 74 6f 72 65 64 20 61  t is .# stored a
03d0: 6e 64 20 72 65 75 73 65 64 20 65 61 63 68 20 73  nd reused each s
03e0: 75 62 73 65 71 75 65 6e 74 20 74 69 6d 65 20 61  ubsequent time a
03f0: 20 62 6c 6f 63 6b 20 69 73 20 72 65 61 64 2e 20   block is read. 
0400: 54 68 69 73 20 74 65 73 74 20 63 61 73 65 20 0a  This test case .
0410: 23 20 74 65 73 74 73 20 74 68 65 20 65 66 66 65  # tests the effe
0420: 63 74 73 20 6f 66 20 61 6e 20 4f 4f 4d 20 65 72  cts of an OOM er
0430: 72 6f 72 20 6f 63 63 75 72 69 6e 67 20 77 68 69  ror occuring whi
0440: 6c 65 20 63 6f 6d 70 69 6c 69 6e 67 20 74 68 65  le compiling the
0450: 20 73 74 61 74 65 6d 65 6e 74 2e 0a 23 0a 23 20   statement..#.# 
0460: 53 69 6d 69 6c 61 72 6c 79 2c 20 77 68 65 6e 20  Similarly, when 
0470: 46 54 53 33 20 66 69 72 73 74 20 6e 65 65 64 73  FTS3 first needs
0480: 20 74 6f 20 73 63 61 6e 20 74 68 72 6f 75 67 68   to scan through
0490: 20 61 20 73 65 74 20 6f 66 20 73 65 67 6d 65 6e   a set of segmen
04a0: 74 20 6c 65 61 76 65 73 0a 23 20 74 6f 20 66 69  t leaves.# to fi
04b0: 6e 64 20 61 20 73 65 74 20 6f 66 20 64 6f 63 75  nd a set of docu
04c0: 6d 65 6e 74 73 20 74 68 61 74 20 6d 61 74 63 68  ments that match
04d0: 65 73 20 61 20 74 65 72 6d 2c 20 69 74 20 61 6c  es a term, it al
04e0: 6c 6f 63 61 74 65 73 20 61 20 73 74 72 69 6e 67  locates a string
04f0: 0a 23 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68  .# containing th
0500: 65 20 74 65 78 74 20 6f 66 20 74 68 65 20 72 65  e text of the re
0510: 71 75 69 72 65 64 20 53 51 4c 2c 20 61 6e 64 20  quired SQL, and 
0520: 63 6f 6d 70 69 6c 65 73 20 6f 6e 65 20 6f 72 20  compiles one or 
0530: 6d 6f 72 65 20 0a 23 20 73 74 61 74 65 6d 65 6e  more .# statemen
0540: 74 73 20 74 6f 20 74 72 61 76 65 72 73 65 20 74  ts to traverse t
0550: 68 65 20 6c 65 61 76 65 73 2e 20 54 68 69 73 20  he leaves. This 
0560: 74 65 73 74 20 63 61 73 65 20 74 65 73 74 73 20  test case tests 
0570: 74 68 61 74 20 4f 4f 4d 20 65 72 72 6f 72 73 0a  that OOM errors.
0580: 23 20 74 68 61 74 20 6f 63 63 75 72 20 77 68 69  # that occur whi
0590: 6c 65 20 61 6c 6c 6f 63 61 74 69 6e 67 20 74 68  le allocating th
05a0: 69 73 20 73 74 72 69 6e 67 20 61 6e 64 20 73 74  is string and st
05b0: 61 74 65 6d 65 6e 74 20 61 72 65 20 68 61 6e 64  atement are hand
05c0: 6c 65 64 20 63 6f 72 72 65 63 74 6c 79 0a 23 20  led correctly.# 
05d0: 61 6c 73 6f 2e 0a 23 0a 64 6f 5f 74 65 73 74 20  also..#.do_test 
05e0: 66 74 73 33 63 6f 76 2d 31 2e 31 20 7b 0a 20 20  fts3cov-1.1 {.  
05f0: 65 78 65 63 73 71 6c 20 7b 20 0a 20 20 20 20 43  execsql { .    C
0600: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
0610: 42 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73  BLE t1 USING fts
0620: 33 28 78 29 3b 0a 20 20 20 20 49 4e 53 45 52 54  3(x);.    INSERT
0630: 20 49 4e 54 4f 20 74 31 28 74 31 29 20 56 41 4c   INTO t1(t1) VAL
0640: 55 45 53 28 27 6e 6f 64 65 73 69 7a 65 3d 32 34  UES('nodesize=24
0650: 27 29 3b 0a 20 20 20 20 42 45 47 49 4e 3b 0a 20  ');.    BEGIN;. 
0660: 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f       INSERT INTO
0670: 20 74 31 20 56 41 4c 55 45 53 28 27 49 73 20 74   t1 VALUES('Is t
0680: 68 65 20 6e 69 67 68 74 20 63 68 69 6c 6c 79 20  he night chilly 
0690: 61 6e 64 20 64 61 72 6b 3f 27 29 3b 0a 20 20 20  and dark?');.   
06a0: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74     INSERT INTO t
06b0: 31 20 56 41 4c 55 45 53 28 27 54 68 65 20 6e 69  1 VALUES('The ni
06c0: 67 68 74 20 69 73 20 63 68 69 6c 6c 79 2c 20 62  ght is chilly, b
06d0: 75 74 20 6e 6f 74 20 64 61 72 6b 2e 27 29 3b 0a  ut not dark.');.
06e0: 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54        INSERT INT
06f0: 4f 20 74 31 20 56 41 4c 55 45 53 28 27 54 68 65  O t1 VALUES('The
0700: 20 74 68 69 6e 20 67 72 61 79 20 63 6c 6f 75 64   thin gray cloud
0710: 20 69 73 20 73 70 72 65 61 64 20 6f 6e 20 68 69   is spread on hi
0720: 67 68 2c 27 29 3b 0a 20 20 20 20 20 20 49 4e 53  gh,');.      INS
0730: 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55  ERT INTO t1 VALU
0740: 45 53 28 27 49 74 20 63 6f 76 65 72 73 20 62 75  ES('It covers bu
0750: 74 20 6e 6f 74 20 68 69 64 65 73 20 74 68 65 20  t not hides the 
0760: 73 6b 79 2e 27 29 3b 0a 20 20 20 20 43 4f 4d 4d  sky.');.    COMM
0770: 49 54 3b 0a 20 20 20 20 53 45 4c 45 43 54 20 63  IT;.    SELECT c
0780: 6f 75 6e 74 28 2a 29 3e 30 20 46 52 4f 4d 20 74  ount(*)>0 FROM t
0790: 31 5f 73 65 67 6d 65 6e 74 73 3b 0a 20 20 7d 0a  1_segments;.  }.
07a0: 7d 20 7b 31 7d 0a 0a 73 65 74 20 44 4f 5f 4d 41  } {1}..set DO_MA
07b0: 4c 4c 4f 43 5f 54 45 53 54 20 31 0a 64 6f 5f 72  LLOC_TEST 1.do_r
07c0: 65 73 74 61 72 74 5f 73 65 6c 65 63 74 5f 74 65  estart_select_te
07d0: 73 74 20 66 74 73 33 63 6f 76 2d 31 2e 32 20 7b  st fts3cov-1.2 {
07e0: 0a 20 20 53 45 4c 45 43 54 20 64 6f 63 69 64 20  .  SELECT docid 
07f0: 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 74 31  FROM t1 WHERE t1
0800: 20 4d 41 54 43 48 20 27 63 68 69 6c 6c 79 27 3b   MATCH 'chilly';
0810: 0a 7d 20 7b 31 20 32 7d 0a 73 65 74 20 44 4f 5f  .} {1 2}.set DO_
0820: 4d 41 4c 4c 4f 43 5f 54 45 53 54 20 30 0a 0a 23  MALLOC_TEST 0..#
0830: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0840: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0850: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0860: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0870: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 57 68 65  ----------.# Whe
0880: 6e 20 71 75 65 72 79 69 6e 67 20 74 68 65 20 66  n querying the f
0890: 75 6c 6c 2d 74 65 78 74 20 69 6e 64 65 78 2c 20  ull-text index, 
08a0: 69 66 20 61 6e 20 65 78 70 65 63 74 65 64 20 69  if an expected i
08b0: 6e 74 65 72 6e 61 6c 20 6e 6f 64 65 20 62 6c 6f  nternal node blo
08c0: 63 6b 20 69 73 20 0a 23 20 6d 69 73 73 69 6e 67  ck is .# missing
08d0: 20 66 72 6f 6d 20 74 68 65 20 25 5f 73 65 67 6d   from the %_segm
08e0: 65 6e 74 73 20 74 61 62 6c 65 2c 20 6f 72 20 69  ents table, or i
08f0: 66 20 61 20 4e 55 4c 4c 20 76 61 6c 75 65 20 69  f a NULL value i
0900: 73 20 73 74 6f 72 65 64 20 69 6e 20 74 68 65 20  s stored in the 
0910: 0a 23 20 25 5f 73 65 67 6d 65 6e 74 73 20 74 61  .# %_segments ta
0920: 62 6c 65 20 69 6e 73 74 65 61 64 20 6f 66 20 61  ble instead of a
0930: 20 62 69 6e 61 72 79 20 62 6c 6f 62 2c 20 64 61   binary blob, da
0940: 74 61 62 61 73 65 20 63 6f 72 72 75 70 74 69 6f  tabase corruptio
0950: 6e 20 73 68 6f 75 6c 64 20 62 65 20 0a 23 20 72  n should be .# r
0960: 65 70 6f 72 74 65 64 2e 0a 23 0a 23 20 45 76 65  eported..#.# Eve
0970: 6e 20 77 69 74 68 20 74 69 6e 79 20 32 34 20 62  n with tiny 24 b
0980: 79 74 65 20 6e 6f 64 65 73 2c 20 69 74 20 74 61  yte nodes, it ta
0990: 6b 65 73 20 61 20 66 61 69 72 20 62 69 74 20 6f  kes a fair bit o
09a0: 66 20 64 61 74 61 20 74 6f 20 70 72 6f 64 75 63  f data to produc
09b0: 65 20 61 0a 23 20 73 65 67 6d 65 6e 74 20 62 2d  e a.# segment b-
09c0: 74 72 65 65 20 74 68 61 74 20 75 73 65 73 20 74  tree that uses t
09d0: 68 65 20 25 5f 73 65 67 6d 65 6e 74 73 20 74 61  he %_segments ta
09e0: 62 6c 65 20 74 6f 20 73 74 6f 72 65 20 69 6e 74  ble to store int
09f0: 65 72 6e 61 6c 20 6e 6f 64 65 73 2e 20 0a 23 0a  ernal nodes. .#.
0a00: 64 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d  do_test fts3cov-
0a10: 32 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c 20  2.1 {.  execsql 
0a20: 7b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  {.    INSERT INT
0a30: 4f 20 74 31 28 74 31 29 20 56 41 4c 55 45 53 28  O t1(t1) VALUES(
0a40: 27 6e 6f 64 65 73 69 7a 65 3d 32 34 27 29 3b 0a  'nodesize=24');.
0a50: 20 20 20 20 42 45 47 49 4e 3b 0a 20 20 20 20 20      BEGIN;.     
0a60: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20   INSERT INTO t1 
0a70: 56 41 4c 55 45 53 28 27 54 68 65 20 6d 6f 6f 6e  VALUES('The moon
0a80: 20 69 73 20 62 65 68 69 6e 64 2c 20 61 6e 64 20   is behind, and 
0a90: 61 74 20 74 68 65 20 66 75 6c 6c 3b 27 29 3b 0a  at the full;');.
0aa0: 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54        INSERT INT
0ab0: 4f 20 74 31 20 56 41 4c 55 45 53 28 27 41 6e 64  O t1 VALUES('And
0ac0: 20 79 65 74 20 73 68 65 20 6c 6f 6f 6b 73 20 62   yet she looks b
0ad0: 6f 74 68 20 73 6d 61 6c 6c 20 61 6e 64 20 64 75  oth small and du
0ae0: 6c 6c 2e 27 29 3b 0a 20 20 20 20 20 20 49 4e 53  ll.');.      INS
0af0: 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55  ERT INTO t1 VALU
0b00: 45 53 28 27 54 68 65 20 6e 69 67 68 74 20 69 73  ES('The night is
0b10: 20 63 68 69 6c 6c 2c 20 74 68 65 20 63 6c 6f 75   chill, the clou
0b20: 64 20 69 73 20 67 72 61 79 3a 27 29 3b 0a 20 20  d is gray:');.  
0b30: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
0b40: 74 31 20 56 41 4c 55 45 53 28 27 27 27 54 20 69  t1 VALUES('''T i
0b50: 73 20 61 20 6d 6f 6e 74 68 20 62 65 66 6f 72 65  s a month before
0b60: 20 74 68 65 20 6d 6f 6e 74 68 20 6f 66 20 4d 61   the month of Ma
0b70: 79 2c 27 29 3b 0a 20 20 20 20 20 20 49 4e 53 45  y,');.      INSE
0b80: 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45  RT INTO t1 VALUE
0b90: 53 28 27 41 6e 64 20 74 68 65 20 53 70 72 69 6e  S('And the Sprin
0ba0: 67 20 63 6f 6d 65 73 20 73 6c 6f 77 6c 79 20 75  g comes slowly u
0bb0: 70 20 74 68 69 73 20 77 61 79 2e 27 29 3b 0a 20  p this way.');. 
0bc0: 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f       INSERT INTO
0bd0: 20 74 31 20 56 41 4c 55 45 53 28 27 54 68 65 20   t1 VALUES('The 
0be0: 6c 6f 76 65 6c 79 20 6c 61 64 79 2c 20 43 68 72  lovely lady, Chr
0bf0: 69 73 74 61 62 65 6c 2c 27 29 3b 0a 20 20 20 20  istabel,');.    
0c00: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31    INSERT INTO t1
0c10: 20 56 41 4c 55 45 53 28 27 57 68 6f 6d 20 68 65   VALUES('Whom he
0c20: 72 20 66 61 74 68 65 72 20 6c 6f 76 65 73 20 73  r father loves s
0c30: 6f 20 77 65 6c 6c 2c 27 29 3b 0a 20 20 20 20 20  o well,');.     
0c40: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20   INSERT INTO t1 
0c50: 56 41 4c 55 45 53 28 27 57 68 61 74 20 6d 61 6b  VALUES('What mak
0c60: 65 73 20 68 65 72 20 69 6e 20 74 68 65 20 77 6f  es her in the wo
0c70: 6f 64 20 73 6f 20 6c 61 74 65 2c 27 29 3b 0a 20  od so late,');. 
0c80: 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f       INSERT INTO
0c90: 20 74 31 20 56 41 4c 55 45 53 28 27 41 20 66 75   t1 VALUES('A fu
0ca0: 72 6c 6f 6e 67 20 66 72 6f 6d 20 74 68 65 20 63  rlong from the c
0cb0: 61 73 74 6c 65 20 67 61 74 65 3f 27 29 3b 0a 20  astle gate?');. 
0cc0: 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f       INSERT INTO
0cd0: 20 74 31 20 56 41 4c 55 45 53 28 27 53 68 65 20   t1 VALUES('She 
0ce0: 68 61 64 20 64 72 65 61 6d 73 20 61 6c 6c 20 79  had dreams all y
0cf0: 65 73 74 65 72 6e 69 67 68 74 27 29 3b 0a 20 20  esternight');.  
0d00: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
0d10: 74 31 20 56 41 4c 55 45 53 28 27 4f 66 20 68 65  t1 VALUES('Of he
0d20: 72 20 6f 77 6e 20 62 65 74 72 6f 74 68 65 64 20  r own betrothed 
0d30: 6b 6e 69 67 68 74 3b 27 29 3b 0a 20 20 20 20 20  knight;');.     
0d40: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20   INSERT INTO t1 
0d50: 56 41 4c 55 45 53 28 27 41 6e 64 20 73 68 65 20  VALUES('And she 
0d60: 69 6e 20 74 68 65 20 6d 69 64 6e 69 67 68 74 20  in the midnight 
0d70: 77 6f 6f 64 20 77 69 6c 6c 20 70 72 61 79 27 29  wood will pray')
0d80: 3b 0a 20 20 20 20 20 20 49 4e 53 45 52 54 20 49  ;.      INSERT I
0d90: 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 27 46  NTO t1 VALUES('F
0da0: 6f 72 20 74 68 65 20 77 65 61 6c 20 6f 66 20 68  or the weal of h
0db0: 65 72 20 6c 6f 76 65 72 20 74 68 61 74 27 27 73  er lover that''s
0dc0: 20 66 61 72 20 61 77 61 79 2e 27 29 3b 0a 20 20   far away.');.  
0dd0: 20 20 43 4f 4d 4d 49 54 3b 0a 0a 20 20 20 20 49    COMMIT;..    I
0de0: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 28 74 31  NSERT INTO t1(t1
0df0: 29 20 56 41 4c 55 45 53 28 27 6f 70 74 69 6d 69  ) VALUES('optimi
0e00: 7a 65 27 29 3b 0a 20 20 20 20 53 45 4c 45 43 54  ze');.    SELECT
0e10: 20 73 75 62 73 74 72 28 68 65 78 28 72 6f 6f 74   substr(hex(root
0e20: 29 2c 20 31 2c 20 32 29 20 46 52 4f 4d 20 74 31  ), 1, 2) FROM t1
0e30: 5f 73 65 67 64 69 72 3b 0a 20 20 7d 0a 7d 20 7b  _segdir;.  }.} {
0e40: 30 33 7d 0a 0a 23 20 54 65 73 74 20 74 68 65 20  03}..# Test the 
0e50: 22 6d 69 73 73 69 6e 67 20 65 6e 74 72 79 22 20  "missing entry" 
0e60: 63 61 73 65 3a 0a 64 6f 5f 74 65 73 74 20 66 74  case:.do_test ft
0e70: 73 33 63 6f 76 2d 32 2e 31 20 7b 0a 20 20 73 65  s3cov-2.1 {.  se
0e80: 74 20 72 6f 6f 74 20 5b 64 62 20 6f 6e 65 20 7b  t root [db one {
0e90: 53 45 4c 45 43 54 20 72 6f 6f 74 20 46 52 4f 4d  SELECT root FROM
0ea0: 20 74 31 5f 73 65 67 64 69 72 7d 5d 0a 20 20 72   t1_segdir}].  r
0eb0: 65 61 64 5f 66 74 73 33 76 61 72 69 6e 74 20 5b  ead_fts3varint [
0ec0: 73 74 72 69 6e 67 20 72 61 6e 67 65 20 24 72 6f  string range $ro
0ed0: 6f 74 20 31 20 65 6e 64 5d 20 6c 65 66 74 5f 63  ot 1 end] left_c
0ee0: 68 69 6c 64 0a 20 20 65 78 65 63 73 71 6c 20 7b  hild.  execsql {
0ef0: 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 74 31 5f   DELETE FROM t1_
0f00: 73 65 67 6d 65 6e 74 73 20 57 48 45 52 45 20 62  segments WHERE b
0f10: 6c 6f 63 6b 69 64 20 3d 20 24 6c 65 66 74 5f 63  lockid = $left_c
0f20: 68 69 6c 64 20 7d 0a 7d 20 7b 7d 0a 64 6f 5f 65  hild }.} {}.do_e
0f30: 72 72 6f 72 5f 74 65 73 74 20 66 74 73 33 63 6f  rror_test fts3co
0f40: 76 2d 32 2e 32 20 7b 0a 20 20 53 45 4c 45 43 54  v-2.2 {.  SELECT
0f50: 20 2a 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45   * FROM t1 WHERE
0f60: 20 74 31 20 4d 41 54 43 48 20 27 63 2a 27 0a 7d   t1 MATCH 'c*'.}
0f70: 20 7b 64 61 74 61 62 61 73 65 20 64 69 73 6b 20   {database disk 
0f80: 69 6d 61 67 65 20 69 73 20 6d 61 6c 66 6f 72 6d  image is malform
0f90: 65 64 7d 0a 0a 23 20 54 65 73 74 20 74 68 65 20  ed}..# Test the 
0fa0: 22 72 65 70 6c 61 63 65 64 20 77 69 74 68 20 4e  "replaced with N
0fb0: 55 4c 4c 22 20 63 61 73 65 3a 0a 64 6f 5f 74 65  ULL" case:.do_te
0fc0: 73 74 20 66 74 73 33 63 6f 76 2d 32 2e 33 20 7b  st fts3cov-2.3 {
0fd0: 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 49 4e 53  .  execsql { INS
0fe0: 45 52 54 20 49 4e 54 4f 20 74 31 5f 73 65 67 6d  ERT INTO t1_segm
0ff0: 65 6e 74 73 20 56 41 4c 55 45 53 28 24 6c 65 66  ents VALUES($lef
1000: 74 5f 63 68 69 6c 64 2c 20 4e 55 4c 4c 29 20 7d  t_child, NULL) }
1010: 0a 7d 20 7b 7d 0a 64 6f 5f 65 72 72 6f 72 5f 74  .} {}.do_error_t
1020: 65 73 74 20 66 74 73 33 63 6f 76 2d 32 2e 34 20  est fts3cov-2.4 
1030: 7b 0a 20 20 53 45 4c 45 43 54 20 2a 20 46 52 4f  {.  SELECT * FRO
1040: 4d 20 74 31 20 57 48 45 52 45 20 74 31 20 4d 41  M t1 WHERE t1 MA
1050: 54 43 48 20 27 63 6c 6f 75 64 27 0a 7d 20 7b 64  TCH 'cloud'.} {d
1060: 61 74 61 62 61 73 65 20 64 69 73 6b 20 69 6d 61  atabase disk ima
1070: 67 65 20 69 73 20 6d 61 6c 66 6f 72 6d 65 64 7d  ge is malformed}
1080: 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ..#-------------
1090: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
10a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
10b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
10c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20  -------------.# 
10d0: 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 65  The following te
10e0: 73 74 73 20 61 72 65 20 74 6f 20 74 65 73 74 20  sts are to test 
10f0: 74 68 65 20 65 66 66 65 63 74 73 20 6f 66 20 4f  the effects of O
1100: 4f 4d 20 65 72 72 6f 72 73 20 77 68 69 6c 65 20  OM errors while 
1110: 73 74 6f 72 69 6e 67 0a 23 20 74 65 72 6d 73 20  storing.# terms 
1120: 69 6e 20 74 68 65 20 70 65 6e 64 69 6e 67 2d 68  in the pending-h
1130: 61 73 68 20 74 61 62 6c 65 2e 20 53 70 65 63 69  ash table. Speci
1140: 66 69 63 61 6c 6c 79 2c 20 77 68 69 6c 65 20 63  fically, while c
1150: 72 65 61 74 69 6e 67 20 64 6f 63 6c 69 73 74 0a  reating doclist.
1160: 23 20 62 6c 6f 62 73 20 74 6f 20 73 74 6f 72 65  # blobs to store
1170: 20 69 6e 20 74 68 65 20 74 61 62 6c 65 2e 20 4d   in the table. M
1180: 6f 72 65 20 73 70 65 63 69 66 69 63 61 6c 6c 79  ore specifically
1190: 2c 20 74 6f 20 74 65 73 74 20 4f 4f 4d 20 65 72  , to test OOM er
11a0: 72 6f 72 73 20 77 68 69 6c 65 0a 23 20 61 70 70  rors while.# app
11b0: 65 6e 64 69 6e 67 20 63 6f 6c 75 6d 6e 20 6e 75  ending column nu
11c0: 6d 62 65 72 73 20 74 6f 20 64 6f 63 6c 69 73 74  mbers to doclist
11d0: 73 2e 20 46 6f 72 20 65 78 61 6d 70 6c 65 2c 20  s. For example, 
11e0: 69 66 20 61 20 64 6f 63 6c 69 73 74 20 63 6f 6e  if a doclist con
11f0: 73 69 73 74 73 0a 23 20 6f 66 3a 0a 23 0a 23 20  sists.# of:.#.# 
1200: 20 20 3c 64 6f 63 69 64 3e 20 3c 63 6f 6c 75 6d    <docid> <colum
1210: 6e 20 30 20 6f 66 66 73 65 74 2d 6c 69 73 74 3e  n 0 offset-list>
1220: 20 30 78 30 31 20 3c 63 6f 6c 75 6d 6e 20 4e 3e   0x01 <column N>
1230: 20 3c 63 6f 6c 75 6d 6e 20 4e 20 6f 66 66 73 65   <column N offse
1240: 74 2d 6c 69 73 74 3e 0a 23 0a 23 20 54 68 65 20  t-list>.#.# The 
1250: 66 6f 6c 6c 6f 77 69 6e 67 20 74 65 73 74 73 20  following tests 
1260: 63 68 65 63 6b 20 74 68 61 74 20 6d 61 6c 6c 6f  check that mallo
1270: 63 20 65 72 72 6f 72 73 20 65 6e 63 6f 75 6e 74  c errors encount
1280: 65 72 65 64 20 77 68 69 6c 65 20 61 70 70 65 6e  ered while appen
1290: 64 69 6e 67 0a 23 20 74 68 65 20 22 30 78 30 31  ding.# the "0x01
12a0: 20 3c 63 6f 6c 75 6d 6e 20 4e 3e 22 20 64 61 74   <column N>" dat
12b0: 61 20 74 6f 20 74 68 65 20 64 79 6e 61 6d 69 63  a to the dynamic
12c0: 61 6c 6c 79 20 67 72 6f 77 61 62 6c 65 20 62 6c  ally growable bl
12d0: 6f 62 20 75 73 65 64 20 74 6f 20 0a 23 20 61 63  ob used to .# ac
12e0: 63 75 6d 75 6c 61 74 65 20 74 68 65 20 64 6f 63  cumulate the doc
12f0: 6c 69 73 74 20 69 6e 20 6d 65 6d 6f 72 79 20 61  list in memory a
1300: 72 65 20 68 61 6e 64 6c 65 64 20 63 6f 72 72 65  re handled corre
1310: 63 74 6c 79 2e 0a 23 0a 64 6f 5f 74 65 73 74 20  ctly..#.do_test 
1320: 66 74 73 33 63 6f 76 2d 33 2e 31 20 7b 0a 20 20  fts3cov-3.1 {.  
1330: 73 65 74 20 63 6f 6c 73 20 5b 6c 69 73 74 5d 0a  set cols [list].
1340: 20 20 73 65 74 20 76 61 6c 73 20 5b 6c 69 73 74    set vals [list
1350: 5d 0a 20 20 66 6f 72 20 7b 73 65 74 20 69 20 30  ].  for {set i 0
1360: 7d 20 7b 24 69 20 3c 20 31 32 30 7d 20 7b 69 6e  } {$i < 120} {in
1370: 63 72 20 69 7d 20 7b 0a 20 20 20 20 6c 61 70 70  cr i} {.    lapp
1380: 65 6e 64 20 63 6f 6c 73 20 22 63 6f 6c 24 69 22  end cols "col$i"
1390: 0a 20 20 20 20 6c 61 70 70 65 6e 64 20 76 61 6c  .    lappend val
13a0: 73 20 22 27 77 6f 72 64 27 22 0a 20 20 7d 0a 20  s "'word'".  }. 
13b0: 20 65 78 65 63 73 71 6c 20 22 43 52 45 41 54 45   execsql "CREATE
13c0: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74   VIRTUAL TABLE t
13d0: 32 20 55 53 49 4e 47 20 66 74 73 33 28 5b 6a 6f  2 USING fts3([jo
13e0: 69 6e 20 24 63 6f 6c 73 20 2c 5d 29 22 0a 7d 20  in $cols ,])".} 
13f0: 7b 7d 0a 73 65 74 20 44 4f 5f 4d 41 4c 4c 4f 43  {}.set DO_MALLOC
1400: 5f 54 45 53 54 20 31 20 0a 64 6f 5f 77 72 69 74  _TEST 1 .do_writ
1410: 65 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 33  e_test fts3cov-3
1420: 2e 32 20 74 32 5f 63 6f 6e 74 65 6e 74 20 22 0a  .2 t2_content ".
1430: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 32    INSERT INTO t2
1440: 28 64 6f 63 69 64 2c 20 5b 6a 6f 69 6e 20 24 63  (docid, [join $c
1450: 6f 6c 73 20 2c 5d 29 20 56 41 4c 55 45 53 28 31  ols ,]) VALUES(1
1460: 2c 20 5b 6a 6f 69 6e 20 24 76 61 6c 73 20 2c 5d  , [join $vals ,]
1470: 29 0a 22 0a 64 6f 5f 77 72 69 74 65 5f 74 65 73  ).".do_write_tes
1480: 74 20 66 74 73 33 63 6f 76 2d 33 2e 33 20 74 32  t fts3cov-3.3 t2
1490: 5f 63 6f 6e 74 65 6e 74 20 22 0a 20 20 49 4e 53  _content ".  INS
14a0: 45 52 54 20 49 4e 54 4f 20 74 32 28 64 6f 63 69  ERT INTO t2(doci
14b0: 64 2c 20 5b 6a 6f 69 6e 20 24 63 6f 6c 73 20 2c  d, [join $cols ,
14c0: 5d 29 20 56 41 4c 55 45 53 28 32 30 30 2c 20 5b  ]) VALUES(200, [
14d0: 6a 6f 69 6e 20 24 76 61 6c 73 20 2c 5d 29 0a 22  join $vals ,])."
14e0: 0a 64 6f 5f 77 72 69 74 65 5f 74 65 73 74 20 66  .do_write_test f
14f0: 74 73 33 63 6f 76 2d 33 2e 34 20 74 32 5f 63 6f  ts3cov-3.4 t2_co
1500: 6e 74 65 6e 74 20 22 0a 20 20 49 4e 53 45 52 54  ntent ".  INSERT
1510: 20 49 4e 54 4f 20 74 32 28 64 6f 63 69 64 2c 20   INTO t2(docid, 
1520: 5b 6a 6f 69 6e 20 24 63 6f 6c 73 20 2c 5d 29 20  [join $cols ,]) 
1530: 56 41 4c 55 45 53 28 36 30 30 30 30 2c 20 5b 6a  VALUES(60000, [j
1540: 6f 69 6e 20 24 76 61 6c 73 20 2c 5d 29 0a 22 0a  oin $vals ,]).".
1550: 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .#--------------
1560: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1570: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1580: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1590: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 49 66  -----------.# If
15a0: 20 74 6f 6f 20 6d 75 63 68 20 64 61 74 61 20 61   too much data a
15b0: 63 63 75 6d 75 6c 61 74 65 73 20 69 6e 20 74 68  ccumulates in th
15c0: 65 20 70 65 6e 64 69 6e 67 2d 74 65 72 6d 73 20  e pending-terms 
15d0: 68 61 73 68 20 74 61 62 6c 65 2c 20 69 74 20 69  hash table, it i
15e0: 73 0a 23 20 66 6c 75 73 68 65 64 20 74 6f 20 74  s.# flushed to t
15f0: 68 65 20 64 61 74 61 62 61 73 65 20 61 75 74 6f  he database auto
1600: 6d 61 74 69 63 61 6c 6c 79 2c 20 65 76 65 6e 20  matically, even 
1610: 69 66 20 74 68 65 20 74 72 61 6e 73 61 63 74 69  if the transacti
1620: 6f 6e 20 68 61 73 20 6e 6f 74 0a 23 20 66 69 6e  on has not.# fin
1630: 69 73 68 65 64 2e 20 54 68 65 20 66 6f 6c 6c 6f  ished. The follo
1640: 77 69 6e 67 20 74 65 73 74 73 20 63 68 65 63 6b  wing tests check
1650: 20 74 68 65 20 65 66 66 65 63 74 73 20 6f 66 20   the effects of 
1660: 65 6e 63 6f 75 6e 74 65 72 69 6e 67 20 61 6e 20  encountering an 
1670: 4f 4f 4d 20 0a 23 20 77 68 69 6c 65 20 64 6f 69  OOM .# while doi
1680: 6e 67 20 74 68 69 73 2e 0a 23 0a 64 6f 5f 74 65  ng this..#.do_te
1690: 73 74 20 66 74 73 33 63 6f 76 2d 34 2e 31 20 7b  st fts3cov-4.1 {
16a0: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
16b0: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
16c0: 54 41 42 4c 45 20 74 33 20 55 53 49 4e 47 20 66  TABLE t3 USING f
16d0: 74 73 33 28 78 29 3b 0a 20 20 20 20 49 4e 53 45  ts3(x);.    INSE
16e0: 52 54 20 49 4e 54 4f 20 74 33 28 74 33 29 20 56  RT INTO t3(t3) V
16f0: 41 4c 55 45 53 28 27 6e 6f 64 65 73 69 7a 65 3d  ALUES('nodesize=
1700: 32 34 27 29 3b 0a 20 20 20 20 49 4e 53 45 52 54  24');.    INSERT
1710: 20 49 4e 54 4f 20 74 33 28 74 33 29 20 56 41 4c   INTO t3(t3) VAL
1720: 55 45 53 28 27 6d 61 78 70 65 6e 64 69 6e 67 3d  UES('maxpending=
1730: 31 30 30 27 29 3b 0a 20 20 7d 0a 7d 20 7b 7d 0a  100');.  }.} {}.
1740: 73 65 74 20 44 4f 5f 4d 41 4c 4c 4f 43 5f 54 45  set DO_MALLOC_TE
1750: 53 54 20 31 20 0a 64 6f 5f 77 72 69 74 65 5f 74  ST 1 .do_write_t
1760: 65 73 74 20 66 74 73 33 63 6f 76 2d 34 2e 32 20  est fts3cov-4.2 
1770: 74 33 5f 63 6f 6e 74 65 6e 74 20 7b 0a 20 20 49  t3_content {.  I
1780: 4e 53 45 52 54 20 49 4e 54 4f 20 74 33 28 64 6f  NSERT INTO t3(do
1790: 63 69 64 2c 20 78 29 0a 20 20 20 20 53 45 4c 45  cid, x).    SELE
17a0: 43 54 20 31 2c 20 27 54 68 65 6e 20 43 68 72 69  CT 1, 'Then Chri
17b0: 73 74 61 62 65 6c 20 73 74 72 65 74 63 68 65 64  stabel stretched
17c0: 20 66 6f 72 74 68 20 68 65 72 20 68 61 6e 64 2c   forth her hand,
17d0: 27 20 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20 20 20  ' UNION ALL.    
17e0: 53 45 4c 45 43 54 20 33 2c 20 27 41 6e 64 20 63  SELECT 3, 'And c
17f0: 6f 6d 66 6f 72 74 65 64 20 66 61 69 72 20 47 65  omforted fair Ge
1800: 72 61 6c 64 69 6e 65 3a 27 20 20 20 20 20 20 20  raldine:'       
1810: 20 20 20 20 20 20 55 4e 49 4f 4e 20 41 4c 4c 0a        UNION ALL.
1820: 20 20 20 20 53 45 4c 45 43 54 20 34 2c 20 27 27      SELECT 4, ''
1830: 27 4f 20 77 65 6c 6c 2c 20 62 72 69 67 68 74 20  'O well, bright 
1840: 64 61 6d 65 2c 20 6d 61 79 20 79 6f 75 20 63 6f  dame, may you co
1850: 6d 6d 61 6e 64 27 20 20 20 20 55 4e 49 4f 4e 20  mmand'    UNION 
1860: 41 4c 4c 0a 20 20 20 20 53 45 4c 45 43 54 20 35  ALL.    SELECT 5
1870: 2c 20 27 54 68 65 20 73 65 72 76 69 63 65 20 6f  , 'The service o
1880: 66 20 53 69 72 20 4c 65 6f 6c 69 6e 65 3b 27 20  f Sir Leoline;' 
1890: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 55 4e                UN
18a0: 49 4f 4e 20 41 4c 4c 0a 20 20 20 20 53 45 4c 45  ION ALL.    SELE
18b0: 43 54 20 32 2c 20 27 41 6e 64 20 67 6c 61 64 6c  CT 2, 'And gladl
18c0: 79 20 6f 75 72 20 73 74 6f 75 74 20 63 68 69 76  y our stout chiv
18d0: 61 6c 72 79 27 20 20 20 20 20 20 20 20 20 20 20  alry'           
18e0: 20 20 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20 20 20    UNION ALL.    
18f0: 53 45 4c 45 43 54 20 37 2c 20 27 57 69 6c 6c 20  SELECT 7, 'Will 
1900: 68 65 20 73 65 6e 64 20 66 6f 72 74 68 2c 20 61  he send forth, a
1910: 6e 64 20 66 72 69 65 6e 64 73 20 77 69 74 68 61  nd friends witha
1920: 6c 2c 27 20 20 20 55 4e 49 4f 4e 20 41 4c 4c 0a  l,'   UNION ALL.
1930: 20 20 20 20 53 45 4c 45 43 54 20 38 2c 20 27 54      SELECT 8, 'T
1940: 6f 20 67 75 69 64 65 20 61 6e 64 20 67 75 61 72  o guide and guar
1950: 64 20 79 6f 75 20 73 61 66 65 20 61 6e 64 20 66  d you safe and f
1960: 72 65 65 27 20 20 20 20 20 20 55 4e 49 4f 4e 20  ree'      UNION 
1970: 41 4c 4c 0a 20 20 20 20 53 45 4c 45 43 54 20 36  ALL.    SELECT 6
1980: 2c 20 27 48 6f 6d 65 20 74 6f 20 79 6f 75 72 20  , 'Home to your 
1990: 6e 6f 62 6c 65 20 66 61 74 68 65 72 27 27 73 20  noble father''s 
19a0: 68 61 6c 6c 2e 27 27 27 0a 7d 0a 0a 23 2d 2d 2d  hall.'''.}..#---
19b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
19c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
19d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
19e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
19f0: 2d 2d 2d 2d 2d 2d 0a 23 20 57 68 65 6e 20 62 75  ------.# When bu
1a00: 69 6c 64 69 6e 67 20 74 68 65 20 69 6e 74 65 72  ilding the inter
1a10: 6e 61 6c 20 74 72 65 65 20 73 74 72 75 63 74 75  nal tree structu
1a20: 72 65 20 66 6f 72 20 65 61 63 68 20 73 65 67 6d  re for each segm
1a30: 65 6e 74 20 62 2d 74 72 65 65 2c 20 46 54 53 33  ent b-tree, FTS3
1a40: 0a 23 20 61 73 73 75 6d 65 73 20 74 68 61 74 20  .# assumes that 
1a50: 74 68 65 20 63 6f 6e 74 65 6e 74 20 6f 66 20 65  the content of e
1a60: 61 63 68 20 69 6e 74 65 72 6e 61 6c 20 6e 6f 64  ach internal nod
1a70: 65 20 77 69 6c 6c 20 62 65 20 6c 65 73 73 20 74  e will be less t
1a80: 68 61 6e 0a 23 20 24 6e 6f 64 65 73 69 7a 65 20  han.# $nodesize 
1a90: 62 79 74 65 73 2c 20 77 68 65 72 65 20 24 6e 6f  bytes, where $no
1aa0: 64 65 73 69 7a 65 20 69 73 20 74 68 65 20 61 64  desize is the ad
1ab0: 76 69 73 6f 72 79 20 6e 6f 64 65 20 73 69 7a 65  visory node size
1ac0: 2e 20 49 66 20 74 68 69 73 20 74 75 72 6e 73 0a  . If this turns.
1ad0: 23 20 6f 75 74 20 74 6f 20 62 65 20 75 6e 74 72  # out to be untr
1ae0: 75 65 2c 20 74 68 65 6e 20 61 6e 20 65 78 74 72  ue, then an extr
1af0: 61 20 62 75 66 66 65 72 20 6d 75 73 74 20 62 65  a buffer must be
1b00: 20 6d 61 6c 6c 6f 63 27 64 20 66 6f 72 20 65 61   malloc'd for ea
1b10: 63 68 20 74 65 72 6d 2e 0a 23 20 54 68 69 73 20  ch term..# This 
1b20: 74 65 73 74 20 63 61 73 65 20 74 65 73 74 73 20  test case tests 
1b30: 74 68 65 73 65 20 70 61 74 68 73 20 61 6e 64 20  these paths and 
1b40: 74 68 65 20 65 66 66 65 63 74 73 20 6f 66 20 73  the effects of s
1b50: 61 69 64 20 6d 61 6c 6c 6f 63 73 20 66 61 69 6c  aid mallocs fail
1b60: 69 6e 67 0a 23 20 62 79 20 69 6e 73 65 72 74 69  ing.# by inserti
1b70: 6e 67 20 69 6e 73 65 72 74 20 61 20 64 6f 63 75  ng insert a docu
1b80: 6d 65 6e 74 20 77 69 74 68 20 73 6f 6d 65 20 66  ment with some f
1b90: 61 69 72 6c 79 20 6c 61 72 67 65 20 74 65 72 6d  airly large term
1ba0: 73 20 69 6e 74 6f 20 61 0a 23 20 66 75 6c 6c 2d  s into a.# full-
1bb0: 74 65 78 74 20 74 61 62 6c 65 20 77 69 74 68 20  text table with 
1bc0: 61 20 76 65 72 79 20 73 6d 61 6c 6c 20 6e 6f 64  a very small nod
1bd0: 65 2d 73 69 7a 65 2e 20 0a 23 0a 23 20 54 65 73  e-size. .#.# Tes
1be0: 74 20 74 68 69 73 20 68 61 6e 64 6c 69 6e 67 20  t this handling 
1bf0: 6f 66 20 6c 61 72 67 65 20 74 65 72 6d 73 20 69  of large terms i
1c00: 6e 20 74 68 72 65 65 20 63 6f 6e 74 65 78 74 73  n three contexts
1c10: 3a 0a 23 0a 23 20 20 20 31 2e 20 57 68 65 6e 20  :.#.#   1. When 
1c20: 66 6c 75 73 68 69 6e 67 20 74 68 65 20 70 65 6e  flushing the pen
1c30: 64 69 6e 67 2d 74 65 72 6d 73 20 74 61 62 6c 65  ding-terms table
1c40: 2e 0a 23 20 20 20 32 2e 20 57 68 65 6e 20 6f 70  ..#   2. When op
1c50: 74 69 6d 69 7a 69 6e 67 20 74 68 65 20 64 61 74  timizing the dat
1c60: 61 20 73 74 72 75 63 74 75 72 65 73 20 75 73 69  a structures usi
1c70: 6e 67 20 74 68 65 20 49 4e 53 45 52 54 20 73 79  ng the INSERT sy
1c80: 6e 74 61 78 2e 20 0a 23 20 20 20 32 2e 20 57 68  ntax. .#   2. Wh
1c90: 65 6e 20 6f 70 74 69 6d 69 7a 69 6e 67 20 74 68  en optimizing th
1ca0: 65 20 64 61 74 61 20 73 74 72 75 63 74 75 72 65  e data structure
1cb0: 73 20 75 73 69 6e 67 20 74 68 65 20 64 65 70 72  s using the depr
1cc0: 65 63 61 74 65 64 20 53 45 4c 45 43 54 20 73 79  ecated SELECT sy
1cd0: 6e 74 61 78 2e 20 0a 23 0a 64 6f 5f 74 65 73 74  ntax. .#.do_test
1ce0: 20 66 74 73 33 63 6f 76 2d 35 2e 31 20 7b 0a 20   fts3cov-5.1 {. 
1cf0: 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 43   execsql {.    C
1d00: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
1d10: 42 4c 45 20 74 34 20 55 53 49 4e 47 20 66 74 73  BLE t4 USING fts
1d20: 33 28 78 29 3b 0a 20 20 20 20 49 4e 53 45 52 54  3(x);.    INSERT
1d30: 20 49 4e 54 4f 20 74 34 28 74 34 29 20 56 41 4c   INTO t4(t4) VAL
1d40: 55 45 53 28 27 6e 6f 64 65 73 69 7a 65 3d 32 34  UES('nodesize=24
1d50: 27 29 3b 0a 20 20 7d 0a 7d 20 7b 7d 0a 73 65 74  ');.  }.} {}.set
1d60: 20 44 4f 5f 4d 41 4c 4c 4f 43 5f 54 45 53 54 20   DO_MALLOC_TEST 
1d70: 31 0a 0a 23 20 54 65 73 74 20 77 68 65 6e 20 66  1..# Test when f
1d80: 6c 75 73 68 69 6e 67 20 70 65 6e 64 69 6e 67 2d  lushing pending-
1d90: 74 65 72 6d 73 20 74 61 62 6c 65 2e 0a 64 6f 5f  terms table..do_
1da0: 77 72 69 74 65 5f 74 65 73 74 20 66 74 73 33 63  write_test fts3c
1db0: 6f 76 2d 35 2e 32 20 74 34 5f 63 6f 6e 74 65 6e  ov-5.2 t4_conten
1dc0: 74 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  t {.  INSERT INT
1dd0: 4f 20 74 34 0a 20 20 20 20 53 45 4c 45 43 54 20  O t4.    SELECT 
1de0: 27 49 74 69 73 61 6e 61 6e 63 69 65 6e 74 4d 61  'ItisanancientMa
1df0: 72 69 6e 65 72 41 6e 64 68 65 73 74 6f 70 70 65  rinerAndhestoppe
1e00: 74 68 6f 6e 65 6f 66 74 68 72 65 65 41 41 27 20  thoneofthreeAA' 
1e10: 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20 20 20 53 45  UNION ALL.    SE
1e20: 4c 45 43 54 20 27 49 74 69 73 61 6e 61 6e 63 69  LECT 'Itisananci
1e30: 65 6e 74 4d 61 72 69 6e 65 72 41 6e 64 68 65 73  entMarinerAndhes
1e40: 74 6f 70 70 65 74 68 6f 6e 65 6f 66 74 68 72 65  toppethoneofthre
1e50: 65 42 42 27 20 55 4e 49 4f 4e 20 41 4c 4c 0a 20  eBB' UNION ALL. 
1e60: 20 20 20 53 45 4c 45 43 54 20 27 49 74 69 73 61     SELECT 'Itisa
1e70: 6e 61 6e 63 69 65 6e 74 4d 61 72 69 6e 65 72 41  nancientMarinerA
1e80: 6e 64 68 65 73 74 6f 70 70 65 74 68 6f 6e 65 6f  ndhestoppethoneo
1e90: 66 74 68 72 65 65 43 43 27 20 55 4e 49 4f 4e 20  fthreeCC' UNION 
1ea0: 41 4c 4c 0a 20 20 20 20 53 45 4c 45 43 54 20 27  ALL.    SELECT '
1eb0: 42 79 74 68 79 6c 6f 6e 67 67 72 65 79 62 65 61  Bythylonggreybea
1ec0: 72 64 61 6e 64 67 6c 69 74 74 65 72 69 6e 67 65  rdandglitteringe
1ed0: 79 65 4e 6f 77 77 68 65 72 65 66 6f 72 65 73 74  yeNowwhereforest
1ee0: 6f 70 70 73 74 41 41 27 20 55 4e 49 4f 4e 20 41  oppstAA' UNION A
1ef0: 4c 4c 0a 20 20 20 20 53 45 4c 45 43 54 20 27 42  LL.    SELECT 'B
1f00: 79 74 68 79 6c 6f 6e 67 67 72 65 79 62 65 61 72  ythylonggreybear
1f10: 64 61 6e 64 67 6c 69 74 74 65 72 69 6e 67 65 79  dandglitteringey
1f20: 65 4e 6f 77 77 68 65 72 65 66 6f 72 65 73 74 6f  eNowwhereforesto
1f30: 70 70 73 74 42 42 27 20 55 4e 49 4f 4e 20 41 4c  ppstBB' UNION AL
1f40: 4c 0a 20 20 20 20 53 45 4c 45 43 54 20 27 42 79  L.    SELECT 'By
1f50: 74 68 79 6c 6f 6e 67 67 72 65 79 62 65 61 72 64  thylonggreybeard
1f60: 61 6e 64 67 6c 69 74 74 65 72 69 6e 67 65 79 65  andglitteringeye
1f70: 4e 6f 77 77 68 65 72 65 66 6f 72 65 73 74 6f 70  Nowwhereforestop
1f80: 70 73 74 43 43 27 0a 7d 0a 0a 23 20 54 65 73 74  pstCC'.}..# Test
1f90: 20 77 68 65 6e 20 6f 70 74 69 6d 69 7a 69 6e 67   when optimizing
1fa0: 20 76 69 61 20 49 4e 53 45 52 54 2e 0a 64 6f 5f   via INSERT..do_
1fb0: 74 65 73 74 20 66 74 73 33 63 6f 76 2d 35 2e 33  test fts3cov-5.3
1fc0: 20 7b 20 65 78 65 63 73 71 6c 20 7b 20 49 4e 53   { execsql { INS
1fd0: 45 52 54 20 49 4e 54 4f 20 74 34 20 56 41 4c 55  ERT INTO t4 VALU
1fe0: 45 53 28 27 65 78 74 72 61 21 27 29 20 7d 20 7d  ES('extra!') } }
1ff0: 20 7b 7d 0a 64 6f 5f 77 72 69 74 65 5f 74 65 73   {}.do_write_tes
2000: 74 20 66 74 73 33 63 6f 76 2d 35 2e 32 20 74 34  t fts3cov-5.2 t4
2010: 5f 73 65 67 6d 65 6e 74 73 20 7b 20 49 4e 53 45  _segments { INSE
2020: 52 54 20 49 4e 54 4f 20 74 34 28 74 34 29 20 56  RT INTO t4(t4) V
2030: 41 4c 55 45 53 28 27 6f 70 74 69 6d 69 7a 65 27  ALUES('optimize'
2040: 29 20 7d 0a 0a 23 20 54 65 73 74 20 77 68 65 6e  ) }..# Test when
2050: 20 6f 70 74 69 6d 69 7a 69 6e 67 20 76 69 61 20   optimizing via 
2060: 53 45 4c 45 43 54 2e 0a 64 6f 5f 74 65 73 74 20  SELECT..do_test 
2070: 66 74 73 33 63 6f 76 2d 35 2e 35 20 7b 20 65 78  fts3cov-5.5 { ex
2080: 65 63 73 71 6c 20 7b 20 49 4e 53 45 52 54 20 49  ecsql { INSERT I
2090: 4e 54 4f 20 74 34 20 56 41 4c 55 45 53 28 27 6d  NTO t4 VALUES('m
20a0: 6f 72 65 20 65 78 74 72 61 21 27 29 20 7d 20 7d  ore extra!') } }
20b0: 20 7b 7d 0a 64 6f 5f 77 72 69 74 65 5f 74 65 73   {}.do_write_tes
20c0: 74 20 66 74 73 33 63 6f 76 2d 35 2e 36 20 74 34  t fts3cov-5.6 t4
20d0: 5f 73 65 67 6d 65 6e 74 73 20 7b 0a 20 20 53 45  _segments {.  SE
20e0: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 28 53 45 4c  LECT * FROM (SEL
20f0: 45 43 54 20 6f 70 74 69 6d 69 7a 65 28 74 34 29  ECT optimize(t4)
2100: 20 46 52 4f 4d 20 74 34 20 4c 49 4d 49 54 20 31   FROM t4 LIMIT 1
2110: 29 0a 20 20 45 58 43 45 50 54 20 53 45 4c 45 43  ).  EXCEPT SELEC
2120: 54 20 27 49 6e 64 65 78 20 6f 70 74 69 6d 69 7a  T 'Index optimiz
2130: 65 64 27 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d  ed'.}..#--------
2140: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2150: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2160: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2170: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2180: 2d 0a 23 20 57 68 65 6e 20 6d 65 72 67 69 6e 67  -.# When merging
2190: 20 61 6c 6c 20 73 65 67 6d 65 6e 74 73 20 61 74   all segments at
21a0: 20 61 20 67 69 76 65 6e 20 6c 65 76 65 6c 20 74   a given level t
21b0: 6f 20 63 72 65 61 74 65 20 61 20 73 69 6e 67 6c  o create a singl
21c0: 65 20 73 65 67 6d 65 6e 74 0a 23 20 61 74 20 6c  e segment.# at l
21d0: 65 76 65 6c 2b 31 2c 20 46 54 53 33 20 72 75 6e  evel+1, FTS3 run
21e0: 73 20 61 20 71 75 65 72 79 20 6f 66 20 74 68 65  s a query of the
21f0: 20 66 6f 72 6d 3a 0a 23 0a 23 20 20 20 53 45 4c   form:.#.#   SEL
2200: 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f  ECT count(*) FRO
2210: 4d 20 25 5f 73 65 67 64 69 72 20 57 48 45 52 45  M %_segdir WHERE
2220: 20 6c 65 76 65 6c 20 3d 20 3f 0a 23 0a 23 20 54   level = ?.#.# T
2230: 68 65 20 71 75 65 72 79 20 69 73 20 63 6f 6d 70  he query is comp
2240: 69 6c 65 64 20 74 68 65 20 66 69 72 73 74 20 74  iled the first t
2250: 69 6d 65 20 74 68 69 73 20 6f 70 65 72 61 74 69  ime this operati
2260: 6f 6e 20 69 73 20 72 65 71 75 69 72 65 64 20 61  on is required a
2270: 6e 64 0a 23 20 72 65 75 73 65 64 20 74 68 65 72  nd.# reused ther
2280: 65 61 66 74 65 72 2e 20 54 68 69 73 20 74 65 73  eafter. This tes
2290: 74 20 61 69 6d 73 20 74 6f 20 74 65 73 74 20 74  t aims to test t
22a0: 68 65 20 65 66 66 65 63 74 73 20 6f 66 20 61 6e  he effects of an
22b0: 20 4f 4f 4d 20 77 68 69 6c 65 0a 23 20 70 72 65   OOM while.# pre
22c0: 70 61 72 69 6e 67 20 61 6e 64 20 65 78 65 63 75  paring and execu
22d0: 74 69 6e 67 20 74 68 69 73 20 71 75 65 72 79 20  ting this query 
22e0: 66 6f 72 20 74 68 65 20 66 69 72 73 74 20 74 69  for the first ti
22f0: 6d 65 2e 0a 23 0a 23 20 54 68 65 6e 2c 20 6b 65  me..#.# Then, ke
2300: 65 70 20 69 6e 73 65 72 74 69 6e 67 20 72 6f 77  ep inserting row
2310: 73 20 69 6e 74 6f 20 74 68 65 20 74 61 62 6c 65  s into the table
2320: 20 73 6f 20 74 68 61 74 20 74 68 65 20 65 66 66   so that the eff
2330: 65 63 74 73 20 6f 66 20 61 6e 20 4f 4f 4d 0a 23  ects of an OOM.#
2340: 20 77 68 69 6c 65 20 72 65 2d 65 78 65 63 75 74   while re-execut
2350: 69 6e 67 20 74 68 65 20 73 61 6d 65 20 71 75 65  ing the same que
2360: 72 79 20 63 61 6e 20 61 6c 73 6f 20 62 65 20 74  ry can also be t
2370: 65 73 74 65 64 2e 0a 23 0a 64 6f 5f 74 65 73 74  ested..#.do_test
2380: 20 66 74 73 33 63 6f 76 2d 36 2e 31 20 7b 0a 20   fts3cov-6.1 {. 
2390: 20 65 78 65 63 73 71 6c 20 7b 20 43 52 45 41 54   execsql { CREAT
23a0: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20  E VIRTUAL TABLE 
23b0: 74 35 20 55 53 49 4e 47 20 66 74 73 33 28 78 29  t5 USING fts3(x)
23c0: 20 7d 0a 20 20 66 6f 72 20 7b 73 65 74 20 69 20   }.  for {set i 
23d0: 30 7d 20 7b 24 69 3c 31 36 7d 20 7b 69 6e 63 72  0} {$i<16} {incr
23e0: 20 69 7d 20 7b 20 65 78 65 63 73 71 6c 20 22 49   i} { execsql "I
23f0: 4e 53 45 52 54 20 49 4e 54 4f 20 74 35 20 56 41  NSERT INTO t5 VA
2400: 4c 55 45 53 28 27 74 65 72 6d 24 69 27 29 22 20  LUES('term$i')" 
2410: 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 53 45  }.  execsql { SE
2420: 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52  LECT count(*) FR
2430: 4f 4d 20 74 35 5f 73 65 67 64 69 72 20 7d 0a 7d  OM t5_segdir }.}
2440: 20 7b 31 36 7d 0a 0a 23 20 46 69 72 73 74 20 74   {16}..# First t
2450: 69 6d 65 2e 0a 64 62 20 63 6c 6f 73 65 0a 73 71  ime..db close.sq
2460: 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e 64 62  lite3 db test.db
2470: 0a 64 6f 5f 77 72 69 74 65 5f 74 65 73 74 20 66  .do_write_test f
2480: 74 73 33 63 6f 76 2d 36 2e 32 20 74 35 5f 63 6f  ts3cov-6.2 t5_co
2490: 6e 74 65 6e 74 20 7b 0a 20 20 49 4e 53 45 52 54  ntent {.  INSERT
24a0: 20 49 4e 54 4f 20 74 35 20 56 41 4c 55 45 53 28   INTO t5 VALUES(
24b0: 27 73 65 67 6d 65 6e 74 20 6e 75 6d 62 65 72 20  'segment number 
24c0: 31 36 21 27 29 3b 0a 7d 0a 0a 23 20 53 65 63 6f  16!');.}..# Seco
24d0: 6e 64 20 74 69 6d 65 2e 0a 64 6f 5f 74 65 73 74  nd time..do_test
24e0: 20 66 74 73 33 63 6f 76 2d 36 2e 33 20 7b 0a 20   fts3cov-6.3 {. 
24f0: 20 66 6f 72 20 7b 73 65 74 20 69 20 31 7d 20 7b   for {set i 1} {
2500: 24 69 3c 31 36 7d 20 7b 69 6e 63 72 20 69 7d 20  $i<16} {incr i} 
2510: 7b 20 65 78 65 63 73 71 6c 20 22 49 4e 53 45 52  { execsql "INSER
2520: 54 20 49 4e 54 4f 20 74 35 20 56 41 4c 55 45 53  T INTO t5 VALUES
2530: 28 27 74 65 72 6d 24 69 27 29 22 20 7d 0a 20 20  ('term$i')" }.  
2540: 65 78 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54  execsql { SELECT
2550: 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 74   count(*) FROM t
2560: 35 5f 73 65 67 64 69 72 20 7d 0a 7d 20 7b 31 37  5_segdir }.} {17
2570: 7d 0a 64 6f 5f 77 72 69 74 65 5f 74 65 73 74 20  }.do_write_test 
2580: 66 74 73 33 63 6f 76 2d 36 2e 34 20 74 35 5f 63  fts3cov-6.4 t5_c
2590: 6f 6e 74 65 6e 74 20 7b 0a 20 20 49 4e 53 45 52  ontent {.  INSER
25a0: 54 20 49 4e 54 4f 20 74 35 20 56 41 4c 55 45 53  T INTO t5 VALUES
25b0: 28 27 73 65 67 6d 65 6e 74 20 6e 75 6d 62 65 72  ('segment number
25c0: 20 31 36 21 27 29 3b 0a 7d 0a 0a 23 2d 2d 2d 2d   16!');.}..#----
25d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
25e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
25f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2600: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2610: 2d 2d 2d 2d 2d 0a 23 20 55 70 64 61 74 65 20 74  -----.# Update t
2620: 68 65 20 64 6f 63 69 64 20 6f 66 20 61 20 72 6f  he docid of a ro
2630: 77 2e 20 54 65 73 74 20 74 68 69 73 20 69 6e 20  w. Test this in 
2640: 74 77 6f 20 73 63 65 6e 61 72 69 6f 73 3a 0a 23  two scenarios:.#
2650: 0a 23 20 20 20 31 2e 20 57 68 65 6e 20 74 68 65  .#   1. When the
2660: 20 72 6f 77 20 62 65 69 6e 67 20 75 70 64 61 74   row being updat
2670: 65 64 20 69 73 20 74 68 65 20 6f 6e 6c 79 20 72  ed is the only r
2680: 6f 77 20 69 6e 20 74 68 65 20 74 61 62 6c 65 2e  ow in the table.
2690: 0a 23 20 20 20 32 2e 20 57 68 65 6e 20 69 74 20  .#   2. When it 
26a0: 69 73 20 6e 6f 74 2e 0a 23 0a 23 20 54 68 65 20  is not..#.# The 
26b0: 74 77 6f 20 63 61 73 65 73 20 61 62 6f 76 65 20  two cases above 
26c0: 74 61 6b 65 20 64 69 66 66 65 72 65 6e 74 20 70  take different p
26d0: 61 74 68 73 20 62 65 63 61 75 73 65 20 69 6e 20  aths because in 
26e0: 63 61 73 65 20 31 20 61 6c 6c 20 64 61 74 61 20  case 1 all data 
26f0: 0a 23 20 73 74 72 75 63 74 75 72 65 73 20 63 61  .# structures ca
2700: 6e 20 73 69 6d 70 6c 79 20 62 65 20 65 6d 70 74  n simply be empt
2710: 69 65 64 20 62 65 66 6f 72 65 20 69 6e 73 65 72  ied before inser
2720: 74 69 6e 67 20 74 68 65 20 6e 65 77 20 72 6f 77  ting the new row
2730: 20 72 65 63 6f 72 64 2e 0a 23 20 49 6e 20 63 61   record..# In ca
2740: 73 65 20 32 2c 20 74 68 65 20 64 61 74 61 20 73  se 2, the data s
2750: 74 72 75 63 74 75 72 65 73 20 61 63 74 75 61 6c  tructures actual
2760: 6c 79 20 68 61 76 65 20 74 6f 20 62 65 20 75 70  ly have to be up
2770: 64 61 74 65 64 2e 0a 23 0a 64 6f 5f 74 65 73 74  dated..#.do_test
2780: 20 66 74 73 33 63 6f 76 2d 37 2e 31 20 7b 0a 20   fts3cov-7.1 {. 
2790: 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 43   execsql {.    C
27a0: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
27b0: 42 4c 45 20 74 37 20 55 53 49 4e 47 20 66 74 73  BLE t7 USING fts
27c0: 33 28 61 2c 20 62 2c 20 63 29 3b 0a 20 20 20 20  3(a, b, c);.    
27d0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 37 20 56  INSERT INTO t7 V
27e0: 41 4c 55 45 53 28 27 41 27 2c 20 27 42 27 2c 20  ALUES('A', 'B', 
27f0: 27 43 27 29 3b 0a 20 20 20 20 55 50 44 41 54 45  'C');.    UPDATE
2800: 20 74 37 20 53 45 54 20 64 6f 63 69 64 20 3d 20   t7 SET docid = 
2810: 35 3b 0a 20 20 20 20 53 45 4c 45 43 54 20 64 6f  5;.    SELECT do
2820: 63 69 64 2c 20 2a 20 46 52 4f 4d 20 74 37 3b 0a  cid, * FROM t7;.
2830: 20 20 7d 0a 7d 20 7b 35 20 41 20 42 20 43 7d 0a    }.} {5 A B C}.
2840: 64 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d  do_test fts3cov-
2850: 37 2e 32 20 7b 0a 20 20 65 78 65 63 73 71 6c 20  7.2 {.  execsql 
2860: 7b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  {.    INSERT INT
2870: 4f 20 74 37 20 56 41 4c 55 45 53 28 27 44 27 2c  O t7 VALUES('D',
2880: 20 27 45 27 2c 20 27 46 27 29 3b 0a 20 20 20 20   'E', 'F');.    
2890: 55 50 44 41 54 45 20 74 37 20 53 45 54 20 64 6f  UPDATE t7 SET do
28a0: 63 69 64 20 3d 20 31 20 57 48 45 52 45 20 64 6f  cid = 1 WHERE do
28b0: 63 69 64 20 3d 20 36 3b 0a 20 20 20 20 53 45 4c  cid = 6;.    SEL
28c0: 45 43 54 20 64 6f 63 69 64 2c 20 2a 20 46 52 4f  ECT docid, * FRO
28d0: 4d 20 74 37 3b 0a 20 20 7d 0a 7d 20 7b 31 20 44  M t7;.  }.} {1 D
28e0: 20 45 20 46 20 35 20 41 20 42 20 43 7d 0a 0a 23   E F 5 A B C}..#
28f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2900: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2910: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2920: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2930: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 49 66 20 61  ---------.# If a
2940: 20 73 65 74 20 6f 66 20 64 6f 63 75 6d 65 6e 74   set of document
2950: 73 20 61 72 65 20 6d 6f 64 69 66 69 65 64 20 77  s are modified w
2960: 69 74 68 69 6e 20 61 20 74 72 61 6e 73 61 63 74  ithin a transact
2970: 69 6f 6e 2c 20 74 68 65 20 0a 23 20 70 65 6e 64  ion, the .# pend
2980: 69 6e 67 2d 74 65 72 6d 73 20 74 61 62 6c 65 20  ing-terms table 
2990: 6d 75 73 74 20 62 65 20 66 6c 75 73 68 65 64 20  must be flushed 
29a0: 65 61 63 68 20 74 69 6d 65 20 61 20 64 6f 63 75  each time a docu
29b0: 6d 65 6e 74 20 77 69 74 68 20 61 20 64 6f 63 69  ment with a doci
29c0: 64 0a 23 20 6c 65 73 73 20 74 68 61 6e 20 6f 72  d.# less than or
29d0: 20 65 71 75 61 6c 20 74 6f 20 74 68 65 20 70 72   equal to the pr
29e0: 65 76 69 6f 75 73 20 64 6f 63 69 64 20 69 73 20  evious docid is 
29f0: 6d 6f 64 69 66 69 65 64 2e 20 0a 23 0a 23 20 54  modified. .#.# T
2a00: 68 69 73 20 74 65 73 74 20 63 68 65 63 6b 73 20  his test checks 
2a10: 74 68 65 20 65 66 66 65 63 74 73 20 6f 66 20 61  the effects of a
2a20: 6e 20 4f 4f 4d 20 65 72 72 6f 72 20 6f 63 63 75  n OOM error occu
2a30: 72 69 6e 67 20 77 68 65 6e 20 74 68 65 20 0a 23  ring when the .#
2a40: 20 70 65 6e 64 69 6e 67 2d 74 65 72 6d 73 20 74   pending-terms t
2a50: 61 62 6c 65 20 69 73 20 66 6c 75 73 68 65 64 20  able is flushed 
2a60: 66 6f 72 20 74 68 69 73 20 72 65 61 73 6f 6e 20  for this reason 
2a70: 61 73 20 70 61 72 74 20 6f 66 20 61 20 44 45 4c  as part of a DEL
2a80: 45 54 45 20 0a 23 20 73 74 61 74 65 6d 65 6e 74  ETE .# statement
2a90: 2e 0a 23 0a 64 6f 5f 6d 61 6c 6c 6f 63 5f 74 65  ..#.do_malloc_te
2aa0: 73 74 20 66 74 73 33 63 6f 76 2d 38 20 2d 73 71  st fts3cov-8 -sq
2ab0: 6c 70 72 65 70 20 7b 0a 20 20 42 45 47 49 4e 3b  lprep {.  BEGIN;
2ac0: 0a 20 20 20 20 43 52 45 41 54 45 20 56 49 52 54  .    CREATE VIRT
2ad0: 55 41 4c 20 54 41 42 4c 45 20 74 38 20 55 53 49  UAL TABLE t8 USI
2ae0: 4e 47 20 66 74 73 33 3b 0a 20 20 20 20 49 4e 53  NG fts3;.    INS
2af0: 45 52 54 20 49 4e 54 4f 20 74 38 20 56 41 4c 55  ERT INTO t8 VALU
2b00: 45 53 28 27 74 68 65 20 6f 75 74 70 75 74 20 6f  ES('the output o
2b10: 66 20 65 61 63 68 20 62 61 74 63 68 20 72 75 6e  f each batch run
2b20: 27 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  ');.    INSERT I
2b30: 4e 54 4f 20 74 38 20 56 41 4c 55 45 53 28 27 28  NTO t8 VALUES('(
2b40: 70 6f 73 73 69 62 6c 79 20 61 20 64 61 79 27 27  possibly a day''
2b50: 73 20 77 6f 72 6b 29 27 29 3b 0a 20 20 20 20 49  s work)');.    I
2b60: 4e 53 45 52 54 20 49 4e 54 4f 20 74 38 20 56 41  NSERT INTO t8 VA
2b70: 4c 55 45 53 28 27 77 61 73 20 77 72 69 74 74 65  LUES('was writte
2b80: 6e 20 74 6f 20 74 77 6f 20 73 65 70 61 72 61 74  n to two separat
2b90: 65 20 64 69 73 6b 73 27 29 3b 0a 20 20 43 4f 4d  e disks');.  COM
2ba0: 4d 49 54 3b 0a 7d 20 2d 73 71 6c 62 6f 64 79 20  MIT;.} -sqlbody 
2bb0: 7b 0a 20 20 42 45 47 49 4e 3b 0a 20 20 20 20 44  {.  BEGIN;.    D
2bc0: 45 4c 45 54 45 20 46 52 4f 4d 20 74 38 20 57 48  ELETE FROM t8 WH
2bd0: 45 52 45 20 72 6f 77 69 64 20 3d 20 33 3b 0a 20  ERE rowid = 3;. 
2be0: 20 20 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 74     DELETE FROM t
2bf0: 38 20 57 48 45 52 45 20 72 6f 77 69 64 20 3d 20  8 WHERE rowid = 
2c00: 32 3b 0a 20 20 20 20 44 45 4c 45 54 45 20 46 52  2;.    DELETE FR
2c10: 4f 4d 20 74 38 20 57 48 45 52 45 20 72 6f 77 69  OM t8 WHERE rowi
2c20: 64 20 3d 20 31 3b 0a 20 20 43 4f 4d 4d 49 54 3b  d = 1;.  COMMIT;
2c30: 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .}..#-----------
2c40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23  --------------.#
2c80: 20 54 65 73 74 20 73 6f 6d 65 20 62 72 61 6e 63   Test some branc
2c90: 68 65 73 20 69 6e 20 74 68 65 20 63 6f 64 65 20  hes in the code 
2ca0: 74 68 61 74 20 68 61 6e 64 6c 65 73 20 22 73 70  that handles "sp
2cb0: 65 63 69 61 6c 22 20 69 6e 73 65 72 74 73 20 6c  ecial" inserts l
2cc0: 69 6b 65 3a 0a 23 0a 23 20 20 20 49 4e 53 45 52  ike:.#.#   INSER
2cd0: 54 20 49 4e 54 4f 20 74 31 28 74 31 29 20 56 41  T INTO t1(t1) VA
2ce0: 4c 55 45 53 28 27 6f 70 74 69 6d 69 7a 65 27 29  LUES('optimize')
2cf0: 3b 0a 23 0a 23 20 41 6c 73 6f 20 74 65 73 74 20  ;.#.# Also test 
2d00: 74 68 61 74 20 61 6e 20 6f 70 74 69 6d 69 7a 65  that an optimize
2d10: 20 28 49 4e 53 45 52 54 20 6d 65 74 68 6f 64 29   (INSERT method)
2d20: 20 77 6f 72 6b 73 20 6f 6e 20 61 6e 20 65 6d 70   works on an emp
2d30: 74 79 20 74 61 62 6c 65 2e 0a 23 0a 73 65 74 20  ty table..#.set 
2d40: 44 4f 5f 4d 41 4c 4c 4f 43 5f 54 45 53 54 20 30  DO_MALLOC_TEST 0
2d50: 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76  .do_test fts3cov
2d60: 2d 39 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c  -9.1 {.  execsql
2d70: 20 7b 20 43 52 45 41 54 45 20 56 49 52 54 55 41   { CREATE VIRTUA
2d80: 4c 20 54 41 42 4c 45 20 78 78 20 55 53 49 4e 47  L TABLE xx USING
2d90: 20 66 74 73 33 20 7d 0a 7d 20 7b 7d 0a 64 6f 5f   fts3 }.} {}.do_
2da0: 65 72 72 6f 72 5f 74 65 73 74 20 66 74 73 33 63  error_test fts3c
2db0: 6f 76 2d 39 2e 32 20 7b 0a 20 20 49 4e 53 45 52  ov-9.2 {.  INSER
2dc0: 54 20 49 4e 54 4f 20 78 78 28 78 78 29 20 56 41  T INTO xx(xx) VA
2dd0: 4c 55 45 53 28 27 6f 70 74 69 6d 69 73 65 27 29  LUES('optimise')
2de0: 3b 20 20 20 2d 2d 20 42 72 69 74 69 73 68 20 73  ;   -- British s
2df0: 70 65 6c 6c 69 6e 67 0a 7d 20 7b 53 51 4c 20 6c  pelling.} {SQL l
2e00: 6f 67 69 63 20 65 72 72 6f 72 20 6f 72 20 6d 69  ogic error or mi
2e10: 73 73 69 6e 67 20 64 61 74 61 62 61 73 65 7d 0a  ssing database}.
2e20: 64 6f 5f 65 72 72 6f 72 5f 74 65 73 74 20 66 74  do_error_test ft
2e30: 73 33 63 6f 76 2d 39 2e 33 20 7b 0a 20 20 49 4e  s3cov-9.3 {.  IN
2e40: 53 45 52 54 20 49 4e 54 4f 20 78 78 28 78 78 29  SERT INTO xx(xx)
2e50: 20 56 41 4c 55 45 53 28 27 73 68 6f 72 74 27 29   VALUES('short')
2e60: 3b 0a 7d 20 7b 53 51 4c 20 6c 6f 67 69 63 20 65  ;.} {SQL logic e
2e70: 72 72 6f 72 20 6f 72 20 6d 69 73 73 69 6e 67 20  rror or missing 
2e80: 64 61 74 61 62 61 73 65 7d 0a 64 6f 5f 65 72 72  database}.do_err
2e90: 6f 72 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d  or_test fts3cov-
2ea0: 39 2e 34 20 7b 0a 20 20 49 4e 53 45 52 54 20 49  9.4 {.  INSERT I
2eb0: 4e 54 4f 20 78 78 28 78 78 29 20 56 41 4c 55 45  NTO xx(xx) VALUE
2ec0: 53 28 27 77 61 79 74 6f 6f 6c 6f 6e 67 74 6f 62  S('waytoolongtob
2ed0: 65 63 6f 72 72 65 63 74 27 29 3b 0a 7d 20 7b 53  ecorrect');.} {S
2ee0: 51 4c 20 6c 6f 67 69 63 20 65 72 72 6f 72 20 6f  QL logic error o
2ef0: 72 20 6d 69 73 73 69 6e 67 20 64 61 74 61 62 61  r missing databa
2f00: 73 65 7d 0a 64 6f 5f 74 65 73 74 20 66 74 73 33  se}.do_test fts3
2f10: 63 6f 76 2d 39 2e 35 20 7b 0a 20 20 65 78 65 63  cov-9.5 {.  exec
2f20: 73 71 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54  sql { INSERT INT
2f30: 4f 20 78 78 28 78 78 29 20 56 41 4c 55 45 53 28  O xx(xx) VALUES(
2f40: 27 6f 70 74 69 6d 69 7a 65 27 29 20 7d 0a 7d 20  'optimize') }.} 
2f50: 7b 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  {}..#-----------
2f60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2f70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2f80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2f90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23  --------------.#
2fa0: 20 54 65 73 74 20 74 68 61 74 20 61 20 74 61 62   Test that a tab
2fb0: 6c 65 20 63 61 6e 20 62 65 20 6f 70 74 69 6d 69  le can be optimi
2fc0: 7a 65 64 20 69 6e 20 74 68 65 20 6d 69 64 64 6c  zed in the middl
2fd0: 65 20 6f 66 20 61 20 74 72 61 6e 73 61 63 74 69  e of a transacti
2fe0: 6f 6e 20 77 68 65 6e 0a 23 20 74 68 65 20 70 65  on when.# the pe
2ff0: 6e 64 69 6e 67 2d 74 65 72 6d 73 20 74 61 62 6c  nding-terms tabl
3000: 65 20 69 73 20 6e 6f 6e 2d 65 6d 70 74 79 2e 20  e is non-empty. 
3010: 54 68 69 73 20 63 61 73 65 20 69 6e 76 6f 6c 76  This case involv
3020: 65 73 20 73 6f 6d 65 20 65 78 74 72 61 0a 23 20  es some extra.# 
3030: 62 72 61 6e 63 68 65 73 20 62 65 63 61 75 73 65  branches because
3040: 20 64 61 74 61 20 6d 75 73 74 20 62 65 20 72 65   data must be re
3050: 61 64 20 6e 6f 74 20 6f 6e 6c 79 20 66 72 6f 6d  ad not only from
3060: 20 74 68 65 20 64 61 74 61 62 61 73 65 2c 20 62   the database, b
3070: 75 74 0a 23 20 61 6c 73 6f 20 66 72 6f 6d 20 74  ut.# also from t
3080: 68 65 20 70 65 6e 64 69 6e 67 2d 74 65 72 6d 73  he pending-terms
3090: 20 74 61 62 6c 65 2e 0a 23 0a 64 6f 5f 6d 61 6c   table..#.do_mal
30a0: 6c 6f 63 5f 74 65 73 74 20 66 74 73 33 63 6f 76  loc_test fts3cov
30b0: 2d 31 30 20 2d 73 71 6c 70 72 65 70 20 7b 0a 20  -10 -sqlprep {. 
30c0: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
30d0: 54 41 42 4c 45 20 74 31 30 20 55 53 49 4e 47 20  TABLE t10 USING 
30e0: 66 74 73 33 3b 0a 20 20 49 4e 53 45 52 54 20 49  fts3;.  INSERT I
30f0: 4e 54 4f 20 74 31 30 20 56 41 4c 55 45 53 28 27  NTO t10 VALUES('
3100: 4f 70 74 69 6d 69 73 69 6e 67 20 69 6d 61 67 65  Optimising image
3110: 73 20 66 6f 72 20 74 68 65 20 77 65 62 20 69 73  s for the web is
3120: 20 61 20 74 72 69 63 6b 79 20 62 75 73 69 6e 65   a tricky busine
3130: 73 73 27 29 3b 0a 20 20 42 45 47 49 4e 3b 0a 20  ss');.  BEGIN;. 
3140: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74     INSERT INTO t
3150: 31 30 20 56 41 4c 55 45 53 28 27 59 6f 75 20 68  10 VALUES('You h
3160: 61 76 65 20 74 6f 20 67 65 74 20 74 68 65 20 72  ave to get the r
3170: 69 67 68 74 20 62 61 6c 61 6e 63 65 20 62 65 74  ight balance bet
3180: 77 65 65 6e 27 29 3b 0a 7d 20 2d 73 71 6c 62 6f  ween');.} -sqlbo
3190: 64 79 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e  dy {.  INSERT IN
31a0: 54 4f 20 74 31 30 28 74 31 30 29 20 56 41 4c 55  TO t10(t10) VALU
31b0: 45 53 28 27 6f 70 74 69 6d 69 7a 65 27 29 3b 0a  ES('optimize');.
31c0: 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  }..#------------
31d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
31e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
31f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3200: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20  -------------.# 
3210: 54 65 73 74 20 61 20 66 75 6c 6c 2d 74 65 78 74  Test a full-text
3220: 20 71 75 65 72 79 20 66 6f 72 20 61 20 74 65 72   query for a ter
3230: 6d 20 74 68 61 74 20 77 61 73 20 6f 6e 63 65 20  m that was once 
3240: 69 6e 20 74 68 65 20 69 6e 64 65 78 2c 20 62 75  in the index, bu
3250: 74 20 69 73 0a 23 20 6e 6f 20 6c 6f 6e 67 65 72  t is.# no longer
3260: 2e 0a 23 0a 64 6f 5f 74 65 73 74 20 66 74 73 33  ..#.do_test fts3
3270: 63 6f 76 2d 31 31 2e 31 20 7b 0a 20 20 65 78 65  cov-11.1 {.  exe
3280: 63 73 71 6c 20 7b 20 0a 20 20 20 20 43 52 45 41  csql { .    CREA
3290: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45  TE VIRTUAL TABLE
32a0: 20 78 78 20 55 53 49 4e 47 20 66 74 73 33 3b 0a   xx USING fts3;.
32b0: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
32c0: 78 78 20 56 41 4c 55 45 53 28 27 6f 6e 65 20 74  xx VALUES('one t
32d0: 77 6f 20 74 68 72 65 65 27 29 3b 0a 20 20 20 20  wo three');.    
32e0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 78 20 56  INSERT INTO xx V
32f0: 41 4c 55 45 53 28 27 66 6f 75 72 20 66 69 76 65  ALUES('four five
3300: 20 73 69 78 27 29 3b 0a 20 20 20 20 44 45 4c 45   six');.    DELE
3310: 54 45 20 46 52 4f 4d 20 78 78 20 57 48 45 52 45  TE FROM xx WHERE
3320: 20 64 6f 63 69 64 20 3d 20 31 3b 0a 20 20 7d 0a   docid = 1;.  }.
3330: 20 20 65 78 65 63 73 71 6c 20 7b 20 53 45 4c 45    execsql { SELE
3340: 43 54 20 2a 20 46 52 4f 4d 20 78 78 20 57 48 45  CT * FROM xx WHE
3350: 52 45 20 78 78 20 4d 41 54 43 48 20 27 74 77 6f  RE xx MATCH 'two
3360: 27 20 7d 0a 7d 20 7b 7d 0a 0a 0a 64 6f 5f 6d 61  ' }.} {}...do_ma
3370: 6c 6c 6f 63 5f 74 65 73 74 20 66 74 73 33 63 6f  lloc_test fts3co
3380: 76 2d 31 32 20 2d 73 71 6c 70 72 65 70 20 7b 0a  v-12 -sqlprep {.
3390: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
33a0: 20 54 41 42 4c 45 20 74 31 32 20 55 53 49 4e 47   TABLE t12 USING
33b0: 20 66 74 73 33 3b 0a 20 20 49 4e 53 45 52 54 20   fts3;.  INSERT 
33c0: 49 4e 54 4f 20 74 31 32 20 56 41 4c 55 45 53 28  INTO t12 VALUES(
33d0: 27 69 73 20 6f 6e 65 20 6f 66 20 74 68 65 20 74  'is one of the t
33e0: 77 6f 20 74 6f 67 74 68 65 72 27 29 3b 0a 20 20  wo togther');.  
33f0: 42 45 47 49 4e 3b 0a 20 20 20 20 49 4e 53 45 52  BEGIN;.    INSER
3400: 54 20 49 4e 54 4f 20 74 31 32 20 56 41 4c 55 45  T INTO t12 VALUE
3410: 53 28 27 6f 6e 65 20 77 68 69 63 68 20 77 61 73  S('one which was
3420: 20 61 70 70 72 6f 70 72 69 61 74 65 20 61 74 20   appropriate at 
3430: 74 68 65 20 74 69 6d 65 27 29 3b 0a 7d 20 2d 73  the time');.} -s
3440: 71 6c 62 6f 64 79 20 7b 0a 20 20 53 45 4c 45 43  qlbody {.  SELEC
3450: 54 20 2a 20 46 52 4f 4d 20 74 31 32 20 57 48 45  T * FROM t12 WHE
3460: 52 45 20 74 31 32 20 4d 41 54 43 48 20 27 6f 6e  RE t12 MATCH 'on
3470: 65 27 0a 7d 0a 0a 64 6f 5f 6d 61 6c 6c 6f 63 5f  e'.}..do_malloc_
3480: 74 65 73 74 20 66 74 73 33 63 6f 76 2d 31 33 20  test fts3cov-13 
3490: 2d 73 71 6c 70 72 65 70 20 7b 0a 20 20 50 52 41  -sqlprep {.  PRA
34a0: 47 4d 41 20 65 6e 63 6f 64 69 6e 67 20 3d 20 27  GMA encoding = '
34b0: 55 54 46 2d 31 36 27 3b 0a 20 20 43 52 45 41 54  UTF-16';.  CREAT
34c0: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20  E VIRTUAL TABLE 
34d0: 74 31 33 20 55 53 49 4e 47 20 66 74 73 33 3b 0a  t13 USING fts3;.
34e0: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31    INSERT INTO t1
34f0: 33 20 56 41 4c 55 45 53 28 27 74 77 6f 20 73 63  3 VALUES('two sc
3500: 61 6c 61 72 20 66 75 6e 63 74 69 6f 6e 73 27 29  alar functions')
3510: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
3520: 74 31 33 20 56 41 4c 55 45 53 28 27 73 63 61 6c  t13 VALUES('scal
3530: 61 72 20 74 77 6f 20 66 75 6e 63 74 69 6f 6e 73  ar two functions
3540: 27 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  ');.  INSERT INT
3550: 4f 20 74 31 33 20 56 41 4c 55 45 53 28 27 66 75  O t13 VALUES('fu
3560: 6e 63 74 69 6f 6e 73 20 73 63 61 6c 61 72 20 74  nctions scalar t
3570: 77 6f 27 29 3b 0a 7d 20 2d 73 71 6c 62 6f 64 79  wo');.} -sqlbody
3580: 20 7b 0a 20 20 53 45 4c 45 43 54 20 73 6e 69 70   {.  SELECT snip
3590: 70 65 74 28 74 31 33 2c 20 27 25 25 27 2c 20 27  pet(t13, '%%', '
35a0: 25 25 27 2c 20 27 23 27 29 20 46 52 4f 4d 20 74  %%', '#') FROM t
35b0: 31 33 20 57 48 45 52 45 20 74 31 33 20 4d 41 54  13 WHERE t13 MAT
35c0: 43 48 20 27 74 77 6f 27 3b 0a 20 20 53 45 4c 45  CH 'two';.  SELE
35d0: 43 54 20 73 6e 69 70 70 65 74 28 74 31 33 2c 20  CT snippet(t13, 
35e0: 27 25 25 27 2c 20 27 25 25 27 29 20 46 52 4f 4d  '%%', '%%') FROM
35f0: 20 74 31 33 20 57 48 45 52 45 20 74 31 33 20 4d   t13 WHERE t13 M
3600: 41 54 43 48 20 27 74 77 6f 27 3b 0a 20 20 53 45  ATCH 'two';.  SE
3610: 4c 45 43 54 20 73 6e 69 70 70 65 74 28 74 31 33  LECT snippet(t13
3620: 2c 20 27 25 25 27 29 20 46 52 4f 4d 20 74 31 33  , '%%') FROM t13
3630: 20 57 48 45 52 45 20 74 31 33 20 4d 41 54 43 48   WHERE t13 MATCH
3640: 20 27 74 77 6f 27 3b 0a 7d 0a 0a 66 69 6e 69 73   'two';.}..finis
3650: 68 5f 74 65 73 74 0a                             h_test.