[td-255] avoid memset the allocated memory to improve the query performance.
This commit is contained in:
parent
cc68a1414c
commit
267e6e0ba6
|
@ -174,7 +174,9 @@ void tscClearInterpInfo(SQueryInfo* pQueryInfo);
|
|||
|
||||
bool tscIsInsertData(char* sqlstr);
|
||||
|
||||
int tscAllocPayload(SSqlCmd* pCmd, int size);
|
||||
// the memory is not reset in case of fast allocate payload function
|
||||
int32_t tscAllocPayloadFast(SSqlCmd *pCmd, size_t size);
|
||||
int32_t tscAllocPayload(SSqlCmd* pCmd, int size);
|
||||
|
||||
TAOS_FIELD tscCreateField(int8_t type, const char* name, int16_t bytes);
|
||||
|
||||
|
|
|
@ -887,8 +887,9 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
|
|||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t size = tscEstimateQueryMsgSize(pSql);
|
||||
assert(size > 0);
|
||||
|
||||
if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, size)) {
|
||||
if (TSDB_CODE_SUCCESS != tscAllocPayloadFast(pCmd, size)) {
|
||||
tscError("%p failed to malloc for query msg", pSql);
|
||||
return TSDB_CODE_TSC_INVALID_OPERATION; // todo add test for this
|
||||
}
|
||||
|
|
|
@ -2080,32 +2080,34 @@ bool tscIsInsertData(char* sqlstr) {
|
|||
} while (1);
|
||||
}
|
||||
|
||||
int tscAllocPayload(SSqlCmd* pCmd, int size) {
|
||||
int32_t tscAllocPayloadFast(SSqlCmd *pCmd, size_t size) {
|
||||
if (pCmd->payload == NULL) {
|
||||
assert(pCmd->allocSize == 0);
|
||||
|
||||
pCmd->payload = (char*)calloc(1, size);
|
||||
if (pCmd->payload == NULL) {
|
||||
pCmd->payload = malloc(size);
|
||||
} else if (pCmd->allocSize < size) {
|
||||
char* tmp = realloc(pCmd->payload, size);
|
||||
if (tmp == NULL) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pCmd->payload = tmp;
|
||||
pCmd->allocSize = size;
|
||||
} else {
|
||||
if (pCmd->allocSize < (uint32_t)size) {
|
||||
char* b = realloc(pCmd->payload, size);
|
||||
if (b == NULL) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
pCmd->payload = b;
|
||||
pCmd->allocSize = size;
|
||||
}
|
||||
assert(pCmd->allocSize >= size);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tscAllocPayload(SSqlCmd* pCmd, int size) {
|
||||
assert(size > 0);
|
||||
|
||||
int32_t code = tscAllocPayloadFast(pCmd, (size_t) size);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
memset(pCmd->payload, 0, pCmd->allocSize);
|
||||
}
|
||||
|
||||
assert(pCmd->allocSize >= (uint32_t)size && size > 0);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return code;
|
||||
}
|
||||
|
||||
TAOS_FIELD tscCreateField(int8_t type, const char* name, int16_t bytes) {
|
||||
|
|
Loading…
Reference in New Issue