Visitar URL original
upstream fix for problem where optimizing an fts5 table can causes it… · sqlcipher/sqlcipher@1341249 · GitHub
Skip to content

Commit 1341249

Browse files
committed
upstream fix for problem where optimizing an fts5 table can causes it to become unreadable (35bed981,459d986d38fc)
1 parent 8763afa commit 1341249

2 files changed

Lines changed: 68 additions & 2 deletions

File tree

‎ext/fts5/fts5_index.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
# error "FTS5_MAX_PREFIX_INDEXES is too large"
5555
#endif
5656

57+
#define FTS5_MAX_LEVEL 64
58+
5759
/*
5860
** Details:
5961
**
@@ -4766,10 +4768,10 @@ static Fts5Structure *fts5IndexOptimizeStruct(
47664768
if( pNew ){
47674769
Fts5StructureLevel *pLvl;
47684770
nByte = nSeg * sizeof(Fts5StructureSegment);
4769-
pNew->nLevel = pStruct->nLevel+1;
4771+
pNew->nLevel = MIN(pStruct->nLevel+1, FTS5_MAX_LEVEL);
47704772
pNew->nRef = 1;
47714773
pNew->nWriteCounter = pStruct->nWriteCounter;
4772-
pLvl = &pNew->aLevel[pStruct->nLevel];
4774+
pLvl = &pNew->aLevel[pNew->nLevel-1];
47734775
pLvl->aSeg = (Fts5StructureSegment*)sqlite3Fts5MallocZero(&p->rc, nByte);
47744776
if( pLvl->aSeg ){
47754777
int iLvl, iSeg;

‎ext/fts5/test/fts5optimize2.test‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# 2014 Dec 20
2+
#
3+
# The author disclaims copyright to this source code. In place of
4+
# a legal notice, here is a blessing:
5+
#
6+
# May you do good and not evil.
7+
# May you find forgiveness for yourself and forgive others.
8+
# May you share freely, never taking more than you give.
9+
#
10+
#***********************************************************************
11+
#
12+
# TESTRUNNER: slow
13+
#
14+
15+
source [file join [file dirname [info script]] fts5_common.tcl]
16+
set testprefix fts5optimize2
17+
18+
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
19+
ifcapable !fts5 {
20+
finish_test
21+
return
22+
}
23+
24+
set nLoop 2500
25+
26+
do_execsql_test 1.0 {
27+
CREATE VIRTUAL TABLE t1 USING fts5(x);
28+
INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
29+
}
30+
31+
do_test 1.1 {
32+
for {set ii 0} {$ii < $nLoop} {incr ii} {
33+
execsql {
34+
INSERT INTO t1 VALUES('abc def ghi');
35+
INSERT INTO t1 VALUES('jkl mno pqr');
36+
INSERT INTO t1(t1) VALUES('optimize');
37+
}
38+
}
39+
} {}
40+
41+
do_execsql_test 1.2 {
42+
SELECT count(*) FROM t1('mno')
43+
} $nLoop
44+
45+
do_execsql_test 2.0 {
46+
CREATE VIRTUAL TABLE t2 USING fts5(x);
47+
INSERT INTO t2(t2, rank) VALUES('pgsz', 32);
48+
}
49+
50+
do_test 2.1 {
51+
for {set ii 0} {$ii < $nLoop} {incr ii} {
52+
execsql {
53+
INSERT INTO t2 VALUES('abc def ghi');
54+
INSERT INTO t2 VALUES('jkl mno pqr');
55+
INSERT INTO t2(t2, rank) VALUES('merge', -1);
56+
}
57+
}
58+
} {}
59+
60+
do_execsql_test 2.2 {
61+
SELECT count(*) FROM t2('mno')
62+
} $nLoop
63+
64+
finish_test

0 commit comments

Comments
 (0)