MCPcopy Create free account
hub / github.com/MariaDB/server / init_key_info

Function init_key_info

sql/sql_table.cc:3101–3161  ·  view source on GitHub ↗

@brief Initialize the key length and algorithm (if long hash). This function does: 1. Append system key parts (versioning, periods) 2. Call Type_handler key_part initialization function. 3. Determine the length of each key_part. 4. Calculate the total Key length. 5. Determine if the key is long unique based on its length smd result from type handler. It'll be saved in key_cr

Source from the content-addressed store, hash-verified

3099 @return TRUE error
3100 */
3101static
3102my_bool init_key_info(THD *thd, Alter_info *alter_info,
3103 HA_CREATE_INFO *create_info,
3104 const handler *file)
3105{
3106 DBUG_ENTER("init_key_info");
3107 uint max_key_length= file->max_key_length();
3108 uint max_key_part_length= file->max_key_part_length();
3109
3110 for (Key &key: alter_info->key_list)
3111 {
3112 /*
3113 Ensure we aren't re-initializing keys that were already initialized.
3114 */
3115 DBUG_ASSERT(!key.length);
3116
3117 if (key.type == Key::FOREIGN_KEY)
3118 continue;
3119
3120 int parts_added= append_system_key_parts(thd, create_info, &key);
3121 if (parts_added < 0)
3122 DBUG_RETURN(true);
3123
3124 bool is_hash_field_needed= false;
3125 for (Key_part_spec &kp: key.columns)
3126 {
3127 if (init_key_part_spec(thd, alter_info, file, key, kp,
3128 max_key_length, max_key_part_length,
3129 &is_hash_field_needed))
3130 DBUG_RETURN(TRUE);
3131
3132 key.length+= kp.length;
3133 if (key.length > max_key_length)
3134 {
3135 if (key.type == Key::UNIQUE)
3136 is_hash_field_needed= true; // for case "a BLOB UNIQUE"
3137 else if (key.type <= Key::MULTIPLE)
3138 {
3139 my_error(ER_TOO_LONG_KEY, MYF(0), max_key_length);
3140 DBUG_RETURN(TRUE);
3141 }
3142 }
3143
3144 KEY_CREATE_INFO *key_cinfo= &key.key_create_info;
3145
3146 if (is_hash_field_needed)
3147 {
3148 if (key_cinfo->algorithm == HA_KEY_ALG_UNDEF)
3149 key_cinfo->algorithm= HA_KEY_ALG_LONG_HASH;
3150
3151 if (key_cinfo->algorithm != HA_KEY_ALG_HASH &&
3152 key_cinfo->algorithm != HA_KEY_ALG_LONG_HASH)
3153 {
3154 my_error(ER_TOO_LONG_KEY, MYF(0), max_key_length);
3155 DBUG_RETURN(TRUE);
3156 }
3157 }
3158 }

Callers 1

Calls 5

append_system_key_partsFunction · 0.85
init_key_part_specFunction · 0.85
my_errorFunction · 0.85
max_key_part_lengthMethod · 0.80
max_key_lengthMethod · 0.45

Tested by

no test coverage detected