mirror of
https://github.com/MariaDB/server.git
synced 2025-01-26 00:34:18 +01:00
f557ff3ea9
------------------------------------------------------------------------ r2838 | vasil | 2008-10-21 12:49:27 +0300 (Tue, 21 Oct 2008) | 61 lines branches/zip: Merge 2744:2837 from branches/5.1 (skipping r2782 and r2826): ------------------------------------------------------------------------ r2832 | vasil | 2008-10-21 10:08:30 +0300 (Tue, 21 Oct 2008) | 10 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc branches/5.1: In ha_innobase::info(): Replace sql_print_warning() which prints to mysqld error log with push_warning_printf() which sends the error message to the client. Suggested by: Marko, Sunny, Michael Objected by: Inaam ------------------------------------------------------------------------ r2837 | vasil | 2008-10-21 12:07:44 +0300 (Tue, 21 Oct 2008) | 32 lines Changed paths: M /branches/5.1/mysql-test/innodb-semi-consistent.result M /branches/5.1/mysql-test/innodb-semi-consistent.test M /branches/5.1/mysql-test/innodb.result M /branches/5.1/mysql-test/innodb.test branches/5.1: Merge a change from MySQL (this fixes the failing innodb and innodb-semi-consistent tests): revno: 2757 committer: Georgi Kodinov <kgeorge@mysql.com> branch nick: B39812-5.1-5.1.29-rc timestamp: Fri 2008-10-03 15:24:19 +0300 message: Bug #39812: Make statement replication default for 5.1 (to match 5.0) Make STMT replication default for 5.1. Add a default of MIXED into the config files Fix the tests that needed MIXED replication mode. modified: mysql-test/include/mix1.inc mysql-test/r/innodb-semi-consistent.result mysql-test/r/innodb.result mysql-test/r/innodb_mysql.result mysql-test/r/tx_isolation_func.result mysql-test/t/innodb-semi-consistent.test mysql-test/t/innodb.test mysql-test/t/tx_isolation_func.test sql/mysqld.cc support-files/my-huge.cnf.sh support-files/my-innodb-heavy-4G.cnf.sh support-files/my-large.cnf.sh support-files/my-medium.cnf.sh support-files/my-small.cnf.sh ------------------------------------------------------------------------ ------------------------------------------------------------------------ r2847 | marko | 2008-10-22 10:07:37 +0300 (Wed, 22 Oct 2008) | 6 lines branches/zip: page_zip_rec_needs_ext(): Fix a bug that was introduced in the fix of Mantis issue #73. With key_block_size=16, we will also have to check the available space on the uncompressed page. Otherwise, the clustered index record can be almost 16 kilobytes in size, and the undo log record will not fit. ------------------------------------------------------------------------ r2850 | marko | 2008-10-22 13:52:12 +0300 (Wed, 22 Oct 2008) | 2 lines branches/zip: ibuf_insert_to_index_page(): Discard the local variable block. page_cur is always positioned on block, the function parameter. ------------------------------------------------------------------------ r2853 | sunny | 2008-10-23 01:52:09 +0300 (Thu, 23 Oct 2008) | 2 lines branches/zip: Add missing UNIV_INTERN. ------------------------------------------------------------------------ r2855 | sunny | 2008-10-23 09:29:46 +0300 (Thu, 23 Oct 2008) | 36 lines branches/zip: Merge revisions 2837:2852 from branches/5.1: ------------------------------------------------------------------------ r2849 | sunny | 2008-10-22 12:01:18 +0300 (Wed, 22 Oct 2008) | 8 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/include/row0mysql.h M /branches/5.1/row/row0mysql.c branches/5.1: Return the actual error code encountered when allocating a new autoinc value. The change in behavior (bug) was introduced in 5.1.22 when we introduced the new AUTOINC locking model. rb://31 Bug#40224 New AUTOINC changes mask reporting of deadlock/timeout errors ------------------------------------------------------------------------ r2852 | sunny | 2008-10-23 01:42:24 +0300 (Thu, 23 Oct 2008) | 9 lines Changed paths: M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/handler/ha_innodb.h branches/5.1: Backport r2724 from branches/zip Check column value against the col max value before updating the table's global autoinc counter value. This is part of simplifying the AUTOINC sub-system. We extract the type info from MySQL data structures at runtime. This fixes Bug#37788 InnoDB Plugin: AUTO_INCREMENT wrong for compressed tables ------------------------------------------------------------------------ ------------------------------------------------------------------------ r2856 | sunny | 2008-10-23 10:07:05 +0300 (Thu, 23 Oct 2008) | 1 line Reverting test file changes from r2855 ------------------------------------------------------------------------ r2857 | sunny | 2008-10-23 10:24:33 +0300 (Thu, 23 Oct 2008) | 30 lines branches/zip: Merge revisions 2852:2854 from branches/5.1: ------------------------------------------------------------------------ r2854 | sunny | 2008-10-23 08:30:32 +0300 (Thu, 23 Oct 2008) | 13 lines Changed paths: M /branches/5.1/dict/dict0dict.c M /branches/5.1/dict/dict0mem.c M /branches/5.1/handler/ha_innodb.cc M /branches/5.1/handler/ha_innodb.h M /branches/5.1/include/dict0dict.h M /branches/5.1/include/dict0mem.h M /branches/5.1/row/row0mysql.c branches/5.1: Backport changes from branches/zip r2725 Simplify the autoinc initialization code. This removes the non-determinism related to reading the table's autoinc value for the first time. This change has also reduced the sizeof dict_table_t by sizeof(ibool) bytes because we don't need the dict_table_t::autoinc_inited field anymore. Bug#39830 Table autoinc value not updated on first insert. Bug#35498 Cannot get table test/table1 auto-inccounter value in ::info Bug#36411 Failed to read auto-increment value from storage engine" in 5.1.24 auto-inc rb://16 ------------------------------------------------------------------------ ------------------------------------------------------------------------ r2858 | vasil | 2008-10-23 11:33:43 +0300 (Thu, 23 Oct 2008) | 4 lines branches/zip: Update the ChangeLog ------------------------------------------------------------------------ r2861 | marko | 2008-10-23 12:27:15 +0300 (Thu, 23 Oct 2008) | 24 lines branches/zip: Clean up the file format stamping. trx_sys_file_format_max_upgrade(): Rename from trx_sys_file_format_max_update(). Improve the documentation. Add a const qualifier to the parameter "name". Replace the parameter "flags" with "format_id", because this function should deal with file format identifiers, not with table flags. trx_sys_file_format_max_write(), trx_sys_file_format_max_set(): Add a const qualifier to the parameter "name". ha_innodb.cc: Correct the spelling in some comments: "side effect". Remove redundant prototypes for some static callback functions. innodb_file_format_name_update(), innodb_file_format_check_update(): Correct the function signature. Use appropriate pointer type conversions. MYSQL_SYSVAR_STR(file_format), MYSQL_SYSVAR_STR(file_format_check): Remove the type conversions from the callback function pointers. When the function signatures match, no type conversion is needed. The type conversions would only prevent compilation warnings for any mismatch. Approved by Sunny in rb://25. ------------------------------------------------------------------------ r2862 | marko | 2008-10-23 12:37:42 +0300 (Thu, 23 Oct 2008) | 8 lines branches/zip: Non-functional changes: ibuf_get_volume_buffered(): Declare with static linkage. This function is private to ibuf0ibuf.c. btr_cur_pessimistic_delete(): Use the cached result of btr_cur_get_index(cursor). ------------------------------------------------------------------------
381 lines
12 KiB
Text
381 lines
12 KiB
Text
/******************************************************
|
|
Compressed page interface
|
|
|
|
(c) 2005 Innobase Oy
|
|
|
|
Created June 2005 by Marko Makela
|
|
*******************************************************/
|
|
|
|
#ifdef UNIV_MATERIALIZE
|
|
# undef UNIV_INLINE
|
|
# define UNIV_INLINE
|
|
#endif
|
|
|
|
#include "page0zip.h"
|
|
#include "page0page.h"
|
|
|
|
/* The format of compressed pages is as follows.
|
|
|
|
The header and trailer of the uncompressed pages, excluding the page
|
|
directory in the trailer, are copied as is to the header and trailer
|
|
of the compressed page.
|
|
|
|
At the end of the compressed page, there is a dense page directory
|
|
pointing to every user record contained on the page, including deleted
|
|
records on the free list. The dense directory is indexed in the
|
|
collation order, i.e., in the order in which the record list is
|
|
linked on the uncompressed page. The infimum and supremum records are
|
|
excluded. The two most significant bits of the entries are allocated
|
|
for the delete-mark and an n_owned flag indicating the last record in
|
|
a chain of records pointed to from the sparse page directory on the
|
|
uncompressed page.
|
|
|
|
The data between PAGE_ZIP_START and the last page directory entry will
|
|
be written in compressed format, starting at offset PAGE_DATA.
|
|
Infimum and supremum records are not stored. We exclude the
|
|
REC_N_NEW_EXTRA_BYTES in every record header. These can be recovered
|
|
from the dense page directory stored at the end of the compressed
|
|
page.
|
|
|
|
The fields node_ptr (in non-leaf B-tree nodes; level>0), trx_id and
|
|
roll_ptr (in leaf B-tree nodes; level=0), and BLOB pointers of
|
|
externally stored columns are stored separately, in ascending order of
|
|
heap_no and column index, starting backwards from the dense page
|
|
directory.
|
|
|
|
The compressed data stream may be followed by a modification log
|
|
covering the compressed portion of the page, as follows.
|
|
|
|
MODIFICATION LOG ENTRY FORMAT
|
|
- write record:
|
|
- (heap_no - 1) << 1 (1..2 bytes)
|
|
- extra bytes backwards
|
|
- data bytes
|
|
- clear record:
|
|
- (heap_no - 1) << 1 | 1 (1..2 bytes)
|
|
|
|
The integer values are stored in a variable-length format:
|
|
- 0xxxxxxx: 0..127
|
|
- 1xxxxxxx xxxxxxxx: 0..32767
|
|
|
|
The end of the modification log is marked by a 0 byte.
|
|
|
|
In summary, the compressed page looks like this:
|
|
|
|
(1) Uncompressed page header (PAGE_DATA bytes)
|
|
(2) Compressed index information
|
|
(3) Compressed page data
|
|
(4) Page modification log (page_zip->m_start..page_zip->m_end)
|
|
(5) Empty zero-filled space
|
|
(6) BLOB pointers (on leaf pages)
|
|
- BTR_EXTERN_FIELD_REF_SIZE for each externally stored column
|
|
- in descending collation order
|
|
(7) Uncompressed columns of user records, n_dense * uncompressed_size bytes,
|
|
- indexed by heap_no
|
|
- DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN for leaf pages of clustered indexes
|
|
- REC_NODE_PTR_SIZE for non-leaf pages
|
|
- 0 otherwise
|
|
(8) dense page directory, stored backwards
|
|
- n_dense = n_heap - 2
|
|
- existing records in ascending collation order
|
|
- deleted records (free list) in link order
|
|
*/
|
|
|
|
/* Start offset of the area that will be compressed */
|
|
#define PAGE_ZIP_START PAGE_NEW_SUPREMUM_END
|
|
/* Size of an compressed page directory entry */
|
|
#define PAGE_ZIP_DIR_SLOT_SIZE 2
|
|
/* Mask of record offsets */
|
|
#define PAGE_ZIP_DIR_SLOT_MASK 0x3fff
|
|
/* 'owned' flag */
|
|
#define PAGE_ZIP_DIR_SLOT_OWNED 0x4000
|
|
/* 'deleted' flag */
|
|
#define PAGE_ZIP_DIR_SLOT_DEL 0x8000
|
|
|
|
/**************************************************************************
|
|
Determine the size of a compressed page in bytes. */
|
|
UNIV_INLINE
|
|
ulint
|
|
page_zip_get_size(
|
|
/*==============*/
|
|
/* out: size in bytes */
|
|
const page_zip_des_t* page_zip) /* in: compressed page */
|
|
{
|
|
ulint size;
|
|
|
|
if (UNIV_UNLIKELY(!page_zip->ssize)) {
|
|
return(0);
|
|
}
|
|
|
|
size = (PAGE_ZIP_MIN_SIZE >> 1) << page_zip->ssize;
|
|
|
|
ut_ad(size >= PAGE_ZIP_MIN_SIZE);
|
|
ut_ad(size <= UNIV_PAGE_SIZE);
|
|
|
|
return(size);
|
|
}
|
|
/**************************************************************************
|
|
Set the size of a compressed page in bytes. */
|
|
UNIV_INLINE
|
|
void
|
|
page_zip_set_size(
|
|
/*==============*/
|
|
page_zip_des_t* page_zip, /* in/out: compressed page */
|
|
ulint size) /* in: size in bytes */
|
|
{
|
|
if (size) {
|
|
int ssize;
|
|
|
|
ut_ad(ut_is_2pow(size));
|
|
|
|
for (ssize = 1; size > (ulint) (512 << ssize); ssize++);
|
|
|
|
page_zip->ssize = ssize;
|
|
} else {
|
|
page_zip->ssize = 0;
|
|
}
|
|
|
|
ut_ad(page_zip_get_size(page_zip) == size);
|
|
}
|
|
|
|
/**************************************************************************
|
|
Determine if a record is so big that it needs to be stored externally. */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_zip_rec_needs_ext(
|
|
/*===================*/
|
|
/* out: FALSE if the entire record
|
|
can be stored locally on the page */
|
|
ulint rec_size, /* in: length of the record in bytes */
|
|
ulint comp, /* in: nonzero=compact format */
|
|
ulint n_fields, /* in: number of fields in the record;
|
|
ignored if zip_size == 0 */
|
|
ulint zip_size) /* in: compressed page size in bytes, or 0 */
|
|
{
|
|
ut_ad(rec_size > comp ? REC_N_NEW_EXTRA_BYTES : REC_N_OLD_EXTRA_BYTES);
|
|
ut_ad(ut_is_2pow(zip_size));
|
|
ut_ad(comp || !zip_size);
|
|
|
|
#if UNIV_PAGE_SIZE > REC_MAX_DATA_SIZE
|
|
if (UNIV_UNLIKELY(rec_size >= REC_MAX_DATA_SIZE)) {
|
|
return(TRUE);
|
|
}
|
|
#endif
|
|
|
|
if (UNIV_UNLIKELY(zip_size)) {
|
|
ut_ad(comp);
|
|
/* On a compressed page, there is a two-byte entry in
|
|
the dense page directory for every record. But there
|
|
is no record header. There should be enough room for
|
|
one record on an empty leaf page. Subtract 1 byte for
|
|
the encoded heap number. Check also the available space
|
|
on the uncompressed page. */
|
|
return(rec_size - (REC_N_NEW_EXTRA_BYTES - 2)
|
|
>= (page_zip_empty_size(n_fields, zip_size) - 1)
|
|
|| rec_size >= page_get_free_space_of_empty(TRUE) / 2);
|
|
}
|
|
|
|
return(rec_size >= page_get_free_space_of_empty(comp) / 2);
|
|
}
|
|
|
|
#ifdef UNIV_DEBUG
|
|
/**************************************************************************
|
|
Validate a compressed page descriptor. */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_zip_simple_validate(
|
|
/*=====================*/
|
|
/* out: TRUE if ok */
|
|
const page_zip_des_t* page_zip)/* in: compressed page descriptor */
|
|
{
|
|
ut_ad(page_zip);
|
|
ut_ad(page_zip->data);
|
|
ut_ad(page_zip->ssize < PAGE_ZIP_NUM_SSIZE);
|
|
ut_ad(page_zip_get_size(page_zip)
|
|
> PAGE_DATA + PAGE_ZIP_DIR_SLOT_SIZE);
|
|
ut_ad(page_zip->m_start <= page_zip->m_end);
|
|
ut_ad(page_zip->m_end < page_zip_get_size(page_zip));
|
|
ut_ad(page_zip->n_blobs
|
|
< page_zip_get_size(page_zip) / BTR_EXTERN_FIELD_REF_SIZE);
|
|
return(TRUE);
|
|
}
|
|
#endif /* UNIV_DEBUG */
|
|
|
|
/**************************************************************************
|
|
Determine if the length of the page trailer. */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_zip_get_trailer_len(
|
|
/*=====================*/
|
|
/* out: length of the page trailer,
|
|
in bytes, not including the terminating
|
|
zero byte of the modification log */
|
|
const page_zip_des_t* page_zip,/* in: compressed page */
|
|
ibool is_clust,/* in: TRUE if clustered index */
|
|
ulint* entry_size)/* out: size of the uncompressed
|
|
portion of a user record */
|
|
{
|
|
ulint uncompressed_size;
|
|
|
|
ut_ad(page_zip_simple_validate(page_zip));
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
|
|
|
if (UNIV_UNLIKELY(!page_is_leaf(page_zip->data))) {
|
|
uncompressed_size = PAGE_ZIP_DIR_SLOT_SIZE
|
|
+ REC_NODE_PTR_SIZE;
|
|
ut_ad(!page_zip->n_blobs);
|
|
} else if (UNIV_UNLIKELY(is_clust)) {
|
|
uncompressed_size = PAGE_ZIP_DIR_SLOT_SIZE
|
|
+ DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN;
|
|
} else {
|
|
uncompressed_size = PAGE_ZIP_DIR_SLOT_SIZE;
|
|
ut_ad(!page_zip->n_blobs);
|
|
}
|
|
|
|
if (entry_size) {
|
|
*entry_size = uncompressed_size;
|
|
}
|
|
|
|
return((page_dir_get_n_heap(page_zip->data) - 2)
|
|
* uncompressed_size
|
|
+ page_zip->n_blobs * BTR_EXTERN_FIELD_REF_SIZE);
|
|
}
|
|
|
|
/**************************************************************************
|
|
Determine how big record can be inserted without recompressing the page. */
|
|
UNIV_INLINE
|
|
lint
|
|
page_zip_max_ins_size(
|
|
/*==================*/
|
|
/* out: a positive number
|
|
indicating the maximum size of
|
|
a record whose insertion is
|
|
guaranteed to succeed, or
|
|
zero or negative */
|
|
const page_zip_des_t* page_zip,/* in: compressed page */
|
|
ibool is_clust)/* in: TRUE if clustered index */
|
|
{
|
|
ulint uncompressed_size;
|
|
ulint trailer_len;
|
|
|
|
trailer_len = page_zip_get_trailer_len(page_zip, is_clust,
|
|
&uncompressed_size);
|
|
|
|
/* When a record is created, a pointer may be added to
|
|
the dense directory.
|
|
Likewise, space for the columns that will not be
|
|
compressed will be allocated from the page trailer.
|
|
Also the BLOB pointers will be allocated from there, but
|
|
we may as well count them in the length of the record. */
|
|
|
|
trailer_len += uncompressed_size;
|
|
|
|
return((lint) page_zip_get_size(page_zip)
|
|
- trailer_len - page_zip->m_end
|
|
- (REC_N_NEW_EXTRA_BYTES - 2));
|
|
}
|
|
|
|
/**************************************************************************
|
|
Determine if enough space is available in the modification log. */
|
|
UNIV_INLINE
|
|
ibool
|
|
page_zip_available(
|
|
/*===============*/
|
|
/* out: TRUE if enough space
|
|
is available */
|
|
const page_zip_des_t* page_zip,/* in: compressed page */
|
|
ibool is_clust,/* in: TRUE if clustered index */
|
|
ulint length, /* in: combined size of the record */
|
|
ulint create) /* in: nonzero=add the record to
|
|
the heap */
|
|
{
|
|
ulint uncompressed_size;
|
|
ulint trailer_len;
|
|
|
|
ut_ad(length > REC_N_NEW_EXTRA_BYTES);
|
|
|
|
trailer_len = page_zip_get_trailer_len(page_zip, is_clust,
|
|
&uncompressed_size);
|
|
|
|
/* Subtract the fixed extra bytes and add the maximum
|
|
space needed for identifying the record (encoded heap_no). */
|
|
length -= REC_N_NEW_EXTRA_BYTES - 2;
|
|
|
|
if (UNIV_UNLIKELY(create)) {
|
|
/* When a record is created, a pointer may be added to
|
|
the dense directory.
|
|
Likewise, space for the columns that will not be
|
|
compressed will be allocated from the page trailer.
|
|
Also the BLOB pointers will be allocated from there, but
|
|
we may as well count them in the length of the record. */
|
|
|
|
trailer_len += uncompressed_size;
|
|
}
|
|
|
|
return(UNIV_LIKELY(length
|
|
+ trailer_len
|
|
+ page_zip->m_end
|
|
< page_zip_get_size(page_zip)));
|
|
}
|
|
|
|
/**************************************************************************
|
|
Initialize a compressed page descriptor. */
|
|
UNIV_INLINE
|
|
void
|
|
page_zip_des_init(
|
|
/*==============*/
|
|
page_zip_des_t* page_zip) /* in/out: compressed page
|
|
descriptor */
|
|
{
|
|
memset(page_zip, 0, sizeof *page_zip);
|
|
}
|
|
|
|
/**************************************************************************
|
|
Write a log record of writing to the uncompressed header portion of a page. */
|
|
UNIV_INTERN
|
|
void
|
|
page_zip_write_header_log(
|
|
/*======================*/
|
|
const byte* data,/* in: data on the uncompressed page */
|
|
ulint length, /* in: length of the data */
|
|
mtr_t* mtr); /* in: mini-transaction */
|
|
|
|
/**************************************************************************
|
|
Write data to the uncompressed header portion of a page. The data must
|
|
already have been written to the uncompressed page.
|
|
However, the data portion of the uncompressed page may differ from
|
|
the compressed page when a record is being inserted in
|
|
page_cur_insert_rec_zip(). */
|
|
UNIV_INLINE
|
|
void
|
|
page_zip_write_header(
|
|
/*==================*/
|
|
page_zip_des_t* page_zip,/* in/out: compressed page */
|
|
const byte* str, /* in: address on the uncompressed page */
|
|
ulint length, /* in: length of the data */
|
|
mtr_t* mtr) /* in: mini-transaction, or NULL */
|
|
{
|
|
ulint pos;
|
|
|
|
ut_ad(buf_frame_get_page_zip(str) == page_zip);
|
|
ut_ad(page_zip_simple_validate(page_zip));
|
|
UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip));
|
|
|
|
pos = page_offset(str);
|
|
|
|
ut_ad(pos < PAGE_DATA);
|
|
|
|
memcpy(page_zip->data + pos, str, length);
|
|
|
|
/* The following would fail in page_cur_insert_rec_zip(). */
|
|
/* ut_ad(page_zip_validate(page_zip, str - pos)); */
|
|
|
|
if (UNIV_LIKELY_NULL(mtr)) {
|
|
page_zip_write_header_log(str, length, mtr);
|
|
}
|
|
}
|
|
|
|
#ifdef UNIV_MATERIALIZE
|
|
# undef UNIV_INLINE
|
|
# define UNIV_INLINE UNIV_INLINE_ORIGINAL
|
|
#endif
|