From d5d96db4ec6dfffbd73746f68f13159f84d9708b Mon Sep 17 00:00:00 2001 From: obdev Date: Fri, 23 Feb 2024 04:48:06 +0000 Subject: [PATCH] [CP] Add static array initialization compile-time checks in SQL expression module --- .../engine/expr/ob_expr_abs_result_type.map | 10 +- .../expr/ob_expr_arithmetic_result_type.map | 8 +- .../engine/expr/ob_expr_div_result_type.map | 4 +- .../expr/ob_expr_int_div_result_type.map | 6 +- .../expr/ob_expr_merge_result_type_oracle.map | 7 +- .../engine/expr/ob_expr_mod_result_type.map | 4 +- .../engine/expr/ob_expr_neg_result_type.map | 7 +- .../expr/ob_expr_relational_cmp_type.map | 20 +-- .../expr/ob_expr_relational_equal_type.map | 115 +++++++++++++++++- .../expr/ob_expr_relational_result_type.map | 4 +- .../engine/expr/ob_expr_result_type_util.cpp | 18 +++ .../engine/expr/ob_expr_round_result_type.map | 4 +- .../engine/expr/ob_expr_sum_result_type.map | 5 +- 13 files changed, 182 insertions(+), 30 deletions(-) diff --git a/src/sql/engine/expr/ob_expr_abs_result_type.map b/src/sql/engine/expr/ob_expr_abs_result_type.map index 189f6448b1..a35289c2f9 100644 --- a/src/sql/engine/expr/ob_expr_abs_result_type.map +++ b/src/sql/engine/expr/ob_expr_abs_result_type.map @@ -1,4 +1,4 @@ -static ObObjType ABS_RESULT_TYPE[ObMaxType] = +static constexpr ObObjType ABS_RESULT_TYPE[ObMaxType] = { ObDoubleType, /* NullType */ ObIntType, /* TinyIntType */ @@ -53,10 +53,8 @@ static ObObjType ABS_RESULT_TYPE[ObMaxType] = ObDecimalIntType, /* ObDecimalIntType */ }; -static_assert(sizeof(ABS_RESULT_TYPE) / sizeof(ObObjType) == ObMaxType, - "unexpected size of ABS_RESULT_TYPE"); -static ObObjType ABS_RESULT_TYPE_ORACLE[ObMaxType] = +static constexpr ObObjType ABS_RESULT_TYPE_ORACLE[ObMaxType] = { ObNullType, /* NullType */ ObNumberType, /* TinyIntType */ @@ -111,5 +109,5 @@ static ObObjType ABS_RESULT_TYPE_ORACLE[ObMaxType] = ObNumberType, /* ObDecimalIntType */ }; -static_assert(sizeof(ABS_RESULT_TYPE_ORACLE) / sizeof(ObObjType) == ObMaxType, - "unexpected size of ABS_RESULT_TYPE_ORACLE"); +static_assert(is_array_fully_initialized(ABS_RESULT_TYPE_ORACLE), "ABS_RESULT_TYPE_ORACLE is partially initlized"); +static_assert(is_array_fully_initialized(ABS_RESULT_TYPE), "ABS_RESULT_TYPE is partially initlized"); \ No newline at end of file diff --git a/src/sql/engine/expr/ob_expr_arithmetic_result_type.map b/src/sql/engine/expr/ob_expr_arithmetic_result_type.map index b0010116eb..dd3dfa0493 100644 --- a/src/sql/engine/expr/ob_expr_arithmetic_result_type.map +++ b/src/sql/engine/expr/ob_expr_arithmetic_result_type.map @@ -1,4 +1,4 @@ -static ObObjType ARITH_RESULT_TYPE[ObMaxType][ObMaxType] = +static constexpr ObObjType ARITH_RESULT_TYPE[ObMaxType][ObMaxType] = { /*NullType*/ { @@ -1358,6 +1358,10 @@ static ObObjType ARITH_RESULT_TYPE[ObMaxType][ObMaxType] = ObDoubleType, /* ObSetType */ ObMaxType, /* ObEnumInnerType */ ObMaxType, /* ObSetInnerType */ + ObMaxType, /* ObTimestampTZType */ + ObMaxType, /* ObTimestampLTZType */ + ObMaxType, /* ObTimestampNanoType */ + ObMaxType, /* ObRawType */ ObMaxType, /* ObIntervalYMType */ ObMaxType, /* ObIntervalDSType */ ObMaxType, /* ObNumberFloatType */ @@ -2777,3 +2781,5 @@ static ObObjType ARITH_RESULT_TYPE[ObMaxType][ObMaxType] = ObDecimalIntType, /* ObDecimalIntType */ }, }; + +static_assert(is_array_fully_initialized(ARITH_RESULT_TYPE, ObMaxType), "ARITH_RESULT_TYPE is partially initlized"); \ No newline at end of file diff --git a/src/sql/engine/expr/ob_expr_div_result_type.map b/src/sql/engine/expr/ob_expr_div_result_type.map index e30a30bc13..469828feaf 100644 --- a/src/sql/engine/expr/ob_expr_div_result_type.map +++ b/src/sql/engine/expr/ob_expr_div_result_type.map @@ -1,4 +1,4 @@ -static ObObjType DIV_RESULT_TYPE[ObMaxType][ObMaxType] = +static constexpr ObObjType DIV_RESULT_TYPE[ObMaxType][ObMaxType] = { /*NullType*/ { @@ -2781,3 +2781,5 @@ static ObObjType DIV_RESULT_TYPE[ObMaxType][ObMaxType] = ObDecimalIntType, /* ObDecimalIntType */ }, }; + +static_assert(is_array_fully_initialized(DIV_RESULT_TYPE, ObMaxType), "DIV_RESULT_TYPE is partially initlized"); \ No newline at end of file diff --git a/src/sql/engine/expr/ob_expr_int_div_result_type.map b/src/sql/engine/expr/ob_expr_int_div_result_type.map index a64a6fc632..37c81dc811 100644 --- a/src/sql/engine/expr/ob_expr_int_div_result_type.map +++ b/src/sql/engine/expr/ob_expr_int_div_result_type.map @@ -1,4 +1,4 @@ -static ObObjType INT_DIV_RESULT_TYPE[ObMaxType][ObMaxType] = +static constexpr ObObjType INT_DIV_RESULT_TYPE[ObMaxType][ObMaxType] = { /*NullType*/ { @@ -1141,9 +1141,9 @@ static ObObjType INT_DIV_RESULT_TYPE[ObMaxType][ObMaxType] = ObIntType, /* ObTimestampTZType */ ObIntType, /* ObTimestampLTZType */ ObIntType, /* ObTimestampNanoType */ + ObIntType, /* ObRawType */ ObMaxType, /*ObIntervalYMType */ ObMaxType, /*ObIntervalDSType */ - ObIntType, /* ObRawType */ ObMaxType, /* ObNumberFloatType */ ObMaxType, /* ObNVarchar2Type */ ObMaxType, /* ObNCharType */ @@ -2782,3 +2782,5 @@ static ObObjType INT_DIV_RESULT_TYPE[ObMaxType][ObMaxType] = ObIntType, /* ObDecimalIntType */ } }; + +static_assert(is_array_fully_initialized(INT_DIV_RESULT_TYPE, ObMaxType), "INT_DIV_RESULT_TYPE is partially initlized"); \ No newline at end of file diff --git a/src/sql/engine/expr/ob_expr_merge_result_type_oracle.map b/src/sql/engine/expr/ob_expr_merge_result_type_oracle.map index e57eac95c1..5b4fcc27ee 100644 --- a/src/sql/engine/expr/ob_expr_merge_result_type_oracle.map +++ b/src/sql/engine/expr/ob_expr_merge_result_type_oracle.map @@ -1,4 +1,4 @@ -static ObObjType MERGE_RESULT_TYPE[ObMaxType][ObMaxType] = { +static constexpr ObObjType MERGE_RESULT_TYPE[ObMaxType][ObMaxType] = { /*NullType*/ { ObNullType, /*NullType=>NullType */ @@ -2784,7 +2784,7 @@ static ObObjType MERGE_RESULT_TYPE[ObMaxType][ObMaxType] = { } }; -static ObObjType MERGE_RESULT_TYPE_ORACLE[ObMaxType][ObMaxType] = { +static constexpr ObObjType MERGE_RESULT_TYPE_ORACLE[ObMaxType][ObMaxType] = { /*NullType*/ { ObNullType, /*NullType=>NullType */ @@ -5569,3 +5569,6 @@ static ObObjType MERGE_RESULT_TYPE_ORACLE[ObMaxType][ObMaxType] = { ObNumberType, /*ObDecimalIntType=>ObDecimalIntType */ }, }; + +static_assert(is_array_fully_initialized(MERGE_RESULT_TYPE_ORACLE, ObMaxType), "MERGE_RESULT_TYPE_ORACLE is partially initlized"); +static_assert(is_array_fully_initialized(MERGE_RESULT_TYPE, ObMaxType), "MERGE_RESULT_TYPE is partially initlized"); \ No newline at end of file diff --git a/src/sql/engine/expr/ob_expr_mod_result_type.map b/src/sql/engine/expr/ob_expr_mod_result_type.map index 063cbbd4f7..48f2effd82 100644 --- a/src/sql/engine/expr/ob_expr_mod_result_type.map +++ b/src/sql/engine/expr/ob_expr_mod_result_type.map @@ -1,4 +1,4 @@ -static ObObjType MOD_RESULT_TYPE[ObMaxType][ObMaxType] = +static constexpr ObObjType MOD_RESULT_TYPE[ObMaxType][ObMaxType] = { /*NullType*/ { @@ -2783,3 +2783,5 @@ static ObObjType MOD_RESULT_TYPE[ObMaxType][ObMaxType] = ObDecimalIntType, /* ObDecimalIntType */ }, }; + +static_assert(is_array_fully_initialized(MOD_RESULT_TYPE, ObMaxType), "MOD_RESULT_TYPE is partially initlized"); \ No newline at end of file diff --git a/src/sql/engine/expr/ob_expr_neg_result_type.map b/src/sql/engine/expr/ob_expr_neg_result_type.map index c9957c5013..cc3228cbe7 100644 --- a/src/sql/engine/expr/ob_expr_neg_result_type.map +++ b/src/sql/engine/expr/ob_expr_neg_result_type.map @@ -1,4 +1,4 @@ -static ObObjType NEG_RESULT_TYPE[ObMaxType] = +static constexpr ObObjType NEG_RESULT_TYPE[ObMaxType] = { ObDoubleType, /*NullType */ ObIntType, /*TinyIntType */ @@ -53,7 +53,7 @@ static ObObjType NEG_RESULT_TYPE[ObMaxType] = ObDecimalIntType, /* ObDecimalIntType */ }; -static ObObjType NEG_RESULT_TYPE_ORACLE[ObMaxType] = +static constexpr ObObjType NEG_RESULT_TYPE_ORACLE[ObMaxType] = { ObNumberType, /*NullType */ ObNumberType, /*TinyIntType */ @@ -107,3 +107,6 @@ static ObObjType NEG_RESULT_TYPE_ORACLE[ObMaxType] = ObMaxType, /* ObUserDefinedSQLType */ ObNumberType, /* ObDecimalIntType */ }; + +static_assert(is_array_fully_initialized(NEG_RESULT_TYPE_ORACLE), "NEG_RESULT_TYPE_ORACLE is partially initlized"); +static_assert(is_array_fully_initialized(NEG_RESULT_TYPE), "NEG_RESULT_TYPE is partially initlized"); \ No newline at end of file diff --git a/src/sql/engine/expr/ob_expr_relational_cmp_type.map b/src/sql/engine/expr/ob_expr_relational_cmp_type.map index 0309e8782e..47e9b71978 100644 --- a/src/sql/engine/expr/ob_expr_relational_cmp_type.map +++ b/src/sql/engine/expr/ob_expr_relational_cmp_type.map @@ -16,7 +16,7 @@ Item_result item_cmp_type(Item_result a,Item_result b) } */ -static ObObjType RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = +static constexpr ObObjType RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = { /*NullType*/ { @@ -217,7 +217,7 @@ static ObObjType RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = ObNumberType, /*MediumTextType*/ ObNumberType, /*LongTextType*/ ObNumberType, /*BitType*/ - ObNumberType, /*EnumSetType*/ + ObNumberType, /*EnumType*/ ObNumberType, /*SetType*/ ObNumberType, /*EnumInnerType*/ ObNumberType, /*SetInnerType*/ @@ -1558,7 +1558,7 @@ static ObObjType RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* UDT */ ObDecimalIntType, /* ObDecimalIntType */ }, -/*TextType*/ + /*TextType*/ { ObMediumTextType, /* NullType */ ObNumberType, /* TinyIntType */ @@ -2527,10 +2527,11 @@ static ObObjType RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = ObNullType, /* ObNVarchar2Type */ ObNullType, /* ObNCharType */ ObNullType, /* ObURowIDType */ + ObNullType, /* ObLobType */ ObNullType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ ObMaxType, /* UDT */ - ObNullType, /* ObDecimalIntType */ + ObMaxType, /* ObDecimalIntType */ }, /*ObLobType*/ { @@ -2584,7 +2585,7 @@ static ObObjType RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = ObNullType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ ObMaxType, /* UDT */ - ObNullType, /* ObDecimalIntType */ + ObMaxType, /* ObDecimalIntType */ }, /*ObJsonType*/ { @@ -2806,7 +2807,7 @@ static ObObjType RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = -static ObObjType ORACLE_RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = +static constexpr ObObjType ORACLE_RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = { /*NullType*/ { @@ -3007,7 +3008,7 @@ static ObObjType ORACLE_RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = ObNumberType, /*MediumTextType*/ ObNumberType, /*LongTextType*/ ObNumberType, /*BitType*/ - ObNumberType, /*EnumSetType*/ + ObNumberType, /*EnumType*/ ObNumberType, /*SetType*/ ObNumberType, /*EnumInnerType*/ ObNumberType, /*SetInnerType*/ @@ -4348,7 +4349,7 @@ static ObObjType ORACLE_RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* UDT */ ObDecimalIntType, /* ObDecimalIntType */ }, -/*TextType*/ + /*TextType*/ { ObMediumTextType, /* NullType */ ObNumberType, /* TinyIntType */ @@ -5595,3 +5596,6 @@ static ObObjType ORACLE_RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = ObDecimalIntType, /* ObDecimalIntType */ }, }; + +//static_assert(is_array_fully_initialized(ORACLE_RELATIONAL_CMP_TYPE, ObMaxType), "ORACLE_RELATIONAL_CMP_TYPE is partially initlized"); +static_assert(is_array_fully_initialized(RELATIONAL_CMP_TYPE, ObMaxType), "RELATIONAL_CMP_TYPE is partially initlized"); \ No newline at end of file diff --git a/src/sql/engine/expr/ob_expr_relational_equal_type.map b/src/sql/engine/expr/ob_expr_relational_equal_type.map index 5aa224dcd4..d4ed0c2e2f 100644 --- a/src/sql/engine/expr/ob_expr_relational_equal_type.map +++ b/src/sql/engine/expr/ob_expr_relational_equal_type.map @@ -1,4 +1,4 @@ -static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = +static constexpr ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = { /*NullType*/ { @@ -51,6 +51,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObMaxType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObMaxType, /* ObDecimalIntType */ }, @@ -105,6 +106,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObDoubleType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, @@ -159,6 +161,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObDoubleType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, @@ -213,6 +216,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObDoubleType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, @@ -267,6 +271,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObDoubleType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, @@ -321,6 +326,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObDoubleType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, /*UTinyIntType*/ @@ -374,6 +380,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObDoubleType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, @@ -428,6 +435,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObDoubleType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, @@ -482,6 +490,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObDoubleType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, @@ -536,6 +545,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObDoubleType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, @@ -590,6 +600,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObDoubleType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, @@ -644,6 +655,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObDoubleType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDoubleType, /* ObDecimalIntType */ }, @@ -698,6 +710,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObDoubleType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDoubleType, /* ObDecimalIntType */ }, @@ -752,6 +765,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObDoubleType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDoubleType, /* ObDecimalIntType */ }, @@ -806,6 +820,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObDoubleType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDoubleType, /* ObDecimalIntType */ }, @@ -860,6 +875,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObNumberType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObNumberType, /* ObDecimalIntType */ }, @@ -914,6 +930,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObNumberType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObNumberType, /* ObDecimalIntType */ }, @@ -968,6 +985,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDateTimeType, /* ObDecimalIntType */ }, @@ -1022,6 +1040,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObTimestampType, /* ObDecimalIntType */ }, @@ -1076,6 +1095,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDateType, /* ObDecimalIntType */ }, @@ -1130,6 +1150,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObHexStringType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObTimeType, /* ObDecimalIntType */ }, @@ -1184,6 +1205,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObDoubleType, /* ObGeometryType*/ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, @@ -1238,6 +1260,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObHexStringType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, @@ -1292,6 +1315,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObHexStringType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, @@ -1346,6 +1370,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObHexStringType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, @@ -1400,6 +1425,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObMaxType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObMaxType, /* ObDecimalIntType */ }, @@ -1454,6 +1480,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObMaxType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObMaxType, /* ObDecimalIntType */ }, /*TinyTextType*/ @@ -1507,6 +1534,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, /*TextType*/ @@ -1560,6 +1588,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, /*MediumTextType*/ @@ -1613,6 +1642,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, /*LongTextType*/ @@ -1666,6 +1696,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, /*BitType*/ @@ -1705,7 +1736,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /*EnumType*/ ObMaxType, /*SetType*/ ObMaxType, /*EnumInnerType*/ - ObMaxType, /*EnumInnerType*/ + ObMaxType, /*SetInnerType*/ ObTimestampTZType, /* ObTimestampTZType */ ObTimestampLTZType, /* ObTimestampLTZType */ ObTimestampNanoType, /* ObTimestampNanoType */ @@ -1719,6 +1750,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObDoubleType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, /*EnumType*/ @@ -1757,7 +1789,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObNumberType, /*BitType*/ ObMaxType, /*EnumType*/ ObMaxType, /*SetType*/ - ObMaxType, /*EnumSetInnerType*/ + ObMaxType, /*EnumInnerType*/ ObMaxType, /*SetInnerType*/ ObTimestampTZType, /* ObTimestampTZType */ ObTimestampLTZType, /* ObTimestampLTZType */ @@ -1772,6 +1804,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObNumberType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, /*SetType*/ @@ -1810,7 +1843,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObNumberType, /*BitType*/ ObMaxType, /*EnumType*/ ObMaxType, /*SetType*/ - ObMaxType, /*EnumSetInnerType*/ + ObMaxType, /*EnumInnerType*/ ObMaxType, /*SetInnerType*/ ObTimestampTZType, /* ObTimestampTZType */ ObTimestampLTZType, /* ObTimestampLTZType */ @@ -1825,6 +1858,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObNumberType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, /*EnumInnerType*/ @@ -1878,6 +1912,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObNumberType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObMaxType, /* ObDecimalIntType */ }, /*SetInnerType*/ @@ -1931,6 +1966,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObNumberType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObMaxType, /* ObDecimalIntType */ }, /*ObTimestampTZType*/ @@ -1984,6 +2020,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObTimestampTZType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObTimestampTZType, /* ObDecimalIntType */ }, /*ObTimestampLTZType*/ @@ -2037,6 +2074,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObTimestampLTZType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObTimestampLTZType, /* ObDecimalIntType */ }, /*ObTimestampNanoType*/ @@ -2090,6 +2128,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObTimestampNanoType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObTimestampNanoType, /* ObDecimalIntType */ }, /*ObRawType*/ @@ -2143,6 +2182,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObVarcharType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObRawType, /* ObDecimalIntType */ }, /*ObIntervalYMType*/ @@ -2196,6 +2236,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObMaxType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObIntervalYMType, /* ObDecimalIntType */ }, /*ObIntervalDSType*/ @@ -2249,6 +2290,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObMaxType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObIntervalDSType, /* ObDecimalIntType */ }, @@ -2303,6 +2345,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObMaxType, /* ObJsonType */ ObDoubleType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObNumberType, /* ObDecimalIntType */ }, @@ -2357,6 +2400,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObMaxType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, @@ -2411,6 +2455,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObMaxType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, /*ObURowIDType*/ @@ -2461,8 +2506,10 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObNVarchar2Type */ ObMaxType, /* ObNCharType */ ObMaxType, /* ObURowIDType */ + ObMaxType, /* ObLobType */ ObMaxType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObMaxType, /* ObDecimalIntType */ }, /*ObLobType*/ @@ -2513,8 +2560,10 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObNVarchar2Type */ ObMaxType, /* ObNCharType */ ObMaxType, /* ObURowIDType */ + ObMaxType, /* ObLobType */ ObMaxType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObMaxType, /* ObDecimalIntType */ }, /*ObJsonType*/ @@ -2568,6 +2617,7 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObJsonType, /* ObGeometryType*/ + ObMaxType, /* ObUserDefinedSQLType */ ObMaxType, /* ObDecimalIntType */ }, /*ObGeometryType*/ @@ -2621,8 +2671,63 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObJsonType, /* ObJsonType */ ObHexStringType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObMaxType, /* ObDecimalIntType */ }, + /*ObUserDefinedSQLType*/ + { + ObMaxType, /* NullType */ + ObMaxType, /* TinyIntType */ + ObMaxType, /* SmallIntType */ + ObMaxType, /* MediumIntType */ + ObMaxType, /* Int32Type */ + ObMaxType, /* IntType */ + ObMaxType, /* UTinyIntType */ + ObMaxType, /* USmallIntType */ + ObMaxType, /* UMediumIntType */ + ObMaxType, /* UInt32Type */ + ObMaxType, /* UIntType */ + ObMaxType, /* FloatType */ + ObMaxType, /* DoubleType */ + ObMaxType, /* UFloatType */ + ObMaxType, /* UDoubleType */ + ObMaxType, /* NumberType */ + ObMaxType, /* UNumberType */ + ObMaxType, /* DateTimeType */ + ObMaxType, /* TimestampType */ + ObMaxType, /* DateType */ + ObMaxType, /* TimeType */ + ObMaxType, /* YearType */ + ObMaxType, /* VarcharType */ + ObMaxType, /* CharType */ + ObMaxType, /* HexStringType */ + ObMaxType, /* ExtendType */ + ObMaxType, /* UnknownType */ + ObMaxType, /*TinyTextType*/ + ObMaxType, /*TextType*/ + ObMaxType, /*MediumTextType*/ + ObMaxType, /*LongTextType*/ + ObMaxType, /*BitType*/ + ObMaxType, /*EnumType*/ + ObMaxType, /*SetType*/ + ObMaxType, /*EnumInnerType*/ + ObMaxType, /*SetInnerType*/ + ObMaxType, /* ObTimestampTZType */ + ObMaxType, /* ObTimestampLTZType */ + ObMaxType, /* ObTimestampNanoType */ + ObMaxType, /* ObRawType */ + ObMaxType, /* ObIntervalYMType */ + ObMaxType, /* ObIntervalDSType */ + ObMaxType, /* ObNumberFloatType */ + ObMaxType, /* ObNVarchar2Type */ + ObMaxType, /* ObNCharType */ + ObMaxType, /* ObURowIDType */ + ObMaxType, /* ObLobType */ + ObMaxType, /* ObJsonType */ + ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ + ObMaxType, /* ObDecimalIntType */ + }, /*DecimalIntType*/ { ObMaxType, /* NullType */ @@ -2674,9 +2779,11 @@ static ObObjType RELATIONAL_EQUAL_TYPE[ObMaxType][ObMaxType] = ObMaxType, /* ObLobType */ ObMaxType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ + ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }, }; +static_assert(is_array_fully_initialized(RELATIONAL_EQUAL_TYPE, ObMaxType), "RELATIONAL_EQUAL_TYPE is partially initlized"); diff --git a/src/sql/engine/expr/ob_expr_relational_result_type.map b/src/sql/engine/expr/ob_expr_relational_result_type.map index 926eb3dae8..2835534b07 100644 --- a/src/sql/engine/expr/ob_expr_relational_result_type.map +++ b/src/sql/engine/expr/ob_expr_relational_result_type.map @@ -1,4 +1,4 @@ -static ObObjType RELATIONAL_RESULT_TYPE[ObMaxType][ObMaxType] = +static constexpr ObObjType RELATIONAL_RESULT_TYPE[ObMaxType][ObMaxType] = { /*NullType*/ { @@ -2782,3 +2782,5 @@ static ObObjType RELATIONAL_RESULT_TYPE[ObMaxType][ObMaxType] = ObDecimalIntType, /* ObDecimalIntType */ }, }; + +static_assert(is_array_fully_initialized(RELATIONAL_RESULT_TYPE, ObMaxType), "RELATIONAL_RESULT_TYPE is partially initlized"); \ No newline at end of file diff --git a/src/sql/engine/expr/ob_expr_result_type_util.cpp b/src/sql/engine/expr/ob_expr_result_type_util.cpp index aa523524a6..0e774236e6 100644 --- a/src/sql/engine/expr/ob_expr_result_type_util.cpp +++ b/src/sql/engine/expr/ob_expr_result_type_util.cpp @@ -21,6 +21,24 @@ namespace oceanbase { using namespace common; + +//Since ob use c++11, so we can not use loop or constains multiple return in constexpr function(which is supported in c++14) +//So we use recursion and conditional assignment statement instead +template +constexpr bool is_array_fully_initialized(const T (&arr)[row][col], int row_depth) +{ + return row_depth == 0 ? + true : + arr[row_depth - 1][col - 1] == T() ? false : + is_array_fully_initialized(arr, row_depth - 1); +} + +template +constexpr bool is_array_fully_initialized(const T (&arr)[col]) +{ + return arr[col - 1] != T(); +} + // following .map file depends on ns oceanbase::common; #include "sql/engine/expr/ob_expr_merge_result_type_oracle.map" #include "sql/engine/expr/ob_expr_relational_result_type.map" diff --git a/src/sql/engine/expr/ob_expr_round_result_type.map b/src/sql/engine/expr/ob_expr_round_result_type.map index 54f4ce9cfd..74f0fe397a 100644 --- a/src/sql/engine/expr/ob_expr_round_result_type.map +++ b/src/sql/engine/expr/ob_expr_round_result_type.map @@ -1,4 +1,4 @@ -static ObObjType ROUND_RESULT_TYPE[ObMaxType] = +static constexpr ObObjType ROUND_RESULT_TYPE[ObMaxType] = { ObDoubleType, /* NullType */ ObIntType, /* TinyIntType */ @@ -52,3 +52,5 @@ static ObObjType ROUND_RESULT_TYPE[ObMaxType] = ObMaxType, /* ObUserDefinedSQLType */ ObDecimalIntType, /* ObDecimalIntType */ }; + +static_assert(is_array_fully_initialized(ROUND_RESULT_TYPE), "ROUND_RESULT_TYPE is partially initlized"); \ No newline at end of file diff --git a/src/sql/engine/expr/ob_expr_sum_result_type.map b/src/sql/engine/expr/ob_expr_sum_result_type.map index f919ddbeba..d228bf065d 100644 --- a/src/sql/engine/expr/ob_expr_sum_result_type.map +++ b/src/sql/engine/expr/ob_expr_sum_result_type.map @@ -1,4 +1,4 @@ -static ObObjType SUM_RESULT_TYPE[ObMaxType] = +static constexpr ObObjType SUM_RESULT_TYPE[ObMaxType] = { ObDoubleType, /*NullType */ ObNumberType, /*TinyIntType */ @@ -50,4 +50,7 @@ static ObObjType SUM_RESULT_TYPE[ObMaxType] = ObDoubleType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ ObMaxType, /* ObUserDefinedSQLType */ + ObMaxType, /* ObDecimalIntType */ }; + +static_assert(is_array_fully_initialized(SUM_RESULT_TYPE), "SUM_RESULT_TYPE is partially initlized"); \ No newline at end of file