Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve fetch speed if no set result file #734

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 30 additions & 21 deletions src/benchUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,38 +796,47 @@ int postProceSql(char *sqlstr, char* dbName, int precision, int iface,
return code;
}

// fetch result fo file or nothing
void fetchResult(TAOS_RES *res, threadInfo *pThreadInfo) {
TAOS_ROW row = NULL;
int num_rows = 0;
int num_fields = taos_field_count(res);
TAOS_FIELD *fields = taos_fetch_fields(res);

char *databuf = (char *)benchCalloc(1, FETCH_BUFFER_SIZE, true);

int64_t totalLen = 0;
TAOS_ROW row = NULL;
int num_fields = 0;
int64_t totalLen = 0;
TAOS_FIELD *fields = 0;
char *databuf = NULL;
bool toFile = strlen(pThreadInfo->filePath) > 0;

if(toFile) {
num_fields = taos_field_count(res);
fields = taos_fetch_fields(res);
databuf = (char *)benchCalloc(1, FETCH_BUFFER_SIZE, true);
}

// fetch the records row by row
while ((row = taos_fetch_row(res))) {
if (totalLen >= (FETCH_BUFFER_SIZE - HEAD_BUFF_LEN * 2)) {
if (strlen(pThreadInfo->filePath) > 0) {
if (toFile) {
if (totalLen >= (FETCH_BUFFER_SIZE - HEAD_BUFF_LEN * 2)) {
// buff is full
appendResultBufToFile(databuf, pThreadInfo->filePath);
totalLen = 0;
memset(databuf, 0, FETCH_BUFFER_SIZE);
}
totalLen = 0;
memset(databuf, 0, FETCH_BUFFER_SIZE);

// format row
char temp[HEAD_BUFF_LEN] = {0};
int len = taos_print_row(temp, row, fields, num_fields);
len += snprintf(temp + len, HEAD_BUFF_LEN - len, "\n");
debugPrint("query result:%s\n", temp);
memcpy(databuf + totalLen, temp, len);
totalLen += len;
}
num_rows++;
char temp[HEAD_BUFF_LEN] = {0};
int len = taos_print_row(temp, row, fields, num_fields);
len += snprintf(temp + len, HEAD_BUFF_LEN - len, "\n");
debugPrint("query result:%s\n", temp);
memcpy(databuf + totalLen, temp, len);
totalLen += len;
//if not toFile , only loop call taos_fetch_row
}

if (strlen(pThreadInfo->filePath) > 0) {
// end
if (toFile) {
appendResultBufToFile(databuf, pThreadInfo->filePath);
free(databuf);
}
free(databuf);
}

char *convertDatatypeToString(int type) {
Expand Down
Loading