/ Artifact Content
Login

Artifact 8e092654ab874afcc4a25f2255497eeb37da74e9:


# 2012 March 06
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#*************************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is testing the incremental merge function.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/fts3_common.tcl
set ::testprefix fts4merge

# If SQLITE_ENABLE_FTS3 is defined, omit this file.
ifcapable !fts3 {
  finish_test
  return
}

#-------------------------------------------------------------------------
# Test cases 1.*
#
do_test 1.0 { fts3_build_db_1 1004 } {}
do_test 1.1 { fts3_integrity_check t1 } {ok}
do_execsql_test 1.1 { 
  SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level 
} {
  0 {0 1 2 3 4 5 6 7 8 9 10 11} 
  1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13}
  2 {0 1 2}
}

for {set i 0} {$i<20} {incr i} {
  do_execsql_test 1.2.$i.1 { INSERT INTO t1(t1) VALUES('merge=1') }
  do_test 1.2.$i.2 { fts3_integrity_check t1 } ok
  do_execsql_test 1.2.$i.3 { 
    SELECT docid FROM t1 WHERE t1 MATCH 'zero one two three'
  } {123 132 213 231 312 321}
}

do_execsql_test 1.3 { 
  SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level 
} {
  0 {0 1 2 3} 
  1 {0 1 2 3 4 5 6} 
  2 {0 1 2 3}
}

for {set i 0} {$i<100} {incr i} {
  do_execsql_test 1.4.$i { INSERT INTO t1(t1) VALUES('merge=1,4') }
  do_test 1.4.$i.2 { fts3_integrity_check t1 } ok
  do_execsql_test 1.4.$i.3 { 
    SELECT docid FROM t1 WHERE t1 MATCH 'zero one two three'
  } {123 132 213 231 312 321}
}

do_execsql_test 1.5 { 
  SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level 
} {
  2 {0 1}
  3 0
}

#-------------------------------------------------------------------------
# Test cases 2.* test that errors in the xxx part of the 'merge=xxx' are
# handled correctly.
#
do_execsql_test 2.0 { CREATE VIRTUAL TABLE t2 USING fts4 }

foreach {tn arg} {
  1   {merge=abc}
  2   {merge=%%%}
  3   {merge=,}
  4   {merge=5,}
  5   {merge=6,%}
  6   {merge=6,six}
  7   {merge=6,1}
  8   {merge=6,0}
} {
  do_catchsql_test 2.$tn { 
    INSERT INTO t2(t2) VALUES($arg);
  } {1 {SQL logic error or missing database}}
}

#-------------------------------------------------------------------------
# Test cases 3.*
#
do_test 3.0 { 
  reset_db
  execsql { PRAGMA page_size = 512 }
  fts3_build_db_2 30040 
} {}
do_test 3.1 { fts3_integrity_check t2 } {ok}

do_execsql_test 3.2 { 
  SELECT level, group_concat(idx, ' ') FROM t2_segdir GROUP BY level 
} {
  0 {0 1 2 3 4 5 6} 
  1 {0 1 2 3 4} 
  2 {0 1 2 3 4} 
  3 {0 1 2 3 4 5 6}
}

do_execsql_test 3.3 { 
  INSERT INTO t2(t2) VALUES('merge=1000000,2');
  SELECT level, group_concat(idx, ' ') FROM t2_segdir GROUP BY level 
} {
  0 0 
  2 0
  3 0 
  4 0
  6 0
}

#-------------------------------------------------------------------------
# Test cases 4.*
#
reset_db
do_execsql_test 4.1 {
  PRAGMA page_size = 512;
  CREATE VIRTUAL TABLE t4 USING fts4;
  PRAGMA main.page_size;
} {512}

do_test 4.2 {
  foreach x {a c b d e f g h i j k l m n o p} {
    execsql "INSERT INTO t4 VALUES('[string repeat $x 600]')"
  }
  execsql {SELECT level, group_concat(idx, ' ') FROM t4_segdir GROUP BY level}
} {0 {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15}}

foreach {tn expect} {
  1  "0 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} 1 0"
  2  "0 {0 1 2 3 4 5 6 7 8 9 10 11 12}    1 0"
  3  "0 {0 1 2 3 4 5 6 7 8 9 10 11}       1 0"
  4  "0 {0 1 2 3 4 5 6 7 8 9 10}          1 0"
  5  "0 {0 1 2 3 4 5 6 7 8 9}             1 0"
  6  "0 {0 1 2 3 4 5 6 7 8}               1 0"
  7  "0 {0 1 2 3 4 5 6 7}                 1 0"
  8  "0 {0 1 2 3 4 5 6}                   1 0"
  9  "0 {0 1 2 3 4 5}                     1 0"
} {
  do_execsql_test 4.3.$tn {
    INSERT INTO t4(t4) VALUES('merge=1,16');
    SELECT level, group_concat(idx, ' ') FROM t4_segdir GROUP BY level;
  } $expect
}

do_execsql_test 4.4.1 {
  SELECT quote(value) FROM t4_stat WHERE rowid=1
} {X'0006'}

do_execsql_test 4.4.2 {
  DELETE FROM t4_stat WHERE rowid=1;
  INSERT INTO t4(t4) VALUES('merge=1,12');
  SELECT level, group_concat(idx, ' ') FROM t4_segdir GROUP BY level;
} "0 {0 1 2 3 4 5}                     1 0"


finish_test