1. 21 Jul, 2023 1 commit
  2. 20 Jul, 2023 1 commit
  3. 19 Jul, 2023 1 commit
  4. 18 Jul, 2023 1 commit
    • Alexander Barkov's avatar
      MDEV-26186 280 Bytes lost in mysys/array.c, mysys/hash.c, sql/sp.cc,... · 1a5c4c2d
      Alexander Barkov authored
      MDEV-26186 280 Bytes lost in mysys/array.c, mysys/hash.c, sql/sp.cc, sql/sp.cc, sql/item_create.cc, sql/item_create.cc, sql/sql_yacc.yy:10748 when using oracle sql_mode
      
      There was a memory leak under these conditions:
      - YYABORT was called in the end-of-rule action of a rule containing expr_lex
      - This expr_lex was not bound to any sp_lex_keeper
      
      Bison did not call %destructor <expr_lex> in this case, because its stack
      already contained a reduced upper-level rule.
      
      Fixing rules starting with RETURN, CONTINUE, EXIT keywords:
      
      Turning end-of-rule actions with YYABORT into mid-rule actions
      by adding an empty trailing { } block. This prevents the upper level
      rule from being reduced without calling %destructor <expr_lex>.
      
      In other rules expr_lex is used not immediately before the last
      end-of-rule { } block, so they don't need changes.
      1a5c4c2d
  5. 17 Jul, 2023 1 commit
    • Alexander Barkov's avatar
      MDEV-27207 Assertion `!m_null_value' failed in int... · 68403eed
      Alexander Barkov authored
      MDEV-27207 Assertion `!m_null_value' failed in int FixedBinTypeBundle<FbtImpl>::cmp_item_fbt::compare or in cmp_item_inet6::compare
      
      Also fixing:  MDEV-31719 Wrong result of: WHERE inet6_column IN ('','::1')
      
      Problem:
      
      When converting an Item value from string to INET6 it's possible
      that the Item value itself is a not-NULL string value,
      while the following result of the string-to-INET6 conversion returns NULL.
      
      Methods cmp_item_xxx::set(), cmp_item_xxx::store_value_by_template(),
      in_inet6::set() did not take this scenario into account and
      tested source_item->null_value, which does not indicate if the conversion
      failed.
      
      Changing the return data type of the mentioned methods from "void" to "bool".
      
      "true" means that:
      - either the source Item was NULL
      - or the source Item was not NULL, but the data type coversion to
        the destination data type (INET6 in this issue) returned NULL.
      
      "false" means that the Item was not NULL and the data type conversion
      to the destination data type worked without error.
      
      This patches fixes the INET6 data type.
      After merging to 10.9, this patch should also fix same problems in UUID.
      68403eed
  6. 14 Jul, 2023 1 commit
    • Alexander Barkov's avatar
      MDEV-30662 SQL/PL package body does not appear in I_S.ROUTINES.ROUTINE_DEFINITION · 400c1013
      Alexander Barkov authored
      - Moving the code from a public function trim_whitespaces()
        to the class Lex_cstring as methods. This code may
        be useful in other contexts, and also this code becomes
        visible inside sql_class.h
      
      - Adding a helper method THD::strmake_lex_cstring_trim_whitespaces()
      
      - Unifying the way how CREATE PROCEDURE/CREATE FUNCTION and
        CREATE PACKAGE/CREATE PACKAGE BODY work:
      
        a) Now CREATE PACKAGE/CREATE PACKAGE BODY also calls
        Lex->sphead->set_body_start() to remember the cpp body start inside
        an sp_head member.
      
        b) adding a "const char *cpp_body_end" parameter to
        sp_head::set_stmt_end().
      
        These changes made it possible to reuse sp_head::set_stmt_end() inside
        LEX::create_package_finalize() and remove the duplucate code.
      
      - Renaming sp_head::m_body_begin to m_cpp_body_begin and adding a comment
        to make it clear that this member is used only during parsing, and
        points to a fragment inside the cpp buffer.
      
      - Changed sp_head::set_body_start() and sp_head::set_stmt_end()
        to skip the calls related to "body_utf8" in cases when m_parent is not NULL.
        A non-NULL m_parent means that we're inside a package routine.
        "body_utf8" in such case belongs not to the current sphead itself,
        but to parent (the package) sphead.
        So an sphead instance of a package routine should neither initialize,
        nor finalize, nor change in any other ways the "body_utf8" related
        members of Lex_input_stream, and should not take over or copy "body_utf8"
        data from Lex_input_stream to "this".
      400c1013
  7. 11 Jul, 2023 1 commit
    • Brandon Nesterenko's avatar
      MDEV-30978: On slave XA COMMIT/XA ROLLBACK fail to return an error in read-only mode · 9808ebe1
      Brandon Nesterenko authored
      Where a read-only server permits writes through replication, it
      should not permit user connections to commit/rollback XA
      transactions prepared via replication. The bug reported in
      MDEV-30978 shows that this can happen. This is because there is no
      read only check in the XA transaction logic, the most relevant one
      occurs in ha_commit_trans() for normal statements/transactions.
      
      This patch extends the XA transaction logic to check the read only
      status of the server before performing an XA COMMIT or ROLLBACK.
      
      Reviewed By:
      Andrei Elkin <andrei.elkin@mariadb.com>
      9808ebe1
  8. 06 Jul, 2023 1 commit
  9. 05 Jul, 2023 2 commits
  10. 04 Jul, 2023 2 commits
  11. 03 Jul, 2023 8 commits
  12. 29 Jun, 2023 5 commits
    • Sergei Golubchik's avatar
    • Alexander Barkov's avatar
      MDEV-31578 DECLARE CURSOR: "Memory not freed: 280 bytes lost" on syntax error · fdab2c4c
      Alexander Barkov authored
      When CURSOR parameters get parsed, their sp_assignment_lex instances
      (one instance per parameter) get collected to List<sp_assignment_lex>.
      
      These instances get linked to sphead only in the end of the list.
      If a syntax error happened in the middle of the parameter list,
      these instances were not deleted, which caused memory leaks.
      
      Fix:
      
      using a Bison %destructor to free rules of the <sp_assignment_lex_list>
      type (on syntax errors).
      
      Afte the fix these sp_assignment_lex instances from CURSOR parameters
      deleted as follows:
      
      - If the CURSOR statement was fully parsed, then these instances
        get properly linked to sp_head structures, so they are deleted
        during ~sp_head (this did not change)
      
      - If the CURSOR statement failed on a syntax error, then by Bison's
        %destructor (this is being added in the current patch).
      fdab2c4c
    • Alexander Barkov's avatar
      MDEV-30680 Warning: Memory not freed: 280 on mangled query, LeakSanitizer: detected memory leaks · 0d3720c1
      Alexander Barkov authored
      The parser works as follows:
      
      The rule expr_lex returns a pointer to a newly created sp_expr_lex
      instance which is not linked to any MariaDB structures yet - it is
      pointed only from a Bison stack variable. The sp_expr_lex instance
      gets linked to other structures (such as sp_instr_jump_if_not) later,
      after scanning some following grammar.
      
      Problem before the fix:
      If a parse error happened immediately after expr_lex (before it got linked),
      the created sp_expr_lex value got lost causing a memory leak.
      
      Fix:
      
      - Using Bison's "destructor" directive to free the results of expr_lex
        on parse/oom errors.
      
      - Moving the call for LEX::cleanup_lex_after_parse_error() from
        MYSQL_YYABORT and yyerror inside parse_sql().
        This is needed because Bison calls destructors after yyerror(),
        while it's important to delete the sp_expr_lex instance before
        LEX::cleanup_lex_after_parse_error().
        The latter frees the memory root containing the sp_expr_lex instance.
      
        After this change the code block are executed in the following order:
      
        - yyerror() -- now only raises the error to DA (no cleanup done any more)
        - %destructor { delete $$; } <expr_lex>  -- destructs the sp_expr_lex instance
        - LEX::cleanup_lex_after_parse_error()   -- frees the memory root containing
                                                    the sp_expr_lex instance
      
      - Removing the "delete sublex" related code from restore_lex():
        - restore_lex() is called in most cases on success, when delete is not needed.
        - There is one place when restore_lex() is called on error:
          In sp_create_assignment_instr(). But in this case LEX::sp_lex_in_use
          is true anyway.
          The patch adds a new DBUG_ASSERT(lex->sp_lex_in_use) to guard this.
      0d3720c1
    • Alexander Barkov's avatar
      MDEV-30932 UBSAN: negation of -X cannot be represented in type .. · 67657a01
      Alexander Barkov authored
        'long long int'; cast to an unsigned type to negate this value ..
        to itself in Item_func_mul::int_op and Item_func_round::int_op
      
      Problems:
      
        The code in multiple places in the following methods:
          - Item_func_mul::int_op()
          - longlong Item_func_int_div::val_int()
          - Item_func_mod::int_op()
          - Item_func_round::int_op()
      
        did not properly check for corner values LONGLONG_MIN
        and (LONGLONG_MAX+1) before doing negation.
        This cuased UBSAN to complain about undefined behaviour.
      
      Fix summary:
      
        - Adding helper classes ULonglong, ULonglong_null, ULonglong_hybrid
          (in addition to their signed couterparts in sql/sql_type_int.h).
      
        - Moving the code performing multiplication of ulonglong numbers
          from Item_func_mul::int_op() to ULonglong_hybrid::ullmul().
      
        - Moving the code responsible for extracting absolute values
          from negative numbers to Longlong::abs().
          It makes sure to perform negation without undefinite behavior:
          LONGLONG_MIN is handled in a special way.
      
        - Moving negation related code to ULonglong::operator-().
          It makes sure to perform negation without undefinite behavior:
          (LONGLONG_MAX + 1) is handled in a special way.
      
        - Moving signed<=>unsigned conversion code to
          Longlong_hybrid::val_int() and ULonglong_hybrid::val_int().
      
        - Reusing old and new sql_type_int.h classes in multiple
          places in Item_func_xxx::int_op().
      
      Fix details (explain how sql_type_int.h classes are reused):
      
        - Instead of straight negation of negative "longlong" arguments
          *before* performing unsigned multiplication,
          Item_func_mul::int_op() now calls ULonglong_null::ullmul()
          using Longlong_hybrid_null::abs() to pass arguments.
          This fixes undefined behavior N1.
      
        - Instead of straight negation of "ulonglong" result
          *after* performing unsigned multiplication,
          Item_func_mul::int_op() now calls ULonglong_hybrid::val_int(),
          which recursively calls ULonglong::operator-().
          This fixes undefined behavior N2.
      
        - Removing duplicate negating code from Item_func_mod::int_op().
          Using ULonglong_hybrid::val_int() instead.
          This fixes undefinite behavior N3.
      
        - Removing literal "longlong" negation from Item_func_round::int_op().
          Using Longlong::abs() instead, which correctly handler LONGLONG_MIN.
          This fixes undefinite behavior N4.
      
        - Removing the duplicate (negation related) code from
          Item_func_int_div::val_int(). Reusing class ULonglong_hybrid.
          There were no undefinite behavior in here.
          However, this change allowed to reveal a bug in
          "-9223372036854775808 DIV 1".
          The removed negation code appeared to be incorrect when
          negating +9223372036854775808. It returned the "out of range" error.
          ULonglong_hybrid::operator-() now handles all values correctly
          and returns +9223372036854775808 as a negation for -9223372036854775808.
      
          Re-recording wrong results for
            SELECT -9223372036854775808 DIV  1;
          Now instead of "out of range", it returns -9223372036854775808,
          which is the smallest possible value for the expression data type
          (signed) BIGINT.
      
        - Removing "no UBSAN" branch from Item_func_splus::int_opt()
          and Item_func_minus::int_opt(), as it made UBSAN happy but
          in RelWithDebInfo some MTR tests started to fail.
      67657a01
    • Yuchen Pei's avatar
  13. 28 Jun, 2023 3 commits
  14. 27 Jun, 2023 4 commits
    • Sergei Golubchik's avatar
      mtr: fix the help text for debuggers · d214628a
      Sergei Golubchik authored
      d214628a
    • Thirunarayanan Balathandayuthapani's avatar
      MDEV-31086 MODIFY COLUMN can break FK constraints, and lead to unrestorable dumps · 5f09b53b
      Thirunarayanan Balathandayuthapani authored
      - When foreign_key_check is disabled, allowing to modify the
      column which is part of foreign key constraint can lead to
      refusal of TRUNCATE TABLE, OPTIMIZE TABLE later. So it make
      sense to block the column modify operation when foreign key
      is involved irrespective of foreign_key_check variable.
      
      Correct way to modify the charset of the column when fk is involved:
      
      SET foreign_key_checks=OFF;
      ALTER TABLE child DROP FOREIGN KEY fk, MODIFY m VARCHAR(200) CHARSET utf8mb4;
      ALTER TABLE parent MODIFY m VARCHAR(200) CHARSET utf8mb4;
      ALTER TABLE child ADD CONSTRAINT FOREIGN KEY (m) REFERENCES PARENT(m);
      SET foreign_key_checks=ON;
      
      fk_check_column_changes(): Remove the FOREIGN_KEY_CHECKS while
      checking the column change for foreign key constraint. This
      is the partial revert of commit 5f1f2fc0
      and it changes the behaviour of copy alter algorithm
      
      ha_innobase::prepare_inplace_alter_table(): Find the modified
      column and check whether it is part of existing and newly
      added foreign key constraint.
      5f09b53b
    • Marko Mäkelä's avatar
      MDEV-31487: Recovery or backup failure after innodb_undo_log_truncate=ON · 84dbd025
      Marko Mäkelä authored
      recv_sys_t::parse(): For undo tablespace truncation mini-transactions,
      remember the start_lsn instead of the end LSN. This is what we expect
      after commit 461402a5 (MDEV-30479).
      84dbd025
    • Yuchen Pei's avatar
      MDEV-29447 MDEV-26285 MDEV-31338 Refactor spider_db_mbase_util::open_item_func · 423c28f0
      Yuchen Pei authored
      spider_db_mbase_util::open_item_func() is a monster function.
      It is difficult to maintain while it is expected that we need to
      modify it when a new SQL function or a new func_type is added.
      
      We split the function into two distinct functions: one handles the
      case of str != NULL and the other handles the case of str == NULL.
      
      This refactoring was done in a conservative way because we do not
      have comprehensive tests on the function.
      
      It also fixes MDEV-29447 and MDEV-31338 where field items that are
      arguments of a func item may be used before created / initialised.
      
      Note this commit is adapted from a patch by Nayuta for MDEV-26285.
      423c28f0
  15. 26 Jun, 2023 1 commit
  16. 22 Jun, 2023 2 commits
  17. 20 Jun, 2023 1 commit
  18. 19 Jun, 2023 1 commit
  19. 16 Jun, 2023 1 commit
  20. 15 Jun, 2023 1 commit
  21. 14 Jun, 2023 1 commit
    • Sergei Petrunia's avatar
      MDEV-31479: Inconsistency between MRR and SQL layer costs can cause poor query plan · 0e2e70c4
      Sergei Petrunia authored
      (Same as
      TODO-3938: best_access_path shows negative costs for mrr=on)
      
      best_access_path() assumes that quick select cost includes
      (quick->rows/TIME_FOR_COMPARE) as a cost of checking the attached
      part of the WHERE condition.
      
      It calls adjust_quick_cost() to subtract addition from quick's cost.
      
      The problem was that DS-MRR cost formula didn't include this cost.
      For very large tables, adjust_quick_cost() would produce a negative
      cost which would cause assert in debug build or bad query plan choice
      in release builds.
      Approved-by: default avatarMonty <monty@mariadb.org>
      0e2e70c4