/ Hex Artifact Content
Login

Artifact 289833c34ad45a5e6e6133b53b6a71647231fb89d36ddcb8d9c87211b6721d7f:


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 73 71 6c 69 74 65 33 5f 64 62 5f 63  cl..sqlite3_db_c
02c0: 6f 6e 66 69 67 20 64 62 20 44 45 46 45 4e 53 49  onfig db DEFENSI
02d0: 56 45 20 30 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  VE 0.do_execsql_
02e0: 74 65 73 74 20 31 2e 31 20 7b 20 43 52 45 41 54  test 1.1 { CREAT
02f0: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20  E VIRTUAL TABLE 
0300: 78 31 20 55 53 49 4e 47 20 66 74 73 33 3b 20 7d  x1 USING fts3; }
0310: 0a 0a 64 6f 5f 74 65 73 74 20 31 2e 32 20 7b 0a  ..do_test 1.2 {.
0320: 20 20 66 6f 72 65 61 63 68 20 4c 20 7b 0a 20 20    foreach L {.  
0330: 20 20 7b 22 53 65 65 20 68 65 72 65 2c 20 79 6f    {"See here, yo
0340: 75 6e 67 20 6d 61 6e 2c 22 20 73 61 69 64 20 4d  ung man," said M
0350: 75 6c 67 61 20 42 69 6c 6c 2c 20 22 66 72 6f 6d  ulga Bill, "from
0360: 20 57 61 6c 67 65 74 74 20 74 6f 20 74 68 65 20   Walgett to the 
0370: 73 65 61 2c 7d 0a 20 20 20 20 7b 46 72 6f 6d 20  sea,}.    {From 
0380: 43 6f 6e 72 6f 79 27 73 20 47 61 70 20 74 6f 20  Conroy's Gap to 
0390: 43 61 73 74 6c 65 72 65 61 67 68 2c 20 74 68 65  Castlereagh, the
03a0: 72 65 27 73 20 6e 6f 6e 65 20 63 61 6e 20 72 69  re's none can ri
03b0: 64 65 20 6c 69 6b 65 20 6d 65 2e 7d 0a 20 20 20  de like me.}.   
03c0: 20 7b 49 27 6d 20 67 6f 6f 64 20 61 6c 6c 20 72   {I'm good all r
03d0: 6f 75 6e 64 20 61 74 20 65 76 65 72 79 74 68 69  ound at everythi
03e0: 6e 67 20 61 73 20 65 76 65 72 79 62 6f 64 79 20  ng as everybody 
03f0: 6b 6e 6f 77 73 2c 7d 0a 20 20 20 20 7b 41 6c 74  knows,}.    {Alt
0400: 68 6f 75 67 68 20 49 27 6d 20 6e 6f 74 20 74 68  hough I'm not th
0410: 65 20 6f 6e 65 20 74 6f 20 74 61 6c 6b 20 2d 2d  e one to talk --
0420: 20 49 20 68 61 74 65 20 61 20 6d 61 6e 20 74 68   I hate a man th
0430: 61 74 20 62 6c 6f 77 73 2e 7d 0a 20 20 7d 20 7b  at blows.}.  } {
0440: 0a 20 20 20 20 65 78 65 63 73 71 6c 20 7b 20 49  .    execsql { I
0450: 4e 53 45 52 54 20 49 4e 54 4f 20 78 31 20 56 41  NSERT INTO x1 VA
0460: 4c 55 45 53 28 24 4c 29 20 7d 0a 20 20 7d 0a 20  LUES($L) }.  }. 
0470: 20 65 78 65 63 73 71 6c 20 7b 20 53 45 4c 45 43   execsql { SELEC
0480: 54 20 65 6e 64 5f 62 6c 6f 63 6b 2c 20 6c 65 6e  T end_block, len
0490: 67 74 68 28 72 6f 6f 74 29 20 46 52 4f 4d 20 78  gth(root) FROM x
04a0: 31 5f 73 65 67 64 69 72 20 7d 0a 7d 20 7b 7b 30  1_segdir }.} {{0
04b0: 20 31 31 34 7d 20 31 31 34 20 7b 30 20 31 31 38   114} 114 {0 118
04c0: 7d 20 31 31 38 20 7b 30 20 39 35 7d 20 39 35 20  } 118 {0 95} 95 
04d0: 7b 30 20 31 31 35 7d 20 31 31 35 7d 0a 0a 64 6f  {0 115} 115}..do
04e0: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31 2e  _execsql_test 1.
04f0: 33 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  3 {.  INSERT INT
0500: 4f 20 78 31 28 78 31 29 20 56 41 4c 55 45 53 28  O x1(x1) VALUES(
0510: 27 6f 70 74 69 6d 69 7a 65 27 29 3b 0a 20 20 53  'optimize');.  S
0520: 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 65 6e 64  ELECT level, end
0530: 5f 62 6c 6f 63 6b 2c 20 6c 65 6e 67 74 68 28 72  _block, length(r
0540: 6f 6f 74 29 20 46 52 4f 4d 20 78 31 5f 73 65 67  oot) FROM x1_seg
0550: 64 69 72 3b 0a 7d 20 7b 30 20 7b 30 20 33 39 34  dir;.} {0 {0 394
0560: 7d 20 33 39 34 7d 0a 0a 64 6f 5f 74 65 73 74 20  } 394}..do_test 
0570: 31 2e 34 20 7b 0a 20 20 66 6f 72 65 61 63 68 20  1.4 {.  foreach 
0580: 4c 20 7b 0a 20 20 20 20 7b 42 75 74 20 72 69 64  L {.    {But rid
0590: 69 6e 67 20 69 73 20 6d 79 20 73 70 65 63 69 61  ing is my specia
05a0: 6c 20 67 69 66 74 2c 20 6d 79 20 63 68 69 65 66  l gift, my chief
05b0: 65 73 74 2c 20 73 6f 6c 65 20 64 65 6c 69 67 68  est, sole deligh
05c0: 74 3b 7d 0a 20 20 20 20 7b 4a 75 73 74 20 61 73  t;}.    {Just as
05d0: 6b 20 61 20 77 69 6c 64 20 64 75 63 6b 20 63 61  k a wild duck ca
05e0: 6e 20 69 74 20 73 77 69 6d 2c 20 61 20 77 69 6c  n it swim, a wil
05f0: 64 63 61 74 20 63 61 6e 20 69 74 20 66 69 67 68  dcat can it figh
0600: 74 2e 7d 0a 20 20 20 20 7b 54 68 65 72 65 27 73  t.}.    {There's
0610: 20 6e 6f 74 68 69 6e 67 20 63 6c 6f 74 68 65 64   nothing clothed
0620: 20 69 6e 20 68 61 69 72 20 6f 72 20 68 69 64 65   in hair or hide
0630: 2c 20 6f 72 20 62 75 69 6c 74 20 6f 66 20 66 6c  , or built of fl
0640: 65 73 68 20 6f 72 20 73 74 65 65 6c 2c 7d 0a 20  esh or steel,}. 
0650: 20 20 20 7b 54 68 65 72 65 27 73 20 6e 6f 74 68     {There's noth
0660: 69 6e 67 20 77 61 6c 6b 73 20 6f 72 20 6a 75 6d  ing walks or jum
0670: 70 73 2c 20 6f 72 20 72 75 6e 73 2c 20 6f 6e 20  ps, or runs, on 
0680: 61 78 6c 65 2c 20 68 6f 6f 66 2c 20 6f 72 20 77  axle, hoof, or w
0690: 68 65 65 6c 2c 7d 0a 20 20 20 20 7b 42 75 74 20  heel,}.    {But 
06a0: 77 68 61 74 20 49 27 6c 6c 20 73 69 74 2c 20 77  what I'll sit, w
06b0: 68 69 6c 65 20 68 69 64 65 20 77 69 6c 6c 20 68  hile hide will h
06c0: 6f 6c 64 20 61 6e 64 20 67 69 72 74 68 73 20 61  old and girths a
06d0: 6e 64 20 73 74 72 61 70 73 20 61 72 65 20 74 69  nd straps are ti
06e0: 67 68 74 3a 7d 0a 20 20 20 20 7b 49 27 6c 6c 20  ght:}.    {I'll 
06f0: 72 69 64 65 20 74 68 69 73 20 68 65 72 65 20 74  ride this here t
0700: 77 6f 2d 77 68 65 65 6c 65 64 20 63 6f 6e 63 65  wo-wheeled conce
0710: 72 6e 20 72 69 67 68 74 20 73 74 72 61 69 67 68  rn right straigh
0720: 74 20 61 77 61 79 20 61 74 20 73 69 67 68 74 2e  t away at sight.
0730: 22 7d 0a 20 20 7d 20 7b 0a 20 20 20 20 65 78 65  "}.  } {.    exe
0740: 63 73 71 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e  csql { INSERT IN
0750: 54 4f 20 78 31 20 56 41 4c 55 45 53 28 24 4c 29  TO x1 VALUES($L)
0760: 20 7d 0a 20 20 7d 0a 20 20 65 78 65 63 73 71 6c   }.  }.  execsql
0770: 20 7b 20 0a 20 20 20 20 49 4e 53 45 52 54 20 49   { .    INSERT I
0780: 4e 54 4f 20 78 31 28 78 31 29 20 56 41 4c 55 45  NTO x1(x1) VALUE
0790: 53 28 27 6d 65 72 67 65 3d 34 2c 34 27 29 3b 0a  S('merge=4,4');.
07a0: 20 20 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c      SELECT level
07b0: 2c 20 65 6e 64 5f 62 6c 6f 63 6b 2c 20 6c 65 6e  , end_block, len
07c0: 67 74 68 28 72 6f 6f 74 29 20 46 52 4f 4d 20 78  gth(root) FROM x
07d0: 31 5f 73 65 67 64 69 72 3b 0a 20 20 7d 0a 7d 20  1_segdir;.  }.} 
07e0: 7b 31 20 7b 32 32 34 20 39 32 31 7d 20 32 7d 0a  {1 {224 921} 2}.
07f0: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
0800: 20 31 2e 35 20 7b 0a 20 20 53 45 4c 45 43 54 20   1.5 {.  SELECT 
0810: 6c 65 6e 67 74 68 28 62 6c 6f 63 6b 29 20 46 52  length(block) FR
0820: 4f 4d 20 78 31 5f 73 65 67 6d 65 6e 74 73 3b 0a  OM x1_segments;.
0830: 7d 20 7b 39 32 31 20 7b 7d 7d 0a 0a 64 6f 5f 74  } {921 {}}..do_t
0840: 65 73 74 20 31 2e 36 20 7b 0a 20 20 66 6f 72 65  est 1.6 {.  fore
0850: 61 63 68 20 4c 20 7b 0a 20 20 20 20 7b 27 54 77  ach L {.    {'Tw
0860: 61 73 20 4d 75 6c 67 61 20 42 69 6c 6c 2c 20 66  as Mulga Bill, f
0870: 72 6f 6d 20 45 61 67 6c 65 68 61 77 6b 2c 20 74  rom Eaglehawk, t
0880: 68 61 74 20 73 6f 75 67 68 74 20 68 69 73 20 6f  hat sought his o
0890: 77 6e 20 61 62 6f 64 65 2c 7d 0a 20 20 20 20 7b  wn abode,}.    {
08a0: 54 68 61 74 20 70 65 72 63 68 65 64 20 61 62 6f  That perched abo
08b0: 76 65 20 44 65 61 64 20 4d 61 6e 27 73 20 43 72  ve Dead Man's Cr
08c0: 65 65 6b 2c 20 62 65 73 69 64 65 20 74 68 65 20  eek, beside the 
08d0: 6d 6f 75 6e 74 61 69 6e 20 72 6f 61 64 2e 7d 0a  mountain road.}.
08e0: 20 20 20 20 7b 48 65 20 74 75 72 6e 65 64 20 74      {He turned t
08f0: 68 65 20 63 79 63 6c 65 20 64 6f 77 6e 20 74 68  he cycle down th
0900: 65 20 68 69 6c 6c 20 61 6e 64 20 6d 6f 75 6e 74  e hill and mount
0910: 65 64 20 66 6f 72 20 74 68 65 20 66 72 61 79 2c  ed for the fray,
0920: 7d 0a 20 20 20 20 7b 42 75 74 20 27 65 72 65 20  }.    {But 'ere 
0930: 68 65 27 64 20 67 6f 6e 65 20 61 20 64 6f 7a 65  he'd gone a doze
0940: 6e 20 79 61 72 64 73 20 69 74 20 62 6f 6c 74 65  n yards it bolte
0950: 64 20 63 6c 65 61 6e 20 61 77 61 79 2e 7d 0a 0a  d clean away.}..
0960: 20 20 20 20 7b 49 74 20 6c 65 66 74 20 74 68 65      {It left the
0970: 20 74 72 61 63 6b 2c 20 61 6e 64 20 74 68 72 6f   track, and thro
0980: 75 67 68 20 74 68 65 20 74 72 65 65 73 2c 20 6a  ugh the trees, j
0990: 75 73 74 20 6c 69 6b 65 20 61 20 73 69 6c 76 65  ust like a silve
09a0: 72 20 73 74 65 61 6b 2c 7d 0a 20 20 20 20 7b 49  r steak,}.    {I
09b0: 74 20 77 68 69 73 74 6c 65 64 20 64 6f 77 6e 20  t whistled down 
09c0: 74 68 65 20 61 77 66 75 6c 20 73 6c 6f 70 65 20  the awful slope 
09d0: 74 6f 77 61 72 64 73 20 74 68 65 20 44 65 61 64  towards the Dead
09e0: 20 4d 61 6e 27 73 20 43 72 65 65 6b 2e 7d 0a 20   Man's Creek.}. 
09f0: 20 20 20 7b 49 74 20 73 68 61 76 65 64 20 61 20     {It shaved a 
0a00: 73 74 75 6d 70 20 62 79 20 68 61 6c 66 20 61 6e  stump by half an
0a10: 20 69 6e 63 68 2c 20 69 74 20 64 6f 64 67 65 64   inch, it dodged
0a20: 20 61 20 62 69 67 20 77 68 69 74 65 2d 62 6f 78   a big white-box
0a30: 3a 7d 0a 20 20 20 20 7b 54 68 65 20 76 65 72 79  :}.    {The very
0a40: 20 77 61 6c 6c 61 72 6f 6f 73 20 69 6e 20 66 72   wallaroos in fr
0a50: 69 67 68 74 20 77 65 6e 74 20 73 63 72 61 6d 62  ight went scramb
0a60: 6c 69 6e 67 20 75 70 20 74 68 65 20 72 6f 63 6b  ling up the rock
0a70: 73 2c 7d 0a 0a 20 20 20 20 7b 54 68 65 20 77 6f  s,}..    {The wo
0a80: 6d 62 61 74 73 20 68 69 64 69 6e 67 20 69 6e 20  mbats hiding in 
0a90: 74 68 65 69 72 20 63 61 76 65 73 20 64 75 67 20  their caves dug 
0aa0: 64 65 65 70 65 72 20 75 6e 64 65 72 67 72 6f 75  deeper undergrou
0ab0: 6e 64 2c 7d 0a 20 20 20 20 7b 41 73 20 4d 75 6c  nd,}.    {As Mul
0ac0: 67 61 20 42 69 6c 6c 2c 20 61 73 20 77 68 69 74  ga Bill, as whit
0ad0: 65 20 61 73 20 63 68 61 6c 6b 2c 20 73 61 74 20  e as chalk, sat 
0ae0: 74 69 67 68 74 20 74 6f 20 65 76 65 72 79 20 62  tight to every b
0af0: 6f 75 6e 64 2e 7d 0a 20 20 20 20 7b 49 74 20 73  ound.}.    {It s
0b00: 74 72 75 63 6b 20 61 20 73 74 6f 6e 65 20 61 6e  truck a stone an
0b10: 64 20 67 61 76 65 20 61 20 73 70 72 69 6e 67 20  d gave a spring 
0b20: 74 68 61 74 20 63 6c 65 61 72 65 64 20 61 20 66  that cleared a f
0b30: 61 6c 6c 65 6e 20 74 72 65 65 2c 7d 0a 20 20 20  allen tree,}.   
0b40: 20 7b 49 74 20 72 61 63 65 64 20 62 65 73 69 64   {It raced besid
0b50: 65 20 61 20 70 72 65 63 69 70 69 63 65 20 61 73  e a precipice as
0b60: 20 63 6c 6f 73 65 20 61 73 20 63 6c 6f 73 65 20   close as close 
0b70: 63 6f 75 6c 64 20 62 65 3b 7d 0a 0a 20 20 20 20  could be;}..    
0b80: 7b 41 6e 64 20 74 68 65 6e 20 61 73 20 4d 75 6c  {And then as Mul
0b90: 67 61 20 42 69 6c 6c 20 6c 65 74 20 6f 75 74 20  ga Bill let out 
0ba0: 6f 6e 65 20 6c 61 73 74 20 64 65 73 70 61 69 72  one last despair
0bb0: 69 6e 67 20 73 68 72 69 65 6b 7d 0a 20 20 20 20  ing shriek}.    
0bc0: 7b 49 74 20 6d 61 64 65 20 61 20 6c 65 61 70 20  {It made a leap 
0bd0: 6f 66 20 74 77 65 6e 74 79 20 66 65 65 74 20 69  of twenty feet i
0be0: 6e 74 6f 20 74 68 65 20 44 65 61 64 20 4d 61 6e  nto the Dead Man
0bf0: 27 73 20 43 72 65 65 6b 2e 7d 0a 20 20 20 20 7b  's Creek.}.    {
0c00: 49 74 20 73 68 61 76 65 64 20 61 20 73 74 75 6d  It shaved a stum
0c10: 70 20 62 79 20 68 61 6c 66 20 61 6e 20 69 6e 63  p by half an inc
0c20: 68 2c 20 69 74 20 64 6f 64 67 65 64 20 61 20 62  h, it dodged a b
0c30: 69 67 20 77 68 69 74 65 2d 62 6f 78 3a 7d 0a 20  ig white-box:}. 
0c40: 20 20 20 7b 54 68 65 20 76 65 72 79 20 77 61 6c     {The very wal
0c50: 6c 61 72 6f 6f 73 20 69 6e 20 66 72 69 67 68 74  laroos in fright
0c60: 20 77 65 6e 74 20 73 63 72 61 6d 62 6c 69 6e 67   went scrambling
0c70: 20 75 70 20 74 68 65 20 72 6f 63 6b 73 2c 7d 0a   up the rocks,}.
0c80: 20 20 20 20 7b 54 68 65 20 77 6f 6d 62 61 74 73      {The wombats
0c90: 20 68 69 64 69 6e 67 20 69 6e 20 74 68 65 69 72   hiding in their
0ca0: 20 63 61 76 65 73 20 64 75 67 20 64 65 65 70 65   caves dug deepe
0cb0: 72 20 75 6e 64 65 72 67 72 6f 75 6e 64 2c 7d 0a  r underground,}.
0cc0: 20 20 7d 20 7b 0a 20 20 20 20 65 78 65 63 73 71    } {.    execsq
0cd0: 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  l { INSERT INTO 
0ce0: 78 31 20 56 41 4c 55 45 53 28 24 4c 29 20 7d 0a  x1 VALUES($L) }.
0cf0: 20 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b 20    }.  execsql { 
0d00: 0a 20 20 20 20 53 45 4c 45 43 54 20 6c 65 76 65  .    SELECT leve
0d10: 6c 2c 20 65 6e 64 5f 62 6c 6f 63 6b 2c 20 6c 65  l, end_block, le
0d20: 6e 67 74 68 28 72 6f 6f 74 29 20 46 52 4f 4d 20  ngth(root) FROM 
0d30: 78 31 5f 73 65 67 64 69 72 3b 0a 20 20 7d 0a 7d  x1_segdir;.  }.}
0d40: 20 7b 31 20 7b 32 32 34 20 39 32 31 7d 20 32 20   {1 {224 921} 2 
0d50: 31 20 7b 32 32 36 20 31 32 33 30 7d 20 37 20 30  1 {226 1230} 7 0
0d60: 20 7b 30 20 39 38 7d 20 39 38 7d 0a 0a 64 6f 5f   {0 98} 98}..do_
0d70: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31 2e 37  execsql_test 1.7
0d80: 20 7b 0a 20 20 53 45 4c 45 43 54 20 73 75 6d 28   {.  SELECT sum(
0d90: 6c 65 6e 67 74 68 28 62 6c 6f 63 6b 29 29 20 46  length(block)) F
0da0: 52 4f 4d 20 78 31 5f 73 65 67 6d 65 6e 74 73 20  ROM x1_segments 
0db0: 57 48 45 52 45 20 62 6c 6f 63 6b 69 64 20 49 4e  WHERE blockid IN
0dc0: 20 28 32 32 34 2c 32 32 35 2c 32 32 36 29 0a 7d   (224,225,226).}
0dd0: 20 7b 31 32 33 30 7d 0a 0a 23 2d 2d 2d 2d 2d 2d   {1230}..#------
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 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e20: 2d 2d 2d 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c  ---.#.do_execsql
0e30: 5f 74 65 73 74 20 32 2e 31 20 7b 20 0a 20 20 43  _test 2.1 { .  C
0e40: 52 45 41 54 45 20 54 41 42 4c 45 20 74 31 28 64  REATE TABLE t1(d
0e50: 6f 63 69 64 2c 20 77 6f 72 64 73 29 3b 0a 20 20  ocid, words);.  
0e60: 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54  CREATE VIRTUAL T
0e70: 41 42 4c 45 20 78 32 20 55 53 49 4e 47 20 66 74  ABLE x2 USING ft
0e80: 73 34 3b 0a 7d 0a 66 74 73 5f 6b 6a 76 5f 67 65  s4;.}.fts_kjv_ge
0e90: 6e 65 73 69 73 20 0a 64 6f 5f 74 65 73 74 20 32  nesis .do_test 2
0ea0: 2e 32 20 7b 0a 20 20 66 6f 72 65 61 63 68 20 69  .2 {.  foreach i
0eb0: 64 20 5b 64 62 20 65 76 61 6c 20 7b 53 45 4c 45  d [db eval {SELE
0ec0: 43 54 20 64 6f 63 69 64 20 46 52 4f 4d 20 74 31  CT docid FROM t1
0ed0: 7d 5d 20 7b 0a 20 20 20 20 65 78 65 63 73 71 6c  }] {.    execsql
0ee0: 20 7b 0a 20 20 20 20 20 20 49 4e 53 45 52 54 20   {.      INSERT 
0ef0: 49 4e 54 4f 20 78 32 28 64 6f 63 69 64 2c 20 63  INTO x2(docid, c
0f00: 6f 6e 74 65 6e 74 29 20 53 45 4c 45 43 54 20 24  ontent) SELECT $
0f10: 69 64 2c 20 77 6f 72 64 73 20 46 52 4f 4d 20 74  id, words FROM t
0f20: 31 20 57 48 45 52 45 20 64 6f 63 69 64 3d 24 69  1 WHERE docid=$i
0f30: 64 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 66 6f  d.    }.  }.  fo
0f40: 72 65 61 63 68 20 69 64 20 5b 64 62 20 65 76 61  reach id [db eva
0f50: 6c 20 7b 53 45 4c 45 43 54 20 64 6f 63 69 64 20  l {SELECT docid 
0f60: 46 52 4f 4d 20 74 31 7d 5d 20 7b 0a 20 20 20 20  FROM t1}] {.    
0f70: 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 20 20  execsql {.      
0f80: 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 32 28 64  INSERT INTO x2(d
0f90: 6f 63 69 64 2c 20 63 6f 6e 74 65 6e 74 29 20 53  ocid, content) S
0fa0: 45 4c 45 43 54 20 4e 55 4c 4c 2c 20 77 6f 72 64  ELECT NULL, word
0fb0: 73 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20  s FROM t1 WHERE 
0fc0: 64 6f 63 69 64 3d 24 69 64 0a 20 20 20 20 7d 0a  docid=$id.    }.
0fd0: 20 20 20 20 69 66 20 7b 5b 64 62 20 6f 6e 65 20      if {[db one 
0fe0: 7b 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29  {SELECT count(*)
0ff0: 20 46 52 4f 4d 20 78 32 5f 73 65 67 64 69 72 20   FROM x2_segdir 
1000: 57 48 45 52 45 20 6c 65 76 65 6c 3c 32 7d 5d 3d  WHERE level<2}]=
1010: 3d 32 7d 20 62 72 65 61 6b 0a 20 20 7d 0a 7d 20  =2} break.  }.} 
1020: 7b 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  {}..do_execsql_t
1030: 65 73 74 20 32 2e 33 20 7b 20 0a 20 20 53 45 4c  est 2.3 { .  SEL
1040: 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f  ECT count(*) FRO
1050: 4d 20 78 32 5f 73 65 67 64 69 72 20 57 48 45 52  M x2_segdir WHER
1060: 45 20 6c 65 76 65 6c 3d 32 3b 0a 20 20 53 45 4c  E level=2;.  SEL
1070: 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f  ECT count(*) FRO
1080: 4d 20 78 32 5f 73 65 67 64 69 72 20 57 48 45 52  M x2_segdir WHER
1090: 45 20 6c 65 76 65 6c 3d 33 3b 0a 7d 20 7b 36 20  E level=3;.} {6 
10a0: 30 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  0}..do_execsql_t
10b0: 65 73 74 20 32 2e 34 20 7b 20 0a 20 20 49 4e 53  est 2.4 { .  INS
10c0: 45 52 54 20 49 4e 54 4f 20 78 32 28 78 32 29 20  ERT INTO x2(x2) 
10d0: 56 41 4c 55 45 53 28 27 6d 65 72 67 65 3d 34 2c  VALUES('merge=4,
10e0: 34 27 29 3b 0a 20 20 53 45 4c 45 43 54 20 63 6f  4');.  SELECT co
10f0: 75 6e 74 28 2a 29 20 46 52 4f 4d 20 78 32 5f 73  unt(*) FROM x2_s
1100: 65 67 64 69 72 20 57 48 45 52 45 20 6c 65 76 65  egdir WHERE leve
1110: 6c 3d 32 3b 0a 20 20 53 45 4c 45 43 54 20 63 6f  l=2;.  SELECT co
1120: 75 6e 74 28 2a 29 20 46 52 4f 4d 20 78 32 5f 73  unt(*) FROM x2_s
1130: 65 67 64 69 72 20 57 48 45 52 45 20 6c 65 76 65  egdir WHERE leve
1140: 6c 3d 33 3b 0a 7d 20 7b 36 20 31 7d 0a 0a 64 6f  l=3;.} {6 1}..do
1150: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 32 2e  _execsql_test 2.
1160: 35 20 7b 20 0a 20 20 53 45 4c 45 43 54 20 65 6e  5 { .  SELECT en
1170: 64 5f 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 32 5f  d_block FROM x2_
1180: 73 65 67 64 69 72 20 57 48 45 52 45 20 6c 65 76  segdir WHERE lev
1190: 65 6c 3d 33 3b 0a 20 20 49 4e 53 45 52 54 20 49  el=3;.  INSERT I
11a0: 4e 54 4f 20 78 32 28 78 32 29 20 56 41 4c 55 45  NTO x2(x2) VALUE
11b0: 53 28 27 6d 65 72 67 65 3d 34 2c 34 27 29 3b 0a  S('merge=4,4');.
11c0: 20 20 53 45 4c 45 43 54 20 65 6e 64 5f 62 6c 6f    SELECT end_blo
11d0: 63 6b 20 46 52 4f 4d 20 78 32 5f 73 65 67 64 69  ck FROM x2_segdi
11e0: 72 20 57 48 45 52 45 20 6c 65 76 65 6c 3d 33 3b  r WHERE level=3;
11f0: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78  .  INSERT INTO x
1200: 32 28 78 32 29 20 56 41 4c 55 45 53 28 27 6d 65  2(x2) VALUES('me
1210: 72 67 65 3d 34 2c 34 27 29 3b 0a 20 20 53 45 4c  rge=4,4');.  SEL
1220: 45 43 54 20 65 6e 64 5f 62 6c 6f 63 6b 20 46 52  ECT end_block FR
1230: 4f 4d 20 78 32 5f 73 65 67 64 69 72 20 57 48 45  OM x2_segdir WHE
1240: 52 45 20 6c 65 76 65 6c 3d 33 3b 0a 7d 20 7b 7b  RE level=3;.} {{
1250: 35 35 38 38 20 2d 33 39 35 30 7d 20 7b 35 35 38  5588 -3950} {558
1260: 38 20 2d 31 31 37 36 36 7d 20 7b 35 35 38 38 20  8 -11766} {5588 
1270: 2d 31 35 35 34 31 7d 7d 0a 0a 64 6f 5f 65 78 65  -15541}}..do_exe
1280: 63 73 71 6c 5f 74 65 73 74 20 32 2e 36 20 7b 0a  csql_test 2.6 {.
1290: 20 20 53 45 4c 45 43 54 20 73 75 6d 28 6c 65 6e    SELECT sum(len
12a0: 67 74 68 28 62 6c 6f 63 6b 29 29 20 46 52 4f 4d  gth(block)) FROM
12b0: 20 78 32 5f 73 65 67 64 69 72 2c 20 78 32 5f 73   x2_segdir, x2_s
12c0: 65 67 6d 65 6e 74 73 20 57 48 45 52 45 20 0a 20  egments WHERE . 
12d0: 20 20 20 62 6c 6f 63 6b 69 64 20 42 45 54 57 45     blockid BETWE
12e0: 45 4e 20 73 74 61 72 74 5f 62 6c 6f 63 6b 20 41  EN start_block A
12f0: 4e 44 20 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c  ND leaves_end_bl
1300: 6f 63 6b 0a 20 20 20 20 41 4e 44 20 6c 65 76 65  ock.    AND leve
1310: 6c 3d 33 0a 7d 20 7b 31 35 35 34 31 7d 0a 0a 64  l=3.} {15541}..d
1320: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 32  o_execsql_test 2
1330: 2e 37 20 7b 20 0a 20 20 49 4e 53 45 52 54 20 49  .7 { .  INSERT I
1340: 4e 54 4f 20 78 32 28 78 32 29 20 56 41 4c 55 45  NTO x2(x2) VALUE
1350: 53 28 27 6d 65 72 67 65 3d 31 30 30 30 2c 34 27  S('merge=1000,4'
1360: 29 3b 0a 20 20 53 45 4c 45 43 54 20 65 6e 64 5f  );.  SELECT end_
1370: 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 32 5f 73 65  block FROM x2_se
1380: 67 64 69 72 20 57 48 45 52 45 20 6c 65 76 65 6c  gdir WHERE level
1390: 3d 33 3b 0a 7d 20 7b 7b 35 35 38 38 20 31 32 37  =3;.} {{5588 127
13a0: 35 36 33 7d 7d 0a 0a 64 6f 5f 65 78 65 63 73 71  563}}..do_execsq
13b0: 6c 5f 74 65 73 74 20 32 2e 38 20 7b 0a 20 20 53  l_test 2.8 {.  S
13c0: 45 4c 45 43 54 20 73 75 6d 28 6c 65 6e 67 74 68  ELECT sum(length
13d0: 28 62 6c 6f 63 6b 29 29 20 46 52 4f 4d 20 78 32  (block)) FROM x2
13e0: 5f 73 65 67 64 69 72 2c 20 78 32 5f 73 65 67 6d  _segdir, x2_segm
13f0: 65 6e 74 73 20 57 48 45 52 45 20 0a 20 20 20 20  ents WHERE .    
1400: 62 6c 6f 63 6b 69 64 20 42 45 54 57 45 45 4e 20  blockid BETWEEN 
1410: 73 74 61 72 74 5f 62 6c 6f 63 6b 20 41 4e 44 20  start_block AND 
1420: 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b  leaves_end_block
1430: 0a 20 20 20 20 41 4e 44 20 6c 65 76 65 6c 3d 33  .    AND level=3
1440: 0a 7d 20 7b 31 32 37 35 36 33 7d 0a 0a 23 2d 2d  .} {127563}..#--
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 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1480: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1490: 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 65 73 74 20  --------.# Test 
14a0: 74 68 61 74 20 64 65 6c 65 74 65 20 6d 61 72 6b  that delete mark
14b0: 65 72 73 20 61 72 65 20 72 65 6d 6f 76 65 64 20  ers are removed 
14c0: 66 72 6f 6d 20 46 54 53 20 73 65 67 6d 65 6e 74  from FTS segment
14d0: 73 20 77 68 65 6e 20 70 6f 73 73 69 62 6c 65 2e  s when possible.
14e0: 0a 23 20 49 74 20 69 73 20 6f 6e 6c 79 20 70 6f  .# It is only po
14f0: 73 73 69 62 6c 65 20 74 6f 20 72 65 6d 6f 76 65  ssible to remove
1500: 20 64 65 6c 65 74 65 20 6d 61 72 6b 65 72 73 20   delete markers 
1510: 77 68 65 6e 20 74 68 65 20 6f 75 74 70 75 74 20  when the output 
1520: 6f 66 20 74 68 65 0a 23 20 6d 65 72 67 65 20 6f  of the.# merge o
1530: 70 65 72 61 74 69 6f 6e 20 77 69 6c 6c 20 62 65  peration will be
1540: 63 6f 6d 65 20 74 68 65 20 6f 6c 64 65 73 74 20  come the oldest 
1550: 73 65 67 6d 65 6e 74 20 69 6e 20 74 68 65 20 69  segment in the i
1560: 6e 64 65 78 2e 0a 23 0a 23 20 20 20 33 2e 31 20  ndex..#.#   3.1 
1570: 2d 20 77 68 65 6e 20 74 68 65 20 6f 6c 64 65 73  - when the oldes
1580: 74 20 73 65 67 6d 65 6e 74 20 69 73 20 63 72 65  t segment is cre
1590: 61 74 65 64 20 62 79 20 61 6e 20 27 6f 70 74 69  ated by an 'opti
15a0: 6d 69 7a 65 27 2e 0a 23 20 20 20 33 2e 32 20 2d  mize'..#   3.2 -
15b0: 20 77 68 65 6e 20 74 68 65 20 6f 6c 64 65 73 74   when the oldest
15c0: 20 73 65 67 6d 65 6e 74 20 69 73 20 63 72 65 61   segment is crea
15d0: 74 65 64 20 62 79 20 61 6e 20 69 6e 63 72 65 6d  ted by an increm
15e0: 65 6e 74 61 6c 20 6d 65 72 67 65 2e 0a 23 20 20  ental merge..#  
15f0: 20 33 2e 33 20 2d 20 62 79 20 61 20 63 72 69 73   3.3 - by a cris
1600: 69 73 20 6d 65 72 67 65 2e 0a 23 0a 0a 70 72 6f  is merge..#..pro
1610: 63 20 69 6e 73 65 72 74 5f 64 6f 63 20 7b 61 72  c insert_doc {ar
1620: 67 73 7d 20 7b 0a 20 20 66 6f 72 65 61 63 68 20  gs} {.  foreach 
1630: 69 44 6f 63 20 24 61 72 67 73 20 7b 0a 20 20 20  iDoc $args {.   
1640: 20 73 65 74 20 4c 20 5b 6c 69 6e 64 65 78 20 7b   set L [lindex {
1650: 0a 20 20 20 20 20 20 7b 49 6e 20 79 6f 75 72 20  .      {In your 
1660: 65 61 67 65 72 6e 65 73 73 20 74 6f 20 65 6e 67  eagerness to eng
1670: 61 67 65 20 74 68 65 20 54 72 6f 6a 61 6e 73 2c  age the Trojans,
1680: 7d 0a 20 20 20 20 20 20 7b 64 6f 6e e2 80 99 74  }.      {don...t
1690: 20 61 6e 79 20 6f 66 20 79 6f 75 20 63 68 61 72   any of you char
16a0: 67 65 20 61 68 65 61 64 20 6f 66 20 6f 74 68 65  ge ahead of othe
16b0: 72 73 2c 7d 0a 20 20 20 20 20 20 7b 74 72 75 73  rs,}.      {trus
16c0: 74 69 6e 67 20 69 6e 20 79 6f 75 72 20 73 74 72  ting in your str
16d0: 65 6e 67 74 68 20 61 6e 64 20 68 6f 72 73 65 6d  ength and horsem
16e0: 61 6e 73 68 69 70 2e 7d 0a 20 20 20 20 20 20 7b  anship.}.      {
16f0: 41 6e 64 20 64 6f 6e e2 80 99 74 20 6c 61 67 20  And don...t lag 
1700: 62 65 68 69 6e 64 2e 20 54 68 61 74 20 77 69 6c  behind. That wil
1710: 6c 20 68 75 72 74 20 6f 75 72 20 63 68 61 72 67  l hurt our charg
1720: 65 2e 7d 0a 20 20 20 20 20 20 7b 41 6e 79 20 6d  e.}.      {Any m
1730: 61 6e 20 77 68 6f 73 65 20 63 68 61 72 69 6f 74  an whose chariot
1740: 20 63 6f 6e 66 72 6f 6e 74 73 20 61 6e 20 65 6e   confronts an en
1750: 65 6d 79 e2 80 99 73 7d 0a 20 20 20 20 20 20 7b  emy...s}.      {
1760: 73 68 6f 75 6c 64 20 74 68 72 75 73 74 20 77 69  should thrust wi
1770: 74 68 20 68 69 73 20 73 70 65 61 72 20 61 74 20  th his spear at 
1780: 68 69 6d 20 66 72 6f 6d 20 74 68 65 72 65 2e 7d  him from there.}
1790: 0a 20 20 20 20 20 20 7b 54 68 61 74 e2 80 99 73  .      {That...s
17a0: 20 74 68 65 20 6d 6f 73 74 20 65 66 66 65 63 74   the most effect
17b0: 69 76 65 20 74 61 63 74 69 63 2c 20 74 68 65 20  ive tactic, the 
17c0: 77 61 79 7d 0a 20 20 20 20 20 20 7b 6d 65 6e 20  way}.      {men 
17d0: 77 69 70 65 64 20 6f 75 74 20 63 69 74 79 20 73  wiped out city s
17e0: 74 72 6f 6e 67 68 6f 6c 64 73 20 6c 6f 6e 67 20  trongholds long 
17f0: 61 67 6f 20 e2 80 94 7d 0a 20 20 20 20 20 20 7b  ago ...}.      {
1800: 74 68 65 69 72 20 63 68 65 73 74 73 20 66 75 6c  their chests ful
1810: 6c 20 6f 66 20 74 68 61 74 20 73 74 79 6c 65 20  l of that style 
1820: 61 6e 64 20 73 70 69 72 69 74 2e 7d 0a 20 20 20  and spirit.}.   
1830: 20 7d 20 5b 65 78 70 72 20 24 69 44 6f 63 25 39   } [expr $iDoc%9
1840: 5d 5d 0a 20 20 20 20 65 78 65 63 73 71 6c 20 7b  ]].    execsql {
1850: 20 52 45 50 4c 41 43 45 20 49 4e 54 4f 20 78 33   REPLACE INTO x3
1860: 28 64 6f 63 69 64 2c 20 63 6f 6e 74 65 6e 74 29  (docid, content)
1870: 20 56 41 4c 55 45 53 28 24 69 44 6f 63 2c 20 24   VALUES($iDoc, $
1880: 4c 29 20 7d 0a 20 20 7d 0a 7d 0a 0a 70 72 6f 63  L) }.  }.}..proc
1890: 20 64 65 6c 65 74 65 5f 64 6f 63 20 7b 61 72 67   delete_doc {arg
18a0: 73 7d 20 7b 0a 20 20 66 6f 72 65 61 63 68 20 69  s} {.  foreach i
18b0: 44 6f 63 20 24 61 72 67 73 20 7b 0a 20 20 20 20  Doc $args {.    
18c0: 65 78 65 63 73 71 6c 20 7b 20 44 45 4c 45 54 45  execsql { DELETE
18d0: 20 46 52 4f 4d 20 78 33 20 57 48 45 52 45 20 64   FROM x3 WHERE d
18e0: 6f 63 69 64 20 3d 20 24 69 44 6f 63 20 7d 0a 20  ocid = $iDoc }. 
18f0: 20 7d 0a 7d 0a 0a 70 72 6f 63 20 73 65 63 6f 6e   }.}..proc secon
1900: 64 20 7b 78 7d 20 7b 20 6c 69 6e 64 65 78 20 24  d {x} { lindex $
1910: 78 20 31 20 7d 0a 64 62 20 66 75 6e 63 20 73 65  x 1 }.db func se
1920: 63 6f 6e 64 20 73 65 63 6f 6e 64 0a 0a 64 6f 5f  cond second..do_
1930: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 33 2e 30  execsql_test 3.0
1940: 20 7b 20 43 52 45 41 54 45 20 56 49 52 54 55 41   { CREATE VIRTUA
1950: 4c 20 54 41 42 4c 45 20 78 33 20 55 53 49 4e 47  L TABLE x3 USING
1960: 20 66 74 73 34 20 7d 0a 0a 64 6f 5f 74 65 73 74   fts4 }..do_test
1970: 20 33 2e 31 2e 31 20 7b 0a 20 20 64 62 20 74 72   3.1.1 {.  db tr
1980: 61 6e 73 61 63 74 69 6f 6e 20 7b 20 69 6e 73 65  ansaction { inse
1990: 72 74 5f 64 6f 63 20 31 20 32 20 33 20 34 20 35  rt_doc 1 2 3 4 5
19a0: 20 36 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b   6 }.  execsql {
19b0: 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69   SELECT level, i
19c0: 64 78 2c 20 73 65 63 6f 6e 64 28 65 6e 64 5f 62  dx, second(end_b
19d0: 6c 6f 63 6b 29 20 46 52 4f 4d 20 78 33 5f 73 65  lock) FROM x3_se
19e0: 67 64 69 72 20 7d 0a 7d 20 7b 30 20 30 20 34 31  gdir }.} {0 0 41
19f0: 32 7d 0a 64 6f 5f 74 65 73 74 20 33 2e 31 2e 32  2}.do_test 3.1.2
1a00: 20 7b 0a 20 20 64 65 6c 65 74 65 5f 64 6f 63 20   {.  delete_doc 
1a10: 31 20 32 20 33 20 34 20 35 20 36 0a 20 20 65 78  1 2 3 4 5 6.  ex
1a20: 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 63  ecsql { SELECT c
1a30: 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 78 33 5f  ount(*) FROM x3_
1a40: 73 65 67 64 69 72 20 7d 0a 7d 20 7b 30 7d 0a 64  segdir }.} {0}.d
1a50: 6f 5f 74 65 73 74 20 33 2e 31 2e 33 20 7b 0a 20  o_test 3.1.3 {. 
1a60: 20 64 62 20 74 72 61 6e 73 61 63 74 69 6f 6e 20   db transaction 
1a70: 7b 20 0a 20 20 20 20 69 6e 73 65 72 74 5f 64 6f  { .    insert_do
1a80: 63 20 31 20 32 20 33 20 34 20 35 20 36 20 37 20  c 1 2 3 4 5 6 7 
1a90: 38 20 39 0a 20 20 20 20 64 65 6c 65 74 65 5f 64  8 9.    delete_d
1aa0: 6f 63 20 39 20 38 20 37 0a 20 20 7d 0a 20 20 65  oc 9 8 7.  }.  e
1ab0: 78 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54 20  xecsql { SELECT 
1ac0: 6c 65 76 65 6c 2c 20 69 64 78 2c 20 73 65 63 6f  level, idx, seco
1ad0: 6e 64 28 65 6e 64 5f 62 6c 6f 63 6b 29 20 46 52  nd(end_block) FR
1ae0: 4f 4d 20 78 33 5f 73 65 67 64 69 72 20 7d 0a 7d  OM x3_segdir }.}
1af0: 20 7b 30 20 30 20 35 39 31 20 30 20 31 20 36 35   {0 0 591 0 1 65
1b00: 20 30 20 32 20 37 32 20 30 20 33 20 37 36 7d 0a   0 2 72 0 3 76}.
1b10: 64 6f 5f 74 65 73 74 20 33 2e 31 2e 34 20 7b 0a  do_test 3.1.4 {.
1b20: 20 20 65 78 65 63 73 71 6c 20 7b 20 49 4e 53 45    execsql { INSE
1b30: 52 54 20 49 4e 54 4f 20 78 33 28 78 33 29 20 56  RT INTO x3(x3) V
1b40: 41 4c 55 45 53 28 27 6f 70 74 69 6d 69 7a 65 27  ALUES('optimize'
1b50: 29 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b 20  ) }.  execsql { 
1b60: 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69 64  SELECT level, id
1b70: 78 2c 20 73 65 63 6f 6e 64 28 65 6e 64 5f 62 6c  x, second(end_bl
1b80: 6f 63 6b 29 20 46 52 4f 4d 20 78 33 5f 73 65 67  ock) FROM x3_seg
1b90: 64 69 72 20 7d 0a 7d 20 7b 30 20 30 20 34 31 32  dir }.} {0 0 412
1ba0: 7d 0a 0a 64 6f 5f 74 65 73 74 20 33 2e 32 2e 31  }..do_test 3.2.1
1bb0: 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 44   {.  execsql { D
1bc0: 45 4c 45 54 45 20 46 52 4f 4d 20 78 33 20 7d 0a  ELETE FROM x3 }.
1bd0: 20 20 69 6e 73 65 72 74 5f 64 6f 63 20 38 20 37    insert_doc 8 7
1be0: 20 36 20 35 20 34 20 33 20 32 20 31 0a 20 20 64   6 5 4 3 2 1.  d
1bf0: 65 6c 65 74 65 5f 64 6f 63 20 37 20 38 0a 20 20  elete_doc 7 8.  
1c00: 65 78 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54  execsql { SELECT
1c10: 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 78   count(*) FROM x
1c20: 33 5f 73 65 67 64 69 72 20 7d 0a 7d 20 7b 31 30  3_segdir }.} {10
1c30: 7d 0a 64 6f 5f 74 65 73 74 20 33 2e 32 2e 32 20  }.do_test 3.2.2 
1c40: 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 49 4e  {.  execsql { IN
1c50: 53 45 52 54 20 49 4e 54 4f 20 78 33 28 78 33 29  SERT INTO x3(x3)
1c60: 20 56 41 4c 55 45 53 28 27 6d 65 72 67 65 3d 35   VALUES('merge=5
1c70: 30 30 2c 31 30 27 29 20 7d 0a 20 20 65 78 65 63  00,10') }.  exec
1c80: 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 6c 65 76  sql { SELECT lev
1c90: 65 6c 2c 20 69 64 78 2c 20 73 65 63 6f 6e 64 28  el, idx, second(
1ca0: 65 6e 64 5f 62 6c 6f 63 6b 29 20 46 52 4f 4d 20  end_block) FROM 
1cb0: 78 33 5f 73 65 67 64 69 72 20 7d 0a 7d 20 7b 31  x3_segdir }.} {1
1cc0: 20 30 20 34 31 32 7d 0a 0a 23 20 54 68 69 73 20   0 412}..# This 
1cd0: 61 73 73 75 6d 65 73 20 74 68 65 20 63 72 69 73  assumes the cris
1ce0: 69 73 20 6d 65 72 67 65 20 68 61 70 70 65 6e 73  is merge happens
1cf0: 20 77 68 65 6e 20 74 68 65 72 65 20 61 72 65 20   when there are 
1d00: 61 6c 72 65 61 64 79 20 31 36 20 0a 23 20 73 65  already 16 .# se
1d10: 67 6d 65 6e 74 73 20 61 6e 64 20 6f 6e 65 20 6d  gments and one m
1d20: 6f 72 65 20 69 73 20 61 64 64 65 64 2e 0a 23 0a  ore is added..#.
1d30: 64 6f 5f 74 65 73 74 20 33 2e 33 2e 31 20 7b 0a  do_test 3.3.1 {.
1d40: 20 20 65 78 65 63 73 71 6c 20 7b 20 44 45 4c 45    execsql { DELE
1d50: 54 45 20 46 52 4f 4d 20 78 33 20 7d 0a 20 20 69  TE FROM x3 }.  i
1d60: 6e 73 65 72 74 5f 64 6f 63 20 31 20 32 20 33 20  nsert_doc 1 2 3 
1d70: 34 20 35 20 36 20 20 37 20 38 20 39 20 31 30 20  4 5 6  7 8 9 10 
1d80: 31 31 0a 20 20 64 65 6c 65 74 65 5f 64 6f 63 20  11.  delete_doc 
1d90: 31 31 20 31 30 20 39 20 38 20 37 0a 20 20 65 78  11 10 9 8 7.  ex
1da0: 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 63  ecsql { SELECT c
1db0: 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 78 33 5f  ount(*) FROM x3_
1dc0: 73 65 67 64 69 72 20 7d 0a 7d 20 7b 31 36 7d 0a  segdir }.} {16}.
1dd0: 0a 64 6f 5f 74 65 73 74 20 33 2e 33 2e 32 20 7b  .do_test 3.3.2 {
1de0: 0a 20 20 69 6e 73 65 72 74 5f 64 6f 63 20 31 32  .  insert_doc 12
1df0: 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 53 45 4c  .  execsql { SEL
1e00: 45 43 54 20 6c 65 76 65 6c 2c 20 69 64 78 2c 20  ECT level, idx, 
1e10: 73 65 63 6f 6e 64 28 65 6e 64 5f 62 6c 6f 63 6b  second(end_block
1e20: 29 20 46 52 4f 4d 20 78 33 5f 73 65 67 64 69 72  ) FROM x3_segdir
1e30: 20 57 48 45 52 45 20 6c 65 76 65 6c 3d 31 20 7d   WHERE level=1 }
1e40: 0a 7d 20 7b 31 20 30 20 34 31 32 7d 0a 0a 23 2d  .} {1 0 412}..#-
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 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1e80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1e90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 43 68 65 63  ---------.# Chec
1ea0: 6b 20 61 20 74 68 65 6f 72 79 20 6f 6e 20 61 20  k a theory on a 
1eb0: 62 75 67 20 69 6e 20 66 74 73 34 20 2d 20 74 68  bug in fts4 - th
1ec0: 61 74 20 73 65 67 6d 65 6e 74 73 20 77 69 74 68  at segments with
1ed0: 20 69 64 78 3d 3d 30 20 77 65 72 65 20 6e 6f 74   idx==0 were not
1ee0: 20 0a 23 20 62 65 69 6e 67 20 69 6e 63 72 65 6d   .# being increm
1ef0: 65 6e 74 61 6c 6c 79 20 6d 65 72 67 65 64 20 63  entally merged c
1f00: 6f 72 72 65 63 74 6c 79 2e 20 54 68 65 6f 72 79  orrectly. Theory
1f10: 20 74 75 72 6e 65 64 20 6f 75 74 20 74 6f 20 62   turned out to b
1f20: 65 20 66 61 6c 73 65 2e 0a 23 0a 64 6f 5f 65 78  e false..#.do_ex
1f30: 65 63 73 71 6c 5f 74 65 73 74 20 34 2e 31 20 7b  ecsql_test 4.1 {
1f40: 0a 20 20 44 52 4f 50 20 54 41 42 4c 45 20 49 46  .  DROP TABLE IF
1f50: 20 45 58 49 53 54 53 20 78 34 3b 0a 20 20 44 52   EXISTS x4;.  DR
1f60: 4f 50 20 54 41 42 4c 45 20 49 46 20 45 58 49 53  OP TABLE IF EXIS
1f70: 54 53 20 74 31 3b 0a 20 20 43 52 45 41 54 45 20  TS t1;.  CREATE 
1f80: 54 41 42 4c 45 20 74 31 28 64 6f 63 69 64 2c 20  TABLE t1(docid, 
1f90: 77 6f 72 64 73 29 3b 0a 20 20 43 52 45 41 54 45  words);.  CREATE
1fa0: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 78   VIRTUAL TABLE x
1fb0: 34 20 55 53 49 4e 47 20 66 74 73 34 28 77 6f 72  4 USING fts4(wor
1fc0: 64 73 29 3b 0a 7d 0a 64 6f 5f 74 65 73 74 20 34  ds);.}.do_test 4
1fd0: 2e 32 20 7b 0a 20 20 66 74 73 5f 6b 6a 76 5f 67  .2 {.  fts_kjv_g
1fe0: 65 6e 65 73 69 73 20 0a 20 20 65 78 65 63 73 71  enesis .  execsq
1ff0: 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  l { INSERT INTO 
2000: 78 34 20 53 45 4c 45 43 54 20 77 6f 72 64 73 20  x4 SELECT words 
2010: 46 52 4f 4d 20 74 31 20 7d 0a 20 20 65 78 65 63  FROM t1 }.  exec
2020: 73 71 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54  sql { INSERT INT
2030: 4f 20 78 34 20 53 45 4c 45 43 54 20 77 6f 72 64  O x4 SELECT word
2040: 73 20 46 52 4f 4d 20 74 31 20 7d 0a 7d 20 7b 7d  s FROM t1 }.} {}
2050: 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  ..do_execsql_tes
2060: 74 20 34 2e 33 20 7b 0a 20 20 53 45 4c 45 43 54  t 4.3 {.  SELECT
2070: 20 6c 65 76 65 6c 2c 20 69 64 78 2c 20 73 65 63   level, idx, sec
2080: 6f 6e 64 28 65 6e 64 5f 62 6c 6f 63 6b 29 20 46  ond(end_block) F
2090: 52 4f 4d 20 78 34 5f 73 65 67 64 69 72 20 0a 7d  ROM x4_segdir .}
20a0: 20 7b 30 20 30 20 31 31 37 34 38 33 20 30 20 31   {0 0 117483 0 1
20b0: 20 31 31 38 30 30 36 7d 0a 0a 64 6f 5f 65 78 65   118006}..do_exe
20c0: 63 73 71 6c 5f 74 65 73 74 20 34 2e 34 20 7b 0a  csql_test 4.4 {.
20d0: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 34    INSERT INTO x4
20e0: 28 78 34 29 20 56 41 4c 55 45 53 28 27 6d 65 72  (x4) VALUES('mer
20f0: 67 65 3d 31 30 2c 32 27 29 3b 0a 20 20 53 45 4c  ge=10,2');.  SEL
2100: 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f  ECT count(*) FRO
2110: 4d 20 78 34 5f 73 65 67 64 69 72 3b 0a 7d 20 7b  M x4_segdir;.} {
2120: 33 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  3}..do_execsql_t
2130: 65 73 74 20 34 2e 35 20 7b 0a 20 20 49 4e 53 45  est 4.5 {.  INSE
2140: 52 54 20 49 4e 54 4f 20 78 34 28 78 34 29 20 56  RT INTO x4(x4) V
2150: 41 4c 55 45 53 28 27 6d 65 72 67 65 3d 31 30 2c  ALUES('merge=10,
2160: 32 27 29 3b 0a 20 20 53 45 4c 45 43 54 20 63 6f  2');.  SELECT co
2170: 75 6e 74 28 2a 29 20 46 52 4f 4d 20 78 34 5f 73  unt(*) FROM x4_s
2180: 65 67 64 69 72 3b 0a 7d 20 7b 33 7d 0a 0a 64 6f  egdir;.} {3}..do
2190: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 34 2e  _execsql_test 4.
21a0: 36 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  6 {.  INSERT INT
21b0: 4f 20 78 34 28 78 34 29 20 56 41 4c 55 45 53 28  O x4(x4) VALUES(
21c0: 27 6d 65 72 67 65 3d 31 30 30 30 2c 32 27 29 3b  'merge=1000,2');
21d0: 0a 20 20 53 45 4c 45 43 54 20 63 6f 75 6e 74 28  .  SELECT count(
21e0: 2a 29 20 46 52 4f 4d 20 78 34 5f 73 65 67 64 69  *) FROM x4_segdi
21f0: 72 3b 0a 7d 20 7b 31 7d 0a 0a 0a 0a 23 2d 2d 2d  r;.} {1}....#---
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 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2230: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2240: 2d 2d 2d 2d 2d 2d 2d 0a 23 20 43 68 65 63 6b 20  -------.# Check 
2250: 74 68 61 74 20 73 65 67 6d 65 6e 74 73 20 61 72  that segments ar
2260: 65 20 6e 6f 74 20 70 72 6f 6d 6f 74 65 64 20 69  e not promoted i
2270: 66 20 74 68 65 20 22 65 6e 64 5f 62 6c 6f 63 6b  f the "end_block
2280: 22 20 66 69 65 6c 64 20 64 6f 65 73 20 6e 6f 74  " field does not
2290: 0a 23 20 63 6f 6e 74 61 69 6e 20 61 20 73 69 7a  .# contain a siz
22a0: 65 2e 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  e..#.do_execsql_
22b0: 74 65 73 74 20 35 2e 31 20 7b 0a 20 20 44 52 4f  test 5.1 {.  DRO
22c0: 50 20 54 41 42 4c 45 20 49 46 20 45 58 49 53 54  P TABLE IF EXIST
22d0: 53 20 78 32 3b 0a 20 20 44 52 4f 50 20 54 41 42  S x2;.  DROP TAB
22e0: 4c 45 20 49 46 20 45 58 49 53 54 53 20 74 31 3b  LE IF EXISTS t1;
22f0: 0a 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20  .  CREATE TABLE 
2300: 74 31 28 64 6f 63 69 64 2c 20 77 6f 72 64 73 29  t1(docid, words)
2310: 3b 0a 20 20 43 52 45 41 54 45 20 56 49 52 54 55  ;.  CREATE VIRTU
2320: 41 4c 20 54 41 42 4c 45 20 78 32 20 55 53 49 4e  AL TABLE x2 USIN
2330: 47 20 66 74 73 34 3b 0a 7d 0a 66 74 73 5f 6b 6a  G fts4;.}.fts_kj
2340: 76 5f 67 65 6e 65 73 69 73 20 0a 0a 70 72 6f 63  v_genesis ..proc
2350: 20 66 69 72 73 74 20 7b 4c 7d 20 7b 6c 69 6e 64   first {L} {lind
2360: 65 78 20 24 4c 20 30 7d 0a 64 62 20 66 75 6e 63  ex $L 0}.db func
2370: 20 66 69 72 73 74 20 66 69 72 73 74 0a 0a 64 6f   first first..do
2380: 5f 74 65 73 74 20 35 2e 32 20 7b 0a 20 20 66 6f  _test 5.2 {.  fo
2390: 72 65 61 63 68 20 72 20 5b 64 62 20 65 76 61 6c  reach r [db eval
23a0: 20 7b 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20   { SELECT rowid 
23b0: 46 52 4f 4d 20 74 31 20 7d 5d 20 7b 0a 20 20 20  FROM t1 }] {.   
23c0: 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 20   execsql {.     
23d0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 32 28   INSERT INTO x2(
23e0: 64 6f 63 69 64 2c 20 63 6f 6e 74 65 6e 74 29 20  docid, content) 
23f0: 53 45 4c 45 43 54 20 64 6f 63 69 64 2c 20 77 6f  SELECT docid, wo
2400: 72 64 73 20 46 52 4f 4d 20 74 31 20 57 48 45 52  rds FROM t1 WHER
2410: 45 20 72 6f 77 69 64 3d 24 72 0a 20 20 20 20 7d  E rowid=$r.    }
2420: 0a 20 20 7d 0a 20 20 66 6f 72 65 61 63 68 20 64  .  }.  foreach d
2430: 20 5b 64 62 20 65 76 61 6c 20 7b 20 53 45 4c 45   [db eval { SELE
2440: 43 54 20 64 6f 63 69 64 20 46 52 4f 4d 20 74 31  CT docid FROM t1
2450: 20 4c 49 4d 49 54 20 2d 31 20 4f 46 46 53 45 54   LIMIT -1 OFFSET
2460: 20 32 30 20 7d 5d 20 7b 0a 20 20 20 20 65 78 65   20 }] {.    exe
2470: 63 73 71 6c 20 7b 20 44 45 4c 45 54 45 20 46 52  csql { DELETE FR
2480: 4f 4d 20 78 32 20 57 48 45 52 45 20 64 6f 63 69  OM x2 WHERE doci
2490: 64 20 3d 20 24 64 20 7d 0a 20 20 7d 0a 0a 20 20  d = $d }.  }..  
24a0: 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 49 4e  execsql {.    IN
24b0: 53 45 52 54 20 49 4e 54 4f 20 78 32 28 78 32 29  SERT INTO x2(x2)
24c0: 20 56 41 4c 55 45 53 28 27 6f 70 74 69 6d 69 7a   VALUES('optimiz
24d0: 65 27 29 3b 0a 20 20 20 20 53 45 4c 45 43 54 20  e');.    SELECT 
24e0: 6c 65 76 65 6c 2c 20 69 64 78 2c 20 65 6e 64 5f  level, idx, end_
24f0: 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 32 5f 73 65  block FROM x2_se
2500: 67 64 69 72 0a 20 20 7d 0a 7d 20 7b 32 20 30 20  gdir.  }.} {2 0 
2510: 7b 37 35 32 20 31 39 32 36 7d 7d 0a 0a 64 6f 5f  {752 1926}}..do_
2520: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 35 2e 33  execsql_test 5.3
2530: 20 7b 0a 20 20 55 50 44 41 54 45 20 78 32 5f 73   {.  UPDATE x2_s
2540: 65 67 64 69 72 20 53 45 54 20 65 6e 64 5f 62 6c  egdir SET end_bl
2550: 6f 63 6b 20 3d 20 43 41 53 54 28 20 66 69 72 73  ock = CAST( firs
2560: 74 28 65 6e 64 5f 62 6c 6f 63 6b 29 20 41 53 20  t(end_block) AS 
2570: 49 4e 54 45 47 45 52 20 29 3b 0a 20 20 53 45 4c  INTEGER );.  SEL
2580: 45 43 54 20 65 6e 64 5f 62 6c 6f 63 6b 2c 20 74  ECT end_block, t
2590: 79 70 65 6f 66 28 65 6e 64 5f 62 6c 6f 63 6b 29  ypeof(end_block)
25a0: 20 46 52 4f 4d 20 78 32 5f 73 65 67 64 69 72 3b   FROM x2_segdir;
25b0: 0a 7d 20 7b 37 35 32 20 69 6e 74 65 67 65 72 7d  .} {752 integer}
25c0: 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  ..do_execsql_tes
25d0: 74 20 35 2e 34 20 7b 0a 20 20 49 4e 53 45 52 54  t 5.4 {.  INSERT
25e0: 20 49 4e 54 4f 20 78 32 20 53 45 4c 45 43 54 20   INTO x2 SELECT 
25f0: 77 6f 72 64 73 20 46 52 4f 4d 20 74 31 20 4c 49  words FROM t1 LI
2600: 4d 49 54 20 35 30 3b 0a 20 20 53 45 4c 45 43 54  MIT 50;.  SELECT
2610: 20 6c 65 76 65 6c 2c 20 69 64 78 2c 20 65 6e 64   level, idx, end
2620: 5f 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 32 5f 73  _block FROM x2_s
2630: 65 67 64 69 72 0a 7d 20 7b 32 20 30 20 37 35 32  egdir.} {2 0 752
2640: 20 30 20 30 20 7b 37 35 38 20 35 31 37 34 7d 7d   0 0 {758 5174}}
2650: 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  ..do_execsql_tes
2660: 74 20 35 2e 35 20 7b 0a 20 20 55 50 44 41 54 45  t 5.5 {.  UPDATE
2670: 20 78 32 5f 73 65 67 64 69 72 20 53 45 54 20 65   x2_segdir SET e
2680: 6e 64 5f 62 6c 6f 63 6b 20 3d 20 65 6e 64 5f 62  nd_block = end_b
2690: 6c 6f 63 6b 20 7c 7c 20 27 20 31 39 32 36 27 20  lock || ' 1926' 
26a0: 57 48 45 52 45 20 6c 65 76 65 6c 3d 32 3b 0a 20  WHERE level=2;. 
26b0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 32 20   INSERT INTO x2 
26c0: 53 45 4c 45 43 54 20 77 6f 72 64 73 20 46 52 4f  SELECT words FRO
26d0: 4d 20 74 31 20 4c 49 4d 49 54 20 34 30 3b 0a 20  M t1 LIMIT 40;. 
26e0: 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69   SELECT level, i
26f0: 64 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20 46 52  dx, end_block FR
2700: 4f 4d 20 78 32 5f 73 65 67 64 69 72 0a 7d 20 7b  OM x2_segdir.} {
2710: 30 20 30 20 7b 37 35 32 20 31 39 32 36 7d 20 30  0 0 {752 1926} 0
2720: 20 31 20 7b 37 35 38 20 35 31 37 34 7d 20 30 20   1 {758 5174} 0 
2730: 32 20 7b 37 36 33 20 34 31 37 30 7d 7d 0a 0a 70  2 {763 4170}}..p
2740: 72 6f 63 20 74 31 5f 74 6f 5f 78 32 20 7b 7d 20  roc t1_to_x2 {} 
2750: 7b 0a 20 20 66 6f 72 65 61 63 68 20 69 64 20 5b  {.  foreach id [
2760: 64 62 20 65 76 61 6c 20 7b 53 45 4c 45 43 54 20  db eval {SELECT 
2770: 64 6f 63 69 64 20 46 52 4f 4d 20 74 31 20 4c 49  docid FROM t1 LI
2780: 4d 49 54 20 32 7d 5d 20 7b 0a 20 20 20 20 65 78  MIT 2}] {.    ex
2790: 65 63 73 71 6c 20 7b 0a 20 20 20 20 20 20 44 45  ecsql {.      DE
27a0: 4c 45 54 45 20 46 52 4f 4d 20 78 32 20 57 48 45  LETE FROM x2 WHE
27b0: 52 45 20 64 6f 63 69 64 3d 24 69 64 3b 0a 20 20  RE docid=$id;.  
27c0: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
27d0: 78 32 28 64 6f 63 69 64 2c 20 63 6f 6e 74 65 6e  x2(docid, conten
27e0: 74 29 20 53 45 4c 45 43 54 20 24 69 64 2c 20 77  t) SELECT $id, w
27f0: 6f 72 64 73 20 46 52 4f 4d 20 74 31 20 57 48 45  ords FROM t1 WHE
2800: 52 45 20 64 6f 63 69 64 3d 24 69 64 3b 0a 20 20  RE docid=$id;.  
2810: 20 20 7d 0a 20 20 7d 0a 7d 0a 0a 23 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 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2850: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2860: 2d 2d 2d 2d 2d 2d 0a 23 20 43 68 65 63 6b 20 74  ------.# Check t
2870: 68 61 74 20 73 65 67 6d 65 6e 74 73 20 63 72 65  hat segments cre
2880: 61 74 65 64 20 62 79 20 61 75 74 6f 2d 6d 65 72  ated by auto-mer
2890: 67 65 20 61 72 65 20 6e 6f 74 20 70 72 6f 6d 6f  ge are not promo
28a0: 74 65 64 20 75 6e 74 69 6c 20 74 68 65 79 0a 23  ted until they.#
28b0: 20 61 72 65 20 63 6f 6d 70 6c 65 74 65 64 2e 0a   are completed..
28c0: 23 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  #..do_execsql_te
28d0: 73 74 20 36 2e 31 20 7b 0a 20 20 43 52 45 41 54  st 6.1 {.  CREAT
28e0: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20  E VIRTUAL TABLE 
28f0: 78 35 20 55 53 49 4e 47 20 66 74 73 34 3b 0a 20  x5 USING fts4;. 
2900: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 35 20   INSERT INTO x5 
2910: 53 45 4c 45 43 54 20 77 6f 72 64 73 20 46 52 4f  SELECT words FRO
2920: 4d 20 74 31 20 4c 49 4d 49 54 20 31 30 30 20 4f  M t1 LIMIT 100 O
2930: 46 46 53 45 54 20 30 3b 0a 20 20 49 4e 53 45 52  FFSET 0;.  INSER
2940: 54 20 49 4e 54 4f 20 78 35 20 53 45 4c 45 43 54  T INTO x5 SELECT
2950: 20 77 6f 72 64 73 20 46 52 4f 4d 20 74 31 20 4c   words FROM t1 L
2960: 49 4d 49 54 20 31 30 30 20 4f 46 46 53 45 54 20  IMIT 100 OFFSET 
2970: 32 35 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  25;.  INSERT INT
2980: 4f 20 78 35 20 53 45 4c 45 43 54 20 77 6f 72 64  O x5 SELECT word
2990: 73 20 46 52 4f 4d 20 74 31 20 4c 49 4d 49 54 20  s FROM t1 LIMIT 
29a0: 31 30 30 20 4f 46 46 53 45 54 20 35 30 3b 0a 20  100 OFFSET 50;. 
29b0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 35 20   INSERT INTO x5 
29c0: 53 45 4c 45 43 54 20 77 6f 72 64 73 20 46 52 4f  SELECT words FRO
29d0: 4d 20 74 31 20 4c 49 4d 49 54 20 31 30 30 20 4f  M t1 LIMIT 100 O
29e0: 46 46 53 45 54 20 37 35 3b 0a 20 20 53 45 4c 45  FFSET 75;.  SELE
29f0: 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d  CT count(*) FROM
2a00: 20 78 35 5f 73 65 67 64 69 72 0a 7d 20 7b 34 7d   x5_segdir.} {4}
2a10: 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  ..do_execsql_tes
2a20: 74 20 36 2e 32 20 7b 0a 20 20 49 4e 53 45 52 54  t 6.2 {.  INSERT
2a30: 20 49 4e 54 4f 20 78 35 28 78 35 29 20 56 41 4c   INTO x5(x5) VAL
2a40: 55 45 53 28 27 6d 65 72 67 65 3d 32 2c 34 27 29  UES('merge=2,4')
2a50: 3b 0a 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c  ;.  SELECT level
2a60: 2c 20 69 64 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b  , idx, end_block
2a70: 20 46 52 4f 4d 20 78 35 5f 73 65 67 64 69 72 3b   FROM x5_segdir;
2a80: 0a 7d 20 7b 30 20 30 20 7b 31 30 20 39 32 31 36  .} {0 0 {10 9216
2a90: 7d 20 30 20 31 20 7b 32 31 20 39 33 33 30 7d 20  } 0 1 {21 9330} 
2aa0: 30 20 32 20 7b 33 31 20 38 38 35 30 7d 20 30 20  0 2 {31 8850} 0 
2ab0: 33 20 7b 34 30 20 38 36 38 39 7d 20 31 20 30 20  3 {40 8689} 1 0 
2ac0: 7b 31 33 32 30 20 2d 33 31 31 37 7d 7d 0a 0a 64  {1320 -3117}}..d
2ad0: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 36  o_execsql_test 6
2ae0: 2e 33 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e  .3 {.  INSERT IN
2af0: 54 4f 20 78 35 20 53 45 4c 45 43 54 20 77 6f 72  TO x5 SELECT wor
2b00: 64 73 20 46 52 4f 4d 20 74 31 20 4c 49 4d 49 54  ds FROM t1 LIMIT
2b10: 20 31 30 30 20 4f 46 46 53 45 54 20 31 30 30 3b   100 OFFSET 100;
2b20: 0a 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c  .  SELECT level,
2b30: 20 69 64 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20   idx, end_block 
2b40: 46 52 4f 4d 20 78 35 5f 73 65 67 64 69 72 3b 0a  FROM x5_segdir;.
2b50: 7d 20 7b 0a 20 20 30 20 30 20 7b 31 30 20 39 32  } {.  0 0 {10 92
2b60: 31 36 7d 20 30 20 31 20 7b 32 31 20 39 33 33 30  16} 0 1 {21 9330
2b70: 7d 20 30 20 32 20 7b 33 31 20 38 38 35 30 7d 20  } 0 2 {31 8850} 
2b80: 0a 20 20 30 20 33 20 7b 34 30 20 38 36 38 39 7d  .  0 3 {40 8689}
2b90: 20 31 20 30 20 7b 31 33 32 30 20 2d 33 31 31 37   1 0 {1320 -3117
2ba0: 7d 20 30 20 34 20 7b 31 33 32 39 20 38 32 39 37  } 0 4 {1329 8297
2bb0: 7d 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  }.}..do_execsql_
2bc0: 74 65 73 74 20 36 2e 34 20 7b 0a 20 20 49 4e 53  test 6.4 {.  INS
2bd0: 45 52 54 20 49 4e 54 4f 20 78 35 28 78 35 29 20  ERT INTO x5(x5) 
2be0: 56 41 4c 55 45 53 28 27 6d 65 72 67 65 3d 32 30  VALUES('merge=20
2bf0: 30 2c 34 27 29 3b 0a 20 20 53 45 4c 45 43 54 20  0,4');.  SELECT 
2c00: 6c 65 76 65 6c 2c 20 69 64 78 2c 20 65 6e 64 5f  level, idx, end_
2c10: 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 35 5f 73 65  block FROM x5_se
2c20: 67 64 69 72 3b 0a 7d 20 7b 30 20 30 20 7b 31 33  gdir;.} {0 0 {13
2c30: 32 39 20 38 32 39 37 7d 20 31 20 30 20 7b 31 33  29 8297} 1 0 {13
2c40: 32 30 20 32 38 30 30 39 7d 7d 0a 0a 64 6f 5f 65  20 28009}}..do_e
2c50: 78 65 63 73 71 6c 5f 74 65 73 74 20 36 2e 35 20  xecsql_test 6.5 
2c60: 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  {.  INSERT INTO 
2c70: 78 35 20 53 45 4c 45 43 54 20 77 6f 72 64 73 20  x5 SELECT words 
2c80: 46 52 4f 4d 20 74 31 3b 0a 20 20 53 45 4c 45 43  FROM t1;.  SELEC
2c90: 54 20 6c 65 76 65 6c 2c 20 69 64 78 2c 20 65 6e  T level, idx, en
2ca0: 64 5f 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 35 5f  d_block FROM x5_
2cb0: 73 65 67 64 69 72 3b 0a 7d 20 7b 0a 20 20 30 20  segdir;.} {.  0 
2cc0: 31 20 7b 31 33 32 39 20 38 32 39 37 7d 20 30 20  1 {1329 8297} 0 
2cd0: 30 20 7b 31 33 32 30 20 32 38 30 30 39 7d 20 30  0 {1320 28009} 0
2ce0: 20 32 20 7b 31 34 34 39 20 31 31 38 30 30 36 7d   2 {1449 118006}
2cf0: 0a 7d 0a 0a 23 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 2d 2d  ----------------
2d20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2d30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
2d40: 23 20 45 6e 73 75 72 65 20 74 68 61 74 20 69 66  # Ensure that if
2d50: 20 70 61 72 74 20 6f 66 20 61 6e 20 69 6e 63 72   part of an incr
2d60: 65 6d 65 6e 74 61 6c 20 6d 65 72 67 65 20 69 73  emental merge is
2d70: 20 70 65 72 66 6f 72 6d 65 64 20 62 79 20 61 6e   performed by an
2d80: 20 6f 6c 64 0a 23 20 76 65 72 73 69 6f 6e 20 74   old.# version t
2d90: 68 61 74 20 64 6f 65 73 20 6e 6f 74 20 73 75 70  hat does not sup
2da0: 70 6f 72 74 20 73 74 6f 72 69 6e 67 20 73 65 67  port storing seg
2db0: 6d 65 6e 74 20 73 69 7a 65 73 20 69 6e 20 74 68  ment sizes in th
2dc0: 65 20 65 6e 64 5f 62 6c 6f 63 6b 0a 23 20 66 69  e end_block.# fi
2dd0: 65 6c 64 2c 20 6e 6f 20 73 69 7a 65 20 69 73 20  eld, no size is 
2de0: 73 74 6f 72 65 64 20 69 6e 20 74 68 65 20 66 69  stored in the fi
2df0: 6e 61 6c 20 73 65 67 6d 65 6e 74 20 28 61 73 20  nal segment (as 
2e00: 69 74 20 77 6f 75 6c 64 20 62 65 20 69 6e 63 6f  it would be inco
2e10: 72 72 65 63 74 29 2e 0a 23 0a 64 6f 5f 65 78 65  rrect)..#.do_exe
2e20: 63 73 71 6c 5f 74 65 73 74 20 37 2e 31 20 7b 0a  csql_test 7.1 {.
2e30: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
2e40: 20 54 41 42 4c 45 20 78 36 20 55 53 49 4e 47 20   TABLE x6 USING 
2e50: 66 74 73 34 3b 0a 20 20 49 4e 53 45 52 54 20 49  fts4;.  INSERT I
2e60: 4e 54 4f 20 78 36 20 53 45 4c 45 43 54 20 77 6f  NTO x6 SELECT wo
2e70: 72 64 73 20 46 52 4f 4d 20 74 31 3b 0a 20 20 49  rds FROM t1;.  I
2e80: 4e 53 45 52 54 20 49 4e 54 4f 20 78 36 20 53 45  NSERT INTO x6 SE
2e90: 4c 45 43 54 20 77 6f 72 64 73 20 46 52 4f 4d 20  LECT words FROM 
2ea0: 74 31 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  t1;.  INSERT INT
2eb0: 4f 20 78 36 20 53 45 4c 45 43 54 20 77 6f 72 64  O x6 SELECT word
2ec0: 73 20 46 52 4f 4d 20 74 31 3b 0a 20 20 49 4e 53  s FROM t1;.  INS
2ed0: 45 52 54 20 49 4e 54 4f 20 78 36 20 53 45 4c 45  ERT INTO x6 SELE
2ee0: 43 54 20 77 6f 72 64 73 20 46 52 4f 4d 20 74 31  CT words FROM t1
2ef0: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
2f00: 78 36 20 53 45 4c 45 43 54 20 77 6f 72 64 73 20  x6 SELECT words 
2f10: 46 52 4f 4d 20 74 31 3b 0a 20 20 49 4e 53 45 52  FROM t1;.  INSER
2f20: 54 20 49 4e 54 4f 20 78 36 20 53 45 4c 45 43 54  T INTO x6 SELECT
2f30: 20 77 6f 72 64 73 20 46 52 4f 4d 20 74 31 3b 0a   words FROM t1;.
2f40: 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20    SELECT level, 
2f50: 69 64 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20 46  idx, end_block F
2f60: 52 4f 4d 20 78 36 5f 73 65 67 64 69 72 3b 0a 7d  ROM x6_segdir;.}
2f70: 20 7b 0a 20 20 30 20 30 20 7b 31 31 38 20 31 31   {.  0 0 {118 11
2f80: 37 34 38 33 7d 20 30 20 31 20 7b 32 33 38 20 31  7483} 0 1 {238 1
2f90: 31 38 30 30 36 7d 20 30 20 32 20 7b 33 35 38 20  18006} 0 2 {358 
2fa0: 31 31 38 30 30 36 7d 20 0a 20 20 30 20 33 20 7b  118006} .  0 3 {
2fb0: 34 37 38 20 31 31 38 30 30 36 7d 20 30 20 34 20  478 118006} 0 4 
2fc0: 7b 35 39 38 20 31 31 38 30 30 36 7d 20 30 20 35  {598 118006} 0 5
2fd0: 20 7b 37 31 38 20 31 31 38 30 30 36 7d 0a 7d 0a   {718 118006}.}.
2fe0: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
2ff0: 20 37 2e 32 20 7b 0a 20 20 49 4e 53 45 52 54 20   7.2 {.  INSERT 
3000: 49 4e 54 4f 20 78 36 28 78 36 29 20 56 41 4c 55  INTO x6(x6) VALU
3010: 45 53 28 27 6d 65 72 67 65 3d 32 35 2c 34 27 29  ES('merge=25,4')
3020: 3b 0a 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c  ;.  SELECT level
3030: 2c 20 69 64 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b  , idx, end_block
3040: 20 46 52 4f 4d 20 78 36 5f 73 65 67 64 69 72 3b   FROM x6_segdir;
3050: 0a 7d 20 7b 0a 20 20 30 20 30 20 7b 31 31 38 20  .} {.  0 0 {118 
3060: 31 31 37 34 38 33 7d 20 30 20 31 20 7b 32 33 38  117483} 0 1 {238
3070: 20 31 31 38 30 30 36 7d 20 30 20 32 20 7b 33 35   118006} 0 2 {35
3080: 38 20 31 31 38 30 30 36 7d 20 0a 20 20 30 20 33  8 118006} .  0 3
3090: 20 7b 34 37 38 20 31 31 38 30 30 36 7d 20 30 20   {478 118006} 0 
30a0: 34 20 7b 35 39 38 20 31 31 38 30 30 36 7d 20 30  4 {598 118006} 0
30b0: 20 35 20 7b 37 31 38 20 31 31 38 30 30 36 7d 0a   5 {718 118006}.
30c0: 20 20 31 20 30 20 7b 32 33 36 39 34 20 2d 36 39    1 0 {23694 -69
30d0: 34 37 37 7d 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73  477}.}..do_execs
30e0: 71 6c 5f 74 65 73 74 20 37 2e 33 20 7b 0a 20 20  ql_test 7.3 {.  
30f0: 55 50 44 41 54 45 20 78 36 5f 73 65 67 64 69 72  UPDATE x6_segdir
3100: 20 53 45 54 20 65 6e 64 5f 62 6c 6f 63 6b 20 3d   SET end_block =
3110: 20 66 69 72 73 74 28 65 6e 64 5f 62 6c 6f 63 6b   first(end_block
3120: 29 20 57 48 45 52 45 20 6c 65 76 65 6c 3d 31 3b  ) WHERE level=1;
3130: 0a 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c  .  SELECT level,
3140: 20 69 64 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20   idx, end_block 
3150: 46 52 4f 4d 20 78 36 5f 73 65 67 64 69 72 3b 0a  FROM x6_segdir;.
3160: 7d 20 7b 0a 20 20 30 20 30 20 7b 31 31 38 20 31  } {.  0 0 {118 1
3170: 31 37 34 38 33 7d 20 30 20 31 20 7b 32 33 38 20  17483} 0 1 {238 
3180: 31 31 38 30 30 36 7d 20 30 20 32 20 7b 33 35 38  118006} 0 2 {358
3190: 20 31 31 38 30 30 36 7d 20 0a 20 20 30 20 33 20   118006} .  0 3 
31a0: 7b 34 37 38 20 31 31 38 30 30 36 7d 20 30 20 34  {478 118006} 0 4
31b0: 20 7b 35 39 38 20 31 31 38 30 30 36 7d 20 30 20   {598 118006} 0 
31c0: 35 20 7b 37 31 38 20 31 31 38 30 30 36 7d 0a 20  5 {718 118006}. 
31d0: 20 31 20 30 20 32 33 36 39 34 0a 7d 0a 0a 64 6f   1 0 23694.}..do
31e0: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 37 2e  _execsql_test 7.
31f0: 34 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  4 {.  INSERT INT
3200: 4f 20 78 36 28 78 36 29 20 56 41 4c 55 45 53 28  O x6(x6) VALUES(
3210: 27 6d 65 72 67 65 3d 32 35 2c 34 27 29 3b 0a 20  'merge=25,4');. 
3220: 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69   SELECT level, i
3230: 64 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20 46 52  dx, end_block FR
3240: 4f 4d 20 78 36 5f 73 65 67 64 69 72 3b 0a 7d 20  OM x6_segdir;.} 
3250: 7b 0a 20 20 30 20 30 20 7b 31 31 38 20 31 31 37  {.  0 0 {118 117
3260: 34 38 33 7d 20 30 20 31 20 7b 32 33 38 20 31 31  483} 0 1 {238 11
3270: 38 30 30 36 7d 20 30 20 32 20 7b 33 35 38 20 31  8006} 0 2 {358 1
3280: 31 38 30 30 36 7d 20 0a 20 20 30 20 33 20 7b 34  18006} .  0 3 {4
3290: 37 38 20 31 31 38 30 30 36 7d 20 30 20 34 20 7b  78 118006} 0 4 {
32a0: 35 39 38 20 31 31 38 30 30 36 7d 20 30 20 35 20  598 118006} 0 5 
32b0: 7b 37 31 38 20 31 31 38 30 30 36 7d 0a 20 20 31  {718 118006}.  1
32c0: 20 30 20 32 33 36 39 34 0a 7d 0a 0a 64 6f 5f 65   0 23694.}..do_e
32d0: 78 65 63 73 71 6c 5f 74 65 73 74 20 37 2e 35 20  xecsql_test 7.5 
32e0: 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  {.  INSERT INTO 
32f0: 78 36 28 78 36 29 20 56 41 4c 55 45 53 28 27 6d  x6(x6) VALUES('m
3300: 65 72 67 65 3d 32 35 30 30 2c 34 27 29 3b 0a 20  erge=2500,4');. 
3310: 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69   SELECT level, i
3320: 64 78 2c 20 73 74 61 72 74 5f 62 6c 6f 63 6b 2c  dx, start_block,
3330: 20 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63   leaves_end_bloc
3340: 6b 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20 46 52 4f  k, end_block FRO
3350: 4d 20 78 36 5f 73 65 67 64 69 72 3b 0a 7d 20 7b  M x6_segdir;.} {
3360: 0a 20 20 31 20 30 20 37 31 39 20 31 31 37 31 20  .  1 0 719 1171 
3370: 32 33 36 39 34 0a 7d 0a 0a 64 6f 5f 65 78 65 63  23694.}..do_exec
3380: 73 71 6c 5f 74 65 73 74 20 37 2e 36 20 7b 0a 20  sql_test 7.6 {. 
3390: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 36 28   INSERT INTO x6(
33a0: 78 36 29 20 56 41 4c 55 45 53 28 27 6d 65 72 67  x6) VALUES('merg
33b0: 65 3d 32 35 30 30 2c 32 27 29 3b 0a 20 20 53 45  e=2500,2');.  SE
33c0: 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69 64 78 2c  LECT level, idx,
33d0: 20 73 74 61 72 74 5f 62 6c 6f 63 6b 2c 20 6c 65   start_block, le
33e0: 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b 2c 20  aves_end_block, 
33f0: 65 6e 64 5f 62 6c 6f 63 6b 20 46 52 4f 4d 20 78  end_block FROM x
3400: 36 5f 73 65 67 64 69 72 3b 0a 7d 20 7b 0a 20 20  6_segdir;.} {.  
3410: 31 20 30 20 37 31 39 20 31 31 37 31 20 32 33 36  1 0 719 1171 236
3420: 39 34 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c  94.}..do_execsql
3430: 5f 74 65 73 74 20 37 2e 37 20 7b 0a 20 20 53 45  _test 7.7 {.  SE
3440: 4c 45 43 54 20 73 75 6d 28 6c 65 6e 67 74 68 28  LECT sum(length(
3450: 62 6c 6f 63 6b 29 29 20 46 52 4f 4d 20 78 36 5f  block)) FROM x6_
3460: 73 65 67 6d 65 6e 74 73 20 0a 7d 20 7b 36 33 35  segments .} {635
3470: 32 34 37 7d 0a 0a 0a 66 69 6e 69 73 68 5f 74 65  247}...finish_te
3480: 73 74 0a                                         st.