/ Hex Artifact Content
Login

Artifact a73eab34dd9960d10603347fc77fefe2f9322e26:


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: 30 20 7b 30 20 31 31 30 7d 20 31 31 30 20 30 20  0 {0 110} 110 0 
07d0: 7b 30 20 31 33 32 7d 20 31 33 32 20 30 20 7b 30  {0 132} 132 0 {0
07e0: 20 31 32 39 7d 20 31 32 39 20 31 20 7b 31 32 38   129} 129 1 {128
07f0: 20 36 35 38 7d 20 32 7d 0a 0a 64 6f 5f 65 78 65   658} 2}..do_exe
0800: 63 73 71 6c 5f 74 65 73 74 20 31 2e 35 20 7b 0a  csql_test 1.5 {.
0810: 20 20 53 45 4c 45 43 54 20 6c 65 6e 67 74 68 28    SELECT length(
0820: 62 6c 6f 63 6b 29 20 46 52 4f 4d 20 78 31 5f 73  block) FROM x1_s
0830: 65 67 6d 65 6e 74 73 3b 0a 7d 20 7b 36 35 38 20  egments;.} {658 
0840: 7b 7d 7d 0a 0a 64 6f 5f 74 65 73 74 20 31 2e 36  {}}..do_test 1.6
0850: 20 7b 0a 20 20 66 6f 72 65 61 63 68 20 4c 20 7b   {.  foreach L {
0860: 0a 20 20 20 20 7b 27 54 77 61 73 20 4d 75 6c 67  .    {'Twas Mulg
0870: 61 20 42 69 6c 6c 2c 20 66 72 6f 6d 20 45 61 67  a Bill, from Eag
0880: 6c 65 68 61 77 6b 2c 20 74 68 61 74 20 73 6f 75  lehawk, that sou
0890: 67 68 74 20 68 69 73 20 6f 77 6e 20 61 62 6f 64  ght his own abod
08a0: 65 2c 7d 0a 20 20 20 20 7b 54 68 61 74 20 70 65  e,}.    {That pe
08b0: 72 63 68 65 64 20 61 62 6f 76 65 20 44 65 61 64  rched above Dead
08c0: 20 4d 61 6e 27 73 20 43 72 65 65 6b 2c 20 62 65   Man's Creek, be
08d0: 73 69 64 65 20 74 68 65 20 6d 6f 75 6e 74 61 69  side the mountai
08e0: 6e 20 72 6f 61 64 2e 7d 0a 20 20 20 20 7b 48 65  n road.}.    {He
08f0: 20 74 75 72 6e 65 64 20 74 68 65 20 63 79 63 6c   turned the cycl
0900: 65 20 64 6f 77 6e 20 74 68 65 20 68 69 6c 6c 20  e down the hill 
0910: 61 6e 64 20 6d 6f 75 6e 74 65 64 20 66 6f 72 20  and mounted for 
0920: 74 68 65 20 66 72 61 79 2c 7d 0a 20 20 20 20 7b  the fray,}.    {
0930: 42 75 74 20 27 65 72 65 20 68 65 27 64 20 67 6f  But 'ere he'd go
0940: 6e 65 20 61 20 64 6f 7a 65 6e 20 79 61 72 64 73  ne a dozen yards
0950: 20 69 74 20 62 6f 6c 74 65 64 20 63 6c 65 61 6e   it bolted clean
0960: 20 61 77 61 79 2e 7d 0a 20 20 20 20 7b 49 74 20   away.}.    {It 
0970: 6c 65 66 74 20 74 68 65 20 74 72 61 63 6b 2c 20  left the track, 
0980: 61 6e 64 20 74 68 72 6f 75 67 68 20 74 68 65 20  and through the 
0990: 74 72 65 65 73 2c 20 6a 75 73 74 20 6c 69 6b 65  trees, just like
09a0: 20 61 20 73 69 6c 76 65 72 20 73 74 65 61 6b 2c   a silver steak,
09b0: 7d 0a 20 20 20 20 7b 49 74 20 77 68 69 73 74 6c  }.    {It whistl
09c0: 65 64 20 64 6f 77 6e 20 74 68 65 20 61 77 66 75  ed down the awfu
09d0: 6c 20 73 6c 6f 70 65 20 74 6f 77 61 72 64 73 20  l slope towards 
09e0: 74 68 65 20 44 65 61 64 20 4d 61 6e 27 73 20 43  the Dead Man's C
09f0: 72 65 65 6b 2e 7d 0a 20 20 20 20 7b 49 74 20 73  reek.}.    {It s
0a00: 68 61 76 65 64 20 61 20 73 74 75 6d 70 20 62 79  haved a stump by
0a10: 20 68 61 6c 66 20 61 6e 20 69 6e 63 68 2c 20 69   half an inch, i
0a20: 74 20 64 6f 64 67 65 64 20 61 20 62 69 67 20 77  t dodged a big w
0a30: 68 69 74 65 2d 62 6f 78 3a 7d 0a 20 20 20 20 7b  hite-box:}.    {
0a40: 54 68 65 20 76 65 72 79 20 77 61 6c 6c 61 72 6f  The very wallaro
0a50: 6f 73 20 69 6e 20 66 72 69 67 68 74 20 77 65 6e  os in fright wen
0a60: 74 20 73 63 72 61 6d 62 6c 69 6e 67 20 75 70 20  t scrambling up 
0a70: 74 68 65 20 72 6f 63 6b 73 2c 7d 0a 20 20 20 20  the rocks,}.    
0a80: 7b 54 68 65 20 77 6f 6d 62 61 74 73 20 68 69 64  {The wombats hid
0a90: 69 6e 67 20 69 6e 20 74 68 65 69 72 20 63 61 76  ing in their cav
0aa0: 65 73 20 64 75 67 20 64 65 65 70 65 72 20 75 6e  es dug deeper un
0ab0: 64 65 72 67 72 6f 75 6e 64 2c 7d 0a 20 20 20 20  derground,}.    
0ac0: 7b 41 73 20 4d 75 6c 67 61 20 42 69 6c 6c 2c 20  {As Mulga Bill, 
0ad0: 61 73 20 77 68 69 74 65 20 61 73 20 63 68 61 6c  as white as chal
0ae0: 6b 2c 20 73 61 74 20 74 69 67 68 74 20 74 6f 20  k, sat tight to 
0af0: 65 76 65 72 79 20 62 6f 75 6e 64 2e 7d 0a 20 20  every bound.}.  
0b00: 20 20 7b 49 74 20 73 74 72 75 63 6b 20 61 20 73    {It struck a s
0b10: 74 6f 6e 65 20 61 6e 64 20 67 61 76 65 20 61 20  tone and gave a 
0b20: 73 70 72 69 6e 67 20 74 68 61 74 20 63 6c 65 61  spring that clea
0b30: 72 65 64 20 61 20 66 61 6c 6c 65 6e 20 74 72 65  red a fallen tre
0b40: 65 2c 7d 0a 20 20 20 20 7b 49 74 20 72 61 63 65  e,}.    {It race
0b50: 64 20 62 65 73 69 64 65 20 61 20 70 72 65 63 69  d beside a preci
0b60: 70 69 63 65 20 61 73 20 63 6c 6f 73 65 20 61 73  pice as close as
0b70: 20 63 6c 6f 73 65 20 63 6f 75 6c 64 20 62 65 3b   close could be;
0b80: 7d 0a 20 20 20 20 7b 41 6e 64 20 74 68 65 6e 20  }.    {And then 
0b90: 61 73 20 4d 75 6c 67 61 20 42 69 6c 6c 20 6c 65  as Mulga Bill le
0ba0: 74 20 6f 75 74 20 6f 6e 65 20 6c 61 73 74 20 64  t out one last d
0bb0: 65 73 70 61 69 72 69 6e 67 20 73 68 72 69 65 6b  espairing shriek
0bc0: 7d 0a 20 20 20 20 7b 49 74 20 6d 61 64 65 20 61  }.    {It made a
0bd0: 20 6c 65 61 70 20 6f 66 20 74 77 65 6e 74 79 20   leap of twenty 
0be0: 66 65 65 74 20 69 6e 74 6f 20 74 68 65 20 44 65  feet into the De
0bf0: 61 64 20 4d 61 6e 27 73 20 43 72 65 65 6b 2e 7d  ad Man's Creek.}
0c00: 0a 20 20 7d 20 7b 0a 20 20 20 20 65 78 65 63 73  .  } {.    execs
0c10: 71 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f  ql { INSERT INTO
0c20: 20 78 31 20 56 41 4c 55 45 53 28 24 4c 29 20 7d   x1 VALUES($L) }
0c30: 0a 20 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b  .  }.  execsql {
0c40: 20 0a 20 20 20 20 53 45 4c 45 43 54 20 6c 65 76   .    SELECT lev
0c50: 65 6c 2c 20 65 6e 64 5f 62 6c 6f 63 6b 2c 20 6c  el, end_block, l
0c60: 65 6e 67 74 68 28 72 6f 6f 74 29 20 46 52 4f 4d  ength(root) FROM
0c70: 20 78 31 5f 73 65 67 64 69 72 3b 0a 20 20 7d 0a   x1_segdir;.  }.
0c80: 7d 20 7b 31 20 7b 31 32 38 20 36 35 38 7d 20 32  } {1 {128 658} 2
0c90: 20 31 20 7b 31 33 30 20 31 33 37 37 7d 20 36 20   1 {130 1377} 6 
0ca0: 30 20 7b 30 20 31 31 37 7d 20 31 31 37 7d 0a 0a  0 {0 117} 117}..
0cb0: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
0cc0: 31 2e 37 20 7b 0a 20 20 53 45 4c 45 43 54 20 73  1.7 {.  SELECT s
0cd0: 75 6d 28 6c 65 6e 67 74 68 28 62 6c 6f 63 6b 29  um(length(block)
0ce0: 29 20 46 52 4f 4d 20 78 31 5f 73 65 67 6d 65 6e  ) FROM x1_segmen
0cf0: 74 73 20 57 48 45 52 45 20 62 6c 6f 63 6b 69 64  ts WHERE blockid
0d00: 20 49 4e 20 28 31 32 39 2c 20 31 33 30 29 3b 0a   IN (129, 130);.
0d10: 7d 20 7b 31 33 37 37 7d 0a 0a 23 2d 2d 2d 2d 2d  } {1377}..#-----
0d20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d60: 2d 2d 2d 2d 0a 23 0a 64 6f 5f 65 78 65 63 73 71  ----.#.do_execsq
0d70: 6c 5f 74 65 73 74 20 32 2e 31 20 7b 20 0a 20 20  l_test 2.1 { .  
0d80: 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 31 28  CREATE TABLE t1(
0d90: 64 6f 63 69 64 2c 20 77 6f 72 64 73 29 3b 0a 20  docid, words);. 
0da0: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
0db0: 54 41 42 4c 45 20 78 32 20 55 53 49 4e 47 20 66  TABLE x2 USING f
0dc0: 74 73 34 3b 0a 7d 0a 66 74 73 5f 6b 6a 76 5f 67  ts4;.}.fts_kjv_g
0dd0: 65 6e 65 73 69 73 20 0a 64 6f 5f 74 65 73 74 20  enesis .do_test 
0de0: 32 2e 32 20 7b 0a 20 20 66 6f 72 65 61 63 68 20  2.2 {.  foreach 
0df0: 69 64 20 5b 64 62 20 65 76 61 6c 20 7b 53 45 4c  id [db eval {SEL
0e00: 45 43 54 20 64 6f 63 69 64 20 46 52 4f 4d 20 74  ECT docid FROM t
0e10: 31 7d 5d 20 7b 0a 20 20 20 20 65 78 65 63 73 71  1}] {.    execsq
0e20: 6c 20 7b 0a 20 20 20 20 20 20 49 4e 53 45 52 54  l {.      INSERT
0e30: 20 49 4e 54 4f 20 78 32 28 64 6f 63 69 64 2c 20   INTO x2(docid, 
0e40: 63 6f 6e 74 65 6e 74 29 20 53 45 4c 45 43 54 20  content) SELECT 
0e50: 24 69 64 2c 20 77 6f 72 64 73 20 46 52 4f 4d 20  $id, words FROM 
0e60: 74 31 20 57 48 45 52 45 20 64 6f 63 69 64 3d 24  t1 WHERE docid=$
0e70: 69 64 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 66  id.    }.  }.  f
0e80: 6f 72 65 61 63 68 20 69 64 20 5b 64 62 20 65 76  oreach id [db ev
0e90: 61 6c 20 7b 53 45 4c 45 43 54 20 64 6f 63 69 64  al {SELECT docid
0ea0: 20 46 52 4f 4d 20 74 31 7d 5d 20 7b 0a 20 20 20   FROM t1}] {.   
0eb0: 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 20   execsql {.     
0ec0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 32 28   INSERT INTO x2(
0ed0: 64 6f 63 69 64 2c 20 63 6f 6e 74 65 6e 74 29 20  docid, content) 
0ee0: 53 45 4c 45 43 54 20 4e 55 4c 4c 2c 20 77 6f 72  SELECT NULL, wor
0ef0: 64 73 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45  ds FROM t1 WHERE
0f00: 20 64 6f 63 69 64 3d 24 69 64 0a 20 20 20 20 7d   docid=$id.    }
0f10: 0a 20 20 20 20 69 66 20 7b 5b 64 62 20 6f 6e 65  .    if {[db one
0f20: 20 7b 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a   {SELECT count(*
0f30: 29 20 46 52 4f 4d 20 78 32 5f 73 65 67 64 69 72  ) FROM x2_segdir
0f40: 20 57 48 45 52 45 20 6c 65 76 65 6c 3c 32 7d 5d   WHERE level<2}]
0f50: 3d 3d 32 7d 20 62 72 65 61 6b 0a 20 20 7d 0a 7d  ==2} break.  }.}
0f60: 20 7b 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f   {}..do_execsql_
0f70: 74 65 73 74 20 32 2e 33 20 7b 20 0a 20 20 53 45  test 2.3 { .  SE
0f80: 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52  LECT count(*) FR
0f90: 4f 4d 20 78 32 5f 73 65 67 64 69 72 20 57 48 45  OM x2_segdir WHE
0fa0: 52 45 20 6c 65 76 65 6c 3d 32 3b 0a 20 20 53 45  RE level=2;.  SE
0fb0: 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52  LECT count(*) FR
0fc0: 4f 4d 20 78 32 5f 73 65 67 64 69 72 20 57 48 45  OM x2_segdir WHE
0fd0: 52 45 20 6c 65 76 65 6c 3d 33 3b 0a 7d 20 7b 36  RE level=3;.} {6
0fe0: 20 30 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f   0}..do_execsql_
0ff0: 74 65 73 74 20 32 2e 34 20 7b 20 0a 20 20 49 4e  test 2.4 { .  IN
1000: 53 45 52 54 20 49 4e 54 4f 20 78 32 28 78 32 29  SERT INTO x2(x2)
1010: 20 56 41 4c 55 45 53 28 27 6d 65 72 67 65 3d 34   VALUES('merge=4
1020: 2c 34 27 29 3b 0a 20 20 53 45 4c 45 43 54 20 63  ,4');.  SELECT c
1030: 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 78 32 5f  ount(*) FROM x2_
1040: 73 65 67 64 69 72 20 57 48 45 52 45 20 6c 65 76  segdir WHERE lev
1050: 65 6c 3d 32 3b 0a 20 20 53 45 4c 45 43 54 20 63  el=2;.  SELECT c
1060: 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 78 32 5f  ount(*) FROM x2_
1070: 73 65 67 64 69 72 20 57 48 45 52 45 20 6c 65 76  segdir WHERE lev
1080: 65 6c 3d 33 3b 0a 7d 20 7b 36 20 31 7d 0a 0a 64  el=3;.} {6 1}..d
1090: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 32  o_execsql_test 2
10a0: 2e 35 20 7b 20 0a 20 20 53 45 4c 45 43 54 20 65  .5 { .  SELECT e
10b0: 6e 64 5f 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 32  nd_block FROM x2
10c0: 5f 73 65 67 64 69 72 20 57 48 45 52 45 20 6c 65  _segdir WHERE le
10d0: 76 65 6c 3d 33 3b 0a 20 20 49 4e 53 45 52 54 20  vel=3;.  INSERT 
10e0: 49 4e 54 4f 20 78 32 28 78 32 29 20 56 41 4c 55  INTO x2(x2) VALU
10f0: 45 53 28 27 6d 65 72 67 65 3d 34 2c 34 27 29 3b  ES('merge=4,4');
1100: 0a 20 20 53 45 4c 45 43 54 20 65 6e 64 5f 62 6c  .  SELECT end_bl
1110: 6f 63 6b 20 46 52 4f 4d 20 78 32 5f 73 65 67 64  ock FROM x2_segd
1120: 69 72 20 57 48 45 52 45 20 6c 65 76 65 6c 3d 33  ir WHERE level=3
1130: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
1140: 78 32 28 78 32 29 20 56 41 4c 55 45 53 28 27 6d  x2(x2) VALUES('m
1150: 65 72 67 65 3d 34 2c 34 27 29 3b 0a 20 20 53 45  erge=4,4');.  SE
1160: 4c 45 43 54 20 65 6e 64 5f 62 6c 6f 63 6b 20 46  LECT end_block F
1170: 52 4f 4d 20 78 32 5f 73 65 67 64 69 72 20 57 48  ROM x2_segdir WH
1180: 45 52 45 20 6c 65 76 65 6c 3d 33 3b 0a 7d 20 7b  ERE level=3;.} {
1190: 7b 33 38 32 38 20 2d 33 34 33 30 7d 20 7b 33 38  {3828 -3430} {38
11a0: 32 38 20 2d 31 30 31 39 31 7d 20 7b 33 38 32 38  28 -10191} {3828
11b0: 20 2d 31 34 31 30 39 7d 7d 0a 0a 64 6f 5f 65 78   -14109}}..do_ex
11c0: 65 63 73 71 6c 5f 74 65 73 74 20 32 2e 36 20 7b  ecsql_test 2.6 {
11d0: 0a 20 20 53 45 4c 45 43 54 20 73 75 6d 28 6c 65  .  SELECT sum(le
11e0: 6e 67 74 68 28 62 6c 6f 63 6b 29 29 20 46 52 4f  ngth(block)) FRO
11f0: 4d 20 78 32 5f 73 65 67 64 69 72 2c 20 78 32 5f  M x2_segdir, x2_
1200: 73 65 67 6d 65 6e 74 73 20 57 48 45 52 45 20 0a  segments WHERE .
1210: 20 20 20 20 62 6c 6f 63 6b 69 64 20 42 45 54 57      blockid BETW
1220: 45 45 4e 20 73 74 61 72 74 5f 62 6c 6f 63 6b 20  EEN start_block 
1230: 41 4e 44 20 6c 65 61 76 65 73 5f 65 6e 64 5f 62  AND leaves_end_b
1240: 6c 6f 63 6b 0a 20 20 20 20 41 4e 44 20 6c 65 76  lock.    AND lev
1250: 65 6c 3d 33 0a 7d 20 7b 31 34 31 30 39 7d 0a 0a  el=3.} {14109}..
1260: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
1270: 32 2e 37 20 7b 20 0a 20 20 49 4e 53 45 52 54 20  2.7 { .  INSERT 
1280: 49 4e 54 4f 20 78 32 28 78 32 29 20 56 41 4c 55  INTO x2(x2) VALU
1290: 45 53 28 27 6d 65 72 67 65 3d 31 30 30 30 2c 34  ES('merge=1000,4
12a0: 27 29 3b 0a 20 20 53 45 4c 45 43 54 20 65 6e 64  ');.  SELECT end
12b0: 5f 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 32 5f 73  _block FROM x2_s
12c0: 65 67 64 69 72 20 57 48 45 52 45 20 6c 65 76 65  egdir WHERE leve
12d0: 6c 3d 33 3b 0a 7d 20 7b 7b 33 38 32 38 20 38 36  l=3;.} {{3828 86
12e0: 31 32 30 7d 7d 0a 0a 64 6f 5f 65 78 65 63 73 71  120}}..do_execsq
12f0: 6c 5f 74 65 73 74 20 32 2e 38 20 7b 0a 20 20 53  l_test 2.8 {.  S
1300: 45 4c 45 43 54 20 73 75 6d 28 6c 65 6e 67 74 68  ELECT sum(length
1310: 28 62 6c 6f 63 6b 29 29 20 46 52 4f 4d 20 78 32  (block)) FROM x2
1320: 5f 73 65 67 64 69 72 2c 20 78 32 5f 73 65 67 6d  _segdir, x2_segm
1330: 65 6e 74 73 20 57 48 45 52 45 20 0a 20 20 20 20  ents WHERE .    
1340: 62 6c 6f 63 6b 69 64 20 42 45 54 57 45 45 4e 20  blockid BETWEEN 
1350: 73 74 61 72 74 5f 62 6c 6f 63 6b 20 41 4e 44 20  start_block AND 
1360: 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b  leaves_end_block
1370: 0a 20 20 20 20 41 4e 44 20 6c 65 76 65 6c 3d 33  .    AND level=3
1380: 0a 7d 20 7b 38 36 31 32 30 7d 0a 0a 23 2d 2d 2d  .} {86120}..#---
1390: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
13a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
13b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
13c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
13d0: 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 65 73 74 20 74  -------.# Test t
13e0: 68 61 74 20 64 65 6c 65 74 65 20 6d 61 72 6b 65  hat delete marke
13f0: 72 73 20 61 72 65 20 72 65 6d 6f 76 65 64 20 66  rs are removed f
1400: 72 6f 6d 20 46 54 53 20 73 65 67 6d 65 6e 74 73  rom FTS segments
1410: 20 77 68 65 6e 20 70 6f 73 73 69 62 6c 65 2e 0a   when possible..
1420: 23 20 49 74 20 69 73 20 6f 6e 6c 79 20 70 6f 73  # It is only pos
1430: 73 69 62 6c 65 20 74 6f 20 72 65 6d 6f 76 65 20  sible to remove 
1440: 64 65 6c 65 74 65 20 6d 61 72 6b 65 72 73 20 77  delete markers w
1450: 68 65 6e 20 74 68 65 20 6f 75 74 70 75 74 20 6f  hen the output o
1460: 66 20 74 68 65 0a 23 20 6d 65 72 67 65 20 6f 70  f the.# merge op
1470: 65 72 61 74 69 6f 6e 20 77 69 6c 6c 20 62 65 63  eration will bec
1480: 6f 6d 65 20 74 68 65 20 6f 6c 64 65 73 74 20 73  ome the oldest s
1490: 65 67 6d 65 6e 74 20 69 6e 20 74 68 65 20 69 6e  egment in the in
14a0: 64 65 78 2e 0a 23 0a 23 20 20 20 33 2e 31 20 2d  dex..#.#   3.1 -
14b0: 20 77 68 65 6e 20 74 68 65 20 6f 6c 64 65 73 74   when the oldest
14c0: 20 73 65 67 6d 65 6e 74 20 69 73 20 63 72 65 61   segment is crea
14d0: 74 65 64 20 62 79 20 61 6e 20 27 6f 70 74 69 6d  ted by an 'optim
14e0: 69 7a 65 27 2e 0a 23 20 20 20 33 2e 32 20 2d 20  ize'..#   3.2 - 
14f0: 77 68 65 6e 20 74 68 65 20 6f 6c 64 65 73 74 20  when the oldest 
1500: 73 65 67 6d 65 6e 74 20 69 73 20 63 72 65 61 74  segment is creat
1510: 65 64 20 62 79 20 61 6e 20 69 6e 63 72 65 6d 65  ed by an increme
1520: 6e 74 61 6c 20 6d 65 72 67 65 2e 0a 23 20 20 20  ntal merge..#   
1530: 33 2e 33 20 2d 20 62 79 20 61 20 63 72 69 73 69  3.3 - by a crisi
1540: 73 20 6d 65 72 67 65 2e 0a 23 0a 0a 70 72 6f 63  s merge..#..proc
1550: 20 69 6e 73 65 72 74 5f 64 6f 63 20 7b 61 72 67   insert_doc {arg
1560: 73 7d 20 7b 0a 20 20 66 6f 72 65 61 63 68 20 69  s} {.  foreach i
1570: 44 6f 63 20 24 61 72 67 73 20 7b 0a 20 20 20 20  Doc $args {.    
1580: 73 65 74 20 4c 20 5b 6c 69 6e 64 65 78 20 7b 0a  set L [lindex {.
1590: 20 20 20 20 20 20 7b 49 6e 20 79 6f 75 72 20 65        {In your e
15a0: 61 67 65 72 6e 65 73 73 20 74 6f 20 65 6e 67 61  agerness to enga
15b0: 67 65 20 74 68 65 20 54 72 6f 6a 61 6e 73 2c 7d  ge the Trojans,}
15c0: 0a 20 20 20 20 20 20 7b 64 6f 6e e2 80 99 74 20  .      {don...t 
15d0: 61 6e 79 20 6f 66 20 79 6f 75 20 63 68 61 72 67  any of you charg
15e0: 65 20 61 68 65 61 64 20 6f 66 20 6f 74 68 65 72  e ahead of other
15f0: 73 2c 7d 0a 20 20 20 20 20 20 7b 74 72 75 73 74  s,}.      {trust
1600: 69 6e 67 20 69 6e 20 79 6f 75 72 20 73 74 72 65  ing in your stre
1610: 6e 67 74 68 20 61 6e 64 20 68 6f 72 73 65 6d 61  ngth and horsema
1620: 6e 73 68 69 70 2e 7d 0a 20 20 20 20 20 20 7b 41  nship.}.      {A
1630: 6e 64 20 64 6f 6e e2 80 99 74 20 6c 61 67 20 62  nd don...t lag b
1640: 65 68 69 6e 64 2e 20 54 68 61 74 20 77 69 6c 6c  ehind. That will
1650: 20 68 75 72 74 20 6f 75 72 20 63 68 61 72 67 65   hurt our charge
1660: 2e 7d 0a 20 20 20 20 20 20 7b 41 6e 79 20 6d 61  .}.      {Any ma
1670: 6e 20 77 68 6f 73 65 20 63 68 61 72 69 6f 74 20  n whose chariot 
1680: 63 6f 6e 66 72 6f 6e 74 73 20 61 6e 20 65 6e 65  confronts an ene
1690: 6d 79 e2 80 99 73 7d 0a 20 20 20 20 20 20 7b 73  my...s}.      {s
16a0: 68 6f 75 6c 64 20 74 68 72 75 73 74 20 77 69 74  hould thrust wit
16b0: 68 20 68 69 73 20 73 70 65 61 72 20 61 74 20 68  h his spear at h
16c0: 69 6d 20 66 72 6f 6d 20 74 68 65 72 65 2e 7d 0a  im from there.}.
16d0: 20 20 20 20 20 20 7b 54 68 61 74 e2 80 99 73 20        {That...s 
16e0: 74 68 65 20 6d 6f 73 74 20 65 66 66 65 63 74 69  the most effecti
16f0: 76 65 20 74 61 63 74 69 63 2c 20 74 68 65 20 77  ve tactic, the w
1700: 61 79 7d 0a 20 20 20 20 20 20 7b 6d 65 6e 20 77  ay}.      {men w
1710: 69 70 65 64 20 6f 75 74 20 63 69 74 79 20 73 74  iped out city st
1720: 72 6f 6e 67 68 6f 6c 64 73 20 6c 6f 6e 67 20 61  rongholds long a
1730: 67 6f 20 e2 80 94 7d 0a 20 20 20 20 20 20 7b 74  go ...}.      {t
1740: 68 65 69 72 20 63 68 65 73 74 73 20 66 75 6c 6c  heir chests full
1750: 20 6f 66 20 74 68 61 74 20 73 74 79 6c 65 20 61   of that style a
1760: 6e 64 20 73 70 69 72 69 74 2e 7d 0a 20 20 20 20  nd spirit.}.    
1770: 7d 20 5b 65 78 70 72 20 24 69 44 6f 63 25 39 5d  } [expr $iDoc%9]
1780: 5d 0a 20 20 20 20 65 78 65 63 73 71 6c 20 7b 20  ].    execsql { 
1790: 52 45 50 4c 41 43 45 20 49 4e 54 4f 20 78 33 28  REPLACE INTO x3(
17a0: 64 6f 63 69 64 2c 20 63 6f 6e 74 65 6e 74 29 20  docid, content) 
17b0: 56 41 4c 55 45 53 28 24 69 44 6f 63 2c 20 24 4c  VALUES($iDoc, $L
17c0: 29 20 7d 0a 20 20 7d 0a 7d 0a 0a 70 72 6f 63 20  ) }.  }.}..proc 
17d0: 64 65 6c 65 74 65 5f 64 6f 63 20 7b 61 72 67 73  delete_doc {args
17e0: 7d 20 7b 0a 20 20 66 6f 72 65 61 63 68 20 69 44  } {.  foreach iD
17f0: 6f 63 20 24 61 72 67 73 20 7b 0a 20 20 20 20 65  oc $args {.    e
1800: 78 65 63 73 71 6c 20 7b 20 44 45 4c 45 54 45 20  xecsql { DELETE 
1810: 46 52 4f 4d 20 78 33 20 57 48 45 52 45 20 64 6f  FROM x3 WHERE do
1820: 63 69 64 20 3d 20 24 69 44 6f 63 20 7d 0a 20 20  cid = $iDoc }.  
1830: 7d 0a 7d 0a 0a 70 72 6f 63 20 73 65 63 6f 6e 64  }.}..proc second
1840: 20 7b 78 7d 20 7b 20 6c 69 6e 64 65 78 20 24 78   {x} { lindex $x
1850: 20 31 20 7d 0a 64 62 20 66 75 6e 63 20 73 65 63   1 }.db func sec
1860: 6f 6e 64 20 73 65 63 6f 6e 64 0a 0a 64 6f 5f 65  ond second..do_e
1870: 78 65 63 73 71 6c 5f 74 65 73 74 20 33 2e 30 20  xecsql_test 3.0 
1880: 7b 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c  { CREATE VIRTUAL
1890: 20 54 41 42 4c 45 20 78 33 20 55 53 49 4e 47 20   TABLE x3 USING 
18a0: 66 74 73 34 20 7d 0a 0a 64 6f 5f 74 65 73 74 20  fts4 }..do_test 
18b0: 33 2e 31 2e 31 20 7b 0a 20 20 64 62 20 74 72 61  3.1.1 {.  db tra
18c0: 6e 73 61 63 74 69 6f 6e 20 7b 20 69 6e 73 65 72  nsaction { inser
18d0: 74 5f 64 6f 63 20 31 20 32 20 33 20 34 20 35 20  t_doc 1 2 3 4 5 
18e0: 36 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b 20  6 }.  execsql { 
18f0: 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69 64  SELECT level, id
1900: 78 2c 20 73 65 63 6f 6e 64 28 65 6e 64 5f 62 6c  x, second(end_bl
1910: 6f 63 6b 29 20 46 52 4f 4d 20 78 33 5f 73 65 67  ock) FROM x3_seg
1920: 64 69 72 20 7d 0a 7d 20 7b 30 20 30 20 34 31 32  dir }.} {0 0 412
1930: 7d 0a 64 6f 5f 74 65 73 74 20 33 2e 31 2e 32 20  }.do_test 3.1.2 
1940: 7b 0a 20 20 64 65 6c 65 74 65 5f 64 6f 63 20 31  {.  delete_doc 1
1950: 20 32 20 33 20 34 20 35 20 36 0a 20 20 65 78 65   2 3 4 5 6.  exe
1960: 63 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 63 6f  csql { SELECT co
1970: 75 6e 74 28 2a 29 20 46 52 4f 4d 20 78 33 5f 73  unt(*) FROM x3_s
1980: 65 67 64 69 72 20 7d 0a 7d 20 7b 30 7d 0a 64 6f  egdir }.} {0}.do
1990: 5f 74 65 73 74 20 33 2e 31 2e 33 20 7b 0a 20 20  _test 3.1.3 {.  
19a0: 64 62 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 7b  db transaction {
19b0: 20 0a 20 20 20 20 69 6e 73 65 72 74 5f 64 6f 63   .    insert_doc
19c0: 20 31 20 32 20 33 20 34 20 35 20 36 20 37 20 38   1 2 3 4 5 6 7 8
19d0: 20 39 0a 20 20 20 20 64 65 6c 65 74 65 5f 64 6f   9.    delete_do
19e0: 63 20 39 20 38 20 37 0a 20 20 7d 0a 20 20 65 78  c 9 8 7.  }.  ex
19f0: 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 6c  ecsql { SELECT l
1a00: 65 76 65 6c 2c 20 69 64 78 2c 20 73 65 63 6f 6e  evel, idx, secon
1a10: 64 28 65 6e 64 5f 62 6c 6f 63 6b 29 20 46 52 4f  d(end_block) FRO
1a20: 4d 20 78 33 5f 73 65 67 64 69 72 20 7d 0a 7d 20  M x3_segdir }.} 
1a30: 7b 30 20 30 20 35 39 31 20 30 20 31 20 37 32 20  {0 0 591 0 1 72 
1a40: 30 20 32 20 37 36 7d 0a 64 6f 5f 74 65 73 74 20  0 2 76}.do_test 
1a50: 33 2e 31 2e 34 20 7b 0a 20 20 65 78 65 63 73 71  3.1.4 {.  execsq
1a60: 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  l { INSERT INTO 
1a70: 78 33 28 78 33 29 20 56 41 4c 55 45 53 28 27 6f  x3(x3) VALUES('o
1a80: 70 74 69 6d 69 7a 65 27 29 20 7d 0a 20 20 65 78  ptimize') }.  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 34 36 33 7d 0a 0a 64 6f 5f 74 65  {0 0 463}..do_te
1ae0: 73 74 20 33 2e 32 2e 31 20 7b 0a 20 20 65 78 65  st 3.2.1 {.  exe
1af0: 63 73 71 6c 20 7b 20 44 45 4c 45 54 45 20 46 52  csql { DELETE FR
1b00: 4f 4d 20 78 33 20 7d 0a 20 20 69 6e 73 65 72 74  OM x3 }.  insert
1b10: 5f 64 6f 63 20 38 20 37 20 36 20 35 20 34 20 33  _doc 8 7 6 5 4 3
1b20: 20 32 20 31 0a 20 20 64 65 6c 65 74 65 5f 64 6f   2 1.  delete_do
1b30: 63 20 37 20 38 0a 20 20 65 78 65 63 73 71 6c 20  c 7 8.  execsql 
1b40: 7b 20 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a  { SELECT count(*
1b50: 29 20 46 52 4f 4d 20 78 33 5f 73 65 67 64 69 72  ) FROM x3_segdir
1b60: 20 7d 0a 7d 20 7b 31 30 7d 0a 64 6f 5f 74 65 73   }.} {10}.do_tes
1b70: 74 20 33 2e 32 2e 32 20 7b 0a 20 20 65 78 65 63  t 3.2.2 {.  exec
1b80: 73 71 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54  sql { INSERT INT
1b90: 4f 20 78 33 28 78 33 29 20 56 41 4c 55 45 53 28  O x3(x3) VALUES(
1ba0: 27 6d 65 72 67 65 3d 35 30 30 2c 31 30 27 29 20  'merge=500,10') 
1bb0: 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 53 45  }.  execsql { SE
1bc0: 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69 64 78 2c  LECT level, idx,
1bd0: 20 73 65 63 6f 6e 64 28 65 6e 64 5f 62 6c 6f 63   second(end_bloc
1be0: 6b 29 20 46 52 4f 4d 20 78 33 5f 73 65 67 64 69  k) FROM x3_segdi
1bf0: 72 20 7d 0a 7d 20 7b 31 20 30 20 34 31 32 7d 0a  r }.} {1 0 412}.
1c00: 0a 23 20 54 68 69 73 20 61 73 73 75 6d 65 73 20  .# This assumes 
1c10: 74 68 65 20 63 72 69 73 69 73 20 6d 65 72 67 65  the crisis merge
1c20: 20 68 61 70 70 65 6e 73 20 77 68 65 6e 20 74 68   happens when th
1c30: 65 72 65 20 61 72 65 20 61 6c 72 65 61 64 79 20  ere are already 
1c40: 31 36 20 0a 23 20 73 65 67 6d 65 6e 74 73 20 61  16 .# segments a
1c50: 6e 64 20 6f 6e 65 20 6d 6f 72 65 20 69 73 20 61  nd one more is a
1c60: 64 64 65 64 2e 0a 23 0a 64 6f 5f 74 65 73 74 20  dded..#.do_test 
1c70: 33 2e 33 2e 31 20 7b 0a 20 20 65 78 65 63 73 71  3.3.1 {.  execsq
1c80: 6c 20 7b 20 44 45 4c 45 54 45 20 46 52 4f 4d 20  l { DELETE FROM 
1c90: 78 33 20 7d 0a 20 20 69 6e 73 65 72 74 5f 64 6f  x3 }.  insert_do
1ca0: 63 20 31 20 32 20 33 20 34 20 35 20 36 20 20 37  c 1 2 3 4 5 6  7
1cb0: 20 38 20 39 20 31 30 20 31 31 0a 20 20 64 65 6c   8 9 10 11.  del
1cc0: 65 74 65 5f 64 6f 63 20 31 31 20 31 30 20 39 20  ete_doc 11 10 9 
1cd0: 38 20 37 0a 20 20 65 78 65 63 73 71 6c 20 7b 20  8 7.  execsql { 
1ce0: 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20  SELECT count(*) 
1cf0: 46 52 4f 4d 20 78 33 5f 73 65 67 64 69 72 20 7d  FROM x3_segdir }
1d00: 0a 7d 20 7b 31 36 7d 0a 0a 64 6f 5f 74 65 73 74  .} {16}..do_test
1d10: 20 33 2e 33 2e 32 20 7b 0a 20 20 69 6e 73 65 72   3.3.2 {.  inser
1d20: 74 5f 64 6f 63 20 31 32 0a 20 20 65 78 65 63 73  t_doc 12.  execs
1d30: 71 6c 20 7b 20 53 45 4c 45 43 54 20 6c 65 76 65  ql { SELECT leve
1d40: 6c 2c 20 69 64 78 2c 20 73 65 63 6f 6e 64 28 65  l, idx, second(e
1d50: 6e 64 5f 62 6c 6f 63 6b 29 20 46 52 4f 4d 20 78  nd_block) FROM x
1d60: 33 5f 73 65 67 64 69 72 20 57 48 45 52 45 20 6c  3_segdir WHERE l
1d70: 65 76 65 6c 3d 31 20 7d 0a 7d 20 7b 31 20 30 20  evel=1 }.} {1 0 
1d80: 34 31 32 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d  412}..#---------
1d90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1da0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1db0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1dc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1dd0: 2d 0a 23 20 43 68 65 63 6b 20 61 20 74 68 65 6f  -.# Check a theo
1de0: 72 79 20 6f 6e 20 61 20 62 75 67 20 69 6e 20 66  ry on a bug in f
1df0: 74 73 34 20 2d 20 74 68 61 74 20 73 65 67 6d 65  ts4 - that segme
1e00: 6e 74 73 20 77 69 74 68 20 69 64 78 3d 3d 30 20  nts with idx==0 
1e10: 77 65 72 65 20 6e 6f 74 20 0a 23 20 62 65 69 6e  were not .# bein
1e20: 67 20 69 6e 63 72 65 6d 65 6e 74 61 6c 6c 79 20  g incrementally 
1e30: 6d 65 72 67 65 64 20 63 6f 72 72 65 63 74 6c 79  merged correctly
1e40: 2e 20 54 68 65 6f 72 79 20 74 75 72 6e 65 64 20  . Theory turned 
1e50: 6f 75 74 20 74 6f 20 62 65 20 66 61 6c 73 65 2e  out to be false.
1e60: 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  .#.do_execsql_te
1e70: 73 74 20 34 2e 31 20 7b 0a 20 20 44 52 4f 50 20  st 4.1 {.  DROP 
1e80: 54 41 42 4c 45 20 49 46 20 45 58 49 53 54 53 20  TABLE IF EXISTS 
1e90: 78 34 3b 0a 20 20 44 52 4f 50 20 54 41 42 4c 45  x4;.  DROP TABLE
1ea0: 20 49 46 20 45 58 49 53 54 53 20 74 31 3b 0a 20   IF EXISTS t1;. 
1eb0: 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 31   CREATE TABLE t1
1ec0: 28 64 6f 63 69 64 2c 20 77 6f 72 64 73 29 3b 0a  (docid, words);.
1ed0: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
1ee0: 20 54 41 42 4c 45 20 78 34 20 55 53 49 4e 47 20   TABLE x4 USING 
1ef0: 66 74 73 34 28 77 6f 72 64 73 29 3b 0a 7d 0a 64  fts4(words);.}.d
1f00: 6f 5f 74 65 73 74 20 34 2e 32 20 7b 0a 20 20 66  o_test 4.2 {.  f
1f10: 74 73 5f 6b 6a 76 5f 67 65 6e 65 73 69 73 20 0a  ts_kjv_genesis .
1f20: 20 20 65 78 65 63 73 71 6c 20 7b 20 49 4e 53 45    execsql { INSE
1f30: 52 54 20 49 4e 54 4f 20 78 34 20 53 45 4c 45 43  RT INTO x4 SELEC
1f40: 54 20 77 6f 72 64 73 20 46 52 4f 4d 20 74 31 20  T words FROM t1 
1f50: 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 49 4e  }.  execsql { IN
1f60: 53 45 52 54 20 49 4e 54 4f 20 78 34 20 53 45 4c  SERT INTO x4 SEL
1f70: 45 43 54 20 77 6f 72 64 73 20 46 52 4f 4d 20 74  ECT words FROM t
1f80: 31 20 7d 0a 7d 20 7b 7d 0a 0a 64 6f 5f 65 78 65  1 }.} {}..do_exe
1f90: 63 73 71 6c 5f 74 65 73 74 20 34 2e 33 20 7b 0a  csql_test 4.3 {.
1fa0: 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20    SELECT level, 
1fb0: 69 64 78 2c 20 73 65 63 6f 6e 64 28 65 6e 64 5f  idx, second(end_
1fc0: 62 6c 6f 63 6b 29 20 46 52 4f 4d 20 78 34 5f 73  block) FROM x4_s
1fd0: 65 67 64 69 72 20 0a 7d 20 7b 30 20 30 20 31 31  egdir .} {0 0 11
1fe0: 37 34 38 33 20 30 20 31 20 31 31 38 30 30 36 7d  7483 0 1 118006}
1ff0: 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  ..do_execsql_tes
2000: 74 20 34 2e 34 20 7b 0a 20 20 49 4e 53 45 52 54  t 4.4 {.  INSERT
2010: 20 49 4e 54 4f 20 78 34 28 78 34 29 20 56 41 4c   INTO x4(x4) VAL
2020: 55 45 53 28 27 6d 65 72 67 65 3d 31 30 2c 32 27  UES('merge=10,2'
2030: 29 3b 0a 20 20 53 45 4c 45 43 54 20 63 6f 75 6e  );.  SELECT coun
2040: 74 28 2a 29 20 46 52 4f 4d 20 78 34 5f 73 65 67  t(*) FROM x4_seg
2050: 64 69 72 3b 0a 7d 20 7b 33 7d 0a 0a 64 6f 5f 65  dir;.} {3}..do_e
2060: 78 65 63 73 71 6c 5f 74 65 73 74 20 34 2e 35 20  xecsql_test 4.5 
2070: 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  {.  INSERT INTO 
2080: 78 34 28 78 34 29 20 56 41 4c 55 45 53 28 27 6d  x4(x4) VALUES('m
2090: 65 72 67 65 3d 31 30 2c 32 27 29 3b 0a 20 20 53  erge=10,2');.  S
20a0: 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46  ELECT count(*) F
20b0: 52 4f 4d 20 78 34 5f 73 65 67 64 69 72 3b 0a 7d  ROM x4_segdir;.}
20c0: 20 7b 33 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c   {3}..do_execsql
20d0: 5f 74 65 73 74 20 34 2e 36 20 7b 0a 20 20 49 4e  _test 4.6 {.  IN
20e0: 53 45 52 54 20 49 4e 54 4f 20 78 34 28 78 34 29  SERT INTO x4(x4)
20f0: 20 56 41 4c 55 45 53 28 27 6d 65 72 67 65 3d 31   VALUES('merge=1
2100: 30 30 30 2c 32 27 29 3b 0a 20 20 53 45 4c 45 43  000,2');.  SELEC
2110: 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20  T count(*) FROM 
2120: 78 34 5f 73 65 67 64 69 72 3b 0a 7d 20 7b 31 7d  x4_segdir;.} {1}
2130: 0a 0a 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ....#-----------
2140: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2150: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2160: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2170: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
2180: 23 20 43 68 65 63 6b 20 74 68 61 74 20 73 65 67  # Check that seg
2190: 6d 65 6e 74 73 20 61 72 65 20 6e 6f 74 20 70 72  ments are not pr
21a0: 6f 6d 6f 74 65 64 20 69 66 20 74 68 65 20 22 65  omoted if the "e
21b0: 6e 64 5f 62 6c 6f 63 6b 22 20 66 69 65 6c 64 20  nd_block" field 
21c0: 64 6f 65 73 20 6e 6f 74 0a 23 20 63 6f 6e 74 61  does not.# conta
21d0: 69 6e 20 61 20 73 69 7a 65 2e 0a 23 0a 64 6f 5f  in a size..#.do_
21e0: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 35 2e 31  execsql_test 5.1
21f0: 20 7b 0a 20 20 44 52 4f 50 20 54 41 42 4c 45 20   {.  DROP TABLE 
2200: 49 46 20 45 58 49 53 54 53 20 78 32 3b 0a 20 20  IF EXISTS x2;.  
2210: 44 52 4f 50 20 54 41 42 4c 45 20 49 46 20 45 58  DROP TABLE IF EX
2220: 49 53 54 53 20 74 31 3b 0a 20 20 43 52 45 41 54  ISTS t1;.  CREAT
2230: 45 20 54 41 42 4c 45 20 74 31 28 64 6f 63 69 64  E TABLE t1(docid
2240: 2c 20 77 6f 72 64 73 29 3b 0a 20 20 43 52 45 41  , words);.  CREA
2250: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45  TE VIRTUAL TABLE
2260: 20 78 32 20 55 53 49 4e 47 20 66 74 73 34 3b 0a   x2 USING fts4;.
2270: 7d 0a 66 74 73 5f 6b 6a 76 5f 67 65 6e 65 73 69  }.fts_kjv_genesi
2280: 73 20 0a 0a 70 72 6f 63 20 66 69 72 73 74 20 7b  s ..proc first {
2290: 4c 7d 20 7b 6c 69 6e 64 65 78 20 24 4c 20 30 7d  L} {lindex $L 0}
22a0: 0a 64 62 20 66 75 6e 63 20 66 69 72 73 74 20 66  .db func first f
22b0: 69 72 73 74 0a 0a 64 6f 5f 74 65 73 74 20 35 2e  irst..do_test 5.
22c0: 32 20 7b 0a 20 20 66 6f 72 65 61 63 68 20 72 20  2 {.  foreach r 
22d0: 5b 64 62 20 65 76 61 6c 20 7b 20 53 45 4c 45 43  [db eval { SELEC
22e0: 54 20 72 6f 77 69 64 20 46 52 4f 4d 20 74 31 20  T rowid FROM t1 
22f0: 7d 5d 20 7b 0a 20 20 20 20 65 78 65 63 73 71 6c  }] {.    execsql
2300: 20 7b 0a 20 20 20 20 20 20 49 4e 53 45 52 54 20   {.      INSERT 
2310: 49 4e 54 4f 20 78 32 28 64 6f 63 69 64 2c 20 63  INTO x2(docid, c
2320: 6f 6e 74 65 6e 74 29 20 53 45 4c 45 43 54 20 64  ontent) SELECT d
2330: 6f 63 69 64 2c 20 77 6f 72 64 73 20 46 52 4f 4d  ocid, words FROM
2340: 20 74 31 20 57 48 45 52 45 20 72 6f 77 69 64 3d   t1 WHERE rowid=
2350: 24 72 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 66  $r.    }.  }.  f
2360: 6f 72 65 61 63 68 20 64 20 5b 64 62 20 65 76 61  oreach d [db eva
2370: 6c 20 7b 20 53 45 4c 45 43 54 20 64 6f 63 69 64  l { SELECT docid
2380: 20 46 52 4f 4d 20 74 31 20 4c 49 4d 49 54 20 2d   FROM t1 LIMIT -
2390: 31 20 4f 46 46 53 45 54 20 32 30 20 7d 5d 20 7b  1 OFFSET 20 }] {
23a0: 0a 20 20 20 20 65 78 65 63 73 71 6c 20 7b 20 44  .    execsql { D
23b0: 45 4c 45 54 45 20 46 52 4f 4d 20 78 32 20 57 48  ELETE FROM x2 WH
23c0: 45 52 45 20 64 6f 63 69 64 20 3d 20 24 64 20 7d  ERE docid = $d }
23d0: 0a 20 20 7d 0a 0a 20 20 65 78 65 63 73 71 6c 20  .  }..  execsql 
23e0: 7b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  {.    INSERT INT
23f0: 4f 20 78 32 28 78 32 29 20 56 41 4c 55 45 53 28  O x2(x2) VALUES(
2400: 27 6f 70 74 69 6d 69 7a 65 27 29 3b 0a 20 20 20  'optimize');.   
2410: 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69   SELECT level, i
2420: 64 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20 46 52  dx, end_block FR
2430: 4f 4d 20 78 32 5f 73 65 67 64 69 72 0a 20 20 7d  OM x2_segdir.  }
2440: 0a 7d 20 7b 32 20 30 20 7b 37 35 32 20 31 39 32  .} {2 0 {752 192
2450: 36 7d 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  6}}..do_execsql_
2460: 74 65 73 74 20 35 2e 33 20 7b 0a 20 20 55 50 44  test 5.3 {.  UPD
2470: 41 54 45 20 78 32 5f 73 65 67 64 69 72 20 53 45  ATE x2_segdir SE
2480: 54 20 65 6e 64 5f 62 6c 6f 63 6b 20 3d 20 43 41  T end_block = CA
2490: 53 54 28 20 66 69 72 73 74 28 65 6e 64 5f 62 6c  ST( first(end_bl
24a0: 6f 63 6b 29 20 41 53 20 49 4e 54 45 47 45 52 20  ock) AS INTEGER 
24b0: 29 3b 0a 20 20 53 45 4c 45 43 54 20 65 6e 64 5f  );.  SELECT end_
24c0: 62 6c 6f 63 6b 2c 20 74 79 70 65 6f 66 28 65 6e  block, typeof(en
24d0: 64 5f 62 6c 6f 63 6b 29 20 46 52 4f 4d 20 78 32  d_block) FROM x2
24e0: 5f 73 65 67 64 69 72 3b 0a 7d 20 7b 37 35 32 20  _segdir;.} {752 
24f0: 69 6e 74 65 67 65 72 7d 0a 0a 64 6f 5f 65 78 65  integer}..do_exe
2500: 63 73 71 6c 5f 74 65 73 74 20 35 2e 34 20 7b 0a  csql_test 5.4 {.
2510: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 32    INSERT INTO x2
2520: 20 53 45 4c 45 43 54 20 77 6f 72 64 73 20 46 52   SELECT words FR
2530: 4f 4d 20 74 31 20 4c 49 4d 49 54 20 35 30 3b 0a  OM t1 LIMIT 50;.
2540: 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20    SELECT level, 
2550: 69 64 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20 46  idx, end_block F
2560: 52 4f 4d 20 78 32 5f 73 65 67 64 69 72 0a 7d 20  ROM x2_segdir.} 
2570: 7b 32 20 30 20 37 35 32 20 30 20 30 20 7b 37 35  {2 0 752 0 0 {75
2580: 38 20 35 31 37 34 7d 7d 0a 0a 64 6f 5f 65 78 65  8 5174}}..do_exe
2590: 63 73 71 6c 5f 74 65 73 74 20 35 2e 35 20 7b 0a  csql_test 5.5 {.
25a0: 20 20 55 50 44 41 54 45 20 78 32 5f 73 65 67 64    UPDATE x2_segd
25b0: 69 72 20 53 45 54 20 65 6e 64 5f 62 6c 6f 63 6b  ir SET end_block
25c0: 20 3d 20 65 6e 64 5f 62 6c 6f 63 6b 20 7c 7c 20   = end_block || 
25d0: 27 20 31 39 32 36 27 20 57 48 45 52 45 20 6c 65  ' 1926' WHERE le
25e0: 76 65 6c 3d 32 3b 0a 20 20 49 4e 53 45 52 54 20  vel=2;.  INSERT 
25f0: 49 4e 54 4f 20 78 32 20 53 45 4c 45 43 54 20 77  INTO x2 SELECT w
2600: 6f 72 64 73 20 46 52 4f 4d 20 74 31 20 4c 49 4d  ords FROM t1 LIM
2610: 49 54 20 34 30 3b 0a 20 20 53 45 4c 45 43 54 20  IT 40;.  SELECT 
2620: 6c 65 76 65 6c 2c 20 69 64 78 2c 20 65 6e 64 5f  level, idx, end_
2630: 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 32 5f 73 65  block FROM x2_se
2640: 67 64 69 72 0a 7d 20 7b 30 20 30 20 7b 37 35 32  gdir.} {0 0 {752
2650: 20 31 39 32 36 7d 20 30 20 31 20 7b 37 35 38 20   1926} 0 1 {758 
2660: 35 31 37 34 7d 20 30 20 32 20 7b 37 36 33 20 34  5174} 0 2 {763 4
2670: 31 37 30 7d 7d 0a 0a 70 72 6f 63 20 74 31 5f 74  170}}..proc t1_t
2680: 6f 5f 78 32 20 7b 7d 20 7b 0a 20 20 66 6f 72 65  o_x2 {} {.  fore
2690: 61 63 68 20 69 64 20 5b 64 62 20 65 76 61 6c 20  ach id [db eval 
26a0: 7b 53 45 4c 45 43 54 20 64 6f 63 69 64 20 46 52  {SELECT docid FR
26b0: 4f 4d 20 74 31 20 4c 49 4d 49 54 20 32 7d 5d 20  OM t1 LIMIT 2}] 
26c0: 7b 0a 20 20 20 20 65 78 65 63 73 71 6c 20 7b 0a  {.    execsql {.
26d0: 20 20 20 20 20 20 44 45 4c 45 54 45 20 46 52 4f        DELETE FRO
26e0: 4d 20 78 32 20 57 48 45 52 45 20 64 6f 63 69 64  M x2 WHERE docid
26f0: 3d 24 69 64 3b 0a 20 20 20 20 20 20 49 4e 53 45  =$id;.      INSE
2700: 52 54 20 49 4e 54 4f 20 78 32 28 64 6f 63 69 64  RT INTO x2(docid
2710: 2c 20 63 6f 6e 74 65 6e 74 29 20 53 45 4c 45 43  , content) SELEC
2720: 54 20 24 69 64 2c 20 77 6f 72 64 73 20 46 52 4f  T $id, words FRO
2730: 4d 20 74 31 20 57 48 45 52 45 20 64 6f 63 69 64  M t1 WHERE docid
2740: 3d 24 69 64 3b 0a 20 20 20 20 7d 0a 20 20 7d 0a  =$id;.    }.  }.
2750: 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  }..#------------
2760: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2770: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2780: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2790: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23  --------------.#
27a0: 20 43 68 65 63 6b 20 74 68 61 74 20 73 65 67 6d   Check that segm
27b0: 65 6e 74 73 20 63 72 65 61 74 65 64 20 62 79 20  ents created by 
27c0: 61 75 74 6f 2d 6d 65 72 67 65 20 61 72 65 20 6e  auto-merge are n
27d0: 6f 74 20 70 72 6f 6d 6f 74 65 64 20 75 6e 74 69  ot promoted unti
27e0: 6c 20 74 68 65 79 0a 23 20 61 72 65 20 63 6f 6d  l they.# are com
27f0: 70 6c 65 74 65 64 2e 0a 23 0a 0a 64 6f 5f 65 78  pleted..#..do_ex
2800: 65 63 73 71 6c 5f 74 65 73 74 20 36 2e 31 20 7b  ecsql_test 6.1 {
2810: 0a 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41  .  CREATE VIRTUA
2820: 4c 20 54 41 42 4c 45 20 78 35 20 55 53 49 4e 47  L TABLE x5 USING
2830: 20 66 74 73 34 3b 0a 20 20 49 4e 53 45 52 54 20   fts4;.  INSERT 
2840: 49 4e 54 4f 20 78 35 20 53 45 4c 45 43 54 20 77  INTO x5 SELECT w
2850: 6f 72 64 73 20 46 52 4f 4d 20 74 31 20 4c 49 4d  ords FROM t1 LIM
2860: 49 54 20 31 30 30 20 4f 46 46 53 45 54 20 30 3b  IT 100 OFFSET 0;
2870: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78  .  INSERT INTO x
2880: 35 20 53 45 4c 45 43 54 20 77 6f 72 64 73 20 46  5 SELECT words F
2890: 52 4f 4d 20 74 31 20 4c 49 4d 49 54 20 31 30 30  ROM t1 LIMIT 100
28a0: 20 4f 46 46 53 45 54 20 32 35 3b 0a 20 20 49 4e   OFFSET 25;.  IN
28b0: 53 45 52 54 20 49 4e 54 4f 20 78 35 20 53 45 4c  SERT INTO x5 SEL
28c0: 45 43 54 20 77 6f 72 64 73 20 46 52 4f 4d 20 74  ECT words FROM t
28d0: 31 20 4c 49 4d 49 54 20 31 30 30 20 4f 46 46 53  1 LIMIT 100 OFFS
28e0: 45 54 20 35 30 3b 0a 20 20 49 4e 53 45 52 54 20  ET 50;.  INSERT 
28f0: 49 4e 54 4f 20 78 35 20 53 45 4c 45 43 54 20 77  INTO x5 SELECT w
2900: 6f 72 64 73 20 46 52 4f 4d 20 74 31 20 4c 49 4d  ords FROM t1 LIM
2910: 49 54 20 31 30 30 20 4f 46 46 53 45 54 20 37 35  IT 100 OFFSET 75
2920: 3b 0a 20 20 53 45 4c 45 43 54 20 63 6f 75 6e 74  ;.  SELECT count
2930: 28 2a 29 20 46 52 4f 4d 20 78 35 5f 73 65 67 64  (*) FROM x5_segd
2940: 69 72 0a 7d 20 7b 34 7d 0a 0a 64 6f 5f 65 78 65  ir.} {4}..do_exe
2950: 63 73 71 6c 5f 74 65 73 74 20 36 2e 32 20 7b 0a  csql_test 6.2 {.
2960: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 35    INSERT INTO x5
2970: 28 78 35 29 20 56 41 4c 55 45 53 28 27 6d 65 72  (x5) VALUES('mer
2980: 67 65 3d 32 2c 34 27 29 3b 0a 20 20 53 45 4c 45  ge=2,4');.  SELE
2990: 43 54 20 6c 65 76 65 6c 2c 20 69 64 78 2c 20 65  CT level, idx, e
29a0: 6e 64 5f 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 35  nd_block FROM x5
29b0: 5f 73 65 67 64 69 72 3b 0a 7d 20 7b 30 20 30 20  _segdir;.} {0 0 
29c0: 7b 31 30 20 39 32 31 36 7d 20 30 20 31 20 7b 32  {10 9216} 0 1 {2
29d0: 31 20 39 33 33 30 7d 20 30 20 32 20 7b 33 31 20  1 9330} 0 2 {31 
29e0: 38 38 35 30 7d 20 30 20 33 20 7b 34 30 20 38 36  8850} 0 3 {40 86
29f0: 38 39 7d 20 31 20 30 20 7b 31 33 32 30 20 2d 33  89} 1 0 {1320 -3
2a00: 31 31 37 7d 7d 0a 0a 64 6f 5f 65 78 65 63 73 71  117}}..do_execsq
2a10: 6c 5f 74 65 73 74 20 36 2e 33 20 7b 0a 20 20 49  l_test 6.3 {.  I
2a20: 4e 53 45 52 54 20 49 4e 54 4f 20 78 35 20 53 45  NSERT INTO x5 SE
2a30: 4c 45 43 54 20 77 6f 72 64 73 20 46 52 4f 4d 20  LECT words FROM 
2a40: 74 31 20 4c 49 4d 49 54 20 31 30 30 20 4f 46 46  t1 LIMIT 100 OFF
2a50: 53 45 54 20 31 30 30 3b 0a 20 20 53 45 4c 45 43  SET 100;.  SELEC
2a60: 54 20 6c 65 76 65 6c 2c 20 69 64 78 2c 20 65 6e  T level, idx, en
2a70: 64 5f 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 35 5f  d_block FROM x5_
2a80: 73 65 67 64 69 72 3b 0a 7d 20 7b 0a 20 20 30 20  segdir;.} {.  0 
2a90: 30 20 7b 31 30 20 39 32 31 36 7d 20 30 20 31 20  0 {10 9216} 0 1 
2aa0: 7b 32 31 20 39 33 33 30 7d 20 30 20 32 20 7b 33  {21 9330} 0 2 {3
2ab0: 31 20 38 38 35 30 7d 20 0a 20 20 30 20 33 20 7b  1 8850} .  0 3 {
2ac0: 34 30 20 38 36 38 39 7d 20 31 20 30 20 7b 31 33  40 8689} 1 0 {13
2ad0: 32 30 20 2d 33 31 31 37 7d 20 30 20 34 20 7b 31  20 -3117} 0 4 {1
2ae0: 33 32 39 20 38 32 39 37 7d 0a 7d 0a 0a 64 6f 5f  329 8297}.}..do_
2af0: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 36 2e 34  execsql_test 6.4
2b00: 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f   {.  INSERT INTO
2b10: 20 78 35 28 78 35 29 20 56 41 4c 55 45 53 28 27   x5(x5) VALUES('
2b20: 6d 65 72 67 65 3d 32 30 30 2c 34 27 29 3b 0a 20  merge=200,4');. 
2b30: 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 69   SELECT level, i
2b40: 64 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20 46 52  dx, end_block FR
2b50: 4f 4d 20 78 35 5f 73 65 67 64 69 72 3b 0a 7d 20  OM x5_segdir;.} 
2b60: 7b 30 20 30 20 7b 31 33 32 39 20 38 32 39 37 7d  {0 0 {1329 8297}
2b70: 20 31 20 30 20 7b 31 33 32 30 20 32 38 30 30 39   1 0 {1320 28009
2b80: 7d 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  }}..do_execsql_t
2b90: 65 73 74 20 36 2e 35 20 7b 0a 20 20 49 4e 53 45  est 6.5 {.  INSE
2ba0: 52 54 20 49 4e 54 4f 20 78 35 20 53 45 4c 45 43  RT INTO x5 SELEC
2bb0: 54 20 77 6f 72 64 73 20 46 52 4f 4d 20 74 31 3b  T words FROM t1;
2bc0: 0a 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c  .  SELECT level,
2bd0: 20 69 64 78 2c 20 65 6e 64 5f 62 6c 6f 63 6b 20   idx, end_block 
2be0: 46 52 4f 4d 20 78 35 5f 73 65 67 64 69 72 3b 0a  FROM x5_segdir;.
2bf0: 7d 20 7b 0a 20 20 30 20 31 20 7b 31 33 32 39 20  } {.  0 1 {1329 
2c00: 38 32 39 37 7d 20 30 20 30 20 7b 31 33 32 30 20  8297} 0 0 {1320 
2c10: 32 38 30 30 39 7d 20 30 20 32 20 7b 31 34 34 39  28009} 0 2 {1449
2c20: 20 31 31 38 30 30 36 7d 0a 7d 0a 0a 23 2d 2d 2d   118006}.}..#---
2c30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c70: 2d 2d 2d 2d 2d 2d 2d 0a 23 20 45 6e 73 75 72 65  -------.# Ensure
2c80: 20 74 68 61 74 20 69 66 20 70 61 72 74 20 6f 66   that if part of
2c90: 20 61 6e 20 69 6e 63 72 65 6d 65 6e 74 61 6c 20   an incremental 
2ca0: 6d 65 72 67 65 20 69 73 20 70 65 72 66 6f 72 6d  merge is perform
2cb0: 65 64 20 62 79 20 61 6e 20 6f 6c 64 0a 23 20 76  ed by an old.# v
2cc0: 65 72 73 69 6f 6e 20 74 68 61 74 20 64 6f 65 73  ersion that does
2cd0: 20 6e 6f 74 20 73 75 70 70 6f 72 74 20 73 74 6f   not support sto
2ce0: 72 69 6e 67 20 73 65 67 6d 65 6e 74 20 73 69 7a  ring segment siz
2cf0: 65 73 20 69 6e 20 74 68 65 20 65 6e 64 5f 62 6c  es in the end_bl
2d00: 6f 63 6b 0a 23 20 66 69 65 6c 64 2c 20 6e 6f 20  ock.# field, no 
2d10: 73 69 7a 65 20 69 73 20 73 74 6f 72 65 64 20 69  size is stored i
2d20: 6e 20 74 68 65 20 66 69 6e 61 6c 20 73 65 67 6d  n the final segm
2d30: 65 6e 74 20 28 61 73 20 69 74 20 77 6f 75 6c 64  ent (as it would
2d40: 20 62 65 20 69 6e 63 6f 72 72 65 63 74 29 2e 0a   be incorrect)..
2d50: 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  #.do_execsql_tes
2d60: 74 20 37 2e 31 20 7b 0a 20 20 43 52 45 41 54 45  t 7.1 {.  CREATE
2d70: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 78   VIRTUAL TABLE x
2d80: 36 20 55 53 49 4e 47 20 66 74 73 34 3b 0a 20 20  6 USING fts4;.  
2d90: 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 36 20 53  INSERT INTO x6 S
2da0: 45 4c 45 43 54 20 77 6f 72 64 73 20 46 52 4f 4d  ELECT words FROM
2db0: 20 74 31 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e   t1;.  INSERT IN
2dc0: 54 4f 20 78 36 20 53 45 4c 45 43 54 20 77 6f 72  TO x6 SELECT wor
2dd0: 64 73 20 46 52 4f 4d 20 74 31 3b 0a 20 20 49 4e  ds FROM t1;.  IN
2de0: 53 45 52 54 20 49 4e 54 4f 20 78 36 20 53 45 4c  SERT INTO x6 SEL
2df0: 45 43 54 20 77 6f 72 64 73 20 46 52 4f 4d 20 74  ECT words FROM t
2e00: 31 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  1;.  INSERT INTO
2e10: 20 78 36 20 53 45 4c 45 43 54 20 77 6f 72 64 73   x6 SELECT words
2e20: 20 46 52 4f 4d 20 74 31 3b 0a 20 20 49 4e 53 45   FROM t1;.  INSE
2e30: 52 54 20 49 4e 54 4f 20 78 36 20 53 45 4c 45 43  RT INTO x6 SELEC
2e40: 54 20 77 6f 72 64 73 20 46 52 4f 4d 20 74 31 3b  T words FROM t1;
2e50: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78  .  INSERT INTO x
2e60: 36 20 53 45 4c 45 43 54 20 77 6f 72 64 73 20 46  6 SELECT words F
2e70: 52 4f 4d 20 74 31 3b 0a 20 20 53 45 4c 45 43 54  ROM t1;.  SELECT
2e80: 20 6c 65 76 65 6c 2c 20 69 64 78 2c 20 65 6e 64   level, idx, end
2e90: 5f 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 36 5f 73  _block FROM x6_s
2ea0: 65 67 64 69 72 3b 0a 7d 20 7b 0a 20 20 30 20 30  egdir;.} {.  0 0
2eb0: 20 7b 31 31 38 20 31 31 37 34 38 33 7d 20 30 20   {118 117483} 0 
2ec0: 31 20 7b 32 33 38 20 31 31 38 30 30 36 7d 20 30  1 {238 118006} 0
2ed0: 20 32 20 7b 33 35 38 20 31 31 38 30 30 36 7d 20   2 {358 118006} 
2ee0: 0a 20 20 30 20 33 20 7b 34 37 38 20 31 31 38 30  .  0 3 {478 1180
2ef0: 30 36 7d 20 30 20 34 20 7b 35 39 38 20 31 31 38  06} 0 4 {598 118
2f00: 30 30 36 7d 20 30 20 35 20 7b 37 31 38 20 31 31  006} 0 5 {718 11
2f10: 38 30 30 36 7d 0a 7d 0a 0a 64 6f 5f 65 78 65 63  8006}.}..do_exec
2f20: 73 71 6c 5f 74 65 73 74 20 37 2e 32 20 7b 0a 20  sql_test 7.2 {. 
2f30: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 36 28   INSERT INTO x6(
2f40: 78 36 29 20 56 41 4c 55 45 53 28 27 6d 65 72 67  x6) VALUES('merg
2f50: 65 3d 32 35 2c 34 27 29 3b 0a 20 20 53 45 4c 45  e=25,4');.  SELE
2f60: 43 54 20 6c 65 76 65 6c 2c 20 69 64 78 2c 20 65  CT level, idx, e
2f70: 6e 64 5f 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 36  nd_block FROM x6
2f80: 5f 73 65 67 64 69 72 3b 0a 7d 20 7b 0a 20 20 30  _segdir;.} {.  0
2f90: 20 30 20 7b 31 31 38 20 31 31 37 34 38 33 7d 20   0 {118 117483} 
2fa0: 30 20 31 20 7b 32 33 38 20 31 31 38 30 30 36 7d  0 1 {238 118006}
2fb0: 20 30 20 32 20 7b 33 35 38 20 31 31 38 30 30 36   0 2 {358 118006
2fc0: 7d 20 0a 20 20 30 20 33 20 7b 34 37 38 20 31 31  } .  0 3 {478 11
2fd0: 38 30 30 36 7d 20 30 20 34 20 7b 35 39 38 20 31  8006} 0 4 {598 1
2fe0: 31 38 30 30 36 7d 20 30 20 35 20 7b 37 31 38 20  18006} 0 5 {718 
2ff0: 31 31 38 30 30 36 7d 0a 20 20 31 20 30 20 7b 31  118006}.  1 0 {1
3000: 36 30 31 34 20 2d 35 31 32 32 36 7d 0a 7d 0a 0a  6014 -51226}.}..
3010: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
3020: 37 2e 33 20 7b 0a 20 20 55 50 44 41 54 45 20 78  7.3 {.  UPDATE x
3030: 36 5f 73 65 67 64 69 72 20 53 45 54 20 65 6e 64  6_segdir SET end
3040: 5f 62 6c 6f 63 6b 20 3d 20 66 69 72 73 74 28 65  _block = first(e
3050: 6e 64 5f 62 6c 6f 63 6b 29 20 57 48 45 52 45 20  nd_block) WHERE 
3060: 6c 65 76 65 6c 3d 31 3b 0a 20 20 53 45 4c 45 43  level=1;.  SELEC
3070: 54 20 6c 65 76 65 6c 2c 20 69 64 78 2c 20 65 6e  T level, idx, en
3080: 64 5f 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 36 5f  d_block FROM x6_
3090: 73 65 67 64 69 72 3b 0a 7d 20 7b 0a 20 20 30 20  segdir;.} {.  0 
30a0: 30 20 7b 31 31 38 20 31 31 37 34 38 33 7d 20 30  0 {118 117483} 0
30b0: 20 31 20 7b 32 33 38 20 31 31 38 30 30 36 7d 20   1 {238 118006} 
30c0: 30 20 32 20 7b 33 35 38 20 31 31 38 30 30 36 7d  0 2 {358 118006}
30d0: 20 0a 20 20 30 20 33 20 7b 34 37 38 20 31 31 38   .  0 3 {478 118
30e0: 30 30 36 7d 20 30 20 34 20 7b 35 39 38 20 31 31  006} 0 4 {598 11
30f0: 38 30 30 36 7d 20 30 20 35 20 7b 37 31 38 20 31  8006} 0 5 {718 1
3100: 31 38 30 30 36 7d 0a 20 20 31 20 30 20 31 36 30  18006}.  1 0 160
3110: 31 34 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c  14.}..do_execsql
3120: 5f 74 65 73 74 20 37 2e 34 20 7b 0a 20 20 49 4e  _test 7.4 {.  IN
3130: 53 45 52 54 20 49 4e 54 4f 20 78 36 28 78 36 29  SERT INTO x6(x6)
3140: 20 56 41 4c 55 45 53 28 27 6d 65 72 67 65 3d 32   VALUES('merge=2
3150: 35 2c 34 27 29 3b 0a 20 20 53 45 4c 45 43 54 20  5,4');.  SELECT 
3160: 6c 65 76 65 6c 2c 20 69 64 78 2c 20 65 6e 64 5f  level, idx, end_
3170: 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 36 5f 73 65  block FROM x6_se
3180: 67 64 69 72 3b 0a 7d 20 7b 0a 20 20 30 20 30 20  gdir;.} {.  0 0 
3190: 7b 31 31 38 20 31 31 37 34 38 33 7d 20 30 20 31  {118 117483} 0 1
31a0: 20 7b 32 33 38 20 31 31 38 30 30 36 7d 20 30 20   {238 118006} 0 
31b0: 32 20 7b 33 35 38 20 31 31 38 30 30 36 7d 20 0a  2 {358 118006} .
31c0: 20 20 30 20 33 20 7b 34 37 38 20 31 31 38 30 30    0 3 {478 11800
31d0: 36 7d 20 30 20 34 20 7b 35 39 38 20 31 31 38 30  6} 0 4 {598 1180
31e0: 30 36 7d 20 30 20 35 20 7b 37 31 38 20 31 31 38  06} 0 5 {718 118
31f0: 30 30 36 7d 0a 20 20 31 20 30 20 31 36 30 31 34  006}.  1 0 16014
3200: 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  .}..do_execsql_t
3210: 65 73 74 20 37 2e 35 20 7b 0a 20 20 49 4e 53 45  est 7.5 {.  INSE
3220: 52 54 20 49 4e 54 4f 20 78 36 28 78 36 29 20 56  RT INTO x6(x6) V
3230: 41 4c 55 45 53 28 27 6d 65 72 67 65 3d 32 35 30  ALUES('merge=250
3240: 30 2c 34 27 29 3b 0a 20 20 53 45 4c 45 43 54 20  0,4');.  SELECT 
3250: 6c 65 76 65 6c 2c 20 69 64 78 2c 20 65 6e 64 5f  level, idx, end_
3260: 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 36 5f 73 65  block FROM x6_se
3270: 67 64 69 72 3b 0a 7d 20 7b 0a 20 20 30 20 30 20  gdir;.} {.  0 0 
3280: 7b 35 39 38 20 31 31 38 30 30 36 7d 20 30 20 31  {598 118006} 0 1
3290: 20 7b 37 31 38 20 31 31 38 30 30 36 7d 20 31 20   {718 118006} 1 
32a0: 30 20 31 36 30 31 34 0a 7d 0a 0a 64 6f 5f 65 78  0 16014.}..do_ex
32b0: 65 63 73 71 6c 5f 74 65 73 74 20 37 2e 36 20 7b  ecsql_test 7.6 {
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 32 27 29 3b 0a 20 20  rge=2500,2');.  
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 32 20 30 20 32 33 36 39 35 20 32 34 31 34    2 0 23695 2414
3350: 37 20 7b 34 31 32 36 32 20 36 33 33 35 30 37 7d  7 {41262 633507}
3360: 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  .}..do_execsql_t
3370: 65 73 74 20 37 2e 37 20 7b 0a 20 20 53 45 4c 45  est 7.7 {.  SELE
3380: 43 54 20 73 75 6d 28 6c 65 6e 67 74 68 28 62 6c  CT sum(length(bl
3390: 6f 63 6b 29 29 20 46 52 4f 4d 20 78 36 5f 73 65  ock)) FROM x6_se
33a0: 67 6d 65 6e 74 73 20 0a 20 20 57 48 45 52 45 20  gments .  WHERE 
33b0: 62 6c 6f 63 6b 69 64 20 42 45 54 57 45 45 4e 20  blockid BETWEEN 
33c0: 32 33 36 39 35 20 41 4e 44 20 32 34 31 34 37 0a  23695 AND 24147.
33d0: 7d 20 7b 36 33 33 35 30 37 7d 0a 0a 0a 0a 66 69  } {633507}....fi
33e0: 6e 69 73 68 5f 74 65 73 74 0a 0a                 nish_test..