Merge pull request #28512 from taosdata/opti/TD-30681

Opti/td 30681
This commit is contained in:
Shengliang Guan 2024-11-01 14:42:39 +08:00 committed by GitHub
commit daa8341a3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 68 additions and 50 deletions

View File

@ -238,12 +238,26 @@ typedef struct {
case TSDB_DATA_TYPE_UBIGINT: \ case TSDB_DATA_TYPE_UBIGINT: \
snprintf(_output, (int32_t)(_outputBytes), "%" PRIu64, *(uint64_t *)(_input)); \ snprintf(_output, (int32_t)(_outputBytes), "%" PRIu64, *(uint64_t *)(_input)); \
break; \ break; \
case TSDB_DATA_TYPE_FLOAT: \ case TSDB_DATA_TYPE_FLOAT: { \
int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \
if (n >= (_outputBytes)) { \
n = snprintf(_output, (int32_t)(_outputBytes), "%.7e", *(float *)(_input)); \
if (n >= (_outputBytes)) { \
snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \ snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \
} \
} \
break; \ break; \
case TSDB_DATA_TYPE_DOUBLE: \ } \
case TSDB_DATA_TYPE_DOUBLE: { \
int32_t n = snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \
if (n >= (_outputBytes)) { \
snprintf(_output, (int32_t)(_outputBytes), "%.15e", *(double *)(_input)); \
if (n >= (_outputBytes)) { \
snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \ snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \
} \
} \
break; \ break; \
} \
case TSDB_DATA_TYPE_UINT: \ case TSDB_DATA_TYPE_UINT: \
snprintf(_output, (int32_t)(_outputBytes), "%u", *(uint32_t *)(_input)); \ snprintf(_output, (int32_t)(_outputBytes), "%u", *(uint32_t *)(_input)); \
break; \ break; \

View File

@ -175,8 +175,8 @@ static int32_t valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) {
case TSDB_DATA_TYPE_VARCHAR: case TSDB_DATA_TYPE_VARCHAR:
case TSDB_DATA_TYPE_VARBINARY: case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_GEOMETRY: { case TSDB_DATA_TYPE_GEOMETRY: {
int32_t len = pSrc->node.resType.bytes + 1; int32_t len = varDataTLen(pSrc->datum.p);
pDst->datum.p = taosMemoryCalloc(1, len); pDst->datum.p = taosMemoryCalloc(1, len + 1);
if (NULL == pDst->datum.p) { if (NULL == pDst->datum.p) {
return terrno; return terrno;
} }

View File

@ -28,6 +28,8 @@ extern "C" {
#define QUERY_SMA_OPTIMIZE_DISABLE 0 #define QUERY_SMA_OPTIMIZE_DISABLE 0
#define QUERY_SMA_OPTIMIZE_ENABLE 1 #define QUERY_SMA_OPTIMIZE_ENABLE 1
#define QUERY_NUMBER_MAX_DISPLAY_LEN 65
int32_t parseInsertSql(SParseContext* pCxt, SQuery** pQuery, SCatalogReq* pCatalogReq, const SMetaData* pMetaData); int32_t parseInsertSql(SParseContext* pCxt, SQuery** pQuery, SCatalogReq* pCatalogReq, const SMetaData* pMetaData);
int32_t continueCreateTbFromFile(SParseContext* pCxt, SQuery** pQuery); int32_t continueCreateTbFromFile(SParseContext* pCxt, SQuery** pQuery);
int32_t parse(SParseContext* pParseCxt, SQuery** pQuery); int32_t parse(SParseContext* pParseCxt, SQuery** pQuery);

View File

@ -3308,25 +3308,26 @@ static int32_t selectCommonType(SDataType* commonType, const SDataType* newType)
} else { } else {
resultType = gDisplyTypes[type2][type1]; resultType = gDisplyTypes[type2][type1];
} }
if (resultType == -1) { if (resultType == -1) {
return TSDB_CODE_SCALAR_CONVERT_ERROR; return TSDB_CODE_SCALAR_CONVERT_ERROR;
} }
if (commonType->type == newType->type) { if (commonType->type == newType->type) {
commonType->bytes = TMAX(commonType->bytes, newType->bytes); commonType->bytes = TMAX(commonType->bytes, newType->bytes);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (resultType == commonType->type) {
return TSDB_CODE_SUCCESS; if ((resultType == TSDB_DATA_TYPE_VARCHAR) && (IS_MATHABLE_TYPE(commonType->type) || IS_MATHABLE_TYPE(newType->type))) {
} commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), QUERY_NUMBER_MAX_DISPLAY_LEN);
if (resultType == newType->type) { } else if ((resultType == TSDB_DATA_TYPE_NCHAR) && (IS_MATHABLE_TYPE(commonType->type) || IS_MATHABLE_TYPE(newType->type))) {
*commonType = *newType; commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), QUERY_NUMBER_MAX_DISPLAY_LEN * TSDB_NCHAR_SIZE);
return TSDB_CODE_SUCCESS; } else {
}
commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), TYPE_BYTES[resultType]); commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), TYPE_BYTES[resultType]);
if (resultType == TSDB_DATA_TYPE_VARCHAR && (IS_FLOAT_TYPE(commonType->type) || IS_FLOAT_TYPE(newType->type))) {
commonType->bytes += TYPE_BYTES[TSDB_DATA_TYPE_DOUBLE];
} }
commonType->type = resultType; commonType->type = resultType;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }

View File

@ -2085,7 +2085,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
(void)memcpy(varDataVal(output), convBuf, len); (void)memcpy(varDataVal(output), convBuf, len);
varDataSetLen(output, len); varDataSetLen(output, len);
} else { } else {
NUM_TO_STRING(inputType, input, bufSize, buf); int32_t outputSize = (outputLen - VARSTR_HEADER_SIZE) < bufSize ? (outputLen - VARSTR_HEADER_SIZE + 1): bufSize;
NUM_TO_STRING(inputType, input, outputSize, buf);
int32_t len = (int32_t)strlen(buf); int32_t len = (int32_t)strlen(buf);
len = (outputLen - VARSTR_HEADER_SIZE) > len ? len : (outputLen - VARSTR_HEADER_SIZE); len = (outputLen - VARSTR_HEADER_SIZE) > len ? len : (outputLen - VARSTR_HEADER_SIZE);
(void)memcpy(varDataVal(output), buf, len); (void)memcpy(varDataVal(output), buf, len);

View File

@ -1031,23 +1031,23 @@ int8_t gConvertTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = {
/*GEOM*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0}; /*GEOM*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0};
int8_t gDisplyTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = { int8_t gDisplyTypes[TSDB_DATA_TYPE_MAX][TSDB_DATA_TYPE_MAX] = {
/*NULL BOOL TINY SMAL INT BIGI FLOA DOUB VARC TIME NCHA UTINY USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/ /*NULL BOOL TINY SMAL INT BIGI FLOA DOUB VARC TIM NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB MEDB GEOM*/
/*NULL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, -1, -1, -1, 8, /*NULL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, -1, -1, -1, 20,
/*BOOL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 5, 10, 11, 12, 13, 14, 8, -1, -1, -1, -1, 8, /*BOOL*/ 0, 1, 2, 3, 4, 5, 6, 7, 8, 5, 10, 11, 12, 13, 14, -1, -1, -1, -1, -1, -1,
/*TINY*/ 0, 0, 2, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, 8, -1, -1, -1, -1, 8, /*TINY*/ 0, 0, 2, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, -1, -1, -1, -1, -1, -1,
/*SMAL*/ 0, 0, 0, 3, 4, 5, 8, 8, 8, 5, 10, 3, 4, 5, 8, 8, -1, -1, -1, -1, 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 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1,
/*BLOB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, /*BLOB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1,

View File

@ -838,7 +838,7 @@ endi
if $data20 != 11 then if $data20 != 11 then
return -1 return -1
endi endi
if $data30 != 1664176504 then if $data30 != 1664176504000 then
return -1 return -1
endi endi
@ -1130,38 +1130,38 @@ if $data00 != varchar_val then
return -1 return -1
endi endi
sql select case when ts > '2022-01-01 00:00:00' then c_varchar else c_geometry end as result from t_test; sql select case when 1 then 1234567890987654 else 'abcertyuiojhgfddhjgfcvbn' end;
if $data00 != varchar_val then if $data00 != 1234567890987654 then
return -1 return -1
endi endi
sql select case when ts > '2022-01-01 00:00:00' then c_bool else c_geometry end as result from t_test; sql select case when 0 then 1234567890987654 else 'abcertyuiojhgfddhjgfcvbn' end;
if $data00 != true then if $data00 != abcertyuiojhgfddhjgfcvbn then
return -1 return -1
endi endi
sql select case when 0 then tag_id else c_geometry end as result from t_test; sql select case when 0 then 1234567890987654 else c_nchar end from t_test;
if $data00 != 16842773 then
return -1
endi
sql select case when 0 then tag_id else c_nchar end as result from t_test;
if $data00 != 涛思数据 then if $data00 != 涛思数据 then
return -1 return -1
endi endi
sql select case when 0 then tag_id else c_int end as result from t_test; sql select case when 1 then 1234567890987654 else c_nchar end from t_test;
if $data00 != 123 then if $data00 != 1234567890987654 then
return -1 return -1
endi endi
sql select case when 0 then tag_id else c_float end as result from t_test; sql select case when 1 then c_varchar else c_varbinary end from t_test;
if $data00 != 123.449997 then if $data00 != null then
return -1 return -1
endi endi
sql_error select case when ts > '2022-01-01 00:00:00' then c_varchar else c_geometry end as result from t_test;
sql_error select case when ts > '2022-01-01 00:00:00' then c_bool else c_geometry end as result from t_test;
sql_error select case when 0 then tag_id else c_geometry end as result from t_test;
sql_error select case when 0 then tag_id else c_nchar end as result from t_test;
sql_error select case when 0 then tag_id else c_int end as result from t_test;
sql_error select case when 0 then tag_id else c_float end as result from t_test;
sql_error select case when c_double > 100 then c_varbinary else c_geometry end as result from t_test; sql_error select case when c_double > 100 then c_varbinary else c_geometry end as result from t_test;
sql_error select case when c_bool then c_double else c_varbinary end as result from t_test; sql_error select case when c_bool then c_double else c_varbinary end as result from t_test;
sql_error select case when c_bool then c_varbinary else c_varchar end as result from t_test;
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s stop -x SIGINT