mirror of
https://github.com/MariaDB/server.git
synced 2026-01-06 05:22:24 +03:00
cleanup: reduce code duplication
remove copy-pasted code, fix meaningless comparison.
followup for ea2162b6aa
This commit is contained in:
@@ -33,6 +33,27 @@
|
||||
|
||||
static int compare_columns(MARIA_COLUMNDEF **a, MARIA_COLUMNDEF **b);
|
||||
|
||||
|
||||
static ulonglong update_tot_length(ulonglong tot_length, ulonglong max_rows, uint length)
|
||||
{
|
||||
ulonglong tot_length_part;
|
||||
|
||||
if (tot_length == ULONGLONG_MAX)
|
||||
return ULONGLONG_MAX;
|
||||
|
||||
tot_length_part= (max_rows/(ulong) ((maria_block_size -
|
||||
MAX_KEYPAGE_HEADER_SIZE - KEYPAGE_CHECKSUM_SIZE)/
|
||||
(length*2)));
|
||||
if (tot_length_part >= ULONGLONG_MAX / maria_block_size)
|
||||
return ULONGLONG_MAX;
|
||||
|
||||
if (tot_length > ULONGLONG_MAX - tot_length_part * maria_block_size)
|
||||
return ULONGLONG_MAX;
|
||||
|
||||
return tot_length + tot_length_part * maria_block_size;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Old options is used when recreating database, from maria_chk
|
||||
*/
|
||||
@@ -661,23 +682,7 @@ int maria_create(const char *name, enum data_file_type datafile_type,
|
||||
if (length > max_key_length)
|
||||
max_key_length= length;
|
||||
|
||||
if (tot_length == ULLONG_MAX)
|
||||
continue;
|
||||
|
||||
ulonglong tot_length_part= (max_rows/(ulong) (((uint) maria_block_size -
|
||||
MAX_KEYPAGE_HEADER_SIZE -
|
||||
KEYPAGE_CHECKSUM_SIZE)/
|
||||
(length*2)));
|
||||
if (tot_length_part >= (ULLONG_MAX / maria_block_size +
|
||||
ULLONG_MAX % maria_block_size))
|
||||
tot_length= ULLONG_MAX;
|
||||
else
|
||||
{
|
||||
if (tot_length > ULLONG_MAX - tot_length_part * maria_block_size)
|
||||
tot_length= ULLONG_MAX;
|
||||
else
|
||||
tot_length+= tot_length_part * maria_block_size;
|
||||
}
|
||||
tot_length= update_tot_length(tot_length, max_rows, length);
|
||||
}
|
||||
|
||||
unique_key_parts=0;
|
||||
@@ -687,23 +692,7 @@ int maria_create(const char *name, enum data_file_type datafile_type,
|
||||
unique_key_parts+=uniquedef->keysegs;
|
||||
share.state.key_root[keys+i]= HA_OFFSET_ERROR;
|
||||
|
||||
if (tot_length == ULLONG_MAX)
|
||||
continue;
|
||||
ulonglong tot_length_part= (max_rows/(ulong) (((uint) maria_block_size -
|
||||
MAX_KEYPAGE_HEADER_SIZE -
|
||||
KEYPAGE_CHECKSUM_SIZE) /
|
||||
((MARIA_UNIQUE_HASH_LENGTH + pointer)*2)));
|
||||
|
||||
if (tot_length_part >= (ULLONG_MAX / maria_block_size +
|
||||
ULLONG_MAX % maria_block_size))
|
||||
tot_length= ULLONG_MAX;
|
||||
else
|
||||
{
|
||||
if (tot_length > ULLONG_MAX - tot_length_part * maria_block_size)
|
||||
tot_length= ULLONG_MAX;
|
||||
else
|
||||
tot_length+= tot_length_part * maria_block_size;
|
||||
}
|
||||
tot_length= update_tot_length(tot_length, max_rows, MARIA_UNIQUE_HASH_LENGTH + pointer);
|
||||
}
|
||||
keys+=uniques; /* Each unique has 1 key */
|
||||
key_segs+=uniques; /* Each unique has 1 key seg */
|
||||
|
||||
Reference in New Issue
Block a user