未验证 提交 b4b40078 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #16767 from taosdata/FIX/TS-1760-V26

fix: change the size limit of sql stmt rebuilt for show create table to TSDB_MAX_SQL_LEN
...@@ -295,7 +295,7 @@ void tscSCreateCallBack(void *param, TAOS_RES *tres, int code) { ...@@ -295,7 +295,7 @@ void tscSCreateCallBack(void *param, TAOS_RES *tres, int code) {
taos_fetch_rows_a(tres, tscSCreateCallBack, param); taos_fetch_rows_a(tres, tscSCreateCallBack, param);
builder->callStage = SCREATE_CALLBACK_RETRIEVE; builder->callStage = SCREATE_CALLBACK_RETRIEVE;
} else { } else {
char *result = calloc(1, TSDB_MAX_BINARY_LEN); char *result = calloc(1, TSDB_MAX_SQL_LEN);
pRes->code = builder->fp(builder, result); pRes->code = builder->fp(builder, result);
taos_free_result(pSql); taos_free_result(pSql);
...@@ -359,6 +359,7 @@ TAOS_ROW tscFetchRow(void *param) { ...@@ -359,6 +359,7 @@ TAOS_ROW tscFetchRow(void *param) {
tscClearSqlOwner(pSql); tscClearSqlOwner(pSql);
return data; return data;
} }
static int32_t tscGetTableTagValue(SCreateBuilder *builder, char *result) { static int32_t tscGetTableTagValue(SCreateBuilder *builder, char *result) {
TAOS_ROW row = tscFetchRow(builder); TAOS_ROW row = tscFetchRow(builder);
SSqlObj* pSql = builder->pInterSql; SSqlObj* pSql = builder->pInterSql;
...@@ -381,16 +382,16 @@ static int32_t tscGetTableTagValue(SCreateBuilder *builder, char *result) { ...@@ -381,16 +382,16 @@ static int32_t tscGetTableTagValue(SCreateBuilder *builder, char *result) {
int32_t ret = tscGetNthFieldResult(row, fields, lengths, i, buf); int32_t ret = tscGetNthFieldResult(row, fields, lengths, i, buf);
if (i == 0) { if (i == 0) {
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "%s", "("); snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "%s", "(");
} }
if ((fields[i].type == TSDB_DATA_TYPE_NCHAR if ((fields[i].type == TSDB_DATA_TYPE_NCHAR
|| fields[i].type == TSDB_DATA_TYPE_BINARY || fields[i].type == TSDB_DATA_TYPE_BINARY
|| fields[i].type == TSDB_DATA_TYPE_TIMESTAMP) && 0 == ret) { || fields[i].type == TSDB_DATA_TYPE_TIMESTAMP) && 0 == ret) {
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "\"%s\",", buf); snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "\"%s\",", buf);
} else if (fields[i].type == TSDB_DATA_TYPE_JSON) { } else if (fields[i].type == TSDB_DATA_TYPE_JSON) {
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "'%s,", buf); snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "'%s,", buf);
} else { } else {
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "%s,", buf); snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "%s,", buf);
} }
free(buf); free(buf);
...@@ -487,14 +488,14 @@ int32_t tscRebuildCreateTableStatement(void *param,char *result) { ...@@ -487,14 +488,14 @@ int32_t tscRebuildCreateTableStatement(void *param,char *result) {
SCreateBuilder *builder = (SCreateBuilder *)param; SCreateBuilder *builder = (SCreateBuilder *)param;
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
char *buf = calloc(1,TSDB_MAX_BINARY_LEN); char *buf = calloc(1,TSDB_MAX_SQL_LEN);
if (buf == NULL) { if (buf == NULL) {
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
code = tscGetTableTagValue(builder, buf); code = tscGetTableTagValue(builder, buf);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "CREATE TABLE `%s` USING `%s` TAGS %s", builder->buf, builder->sTableName, buf); snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "CREATE TABLE `%s` USING `%s` TAGS %s", builder->buf, builder->sTableName, buf);
code = tscSCreateBuildResult(builder->pParentSql, SCREATE_BUILD_TABLE, builder->buf, result); code = tscSCreateBuildResult(builder->pParentSql, SCREATE_BUILD_TABLE, builder->buf, result);
} }
free(buf); free(buf);
...@@ -537,7 +538,7 @@ static int32_t tscGetDBInfo(SCreateBuilder *builder, char *result) { ...@@ -537,7 +538,7 @@ static int32_t tscGetDBInfo(SCreateBuilder *builder, char *result) {
int32_t* lengths = taos_fetch_lengths(pSql); int32_t* lengths = taos_fetch_lengths(pSql);
int32_t ret = tscGetNthFieldResult(row, fields, lengths, 0, buf); int32_t ret = tscGetNthFieldResult(row, fields, lengths, 0, buf);
if (0 == ret && 0 == strcmp(buf, builder->buf)) { if (0 == ret && 0 == strcmp(buf, builder->buf)) {
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "CREATE DATABASE `%s`", buf); snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "CREATE DATABASE `%s`", buf);
for (int i = 1; i < num_fields; i++) { for (int i = 1; i < num_fields; i++) {
for (int j = 0; showColumns[j][0] != NULL; j++) { for (int j = 0; showColumns[j][0] != NULL; j++) {
if (STR_NOCASE_EQUAL(fields[i].name, strlen(fields[i].name), showColumns[j][0], strlen(showColumns[j][0]))) { if (STR_NOCASE_EQUAL(fields[i].name, strlen(fields[i].name), showColumns[j][0], strlen(showColumns[j][0]))) {
...@@ -545,9 +546,9 @@ static int32_t tscGetDBInfo(SCreateBuilder *builder, char *result) { ...@@ -545,9 +546,9 @@ static int32_t tscGetDBInfo(SCreateBuilder *builder, char *result) {
ret = tscGetNthFieldResult(row, fields, lengths, i, buf); ret = tscGetNthFieldResult(row, fields, lengths, i, buf);
if (ret == 0) { if (ret == 0) {
if (STR_NOCASE_EQUAL(showColumns[j][0], strlen(showColumns[j][0]), "PRECISION", strlen("PRECISION"))) { if (STR_NOCASE_EQUAL(showColumns[j][0], strlen(showColumns[j][0]), "PRECISION", strlen("PRECISION"))) {
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), " %s '%s'", showColumns[j][1], buf); snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), " %s '%s'", showColumns[j][1], buf);
} else { } else {
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), " %s %s", showColumns[j][1], buf); snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), " %s %s", showColumns[j][1], buf);
} }
} }
} }
...@@ -569,7 +570,7 @@ int32_t tscRebuildCreateDBStatement(void *param,char *result) { ...@@ -569,7 +570,7 @@ int32_t tscRebuildCreateDBStatement(void *param,char *result) {
SCreateBuilder *builder = (SCreateBuilder *)param; SCreateBuilder *builder = (SCreateBuilder *)param;
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
char *buf = calloc(1, TSDB_MAX_BINARY_LEN); char *buf = calloc(1, TSDB_MAX_SQL_LEN);
if (buf == NULL) { if (buf == NULL) {
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
...@@ -582,7 +583,7 @@ int32_t tscRebuildCreateDBStatement(void *param,char *result) { ...@@ -582,7 +583,7 @@ int32_t tscRebuildCreateDBStatement(void *param,char *result) {
} }
static int32_t tscGetTableTagColumnName(SSqlObj *pSql, char **result) { static int32_t tscGetTableTagColumnName(SSqlObj *pSql, char **result) {
char *buf = (char *)malloc(TSDB_MAX_BINARY_LEN); char *buf = (char *)malloc(TSDB_MAX_SQL_LEN);
if (buf == NULL) { if (buf == NULL) {
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
...@@ -599,15 +600,16 @@ static int32_t tscGetTableTagColumnName(SSqlObj *pSql, char **result) { ...@@ -599,15 +600,16 @@ static int32_t tscGetTableTagColumnName(SSqlObj *pSql, char **result) {
int32_t numOfTags = tscGetNumOfTags(pMeta); int32_t numOfTags = tscGetNumOfTags(pMeta);
for (int32_t i = 0; i < numOfTags; i++) { for (int32_t i = 0; i < numOfTags; i++) {
if (i != numOfTags - 1) { if (i != numOfTags - 1) {
snprintf(buf + strlen(buf), TSDB_MAX_BINARY_LEN - strlen(buf), "`%s`,", pTagsSchema[i].name); snprintf(buf + strlen(buf), TSDB_MAX_SQL_LEN - strlen(buf), "`%s`,", pTagsSchema[i].name);
} else { } else {
snprintf(buf + strlen(buf), TSDB_MAX_BINARY_LEN - strlen(buf), "`%s`", pTagsSchema[i].name); snprintf(buf + strlen(buf), TSDB_MAX_SQL_LEN - strlen(buf), "`%s`", pTagsSchema[i].name);
} }
} }
*result = buf; *result = buf;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, char *ddl) { static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, char *ddl) {
SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd); SQueryInfo* pQueryInfo = tscGetQueryInfo(&pSql->cmd);
...@@ -640,7 +642,7 @@ static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, ch ...@@ -640,7 +642,7 @@ static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, ch
param->fp = tscRebuildCreateTableStatement; param->fp = tscRebuildCreateTableStatement;
param->callStage = SCREATE_CALLBACK_QUERY; param->callStage = SCREATE_CALLBACK_QUERY;
char *query = (char *)calloc(1, TSDB_MAX_BINARY_LEN); char *query = (char *)calloc(1, TSDB_MAX_SQL_LEN);
if (query == NULL) { if (query == NULL) {
free(param); free(param);
free(pInterSql); free(pInterSql);
...@@ -656,7 +658,7 @@ static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, ch ...@@ -656,7 +658,7 @@ static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, ch
return code; return code;
} }
snprintf(query + strlen(query), TSDB_MAX_BINARY_LEN - strlen(query), "SELECT %s FROM %s WHERE TBNAME IN(\'%s\')", columns, fullName, tblName); snprintf(query + strlen(query), TSDB_MAX_SQL_LEN - strlen(query), "SELECT %s FROM %s WHERE TBNAME IN(\'%s\')", columns, fullName, tblName);
doAsyncQuery(pSql->pTscObj, pInterSql, tscSCreateCallBack, param, query, strlen(query)); doAsyncQuery(pSql->pTscObj, pInterSql, tscSCreateCallBack, param, query, strlen(query));
free(query); free(query);
free(columns); free(columns);
...@@ -681,9 +683,9 @@ static int32_t tscRebuildDDLForNormalTable(SSqlObj *pSql, const char *tableName, ...@@ -681,9 +683,9 @@ static int32_t tscRebuildDDLForNormalTable(SSqlObj *pSql, const char *tableName,
if (type == TSDB_DATA_TYPE_NCHAR) { if (type == TSDB_DATA_TYPE_NCHAR) {
bytes = bytes/TSDB_NCHAR_SIZE; bytes = bytes/TSDB_NCHAR_SIZE;
} }
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "`%s` %s(%d),", pSchema[i].name, tDataTypes[pSchema[i].type].name, bytes); snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "`%s` %s(%d),", pSchema[i].name, tDataTypes[pSchema[i].type].name, bytes);
} else { } else {
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "`%s` %s,", pSchema[i].name, tDataTypes[pSchema[i].type].name); snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "`%s` %s,", pSchema[i].name, tDataTypes[pSchema[i].type].name);
} }
} }
sprintf(result + strlen(result) - 1, "%s", ")"); sprintf(result + strlen(result) - 1, "%s", ")");
...@@ -708,12 +710,12 @@ static int32_t tscRebuildDDLForSuperTable(SSqlObj *pSql, const char *tableName, ...@@ -708,12 +710,12 @@ static int32_t tscRebuildDDLForSuperTable(SSqlObj *pSql, const char *tableName,
if (type == TSDB_DATA_TYPE_NCHAR) { if (type == TSDB_DATA_TYPE_NCHAR) {
bytes = bytes/TSDB_NCHAR_SIZE; bytes = bytes/TSDB_NCHAR_SIZE;
} }
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result),"`%s` %s(%d),", pSchema[i].name,tDataTypes[pSchema[i].type].name, bytes); snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result),"`%s` %s(%d),", pSchema[i].name,tDataTypes[pSchema[i].type].name, bytes);
} else { } else {
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "`%s` %s,", pSchema[i].name, tDataTypes[type].name); snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "`%s` %s,", pSchema[i].name, tDataTypes[type].name);
} }
} }
snprintf(result + strlen(result) - 1, TSDB_MAX_BINARY_LEN - strlen(result), "%s %s", ")", "TAGS ("); snprintf(result + strlen(result) - 1, TSDB_MAX_SQL_LEN - strlen(result), "%s %s", ")", "TAGS (");
for (int32_t i = numOfRows; i < totalRows; i++) { for (int32_t i = numOfRows; i < totalRows; i++) {
uint8_t type = pSchema[i].type; uint8_t type = pSchema[i].type;
...@@ -722,9 +724,9 @@ static int32_t tscRebuildDDLForSuperTable(SSqlObj *pSql, const char *tableName, ...@@ -722,9 +724,9 @@ static int32_t tscRebuildDDLForSuperTable(SSqlObj *pSql, const char *tableName,
if (type == TSDB_DATA_TYPE_NCHAR) { if (type == TSDB_DATA_TYPE_NCHAR) {
bytes = bytes/TSDB_NCHAR_SIZE; bytes = bytes/TSDB_NCHAR_SIZE;
} }
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "`%s` %s(%d),", pSchema[i].name,tDataTypes[pSchema[i].type].name, bytes); snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "`%s` %s(%d),", pSchema[i].name,tDataTypes[pSchema[i].type].name, bytes);
} else { } else {
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "`%s` %s,", pSchema[i].name, tDataTypes[type].name); snprintf(result + strlen(result), TSDB_MAX_SQL_LEN - strlen(result), "`%s` %s,", pSchema[i].name, tDataTypes[type].name);
} }
} }
sprintf(result + strlen(result) - 1, "%s", ")"); sprintf(result + strlen(result) - 1, "%s", ")");
...@@ -742,7 +744,7 @@ static int32_t tscProcessShowCreateTable(SSqlObj *pSql) { ...@@ -742,7 +744,7 @@ static int32_t tscProcessShowCreateTable(SSqlObj *pSql) {
return TSDB_CODE_TSC_INVALID_VALUE; return TSDB_CODE_TSC_INVALID_VALUE;
} }
char *result = (char *)calloc(1, TSDB_MAX_BINARY_LEN); char *result = (char *)calloc(1, TSDB_MAX_SQL_LEN);
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
code = tscRebuildDDLForSuperTable(pSql, tableName, result); code = tscRebuildDDLForSuperTable(pSql, tableName, result);
......
...@@ -96,6 +96,23 @@ class TDTestCase: ...@@ -96,6 +96,23 @@ class TDTestCase:
tdSql.execute("drop stable if exists db.st") tdSql.execute("drop stable if exists db.st")
tdSql.execute("create table stb(ts timestamp, c1 int) tags(t1 int)") tdSql.execute("create table stb(ts timestamp, c1 int) tags(t1 int)")
tdSql.error("create table `` using stb tags(1)") tdSql.error("create table `` using stb tags(1)")
# TS-1760
sql = "create table stb9 (ts timestamp"
for i in range(999):
sql += ", longcolumntest%d double" % i
sql += ") tags(t1 int)"
tdSql.execute(sql)
tdSql.query("describe stb9")
tdSql.checkRows(1001)
tdSql.query("show create table stb9")
query = tdSql.getData(0, 1)
tdSql.execute("drop table if exists stb9")
tdSql.execute(query)
tdSql.query("describe stb9")
tdSql.checkRows(1001)
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册