sql: assertion fault on select after analyze
Binary search in whereKeyStats function that uses routine sqlite3VdbeRecordCompareMsgpack returned invalid result, because it made wrong assumption about the number of coinciding index columns based on _sql_stat4. But all collected index statistics were wrong. The analyzeOneTable routine used to call sqlite3GetTempRange and sqlite3ReleaseTempRange functions inside of cycle intensively changes Parser->nMem value. Thanks this pattern routine sqlite3ReleaseTempRange could push nMem variable onto aTempReg queue. As Parser->nMem could be bigger next time, this variable may be used twice: [74, 'Column', 4, 1, 11, '', '00', 'r[11]='] [75, 'Column', 4, 2, 12, '', '00', 'r[12]='] |-> [76, 'Column', 4, 3, 13, '', '00', 'r[13]='] [77, 'Column', 4, 4, 14, '', '00', 'r[14]='] !rewrite [78, 'Column', 4, 0, 13, '', '00', 'r[13]=ID'] [79, 'MakeRecord', 13, 1, 6, '', '00', 'r[6]=mkrec(r[13])'] Thus all assumptions about data below should be invalid and some artifacts could exhibit. Example: \set language sql CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, a, b, c, f, d, e); CREATE INDEX i1 ON t1(a, b, c, f, d); \set language lua for i = 0, 100 do box.sql.execute(string.format("INSERT INTO t1 VALUES(null, 'x', 'y', 'z', 'a', %s, %s);", i, math.floor(i / 2))) end \set language sql SELECT * FROM "_sql_stat4"; --- ['T1', 'I1', '101 101 1 1 1', '0 0 44 44 44', '0 0 44 44 44', ['x', 'y', 'z', 'a', 44]] --- Expected: --- ['T1', 'I1', '101 101 101 101 1', '0 0 0 0 44', '0 0 0 0 44', ['x', 'y', 'z', 'a', 44]] --- Resolves #2847.
Showing
- src/box/sql/analyze.c 4 additions, 2 deletionssrc/box/sql/analyze.c
- test/sql-tap/analyze1.test.lua 58 additions, 1 deletiontest/sql-tap/analyze1.test.lua
- test/sql-tap/analyze4.test.lua 1 addition, 1 deletiontest/sql-tap/analyze4.test.lua
- test/sql-tap/analyze9.test.lua 8 additions, 8 deletionstest/sql-tap/analyze9.test.lua
Loading
Please register or sign in to comment