1. 19 Jul, 2023 1 commit
  2. 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
  3. 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
  4. 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
  5. 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
  6. 06 Jul, 2023 1 commit
  7. 05 Jul, 2023 1 commit
  8. 03 Jul, 2023 1 commit
  9. 29 Jun, 2023 2 commits
    • 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
  10. 28 Jun, 2023 2 commits
  11. 27 Jun, 2023 1 commit
  12. 20 Jun, 2023 1 commit
  13. 16 Jun, 2023 1 commit
  14. 15 Jun, 2023 1 commit
  15. 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
  16. 09 Jun, 2023 1 commit
    • Thirunarayanan Balathandayuthapani's avatar
      MDEV-31442 page_cleaner thread aborts while releasing the tablespace · 841e905f
      Thirunarayanan Balathandayuthapani authored
      After further I/O on a tablespace has been stopped
      (for example due to DROP TABLE or an operation that
      rebuilds a table), page cleaner thread tries to
      flush the pending writes for the tablespace and
      releases the tablespace reference even though it was not
      acquired.
      
      fil_space_t::flush(): Don't release the tablespace when it is
      being stopped and closed
      
      Thanks to Marko Mäkelä for suggesting this patch.
      841e905f
  17. 08 Jun, 2023 5 commits
  18. 07 Jun, 2023 3 commits
  19. 05 Jun, 2023 2 commits
  20. 03 Jun, 2023 8 commits
    • Marko Mäkelä's avatar
      MDEV-31234 fixup: Allow innodb_undo_log_truncate=ON after upgrade · 3b4b512d
      Marko Mäkelä authored
      trx_purge_truncate_history(): Relax a condition that would prevent
      undo log truncation if the undo log tablespaces were "contaminated"
      by the bug that commit e0084b9d fixed.
      That is, trx_purge_truncate_rseg_history() would have invoked
      flst_remove() on TRX_RSEG_HISTORY but not reduced TRX_RSEG_HISTORY_SIZE.
      
      To avoid any regression with normal operation, we implement this
      fixup during slow shutdown only. The condition on the history list
      being empty is necessary: without it, in the test
      innodb.undo_truncate_recover there may be much fewer than the
      expected 90,000 calls to row_purge() before the truncation.
      That is, we would truncate the undo tablespace before actually having
      processed all undo log records in it.
      
      To truncate such "contaminated" or "bloated" undo log tablespaces
      (when using innodb_undo_tablespaces=2 or more)
      you can execute the following SQL:
      
      BEGIN;INSERT mysql.innodb_table_stats VALUES('','',DEFAULT,0,0,0);ROLLBACK;
      SET GLOBAL innodb_undo_log_truncate=ON, innodb_fast_shutdown=0;
      SHUTDOWN;
      
      The first line creates a dummy InnoDB transaction, to ensure that there
      will be some history to be purged during shutdown and that the undo
      tablespaces will be truncated.
      3b4b512d
    • Marko Mäkelä's avatar
      MDEV-31234 fixup: Free some UNDO pages earlier · 48d6a5f6
      Marko Mäkelä authored
      trx_purge_truncate_rseg_history(): Add a parameter to specify if
      the entire rollback segment is safe to be freed. If not, we may
      still be able to invoke trx_undo_truncate_start() and free some pages.
      48d6a5f6
    • Marko Mäkelä's avatar
      MDEV-31234 InnoDB does not free UNDO after the fix of MDEV-30671 · 318012a8
      Marko Mäkelä authored
      trx_purge_truncate_history(): Only call trx_purge_truncate_rseg_history()
      if the rollback segment is safe to process. This will avoid leaking undo
      log pages that are not yet ready to be processed. This fixes a regression
      that was introduced in
      commit 0de3be8c (MDEV-30671).
      
      trx_sys_t::any_active_transactions(): Separately count XA PREPARE
      transactions.
      
      srv_purge_should_exit(): Terminate slow shutdown if the history size
      does not change and XA PREPARE transactions exist in the system.
      This will avoid a hang of the test innodb.recovery_shutdown.
      
      Tested by: Matthias Leich
      318012a8
    • Sergei Golubchik's avatar
      eb472f77
    • Sergei Golubchik's avatar
      Revert "MDEV-30473 : Do not allow GET_LOCK() / RELEASE_LOCK() in cluster" · 0fd54c98
      Sergei Golubchik authored
      This reverts commit 844ddb11.
      
      This fixes MDEV-30967, MDEV-31325, MDEV-31388
      0fd54c98
    • Igor Babaev's avatar
      MDEV-31240 Crash with condition pushable into derived and containing outer reference · 8f3bf593
      Igor Babaev authored
      This bug could affect queries containing a subquery over splittable derived
      tables and having an outer references in its WHERE clause. If such subquery
      contained an equality condition whose left part was a reference to a column
      of the derived table and the right part referred only to outer columns
      then the server crashed in the function st_join_table::choose_best_splitting()
      The crashing code was added in the commit ce7ffe61
      that made the code of the function sensitive to presence of the flag
      OUTER_REF_TABLE_BIT in the KEYUSE_EXT::needed_in_prefix fields.
      
      The field needed_in_prefix of the KEYUSE_EXT structure should not contain
      table maps with OUTER_REF_TABLE_BIT or RAND_TABLE_BIT.
      
      Note that this fix is quite conservative: for affected queries it just
      returns the query plans that were used before the above mentioned commit.
      In fact the equalities causing crashes should be pushed into derived tables
      without any usage of split optimization.
      
      Approved by Sergei Petrunia <sergey@mariadb.com>
      8f3bf593
    • Igor Babaev's avatar
      MDEV-31224 Crash with EXPLAIN EXTENDED for multi-table update of system table · aa713f5a
      Igor Babaev authored
      EXPLAIN EXTENDED should always print the field item used in the left part
      of an equality expression from the SET clause of an update statement as a
      reference to table column.
      
      Approved by Oleksandr Byelkin <sanja@mariadb.com>
      aa713f5a
    • Daniel Bartholomew's avatar
      bump the VERSION · 54324e54
      Daniel Bartholomew authored
      54324e54
  21. 01 Jun, 2023 2 commits
  22. 24 May, 2023 2 commits