Skip to content
Snippets Groups Projects
  1. Jan 24, 2018
    • Nikita Pettik's avatar
      sql: add mechanism to emulate ROWID · 257cfeb2
      Nikita Pettik authored
      It is worth mentioning, that there are two types of ephemeral tables:
      one holds rows as they are inserted (all rows turn out to be distinct);
      another adds ROWID column in order to hold equal rows.  Inasmuch as
      original ROWID mechanism is to be removed, the purpose of this patch is
      to emulate ROWID behavior for ephemeral tables.
      
       - Substituted all ephemeral table opcodes which don't rely on SQLite's
         ROWID with Tarantool ones.
       - Implemeted opcode OP_NextIdEphemeral to emulate behavior of ROWID
         feature.  In current implemetation ROWID is not hidden PK index, but
         just another one column to keep in table equal tuples.
       - Substituted old ephemeral tables with ROWID for INSERT INTO ...
         SELECT ... FROM statement. It utilizes ephemeral tables as
         intermediate holder for data from SELECT
         (before it is inserted to table).
      
      Part of #2680
      257cfeb2
    • Nikita Pettik's avatar
      sql: complete API for ephemeral tables · 66169c92
      Nikita Pettik authored
       - Completed implementing tarantoolSqlite3Ephemeral* API.  Added
         functions: Last, Next, Previous, Delete, Unpack.
       - Added support of ephemeral tables for IN expression.
       - Added support of ephemeral tables for sub-select queries.
       - Fixed tests, which rely on the name of ephemeral creation opcode.
      
      Part of #2680
      66169c92
    • Nikita Pettik's avatar
      sql: introduce Tarantool's ephemeral tables · c741896d
      Nikita Pettik authored
       - Added intermediate functions between SQL and Tarantool,
         tarantoolSqlite3Ephemeral* in order to create and use Tarantool's
         ephemeral tables. Also, for this reason added BTCF_TEphemeral flag to
         BtCursor instead of BTCF_TaCursor to call appropriate functions.
       - Added struct space* to SQL cursor, which allows to delete ephemeral
         tables.  (since ephemeral tables don't have space_id and it is
         impossible to find them by traditional space_id lookup). Moreover, it
         enables us to avoid using box API inasmuch as we can directly call
         space_execute_* functions having struct space*.
       - As the first stage of implemenation, ephemeral tables were
         successfully replaced for DELETE FROM ... WHERE statement. It utilized
         ephemeral space as intermediate holder where all tuples to be removed
         are placed before actual deletion.
      
      Part of #2680
      c741896d
    • Nikita Pettik's avatar
      Add replace/delete functions for ephemeral spaces · 9a9d2786
      Nikita Pettik authored
      Ephemeral tables shouldn't be involved in any transaction routine,
      since they are used only for internal needs. Moreover, ephemeral spaces
      can be created and destroyed within one transaction, which may lead to
      incorrect behaviour. Thus, ephemeral replace and delete don't take txn
      as an argument.
      
      Furthermore, delete operation should work on tuples with nulls in primary key.
      As a rule, it is considered to be bad practice, due to ambiguity when
      deleting tuple from space with several tuples containing nulls in PK.
      On the other hand, ephemeral spaces are used only for internal needs,
      so if it is guaranteed that no such situation occur, it is OK to allow
      insertion nulls in PK. Hence, function which implements deletion on ephemeral
      tables, doesn't check tuple on null fields.
      
      Currently, supported only by memtx engine.
      9a9d2786
    • Nikita Pettik's avatar
      Rework memtx replace function · 880712c9
      Nikita Pettik authored
      By now, replace function takes new tuple and old tuple as arguments, instead
      of single txn_stmt. It has been done in order to avoid abusing txn_stmt:
      the only usage was extracting tuples from it.
      As a result, this function can be used by ephemeral tables
      without any patching.
      880712c9
    • Vladimir Davydov's avatar
      Introduce ephemeral spaces · d8593931
      Vladimir Davydov authored
      Ephemeral spaces are invisible via public API and they are not
      persistent. They are needed solely to do some transient calculations.
      
      To create an ephemeral space, use space_new_ephemeral() function,
      which takes a space definition and a list of index definitions as
      arguments. A space created with this function may be accessed and
      modified via internal API (space_execute_replace(), index_get(),
      etc).
      
      Currently, only the memtx engine supports ephemeral spaces.
      
      Closes #2776
      d8593931
    • Kirill Yukhin's avatar
      sql: add parser generated source · 41876f70
      Kirill Yukhin authored
      Add forgotten box/sql/parse.c source which is being
      regenerated in -DSQL_MAINTAINER_MODE=1 only.
      41876f70
    • Kirill Yukhin's avatar
      sql: Disable asserts for release builds · 8d7bfe97
      Kirill Yukhin authored
      Macro SQLITE_DEBUG was set unconditionally, so both release build
      modes had debugging enabled, including all asserts() and TESTCASE().
      Move this macro definition under check if mode is Debug and fix all
      warning which arised after disabling asserts().
      Most of them are unused variables.
      8d7bfe97
    • Kirill Yukhin's avatar
      sql: Enable asserts for box/sql.c · 7a8de281
      Kirill Yukhin authored
      Since asserts were always disbled in src/box/sql.c, number
      of issues were hidden. This patch enables asserts for mentioned
      file by disabling set of NDEBUG in box/src/sqliteInt.h.
      Also this patch fixes incorrect assertions about strlen() and
      assertion that fieldno should always be less than format->field_count.
      This assert is not always hold, e.g. for _schema space where max_id
      is stored behind formatted fields.
      
      Closes #3057
      7a8de281
    • Kirill Yukhin's avatar
      sql: add regenerated pase file. · 67a9422e
      Kirill Yukhin authored
      Add forgotten in previous commit regenerated box/sql/parse.c
      67a9422e
  2. Jan 23, 2018
    • Kirill Yukhin's avatar
      sql: Ban ALTER TABLE ADD COLUMN · 5163872d
      Kirill Yukhin authored
      Currently, only ALTER TABLE RENAME is supported in SQL. Ban
      ALTER TABLE ADD COLUMN in the grammar until it is supported.
      Corresponding issue submitted: #3075
      
      Closes #2607
      5163872d
  3. Jan 18, 2018
    • Kirill Yukhin's avatar
      sql: Fix build for FreeBSD · e2c08028
      Kirill Yukhin authored
      There're 3 places where FreeBSD specific routines
      contained (for compatibility) unused parameters.
      Mark them w/ unused attribute.
      
      Closes #3037
      e2c08028
  4. Jan 15, 2018
    • Alexander Turenko's avatar
      sql: remove SQLite shared cache mode · ff0b2857
      Alexander Turenko authored
      SQLITE_ENABLE_UNLOCK_NOTIFY assumed to be always disabled.
      SQLITE_OMIT_SHARED_CACHE assumed to be always enabled.
      
      Deleted files
      -------------
      
      src/box/sql/notify.c
      src/box/sql/btmutex.c
      
      Deleted non-static functions
      ----------------------------
      
      // btmutex.c
      sqlite3BtreeEnter()
      sqlite3BtreeLeave()
      sqlite3BtreeHoldsMutex()
      sqlite3BtreeEnterAll()
      sqlite3BtreeLeaveAll()
      sqlite3BtreeHoldsAllMutexes()
      sqlite3SchemaMutexHeld()
      sqlite3BtreeEnterCursor()
      sqlite3BtreeLeaveCursor()
      
      // btree.c
      sqlite3BtreeLockTable()
      sqlite3BtreeSharable()
      sqlite3BtreeConnectionCount()
      
      // notify.c
      sqlite3_unlock_notify()
      sqlite3ConnectionBlocked()
      sqlite3ConnectionUnlocked()
      sqlite3ConnectionClosed()
      
      // vdbeaux.c
      sqlite3VdbeEnter()
      sqlite3VdbeLeave()
      
      Deleted structure fields
      ------------------------
      
      // btreeInt.h
      struct Btree.wantToLock
      struct Btree.lock
      struct BtShared.nRef
      struct BtShared.pNext
      struct BtShared.pLock
      struct BtShared.pWriter
      
      // sqliteInt.h
      struct sqlite3.pBlockingConnection
      struct sqlite3.pUnlockConnection
      struct sqlite3.pUnlockArg
      struct sqlite3.xUnlockNotify
      struct sqlite3.pNextBlocked
      
      Deleted asserts
      ---------------
      
      // common
      assert(sqlite3BtreeHoldsAllMutexes(...))
      assert(sqlite3SchemaMutexHeld(...))
      assert(sqlite3BtreeHoldsMutex(...))
      
      // btree.c
      assert(... || sqlite3BtreeConnectionCount(...) > 0)
      assert(p->wantToLock == 0 && p->locked == 0)
      assert(hasSharedCacheTableLock(...))
      assert(... || !hasReadConflicts(...))
      Unverified
      ff0b2857
  5. Jan 05, 2018
    • khatskevich's avatar
      sql: add test on savepoints · e5b5dbc1
      khatskevich authored
      Part of #2931
      e5b5dbc1
    • khatskevich's avatar
      sql: add do_cahchsql_set_test to sqltester · b30a0b93
      khatskevich authored
        There are some cases where a number of similar tests should be performed.
      In this scenario, we had to write a lot of redundant symbols.
      
        The new method allows one to write the minimal number of code necessary for
      tests.
      b30a0b93
    • khatskevich's avatar
      eb5171ec
    • AKhatskevich's avatar
      sql: recover SQL savepoints & abort · c3d5944d
      AKhatskevich authored
      This comit introduces a number of changes:
      
      1. move a transaction state to fiber local struct
      
        This is important because the `sqlite3` is a shared structure and it was
      used to store data related to the transaction. However it was working because
      yield is called only on commit and it garanteed unique access. (With possible
      effects on ddl.)
      
      NOTE: `nDeferredCons` and `nDeferredImmCons` are stored in vdbe during vdbe
      execution and moved to sql_txn when it needs to be saved until execution of the
      next vdbe in the same transaction.
      
      2. support savepoints
      
      2.1. support abort (anonymous savepoints)
      
        Abort mechanism was simplified. Instead of storing track of all
      savepoints without name, this commit introduces `anonymous_savepoint`.
        `anonymous_savepoint` is a structure which is stored in Vdbe and represents
      the state of database on the beginning of the current statement. Tarantool
      disallow multistatement, so a vdbe can have one statement max. That is why
      having one savepoint is enough to perform abort.
      
      2.2. named savepoints
      
      Key points:
        - It uses Tarantool's savepoints
        - It allocates savepoints on the "region" (they are destroyed automatically)
        - There are some crutches around ddl (ddl should not be placed into a
      transaction)
      
      Closes #2989 #2931 #2964
      c3d5944d
  6. Dec 26, 2017
  7. Dec 20, 2017
  8. Dec 18, 2017
    • Kirill Yukhin's avatar
      sql: Remove dead opcodes, including table locking · f92bc1e6
      Kirill Yukhin authored
      Removed OP_ParseSchema, OP_TableLock.
      All other dead code connected to locking of open tables (for both
      reading and writing) removed as well.
      Remove auth.c file, it is not used anymore.
      f92bc1e6
    • Kirill Yukhin's avatar
      sql: emove idb operand from VM opcodes · daa00ab8
      Kirill Yukhin authored
      Few opcodes like OpenRead/OpenWrite exepcted 3rd argument to be DB
      descriptor. Now there's a single DB backend and there's no need
      for any descriptors. Remove from VDBE, fix code generator, update
      opcode descriptions.
      
      Closes #2855
      daa00ab8
  9. Dec 15, 2017
  10. Dec 08, 2017
  11. Dec 06, 2017
    • Nikita Pettik's avatar
      sql: fail of DROP TABLE doesn't lead to truncate · 41ca410c
      Nikita Pettik authored
      Deletion of rows from table (which is part of DROP TABLE procedure) is
      wrapped in transaction now. If any Foreign Key violations occur, then
      rollback transaction and halt execution of statement. Otherwise, commit
      changes and continue DROP TABLE routine. This logic is implemented by
      OP_FkCheckCommit opcode.
      Added tests for this case.
      
      Closes #2953
      41ca410c
  12. Dec 05, 2017
    • khatskevich's avatar
      remove sqlite's likely/SWAP completely · 2d38c663
      khatskevich authored
        There were analogies of those functions in Tarantool. This commit makes
      SQL reuse them.
        All crutches (undef) are deleted.
      2d38c663
    • Nikita Pettik's avatar
      sql: enable alter rename table · 9faea8e1
      Nikita Pettik authored
      Added new opcode OP_RenameTable, which implements
      SQL statment: ALTER TABLE old_name RENAME TO new_name;
      The main idea is to replace corresponding tuple in _space.
      New tuple will contain new name and new SQL statement, which
      creates this table. If it is parent table for foreign key,
      update SQL statement of child table. Then, remove old name
      from hash table and by calling callback function from VDBE,
      update database schema with new table name. After all,
      in the same way update triggers' statements in _trigger table,
      if any exist.
      
      Closes #2204
      9faea8e1
  13. Nov 30, 2017
Loading