Skip to content

Commit

Permalink
fix ComputeNaturalSize and StaticExtrnalSize on bit calculate, used b…
Browse files Browse the repository at this point in the history
…y desc tables stoneatom#919
  • Loading branch information
hustjieke committed Dec 20, 2022
1 parent 4ea052c commit 81dc6d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions storage/tianmu/common/txt_data_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ uint TxtDataFormat::StaticExtrnalSize(ColumnType attrt, uint precision, int scal
if (attrt == ColumnType::NUM)
return 1 + precision + (scale ? 1 : 0) + (precision == (uint)scale ? 1 : 0);
// because "-0.1" may be declared as DEC(1,1), so 18 decimal places may take
// 21 characters
// 21 characters, "-0.xxxxx...", "-", "0", "." need extra 3 bytes, 21 = 3 + 18.
if (attrt == ColumnType::BIT) // unsigned value.
return precision; // e.g.: if precison = 4, bit value max display will be "1010", one byte one digit.
if (attrt == ColumnType::BYTE || attrt == ColumnType::VARBYTE || attrt == ColumnType::BIN)
return precision * 2;
if (attrt == ColumnType::TIME_N || attrt == ColumnType::DATETIME_N)
Expand All @@ -51,9 +53,9 @@ uint TxtDataFormat::StaticExtrnalSize(ColumnType attrt, uint precision, int scal
if (attrt == ColumnType::DATE)
return 10;
else if (attrt == ColumnType::INT)
return 11;
return 11; // -2,147,483,648 ~ 2,147,483,647, 1(signed) + 10(max digits)
else if (attrt == ColumnType::BIGINT || attrt == ColumnType::BIT)
return 20;
return 20; // -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807, 1(signed) + 19(max digits)
else if (attrt == ColumnType::BYTEINT || attrt == ColumnType::YEAR)
return 4;
else if (attrt == ColumnType::SMALLINT)
Expand Down
3 changes: 3 additions & 0 deletions storage/tianmu/core/tianmu_attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ size_t TianmuAttr::ComputeNaturalSize() {
case common::ColumnType::NUM:
na_size += (Type().GetPrecision() + (Type().GetScale() ? 1 : 0)) * NumOfObj();
break;
case common::ColumnType::BIT:
na_size += Type().GetPrecision() * NumOfObj(); // one bytes one digit
break;
case common::ColumnType::BIGINT:
case common::ColumnType::REAL:
case common::ColumnType::BIT:
Expand Down

0 comments on commit 81dc6d2

Please sign in to comment.