/ Hex Artifact Content
Login

Artifact 2bd8c97bcb9975f2334147173b4872505b6a41359a4f9068960a36afe07a679f:


0000: 23 20 32 30 30 38 20 4a 75 6e 65 20 32 36 0a 23  # 2008 June 26.#
0010: 0a 23 20 54 68 65 20 61 75 74 68 6f 72 20 64 69  .# The author di
0020: 73 63 6c 61 69 6d 73 20 63 6f 70 79 72 69 67 68  sclaims copyrigh
0030: 74 20 74 6f 20 74 68 69 73 20 73 6f 75 72 63 65  t to this source
0040: 20 63 6f 64 65 2e 20 20 49 6e 20 70 6c 61 63 65   code.  In place
0050: 20 6f 66 0a 23 20 61 20 6c 65 67 61 6c 20 6e 6f   of.# a legal no
0060: 74 69 63 65 2c 20 68 65 72 65 20 69 73 20 61 20  tice, here is a 
0070: 62 6c 65 73 73 69 6e 67 3a 0a 23 0a 23 20 20 20  blessing:.#.#   
0080: 20 4d 61 79 20 79 6f 75 20 64 6f 20 67 6f 6f 64   May you do good
0090: 20 61 6e 64 20 6e 6f 74 20 65 76 69 6c 2e 0a 23   and not evil..#
00a0: 20 20 20 20 4d 61 79 20 79 6f 75 20 66 69 6e 64      May you find
00b0: 20 66 6f 72 67 69 76 65 6e 65 73 73 20 66 6f 72   forgiveness for
00c0: 20 79 6f 75 72 73 65 6c 66 20 61 6e 64 20 66 6f   yourself and fo
00d0: 72 67 69 76 65 20 6f 74 68 65 72 73 2e 0a 23 20  rgive others..# 
00e0: 20 20 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65     May you share
00f0: 20 66 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74   freely, never t
0100: 61 6b 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20  aking more than 
0110: 79 6f 75 20 67 69 76 65 2e 0a 23 0a 23 2a 2a 2a  you give..#.#***
0120: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0160: 2a 2a 2a 2a 2a 2a 0a 23 20 54 68 69 73 20 66 69  ******.# This fi
0170: 6c 65 20 69 6d 70 6c 65 6d 65 6e 74 73 20 72 65  le implements re
0180: 67 72 65 73 73 69 6f 6e 20 74 65 73 74 73 20 66  gression tests f
0190: 6f 72 20 53 51 4c 69 74 65 20 6c 69 62 72 61 72  or SQLite librar
01a0: 79 2e 20 20 54 68 65 20 66 6f 63 75 73 0a 23 20  y.  The focus.# 
01b0: 6f 66 20 74 68 69 73 20 73 63 72 69 70 74 20 69  of this script i
01c0: 73 20 74 65 73 74 69 6e 67 20 74 68 65 20 46 54  s testing the FT
01d0: 53 33 20 6d 6f 64 75 6c 65 27 73 20 6f 70 74 69  S3 module's opti
01e0: 6d 69 7a 65 28 29 20 66 75 6e 63 74 69 6f 6e 2e  mize() function.
01f0: 0a 23 0a 0a 73 65 74 20 74 65 73 74 64 69 72 20  .#..set testdir 
0200: 5b 66 69 6c 65 20 64 69 72 6e 61 6d 65 20 24 61  [file dirname $a
0210: 72 67 76 30 5d 0a 73 6f 75 72 63 65 20 24 74 65  rgv0].source $te
0220: 73 74 64 69 72 2f 74 65 73 74 65 72 2e 74 63 6c  stdir/tester.tcl
0230: 0a 73 6f 75 72 63 65 20 24 74 65 73 74 64 69 72  .source $testdir
0240: 2f 66 74 73 33 5f 63 6f 6d 6d 6f 6e 2e 74 63 6c  /fts3_common.tcl
0250: 0a 0a 23 20 49 66 20 53 51 4c 49 54 45 5f 45 4e  ..# If SQLITE_EN
0260: 41 42 4c 45 5f 46 54 53 33 20 69 73 20 6e 6f 74  ABLE_FTS3 is not
0270: 20 64 65 66 69 6e 65 64 2c 20 6f 6d 69 74 20 74   defined, omit t
0280: 68 69 73 20 66 69 6c 65 2e 0a 69 66 63 61 70 61  his file..ifcapa
0290: 62 6c 65 20 21 66 74 73 33 20 7b 0a 20 20 66 69  ble !fts3 {.  fi
02a0: 6e 69 73 68 5f 74 65 73 74 0a 20 20 72 65 74 75  nish_test.  retu
02b0: 72 6e 0a 7d 0a 0a 23 2a 2a 2a 2a 2a 2a 2a 2a 2a  rn.}..#*********
02c0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
02d0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
02e0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
02f0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0300: 0a 23 20 55 74 69 6c 69 74 79 20 66 75 6e 63 74  .# Utility funct
0310: 69 6f 6e 20 74 6f 20 63 68 65 63 6b 20 66 6f 72  ion to check for
0320: 20 74 68 65 20 65 78 70 65 63 74 65 64 20 74 65   the expected te
0330: 72 6d 73 20 69 6e 20 74 68 65 20 73 65 67 6d 65  rms in the segme
0340: 6e 74 0a 23 20 6c 65 76 65 6c 2f 69 6e 64 65 78  nt.# level/index
0350: 2e 20 20 5f 61 6c 6c 20 76 65 72 73 69 6f 6e 20  .  _all version 
0360: 64 6f 65 73 20 73 61 6d 65 20 62 75 74 20 66 6f  does same but fo
0370: 72 20 65 6e 74 69 72 65 20 69 6e 64 65 78 2e 0a  r entire index..
0380: 70 72 6f 63 20 63 68 65 63 6b 5f 74 65 72 6d 73  proc check_terms
0390: 20 7b 74 65 73 74 20 6c 65 76 65 6c 20 69 6e 64   {test level ind
03a0: 65 78 20 74 65 72 6d 73 7d 20 7b 0a 20 20 73 65  ex terms} {.  se
03b0: 74 20 77 68 65 72 65 20 22 6c 65 76 65 6c 20 3d  t where "level =
03c0: 20 24 6c 65 76 65 6c 20 41 4e 44 20 69 64 78 20   $level AND idx 
03d0: 3d 20 24 69 6e 64 65 78 22 0a 20 20 64 6f 5f 74  = $index".  do_t
03e0: 65 73 74 20 24 74 65 73 74 2e 74 65 72 6d 73 20  est $test.terms 
03f0: 5b 6c 69 73 74 20 66 74 73 33 5f 74 65 72 6d 73  [list fts3_terms
0400: 20 74 31 20 24 77 68 65 72 65 5d 20 24 74 65 72   t1 $where] $ter
0410: 6d 73 0a 7d 0a 70 72 6f 63 20 63 68 65 63 6b 5f  ms.}.proc check_
0420: 74 65 72 6d 73 5f 61 6c 6c 20 7b 74 65 73 74 20  terms_all {test 
0430: 74 65 72 6d 73 7d 20 7b 0a 20 20 64 6f 5f 74 65  terms} {.  do_te
0440: 73 74 20 24 74 65 73 74 2e 74 65 72 6d 73 20 5b  st $test.terms [
0450: 6c 69 73 74 20 66 74 73 33 5f 74 65 72 6d 73 20  list fts3_terms 
0460: 74 31 20 31 5d 20 24 74 65 72 6d 73 0a 7d 0a 0a  t1 1] $terms.}..
0470: 23 20 55 74 69 6c 69 74 79 20 66 75 6e 63 74 69  # Utility functi
0480: 6f 6e 20 74 6f 20 63 68 65 63 6b 20 66 6f 72 20  on to check for 
0490: 74 68 65 20 65 78 70 65 63 74 65 64 20 64 6f 63  the expected doc
04a0: 6c 69 73 74 20 66 6f 72 20 74 68 65 20 74 65 72  list for the ter
04b0: 6d 20 69 6e 0a 23 20 73 65 67 6d 65 6e 74 20 6c  m in.# segment l
04c0: 65 76 65 6c 2f 69 6e 64 65 78 2e 20 20 5f 61 6c  evel/index.  _al
04d0: 6c 20 76 65 72 73 69 6f 6e 20 64 6f 65 73 20 73  l version does s
04e0: 61 6d 65 20 66 6f 72 20 65 6e 74 69 72 65 20 69  ame for entire i
04f0: 6e 64 65 78 2e 0a 70 72 6f 63 20 63 68 65 63 6b  ndex..proc check
0500: 5f 64 6f 63 6c 69 73 74 20 7b 74 65 73 74 20 6c  _doclist {test l
0510: 65 76 65 6c 20 69 6e 64 65 78 20 74 65 72 6d 20  evel index term 
0520: 64 6f 63 6c 69 73 74 7d 20 7b 0a 20 20 73 65 74  doclist} {.  set
0530: 20 77 68 65 72 65 20 22 6c 65 76 65 6c 20 3d 20   where "level = 
0540: 24 6c 65 76 65 6c 20 41 4e 44 20 69 64 78 20 3d  $level AND idx =
0550: 20 24 69 6e 64 65 78 22 0a 20 20 64 6f 5f 74 65   $index".  do_te
0560: 73 74 20 24 74 65 73 74 2e 64 6f 63 6c 69 73 74  st $test.doclist
0570: 20 5b 6c 69 73 74 20 66 74 73 33 5f 64 6f 63 6c   [list fts3_docl
0580: 69 73 74 20 74 31 20 24 74 65 72 6d 20 24 77 68  ist t1 $term $wh
0590: 65 72 65 5d 20 24 64 6f 63 6c 69 73 74 0a 7d 0a  ere] $doclist.}.
05a0: 70 72 6f 63 20 63 68 65 63 6b 5f 64 6f 63 6c 69  proc check_docli
05b0: 73 74 5f 61 6c 6c 20 7b 74 65 73 74 20 74 65 72  st_all {test ter
05c0: 6d 20 64 6f 63 6c 69 73 74 7d 20 7b 0a 20 20 64  m doclist} {.  d
05d0: 6f 5f 74 65 73 74 20 24 74 65 73 74 2e 64 6f 63  o_test $test.doc
05e0: 6c 69 73 74 20 5b 6c 69 73 74 20 66 74 73 33 5f  list [list fts3_
05f0: 64 6f 63 6c 69 73 74 20 74 31 20 24 74 65 72 6d  doclist t1 $term
0600: 20 31 5d 20 24 64 6f 63 6c 69 73 74 0a 7d 0a 0a   1] $doclist.}..
0610: 23 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  #***************
0620: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0630: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0640: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0650: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 23 20 54 65 73  **********.# Tes
0660: 74 20 72 65 73 75 6c 74 73 20 77 68 65 6e 20 61  t results when a
0670: 6c 6c 20 72 6f 77 73 20 61 72 65 20 64 65 6c 65  ll rows are dele
0680: 74 65 64 20 61 6e 64 20 6f 6e 65 20 69 73 20 61  ted and one is a
0690: 64 64 65 64 20 62 61 63 6b 2e 0a 23 20 50 72 65  dded back..# Pre
06a0: 76 69 6f 75 73 6c 79 20 6f 6c 64 65 72 20 73 65  viously older se
06b0: 67 6d 65 6e 74 73 20 77 6f 75 6c 64 20 63 6f 6e  gments would con
06c0: 74 69 6e 75 65 20 74 6f 20 65 78 69 73 74 2c 20  tinue to exist, 
06d0: 62 75 74 20 6e 6f 77 20 74 68 65 20 69 6e 64 65  but now the inde
06e0: 78 0a 23 20 73 68 6f 75 6c 64 20 62 65 20 64 72  x.# should be dr
06f0: 6f 70 70 65 64 20 77 68 65 6e 20 74 68 65 20 74  opped when the t
0700: 61 62 6c 65 20 69 73 20 65 6d 70 74 79 2e 20 20  able is empty.  
0710: 54 68 65 20 72 65 73 75 6c 74 73 20 73 68 6f 75  The results shou
0720: 6c 64 20 6c 6f 6f 6b 0a 23 20 65 78 61 63 74 6c  ld look.# exactl
0730: 79 20 6c 69 6b 65 20 77 65 20 6e 65 76 65 72 20  y like we never 
0740: 61 64 64 65 64 20 74 68 65 20 65 61 72 6c 69 65  added the earlie
0750: 72 20 72 6f 77 73 20 69 6e 20 74 68 65 20 66 69  r rows in the fi
0760: 72 73 74 20 70 6c 61 63 65 2e 0a 64 62 20 65 76  rst place..db ev
0770: 61 6c 20 7b 0a 20 20 44 52 4f 50 20 54 41 42 4c  al {.  DROP TABL
0780: 45 20 49 46 20 45 58 49 53 54 53 20 74 31 3b 0a  E IF EXISTS t1;.
0790: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
07a0: 20 54 41 42 4c 45 20 74 31 20 55 53 49 4e 47 20   TABLE t1 USING 
07b0: 66 74 73 33 28 63 29 3b 0a 20 20 49 4e 53 45 52  fts3(c);.  INSER
07c0: 54 20 49 4e 54 4f 20 74 31 20 28 64 6f 63 69 64  T INTO t1 (docid
07d0: 2c 20 63 29 20 56 41 4c 55 45 53 20 28 31 2c 20  , c) VALUES (1, 
07e0: 27 54 68 69 73 20 69 73 20 61 20 74 65 73 74 27  'This is a test'
07f0: 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  );.  INSERT INTO
0800: 20 74 31 20 28 64 6f 63 69 64 2c 20 63 29 20 56   t1 (docid, c) V
0810: 41 4c 55 45 53 20 28 32 2c 20 27 54 68 61 74 20  ALUES (2, 'That 
0820: 77 61 73 20 61 20 74 65 73 74 27 29 3b 0a 20 20  was a test');.  
0830: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 28  INSERT INTO t1 (
0840: 64 6f 63 69 64 2c 20 63 29 20 56 41 4c 55 45 53  docid, c) VALUES
0850: 20 28 33 2c 20 27 54 68 69 73 20 69 73 20 61 20   (3, 'This is a 
0860: 74 65 73 74 27 29 3b 0a 20 20 44 45 4c 45 54 45  test');.  DELETE
0870: 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 31   FROM t1 WHERE 1
0880: 3d 31 3b 20 2d 2d 20 44 65 6c 65 74 65 20 65 61  =1; -- Delete ea
0890: 63 68 20 72 6f 77 20 72 61 74 68 65 72 20 74 68  ch row rather th
08a0: 61 6e 20 64 72 6f 70 70 69 6e 67 20 74 61 62 6c  an dropping tabl
08b0: 65 2e 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  e..  INSERT INTO
08c0: 20 74 31 20 28 64 6f 63 69 64 2c 20 63 29 20 56   t1 (docid, c) V
08d0: 41 4c 55 45 53 20 28 31 2c 20 27 54 68 69 73 20  ALUES (1, 'This 
08e0: 69 73 20 61 20 74 65 73 74 27 29 3b 0a 7d 0a 0a  is a test');.}..
08f0: 23 20 53 68 6f 75 6c 64 20 62 65 20 61 20 73 69  # Should be a si
0900: 6e 67 6c 65 20 69 6e 69 74 69 61 6c 20 73 65 67  ngle initial seg
0910: 6d 65 6e 74 2e 0a 64 6f 5f 74 65 73 74 20 66 74  ment..do_test ft
0920: 73 33 64 2d 31 2e 73 65 67 6d 65 6e 74 73 20 7b  s3d-1.segments {
0930: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
0940: 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69   SELECT level, i
0950: 64 78 20 46 52 4f 4d 20 74 31 5f 73 65 67 64 69  dx FROM t1_segdi
0960: 72 20 4f 52 44 45 52 20 42 59 20 6c 65 76 65 6c  r ORDER BY level
0970: 2c 20 69 64 78 3b 0a 20 20 7d 0a 7d 20 7b 30 20  , idx;.  }.} {0 
0980: 30 7d 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 64  0}.do_test fts3d
0990: 2d 31 2e 6d 61 74 63 68 65 73 20 7b 0a 20 20 65  -1.matches {.  e
09a0: 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c  xecsql {.    SEL
09b0: 45 43 54 20 4f 46 46 53 45 54 53 28 74 31 29 20  ECT OFFSETS(t1) 
09c0: 46 52 4f 4d 20 74 31 0a 20 20 20 20 20 57 48 45  FROM t1.     WHE
09d0: 52 45 20 74 31 20 4d 41 54 43 48 20 27 74 68 69  RE t1 MATCH 'thi
09e0: 73 20 4f 52 20 74 68 61 74 20 4f 52 20 77 61 73  s OR that OR was
09f0: 20 4f 52 20 61 20 4f 52 20 69 73 20 4f 52 20 74   OR a OR is OR t
0a00: 65 73 74 27 20 4f 52 44 45 52 20 42 59 20 64 6f  est' ORDER BY do
0a10: 63 69 64 3b 0a 20 20 7d 0a 7d 20 7b 7b 30 20 30  cid;.  }.} {{0 0
0a20: 20 30 20 34 20 30 20 34 20 35 20 32 20 30 20 33   0 4 0 4 5 2 0 3
0a30: 20 38 20 31 20 30 20 35 20 31 30 20 34 7d 7d 0a   8 1 0 5 10 4}}.
0a40: 0a 63 68 65 63 6b 5f 74 65 72 6d 73 5f 61 6c 6c  .check_terms_all
0a50: 20 66 74 73 33 64 2d 31 2e 31 20 7b 61 20 69 73   fts3d-1.1 {a is
0a60: 20 74 65 73 74 20 74 68 69 73 7d 0a 63 68 65 63   test this}.chec
0a70: 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74  k_doclist_all ft
0a80: 73 33 64 2d 31 2e 31 2e 31 20 61 20 7b 5b 31 20  s3d-1.1.1 a {[1 
0a90: 30 5b 32 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63  0[2]]}.check_doc
0aa0: 6c 69 73 74 5f 61 6c 6c 20 66 74 73 33 64 2d 31  list_all fts3d-1
0ab0: 2e 31 2e 32 20 69 73 20 7b 5b 31 20 30 5b 31 5d  .1.2 is {[1 0[1]
0ac0: 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74  ]}.check_doclist
0ad0: 5f 61 6c 6c 20 66 74 73 33 64 2d 31 2e 31 2e 33  _all fts3d-1.1.3
0ae0: 20 74 65 73 74 20 7b 5b 31 20 30 5b 33 5d 5d 7d   test {[1 0[3]]}
0af0: 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f 61  .check_doclist_a
0b00: 6c 6c 20 66 74 73 33 64 2d 31 2e 31 2e 34 20 74  ll fts3d-1.1.4 t
0b10: 68 69 73 20 7b 5b 31 20 30 5b 30 5d 5d 7d 0a 0a  his {[1 0[0]]}..
0b20: 63 68 65 63 6b 5f 74 65 72 6d 73 20 20 20 66 74  check_terms   ft
0b30: 73 33 64 2d 31 2e 32 20 20 20 30 20 30 20 7b 61  s3d-1.2   0 0 {a
0b40: 20 69 73 20 74 65 73 74 20 74 68 69 73 7d 0a 63   is test this}.c
0b50: 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73  heck_doclist fts
0b60: 33 64 2d 31 2e 32 2e 31 20 30 20 30 20 61 20 7b  3d-1.2.1 0 0 a {
0b70: 5b 31 20 30 5b 32 5d 5d 7d 0a 63 68 65 63 6b 5f  [1 0[2]]}.check_
0b80: 64 6f 63 6c 69 73 74 20 66 74 73 33 64 2d 31 2e  doclist fts3d-1.
0b90: 32 2e 32 20 30 20 30 20 69 73 20 7b 5b 31 20 30  2.2 0 0 is {[1 0
0ba0: 5b 31 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c  [1]]}.check_docl
0bb0: 69 73 74 20 66 74 73 33 64 2d 31 2e 32 2e 33 20  ist fts3d-1.2.3 
0bc0: 30 20 30 20 74 65 73 74 20 7b 5b 31 20 30 5b 33  0 0 test {[1 0[3
0bd0: 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73  ]]}.check_doclis
0be0: 74 20 66 74 73 33 64 2d 31 2e 32 2e 34 20 30 20  t fts3d-1.2.4 0 
0bf0: 30 20 74 68 69 73 20 7b 5b 31 20 30 5b 30 5d 5d  0 this {[1 0[0]]
0c00: 7d 0a 0a 23 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  }..#************
0c10: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0c20: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0c30: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0c40: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 23 20  *************.# 
0c50: 54 65 73 74 20 72 65 73 75 6c 74 73 20 77 68 65  Test results whe
0c60: 6e 20 65 76 65 72 79 74 68 69 6e 67 20 69 73 20  n everything is 
0c70: 6f 70 74 69 6d 69 7a 65 64 20 6d 61 6e 75 61 6c  optimized manual
0c80: 6c 79 2e 0a 23 20 4e 4f 54 45 28 73 68 65 73 73  ly..# NOTE(shess
0c90: 29 3a 20 54 68 69 73 20 69 73 20 61 20 63 6f 70  ): This is a cop
0ca0: 79 20 6f 66 20 66 74 73 33 63 2d 31 2e 33 2e 20  y of fts3c-1.3. 
0cb0: 20 49 27 76 65 20 70 75 6c 6c 65 64 20 61 20 63   I've pulled a c
0cc0: 6f 70 79 20 68 65 72 65 0a 23 20 62 65 63 61 75  opy here.# becau
0cd0: 73 65 20 66 74 73 33 64 2d 32 20 61 6e 64 20 66  se fts3d-2 and f
0ce0: 74 73 33 64 2d 33 20 73 68 6f 75 6c 64 20 68 61  ts3d-3 should ha
0cf0: 76 65 20 69 64 65 6e 74 69 63 61 6c 20 72 65 73  ve identical res
0d00: 75 6c 74 73 2e 0a 64 62 20 65 76 61 6c 20 7b 0a  ults..db eval {.
0d10: 20 20 44 52 4f 50 20 54 41 42 4c 45 20 49 46 20    DROP TABLE IF 
0d20: 45 58 49 53 54 53 20 74 31 3b 0a 20 20 43 52 45  EXISTS t1;.  CRE
0d30: 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c  ATE VIRTUAL TABL
0d40: 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 28  E t1 USING fts3(
0d50: 63 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  c);.  INSERT INT
0d60: 4f 20 74 31 20 28 64 6f 63 69 64 2c 20 63 29 20  O t1 (docid, c) 
0d70: 56 41 4c 55 45 53 20 28 31 2c 20 27 54 68 69 73  VALUES (1, 'This
0d80: 20 69 73 20 61 20 74 65 73 74 27 29 3b 0a 20 20   is a test');.  
0d90: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 28  INSERT INTO t1 (
0da0: 64 6f 63 69 64 2c 20 63 29 20 56 41 4c 55 45 53  docid, c) VALUES
0db0: 20 28 32 2c 20 27 54 68 61 74 20 77 61 73 20 61   (2, 'That was a
0dc0: 20 74 65 73 74 27 29 3b 0a 20 20 49 4e 53 45 52   test');.  INSER
0dd0: 54 20 49 4e 54 4f 20 74 31 20 28 64 6f 63 69 64  T INTO t1 (docid
0de0: 2c 20 63 29 20 56 41 4c 55 45 53 20 28 33 2c 20  , c) VALUES (3, 
0df0: 27 54 68 69 73 20 69 73 20 61 20 74 65 73 74 27  'This is a test'
0e00: 29 3b 0a 20 20 44 45 4c 45 54 45 20 46 52 4f 4d  );.  DELETE FROM
0e10: 20 74 31 20 57 48 45 52 45 20 64 6f 63 69 64 20   t1 WHERE docid 
0e20: 49 4e 20 28 31 2c 33 29 3b 0a 20 20 44 52 4f 50  IN (1,3);.  DROP
0e30: 20 54 41 42 4c 45 20 49 46 20 45 58 49 53 54 53   TABLE IF EXISTS
0e40: 20 74 31 6f 6c 64 3b 0a 20 20 41 4c 54 45 52 20   t1old;.  ALTER 
0e50: 54 41 42 4c 45 20 74 31 20 52 45 4e 41 4d 45 20  TABLE t1 RENAME 
0e60: 54 4f 20 74 31 6f 6c 64 3b 0a 20 20 43 52 45 41  TO t1old;.  CREA
0e70: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45  TE VIRTUAL TABLE
0e80: 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 28 63   t1 USING fts3(c
0e90: 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  );.  INSERT INTO
0ea0: 20 74 31 20 28 64 6f 63 69 64 2c 20 63 29 20 53   t1 (docid, c) S
0eb0: 45 4c 45 43 54 20 64 6f 63 69 64 2c 20 63 20 46  ELECT docid, c F
0ec0: 52 4f 4d 20 74 31 6f 6c 64 3b 0a 20 20 44 52 4f  ROM t1old;.  DRO
0ed0: 50 20 54 41 42 4c 45 20 74 31 6f 6c 64 3b 0a 7d  P TABLE t1old;.}
0ee0: 0a 0a 23 20 53 68 6f 75 6c 64 20 62 65 20 61 20  ..# Should be a 
0ef0: 73 69 6e 67 6c 65 20 6f 70 74 69 6d 61 6c 20 73  single optimal s
0f00: 65 67 6d 65 6e 74 20 77 69 74 68 20 74 68 65 20  egment with the 
0f10: 73 61 6d 65 20 6c 6f 67 69 63 61 6c 20 72 65 73  same logical res
0f20: 75 6c 74 73 2e 0a 64 6f 5f 74 65 73 74 20 66 74  ults..do_test ft
0f30: 73 33 64 2d 32 2e 73 65 67 6d 65 6e 74 73 20 7b  s3d-2.segments {
0f40: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
0f50: 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69   SELECT level, i
0f60: 64 78 20 46 52 4f 4d 20 74 31 5f 73 65 67 64 69  dx FROM t1_segdi
0f70: 72 20 4f 52 44 45 52 20 42 59 20 6c 65 76 65 6c  r ORDER BY level
0f80: 2c 20 69 64 78 3b 0a 20 20 7d 0a 7d 20 7b 30 20  , idx;.  }.} {0 
0f90: 30 7d 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 64  0}.do_test fts3d
0fa0: 2d 32 2e 6d 61 74 63 68 65 73 20 7b 0a 20 20 65  -2.matches {.  e
0fb0: 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c  xecsql {.    SEL
0fc0: 45 43 54 20 4f 46 46 53 45 54 53 28 74 31 29 20  ECT OFFSETS(t1) 
0fd0: 46 52 4f 4d 20 74 31 0a 20 20 20 20 20 57 48 45  FROM t1.     WHE
0fe0: 52 45 20 74 31 20 4d 41 54 43 48 20 27 74 68 69  RE t1 MATCH 'thi
0ff0: 73 20 4f 52 20 74 68 61 74 20 4f 52 20 77 61 73  s OR that OR was
1000: 20 4f 52 20 61 20 4f 52 20 69 73 20 4f 52 20 74   OR a OR is OR t
1010: 65 73 74 27 20 4f 52 44 45 52 20 42 59 20 64 6f  est' ORDER BY do
1020: 63 69 64 3b 0a 20 20 7d 0a 7d 20 7b 7b 30 20 31  cid;.  }.} {{0 1
1030: 20 30 20 34 20 30 20 32 20 35 20 33 20 30 20 33   0 4 0 2 5 3 0 3
1040: 20 39 20 31 20 30 20 35 20 31 31 20 34 7d 7d 0a   9 1 0 5 11 4}}.
1050: 0a 63 68 65 63 6b 5f 74 65 72 6d 73 5f 61 6c 6c  .check_terms_all
1060: 20 66 74 73 33 64 2d 32 2e 31 20 7b 61 20 74 65   fts3d-2.1 {a te
1070: 73 74 20 74 68 61 74 20 77 61 73 7d 0a 63 68 65  st that was}.che
1080: 63 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66  ck_doclist_all f
1090: 74 73 33 64 2d 32 2e 31 2e 31 20 61 20 7b 5b 32  ts3d-2.1.1 a {[2
10a0: 20 30 5b 32 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f   0[2]]}.check_do
10b0: 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73 33 64 2d  clist_all fts3d-
10c0: 32 2e 31 2e 32 20 74 65 73 74 20 7b 5b 32 20 30  2.1.2 test {[2 0
10d0: 5b 33 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c  [3]]}.check_docl
10e0: 69 73 74 5f 61 6c 6c 20 66 74 73 33 64 2d 32 2e  ist_all fts3d-2.
10f0: 31 2e 33 20 74 68 61 74 20 7b 5b 32 20 30 5b 30  1.3 that {[2 0[0
1100: 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73  ]]}.check_doclis
1110: 74 5f 61 6c 6c 20 66 74 73 33 64 2d 32 2e 31 2e  t_all fts3d-2.1.
1120: 34 20 77 61 73 20 7b 5b 32 20 30 5b 31 5d 5d 7d  4 was {[2 0[1]]}
1130: 0a 0a 63 68 65 63 6b 5f 74 65 72 6d 73 20 66 74  ..check_terms ft
1140: 73 33 64 2d 32 2e 32 20 30 20 30 20 7b 61 20 74  s3d-2.2 0 0 {a t
1150: 65 73 74 20 74 68 61 74 20 77 61 73 7d 0a 63 68  est that was}.ch
1160: 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33  eck_doclist fts3
1170: 64 2d 32 2e 32 2e 31 20 30 20 30 20 61 20 7b 5b  d-2.2.1 0 0 a {[
1180: 32 20 30 5b 32 5d 5d 7d 0a 63 68 65 63 6b 5f 64  2 0[2]]}.check_d
1190: 6f 63 6c 69 73 74 20 66 74 73 33 64 2d 32 2e 32  oclist fts3d-2.2
11a0: 2e 32 20 30 20 30 20 74 65 73 74 20 7b 5b 32 20  .2 0 0 test {[2 
11b0: 30 5b 33 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63  0[3]]}.check_doc
11c0: 6c 69 73 74 20 66 74 73 33 64 2d 32 2e 32 2e 33  list fts3d-2.2.3
11d0: 20 30 20 30 20 74 68 61 74 20 7b 5b 32 20 30 5b   0 0 that {[2 0[
11e0: 30 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69  0]]}.check_docli
11f0: 73 74 20 66 74 73 33 64 2d 32 2e 32 2e 34 20 30  st fts3d-2.2.4 0
1200: 20 30 20 77 61 73 20 7b 5b 32 20 30 5b 31 5d 5d   0 was {[2 0[1]]
1210: 7d 0a 0a 23 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  }..#************
1220: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
1230: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
1240: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
1250: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 23 20  *************.# 
1260: 54 65 73 74 20 72 65 73 75 6c 74 73 20 77 68 65  Test results whe
1270: 6e 20 65 76 65 72 79 74 68 69 6e 67 20 69 73 20  n everything is 
1280: 6f 70 74 69 6d 69 7a 65 64 20 76 69 61 20 6f 70  optimized via op
1290: 74 69 6d 69 7a 65 28 29 2e 0a 64 62 20 65 76 61  timize()..db eva
12a0: 6c 20 7b 0a 20 20 44 52 4f 50 20 54 41 42 4c 45  l {.  DROP TABLE
12b0: 20 49 46 20 45 58 49 53 54 53 20 74 31 3b 0a 20   IF EXISTS t1;. 
12c0: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
12d0: 54 41 42 4c 45 20 74 31 20 55 53 49 4e 47 20 66  TABLE t1 USING f
12e0: 74 73 33 28 63 29 3b 0a 20 20 49 4e 53 45 52 54  ts3(c);.  INSERT
12f0: 20 49 4e 54 4f 20 74 31 20 28 64 6f 63 69 64 2c   INTO t1 (docid,
1300: 20 63 29 20 56 41 4c 55 45 53 20 28 31 2c 20 27   c) VALUES (1, '
1310: 54 68 69 73 20 69 73 20 61 20 74 65 73 74 27 29  This is a test')
1320: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
1330: 74 31 20 28 64 6f 63 69 64 2c 20 63 29 20 56 41  t1 (docid, c) VA
1340: 4c 55 45 53 20 28 32 2c 20 27 54 68 61 74 20 77  LUES (2, 'That w
1350: 61 73 20 61 20 74 65 73 74 27 29 3b 0a 20 20 49  as a test');.  I
1360: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 28 64  NSERT INTO t1 (d
1370: 6f 63 69 64 2c 20 63 29 20 56 41 4c 55 45 53 20  ocid, c) VALUES 
1380: 28 33 2c 20 27 54 68 69 73 20 69 73 20 61 20 74  (3, 'This is a t
1390: 65 73 74 27 29 3b 0a 20 20 44 45 4c 45 54 45 20  est');.  DELETE 
13a0: 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 64 6f  FROM t1 WHERE do
13b0: 63 69 64 20 49 4e 20 28 31 2c 33 29 3b 0a 20 20  cid IN (1,3);.  
13c0: 53 45 4c 45 43 54 20 4f 50 54 49 4d 49 5a 45 28  SELECT OPTIMIZE(
13d0: 74 31 29 20 46 52 4f 4d 20 74 31 20 4c 49 4d 49  t1) FROM t1 LIMI
13e0: 54 20 31 3b 0a 7d 0a 0a 23 20 53 68 6f 75 6c 64  T 1;.}..# Should
13f0: 20 62 65 20 61 20 73 69 6e 67 6c 65 20 6f 70 74   be a single opt
1400: 69 6d 61 6c 20 73 65 67 6d 65 6e 74 20 77 69 74  imal segment wit
1410: 68 20 74 68 65 20 73 61 6d 65 20 6c 6f 67 69 63  h the same logic
1420: 61 6c 20 72 65 73 75 6c 74 73 2e 0a 64 6f 5f 74  al results..do_t
1430: 65 73 74 20 66 74 73 33 64 2d 33 2e 73 65 67 6d  est fts3d-3.segm
1440: 65 6e 74 73 20 7b 0a 20 20 65 78 65 63 73 71 6c  ents {.  execsql
1450: 20 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 6c 65   {.    SELECT le
1460: 76 65 6c 2c 20 69 64 78 20 46 52 4f 4d 20 74 31  vel, idx FROM t1
1470: 5f 73 65 67 64 69 72 20 4f 52 44 45 52 20 42 59  _segdir ORDER BY
1480: 20 6c 65 76 65 6c 2c 20 69 64 78 3b 0a 20 20 7d   level, idx;.  }
1490: 0a 7d 20 7b 30 20 30 7d 0a 64 6f 5f 74 65 73 74  .} {0 0}.do_test
14a0: 20 66 74 73 33 64 2d 33 2e 6d 61 74 63 68 65 73   fts3d-3.matches
14b0: 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20   {.  execsql {. 
14c0: 20 20 20 53 45 4c 45 43 54 20 4f 46 46 53 45 54     SELECT OFFSET
14d0: 53 28 74 31 29 20 46 52 4f 4d 20 74 31 0a 20 20  S(t1) FROM t1.  
14e0: 20 20 20 57 48 45 52 45 20 74 31 20 4d 41 54 43     WHERE t1 MATC
14f0: 48 20 27 74 68 69 73 20 4f 52 20 74 68 61 74 20  H 'this OR that 
1500: 4f 52 20 77 61 73 20 4f 52 20 61 20 4f 52 20 69  OR was OR a OR i
1510: 73 20 4f 52 20 74 65 73 74 27 20 4f 52 44 45 52  s OR test' ORDER
1520: 20 42 59 20 64 6f 63 69 64 3b 0a 20 20 7d 0a 7d   BY docid;.  }.}
1530: 20 7b 7b 30 20 31 20 30 20 34 20 30 20 32 20 35   {{0 1 0 4 0 2 5
1540: 20 33 20 30 20 33 20 39 20 31 20 30 20 35 20 31   3 0 3 9 1 0 5 1
1550: 31 20 34 7d 7d 0a 0a 63 68 65 63 6b 5f 74 65 72  1 4}}..check_ter
1560: 6d 73 5f 61 6c 6c 20 66 74 73 33 64 2d 33 2e 31  ms_all fts3d-3.1
1570: 20 7b 61 20 74 65 73 74 20 74 68 61 74 20 77 61   {a test that wa
1580: 73 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74  s}.check_doclist
1590: 5f 61 6c 6c 20 66 74 73 33 64 2d 33 2e 31 2e 31  _all fts3d-3.1.1
15a0: 20 61 20 7b 5b 32 20 30 5b 32 5d 5d 7d 0a 63 68   a {[2 0[2]]}.ch
15b0: 65 63 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20  eck_doclist_all 
15c0: 66 74 73 33 64 2d 33 2e 31 2e 32 20 74 65 73 74  fts3d-3.1.2 test
15d0: 20 7b 5b 32 20 30 5b 33 5d 5d 7d 0a 63 68 65 63   {[2 0[3]]}.chec
15e0: 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74  k_doclist_all ft
15f0: 73 33 64 2d 33 2e 31 2e 33 20 74 68 61 74 20 7b  s3d-3.1.3 that {
1600: 5b 32 20 30 5b 30 5d 5d 7d 0a 63 68 65 63 6b 5f  [2 0[0]]}.check_
1610: 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73 33  doclist_all fts3
1620: 64 2d 33 2e 31 2e 34 20 77 61 73 20 7b 5b 32 20  d-3.1.4 was {[2 
1630: 30 5b 31 5d 5d 7d 0a 0a 63 68 65 63 6b 5f 74 65  0[1]]}..check_te
1640: 72 6d 73 20 66 74 73 33 64 2d 33 2e 32 20 30 20  rms fts3d-3.2 0 
1650: 30 20 7b 61 20 74 65 73 74 20 74 68 61 74 20 77  0 {a test that w
1660: 61 73 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73  as}.check_doclis
1670: 74 20 66 74 73 33 64 2d 33 2e 32 2e 31 20 30 20  t fts3d-3.2.1 0 
1680: 30 20 61 20 7b 5b 32 20 30 5b 32 5d 5d 7d 0a 63  0 a {[2 0[2]]}.c
1690: 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73  heck_doclist fts
16a0: 33 64 2d 33 2e 32 2e 32 20 30 20 30 20 74 65 73  3d-3.2.2 0 0 tes
16b0: 74 20 7b 5b 32 20 30 5b 33 5d 5d 7d 0a 63 68 65  t {[2 0[3]]}.che
16c0: 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64  ck_doclist fts3d
16d0: 2d 33 2e 32 2e 33 20 30 20 30 20 74 68 61 74 20  -3.2.3 0 0 that 
16e0: 7b 5b 32 20 30 5b 30 5d 5d 7d 0a 63 68 65 63 6b  {[2 0[0]]}.check
16f0: 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64 2d 33  _doclist fts3d-3
1700: 2e 32 2e 34 20 30 20 30 20 77 61 73 20 7b 5b 32  .2.4 0 0 was {[2
1710: 20 30 5b 31 5d 5d 7d 0a 0a 23 2a 2a 2a 2a 2a 2a   0[1]]}..#******
1720: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
1730: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
1740: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
1750: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
1760: 2a 2a 2a 0a 23 20 54 65 73 74 20 6f 70 74 69 6d  ***.# Test optim
1770: 69 7a 65 28 29 20 61 67 61 69 6e 73 74 20 61 20  ize() against a 
1780: 74 61 62 6c 65 20 69 6e 76 6f 6c 76 69 6e 67 20  table involving 
1790: 73 65 67 6d 65 6e 74 20 6d 65 72 67 65 73 2e 0a  segment merges..
17a0: 23 20 4e 4f 54 45 28 73 68 65 73 73 29 3a 20 53  # NOTE(shess): S
17b0: 69 6e 63 65 20 74 68 65 72 65 27 73 20 6e 6f 20  ince there's no 
17c0: 74 72 61 6e 73 61 63 74 69 6f 6e 2c 20 65 61 63  transaction, eac
17d0: 68 20 6f 66 20 74 68 65 20 49 4e 53 45 52 54 2f  h of the INSERT/
17e0: 55 50 44 41 54 45 0a 23 20 73 74 61 74 65 6d 65  UPDATE.# stateme
17f0: 6e 74 73 20 67 65 6e 65 72 61 74 65 73 20 61 20  nts generates a 
1800: 73 65 67 6d 65 6e 74 2e 0a 64 62 20 65 76 61 6c  segment..db eval
1810: 20 7b 0a 20 20 44 52 4f 50 20 54 41 42 4c 45 20   {.  DROP TABLE 
1820: 49 46 20 45 58 49 53 54 53 20 74 31 3b 0a 20 20  IF EXISTS t1;.  
1830: 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54  CREATE VIRTUAL T
1840: 41 42 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74  ABLE t1 USING ft
1850: 73 33 28 63 29 3b 0a 0a 20 20 49 4e 53 45 52 54  s3(c);..  INSERT
1860: 20 49 4e 54 4f 20 74 31 20 28 72 6f 77 69 64 2c   INTO t1 (rowid,
1870: 20 63 29 20 56 41 4c 55 45 53 20 28 31 2c 20 27   c) VALUES (1, '
1880: 54 68 69 73 20 69 73 20 61 20 74 65 73 74 27 29  This is a test')
1890: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
18a0: 74 31 20 28 72 6f 77 69 64 2c 20 63 29 20 56 41  t1 (rowid, c) VA
18b0: 4c 55 45 53 20 28 32 2c 20 27 54 68 61 74 20 77  LUES (2, 'That w
18c0: 61 73 20 61 20 74 65 73 74 27 29 3b 0a 20 20 49  as a test');.  I
18d0: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 28 72  NSERT INTO t1 (r
18e0: 6f 77 69 64 2c 20 63 29 20 56 41 4c 55 45 53 20  owid, c) VALUES 
18f0: 28 33 2c 20 27 54 68 69 73 20 69 73 20 61 20 74  (3, 'This is a t
1900: 65 73 74 27 29 3b 0a 0a 20 20 55 50 44 41 54 45  est');..  UPDATE
1910: 20 74 31 20 53 45 54 20 63 20 3d 20 27 54 68 69   t1 SET c = 'Thi
1920: 73 20 69 73 20 61 20 74 65 73 74 20 6f 6e 65 27  s is a test one'
1930: 20 57 48 45 52 45 20 72 6f 77 69 64 20 3d 20 31   WHERE rowid = 1
1940: 3b 0a 20 20 55 50 44 41 54 45 20 74 31 20 53 45  ;.  UPDATE t1 SE
1950: 54 20 63 20 3d 20 27 54 68 61 74 20 77 61 73 20  T c = 'That was 
1960: 61 20 74 65 73 74 20 6f 6e 65 27 20 57 48 45 52  a test one' WHER
1970: 45 20 72 6f 77 69 64 20 3d 20 32 3b 0a 20 20 55  E rowid = 2;.  U
1980: 50 44 41 54 45 20 74 31 20 53 45 54 20 63 20 3d  PDATE t1 SET c =
1990: 20 27 54 68 69 73 20 69 73 20 61 20 74 65 73 74   'This is a test
19a0: 20 6f 6e 65 27 20 57 48 45 52 45 20 72 6f 77 69   one' WHERE rowi
19b0: 64 20 3d 20 33 3b 0a 0a 20 20 55 50 44 41 54 45  d = 3;..  UPDATE
19c0: 20 74 31 20 53 45 54 20 63 20 3d 20 27 54 68 69   t1 SET c = 'Thi
19d0: 73 20 69 73 20 61 20 74 65 73 74 20 74 77 6f 27  s is a test two'
19e0: 20 57 48 45 52 45 20 72 6f 77 69 64 20 3d 20 31   WHERE rowid = 1
19f0: 3b 0a 20 20 55 50 44 41 54 45 20 74 31 20 53 45  ;.  UPDATE t1 SE
1a00: 54 20 63 20 3d 20 27 54 68 61 74 20 77 61 73 20  T c = 'That was 
1a10: 61 20 74 65 73 74 20 74 77 6f 27 20 57 48 45 52  a test two' WHER
1a20: 45 20 72 6f 77 69 64 20 3d 20 32 3b 0a 20 20 55  E rowid = 2;.  U
1a30: 50 44 41 54 45 20 74 31 20 53 45 54 20 63 20 3d  PDATE t1 SET c =
1a40: 20 27 54 68 69 73 20 69 73 20 61 20 74 65 73 74   'This is a test
1a50: 20 74 77 6f 27 20 57 48 45 52 45 20 72 6f 77 69   two' WHERE rowi
1a60: 64 20 3d 20 33 3b 0a 0a 20 20 55 50 44 41 54 45  d = 3;..  UPDATE
1a70: 20 74 31 20 53 45 54 20 63 20 3d 20 27 54 68 69   t1 SET c = 'Thi
1a80: 73 20 69 73 20 61 20 74 65 73 74 20 74 68 72 65  s is a test thre
1a90: 65 27 20 57 48 45 52 45 20 72 6f 77 69 64 20 3d  e' WHERE rowid =
1aa0: 20 31 3b 0a 20 20 55 50 44 41 54 45 20 74 31 20   1;.  UPDATE t1 
1ab0: 53 45 54 20 63 20 3d 20 27 54 68 61 74 20 77 61  SET c = 'That wa
1ac0: 73 20 61 20 74 65 73 74 20 74 68 72 65 65 27 20  s a test three' 
1ad0: 57 48 45 52 45 20 72 6f 77 69 64 20 3d 20 32 3b  WHERE rowid = 2;
1ae0: 0a 20 20 55 50 44 41 54 45 20 74 31 20 53 45 54  .  UPDATE t1 SET
1af0: 20 63 20 3d 20 27 54 68 69 73 20 69 73 20 61 20   c = 'This is a 
1b00: 74 65 73 74 20 74 68 72 65 65 27 20 57 48 45 52  test three' WHER
1b10: 45 20 72 6f 77 69 64 20 3d 20 33 3b 0a 0a 20 20  E rowid = 3;..  
1b20: 55 50 44 41 54 45 20 74 31 20 53 45 54 20 63 20  UPDATE t1 SET c 
1b30: 3d 20 27 54 68 69 73 20 69 73 20 61 20 74 65 73  = 'This is a tes
1b40: 74 20 66 6f 75 72 27 20 57 48 45 52 45 20 72 6f  t four' WHERE ro
1b50: 77 69 64 20 3d 20 31 3b 0a 20 20 55 50 44 41 54  wid = 1;.  UPDAT
1b60: 45 20 74 31 20 53 45 54 20 63 20 3d 20 27 54 68  E t1 SET c = 'Th
1b70: 61 74 20 77 61 73 20 61 20 74 65 73 74 20 66 6f  at was a test fo
1b80: 75 72 27 20 57 48 45 52 45 20 72 6f 77 69 64 20  ur' WHERE rowid 
1b90: 3d 20 32 3b 0a 20 20 55 50 44 41 54 45 20 74 31  = 2;.  UPDATE t1
1ba0: 20 53 45 54 20 63 20 3d 20 27 54 68 69 73 20 69   SET c = 'This i
1bb0: 73 20 61 20 74 65 73 74 20 66 6f 75 72 27 20 57  s a test four' W
1bc0: 48 45 52 45 20 72 6f 77 69 64 20 3d 20 33 3b 0a  HERE rowid = 3;.
1bd0: 0a 20 20 55 50 44 41 54 45 20 74 31 20 53 45 54  .  UPDATE t1 SET
1be0: 20 63 20 3d 20 27 54 68 69 73 20 69 73 20 61 20   c = 'This is a 
1bf0: 74 65 73 74 27 20 57 48 45 52 45 20 72 6f 77 69  test' WHERE rowi
1c00: 64 20 3d 20 31 3b 0a 20 20 55 50 44 41 54 45 20  d = 1;.  UPDATE 
1c10: 74 31 20 53 45 54 20 63 20 3d 20 27 54 68 61 74  t1 SET c = 'That
1c20: 20 77 61 73 20 61 20 74 65 73 74 27 20 57 48 45   was a test' WHE
1c30: 52 45 20 72 6f 77 69 64 20 3d 20 32 3b 0a 20 20  RE rowid = 2;.  
1c40: 55 50 44 41 54 45 20 74 31 20 53 45 54 20 63 20  UPDATE t1 SET c 
1c50: 3d 20 27 54 68 69 73 20 69 73 20 61 20 74 65 73  = 'This is a tes
1c60: 74 27 20 57 48 45 52 45 20 72 6f 77 69 64 20 3d  t' WHERE rowid =
1c70: 20 33 3b 0a 7d 0a 0a 23 20 32 20 73 65 67 6d 65   3;.}..# 2 segme
1c80: 6e 74 73 20 69 6e 20 6c 65 76 65 6c 20 30 2c 20  nts in level 0, 
1c90: 31 20 69 6e 20 6c 65 76 65 6c 20 31 20 28 31 38  1 in level 1 (18
1ca0: 20 73 65 67 6d 65 6e 74 73 20 63 72 65 61 74 65   segments create
1cb0: 64 2c 20 31 36 0a 23 20 6d 65 72 67 65 64 29 2e  d, 16.# merged).
1cc0: 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 64 2d 34  .do_test fts3d-4
1cd0: 2e 73 65 67 6d 65 6e 74 73 20 7b 0a 20 20 65 78  .segments {.  ex
1ce0: 65 63 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45  ecsql {.    SELE
1cf0: 43 54 20 6c 65 76 65 6c 2c 20 69 64 78 20 46 52  CT level, idx FR
1d00: 4f 4d 20 74 31 5f 73 65 67 64 69 72 20 4f 52 44  OM t1_segdir ORD
1d10: 45 52 20 42 59 20 6c 65 76 65 6c 2c 20 69 64 78  ER BY level, idx
1d20: 3b 0a 20 20 7d 0a 7d 20 7b 30 20 30 20 30 20 31  ;.  }.} {0 0 0 1
1d30: 20 31 20 30 7d 0a 0a 64 6f 5f 74 65 73 74 20 66   1 0}..do_test f
1d40: 74 73 33 64 2d 34 2e 6d 61 74 63 68 65 73 20 7b  ts3d-4.matches {
1d50: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
1d60: 20 53 45 4c 45 43 54 20 4f 46 46 53 45 54 53 28   SELECT OFFSETS(
1d70: 74 31 29 20 46 52 4f 4d 20 74 31 0a 20 20 20 20  t1) FROM t1.    
1d80: 20 57 48 45 52 45 20 74 31 20 4d 41 54 43 48 20   WHERE t1 MATCH 
1d90: 27 74 68 69 73 20 4f 52 20 74 68 61 74 20 4f 52  'this OR that OR
1da0: 20 77 61 73 20 4f 52 20 61 20 4f 52 20 69 73 20   was OR a OR is 
1db0: 4f 52 20 74 65 73 74 27 20 4f 52 44 45 52 20 42  OR test' ORDER B
1dc0: 59 20 64 6f 63 69 64 3b 0a 20 20 7d 0a 7d 20 5b  Y docid;.  }.} [
1dd0: 6c 69 73 74 20 7b 30 20 30 20 30 20 34 20 30 20  list {0 0 0 4 0 
1de0: 34 20 35 20 32 20 30 20 33 20 38 20 31 20 30 20  4 5 2 0 3 8 1 0 
1df0: 35 20 31 30 20 34 7d 20 5c 0a 20 20 20 20 20 20  5 10 4} \.      
1e00: 20 20 7b 30 20 31 20 30 20 34 20 30 20 32 20 35    {0 1 0 4 0 2 5
1e10: 20 33 20 30 20 33 20 39 20 31 20 30 20 35 20 31   3 0 3 9 1 0 5 1
1e20: 31 20 34 7d 20 5c 0a 20 20 20 20 20 20 20 20 7b  1 4} \.        {
1e30: 30 20 30 20 30 20 34 20 30 20 34 20 35 20 32 20  0 0 0 4 0 4 5 2 
1e40: 30 20 33 20 38 20 31 20 30 20 35 20 31 30 20 34  0 3 8 1 0 5 10 4
1e50: 7d 5d 0a 0a 64 62 20 65 76 61 6c 20 7b 53 45 4c  }]..db eval {SEL
1e60: 45 43 54 20 63 20 46 52 4f 4d 20 74 31 20 7d 0a  ECT c FROM t1 }.
1e70: 63 68 65 63 6b 5f 74 65 72 6d 73 5f 61 6c 6c 20  check_terms_all 
1e80: 66 74 73 33 64 2d 34 2e 31 20 20 20 20 20 20 7b  fts3d-4.1      {
1e90: 61 20 66 6f 75 72 20 69 73 20 74 65 73 74 20 74  a four is test t
1ea0: 68 61 74 20 74 68 69 73 20 77 61 73 7d 0a 63 68  hat this was}.ch
1eb0: 65 63 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20  eck_doclist_all 
1ec0: 66 74 73 33 64 2d 34 2e 31 2e 31 20 20 61 20 7b  fts3d-4.1.1  a {
1ed0: 5b 31 20 30 5b 32 5d 5d 20 5b 32 20 30 5b 32 5d  [1 0[2]] [2 0[2]
1ee0: 5d 20 5b 33 20 30 5b 32 5d 5d 7d 0a 63 68 65 63  ] [3 0[2]]}.chec
1ef0: 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74  k_doclist_all ft
1f00: 73 33 64 2d 34 2e 31 2e 32 20 20 66 6f 75 72 20  s3d-4.1.2  four 
1f10: 7b 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74  {}.check_doclist
1f20: 5f 61 6c 6c 20 66 74 73 33 64 2d 34 2e 31 2e 33  _all fts3d-4.1.3
1f30: 20 20 69 73 20 7b 5b 31 20 30 5b 31 5d 5d 20 5b    is {[1 0[1]] [
1f40: 33 20 30 5b 31 5d 5d 7d 0a 23 63 68 65 63 6b 5f  3 0[1]]}.#check_
1f50: 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73 33  doclist_all fts3
1f60: 64 2d 34 2e 31 2e 34 20 20 6f 6e 65 20 7b 7d 0a  d-4.1.4  one {}.
1f70: 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c  check_doclist_al
1f80: 6c 20 66 74 73 33 64 2d 34 2e 31 2e 35 20 20 74  l fts3d-4.1.5  t
1f90: 65 73 74 20 7b 5b 31 20 30 5b 33 5d 5d 20 5b 32  est {[1 0[3]] [2
1fa0: 20 30 5b 33 5d 5d 20 5b 33 20 30 5b 33 5d 5d 7d   0[3]] [3 0[3]]}
1fb0: 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f 61  .check_doclist_a
1fc0: 6c 6c 20 66 74 73 33 64 2d 34 2e 31 2e 36 20 20  ll fts3d-4.1.6  
1fd0: 74 68 61 74 20 7b 5b 32 20 30 5b 30 5d 5d 7d 0a  that {[2 0[0]]}.
1fe0: 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c  check_doclist_al
1ff0: 6c 20 66 74 73 33 64 2d 34 2e 31 2e 37 20 20 74  l fts3d-4.1.7  t
2000: 68 69 73 20 7b 5b 31 20 30 5b 30 5d 5d 20 5b 33  his {[1 0[0]] [3
2010: 20 30 5b 30 5d 5d 7d 0a 23 63 68 65 63 6b 5f 64   0[0]]}.#check_d
2020: 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73 33 64  oclist_all fts3d
2030: 2d 34 2e 31 2e 38 20 20 74 68 72 65 65 20 7b 7d  -4.1.8  three {}
2040: 0a 23 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f  .#check_doclist_
2050: 61 6c 6c 20 66 74 73 33 64 2d 34 2e 31 2e 39 20  all fts3d-4.1.9 
2060: 20 74 77 6f 20 7b 7d 0a 63 68 65 63 6b 5f 64 6f   two {}.check_do
2070: 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73 33 64 2d  clist_all fts3d-
2080: 34 2e 31 2e 31 30 20 77 61 73 20 7b 5b 32 20 30  4.1.10 was {[2 0
2090: 5b 31 5d 5d 7d 0a 0a 63 68 65 63 6b 5f 74 65 72  [1]]}..check_ter
20a0: 6d 73 20 66 74 73 33 64 2d 34 2e 32 20 20 20 20  ms fts3d-4.2    
20b0: 20 30 20 30 20 7b 61 20 66 6f 75 72 20 74 65 73   0 0 {a four tes
20c0: 74 20 74 68 61 74 20 77 61 73 7d 0a 63 68 65 63  t that was}.chec
20d0: 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64 2d  k_doclist fts3d-
20e0: 34 2e 32 2e 31 20 30 20 30 20 61 20 7b 5b 32 20  4.2.1 0 0 a {[2 
20f0: 30 5b 32 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63  0[2]]}.check_doc
2100: 6c 69 73 74 20 66 74 73 33 64 2d 34 2e 32 2e 32  list fts3d-4.2.2
2110: 20 30 20 30 20 66 6f 75 72 20 7b 5b 32 5d 7d 0a   0 0 four {[2]}.
2120: 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74  check_doclist ft
2130: 73 33 64 2d 34 2e 32 2e 33 20 30 20 30 20 74 65  s3d-4.2.3 0 0 te
2140: 73 74 20 7b 5b 32 20 30 5b 33 5d 5d 7d 0a 63 68  st {[2 0[3]]}.ch
2150: 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33  eck_doclist fts3
2160: 64 2d 34 2e 32 2e 34 20 30 20 30 20 74 68 61 74  d-4.2.4 0 0 that
2170: 20 7b 5b 32 20 30 5b 30 5d 5d 7d 0a 63 68 65 63   {[2 0[0]]}.chec
2180: 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64 2d  k_doclist fts3d-
2190: 34 2e 32 2e 35 20 30 20 30 20 77 61 73 20 7b 5b  4.2.5 0 0 was {[
21a0: 32 20 30 5b 31 5d 5d 7d 0a 0a 63 68 65 63 6b 5f  2 0[1]]}..check_
21b0: 74 65 72 6d 73 20 66 74 73 33 64 2d 34 2e 33 20  terms fts3d-4.3 
21c0: 20 20 20 20 30 20 31 20 7b 61 20 66 6f 75 72 20      0 1 {a four 
21d0: 69 73 20 74 65 73 74 20 74 68 69 73 7d 0a 63 68  is test this}.ch
21e0: 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33  eck_doclist fts3
21f0: 64 2d 34 2e 33 2e 31 20 30 20 31 20 61 20 7b 5b  d-4.3.1 0 1 a {[
2200: 33 20 30 5b 32 5d 5d 7d 0a 63 68 65 63 6b 5f 64  3 0[2]]}.check_d
2210: 6f 63 6c 69 73 74 20 66 74 73 33 64 2d 34 2e 33  oclist fts3d-4.3
2220: 2e 32 20 30 20 31 20 66 6f 75 72 20 7b 5b 33 5d  .2 0 1 four {[3]
2230: 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20  }.check_doclist 
2240: 66 74 73 33 64 2d 34 2e 33 2e 33 20 30 20 31 20  fts3d-4.3.3 0 1 
2250: 69 73 20 7b 5b 33 20 30 5b 31 5d 5d 7d 0a 63 68  is {[3 0[1]]}.ch
2260: 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33  eck_doclist fts3
2270: 64 2d 34 2e 33 2e 34 20 30 20 31 20 74 65 73 74  d-4.3.4 0 1 test
2280: 20 7b 5b 33 20 30 5b 33 5d 5d 7d 0a 63 68 65 63   {[3 0[3]]}.chec
2290: 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64 2d  k_doclist fts3d-
22a0: 34 2e 33 2e 35 20 30 20 31 20 74 68 69 73 20 7b  4.3.5 0 1 this {
22b0: 5b 33 20 30 5b 30 5d 5d 7d 0a 0a 63 68 65 63 6b  [3 0[0]]}..check
22c0: 5f 74 65 72 6d 73 20 66 74 73 33 64 2d 34 2e 34  _terms fts3d-4.4
22d0: 20 20 20 20 20 20 31 20 30 20 7b 61 20 66 6f 75        1 0 {a fou
22e0: 72 20 69 73 20 74 65 73 74 20 74 68 61 74 20 74  r is test that t
22f0: 68 69 73 20 77 61 73 7d 0a 63 68 65 63 6b 5f 64  his was}.check_d
2300: 6f 63 6c 69 73 74 20 66 74 73 33 64 2d 34 2e 34  oclist fts3d-4.4
2310: 2e 31 20 20 31 20 30 20 61 20 7b 5b 31 20 30 5b  .1  1 0 a {[1 0[
2320: 32 5d 5d 20 5b 32 20 30 5b 32 5d 5d 20 5b 33 20  2]] [2 0[2]] [3 
2330: 30 5b 32 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63  0[2]]}.check_doc
2340: 6c 69 73 74 20 66 74 73 33 64 2d 34 2e 34 2e 32  list fts3d-4.4.2
2350: 20 20 31 20 30 20 66 6f 75 72 20 7b 5b 32 20 30    1 0 four {[2 0
2360: 5b 34 5d 5d 20 5b 33 20 30 5b 34 5d 5d 7d 0a 63  [4]] [3 0[4]]}.c
2370: 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73  heck_doclist fts
2380: 33 64 2d 34 2e 34 2e 33 20 20 31 20 30 20 69 73  3d-4.4.3  1 0 is
2390: 20 7b 5b 31 20 30 5b 31 5d 5d 20 5b 33 20 30 5b   {[1 0[1]] [3 0[
23a0: 31 5d 5d 7d 0a 23 63 68 65 63 6b 5f 64 6f 63 6c  1]]}.#check_docl
23b0: 69 73 74 20 66 74 73 33 64 2d 34 2e 34 2e 34 20  ist fts3d-4.4.4 
23c0: 20 31 20 30 20 6f 6e 65 20 7b 5b 31 5d 20 5b 32   1 0 one {[1] [2
23d0: 5d 20 5b 33 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63  ] [3]}.check_doc
23e0: 6c 69 73 74 20 66 74 73 33 64 2d 34 2e 34 2e 35  list fts3d-4.4.5
23f0: 20 20 31 20 30 20 74 65 73 74 20 7b 5b 31 20 30    1 0 test {[1 0
2400: 5b 33 5d 5d 20 5b 32 20 30 5b 33 5d 5d 20 5b 33  [3]] [2 0[3]] [3
2410: 20 30 5b 33 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f   0[3]]}.check_do
2420: 63 6c 69 73 74 20 66 74 73 33 64 2d 34 2e 34 2e  clist fts3d-4.4.
2430: 36 20 20 31 20 30 20 74 68 61 74 20 7b 5b 32 20  6  1 0 that {[2 
2440: 30 5b 30 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63  0[0]]}.check_doc
2450: 6c 69 73 74 20 66 74 73 33 64 2d 34 2e 34 2e 37  list fts3d-4.4.7
2460: 20 20 31 20 30 20 74 68 69 73 20 7b 5b 31 20 30    1 0 this {[1 0
2470: 5b 30 5d 5d 20 5b 33 20 30 5b 30 5d 5d 7d 0a 23  [0]] [3 0[0]]}.#
2480: 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74  check_doclist ft
2490: 73 33 64 2d 34 2e 34 2e 38 20 20 31 20 30 20 74  s3d-4.4.8  1 0 t
24a0: 68 72 65 65 20 7b 5b 31 5d 20 5b 32 5d 20 5b 33  hree {[1] [2] [3
24b0: 5d 7d 0a 23 63 68 65 63 6b 5f 64 6f 63 6c 69 73  ]}.#check_doclis
24c0: 74 20 66 74 73 33 64 2d 34 2e 34 2e 39 20 20 31  t fts3d-4.4.9  1
24d0: 20 30 20 74 77 6f 20 7b 5b 31 5d 20 5b 32 5d 20   0 two {[1] [2] 
24e0: 5b 33 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69  [3]}.check_docli
24f0: 73 74 20 66 74 73 33 64 2d 34 2e 34 2e 31 30 20  st fts3d-4.4.10 
2500: 31 20 30 20 77 61 73 20 7b 5b 32 20 30 5b 31 5d  1 0 was {[2 0[1]
2510: 5d 7d 0a 0a 23 20 4f 70 74 69 6d 69 7a 65 20 73  ]}..# Optimize s
2520: 68 6f 75 6c 64 20 6c 65 61 76 65 20 74 68 65 20  hould leave the 
2530: 72 65 73 75 6c 74 20 69 6e 20 74 68 65 20 6c 65  result in the le
2540: 76 65 6c 20 6f 66 20 74 68 65 20 68 69 67 68 65  vel of the highe
2550: 73 74 2d 6c 65 76 65 6c 0a 23 20 70 72 69 6f 72  st-level.# prior
2560: 20 73 65 67 6d 65 6e 74 2e 0a 64 6f 5f 74 65 73   segment..do_tes
2570: 74 20 66 74 73 33 64 2d 34 2e 35 20 7b 0a 20 20  t fts3d-4.5 {.  
2580: 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 53 45  execsql {.    SE
2590: 4c 45 43 54 20 4f 50 54 49 4d 49 5a 45 28 74 31  LECT OPTIMIZE(t1
25a0: 29 20 46 52 4f 4d 20 74 31 20 4c 49 4d 49 54 20  ) FROM t1 LIMIT 
25b0: 31 3b 0a 20 20 20 20 53 45 4c 45 43 54 20 6c 65  1;.    SELECT le
25c0: 76 65 6c 2c 20 69 64 78 20 46 52 4f 4d 20 74 31  vel, idx FROM t1
25d0: 5f 73 65 67 64 69 72 20 4f 52 44 45 52 20 42 59  _segdir ORDER BY
25e0: 20 6c 65 76 65 6c 2c 20 69 64 78 3b 0a 20 20 7d   level, idx;.  }
25f0: 0a 7d 20 7b 7b 49 6e 64 65 78 20 6f 70 74 69 6d  .} {{Index optim
2600: 69 7a 65 64 7d 20 31 20 30 7d 0a 0a 23 20 49 64  ized} 1 0}..# Id
2610: 65 6e 74 69 63 61 6c 20 74 6f 20 66 74 73 33 64  entical to fts3d
2620: 2d 34 2e 6d 61 74 63 68 65 73 2e 0a 64 6f 5f 74  -4.matches..do_t
2630: 65 73 74 20 66 74 73 33 64 2d 34 2e 35 2e 6d 61  est fts3d-4.5.ma
2640: 74 63 68 65 73 20 7b 0a 20 20 65 78 65 63 73 71  tches {.  execsq
2650: 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 4f  l {.    SELECT O
2660: 46 46 53 45 54 53 28 74 31 29 20 46 52 4f 4d 20  FFSETS(t1) FROM 
2670: 74 31 0a 20 20 20 20 20 57 48 45 52 45 20 74 31  t1.     WHERE t1
2680: 20 4d 41 54 43 48 20 27 74 68 69 73 20 4f 52 20   MATCH 'this OR 
2690: 74 68 61 74 20 4f 52 20 77 61 73 20 4f 52 20 61  that OR was OR a
26a0: 20 4f 52 20 69 73 20 4f 52 20 74 65 73 74 27 20   OR is OR test' 
26b0: 4f 52 44 45 52 20 42 59 20 64 6f 63 69 64 3b 0a  ORDER BY docid;.
26c0: 20 20 7d 0a 7d 20 5b 6c 69 73 74 20 7b 30 20 30    }.} [list {0 0
26d0: 20 30 20 34 20 30 20 34 20 35 20 32 20 30 20 33   0 4 0 4 5 2 0 3
26e0: 20 38 20 31 20 30 20 35 20 31 30 20 34 7d 20 5c   8 1 0 5 10 4} \
26f0: 0a 20 20 20 20 20 20 20 20 7b 30 20 31 20 30 20  .        {0 1 0 
2700: 34 20 30 20 32 20 35 20 33 20 30 20 33 20 39 20  4 0 2 5 3 0 3 9 
2710: 31 20 30 20 35 20 31 31 20 34 7d 20 5c 0a 20 20  1 0 5 11 4} \.  
2720: 20 20 20 20 20 20 7b 30 20 30 20 30 20 34 20 30        {0 0 0 4 0
2730: 20 34 20 35 20 32 20 30 20 33 20 38 20 31 20 30   4 5 2 0 3 8 1 0
2740: 20 35 20 31 30 20 34 7d 5d 0a 0a 63 68 65 63 6b   5 10 4}]..check
2750: 5f 74 65 72 6d 73 5f 61 6c 6c 20 66 74 73 33 64  _terms_all fts3d
2760: 2d 34 2e 35 2e 31 20 20 20 20 20 7b 61 20 69 73  -4.5.1     {a is
2770: 20 74 65 73 74 20 74 68 61 74 20 74 68 69 73 20   test that this 
2780: 77 61 73 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69  was}.check_docli
2790: 73 74 5f 61 6c 6c 20 66 74 73 33 64 2d 34 2e 35  st_all fts3d-4.5
27a0: 2e 31 2e 31 20 61 20 7b 5b 31 20 30 5b 32 5d 5d  .1.1 a {[1 0[2]]
27b0: 20 5b 32 20 30 5b 32 5d 5d 20 5b 33 20 30 5b 32   [2 0[2]] [3 0[2
27c0: 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73  ]]}.check_doclis
27d0: 74 5f 61 6c 6c 20 66 74 73 33 64 2d 34 2e 35 2e  t_all fts3d-4.5.
27e0: 31 2e 32 20 69 73 20 7b 5b 31 20 30 5b 31 5d 5d  1.2 is {[1 0[1]]
27f0: 20 5b 33 20 30 5b 31 5d 5d 7d 0a 63 68 65 63 6b   [3 0[1]]}.check
2800: 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73  _doclist_all fts
2810: 33 64 2d 34 2e 35 2e 31 2e 33 20 74 65 73 74 20  3d-4.5.1.3 test 
2820: 7b 5b 31 20 30 5b 33 5d 5d 20 5b 32 20 30 5b 33  {[1 0[3]] [2 0[3
2830: 5d 5d 20 5b 33 20 30 5b 33 5d 5d 7d 0a 63 68 65  ]] [3 0[3]]}.che
2840: 63 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66  ck_doclist_all f
2850: 74 73 33 64 2d 34 2e 35 2e 31 2e 34 20 74 68 61  ts3d-4.5.1.4 tha
2860: 74 20 7b 5b 32 20 30 5b 30 5d 5d 7d 0a 63 68 65  t {[2 0[0]]}.che
2870: 63 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66  ck_doclist_all f
2880: 74 73 33 64 2d 34 2e 35 2e 31 2e 35 20 74 68 69  ts3d-4.5.1.5 thi
2890: 73 20 7b 5b 31 20 30 5b 30 5d 5d 20 5b 33 20 30  s {[1 0[0]] [3 0
28a0: 5b 30 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c  [0]]}.check_docl
28b0: 69 73 74 5f 61 6c 6c 20 66 74 73 33 64 2d 34 2e  ist_all fts3d-4.
28c0: 35 2e 31 2e 36 20 77 61 73 20 7b 5b 32 20 30 5b  5.1.6 was {[2 0[
28d0: 31 5d 5d 7d 0a 0a 63 68 65 63 6b 5f 74 65 72 6d  1]]}..check_term
28e0: 73 20 66 74 73 33 64 2d 34 2e 35 2e 32 20 20 20  s fts3d-4.5.2   
28f0: 20 20 31 20 30 20 7b 61 20 69 73 20 74 65 73 74    1 0 {a is test
2900: 20 74 68 61 74 20 74 68 69 73 20 77 61 73 7d 0a   that this was}.
2910: 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74  check_doclist ft
2920: 73 33 64 2d 34 2e 35 2e 32 2e 31 20 31 20 30 20  s3d-4.5.2.1 1 0 
2930: 61 20 7b 5b 31 20 30 5b 32 5d 5d 20 5b 32 20 30  a {[1 0[2]] [2 0
2940: 5b 32 5d 5d 20 5b 33 20 30 5b 32 5d 5d 7d 0a 63  [2]] [3 0[2]]}.c
2950: 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73  heck_doclist fts
2960: 33 64 2d 34 2e 35 2e 32 2e 32 20 31 20 30 20 69  3d-4.5.2.2 1 0 i
2970: 73 20 7b 5b 31 20 30 5b 31 5d 5d 20 5b 33 20 30  s {[1 0[1]] [3 0
2980: 5b 31 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c  [1]]}.check_docl
2990: 69 73 74 20 66 74 73 33 64 2d 34 2e 35 2e 32 2e  ist fts3d-4.5.2.
29a0: 33 20 31 20 30 20 74 65 73 74 20 7b 5b 31 20 30  3 1 0 test {[1 0
29b0: 5b 33 5d 5d 20 5b 32 20 30 5b 33 5d 5d 20 5b 33  [3]] [2 0[3]] [3
29c0: 20 30 5b 33 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f   0[3]]}.check_do
29d0: 63 6c 69 73 74 20 66 74 73 33 64 2d 34 2e 35 2e  clist fts3d-4.5.
29e0: 32 2e 34 20 31 20 30 20 74 68 61 74 20 7b 5b 32  2.4 1 0 that {[2
29f0: 20 30 5b 30 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f   0[0]]}.check_do
2a00: 63 6c 69 73 74 20 66 74 73 33 64 2d 34 2e 35 2e  clist fts3d-4.5.
2a10: 32 2e 35 20 31 20 30 20 74 68 69 73 20 7b 5b 31  2.5 1 0 this {[1
2a20: 20 30 5b 30 5d 5d 20 5b 33 20 30 5b 30 5d 5d 7d   0[0]] [3 0[0]]}
2a30: 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66  .check_doclist f
2a40: 74 73 33 64 2d 34 2e 35 2e 32 2e 36 20 31 20 30  ts3d-4.5.2.6 1 0
2a50: 20 77 61 73 20 7b 5b 32 20 30 5b 31 5d 5d 7d 0a   was {[2 0[1]]}.
2a60: 0a 23 20 52 65 2d 6f 70 74 69 6d 69 7a 69 6e 67  .# Re-optimizing
2a70: 20 64 6f 65 73 20 6e 6f 74 68 69 6e 67 2e 0a 64   does nothing..d
2a80: 6f 5f 74 65 73 74 20 66 74 73 33 64 2d 35 2e 30  o_test fts3d-5.0
2a90: 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20   {.  execsql {. 
2aa0: 20 20 20 53 45 4c 45 43 54 20 4f 50 54 49 4d 49     SELECT OPTIMI
2ab0: 5a 45 28 74 31 29 20 46 52 4f 4d 20 74 31 20 4c  ZE(t1) FROM t1 L
2ac0: 49 4d 49 54 20 31 3b 0a 20 20 20 20 53 45 4c 45  IMIT 1;.    SELE
2ad0: 43 54 20 6c 65 76 65 6c 2c 20 69 64 78 20 46 52  CT level, idx FR
2ae0: 4f 4d 20 74 31 5f 73 65 67 64 69 72 20 4f 52 44  OM t1_segdir ORD
2af0: 45 52 20 42 59 20 6c 65 76 65 6c 2c 20 69 64 78  ER BY level, idx
2b00: 3b 0a 20 20 7d 0a 7d 20 7b 7b 49 6e 64 65 78 20  ;.  }.} {{Index 
2b10: 61 6c 72 65 61 64 79 20 6f 70 74 69 6d 61 6c 7d  already optimal}
2b20: 20 31 20 30 7d 0a 0a 23 20 45 76 65 6e 20 69 66   1 0}..# Even if
2b30: 20 77 65 20 6d 6f 76 65 20 74 68 69 6e 67 73 20   we move things 
2b40: 61 72 6f 75 6e 64 2c 20 73 74 69 6c 6c 20 64 6f  around, still do
2b50: 65 73 20 6e 6f 74 68 69 6e 67 2e 0a 73 71 6c 69  es nothing..sqli
2b60: 74 65 33 5f 64 62 5f 63 6f 6e 66 69 67 20 64 62  te3_db_config db
2b70: 20 44 45 46 45 4e 53 49 56 45 20 30 0a 64 6f 5f   DEFENSIVE 0.do_
2b80: 74 65 73 74 20 66 74 73 33 64 2d 35 2e 31 20 7b  test fts3d-5.1 {
2b90: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
2ba0: 20 55 50 44 41 54 45 20 74 31 5f 73 65 67 64 69   UPDATE t1_segdi
2bb0: 72 20 53 45 54 20 6c 65 76 65 6c 20 3d 20 32 20  r SET level = 2 
2bc0: 57 48 45 52 45 20 6c 65 76 65 6c 20 3d 20 31 20  WHERE level = 1 
2bd0: 41 4e 44 20 69 64 78 20 3d 20 30 3b 0a 20 20 20  AND idx = 0;.   
2be0: 20 53 45 4c 45 43 54 20 4f 50 54 49 4d 49 5a 45   SELECT OPTIMIZE
2bf0: 28 74 31 29 20 46 52 4f 4d 20 74 31 20 4c 49 4d  (t1) FROM t1 LIM
2c00: 49 54 20 31 3b 0a 20 20 20 20 53 45 4c 45 43 54  IT 1;.    SELECT
2c10: 20 6c 65 76 65 6c 2c 20 69 64 78 20 46 52 4f 4d   level, idx FROM
2c20: 20 74 31 5f 73 65 67 64 69 72 20 4f 52 44 45 52   t1_segdir ORDER
2c30: 20 42 59 20 6c 65 76 65 6c 2c 20 69 64 78 3b 0a   BY level, idx;.
2c40: 20 20 7d 0a 7d 20 7b 7b 49 6e 64 65 78 20 61 6c    }.} {{Index al
2c50: 72 65 61 64 79 20 6f 70 74 69 6d 61 6c 7d 20 32  ready optimal} 2
2c60: 20 30 7d 0a 0a 0a 23 20 41 4c 54 45 52 20 54 41   0}...# ALTER TA
2c70: 42 4c 45 20 52 45 4e 41 4d 45 20 73 68 6f 75 6c  BLE RENAME shoul
2c80: 64 20 77 6f 72 6b 20 72 65 67 61 72 64 6c 65 73  d work regardles
2c90: 73 20 6f 66 20 74 68 65 20 64 61 74 61 62 61 73  s of the databas
2ca0: 65 20 65 6e 63 6f 64 69 6e 67 2e 0a 23 0a 64 6f  e encoding..#.do
2cb0: 5f 74 65 73 74 20 66 74 73 33 64 2d 36 2e 30 20  _test fts3d-6.0 
2cc0: 7b 0a 20 20 64 62 20 63 6c 6f 73 65 0a 20 20 66  {.  db close.  f
2cd0: 6f 72 63 65 64 65 6c 65 74 65 20 74 65 73 74 2e  orcedelete test.
2ce0: 64 62 0a 20 20 73 71 6c 69 74 65 33 20 64 62 20  db.  sqlite3 db 
2cf0: 74 65 73 74 2e 64 62 0a 20 20 64 62 20 65 76 61  test.db.  db eva
2d00: 6c 20 7b 0a 20 20 20 20 50 52 41 47 4d 41 20 65  l {.    PRAGMA e
2d10: 6e 63 6f 64 69 6e 67 3d 55 54 46 38 3b 0a 20 20  ncoding=UTF8;.  
2d20: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
2d30: 20 54 41 42 4c 45 20 66 74 73 20 55 53 49 4e 47   TABLE fts USING
2d40: 20 66 74 73 33 28 61 2c 62 2c 63 29 3b 0a 20 20   fts3(a,b,c);.  
2d50: 20 20 53 45 4c 45 43 54 20 6e 61 6d 65 20 46 52    SELECT name FR
2d60: 4f 4d 20 73 71 6c 69 74 65 5f 6d 61 73 74 65 72  OM sqlite_master
2d70: 20 57 48 45 52 45 20 6e 61 6d 65 20 47 4c 4f 42   WHERE name GLOB
2d80: 20 27 3f 3f 3f 5f 2a 27 20 4f 52 44 45 52 20 42   '???_*' ORDER B
2d90: 59 20 31 3b 0a 20 20 7d 0a 7d 20 7b 66 74 73 5f  Y 1;.  }.} {fts_
2da0: 63 6f 6e 74 65 6e 74 20 66 74 73 5f 73 65 67 64  content fts_segd
2db0: 69 72 20 66 74 73 5f 73 65 67 6d 65 6e 74 73 7d  ir fts_segments}
2dc0: 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 64 2d 36  .do_test fts3d-6
2dd0: 2e 31 20 7b 0a 20 20 64 62 20 65 76 61 6c 20 7b  .1 {.  db eval {
2de0: 0a 20 20 20 20 41 4c 54 45 52 20 54 41 42 4c 45  .    ALTER TABLE
2df0: 20 66 74 73 20 52 45 4e 41 4d 45 20 54 4f 20 78   fts RENAME TO x
2e00: 79 7a 3b 0a 20 20 20 20 53 45 4c 45 43 54 20 6e  yz;.    SELECT n
2e10: 61 6d 65 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f  ame FROM sqlite_
2e20: 6d 61 73 74 65 72 20 57 48 45 52 45 20 6e 61 6d  master WHERE nam
2e30: 65 20 47 4c 4f 42 20 27 3f 3f 3f 5f 2a 27 20 4f  e GLOB '???_*' O
2e40: 52 44 45 52 20 42 59 20 31 3b 0a 20 20 7d 0a 7d  RDER BY 1;.  }.}
2e50: 20 7b 78 79 7a 5f 63 6f 6e 74 65 6e 74 20 78 79   {xyz_content xy
2e60: 7a 5f 73 65 67 64 69 72 20 78 79 7a 5f 73 65 67  z_segdir xyz_seg
2e70: 6d 65 6e 74 73 7d 0a 64 6f 5f 74 65 73 74 20 66  ments}.do_test f
2e80: 74 73 33 64 2d 36 2e 32 20 7b 0a 20 20 64 62 20  ts3d-6.2 {.  db 
2e90: 63 6c 6f 73 65 0a 20 20 66 6f 72 63 65 64 65 6c  close.  forcedel
2ea0: 65 74 65 20 74 65 73 74 2e 64 62 0a 20 20 73 71  ete test.db.  sq
2eb0: 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e 64 62  lite3 db test.db
2ec0: 0a 20 20 64 62 20 65 76 61 6c 20 7b 0a 20 20 20  .  db eval {.   
2ed0: 20 50 52 41 47 4d 41 20 65 6e 63 6f 64 69 6e 67   PRAGMA encoding
2ee0: 3d 55 54 46 31 36 6c 65 3b 0a 20 20 20 20 43 52  =UTF16le;.    CR
2ef0: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42  EATE VIRTUAL TAB
2f00: 4c 45 20 66 74 73 20 55 53 49 4e 47 20 66 74 73  LE fts USING fts
2f10: 33 28 61 2c 62 2c 63 29 3b 0a 20 20 20 20 53 45  3(a,b,c);.    SE
2f20: 4c 45 43 54 20 6e 61 6d 65 20 46 52 4f 4d 20 73  LECT name FROM s
2f30: 71 6c 69 74 65 5f 6d 61 73 74 65 72 20 57 48 45  qlite_master WHE
2f40: 52 45 20 6e 61 6d 65 20 47 4c 4f 42 20 27 3f 3f  RE name GLOB '??
2f50: 3f 5f 2a 27 20 4f 52 44 45 52 20 42 59 20 31 3b  ?_*' ORDER BY 1;
2f60: 0a 20 20 7d 0a 7d 20 7b 66 74 73 5f 63 6f 6e 74  .  }.} {fts_cont
2f70: 65 6e 74 20 66 74 73 5f 73 65 67 64 69 72 20 66  ent fts_segdir f
2f80: 74 73 5f 73 65 67 6d 65 6e 74 73 7d 0a 64 6f 5f  ts_segments}.do_
2f90: 74 65 73 74 20 66 74 73 33 64 2d 36 2e 33 20 7b  test fts3d-6.3 {
2fa0: 0a 20 20 64 62 20 65 76 61 6c 20 7b 0a 20 20 20  .  db eval {.   
2fb0: 20 41 4c 54 45 52 20 54 41 42 4c 45 20 66 74 73   ALTER TABLE fts
2fc0: 20 52 45 4e 41 4d 45 20 54 4f 20 78 79 7a 3b 0a   RENAME TO xyz;.
2fd0: 20 20 20 20 53 45 4c 45 43 54 20 6e 61 6d 65 20      SELECT name 
2fe0: 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d 61 73 74  FROM sqlite_mast
2ff0: 65 72 20 57 48 45 52 45 20 6e 61 6d 65 20 47 4c  er WHERE name GL
3000: 4f 42 20 27 3f 3f 3f 5f 2a 27 20 4f 52 44 45 52  OB '???_*' ORDER
3010: 20 42 59 20 31 3b 0a 20 20 7d 0a 7d 20 7b 78 79   BY 1;.  }.} {xy
3020: 7a 5f 63 6f 6e 74 65 6e 74 20 78 79 7a 5f 73 65  z_content xyz_se
3030: 67 64 69 72 20 78 79 7a 5f 73 65 67 6d 65 6e 74  gdir xyz_segment
3040: 73 7d 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 64  s}.do_test fts3d
3050: 2d 36 2e 34 20 7b 0a 20 20 64 62 20 63 6c 6f 73  -6.4 {.  db clos
3060: 65 0a 20 20 66 6f 72 63 65 64 65 6c 65 74 65 20  e.  forcedelete 
3070: 74 65 73 74 2e 64 62 0a 20 20 73 71 6c 69 74 65  test.db.  sqlite
3080: 33 20 64 62 20 74 65 73 74 2e 64 62 0a 20 20 64  3 db test.db.  d
3090: 62 20 65 76 61 6c 20 7b 0a 20 20 20 20 50 52 41  b eval {.    PRA
30a0: 47 4d 41 20 65 6e 63 6f 64 69 6e 67 3d 55 54 46  GMA encoding=UTF
30b0: 31 36 62 65 3b 0a 20 20 20 20 43 52 45 41 54 45  16be;.    CREATE
30c0: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 66   VIRTUAL TABLE f
30d0: 74 73 20 55 53 49 4e 47 20 66 74 73 33 28 61 2c  ts USING fts3(a,
30e0: 62 2c 63 29 3b 0a 20 20 20 20 53 45 4c 45 43 54  b,c);.    SELECT
30f0: 20 6e 61 6d 65 20 46 52 4f 4d 20 73 71 6c 69 74   name FROM sqlit
3100: 65 5f 6d 61 73 74 65 72 20 57 48 45 52 45 20 6e  e_master WHERE n
3110: 61 6d 65 20 47 4c 4f 42 20 27 3f 3f 3f 5f 2a 27  ame GLOB '???_*'
3120: 20 4f 52 44 45 52 20 42 59 20 31 3b 0a 20 20 7d   ORDER BY 1;.  }
3130: 0a 7d 20 7b 66 74 73 5f 63 6f 6e 74 65 6e 74 20  .} {fts_content 
3140: 66 74 73 5f 73 65 67 64 69 72 20 66 74 73 5f 73  fts_segdir fts_s
3150: 65 67 6d 65 6e 74 73 7d 0a 64 6f 5f 74 65 73 74  egments}.do_test
3160: 20 66 74 73 33 64 2d 36 2e 35 20 7b 0a 20 20 64   fts3d-6.5 {.  d
3170: 62 20 65 76 61 6c 20 7b 0a 20 20 20 20 41 4c 54  b eval {.    ALT
3180: 45 52 20 54 41 42 4c 45 20 66 74 73 20 52 45 4e  ER TABLE fts REN
3190: 41 4d 45 20 54 4f 20 78 79 7a 3b 0a 20 20 20 20  AME TO xyz;.    
31a0: 53 45 4c 45 43 54 20 6e 61 6d 65 20 46 52 4f 4d  SELECT name FROM
31b0: 20 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 20 57   sqlite_master W
31c0: 48 45 52 45 20 6e 61 6d 65 20 47 4c 4f 42 20 27  HERE name GLOB '
31d0: 3f 3f 3f 5f 2a 27 20 4f 52 44 45 52 20 42 59 20  ???_*' ORDER BY 
31e0: 31 3b 0a 20 20 7d 0a 7d 20 7b 78 79 7a 5f 63 6f  1;.  }.} {xyz_co
31f0: 6e 74 65 6e 74 20 78 79 7a 5f 73 65 67 64 69 72  ntent xyz_segdir
3200: 20 78 79 7a 5f 73 65 67 6d 65 6e 74 73 7d 0a 0a   xyz_segments}..
3210: 23 20 41 4c 54 45 52 20 54 41 42 4c 45 20 52 45  # ALTER TABLE RE
3220: 4e 41 4d 45 20 6f 6e 20 61 6e 20 46 54 53 33 20  NAME on an FTS3 
3230: 74 61 62 6c 65 20 66 6f 6c 6c 6f 77 69 6e 67 20  table following 
3240: 61 6e 20 69 6e 63 72 2d 6d 65 72 67 65 20 6f 70  an incr-merge op
3250: 2e 0a 23 0a 64 6f 5f 74 65 73 74 20 66 74 73 33  ..#.do_test fts3
3260: 64 2d 36 2e 36 20 7b 0a 20 20 65 78 65 63 73 71  d-6.6 {.  execsq
3270: 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  l { INSERT INTO 
3280: 78 79 7a 28 78 79 7a 29 20 56 41 4c 55 45 53 28  xyz(xyz) VALUES(
3290: 27 6d 65 72 67 65 3d 32 2c 32 27 29 20 7d 0a 20  'merge=2,2') }. 
32a0: 20 73 71 6c 69 74 65 33 20 64 62 20 74 65 73 74   sqlite3 db test
32b0: 2e 64 62 0a 20 20 65 78 65 63 73 71 6c 20 7b 20  .db.  execsql { 
32c0: 0a 20 20 20 20 41 4c 54 45 52 20 54 41 42 4c 45  .    ALTER TABLE
32d0: 20 78 79 7a 20 52 45 4e 41 4d 45 20 54 4f 20 6f   xyz RENAME TO o
32e0: 74 74 3b 0a 20 20 20 20 53 45 4c 45 43 54 20 6e  tt;.    SELECT n
32f0: 61 6d 65 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f  ame FROM sqlite_
3300: 6d 61 73 74 65 72 20 57 48 45 52 45 20 6e 61 6d  master WHERE nam
3310: 65 20 47 4c 4f 42 20 27 3f 3f 3f 5f 2a 27 20 4f  e GLOB '???_*' O
3320: 52 44 45 52 20 42 59 20 31 3b 0a 20 20 7d 0a 7d  RDER BY 1;.  }.}
3330: 20 7b 6f 74 74 5f 63 6f 6e 74 65 6e 74 20 6f 74   {ott_content ot
3340: 74 5f 73 65 67 64 69 72 20 6f 74 74 5f 73 65 67  t_segdir ott_seg
3350: 6d 65 6e 74 73 20 6f 74 74 5f 73 74 61 74 7d 0a  ments ott_stat}.
3360: 20 0a 0a 66 69 6e 69 73 68 5f 74 65 73 74 0a      ..finish_test.