/ Hex Artifact Content
Login

Artifact e5390da74619cacc389711bac9349640b32c4f9a:


0000: 23 20 32 30 31 34 20 4d 61 79 20 31 32 0a 23 0a  # 2014 May 12.#.
0010: 23 20 54 68 65 20 61 75 74 68 6f 72 20 64 69 73  # The author dis
0020: 63 6c 61 69 6d 73 20 63 6f 70 79 72 69 67 68 74  claims copyright
0030: 20 74 6f 20 74 68 69 73 20 73 6f 75 72 63 65 20   to this source 
0040: 63 6f 64 65 2e 20 20 49 6e 20 70 6c 61 63 65 20  code.  In place 
0050: 6f 66 0a 23 20 61 20 6c 65 67 61 6c 20 6e 6f 74  of.# a legal not
0060: 69 63 65 2c 20 68 65 72 65 20 69 73 20 61 20 62  ice, here is a b
0070: 6c 65 73 73 69 6e 67 3a 0a 23 0a 23 20 20 20 20  lessing:.#.#    
0080: 4d 61 79 20 79 6f 75 20 64 6f 20 67 6f 6f 64 20  May you do good 
0090: 61 6e 64 20 6e 6f 74 20 65 76 69 6c 2e 0a 23 20  and not evil..# 
00a0: 20 20 20 4d 61 79 20 79 6f 75 20 66 69 6e 64 20     May you find 
00b0: 66 6f 72 67 69 76 65 6e 65 73 73 20 66 6f 72 20  forgiveness for 
00c0: 79 6f 75 72 73 65 6c 66 20 61 6e 64 20 66 6f 72  yourself and for
00d0: 67 69 76 65 20 6f 74 68 65 72 73 2e 0a 23 20 20  give others..#  
00e0: 20 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65 20    May you share 
00f0: 66 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74 61  freely, never ta
0100: 6b 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20 79  king more than y
0110: 6f 75 20 67 69 76 65 2e 0a 23 0a 23 2a 2a 2a 2a  ou 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 0a 23 20 54 68 69 73 20 66 69 6c  *****.# This fil
0170: 65 20 69 6d 70 6c 65 6d 65 6e 74 73 20 72 65 67  e implements reg
0180: 72 65 73 73 69 6f 6e 20 74 65 73 74 73 20 66 6f  ression tests fo
0190: 72 20 53 51 4c 69 74 65 20 6c 69 62 72 61 72 79  r SQLite library
01a0: 2e 20 20 54 68 65 0a 23 20 66 6f 63 75 73 20 6f  .  The.# focus o
01b0: 66 20 74 68 69 73 20 73 63 72 69 70 74 20 69 73  f this script is
01c0: 20 74 65 73 74 69 6e 67 20 74 68 65 20 46 54 53   testing the FTS
01d0: 34 20 6d 6f 64 75 6c 65 2e 0a 23 0a 23 0a 0a 73  4 module..#.#..s
01e0: 65 74 20 74 65 73 74 64 69 72 20 5b 66 69 6c 65  et testdir [file
01f0: 20 64 69 72 6e 61 6d 65 20 24 61 72 67 76 30 5d   dirname $argv0]
0200: 0a 73 6f 75 72 63 65 20 24 74 65 73 74 64 69 72  .source $testdir
0210: 2f 74 65 73 74 65 72 2e 74 63 6c 0a 73 65 74 20  /tester.tcl.set 
0220: 74 65 73 74 70 72 65 66 69 78 20 66 74 73 34 67  testprefix fts4g
0230: 72 6f 77 74 68 0a 0a 23 20 49 66 20 53 51 4c 49  rowth..# If SQLI
0240: 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 33 20 69  TE_ENABLE_FTS3 i
0250: 73 20 64 65 66 69 6e 65 64 2c 20 6f 6d 69 74 20  s defined, omit 
0260: 74 68 69 73 20 66 69 6c 65 2e 0a 69 66 63 61 70  this file..ifcap
0270: 61 62 6c 65 20 21 66 74 73 33 20 7b 0a 20 20 66  able !fts3 {.  f
0280: 69 6e 69 73 68 5f 74 65 73 74 0a 20 20 72 65 74  inish_test.  ret
0290: 75 72 6e 0a 7d 0a 0a 73 6f 75 72 63 65 20 24 74  urn.}..source $t
02a0: 65 73 74 64 69 72 2f 67 65 6e 65 73 69 73 2e 74  estdir/genesis.t
02b0: 63 6c 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  cl..do_execsql_t
02c0: 65 73 74 20 31 2e 31 20 7b 20 43 52 45 41 54 45  est 1.1 { CREATE
02d0: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 78   VIRTUAL TABLE x
02e0: 31 20 55 53 49 4e 47 20 66 74 73 33 3b 20 7d 0a  1 USING fts3; }.
02f0: 0a 64 6f 5f 74 65 73 74 20 31 2e 32 20 7b 0a 20  .do_test 1.2 {. 
0300: 20 66 6f 72 65 61 63 68 20 4c 20 7b 0a 20 20 20   foreach L {.   
0310: 20 7b 22 53 65 65 20 68 65 72 65 2c 20 79 6f 75   {"See here, you
0320: 6e 67 20 6d 61 6e 2c 22 20 73 61 69 64 20 4d 75  ng man," said Mu
0330: 6c 67 61 20 42 69 6c 6c 2c 20 22 66 72 6f 6d 20  lga Bill, "from 
0340: 57 61 6c 67 65 74 74 20 74 6f 20 74 68 65 20 73  Walgett to the s
0350: 65 61 2c 7d 0a 20 20 20 20 7b 46 72 6f 6d 20 43  ea,}.    {From C
0360: 6f 6e 72 6f 79 27 73 20 47 61 70 20 74 6f 20 43  onroy's Gap to C
0370: 61 73 74 6c 65 72 65 61 67 68 2c 20 74 68 65 72  astlereagh, ther
0380: 65 27 73 20 6e 6f 6e 65 20 63 61 6e 20 72 69 64  e's none can rid
0390: 65 20 6c 69 6b 65 20 6d 65 2e 7d 0a 20 20 20 20  e like me.}.    
03a0: 7b 49 27 6d 20 67 6f 6f 64 20 61 6c 6c 20 72 6f  {I'm good all ro
03b0: 75 6e 64 20 61 74 20 65 76 65 72 79 74 68 69 6e  und at everythin
03c0: 67 20 61 73 20 65 76 65 72 79 62 6f 64 79 20 6b  g as everybody k
03d0: 6e 6f 77 73 2c 7d 0a 20 20 20 20 7b 41 6c 74 68  nows,}.    {Alth
03e0: 6f 75 67 68 20 49 27 6d 20 6e 6f 74 20 74 68 65  ough I'm not the
03f0: 20 6f 6e 65 20 74 6f 20 74 61 6c 6b 20 2d 2d 20   one to talk -- 
0400: 49 20 68 61 74 65 20 61 20 6d 61 6e 20 74 68 61  I hate a man tha
0410: 74 20 62 6c 6f 77 73 2e 7d 0a 20 20 7d 20 7b 0a  t blows.}.  } {.
0420: 20 20 20 20 65 78 65 63 73 71 6c 20 7b 20 49 4e      execsql { IN
0430: 53 45 52 54 20 49 4e 54 4f 20 78 31 20 56 41 4c  SERT INTO x1 VAL
0440: 55 45 53 28 24 4c 29 20 7d 0a 20 20 7d 0a 20 20  UES($L) }.  }.  
0450: 65 78 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54  execsql { SELECT
0460: 20 65 6e 64 5f 62 6c 6f 63 6b 2c 20 6c 65 6e 67   end_block, leng
0470: 74 68 28 72 6f 6f 74 29 20 46 52 4f 4d 20 78 31  th(root) FROM x1
0480: 5f 73 65 67 64 69 72 20 7d 0a 7d 20 7b 7b 30 20  _segdir }.} {{0 
0490: 31 31 34 7d 20 31 31 34 20 7b 30 20 31 31 38 7d  114} 114 {0 118}
04a0: 20 31 31 38 20 7b 30 20 39 35 7d 20 39 35 20 7b   118 {0 95} 95 {
04b0: 30 20 31 31 35 7d 20 31 31 35 7d 0a 0a 64 6f 5f  0 115} 115}..do_
04c0: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31 2e 33  execsql_test 1.3
04d0: 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f   {.  INSERT INTO
04e0: 20 78 31 28 78 31 29 20 56 41 4c 55 45 53 28 27   x1(x1) VALUES('
04f0: 6f 70 74 69 6d 69 7a 65 27 29 3b 0a 20 20 53 45  optimize');.  SE
0500: 4c 45 43 54 20 6c 65 76 65 6c 2c 20 65 6e 64 5f  LECT level, end_
0510: 62 6c 6f 63 6b 2c 20 6c 65 6e 67 74 68 28 72 6f  block, length(ro
0520: 6f 74 29 20 46 52 4f 4d 20 78 31 5f 73 65 67 64  ot) FROM x1_segd
0530: 69 72 3b 0a 7d 20 7b 30 20 7b 30 20 33 39 34 7d  ir;.} {0 {0 394}
0540: 20 33 39 34 7d 0a 0a 64 6f 5f 74 65 73 74 20 31   394}..do_test 1
0550: 2e 34 20 7b 0a 20 20 66 6f 72 65 61 63 68 20 4c  .4 {.  foreach L
0560: 20 7b 0a 20 20 20 20 7b 42 75 74 20 72 69 64 69   {.    {But ridi
0570: 6e 67 20 69 73 20 6d 79 20 73 70 65 63 69 61 6c  ng is my special
0580: 20 67 69 66 74 2c 20 6d 79 20 63 68 69 65 66 65   gift, my chiefe
0590: 73 74 2c 20 73 6f 6c 65 20 64 65 6c 69 67 68 74  st, sole delight
05a0: 3b 7d 0a 20 20 20 20 7b 4a 75 73 74 20 61 73 6b  ;}.    {Just ask
05b0: 20 61 20 77 69 6c 64 20 64 75 63 6b 20 63 61 6e   a wild duck can
05c0: 20 69 74 20 73 77 69 6d 2c 20 61 20 77 69 6c 64   it swim, a wild
05d0: 63 61 74 20 63 61 6e 20 69 74 20 66 69 67 68 74  cat can it fight
05e0: 2e 7d 0a 20 20 20 20 7b 54 68 65 72 65 27 73 20  .}.    {There's 
05f0: 6e 6f 74 68 69 6e 67 20 63 6c 6f 74 68 65 64 20  nothing clothed 
0600: 69 6e 20 68 61 69 72 20 6f 72 20 68 69 64 65 2c  in hair or hide,
0610: 20 6f 72 20 62 75 69 6c 74 20 6f 66 20 66 6c 65   or built of fle
0620: 73 68 20 6f 72 20 73 74 65 65 6c 2c 7d 0a 20 20  sh or steel,}.  
0630: 20 20 7b 54 68 65 72 65 27 73 20 6e 6f 74 68 69    {There's nothi
0640: 6e 67 20 77 61 6c 6b 73 20 6f 72 20 6a 75 6d 70  ng walks or jump
0650: 73 2c 20 6f 72 20 72 75 6e 73 2c 20 6f 6e 20 61  s, or runs, on a
0660: 78 6c 65 2c 20 68 6f 6f 66 2c 20 6f 72 20 77 68  xle, hoof, or wh
0670: 65 65 6c 2c 7d 0a 20 20 20 20 7b 42 75 74 20 77  eel,}.    {But w
0680: 68 61 74 20 49 27 6c 6c 20 73 69 74 2c 20 77 68  hat I'll sit, wh
0690: 69 6c 65 20 68 69 64 65 20 77 69 6c 6c 20 68 6f  ile hide will ho
06a0: 6c 64 20 61 6e 64 20 67 69 72 74 68 73 20 61 6e  ld and girths an
06b0: 64 20 73 74 72 61 70 73 20 61 72 65 20 74 69 67  d straps are tig
06c0: 68 74 3a 7d 0a 20 20 20 20 7b 49 27 6c 6c 20 72  ht:}.    {I'll r
06d0: 69 64 65 20 74 68 69 73 20 68 65 72 65 20 74 77  ide this here tw
06e0: 6f 2d 77 68 65 65 6c 65 64 20 63 6f 6e 63 65 72  o-wheeled concer
06f0: 6e 20 72 69 67 68 74 20 73 74 72 61 69 67 68 74  n right straight
0700: 20 61 77 61 79 20 61 74 20 73 69 67 68 74 2e 22   away at sight."
0710: 7d 0a 20 20 7d 20 7b 0a 20 20 20 20 65 78 65 63  }.  } {.    exec
0720: 73 71 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54  sql { INSERT INT
0730: 4f 20 78 31 20 56 41 4c 55 45 53 28 24 4c 29 20  O x1 VALUES($L) 
0740: 7d 0a 20 20 7d 0a 20 20 65 78 65 63 73 71 6c 20  }.  }.  execsql 
0750: 7b 20 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e  { .    INSERT IN
0760: 54 4f 20 78 31 28 78 31 29 20 56 41 4c 55 45 53  TO x1(x1) VALUES
0770: 28 27 6d 65 72 67 65 3d 34 2c 34 27 29 3b 0a 20  ('merge=4,4');. 
0780: 20 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c     SELECT level,
0790: 20 65 6e 64 5f 62 6c 6f 63 6b 2c 20 6c 65 6e 67   end_block, leng
07a0: 74 68 28 72 6f 6f 74 29 20 46 52 4f 4d 20 78 31  th(root) FROM x1
07b0: 5f 73 65 67 64 69 72 3b 0a 20 20 7d 0a 7d 20 7b  _segdir;.  }.} {
07c0: 31 20 7b 32 32 34 20 39 32 31 7d 20 32 7d 0a 0a  1 {224 921} 2}..
07d0: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
07e0: 31 2e 35 20 7b 0a 20 20 53 45 4c 45 43 54 20 6c  1.5 {.  SELECT l
07f0: 65 6e 67 74 68 28 62 6c 6f 63 6b 29 20 46 52 4f  ength(block) FRO
0800: 4d 20 78 31 5f 73 65 67 6d 65 6e 74 73 3b 0a 7d  M x1_segments;.}
0810: 20 7b 39 32 31 20 7b 7d 7d 0a 0a 64 6f 5f 74 65   {921 {}}..do_te
0820: 73 74 20 31 2e 36 20 7b 0a 20 20 66 6f 72 65 61  st 1.6 {.  forea
0830: 63 68 20 4c 20 7b 0a 20 20 20 20 7b 27 54 77 61  ch L {.    {'Twa
0840: 73 20 4d 75 6c 67 61 20 42 69 6c 6c 2c 20 66 72  s Mulga Bill, fr
0850: 6f 6d 20 45 61 67 6c 65 68 61 77 6b 2c 20 74 68  om Eaglehawk, th
0860: 61 74 20 73 6f 75 67 68 74 20 68 69 73 20 6f 77  at sought his ow
0870: 6e 20 61 62 6f 64 65 2c 7d 0a 20 20 20 20 7b 54  n abode,}.    {T
0880: 68 61 74 20 70 65 72 63 68 65 64 20 61 62 6f 76  hat perched abov
0890: 65 20 44 65 61 64 20 4d 61 6e 27 73 20 43 72 65  e Dead Man's Cre
08a0: 65 6b 2c 20 62 65 73 69 64 65 20 74 68 65 20 6d  ek, beside the m
08b0: 6f 75 6e 74 61 69 6e 20 72 6f 61 64 2e 7d 0a 20  ountain road.}. 
08c0: 20 20 20 7b 48 65 20 74 75 72 6e 65 64 20 74 68     {He turned th
08d0: 65 20 63 79 63 6c 65 20 64 6f 77 6e 20 74 68 65  e cycle down the
08e0: 20 68 69 6c 6c 20 61 6e 64 20 6d 6f 75 6e 74 65   hill and mounte
08f0: 64 20 66 6f 72 20 74 68 65 20 66 72 61 79 2c 7d  d for the fray,}
0900: 0a 20 20 20 20 7b 42 75 74 20 27 65 72 65 20 68  .    {But 'ere h
0910: 65 27 64 20 67 6f 6e 65 20 61 20 64 6f 7a 65 6e  e'd gone a dozen
0920: 20 79 61 72 64 73 20 69 74 20 62 6f 6c 74 65 64   yards it bolted
0930: 20 63 6c 65 61 6e 20 61 77 61 79 2e 7d 0a 0a 20   clean away.}.. 
0940: 20 20 20 7b 49 74 20 6c 65 66 74 20 74 68 65 20     {It left the 
0950: 74 72 61 63 6b 2c 20 61 6e 64 20 74 68 72 6f 75  track, and throu
0960: 67 68 20 74 68 65 20 74 72 65 65 73 2c 20 6a 75  gh the trees, ju
0970: 73 74 20 6c 69 6b 65 20 61 20 73 69 6c 76 65 72  st like a silver
0980: 20 73 74 65 61 6b 2c 7d 0a 20 20 20 20 7b 49 74   steak,}.    {It
0990: 20 77 68 69 73 74 6c 65 64 20 64 6f 77 6e 20 74   whistled down t
09a0: 68 65 20 61 77 66 75 6c 20 73 6c 6f 70 65 20 74  he awful slope t
09b0: 6f 77 61 72 64 73 20 74 68 65 20 44 65 61 64 20  owards the Dead 
09c0: 4d 61 6e 27 73 20 43 72 65 65 6b 2e 7d 0a 20 20  Man's Creek.}.  
09d0: 20 20 7b 49 74 20 73 68 61 76 65 64 20 61 20 73    {It shaved a s
09e0: 74 75 6d 70 20 62 79 20 68 61 6c 66 20 61 6e 20  tump by half an 
09f0: 69 6e 63 68 2c 20 69 74 20 64 6f 64 67 65 64 20  inch, it dodged 
0a00: 61 20 62 69 67 20 77 68 69 74 65 2d 62 6f 78 3a  a big white-box:
0a10: 7d 0a 20 20 20 20 7b 54 68 65 20 76 65 72 79 20  }.    {The very 
0a20: 77 61 6c 6c 61 72 6f 6f 73 20 69 6e 20 66 72 69  wallaroos in fri
0a30: 67 68 74 20 77 65 6e 74 20 73 63 72 61 6d 62 6c  ght went scrambl
0a40: 69 6e 67 20 75 70 20 74 68 65 20 72 6f 63 6b 73  ing up the rocks
0a50: 2c 7d 0a 0a 20 20 20 20 7b 54 68 65 20 77 6f 6d  ,}..    {The wom
0a60: 62 61 74 73 20 68 69 64 69 6e 67 20 69 6e 20 74  bats hiding in t
0a70: 68 65 69 72 20 63 61 76 65 73 20 64 75 67 20 64  heir caves dug d
0a80: 65 65 70 65 72 20 75 6e 64 65 72 67 72 6f 75 6e  eeper undergroun
0a90: 64 2c 7d 0a 20 20 20 20 7b 41 73 20 4d 75 6c 67  d,}.    {As Mulg
0aa0: 61 20 42 69 6c 6c 2c 20 61 73 20 77 68 69 74 65  a Bill, as white
0ab0: 20 61 73 20 63 68 61 6c 6b 2c 20 73 61 74 20 74   as chalk, sat t
0ac0: 69 67 68 74 20 74 6f 20 65 76 65 72 79 20 62 6f  ight to every bo
0ad0: 75 6e 64 2e 7d 0a 20 20 20 20 7b 49 74 20 73 74  und.}.    {It st
0ae0: 72 75 63 6b 20 61 20 73 74 6f 6e 65 20 61 6e 64  ruck a stone and
0af0: 20 67 61 76 65 20 61 20 73 70 72 69 6e 67 20 74   gave a spring t
0b00: 68 61 74 20 63 6c 65 61 72 65 64 20 61 20 66 61  hat cleared a fa
0b10: 6c 6c 65 6e 20 74 72 65 65 2c 7d 0a 20 20 20 20  llen tree,}.    
0b20: 7b 49 74 20 72 61 63 65 64 20 62 65 73 69 64 65  {It raced beside
0b30: 20 61 20 70 72 65 63 69 70 69 63 65 20 61 73 20   a precipice as 
0b40: 63 6c 6f 73 65 20 61 73 20 63 6c 6f 73 65 20 63  close as close c
0b50: 6f 75 6c 64 20 62 65 3b 7d 0a 0a 20 20 20 20 7b  ould be;}..    {
0b60: 41 6e 64 20 74 68 65 6e 20 61 73 20 4d 75 6c 67  And then as Mulg
0b70: 61 20 42 69 6c 6c 20 6c 65 74 20 6f 75 74 20 6f  a Bill let out o
0b80: 6e 65 20 6c 61 73 74 20 64 65 73 70 61 69 72 69  ne last despairi
0b90: 6e 67 20 73 68 72 69 65 6b 7d 0a 20 20 20 20 7b  ng shriek}.    {
0ba0: 49 74 20 6d 61 64 65 20 61 20 6c 65 61 70 20 6f  It made a leap o
0bb0: 66 20 74 77 65 6e 74 79 20 66 65 65 74 20 69 6e  f twenty feet in
0bc0: 74 6f 20 74 68 65 20 44 65 61 64 20 4d 61 6e 27  to the Dead Man'
0bd0: 73 20 43 72 65 65 6b 2e 7d 0a 20 20 20 20 7b 49  s Creek.}.    {I
0be0: 74 20 73 68 61 76 65 64 20 61 20 73 74 75 6d 70  t shaved a stump
0bf0: 20 62 79 20 68 61 6c 66 20 61 6e 20 69 6e 63 68   by half an inch
0c00: 2c 20 69 74 20 64 6f 64 67 65 64 20 61 20 62 69  , it dodged a bi
0c10: 67 20 77 68 69 74 65 2d 62 6f 78 3a 7d 0a 20 20  g white-box:}.  
0c20: 20 20 7b 54 68 65 20 76 65 72 79 20 77 61 6c 6c    {The very wall
0c30: 61 72 6f 6f 73 20 69 6e 20 66 72 69 67 68 74 20  aroos in fright 
0c40: 77 65 6e 74 20 73 63 72 61 6d 62 6c 69 6e 67 20  went scrambling 
0c50: 75 70 20 74 68 65 20 72 6f 63 6b 73 2c 7d 0a 20  up the rocks,}. 
0c60: 20 20 20 7b 54 68 65 20 77 6f 6d 62 61 74 73 20     {The wombats 
0c70: 68 69 64 69 6e 67 20 69 6e 20 74 68 65 69 72 20  hiding in their 
0c80: 63 61 76 65 73 20 64 75 67 20 64 65 65 70 65 72  caves dug deeper
0c90: 20 75 6e 64 65 72 67 72 6f 75 6e 64 2c 7d 0a 20   underground,}. 
0ca0: 20 7d 20 7b 0a 20 20 20 20 65 78 65 63 73 71 6c   } {.    execsql
0cb0: 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78   { INSERT INTO x
0cc0: 31 20 56 41 4c 55 45 53 28 24 4c 29 20 7d 0a 20  1 VALUES($L) }. 
0cd0: 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 0a   }.  execsql { .
0ce0: 20 20 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c      SELECT level
0cf0: 2c 20 65 6e 64 5f 62 6c 6f 63 6b 2c 20 6c 65 6e  , end_block, len
0d00: 67 74 68 28 72 6f 6f 74 29 20 46 52 4f 4d 20 78  gth(root) FROM x
0d10: 31 5f 73 65 67 64 69 72 3b 0a 20 20 7d 0a 7d 20  1_segdir;.  }.} 
0d20: 7b 31 20 7b 32 32 34 20 39 32 31 7d 20 32 20 31  {1 {224 921} 2 1
0d30: 20 7b 32 32 36 20 31 32 33 30 7d 20 37 20 30 20   {226 1230} 7 0 
0d40: 7b 30 20 39 38 7d 20 39 38 7d 0a 0a 64 6f 5f 65  {0 98} 98}..do_e
0d50: 78 65 63 73 71 6c 5f 74 65 73 74 20 31 2e 37 20  xecsql_test 1.7 
0d60: 7b 0a 20 20 53 45 4c 45 43 54 20 73 75 6d 28 6c  {.  SELECT sum(l
0d70: 65 6e 67 74 68 28 62 6c 6f 63 6b 29 29 20 46 52  ength(block)) FR
0d80: 4f 4d 20 78 31 5f 73 65 67 6d 65 6e 74 73 20 57  OM x1_segments W
0d90: 48 45 52 45 20 62 6c 6f 63 6b 69 64 20 49 4e 20  HERE blockid IN 
0da0: 28 32 32 34 2c 32 32 35 2c 32 32 36 29 0a 7d 20  (224,225,226).} 
0db0: 7b 31 32 33 30 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d  {1230}..#-------
0dc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0dd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0de0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0df0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e00: 2d 2d 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  --.#.do_execsql_
0e10: 74 65 73 74 20 32 2e 31 20 7b 20 0a 20 20 43 52  test 2.1 { .  CR
0e20: 45 41 54 45 20 54 41 42 4c 45 20 74 31 28 64 6f  EATE TABLE t1(do
0e30: 63 69 64 2c 20 77 6f 72 64 73 29 3b 0a 20 20 43  cid, words);.  C
0e40: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
0e50: 42 4c 45 20 78 32 20 55 53 49 4e 47 20 66 74 73  BLE x2 USING fts
0e60: 34 3b 0a 7d 0a 66 74 73 5f 6b 6a 76 5f 67 65 6e  4;.}.fts_kjv_gen
0e70: 65 73 69 73 20 0a 64 6f 5f 74 65 73 74 20 32 2e  esis .do_test 2.
0e80: 32 20 7b 0a 20 20 66 6f 72 65 61 63 68 20 69 64  2 {.  foreach id
0e90: 20 5b 64 62 20 65 76 61 6c 20 7b 53 45 4c 45 43   [db eval {SELEC
0ea0: 54 20 64 6f 63 69 64 20 46 52 4f 4d 20 74 31 7d  T docid FROM t1}
0eb0: 5d 20 7b 0a 20 20 20 20 65 78 65 63 73 71 6c 20  ] {.    execsql 
0ec0: 7b 0a 20 20 20 20 20 20 49 4e 53 45 52 54 20 49  {.      INSERT I
0ed0: 4e 54 4f 20 78 32 28 64 6f 63 69 64 2c 20 63 6f  NTO x2(docid, co
0ee0: 6e 74 65 6e 74 29 20 53 45 4c 45 43 54 20 24 69  ntent) SELECT $i
0ef0: 64 2c 20 77 6f 72 64 73 20 46 52 4f 4d 20 74 31  d, words FROM t1
0f00: 20 57 48 45 52 45 20 64 6f 63 69 64 3d 24 69 64   WHERE docid=$id
0f10: 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 66 6f 72  .    }.  }.  for
0f20: 65 61 63 68 20 69 64 20 5b 64 62 20 65 76 61 6c  each id [db eval
0f30: 20 7b 53 45 4c 45 43 54 20 64 6f 63 69 64 20 46   {SELECT docid F
0f40: 52 4f 4d 20 74 31 7d 5d 20 7b 0a 20 20 20 20 65  ROM t1}] {.    e
0f50: 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 20 20 49  xecsql {.      I
0f60: 4e 53 45 52 54 20 49 4e 54 4f 20 78 32 28 64 6f  NSERT INTO x2(do
0f70: 63 69 64 2c 20 63 6f 6e 74 65 6e 74 29 20 53 45  cid, content) SE
0f80: 4c 45 43 54 20 4e 55 4c 4c 2c 20 77 6f 72 64 73  LECT NULL, words
0f90: 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 64   FROM t1 WHERE d
0fa0: 6f 63 69 64 3d 24 69 64 0a 20 20 20 20 7d 0a 20  ocid=$id.    }. 
0fb0: 20 20 20 69 66 20 7b 5b 64 62 20 6f 6e 65 20 7b     if {[db one {
0fc0: 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20  SELECT count(*) 
0fd0: 46 52 4f 4d 20 78 32 5f 73 65 67 64 69 72 20 57  FROM x2_segdir W
0fe0: 48 45 52 45 20 6c 65 76 65 6c 3c 32 7d 5d 3d 3d  HERE level<2}]==
0ff0: 32 7d 20 62 72 65 61 6b 0a 20 20 7d 0a 7d 20 7b  2} break.  }.} {
1000: 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  }..do_execsql_te
1010: 73 74 20 32 2e 33 20 7b 20 0a 20 20 53 45 4c 45  st 2.3 { .  SELE
1020: 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d  CT count(*) FROM
1030: 20 78 32 5f 73 65 67 64 69 72 20 57 48 45 52 45   x2_segdir WHERE
1040: 20 6c 65 76 65 6c 3d 32 3b 0a 20 20 53 45 4c 45   level=2;.  SELE
1050: 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d  CT count(*) FROM
1060: 20 78 32 5f 73 65 67 64 69 72 20 57 48 45 52 45   x2_segdir WHERE
1070: 20 6c 65 76 65 6c 3d 33 3b 0a 7d 20 7b 36 20 30   level=3;.} {6 0
1080: 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  }..do_execsql_te
1090: 73 74 20 32 2e 34 20 7b 20 0a 20 20 49 4e 53 45  st 2.4 { .  INSE
10a0: 52 54 20 49 4e 54 4f 20 78 32 28 78 32 29 20 56  RT INTO x2(x2) V
10b0: 41 4c 55 45 53 28 27 6d 65 72 67 65 3d 34 2c 34  ALUES('merge=4,4
10c0: 27 29 3b 0a 20 20 53 45 4c 45 43 54 20 63 6f 75  ');.  SELECT cou
10d0: 6e 74 28 2a 29 20 46 52 4f 4d 20 78 32 5f 73 65  nt(*) FROM x2_se
10e0: 67 64 69 72 20 57 48 45 52 45 20 6c 65 76 65 6c  gdir WHERE level
10f0: 3d 32 3b 0a 20 20 53 45 4c 45 43 54 20 63 6f 75  =2;.  SELECT cou
1100: 6e 74 28 2a 29 20 46 52 4f 4d 20 78 32 5f 73 65  nt(*) FROM x2_se
1110: 67 64 69 72 20 57 48 45 52 45 20 6c 65 76 65 6c  gdir WHERE level
1120: 3d 33 3b 0a 7d 20 7b 36 20 31 7d 0a 0a 64 6f 5f  =3;.} {6 1}..do_
1130: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 32 2e 35  execsql_test 2.5
1140: 20 7b 20 0a 20 20 53 45 4c 45 43 54 20 65 6e 64   { .  SELECT end
1150: 5f 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 32 5f 73  _block FROM x2_s
1160: 65 67 64 69 72 20 57 48 45 52 45 20 6c 65 76 65  egdir WHERE leve
1170: 6c 3d 33 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e  l=3;.  INSERT IN
1180: 54 4f 20 78 32 28 78 32 29 20 56 41 4c 55 45 53  TO x2(x2) VALUES
1190: 28 27 6d 65 72 67 65 3d 34 2c 34 27 29 3b 0a 20  ('merge=4,4');. 
11a0: 20 53 45 4c 45 43 54 20 65 6e 64 5f 62 6c 6f 63   SELECT end_bloc
11b0: 6b 20 46 52 4f 4d 20 78 32 5f 73 65 67 64 69 72  k FROM x2_segdir
11c0: 20 57 48 45 52 45 20 6c 65 76 65 6c 3d 33 3b 0a   WHERE level=3;.
11d0: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 32    INSERT INTO x2
11e0: 28 78 32 29 20 56 41 4c 55 45 53 28 27 6d 65 72  (x2) VALUES('mer
11f0: 67 65 3d 34 2c 34 27 29 3b 0a 20 20 53 45 4c 45  ge=4,4');.  SELE
1200: 43 54 20 65 6e 64 5f 62 6c 6f 63 6b 20 46 52 4f  CT end_block FRO
1210: 4d 20 78 32 5f 73 65 67 64 69 72 20 57 48 45 52  M x2_segdir WHER
1220: 45 20 6c 65 76 65 6c 3d 33 3b 0a 7d 20 7b 7b 35  E level=3;.} {{5
1230: 35 38 38 20 2d 33 39 35 30 7d 20 7b 35 35 38 38  588 -3950} {5588
1240: 20 2d 31 31 37 36 36 7d 20 7b 35 35 38 38 20 2d   -11766} {5588 -
1250: 31 35 35 34 31 7d 7d 0a 0a 64 6f 5f 65 78 65 63  15541}}..do_exec
1260: 73 71 6c 5f 74 65 73 74 20 32 2e 36 20 7b 0a 20  sql_test 2.6 {. 
1270: 20 53 45 4c 45 43 54 20 73 75 6d 28 6c 65 6e 67   SELECT sum(leng
1280: 74 68 28 62 6c 6f 63 6b 29 29 20 46 52 4f 4d 20  th(block)) FROM 
1290: 78 32 5f 73 65 67 64 69 72 2c 20 78 32 5f 73 65  x2_segdir, x2_se
12a0: 67 6d 65 6e 74 73 20 57 48 45 52 45 20 0a 20 20  gments WHERE .  
12b0: 20 20 62 6c 6f 63 6b 69 64 20 42 45 54 57 45 45    blockid BETWEE
12c0: 4e 20 73 74 61 72 74 5f 62 6c 6f 63 6b 20 41 4e  N start_block AN
12d0: 44 20 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f  D leaves_end_blo
12e0: 63 6b 0a 20 20 20 20 41 4e 44 20 6c 65 76 65 6c  ck.    AND level
12f0: 3d 33 0a 7d 20 7b 31 35 35 34 31 7d 0a 0a 64 6f  =3.} {15541}..do
1300: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 32 2e  _execsql_test 2.
1310: 37 20 7b 20 0a 20 20 49 4e 53 45 52 54 20 49 4e  7 { .  INSERT IN
1320: 54 4f 20 78 32 28 78 32 29 20 56 41 4c 55 45 53  TO x2(x2) VALUES
1330: 28 27 6d 65 72 67 65 3d 31 30 30 30 2c 34 27 29  ('merge=1000,4')
1340: 3b 0a 20 20 53 45 4c 45 43 54 20 65 6e 64 5f 62  ;.  SELECT end_b
1350: 6c 6f 63 6b 20 46 52 4f 4d 20 78 32 5f 73 65 67  lock FROM x2_seg
1360: 64 69 72 20 57 48 45 52 45 20 6c 65 76 65 6c 3d  dir WHERE level=
1370: 33 3b 0a 7d 20 7b 7b 35 35 38 38 20 31 32 37 35  3;.} {{5588 1275
1380: 36 33 7d 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c  63}}..do_execsql
1390: 5f 74 65 73 74 20 32 2e 38 20 7b 0a 20 20 53 45  _test 2.8 {.  SE
13a0: 4c 45 43 54 20 73 75 6d 28 6c 65 6e 67 74 68 28  LECT sum(length(
13b0: 62 6c 6f 63 6b 29 29 20 46 52 4f 4d 20 78 32 5f  block)) FROM x2_
13c0: 73 65 67 64 69 72 2c 20 78 32 5f 73 65 67 6d 65  segdir, x2_segme
13d0: 6e 74 73 20 57 48 45 52 45 20 0a 20 20 20 20 62  nts WHERE .    b
13e0: 6c 6f 63 6b 69 64 20 42 45 54 57 45 45 4e 20 73  lockid BETWEEN s
13f0: 74 61 72 74 5f 62 6c 6f 63 6b 20 41 4e 44 20 6c  tart_block AND l
1400: 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b 0a  eaves_end_block.
1410: 20 20 20 20 41 4e 44 20 6c 65 76 65 6c 3d 33 0a      AND level=3.
1420: 7d 20 7b 31 32 37 35 36 33 7d 0a 0a 23 2d 2d 2d  } {127563}..#---
1430: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1440: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1450: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1460: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1470: 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 65 73 74 20 74  -------.# Test t
1480: 68 61 74 20 64 65 6c 65 74 65 20 6d 61 72 6b 65  hat delete marke
1490: 72 73 20 61 72 65 20 72 65 6d 6f 76 65 64 20 66  rs are removed f
14a0: 72 6f 6d 20 46 54 53 20 73 65 67 6d 65 6e 74 73  rom FTS segments
14b0: 20 77 68 65 6e 20 70 6f 73 73 69 62 6c 65 2e 0a   when possible..
14c0: 23 20 49 74 20 69 73 20 6f 6e 6c 79 20 70 6f 73  # It is only pos
14d0: 73 69 62 6c 65 20 74 6f 20 72 65 6d 6f 76 65 20  sible to remove 
14e0: 64 65 6c 65 74 65 20 6d 61 72 6b 65 72 73 20 77  delete markers w
14f0: 68 65 6e 20 74 68 65 20 6f 75 74 70 75 74 20 6f  hen the output o
1500: 66 20 74 68 65 0a 23 20 6d 65 72 67 65 20 6f 70  f the.# merge op
1510: 65 72 61 74 69 6f 6e 20 77 69 6c 6c 20 62 65 63  eration will bec
1520: 6f 6d 65 20 74 68 65 20 6f 6c 64 65 73 74 20 73  ome the oldest s
1530: 65 67 6d 65 6e 74 20 69 6e 20 74 68 65 20 69 6e  egment in the in
1540: 64 65 78 2e 0a 23 0a 23 20 20 20 33 2e 31 20 2d  dex..#.#   3.1 -
1550: 20 77 68 65 6e 20 74 68 65 20 6f 6c 64 65 73 74   when the oldest
1560: 20 73 65 67 6d 65 6e 74 20 69 73 20 63 72 65 61   segment is crea
1570: 74 65 64 20 62 79 20 61 6e 20 27 6f 70 74 69 6d  ted by an 'optim
1580: 69 7a 65 27 2e 0a 23 20 20 20 33 2e 32 20 2d 20  ize'..#   3.2 - 
1590: 77 68 65 6e 20 74 68 65 20 6f 6c 64 65 73 74 20  when the oldest 
15a0: 73 65 67 6d 65 6e 74 20 69 73 20 63 72 65 61 74  segment is creat
15b0: 65 64 20 62 79 20 61 6e 20 69 6e 63 72 65 6d 65  ed by an increme
15c0: 6e 74 61 6c 20 6d 65 72 67 65 2e 0a 23 20 20 20  ntal merge..#   
15d0: 33 2e 33 20 2d 20 62 79 20 61 20 63 72 69 73 69  3.3 - by a crisi
15e0: 73 20 6d 65 72 67 65 2e 0a 23 0a 0a 70 72 6f 63  s merge..#..proc
15f0: 20 69 6e 73 65 72 74 5f 64 6f 63 20 7b 61 72 67   insert_doc {arg
1600: 73 7d 20 7b 0a 20 20 66 6f 72 65 61 63 68 20 69  s} {.  foreach i
1610: 44 6f 63 20 24 61 72 67 73 20 7b 0a 20 20 20 20  Doc $args {.    
1620: 73 65 74 20 4c 20 5b 6c 69 6e 64 65 78 20 7b 0a  set L [lindex {.
1630: 20 20 20 20 20 20 7b 49 6e 20 79 6f 75 72 20 65        {In your e
1640: 61 67 65 72 6e 65 73 73 20 74 6f 20 65 6e 67 61  agerness to enga
1650: 67 65 20 74 68 65 20 54 72 6f 6a 61 6e 73 2c 7d  ge the Trojans,}
1660: 0a 20 20 20 20 20 20 7b 64 6f 6e e2 80 99 74 20  .      {don...t 
1670: 61 6e 79 20 6f 66 20 79 6f 75 20 63 68 61 72 67  any of you charg
1680: 65 20 61 68 65 61 64 20 6f 66 20 6f 74 68 65 72  e ahead of other
1690: 73 2c 7d 0a 20 20 20 20 20 20 7b 74 72 75 73 74  s,}.      {trust
16a0: 69 6e 67 20 69 6e 20 79 6f 75 72 20 73 74 72 65  ing in your stre
16b0: 6e 67 74 68 20 61 6e 64 20 68 6f 72 73 65 6d 61  ngth and horsema
16c0: 6e 73 68 69 70 2e 7d 0a 20 20 20 20 20 20 7b 41  nship.}.      {A
16d0: 6e 64 20 64 6f 6e e2 80 99 74 20 6c 61 67 20 62  nd don...t lag b
16e0: 65 68 69 6e 64 2e 20 54 68 61 74 20 77 69 6c 6c  ehind. That will
16f0: 20 68 75 72 74 20 6f 75 72 20 63 68 61 72 67 65   hurt our charge
1700: 2e 7d 0a 20 20 20 20 20 20 7b 41 6e 79 20 6d 61  .}.      {Any ma
1710: 6e 20 77 68 6f 73 65 20 63 68 61 72 69 6f 74 20  n whose chariot 
1720: 63 6f 6e 66 72 6f 6e 74 73 20 61 6e 20 65 6e 65  confronts an ene
1730: 6d 79 e2 80 99 73 7d 0a 20 20 20 20 20 20 7b 73  my...s}.      {s
1740: 68 6f 75 6c 64 20 74 68 72 75 73 74 20 77 69 74  hould thrust wit
1750: 68 20 68 69 73 20 73 70 65 61 72 20 61 74 20 68  h his spear at h
1760: 69 6d 20 66 72 6f 6d 20 74 68 65 72 65 2e 7d 0a  im from there.}.
1770: 20 20 20 20 20 20 7b 54 68 61 74 e2 80 99 73 20        {That...s 
1780: 74 68 65 20 6d 6f 73 74 20 65 66 66 65 63 74 69  the most effecti
1790: 76 65 20 74 61 63 74 69 63 2c 20 74 68 65 20 77  ve tactic, the w
17a0: 61 79 7d 0a 20 20 20 20 20 20 7b 6d 65 6e 20 77  ay}.      {men w
17b0: 69 70 65 64 20 6f 75 74 20 63 69 74 79 20 73 74  iped out city st
17c0: 72 6f 6e 67 68 6f 6c 64 73 20 6c 6f 6e 67 20 61  rongholds long a
17d0: 67 6f 20 e2 80 94 7d 0a 20 20 20 20 20 20 7b 74  go ...}.      {t
17e0: 68 65 69 72 20 63 68 65 73 74 73 20 66 75 6c 6c  heir chests full
17f0: 20 6f 66 20 74 68 61 74 20 73 74 79 6c 65 20 61   of that style a
1800: 6e 64 20 73 70 69 72 69 74 2e 7d 0a 20 20 20 20  nd spirit.}.    
1810: 7d 20 5b 65 78 70 72 20 24 69 44 6f 63 25 39 5d  } [expr $iDoc%9]
1820: 5d 0a 20 20 20 20 65 78 65 63 73 71 6c 20 7b 20  ].    execsql { 
1830: 52 45 50 4c 41 43 45 20 49 4e 54 4f 20 78 33 28  REPLACE INTO x3(
1840: 64 6f 63 69 64 2c 20 63 6f 6e 74 65 6e 74 29 20  docid, content) 
1850: 56 41 4c 55 45 53 28 24 69 44 6f 63 2c 20 24 4c  VALUES($iDoc, $L
1860: 29 20 7d 0a 20 20 7d 0a 7d 0a 0a 70 72 6f 63 20  ) }.  }.}..proc 
1870: 64 65 6c 65 74 65 5f 64 6f 63 20 7b 61 72 67 73  delete_doc {args
1880: 7d 20 7b 0a 20 20 66 6f 72 65 61 63 68 20 69 44  } {.  foreach iD
1890: 6f 63 20 24 61 72 67 73 20 7b 0a 20 20 20 20 65  oc $args {.    e
18a0: 78 65 63 73 71 6c 20 7b 20 44 45 4c 45 54 45 20  xecsql { DELETE 
18b0: 46 52 4f 4d 20 78 33 20 57 48 45 52 45 20 64 6f  FROM x3 WHERE do
18c0: 63 69 64 20 3d 20 24 69 44 6f 63 20 7d 0a 20 20  cid = $iDoc }.  
18d0: 7d 0a 7d 0a 0a 70 72 6f 63 20 73 65 63 6f 6e 64  }.}..proc second
18e0: 20 7b 78 7d 20 7b 20 6c 69 6e 64 65 78 20 24 78   {x} { lindex $x
18f0: 20 31 20 7d 0a 64 62 20 66 75 6e 63 20 73 65 63   1 }.db func sec
1900: 6f 6e 64 20 73 65 63 6f 6e 64 0a 0a 64 6f 5f 65  ond second..do_e
1910: 78 65 63 73 71 6c 5f 74 65 73 74 20 33 2e 30 20  xecsql_test 3.0 
1920: 7b 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c  { CREATE VIRTUAL
1930: 20 54 41 42 4c 45 20 78 33 20 55 53 49 4e 47 20   TABLE x3 USING 
1940: 66 74 73 34 20 7d 0a 0a 64 6f 5f 74 65 73 74 20  fts4 }..do_test 
1950: 33 2e 31 2e 31 20 7b 0a 20 20 64 62 20 74 72 61  3.1.1 {.  db tra
1960: 6e 73 61 63 74 69 6f 6e 20 7b 20 69 6e 73 65 72  nsaction { inser
1970: 74 5f 64 6f 63 20 31 20 32 20 33 20 34 20 35 20  t_doc 1 2 3 4 5 
1980: 36 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b 20  6 }.  execsql { 
1990: 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69 64  SELECT level, id
19a0: 78 2c 20 73 65 63 6f 6e 64 28 65 6e 64 5f 62 6c  x, second(end_bl
19b0: 6f 63 6b 29 20 46 52 4f 4d 20 78 33 5f 73 65 67  ock) FROM x3_seg
19c0: 64 69 72 20 7d 0a 7d 20 7b 30 20 30 20 34 31 32  dir }.} {0 0 412
19d0: 7d 0a 64 6f 5f 74 65 73 74 20 33 2e 31 2e 32 20  }.do_test 3.1.2 
19e0: 7b 0a 20 20 64 65 6c 65 74 65 5f 64 6f 63 20 31  {.  delete_doc 1
19f0: 20 32 20 33 20 34 20 35 20 36 0a 20 20 65 78 65   2 3 4 5 6.  exe
1a00: 63 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 63 6f  csql { SELECT co
1a10: 75 6e 74 28 2a 29 20 46 52 4f 4d 20 78 33 5f 73  unt(*) FROM x3_s
1a20: 65 67 64 69 72 20 7d 0a 7d 20 7b 30 7d 0a 64 6f  egdir }.} {0}.do
1a30: 5f 74 65 73 74 20 33 2e 31 2e 33 20 7b 0a 20 20  _test 3.1.3 {.  
1a40: 64 62 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 7b  db transaction {
1a50: 20 0a 20 20 20 20 69 6e 73 65 72 74 5f 64 6f 63   .    insert_doc
1a60: 20 31 20 32 20 33 20 34 20 35 20 36 20 37 20 38   1 2 3 4 5 6 7 8
1a70: 20 39 0a 20 20 20 20 64 65 6c 65 74 65 5f 64 6f   9.    delete_do
1a80: 63 20 39 20 38 20 37 0a 20 20 7d 0a 20 20 65 78  c 9 8 7.  }.  ex
1a90: 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 6c  ecsql { SELECT l
1aa0: 65 76 65 6c 2c 20 69 64 78 2c 20 73 65 63 6f 6e  evel, idx, secon
1ab0: 64 28 65 6e 64 5f 62 6c 6f 63 6b 29 20 46 52 4f  d(end_block) FRO
1ac0: 4d 20 78 33 5f 73 65 67 64 69 72 20 7d 0a 7d 20  M x3_segdir }.} 
1ad0: 7b 30 20 30 20 35 39 31 20 30 20 31 20 36 35 20  {0 0 591 0 1 65 
1ae0: 30 20 32 20 37 32 20 30 20 33 20 37 36 7d 0a 64  0 2 72 0 3 76}.d
1af0: 6f 5f 74 65 73 74 20 33 2e 31 2e 34 20 7b 0a 20  o_test 3.1.4 {. 
1b00: 20 65 78 65 63 73 71 6c 20 7b 20 49 4e 53 45 52   execsql { INSER
1b10: 54 20 49 4e 54 4f 20 78 33 28 78 33 29 20 56 41  T INTO x3(x3) VA
1b20: 4c 55 45 53 28 27 6f 70 74 69 6d 69 7a 65 27 29  LUES('optimize')
1b30: 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 53   }.  execsql { S
1b40: 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69 64 78  ELECT level, idx
1b50: 2c 20 73 65 63 6f 6e 64 28 65 6e 64 5f 62 6c 6f  , second(end_blo
1b60: 63 6b 29 20 46 52 4f 4d 20 78 33 5f 73 65 67 64  ck) FROM x3_segd
1b70: 69 72 20 7d 0a 7d 20 7b 30 20 30 20 34 31 32 7d  ir }.} {0 0 412}
1b80: 0a 0a 64 6f 5f 74 65 73 74 20 33 2e 32 2e 31 20  ..do_test 3.2.1 
1b90: 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 44 45  {.  execsql { DE
1ba0: 4c 45 54 45 20 46 52 4f 4d 20 78 33 20 7d 0a 20  LETE FROM x3 }. 
1bb0: 20 69 6e 73 65 72 74 5f 64 6f 63 20 38 20 37 20   insert_doc 8 7 
1bc0: 36 20 35 20 34 20 33 20 32 20 31 0a 20 20 64 65  6 5 4 3 2 1.  de
1bd0: 6c 65 74 65 5f 64 6f 63 20 37 20 38 0a 20 20 65  lete_doc 7 8.  e
1be0: 78 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54 20  xecsql { SELECT 
1bf0: 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 78 33  count(*) FROM x3
1c00: 5f 73 65 67 64 69 72 20 7d 0a 7d 20 7b 31 30 7d  _segdir }.} {10}
1c10: 0a 64 6f 5f 74 65 73 74 20 33 2e 32 2e 32 20 7b  .do_test 3.2.2 {
1c20: 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 49 4e 53  .  execsql { INS
1c30: 45 52 54 20 49 4e 54 4f 20 78 33 28 78 33 29 20  ERT INTO x3(x3) 
1c40: 56 41 4c 55 45 53 28 27 6d 65 72 67 65 3d 35 30  VALUES('merge=50
1c50: 30 2c 31 30 27 29 20 7d 0a 20 20 65 78 65 63 73  0,10') }.  execs
1c60: 71 6c 20 7b 20 53 45 4c 45 43 54 20 6c 65 76 65  ql { SELECT leve
1c70: 6c 2c 20 69 64 78 2c 20 73 65 63 6f 6e 64 28 65  l, idx, second(e
1c80: 6e 64 5f 62 6c 6f 63 6b 29 20 46 52 4f 4d 20 78  nd_block) FROM x
1c90: 33 5f 73 65 67 64 69 72 20 7d 0a 7d 20 7b 31 20  3_segdir }.} {1 
1ca0: 30 20 34 31 32 7d 0a 0a 23 20 54 68 69 73 20 61  0 412}..# This a
1cb0: 73 73 75 6d 65 73 20 74 68 65 20 63 72 69 73 69  ssumes the crisi
1cc0: 73 20 6d 65 72 67 65 20 68 61 70 70 65 6e 73 20  s merge happens 
1cd0: 77 68 65 6e 20 74 68 65 72 65 20 61 72 65 20 61  when there are a
1ce0: 6c 72 65 61 64 79 20 31 36 20 0a 23 20 73 65 67  lready 16 .# seg
1cf0: 6d 65 6e 74 73 20 61 6e 64 20 6f 6e 65 20 6d 6f  ments and one mo
1d00: 72 65 20 69 73 20 61 64 64 65 64 2e 0a 23 0a 64  re is added..#.d
1d10: 6f 5f 74 65 73 74 20 33 2e 33 2e 31 20 7b 0a 20  o_test 3.3.1 {. 
1d20: 20 65 78 65 63 73 71 6c 20 7b 20 44 45 4c 45 54   execsql { DELET
1d30: 45 20 46 52 4f 4d 20 78 33 20 7d 0a 20 20 69 6e  E FROM x3 }.  in
1d40: 73 65 72 74 5f 64 6f 63 20 31 20 32 20 33 20 34  sert_doc 1 2 3 4
1d50: 20 35 20 36 20 20 37 20 38 20 39 20 31 30 20 31   5 6  7 8 9 10 1
1d60: 31 0a 20 20 64 65 6c 65 74 65 5f 64 6f 63 20 31  1.  delete_doc 1
1d70: 31 20 31 30 20 39 20 38 20 37 0a 20 20 65 78 65  1 10 9 8 7.  exe
1d80: 63 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 63 6f  csql { SELECT co
1d90: 75 6e 74 28 2a 29 20 46 52 4f 4d 20 78 33 5f 73  unt(*) FROM x3_s
1da0: 65 67 64 69 72 20 7d 0a 7d 20 7b 31 36 7d 0a 0a  egdir }.} {16}..
1db0: 64 6f 5f 74 65 73 74 20 33 2e 33 2e 32 20 7b 0a  do_test 3.3.2 {.
1dc0: 20 20 69 6e 73 65 72 74 5f 64 6f 63 20 31 32 0a    insert_doc 12.
1dd0: 20 20 65 78 65 63 73 71 6c 20 7b 20 53 45 4c 45    execsql { SELE
1de0: 43 54 20 6c 65 76 65 6c 2c 20 69 64 78 2c 20 73  CT level, idx, s
1df0: 65 63 6f 6e 64 28 65 6e 64 5f 62 6c 6f 63 6b 29  econd(end_block)
1e00: 20 46 52 4f 4d 20 78 33 5f 73 65 67 64 69 72 20   FROM x3_segdir 
1e10: 57 48 45 52 45 20 6c 65 76 65 6c 3d 31 20 7d 0a  WHERE level=1 }.
1e20: 7d 20 7b 31 20 30 20 34 31 32 7d 0a 0a 23 2d 2d  } {1 0 412}..#--
1e30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1e40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1e50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1e60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1e70: 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 43 68 65 63 6b  --------.# Check
1e80: 20 61 20 74 68 65 6f 72 79 20 6f 6e 20 61 20 62   a theory on a b
1e90: 75 67 20 69 6e 20 66 74 73 34 20 2d 20 74 68 61  ug in fts4 - tha
1ea0: 74 20 73 65 67 6d 65 6e 74 73 20 77 69 74 68 20  t segments with 
1eb0: 69 64 78 3d 3d 30 20 77 65 72 65 20 6e 6f 74 20  idx==0 were not 
1ec0: 0a 23 20 62 65 69 6e 67 20 69 6e 63 72 65 6d 65  .# being increme
1ed0: 6e 74 61 6c 6c 79 20 6d 65 72 67 65 64 20 63 6f  ntally merged co
1ee0: 72 72 65 63 74 6c 79 2e 20 54 68 65 6f 72 79 20  rrectly. Theory 
1ef0: 74 75 72 6e 65 64 20 6f 75 74 20 74 6f 20 62 65  turned out to be
1f00: 20 66 61 6c 73 65 2e 0a 23 0a 64 6f 5f 65 78 65   false..#.do_exe
1f10: 63 73 71 6c 5f 74 65 73 74 20 34 2e 31 20 7b 0a  csql_test 4.1 {.
1f20: 20 20 44 52 4f 50 20 54 41 42 4c 45 20 49 46 20    DROP TABLE IF 
1f30: 45 58 49 53 54 53 20 78 34 3b 0a 20 20 44 52 4f  EXISTS x4;.  DRO
1f40: 50 20 54 41 42 4c 45 20 49 46 20 45 58 49 53 54  P TABLE IF EXIST
1f50: 53 20 74 31 3b 0a 20 20 43 52 45 41 54 45 20 54  S t1;.  CREATE T
1f60: 41 42 4c 45 20 74 31 28 64 6f 63 69 64 2c 20 77  ABLE t1(docid, w
1f70: 6f 72 64 73 29 3b 0a 20 20 43 52 45 41 54 45 20  ords);.  CREATE 
1f80: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 78 34  VIRTUAL TABLE x4
1f90: 20 55 53 49 4e 47 20 66 74 73 34 28 77 6f 72 64   USING fts4(word
1fa0: 73 29 3b 0a 7d 0a 64 6f 5f 74 65 73 74 20 34 2e  s);.}.do_test 4.
1fb0: 32 20 7b 0a 20 20 66 74 73 5f 6b 6a 76 5f 67 65  2 {.  fts_kjv_ge
1fc0: 6e 65 73 69 73 20 0a 20 20 65 78 65 63 73 71 6c  nesis .  execsql
1fd0: 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78   { INSERT INTO x
1fe0: 34 20 53 45 4c 45 43 54 20 77 6f 72 64 73 20 46  4 SELECT words F
1ff0: 52 4f 4d 20 74 31 20 7d 0a 20 20 65 78 65 63 73  ROM t1 }.  execs
2000: 71 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f  ql { INSERT INTO
2010: 20 78 34 20 53 45 4c 45 43 54 20 77 6f 72 64 73   x4 SELECT words
2020: 20 46 52 4f 4d 20 74 31 20 7d 0a 7d 20 7b 7d 0a   FROM t1 }.} {}.
2030: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
2040: 20 34 2e 33 20 7b 0a 20 20 53 45 4c 45 43 54 20   4.3 {.  SELECT 
2050: 6c 65 76 65 6c 2c 20 69 64 78 2c 20 73 65 63 6f  level, idx, seco
2060: 6e 64 28 65 6e 64 5f 62 6c 6f 63 6b 29 20 46 52  nd(end_block) FR
2070: 4f 4d 20 78 34 5f 73 65 67 64 69 72 20 0a 7d 20  OM x4_segdir .} 
2080: 7b 30 20 30 20 31 31 37 34 38 33 20 30 20 31 20  {0 0 117483 0 1 
2090: 31 31 38 30 30 36 7d 0a 0a 64 6f 5f 65 78 65 63  118006}..do_exec
20a0: 73 71 6c 5f 74 65 73 74 20 34 2e 34 20 7b 0a 20  sql_test 4.4 {. 
20b0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 34 28   INSERT INTO x4(
20c0: 78 34 29 20 56 41 4c 55 45 53 28 27 6d 65 72 67  x4) VALUES('merg
20d0: 65 3d 31 30 2c 32 27 29 3b 0a 20 20 53 45 4c 45  e=10,2');.  SELE
20e0: 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d  CT count(*) FROM
20f0: 20 78 34 5f 73 65 67 64 69 72 3b 0a 7d 20 7b 33   x4_segdir;.} {3
2100: 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  }..do_execsql_te
2110: 73 74 20 34 2e 35 20 7b 0a 20 20 49 4e 53 45 52  st 4.5 {.  INSER
2120: 54 20 49 4e 54 4f 20 78 34 28 78 34 29 20 56 41  T INTO x4(x4) VA
2130: 4c 55 45 53 28 27 6d 65 72 67 65 3d 31 30 2c 32  LUES('merge=10,2
2140: 27 29 3b 0a 20 20 53 45 4c 45 43 54 20 63 6f 75  ');.  SELECT cou
2150: 6e 74 28 2a 29 20 46 52 4f 4d 20 78 34 5f 73 65  nt(*) FROM x4_se
2160: 67 64 69 72 3b 0a 7d 20 7b 33 7d 0a 0a 64 6f 5f  gdir;.} {3}..do_
2170: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 34 2e 36  execsql_test 4.6
2180: 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f   {.  INSERT INTO
2190: 20 78 34 28 78 34 29 20 56 41 4c 55 45 53 28 27   x4(x4) VALUES('
21a0: 6d 65 72 67 65 3d 31 30 30 30 2c 32 27 29 3b 0a  merge=1000,2');.
21b0: 20 20 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a    SELECT count(*
21c0: 29 20 46 52 4f 4d 20 78 34 5f 73 65 67 64 69 72  ) FROM x4_segdir
21d0: 3b 0a 7d 20 7b 31 7d 0a 0a 0a 0a 23 2d 2d 2d 2d  ;.} {1}....#----
21e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
21f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2200: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2210: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2220: 2d 2d 2d 2d 2d 2d 0a 23 20 43 68 65 63 6b 20 74  ------.# Check t
2230: 68 61 74 20 73 65 67 6d 65 6e 74 73 20 61 72 65  hat segments are
2240: 20 6e 6f 74 20 70 72 6f 6d 6f 74 65 64 20 69 66   not promoted if
2250: 20 74 68 65 20 22 65 6e 64 5f 62 6c 6f 63 6b 22   the "end_block"
2260: 20 66 69 65 6c 64 20 64 6f 65 73 20 6e 6f 74 0a   field does not.
2270: 23 20 63 6f 6e 74 61 69 6e 20 61 20 73 69 7a 65  # contain a size
2280: 2e 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  ..#.do_execsql_t
2290: 65 73 74 20 35 2e 31 20 7b 0a 20 20 44 52 4f 50  est 5.1 {.  DROP
22a0: 20 54 41 42 4c 45 20 49 46 20 45 58 49 53 54 53   TABLE IF EXISTS
22b0: 20 78 32 3b 0a 20 20 44 52 4f 50 20 54 41 42 4c   x2;.  DROP TABL
22c0: 45 20 49 46 20 45 58 49 53 54 53 20 74 31 3b 0a  E IF EXISTS t1;.
22d0: 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 74    CREATE TABLE t
22e0: 31 28 64 6f 63 69 64 2c 20 77 6f 72 64 73 29 3b  1(docid, words);
22f0: 0a 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41  .  CREATE VIRTUA
2300: 4c 20 54 41 42 4c 45 20 78 32 20 55 53 49 4e 47  L TABLE x2 USING
2310: 20 66 74 73 34 3b 0a 7d 0a 66 74 73 5f 6b 6a 76   fts4;.}.fts_kjv
2320: 5f 67 65 6e 65 73 69 73 20 0a 0a 70 72 6f 63 20  _genesis ..proc 
2330: 66 69 72 73 74 20 7b 4c 7d 20 7b 6c 69 6e 64 65  first {L} {linde
2340: 78 20 24 4c 20 30 7d 0a 64 62 20 66 75 6e 63 20  x $L 0}.db func 
2350: 66 69 72 73 74 20 66 69 72 73 74 0a 0a 64 6f 5f  first first..do_
2360: 74 65 73 74 20 35 2e 32 20 7b 0a 20 20 66 6f 72  test 5.2 {.  for
2370: 65 61 63 68 20 72 20 5b 64 62 20 65 76 61 6c 20  each r [db eval 
2380: 7b 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46  { SELECT rowid F
2390: 52 4f 4d 20 74 31 20 7d 5d 20 7b 0a 20 20 20 20  ROM t1 }] {.    
23a0: 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 20 20  execsql {.      
23b0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 32 28 64  INSERT INTO x2(d
23c0: 6f 63 69 64 2c 20 63 6f 6e 74 65 6e 74 29 20 53  ocid, content) S
23d0: 45 4c 45 43 54 20 64 6f 63 69 64 2c 20 77 6f 72  ELECT docid, wor
23e0: 64 73 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45  ds FROM t1 WHERE
23f0: 20 72 6f 77 69 64 3d 24 72 0a 20 20 20 20 7d 0a   rowid=$r.    }.
2400: 20 20 7d 0a 20 20 66 6f 72 65 61 63 68 20 64 20    }.  foreach d 
2410: 5b 64 62 20 65 76 61 6c 20 7b 20 53 45 4c 45 43  [db eval { SELEC
2420: 54 20 64 6f 63 69 64 20 46 52 4f 4d 20 74 31 20  T docid FROM t1 
2430: 4c 49 4d 49 54 20 2d 31 20 4f 46 46 53 45 54 20  LIMIT -1 OFFSET 
2440: 32 30 20 7d 5d 20 7b 0a 20 20 20 20 65 78 65 63  20 }] {.    exec
2450: 73 71 6c 20 7b 20 44 45 4c 45 54 45 20 46 52 4f  sql { DELETE FRO
2460: 4d 20 78 32 20 57 48 45 52 45 20 64 6f 63 69 64  M x2 WHERE docid
2470: 20 3d 20 24 64 20 7d 0a 20 20 7d 0a 0a 20 20 65   = $d }.  }..  e
2480: 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 49 4e 53  xecsql {.    INS
2490: 45 52 54 20 49 4e 54 4f 20 78 32 28 78 32 29 20  ERT INTO x2(x2) 
24a0: 56 41 4c 55 45 53 28 27 6f 70 74 69 6d 69 7a 65  VALUES('optimize
24b0: 27 29 3b 0a 20 20 20 20 53 45 4c 45 43 54 20 6c  ');.    SELECT l
24c0: 65 76 65 6c 2c 20 69 64 78 2c 20 65 6e 64 5f 62  evel, idx, end_b
24d0: 6c 6f 63 6b 20 46 52 4f 4d 20 78 32 5f 73 65 67  lock FROM x2_seg
24e0: 64 69 72 0a 20 20 7d 0a 7d 20 7b 32 20 30 20 7b  dir.  }.} {2 0 {
24f0: 37 35 32 20 31 39 32 36 7d 7d 0a 0a 64 6f 5f 65  752 1926}}..do_e
2500: 78 65 63 73 71 6c 5f 74 65 73 74 20 35 2e 33 20  xecsql_test 5.3 
2510: 7b 0a 20 20 55 50 44 41 54 45 20 78 32 5f 73 65  {.  UPDATE x2_se
2520: 67 64 69 72 20 53 45 54 20 65 6e 64 5f 62 6c 6f  gdir SET end_blo
2530: 63 6b 20 3d 20 43 41 53 54 28 20 66 69 72 73 74  ck = CAST( first
2540: 28 65 6e 64 5f 62 6c 6f 63 6b 29 20 41 53 20 49  (end_block) AS I
2550: 4e 54 45 47 45 52 20 29 3b 0a 20 20 53 45 4c 45  NTEGER );.  SELE
2560: 43 54 20 65 6e 64 5f 62 6c 6f 63 6b 2c 20 74 79  CT end_block, ty
2570: 70 65 6f 66 28 65 6e 64 5f 62 6c 6f 63 6b 29 20  peof(end_block) 
2580: 46 52 4f 4d 20 78 32 5f 73 65 67 64 69 72 3b 0a  FROM x2_segdir;.
2590: 7d 20 7b 37 35 32 20 69 6e 74 65 67 65 72 7d 0a  } {752 integer}.
25a0: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
25b0: 20 35 2e 34 20 7b 0a 20 20 49 4e 53 45 52 54 20   5.4 {.  INSERT 
25c0: 49 4e 54 4f 20 78 32 20 53 45 4c 45 43 54 20 77  INTO x2 SELECT w
25d0: 6f 72 64 73 20 46 52 4f 4d 20 74 31 20 4c 49 4d  ords FROM t1 LIM
25e0: 49 54 20 35 30 3b 0a 20 20 53 45 4c 45 43 54 20  IT 50;.  SELECT 
25f0: 6c 65 76 65 6c 2c 20 69 64 78 2c 20 65 6e 64 5f  level, idx, end_
2600: 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 32 5f 73 65  block FROM x2_se
2610: 67 64 69 72 0a 7d 20 7b 32 20 30 20 37 35 32 20  gdir.} {2 0 752 
2620: 30 20 30 20 7b 37 35 38 20 35 31 37 34 7d 7d 0a  0 0 {758 5174}}.
2630: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
2640: 20 35 2e 35 20 7b 0a 20 20 55 50 44 41 54 45 20   5.5 {.  UPDATE 
2650: 78 32 5f 73 65 67 64 69 72 20 53 45 54 20 65 6e  x2_segdir SET en
2660: 64 5f 62 6c 6f 63 6b 20 3d 20 65 6e 64 5f 62 6c  d_block = end_bl
2670: 6f 63 6b 20 7c 7c 20 27 20 31 39 32 36 27 20 57  ock || ' 1926' W
2680: 48 45 52 45 20 6c 65 76 65 6c 3d 32 3b 0a 20 20  HERE level=2;.  
2690: 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 32 20 53  INSERT INTO x2 S
26a0: 45 4c 45 43 54 20 77 6f 72 64 73 20 46 52 4f 4d  ELECT words FROM
26b0: 20 74 31 20 4c 49 4d 49 54 20 34 30 3b 0a 20 20   t1 LIMIT 40;.  
26c0: 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69 64  SELECT level, id
26d0: 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20 46 52 4f  x, end_block FRO
26e0: 4d 20 78 32 5f 73 65 67 64 69 72 0a 7d 20 7b 30  M x2_segdir.} {0
26f0: 20 30 20 7b 37 35 32 20 31 39 32 36 7d 20 30 20   0 {752 1926} 0 
2700: 31 20 7b 37 35 38 20 35 31 37 34 7d 20 30 20 32  1 {758 5174} 0 2
2710: 20 7b 37 36 33 20 34 31 37 30 7d 7d 0a 0a 70 72   {763 4170}}..pr
2720: 6f 63 20 74 31 5f 74 6f 5f 78 32 20 7b 7d 20 7b  oc t1_to_x2 {} {
2730: 0a 20 20 66 6f 72 65 61 63 68 20 69 64 20 5b 64  .  foreach id [d
2740: 62 20 65 76 61 6c 20 7b 53 45 4c 45 43 54 20 64  b eval {SELECT d
2750: 6f 63 69 64 20 46 52 4f 4d 20 74 31 20 4c 49 4d  ocid FROM t1 LIM
2760: 49 54 20 32 7d 5d 20 7b 0a 20 20 20 20 65 78 65  IT 2}] {.    exe
2770: 63 73 71 6c 20 7b 0a 20 20 20 20 20 20 44 45 4c  csql {.      DEL
2780: 45 54 45 20 46 52 4f 4d 20 78 32 20 57 48 45 52  ETE FROM x2 WHER
2790: 45 20 64 6f 63 69 64 3d 24 69 64 3b 0a 20 20 20  E docid=$id;.   
27a0: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78     INSERT INTO x
27b0: 32 28 64 6f 63 69 64 2c 20 63 6f 6e 74 65 6e 74  2(docid, content
27c0: 29 20 53 45 4c 45 43 54 20 24 69 64 2c 20 77 6f  ) SELECT $id, wo
27d0: 72 64 73 20 46 52 4f 4d 20 74 31 20 57 48 45 52  rds FROM t1 WHER
27e0: 45 20 64 6f 63 69 64 3d 24 69 64 3b 0a 20 20 20  E docid=$id;.   
27f0: 20 7d 0a 20 20 7d 0a 7d 0a 0a 23 2d 2d 2d 2d 2d   }.  }.}..#-----
2800: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2810: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2820: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2830: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2840: 2d 2d 2d 2d 2d 0a 23 20 43 68 65 63 6b 20 74 68  -----.# Check th
2850: 61 74 20 73 65 67 6d 65 6e 74 73 20 63 72 65 61  at segments crea
2860: 74 65 64 20 62 79 20 61 75 74 6f 2d 6d 65 72 67  ted by auto-merg
2870: 65 20 61 72 65 20 6e 6f 74 20 70 72 6f 6d 6f 74  e are not promot
2880: 65 64 20 75 6e 74 69 6c 20 74 68 65 79 0a 23 20  ed until they.# 
2890: 61 72 65 20 63 6f 6d 70 6c 65 74 65 64 2e 0a 23  are completed..#
28a0: 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  ..do_execsql_tes
28b0: 74 20 36 2e 31 20 7b 0a 20 20 43 52 45 41 54 45  t 6.1 {.  CREATE
28c0: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 78   VIRTUAL TABLE x
28d0: 35 20 55 53 49 4e 47 20 66 74 73 34 3b 0a 20 20  5 USING fts4;.  
28e0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 35 20 53  INSERT INTO x5 S
28f0: 45 4c 45 43 54 20 77 6f 72 64 73 20 46 52 4f 4d  ELECT words FROM
2900: 20 74 31 20 4c 49 4d 49 54 20 31 30 30 20 4f 46   t1 LIMIT 100 OF
2910: 46 53 45 54 20 30 3b 0a 20 20 49 4e 53 45 52 54  FSET 0;.  INSERT
2920: 20 49 4e 54 4f 20 78 35 20 53 45 4c 45 43 54 20   INTO x5 SELECT 
2930: 77 6f 72 64 73 20 46 52 4f 4d 20 74 31 20 4c 49  words FROM t1 LI
2940: 4d 49 54 20 31 30 30 20 4f 46 46 53 45 54 20 32  MIT 100 OFFSET 2
2950: 35 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  5;.  INSERT INTO
2960: 20 78 35 20 53 45 4c 45 43 54 20 77 6f 72 64 73   x5 SELECT words
2970: 20 46 52 4f 4d 20 74 31 20 4c 49 4d 49 54 20 31   FROM t1 LIMIT 1
2980: 30 30 20 4f 46 46 53 45 54 20 35 30 3b 0a 20 20  00 OFFSET 50;.  
2990: 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 35 20 53  INSERT INTO x5 S
29a0: 45 4c 45 43 54 20 77 6f 72 64 73 20 46 52 4f 4d  ELECT words FROM
29b0: 20 74 31 20 4c 49 4d 49 54 20 31 30 30 20 4f 46   t1 LIMIT 100 OF
29c0: 46 53 45 54 20 37 35 3b 0a 20 20 53 45 4c 45 43  FSET 75;.  SELEC
29d0: 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20  T count(*) FROM 
29e0: 78 35 5f 73 65 67 64 69 72 0a 7d 20 7b 34 7d 0a  x5_segdir.} {4}.
29f0: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
2a00: 20 36 2e 32 20 7b 0a 20 20 49 4e 53 45 52 54 20   6.2 {.  INSERT 
2a10: 49 4e 54 4f 20 78 35 28 78 35 29 20 56 41 4c 55  INTO x5(x5) VALU
2a20: 45 53 28 27 6d 65 72 67 65 3d 32 2c 34 27 29 3b  ES('merge=2,4');
2a30: 0a 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c  .  SELECT level,
2a40: 20 69 64 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20   idx, end_block 
2a50: 46 52 4f 4d 20 78 35 5f 73 65 67 64 69 72 3b 0a  FROM x5_segdir;.
2a60: 7d 20 7b 30 20 30 20 7b 31 30 20 39 32 31 36 7d  } {0 0 {10 9216}
2a70: 20 30 20 31 20 7b 32 31 20 39 33 33 30 7d 20 30   0 1 {21 9330} 0
2a80: 20 32 20 7b 33 31 20 38 38 35 30 7d 20 30 20 33   2 {31 8850} 0 3
2a90: 20 7b 34 30 20 38 36 38 39 7d 20 31 20 30 20 7b   {40 8689} 1 0 {
2aa0: 31 33 32 30 20 2d 33 31 31 37 7d 7d 0a 0a 64 6f  1320 -3117}}..do
2ab0: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 36 2e  _execsql_test 6.
2ac0: 33 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  3 {.  INSERT INT
2ad0: 4f 20 78 35 20 53 45 4c 45 43 54 20 77 6f 72 64  O x5 SELECT word
2ae0: 73 20 46 52 4f 4d 20 74 31 20 4c 49 4d 49 54 20  s FROM t1 LIMIT 
2af0: 31 30 30 20 4f 46 46 53 45 54 20 31 30 30 3b 0a  100 OFFSET 100;.
2b00: 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20    SELECT level, 
2b10: 69 64 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20 46  idx, end_block F
2b20: 52 4f 4d 20 78 35 5f 73 65 67 64 69 72 3b 0a 7d  ROM x5_segdir;.}
2b30: 20 7b 0a 20 20 30 20 30 20 7b 31 30 20 39 32 31   {.  0 0 {10 921
2b40: 36 7d 20 30 20 31 20 7b 32 31 20 39 33 33 30 7d  6} 0 1 {21 9330}
2b50: 20 30 20 32 20 7b 33 31 20 38 38 35 30 7d 20 0a   0 2 {31 8850} .
2b60: 20 20 30 20 33 20 7b 34 30 20 38 36 38 39 7d 20    0 3 {40 8689} 
2b70: 31 20 30 20 7b 31 33 32 30 20 2d 33 31 31 37 7d  1 0 {1320 -3117}
2b80: 20 30 20 34 20 7b 31 33 32 39 20 38 32 39 37 7d   0 4 {1329 8297}
2b90: 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  .}..do_execsql_t
2ba0: 65 73 74 20 36 2e 34 20 7b 0a 20 20 49 4e 53 45  est 6.4 {.  INSE
2bb0: 52 54 20 49 4e 54 4f 20 78 35 28 78 35 29 20 56  RT INTO x5(x5) V
2bc0: 41 4c 55 45 53 28 27 6d 65 72 67 65 3d 32 30 30  ALUES('merge=200
2bd0: 2c 34 27 29 3b 0a 20 20 53 45 4c 45 43 54 20 6c  ,4');.  SELECT l
2be0: 65 76 65 6c 2c 20 69 64 78 2c 20 65 6e 64 5f 62  evel, idx, end_b
2bf0: 6c 6f 63 6b 20 46 52 4f 4d 20 78 35 5f 73 65 67  lock FROM x5_seg
2c00: 64 69 72 3b 0a 7d 20 7b 30 20 30 20 7b 31 33 32  dir;.} {0 0 {132
2c10: 39 20 38 32 39 37 7d 20 31 20 30 20 7b 31 33 32  9 8297} 1 0 {132
2c20: 30 20 32 38 30 30 39 7d 7d 0a 0a 64 6f 5f 65 78  0 28009}}..do_ex
2c30: 65 63 73 71 6c 5f 74 65 73 74 20 36 2e 35 20 7b  ecsql_test 6.5 {
2c40: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78  .  INSERT INTO x
2c50: 35 20 53 45 4c 45 43 54 20 77 6f 72 64 73 20 46  5 SELECT words F
2c60: 52 4f 4d 20 74 31 3b 0a 20 20 53 45 4c 45 43 54  ROM t1;.  SELECT
2c70: 20 6c 65 76 65 6c 2c 20 69 64 78 2c 20 65 6e 64   level, idx, end
2c80: 5f 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 35 5f 73  _block FROM x5_s
2c90: 65 67 64 69 72 3b 0a 7d 20 7b 0a 20 20 30 20 31  egdir;.} {.  0 1
2ca0: 20 7b 31 33 32 39 20 38 32 39 37 7d 20 30 20 30   {1329 8297} 0 0
2cb0: 20 7b 31 33 32 30 20 32 38 30 30 39 7d 20 30 20   {1320 28009} 0 
2cc0: 32 20 7b 31 34 34 39 20 31 31 38 30 30 36 7d 0a  2 {1449 118006}.
2cd0: 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  }..#------------
2ce0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2cf0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2d00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2d10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23  --------------.#
2d20: 20 45 6e 73 75 72 65 20 74 68 61 74 20 69 66 20   Ensure that if 
2d30: 70 61 72 74 20 6f 66 20 61 6e 20 69 6e 63 72 65  part of an incre
2d40: 6d 65 6e 74 61 6c 20 6d 65 72 67 65 20 69 73 20  mental merge is 
2d50: 70 65 72 66 6f 72 6d 65 64 20 62 79 20 61 6e 20  performed by an 
2d60: 6f 6c 64 0a 23 20 76 65 72 73 69 6f 6e 20 74 68  old.# version th
2d70: 61 74 20 64 6f 65 73 20 6e 6f 74 20 73 75 70 70  at does not supp
2d80: 6f 72 74 20 73 74 6f 72 69 6e 67 20 73 65 67 6d  ort storing segm
2d90: 65 6e 74 20 73 69 7a 65 73 20 69 6e 20 74 68 65  ent sizes in the
2da0: 20 65 6e 64 5f 62 6c 6f 63 6b 0a 23 20 66 69 65   end_block.# fie
2db0: 6c 64 2c 20 6e 6f 20 73 69 7a 65 20 69 73 20 73  ld, no size is s
2dc0: 74 6f 72 65 64 20 69 6e 20 74 68 65 20 66 69 6e  tored in the fin
2dd0: 61 6c 20 73 65 67 6d 65 6e 74 20 28 61 73 20 69  al segment (as i
2de0: 74 20 77 6f 75 6c 64 20 62 65 20 69 6e 63 6f 72  t would be incor
2df0: 72 65 63 74 29 2e 0a 23 0a 64 6f 5f 65 78 65 63  rect)..#.do_exec
2e00: 73 71 6c 5f 74 65 73 74 20 37 2e 31 20 7b 0a 20  sql_test 7.1 {. 
2e10: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
2e20: 54 41 42 4c 45 20 78 36 20 55 53 49 4e 47 20 66  TABLE x6 USING f
2e30: 74 73 34 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e  ts4;.  INSERT IN
2e40: 54 4f 20 78 36 20 53 45 4c 45 43 54 20 77 6f 72  TO x6 SELECT wor
2e50: 64 73 20 46 52 4f 4d 20 74 31 3b 0a 20 20 49 4e  ds FROM t1;.  IN
2e60: 53 45 52 54 20 49 4e 54 4f 20 78 36 20 53 45 4c  SERT INTO x6 SEL
2e70: 45 43 54 20 77 6f 72 64 73 20 46 52 4f 4d 20 74  ECT words FROM t
2e80: 31 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  1;.  INSERT INTO
2e90: 20 78 36 20 53 45 4c 45 43 54 20 77 6f 72 64 73   x6 SELECT words
2ea0: 20 46 52 4f 4d 20 74 31 3b 0a 20 20 49 4e 53 45   FROM t1;.  INSE
2eb0: 52 54 20 49 4e 54 4f 20 78 36 20 53 45 4c 45 43  RT INTO x6 SELEC
2ec0: 54 20 77 6f 72 64 73 20 46 52 4f 4d 20 74 31 3b  T words FROM t1;
2ed0: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78  .  INSERT INTO x
2ee0: 36 20 53 45 4c 45 43 54 20 77 6f 72 64 73 20 46  6 SELECT words F
2ef0: 52 4f 4d 20 74 31 3b 0a 20 20 49 4e 53 45 52 54  ROM t1;.  INSERT
2f00: 20 49 4e 54 4f 20 78 36 20 53 45 4c 45 43 54 20   INTO x6 SELECT 
2f10: 77 6f 72 64 73 20 46 52 4f 4d 20 74 31 3b 0a 20  words FROM t1;. 
2f20: 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69   SELECT level, i
2f30: 64 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20 46 52  dx, end_block FR
2f40: 4f 4d 20 78 36 5f 73 65 67 64 69 72 3b 0a 7d 20  OM x6_segdir;.} 
2f50: 7b 0a 20 20 30 20 30 20 7b 31 31 38 20 31 31 37  {.  0 0 {118 117
2f60: 34 38 33 7d 20 30 20 31 20 7b 32 33 38 20 31 31  483} 0 1 {238 11
2f70: 38 30 30 36 7d 20 30 20 32 20 7b 33 35 38 20 31  8006} 0 2 {358 1
2f80: 31 38 30 30 36 7d 20 0a 20 20 30 20 33 20 7b 34  18006} .  0 3 {4
2f90: 37 38 20 31 31 38 30 30 36 7d 20 30 20 34 20 7b  78 118006} 0 4 {
2fa0: 35 39 38 20 31 31 38 30 30 36 7d 20 30 20 35 20  598 118006} 0 5 
2fb0: 7b 37 31 38 20 31 31 38 30 30 36 7d 0a 7d 0a 0a  {718 118006}.}..
2fc0: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
2fd0: 37 2e 32 20 7b 0a 20 20 49 4e 53 45 52 54 20 49  7.2 {.  INSERT I
2fe0: 4e 54 4f 20 78 36 28 78 36 29 20 56 41 4c 55 45  NTO x6(x6) VALUE
2ff0: 53 28 27 6d 65 72 67 65 3d 32 35 2c 34 27 29 3b  S('merge=25,4');
3000: 0a 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c  .  SELECT level,
3010: 20 69 64 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20   idx, end_block 
3020: 46 52 4f 4d 20 78 36 5f 73 65 67 64 69 72 3b 0a  FROM x6_segdir;.
3030: 7d 20 7b 0a 20 20 30 20 30 20 7b 31 31 38 20 31  } {.  0 0 {118 1
3040: 31 37 34 38 33 7d 20 30 20 31 20 7b 32 33 38 20  17483} 0 1 {238 
3050: 31 31 38 30 30 36 7d 20 30 20 32 20 7b 33 35 38  118006} 0 2 {358
3060: 20 31 31 38 30 30 36 7d 20 0a 20 20 30 20 33 20   118006} .  0 3 
3070: 7b 34 37 38 20 31 31 38 30 30 36 7d 20 30 20 34  {478 118006} 0 4
3080: 20 7b 35 39 38 20 31 31 38 30 30 36 7d 20 30 20   {598 118006} 0 
3090: 35 20 7b 37 31 38 20 31 31 38 30 30 36 7d 0a 20  5 {718 118006}. 
30a0: 20 31 20 30 20 7b 32 33 36 39 34 20 2d 36 39 34   1 0 {23694 -694
30b0: 37 37 7d 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71  77}.}..do_execsq
30c0: 6c 5f 74 65 73 74 20 37 2e 33 20 7b 0a 20 20 55  l_test 7.3 {.  U
30d0: 50 44 41 54 45 20 78 36 5f 73 65 67 64 69 72 20  PDATE x6_segdir 
30e0: 53 45 54 20 65 6e 64 5f 62 6c 6f 63 6b 20 3d 20  SET end_block = 
30f0: 66 69 72 73 74 28 65 6e 64 5f 62 6c 6f 63 6b 29  first(end_block)
3100: 20 57 48 45 52 45 20 6c 65 76 65 6c 3d 31 3b 0a   WHERE level=1;.
3110: 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20    SELECT level, 
3120: 69 64 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20 46  idx, end_block F
3130: 52 4f 4d 20 78 36 5f 73 65 67 64 69 72 3b 0a 7d  ROM x6_segdir;.}
3140: 20 7b 0a 20 20 30 20 30 20 7b 31 31 38 20 31 31   {.  0 0 {118 11
3150: 37 34 38 33 7d 20 30 20 31 20 7b 32 33 38 20 31  7483} 0 1 {238 1
3160: 31 38 30 30 36 7d 20 30 20 32 20 7b 33 35 38 20  18006} 0 2 {358 
3170: 31 31 38 30 30 36 7d 20 0a 20 20 30 20 33 20 7b  118006} .  0 3 {
3180: 34 37 38 20 31 31 38 30 30 36 7d 20 30 20 34 20  478 118006} 0 4 
3190: 7b 35 39 38 20 31 31 38 30 30 36 7d 20 30 20 35  {598 118006} 0 5
31a0: 20 7b 37 31 38 20 31 31 38 30 30 36 7d 0a 20 20   {718 118006}.  
31b0: 31 20 30 20 32 33 36 39 34 0a 7d 0a 0a 64 6f 5f  1 0 23694.}..do_
31c0: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 37 2e 34  execsql_test 7.4
31d0: 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f   {.  INSERT INTO
31e0: 20 78 36 28 78 36 29 20 56 41 4c 55 45 53 28 27   x6(x6) VALUES('
31f0: 6d 65 72 67 65 3d 32 35 2c 34 27 29 3b 0a 20 20  merge=25,4');.  
3200: 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69 64  SELECT level, id
3210: 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20 46 52 4f  x, end_block FRO
3220: 4d 20 78 36 5f 73 65 67 64 69 72 3b 0a 7d 20 7b  M x6_segdir;.} {
3230: 0a 20 20 30 20 30 20 7b 31 31 38 20 31 31 37 34  .  0 0 {118 1174
3240: 38 33 7d 20 30 20 31 20 7b 32 33 38 20 31 31 38  83} 0 1 {238 118
3250: 30 30 36 7d 20 30 20 32 20 7b 33 35 38 20 31 31  006} 0 2 {358 11
3260: 38 30 30 36 7d 20 0a 20 20 30 20 33 20 7b 34 37  8006} .  0 3 {47
3270: 38 20 31 31 38 30 30 36 7d 20 30 20 34 20 7b 35  8 118006} 0 4 {5
3280: 39 38 20 31 31 38 30 30 36 7d 20 30 20 35 20 7b  98 118006} 0 5 {
3290: 37 31 38 20 31 31 38 30 30 36 7d 0a 20 20 31 20  718 118006}.  1 
32a0: 30 20 32 33 36 39 34 0a 7d 0a 0a 64 6f 5f 65 78  0 23694.}..do_ex
32b0: 65 63 73 71 6c 5f 74 65 73 74 20 37 2e 35 20 7b  ecsql_test 7.5 {
32c0: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78  .  INSERT INTO x
32d0: 36 28 78 36 29 20 56 41 4c 55 45 53 28 27 6d 65  6(x6) VALUES('me
32e0: 72 67 65 3d 32 35 30 30 2c 34 27 29 3b 0a 20 20  rge=2500,4');.  
32f0: 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69 64  SELECT level, id
3300: 78 2c 20 73 74 61 72 74 5f 62 6c 6f 63 6b 2c 20  x, start_block, 
3310: 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b  leaves_end_block
3320: 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20 46 52 4f 4d  , end_block FROM
3330: 20 78 36 5f 73 65 67 64 69 72 3b 0a 7d 20 7b 0a   x6_segdir;.} {.
3340: 20 20 31 20 30 20 37 31 39 20 31 31 37 31 20 32    1 0 719 1171 2
3350: 33 36 39 34 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73  3694.}..do_execs
3360: 71 6c 5f 74 65 73 74 20 37 2e 36 20 7b 0a 20 20  ql_test 7.6 {.  
3370: 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 36 28 78  INSERT INTO x6(x
3380: 36 29 20 56 41 4c 55 45 53 28 27 6d 65 72 67 65  6) VALUES('merge
3390: 3d 32 35 30 30 2c 32 27 29 3b 0a 20 20 53 45 4c  =2500,2');.  SEL
33a0: 45 43 54 20 6c 65 76 65 6c 2c 20 69 64 78 2c 20  ECT level, idx, 
33b0: 73 74 61 72 74 5f 62 6c 6f 63 6b 2c 20 6c 65 61  start_block, lea
33c0: 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b 2c 20 65  ves_end_block, e
33d0: 6e 64 5f 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 36  nd_block FROM x6
33e0: 5f 73 65 67 64 69 72 3b 0a 7d 20 7b 0a 20 20 31  _segdir;.} {.  1
33f0: 20 30 20 37 31 39 20 31 31 37 31 20 32 33 36 39   0 719 1171 2369
3400: 34 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  4.}..do_execsql_
3410: 74 65 73 74 20 37 2e 37 20 7b 0a 20 20 53 45 4c  test 7.7 {.  SEL
3420: 45 43 54 20 73 75 6d 28 6c 65 6e 67 74 68 28 62  ECT sum(length(b
3430: 6c 6f 63 6b 29 29 20 46 52 4f 4d 20 78 36 5f 73  lock)) FROM x6_s
3440: 65 67 6d 65 6e 74 73 20 0a 7d 20 7b 36 33 35 32  egments .} {6352
3450: 34 37 7d 0a 0a 0a 66 69 6e 69 73 68 5f 74 65 73  47}...finish_tes
3460: 74 0a                                            t.