/ Check-in [5c447e22]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remove the fts3merge.test script in favour of changing the fts4merge.test script so that it runs tests using both fts4 and fts3. Fix some problems with incr-merge and FTS3 tables.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fts4-incr-merge
Files: files | file ages | folders
SHA1:5c447e226afca0d46b9ed994dea26a16a9ae168c
User & Date: dan 2012-03-27 15:00:06
Context
2012-03-27
15:10
Really delete the fts3merge.test script (should have been deleted by the previous commit). check-in: 83838149 user: dan tags: fts4-incr-merge
15:00
Remove the fts3merge.test script in favour of changing the fts4merge.test script so that it runs tests using both fts4 and fts3. Fix some problems with incr-merge and FTS3 tables. check-in: 5c447e22 user: dan tags: fts4-incr-merge
14:54
In the fts3view utility, label the blank segments used to mark the end of a segment sequence for a level/idx as "null". Improve the alignment of root segment names. check-in: 04aea024 user: drh tags: fts4-incr-merge
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3.c.

638
639
640
641
642
643
644

645
646
647
648
649
650
651
....
1280
1281
1282
1283
1284
1285
1286

1287
1288
1289
1290
1291
1292
1293
....
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
....
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
  );
  if( p->bHasDocsize ){
    fts3DbExec(&rc, db, 
        "CREATE TABLE %Q.'%q_docsize'(docid INTEGER PRIMARY KEY, size BLOB);",
        p->zDb, p->zName
    );
  }

  if( p->bHasStat ){
    sqlite3Fts3CreateStatTable(&rc, p);
  }
  return rc;
}

/*
................................................................................
  p->nColumn = nCol;
  p->nPendingData = 0;
  p->azColumn = (char **)&p[1];
  p->pTokenizer = pTokenizer;
  p->nMaxPendingData = FTS3_MAX_PENDING_DATA;
  p->bHasDocsize = (isFts4 && bNoDocsize==0);
  p->bHasStat = isFts4;

  p->bDescIdx = bDescIdx;
  p->bAutoincrmerge = 0xff;   /* 0xff means setting unknown */
  p->zContentTbl = zContent;
  p->zLanguageid = zLanguageid;
  zContent = 0;
  zLanguageid = 0;
  TESTONLY( p->inTransaction = -1 );
................................................................................
      return SQLITE_NOMEM;
    }

    pCsr->iLangid = 0;
    if( nVal==2 ) pCsr->iLangid = sqlite3_value_int(apVal[1]);

    rc = sqlite3Fts3ExprParse(p->pTokenizer, pCsr->iLangid,
        p->azColumn, p->bHasStat, p->nColumn, iCol, zQuery, -1, &pCsr->pExpr
    );
    if( rc!=SQLITE_OK ){
      if( rc==SQLITE_ERROR ){
        static const char *zErr = "malformed MATCH expression: [%s]";
        p->base.zErrMsg = sqlite3_mprintf(zErr, zQuery);
      }
      return rc;
................................................................................
  int nToken = 0;
  int nOr = 0;

  /* Allocate a MultiSegReader for each token in the expression. */
  fts3EvalAllocateReaders(pCsr, pCsr->pExpr, &nToken, &nOr, &rc);

  /* Determine which, if any, tokens in the expression should be deferred. */
  if( rc==SQLITE_OK && nToken>1 && pTab->bHasStat ){
    Fts3TokenAndCost *aTC;
    Fts3Expr **apOr;
    aTC = (Fts3TokenAndCost *)sqlite3_malloc(
        sizeof(Fts3TokenAndCost) * nToken
      + sizeof(Fts3Expr *) * nOr * 2
    );
    apOr = (Fts3Expr **)&aTC[nToken];







>







 







>







 







|







 







|







638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
....
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
....
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
....
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
  );
  if( p->bHasDocsize ){
    fts3DbExec(&rc, db, 
        "CREATE TABLE %Q.'%q_docsize'(docid INTEGER PRIMARY KEY, size BLOB);",
        p->zDb, p->zName
    );
  }
  assert( p->bHasStat==p->bFts4 );
  if( p->bHasStat ){
    sqlite3Fts3CreateStatTable(&rc, p);
  }
  return rc;
}

/*
................................................................................
  p->nColumn = nCol;
  p->nPendingData = 0;
  p->azColumn = (char **)&p[1];
  p->pTokenizer = pTokenizer;
  p->nMaxPendingData = FTS3_MAX_PENDING_DATA;
  p->bHasDocsize = (isFts4 && bNoDocsize==0);
  p->bHasStat = isFts4;
  p->bFts4 = isFts4;
  p->bDescIdx = bDescIdx;
  p->bAutoincrmerge = 0xff;   /* 0xff means setting unknown */
  p->zContentTbl = zContent;
  p->zLanguageid = zLanguageid;
  zContent = 0;
  zLanguageid = 0;
  TESTONLY( p->inTransaction = -1 );
................................................................................
      return SQLITE_NOMEM;
    }

    pCsr->iLangid = 0;
    if( nVal==2 ) pCsr->iLangid = sqlite3_value_int(apVal[1]);

    rc = sqlite3Fts3ExprParse(p->pTokenizer, pCsr->iLangid,
        p->azColumn, p->bFts4, p->nColumn, iCol, zQuery, -1, &pCsr->pExpr
    );
    if( rc!=SQLITE_OK ){
      if( rc==SQLITE_ERROR ){
        static const char *zErr = "malformed MATCH expression: [%s]";
        p->base.zErrMsg = sqlite3_mprintf(zErr, zQuery);
      }
      return rc;
................................................................................
  int nToken = 0;
  int nOr = 0;

  /* Allocate a MultiSegReader for each token in the expression. */
  fts3EvalAllocateReaders(pCsr, pCsr->pExpr, &nToken, &nOr, &rc);

  /* Determine which, if any, tokens in the expression should be deferred. */
  if( rc==SQLITE_OK && nToken>1 && pTab->bFts4 ){
    Fts3TokenAndCost *aTC;
    Fts3Expr **apOr;
    aTC = (Fts3TokenAndCost *)sqlite3_malloc(
        sizeof(Fts3TokenAndCost) * nToken
      + sizeof(Fts3Expr *) * nOr * 2
    );
    apOr = (Fts3Expr **)&aTC[nToken];

Changes to ext/fts3/fts3Int.h.

205
206
207
208
209
210
211

212
213
214
215
216
217
218
  */
  sqlite3_stmt *aStmt[37];

  char *zReadExprlist;
  char *zWriteExprlist;

  int nNodeSize;                  /* Soft limit for node size */

  u8 bHasStat;                    /* True if %_stat table exists */
  u8 bHasDocsize;                 /* True if %_docsize table exists */
  u8 bDescIdx;                    /* True if doclists are in reverse order */
  u8 bIgnoreSavepoint;            /* True to ignore xSavepoint invocations */
  int nPgsz;                      /* Page size for host database */
  char *zSegmentsTbl;             /* Name of %_segments table */
  sqlite3_blob *pSegments;        /* Blob handle open on %_segments table */







>







205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
  */
  sqlite3_stmt *aStmt[37];

  char *zReadExprlist;
  char *zWriteExprlist;

  int nNodeSize;                  /* Soft limit for node size */
  u8 bFts4;                       /* True for FTS4, false for FTS3 */
  u8 bHasStat;                    /* True if %_stat table exists */
  u8 bHasDocsize;                 /* True if %_docsize table exists */
  u8 bDescIdx;                    /* True if doclists are in reverse order */
  u8 bIgnoreSavepoint;            /* True to ignore xSavepoint invocations */
  int nPgsz;                      /* Page size for host database */
  char *zSegmentsTbl;             /* Name of %_segments table */
  sqlite3_blob *pSegments;        /* Blob handle open on %_segments table */

Changes to ext/fts3/fts3_snippet.c.

790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
static int fts3MatchinfoCheck(
  Fts3Table *pTab, 
  char cArg,
  char **pzErr
){
  if( (cArg==FTS3_MATCHINFO_NPHRASE)
   || (cArg==FTS3_MATCHINFO_NCOL)
   || (cArg==FTS3_MATCHINFO_NDOC && pTab->bHasStat)
   || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bHasStat)
   || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize)
   || (cArg==FTS3_MATCHINFO_LCS)
   || (cArg==FTS3_MATCHINFO_HITS)
  ){
    return SQLITE_OK;
  }
  *pzErr = sqlite3_mprintf("unrecognized matchinfo request: %c", cArg);







|
|







790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
static int fts3MatchinfoCheck(
  Fts3Table *pTab, 
  char cArg,
  char **pzErr
){
  if( (cArg==FTS3_MATCHINFO_NPHRASE)
   || (cArg==FTS3_MATCHINFO_NCOL)
   || (cArg==FTS3_MATCHINFO_NDOC && pTab->bFts4)
   || (cArg==FTS3_MATCHINFO_AVGLENGTH && pTab->bFts4)
   || (cArg==FTS3_MATCHINFO_LENGTH && pTab->bHasDocsize)
   || (cArg==FTS3_MATCHINFO_LCS)
   || (cArg==FTS3_MATCHINFO_HITS)
  ){
    return SQLITE_OK;
  }
  *pzErr = sqlite3_mprintf("unrecognized matchinfo request: %c", cArg);

Changes to ext/fts3/fts3_write.c.

1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
....
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
....
4725
4726
4727
4728
4729
4730
4731


4732

4733
4734
4735
4736
4737
4738
4739
....
4750
4751
4752
4753
4754
4755
4756

4757
4758
4759
4760
4761
4762
4763
....
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
){
  Fts3Table *p = (Fts3Table*)pCsr->base.pVtab;
  int nOvfl = 0;
  int ii;
  int rc = SQLITE_OK;
  int pgsz = p->nPgsz;

  assert( p->bHasStat );
  assert( pgsz>0 );

  for(ii=0; rc==SQLITE_OK && ii<pMsr->nSegment; ii++){
    Fts3SegReader *pReader = pMsr->apSegment[ii];
    if( !fts3SegReaderIsPending(pReader) 
     && !fts3SegReaderIsRootOnly(pReader) 
    ){
................................................................................
      }else{
        nEntry++;
        for(iCol=0; iCol<=p->nColumn; iCol++){
          aSzIns[iCol] += aSz[iCol];
        }
      }
    }
    if( p->bHasStat ){
      fts3UpdateDocTotals(&rc, p, aSzIns, aSzDel, nEntry);
    }
    sqlite3_free(aSz);

    if( pStmt ){
      int rc2 = sqlite3_finalize(pStmt);
      if( rc==SQLITE_OK ){
................................................................................
    nMin = fts3Getint(&z);
  }

  if( z[0]!='\0' || nMin<2 ){
    rc = SQLITE_ERROR;
  }else{
    rc = SQLITE_OK;


    if( !p->bHasStat ) sqlite3Fts3CreateStatTable(&rc, p);

    if( rc==SQLITE_OK ){
      rc = sqlite3Fts3Incrmerge(p, nMerge, nMin);
    }
    sqlite3Fts3SegmentsClose(p);
  }
  return rc;
}
................................................................................
  Fts3Table *p,                   /* FTS3 table handle */
  const char *zParam              /* Nul-terminated string containing boolean */
){
  int rc = SQLITE_OK;
  sqlite3_stmt *pStmt = 0;
  p->bAutoincrmerge = fts3Getint(&zParam)!=0;
  if( !p->bHasStat ){

    sqlite3Fts3CreateStatTable(&rc, p);
    if( rc ) return rc;
  }
  rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pStmt, 0);
  if( rc ) return rc;;
  sqlite3_bind_int(pStmt, 1, FTS_STAT_AUTOINCRMERGE);
  sqlite3_bind_int(pStmt, 2, p->bAutoincrmerge);
................................................................................
    }
    if( p->bHasDocsize ){
      fts3InsertDocsize(&rc, p, aSzIns);
    }
    nChng++;
  }

  if( p->bHasStat ){
    fts3UpdateDocTotals(&rc, p, aSzIns, aSzDel, nChng);
  }

 update_out:
  sqlite3_free(aSzIns);
  sqlite3Fts3SegmentsClose(p);
  return rc;







|







 







|







 







>
>
|
>







 







>







 







|







1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
....
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
....
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
....
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
....
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
){
  Fts3Table *p = (Fts3Table*)pCsr->base.pVtab;
  int nOvfl = 0;
  int ii;
  int rc = SQLITE_OK;
  int pgsz = p->nPgsz;

  assert( p->bFts4 );
  assert( pgsz>0 );

  for(ii=0; rc==SQLITE_OK && ii<pMsr->nSegment; ii++){
    Fts3SegReader *pReader = pMsr->apSegment[ii];
    if( !fts3SegReaderIsPending(pReader) 
     && !fts3SegReaderIsRootOnly(pReader) 
    ){
................................................................................
      }else{
        nEntry++;
        for(iCol=0; iCol<=p->nColumn; iCol++){
          aSzIns[iCol] += aSz[iCol];
        }
      }
    }
    if( p->bFts4 ){
      fts3UpdateDocTotals(&rc, p, aSzIns, aSzDel, nEntry);
    }
    sqlite3_free(aSz);

    if( pStmt ){
      int rc2 = sqlite3_finalize(pStmt);
      if( rc==SQLITE_OK ){
................................................................................
    nMin = fts3Getint(&z);
  }

  if( z[0]!='\0' || nMin<2 ){
    rc = SQLITE_ERROR;
  }else{
    rc = SQLITE_OK;
    if( !p->bHasStat ){
      assert( p->bFts4==0 );
      sqlite3Fts3CreateStatTable(&rc, p);
    }
    if( rc==SQLITE_OK ){
      rc = sqlite3Fts3Incrmerge(p, nMerge, nMin);
    }
    sqlite3Fts3SegmentsClose(p);
  }
  return rc;
}
................................................................................
  Fts3Table *p,                   /* FTS3 table handle */
  const char *zParam              /* Nul-terminated string containing boolean */
){
  int rc = SQLITE_OK;
  sqlite3_stmt *pStmt = 0;
  p->bAutoincrmerge = fts3Getint(&zParam)!=0;
  if( !p->bHasStat ){
    assert( p->bFts4==0 );
    sqlite3Fts3CreateStatTable(&rc, p);
    if( rc ) return rc;
  }
  rc = fts3SqlStmt(p, SQL_REPLACE_STAT, &pStmt, 0);
  if( rc ) return rc;;
  sqlite3_bind_int(pStmt, 1, FTS_STAT_AUTOINCRMERGE);
  sqlite3_bind_int(pStmt, 2, p->bAutoincrmerge);
................................................................................
    }
    if( p->bHasDocsize ){
      fts3InsertDocsize(&rc, p, aSzIns);
    }
    nChng++;
  }

  if( p->bFts4 ){
    fts3UpdateDocTotals(&rc, p, aSzIns, aSzDel, nChng);
  }

 update_out:
  sqlite3_free(aSzIns);
  sqlite3Fts3SegmentsClose(p);
  return rc;

Changes to test/fts3_common.tcl.

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56













57
58
59
60
61
62
63
64
..
81
82
83
84
85
86
87
88















89
90
91
92

93

94
95
96
97
98
99
100
#   fts3_doclist TBL TERM WHERE
#     Todo.
#
#
#

#-------------------------------------------------------------------------
# USAGE: fts3_build_db_1 N
#
# Build a sample FTS table in the database opened by database connection 
# [db]. The name of the new table is "t1".
#
proc fts3_build_db_1 {n} {

  if {$n > 10000} {error "n must be <= 10000"}














  db eval { CREATE VIRTUAL TABLE t1 USING fts4(x, y) }

  set xwords [list zero one two three four five six seven eight nine ten]
  set ywords [list alpha beta gamma delta epsilon zeta eta theta iota kappa]

  for {set i 0} {$i < $n} {incr i} {
    set x ""
    set y ""
................................................................................

#-------------------------------------------------------------------------
# USAGE: fts3_build_db_2 N ARGS
#
# Build a sample FTS table in the database opened by database connection 
# [db]. The name of the new table is "t2".
#
proc fts3_build_db_2 {n args} {
















  if {$n > 100000} {error "n must be <= 100000"}

  set sql "CREATE VIRTUAL TABLE t2 USING fts4(content"

  foreach a $args { append sql ", " $a }

  append sql ")"
  db eval $sql

  set chars [list a b c d e f g h  i j k l m n o p  q r s t u v w x  y z ""]

  for {set i 0} {$i < $n} {incr i} {
    set word ""







|




|

|

>
>
>
>
>
>
>
>
>
>
>
>
>
|







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



|
>
|
>







41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
..
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#   fts3_doclist TBL TERM WHERE
#     Todo.
#
#
#

#-------------------------------------------------------------------------
# USAGE: fts3_build_db_1 SWITCHES N
#
# Build a sample FTS table in the database opened by database connection 
# [db]. The name of the new table is "t1".
#
proc fts3_build_db_1 {args} {

  set default(-module) fts4

  set nArg [llength $args]
  if {($nArg%2)==0} {
    error "wrong # args: should be \"fts3_build_db_1 ?switches? n\""
  }

  set n [lindex $args [expr $nArg-1]]
  array set opts [array get default]
  array set opts [lrange $args 0 [expr $nArg-2]]
  foreach k [array names opts] {
    if {0==[info exists default($k)]} { error "unknown option: $k" }
  }

  if {$n > 10000} {error "n must be <= 10000"}
  db eval "CREATE VIRTUAL TABLE t1 USING $opts(-module) (x, y)"

  set xwords [list zero one two three four five six seven eight nine ten]
  set ywords [list alpha beta gamma delta epsilon zeta eta theta iota kappa]

  for {set i 0} {$i < $n} {incr i} {
    set x ""
    set y ""
................................................................................

#-------------------------------------------------------------------------
# USAGE: fts3_build_db_2 N ARGS
#
# Build a sample FTS table in the database opened by database connection 
# [db]. The name of the new table is "t2".
#
proc fts3_build_db_2 {args} {

  set default(-module) fts4
  set default(-extra)   ""

  set nArg [llength $args]
  if {($nArg%2)==0} {
    error "wrong # args: should be \"fts3_build_db_1 ?switches? n\""
  }

  set n [lindex $args [expr $nArg-1]]
  array set opts [array get default]
  array set opts [lrange $args 0 [expr $nArg-2]]
  foreach k [array names opts] {
    if {0==[info exists default($k)]} { error "unknown option: $k" }
  }

  if {$n > 100000} {error "n must be <= 100000"}

  set sql "CREATE VIRTUAL TABLE t2 USING $opts(-module) (content"
  if {$opts(-extra) != ""} {
    append sql ", " $opts(-extra)
  }
  append sql ")"
  db eval $sql

  set chars [list a b c d e f g h  i j k l m n o p  q r s t u v w x  y z ""]

  for {set i 0} {$i < $n} {incr i} {
    set word ""

Changes to test/fts4check.test.

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
...
147
148
149
150
151
152
153
154
155
156
157
#   2.1: Run the integrity check code to check it passes.
#
#   2.2: Make a series of minor changes to the underlying FTS data structures
#        (e.g. delete or insert a row from the %_content table). Check that
#        this causes the integrity-check code to fail.
#

do_test 2.0 { fts3_build_db_2 20000 {prefix="3,1"} } {}
do_test 2.1 { fts_integrity db t2 } {ok}
foreach {tn disruption} {
  1 {
    INSERT INTO t2_content VALUES(NULL, 'xyz')
  }
  3 {
    DELETE FROM t2_segdir WHERE level=0 AND idx=(
................................................................................
} {
  do_execsql_test  3.2.1.$tn "BEGIN; $disruption"
  do_catchsql_test 3.2.2.$tn {
    INSERT INTO t3 (t3) VALUES('integrity-check')
  } {1 {database disk image is malformed}}
  do_execsql_test  3.2.3.$tn "ROLLBACK"
}



finish_test







|







 








<
<

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
...
147
148
149
150
151
152
153
154


155
#   2.1: Run the integrity check code to check it passes.
#
#   2.2: Make a series of minor changes to the underlying FTS data structures
#        (e.g. delete or insert a row from the %_content table). Check that
#        this causes the integrity-check code to fail.
#

do_test 2.0 { fts3_build_db_2 -extra {prefix="3,1"} 20000 } {}
do_test 2.1 { fts_integrity db t2 } {ok}
foreach {tn disruption} {
  1 {
    INSERT INTO t2_content VALUES(NULL, 'xyz')
  }
  3 {
    DELETE FROM t2_segdir WHERE level=0 AND idx=(
................................................................................
} {
  do_execsql_test  3.2.1.$tn "BEGIN; $disruption"
  do_catchsql_test 3.2.2.$tn {
    INSERT INTO t3 (t3) VALUES('integrity-check')
  } {1 {database disk image is malformed}}
  do_execsql_test  3.2.3.$tn "ROLLBACK"
}



finish_test

Changes to test/fts4merge.test.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335






# 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
}

proc fts3_integrity_check {tbl} {
  db eval "INSERT INTO $tbl ($tbl) VALUES('integrity-check')"
  return "ok"
}

#-------------------------------------------------------------------------
# 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"


#-------------------------------------------------------------------------
# Test cases 5.*
#
# Test that if a crisis-merge occurs that disrupts an ongoing incremental
# merge, the next call to "merge=A,B" identifies this and starts a new
# incremental merge. There are two scenarios:
#
#   * There are less segments on the input level that the disrupted
#     incremental merge operated on, or
#   
#   * Sufficient segments exist on the input level but the segments 
#     contain keys smaller than the largest key in the potential output 
#     segment.
# 
do_test 5.1 {
  reset_db
  fts3_build_db_1 1000
} {}

do_execsql_test 5.2 {
  SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level;
} {
  0 {0 1 2 3 4 5 6 7} 
  1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} 
  2 {0 1 2}
}

do_execsql_test 5.3 {
  INSERT INTO t1(t1) VALUES('merge=1,5');
  INSERT INTO t1(t1) VALUES('merge=1,5');
  SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level;
} {
  0 {0 1 2}
  1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14} 
  2 {0 1 2 3}
}

do_execsql_test 5.4 {SELECT quote(value) from t1_stat WHERE rowid=1} {X'0105'}
do_test 5.5 {
  foreach docid [execsql {SELECT docid FROM t1}] {
    execsql {INSERT INTO t1 SELECT * FROM t1 WHERE docid=$docid}
  }
} {}

do_execsql_test 5.6 {SELECT quote(value) from t1_stat WHERE rowid=1} {X'0105'}

do_execsql_test 5.7 {
  SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level;
  SELECT quote(value) from t1_stat WHERE rowid=1;
} {
  0 {0 1 2 3 4 5 6 7 8 9 10} 
  1 {0 1 2 3 4 5 6 7 8 9 10 11 12} 
  2 {0 1 2 3 4 5 6 7}
  X'0105'
}

do_execsql_test 5.8 {
  INSERT INTO t1(t1) VALUES('merge=1,6');
  INSERT INTO t1(t1) VALUES('merge=1,6');
  SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level;
  SELECT quote(value) from t1_stat WHERE rowid=1;
} {
  0 {0 1 2 3 4} 
  1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} 
  2 {0 1 2 3 4 5 6 7 8} X'0106'
}

do_test 5.8.1 { fts3_integrity_check t1 } ok

do_test 5.9 {
  set L [expr 16*16*7 + 16*3 + 12]
  foreach docid [execsql {
      SELECT docid FROM t1 UNION ALL SELECT docid FROM t1 LIMIT $L
  }] {
    execsql {INSERT INTO t1 SELECT * FROM t1 WHERE docid=$docid}
  }
} {}

do_execsql_test 5.10 {
  SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level;
  SELECT quote(value) from t1_stat WHERE rowid=1;
} {
  0 0 1 {0 1} 2 0 3 0 X'0106'
}

do_execsql_test 5.11 {
  INSERT INTO t1(t1) VALUES('merge=1,6');
  SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level;
  SELECT quote(value) from t1_stat WHERE rowid=1;
} {
  0 0 1 {0 1} 2 0 3 0 X''
}

#-------------------------------------------------------------------------
# Test cases 6.*
#
# At one point the following test caused an assert() to fail (because the
# second 'merge=1,2' operation below actually "merges" a single input
# segment, which was unexpected).
#
do_test 6.1 {
  reset_db
  set a [string repeat a 900]
  set b [string repeat b 900]
  set c [string repeat c 900]
  set d [string repeat d 900]
  execsql {
    CREATE VIRTUAL TABLE t1 USING fts4;
    BEGIN;
      INSERT INTO t1 VALUES($a);
      INSERT INTO t1 VALUES($b);
    COMMIT;
    BEGIN;
      INSERT INTO t1 VALUES($c);
      INSERT INTO t1 VALUES($d);
    COMMIT;
  }

  execsql {
    INSERT INTO t1(t1) VALUES('merge=1,2');
    INSERT INTO t1(t1) VALUES('merge=1,2');
  }
} {}

#-------------------------------------------------------------------------
# Test cases 7.*
#
# Test that the value returned by sqlite3_total_changes() increases by
# 1 following a no-op "merge=A,B", or by more than 1 if actual work is
# performed.
#
do_test 7.0 {
  reset_db
  fts3_build_db_1 1000
} {}

do_execsql_test 7.1 {
  SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level
} {
  0 {0 1 2 3 4 5 6 7} 
  1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} 
  2 {0 1 2}
}
do_test 7.2 {
  set x [db total_changes]
  execsql { INSERT INTO t1(t1) VALUES('merge=2,10') }
  expr { ([db total_changes] - $x)>1 }
} {1}
do_test 7.3 {
  set x [db total_changes]
  execsql { INSERT INTO t1(t1) VALUES('merge=200,10') }
  expr { ([db total_changes] - $x)>1 }
} {1}
do_test 7.4 {
  set x [db total_changes]
  execsql { INSERT INTO t1(t1) VALUES('merge=200,10') }
  expr { ([db total_changes] - $x)>1 }
} {0}
do_test 7.5 {
  set x [db total_changes]
  execsql { INSERT INTO t1(t1) VALUES('merge=200,10') }
  expr { ([db total_changes] - $x)>1 }
} {0}

finish_test













|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# 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

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

proc fts3_integrity_check {tbl} {
  db eval "INSERT INTO $tbl ($tbl) VALUES('integrity-check')"
  return "ok"
}

foreach mod {fts3 fts4} {
  set ::testprefix fts4merge-$mod
  reset_db

  #-------------------------------------------------------------------------
  # Test cases 1.*
  #
  do_test 1.0 { fts3_build_db_1 -module $mod 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 $mod"
  
  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 -module $mod 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 $mod;
    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"
  
  
  #-------------------------------------------------------------------------
  # Test cases 5.*
  #
  # Test that if a crisis-merge occurs that disrupts an ongoing incremental
  # merge, the next call to "merge=A,B" identifies this and starts a new
  # incremental merge. There are two scenarios:
  #
  #   * There are less segments on the input level that the disrupted
  #     incremental merge operated on, or
  #   
  #   * Sufficient segments exist on the input level but the segments 
  #     contain keys smaller than the largest key in the potential output 
  #     segment.
  # 
  do_test 5.1 {
    reset_db
    fts3_build_db_1 -module $mod 1000
  } {}
  
  do_execsql_test 5.2 {
    SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level;
  } {
    0 {0 1 2 3 4 5 6 7} 
    1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} 
    2 {0 1 2}
  }
  
  do_execsql_test 5.3 {
    INSERT INTO t1(t1) VALUES('merge=1,5');
    INSERT INTO t1(t1) VALUES('merge=1,5');
    SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level;
  } {
    0 {0 1 2}
    1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14} 
    2 {0 1 2 3}
  }
  
  do_execsql_test 5.4 {SELECT quote(value) from t1_stat WHERE rowid=1} {X'0105'}
  do_test 5.5 {
    foreach docid [execsql {SELECT docid FROM t1}] {
      execsql {INSERT INTO t1 SELECT * FROM t1 WHERE docid=$docid}
    }
  } {}
  
  do_execsql_test 5.6 {SELECT quote(value) from t1_stat WHERE rowid=1} {X'0105'}
  
  do_execsql_test 5.7 {
    SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level;
    SELECT quote(value) from t1_stat WHERE rowid=1;
  } {
    0 {0 1 2 3 4 5 6 7 8 9 10} 
    1 {0 1 2 3 4 5 6 7 8 9 10 11 12} 
    2 {0 1 2 3 4 5 6 7}
    X'0105'
  }
  
  do_execsql_test 5.8 {
    INSERT INTO t1(t1) VALUES('merge=1,6');
    INSERT INTO t1(t1) VALUES('merge=1,6');
    SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level;
    SELECT quote(value) from t1_stat WHERE rowid=1;
  } {
    0 {0 1 2 3 4} 
    1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} 
    2 {0 1 2 3 4 5 6 7 8} X'0106'
  }
  
  do_test 5.8.1 { fts3_integrity_check t1 } ok
  
  do_test 5.9 {
    set L [expr 16*16*7 + 16*3 + 12]
    foreach docid [execsql {
        SELECT docid FROM t1 UNION ALL SELECT docid FROM t1 LIMIT $L
    }] {
      execsql {INSERT INTO t1 SELECT * FROM t1 WHERE docid=$docid}
    }
  } {}
  
  do_execsql_test 5.10 {
    SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level;
    SELECT quote(value) from t1_stat WHERE rowid=1;
  } {
    0 0 1 {0 1} 2 0 3 0 X'0106'
  }
  
  do_execsql_test 5.11 {
    INSERT INTO t1(t1) VALUES('merge=1,6');
    SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level;
    SELECT quote(value) from t1_stat WHERE rowid=1;
  } {
    0 0 1 {0 1} 2 0 3 0 X''
  }
  
  #-------------------------------------------------------------------------
  # Test cases 6.*
  #
  # At one point the following test caused an assert() to fail (because the
  # second 'merge=1,2' operation below actually "merges" a single input
  # segment, which was unexpected).
  #
  do_test 6.1 {
    reset_db
    set a [string repeat a 900]
    set b [string repeat b 900]
    set c [string repeat c 900]
    set d [string repeat d 900]

    execsql "CREATE VIRTUAL TABLE t1 USING $mod"
    execsql {
      BEGIN;
        INSERT INTO t1 VALUES($a);
        INSERT INTO t1 VALUES($b);
      COMMIT;
      BEGIN;
        INSERT INTO t1 VALUES($c);
        INSERT INTO t1 VALUES($d);
      COMMIT;
    }
  
    execsql {
      INSERT INTO t1(t1) VALUES('merge=1,2');
      INSERT INTO t1(t1) VALUES('merge=1,2');
    }
  } {}
  
  #-------------------------------------------------------------------------
  # Test cases 7.*
  #
  # Test that the value returned by sqlite3_total_changes() increases by
  # 1 following a no-op "merge=A,B", or by more than 1 if actual work is
  # performed.
  #
  do_test 7.0 {
    reset_db
    fts3_build_db_1 -module $mod 1000
  } {}
  
  do_execsql_test 7.1 {
    SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level
  } {
    0 {0 1 2 3 4 5 6 7} 
    1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} 
    2 {0 1 2}
  }
  do_test 7.2 {
    set x [db total_changes]
    execsql { INSERT INTO t1(t1) VALUES('merge=2,10') }
    expr { ([db total_changes] - $x)>1 }
  } {1}
  do_test 7.3 {
    set x [db total_changes]
    execsql { INSERT INTO t1(t1) VALUES('merge=200,10') }
    expr { ([db total_changes] - $x)>1 }
  } {1}
  do_test 7.4 {
    set x [db total_changes]
    execsql { INSERT INTO t1(t1) VALUES('merge=200,10') }
    expr { ([db total_changes] - $x)>1 }
  } {0}
  do_test 7.5 {
    set x [db total_changes]
    execsql { INSERT INTO t1(t1) VALUES('merge=200,10') }
    expr { ([db total_changes] - $x)>1 }
  } {0}

}

finish_test