mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 23:04:20 +01:00
37312683cc
------------------------------------------------------------------------ r5971 | marko | 2009-09-23 23:03:51 +1000 (Wed, 23 Sep 2009) | 2 lines branches/zip: os_file_pwrite(): Make the code compile in InnoDB Hot Backup when the pwrite system call is not available. ------------------------------------------------------------------------ r5972 | marko | 2009-09-24 05:44:52 +1000 (Thu, 24 Sep 2009) | 5 lines branches/zip: fil_node_open_file(): In InnoDB Hot Backup, determine the page size of single-file tablespaces before computing the file node size. Otherwise, the space->size of compressed tablespaces would be computed with UNIV_PAGE_SIZE instead of key_block_size. This should fix Issue #313. ------------------------------------------------------------------------ r5973 | marko | 2009-09-24 05:53:21 +1000 (Thu, 24 Sep 2009) | 2 lines branches/zip: recv_add_to_hash_table(): Simplify obfuscated pointer arithmetics. ------------------------------------------------------------------------ r5978 | marko | 2009-09-24 17:47:56 +1000 (Thu, 24 Sep 2009) | 1 line branches/zip: Fix warnings and errors when UNIV_HOTBACKUP is defined. ------------------------------------------------------------------------ r5979 | marko | 2009-09-24 20:16:10 +1000 (Thu, 24 Sep 2009) | 4 lines branches/zip: ha_innodb.cc: Define MYSQL_PLUGIN_IMPORT when necessary. This preprocessor symbol has been recently introduced in MySQL 5.1. The InnoDB Plugin should remain source compatible with MySQL 5.1.24 and later. ------------------------------------------------------------------------ r5988 | calvin | 2009-09-26 05:14:43 +1000 (Sat, 26 Sep 2009) | 8 lines branches/zip: fix bug#47055 unconditional exit(1) on ERROR_WORKING_SET_QUOTA 1453 (0x5AD) for InnoDB backend When error ERROR_WORKING_SET_QUOTA or ERROR_NO_SYSTEM_RESOURCES occurs, yields for 100ms and retries the operation. Approved by: Heikki (on IM) ------------------------------------------------------------------------ r5992 | vasil | 2009-09-28 17:10:29 +1000 (Mon, 28 Sep 2009) | 4 lines branches/zip: Add ChangeLog entry for c5988. ------------------------------------------------------------------------ r5994 | marko | 2009-09-28 18:33:59 +1000 (Mon, 28 Sep 2009) | 17 lines branches/zip: Try to prevent the reuse of tablespace identifiers after InnoDB has crashed during table creation. Also, refuse to start if files with duplicate tablespace identifiers are encountered. fil_node_create(): Update fil_system->max_assigned_id. This should prevent the reuse of a space->id when InnoDB does a full crash recovery and invokes fil_load_single_table_tablespaces(). Normally, fil_system->max_assigned_id is initialized from SELECT MAX(ID) FROM SYS_TABLES. fil_open_single_table_tablespace(): Return FALSE when fil_space_create() fails. fil_load_single_table_tablespace(): Exit if fil_space_create() fails and innodb_force_recovery=0. rb://173 approved by Heikki Tuuri. This addresses Issue #335. ------------------------------------------------------------------------ r5995 | marko | 2009-09-28 18:52:25 +1000 (Mon, 28 Sep 2009) | 17 lines branches/zip: Do not write to PAGE_INDEX_ID after page creation, not even when restoring an uncompressed page after a compression failure. btr_page_reorganize_low(): On compression failure, do not restore those page header fields that should not be affected by the reorganization. Instead, compare the fields. page_zip_decompress(): Add the parameter ibool all, for copying all page header fields. Pass the parameter all=TRUE on block read completion, redo log application, and page_zip_validate(); pass all=FALSE in all other cases. page_zip_reorganize(): Do not restore the uncompressed page on failure. It will be restored (to pre-modification state) by the caller anyway. rb://167, Issue #346 ------------------------------------------------------------------------ r5996 | marko | 2009-09-28 22:46:02 +1000 (Mon, 28 Sep 2009) | 4 lines branches/zip: Address Issue #350 in comments. lock_rec_queue_validate(), lock_rec_queue_validate(): Note that this debug code may violate the latching order and cause deadlocks. ------------------------------------------------------------------------ r5997 | marko | 2009-09-28 23:03:58 +1000 (Mon, 28 Sep 2009) | 12 lines branches/zip: Remove an assertion failure when the InnoDB data dictionary is inconsistent with the MySQL .frm file. ha_innobase::index_read(): When the index cannot be found, return an error. ha_innobase::change_active_index(): When prebuilt->index == NULL, set also prebuilt->index_usable = FALSE. This is not needed for correctness, because prebuilt->index_usable is only checked by row_search_for_mysql(), which requires prebuilt->index != NULL. This addresses Issue #349. Approved by Heikki Tuuri over IM. ------------------------------------------------------------------------ r6005 | vasil | 2009-09-29 18:09:52 +1000 (Tue, 29 Sep 2009) | 4 lines branches/zip: ChangeLog: wrap around 78th column, not earlier. ------------------------------------------------------------------------ r6006 | vasil | 2009-09-29 20:15:25 +1000 (Tue, 29 Sep 2009) | 4 lines branches/zip: Add ChangeLog entry for the release of 1.0.4. ------------------------------------------------------------------------ r6007 | vasil | 2009-09-29 23:19:59 +1000 (Tue, 29 Sep 2009) | 6 lines branches/zip: Fix the year, should be 2009. Pointed by: Calvin ------------------------------------------------------------------------ r6026 | marko | 2009-09-30 17:18:24 +1000 (Wed, 30 Sep 2009) | 1 line branches/zip: Add some debug assertions for checking FSEG_MAGIC_N. ------------------------------------------------------------------------ r6028 | marko | 2009-09-30 23:55:23 +1000 (Wed, 30 Sep 2009) | 3 lines branches/zip: recv_no_log_write: New debug flag for tracking down Mantis Issue #347. No modifications should be made to the database while recv_apply_hashed_log_recs() is about to complete. ------------------------------------------------------------------------ r6029 | calvin | 2009-10-01 06:32:02 +1000 (Thu, 01 Oct 2009) | 4 lines branches/zip: non-functional changes Fix typo. ------------------------------------------------------------------------ r6031 | marko | 2009-10-01 21:24:33 +1000 (Thu, 01 Oct 2009) | 49 lines branches/zip: Clean up after a crash during DROP INDEX. When InnoDB crashes while dropping an index, ensure that the index will be completely dropped during crash recovery. row_merge_drop_index(): Before dropping an index, rename the index to start with TEMP_INDEX_PREFIX_STR and commit the change, so that row_merge_drop_temp_indexes() will drop the index after crash recovery if the server crashes while dropping the index. fseg_inode_try_get(): New function, forked from fseg_inode_get(). Return NULL if the file segment index node is free. fseg_inode_get(): Assert that the file segment index node is not free. fseg_free_step(): If the file segment index node is already free, print a diagnostic message and return TRUE. fsp_free_seg_inode(): Write a nonzero number to FSEG_MAGIC_N, so that allocated-and-freed file segment index nodes can be better distinguished from uninitialized ones. This is rb://174, addressing Issue #348. Tested by restarting mysqld upon the completion of the added log_write_up_to() invocation below, during DROP INDEX. The index was dropped after crash recovery, and re-issuing the DROP INDEX did not crash the server. Index: btr/btr0btr.c =================================================================== --- btr/btr0btr.c (revision 6026) +++ btr/btr0btr.c (working copy) @@ -42,6 +42,7 @@ Created 6/2/1994 Heikki Tuuri #include "ibuf0ibuf.h" #include "trx0trx.h" +#include "log0log.h" /* Latching strategy of the InnoDB B-tree -------------------------------------- @@ -873,6 +874,8 @@ leaf_loop: goto leaf_loop; } + + log_write_up_to(mtr.end_lsn, LOG_WAIT_ALL_GROUPS, TRUE); top_loop: mtr_start(&mtr); ------------------------------------------------------------------------ r6033 | calvin | 2009-10-02 06:19:46 +1000 (Fri, 02 Oct 2009) | 4 lines branches/zip: fix a typo in error message Reported as bug#47763. ------------------------------------------------------------------------ r6043 | inaam | 2009-10-06 01:45:35 +1100 (Tue, 06 Oct 2009) | 12 lines branches/zip rb://176 Do not invalidate buffer pool while an LRU batch is active. Added code to buf_pool_invalidate() to wait for the running batches to finish. This patch also resets the state of buf_pool struct at invalidation. This addresses the concern where buf_pool->freed_page_clock becomes non-zero because we read in a system tablespace page for file format info at startup. Approved by: Marko ------------------------------------------------------------------------ r6044 | pekka | 2009-10-07 01:44:54 +1100 (Wed, 07 Oct 2009) | 5 lines branches/zip: Add os_file_is_same() function for Hot Backup (inside ifdef UNIV_HOTBACKUP). This is part of the fix for Issue #186. Note! The Windows implementation is incomplete. ------------------------------------------------------------------------ r6046 | pekka | 2009-10-08 20:24:56 +1100 (Thu, 08 Oct 2009) | 3 lines branches/zip: Revert r6044 which added os_file_is_same() function (issue#186). This functionality is moved to Hot Backup source tree. ------------------------------------------------------------------------ r6048 | vasil | 2009-10-09 16:42:55 +1100 (Fri, 09 Oct 2009) | 16 lines branches/zip: When scanning a directory readdir() is called and stat() after it, if a file is deleted between the two calls stat will fail and the whole precedure will fail. Change this behavior to continue with the next entry if stat() fails because of nonexistent file. This is transparent change as it will make it look as if the file was deleted before the readdir() call. This change is needed in order to fix https://svn.innodb.com/mantis/view.php?id=174 in which we need to abort if os_file_readdir_next_file() encounters "real" errors. Approved by: Marko, Pekka (rb://177) ------------------------------------------------------------------------ r6049 | vasil | 2009-10-10 03:05:26 +1100 (Sat, 10 Oct 2009) | 7 lines branches/zip: Fix compilation warning in Hot Backup: innodb/fil/fil0fil.c: In function 'fil_load_single_table_tablespace': innodb/fil/fil0fil.c:3253: warning: format '%lld' expects type 'long long int', but argument 6 has type 'ib_int64_t' ------------------------------------------------------------------------ r6064 | calvin | 2009-10-14 02:23:35 +1100 (Wed, 14 Oct 2009) | 4 lines branches/zip: non-functional changes Changes from MySQL to fix build issue. ------------------------------------------------------------------------ r6065 | inaam | 2009-10-14 04:43:13 +1100 (Wed, 14 Oct 2009) | 7 lines branches/zip rb://182 Call fsync() on datafiles after a batch of pages is written to disk even when skip_innodb_doublewrite is set. Approved by: Heikki ------------------------------------------------------------------------ r6080 | sunny | 2009-10-15 09:29:01 +1100 (Thu, 15 Oct 2009) | 3 lines branches/zip: Change page_mem_alloc_free() to inline. Fix Bug #47058 - Failure to compile innodb_plugin on solaris 10u7 + spro cc/CC 5.10 ------------------------------------------------------------------------ r6084 | vasil | 2009-10-15 16:21:17 +1100 (Thu, 15 Oct 2009) | 4 lines branches/zip: Add ChangeLog entry for r6080. ------------------------------------------------------------------------ r6095 | vasil | 2009-10-20 00:04:59 +1100 (Tue, 20 Oct 2009) | 7 lines branches/zip: Fix Bug#47808 innodb_information_schema.test fails when run under valgrind by using the wait_until_rows_count macro that loops until the number of rows becomes 14 instead of sleep 0.1, which is obviously very fragile. ------------------------------------------------------------------------ r6096 | vasil | 2009-10-20 00:06:09 +1100 (Tue, 20 Oct 2009) | 4 lines branches/zip: Add ChangeLog entry for r6095. ------------------------------------------------------------------------ r6099 | jyang | 2009-10-22 13:58:39 +1100 (Thu, 22 Oct 2009) | 7 lines branches/zip: Port bug #46000 related changes from 5.1 to zip branch. Due to different code path for creating index in zip branch comparing to 5.1), the index reserved name check function is extended to be used in ha_innobase::add_index(). rb://190 Approved by: Marko ------------------------------------------------------------------------ r6100 | jyang | 2009-10-22 14:51:07 +1100 (Thu, 22 Oct 2009) | 6 lines branches/zip: As a request from mysql, WARN_LEVEL_ERROR cannot be used for push_warning_* call any more. Switch to WARN_LEVEL_WARN. Bug #47233. rb://172 approved by Sunny Bains and Marko. ------------------------------------------------------------------------ r6101 | jyang | 2009-10-23 19:45:50 +1100 (Fri, 23 Oct 2009) | 7 lines branches/zip: Update test result with the WARN_LEVEL_ERROR to WARN_LEVEL_WARN change. This is the same result as submitted in rb://172 review, which approved by Sunny Bains and Marko. ------------------------------------------------------------------------ r6102 | marko | 2009-10-26 18:32:23 +1100 (Mon, 26 Oct 2009) | 1 line branches/zip: row_prebuilt_struct::prebuilts: Unused field, remove. ------------------------------------------------------------------------ r6103 | marko | 2009-10-27 00:46:18 +1100 (Tue, 27 Oct 2009) | 4 lines branches/zip: row_ins_alloc_sys_fields(): Zero out the system columns DB_TRX_ID, DB_ROLL_PTR and DB_ROW_ID, in order to avoid harmless Valgrind warnings about uninitialized data. (The warnings were harmless, because the fields would be initialized at a later stage.) ------------------------------------------------------------------------ r6105 | calvin | 2009-10-28 09:05:52 +1100 (Wed, 28 Oct 2009) | 6 lines branches/zip: backport r3848 from 6.0 branch ---- branches/6.0: innobase_start_or_create_for_mysql(): Make the 10 MB minimum tablespace limit independent of UNIV_PAGE_SIZE. (Bug #41490) ------------------------------------------------------------------------ r6107 | marko | 2009-10-29 01:10:34 +1100 (Thu, 29 Oct 2009) | 5 lines branches/zip: buf_page_set_old(): Improve UNIV_LRU_DEBUG diagnostics in order to catch the buf_pool->LRU_old corruption reported in Issue #381. buf_LRU_old_init(): Set the property from the tail towards the front of the buf_pool->LRU list, in order not to trip the debug check. ------------------------------------------------------------------------ r6108 | calvin | 2009-10-29 16:58:04 +1100 (Thu, 29 Oct 2009) | 5 lines branches/zip: close file handle when building with UNIV_HOTBACKUP The change does not affect regular InnoDB engine. Confirmed by Marko. ------------------------------------------------------------------------ r6109 | jyang | 2009-10-29 19:37:32 +1100 (Thu, 29 Oct 2009) | 7 lines branches/zip: In os_mem_alloc_large(), if we fail to attach the shared memory, reset memory pointer ptr to NULL, and allocate memory from conventional pool. Bug #48237 Error handling in os_mem_alloc_large appears to be incorrect rb://198 Approved by: Marko ------------------------------------------------------------------------ r6110 | marko | 2009-10-29 21:44:57 +1100 (Thu, 29 Oct 2009) | 2 lines branches/zip: Makefile.am (INCLUDES): Merge a change from MySQL: Use $(srcdir)/include instead of $(top_srcdir)/storage/innobase/include. ------------------------------------------------------------------------ r6111 | marko | 2009-10-29 22:04:11 +1100 (Thu, 29 Oct 2009) | 33 lines branches/zip: Fix corruption of buf_pool->LRU_old and improve debug assertions. This was reported as Issue #381. buf_page_set_old(): Assert that blocks may only be set old if buf_pool->LRU_old is initialized and buf_pool->LRU_old_len is nonzero. Assert that buf_pool->LRU_old points to the block at the old/new boundary. buf_LRU_old_adjust_len(): Invoke buf_page_set_old() after adjusting buf_pool->LRU_old and buf_pool->LRU_old_len, in order not to violate the added assertions. buf_LRU_old_init(): Replace buf_page_set_old() with a direct assignment to bpage->old, because these loops that initialize all the blocks would temporarily violate the assertions about buf_pool->LRU_old. buf_LRU_remove_block(): When setting buf_pool->LRU_old = NULL, also clear all bpage->old flags and set buf_pool->LRU_old_len = 0. buf_LRU_add_block_to_end_low(), buf_LRU_add_block_low(): Move the buf_page_set_old() call later in order not to violate the debug assertions. If buf_pool->LRU_old is NULL, set old=FALSE. buf_LRU_free_block(): Replace the UNIV_LRU_DEBUG assertion with a dummy buf_page_set_old() call that performs more thorough checks. buf_LRU_validate(): Do not tolerate garbage in buf_pool->LRU_old_len even if buf_pool->LRU_old is NULL. Check that bpage->old is monotonic. buf_relocate(): Make the UNIV_LRU_DEBUG checks stricter. buf0buf.h: Revise the documentation of buf_page_t::old and buf_pool_t::LRU_old_len. ------------------------------------------------------------------------ r6112 | calvin | 2009-10-30 01:21:15 +1100 (Fri, 30 Oct 2009) | 4 lines branches/zip: consideration for icc compilers Proposed by MySQL, and approved by Marko. ------------------------------------------------------------------------ r6113 | vasil | 2009-10-30 03:15:50 +1100 (Fri, 30 Oct 2009) | 93 lines branches/zip: Merge r5912:6112 from branches/5.1: (after this merge the innodb-autoinc test starts to fail, but I commit anyway because it would be easier to investigate the failure this way) ------------------------------------------------------------------------ r5952 | calvin | 2009-09-22 19:45:07 +0300 (Tue, 22 Sep 2009) | 7 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: fix bug#42383: Can't create table 'test.bug39438' For embedded server, MySQL may pass in full path, which is currently disallowed. It is needed to relax the condition by accepting full paths in the embedded case. Approved by: Heikki (on IM) ------------------------------------------------------------------------ r6032 | vasil | 2009-10-01 15:55:49 +0300 (Thu, 01 Oct 2009) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: Fix Bug#38996 Race condition in ANALYZE TABLE by serializing ANALYZE TABLE inside InnoDB. Approved by: Heikki (rb://175) ------------------------------------------------------------------------ r6045 | jyang | 2009-10-08 02:27:08 +0300 (Thu, 08 Oct 2009) | 7 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc A /branches/5.1/mysql-test/innodb_bug47777.result A /branches/5.1/mysql-test/innodb_bug47777.test branches/5.1: Fix bug #47777. Treat the Geometry data same as Binary BLOB in ha_innobase::store_key_val_for_row(), since the Geometry data is stored as Binary BLOB in Innodb. Review: rb://180 approved by Marko Makela. ------------------------------------------------------------------------ r6051 | sunny | 2009-10-12 07:05:00 +0300 (Mon, 12 Oct 2009) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test branches/5.1: Ignore negative values supplied by the user when calculating the next value to store in dict_table_t. Setting autoincrement columns top negative values is undefined behavior and this change should bring the behavior of InnoDB closer to what users expect. Added several tests to check. rb://162 ------------------------------------------------------------------------ r6052 | sunny | 2009-10-12 07:09:56 +0300 (Mon, 12 Oct 2009) | 4 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test branches/5.1: Reset the statement level autoinc counter on ROLLBACK. Fix the test results too. rb://164 ------------------------------------------------------------------------ r6053 | sunny | 2009-10-12 07:37:49 +0300 (Mon, 12 Oct 2009) | 6 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/mysql-test/innodb-autoinc.result M /branches/5.1/mysql-test/innodb-autoinc.test branches/5.1: Copy the maximum AUTOINC value from the old table to the new table when MySQL does a CREATE INDEX ON T. This is required because MySQL does a table copy, rename and drops the old table. Fix Bug#47125: auto_increment start value is ignored if an index is created and engine=innodb rb://168 ------------------------------------------------------------------------ r6076 | vasil | 2009-10-14 19:30:12 +0300 (Wed, 14 Oct 2009) | 4 lines Changed paths: M /branches/5.1/row/row0mysql.c branches/5.1: Fix typo. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r6114 | vasil | 2009-10-30 03:43:51 +1100 (Fri, 30 Oct 2009) | 6 lines branches/zip: * Add ChangeLog entries for latest changes * Obey alphabetical order in the list of the files * White-space fixup ------------------------------------------------------------------------ r6121 | sunny | 2009-10-30 10:42:11 +1100 (Fri, 30 Oct 2009) | 7 lines branches/zip: This test has been problematic for sometime now. The underlying bug is that the data dictionaries get out of sync. In the AUTOINC code we try and apply salve to the symptoms. In the past MySQL made some unrelated change and the dictionaries stopped getting out of sync and this test started to fail. Now, it seems they have reverted that changed and the test is passing again. I suspect this is not he last time that this test will change. ------------------------------------------------------------------------ r6124 | jyang | 2009-10-30 19:02:31 +1100 (Fri, 30 Oct 2009) | 5 lines branches/zip: Correct the bug number for -r6109 change from # 48273 to #48237 ------------------------------------------------------------------------ r6126 | vasil | 2009-10-30 19:36:07 +1100 (Fri, 30 Oct 2009) | 45 lines branches/zip: Merge r6112:6125 from branches/5.1: (skipping r6122 and r6123, Jimmy says these are already present and need not be merged): ------------------------------------------------------------------------ r6122 | jyang | 2009-10-30 05:18:38 +0200 (Fri, 30 Oct 2009) | 7 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/mysql-test/innodb_bug44369.result M /branches/5.1/mysql-test/innodb_bug44369.test M /branches/5.1/mysql-test/innodb_bug46000.result M /branches/5.1/mysql-test/innodb_bug46000.test branches/5.1: Chnage WARN_LEVEL_ERROR to WARN_LEVEL_WARN for push_warning_printf() call in innodb. Fix Bug#47233: Innodb calls push_warning(MYSQL_ERROR::WARN_LEVEL_ERROR) rb://170 approved by Marko. ------------------------------------------------------------------------ r6123 | jyang | 2009-10-30 05:43:06 +0200 (Fri, 30 Oct 2009) | 8 lines Changed paths: M /branches/5.1/os/os0proc.c branches/5.1: In os_mem_alloc_large(), if we fail to attach the shared memory, reset memory pointer ptr to NULL, and allocate memory from conventional pool. This is a port from branches/zip. Bug #48237 Error handling in os_mem_alloc_large appears to be incorrect rb://198 Approved by: Marko ------------------------------------------------------------------------ r6125 | vasil | 2009-10-30 10:31:23 +0200 (Fri, 30 Oct 2009) | 4 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: White-space fixup. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r6130 | marko | 2009-11-02 20:42:56 +1100 (Mon, 02 Nov 2009) | 9 lines branches/zip: Free all resources at shutdown. Set pointers to NULL, so that Valgrind will not complain about freed data structures that are reachable via pointers. This addresses Bug #45992 and Bug #46656. This patch is mostly based on changes copied from branches/embedded-1.0, mainly c5432, c3439, c3134, c2994, c2978, but also some other code was copied. Some added cleanup code is specific to MySQL/InnoDB. rb://199 approved by Sunny Bains ------------------------------------------------------------------------
1073 lines
29 KiB
Text
1073 lines
29 KiB
Text
/*****************************************************************************
|
|
|
|
Copyright (c) 1994, 2009, Innobase Oy. All Rights Reserved.
|
|
|
|
This program is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*****************************************************************************/
|
|
|
|
/**************************************************//**
|
|
@file include/page0page.ic
|
|
Index page routines
|
|
|
|
Created 2/2/1994 Heikki Tuuri
|
|
*******************************************************/
|
|
|
|
#include "mach0data.h"
|
|
#ifdef UNIV_DEBUG
|
|
# include "log0recv.h"
|
|
#endif /* !UNIV_DEBUG */
|
|
#ifndef UNIV_HOTBACKUP
|
|
# include "rem0cmp.h"
|
|
#endif /* !UNIV_HOTBACKUP */
|
|
#include "mtr0log.h"
|
|
#include "page0zip.h"
|
|
|
|
#ifdef UNIV_MATERIALIZE
|
|
#undef UNIV_INLINE
|
|
#define UNIV_INLINE
|
|
#endif
|
|
|
|
/************************************************************//**
|
|
Gets the start of a page.
|
|
@return start of the page */
|
|
UNIV_INLINE
|
|
page_t*
|
|
page_align(
|
|
/*=======*/
|
|
const void* ptr) /*!< in: pointer to page frame */
|
|
{
|
|
return((page_t*) ut_align_down(ptr, UNIV_PAGE_SIZE));
|
|
}
|
|
/************************************************************//**
|
|
Gets the offset within a page.
|
|
@return offset from the start of the page */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_offset(
|
|
/*========*/
|
|
const void* ptr) /*!< in: pointer to page frame */
|
|
{
|
|
return(ut_align_offset(ptr, UNIV_PAGE_SIZE));
|
|
}
|
|
/*************************************************************//**
|
|
Returns the max trx id field value. */
|
|
UNIV_INLINE
|
|
trx_id_t
|
|
page_get_max_trx_id(
|
|
/*================*/
|
|
const 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(
|
|
/*===================*/
|
|
buf_block_t* block, /*!< in/out: page */
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page whose
|
|
uncompressed part will be updated, or NULL */
|
|
trx_id_t trx_id, /*!< in: transaction id */
|
|
mtr_t* mtr) /*!< in/out: mini-transaction */
|
|
{
|
|
ut_ad(block);
|
|
ut_ad(mtr_memo_contains(mtr, block, MTR_MEMO_PAGE_X_FIX));
|
|
/* During crash recovery, this function may be called on
|
|
something else than a leaf page of a secondary index or the
|
|
insert buffer index tree (dict_index_is_sec_or_ibuf() returns
|
|
TRUE for the dummy indexes constructed during redo log
|
|
application). In that case, PAGE_MAX_TRX_ID is unused,
|
|
and trx_id is usually zero. */
|
|
ut_ad(!ut_dulint_is_zero(trx_id) || recv_recovery_is_on());
|
|
ut_ad(page_is_leaf(buf_block_get_frame(block)));
|
|
|
|
if (ut_dulint_cmp(page_get_max_trx_id(buf_block_get_frame(block)),
|
|
trx_id) < 0) {
|
|
|
|
page_set_max_trx_id(block, page_zip, trx_id, mtr);
|
|
}
|
|
}
|
|
|
|
/*************************************************************//**
|
|
Reads the given header field. */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_header_get_field(
|
|
/*==================*/
|
|
const 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/out: page */
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page whose
|
|
uncompressed part will be updated, or NULL */
|
|
ulint field, /*!< in: PAGE_N_DIR_SLOTS, ... */
|
|
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);
|
|
if (UNIV_LIKELY_NULL(page_zip)) {
|
|
page_zip_write_header(page_zip,
|
|
page + PAGE_HEADER + field, 2, NULL);
|
|
}
|
|
}
|
|
|
|
/*************************************************************//**
|
|
Returns the offset stored in the given header field.
|
|
@return offset from the start of the page, or 0 */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_header_get_offs(
|
|
/*=================*/
|
|
const 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);
|
|
|
|
return(offs);
|
|
}
|
|
|
|
/*************************************************************//**
|
|
Sets the pointer stored in the given header field. */
|
|
UNIV_INLINE
|
|
void
|
|
page_header_set_ptr(
|
|
/*================*/
|
|
page_t* page, /*!< in: page */
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page whose
|
|
uncompressed part will be updated, or NULL */
|
|
ulint field, /*!< in: PAGE_FREE, ... */
|
|
const 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, page_zip, field, offs);
|
|
}
|
|
|
|
#ifndef UNIV_HOTBACKUP
|
|
/*************************************************************//**
|
|
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/out: page */
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page whose
|
|
uncompressed part will be updated, or NULL */
|
|
mtr_t* mtr) /*!< in: mtr */
|
|
{
|
|
ut_ad(page && mtr);
|
|
|
|
if (UNIV_LIKELY_NULL(page_zip)) {
|
|
mach_write_to_2(page + (PAGE_HEADER + PAGE_LAST_INSERT), 0);
|
|
page_zip_write_header(page_zip,
|
|
page + (PAGE_HEADER + PAGE_LAST_INSERT),
|
|
2, mtr);
|
|
} else {
|
|
mlog_write_ulint(page + (PAGE_HEADER + PAGE_LAST_INSERT), 0,
|
|
MLOG_2BYTES, mtr);
|
|
}
|
|
}
|
|
#endif /* !UNIV_HOTBACKUP */
|
|
|
|
/************************************************************//**
|
|
Determine whether the page is in new-style compact format.
|
|
@return nonzero if the page is in compact format, zero if it is in
|
|
old-style format */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_is_comp(
|
|
/*=========*/
|
|
const 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.
|
|
@return nonzero if in compact format */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_rec_is_comp(
|
|
/*=============*/
|
|
const rec_t* rec) /*!< in: record */
|
|
{
|
|
return(page_is_comp(page_align(rec)));
|
|
}
|
|
|
|
/***************************************************************//**
|
|
Returns the heap number of a record.
|
|
@return heap number */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_rec_get_heap_no(
|
|
/*=================*/
|
|
const rec_t* rec) /*!< in: the physical record */
|
|
{
|
|
if (page_rec_is_comp(rec)) {
|
|
return(rec_get_heap_no_new(rec));
|
|
} else {
|
|
return(rec_get_heap_no_old(rec));
|
|
}
|
|
}
|
|
|
|
/************************************************************//**
|
|
Determine whether the page is a B-tree leaf.
|
|
@return TRUE if the page is a B-tree leaf */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_is_leaf(
|
|
/*=========*/
|
|
const page_t* page) /*!< in: page */
|
|
{
|
|
return(!*(const uint16*) (page + (PAGE_HEADER + PAGE_LEVEL)));
|
|
}
|
|
|
|
/************************************************************//**
|
|
Gets the offset of the first record on the page.
|
|
@return offset of the first record in record list, relative from page */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_get_infimum_offset(
|
|
/*====================*/
|
|
const page_t* page) /*!< in: page which must have record(s) */
|
|
{
|
|
ut_ad(page);
|
|
ut_ad(!page_offset(page));
|
|
|
|
if (page_is_comp(page)) {
|
|
return(PAGE_NEW_INFIMUM);
|
|
} else {
|
|
return(PAGE_OLD_INFIMUM);
|
|
}
|
|
}
|
|
|
|
/************************************************************//**
|
|
Gets the offset of the last record on the page.
|
|
@return offset of the last record in record list, relative from page */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_get_supremum_offset(
|
|
/*=====================*/
|
|
const page_t* page) /*!< in: page which must have record(s) */
|
|
{
|
|
ut_ad(page);
|
|
ut_ad(!page_offset(page));
|
|
|
|
if (page_is_comp(page)) {
|
|
return(PAGE_NEW_SUPREMUM);
|
|
} else {
|
|
return(PAGE_OLD_SUPREMUM);
|
|
}
|
|
}
|
|
|
|
/************************************************************//**
|
|
TRUE if the record is a user record on the page.
|
|
@return TRUE if a user record */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_rec_is_user_rec_low(
|
|
/*=====================*/
|
|
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.
|
|
@return TRUE if the supremum record */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_rec_is_supremum_low(
|
|
/*=====================*/
|
|
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.
|
|
@return TRUE if the infimum record */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_rec_is_infimum_low(
|
|
/*====================*/
|
|
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.
|
|
@return TRUE if a user record */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_rec_is_user_rec(
|
|
/*=================*/
|
|
const rec_t* rec) /*!< in: record */
|
|
{
|
|
return(page_rec_is_user_rec_low(page_offset(rec)));
|
|
}
|
|
|
|
/************************************************************//**
|
|
TRUE if the record is the supremum record on a page.
|
|
@return TRUE if the supremum record */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_rec_is_supremum(
|
|
/*=================*/
|
|
const rec_t* rec) /*!< in: record */
|
|
{
|
|
return(page_rec_is_supremum_low(page_offset(rec)));
|
|
}
|
|
|
|
/************************************************************//**
|
|
TRUE if the record is the infimum record on a page.
|
|
@return TRUE if the infimum record */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_rec_is_infimum(
|
|
/*================*/
|
|
const rec_t* rec) /*!< in: record */
|
|
{
|
|
return(page_rec_is_infimum_low(page_offset(rec)));
|
|
}
|
|
|
|
#ifndef UNIV_HOTBACKUP
|
|
/*************************************************************//**
|
|
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.
|
|
@return 1, 0, -1, if dtuple is greater, equal, less than rec,
|
|
respectively, when only the common first fields are compared */
|
|
UNIV_INLINE
|
|
int
|
|
page_cmp_dtuple_rec_with_match(
|
|
/*===========================*/
|
|
const dtuple_t* dtuple, /*!< in: data tuple */
|
|
const 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 = page_offset(rec);
|
|
|
|
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));
|
|
}
|
|
#endif /* !UNIV_HOTBACKUP */
|
|
|
|
/*************************************************************//**
|
|
Gets the page number.
|
|
@return page number */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_get_page_no(
|
|
/*=============*/
|
|
const page_t* page) /*!< in: page */
|
|
{
|
|
ut_ad(page == page_align((page_t*) page));
|
|
return(mach_read_from_4(page + FIL_PAGE_OFFSET));
|
|
}
|
|
|
|
/*************************************************************//**
|
|
Gets the tablespace identifier.
|
|
@return space id */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_get_space_id(
|
|
/*==============*/
|
|
const page_t* page) /*!< in: page */
|
|
{
|
|
ut_ad(page == page_align((page_t*) page));
|
|
return(mach_read_from_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID));
|
|
}
|
|
|
|
/*************************************************************//**
|
|
Gets the number of user records on page (infimum and supremum records
|
|
are not user records).
|
|
@return number of user records */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_get_n_recs(
|
|
/*============*/
|
|
const page_t* page) /*!< in: index page */
|
|
{
|
|
return(page_header_get_field(page, PAGE_N_RECS));
|
|
}
|
|
|
|
/*************************************************************//**
|
|
Gets the number of dir slots in directory.
|
|
@return number of slots */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_dir_get_n_slots(
|
|
/*=================*/
|
|
const 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(
|
|
/*=================*/
|
|
page_t* page, /*!< in/out: page */
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page whose
|
|
uncompressed part will be updated, or NULL */
|
|
ulint n_slots)/*!< in: number of slots */
|
|
{
|
|
page_header_set_field(page, page_zip, PAGE_N_DIR_SLOTS, n_slots);
|
|
}
|
|
|
|
/*************************************************************//**
|
|
Gets the number of records in the heap.
|
|
@return number of user records */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_dir_get_n_heap(
|
|
/*================*/
|
|
const 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/out: index page */
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page whose
|
|
uncompressed part will be updated, or NULL.
|
|
Note that the size of the dense page directory
|
|
in the compressed page trailer is
|
|
n_heap * PAGE_ZIP_DIR_SLOT_SIZE. */
|
|
ulint n_heap) /*!< in: number of records */
|
|
{
|
|
ut_ad(n_heap < 0x8000);
|
|
ut_ad(!page_zip || n_heap
|
|
== (page_header_get_field(page, PAGE_N_HEAP) & 0x7fff) + 1);
|
|
|
|
page_header_set_field(page, page_zip, PAGE_N_HEAP, n_heap
|
|
| (0x8000
|
|
& page_header_get_field(page, PAGE_N_HEAP)));
|
|
}
|
|
|
|
#ifdef UNIV_DEBUG
|
|
/*************************************************************//**
|
|
Gets pointer to nth directory slot.
|
|
@return pointer to dir slot */
|
|
UNIV_INLINE
|
|
page_dir_slot_t*
|
|
page_dir_get_nth_slot(
|
|
/*==================*/
|
|
const page_t* page, /*!< in: index page */
|
|
ulint n) /*!< in: position */
|
|
{
|
|
ut_ad(page_dir_get_n_slots(page) > n);
|
|
|
|
return((page_dir_slot_t*)
|
|
page + UNIV_PAGE_SIZE - PAGE_DIR
|
|
- (n + 1) * PAGE_DIR_SLOT_SIZE);
|
|
}
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
/**************************************************************//**
|
|
Used to check the consistency of a record on a page.
|
|
@return TRUE if succeed */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_rec_check(
|
|
/*===========*/
|
|
const rec_t* rec) /*!< in: record */
|
|
{
|
|
const page_t* page = page_align(rec);
|
|
|
|
ut_a(rec);
|
|
|
|
ut_a(page_offset(rec) <= page_header_get_field(page, PAGE_HEAP_TOP));
|
|
ut_a(page_offset(rec) >= PAGE_DATA);
|
|
|
|
return(TRUE);
|
|
}
|
|
|
|
/***************************************************************//**
|
|
Gets the record pointed to by a directory slot.
|
|
@return pointer to record */
|
|
UNIV_INLINE
|
|
const rec_t*
|
|
page_dir_slot_get_rec(
|
|
/*==================*/
|
|
const page_dir_slot_t* slot) /*!< in: directory slot */
|
|
{
|
|
return(page_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, page_offset(rec));
|
|
}
|
|
|
|
/***************************************************************//**
|
|
Gets the number of records owned by a directory slot.
|
|
@return number of records */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_dir_slot_get_n_owned(
|
|
/*======================*/
|
|
const page_dir_slot_t* slot) /*!< in: page directory slot */
|
|
{
|
|
const rec_t* rec = page_dir_slot_get_rec(slot);
|
|
if (page_rec_is_comp(slot)) {
|
|
return(rec_get_n_owned_new(rec));
|
|
} else {
|
|
return(rec_get_n_owned_old(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/out: directory slot */
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page, or NULL */
|
|
ulint n) /*!< in: number of records owned by the slot */
|
|
{
|
|
rec_t* rec = (rec_t*) page_dir_slot_get_rec(slot);
|
|
if (page_rec_is_comp(slot)) {
|
|
rec_set_n_owned_new(rec, page_zip, n);
|
|
} else {
|
|
ut_ad(!page_zip);
|
|
rec_set_n_owned_old(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.
|
|
@return pointer to next record */
|
|
UNIV_INLINE
|
|
const rec_t*
|
|
page_rec_get_next_low(
|
|
/*==================*/
|
|
const rec_t* rec, /*!< in: pointer to record */
|
|
ulint comp) /*!< in: nonzero=compact page layout */
|
|
{
|
|
ulint offs;
|
|
const page_t* page;
|
|
|
|
ut_ad(page_rec_check(rec));
|
|
|
|
page = page_align(rec);
|
|
|
|
offs = rec_get_next_offs(rec, comp);
|
|
|
|
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, space id %lu, page %lu\n",
|
|
(ulong)offs, (ulong) page_offset(rec),
|
|
(void*) rec,
|
|
(ulong) page_get_space_id(page),
|
|
(ulong) page_get_page_no(page));
|
|
buf_page_print(page, 0);
|
|
|
|
ut_error;
|
|
}
|
|
|
|
if (UNIV_UNLIKELY(offs == 0)) {
|
|
|
|
return(NULL);
|
|
}
|
|
|
|
return(page + offs);
|
|
}
|
|
|
|
/************************************************************//**
|
|
Gets the pointer to the next record on the page.
|
|
@return pointer to next record */
|
|
UNIV_INLINE
|
|
rec_t*
|
|
page_rec_get_next(
|
|
/*==============*/
|
|
rec_t* rec) /*!< in: pointer to record */
|
|
{
|
|
return((rec_t*) page_rec_get_next_low(rec, page_rec_is_comp(rec)));
|
|
}
|
|
|
|
/************************************************************//**
|
|
Gets the pointer to the next record on the page.
|
|
@return pointer to next record */
|
|
UNIV_INLINE
|
|
const rec_t*
|
|
page_rec_get_next_const(
|
|
/*====================*/
|
|
const rec_t* rec) /*!< in: pointer to record */
|
|
{
|
|
return(page_rec_get_next_low(rec, page_rec_is_comp(rec)));
|
|
}
|
|
|
|
/************************************************************//**
|
|
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 */
|
|
{
|
|
ulint offs;
|
|
|
|
ut_ad(page_rec_check(rec));
|
|
ut_ad(!page_rec_is_supremum(rec));
|
|
ut_ad(rec != next);
|
|
|
|
ut_ad(!next || !page_rec_is_infimum(next));
|
|
ut_ad(!next || page_align(rec) == page_align(next));
|
|
|
|
if (UNIV_LIKELY(next != NULL)) {
|
|
offs = page_offset(next);
|
|
} else {
|
|
offs = 0;
|
|
}
|
|
|
|
if (page_rec_is_comp(rec)) {
|
|
rec_set_next_offs_new(rec, offs);
|
|
} else {
|
|
rec_set_next_offs_old(rec, offs);
|
|
}
|
|
}
|
|
|
|
/************************************************************//**
|
|
Gets the pointer to the previous record.
|
|
@return pointer to previous record */
|
|
UNIV_INLINE
|
|
const rec_t*
|
|
page_rec_get_prev_const(
|
|
/*====================*/
|
|
const rec_t* rec) /*!< in: pointer to record, must not be page
|
|
infimum */
|
|
{
|
|
const page_dir_slot_t* slot;
|
|
ulint slot_no;
|
|
const rec_t* rec2;
|
|
const rec_t* prev_rec = NULL;
|
|
const page_t* page;
|
|
|
|
ut_ad(page_rec_check(rec));
|
|
|
|
page = page_align(rec);
|
|
|
|
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);
|
|
|
|
if (page_is_comp(page)) {
|
|
while (rec != rec2) {
|
|
prev_rec = rec2;
|
|
rec2 = page_rec_get_next_low(rec2, TRUE);
|
|
}
|
|
} else {
|
|
while (rec != rec2) {
|
|
prev_rec = rec2;
|
|
rec2 = page_rec_get_next_low(rec2, FALSE);
|
|
}
|
|
}
|
|
|
|
ut_a(prev_rec);
|
|
|
|
return(prev_rec);
|
|
}
|
|
|
|
/************************************************************//**
|
|
Gets the pointer to the previous record.
|
|
@return pointer to previous record */
|
|
UNIV_INLINE
|
|
rec_t*
|
|
page_rec_get_prev(
|
|
/*==============*/
|
|
rec_t* rec) /*!< in: pointer to record, must not be page
|
|
infimum */
|
|
{
|
|
return((rec_t*) page_rec_get_prev_const(rec));
|
|
}
|
|
|
|
/***************************************************************//**
|
|
Looks for the record which owns the given record.
|
|
@return the owner record */
|
|
UNIV_INLINE
|
|
rec_t*
|
|
page_rec_find_owner_rec(
|
|
/*====================*/
|
|
rec_t* rec) /*!< in: the physical record */
|
|
{
|
|
ut_ad(page_rec_check(rec));
|
|
|
|
if (page_rec_is_comp(rec)) {
|
|
while (rec_get_n_owned_new(rec) == 0) {
|
|
rec = page_rec_get_next(rec);
|
|
}
|
|
} else {
|
|
while (rec_get_n_owned_old(rec) == 0) {
|
|
rec = page_rec_get_next(rec);
|
|
}
|
|
}
|
|
|
|
return(rec);
|
|
}
|
|
|
|
/**********************************************************//**
|
|
Returns the base extra size of a physical record. This is the
|
|
size of the fixed header, independent of the record size.
|
|
@return REC_N_NEW_EXTRA_BYTES or REC_N_OLD_EXTRA_BYTES */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_rec_get_base_extra_size(
|
|
/*=========================*/
|
|
const rec_t* rec) /*!< in: physical record */
|
|
{
|
|
#if REC_N_NEW_EXTRA_BYTES + 1 != REC_N_OLD_EXTRA_BYTES
|
|
# error "REC_N_NEW_EXTRA_BYTES + 1 != REC_N_OLD_EXTRA_BYTES"
|
|
#endif
|
|
return(REC_N_NEW_EXTRA_BYTES + (ulint) !page_rec_is_comp(rec));
|
|
}
|
|
|
|
/************************************************************//**
|
|
Returns the sum of the sizes of the records in the record list, excluding
|
|
the infimum and supremum records.
|
|
@return data in bytes */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_get_data_size(
|
|
/*===============*/
|
|
const 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);
|
|
}
|
|
|
|
|
|
/************************************************************//**
|
|
Allocates a block of memory from the free list of an index page. */
|
|
UNIV_INLINE
|
|
void
|
|
page_mem_alloc_free(
|
|
/*================*/
|
|
page_t* page, /*!< in/out: index page */
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page with enough
|
|
space available for inserting the record,
|
|
or NULL */
|
|
rec_t* next_rec,/*!< in: pointer to the new head of the
|
|
free record list */
|
|
ulint need) /*!< in: number of bytes allocated */
|
|
{
|
|
ulint garbage;
|
|
|
|
#ifdef UNIV_DEBUG
|
|
const rec_t* old_rec = page_header_get_ptr(page, PAGE_FREE);
|
|
ulint next_offs;
|
|
|
|
ut_ad(old_rec);
|
|
next_offs = rec_get_next_offs(old_rec, page_is_comp(page));
|
|
ut_ad(next_rec == (next_offs ? page + next_offs : NULL));
|
|
#endif
|
|
|
|
page_header_set_ptr(page, page_zip, PAGE_FREE, next_rec);
|
|
|
|
garbage = page_header_get_field(page, PAGE_GARBAGE);
|
|
ut_ad(garbage >= need);
|
|
|
|
page_header_set_field(page, page_zip, PAGE_GARBAGE, garbage - need);
|
|
}
|
|
|
|
/*************************************************************//**
|
|
Calculates free space if a page is emptied.
|
|
@return free space */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_get_free_space_of_empty(
|
|
/*=========================*/
|
|
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.
|
|
@return maximum combined size for inserted records */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_get_max_insert_size(
|
|
/*=====================*/
|
|
const 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.
|
|
@return maximum combined size for inserted records */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_get_max_insert_size_after_reorganize(
|
|
/*======================================*/
|
|
const 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/out: index page */
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page, or NULL */
|
|
rec_t* rec, /*!< in: pointer to the (origin of) record */
|
|
dict_index_t* index, /*!< in: index of rec */
|
|
const ulint* offsets)/*!< in: array returned by rec_get_offsets() */
|
|
{
|
|
rec_t* free;
|
|
ulint garbage;
|
|
|
|
ut_ad(rec_offs_validate(rec, index, offsets));
|
|
free = page_header_get_ptr(page, PAGE_FREE);
|
|
|
|
page_rec_set_next(rec, free);
|
|
page_header_set_ptr(page, page_zip, PAGE_FREE, rec);
|
|
|
|
garbage = page_header_get_field(page, PAGE_GARBAGE);
|
|
|
|
page_header_set_field(page, page_zip, PAGE_GARBAGE,
|
|
garbage + rec_offs_size(offsets));
|
|
|
|
if (UNIV_LIKELY_NULL(page_zip)) {
|
|
page_zip_dir_delete(page_zip, rec, index, offsets, free);
|
|
} else {
|
|
page_header_set_field(page, page_zip, PAGE_N_RECS,
|
|
page_get_n_recs(page) - 1);
|
|
}
|
|
}
|
|
|
|
#ifdef UNIV_MATERIALIZE
|
|
#undef UNIV_INLINE
|
|
#define UNIV_INLINE UNIV_INLINE_ORIGINAL
|
|
#endif
|