| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 1996, 2026, Oracle and/or its affiliates. |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or modify it under |
| 6 |
the terms of the GNU General Public License, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
/** @file include/dict0mem.ic |
| 29 |
Data dictionary memory object creation |
| 30 |
|
| 31 |
Created 1/8/1996 Heikki Tuuri |
| 32 |
***********************************************************************/ |
| 33 |
|
| 34 |
#include "data0type.h" |
| 35 |
#include "dict0mem.h" |
| 36 |
#include "fil0fil.h" |
| 37 |
|
| 38 |
/** This function poplulates a dict_index_t index memory structure with |
| 39 |
supplied information. */ |
| 40 |
static inline void dict_mem_fill_index_struct( |
| 41 |
dict_index_t *index, /*!< out: index to be filled */ |
| 42 |
mem_heap_t *heap, /*!< in: memory heap */ |
| 43 |
const char *table_name, /*!< in: table name */ |
| 44 |
const char *index_name, /*!< in: index name */ |
| 45 |
ulint space, /*!< in: space where the index tree is |
| 46 |
placed, ignored if the index is of |
| 47 |
the clustered type */ |
| 48 |
ulint type, /*!< in: DICT_UNIQUE, |
| 49 |
DICT_CLUSTERED, ... ORed */ |
| 50 |
ulint n_fields) /*!< in: number of fields */ |
| 51 |
{ |
| 52 |
if (heap) { |
| 53 |
index->heap = heap; |
| 54 |
index->name = mem_heap_strdup(heap, index_name); |
| 55 |
index->fields = (dict_field_t *)mem_heap_alloc( |
| 56 |
heap, 1 + n_fields * sizeof(dict_field_t)); |
| 57 |
} else { |
| 58 |
index->name = index_name; |
| 59 |
index->heap = nullptr; |
| 60 |
index->fields = nullptr; |
| 61 |
} |
| 62 |
|
| 63 |
/* Assign a ulint to a 4-bit-mapped field. |
| 64 |
Only the low-order 4 bits are assigned. */ |
| 65 |
index->type = type; |
| 66 |
#ifndef UNIV_HOTBACKUP |
| 67 |
index->space = (unsigned int)space; |
| 68 |
index->page = FIL_NULL; |
| 69 |
index->merge_threshold = DICT_INDEX_MERGE_THRESHOLD_DEFAULT; |
| 70 |
#endif /* !UNIV_HOTBACKUP */ |
| 71 |
index->table_name = table_name; |
| 72 |
index->n_fields = (unsigned int)n_fields; |
| 73 |
index->n_total_fields = (unsigned int)n_fields; |
| 74 |
/* The '1 +' above prevents allocation |
| 75 |
of an empty mem block */ |
| 76 |
index->allow_duplicates = false; |
| 77 |
index->nulls_equal = false; |
| 78 |
index->disable_ahi = false; |
| 79 |
index->last_ins_cur = nullptr; |
| 80 |
index->last_sel_cur = nullptr; |
| 81 |
#ifndef UNIV_HOTBACKUP |
| 82 |
new (&index->rec_cache) rec_cache_t(); |
| 83 |
|
| 84 |
#endif /* UNIV_HOTBACKUP */ |
| 85 |
#ifdef UNIV_DEBUG |
| 86 |
index->magic_n = DICT_INDEX_MAGIC_N; |
| 87 |
#endif /* UNIV_DEBUG */ |
| 88 |
} |
| 89 |
|
| 90 |
/** Returns the number of fields before first instant ADD COLUMN. It includes |
| 91 |
dropped fields also (if any) */ |
| 92 |
inline uint32_t dict_index_t::get_instant_fields() const { |
| 93 |
ut_ad(has_instant_cols()); |
| 94 |
|
| 95 |
size_t n_inst_cols_v1 = table->get_n_instant_added_col_v1(); |
| 96 |
size_t n_drop_cols = table->get_n_instant_drop_cols(); |
| 97 |
size_t n_add_cols = table->get_n_instant_add_cols(); |
| 98 |
size_t n_instant_fields = |
| 99 |
n_fields + n_drop_cols - n_add_cols - n_inst_cols_v1; |
| 100 |
|
| 101 |
return n_instant_fields; |
| 102 |
} |