mirror of
https://github.com/MariaDB/server.git
synced 2025-01-23 07:14:17 +01:00
ca9b46f71a
* Fix BUG#15650: "DELETE with LEFT JOIN crashes server with innodb_locks_unsafe_for binlog" * Fix BUG#17134: "Partitions: uncommitted changes are visible" * Fix BUG#17992: "Partitions: InnoDB, somehow rotten table after UPDATE" row0ins.c: MySQL's partitioned table code does not set preduilt->sql_stat_start right if it does an insert in the same statement after doing a search first in the same partition table. We now write trx id always to the buffer, not just when flag sql_stat_start is on. This will waste CPU time very sightly. * Fix BUG#18077: "InnoDB uses full explicit table locks in stored FUNCTION" * Fix BUG#18238: "When locks exhaust the buffer pool, InnoDB does not roll back the trx" * Fix BUG#18252" "Disk space leak in updates of InnoDB BLOB rows in 5.0 and 5.1" * Fix BUG#18283: "When InnoDB returns error 'lock table full', MySQL can write to binlog too much" * Fix BUG#18350: "Use consistent read in CREATE ... SELECT ... if innodb_locks_unsafe_for_binlog" * Fix BUG#18384: "InnoDB memory leak on duplicate key errors in 5.0 if row has many columns" * Fix BUG#18934: "InnoDB crashes when table uses column names like DB_ROW_ID" Refuse tables that use reserved column names. * InnoDB's SQL parser: - Add support for UNSIGNED types, EXIT keyword, quoted identifiers, user-function callbacks for processing results of FETCH statements, bound literals, DATA_VARCHAR for bound literals. - Allow bound literals of type non-INTEGER to be of length 0. - Add make_flex.sh and update lexer/parser generation documentation. - Add comment clarifying the difference between 'alias' and 'indirection' fields in sym_node_t. - Remove never reached duplicate code in pars_set_dfield_type(). - Rewrite pars_info datatypes and APIs, add a few helper functions. - Since the functions definitions in pars_info_t are accessed after pars_sql() returns in the query graph execution stage, we can't free pars_info_t in pars_sql(). Instead, make pars_sql() transfer ownership of pars_info_t to the created query graph, and make que_graph_free() free it if needed. - Allow access to system columns like DB_ROW_ID. * Use bound literals in row_truncate_table_for_mysql, row_drop_table_for_mysql, row_discard_tablespace_for_mysql, and row_rename_table_for_mysql. * Setting an isolation level of the transaction to read committed weakens the locks for this session similarly like the option innodb_locks_unsafe_for binlog. This patch removes alnost all gap locking (used in next-key locking) and makes MySQL to release the row locks on the rows which does not belong to result set. Additionally, nonlocking selects on INSERT INTO SELECT, UPDATE ... (SELECT ...), and CREATE ... SELECT ... use a nonlocking consistent read. If a binlog is used, then binlog format should be set to row based binloging to make the execution of the complex SQL statements. * Disable the statistic variables btr_search_n_hash_fail and n_hash_succ, n_hash_fail, n_patt_succ, and n_searches of btr_search_t in builds without #ifdef UNIV_SEARCH_PERF_STAT. * Make innodb.test faster. Group all consistent read test cases to a one test case and wait their lock timeout after all have been send to the server. Decrease amount of rows inserted in a certain test - this has no effect on the effectiveness of the test and reduces the running time by ~10 sec. Remove temporary work-arounds from innodb.result now that ALTER TABLE DROP FOREIGN KEY works once again. * Make innodb_unsafe_binlog.test faster. Grout all consistent read test cases to a one test case amd wait their lock timeout after all have been sent to the server. Remove unnecessary option --loose_innodb_lock_wait_timeout. * Print dictionary memory size in SHOW INNODB STATUS. * Fix memory leaks in row_create_table_for_mysql() in rare corner cases. * Remove code related to clustered tables. They were never implemented, and the implementation would be challenging with ROW_FORMAT=COMPACT. Remove the table types DICT_TABLE_CLUSTER_MEMBER and DICT_TABLE_CLUSTER and all related tests and functions. dict_table_t: Remove mix_id, mix_len, mix_id_len, mix_id_buf, and cluster_name. plan_t: Remove mixed_index. dict_create_sys_tables_tuple(): Set MIX_ID=0, MIX_LEN=0, CLUSTER_NAME=NULL when inserting into SYS_TABLES. dict_tree_check_search_tuple(): Enclose in #ifdef UNIV_DEBUG. * Move calling of thr_local_free() from trx_free_for_mysql() to innobase_close_connection(). mysql-test/r/innodb.result: Applied innodb-5.1-ss475 snapshot. mysql-test/r/innodb_unsafe_binlog.result: Applied innodb-5.1-ss475 snapshot. mysql-test/t/innodb-master.opt: Applied innodb-5.1-ss475 snapshot. mysql-test/t/innodb.test: Applied innodb-5.1-ss475 snapshot. mysql-test/t/innodb_unsafe_binlog-master.opt: Applied innodb-5.1-ss475 snapshot. mysql-test/t/innodb_unsafe_binlog.test: Applied innodb-5.1-ss475 snapshot. sql/ha_innodb.cc: Applied innodb-5.1-ss475 snapshot. Do not use inlined functions in ha_innodb.cc. Remove assertion ut_error which crashes the mysqld server if it prints a warning about the adaptive latch. storage/innobase/Makefile.am: Applied innodb-5.1-ss475 snapshot. storage/innobase/btr/btr0btr.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/btr/btr0cur.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/btr/btr0pcur.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/btr/btr0sea.c: Applied innodb-5.1-ss475 snapshot. Fix compilation problem with non-C99 compilers. storage/innobase/buf/buf0lru.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/cmakelists.txt: Applied innodb-5.1-ss475 snapshot. storage/innobase/configure.in: Applied innodb-5.1-ss475 snapshot. Add disabled-by-default logic to switch GCC to a strict C89-mode. Add -Werror-implicit-function_declaration to CFLAGS when using gcc. storage/innobase/data/data0type.c: Applied innodb-5.1-ss475 snapshot. dtype_print(): Recognize DATA_FIXBINARY and DATA_BLOB types. Print known flags from prtype. Use a switch statement instead of else-if chain. storage/innobase/dict/dict0crea.c: Applied innodb-5.1-ss475 snapshot. Use bound literals in all SQL statements instead of elaborately constructing correctly allocated and quoted strings to pass the data in ASCII form. storage/innobase/dict/dict0dict.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/dict/dict0load.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/dict/dict0mem.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/eval/eval0proc.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/ibuf/ibuf0ibuf.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/btr0cur.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/btr0cur.ic: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/btr0sea.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/buf0lru.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/dict0dict.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/dict0dict.ic: Applied innodb-5.1-ss475 snapshot. Remove too strict assertions from some dict_table_t accessor functions. storage/innobase/include/dict0mem.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/eval0proc.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/hash0hash.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/lock0lock.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/mem0mem.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/page0page.ic: Applied innodb-5.1-ss475 snapshot. Remove UNIV_RELEASE_NOT_YET_STABLE and related checks. storage/innobase/include/pars0grm.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/pars0pars.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/pars0sym.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/pars0types.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/que0que.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/row0mysql.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/row0sel.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/row0upd.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/trx0trx.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/univ.i: Applied innodb-5.1-ss475 snapshot. Remove UNIV_RELEASE_NOT_YET_STABLE and related checks. When using GCC, use __inline__ instead of inline. storage/innobase/include/ut0mem.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/lock/lock0lock.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/log/log0recv.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/mem/mem0dbg.c: Applied innodb-5.1-ss475 snapshot. Add (void*) cast when using the %p printf format specifier. storage/innobase/mem/mem0mem.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/os/os0sync.c: Applied innodb-5.1-ss475 snapshot. Add (void*) cast when using the %p printf format specifier. storage/innobase/pars/lexyy.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/pars/make_bison.sh: Applied innodb-5.1-ss475 snapshot. storage/innobase/pars/pars0grm.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/pars/pars0grm.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/pars/pars0grm.y: Applied innodb-5.1-ss475 snapshot. storage/innobase/pars/pars0lex.l: Applied innodb-5.1-ss475 snapshot. storage/innobase/pars/pars0opt.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/pars/pars0pars.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/pars/pars0sym.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/que/que0que.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/row/row0ins.c: Applied innodb-5.1-ss475 snapshot. Remove a memory leak when trying to insert a duplicate record to a clustered inedx comprising more than about 90 columns (Bug#18384). row_ins_duplicate_error_in_clust(): Call mem_heap_free(heap) at func_exit if needed. storage/innobase/row/row0mysql.c: Applied innodb-5.1-ss475 snapshot. row_mysql_is_system_table(): Use strncmp, not memcmp, since we don't know how long the input string is. storage/innobase/row/row0sel.c: Applied innodb-5.1-ss475 snapshot. Remove UNIV_RELEASE_NOT_YET_STABLE and related checks. row_sel_field_store_in_mysql_format(): Turn the assertions on mbminlen, mbmaxlen, and templ->type into debug assertions. fetch_step(): Print a more usefull error message when the cursor is closed. storage/innobase/row/row0upd.c: Applied innodb-5.1-ss475 snapshot. row_upd_index_replace_new_col_vals_index_pos(): Add a parameter order_only for limiting the replacement to the ordering fields of the index. storage/innobase/srv/srv0srv.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/sync/sync0arr.c: Applied innodb-5.1-ss475 snapshot. Add (void*) cast when using the %p printf format specifier. storage/innobase/sync/sync0rw.c: Applied innodb-5.1-ss475 snapshot. Add (void*) cast when using the %p printf format specifier. storage/innobase/sync/sync0sync.c: Applied innodb-5.1-ss475 snapshot. Add (void*) cast when using the %p printf format specifier. storage/innobase/trx/trx0trx.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/ut/Makefile.am: Applied innodb-5.1-ss475 snapshot. storage/innobase/ut/ut0mem.c: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/ut0vec.h: Applied innodb-5.1-ss475 snapshot. storage/innobase/include/ut0vec.ic: Applied innodb-5.1-ss475 snapshot. storage/innobase/pars/make_flex.sh: Applied innodb-5.1-ss475 snapshot. storage/innobase/ut/ut0vec.c: Applied innodb-5.1-ss475 snapshot.
828 lines
21 KiB
Text
828 lines
21 KiB
Text
/******************************************************
|
|
Index page routines
|
|
|
|
(c) 1994-1996 Innobase Oy
|
|
|
|
Created 2/2/1994 Heikki Tuuri
|
|
*******************************************************/
|
|
|
|
#include "mach0data.h"
|
|
#include "rem0cmp.h"
|
|
#include "mtr0log.h"
|
|
|
|
#ifdef UNIV_MATERIALIZE
|
|
#undef UNIV_INLINE
|
|
#define UNIV_INLINE
|
|
#endif
|
|
|
|
/*****************************************************************
|
|
Returns the max trx id field value. */
|
|
UNIV_INLINE
|
|
dulint
|
|
page_get_max_trx_id(
|
|
/*================*/
|
|
page_t* page) /* in: page */
|
|
{
|
|
ut_ad(page);
|
|
|
|
return(mach_read_from_8(page + PAGE_HEADER + PAGE_MAX_TRX_ID));
|
|
}
|
|
|
|
/*****************************************************************
|
|
Sets the max trx id field value if trx_id is bigger than the previous
|
|
value. */
|
|
UNIV_INLINE
|
|
void
|
|
page_update_max_trx_id(
|
|
/*===================*/
|
|
page_t* page, /* in: page */
|
|
dulint trx_id) /* in: transaction id */
|
|
{
|
|
ut_ad(page);
|
|
|
|
if (ut_dulint_cmp(page_get_max_trx_id(page), trx_id) < 0) {
|
|
|
|
page_set_max_trx_id(page, trx_id);
|
|
}
|
|
}
|
|
|
|
/*****************************************************************
|
|
Reads the given header field. */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_header_get_field(
|
|
/*==================*/
|
|
page_t* page, /* in: page */
|
|
ulint field) /* in: PAGE_LEVEL, ... */
|
|
{
|
|
ut_ad(page);
|
|
ut_ad(field <= PAGE_INDEX_ID);
|
|
|
|
return(mach_read_from_2(page + PAGE_HEADER + field));
|
|
}
|
|
|
|
/*****************************************************************
|
|
Sets the given header field. */
|
|
UNIV_INLINE
|
|
void
|
|
page_header_set_field(
|
|
/*==================*/
|
|
page_t* page, /* in: page */
|
|
ulint field, /* in: PAGE_LEVEL, ... */
|
|
ulint val) /* in: value */
|
|
{
|
|
ut_ad(page);
|
|
ut_ad(field <= PAGE_N_RECS);
|
|
ut_ad(field == PAGE_N_HEAP || val < UNIV_PAGE_SIZE);
|
|
ut_ad(field != PAGE_N_HEAP || (val & 0x7fff) < UNIV_PAGE_SIZE);
|
|
|
|
mach_write_to_2(page + PAGE_HEADER + field, val);
|
|
}
|
|
|
|
/*****************************************************************
|
|
Returns the pointer stored in the given header field. */
|
|
UNIV_INLINE
|
|
byte*
|
|
page_header_get_ptr(
|
|
/*================*/
|
|
/* out: pointer or NULL */
|
|
page_t* page, /* in: page */
|
|
ulint field) /* in: PAGE_FREE, ... */
|
|
{
|
|
ulint offs;
|
|
|
|
ut_ad(page);
|
|
ut_ad((field == PAGE_FREE)
|
|
|| (field == PAGE_LAST_INSERT)
|
|
|| (field == PAGE_HEAP_TOP));
|
|
|
|
offs = page_header_get_field(page, field);
|
|
|
|
ut_ad((field != PAGE_HEAP_TOP) || offs);
|
|
|
|
if (offs == 0) {
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
return(page + offs);
|
|
}
|
|
|
|
/*****************************************************************
|
|
Sets the pointer stored in the given header field. */
|
|
UNIV_INLINE
|
|
void
|
|
page_header_set_ptr(
|
|
/*================*/
|
|
page_t* page, /* in: page */
|
|
ulint field, /* in: PAGE_FREE, ... */
|
|
byte* ptr) /* in: pointer or NULL*/
|
|
{
|
|
ulint offs;
|
|
|
|
ut_ad(page);
|
|
ut_ad((field == PAGE_FREE)
|
|
|| (field == PAGE_LAST_INSERT)
|
|
|| (field == PAGE_HEAP_TOP));
|
|
|
|
if (ptr == NULL) {
|
|
offs = 0;
|
|
} else {
|
|
offs = ptr - page;
|
|
}
|
|
|
|
ut_ad((field != PAGE_HEAP_TOP) || offs);
|
|
|
|
page_header_set_field(page, field, offs);
|
|
}
|
|
|
|
/*****************************************************************
|
|
Resets the last insert info field in the page header. Writes to mlog
|
|
about this operation. */
|
|
UNIV_INLINE
|
|
void
|
|
page_header_reset_last_insert(
|
|
/*==========================*/
|
|
page_t* page, /* in: page */
|
|
mtr_t* mtr) /* in: mtr */
|
|
{
|
|
ut_ad(page && mtr);
|
|
|
|
mlog_write_ulint(page + PAGE_HEADER + PAGE_LAST_INSERT, 0,
|
|
MLOG_2BYTES, mtr);
|
|
}
|
|
|
|
/****************************************************************
|
|
Determine whether the page is in new-style compact format. */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_is_comp(
|
|
/*=========*/
|
|
/* out: nonzero if the page is in compact
|
|
format, zero if it is in old-style format */
|
|
page_t* page) /* in: index page */
|
|
{
|
|
return(UNIV_EXPECT(page_header_get_field(page, PAGE_N_HEAP) & 0x8000,
|
|
0x8000));
|
|
}
|
|
|
|
/****************************************************************
|
|
TRUE if the record is on a page in compact format. */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_rec_is_comp(
|
|
/*=============*/
|
|
/* out: nonzero if in compact format */
|
|
const rec_t* rec) /* in: record */
|
|
{
|
|
return(page_is_comp(ut_align_down((rec_t*) rec, UNIV_PAGE_SIZE)));
|
|
}
|
|
|
|
/****************************************************************
|
|
Gets the first record on the page. */
|
|
UNIV_INLINE
|
|
rec_t*
|
|
page_get_infimum_rec(
|
|
/*=================*/
|
|
/* out: the first record in record list */
|
|
page_t* page) /* in: page which must have record(s) */
|
|
{
|
|
ut_ad(page);
|
|
|
|
if (page_is_comp(page)) {
|
|
return(page + PAGE_NEW_INFIMUM);
|
|
} else {
|
|
return(page + PAGE_OLD_INFIMUM);
|
|
}
|
|
}
|
|
|
|
/****************************************************************
|
|
Gets the last record on the page. */
|
|
UNIV_INLINE
|
|
rec_t*
|
|
page_get_supremum_rec(
|
|
/*==================*/
|
|
/* out: the last record in record list */
|
|
page_t* page) /* in: page which must have record(s) */
|
|
{
|
|
ut_ad(page);
|
|
|
|
if (page_is_comp(page)) {
|
|
return(page + PAGE_NEW_SUPREMUM);
|
|
} else {
|
|
return(page + PAGE_OLD_SUPREMUM);
|
|
}
|
|
}
|
|
|
|
/****************************************************************
|
|
TRUE if the record is a user record on the page. */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_rec_is_user_rec_low(
|
|
/*=====================*/
|
|
/* out: TRUE if a user record */
|
|
ulint offset) /* in: record offset on page */
|
|
{
|
|
ut_ad(offset >= PAGE_NEW_INFIMUM);
|
|
#if PAGE_OLD_INFIMUM < PAGE_NEW_INFIMUM
|
|
# error "PAGE_OLD_INFIMUM < PAGE_NEW_INFIMUM"
|
|
#endif
|
|
#if PAGE_OLD_SUPREMUM < PAGE_NEW_SUPREMUM
|
|
# error "PAGE_OLD_SUPREMUM < PAGE_NEW_SUPREMUM"
|
|
#endif
|
|
#if PAGE_NEW_INFIMUM > PAGE_OLD_SUPREMUM
|
|
# error "PAGE_NEW_INFIMUM > PAGE_OLD_SUPREMUM"
|
|
#endif
|
|
#if PAGE_OLD_INFIMUM > PAGE_NEW_SUPREMUM
|
|
# error "PAGE_OLD_INFIMUM > PAGE_NEW_SUPREMUM"
|
|
#endif
|
|
#if PAGE_NEW_SUPREMUM > PAGE_OLD_SUPREMUM_END
|
|
# error "PAGE_NEW_SUPREMUM > PAGE_OLD_SUPREMUM_END"
|
|
#endif
|
|
#if PAGE_OLD_SUPREMUM > PAGE_NEW_SUPREMUM_END
|
|
# error "PAGE_OLD_SUPREMUM > PAGE_NEW_SUPREMUM_END"
|
|
#endif
|
|
ut_ad(offset <= UNIV_PAGE_SIZE - PAGE_EMPTY_DIR_START);
|
|
|
|
return(UNIV_LIKELY(offset != PAGE_NEW_SUPREMUM)
|
|
&& UNIV_LIKELY(offset != PAGE_NEW_INFIMUM)
|
|
&& UNIV_LIKELY(offset != PAGE_OLD_INFIMUM)
|
|
&& UNIV_LIKELY(offset != PAGE_OLD_SUPREMUM));
|
|
}
|
|
|
|
/****************************************************************
|
|
TRUE if the record is the supremum record on a page. */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_rec_is_supremum_low(
|
|
/*=====================*/
|
|
/* out: TRUE if the supremum record */
|
|
ulint offset) /* in: record offset on page */
|
|
{
|
|
ut_ad(offset >= PAGE_NEW_INFIMUM);
|
|
ut_ad(offset <= UNIV_PAGE_SIZE - PAGE_EMPTY_DIR_START);
|
|
|
|
return(UNIV_UNLIKELY(offset == PAGE_NEW_SUPREMUM)
|
|
|| UNIV_UNLIKELY(offset == PAGE_OLD_SUPREMUM));
|
|
}
|
|
|
|
/****************************************************************
|
|
TRUE if the record is the infimum record on a page. */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_rec_is_infimum_low(
|
|
/*====================*/
|
|
/* out: TRUE if the infimum record */
|
|
ulint offset) /* in: record offset on page */
|
|
{
|
|
ut_ad(offset >= PAGE_NEW_INFIMUM);
|
|
ut_ad(offset <= UNIV_PAGE_SIZE - PAGE_EMPTY_DIR_START);
|
|
|
|
return(UNIV_UNLIKELY(offset == PAGE_NEW_INFIMUM)
|
|
|| UNIV_UNLIKELY(offset == PAGE_OLD_INFIMUM));
|
|
}
|
|
|
|
/****************************************************************
|
|
TRUE if the record is a user record on the page. */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_rec_is_user_rec(
|
|
/*=================*/
|
|
/* out: TRUE if a user record */
|
|
const rec_t* rec) /* in: record */
|
|
{
|
|
return(page_rec_is_user_rec_low(
|
|
ut_align_offset(rec, UNIV_PAGE_SIZE)));
|
|
}
|
|
|
|
/****************************************************************
|
|
TRUE if the record is the supremum record on a page. */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_rec_is_supremum(
|
|
/*=================*/
|
|
/* out: TRUE if the supremum record */
|
|
const rec_t* rec) /* in: record */
|
|
{
|
|
return(page_rec_is_supremum_low(
|
|
ut_align_offset(rec, UNIV_PAGE_SIZE)));
|
|
}
|
|
|
|
/****************************************************************
|
|
TRUE if the record is the infimum record on a page. */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_rec_is_infimum(
|
|
/*================*/
|
|
/* out: TRUE if the infimum record */
|
|
const rec_t* rec) /* in: record */
|
|
{
|
|
return(page_rec_is_infimum_low(
|
|
ut_align_offset(rec, UNIV_PAGE_SIZE)));
|
|
}
|
|
|
|
/*****************************************************************
|
|
Compares a data tuple to a physical record. Differs from the function
|
|
cmp_dtuple_rec_with_match in the way that the record must reside on an
|
|
index page, and also page infimum and supremum records can be given in
|
|
the parameter rec. These are considered as the negative infinity and
|
|
the positive infinity in the alphabetical order. */
|
|
UNIV_INLINE
|
|
int
|
|
page_cmp_dtuple_rec_with_match(
|
|
/*===========================*/
|
|
/* out: 1, 0, -1, if dtuple is greater, equal,
|
|
less than rec, respectively, when only the
|
|
common first fields are compared */
|
|
dtuple_t* dtuple, /* in: data tuple */
|
|
rec_t* rec, /* in: physical record on a page; may also
|
|
be page infimum or supremum, in which case
|
|
matched-parameter values below are not
|
|
affected */
|
|
const ulint* offsets,/* in: array returned by rec_get_offsets() */
|
|
ulint* matched_fields, /* in/out: number of already completely
|
|
matched fields; when function returns
|
|
contains the value for current comparison */
|
|
ulint* matched_bytes) /* in/out: number of already matched
|
|
bytes within the first field not completely
|
|
matched; when function returns contains the
|
|
value for current comparison */
|
|
{
|
|
ulint rec_offset;
|
|
|
|
ut_ad(dtuple_check_typed(dtuple));
|
|
ut_ad(rec_offs_validate(rec, NULL, offsets));
|
|
ut_ad(!rec_offs_comp(offsets) == !page_rec_is_comp(rec));
|
|
|
|
rec_offset = ut_align_offset(rec, UNIV_PAGE_SIZE);
|
|
|
|
if (UNIV_UNLIKELY(rec_offset == PAGE_NEW_INFIMUM)
|
|
|| UNIV_UNLIKELY(rec_offset == PAGE_OLD_INFIMUM)) {
|
|
return(1);
|
|
}
|
|
if (UNIV_UNLIKELY(rec_offset == PAGE_NEW_SUPREMUM)
|
|
|| UNIV_UNLIKELY(rec_offset == PAGE_OLD_SUPREMUM)) {
|
|
return(-1);
|
|
}
|
|
|
|
return(cmp_dtuple_rec_with_match(dtuple, rec, offsets,
|
|
matched_fields,
|
|
matched_bytes));
|
|
}
|
|
|
|
/*****************************************************************
|
|
Gets the number of user records on page (infimum and supremum records
|
|
are not user records). */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_get_n_recs(
|
|
/*============*/
|
|
/* out: number of user records */
|
|
page_t* page) /* in: index page */
|
|
{
|
|
return(page_header_get_field(page, PAGE_N_RECS));
|
|
}
|
|
|
|
/*****************************************************************
|
|
Gets the number of dir slots in directory. */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_dir_get_n_slots(
|
|
/*=================*/
|
|
/* out: number of slots */
|
|
page_t* page) /* in: index page */
|
|
{
|
|
return(page_header_get_field(page, PAGE_N_DIR_SLOTS));
|
|
}
|
|
/*****************************************************************
|
|
Sets the number of dir slots in directory. */
|
|
UNIV_INLINE
|
|
void
|
|
page_dir_set_n_slots(
|
|
/*=================*/
|
|
/* out: number of slots */
|
|
page_t* page, /* in: index page */
|
|
ulint n_slots)/* in: number of slots */
|
|
{
|
|
page_header_set_field(page, PAGE_N_DIR_SLOTS, n_slots);
|
|
}
|
|
|
|
/*****************************************************************
|
|
Gets the number of records in the heap. */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_dir_get_n_heap(
|
|
/*================*/
|
|
/* out: number of user records */
|
|
page_t* page) /* in: index page */
|
|
{
|
|
return(page_header_get_field(page, PAGE_N_HEAP) & 0x7fff);
|
|
}
|
|
|
|
/*****************************************************************
|
|
Sets the number of records in the heap. */
|
|
UNIV_INLINE
|
|
void
|
|
page_dir_set_n_heap(
|
|
/*================*/
|
|
page_t* page, /* in: index page */
|
|
ulint n_heap) /* in: number of records */
|
|
{
|
|
ut_ad(n_heap < 0x8000);
|
|
|
|
page_header_set_field(page, PAGE_N_HEAP, n_heap | (0x8000 &
|
|
page_header_get_field(page, PAGE_N_HEAP)));
|
|
}
|
|
|
|
/*****************************************************************
|
|
Gets pointer to nth directory slot. */
|
|
UNIV_INLINE
|
|
page_dir_slot_t*
|
|
page_dir_get_nth_slot(
|
|
/*==================*/
|
|
/* out: pointer to dir slot */
|
|
page_t* page, /* in: index page */
|
|
ulint n) /* in: position */
|
|
{
|
|
ut_ad(page_dir_get_n_slots(page) > n);
|
|
|
|
return(page + UNIV_PAGE_SIZE - PAGE_DIR
|
|
- (n + 1) * PAGE_DIR_SLOT_SIZE);
|
|
}
|
|
|
|
/******************************************************************
|
|
Used to check the consistency of a record on a page. */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_rec_check(
|
|
/*===========*/
|
|
/* out: TRUE if succeed */
|
|
rec_t* rec) /* in: record */
|
|
{
|
|
page_t* page;
|
|
|
|
ut_a(rec);
|
|
|
|
page = buf_frame_align(rec);
|
|
|
|
ut_a(rec <= page_header_get_ptr(page, PAGE_HEAP_TOP));
|
|
ut_a(rec >= page + PAGE_DATA);
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
/*******************************************************************
|
|
Gets the record pointed to by a directory slot. */
|
|
UNIV_INLINE
|
|
rec_t*
|
|
page_dir_slot_get_rec(
|
|
/*==================*/
|
|
/* out: pointer to record */
|
|
page_dir_slot_t* slot) /* in: directory slot */
|
|
{
|
|
return(buf_frame_align(slot) + mach_read_from_2(slot));
|
|
}
|
|
|
|
/*******************************************************************
|
|
This is used to set the record offset in a directory slot. */
|
|
UNIV_INLINE
|
|
void
|
|
page_dir_slot_set_rec(
|
|
/*==================*/
|
|
page_dir_slot_t* slot, /* in: directory slot */
|
|
rec_t* rec) /* in: record on the page */
|
|
{
|
|
ut_ad(page_rec_check(rec));
|
|
|
|
mach_write_to_2(slot, ut_align_offset(rec, UNIV_PAGE_SIZE));
|
|
}
|
|
|
|
/*******************************************************************
|
|
Gets the number of records owned by a directory slot. */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_dir_slot_get_n_owned(
|
|
/*======================*/
|
|
/* out: number of records */
|
|
page_dir_slot_t* slot) /* in: page directory slot */
|
|
{
|
|
rec_t* rec = page_dir_slot_get_rec(slot);
|
|
return(rec_get_n_owned(rec, page_rec_is_comp(rec)));
|
|
}
|
|
|
|
/*******************************************************************
|
|
This is used to set the owned records field of a directory slot. */
|
|
UNIV_INLINE
|
|
void
|
|
page_dir_slot_set_n_owned(
|
|
/*======================*/
|
|
page_dir_slot_t* slot, /* in: directory slot */
|
|
ulint n) /* in: number of records owned
|
|
by the slot */
|
|
{
|
|
rec_t* rec = page_dir_slot_get_rec(slot);
|
|
rec_set_n_owned(rec, page_rec_is_comp(rec), n);
|
|
}
|
|
|
|
/****************************************************************
|
|
Calculates the space reserved for directory slots of a given number of
|
|
records. The exact value is a fraction number n * PAGE_DIR_SLOT_SIZE /
|
|
PAGE_DIR_SLOT_MIN_N_OWNED, and it is rounded upwards to an integer. */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_dir_calc_reserved_space(
|
|
/*=========================*/
|
|
ulint n_recs) /* in: number of records */
|
|
{
|
|
return((PAGE_DIR_SLOT_SIZE * n_recs + PAGE_DIR_SLOT_MIN_N_OWNED - 1)
|
|
/ PAGE_DIR_SLOT_MIN_N_OWNED);
|
|
}
|
|
|
|
/****************************************************************
|
|
Gets the pointer to the next record on the page. */
|
|
UNIV_INLINE
|
|
rec_t*
|
|
page_rec_get_next(
|
|
/*==============*/
|
|
/* out: pointer to next record */
|
|
rec_t* rec) /* in: pointer to record */
|
|
{
|
|
ulint offs;
|
|
page_t* page;
|
|
|
|
ut_ad(page_rec_check(rec));
|
|
|
|
page = ut_align_down(rec, UNIV_PAGE_SIZE);
|
|
|
|
offs = rec_get_next_offs(rec, page_is_comp(page));
|
|
|
|
if (UNIV_UNLIKELY(offs >= UNIV_PAGE_SIZE)) {
|
|
fprintf(stderr,
|
|
"InnoDB: Next record offset is nonsensical %lu in record at offset %lu\n"
|
|
"InnoDB: rec address %p, first buffer frame %p\n"
|
|
"InnoDB: buffer pool high end %p, buf fix count %lu\n",
|
|
(ulong)offs, (ulong)(rec - page),
|
|
rec, buf_pool->frame_zero,
|
|
buf_pool->high_end,
|
|
(ulong)buf_block_align(rec)->buf_fix_count);
|
|
buf_page_print(page);
|
|
|
|
ut_error;
|
|
}
|
|
|
|
if (UNIV_UNLIKELY(offs == 0)) {
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
return(page + offs);
|
|
}
|
|
|
|
/****************************************************************
|
|
Sets the pointer to the next record on the page. */
|
|
UNIV_INLINE
|
|
void
|
|
page_rec_set_next(
|
|
/*==============*/
|
|
rec_t* rec, /* in: pointer to record, must not be page supremum */
|
|
rec_t* next) /* in: pointer to next record, must not be page
|
|
infimum */
|
|
{
|
|
page_t* page;
|
|
ulint offs;
|
|
|
|
ut_ad(page_rec_check(rec));
|
|
ut_ad(!page_rec_is_supremum(rec));
|
|
page = ut_align_down(rec, UNIV_PAGE_SIZE);
|
|
|
|
if (next) {
|
|
ut_ad(!page_rec_is_infimum(next));
|
|
ut_ad(page == ut_align_down(next, UNIV_PAGE_SIZE));
|
|
offs = (ulint) (next - page);
|
|
} else {
|
|
offs = 0;
|
|
}
|
|
|
|
rec_set_next_offs(rec, page_is_comp(page), offs);
|
|
}
|
|
|
|
/****************************************************************
|
|
Gets the pointer to the previous record. */
|
|
UNIV_INLINE
|
|
rec_t*
|
|
page_rec_get_prev(
|
|
/*==============*/
|
|
/* out: pointer to previous record */
|
|
rec_t* rec) /* in: pointer to record, must not be page
|
|
infimum */
|
|
{
|
|
page_dir_slot_t* slot;
|
|
ulint slot_no;
|
|
rec_t* rec2;
|
|
rec_t* prev_rec = NULL;
|
|
page_t* page;
|
|
|
|
ut_ad(page_rec_check(rec));
|
|
|
|
page = ut_align_down(rec, UNIV_PAGE_SIZE);
|
|
|
|
ut_ad(!page_rec_is_infimum(rec));
|
|
|
|
slot_no = page_dir_find_owner_slot(rec);
|
|
|
|
ut_a(slot_no != 0);
|
|
|
|
slot = page_dir_get_nth_slot(page, slot_no - 1);
|
|
|
|
rec2 = page_dir_slot_get_rec(slot);
|
|
|
|
while (rec != rec2) {
|
|
prev_rec = rec2;
|
|
rec2 = page_rec_get_next(rec2);
|
|
}
|
|
|
|
ut_a(prev_rec);
|
|
|
|
return(prev_rec);
|
|
}
|
|
|
|
/*******************************************************************
|
|
Looks for the record which owns the given record. */
|
|
UNIV_INLINE
|
|
rec_t*
|
|
page_rec_find_owner_rec(
|
|
/*====================*/
|
|
/* out: the owner record */
|
|
rec_t* rec) /* in: the physical record */
|
|
{
|
|
ut_ad(page_rec_check(rec));
|
|
|
|
if (page_rec_is_comp(rec)) {
|
|
while (rec_get_n_owned(rec, TRUE) == 0) {
|
|
rec = page_rec_get_next(rec);
|
|
}
|
|
} else {
|
|
while (rec_get_n_owned(rec, FALSE) == 0) {
|
|
rec = page_rec_get_next(rec);
|
|
}
|
|
}
|
|
|
|
return(rec);
|
|
}
|
|
|
|
/****************************************************************
|
|
Returns the sum of the sizes of the records in the record list, excluding
|
|
the infimum and supremum records. */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_get_data_size(
|
|
/*===============*/
|
|
/* out: data in bytes */
|
|
page_t* page) /* in: index page */
|
|
{
|
|
ulint ret;
|
|
|
|
ret = (ulint)(page_header_get_field(page, PAGE_HEAP_TOP)
|
|
- (page_is_comp(page)
|
|
? PAGE_NEW_SUPREMUM_END
|
|
: PAGE_OLD_SUPREMUM_END)
|
|
- page_header_get_field(page, PAGE_GARBAGE));
|
|
|
|
ut_ad(ret < UNIV_PAGE_SIZE);
|
|
|
|
return(ret);
|
|
}
|
|
|
|
/*****************************************************************
|
|
Calculates free space if a page is emptied. */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_get_free_space_of_empty(
|
|
/*=========================*/
|
|
/* out: free space */
|
|
ulint comp) /* in: nonzero=compact page layout */
|
|
{
|
|
if (UNIV_LIKELY(comp)) {
|
|
return((ulint)(UNIV_PAGE_SIZE
|
|
- PAGE_NEW_SUPREMUM_END
|
|
- PAGE_DIR
|
|
- 2 * PAGE_DIR_SLOT_SIZE));
|
|
}
|
|
|
|
return((ulint)(UNIV_PAGE_SIZE
|
|
- PAGE_OLD_SUPREMUM_END
|
|
- PAGE_DIR
|
|
- 2 * PAGE_DIR_SLOT_SIZE));
|
|
}
|
|
|
|
/****************************************************************
|
|
Each user record on a page, and also the deleted user records in the heap
|
|
takes its size plus the fraction of the dir cell size /
|
|
PAGE_DIR_SLOT_MIN_N_OWNED bytes for it. If the sum of these exceeds the
|
|
value of page_get_free_space_of_empty, the insert is impossible, otherwise
|
|
it is allowed. This function returns the maximum combined size of records
|
|
which can be inserted on top of the record heap. */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_get_max_insert_size(
|
|
/*=====================*/
|
|
/* out: maximum combined size for inserted records */
|
|
page_t* page, /* in: index page */
|
|
ulint n_recs) /* in: number of records */
|
|
{
|
|
ulint occupied;
|
|
ulint free_space;
|
|
|
|
if (page_is_comp(page)) {
|
|
occupied = page_header_get_field(page, PAGE_HEAP_TOP)
|
|
- PAGE_NEW_SUPREMUM_END + page_dir_calc_reserved_space(
|
|
n_recs + page_dir_get_n_heap(page) - 2);
|
|
|
|
free_space = page_get_free_space_of_empty(TRUE);
|
|
} else {
|
|
occupied = page_header_get_field(page, PAGE_HEAP_TOP)
|
|
- PAGE_OLD_SUPREMUM_END + page_dir_calc_reserved_space(
|
|
n_recs + page_dir_get_n_heap(page) - 2);
|
|
|
|
free_space = page_get_free_space_of_empty(FALSE);
|
|
}
|
|
|
|
/* Above the 'n_recs +' part reserves directory space for the new
|
|
inserted records; the '- 2' excludes page infimum and supremum
|
|
records */
|
|
|
|
if (occupied > free_space) {
|
|
|
|
return(0);
|
|
}
|
|
|
|
return(free_space - occupied);
|
|
}
|
|
|
|
/****************************************************************
|
|
Returns the maximum combined size of records which can be inserted on top
|
|
of the record heap if a page is first reorganized. */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_get_max_insert_size_after_reorganize(
|
|
/*======================================*/
|
|
/* out: maximum combined size for inserted records */
|
|
page_t* page, /* in: index page */
|
|
ulint n_recs) /* in: number of records */
|
|
{
|
|
ulint occupied;
|
|
ulint free_space;
|
|
|
|
occupied = page_get_data_size(page)
|
|
+ page_dir_calc_reserved_space(n_recs + page_get_n_recs(page));
|
|
|
|
free_space = page_get_free_space_of_empty(page_is_comp(page));
|
|
|
|
if (occupied > free_space) {
|
|
|
|
return(0);
|
|
}
|
|
|
|
return(free_space - occupied);
|
|
}
|
|
|
|
/****************************************************************
|
|
Puts a record to free list. */
|
|
UNIV_INLINE
|
|
void
|
|
page_mem_free(
|
|
/*==========*/
|
|
page_t* page, /* in: index page */
|
|
rec_t* rec, /* in: pointer to the (origin of) record */
|
|
const ulint* offsets)/* in: array returned by rec_get_offsets() */
|
|
{
|
|
rec_t* free;
|
|
ulint garbage;
|
|
|
|
ut_ad(rec_offs_validate(rec, NULL, offsets));
|
|
ut_ad(!rec_offs_comp(offsets) == !page_rec_is_comp(rec));
|
|
free = page_header_get_ptr(page, PAGE_FREE);
|
|
|
|
page_rec_set_next(rec, free);
|
|
page_header_set_ptr(page, PAGE_FREE, rec);
|
|
|
|
#if 0 /* It's better not to destroy the user's data. */
|
|
|
|
/* Clear the data bytes of the deleted record in order to improve
|
|
the compression ratio of the page and to make it easier to read
|
|
page dumps in corruption reports. The extra bytes of the record
|
|
cannot be cleared, because page_mem_alloc() needs them in order
|
|
to determine the size of the deleted record. */
|
|
memset(rec, 0, rec_offs_data_size(offsets));
|
|
#endif
|
|
|
|
garbage = page_header_get_field(page, PAGE_GARBAGE);
|
|
|
|
page_header_set_field(page, PAGE_GARBAGE,
|
|
garbage + rec_offs_size(offsets));
|
|
}
|
|
|
|
#ifdef UNIV_MATERIALIZE
|
|
#undef UNIV_INLINE
|
|
#define UNIV_INLINE UNIV_INLINE_ORIGINAL
|
|
#endif
|