提交 f75abdc1 编写于 作者: X xywang

[TS-1318]<fix>: used merge sort to sort vgId and updated a test case

上级 ce5aae6c
...@@ -936,6 +936,96 @@ static void setTidTagType(SJoinSupporter* p, uint8_t type) { ...@@ -936,6 +936,96 @@ static void setTidTagType(SJoinSupporter* p, uint8_t type) {
} }
} }
static int32_t tidTagsMerge(SArray *arr, int32_t start, int32_t mid, int32_t end, const int32_t tagSize)
{
char *pTmp, *pRes = NULL;
char *result = NULL;
STidTags *pi, *pj, *p;
int32_t k = 0;
int32_t i = start;
int32_t j = mid + 1;
if (end - start > 0) {
result = calloc(1, (end - start + 1) * tagSize);
if (result == NULL) {
tscError("failed to allocate memory for tidTagsMerge");
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
}
pRes = result;
while (i <= mid && j <= end) {
pi = taosArrayGet(arr, i);
pj = taosArrayGet(arr, j);
if (pi->vgId <= pj->vgId) {
p = taosArrayGet(arr, i++);
memcpy(pRes, p, tagSize);
} else {
p = taosArrayGet(arr, j++);
memcpy(pRes, p, tagSize);
}
k++;
pRes += tagSize;
}
if (i == mid + 1) {
while(j <= end) {
p = taosArrayGet(arr, j++);
memcpy(pRes, p, tagSize);
k++;
pRes += tagSize;
}
}
if (j == end + 1) {
while (i <= mid) {
p = taosArrayGet(arr, i++);
memcpy(pRes, p, tagSize);
k++;
pRes += tagSize;
}
}
for (i = start, j = 0, pTmp = result; j < k; i++, j++, pTmp += tagSize) {
p = (STidTags *) taosArrayGet(arr, i);
memcpy(p, pTmp, tagSize);
}
if (result) {
tfree(result);
}
return TSDB_CODE_SUCCESS;
}
static int32_t tidTagsMergeSort(SArray *arr, int32_t start, int32_t end, const int32_t tagSize)
{
int32_t ret;
int32_t mid;
if (start >= end) {
return TSDB_CODE_SUCCESS;
}
mid = (start + end) / 2;
ret = tidTagsMergeSort(arr, start, mid, tagSize);
if (ret != TSDB_CODE_SUCCESS) {
return ret;
}
ret = tidTagsMergeSort(arr, mid + 1, end, tagSize);
if (ret != TSDB_CODE_SUCCESS) {
return ret;
}
return tidTagsMerge(arr, start, mid, end, tagSize);
}
static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pParentSql, SArray* resList) { static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pParentSql, SArray* resList) {
int16_t joinNum = pParentSql->subState.numOfSub; int16_t joinNum = pParentSql->subState.numOfSub;
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
...@@ -1125,7 +1215,10 @@ static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pPar ...@@ -1125,7 +1215,10 @@ static int32_t getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pPar
// sort according to the tag value // sort according to the tag value
size_t num = taosArrayGetSize(ctxlist[i].res); size_t num = taosArrayGetSize(ctxlist[i].res);
qsort((ctxlist[i].res)->pData, num, size, tidTagsCompar); int32_t ret = tidTagsMergeSort(ctxlist[i].res, 0, num - 1, size);
if (ret != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
taosArrayPush(resList, &ctxlist[i].res); taosArrayPush(resList, &ctxlist[i].res);
......
...@@ -168,9 +168,9 @@ sql select * from $stb limit 2 offset $offset ...@@ -168,9 +168,9 @@ sql select * from $stb limit 2 offset $offset
if $rows != 2 then if $rows != 2 then
return -1 return -1
endi endi
if $data00 != @18-09-17 10:30:00.002@ then #if $data00 != @18-09-17 10:30:00.002@ then
return -1 # return -1
endi #endi
if $data01 != 9 then if $data01 != 9 then
return -1 return -1
endi endi
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册