Update fts3/4 so that the 'merge=X,0' command merges X pages from all segments of the first level in the fts index that contains 2 or more segments.

FossilOrigin-Name: cddf69dbc46f10ee7e87538dd850e086386b544c
This commit is contained in:
dan
2016-03-07 20:14:27 +00:00
parent 237b2b7111
commit 108b7953ed
5 changed files with 188 additions and 14 deletions
+9 -4
View File
@@ -333,7 +333,8 @@ static int fts3SqlStmt(
** of the oldest level in the db that contains at least ? segments. Or,
** if no level in the FTS index contains more than ? segments, the statement
** returns zero rows. */
/* 28 */ "SELECT level FROM %Q.'%q_segdir' GROUP BY level HAVING count(*)>=?"
/* 28 */ "SELECT level, count(*) AS cnt FROM %Q.'%q_segdir' "
" GROUP BY level HAVING cnt>=?"
" ORDER BY (level %% 1024) ASC LIMIT 1",
/* Estimate the upper limit on the number of leaf nodes in a new segment
@@ -4836,10 +4837,14 @@ int sqlite3Fts3Incrmerge(Fts3Table *p, int nMerge, int nMin){
** set nSeg to -1.
*/
rc = fts3SqlStmt(p, SQL_FIND_MERGE_LEVEL, &pFindLevel, 0);
sqlite3_bind_int(pFindLevel, 1, nMin);
sqlite3_bind_int(pFindLevel, 1, MAX(2, nMin));
if( sqlite3_step(pFindLevel)==SQLITE_ROW ){
iAbsLevel = sqlite3_column_int64(pFindLevel, 0);
nSeg = nMin;
if( nMin<2 ){
nSeg = sqlite3_column_int(pFindLevel, 1);
}else{
nSeg = nMin;
}
}else{
nSeg = -1;
}
@@ -4991,7 +4996,7 @@ static int fts3DoIncrmerge(
nMin = fts3Getint(&z);
}
if( z[0]!='\0' || nMin<2 ){
if( z[0]!='\0' || nMin<0 || nMin==1 ){
rc = SQLITE_ERROR;
}else{
rc = SQLITE_OK;