diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index ee89b5f580cd7e66205c3c9dcfd0c2b7fe5c0cf2..8585a3dac7402cd9a1d4702dcd47b6725270f87e 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -89,12 +89,22 @@ void tscSaveSlowQueryFp(void *handle, void *tmrId) { void tscSaveSlowQuery(SSqlObj *pSql) { const static int64_t SLOW_QUERY_INTERVAL = 3000000L; - if (pSql->res.useconds < SLOW_QUERY_INTERVAL) return; + size_t size = 200; // other part of sql string, expect the main sql str + + if (pSql->res.useconds < SLOW_QUERY_INTERVAL) { + return; + } tscTrace("%p query time:%" PRId64 " sql:%s", pSql, pSql->res.useconds, pSql->sqlstr); - - char *sql = malloc(200); - int len = snprintf(sql, 190, "insert into %s.slowquery values(now, '%s', %" PRId64 ", %" PRId64 ", '", tsMonitorDbName, + int32_t sqlSize = TSDB_SHOW_SQL_LEN + size; + + char *sql = malloc(sqlSize); + if (sql == NULL) { + tscError("%p failed to allocate memory to sent slow to dnode", pSql); + return; + } + + int len = snprintf(sql, size, "insert into %s.slowquery values(now, '%s', %" PRId64 ", %" PRId64 ", '", tsMonitorDbName, pSql->pTscObj->user, pSql->stime, pSql->res.useconds); int sqlLen = snprintf(sql + len, TSDB_SHOW_SQL_LEN, "%s", pSql->sqlstr); if (sqlLen > TSDB_SHOW_SQL_LEN - 1) {