Skip to content

Commit 330c621

Browse files
midenokdr-m
authored andcommitted
Replace dict_instant_t::non_pk_col_map with field_map
1 parent a044e32 commit 330c621

File tree

5 files changed

+85
-58
lines changed

5 files changed

+85
-58
lines changed

extra/innochecksum.cc

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,12 @@
4242
/* Only parts of these files are included from the InnoDB codebase.
4343
The parts not included are excluded by #ifndef UNIV_INNOCHECKSUM. */
4444

45-
typedef void fil_space_t;
46-
47-
#include "page0size.h"
48-
#include "ut0ut.h"
49-
#include "mtr0types.h"
5045
#include "mach0data.h"
51-
#include "fsp0types.h"
52-
#include "rem0rec.h"
46+
#include "page0page.h"
5347
#include "buf0checksum.h" /* buf_calc_page_*() */
5448
#include "buf0buf.h" /* buf_page_is_corrupted */
55-
#include "fil0fil.h" /* FIL_* */
56-
#include "page0page.h" /* PAGE_* */
5749
#include "page0zip.h" /* page_zip_*() */
5850
#include "trx0undo.h" /* TRX_* */
59-
#include "fsp0fsp.h" /* fsp_flags_get_page_size() &
60-
fsp_flags_get_zip_size() */
6151
#include "ut0crc32.h" /* ut_crc32_init() */
6252
#include "fsp0pagecompress.h" /* fil_get_compression_alg_name */
6353
#include "fil0crypt.h" /* fil_space_verify_crypt_checksum */

storage/innobase/dict/dict0mem.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,23 +1216,24 @@ inline void dict_index_t::reconstruct_fields()
12161216
n_nullable = 0;
12171217
ulint n_core_null = 0;
12181218
const bool comp = dict_table_is_comp(table);
1219-
const auto* non_pk_col_map = table->instant->non_pk_col_map;
1219+
const auto* field_map_it = table->instant->field_map;
12201220
for (unsigned i = n_first, j = 0; i < n_fields; ) {
12211221
dict_field_t& f = tfields[i++];
1222-
auto c = *non_pk_col_map++;
1223-
if (c & 1U << 15) {
1222+
auto c = *field_map_it++;
1223+
if (c.is_dropped()) {
12241224
f.col = &table->instant->dropped[j++];
12251225
DBUG_ASSERT(f.col->is_dropped());
12261226
f.fixed_len = dict_col_get_fixed_size(f.col, comp);
12271227
} else {
1228+
DBUG_ASSERT(!c.is_not_null());
12281229
const auto old = std::find_if(
12291230
fields + n_first, fields + n_fields,
12301231
[c](const dict_field_t& o)
1231-
{ return o.col->ind == c; });
1232+
{ return o.col->ind == c.ind(); });
12321233
ut_ad(old >= &fields[n_first]);
12331234
ut_ad(old < &fields[n_fields]);
12341235
DBUG_ASSERT(!old->prefix_len);
1235-
DBUG_ASSERT(old->col == &table->cols[c]);
1236+
DBUG_ASSERT(old->col == &table->cols[c.ind()]);
12361237
f = *old;
12371238
}
12381239

@@ -1269,23 +1270,22 @@ bool dict_table_t::deserialise_columns(const byte* metadata, ulint len)
12691270
return true;
12701271
}
12711272

1272-
uint16_t* non_pk_col_map = static_cast<uint16_t*>(
1273+
field_map_element_t* field_map = static_cast<field_map_element_t*>(
12731274
mem_heap_alloc(heap,
1274-
num_non_pk_fields * sizeof *non_pk_col_map));
1275+
num_non_pk_fields * sizeof *field_map));
12751276

12761277
unsigned n_dropped_cols = 0;
12771278

12781279
for (unsigned i = 0; i < num_non_pk_fields; i++) {
1279-
non_pk_col_map[i] = mach_read_from_2(metadata);
1280+
auto c = field_map[i] = mach_read_from_2(metadata);
12801281
metadata += 2;
12811282

1282-
if (non_pk_col_map[i] & 1U << 15) {
1283-
if ((non_pk_col_map[i] & ~(3U << 14))
1284-
> DICT_MAX_FIXED_COL_LEN + 1) {
1283+
if (field_map[i].is_dropped()) {
1284+
if (c.ind() > DICT_MAX_FIXED_COL_LEN + 1) {
12851285
return true;
12861286
}
12871287
n_dropped_cols++;
1288-
} else if (non_pk_col_map[i] >= n_cols) {
1288+
} else if (c >= n_cols) {
12891289
return true;
12901290
}
12911291
}
@@ -1295,14 +1295,14 @@ bool dict_table_t::deserialise_columns(const byte* metadata, ulint len)
12951295
instant = new (mem_heap_alloc(heap, sizeof *instant)) dict_instant_t();
12961296
instant->n_dropped = n_dropped_cols;
12971297
instant->dropped = dropped_cols;
1298-
instant->non_pk_col_map = non_pk_col_map;
1298+
instant->field_map = field_map;
12991299

13001300
dict_col_t* col = dropped_cols;
13011301
for (unsigned i = 0; i < num_non_pk_fields; i++) {
1302-
if (non_pk_col_map[i] & 1U << 15) {
1303-
auto fixed_len = non_pk_col_map[i] & ~(3U << 14);
1302+
if (field_map[i].is_dropped()) {
1303+
auto fixed_len = field_map[i].ind();
13041304
DBUG_ASSERT(fixed_len <= DICT_MAX_FIXED_COL_LEN + 1);
1305-
(col++)->set_dropped(non_pk_col_map[i] & 1U << 14,
1305+
(col++)->set_dropped(field_map[i].is_not_null(),
13061306
fixed_len == 1,
13071307
fixed_len > 1 ? fixed_len - 1
13081308
: 0);

storage/innobase/handler/handler0alter.cc

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static void instant_metadata_lock(dict_index_t& index, mtr_t& mtr)
160160
ut_ad(!buf_block_get_page_zip(btr_cur_get_block(&btr_cur)));
161161
}
162162

163-
/** Initialize instant->non_pk_col_map.
163+
/** Initialize instant->field_map.
164164
@tparam replace_dropped whether to point clustered index fields
165165
to instant->dropped[]
166166
@param[in] table table definition to copy from */
@@ -174,43 +174,34 @@ inline void dict_table_t::init_instant(const dict_table_t& table)
174174
DBUG_ASSERT(not_redundant() == table.not_redundant());
175175
DBUG_ASSERT(index.n_fields >= oindex.n_fields);
176176

177-
uint16_t* non_pk_col_map = static_cast<uint16_t*>(
177+
field_map_element_t* field_map_it = static_cast<field_map_element_t*>(
178178
mem_heap_zalloc(heap, (index.n_fields - u)
179-
* sizeof *non_pk_col_map));
180-
instant->non_pk_col_map = non_pk_col_map;
179+
* sizeof *field_map_it));
180+
instant->field_map = field_map_it;
181181

182182
ut_d(unsigned n_drop = 0);
183183
ut_d(unsigned n_nullable = 0);
184184
for (unsigned i = u; i < index.n_fields; i++) {
185185
auto& f = index.fields[i];
186186
DBUG_ASSERT(dict_col_get_fixed_size(f.col, not_redundant())
187187
<= DICT_MAX_FIXED_COL_LEN);
188-
#ifdef UNIV_DEBUG
189-
if (!f.col->is_nullable()) {
190-
ut_ad((*non_pk_col_map & 3U << 15) != 1U << 14);
191-
} else if ((*non_pk_col_map & 3U << 15) != 1U << 14) {
192-
n_nullable++;
193-
}
194-
#endif
188+
ut_d(n_nullable += f.col->is_nullable());
189+
195190
if (!f.col->is_dropped()) {
196-
auto c = *non_pk_col_map & 3U << 14;
197-
DBUG_ASSERT(!(c & 1U << 15));
198-
if (!c
199-
&& f.col->is_nullable()
200-
&& !oindex.fields[i].col->is_nullable()) {
201-
c = 1U << 14;
202-
}
203-
*non_pk_col_map++ = c | f.col->ind;
191+
(*field_map_it++).set_ind(f.col->ind);
204192
continue;
205193
}
206194

207195
auto fixed_len = dict_col_get_fixed_size(
208196
f.col, not_redundant());
209-
*non_pk_col_map++ = 1U << 15
210-
| uint16_t(!f.col->is_nullable()) << 14
211-
| (fixed_len
212-
? uint16_t(fixed_len + 1)
213-
: f.col->len > 255);
197+
field_map_it->set_dropped();
198+
if (!f.col->is_nullable()) {
199+
field_map_it->set_not_null();
200+
}
201+
field_map_it->set_ind(fixed_len
202+
? uint16_t(fixed_len + 1)
203+
: f.col->len > 255);
204+
field_map_it++;
214205
ut_ad(f.col >= table.instant->dropped);
215206
ut_ad(f.col < table.instant->dropped
216207
+ table.instant->n_dropped);
@@ -223,7 +214,7 @@ inline void dict_table_t::init_instant(const dict_table_t& table)
223214
}
224215
}
225216
ut_ad(n_drop == n_dropped());
226-
ut_ad(non_pk_col_map == &instant->non_pk_col_map[index.n_fields - u]);
217+
ut_ad(field_map_it == &instant->field_map[index.n_fields - u]);
227218
ut_ad(index.n_nullable == n_nullable);
228219
}
229220

@@ -5275,7 +5266,7 @@ void dict_table_t::serialise_columns(mem_heap_t* heap, dfield_t* field) const
52755266
data += 4;
52765267

52775268
for (ulint i = n_fixed; i < index.n_fields; i++) {
5278-
mach_write_to_2(data, instant->non_pk_col_map[i - n_fixed]);
5269+
mach_write_to_2(data, instant->field_map[i - n_fixed]);
52795270
data += 2;
52805271
}
52815272
}

storage/innobase/include/dict0mem.h

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,15 +1539,62 @@ struct dict_vcol_templ_t {
15391539
dict_vcol_templ_t() : vtempl(0), mysql_table_query_id(~0ULL) {}
15401540
};
15411541

1542+
/** Metadata on clustered index fields starting from first_user_field() */
1543+
class field_map_element_t
1544+
{
1545+
/** Number of bits for representing a column number */
1546+
static constexpr uint16_t IND_BITS = 10;
1547+
1548+
/** Set if the column of the field has been instantly dropped */
1549+
static constexpr uint16_t DROPPED = 1U << (IND_BITS + 5);
1550+
1551+
/** Set if the column was dropped and originally declared NOT NULL */
1552+
static constexpr uint16_t NOT_NULL = 1U << (IND_BITS + 4);
1553+
1554+
/** Column index (if !(data & DROPPED)): table->cols[data & IND],
1555+
or field length (if (data & DROPPED)):
1556+
(data & IND) = 0 if variable-length with max_len < 256 bytes;
1557+
(data & IND) = 1 if variable-length with max_len > 255 bytes;
1558+
(data & IND) = 1 + L otherwise, with L=fixed length of the column */
1559+
static constexpr uint16_t IND = (1U << IND_BITS) - 1;
1560+
1561+
/** Field metadata */
1562+
uint16_t data;
1563+
1564+
void clear_not_null() { data &= ~NOT_NULL; }
1565+
public:
1566+
bool is_dropped() const { return data & DROPPED; }
1567+
void set_dropped() { data |= DROPPED; }
1568+
bool is_not_null() const { return data & NOT_NULL; }
1569+
void set_not_null() { ut_ad(is_dropped()); data |= NOT_NULL; }
1570+
uint16_t ind() const { return data & IND; }
1571+
void set_ind(uint16_t i)
1572+
{
1573+
DBUG_ASSERT(i <= IND);
1574+
DBUG_ASSERT(!ind());
1575+
data |= i;
1576+
}
1577+
field_map_element_t& operator= (uint16_t value)
1578+
{
1579+
data = value;
1580+
return *this;
1581+
}
1582+
operator uint16_t() { return data; }
1583+
};
1584+
1585+
static_assert(sizeof(field_map_element_t) == 2,
1586+
"Size mismatch for a persistent data item!");
1587+
15421588
/** Instantly dropped or reordered columns */
15431589
struct dict_instant_t
15441590
{
15451591
/** Number of dropped columns */
15461592
unsigned n_dropped;
15471593
/** Dropped columns */
15481594
dict_col_t* dropped;
1549-
/** Mapping the non-pk field to column of the table. */
1550-
uint16_t* non_pk_col_map;
1595+
/** Map of clustered index non-PK fields[i - first_user_field()]
1596+
to table columns */
1597+
field_map_element_t* field_map;
15511598
};
15521599

15531600
/** These are used when MySQL FRM and InnoDB data dictionary are
@@ -1717,7 +1764,7 @@ struct dict_table_t {
17171764
}
17181765

17191766
private:
1720-
/** Initialize instant->non_pk_col_map.
1767+
/** Initialize instant->field_map.
17211768
@tparam replace_dropped whether to point clustered index fields
17221769
to instant->dropped[]
17231770
@param[in] table table definition to copy from */

storage/innobase/include/mach0data.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ Created 11/28/1995 Heikki Tuuri
2929
#define mach0data_h
3030

3131
#include "univ.i"
32+
#include "mtr0types.h"
3233

3334
#ifndef UNIV_INNOCHECKSUM
3435

35-
#include "mtr0types.h"
36-
3736
/* The data and all fields are always stored in a database file
3837
in the same format: ascii, big-endian, ... .
3938
All data in the files MUST be accessed using the functions in this

0 commit comments

Comments
 (0)