Giter VIP home page Giter VIP logo

sqlightning's People

Contributors

hyc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sqlightning's Issues

indices get corrupted if keys are too big

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'.

selecting long strings fails

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

segfaults on certain selects involving indices

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:

  • Remove TableA and its entry
  • Remove the index i on TableB
  • Remove TableB's PRIMARY KEY(A, B) constraint
  • Shorten the third value '3___' in TableB by at least one character. Values longer than three characters in any column seem to result in a crash.
  • Use a search key less than or equal to '1'

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.

GDB-Log of the crash

Sqlite misuse error (21) using transactions

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:

  • Remove the explicit transaction statements
  • Uncomment the UPDATE line. Actually, any write-query at the beginning of the transaction works here
  • Change BEGIN TRANSACTION to BEGIN IMMEDIATE TRANSACTION
  • in btree.c 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.

some select statements abort execution or return wrong values

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.