Hello,
with sqlite 3.6.23 with SQLITE_ENABLE_STAT2, I get
an "out of memory" error running the following simple SQL code:
CREATE TABLE dist_T (
d_row INTEGER PRIMARY KEY,
dist TEXT UNIQUE NOT NULL
);
INSERT INTO dist_T VALUES (NULL, '');
INSERT INTO dist_T VALUES (NULL, 'a');
INSERT INTO dist_T VALUES (NULL, 'b');
INSERT INTO dist_T VALUES (NULL, 'c');
INSERT INTO dist_T VALUES (NULL, 'd');
INSERT INTO dist_T VALUES (NULL, 'e');
INSERT INTO dist_T VALUES (NULL, 'f');
INSERT INTO dist_T VALUES (NULL, 'g');
INSERT INTO dist_T VALUES (NULL, 'h');
INSERT INTO dist_T VALUES (NULL, 'i');
ANALYZE;
This is always reproducable if dist_T contains 10 or more rows. With 0-9
rows, I don't see the problem. Also not if SQLITE_ENABLE_STAT2 is not set.
The problem happens when interpreting the results of "SELECT
idx,sampleno,sample FROM 'main'.sqlite_stat2".on line 66154 in sqlite3.c
(sqlite3AnalysisLoad()), apparently because
sqlite3_column_bytes() returned a size of 0 bytes for column 2 in line
66145:
66145 int n = sqlite3_column_bytes(pStmt, 2);
66146 if( n>24 ){
66147 n = 24;
66148 }
66149 pSample->nByte = (u8)n;
66150 pSample->u.z = sqlite3DbMallocRaw(dbMem, n);
66151 if( pSample->u.z ){
66152 memcpy(pSample->u.z, z, n);
66153 }else{
66154 db->mallocFailed = 1;
66155 break;
66156 }
I am including some gdb output. Note that pResultSet[2].n = 0.
(gdb) bt
#0 sqlite3AnalysisLoad (db=0x55af68, iDb=0) at sqlite3.c:66154
#1 0x00002af0c5884bd8 in sqlite3VdbeExec (p=0x569e38) at sqlite3.c:57585
#2 0x00002af0c587c02d in sqlite3Step (p=0x569e38) at sqlite3.c:51342
#3 0x00002af0c587c249 in sqlite3_step (pStmt=0x569e38) at sqlite3.c:51402
#4 0x0000000000403eea in shell_exec (db=0x55af68, zSql=0x55aee0 "ANALYZE;",
xCallback=0x402ba1 <shell_callback>, pArg=0x7fffe5377850,
pzErrMsg=0x7fffe5375aa8) at shell.c:1012
#5 0x0000000000408019 in process_input (p=0x7fffe5377850, in=0x55ab50)
at shell.c:2236
#6 0x0000000000406d1a in do_meta_command (zLine=0x5537d0 ".read",
p=0x7fffe5377850) at shell.c:1860
#7 0x0000000000407deb in process_input (p=0x7fffe5377850, in=0x0) at
shell.c:2195
#8 0x0000000000409183 in main (argc=1, argv=0x7fffe5378eb8) at shell.c:2616
(gdb) p *pIdx
$4 = {zName = 0x56c23d "sqlite_autoindex_dist_T_1", nColumn = 1,
aiColumn = 0x56c230, aiRowEst = 0x56c234,
pTable = 0x56b328, tnum = 3, onError = 99 'c', autoIndex = 1 '\001',
zColAff = 0x56bce8 "ab", pNext = 0x0,
pSchema = 0x55bb88, aSortOrder = 0x56c23c "", azColl = 0x56c228,
aSample = 0x570058}
(gdb) p *((Vdbe*) pStmt)
$5 = {db = 0x55af68, pPrev = 0x0, pNext = 0x569e38, nOp = 15, nOpAlloc =
42, aOp = 0x570d88, nLabel = 4,
nLabelAlloc = 26, aLabel = 0x0, apArg = 0x570fd0, aColName =
0x571188, pResultSet = 0x570ef0, nResColumn = 3,
nCursor = 1, apCsr = 0x570fd0, errorAction = 2 '\002', okVar = 0
'\0', nVar = 0, aVar = 0x570fd0,
azVar = 0x570fd0, magic = 3186757027, nMem = 4, aMem = 0x570eb8,
cacheCtr = 3, pc = 8, rc = 0, zErrMsg = 0x0,
explain = 0 '\0', changeCntOn = 0 '\0', expired = 0 '\0', runOnlyOnce
= 0 '\0', minWriteFileFormat = 255 '377',
inVtabMethod = 0 '\0', usesStmtJournal = 0 '\0', readOnly = 1 '\001',
isPrepareV2 = 0 '\0', nChange = 0,
btreeMask = 1, startTime = 0, aMutex = {nMutex = 0, aBtree = {0x0
<repeats 11 times>}}, aCounter = {0, 0},
zSql = 0x5685b0 "SELECT idx,sampleno,sample FROM
'main'.sqlite_stat2", pFree = 0x0, nFkConstraint = 0,
nStmtDefCons = 0, iStatement = 0, pFrame = 0x0, nFrame = 0, expmask = 0}
(gdb) p ((Vdbe*) pStmt)->pResultSet[0]
$8 = {u = {i = 0, nZero = 0, pDef = 0x0, pRowSet = 0x0, pFrame = 0x0}, r
= 0, db = 0x55af68,
z = 0x568fd8 "sqlite_autoindex_dist_T_1", n = 25, flags = 514, type =
3 '\003', enc = 1 '\001', xDel = 0,
zMalloc = 0x568fd8 "sqlite_autoindex_dist_T_1"}
(gdb) p ((Vdbe*) pStmt)->pResultSet[1]
$9 = {u = {i = 0, nZero = 0, pDef = 0x0, pRowSet = 0x0, pFrame = 0x0}, r
= 0, db = 0x55af68, z = 0x568208 "0",
n = 1, flags = 514, type = 3 '\003', enc = 1 '\001', xDel = 0,
zMalloc = 0x568208 "0"}
(gdb) p ((Vdbe*) pStmt)->pResultSet[2]
$10 = {u = {i = 0, nZero = 0, pDef = 0x0, pRowSet = 0x0, pFrame = 0x0},
r = 0, db = 0x55af68, z = 0x568bc8 "",
n = 0, flags = 514, type = 3 '\003', enc = 1 '\001', xDel = 0,
zMalloc = 0x568bc8 ""}
Regards
Martin
--
Dr. Martin Wilck
PRIMERGY System Software Engineer
x86 Server Engineering
Fujitsu Technology Solutions GmbH
Heinz-Nixdorf-Ring 1
33106 Paderborn, Germany
Phone: ++49 5251 525 2796
Fax: ++49 5251 525 2820
Email: [email protected]
Internet: http://ts.fujitsu.com
Company Details: http://de.ts.fujitsu.com/imprint.html
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users