1. 07 Jun, 2023 1 commit
  2. 02 Jun, 2023 2 commits
    • Marko Mäkelä's avatar
      MDEV-31385 Change buffer stale entries leads to corruption while reusing page · f569e06e
      Marko Mäkelä authored
      buf_page_free(): If buffered changes existed for the page, drop them.
      
      Co-developed with Thirunarayanan Balathandayuthapani
      f569e06e
    • Marko Mäkelä's avatar
      MDEV-31088 Server freeze due to innodb_change_buffering · 8a86df37
      Marko Mäkelä authored
      A 3-thread deadlock has been frequently observed when using
      innodb_change_buffering!=none and innodb_file_per_table=0:
      
      (1) ibuf_merge_or_delete_for_page() holding an exclusive latch on the block
      and waiting for an exclusive tablespace latch in fseg_page_is_allocated()
      (2) btr_free_but_not_root() in fseg_free_step() waiting for an
      exclusive tablespace latch
      (3) fsp_alloc_free_page() holding the exclusive tablespace latch and waiting
      for a latch on the block, which it is reallocating for something else
      
      While this was reproduced using innodb_file_per_table=0, this hang should
      be theoretically possible in .ibd files as well, when the recovery or
      cleanup of a failed DROP INDEX or ADD INDEX is executing concurrently
      with something that involves page allocation.
      
      ibuf_merge_or_delete_for_page(): Avoid invoking fseg_page_is_allocated()
      when block==nullptr. The call was redundant in this case, and it could
      cause deadlocks due to latching order violation.
      
      ibuf_read_merge_pages(): Acquire an exclusive tablespace latch
      before invoking buf_page_get_gen(), which may cause
      fseg_page_is_allocated() to be invoked in ibuf_merge_or_delete_for_page().
      
      Note: This will not fix all latching order violations in this area!
      Deadlocks involving ibuf_merge_or_delete_for_page(block!=nullptr) are
      still possible if the caller is not acquiring an exclusive tablespace latch
      upfront. This would be the case in any read operation that involves a
      change buffer merge, such as SELECT, CHECK TABLE, or any DML operation that
      cannot be buffered in the change buffer.
      8a86df37
  3. 01 Jun, 2023 3 commits
  4. 31 May, 2023 4 commits
  5. 30 May, 2023 2 commits
    • Marko Mäkelä's avatar
      MDEV-31362 recv_sys_t::apply(bool): Assertion `!last_batch || recovered_lsn == scanned_lsn' failed · a6c0a276
      Marko Mäkelä authored
      recv_sys_t::apply(): Remove a bogus debug assertion that had been
      added in commit f2c17cc9 (MDEV-29911).
      
      It is perfectly normal that when the server was killed in the middle of
      writing multiple redo log blocks, the recovery would end such that
      recv_sys.scanned_lsn will point to the end of the last complete 512-byte
      log block, but recv_sys.recovered_lsn will be less than that.
      
      Also, correct the function comment of recv_sys_t::parse().
      a6c0a276
    • Otto Kekalainen's avatar
      Deb: Fix blocksize check to use $mysql_datadir/$datadir correctly · ea66df2f
      Otto Kekalainen authored
      In commit f99a8918 this line was changed to not use awk, and new version
      copied both to init file and preinst file but overlooking that they use
      different variable names.
      
      Also fix minor syntax issues to make Shellcheck happy.
      
      All new code of the whole pull request, including one or several files
      that are either new files or modified ones, are contributed under the
      BSD-new license. I am contributing on behalf of my employer
      Amazon Web Services, Inc.
      ea66df2f
  6. 26 May, 2023 5 commits
    • Marko Mäkelä's avatar
      MDEV-31350: Hang in innodb.recovery_memory · ce547cfc
      Marko Mäkelä authored
      buf_flush_page_cleaner(): Whenever buf_pool.ran_out(), invoke
      buf_pool.get_oldest_modification(0) so that all clean blocks
      will be removed from buf_pool.flush_list and buf_flush_LRU_list_batch()
      will be able to evict some pages.
      
      This fixes a regression that was likely caused by
      commit a55b951e (MDEV-26827).
      ce547cfc
    • Marko Mäkelä's avatar
      MDEV-22739 !cursor->index->is_committed() in row0ins.cc · 7b72fc0a
      Marko Mäkelä authored
      row_ins_sec_index_entry_by_modify(): When noticing a corrupted secondary
      index on which CREATE INDEX is not in progress, return DB_CORRUPTION
      instead of intentionally crashing the server.
      
      Tested by: Matthias Leich
      7b72fc0a
    • Marko Mäkelä's avatar
      MDEV-31346 trx_purge_add_undo_to_history() is not optimal · e38c075a
      Marko Mäkelä authored
      trx_undo_set_state_at_finish(): Merge to its only caller,
      trx_purge_add_undo_to_history().
      
      trx_purge_add_undo_to_history(): Evaluate the condition related to
      TRX_UNDO_STATE only once.
      
      Tested by: Matthias Leich
      e38c075a
    • Marko Mäkelä's avatar
      MDEV-31343 Another server hang with innodb_undo_log_truncate=ON · db876550
      Marko Mäkelä authored
      trx_purge_truncate_history(): While waiting for a write-fixed block
      to become available, simply wait for an exclusive latch on it.
      Also, simplify the iteration: first check for oldest_modification>2
      (to ignore clean pages or pages belonging to the temporary tablespace)
      and then compare the tablespace identifier.
      
      Before releasing buf_pool.flush_list_mutex we will buffer-fix the block
      of interest. In that way, buf_page_t::can_relocate() will not hold on
      the block and it must remain in the buffer pool until we have acquired
      an exclusive latch on it. If the block is still dirty, we will register
      it with the tablespace truncation mini-transaction; else, we will simply
      release the latch and buffer-fix and move to the next block.
      
      This also reverts commit c4d79399
      because that fix should no longer be necessary; the wait for an
      exclusive block latch should allow buf_pool_t::release_freed_page()
      on the same block to proceed.
      
      Tested by: Axel Schwenke, Matthias Leich
      db876550
    • Alexander Barkov's avatar
      Extra tests for MDEV-30483 After upgrade to 10.6 from Mysql 5.7 seeing... · 03a9366c
      Alexander Barkov authored
      Extra tests for MDEV-30483 After upgrade to 10.6 from Mysql 5.7 seeing "InnoDB: Column last_update in table mysql.innodb_table_stats is BINARY(4) NOT NULL but should be INT UNSIGNED NOT NULL"
      
      Adding tests demonstrating that columns:
      - mysql.innodb_table_stats.last_update
      - mysql.innodb_index_stats.last_update
      
      contain sane values close to NOW() rathar than a garbage.
      
      Tests cover these three underlying TIMESTAMP data formats:
      
      - MariaDB Field_timestamp0 - UINT4 based
        Like in a MariaDB native installation running with mysql56_temporal_format=0
      
      - MariaDB Field_timestampf - BINARY(4) based, with UNSIGNED_FLAG
        Like in a MariaDB native installation running with mysql56_temporal_format=1
      
      - MySQL-alike Field_timestampf - BINARY(4) based, without UNSIGNED_FLAG
        Like with a MariaDB server running over a MySQL-5.6 directory
        (e.g. during a migragion).
      03a9366c
  7. 25 May, 2023 3 commits
    • Oleksandr Byelkin's avatar
      44c9008b
    • Marko Mäkelä's avatar
      Merge 10.6 into 10.9 · 31be2534
      Marko Mäkelä authored
      31be2534
    • Alexander Barkov's avatar
      MDEV-30483 After upgrade to 10.6 from Mysql 5.7 seeing "InnoDB: Column... · 9edb1a5c
      Alexander Barkov authored
      MDEV-30483 After upgrade to 10.6 from Mysql 5.7 seeing "InnoDB: Column last_update in table mysql.innodb_table_stats is BINARY(4) NOT NULL but should be INT UNSIGNED NOT NULL"
      
      Problem:
      
      Field_timestampf implementations differ in MySQL and MariaDB:
      - MariaDB sets the UNSIGNED_FLAG in Field::flags
      - MySQL does not
      
      The reference table structures
      (defined in table_stats_schema and index_stats_schema)
      expected the last_update column to have the DATA_UNSIGNED flag,
      because MariaDB's Field_timestampf has the UNSIGNED_FLAG.
      It worked fine on pure MariaDB installations.
      
      However, if a MariaDB server starts over a MySQL-5.7 data directory during
      a migration, the last_update column does not have DATA_UNSIGNED flag,
      because MySQL's Field_timestampf does not have the UNSIGNED_FLAG.
      
      This made InnoDB (after the migration from MySQL) complain into the server
      error log about the unexpected data type.
      
      The actual fix is done in storage/innobase/dict/dict0stats.cc:
      It removes DATA_UNSIGNED from the prtype_mask member of the reference columns,
      so now it does not require the underlying columns to have this flag.
      
      The rest of the fix is needed for MTR tests.
      The new data type plugin TYPE_MYSQL_TIMESTAMP implements a slightly modified
      version of Field_timestampf, which removes the unsigned flag, so
      it works like MySQL's Field_timestampf.
      
      The MTR test ALTERs the data type of the columns
      table_stats_schema.last_update and index_stats_schema.last_update
      from TIMESTAMP to TYPE_MYSQL_TIMESTAMP, then makes InnoDB
      verify the structure of the two statistics tables by creating
      and populating an InnoDB table t1.
      
      Without the fix made storage/innobase/dict/dict0stats.cc,
      MTR complains about unexpected warnings in the server error log:
      
      [ERROR] InnoDB: Column last_update in table mysql.innodb_table_stats is ...
      [ERROR] InnoDB: Column last_update in table mysql.innodb_index_stats is ...
      
      With the fix made storage/innobase/dict/dict0stats.cc these warnings
      go away.
      9edb1a5c
  8. 24 May, 2023 9 commits
  9. 23 May, 2023 7 commits
    • Marko Mäkelä's avatar
      Merge 10.5 into 10.6 · 270eeeb5
      Marko Mäkelä authored
      270eeeb5
    • Marko Mäkelä's avatar
      MDEV-31234 fixup: Allow innodb_undo_log_truncate=ON after upgrade · 9c35f9c9
      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.
      9c35f9c9
    • Monty's avatar
      Optimized version of safe_strcpy() · a7adfd4c
      Monty authored
      Note: We should replace most case of safe_strcpy() with strmake() to avoid
      the not needed zerofill.
      a7adfd4c
    • Monty's avatar
      MDEV-28285 Unexpected result when combining DISTINCT, subselect and LIMIT · 92d2ceac
      Monty authored
      The problem was that when  JOIN_TAB::remove_duplicates() noticed there
      can only be one possible row in the output, it adjusted limits but
      didn't take into account any possible offset.
      
      Fixed by not adjusting limit offset when setting one-row-limit.
      92d2ceac
    • Monty's avatar
      MDEV-31083 ASAN use-after-poison in myrg_attach_children · cd37e494
      Monty authored
      The reason for ASAN report was that the MERGE and MYISAM file
      had different key definitions, which is not allowed.
      
      Fixed by ensuring that the MERGE code is not copying more key stats
      than what is in the MyISAM file.
      
      Other things:
      - Give an error if different MyISAM files has different number of
        key parts.
      cd37e494
    • Monty's avatar
      Update main.selectivity test and results · c7e04af8
      Monty authored
      c7e04af8
    • Monty's avatar
      Make install.db read only in mtr · 6a031406
      Monty authored
      This ensures that no mtr test can change install.db after it's initial
      creation as changing it while as another thread is coping it will lead to
      failures in at least InnoDB and Aria recovery.
      
      Fixed spider/bugfix.mdev_30370 that was wrongly used install.db
      6a031406
  10. 22 May, 2023 4 commits
    • Monty's avatar
      Remove warning of not freed memory if mysqld aborts · b0c285bb
      Monty authored
      Fixes warning when doing:
      ./sql/mariadbd --socket=/tmp/xxxx/ddd
      b0c285bb
    • Monty's avatar
      MDEV-6768 Wrong result with aggregate with join with no result set · 16258677
      Monty authored
      When a query does implicit grouping and join operation produces an empty
      result set, a NULL-complemented row combination is generated.
      However, constant table fields still show non-NULL values.
      
      What happens in the is that end_send_group() is called with a
      const row but without any rows matching the WHERE clause.
      This last part is shown by 'join->first_record' not being set.
      
      This causes item->no_rows_in_result() to be called for all items to reset
      all sum functions to their initial state. However fields are not set
      to NULL.
      
      The used fix is to produce NULL-complemented records for constant tables
      as well. Also, reset the constant table's records back in case we're
      in a subquery which may get re-executed.
      An alternative fix would have item->no_rows_in_result() also work
      with Item_field objects.
      
      There is some other issues with the code:
      - join->no_rows_in_result_called is used but never set.
      - Tables that are used with group functions are not properly marked as
        maybe_null, which is required if the table rows should be regarded as
        null-complemented (not existing).
      - The code that tries to detect if mixed_implicit_grouping should be set
        didn't take into account all usage of fields and sum functions.
      - Item_func::restore_to_before_no_rows_in_result() called the wrong
        function.
      - join->clear() does not use a table_map argument to clear_tables(),
        which caused it to ignore constant tables.
      - unclear_tables() does not correctly restore status to what is
        was before clear_tables().
      
      Main bug fix was to always use a table_map argument to clear_tables() and
      always use join->clear() and clear_tables() together with unclear_tables().
      
      Other fixes:
      - Fixed Item_func::restore_to_before_no_rows_in_result()
      - Set 'join->no_rows_in_result_called' when no_rows_in_result_set()
        is called.
      - Removed not used argument from setup_end_select_func().
      - More code comments
      - Ensure that end_send_group() modifies the same fields as are in the
        result set.
      - Changed return_zero_rows() to use pointers instead of references,
        similar to the rest of the code.
      
      Reviewer: Sergei Petrunia <sergey@mariadb.com>
      16258677
    • Marko Mäkelä's avatar
      Merge 10.5 into 10.6 · 3bd10b57
      Marko Mäkelä authored
      3bd10b57
    • Marko Mäkelä's avatar
      MDEV-29593 fixup: Avoid a leak if rseg.undo_cached is corrupted · a5ce335a
      Marko Mäkelä authored
      trx_purge_truncate_rseg_history(): Avoid a leak similar to the one
      that was fixed in MDEV-31324, in case a supposedly cached undo log
      page is not found in the rseg.undo_cached list.
      a5ce335a