Commit 5af53464 authored by Marko Mäkelä's avatar Marko Mäkelä

Remove code duplication in rem0rec.ic

Assert that the flags EXTERNAL, DEFAULT, and NULL are mutually exclusive.
parent dce195b1
...@@ -101,6 +101,22 @@ offsets[] array, first passed to rec_get_offsets() */ ...@@ -101,6 +101,22 @@ offsets[] array, first passed to rec_get_offsets() */
#define REC_OFFS_NORMAL_SIZE OFFS_IN_REC_NORMAL_SIZE #define REC_OFFS_NORMAL_SIZE OFFS_IN_REC_NORMAL_SIZE
#define REC_OFFS_SMALL_SIZE 10 #define REC_OFFS_SMALL_SIZE 10
/** Get the base address of offsets. The extra_size is stored at
this position, and following positions hold the end offsets of
the fields. */
#define rec_offs_base(offsets) (offsets + REC_OFFS_HEADER_SIZE)
/** Compact flag ORed to the extra size returned by rec_get_offsets() */
const ulint REC_OFFS_COMPACT = ~(ulint(~0) >> 1);
/** SQL NULL flag in offsets returned by rec_get_offsets() */
const ulint REC_OFFS_SQL_NULL = REC_OFFS_COMPACT;
/** External flag in offsets returned by rec_get_offsets() */
const ulint REC_OFFS_EXTERNAL = REC_OFFS_COMPACT >> 1;
/** Default value flag in offsets returned by rec_get_offsets() */
const ulint REC_OFFS_DEFAULT = REC_OFFS_COMPACT >> 2;
/** Mask for offsets returned by rec_get_offsets() */
const ulint REC_OFFS_MASK = REC_OFFS_DEFAULT - 1;
#ifndef UNIV_INNOCHECKSUM #ifndef UNIV_INNOCHECKSUM
/******************************************************//** /******************************************************//**
The following function is used to get the pointer of the next chained record The following function is used to get the pointer of the next chained record
...@@ -591,26 +607,6 @@ rec_get_nth_cfield( ...@@ -591,26 +607,6 @@ rec_get_nth_cfield(
#define rec_get_nth_field(rec, offsets, n, len) \ #define rec_get_nth_field(rec, offsets, n, len) \
(byte*)rec_get_nth_cfield(rec, offsets, n, NULL, NULL, len) (byte*)rec_get_nth_cfield(rec, offsets, n, NULL, NULL, len)
/******************************************************//**
Determine if the offsets are for a record in the new
compact format.
@return nonzero if compact format */
UNIV_INLINE
ulint
rec_offs_comp(
/*==========*/
const ulint* offsets)/*!< in: array returned by rec_get_offsets() */
MY_ATTRIBUTE((warn_unused_result));
/******************************************************//**
Determine if the offsets are for a record containing
externally stored columns.
@return nonzero if externally stored */
UNIV_INLINE
ulint
rec_offs_any_extern(
/*================*/
const ulint* offsets)/*!< in: array returned by rec_get_offsets() */
MY_ATTRIBUTE((warn_unused_result));
/******************************************************//** /******************************************************//**
Determine if the offsets are for a record containing null BLOB pointers. Determine if the offsets are for a record containing null BLOB pointers.
@return first field containing a null BLOB pointer, or NULL if none found */ @return first field containing a null BLOB pointer, or NULL if none found */
...@@ -621,26 +617,6 @@ rec_offs_any_null_extern( ...@@ -621,26 +617,6 @@ rec_offs_any_null_extern(
const rec_t* rec, /*!< in: record */ const rec_t* rec, /*!< in: record */
const ulint* offsets) /*!< in: rec_get_offsets(rec) */ const ulint* offsets) /*!< in: rec_get_offsets(rec) */
MY_ATTRIBUTE((warn_unused_result)); MY_ATTRIBUTE((warn_unused_result));
/******************************************************//**
Determine if the offsets are for a record containing
default value for instant added columns.
@return nonzero if externally stored */
UNIV_INLINE
ulint
rec_offs_any_default(
/*================*/
const ulint* offsets)/*!< in: array returned by rec_get_offsets() */
MY_ATTRIBUTE((warn_unused_result));
/******************************************************//**
Returns nonzero if the extern bit is set in nth field of rec.
@return nonzero if externally stored */
UNIV_INLINE
ulint
rec_offs_nth_extern(
/*================*/
const ulint* offsets,/*!< in: array returned by rec_get_offsets() */
ulint n) /*!< in: nth field */
MY_ATTRIBUTE((warn_unused_result));
/******************************************************//** /******************************************************//**
Returns nonzero if the extern bit is set in nth field of rec. Returns nonzero if the extern bit is set in nth field of rec.
...@@ -660,16 +636,141 @@ void ...@@ -660,16 +636,141 @@ void
rec_offs_make_nth_extern( rec_offs_make_nth_extern(
ulint* offsets, ulint* offsets,
const ulint n); const ulint n);
/******************************************************//**
Returns nonzero if the SQL NULL bit is set in nth field of rec. /** Determine the number of allocated elements for an array of offsets.
@return nonzero if SQL NULL */ @param[in] offsets offsets after rec_offs_set_n_alloc()
UNIV_INLINE @return number of elements */
inline
ulint ulint
rec_offs_nth_sql_null( rec_offs_get_n_alloc(const ulint* offsets)
/*==================*/ {
const ulint* offsets,/*!< in: array returned by rec_get_offsets() */ ulint n_alloc;
ulint n) /*!< in: nth field */ ut_ad(offsets);
MY_ATTRIBUTE((warn_unused_result)); n_alloc = offsets[0];
ut_ad(n_alloc > REC_OFFS_HEADER_SIZE);
UNIV_MEM_ASSERT_W(offsets, n_alloc * sizeof *offsets);
return(n_alloc);
}
/** Determine the number of fields for which offsets have been initialized.
@param[in] offsets rec_get_offsets()
@return number of fields */
inline
ulint
rec_offs_n_fields(const ulint* offsets)
{
ulint n_fields;
ut_ad(offsets);
n_fields = offsets[1];
ut_ad(n_fields > 0);
ut_ad(n_fields <= REC_MAX_N_FIELDS);
ut_ad(n_fields + REC_OFFS_HEADER_SIZE
<= rec_offs_get_n_alloc(offsets));
return(n_fields);
}
/** Get a flag of a record field.
@param[in] offsets rec_get_offsets()
@param[in] n nth field
@param[in] flag flag to extract
@return the flag of the record field */
inline
ulint
rec_offs_nth_flag(const ulint* offsets, ulint n, ulint flag)
{
ut_ad(rec_offs_validate(NULL, NULL, offsets));
ut_ad(n < rec_offs_n_fields(offsets));
/* The DEFAULT, NULL, EXTERNAL flags are mutually exclusive. */
ut_ad(ut_is_2pow(rec_offs_base(offsets)[1 + n]
& (REC_OFFS_DEFAULT
| REC_OFFS_SQL_NULL
| REC_OFFS_EXTERNAL)));
return rec_offs_base(offsets)[1 + n] & flag;
}
/** Determine if a record field is missing
(should be replaced by dict_col_t::def_val).
@param[in] offsets rec_get_offsets()
@param[in] n nth field
@return nonzero if default bit is set */
inline
ulint
rec_offs_nth_default(const ulint* offsets, ulint n)
{
return rec_offs_nth_flag(offsets, n, REC_OFFS_DEFAULT);
}
/** Determine if a record field is SQL NULL
(should be replaced by dict_col_t::def_val).
@param[in] offsets rec_get_offsets()
@param[in] n nth field
@return nonzero if SQL NULL set */
inline
ulint
rec_offs_nth_sql_null(const ulint* offsets, ulint n)
{
return rec_offs_nth_flag(offsets, n, REC_OFFS_SQL_NULL);
}
/** Determine if a record field is stored off-page.
@param[in] offsets rec_get_offsets()
@param[in] n nth field
Returns nonzero if the extern bit is set in nth field of rec.
@return nonzero if externally stored */
inline
ulint
rec_offs_nth_extern(const ulint* offsets, ulint n)
{
return rec_offs_nth_flag(offsets, n, REC_OFFS_EXTERNAL);
}
/** Get a global flag of a record.
@param[in] offsets rec_get_offsets()
@param[in] flag flag to extract
@return the flag of the record field */
inline
ulint
rec_offs_any_flag(const ulint* offsets, ulint flag)
{
ut_ad(rec_offs_validate(NULL, NULL, offsets));
/* The DEFAULT, EXTERNAL flags are mutually exclusive. */
ut_ad(ut_is_2pow(*rec_offs_base(offsets)
& (REC_OFFS_DEFAULT | REC_OFFS_EXTERNAL)));
return *rec_offs_base(offsets) & flag;
}
/** Determine if the offsets are for a record containing off-page columns.
@param[in] offsets rec_get_offsets()
@return nonzero if any off-page columns exist */
inline
ulint
rec_offs_any_extern(const ulint* offsets)
{
return rec_offs_any_flag(offsets, REC_OFFS_EXTERNAL);
}
/** Determine if the offsets are for a record that is missing fields.
@param[in] offsets rec_get_offsets()
@return nonzero if any fields need to be replaced with dict_col_t::def_val. */
inline
ulint
rec_offs_any_default(const ulint* offsets)
{
return rec_offs_any_flag(offsets, REC_OFFS_DEFAULT);
}
/** Determine if the offsets are for other than ROW_FORMAT=REDUNDANT.
@param[in] offsets rec_get_offsets()
@return nonzero if ROW_FORMAT is COMPACT,DYNAMIC or COMPRESSED
@retval 0 if ROW_FORMAT=REDUNDANT */
inline
ulint
rec_offs_comp(const ulint* offsets)
{
ut_ad(rec_offs_validate(NULL, NULL, offsets));
return(*rec_offs_base(offsets) & REC_OFFS_COMPACT);
}
/******************************************************//** /******************************************************//**
Gets the physical size of a field. Gets the physical size of a field.
@return length of field */ @return length of field */
...@@ -723,16 +824,6 @@ rec_get_data_size_old( ...@@ -723,16 +824,6 @@ rec_get_data_size_old(
const rec_t* rec) /*!< in: physical record */ const rec_t* rec) /*!< in: physical record */
MY_ATTRIBUTE((warn_unused_result)); MY_ATTRIBUTE((warn_unused_result));
/**********************************************************//** /**********************************************************//**
The following function returns the number of allocated elements
for an array of offsets.
@return number of elements */
UNIV_INLINE
ulint
rec_offs_get_n_alloc(
/*=================*/
const ulint* offsets)/*!< in: array for rec_get_offsets() */
MY_ATTRIBUTE((warn_unused_result));
/**********************************************************//**
The following function sets the number of allocated elements The following function sets the number of allocated elements
for an array of offsets. */ for an array of offsets. */
UNIV_INLINE UNIV_INLINE
...@@ -746,15 +837,6 @@ rec_offs_set_n_alloc( ...@@ -746,15 +837,6 @@ rec_offs_set_n_alloc(
#define rec_offs_init(offsets) \ #define rec_offs_init(offsets) \
rec_offs_set_n_alloc(offsets, (sizeof offsets) / sizeof *offsets) rec_offs_set_n_alloc(offsets, (sizeof offsets) / sizeof *offsets)
/**********************************************************//** /**********************************************************//**
The following function returns the number of fields in a record.
@return number of fields */
UNIV_INLINE
ulint
rec_offs_n_fields(
/*==============*/
const ulint* offsets)/*!< in: array returned by rec_get_offsets() */
MY_ATTRIBUTE((warn_unused_result));
/**********************************************************//**
The following function returns the data size of a physical The following function returns the data size of a physical
record, that is the sum of field lengths. SQL null fields record, that is the sum of field lengths. SQL null fields
are counted as length 0 fields. The value returned by the function are counted as length 0 fields. The value returned by the function
...@@ -1053,16 +1135,6 @@ rec_print( ...@@ -1053,16 +1135,6 @@ rec_print(
ulint info, ulint info,
const ulint* offsets); const ulint* offsets);
/******************************************************//**
Returns nonzero if the default bit is set in nth field of rec.
@return nonzero if default bit is set */
UNIV_INLINE
ulint
rec_offs_nth_default(
/*================*/
const ulint* offsets,/*!< in: array returned by rec_get_offsets() */
ulint n); /*!< in: nth field */
/******************************************************//** /******************************************************//**
set instant flag */ set instant flag */
UNIV_INLINE UNIV_INLINE
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 1994, 2015, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1994, 2015, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under 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 the terms of the GNU General Public License as published by the Free Software
...@@ -29,17 +30,6 @@ Created 5/30/1994 Heikki Tuuri ...@@ -29,17 +30,6 @@ Created 5/30/1994 Heikki Tuuri
#include "dict0boot.h" #include "dict0boot.h"
#include "btr0types.h" #include "btr0types.h"
/** Compact flag ORed to the extra size returned by rec_get_offsets() */
const ulint REC_OFFS_COMPACT = ~(ulint(~0) >> 1);
/** SQL NULL flag in offsets returned by rec_get_offsets() */
const ulint REC_OFFS_SQL_NULL = REC_OFFS_COMPACT;
/** External flag in offsets returned by rec_get_offsets() */
const ulint REC_OFFS_EXTERNAL = REC_OFFS_COMPACT >> 1;
/** Default value flag in offsets returned by rec_get_offsets() */
const ulint REC_OFFS_DEFAULT = REC_OFFS_COMPACT >> 2;
/** Mask for offsets returned by rec_get_offsets() */
const ulint REC_OFFS_MASK = REC_OFFS_DEFAULT - 1;
/* Offsets of the bit-fields in an old-style record. NOTE! In the table the /* Offsets of the bit-fields in an old-style record. NOTE! In the table the
most significant bytes and bits are written below less significant. most significant bytes and bits are written below less significant.
...@@ -928,29 +918,6 @@ rec_2_is_field_extern( ...@@ -928,29 +918,6 @@ rec_2_is_field_extern(
return(rec_2_get_field_end_info(rec, n) & REC_2BYTE_EXTERN_MASK); return(rec_2_get_field_end_info(rec, n) & REC_2BYTE_EXTERN_MASK);
} }
/* Get the base address of offsets. The extra_size is stored at
this position, and following positions hold the end offsets of
the fields. */
#define rec_offs_base(offsets) (offsets + REC_OFFS_HEADER_SIZE)
/**********************************************************//**
The following function returns the number of allocated elements
for an array of offsets.
@return number of elements */
UNIV_INLINE
ulint
rec_offs_get_n_alloc(
/*=================*/
const ulint* offsets)/*!< in: array for rec_get_offsets() */
{
ulint n_alloc;
ut_ad(offsets);
n_alloc = offsets[0];
ut_ad(n_alloc > REC_OFFS_HEADER_SIZE);
UNIV_MEM_ASSERT_W(offsets, n_alloc * sizeof *offsets);
return(n_alloc);
}
/**********************************************************//** /**********************************************************//**
The following function sets the number of allocated elements The following function sets the number of allocated elements
for an array of offsets. */ for an array of offsets. */
...@@ -968,25 +935,6 @@ rec_offs_set_n_alloc( ...@@ -968,25 +935,6 @@ rec_offs_set_n_alloc(
offsets[0] = n_alloc; offsets[0] = n_alloc;
} }
/**********************************************************//**
The following function returns the number of fields in a record.
@return number of fields */
UNIV_INLINE
ulint
rec_offs_n_fields(
/*==============*/
const ulint* offsets)/*!< in: array returned by rec_get_offsets() */
{
ulint n_fields;
ut_ad(offsets);
n_fields = offsets[1];
ut_ad(n_fields > 0);
ut_ad(n_fields <= REC_MAX_N_FIELDS);
ut_ad(n_fields + REC_OFFS_HEADER_SIZE
<= rec_offs_get_n_alloc(offsets));
return(n_fields);
}
/************************************************************//** /************************************************************//**
The following function is used to get an offset to the nth The following function is used to get an offset to the nth
data field in a record. data field in a record.
...@@ -1026,48 +974,6 @@ rec_get_nth_field_offs( ...@@ -1026,48 +974,6 @@ rec_get_nth_field_offs(
return(offs); return(offs);
} }
/******************************************************//**
Determine if the offsets are for a record in the new
compact format.
@return nonzero if compact format */
UNIV_INLINE
ulint
rec_offs_comp(
/*==========*/
const ulint* offsets)/*!< in: array returned by rec_get_offsets() */
{
ut_ad(rec_offs_validate(NULL, NULL, offsets));
return(*rec_offs_base(offsets) & REC_OFFS_COMPACT);
}
/******************************************************//**
Determine if the offsets are for a record containing
externally stored columns.
@return nonzero if externally stored */
UNIV_INLINE
ulint
rec_offs_any_extern(
/*================*/
const ulint* offsets)/*!< in: array returned by rec_get_offsets() */
{
ut_ad(rec_offs_validate(NULL, NULL, offsets));
return(*rec_offs_base(offsets) & REC_OFFS_EXTERNAL);
}
/******************************************************//**
Determine if the offsets are for a record containing
default value for instant added columns.
@return nonzero if externally stored */
UNIV_INLINE
ulint
rec_offs_any_default(
/*================*/
const ulint* offsets)/*!< in: array returned by rec_get_offsets() */
{
ut_ad(rec_offs_validate(NULL, NULL, offsets));
return(*rec_offs_base(offsets) & REC_OFFS_DEFAULT);
}
/******************************************************//** /******************************************************//**
Determine if the offsets are for a record containing null BLOB pointers. Determine if the offsets are for a record containing null BLOB pointers.
@return first field containing a null BLOB pointer, or NULL if none found */ @return first field containing a null BLOB pointer, or NULL if none found */
...@@ -1104,21 +1010,6 @@ rec_offs_any_null_extern( ...@@ -1104,21 +1010,6 @@ rec_offs_any_null_extern(
return(NULL); return(NULL);
} }
/******************************************************//**
Returns nonzero if the extern bit is set in nth field of rec.
@return nonzero if externally stored */
UNIV_INLINE
ulint
rec_offs_nth_extern(
/*================*/
const ulint* offsets,/*!< in: array returned by rec_get_offsets() */
ulint n) /*!< in: nth field */
{
ut_ad(rec_offs_validate(NULL, NULL, offsets));
ut_ad(n < rec_offs_n_fields(offsets));
return(rec_offs_base(offsets)[1 + n] & REC_OFFS_EXTERNAL);
}
/******************************************************//** /******************************************************//**
Returns nonzero if the extern bit is set in nth field of rec. Returns nonzero if the extern bit is set in nth field of rec.
@return nonzero if externally stored */ @return nonzero if externally stored */
...@@ -1134,38 +1025,6 @@ rec_offs_nth_extern_old( ...@@ -1134,38 +1025,6 @@ rec_offs_nth_extern_old(
return (rec_2_get_field_end_info(rec,n) & REC_2BYTE_EXTERN_MASK); return (rec_2_get_field_end_info(rec,n) & REC_2BYTE_EXTERN_MASK);
} }
/******************************************************//**
Returns nonzero if the default bit is set in nth field of rec.
@return nonzero if default bit is set */
UNIV_INLINE
ulint
rec_offs_nth_default(
/*================*/
const ulint* offsets,/*!< in: array returned by rec_get_offsets() */
ulint n) /*!< in: nth field */
{
ut_ad(rec_offs_validate(NULL, NULL, offsets));
ut_ad(n < rec_offs_n_fields(offsets));
return(rec_offs_base(offsets)[1 + n] & REC_OFFS_DEFAULT);
}
/******************************************************//**
Returns nonzero if the SQL NULL bit is set in nth field of rec.
@return nonzero if SQL NULL */
UNIV_INLINE
ulint
rec_offs_nth_sql_null(
/*==================*/
const ulint* offsets,/*!< in: array returned by rec_get_offsets() */
ulint n) /*!< in: nth field */
{
ut_ad(rec_offs_validate(NULL, NULL, offsets));
ut_ad(n < rec_offs_n_fields(offsets));
ulint ret = (rec_offs_base(offsets)[1 + n] & REC_OFFS_SQL_NULL);
ut_ad(!ret || !rec_offs_nth_default(offsets, n));
return ret;
}
/******************************************************//** /******************************************************//**
Gets the physical size of a field. Gets the physical size of a field.
@return length of field */ @return length of field */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment