aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgalaxycrab <UgnineSirdis@ydb.tech>2022-10-10 22:59:06 +0300
committergalaxycrab <UgnineSirdis@ydb.tech>2022-10-10 22:59:06 +0300
commita6b8cecadad0531eaf559b57c797d7d71bae12d7 (patch)
tree9941eaa7438d8602991bd52590537023f276536f
parent230d573d6775493133032c2762f00f857a9336ce (diff)
downloadydb-a6b8cecadad0531eaf559b57c797d7d71bae12d7.tar.gz
Fix TypeLen usage in GetTypeWeight
-rw-r--r--ydb/library/yql/core/yql_opt_utils.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/ydb/library/yql/core/yql_opt_utils.cpp b/ydb/library/yql/core/yql_opt_utils.cpp
index 069d223976f..119609e07a5 100644
--- a/ydb/library/yql/core/yql_opt_utils.cpp
+++ b/ydb/library/yql/core/yql_opt_utils.cpp
@@ -11,6 +11,8 @@
#include <util/generic/set.h>
#include <util/string/type.h>
+#include <limits>
+
namespace NYql {
using namespace NNodes;
@@ -1440,7 +1442,10 @@ TStringBuf GetEmptyCollectionName(ETypeAnnotationKind kind) {
namespace {
-ui8 GetTypeWeight(const TTypeAnnotationNode& type) {
+constexpr ui64 MaxWeight = std::numeric_limits<ui64>::max();
+constexpr ui64 UnknownWeight = std::numeric_limits<ui32>::max();
+
+ui64 GetTypeWeight(const TTypeAnnotationNode& type) {
switch (type.GetKind()) {
case ETypeAnnotationKind::Data:
switch (type.Cast<TDataExprType>()->GetSlot()) {
@@ -1476,17 +1481,22 @@ ui8 GetTypeWeight(const TTypeAnnotationNode& type) {
}
case ETypeAnnotationKind::Optional:
return 1 + GetTypeWeight(*type.Cast<TOptionalExprType>()->GetItemType());
- case ETypeAnnotationKind::Pg:
- return ui8(ClampVal(NPg::LookupType(type.Cast<TPgExprType>()->GetId()).TypeLen, 1, 255));
+ case ETypeAnnotationKind::Pg: {
+ const auto& typeDesc = NPg::LookupType(type.Cast<TPgExprType>()->GetId());
+ if (typeDesc.TypeLen > 0 && typeDesc.PassByValue) {
+ return typeDesc.TypeLen;
+ }
+ return UnknownWeight;
+ }
default:
- return 255;
+ return UnknownWeight;
}
}
} // namespace
const TItemExprType* GetLightColumn(const TStructExprType& type) {
- ui8 weight = 255;
+ ui64 weight = MaxWeight;
const TItemExprType* field = nullptr;
for (const auto& item : type.GetItems()) {
if (const auto w = GetTypeWeight(*item->GetItemType()); w < weight) {
@@ -1494,9 +1504,6 @@ const TItemExprType* GetLightColumn(const TStructExprType& type) {
field = item;
}
}
- if (const auto& items = type.GetItems(); !items.empty() && !field) {
- field = items[0];
- }
return field;
}