mirror of
https://github.com/MariaDB/server.git
synced 2025-01-20 22:12:30 +01:00
d33b523271
Fixed BUGS: #3300: "UPDATE statement with no index column in where condition locks all rows" Implement semi-consistent read to reduce lock conflicts at the cost of breaking serializability. ha_innobase::unlock_row(): reset the "did semi consistent read" flag ha_innobase::was_semi_consistent_read(), ha_innobase::try_semi_consistent_read(): new methods row_prebuilt_t, row_create_prebuilt(): add field row_read_type for keeping track of semi-consistent reads row_vers_build_for_semi_consistent_read(), row_sel_build_committed_vers_for_mysql(): new functions row_search_for_mysql(): implement semi-consistent reads #9802: "Foreign key checks disallow alter table". Added test cases. #12456: "Cursor shows incorrect data - DML does not affect, probably caching" This patch implements a high-granularity read view to be used with cursors. In this high-granularity consistent read view modifications done by the creating transaction after the cursor is created or future transactions are not visible. But those modifications that transaction did before the cursor was created are visible. #12701: "Support >4GB buffer pool and log files on 64-bit Windows" Do not call os_file_create_tmpfile() at runtime. Instead, create all tempfiles at startup and guard access to them with mutexes. #13778: "If FOREIGN_KEY_CHECKS=0, one can create inconsistent FOREIGN KEYs". When FOREIGN_KEY_CHECKS=0 we still need to check that datatypes between foreign key references are compatible. #14189: "VARBINARY and BINARY variables: trailing space ignored with InnoDB" innobase_init(): Assert that DATA_MYSQL_BINARY_CHARSET_COLL == my_charset_bin.number. dtype_get_pad_char(): Do not pad VARBINARY or BINARY columns. row_ins_cascade_calc_update_vec(): Refuse ON UPDATE CASCADE when trying to change the length of a VARBINARY column that refers to or is referenced by a BINARY column. BINARY columns are no longer padded on comparison, and thus they cannot be padded on storage either. #14747: "Race condition can cause btr_search_drop_page_hash_index() to crash" Note that buf_block_t::index should be protected by btr_search_latch or an s-latch or x-latch on the index page. btr_search_drop_page_hash_index(): Read block->index while holding btr_search_latch and use the cached value in the loop. Remove some redundant assertions. #15108: "mysqld crashes when innodb_log_file_size is set > 4G" #15308: "Problem of Order with Enum Column in Primary Key" #15550: "mysqld crashes in printing a FOREIGN KEY error in InnoDB" row_ins_foreign_report_add_err(): When printing the parent record, use the index in the parent table rather than the index in the child table. #15653: "Slow inserts to InnoDB if many thousands of .ibd files" Keep track on unflushed modifications to file spaces. When there are tens of thousands of file spaces, flushing all files in fil_flush_file_spaces() would be very slow. fil_flush_file_spaces(): Only flush unflushed file spaces. fil_space_t, fil_system_t: Add a list of unflushed spaces. #15991: "innodb-file-per-table + symlink database + rename = cr" os_file_handle_error(): Map the error codes EXDEV, ENOTDIR, and EISDIR to the new code OS_FILE_PATH_ERROR. Treat this code as OS_FILE_PATH_ERROR. This fixes the crash on RENAME TABLE when the .ibd file is a symbolic link to a different file system. #16157: "InnoDB crashes when main location settings are empty" This patch is from Heikki. #16298: "InnoDB segfaults in INSERTs in upgrade of 4.0 -> 5.0 tables with VARCHAR BINARY" dict_load_columns(): Set the charset-collation code DATA_MYSQL_BINARY_CHARSET_COLL for those binary string columns that lack a charset-collation code, i.e., the tables were created with an older version of MySQL/InnoDB than 4.1.2. #16229: "MySQL/InnoDB uses full explicit table locks in trigger processing" Take a InnoDB table lock only if user has explicitly requested a table lock. Added some additional comments to store_lock() and external_lock(). #16387: "InnoDB crash when dropping a foreign key <table>_ibfk_0" Do not mistake TABLENAME_ibfk_0 for auto-generated id. dict_table_get_highest_foreign_id(): Ignore foreign constraint identifiers starting with the pattern TABLENAME_ibfk_0. #16582: "InnoDB: Error in an adaptive hash index pointer to page" Account for a race condition when dropping the adaptive hash index for a B-tree page. btr_search_drop_page_hash_index(): Retry the operation if a hash index with different parameters was built meanwhile. Add diagnostics for the case that hash node pointers to the page remain. btr_search_info_update_hash(), btr_search_info_update_slow(): Document the parameter "info" as in/out. #16814: "SHOW INNODB STATUS format error in LATEST FOREIGN KEY ERROR section" Add a missing newline to the LAST FOREIGN KEY ERROR section in SHOW INNODB STATUS output. dict_foreign_error_report(): Always print a newline after invoking dict_print_info_on_foreign_key_in_create_format(). #16827: "Better InnoDB error message if ibdata files omitted from my.cnf" #17126: "CHECK TABLE on InnoDB causes a short hang during check of adaptive hash" CHECK TABLE blocking other queries, by releasing the btr_search_latch periodically during the adaptive hash table validation. #17405: "Valgrind: conditional jump or move depends on unititialised values" buf_block_init(): Reset magic_n, buf_fix_count and io_fix to avoid testing uninitialized variables.
233 lines
6.8 KiB
Text
233 lines
6.8 KiB
Text
/******************************************************
|
|
Insert buffer
|
|
|
|
(c) 1997 Innobase Oy
|
|
|
|
Created 7/19/1997 Heikki Tuuri
|
|
*******************************************************/
|
|
|
|
#include "buf0lru.h"
|
|
#include "page0page.h"
|
|
|
|
extern ulint ibuf_flush_count;
|
|
|
|
/* If this number is n, an index page must contain at least the page size
|
|
per n bytes of free space for ibuf to try to buffer inserts to this page.
|
|
If there is this much of free space, the corresponding bits are set in the
|
|
ibuf bitmap. */
|
|
#define IBUF_PAGE_SIZE_PER_FREE_SPACE 32
|
|
|
|
/* Insert buffer data struct for a single tablespace */
|
|
struct ibuf_data_struct{
|
|
ulint space; /* space id */
|
|
ulint seg_size;/* allocated pages if the file segment
|
|
containing ibuf header and tree */
|
|
ulint size; /* size of the insert buffer tree in pages */
|
|
ibool empty; /* after an insert to the ibuf tree is
|
|
performed, this is set to FALSE, and if a
|
|
contract operation finds the tree empty, this
|
|
is set to TRUE */
|
|
ulint free_list_len;
|
|
/* length of the free list */
|
|
ulint height; /* tree height */
|
|
dict_index_t* index; /* insert buffer index */
|
|
UT_LIST_NODE_T(ibuf_data_t) data_list;
|
|
/* list of ibuf data structs */
|
|
ulint n_inserts;/* number of inserts made to the insert
|
|
buffer */
|
|
ulint n_merges;/* number of pages merged */
|
|
ulint n_merged_recs;/* number of records merged */
|
|
};
|
|
|
|
/* If the ibuf meter exceeds this value, then the suitable inserts are made to
|
|
the insert buffer instead of directly to the disk page */
|
|
#define IBUF_THRESHOLD 50
|
|
|
|
struct ibuf_struct{
|
|
ulint size; /* current size of the ibuf index
|
|
trees in pages */
|
|
ulint max_size; /* recommended maximum size in pages
|
|
for the ibuf index tree */
|
|
ulint meter; /* heuristic meter which measures
|
|
desirability of doing inserts to the
|
|
insert buffer instead of directly to
|
|
the disk page */
|
|
UT_LIST_BASE_NODE_T(ibuf_data_t) data_list;
|
|
/* list of ibuf data structs for
|
|
each tablespace */
|
|
};
|
|
|
|
/****************************************************************************
|
|
Sets the free bit of the page in the ibuf bitmap. This is done in a separate
|
|
mini-transaction, hence this operation does not restrict further work to only
|
|
ibuf bitmap operations, which would result if the latch to the bitmap page
|
|
were kept. */
|
|
|
|
void
|
|
ibuf_set_free_bits(
|
|
/*===============*/
|
|
ulint type, /* in: index type */
|
|
page_t* page, /* in: index page; free bit is reset if the index is
|
|
a non-clustered non-unique, and page level is 0 */
|
|
ulint val, /* in: value to set: < 4 */
|
|
ulint max_val);/* in: ULINT_UNDEFINED or a maximum value which
|
|
the bits must have before setting; this is for
|
|
debugging */
|
|
|
|
/**************************************************************************
|
|
A basic partial test if an insert to the insert buffer could be possible and
|
|
recommended. */
|
|
UNIV_INLINE
|
|
ibool
|
|
ibuf_should_try(
|
|
/*============*/
|
|
dict_index_t* index, /* in: index where to insert */
|
|
ulint ignore_sec_unique) /* in: if != 0, we should
|
|
ignore UNIQUE constraint on
|
|
a secondary index when we
|
|
decide */
|
|
{
|
|
if (!(index->type & DICT_CLUSTERED)
|
|
&& (ignore_sec_unique || !(index->type & DICT_UNIQUE))
|
|
&& ibuf->meter > IBUF_THRESHOLD) {
|
|
|
|
ibuf_flush_count++;
|
|
|
|
if (ibuf_flush_count % 8 == 0) {
|
|
|
|
buf_LRU_try_free_flushed_blocks();
|
|
}
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
return(FALSE);
|
|
}
|
|
|
|
/***************************************************************************
|
|
Checks if a page address is an ibuf bitmap page address. */
|
|
UNIV_INLINE
|
|
ibool
|
|
ibuf_bitmap_page(
|
|
/*=============*/
|
|
/* out: TRUE if a bitmap page */
|
|
ulint page_no)/* in: page number */
|
|
{
|
|
if (page_no % XDES_DESCRIBED_PER_PAGE == FSP_IBUF_BITMAP_OFFSET) {
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
return(FALSE);
|
|
}
|
|
|
|
/*************************************************************************
|
|
Translates the free space on a page to a value in the ibuf bitmap.*/
|
|
UNIV_INLINE
|
|
ulint
|
|
ibuf_index_page_calc_free_bits(
|
|
/*===========================*/
|
|
/* out: value for ibuf bitmap bits */
|
|
ulint max_ins_size) /* in: maximum insert size after reorganize
|
|
for the page */
|
|
{
|
|
ulint n;
|
|
|
|
n = max_ins_size / (UNIV_PAGE_SIZE / IBUF_PAGE_SIZE_PER_FREE_SPACE);
|
|
|
|
if (n == 3) {
|
|
n = 2;
|
|
}
|
|
|
|
if (n > 3) {
|
|
n = 3;
|
|
}
|
|
|
|
return(n);
|
|
}
|
|
|
|
/*************************************************************************
|
|
Translates the ibuf free bits to the free space on a page in bytes. */
|
|
UNIV_INLINE
|
|
ulint
|
|
ibuf_index_page_calc_free_from_bits(
|
|
/*================================*/
|
|
/* out: maximum insert size after reorganize for the
|
|
page */
|
|
ulint bits) /* in: value for ibuf bitmap bits */
|
|
{
|
|
ut_ad(bits < 4);
|
|
|
|
if (bits == 3) {
|
|
return(4 * UNIV_PAGE_SIZE / IBUF_PAGE_SIZE_PER_FREE_SPACE);
|
|
}
|
|
|
|
return(bits * UNIV_PAGE_SIZE / IBUF_PAGE_SIZE_PER_FREE_SPACE);
|
|
}
|
|
|
|
/*************************************************************************
|
|
Translates the free space on a page to a value in the ibuf bitmap.*/
|
|
UNIV_INLINE
|
|
ulint
|
|
ibuf_index_page_calc_free(
|
|
/*======================*/
|
|
/* out: value for ibuf bitmap bits */
|
|
page_t* page) /* in: non-unique secondary index page */
|
|
{
|
|
return(ibuf_index_page_calc_free_bits(
|
|
page_get_max_insert_size_after_reorganize(page, 1)));
|
|
}
|
|
|
|
/****************************************************************************
|
|
Updates the free bits of the page in the ibuf bitmap if there is not enough
|
|
free on the page any more. This is done in a separate mini-transaction, hence
|
|
this operation does not restrict further work to only ibuf bitmap operations,
|
|
which would result if the latch to the bitmap page were kept. */
|
|
UNIV_INLINE
|
|
void
|
|
ibuf_update_free_bits_if_full(
|
|
/*==========================*/
|
|
dict_index_t* index, /* in: index */
|
|
page_t* page, /* in: index page to which we have added new
|
|
records; the free bits are updated if the
|
|
index is non-clustered and non-unique and
|
|
the page level is 0, and the page becomes
|
|
fuller */
|
|
ulint max_ins_size,/* in: value of maximum insert size with
|
|
reorganize before the latest operation
|
|
performed to the page */
|
|
ulint increase)/* in: upper limit for the additional space
|
|
used in the latest operation, if known, or
|
|
ULINT_UNDEFINED */
|
|
{
|
|
ulint before;
|
|
ulint after;
|
|
|
|
before = ibuf_index_page_calc_free_bits(max_ins_size);
|
|
|
|
if (max_ins_size >= increase) {
|
|
#if ULINT32_UNDEFINED <= UNIV_PAGE_SIZE
|
|
# error "ULINT32_UNDEFINED <= UNIV_PAGE_SIZE"
|
|
#endif
|
|
after = ibuf_index_page_calc_free_bits(max_ins_size
|
|
- increase);
|
|
#ifdef UNIV_IBUF_DEBUG
|
|
ut_a(after <= ibuf_index_page_calc_free(page));
|
|
#endif
|
|
} else {
|
|
after = ibuf_index_page_calc_free(page);
|
|
}
|
|
|
|
if (after == 0) {
|
|
/* We move the page to the front of the buffer pool LRU list:
|
|
the purpose of this is to prevent those pages to which we
|
|
cannot make inserts using the insert buffer from slipping
|
|
out of the buffer pool */
|
|
|
|
buf_page_make_young(page);
|
|
}
|
|
|
|
if (before > after) {
|
|
ibuf_set_free_bits(index->type, page, after, before);
|
|
}
|
|
}
|