/ Hex Artifact Content
Login

Artifact c8a193513a269ec4c205ca09645e26e0bc71b860:


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 63 68 65 63 6b 5f 74 65 72 6d 73 5f  }]..check_terms_
1e60: 61 6c 6c 20 66 74 73 33 64 2d 34 2e 31 20 20 20  all fts3d-4.1   
1e70: 20 20 20 7b 61 20 66 6f 75 72 20 69 73 20 6f 6e     {a four is on
1e80: 65 20 74 65 73 74 20 74 68 61 74 20 74 68 69 73  e test that this
1e90: 20 74 68 72 65 65 20 74 77 6f 20 77 61 73 7d 0a   three two was}.
1ea0: 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c  check_doclist_al
1eb0: 6c 20 66 74 73 33 64 2d 34 2e 31 2e 31 20 20 61  l fts3d-4.1.1  a
1ec0: 20 7b 5b 31 20 30 5b 32 5d 5d 20 5b 32 20 30 5b   {[1 0[2]] [2 0[
1ed0: 32 5d 5d 20 5b 33 20 30 5b 32 5d 5d 7d 0a 63 68  2]] [3 0[2]]}.ch
1ee0: 65 63 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20  eck_doclist_all 
1ef0: 66 74 73 33 64 2d 34 2e 31 2e 32 20 20 66 6f 75  fts3d-4.1.2  fou
1f00: 72 20 7b 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69  r {}.check_docli
1f10: 73 74 5f 61 6c 6c 20 66 74 73 33 64 2d 34 2e 31  st_all fts3d-4.1
1f20: 2e 33 20 20 69 73 20 7b 5b 31 20 30 5b 31 5d 5d  .3  is {[1 0[1]]
1f30: 20 5b 33 20 30 5b 31 5d 5d 7d 0a 63 68 65 63 6b   [3 0[1]]}.check
1f40: 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73  _doclist_all fts
1f50: 33 64 2d 34 2e 31 2e 34 20 20 6f 6e 65 20 7b 7d  3d-4.1.4  one {}
1f60: 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f 61  .check_doclist_a
1f70: 6c 6c 20 66 74 73 33 64 2d 34 2e 31 2e 35 20 20  ll fts3d-4.1.5  
1f80: 74 65 73 74 20 7b 5b 31 20 30 5b 33 5d 5d 20 5b  test {[1 0[3]] [
1f90: 32 20 30 5b 33 5d 5d 20 5b 33 20 30 5b 33 5d 5d  2 0[3]] [3 0[3]]
1fa0: 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f  }.check_doclist_
1fb0: 61 6c 6c 20 66 74 73 33 64 2d 34 2e 31 2e 36 20  all fts3d-4.1.6 
1fc0: 20 74 68 61 74 20 7b 5b 32 20 30 5b 30 5d 5d 7d   that {[2 0[0]]}
1fd0: 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f 61  .check_doclist_a
1fe0: 6c 6c 20 66 74 73 33 64 2d 34 2e 31 2e 37 20 20  ll fts3d-4.1.7  
1ff0: 74 68 69 73 20 7b 5b 31 20 30 5b 30 5d 5d 20 5b  this {[1 0[0]] [
2000: 33 20 30 5b 30 5d 5d 7d 0a 63 68 65 63 6b 5f 64  3 0[0]]}.check_d
2010: 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73 33 64  oclist_all fts3d
2020: 2d 34 2e 31 2e 38 20 20 74 68 72 65 65 20 7b 7d  -4.1.8  three {}
2030: 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f 61  .check_doclist_a
2040: 6c 6c 20 66 74 73 33 64 2d 34 2e 31 2e 39 20 20  ll fts3d-4.1.9  
2050: 74 77 6f 20 7b 7d 0a 63 68 65 63 6b 5f 64 6f 63  two {}.check_doc
2060: 6c 69 73 74 5f 61 6c 6c 20 66 74 73 33 64 2d 34  list_all fts3d-4
2070: 2e 31 2e 31 30 20 77 61 73 20 7b 5b 32 20 30 5b  .1.10 was {[2 0[
2080: 31 5d 5d 7d 0a 0a 63 68 65 63 6b 5f 74 65 72 6d  1]]}..check_term
2090: 73 20 66 74 73 33 64 2d 34 2e 32 20 20 20 20 20  s fts3d-4.2     
20a0: 30 20 30 20 7b 61 20 66 6f 75 72 20 74 65 73 74  0 0 {a four test
20b0: 20 74 68 61 74 20 77 61 73 7d 0a 63 68 65 63 6b   that was}.check
20c0: 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64 2d 34  _doclist fts3d-4
20d0: 2e 32 2e 31 20 30 20 30 20 61 20 7b 5b 32 20 30  .2.1 0 0 a {[2 0
20e0: 5b 32 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c  [2]]}.check_docl
20f0: 69 73 74 20 66 74 73 33 64 2d 34 2e 32 2e 32 20  ist fts3d-4.2.2 
2100: 30 20 30 20 66 6f 75 72 20 7b 5b 32 5d 7d 0a 63  0 0 four {[2]}.c
2110: 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73  heck_doclist fts
2120: 33 64 2d 34 2e 32 2e 33 20 30 20 30 20 74 65 73  3d-4.2.3 0 0 tes
2130: 74 20 7b 5b 32 20 30 5b 33 5d 5d 7d 0a 63 68 65  t {[2 0[3]]}.che
2140: 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64  ck_doclist fts3d
2150: 2d 34 2e 32 2e 34 20 30 20 30 20 74 68 61 74 20  -4.2.4 0 0 that 
2160: 7b 5b 32 20 30 5b 30 5d 5d 7d 0a 63 68 65 63 6b  {[2 0[0]]}.check
2170: 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64 2d 34  _doclist fts3d-4
2180: 2e 32 2e 35 20 30 20 30 20 77 61 73 20 7b 5b 32  .2.5 0 0 was {[2
2190: 20 30 5b 31 5d 5d 7d 0a 0a 63 68 65 63 6b 5f 74   0[1]]}..check_t
21a0: 65 72 6d 73 20 66 74 73 33 64 2d 34 2e 33 20 20  erms fts3d-4.3  
21b0: 20 20 20 30 20 31 20 7b 61 20 66 6f 75 72 20 69     0 1 {a four i
21c0: 73 20 74 65 73 74 20 74 68 69 73 7d 0a 63 68 65  s test this}.che
21d0: 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64  ck_doclist fts3d
21e0: 2d 34 2e 33 2e 31 20 30 20 31 20 61 20 7b 5b 33  -4.3.1 0 1 a {[3
21f0: 20 30 5b 32 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f   0[2]]}.check_do
2200: 63 6c 69 73 74 20 66 74 73 33 64 2d 34 2e 33 2e  clist fts3d-4.3.
2210: 32 20 30 20 31 20 66 6f 75 72 20 7b 5b 33 5d 7d  2 0 1 four {[3]}
2220: 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66  .check_doclist f
2230: 74 73 33 64 2d 34 2e 33 2e 33 20 30 20 31 20 69  ts3d-4.3.3 0 1 i
2240: 73 20 7b 5b 33 20 30 5b 31 5d 5d 7d 0a 63 68 65  s {[3 0[1]]}.che
2250: 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64  ck_doclist fts3d
2260: 2d 34 2e 33 2e 34 20 30 20 31 20 74 65 73 74 20  -4.3.4 0 1 test 
2270: 7b 5b 33 20 30 5b 33 5d 5d 7d 0a 63 68 65 63 6b  {[3 0[3]]}.check
2280: 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64 2d 34  _doclist fts3d-4
2290: 2e 33 2e 35 20 30 20 31 20 74 68 69 73 20 7b 5b  .3.5 0 1 this {[
22a0: 33 20 30 5b 30 5d 5d 7d 0a 0a 63 68 65 63 6b 5f  3 0[0]]}..check_
22b0: 74 65 72 6d 73 20 66 74 73 33 64 2d 34 2e 34 20  terms fts3d-4.4 
22c0: 20 20 20 20 20 31 20 30 20 7b 61 20 66 6f 75 72       1 0 {a four
22d0: 20 69 73 20 6f 6e 65 20 74 65 73 74 20 74 68 61   is one test tha
22e0: 74 20 74 68 69 73 20 74 68 72 65 65 20 74 77 6f  t this three two
22f0: 20 77 61 73 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c   was}.check_docl
2300: 69 73 74 20 66 74 73 33 64 2d 34 2e 34 2e 31 20  ist fts3d-4.4.1 
2310: 20 31 20 30 20 61 20 7b 5b 31 20 30 5b 32 5d 5d   1 0 a {[1 0[2]]
2320: 20 5b 32 20 30 5b 32 5d 5d 20 5b 33 20 30 5b 32   [2 0[2]] [3 0[2
2330: 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73  ]]}.check_doclis
2340: 74 20 66 74 73 33 64 2d 34 2e 34 2e 32 20 20 31  t fts3d-4.4.2  1
2350: 20 30 20 66 6f 75 72 20 7b 5b 31 5d 20 5b 32 20   0 four {[1] [2 
2360: 30 5b 34 5d 5d 20 5b 33 20 30 5b 34 5d 5d 7d 0a  0[4]] [3 0[4]]}.
2370: 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74  check_doclist ft
2380: 73 33 64 2d 34 2e 34 2e 33 20 20 31 20 30 20 69  s3d-4.4.3  1 0 i
2390: 73 20 7b 5b 31 20 30 5b 31 5d 5d 20 5b 33 20 30  s {[1 0[1]] [3 0
23a0: 5b 31 5d 5d 7d 0a 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 63  [0]] [3 0[0]]}.c
2480: 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73  heck_doclist fts
2490: 33 64 2d 34 2e 34 2e 38 20 20 31 20 30 20 74 68  3d-4.4.8  1 0 th
24a0: 72 65 65 20 7b 5b 31 5d 20 5b 32 5d 20 5b 33 5d  ree {[1] [2] [3]
24b0: 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20  }.check_doclist 
24c0: 66 74 73 33 64 2d 34 2e 34 2e 39 20 20 31 20 30  fts3d-4.4.9  1 0
24d0: 20 74 77 6f 20 7b 5b 31 5d 20 5b 32 5d 20 5b 33   two {[1] [2] [3
24e0: 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74  ]}.check_doclist
24f0: 20 66 74 73 33 64 2d 34 2e 34 2e 31 30 20 31 20   fts3d-4.4.10 1 
2500: 30 20 77 61 73 20 7b 5b 32 20 30 5b 31 5d 5d 7d  0 was {[2 0[1]]}
2510: 0a 0a 23 20 4f 70 74 69 6d 69 7a 65 20 73 68 6f  ..# Optimize sho
2520: 75 6c 64 20 6c 65 61 76 65 20 74 68 65 20 72 65  uld leave the re
2530: 73 75 6c 74 20 69 6e 20 74 68 65 20 6c 65 76 65  sult in the leve
2540: 6c 20 6f 66 20 74 68 65 20 68 69 67 68 65 73 74  l of the highest
2550: 2d 6c 65 76 65 6c 0a 23 20 70 72 69 6f 72 20 73  -level.# prior s
2560: 65 67 6d 65 6e 74 2e 0a 64 6f 5f 74 65 73 74 20  egment..do_test 
2570: 66 74 73 33 64 2d 34 2e 35 20 7b 0a 20 20 65 78  fts3d-4.5 {.  ex
2580: 65 63 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45  ecsql {.    SELE
2590: 43 54 20 4f 50 54 49 4d 49 5a 45 28 74 31 29 20  CT OPTIMIZE(t1) 
25a0: 46 52 4f 4d 20 74 31 20 4c 49 4d 49 54 20 31 3b  FROM t1 LIMIT 1;
25b0: 0a 20 20 20 20 53 45 4c 45 43 54 20 6c 65 76 65  .    SELECT leve
25c0: 6c 2c 20 69 64 78 20 46 52 4f 4d 20 74 31 5f 73  l, idx FROM t1_s
25d0: 65 67 64 69 72 20 4f 52 44 45 52 20 42 59 20 6c  egdir ORDER BY l
25e0: 65 76 65 6c 2c 20 69 64 78 3b 0a 20 20 7d 0a 7d  evel, idx;.  }.}
25f0: 20 7b 7b 49 6e 64 65 78 20 6f 70 74 69 6d 69 7a   {{Index optimiz
2600: 65 64 7d 20 31 20 30 7d 0a 0a 23 20 49 64 65 6e  ed} 1 0}..# Iden
2610: 74 69 63 61 6c 20 74 6f 20 66 74 73 33 64 2d 34  tical to fts3d-4
2620: 2e 6d 61 74 63 68 65 73 2e 0a 64 6f 5f 74 65 73  .matches..do_tes
2630: 74 20 66 74 73 33 64 2d 34 2e 35 2e 6d 61 74 63  t fts3d-4.5.matc
2640: 68 65 73 20 7b 0a 20 20 65 78 65 63 73 71 6c 20  hes {.  execsql 
2650: 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 4f 46 46  {.    SELECT OFF
2660: 53 45 54 53 28 74 31 29 20 46 52 4f 4d 20 74 31  SETS(t1) FROM t1
2670: 0a 20 20 20 20 20 57 48 45 52 45 20 74 31 20 4d  .     WHERE t1 M
2680: 41 54 43 48 20 27 74 68 69 73 20 4f 52 20 74 68  ATCH 'this OR th
2690: 61 74 20 4f 52 20 77 61 73 20 4f 52 20 61 20 4f  at OR was OR a O
26a0: 52 20 69 73 20 4f 52 20 74 65 73 74 27 20 4f 52  R is OR test' OR
26b0: 44 45 52 20 42 59 20 64 6f 63 69 64 3b 0a 20 20  DER BY docid;.  
26c0: 7d 0a 7d 20 5b 6c 69 73 74 20 7b 30 20 30 20 30  }.} [list {0 0 0
26d0: 20 34 20 30 20 34 20 35 20 32 20 30 20 33 20 38   4 0 4 5 2 0 3 8
26e0: 20 31 20 30 20 35 20 31 30 20 34 7d 20 5c 0a 20   1 0 5 10 4} \. 
26f0: 20 20 20 20 20 20 20 7b 30 20 31 20 30 20 34 20         {0 1 0 4 
2700: 30 20 32 20 35 20 33 20 30 20 33 20 39 20 31 20  0 2 5 3 0 3 9 1 
2710: 30 20 35 20 31 31 20 34 7d 20 5c 0a 20 20 20 20  0 5 11 4} \.    
2720: 20 20 20 20 7b 30 20 30 20 30 20 34 20 30 20 34      {0 0 0 4 0 4
2730: 20 35 20 32 20 30 20 33 20 38 20 31 20 30 20 35   5 2 0 3 8 1 0 5
2740: 20 31 30 20 34 7d 5d 0a 0a 63 68 65 63 6b 5f 74   10 4}]..check_t
2750: 65 72 6d 73 5f 61 6c 6c 20 66 74 73 33 64 2d 34  erms_all fts3d-4
2760: 2e 35 2e 31 20 20 20 20 20 7b 61 20 69 73 20 74  .5.1     {a is t
2770: 65 73 74 20 74 68 61 74 20 74 68 69 73 20 77 61  est that this wa
2780: 73 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74  s}.check_doclist
2790: 5f 61 6c 6c 20 66 74 73 33 64 2d 34 2e 35 2e 31  _all fts3d-4.5.1
27a0: 2e 31 20 61 20 7b 5b 31 20 30 5b 32 5d 5d 20 5b  .1 a {[1 0[2]] [
27b0: 32 20 30 5b 32 5d 5d 20 5b 33 20 30 5b 32 5d 5d  2 0[2]] [3 0[2]]
27c0: 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f  }.check_doclist_
27d0: 61 6c 6c 20 66 74 73 33 64 2d 34 2e 35 2e 31 2e  all fts3d-4.5.1.
27e0: 32 20 69 73 20 7b 5b 31 20 30 5b 31 5d 5d 20 5b  2 is {[1 0[1]] [
27f0: 33 20 30 5b 31 5d 5d 7d 0a 63 68 65 63 6b 5f 64  3 0[1]]}.check_d
2800: 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73 33 64  oclist_all fts3d
2810: 2d 34 2e 35 2e 31 2e 33 20 74 65 73 74 20 7b 5b  -4.5.1.3 test {[
2820: 31 20 30 5b 33 5d 5d 20 5b 32 20 30 5b 33 5d 5d  1 0[3]] [2 0[3]]
2830: 20 5b 33 20 30 5b 33 5d 5d 7d 0a 63 68 65 63 6b   [3 0[3]]}.check
2840: 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73  _doclist_all fts
2850: 33 64 2d 34 2e 35 2e 31 2e 34 20 74 68 61 74 20  3d-4.5.1.4 that 
2860: 7b 5b 32 20 30 5b 30 5d 5d 7d 0a 63 68 65 63 6b  {[2 0[0]]}.check
2870: 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73  _doclist_all fts
2880: 33 64 2d 34 2e 35 2e 31 2e 35 20 74 68 69 73 20  3d-4.5.1.5 this 
2890: 7b 5b 31 20 30 5b 30 5d 5d 20 5b 33 20 30 5b 30  {[1 0[0]] [3 0[0
28a0: 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73  ]]}.check_doclis
28b0: 74 5f 61 6c 6c 20 66 74 73 33 64 2d 34 2e 35 2e  t_all fts3d-4.5.
28c0: 31 2e 36 20 77 61 73 20 7b 5b 32 20 30 5b 31 5d  1.6 was {[2 0[1]
28d0: 5d 7d 0a 0a 63 68 65 63 6b 5f 74 65 72 6d 73 20  ]}..check_terms 
28e0: 66 74 73 33 64 2d 34 2e 35 2e 32 20 20 20 20 20  fts3d-4.5.2     
28f0: 31 20 30 20 7b 61 20 69 73 20 74 65 73 74 20 74  1 0 {a is test t
2900: 68 61 74 20 74 68 69 73 20 77 61 73 7d 0a 63 68  hat this was}.ch
2910: 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33  eck_doclist fts3
2920: 64 2d 34 2e 35 2e 32 2e 31 20 31 20 30 20 61 20  d-4.5.2.1 1 0 a 
2930: 7b 5b 31 20 30 5b 32 5d 5d 20 5b 32 20 30 5b 32  {[1 0[2]] [2 0[2
2940: 5d 5d 20 5b 33 20 30 5b 32 5d 5d 7d 0a 63 68 65  ]] [3 0[2]]}.che
2950: 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64  ck_doclist fts3d
2960: 2d 34 2e 35 2e 32 2e 32 20 31 20 30 20 69 73 20  -4.5.2.2 1 0 is 
2970: 7b 5b 31 20 30 5b 31 5d 5d 20 5b 33 20 30 5b 31  {[1 0[1]] [3 0[1
2980: 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73  ]]}.check_doclis
2990: 74 20 66 74 73 33 64 2d 34 2e 35 2e 32 2e 33 20  t fts3d-4.5.2.3 
29a0: 31 20 30 20 74 65 73 74 20 7b 5b 31 20 30 5b 33  1 0 test {[1 0[3
29b0: 5d 5d 20 5b 32 20 30 5b 33 5d 5d 20 5b 33 20 30  ]] [2 0[3]] [3 0
29c0: 5b 33 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c  [3]]}.check_docl
29d0: 69 73 74 20 66 74 73 33 64 2d 34 2e 35 2e 32 2e  ist fts3d-4.5.2.
29e0: 34 20 31 20 30 20 74 68 61 74 20 7b 5b 32 20 30  4 1 0 that {[2 0
29f0: 5b 30 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c  [0]]}.check_docl
2a00: 69 73 74 20 66 74 73 33 64 2d 34 2e 35 2e 32 2e  ist fts3d-4.5.2.
2a10: 35 20 31 20 30 20 74 68 69 73 20 7b 5b 31 20 30  5 1 0 this {[1 0
2a20: 5b 30 5d 5d 20 5b 33 20 30 5b 30 5d 5d 7d 0a 63  [0]] [3 0[0]]}.c
2a30: 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73  heck_doclist fts
2a40: 33 64 2d 34 2e 35 2e 32 2e 36 20 31 20 30 20 77  3d-4.5.2.6 1 0 w
2a50: 61 73 20 7b 5b 32 20 30 5b 31 5d 5d 7d 0a 0a 23  as {[2 0[1]]}..#
2a60: 20 52 65 2d 6f 70 74 69 6d 69 7a 69 6e 67 20 64   Re-optimizing d
2a70: 6f 65 73 20 6e 6f 74 68 69 6e 67 2e 0a 64 6f 5f  oes nothing..do_
2a80: 74 65 73 74 20 66 74 73 33 64 2d 35 2e 30 20 7b  test fts3d-5.0 {
2a90: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
2aa0: 20 53 45 4c 45 43 54 20 4f 50 54 49 4d 49 5a 45   SELECT OPTIMIZE
2ab0: 28 74 31 29 20 46 52 4f 4d 20 74 31 20 4c 49 4d  (t1) FROM t1 LIM
2ac0: 49 54 20 31 3b 0a 20 20 20 20 53 45 4c 45 43 54  IT 1;.    SELECT
2ad0: 20 6c 65 76 65 6c 2c 20 69 64 78 20 46 52 4f 4d   level, idx FROM
2ae0: 20 74 31 5f 73 65 67 64 69 72 20 4f 52 44 45 52   t1_segdir ORDER
2af0: 20 42 59 20 6c 65 76 65 6c 2c 20 69 64 78 3b 0a   BY level, idx;.
2b00: 20 20 7d 0a 7d 20 7b 7b 49 6e 64 65 78 20 61 6c    }.} {{Index al
2b10: 72 65 61 64 79 20 6f 70 74 69 6d 61 6c 7d 20 31  ready optimal} 1
2b20: 20 30 7d 0a 0a 23 20 45 76 65 6e 20 69 66 20 77   0}..# Even if w
2b30: 65 20 6d 6f 76 65 20 74 68 69 6e 67 73 20 61 72  e move things ar
2b40: 6f 75 6e 64 2c 20 73 74 69 6c 6c 20 64 6f 65 73  ound, still does
2b50: 20 6e 6f 74 68 69 6e 67 2e 0a 64 6f 5f 74 65 73   nothing..do_tes
2b60: 74 20 66 74 73 33 64 2d 35 2e 31 20 7b 0a 20 20  t fts3d-5.1 {.  
2b70: 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 55 50  execsql {.    UP
2b80: 44 41 54 45 20 74 31 5f 73 65 67 64 69 72 20 53  DATE t1_segdir S
2b90: 45 54 20 6c 65 76 65 6c 20 3d 20 32 20 57 48 45  ET level = 2 WHE
2ba0: 52 45 20 6c 65 76 65 6c 20 3d 20 31 20 41 4e 44  RE level = 1 AND
2bb0: 20 69 64 78 20 3d 20 30 3b 0a 20 20 20 20 53 45   idx = 0;.    SE
2bc0: 4c 45 43 54 20 4f 50 54 49 4d 49 5a 45 28 74 31  LECT OPTIMIZE(t1
2bd0: 29 20 46 52 4f 4d 20 74 31 20 4c 49 4d 49 54 20  ) FROM t1 LIMIT 
2be0: 31 3b 0a 20 20 20 20 53 45 4c 45 43 54 20 6c 65  1;.    SELECT le
2bf0: 76 65 6c 2c 20 69 64 78 20 46 52 4f 4d 20 74 31  vel, idx FROM t1
2c00: 5f 73 65 67 64 69 72 20 4f 52 44 45 52 20 42 59  _segdir ORDER BY
2c10: 20 6c 65 76 65 6c 2c 20 69 64 78 3b 0a 20 20 7d   level, idx;.  }
2c20: 0a 7d 20 7b 7b 49 6e 64 65 78 20 61 6c 72 65 61  .} {{Index alrea
2c30: 64 79 20 6f 70 74 69 6d 61 6c 7d 20 32 20 30 7d  dy optimal} 2 0}
2c40: 0a 0a 0a 23 20 41 4c 54 45 52 20 54 41 42 4c 45  ...# ALTER TABLE
2c50: 20 52 45 4e 41 4d 45 20 73 68 6f 75 6c 64 20 77   RENAME should w
2c60: 6f 72 6b 20 72 65 67 61 72 64 6c 65 73 73 20 6f  ork regardless o
2c70: 66 20 74 68 65 20 64 61 74 61 62 61 73 65 20 65  f the database e
2c80: 6e 63 6f 64 69 6e 67 2e 0a 23 0a 64 6f 5f 74 65  ncoding..#.do_te
2c90: 73 74 20 66 74 73 33 64 2d 36 2e 30 20 7b 0a 20  st fts3d-6.0 {. 
2ca0: 20 64 62 20 63 6c 6f 73 65 0a 20 20 66 6f 72 63   db close.  forc
2cb0: 65 64 65 6c 65 74 65 20 74 65 73 74 2e 64 62 0a  edelete test.db.
2cc0: 20 20 73 71 6c 69 74 65 33 20 64 62 20 74 65 73    sqlite3 db tes
2cd0: 74 2e 64 62 0a 20 20 64 62 20 65 76 61 6c 20 7b  t.db.  db eval {
2ce0: 0a 20 20 20 20 50 52 41 47 4d 41 20 65 6e 63 6f  .    PRAGMA enco
2cf0: 64 69 6e 67 3d 55 54 46 38 3b 0a 20 20 20 20 43  ding=UTF8;.    C
2d00: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
2d10: 42 4c 45 20 66 74 73 20 55 53 49 4e 47 20 66 74  BLE fts USING ft
2d20: 73 33 28 61 2c 62 2c 63 29 3b 0a 20 20 20 20 53  s3(a,b,c);.    S
2d30: 45 4c 45 43 54 20 6e 61 6d 65 20 46 52 4f 4d 20  ELECT name FROM 
2d40: 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 20 57 48  sqlite_master WH
2d50: 45 52 45 20 6e 61 6d 65 20 47 4c 4f 42 20 27 3f  ERE name GLOB '?
2d60: 3f 3f 5f 2a 27 20 4f 52 44 45 52 20 42 59 20 31  ??_*' ORDER BY 1
2d70: 3b 0a 20 20 7d 0a 7d 20 7b 66 74 73 5f 63 6f 6e  ;.  }.} {fts_con
2d80: 74 65 6e 74 20 66 74 73 5f 73 65 67 64 69 72 20  tent fts_segdir 
2d90: 66 74 73 5f 73 65 67 6d 65 6e 74 73 7d 0a 64 6f  fts_segments}.do
2da0: 5f 74 65 73 74 20 66 74 73 33 64 2d 36 2e 31 20  _test fts3d-6.1 
2db0: 7b 0a 20 20 64 62 20 65 76 61 6c 20 7b 0a 20 20  {.  db eval {.  
2dc0: 20 20 41 4c 54 45 52 20 54 41 42 4c 45 20 66 74    ALTER TABLE ft
2dd0: 73 20 52 45 4e 41 4d 45 20 54 4f 20 78 79 7a 3b  s RENAME TO xyz;
2de0: 0a 20 20 20 20 53 45 4c 45 43 54 20 6e 61 6d 65  .    SELECT name
2df0: 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d 61 73   FROM sqlite_mas
2e00: 74 65 72 20 57 48 45 52 45 20 6e 61 6d 65 20 47  ter WHERE name G
2e10: 4c 4f 42 20 27 3f 3f 3f 5f 2a 27 20 4f 52 44 45  LOB '???_*' ORDE
2e20: 52 20 42 59 20 31 3b 0a 20 20 7d 0a 7d 20 7b 78  R BY 1;.  }.} {x
2e30: 79 7a 5f 63 6f 6e 74 65 6e 74 20 78 79 7a 5f 73  yz_content xyz_s
2e40: 65 67 64 69 72 20 78 79 7a 5f 73 65 67 6d 65 6e  egdir xyz_segmen
2e50: 74 73 7d 0a 64 6f 5f 74 65 73 74 20 66 74 73 33  ts}.do_test fts3
2e60: 64 2d 36 2e 32 20 7b 0a 20 20 64 62 20 63 6c 6f  d-6.2 {.  db clo
2e70: 73 65 0a 20 20 66 6f 72 63 65 64 65 6c 65 74 65  se.  forcedelete
2e80: 20 74 65 73 74 2e 64 62 0a 20 20 73 71 6c 69 74   test.db.  sqlit
2e90: 65 33 20 64 62 20 74 65 73 74 2e 64 62 0a 20 20  e3 db test.db.  
2ea0: 64 62 20 65 76 61 6c 20 7b 0a 20 20 20 20 50 52  db eval {.    PR
2eb0: 41 47 4d 41 20 65 6e 63 6f 64 69 6e 67 3d 55 54  AGMA encoding=UT
2ec0: 46 31 36 6c 65 3b 0a 20 20 20 20 43 52 45 41 54  F16le;.    CREAT
2ed0: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20  E VIRTUAL TABLE 
2ee0: 66 74 73 20 55 53 49 4e 47 20 66 74 73 33 28 61  fts USING fts3(a
2ef0: 2c 62 2c 63 29 3b 0a 20 20 20 20 53 45 4c 45 43  ,b,c);.    SELEC
2f00: 54 20 6e 61 6d 65 20 46 52 4f 4d 20 73 71 6c 69  T name FROM sqli
2f10: 74 65 5f 6d 61 73 74 65 72 20 57 48 45 52 45 20  te_master WHERE 
2f20: 6e 61 6d 65 20 47 4c 4f 42 20 27 3f 3f 3f 5f 2a  name GLOB '???_*
2f30: 27 20 4f 52 44 45 52 20 42 59 20 31 3b 0a 20 20  ' ORDER BY 1;.  
2f40: 7d 0a 7d 20 7b 66 74 73 5f 63 6f 6e 74 65 6e 74  }.} {fts_content
2f50: 20 66 74 73 5f 73 65 67 64 69 72 20 66 74 73 5f   fts_segdir fts_
2f60: 73 65 67 6d 65 6e 74 73 7d 0a 64 6f 5f 74 65 73  segments}.do_tes
2f70: 74 20 66 74 73 33 64 2d 36 2e 33 20 7b 0a 20 20  t fts3d-6.3 {.  
2f80: 64 62 20 65 76 61 6c 20 7b 0a 20 20 20 20 41 4c  db eval {.    AL
2f90: 54 45 52 20 54 41 42 4c 45 20 66 74 73 20 52 45  TER TABLE fts RE
2fa0: 4e 41 4d 45 20 54 4f 20 78 79 7a 3b 0a 20 20 20  NAME TO xyz;.   
2fb0: 20 53 45 4c 45 43 54 20 6e 61 6d 65 20 46 52 4f   SELECT name FRO
2fc0: 4d 20 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 20  M sqlite_master 
2fd0: 57 48 45 52 45 20 6e 61 6d 65 20 47 4c 4f 42 20  WHERE name GLOB 
2fe0: 27 3f 3f 3f 5f 2a 27 20 4f 52 44 45 52 20 42 59  '???_*' ORDER BY
2ff0: 20 31 3b 0a 20 20 7d 0a 7d 20 7b 78 79 7a 5f 63   1;.  }.} {xyz_c
3000: 6f 6e 74 65 6e 74 20 78 79 7a 5f 73 65 67 64 69  ontent xyz_segdi
3010: 72 20 78 79 7a 5f 73 65 67 6d 65 6e 74 73 7d 0a  r xyz_segments}.
3020: 64 6f 5f 74 65 73 74 20 66 74 73 33 64 2d 36 2e  do_test fts3d-6.
3030: 34 20 7b 0a 20 20 64 62 20 63 6c 6f 73 65 0a 20  4 {.  db close. 
3040: 20 66 6f 72 63 65 64 65 6c 65 74 65 20 74 65 73   forcedelete tes
3050: 74 2e 64 62 0a 20 20 73 71 6c 69 74 65 33 20 64  t.db.  sqlite3 d
3060: 62 20 74 65 73 74 2e 64 62 0a 20 20 64 62 20 65  b test.db.  db e
3070: 76 61 6c 20 7b 0a 20 20 20 20 50 52 41 47 4d 41  val {.    PRAGMA
3080: 20 65 6e 63 6f 64 69 6e 67 3d 55 54 46 31 36 62   encoding=UTF16b
3090: 65 3b 0a 20 20 20 20 43 52 45 41 54 45 20 56 49  e;.    CREATE VI
30a0: 52 54 55 41 4c 20 54 41 42 4c 45 20 66 74 73 20  RTUAL TABLE fts 
30b0: 55 53 49 4e 47 20 66 74 73 33 28 61 2c 62 2c 63  USING fts3(a,b,c
30c0: 29 3b 0a 20 20 20 20 53 45 4c 45 43 54 20 6e 61  );.    SELECT na
30d0: 6d 65 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d  me FROM sqlite_m
30e0: 61 73 74 65 72 20 57 48 45 52 45 20 6e 61 6d 65  aster WHERE name
30f0: 20 47 4c 4f 42 20 27 3f 3f 3f 5f 2a 27 20 4f 52   GLOB '???_*' OR
3100: 44 45 52 20 42 59 20 31 3b 0a 20 20 7d 0a 7d 20  DER BY 1;.  }.} 
3110: 7b 66 74 73 5f 63 6f 6e 74 65 6e 74 20 66 74 73  {fts_content fts
3120: 5f 73 65 67 64 69 72 20 66 74 73 5f 73 65 67 6d  _segdir fts_segm
3130: 65 6e 74 73 7d 0a 64 6f 5f 74 65 73 74 20 66 74  ents}.do_test ft
3140: 73 33 64 2d 36 2e 35 20 7b 0a 20 20 64 62 20 65  s3d-6.5 {.  db e
3150: 76 61 6c 20 7b 0a 20 20 20 20 41 4c 54 45 52 20  val {.    ALTER 
3160: 54 41 42 4c 45 20 66 74 73 20 52 45 4e 41 4d 45  TABLE fts RENAME
3170: 20 54 4f 20 78 79 7a 3b 0a 20 20 20 20 53 45 4c   TO xyz;.    SEL
3180: 45 43 54 20 6e 61 6d 65 20 46 52 4f 4d 20 73 71  ECT name FROM sq
3190: 6c 69 74 65 5f 6d 61 73 74 65 72 20 57 48 45 52  lite_master WHER
31a0: 45 20 6e 61 6d 65 20 47 4c 4f 42 20 27 3f 3f 3f  E name GLOB '???
31b0: 5f 2a 27 20 4f 52 44 45 52 20 42 59 20 31 3b 0a  _*' ORDER BY 1;.
31c0: 20 20 7d 0a 7d 20 7b 78 79 7a 5f 63 6f 6e 74 65    }.} {xyz_conte
31d0: 6e 74 20 78 79 7a 5f 73 65 67 64 69 72 20 78 79  nt xyz_segdir xy
31e0: 7a 5f 73 65 67 6d 65 6e 74 73 7d 0a 20 0a 0a 66  z_segments}. ..f
31f0: 69 6e 69 73 68 5f 74 65 73 74 0a                 inish_test.