in assessment/sources/mysql/infoschema.go [257:349]
func getColumnMaxSize(dataType string, mods []int64, mysqlCharset string) int64 {
dataTypeLower := strings.ToLower(dataType)
bytesPerChar := int64(1) // Default for binary types or non-char types
switch dataTypeLower {
case "char", "varchar", "tinytext", "text", "mediumtext", "longtext":
bytesPerChar = getMaxBytesPerChar(mysqlCharset)
}
switch dataTypeLower {
case "date":
return 4
case "timestamp", "datetime":
return 8
case "bit":
if len(mods) > 0 {
return int64(math.Ceil(float64(mods[0]) / 8.0))
}
return 1
case "tinyint":
return 1
case "smallint":
return 2
case "mediumint":
return 3
case "int", "integer":
return 4
case "bigint":
return 8
case "float":
return 4
case "double", "real":
return 8
case "decimal", "numeric":
if len(mods) > 0 {
precision := mods[0]
scale := int64(0)
if len(mods) > 1 {
scale = mods[1]
}
// Calculate storage based on precision and scale
intDigits := precision - scale
intBytes := (intDigits + 8) / 9
fracBytes := (scale + 8) / 9
return intBytes + fracBytes // Total size
}
return 8 // Default size if no precision/scale provided
case "char":
maxChars := int64(1) // Default for CHAR is CHAR(1)
if len(mods) > 0 {
maxChars = mods[0]
}
return maxChars * bytesPerChar
case "varchar":
maxChars := int64(0)
if len(mods) > 0 {
maxChars = mods[0]
} else {
maxChars = 255
}
return maxChars * bytesPerChar
case "binary", "varbinary":
if len(mods) > 0 {
return mods[0]
}
return 255
case "tinyblob":
return 255
case "blob":
return 65535
case "mediumblob":
return 16777215
case "longblob":
return 4294967295
case "tinytext":
return 255 * bytesPerChar
case "text":
return 65535 * bytesPerChar
case "mediumtext":
return 16777215 * bytesPerChar
case "longtext":
return 4294967295 * bytesPerChar
case "json":
return 4294967295
default:
return 4
}
}