Skip to content
Snippets Groups Projects
  1. Aug 02, 2019
    • Nikita Pettik's avatar
      sql: make default type of NULL be boolean · ffccbbd8
      Nikita Pettik authored
      It was decided that null value in SQL by default should be of type
      boolean. Justification of such change is that according to ANSI boolean
      type in fact has three different values: true, false and unknown. The
      latter is basically an alias to null value.
      ffccbbd8
    • Nikita Pettik's avatar
      sql: make default constraint names be consistent · 45f61e0d
      Nikita Pettik authored
      If during creation of constraint its name is not specified, then it is
      generated automatically. Occasionally, default names for each type of
      constraint turn out to be different. This patch makes them follow the
      same pattern: "shortcut"_unnamed_"table_name"_"ordinal_numb". For
      instance: fk_unnamed_T1_1 or ck_unnamed_T1_3 etc
      45f61e0d
    • Nikita Pettik's avatar
      sql: don't mangle name of unique constraint · 1f783f26
      Nikita Pettik authored
      If UNIQUE constraint is specified in CREATE TABLE statement and it has
      given name, one is mangled with pattern "unique_%s_%d", where %s is
      original name of constraint and %d - current iid. For instance:
      
      CREATE TABLE t (id INT PRIMARY KEY, a INT CONSTRAINT i1 UNIQUE);
      
      This statement results in secondary index creation with name
      "unique_I1_1". Justification for mangling is that constraint namespace
      should be independent from index namespace. However, ALTER TABLE ADD
      CONSTRAINT UNIQUE which is alias to CREATE INDEX doesn't mangle name.
      What is more, users may wonder why name of index is different from
      name of created constraint. Hence, it has been decided to remove this
      mangling and create index exactly with specified constraint's name.
      1f783f26
    • Nikita Pettik's avatar
      sql: remove OP_IntCopy opcode · 931d58a3
      Nikita Pettik authored
      Its purpose is to copy integer value from one memory cell to another.
      In other words, it is particular case of OP_SCopy instruction. Since it
      is used only during creation of AUTOINCREMENT property, it seems to be
      reasonable to replace it with a bit general OP_SCopy and erase
      OP_IntCopy at all reducing size of SQL codebase.
      931d58a3
    • Nikita Pettik's avatar
      sql: remove OP_SoftNull opcode · ed8891e3
      Nikita Pettik authored
      It's not used anymore and can be removed to reduce size of codebase.
      ed8891e3
    • Mergen Imeev's avatar
      sql: return lookaside system · 2386ce6c
      Mergen Imeev authored
      After the removal of the LOOKASIDE system, it was found that the
      performance dropped. To restore performance, this patch partially
      returns the LOOKASIDE system in almost the same form as it was
      before the patch 4326ca7d.
      
      Closes #4319
      2386ce6c
    • Mergen Imeev's avatar
      sql: rework error handling in box.execute() · 98e29c0f
      Mergen Imeev authored
      In accordance with the Lua coding style in Tarantool, all errors
      returned in Lua should be returned using 'return nil, error'.
      However, box.execute() throws an exception in case of an error.
      This patch causes box.execute() to return an error, as described
      in the coding style.
      
      Closes #4390
      98e29c0f
    • Mergen Imeev's avatar
      lua: new function luaT_push_nil_and_error() · 7b357950
      Mergen Imeev authored
      Currently, if we have to return errors using the format
      'return nil, error', we must do it manually. Since this error
      return method is described in our Lua coding style, it makes sense
      to create a function that will return an error in this format.
      This patch creates mentioned function.
      
      Needed for #4390
      7b357950
  2. Aug 01, 2019
    • Nikita Pettik's avatar
      sql: remove sql_strlike_*() functions as unused · 6770d339
      Nikita Pettik authored
      Follow-up #3589
      6770d339
    • Roman Khabibov's avatar
      sql: make LIKE predicate dependent on collation · 37cd7a37
      Roman Khabibov authored
      According to ANSI, LIKE should match characters taking into
      account passed collation.
      
      ISO/IEC JTC 1/SC 32 2011, Part 2: Foundation, 8.5
      
      Closes #3589
      
      @TarantoolBot document
      Title: LIKE depends on collations
      
      Now <LIKE> operator depends on arguments' collations. Collation to be
      used is determined by common rules: if explicit collation or collations
      (and in case they are compatible) is specified, then it is used to
      process pattern matching; otherwise implicit collation of arguments are
      checked to be compatible and (in case they are) resulting collation is
      used. Moreover, it means that PRAGMA "case_sensitive_like" has been
      removed.
      37cd7a37
    • Roman Khabibov's avatar
      sql: remove "PRAGMA case_sensitive_like" · 85a24ac4
      Roman Khabibov authored
      According to ANSI, LIKE should match characters taking into account
      collations of arguments, and this is done in the next patch. In turn,
      this patch makes LIKE be always case sensitive and erases
      case_sensitive_like pragma. Alongside with it, code related to no-case
      LIKE optimization is removed as well.
      
      Part of #3589
      85a24ac4
    • Nikita Pettik's avatar
      sql: introduce VARBINARY column type · b4e61e1b
      Nikita Pettik authored
      Current patch introduces new type available in SQL:
       - VARBINARY now is reserved keyword;
       - Allow to specify VARBINARY column and CAST type;
       - All literals which start from 'x' are assumed to be of this type;
       - There's no available implicit or explicit conversions between
         VARBINARY and other types;
       - Under the hood all values of VARBINARY type are stored as MP_BIN
         msgpack format type.
      
      Closes #4206
      b4e61e1b
    • Nikita Pettik's avatar
      sql: fix default trim octet for binary strings · 406330e0
      Nikita Pettik authored
      According to ANSI specification, if TRIM function accepts binary string
      and trim octet is not specified, then it is implicitly set to X'00'.
      Before this patch trim octet was set to ' ' both for string and binary
      string arguments. In turn, ' ' is equal to X'20' in hex representation.
      Hence, TRIM function cut wrong characters:
      
      TRIM(X'004420') -> X‘0044'
      
      This patch sets default trim octet to X'00' for binary string arguments.
      
      Part of #4206
      406330e0
    • Nikita Pettik's avatar
      sql: make built-ins raise errors for varbin args · 04cc640c
      Nikita Pettik authored
      Since values of type 'varbinary' can't be cast to any other type, let's
      patch built-in functions which are not assumed to accept arguments of
      this type to raise an error in case argument turn out to be of type
      varbinary.
      
      Part of #4206
      04cc640c
    • Nikita Pettik's avatar
      sql: use 'varbinary' as a name of type instead of 'blob' · 78e59b26
      Nikita Pettik authored
      We are going to introduce new column type 'VARBINARY', which allows to
      store values with MP_BIN msgpack format. On the other hand, now it is also
      possible to meet this type: all literals in form of x'...' are
      supposed to be inserted into SCALAR column type exactly with MP_BIN
      encoding. Prior to this moment type of such values (encoded as MP_BIN)
      was called 'blob'. Thus, let's fix all visible to user messages using
      'varbinary' name of type instead of 'blob'.
      78e59b26
    • Nikita Pettik's avatar
      sql: fix resulting type calculation for CASE-WHEN stmt · 7ba34d22
      Nikita Pettik authored
      Before this patch, resulting type for CASE-WHEN statement was assumed to
      be the same as type of argument of first THEN clause. Obviously, it is
      wrong and could lead to sad consequence (e.g. creating ephemeral table
      with inconsistent format). To deal with this, we check all THEN
      arguments: if all of them have the same type, then such type will be
      resulting of the whole statement; if at least two types are different,
      we can't determine actual resulting type during compilation stage and
      assign SCALAR as a most general type in SQL now.
      
      Need for #4206
      7ba34d22
    • Nikita Pettik's avatar
      sql: always erase numeric flag after stringifying · 20d08db6
      Nikita Pettik authored
      Function which converts values to string representation
      (sqlVdbeMemStringify()) erase MEM_Int/MEM_Real/MEM_Bool flags only when
      it is specified by 'force' parameter. Hence, when 'force' argument is
      false, memory cell after conversion will contain string value, but flag
      indicating its type will be equal to combination of MEM_Str and one of
      mentioned flags. It seems to be remains of affinity routines, since in
      current state memory cell must have only one type.  What is more, it can
      lead to unpredicted consequences, for instance assertion fault
      (sql_value_type() assumes that value has one specific type). Let's fix
      it removing 'force' argument from sqlVdbeMemStringify() and always clean
      up type flag.
      20d08db6
  3. Jul 31, 2019
    • Vladislav Shpilevoy's avatar
      sql: transactional DDL · 2677b823
      Vladislav Shpilevoy authored
      Box recently added support of transactional DDL allowing to do
      any number of non-yielding DDL operations atomically. This is
      really a big relief of one of the biggest pains of SQL. Before
      this patch each multirow SQL DDL statement needed to prepare its
      own rollback procedure for a case if something would go wrong.
      
      Now with box support SQL wraps each DDL statement into a
      transaction, and doesn't need own escape-routes in a form of
      'struct save_record' and others.
      
      Closes #4086
      
      @TarantoolBot document
      Title: SQL DDL is transactional
      
      SQL DDL operations are atomic now. For example, if a CREATE TABLE
      request fails somewhere in the middle, it won't leave any
      garbage. Like a space without indexes, or unused sequences. Even
      if the instance is powered off during the request.
      
      Also, SQL DDL can be manually included into transactions, with
      certain limitations - such a transaction can't yield.
      
      For example, this is legal:
      
          START TRANSACTION;
          CREATE TABLE test(a INTEGER PRIMARY KEY, b INTEGER);
          CREATE INDEX test_a ON test(a);
          COMMIT;
      
      If you want to test it in the console, then wrap it into a
      function to do not get a rollback by yield, because the console
      yields after each command:
      
          function create()
              box.execute('START TRANSACTION;')
              box.execute('CREATE TABLE test(a INTEGER PRIMARY KEY, b INTEGER);')
              box.execute('CREATE INDEX test_a ON test(a);')
              box.execute('COMMIT;')
          end
      
          create()
      
      But the following example is illegal and you will get an error:
      
          box.execute('CREATE TABLE test(a INTEGER PRIMARY KEY, b INTEGER, c INTEGER);')
          box.execute('INSERT INTO test VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3);')
      
          function index()
              box.execute('START TRANSACTION;')
              box.execute('CREATE INDEX test_b ON test(b);')
              box.execute('CREATE INDEX test_c ON test(c);')
              box.execute('COMMIT;')
          end
      
          tarantool> index()
          ---
          - error: Can not perform index build in a multi-statement transaction
          ...
      
      The error is because an attempt to build an index on a non-empty
      space leads to immediate yield.
      2677b823
    • Vladislav Shpilevoy's avatar
      alter: do not access space in drop ck commit trigger · e094965b
      Vladislav Shpilevoy authored
      When transactional DDL is introduced, 'DROP TABLE' will remove a
      space and its cks in one transaction. At the moment of that
      transaction commit the space is already removed from _space and
      from space cache, and can't be accessed from other triggers.
      
      This patch makes all space-related actions in on_replace.
      
      Part of #4086
      e094965b
    • Vladimir Davydov's avatar
      ddl: fix vylog vs xlog sync for multi-statement transactions · 40506534
      Vladimir Davydov authored
      Vinyl writes a signature of each statement that created or dropped or
      modified an LSM tree to vylog. This is needed to match xlog rows to
      vylog records on recovery. So alter_space_commit() passes txn->signature
      to index_commit_create(), index_commit_drop(), and index_commit_modify()
      methods. If a transaction has multiple DDL statements, all of them will
      have the same signature. Per se this is fine. The problem is that on
      recovery we apply statements one-by-one, not transactionally, and so we
      pass signatures assigned to individual statements, not to transactions.
      As a result, while recovering a multi-statement DDL transaction vinyl
      gets different signatures for them instead of those that were used when
      those statements were committed, which apparently breaks its assumptions
      and leads to a crash or even a data loss.
      
      To fix this issue, let's, rather than using txn->signature, make
      alter_space_commit() pass the signature of the actual statement that
      committed a DDL operation, which is pretty easy to compute given the
      number of statements in a transaction at the time when the statement was
      committed.
      
      Fixes commit f266559b ("ddl: allow to execute non-yielding DDL
      statements in transactions").
      
      Closes #4350
      Follow-up #4083
      40506534
    • Roman Khabibov's avatar
      httpc: allow only strings for opts.headers values · dc92c531
      Roman Khabibov authored
      There are two reasons to disable support of tables with __tostring
      metamethods as opts.headers values:
      
      * It seems this feature is not much needed: a type convertion can be
        easily done on a user's end with explicit tostring() call if needed.
      * It never did work since introduction in 2.1.1-311-g85e1d78bc ('httpc:
        add checking of headers in httpc:request'): __tostring presence was
        verified, but a function in the field was not invoked.
      
      Now http client accepts only a Lua string as a header key or a value.
      
      Closes #3679 (again).
      dc92c531
    • Vladimir Davydov's avatar
      txn: fix rollback in case DDL and DML are used in the same transaction · 35a48688
      Vladimir Davydov authored
      A txn_stmt keeps a reference to the space it modifies. Memtx uses this
      space reference to revert the statement on error or voluntary rollback
      so the space must stay valid throughout the whole transaction.
      
      The problem is a DML statement may be followed by a DDL statement that
      modifies the target space in the same transaction. If we try to roll
      it back before running the rollback triggers installed by the DDL
      statement, it will access an invalid space object (e.g. missing an
      index), which will result in a crash.
      
      To fix this problem, let's run triggers installed by a statement right
      after rolling back the statement.
      
      Closes #4368
      35a48688
    • Vladimir Davydov's avatar
      vinyl: fix index.stat.txw.rows accounting on rollback to savepoint · 6d0a9edc
      Vladimir Davydov authored
      We must un-account index.stat.txw.rows not only when a whole transaction
      is rolled back, but also when we undo statements using a savepoint.
      6d0a9edc
    • Alexander Turenko's avatar
      net.box: fix schema fetching from 1.10/2.1 servers · aa0964ae
      Alexander Turenko authored
      After 2.2.0-390-ga7c855e5b ("net.box: fetch '_vcollation' sysview into
      the module") net.box fetches _vcollation view unconditionally, while the
      view was added in 2.2.0-389-g3e3ef182f and, say, tarantool-1.10 and
      tarantool-2.1 do not have it. This leads to a runtime error "Space '277'
      does not exist" on a newer client that connects to an older server.
      
      Now the view is fetched conditionally depending of a version of a
      server: if it is above 2.2.1, then net.box will fetch it. Note: at the
      time there are no release with a number above 2.2.1.
      
      When _vcollation view is available, a collation in an index part will be
      shown by its name (with 'collation' field), otherwise it will be shown
      by its ID (in 'collation_id' field). For example:
      
      Connect to tarantool 1.10:
      
       | tarantool> connection = require('net.box').connect('localhost:3301')
       | ---
       | ...
       |
       | tarantool> connection.space.s.index.sk.parts
       | ---
       | - - type: string
       |     is_nullable: false
       |     collation_id: 2
       |     fieldno: 2
       | ...
      
      Connect to tarantool 2.2.1 (when it will be released):
      
       | tarantool> connection = require('net.box').connect('localhost:3301')
       | ---
       | ...
       |
       | tarantool> connection.space.s.index.sk.parts
       | ---
       | - - type: string
       |     is_nullable: false
       |     collation: unicode_ci
       |     fieldno: 2
       | ...
      
      Fixes #4307.
      aa0964ae
  4. Jul 30, 2019
    • Nikita Pettik's avatar
      sql: rename REAL/FLOAT/DOUBLE types to NUMBER · 36bdfbb2
      Nikita Pettik authored
      Before this patch it was allowed to specify REAL/FLOAT/DOUBLE types
      which matched with NUMBER NoSQL type in space format. However, NUMBER is
      different from standard floating point types, since it is able to hold
      integers in range [-2^63; 2^64-1] alongside with double precision
      floating point values. Hence, to not confuse users it has been decided
      to remove support of REAL/FLOAT/DOUBLE types from SQL grammar and use
      instead original NUMBER type naming.
      36bdfbb2
    • Nikita Pettik's avatar
      sql: add STRING alias to TEXT type · 36fc5fe1
      Nikita Pettik authored
      TEXT type is called "string" in the original Tarantool NoSQL, so it would
      be rational to allow using the same type name in SQL.
      36fc5fe1
    • Vladimir Davydov's avatar
      txn: undo commit/rollback triggers when reverting to savepoint · 7ad71695
      Vladimir Davydov authored
      When reverting to a savepoint inside a DDL transaction, apart from
      undoing changes done by the DDL statements to the system spaces, we also
      have to
      
       - Run rollback triggers installed after the savepoint was set, because
         otherwise changes done to the schema by DDL won't be undone.
       - Remove commit triggers installed after the savepoint, because they
         are not relevant anymore, apparently.
      
      To achieve that let's append DDL triggers right to txn statements.
      This allows us to easily discard commit triggers and run rollback
      triggers when a statement is rolled back.
      
      Note, txn commit/rollback triggers are not removed, because they are
      still used by applier and Lua box.on_commit/on_rollback functions.
      
      Closes #4364
      Closes #4365
      7ad71695
    • Vladimir Davydov's avatar
      txn: kill txn_last_stmt helper · 09e9572c
      Vladimir Davydov authored
      It's not used anywhere anymore.
      09e9572c
    • Vladimir Davydov's avatar
      txn: move stmt list/savepoint manipulation out of txn_stmt_new · 37bedba5
      Vladimir Davydov authored
      txn_stmt_new is supposed to simply allocate an initialize a new txn_stmt
      struct. Adding the new statement to the txn's statement list and setting
      up a savepoint for rollback looks confusing. Move it to txn_begin_stmt.
      37bedba5
    • Vladimir Davydov's avatar
      txn: convert txn flags into bit mask · 16610ded
      Vladimir Davydov authored
      16610ded
  5. Jul 29, 2019
    • Kirill Yukhin's avatar
      Bump small version · 8d7d242f
      Kirill Yukhin authored
      8d7d242f
    • Roman Khabibov's avatar
      httpc: verify "headers" option stronger · fc355a2c
      Roman Khabibov authored
      Added the following checks:
      
      * opts.headers is a table.
      * opts.headers keys are strings.
      
      Clarified an error message re Lua type of opts.headers values.
      
      Found and fixed a memory leak that appears in http client when invalid
      opts.headers is passed.
      
      Closes #4281
      fc355a2c
    • Vladimir Davydov's avatar
      txn: reverse commit trigger list only before running commit triggers · 08db912e
      Vladimir Davydov authored
      Commit triggers must be run in the same order they are added, see commit
      01343264 ("txn: fix execution order of commit triggers"). To achieve
      that we added a new trigger method, trigger_add_tail(), which adds new
      triggers to the trigger list tail rather than to the head, and now we
      use this new method for adding commit triggers.
      
      Come to think of it now, that solution was rather confusing. First,
      commit triggers are still added to the head of the list from Lua.
      Second, to revert triggers on rollback-to-savepoint it would be really
      more convenient to have both commit and rollback trigger lists have the
      same order.
      
      So this patch reverts the above-mentioned commit and instead simply
      uses a reverse iterator to run commit triggers.
      08db912e
    • Vladimir Davydov's avatar
      Update small library · 277fc695
      Vladimir Davydov authored
      To bring new rlist methods - rlist_foreach_entry_safe_reverse and
      rlist_cut_before. Also, remove unit/rlist test as it is now a part
      of the small suite.
      277fc695
  6. Jul 28, 2019
  7. Jul 26, 2019
    • Alexander V. Tikhonov's avatar
      LTO build fails on warning message · f21a9932
      Alexander V. Tikhonov authored
      The uninitialized variable found that caused the fail on build,
      due to LTO builds with flag to check warnings as errors. Set the
      variable to 0 initial value. The found issue was:
      
      [100%] Built target xrow.test
      src/box/sql/vdbe.c: In function ‘sqlVdbeExec’:
      src/box/sql/vdbe.c:3691:11: error: ‘id’ may be used uninitialized
      	in this function [-Werror=maybe-uninitialized]
        uint64_t id;
                 ^
      lto1: all warnings being treated as errors
      lto-wrapper: fatal error: /usr/bin/c++ returned 1 exit status
      compilation terminated.
      /usr/bin/ld: error: lto-wrapper failed
      collect2: error: ld returned 1 exit status
      
      Closes #4378
      f21a9932
    • Alexander V. Tikhonov's avatar
      travis-ci: fix OSX max files limits · 027fa1a0
      Alexander V. Tikhonov authored
      Increased the maximum number of open file descriptors on macOS.
      
      Travis-ci: needed the "ulimit -n <value>" call, because found
      that the tests fail without it even with launchctl limit tool set.
      
      Gitlab-ci: needed the "launchctl limit maxfiles <value>" call,
      because under gitlib-ci it is needed the password to change the
      limits and we call the sudo tool which separates the local set
      of the environment.
      
      Closes #4373
      027fa1a0
    • Kirill Shcherbatov's avatar
      box: introduce functional indexes in memxtx · 4177fe17
      Kirill Shcherbatov authored
      Closes #1260
      
      @TarantoolBot document
      Title: introduce func indexes in memtx
      Now you can define a func_index using a registered persistent
      function.
      
      There are restrictions for function and key definition for
      a functional index:
       - the referenced function must be persistent, deterministic
         and must return a scalar type or an array.
       - you must define key parts which describe the function return value
       - the function must return data which types match the
         defined key parts
       - the function may return multiple keys; this would be a multikey
         functional index; each key entry is indexed separately;
       - for multikey functional indexes, the key definition should
         start with part 1 and cover all returned key parts
       - key parts can't use JSON paths.
       - the function used for the functional index can not access tuple
         fields by name, only by index.
      
      Functional index can't be primary.
      It is not possible to change the used function after a functional
      index is defined on it. The index must be dropped first.
      
      Each key returned by functional index function (even when it is a
      single scalar) must be returned as a table i.e. {1} and must
      match the key definition.
      
      To define a multikey functional index, create a function with
      opts = {is_multikey = true} and return a table of keys.
      
      Example:
      s = box.schema.space.create('withdata')
      s:format({{name = 'name', type = 'string'},
                {name = 'address', type = 'string'}})
      pk = s:create_index('name', {parts = {1, 'string'}})
      lua_code = [[function(tuple)
                      local address = string.split(tuple[2])
                      local ret = {}
                      for _, v in pairs(address) do
      			table.insert(ret, {utf8.upper(v)})
      		end
                      return ret
                   end]]
      box.schema.func.create('address', {body = lua_code,
                             is_deterministic = true, is_sandboxed = true,
                             opts = {is_multikey = true}})
      idx = s:create_index('addr', {unique = false,
                           func = 'address',
                           parts = {{1, 'string', collation = 'unicode_ci'}}})
      s:insert({"James", "SIS Building Lambeth London UK"})
      s:insert({"Sherlock", "221B Baker St Marylebone London NW1 6XE UK"})
      idx:select('Uk')
      ---
      - - ['James', 'SIS Building Lambeth London UK']
        - ['Sherlock', '221B Baker St Marylebone London NW1 6XE UK']
      ...
      4177fe17
    • Kirill Shcherbatov's avatar
      box: introduce tuple_chunk infrastructure · de18adda
      Kirill Shcherbatov authored
      Introduced a new object tuple_chunk: a memory allocation is
      associated with given tuple. tuple_format's vtab is extended
      with few new methods to manage tuple_chunks lifecycle.
      Implemented corresponding methid for memtx engine: a memory
      chunks are allocated with memtx's smalloc allocator.
      
      Needed for #1260
      de18adda
Loading