lmdb / sqlightning Goto Github PK
View Code? Open in Web Editor NEWSQLite3 ported to use LMDB instead of its original Btree code. See https://github.com/LumoSQL/LumoSQL for maintained fork.
SQLite3 ported to use LMDB instead of its original Btree code. See https://github.com/LumoSQL/LumoSQL for maintained fork.
CREATE TABLE IF NOT EXISTS T1 (B TEXT, C TEXT);
CREATE INDEX IF NOT EXISTS T1_idx on T1 (C,B);
INSERT INTO T1 (B, C) VALUES ('A', 'tms_doc_cfg');
INSERT INTO T1 (B, C) VALUES (RANDOMBLOB(17000), 'tms_doc_cfg_element_trans_xslt');
SELECT * FROM T1 WHERE C = "tms_doc_cfg";
returns nothing.
SELECT C,C="tms_doc_cfg" FROM T1 WHERE C > "tms_doc_cfg";
returns 1 in the 2nd column on 'A' .. The index clearly fails..
If the key length is reduced, the select
CREATE TABLE IF NOT EXISTS T1 (B TEXT, C TEXT);
CREATE INDEX IF NOT EXISTS T1_idx on T1 (C,B);
INSERT INTO T1 (B, C) VALUES ('A', 'tms_doc_cfg');
INSERT INTO T1 (B, C) VALUES (RANDOMBLOB(1000), 'tms_doc_cfg_element_trans_xslt');
SELECT * FROM T1 WHERE C = "tms_doc_cfg";
correctly returns 'A', 'tms_doc_cfg'.
Any plans to support SQLite updated version (3.11+) in the near future?
In some cases, as soon as a selected string is longer than 72 characters, only 64 characters are returned correctly.
Example 1:
CREATE TABLE A (U TEXT);
CREATE INDEX I ON A (U);
INSERT INTO A VALUES('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFIJKLM');
SELECT * FROM A;
-- returns:
-- ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB,
-- ��;�A�
Example 2:
CREATE TABLE ABCDEFG (HIJKLMN TEXT, OPQRSTU INT NOT NULL, VWXYZABCD TEXT);
SELECT type,name,sql,tbl_name FROM sqlite_master
UNION SELECT type,name,sql,tbl_name FROM sqlite_temp_master;
-- returns:
-- table|ABCDEFG|CREATE TABLE ABCDEFG (HIJKLMN TEXT, OPQRSTU INT NOT NULL, VWXYZAT\�:|ABCDEFG
-- Fun fact: Using UNION ALL instead of UNION works.
SELECT type,name,sql,tbl_name FROM sqlite_master
UNION ALL SELECT type,name,sql,tbl_name FROM sqlite_temp_master;
-- returns:
-- table|ABCDEFG|CREATE TABLE ABCDEFG (HIJKLMN TEXT, OPQRSTU INT NOT NULL, VWXYZABCD TEXT)|ABCDEFG
The following SQL results in a segfault from sqlightning. The last SELECT from TableB should return an empty result set. Instead, it crashes.
CREATE TABLE TableA (A TEXT, B TEXT, C TEXT);
CREATE TABLE TableB (A TEXT, B TEXT, C TEXT, PRIMARY KEY(A, B));
CREATE INDEX i on TableB (A,B,C);
INSERT INTO TableA (A, B, C) VALUES ('1', '2', '3');
INSERT INTO TableB (A, B, C) VALUES ('1', '2', '3___');
SELECT * FROM TableB WHERE A = '0'; -- works, searched key is less than the one in the table
SELECT * FROM TableB WHERE A = '1'; -- works, searched key equals the one in the table
SELECT * FROM TableB WHERE A = '2'; -- crashes, searched key is greater than the one in the table
Any of these changes to the SQL script make the crash disappear:
Compiling with debugging enabled also makes the assert seen in the code snippet below fail (line ~5618):
static int mdb_cursor_next(MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op)
{
MDB_page *mp;
MDB_node *leaf;
int rc;
if (mc->mc_flags & C_EOF) {
return MDB_NOTFOUND;
}
// this assert fails
mdb_cassert(mc, mc->mc_flags & C_INITIALIZED);
mp = mc->mc_pg[mc->mc_top];
if (mc->mc_db->md_flags & MDB_DUPSORT) {
leaf = NODEPTR(mp, mc->mc_ki[mc->mc_top]);
if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
if (op == MDB_NEXT || op == MDB_NEXT_DUP) {
// as a quickfix we inserted this check for the assertion, preventing the crash
if (!(mc->mc_xcursor->mx_cursor.mc_flags & C_INITIALIZED))
return MDB_NOTFOUND;
rc = mdb_cursor_next(&mc->mc_xcursor->mx_cursor, data, NULL, MDB_NEXT);
if (op != MDB_NEXT || rc != MDB_NOTFOUND) {
if (rc == MDB_SUCCESS)
MDB_GET_KEY(leaf, key);
return rc;
}
}
} else {
mc->mc_xcursor->mx_cursor.mc_flags &= ~(C_INITIALIZED|C_EOF);
if (op == MDB_NEXT_DUP)
return MDB_NOTFOUND;
}
}
…
}
See the code above for our quickfix to prevent the crash. Clearly this only cures the symptom, not the cause.
The following SQL results in a SQLITE_MISUSE (21) error in the last line.
CREATE TABLE A (X TEXT, Y TEXT);
BEGIN TRANSACTION;
--UPDATE A SET Y=Y WHERE X=1;
SELECT X FROM A;
INSERT INTO A (X, Y) VALUES ('U', 'V');
COMMIT TRANSACTION;
SELECT * FROM A;
>>>Error: near line 9: library routine called out of sequence
Any of the following changes makes the error disappear:
sqlite3BtreeBeginTrans
set wrflag = 1;
permanently. Disadvantage: PRAGMA max_page_count
doesnt work anymore, because the db is write-locked..So, any write in a transaction that has started with a read-only query seems to result in an error in SELECTs after that transaction.
This leads us to believe that the error lies in the way Sqlightning manages deferred transactions. A transaction that has started with a read-query appears to stay read-only, and writing within that transaction breaks something that makes all SELECTs after that fail.
A distilled example is:
CREATE TABLE A (id);
INSERT INTO A (id) VALUES ('A');
SELECT id FROM A WHERE id NOT IN ('A', 'B');
>>> returns 'A', which is not correct.
SELECT id FROM A WHERE id NOT IN ('A', 'A');
>>> (2) statement aborts at 15: [SELECT id FROM A WHERE id NOT IN ('A', 'A');]
But in our application the following queries also fail, depending on the given parameters:
SELECT keyID, valueID FROM Attributes WHERE entryID = 'JM87517';
11: database corruption at line 48036 of [118a3b3569];
11: statement aborts at 9:
[SELECT keyID, valueID FROM Attributes WHERE entryID = :entryID] ;
SELECT DISTINCT l1_e_0.id, min(levenshtein('biol', l2_e_2.caption)) AS dst
FROM InfixArray l2_inf_3 CROSS JOIN Entries l2_e_2 CROSS JOIN Entries l1_e_0
CROSS JOIN Terms l1_term_1
WHERE l1_e_0.typeID = 'thc' AND l1_term_1.termID = l2_e_2.id
AND l1_e_0.id = l1_term_1.entryID
AND l2_inf_3.infix = 'bar' AND l2_inf_3.typeID = 'tht' AND l2_e_2.id = l2_inf_3.entryID
GROUP BY l1_e_0.id ORDER BY dst ASC;
11: database corruption at line 48036 of [118a3b3569];
11: statement aborts at 24: [SELECT DISTINCT l1_e_0.id, min(leven .. ]
For some values they fail, for some they return the right values. SQLite without LMDB returns the correct results.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.