/ Hex Artifact Content
Login

Artifact d92a47fe8ed59c9e53d2d8e6d2685bb380aadadc:


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 23 20 24 49 64 3a 20 66 74 73 33 64 2e  .#.# $Id: fts3d.
0200: 74 65 73 74 2c 76 20 31 2e 32 20 32 30 30 38 2f  test,v 1.2 2008/
0210: 30 37 2f 31 35 20 32 31 3a 33 32 3a 30 37 20 73  07/15 21:32:07 s
0220: 68 65 73 73 20 45 78 70 20 24 0a 23 0a 0a 73 65  hess Exp $.#..se
0230: 74 20 74 65 73 74 64 69 72 20 5b 66 69 6c 65 20  t testdir [file 
0240: 64 69 72 6e 61 6d 65 20 24 61 72 67 76 30 5d 0a  dirname $argv0].
0250: 73 6f 75 72 63 65 20 24 74 65 73 74 64 69 72 2f  source $testdir/
0260: 74 65 73 74 65 72 2e 74 63 6c 0a 0a 23 20 49 66  tester.tcl..# If
0270: 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46   SQLITE_ENABLE_F
0280: 54 53 33 20 69 73 20 6e 6f 74 20 64 65 66 69 6e  TS3 is not defin
0290: 65 64 2c 20 6f 6d 69 74 20 74 68 69 73 20 66 69  ed, omit this fi
02a0: 6c 65 2e 0a 69 66 63 61 70 61 62 6c 65 20 21 66  le..ifcapable !f
02b0: 74 73 33 20 7b 0a 20 20 66 69 6e 69 73 68 5f 74  ts3 {.  finish_t
02c0: 65 73 74 0a 20 20 72 65 74 75 72 6e 0a 7d 0a 0a  est.  return.}..
02d0: 23 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: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0310: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 23 20 50 72 6f  **********.# Pro
0320: 62 65 20 74 6f 20 73 65 65 20 69 66 20 73 75 70  be to see if sup
0330: 70 6f 72 74 20 66 6f 72 20 74 68 65 20 46 54 53  port for the FTS
0340: 33 20 64 75 6d 70 5f 2a 20 66 75 6e 63 74 69 6f  3 dump_* functio
0350: 6e 73 20 69 73 20 63 6f 6d 70 69 6c 65 64 20 69  ns is compiled i
0360: 6e 2e 0a 23 20 54 4f 44 4f 28 73 68 65 73 73 29  n..# TODO(shess)
0370: 3a 20 43 68 61 6e 67 65 20 6d 61 69 6e 2e 6d 6b  : Change main.mk
0380: 20 74 6f 20 64 6f 20 74 68 65 20 72 69 67 68 74   to do the right
0390: 20 74 68 69 6e 67 20 61 6e 64 20 72 65 6d 6f 76   thing and remov
03a0: 65 20 74 68 69 73 20 74 65 73 74 2e 0a 64 62 20  e this test..db 
03b0: 65 76 61 6c 20 7b 0a 20 20 44 52 4f 50 20 54 41  eval {.  DROP TA
03c0: 42 4c 45 20 49 46 20 45 58 49 53 54 53 20 74 31  BLE IF EXISTS t1
03d0: 3b 0a 20 20 43 52 45 41 54 45 20 56 49 52 54 55  ;.  CREATE VIRTU
03e0: 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49 4e  AL TABLE t1 USIN
03f0: 47 20 66 74 73 33 28 63 29 3b 0a 20 20 49 4e 53  G fts3(c);.  INS
0400: 45 52 54 20 49 4e 54 4f 20 74 31 20 28 64 6f 63  ERT INTO t1 (doc
0410: 69 64 2c 20 63 29 20 56 41 4c 55 45 53 20 28 31  id, c) VALUES (1
0420: 2c 20 27 78 27 29 3b 0a 7d 0a 0a 73 65 74 20 73  , 'x');.}..set s
0430: 20 7b 53 45 4c 45 43 54 20 64 75 6d 70 5f 74 65   {SELECT dump_te
0440: 72 6d 73 28 74 31 2c 20 31 29 20 46 52 4f 4d 20  rms(t1, 1) FROM 
0450: 74 31 20 4c 49 4d 49 54 20 31 7d 0a 73 65 74 20  t1 LIMIT 1}.set 
0460: 72 20 7b 31 20 7b 75 6e 61 62 6c 65 20 74 6f 20  r {1 {unable to 
0470: 75 73 65 20 66 75 6e 63 74 69 6f 6e 20 64 75 6d  use function dum
0480: 70 5f 74 65 72 6d 73 20 69 6e 20 74 68 65 20 72  p_terms in the r
0490: 65 71 75 65 73 74 65 64 20 63 6f 6e 74 65 78 74  equested context
04a0: 7d 7d 0a 69 66 20 7b 5b 63 61 74 63 68 73 71 6c  }}.if {[catchsql
04b0: 20 24 73 5d 3d 3d 24 72 7d 20 7b 0a 20 20 66 69   $s]==$r} {.  fi
04c0: 6e 69 73 68 5f 74 65 73 74 0a 20 20 72 65 74 75  nish_test.  retu
04d0: 72 6e 0a 7d 0a 0a 23 2a 2a 2a 2a 2a 2a 2a 2a 2a  rn.}..#*********
04e0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
04f0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0500: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0510: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0520: 0a 23 20 55 74 69 6c 69 74 79 20 66 75 6e 63 74  .# Utility funct
0530: 69 6f 6e 20 74 6f 20 63 68 65 63 6b 20 66 6f 72  ion to check for
0540: 20 74 68 65 20 65 78 70 65 63 74 65 64 20 74 65   the expected te
0550: 72 6d 73 20 69 6e 20 74 68 65 20 73 65 67 6d 65  rms in the segme
0560: 6e 74 0a 23 20 6c 65 76 65 6c 2f 69 6e 64 65 78  nt.# level/index
0570: 2e 20 20 5f 61 6c 6c 20 76 65 72 73 69 6f 6e 20  .  _all version 
0580: 64 6f 65 73 20 73 61 6d 65 20 62 75 74 20 66 6f  does same but fo
0590: 72 20 65 6e 74 69 72 65 20 69 6e 64 65 78 2e 0a  r entire index..
05a0: 70 72 6f 63 20 63 68 65 63 6b 5f 74 65 72 6d 73  proc check_terms
05b0: 20 7b 74 65 73 74 20 6c 65 76 65 6c 20 69 6e 64   {test level ind
05c0: 65 78 20 74 65 72 6d 73 7d 20 7b 0a 20 20 23 20  ex terms} {.  # 
05d0: 54 4f 44 4f 28 73 68 65 73 73 29 3a 20 46 69 67  TODO(shess): Fig
05e0: 75 72 65 20 6f 75 74 20 77 68 79 20 75 70 6c 65  ure out why uple
05f0: 76 65 6c 20 69 6e 20 64 6f 5f 74 65 73 74 20 63  vel in do_test c
0600: 61 6e 27 74 20 63 61 74 63 68 0a 20 20 23 20 24  an't catch.  # $
0610: 6c 65 76 65 6c 20 61 6e 64 20 24 69 6e 64 65 78  level and $index
0620: 20 64 69 72 65 63 74 6c 79 2e 0a 20 20 73 65 74   directly..  set
0630: 20 3a 3a 6c 65 76 65 6c 20 24 6c 65 76 65 6c 0a   ::level $level.
0640: 20 20 73 65 74 20 3a 3a 69 6e 64 65 78 20 24 69    set ::index $i
0650: 6e 64 65 78 0a 20 20 64 6f 5f 74 65 73 74 20 24  ndex.  do_test $
0660: 74 65 73 74 2e 74 65 72 6d 73 20 7b 0a 20 20 20  test.terms {.   
0670: 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 20   execsql {.     
0680: 20 53 45 4c 45 43 54 20 64 75 6d 70 5f 74 65 72   SELECT dump_ter
0690: 6d 73 28 74 31 2c 20 24 3a 3a 6c 65 76 65 6c 2c  ms(t1, $::level,
06a0: 20 24 3a 3a 69 6e 64 65 78 29 20 46 52 4f 4d 20   $::index) FROM 
06b0: 74 31 20 4c 49 4d 49 54 20 31 3b 0a 20 20 20 20  t1 LIMIT 1;.    
06c0: 7d 0a 20 20 7d 20 5b 6c 69 73 74 20 24 74 65 72  }.  } [list $ter
06d0: 6d 73 5d 0a 7d 0a 70 72 6f 63 20 63 68 65 63 6b  ms].}.proc check
06e0: 5f 74 65 72 6d 73 5f 61 6c 6c 20 7b 74 65 73 74  _terms_all {test
06f0: 20 74 65 72 6d 73 7d 20 7b 0a 20 20 64 6f 5f 74   terms} {.  do_t
0700: 65 73 74 20 24 74 65 73 74 2e 74 65 72 6d 73 20  est $test.terms 
0710: 7b 0a 20 20 20 20 65 78 65 63 73 71 6c 20 7b 0a  {.    execsql {.
0720: 20 20 20 20 20 20 53 45 4c 45 43 54 20 64 75 6d        SELECT dum
0730: 70 5f 74 65 72 6d 73 28 74 31 29 20 46 52 4f 4d  p_terms(t1) FROM
0740: 20 74 31 20 4c 49 4d 49 54 20 31 3b 0a 20 20 20   t1 LIMIT 1;.   
0750: 20 7d 0a 20 20 7d 20 5b 6c 69 73 74 20 24 74 65   }.  } [list $te
0760: 72 6d 73 5d 0a 7d 0a 0a 23 20 55 74 69 6c 69 74  rms].}..# Utilit
0770: 79 20 66 75 6e 63 74 69 6f 6e 20 74 6f 20 63 68  y function to ch
0780: 65 63 6b 20 66 6f 72 20 74 68 65 20 65 78 70 65  eck for the expe
0790: 63 74 65 64 20 64 6f 63 6c 69 73 74 20 66 6f 72  cted doclist for
07a0: 20 74 68 65 20 74 65 72 6d 20 69 6e 0a 23 20 73   the term in.# s
07b0: 65 67 6d 65 6e 74 20 6c 65 76 65 6c 2f 69 6e 64  egment level/ind
07c0: 65 78 2e 20 20 5f 61 6c 6c 20 76 65 72 73 69 6f  ex.  _all versio
07d0: 6e 20 64 6f 65 73 20 73 61 6d 65 20 66 6f 72 20  n does same for 
07e0: 65 6e 74 69 72 65 20 69 6e 64 65 78 2e 0a 70 72  entire index..pr
07f0: 6f 63 20 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74  oc check_doclist
0800: 20 7b 74 65 73 74 20 6c 65 76 65 6c 20 69 6e 64   {test level ind
0810: 65 78 20 74 65 72 6d 20 64 6f 63 6c 69 73 74 7d  ex term doclist}
0820: 20 7b 0a 20 20 23 20 54 4f 44 4f 28 73 68 65 73   {.  # TODO(shes
0830: 73 29 3a 20 41 67 61 69 6e 2c 20 77 68 79 20 63  s): Again, why c
0840: 61 6e 27 74 20 74 68 65 20 6e 6f 6e 2d 3a 3a 20  an't the non-:: 
0850: 76 65 72 73 69 6f 6e 73 20 77 6f 72 6b 3f 0a 20  versions work?. 
0860: 20 73 65 74 20 3a 3a 74 65 72 6d 20 24 74 65 72   set ::term $ter
0870: 6d 0a 20 20 73 65 74 20 3a 3a 6c 65 76 65 6c 20  m.  set ::level 
0880: 24 6c 65 76 65 6c 0a 20 20 73 65 74 20 3a 3a 69  $level.  set ::i
0890: 6e 64 65 78 20 24 69 6e 64 65 78 0a 20 20 64 6f  ndex $index.  do
08a0: 5f 74 65 73 74 20 24 74 65 73 74 20 7b 0a 20 20  _test $test {.  
08b0: 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20    execsql {.    
08c0: 20 20 53 45 4c 45 43 54 20 64 75 6d 70 5f 64 6f    SELECT dump_do
08d0: 63 6c 69 73 74 28 74 31 2c 20 24 3a 3a 74 65 72  clist(t1, $::ter
08e0: 6d 2c 20 24 3a 3a 6c 65 76 65 6c 2c 20 24 3a 3a  m, $::level, $::
08f0: 69 6e 64 65 78 29 20 46 52 4f 4d 20 74 31 20 4c  index) FROM t1 L
0900: 49 4d 49 54 20 31 3b 0a 20 20 20 20 7d 0a 20 20  IMIT 1;.    }.  
0910: 7d 20 5b 6c 69 73 74 20 24 64 6f 63 6c 69 73 74  } [list $doclist
0920: 5d 0a 7d 0a 70 72 6f 63 20 63 68 65 63 6b 5f 64  ].}.proc check_d
0930: 6f 63 6c 69 73 74 5f 61 6c 6c 20 7b 74 65 73 74  oclist_all {test
0940: 20 74 65 72 6d 20 64 6f 63 6c 69 73 74 7d 20 7b   term doclist} {
0950: 0a 20 20 73 65 74 20 3a 3a 74 65 72 6d 20 24 74  .  set ::term $t
0960: 65 72 6d 0a 20 20 64 6f 5f 74 65 73 74 20 24 74  erm.  do_test $t
0970: 65 73 74 20 7b 0a 20 20 20 20 65 78 65 63 73 71  est {.    execsq
0980: 6c 20 7b 0a 20 20 20 20 20 20 53 45 4c 45 43 54  l {.      SELECT
0990: 20 64 75 6d 70 5f 64 6f 63 6c 69 73 74 28 74 31   dump_doclist(t1
09a0: 2c 20 24 3a 3a 74 65 72 6d 29 20 46 52 4f 4d 20  , $::term) FROM 
09b0: 74 31 20 4c 49 4d 49 54 20 31 3b 0a 20 20 20 20  t1 LIMIT 1;.    
09c0: 7d 0a 20 20 7d 20 5b 6c 69 73 74 20 24 64 6f 63  }.  } [list $doc
09d0: 6c 69 73 74 5d 0a 7d 0a 0a 23 2a 2a 2a 2a 2a 2a  list].}..#******
09e0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
09f0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0a00: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0a10: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0a20: 2a 2a 2a 0a 23 20 54 65 73 74 20 72 65 73 75 6c  ***.# Test resul
0a30: 74 73 20 77 68 65 6e 20 61 6c 6c 20 72 6f 77 73  ts when all rows
0a40: 20 61 72 65 20 64 65 6c 65 74 65 64 20 61 6e 64   are deleted and
0a50: 20 6f 6e 65 20 69 73 20 61 64 64 65 64 20 62 61   one is added ba
0a60: 63 6b 2e 0a 23 20 50 72 65 76 69 6f 75 73 6c 79  ck..# Previously
0a70: 20 6f 6c 64 65 72 20 73 65 67 6d 65 6e 74 73 20   older segments 
0a80: 77 6f 75 6c 64 20 63 6f 6e 74 69 6e 75 65 20 74  would continue t
0a90: 6f 20 65 78 69 73 74 2c 20 62 75 74 20 6e 6f 77  o exist, but now
0aa0: 20 74 68 65 20 69 6e 64 65 78 0a 23 20 73 68 6f   the index.# sho
0ab0: 75 6c 64 20 62 65 20 64 72 6f 70 70 65 64 20 77  uld be dropped w
0ac0: 68 65 6e 20 74 68 65 20 74 61 62 6c 65 20 69 73  hen the table is
0ad0: 20 65 6d 70 74 79 2e 20 20 54 68 65 20 72 65 73   empty.  The res
0ae0: 75 6c 74 73 20 73 68 6f 75 6c 64 20 6c 6f 6f 6b  ults should look
0af0: 0a 23 20 65 78 61 63 74 6c 79 20 6c 69 6b 65 20  .# exactly like 
0b00: 77 65 20 6e 65 76 65 72 20 61 64 64 65 64 20 74  we never added t
0b10: 68 65 20 65 61 72 6c 69 65 72 20 72 6f 77 73 20  he earlier rows 
0b20: 69 6e 20 74 68 65 20 66 69 72 73 74 20 70 6c 61  in the first pla
0b30: 63 65 2e 0a 64 62 20 65 76 61 6c 20 7b 0a 20 20  ce..db eval {.  
0b40: 44 52 4f 50 20 54 41 42 4c 45 20 49 46 20 45 58  DROP TABLE IF EX
0b50: 49 53 54 53 20 74 31 3b 0a 20 20 43 52 45 41 54  ISTS t1;.  CREAT
0b60: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20  E VIRTUAL TABLE 
0b70: 74 31 20 55 53 49 4e 47 20 66 74 73 33 28 63 29  t1 USING fts3(c)
0b80: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
0b90: 74 31 20 28 64 6f 63 69 64 2c 20 63 29 20 56 41  t1 (docid, c) VA
0ba0: 4c 55 45 53 20 28 31 2c 20 27 54 68 69 73 20 69  LUES (1, 'This i
0bb0: 73 20 61 20 74 65 73 74 27 29 3b 0a 20 20 49 4e  s a test');.  IN
0bc0: 53 45 52 54 20 49 4e 54 4f 20 74 31 20 28 64 6f  SERT INTO t1 (do
0bd0: 63 69 64 2c 20 63 29 20 56 41 4c 55 45 53 20 28  cid, c) VALUES (
0be0: 32 2c 20 27 54 68 61 74 20 77 61 73 20 61 20 74  2, 'That was a t
0bf0: 65 73 74 27 29 3b 0a 20 20 49 4e 53 45 52 54 20  est');.  INSERT 
0c00: 49 4e 54 4f 20 74 31 20 28 64 6f 63 69 64 2c 20  INTO t1 (docid, 
0c10: 63 29 20 56 41 4c 55 45 53 20 28 33 2c 20 27 54  c) VALUES (3, 'T
0c20: 68 69 73 20 69 73 20 61 20 74 65 73 74 27 29 3b  his is a test');
0c30: 0a 20 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 74  .  DELETE FROM t
0c40: 31 20 57 48 45 52 45 20 31 3d 31 3b 20 2d 2d 20  1 WHERE 1=1; -- 
0c50: 44 65 6c 65 74 65 20 65 61 63 68 20 72 6f 77 20  Delete each row 
0c60: 72 61 74 68 65 72 20 74 68 61 6e 20 64 72 6f 70  rather than drop
0c70: 70 69 6e 67 20 74 61 62 6c 65 2e 0a 20 20 49 4e  ping table..  IN
0c80: 53 45 52 54 20 49 4e 54 4f 20 74 31 20 28 64 6f  SERT INTO t1 (do
0c90: 63 69 64 2c 20 63 29 20 56 41 4c 55 45 53 20 28  cid, c) VALUES (
0ca0: 31 2c 20 27 54 68 69 73 20 69 73 20 61 20 74 65  1, 'This is a te
0cb0: 73 74 27 29 3b 0a 7d 0a 0a 23 20 53 68 6f 75 6c  st');.}..# Shoul
0cc0: 64 20 62 65 20 61 20 73 69 6e 67 6c 65 20 69 6e  d be a single in
0cd0: 69 74 69 61 6c 20 73 65 67 6d 65 6e 74 2e 0a 64  itial segment..d
0ce0: 6f 5f 74 65 73 74 20 66 74 73 33 64 2d 31 2e 73  o_test fts3d-1.s
0cf0: 65 67 6d 65 6e 74 73 20 7b 0a 20 20 65 78 65 63  egments {.  exec
0d00: 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54  sql {.    SELECT
0d10: 20 6c 65 76 65 6c 2c 20 69 64 78 20 46 52 4f 4d   level, idx FROM
0d20: 20 74 31 5f 73 65 67 64 69 72 20 4f 52 44 45 52   t1_segdir ORDER
0d30: 20 42 59 20 6c 65 76 65 6c 2c 20 69 64 78 3b 0a   BY level, idx;.
0d40: 20 20 7d 0a 7d 20 7b 30 20 30 7d 0a 64 6f 5f 74    }.} {0 0}.do_t
0d50: 65 73 74 20 66 74 73 33 64 2d 31 2e 6d 61 74 63  est fts3d-1.matc
0d60: 68 65 73 20 7b 0a 20 20 65 78 65 63 73 71 6c 20  hes {.  execsql 
0d70: 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 4f 46 46  {.    SELECT OFF
0d80: 53 45 54 53 28 74 31 29 20 46 52 4f 4d 20 74 31  SETS(t1) FROM t1
0d90: 0a 20 20 20 20 20 57 48 45 52 45 20 74 31 20 4d  .     WHERE t1 M
0da0: 41 54 43 48 20 27 74 68 69 73 20 4f 52 20 74 68  ATCH 'this OR th
0db0: 61 74 20 4f 52 20 77 61 73 20 4f 52 20 61 20 4f  at OR was OR a O
0dc0: 52 20 69 73 20 4f 52 20 74 65 73 74 27 20 4f 52  R is OR test' OR
0dd0: 44 45 52 20 42 59 20 64 6f 63 69 64 3b 0a 20 20  DER BY docid;.  
0de0: 7d 0a 7d 20 7b 7b 30 20 30 20 30 20 34 20 30 20  }.} {{0 0 0 4 0 
0df0: 34 20 35 20 32 20 30 20 33 20 38 20 31 20 30 20  4 5 2 0 3 8 1 0 
0e00: 35 20 31 30 20 34 7d 7d 0a 0a 63 68 65 63 6b 5f  5 10 4}}..check_
0e10: 74 65 72 6d 73 5f 61 6c 6c 20 66 74 73 33 64 2d  terms_all fts3d-
0e20: 31 2e 31 20 7b 61 20 69 73 20 74 65 73 74 20 74  1.1 {a is test t
0e30: 68 69 73 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69  his}.check_docli
0e40: 73 74 5f 61 6c 6c 20 66 74 73 33 64 2d 31 2e 31  st_all fts3d-1.1
0e50: 2e 31 20 61 20 7b 5b 31 20 30 5b 32 5d 5d 7d 0a  .1 a {[1 0[2]]}.
0e60: 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c  check_doclist_al
0e70: 6c 20 66 74 73 33 64 2d 31 2e 31 2e 32 20 69 73  l fts3d-1.1.2 is
0e80: 20 7b 5b 31 20 30 5b 31 5d 5d 7d 0a 63 68 65 63   {[1 0[1]]}.chec
0e90: 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74  k_doclist_all ft
0ea0: 73 33 64 2d 31 2e 31 2e 33 20 74 65 73 74 20 7b  s3d-1.1.3 test {
0eb0: 5b 31 20 30 5b 33 5d 5d 7d 0a 63 68 65 63 6b 5f  [1 0[3]]}.check_
0ec0: 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73 33  doclist_all fts3
0ed0: 64 2d 31 2e 31 2e 34 20 74 68 69 73 20 7b 5b 31  d-1.1.4 this {[1
0ee0: 20 30 5b 30 5d 5d 7d 0a 0a 63 68 65 63 6b 5f 74   0[0]]}..check_t
0ef0: 65 72 6d 73 20 20 20 66 74 73 33 64 2d 31 2e 32  erms   fts3d-1.2
0f00: 20 20 20 30 20 30 20 7b 61 20 69 73 20 74 65 73     0 0 {a is tes
0f10: 74 20 74 68 69 73 7d 0a 63 68 65 63 6b 5f 64 6f  t this}.check_do
0f20: 63 6c 69 73 74 20 66 74 73 33 64 2d 31 2e 32 2e  clist fts3d-1.2.
0f30: 31 20 30 20 30 20 61 20 7b 5b 31 20 30 5b 32 5d  1 0 0 a {[1 0[2]
0f40: 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74  ]}.check_doclist
0f50: 20 66 74 73 33 64 2d 31 2e 32 2e 32 20 30 20 30   fts3d-1.2.2 0 0
0f60: 20 69 73 20 7b 5b 31 20 30 5b 31 5d 5d 7d 0a 63   is {[1 0[1]]}.c
0f70: 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73  heck_doclist fts
0f80: 33 64 2d 31 2e 32 2e 33 20 30 20 30 20 74 65 73  3d-1.2.3 0 0 tes
0f90: 74 20 7b 5b 31 20 30 5b 33 5d 5d 7d 0a 63 68 65  t {[1 0[3]]}.che
0fa0: 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64  ck_doclist fts3d
0fb0: 2d 31 2e 32 2e 34 20 30 20 30 20 74 68 69 73 20  -1.2.4 0 0 this 
0fc0: 7b 5b 31 20 30 5b 30 5d 5d 7d 0a 0a 23 2a 2a 2a  {[1 0[0]]}..#***
0fd0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0fe0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0ff0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
1000: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
1010: 2a 2a 2a 2a 2a 2a 0a 23 20 54 65 73 74 20 72 65  ******.# Test re
1020: 73 75 6c 74 73 20 77 68 65 6e 20 65 76 65 72 79  sults when every
1030: 74 68 69 6e 67 20 69 73 20 6f 70 74 69 6d 69 7a  thing is optimiz
1040: 65 64 20 6d 61 6e 75 61 6c 6c 79 2e 0a 23 20 4e  ed manually..# N
1050: 4f 54 45 28 73 68 65 73 73 29 3a 20 54 68 69 73  OTE(shess): This
1060: 20 69 73 20 61 20 63 6f 70 79 20 6f 66 20 66 74   is a copy of ft
1070: 73 33 63 2d 31 2e 33 2e 20 20 49 27 76 65 20 70  s3c-1.3.  I've p
1080: 75 6c 6c 65 64 20 61 20 63 6f 70 79 20 68 65 72  ulled a copy her
1090: 65 0a 23 20 62 65 63 61 75 73 65 20 66 74 73 33  e.# because fts3
10a0: 64 2d 32 20 61 6e 64 20 66 74 73 33 64 2d 33 20  d-2 and fts3d-3 
10b0: 73 68 6f 75 6c 64 20 68 61 76 65 20 69 64 65 6e  should have iden
10c0: 74 69 63 61 6c 20 72 65 73 75 6c 74 73 2e 0a 64  tical results..d
10d0: 62 20 65 76 61 6c 20 7b 0a 20 20 44 52 4f 50 20  b eval {.  DROP 
10e0: 54 41 42 4c 45 20 49 46 20 45 58 49 53 54 53 20  TABLE IF EXISTS 
10f0: 74 31 3b 0a 20 20 43 52 45 41 54 45 20 56 49 52  t1;.  CREATE VIR
1100: 54 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53  TUAL TABLE t1 US
1110: 49 4e 47 20 66 74 73 33 28 63 29 3b 0a 20 20 49  ING fts3(c);.  I
1120: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 28 64  NSERT INTO t1 (d
1130: 6f 63 69 64 2c 20 63 29 20 56 41 4c 55 45 53 20  ocid, c) VALUES 
1140: 28 31 2c 20 27 54 68 69 73 20 69 73 20 61 20 74  (1, 'This is a t
1150: 65 73 74 27 29 3b 0a 20 20 49 4e 53 45 52 54 20  est');.  INSERT 
1160: 49 4e 54 4f 20 74 31 20 28 64 6f 63 69 64 2c 20  INTO t1 (docid, 
1170: 63 29 20 56 41 4c 55 45 53 20 28 32 2c 20 27 54  c) VALUES (2, 'T
1180: 68 61 74 20 77 61 73 20 61 20 74 65 73 74 27 29  hat was a test')
1190: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
11a0: 74 31 20 28 64 6f 63 69 64 2c 20 63 29 20 56 41  t1 (docid, c) VA
11b0: 4c 55 45 53 20 28 33 2c 20 27 54 68 69 73 20 69  LUES (3, 'This i
11c0: 73 20 61 20 74 65 73 74 27 29 3b 0a 20 20 44 45  s a test');.  DE
11d0: 4c 45 54 45 20 46 52 4f 4d 20 74 31 20 57 48 45  LETE FROM t1 WHE
11e0: 52 45 20 64 6f 63 69 64 20 49 4e 20 28 31 2c 33  RE docid IN (1,3
11f0: 29 3b 0a 20 20 44 52 4f 50 20 54 41 42 4c 45 20  );.  DROP TABLE 
1200: 49 46 20 45 58 49 53 54 53 20 74 31 6f 6c 64 3b  IF EXISTS t1old;
1210: 0a 20 20 41 4c 54 45 52 20 54 41 42 4c 45 20 74  .  ALTER TABLE t
1220: 31 20 52 45 4e 41 4d 45 20 54 4f 20 74 31 6f 6c  1 RENAME TO t1ol
1230: 64 3b 0a 20 20 43 52 45 41 54 45 20 56 49 52 54  d;.  CREATE VIRT
1240: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49  UAL TABLE t1 USI
1250: 4e 47 20 66 74 73 33 28 63 29 3b 0a 20 20 49 4e  NG fts3(c);.  IN
1260: 53 45 52 54 20 49 4e 54 4f 20 74 31 20 28 64 6f  SERT INTO t1 (do
1270: 63 69 64 2c 20 63 29 20 53 45 4c 45 43 54 20 64  cid, c) SELECT d
1280: 6f 63 69 64 2c 20 63 20 46 52 4f 4d 20 74 31 6f  ocid, c FROM t1o
1290: 6c 64 3b 0a 20 20 44 52 4f 50 20 54 41 42 4c 45  ld;.  DROP TABLE
12a0: 20 74 31 6f 6c 64 3b 0a 7d 0a 0a 23 20 53 68 6f   t1old;.}..# Sho
12b0: 75 6c 64 20 62 65 20 61 20 73 69 6e 67 6c 65 20  uld be a single 
12c0: 6f 70 74 69 6d 61 6c 20 73 65 67 6d 65 6e 74 20  optimal segment 
12d0: 77 69 74 68 20 74 68 65 20 73 61 6d 65 20 6c 6f  with the same lo
12e0: 67 69 63 61 6c 20 72 65 73 75 6c 74 73 2e 0a 64  gical results..d
12f0: 6f 5f 74 65 73 74 20 66 74 73 33 64 2d 32 2e 73  o_test fts3d-2.s
1300: 65 67 6d 65 6e 74 73 20 7b 0a 20 20 65 78 65 63  egments {.  exec
1310: 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54  sql {.    SELECT
1320: 20 6c 65 76 65 6c 2c 20 69 64 78 20 46 52 4f 4d   level, idx FROM
1330: 20 74 31 5f 73 65 67 64 69 72 20 4f 52 44 45 52   t1_segdir ORDER
1340: 20 42 59 20 6c 65 76 65 6c 2c 20 69 64 78 3b 0a   BY level, idx;.
1350: 20 20 7d 0a 7d 20 7b 30 20 30 7d 0a 64 6f 5f 74    }.} {0 0}.do_t
1360: 65 73 74 20 66 74 73 33 64 2d 32 2e 6d 61 74 63  est fts3d-2.matc
1370: 68 65 73 20 7b 0a 20 20 65 78 65 63 73 71 6c 20  hes {.  execsql 
1380: 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 4f 46 46  {.    SELECT OFF
1390: 53 45 54 53 28 74 31 29 20 46 52 4f 4d 20 74 31  SETS(t1) FROM t1
13a0: 0a 20 20 20 20 20 57 48 45 52 45 20 74 31 20 4d  .     WHERE t1 M
13b0: 41 54 43 48 20 27 74 68 69 73 20 4f 52 20 74 68  ATCH 'this OR th
13c0: 61 74 20 4f 52 20 77 61 73 20 4f 52 20 61 20 4f  at OR was OR a O
13d0: 52 20 69 73 20 4f 52 20 74 65 73 74 27 20 4f 52  R is OR test' OR
13e0: 44 45 52 20 42 59 20 64 6f 63 69 64 3b 0a 20 20  DER BY docid;.  
13f0: 7d 0a 7d 20 7b 7b 30 20 31 20 30 20 34 20 30 20  }.} {{0 1 0 4 0 
1400: 32 20 35 20 33 20 30 20 33 20 39 20 31 20 30 20  2 5 3 0 3 9 1 0 
1410: 35 20 31 31 20 34 7d 7d 0a 0a 63 68 65 63 6b 5f  5 11 4}}..check_
1420: 74 65 72 6d 73 5f 61 6c 6c 20 66 74 73 33 64 2d  terms_all fts3d-
1430: 32 2e 31 20 7b 61 20 74 65 73 74 20 74 68 61 74  2.1 {a test that
1440: 20 77 61 73 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c   was}.check_docl
1450: 69 73 74 5f 61 6c 6c 20 66 74 73 33 64 2d 32 2e  ist_all fts3d-2.
1460: 31 2e 31 20 61 20 7b 5b 32 20 30 5b 32 5d 5d 7d  1.1 a {[2 0[2]]}
1470: 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f 61  .check_doclist_a
1480: 6c 6c 20 66 74 73 33 64 2d 32 2e 31 2e 32 20 74  ll fts3d-2.1.2 t
1490: 65 73 74 20 7b 5b 32 20 30 5b 33 5d 5d 7d 0a 63  est {[2 0[3]]}.c
14a0: 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c  heck_doclist_all
14b0: 20 66 74 73 33 64 2d 32 2e 31 2e 33 20 74 68 61   fts3d-2.1.3 tha
14c0: 74 20 7b 5b 32 20 30 5b 30 5d 5d 7d 0a 63 68 65  t {[2 0[0]]}.che
14d0: 63 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66  ck_doclist_all f
14e0: 74 73 33 64 2d 32 2e 31 2e 34 20 77 61 73 20 7b  ts3d-2.1.4 was {
14f0: 5b 32 20 30 5b 31 5d 5d 7d 0a 0a 63 68 65 63 6b  [2 0[1]]}..check
1500: 5f 74 65 72 6d 73 20 66 74 73 33 64 2d 32 2e 32  _terms fts3d-2.2
1510: 20 30 20 30 20 7b 61 20 74 65 73 74 20 74 68 61   0 0 {a test tha
1520: 74 20 77 61 73 7d 0a 63 68 65 63 6b 5f 64 6f 63  t was}.check_doc
1530: 6c 69 73 74 20 66 74 73 33 64 2d 32 2e 32 2e 31  list fts3d-2.2.1
1540: 20 30 20 30 20 61 20 7b 5b 32 20 30 5b 32 5d 5d   0 0 a {[2 0[2]]
1550: 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20  }.check_doclist 
1560: 66 74 73 33 64 2d 32 2e 32 2e 32 20 30 20 30 20  fts3d-2.2.2 0 0 
1570: 74 65 73 74 20 7b 5b 32 20 30 5b 33 5d 5d 7d 0a  test {[2 0[3]]}.
1580: 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74  check_doclist ft
1590: 73 33 64 2d 32 2e 32 2e 33 20 30 20 30 20 74 68  s3d-2.2.3 0 0 th
15a0: 61 74 20 7b 5b 32 20 30 5b 30 5d 5d 7d 0a 63 68  at {[2 0[0]]}.ch
15b0: 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33  eck_doclist fts3
15c0: 64 2d 32 2e 32 2e 34 20 30 20 30 20 77 61 73 20  d-2.2.4 0 0 was 
15d0: 7b 5b 32 20 30 5b 31 5d 5d 7d 0a 0a 23 2a 2a 2a  {[2 0[1]]}..#***
15e0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
15f0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
1600: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
1610: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
1620: 2a 2a 2a 2a 2a 2a 0a 23 20 54 65 73 74 20 72 65  ******.# Test re
1630: 73 75 6c 74 73 20 77 68 65 6e 20 65 76 65 72 79  sults when every
1640: 74 68 69 6e 67 20 69 73 20 6f 70 74 69 6d 69 7a  thing is optimiz
1650: 65 64 20 76 69 61 20 6f 70 74 69 6d 69 7a 65 28  ed via optimize(
1660: 29 2e 0a 64 62 20 65 76 61 6c 20 7b 0a 20 20 44  )..db eval {.  D
1670: 52 4f 50 20 54 41 42 4c 45 20 49 46 20 45 58 49  ROP TABLE IF EXI
1680: 53 54 53 20 74 31 3b 0a 20 20 43 52 45 41 54 45  STS t1;.  CREATE
1690: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74   VIRTUAL TABLE t
16a0: 31 20 55 53 49 4e 47 20 66 74 73 33 28 63 29 3b  1 USING fts3(c);
16b0: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74  .  INSERT INTO t
16c0: 31 20 28 64 6f 63 69 64 2c 20 63 29 20 56 41 4c  1 (docid, c) VAL
16d0: 55 45 53 20 28 31 2c 20 27 54 68 69 73 20 69 73  UES (1, 'This is
16e0: 20 61 20 74 65 73 74 27 29 3b 0a 20 20 49 4e 53   a test');.  INS
16f0: 45 52 54 20 49 4e 54 4f 20 74 31 20 28 64 6f 63  ERT INTO t1 (doc
1700: 69 64 2c 20 63 29 20 56 41 4c 55 45 53 20 28 32  id, c) VALUES (2
1710: 2c 20 27 54 68 61 74 20 77 61 73 20 61 20 74 65  , 'That was a te
1720: 73 74 27 29 3b 0a 20 20 49 4e 53 45 52 54 20 49  st');.  INSERT I
1730: 4e 54 4f 20 74 31 20 28 64 6f 63 69 64 2c 20 63  NTO t1 (docid, c
1740: 29 20 56 41 4c 55 45 53 20 28 33 2c 20 27 54 68  ) VALUES (3, 'Th
1750: 69 73 20 69 73 20 61 20 74 65 73 74 27 29 3b 0a  is is a test');.
1760: 20 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 74 31    DELETE FROM t1
1770: 20 57 48 45 52 45 20 64 6f 63 69 64 20 49 4e 20   WHERE docid IN 
1780: 28 31 2c 33 29 3b 0a 20 20 53 45 4c 45 43 54 20  (1,3);.  SELECT 
1790: 4f 50 54 49 4d 49 5a 45 28 74 31 29 20 46 52 4f  OPTIMIZE(t1) FRO
17a0: 4d 20 74 31 20 4c 49 4d 49 54 20 31 3b 0a 7d 0a  M t1 LIMIT 1;.}.
17b0: 0a 23 20 53 68 6f 75 6c 64 20 62 65 20 61 20 73  .# Should be a s
17c0: 69 6e 67 6c 65 20 6f 70 74 69 6d 61 6c 20 73 65  ingle optimal se
17d0: 67 6d 65 6e 74 20 77 69 74 68 20 74 68 65 20 73  gment with the s
17e0: 61 6d 65 20 6c 6f 67 69 63 61 6c 20 72 65 73 75  ame logical resu
17f0: 6c 74 73 2e 0a 64 6f 5f 74 65 73 74 20 66 74 73  lts..do_test fts
1800: 33 64 2d 33 2e 73 65 67 6d 65 6e 74 73 20 7b 0a  3d-3.segments {.
1810: 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20    execsql {.    
1820: 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69 64  SELECT level, id
1830: 78 20 46 52 4f 4d 20 74 31 5f 73 65 67 64 69 72  x FROM t1_segdir
1840: 20 4f 52 44 45 52 20 42 59 20 6c 65 76 65 6c 2c   ORDER BY level,
1850: 20 69 64 78 3b 0a 20 20 7d 0a 7d 20 7b 30 20 30   idx;.  }.} {0 0
1860: 7d 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 64 2d  }.do_test fts3d-
1870: 33 2e 6d 61 74 63 68 65 73 20 7b 0a 20 20 65 78  3.matches {.  ex
1880: 65 63 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45  ecsql {.    SELE
1890: 43 54 20 4f 46 46 53 45 54 53 28 74 31 29 20 46  CT OFFSETS(t1) F
18a0: 52 4f 4d 20 74 31 0a 20 20 20 20 20 57 48 45 52  ROM t1.     WHER
18b0: 45 20 74 31 20 4d 41 54 43 48 20 27 74 68 69 73  E t1 MATCH 'this
18c0: 20 4f 52 20 74 68 61 74 20 4f 52 20 77 61 73 20   OR that OR was 
18d0: 4f 52 20 61 20 4f 52 20 69 73 20 4f 52 20 74 65  OR a OR is OR te
18e0: 73 74 27 20 4f 52 44 45 52 20 42 59 20 64 6f 63  st' ORDER BY doc
18f0: 69 64 3b 0a 20 20 7d 0a 7d 20 7b 7b 30 20 31 20  id;.  }.} {{0 1 
1900: 30 20 34 20 30 20 32 20 35 20 33 20 30 20 33 20  0 4 0 2 5 3 0 3 
1910: 39 20 31 20 30 20 35 20 31 31 20 34 7d 7d 0a 0a  9 1 0 5 11 4}}..
1920: 63 68 65 63 6b 5f 74 65 72 6d 73 5f 61 6c 6c 20  check_terms_all 
1930: 66 74 73 33 64 2d 33 2e 31 20 7b 61 20 74 65 73  fts3d-3.1 {a tes
1940: 74 20 74 68 61 74 20 77 61 73 7d 0a 63 68 65 63  t that was}.chec
1950: 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74  k_doclist_all ft
1960: 73 33 64 2d 33 2e 31 2e 31 20 61 20 7b 5b 32 20  s3d-3.1.1 a {[2 
1970: 30 5b 32 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63  0[2]]}.check_doc
1980: 6c 69 73 74 5f 61 6c 6c 20 66 74 73 33 64 2d 33  list_all fts3d-3
1990: 2e 31 2e 32 20 74 65 73 74 20 7b 5b 32 20 30 5b  .1.2 test {[2 0[
19a0: 33 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69  3]]}.check_docli
19b0: 73 74 5f 61 6c 6c 20 66 74 73 33 64 2d 33 2e 31  st_all fts3d-3.1
19c0: 2e 33 20 74 68 61 74 20 7b 5b 32 20 30 5b 30 5d  .3 that {[2 0[0]
19d0: 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74  ]}.check_doclist
19e0: 5f 61 6c 6c 20 66 74 73 33 64 2d 33 2e 31 2e 34  _all fts3d-3.1.4
19f0: 20 77 61 73 20 7b 5b 32 20 30 5b 31 5d 5d 7d 0a   was {[2 0[1]]}.
1a00: 0a 63 68 65 63 6b 5f 74 65 72 6d 73 20 66 74 73  .check_terms fts
1a10: 33 64 2d 33 2e 32 20 30 20 30 20 7b 61 20 74 65  3d-3.2 0 0 {a te
1a20: 73 74 20 74 68 61 74 20 77 61 73 7d 0a 63 68 65  st that was}.che
1a30: 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64  ck_doclist fts3d
1a40: 2d 33 2e 32 2e 31 20 30 20 30 20 61 20 7b 5b 32  -3.2.1 0 0 a {[2
1a50: 20 30 5b 32 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f   0[2]]}.check_do
1a60: 63 6c 69 73 74 20 66 74 73 33 64 2d 33 2e 32 2e  clist fts3d-3.2.
1a70: 32 20 30 20 30 20 74 65 73 74 20 7b 5b 32 20 30  2 0 0 test {[2 0
1a80: 5b 33 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c  [3]]}.check_docl
1a90: 69 73 74 20 66 74 73 33 64 2d 33 2e 32 2e 33 20  ist fts3d-3.2.3 
1aa0: 30 20 30 20 74 68 61 74 20 7b 5b 32 20 30 5b 30  0 0 that {[2 0[0
1ab0: 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73  ]]}.check_doclis
1ac0: 74 20 66 74 73 33 64 2d 33 2e 32 2e 34 20 30 20  t fts3d-3.2.4 0 
1ad0: 30 20 77 61 73 20 7b 5b 32 20 30 5b 31 5d 5d 7d  0 was {[2 0[1]]}
1ae0: 0a 0a 23 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ..#*************
1af0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
1b00: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
1b10: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
1b20: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 23 20 54  ************.# T
1b30: 65 73 74 20 6f 70 74 69 6d 69 7a 65 28 29 20 61  est optimize() a
1b40: 67 61 69 6e 73 74 20 61 20 74 61 62 6c 65 20 69  gainst a table i
1b50: 6e 76 6f 6c 76 69 6e 67 20 73 65 67 6d 65 6e 74  nvolving segment
1b60: 20 6d 65 72 67 65 73 2e 0a 23 20 4e 4f 54 45 28   merges..# NOTE(
1b70: 73 68 65 73 73 29 3a 20 53 69 6e 63 65 20 74 68  shess): Since th
1b80: 65 72 65 27 73 20 6e 6f 20 74 72 61 6e 73 61 63  ere's no transac
1b90: 74 69 6f 6e 2c 20 65 61 63 68 20 6f 66 20 74 68  tion, each of th
1ba0: 65 20 49 4e 53 45 52 54 2f 55 50 44 41 54 45 0a  e INSERT/UPDATE.
1bb0: 23 20 73 74 61 74 65 6d 65 6e 74 73 20 67 65 6e  # statements gen
1bc0: 65 72 61 74 65 73 20 61 20 73 65 67 6d 65 6e 74  erates a segment
1bd0: 2e 0a 64 62 20 65 76 61 6c 20 7b 0a 20 20 44 52  ..db eval {.  DR
1be0: 4f 50 20 54 41 42 4c 45 20 49 46 20 45 58 49 53  OP TABLE IF EXIS
1bf0: 54 53 20 74 31 3b 0a 20 20 43 52 45 41 54 45 20  TS t1;.  CREATE 
1c00: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31  VIRTUAL TABLE t1
1c10: 20 55 53 49 4e 47 20 66 74 73 33 28 63 29 3b 0a   USING fts3(c);.
1c20: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74  .  INSERT INTO t
1c30: 31 20 28 72 6f 77 69 64 2c 20 63 29 20 56 41 4c  1 (rowid, c) VAL
1c40: 55 45 53 20 28 31 2c 20 27 54 68 69 73 20 69 73  UES (1, 'This is
1c50: 20 61 20 74 65 73 74 27 29 3b 0a 20 20 49 4e 53   a test');.  INS
1c60: 45 52 54 20 49 4e 54 4f 20 74 31 20 28 72 6f 77  ERT INTO t1 (row
1c70: 69 64 2c 20 63 29 20 56 41 4c 55 45 53 20 28 32  id, c) VALUES (2
1c80: 2c 20 27 54 68 61 74 20 77 61 73 20 61 20 74 65  , 'That was a te
1c90: 73 74 27 29 3b 0a 20 20 49 4e 53 45 52 54 20 49  st');.  INSERT I
1ca0: 4e 54 4f 20 74 31 20 28 72 6f 77 69 64 2c 20 63  NTO t1 (rowid, c
1cb0: 29 20 56 41 4c 55 45 53 20 28 33 2c 20 27 54 68  ) VALUES (3, 'Th
1cc0: 69 73 20 69 73 20 61 20 74 65 73 74 27 29 3b 0a  is is a test');.
1cd0: 0a 20 20 55 50 44 41 54 45 20 74 31 20 53 45 54  .  UPDATE t1 SET
1ce0: 20 63 20 3d 20 27 54 68 69 73 20 69 73 20 61 20   c = 'This is a 
1cf0: 74 65 73 74 20 6f 6e 65 27 20 57 48 45 52 45 20  test one' WHERE 
1d00: 72 6f 77 69 64 20 3d 20 31 3b 0a 20 20 55 50 44  rowid = 1;.  UPD
1d10: 41 54 45 20 74 31 20 53 45 54 20 63 20 3d 20 27  ATE t1 SET c = '
1d20: 54 68 61 74 20 77 61 73 20 61 20 74 65 73 74 20  That was a test 
1d30: 6f 6e 65 27 20 57 48 45 52 45 20 72 6f 77 69 64  one' WHERE rowid
1d40: 20 3d 20 32 3b 0a 20 20 55 50 44 41 54 45 20 74   = 2;.  UPDATE t
1d50: 31 20 53 45 54 20 63 20 3d 20 27 54 68 69 73 20  1 SET c = 'This 
1d60: 69 73 20 61 20 74 65 73 74 20 6f 6e 65 27 20 57  is a test one' W
1d70: 48 45 52 45 20 72 6f 77 69 64 20 3d 20 33 3b 0a  HERE rowid = 3;.
1d80: 0a 20 20 55 50 44 41 54 45 20 74 31 20 53 45 54  .  UPDATE t1 SET
1d90: 20 63 20 3d 20 27 54 68 69 73 20 69 73 20 61 20   c = 'This is a 
1da0: 74 65 73 74 20 74 77 6f 27 20 57 48 45 52 45 20  test two' WHERE 
1db0: 72 6f 77 69 64 20 3d 20 31 3b 0a 20 20 55 50 44  rowid = 1;.  UPD
1dc0: 41 54 45 20 74 31 20 53 45 54 20 63 20 3d 20 27  ATE t1 SET c = '
1dd0: 54 68 61 74 20 77 61 73 20 61 20 74 65 73 74 20  That was a test 
1de0: 74 77 6f 27 20 57 48 45 52 45 20 72 6f 77 69 64  two' WHERE rowid
1df0: 20 3d 20 32 3b 0a 20 20 55 50 44 41 54 45 20 74   = 2;.  UPDATE t
1e00: 31 20 53 45 54 20 63 20 3d 20 27 54 68 69 73 20  1 SET c = 'This 
1e10: 69 73 20 61 20 74 65 73 74 20 74 77 6f 27 20 57  is a test two' W
1e20: 48 45 52 45 20 72 6f 77 69 64 20 3d 20 33 3b 0a  HERE rowid = 3;.
1e30: 0a 20 20 55 50 44 41 54 45 20 74 31 20 53 45 54  .  UPDATE t1 SET
1e40: 20 63 20 3d 20 27 54 68 69 73 20 69 73 20 61 20   c = 'This is a 
1e50: 74 65 73 74 20 74 68 72 65 65 27 20 57 48 45 52  test three' WHER
1e60: 45 20 72 6f 77 69 64 20 3d 20 31 3b 0a 20 20 55  E rowid = 1;.  U
1e70: 50 44 41 54 45 20 74 31 20 53 45 54 20 63 20 3d  PDATE t1 SET c =
1e80: 20 27 54 68 61 74 20 77 61 73 20 61 20 74 65 73   'That was a tes
1e90: 74 20 74 68 72 65 65 27 20 57 48 45 52 45 20 72  t three' WHERE r
1ea0: 6f 77 69 64 20 3d 20 32 3b 0a 20 20 55 50 44 41  owid = 2;.  UPDA
1eb0: 54 45 20 74 31 20 53 45 54 20 63 20 3d 20 27 54  TE t1 SET c = 'T
1ec0: 68 69 73 20 69 73 20 61 20 74 65 73 74 20 74 68  his is a test th
1ed0: 72 65 65 27 20 57 48 45 52 45 20 72 6f 77 69 64  ree' WHERE rowid
1ee0: 20 3d 20 33 3b 0a 0a 20 20 55 50 44 41 54 45 20   = 3;..  UPDATE 
1ef0: 74 31 20 53 45 54 20 63 20 3d 20 27 54 68 69 73  t1 SET c = 'This
1f00: 20 69 73 20 61 20 74 65 73 74 20 66 6f 75 72 27   is a test four'
1f10: 20 57 48 45 52 45 20 72 6f 77 69 64 20 3d 20 31   WHERE rowid = 1
1f20: 3b 0a 20 20 55 50 44 41 54 45 20 74 31 20 53 45  ;.  UPDATE t1 SE
1f30: 54 20 63 20 3d 20 27 54 68 61 74 20 77 61 73 20  T c = 'That was 
1f40: 61 20 74 65 73 74 20 66 6f 75 72 27 20 57 48 45  a test four' WHE
1f50: 52 45 20 72 6f 77 69 64 20 3d 20 32 3b 0a 20 20  RE rowid = 2;.  
1f60: 55 50 44 41 54 45 20 74 31 20 53 45 54 20 63 20  UPDATE t1 SET c 
1f70: 3d 20 27 54 68 69 73 20 69 73 20 61 20 74 65 73  = 'This is a tes
1f80: 74 20 66 6f 75 72 27 20 57 48 45 52 45 20 72 6f  t four' WHERE ro
1f90: 77 69 64 20 3d 20 33 3b 0a 0a 20 20 55 50 44 41  wid = 3;..  UPDA
1fa0: 54 45 20 74 31 20 53 45 54 20 63 20 3d 20 27 54  TE t1 SET c = 'T
1fb0: 68 69 73 20 69 73 20 61 20 74 65 73 74 27 20 57  his is a test' W
1fc0: 48 45 52 45 20 72 6f 77 69 64 20 3d 20 31 3b 0a  HERE rowid = 1;.
1fd0: 20 20 55 50 44 41 54 45 20 74 31 20 53 45 54 20    UPDATE t1 SET 
1fe0: 63 20 3d 20 27 54 68 61 74 20 77 61 73 20 61 20  c = 'That was a 
1ff0: 74 65 73 74 27 20 57 48 45 52 45 20 72 6f 77 69  test' WHERE rowi
2000: 64 20 3d 20 32 3b 0a 20 20 55 50 44 41 54 45 20  d = 2;.  UPDATE 
2010: 74 31 20 53 45 54 20 63 20 3d 20 27 54 68 69 73  t1 SET c = 'This
2020: 20 69 73 20 61 20 74 65 73 74 27 20 57 48 45 52   is a test' WHER
2030: 45 20 72 6f 77 69 64 20 3d 20 33 3b 0a 7d 0a 0a  E rowid = 3;.}..
2040: 23 20 32 20 73 65 67 6d 65 6e 74 73 20 69 6e 20  # 2 segments in 
2050: 6c 65 76 65 6c 20 30 2c 20 31 20 69 6e 20 6c 65  level 0, 1 in le
2060: 76 65 6c 20 31 20 28 31 38 20 73 65 67 6d 65 6e  vel 1 (18 segmen
2070: 74 73 20 63 72 65 61 74 65 64 2c 20 31 36 0a 23  ts created, 16.#
2080: 20 6d 65 72 67 65 64 29 2e 0a 64 6f 5f 74 65 73   merged)..do_tes
2090: 74 20 66 74 73 33 64 2d 34 2e 73 65 67 6d 65 6e  t fts3d-4.segmen
20a0: 74 73 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  ts {.  execsql {
20b0: 0a 20 20 20 20 53 45 4c 45 43 54 20 6c 65 76 65  .    SELECT leve
20c0: 6c 2c 20 69 64 78 20 46 52 4f 4d 20 74 31 5f 73  l, idx FROM t1_s
20d0: 65 67 64 69 72 20 4f 52 44 45 52 20 42 59 20 6c  egdir ORDER BY l
20e0: 65 76 65 6c 2c 20 69 64 78 3b 0a 20 20 7d 0a 7d  evel, idx;.  }.}
20f0: 20 7b 30 20 30 20 30 20 31 20 31 20 30 7d 0a 0a   {0 0 0 1 1 0}..
2100: 64 6f 5f 74 65 73 74 20 66 74 73 33 64 2d 34 2e  do_test fts3d-4.
2110: 6d 61 74 63 68 65 73 20 7b 0a 20 20 65 78 65 63  matches {.  exec
2120: 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54  sql {.    SELECT
2130: 20 4f 46 46 53 45 54 53 28 74 31 29 20 46 52 4f   OFFSETS(t1) FRO
2140: 4d 20 74 31 0a 20 20 20 20 20 57 48 45 52 45 20  M t1.     WHERE 
2150: 74 31 20 4d 41 54 43 48 20 27 74 68 69 73 20 4f  t1 MATCH 'this O
2160: 52 20 74 68 61 74 20 4f 52 20 77 61 73 20 4f 52  R that OR was OR
2170: 20 61 20 4f 52 20 69 73 20 4f 52 20 74 65 73 74   a OR is OR test
2180: 27 20 4f 52 44 45 52 20 42 59 20 64 6f 63 69 64  ' ORDER BY docid
2190: 3b 0a 20 20 7d 0a 7d 20 5b 6c 69 73 74 20 7b 30  ;.  }.} [list {0
21a0: 20 30 20 30 20 34 20 30 20 34 20 35 20 32 20 30   0 0 4 0 4 5 2 0
21b0: 20 33 20 38 20 31 20 30 20 35 20 31 30 20 34 7d   3 8 1 0 5 10 4}
21c0: 20 5c 0a 20 20 20 20 20 20 20 20 7b 30 20 31 20   \.        {0 1 
21d0: 30 20 34 20 30 20 32 20 35 20 33 20 30 20 33 20  0 4 0 2 5 3 0 3 
21e0: 39 20 31 20 30 20 35 20 31 31 20 34 7d 20 5c 0a  9 1 0 5 11 4} \.
21f0: 20 20 20 20 20 20 20 20 7b 30 20 30 20 30 20 34          {0 0 0 4
2200: 20 30 20 34 20 35 20 32 20 30 20 33 20 38 20 31   0 4 5 2 0 3 8 1
2210: 20 30 20 35 20 31 30 20 34 7d 5d 0a 0a 63 68 65   0 5 10 4}]..che
2220: 63 6b 5f 74 65 72 6d 73 5f 61 6c 6c 20 66 74 73  ck_terms_all fts
2230: 33 64 2d 34 2e 31 20 20 20 20 20 20 7b 61 20 66  3d-4.1      {a f
2240: 6f 75 72 20 69 73 20 6f 6e 65 20 74 65 73 74 20  our is one test 
2250: 74 68 61 74 20 74 68 69 73 20 74 68 72 65 65 20  that this three 
2260: 74 77 6f 20 77 61 73 7d 0a 63 68 65 63 6b 5f 64  two was}.check_d
2270: 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73 33 64  oclist_all fts3d
2280: 2d 34 2e 31 2e 31 20 20 61 20 7b 5b 31 20 30 5b  -4.1.1  a {[1 0[
2290: 32 5d 5d 20 5b 32 20 30 5b 32 5d 5d 20 5b 33 20  2]] [2 0[2]] [3 
22a0: 30 5b 32 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63  0[2]]}.check_doc
22b0: 6c 69 73 74 5f 61 6c 6c 20 66 74 73 33 64 2d 34  list_all fts3d-4
22c0: 2e 31 2e 32 20 20 66 6f 75 72 20 7b 7d 0a 63 68  .1.2  four {}.ch
22d0: 65 63 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20  eck_doclist_all 
22e0: 66 74 73 33 64 2d 34 2e 31 2e 33 20 20 69 73 20  fts3d-4.1.3  is 
22f0: 7b 5b 31 20 30 5b 31 5d 5d 20 5b 33 20 30 5b 31  {[1 0[1]] [3 0[1
2300: 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73  ]]}.check_doclis
2310: 74 5f 61 6c 6c 20 66 74 73 33 64 2d 34 2e 31 2e  t_all fts3d-4.1.
2320: 34 20 20 6f 6e 65 20 7b 7d 0a 63 68 65 63 6b 5f  4  one {}.check_
2330: 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73 33  doclist_all fts3
2340: 64 2d 34 2e 31 2e 35 20 20 74 65 73 74 20 7b 5b  d-4.1.5  test {[
2350: 31 20 30 5b 33 5d 5d 20 5b 32 20 30 5b 33 5d 5d  1 0[3]] [2 0[3]]
2360: 20 5b 33 20 30 5b 33 5d 5d 7d 0a 63 68 65 63 6b   [3 0[3]]}.check
2370: 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73  _doclist_all fts
2380: 33 64 2d 34 2e 31 2e 36 20 20 74 68 61 74 20 7b  3d-4.1.6  that {
2390: 5b 32 20 30 5b 30 5d 5d 7d 0a 63 68 65 63 6b 5f  [2 0[0]]}.check_
23a0: 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73 33  doclist_all fts3
23b0: 64 2d 34 2e 31 2e 37 20 20 74 68 69 73 20 7b 5b  d-4.1.7  this {[
23c0: 31 20 30 5b 30 5d 5d 20 5b 33 20 30 5b 30 5d 5d  1 0[0]] [3 0[0]]
23d0: 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f  }.check_doclist_
23e0: 61 6c 6c 20 66 74 73 33 64 2d 34 2e 31 2e 38 20  all fts3d-4.1.8 
23f0: 20 74 68 72 65 65 20 7b 7d 0a 63 68 65 63 6b 5f   three {}.check_
2400: 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73 33  doclist_all fts3
2410: 64 2d 34 2e 31 2e 39 20 20 74 77 6f 20 7b 7d 0a  d-4.1.9  two {}.
2420: 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c  check_doclist_al
2430: 6c 20 66 74 73 33 64 2d 34 2e 31 2e 31 30 20 77  l fts3d-4.1.10 w
2440: 61 73 20 7b 5b 32 20 30 5b 31 5d 5d 7d 0a 0a 63  as {[2 0[1]]}..c
2450: 68 65 63 6b 5f 74 65 72 6d 73 20 66 74 73 33 64  heck_terms fts3d
2460: 2d 34 2e 32 20 20 20 20 20 30 20 30 20 7b 61 20  -4.2     0 0 {a 
2470: 66 6f 75 72 20 74 65 73 74 20 74 68 61 74 20 77  four test that w
2480: 61 73 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73  as}.check_doclis
2490: 74 20 66 74 73 33 64 2d 34 2e 32 2e 31 20 30 20  t fts3d-4.2.1 0 
24a0: 30 20 61 20 7b 5b 32 20 30 5b 32 5d 5d 7d 0a 63  0 a {[2 0[2]]}.c
24b0: 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73  heck_doclist fts
24c0: 33 64 2d 34 2e 32 2e 32 20 30 20 30 20 66 6f 75  3d-4.2.2 0 0 fou
24d0: 72 20 7b 5b 32 5d 7d 0a 63 68 65 63 6b 5f 64 6f  r {[2]}.check_do
24e0: 63 6c 69 73 74 20 66 74 73 33 64 2d 34 2e 32 2e  clist fts3d-4.2.
24f0: 33 20 30 20 30 20 74 65 73 74 20 7b 5b 32 20 30  3 0 0 test {[2 0
2500: 5b 33 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c  [3]]}.check_docl
2510: 69 73 74 20 66 74 73 33 64 2d 34 2e 32 2e 34 20  ist fts3d-4.2.4 
2520: 30 20 30 20 74 68 61 74 20 7b 5b 32 20 30 5b 30  0 0 that {[2 0[0
2530: 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73  ]]}.check_doclis
2540: 74 20 66 74 73 33 64 2d 34 2e 32 2e 35 20 30 20  t fts3d-4.2.5 0 
2550: 30 20 77 61 73 20 7b 5b 32 20 30 5b 31 5d 5d 7d  0 was {[2 0[1]]}
2560: 0a 0a 63 68 65 63 6b 5f 74 65 72 6d 73 20 66 74  ..check_terms ft
2570: 73 33 64 2d 34 2e 33 20 20 20 20 20 30 20 31 20  s3d-4.3     0 1 
2580: 7b 61 20 66 6f 75 72 20 69 73 20 74 65 73 74 20  {a four is test 
2590: 74 68 69 73 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c  this}.check_docl
25a0: 69 73 74 20 66 74 73 33 64 2d 34 2e 33 2e 31 20  ist fts3d-4.3.1 
25b0: 30 20 31 20 61 20 7b 5b 33 20 30 5b 32 5d 5d 7d  0 1 a {[3 0[2]]}
25c0: 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66  .check_doclist f
25d0: 74 73 33 64 2d 34 2e 33 2e 32 20 30 20 31 20 66  ts3d-4.3.2 0 1 f
25e0: 6f 75 72 20 7b 5b 33 5d 7d 0a 63 68 65 63 6b 5f  our {[3]}.check_
25f0: 64 6f 63 6c 69 73 74 20 66 74 73 33 64 2d 34 2e  doclist fts3d-4.
2600: 33 2e 33 20 30 20 31 20 69 73 20 7b 5b 33 20 30  3.3 0 1 is {[3 0
2610: 5b 31 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c  [1]]}.check_docl
2620: 69 73 74 20 66 74 73 33 64 2d 34 2e 33 2e 34 20  ist fts3d-4.3.4 
2630: 30 20 31 20 74 65 73 74 20 7b 5b 33 20 30 5b 33  0 1 test {[3 0[3
2640: 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73  ]]}.check_doclis
2650: 74 20 66 74 73 33 64 2d 34 2e 33 2e 35 20 30 20  t fts3d-4.3.5 0 
2660: 31 20 74 68 69 73 20 7b 5b 33 20 30 5b 30 5d 5d  1 this {[3 0[0]]
2670: 7d 0a 0a 63 68 65 63 6b 5f 74 65 72 6d 73 20 66  }..check_terms f
2680: 74 73 33 64 2d 34 2e 34 20 20 20 20 20 20 31 20  ts3d-4.4      1 
2690: 30 20 7b 61 20 66 6f 75 72 20 69 73 20 6f 6e 65  0 {a four is one
26a0: 20 74 65 73 74 20 74 68 61 74 20 74 68 69 73 20   test that this 
26b0: 74 68 72 65 65 20 74 77 6f 20 77 61 73 7d 0a 63  three two was}.c
26c0: 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73  heck_doclist fts
26d0: 33 64 2d 34 2e 34 2e 31 20 20 31 20 30 20 61 20  3d-4.4.1  1 0 a 
26e0: 7b 5b 31 20 30 5b 32 5d 5d 20 5b 32 20 30 5b 32  {[1 0[2]] [2 0[2
26f0: 5d 5d 20 5b 33 20 30 5b 32 5d 5d 7d 0a 63 68 65  ]] [3 0[2]]}.che
2700: 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64  ck_doclist fts3d
2710: 2d 34 2e 34 2e 32 20 20 31 20 30 20 66 6f 75 72  -4.4.2  1 0 four
2720: 20 7b 5b 31 5d 20 5b 32 20 30 5b 34 5d 5d 20 5b   {[1] [2 0[4]] [
2730: 33 20 30 5b 34 5d 5d 7d 0a 63 68 65 63 6b 5f 64  3 0[4]]}.check_d
2740: 6f 63 6c 69 73 74 20 66 74 73 33 64 2d 34 2e 34  oclist fts3d-4.4
2750: 2e 33 20 20 31 20 30 20 69 73 20 7b 5b 31 20 30  .3  1 0 is {[1 0
2760: 5b 31 5d 5d 20 5b 33 20 30 5b 31 5d 5d 7d 0a 63  [1]] [3 0[1]]}.c
2770: 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73  heck_doclist fts
2780: 33 64 2d 34 2e 34 2e 34 20 20 31 20 30 20 6f 6e  3d-4.4.4  1 0 on
2790: 65 20 7b 5b 31 5d 20 5b 32 5d 20 5b 33 5d 7d 0a  e {[1] [2] [3]}.
27a0: 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74  check_doclist ft
27b0: 73 33 64 2d 34 2e 34 2e 35 20 20 31 20 30 20 74  s3d-4.4.5  1 0 t
27c0: 65 73 74 20 7b 5b 31 20 30 5b 33 5d 5d 20 5b 32  est {[1 0[3]] [2
27d0: 20 30 5b 33 5d 5d 20 5b 33 20 30 5b 33 5d 5d 7d   0[3]] [3 0[3]]}
27e0: 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66  .check_doclist f
27f0: 74 73 33 64 2d 34 2e 34 2e 36 20 20 31 20 30 20  ts3d-4.4.6  1 0 
2800: 74 68 61 74 20 7b 5b 32 20 30 5b 30 5d 5d 7d 0a  that {[2 0[0]]}.
2810: 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74  check_doclist ft
2820: 73 33 64 2d 34 2e 34 2e 37 20 20 31 20 30 20 74  s3d-4.4.7  1 0 t
2830: 68 69 73 20 7b 5b 31 20 30 5b 30 5d 5d 20 5b 33  his {[1 0[0]] [3
2840: 20 30 5b 30 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f   0[0]]}.check_do
2850: 63 6c 69 73 74 20 66 74 73 33 64 2d 34 2e 34 2e  clist fts3d-4.4.
2860: 38 20 20 31 20 30 20 74 68 72 65 65 20 7b 5b 31  8  1 0 three {[1
2870: 5d 20 5b 32 5d 20 5b 33 5d 7d 0a 63 68 65 63 6b  ] [2] [3]}.check
2880: 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64 2d 34  _doclist fts3d-4
2890: 2e 34 2e 39 20 20 31 20 30 20 74 77 6f 20 7b 5b  .4.9  1 0 two {[
28a0: 31 5d 20 5b 32 5d 20 5b 33 5d 7d 0a 63 68 65 63  1] [2] [3]}.chec
28b0: 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64 2d  k_doclist fts3d-
28c0: 34 2e 34 2e 31 30 20 31 20 30 20 77 61 73 20 7b  4.4.10 1 0 was {
28d0: 5b 32 20 30 5b 31 5d 5d 7d 0a 0a 23 20 4f 70 74  [2 0[1]]}..# Opt
28e0: 69 6d 69 7a 65 20 73 68 6f 75 6c 64 20 6c 65 61  imize should lea
28f0: 76 65 20 74 68 65 20 72 65 73 75 6c 74 20 69 6e  ve the result in
2900: 20 74 68 65 20 6c 65 76 65 6c 20 6f 66 20 74 68   the level of th
2910: 65 20 68 69 67 68 65 73 74 2d 6c 65 76 65 6c 0a  e highest-level.
2920: 23 20 70 72 69 6f 72 20 73 65 67 6d 65 6e 74 2e  # prior segment.
2930: 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 64 2d 34  .do_test fts3d-4
2940: 2e 35 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  .5 {.  execsql {
2950: 0a 20 20 20 20 53 45 4c 45 43 54 20 4f 50 54 49  .    SELECT OPTI
2960: 4d 49 5a 45 28 74 31 29 20 46 52 4f 4d 20 74 31  MIZE(t1) FROM t1
2970: 20 4c 49 4d 49 54 20 31 3b 0a 20 20 20 20 53 45   LIMIT 1;.    SE
2980: 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69 64 78 20  LECT level, idx 
2990: 46 52 4f 4d 20 74 31 5f 73 65 67 64 69 72 20 4f  FROM t1_segdir O
29a0: 52 44 45 52 20 42 59 20 6c 65 76 65 6c 2c 20 69  RDER BY level, i
29b0: 64 78 3b 0a 20 20 7d 0a 7d 20 7b 7b 49 6e 64 65  dx;.  }.} {{Inde
29c0: 78 20 6f 70 74 69 6d 69 7a 65 64 7d 20 31 20 30  x optimized} 1 0
29d0: 7d 0a 0a 23 20 49 64 65 6e 74 69 63 61 6c 20 74  }..# Identical t
29e0: 6f 20 66 74 73 33 64 2d 34 2e 6d 61 74 63 68 65  o fts3d-4.matche
29f0: 73 2e 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 64  s..do_test fts3d
2a00: 2d 34 2e 35 2e 6d 61 74 63 68 65 73 20 7b 0a 20  -4.5.matches {. 
2a10: 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 53   execsql {.    S
2a20: 45 4c 45 43 54 20 4f 46 46 53 45 54 53 28 74 31  ELECT OFFSETS(t1
2a30: 29 20 46 52 4f 4d 20 74 31 0a 20 20 20 20 20 57  ) FROM t1.     W
2a40: 48 45 52 45 20 74 31 20 4d 41 54 43 48 20 27 74  HERE t1 MATCH 't
2a50: 68 69 73 20 4f 52 20 74 68 61 74 20 4f 52 20 77  his OR that OR w
2a60: 61 73 20 4f 52 20 61 20 4f 52 20 69 73 20 4f 52  as OR a OR is OR
2a70: 20 74 65 73 74 27 20 4f 52 44 45 52 20 42 59 20   test' ORDER BY 
2a80: 64 6f 63 69 64 3b 0a 20 20 7d 0a 7d 20 5b 6c 69  docid;.  }.} [li
2a90: 73 74 20 7b 30 20 30 20 30 20 34 20 30 20 34 20  st {0 0 0 4 0 4 
2aa0: 35 20 32 20 30 20 33 20 38 20 31 20 30 20 35 20  5 2 0 3 8 1 0 5 
2ab0: 31 30 20 34 7d 20 5c 0a 20 20 20 20 20 20 20 20  10 4} \.        
2ac0: 7b 30 20 31 20 30 20 34 20 30 20 32 20 35 20 33  {0 1 0 4 0 2 5 3
2ad0: 20 30 20 33 20 39 20 31 20 30 20 35 20 31 31 20   0 3 9 1 0 5 11 
2ae0: 34 7d 20 5c 0a 20 20 20 20 20 20 20 20 7b 30 20  4} \.        {0 
2af0: 30 20 30 20 34 20 30 20 34 20 35 20 32 20 30 20  0 0 4 0 4 5 2 0 
2b00: 33 20 38 20 31 20 30 20 35 20 31 30 20 34 7d 5d  3 8 1 0 5 10 4}]
2b10: 0a 0a 63 68 65 63 6b 5f 74 65 72 6d 73 5f 61 6c  ..check_terms_al
2b20: 6c 20 66 74 73 33 64 2d 34 2e 35 2e 31 20 20 20  l fts3d-4.5.1   
2b30: 20 20 7b 61 20 69 73 20 74 65 73 74 20 74 68 61    {a is test tha
2b40: 74 20 74 68 69 73 20 77 61 73 7d 0a 63 68 65 63  t this was}.chec
2b50: 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74  k_doclist_all ft
2b60: 73 33 64 2d 34 2e 35 2e 31 2e 31 20 61 20 7b 5b  s3d-4.5.1.1 a {[
2b70: 31 20 30 5b 32 5d 5d 20 5b 32 20 30 5b 32 5d 5d  1 0[2]] [2 0[2]]
2b80: 20 5b 33 20 30 5b 32 5d 5d 7d 0a 63 68 65 63 6b   [3 0[2]]}.check
2b90: 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66 74 73  _doclist_all fts
2ba0: 33 64 2d 34 2e 35 2e 31 2e 32 20 69 73 20 7b 5b  3d-4.5.1.2 is {[
2bb0: 31 20 30 5b 31 5d 5d 20 5b 33 20 30 5b 31 5d 5d  1 0[1]] [3 0[1]]
2bc0: 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73 74 5f  }.check_doclist_
2bd0: 61 6c 6c 20 66 74 73 33 64 2d 34 2e 35 2e 31 2e  all fts3d-4.5.1.
2be0: 33 20 74 65 73 74 20 7b 5b 31 20 30 5b 33 5d 5d  3 test {[1 0[3]]
2bf0: 20 5b 32 20 30 5b 33 5d 5d 20 5b 33 20 30 5b 33   [2 0[3]] [3 0[3
2c00: 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73  ]]}.check_doclis
2c10: 74 5f 61 6c 6c 20 66 74 73 33 64 2d 34 2e 35 2e  t_all fts3d-4.5.
2c20: 31 2e 34 20 74 68 61 74 20 7b 5b 32 20 30 5b 30  1.4 that {[2 0[0
2c30: 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c 69 73  ]]}.check_doclis
2c40: 74 5f 61 6c 6c 20 66 74 73 33 64 2d 34 2e 35 2e  t_all fts3d-4.5.
2c50: 31 2e 35 20 74 68 69 73 20 7b 5b 31 20 30 5b 30  1.5 this {[1 0[0
2c60: 5d 5d 20 5b 33 20 30 5b 30 5d 5d 7d 0a 63 68 65  ]] [3 0[0]]}.che
2c70: 63 6b 5f 64 6f 63 6c 69 73 74 5f 61 6c 6c 20 66  ck_doclist_all f
2c80: 74 73 33 64 2d 34 2e 35 2e 31 2e 36 20 77 61 73  ts3d-4.5.1.6 was
2c90: 20 7b 5b 32 20 30 5b 31 5d 5d 7d 0a 0a 63 68 65   {[2 0[1]]}..che
2ca0: 63 6b 5f 74 65 72 6d 73 20 66 74 73 33 64 2d 34  ck_terms fts3d-4
2cb0: 2e 35 2e 32 20 20 20 20 20 31 20 30 20 7b 61 20  .5.2     1 0 {a 
2cc0: 69 73 20 74 65 73 74 20 74 68 61 74 20 74 68 69  is test that thi
2cd0: 73 20 77 61 73 7d 0a 63 68 65 63 6b 5f 64 6f 63  s was}.check_doc
2ce0: 6c 69 73 74 20 66 74 73 33 64 2d 34 2e 35 2e 32  list fts3d-4.5.2
2cf0: 2e 31 20 31 20 30 20 61 20 7b 5b 31 20 30 5b 32  .1 1 0 a {[1 0[2
2d00: 5d 5d 20 5b 32 20 30 5b 32 5d 5d 20 5b 33 20 30  ]] [2 0[2]] [3 0
2d10: 5b 32 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f 63 6c  [2]]}.check_docl
2d20: 69 73 74 20 66 74 73 33 64 2d 34 2e 35 2e 32 2e  ist fts3d-4.5.2.
2d30: 32 20 31 20 30 20 69 73 20 7b 5b 31 20 30 5b 31  2 1 0 is {[1 0[1
2d40: 5d 5d 20 5b 33 20 30 5b 31 5d 5d 7d 0a 63 68 65  ]] [3 0[1]]}.che
2d50: 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73 33 64  ck_doclist fts3d
2d60: 2d 34 2e 35 2e 32 2e 33 20 31 20 30 20 74 65 73  -4.5.2.3 1 0 tes
2d70: 74 20 7b 5b 31 20 30 5b 33 5d 5d 20 5b 32 20 30  t {[1 0[3]] [2 0
2d80: 5b 33 5d 5d 20 5b 33 20 30 5b 33 5d 5d 7d 0a 63  [3]] [3 0[3]]}.c
2d90: 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73  heck_doclist fts
2da0: 33 64 2d 34 2e 35 2e 32 2e 34 20 31 20 30 20 74  3d-4.5.2.4 1 0 t
2db0: 68 61 74 20 7b 5b 32 20 30 5b 30 5d 5d 7d 0a 63  hat {[2 0[0]]}.c
2dc0: 68 65 63 6b 5f 64 6f 63 6c 69 73 74 20 66 74 73  heck_doclist fts
2dd0: 33 64 2d 34 2e 35 2e 32 2e 35 20 31 20 30 20 74  3d-4.5.2.5 1 0 t
2de0: 68 69 73 20 7b 5b 31 20 30 5b 30 5d 5d 20 5b 33  his {[1 0[0]] [3
2df0: 20 30 5b 30 5d 5d 7d 0a 63 68 65 63 6b 5f 64 6f   0[0]]}.check_do
2e00: 63 6c 69 73 74 20 66 74 73 33 64 2d 34 2e 35 2e  clist fts3d-4.5.
2e10: 32 2e 36 20 31 20 30 20 77 61 73 20 7b 5b 32 20  2.6 1 0 was {[2 
2e20: 30 5b 31 5d 5d 7d 0a 0a 23 20 52 65 2d 6f 70 74  0[1]]}..# Re-opt
2e30: 69 6d 69 7a 69 6e 67 20 64 6f 65 73 20 6e 6f 74  imizing does not
2e40: 68 69 6e 67 2e 0a 64 6f 5f 74 65 73 74 20 66 74  hing..do_test ft
2e50: 73 33 64 2d 35 2e 30 20 7b 0a 20 20 65 78 65 63  s3d-5.0 {.  exec
2e60: 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54  sql {.    SELECT
2e70: 20 4f 50 54 49 4d 49 5a 45 28 74 31 29 20 46 52   OPTIMIZE(t1) FR
2e80: 4f 4d 20 74 31 20 4c 49 4d 49 54 20 31 3b 0a 20  OM t1 LIMIT 1;. 
2e90: 20 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c     SELECT level,
2ea0: 20 69 64 78 20 46 52 4f 4d 20 74 31 5f 73 65 67   idx FROM t1_seg
2eb0: 64 69 72 20 4f 52 44 45 52 20 42 59 20 6c 65 76  dir ORDER BY lev
2ec0: 65 6c 2c 20 69 64 78 3b 0a 20 20 7d 0a 7d 20 7b  el, idx;.  }.} {
2ed0: 7b 49 6e 64 65 78 20 61 6c 72 65 61 64 79 20 6f  {Index already o
2ee0: 70 74 69 6d 61 6c 7d 20 31 20 30 7d 0a 0a 23 20  ptimal} 1 0}..# 
2ef0: 45 76 65 6e 20 69 66 20 77 65 20 6d 6f 76 65 20  Even if we move 
2f00: 74 68 69 6e 67 73 20 61 72 6f 75 6e 64 2c 20 73  things around, s
2f10: 74 69 6c 6c 20 64 6f 65 73 20 6e 6f 74 68 69 6e  till does nothin
2f20: 67 2e 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 64  g..do_test fts3d
2f30: 2d 35 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c  -5.1 {.  execsql
2f40: 20 7b 0a 20 20 20 20 55 50 44 41 54 45 20 74 31   {.    UPDATE t1
2f50: 5f 73 65 67 64 69 72 20 53 45 54 20 6c 65 76 65  _segdir SET leve
2f60: 6c 20 3d 20 32 20 57 48 45 52 45 20 6c 65 76 65  l = 2 WHERE leve
2f70: 6c 20 3d 20 31 20 41 4e 44 20 69 64 78 20 3d 20  l = 1 AND idx = 
2f80: 30 3b 0a 20 20 20 20 53 45 4c 45 43 54 20 4f 50  0;.    SELECT OP
2f90: 54 49 4d 49 5a 45 28 74 31 29 20 46 52 4f 4d 20  TIMIZE(t1) FROM 
2fa0: 74 31 20 4c 49 4d 49 54 20 31 3b 0a 20 20 20 20  t1 LIMIT 1;.    
2fb0: 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69 64  SELECT level, id
2fc0: 78 20 46 52 4f 4d 20 74 31 5f 73 65 67 64 69 72  x FROM t1_segdir
2fd0: 20 4f 52 44 45 52 20 42 59 20 6c 65 76 65 6c 2c   ORDER BY level,
2fe0: 20 69 64 78 3b 0a 20 20 7d 0a 7d 20 7b 7b 49 6e   idx;.  }.} {{In
2ff0: 64 65 78 20 61 6c 72 65 61 64 79 20 6f 70 74 69  dex already opti
3000: 6d 61 6c 7d 20 32 20 30 7d 0a 0a 66 69 6e 69 73  mal} 2 0}..finis
3010: 68 5f 74 65 73 74 0a                             h_test.