| 1 | /***************************************************************************** |
| 2 | |
| 3 | Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved. |
| 4 | Copyright (c) 2017, MariaDB Corporation. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it under |
| 7 | the terms of the GNU General Public License as published by the Free Software |
| 8 | Foundation; version 2 of the License. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 12 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License along with |
| 15 | this program; if not, write to the Free Software Foundation, Inc., |
| 16 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA |
| 17 | |
| 18 | *****************************************************************************/ |
| 19 | |
| 20 | /******************************************************************//** |
| 21 | @file include/dict0mem.ic |
| 22 | Data dictionary memory object creation |
| 23 | |
| 24 | Created 1/8/1996 Heikki Tuuri |
| 25 | ***********************************************************************/ |
| 26 | |
| 27 | #include "data0type.h" |
| 28 | #include "dict0mem.h" |
| 29 | #include "fil0fil.h" |
| 30 | |
| 31 | /**********************************************************************//** |
| 32 | This function poplulates a dict_index_t index memory structure with |
| 33 | supplied information. */ |
| 34 | UNIV_INLINE |
| 35 | void |
| 36 | dict_mem_fill_index_struct( |
| 37 | /*=======================*/ |
| 38 | dict_index_t* index, /*!< out: index to be filled */ |
| 39 | mem_heap_t* heap, /*!< in: memory heap */ |
| 40 | const char* index_name, /*!< in: index name */ |
| 41 | ulint type, /*!< in: DICT_UNIQUE, |
| 42 | DICT_CLUSTERED, ... ORed */ |
| 43 | ulint n_fields) /*!< in: number of fields */ |
| 44 | { |
| 45 | |
| 46 | if (heap) { |
| 47 | index->heap = heap; |
| 48 | index->name = mem_heap_strdup(heap, index_name); |
| 49 | index->fields = (dict_field_t*) mem_heap_alloc( |
| 50 | heap, 1 + n_fields * sizeof(dict_field_t)); |
| 51 | } else { |
| 52 | index->name = index_name; |
| 53 | index->heap = NULL; |
| 54 | index->fields = NULL; |
| 55 | } |
| 56 | |
| 57 | /* Assign a ulint to a 4-bit-mapped field. |
| 58 | Only the low-order 4 bits are assigned. */ |
| 59 | index->type = unsigned(type); |
| 60 | index->page = FIL_NULL; |
| 61 | index->merge_threshold = DICT_INDEX_MERGE_THRESHOLD_DEFAULT; |
| 62 | index->n_fields = (unsigned int) n_fields; |
| 63 | index->n_core_fields = (unsigned int) n_fields; |
| 64 | /* The '1 +' above prevents allocation |
| 65 | of an empty mem block */ |
| 66 | index->nulls_equal = false; |
| 67 | #ifdef BTR_CUR_HASH_ADAPT |
| 68 | #ifdef MYSQL_INDEX_DISABLE_AHI |
| 69 | index->disable_ahi = false; |
| 70 | #endif |
| 71 | #endif /* BTR_CUR_HASH_ADAPT */ |
| 72 | ut_d(index->magic_n = DICT_INDEX_MAGIC_N); |
| 73 | } |
| 74 | |