Merge pull request #29129 from taosdata/fix/TD-33191
fix(tsdb/cache): fix invalid param caused by column mismatching
This commit is contained in:
commit
7e2a6f1686
|
@ -1757,34 +1757,31 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr
|
||||||
int32_t code = 0, lino = 0;
|
int32_t code = 0, lino = 0;
|
||||||
rocksdb_writebatch_t *wb = NULL;
|
rocksdb_writebatch_t *wb = NULL;
|
||||||
SArray *pTmpColArray = NULL;
|
SArray *pTmpColArray = NULL;
|
||||||
|
bool extraTS = false;
|
||||||
|
|
||||||
SIdxKey *idxKey = taosArrayGet(remainCols, 0);
|
SIdxKey *idxKey = taosArrayGet(remainCols, 0);
|
||||||
if (idxKey->key.cid != PRIMARYKEY_TIMESTAMP_COL_ID) {
|
if (idxKey->key.cid != PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||||
// ignore 'ts' loaded from cache and load it from tsdb
|
// ignore 'ts' loaded from cache and load it from tsdb
|
||||||
SLastCol *pLastCol = taosArrayGet(pLastArray, 0);
|
// SLastCol *pLastCol = taosArrayGet(pLastArray, 0);
|
||||||
tsdbCacheUpdateLastColToNone(pLastCol, TSDB_LAST_CACHE_NO_CACHE);
|
// tsdbCacheUpdateLastColToNone(pLastCol, TSDB_LAST_CACHE_NO_CACHE);
|
||||||
|
|
||||||
SLastKey *key = &(SLastKey){.lflag = ltype, .uid = uid, .cid = PRIMARYKEY_TIMESTAMP_COL_ID};
|
SLastKey *key = &(SLastKey){.lflag = ltype, .uid = uid, .cid = PRIMARYKEY_TIMESTAMP_COL_ID};
|
||||||
if (!taosArrayInsert(remainCols, 0, &(SIdxKey){0, *key})) {
|
if (!taosArrayInsert(remainCols, 0, &(SIdxKey){0, *key})) {
|
||||||
TAOS_RETURN(terrno);
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extraTS = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int num_keys = TARRAY_SIZE(remainCols);
|
int num_keys = TARRAY_SIZE(remainCols);
|
||||||
int16_t *slotIds = taosMemoryMalloc(num_keys * sizeof(int16_t));
|
int16_t *slotIds = taosMemoryMalloc(num_keys * sizeof(int16_t));
|
||||||
|
|
||||||
int16_t *lastColIds = NULL;
|
int16_t *lastColIds = NULL, *lastSlotIds = NULL, *lastrowColIds = NULL, *lastrowSlotIds = NULL;
|
||||||
int16_t *lastSlotIds = NULL;
|
|
||||||
int16_t *lastrowColIds = NULL;
|
|
||||||
int16_t *lastrowSlotIds = NULL;
|
|
||||||
lastColIds = taosMemoryMalloc(num_keys * sizeof(int16_t));
|
lastColIds = taosMemoryMalloc(num_keys * sizeof(int16_t));
|
||||||
lastSlotIds = taosMemoryMalloc(num_keys * sizeof(int16_t));
|
lastSlotIds = taosMemoryMalloc(num_keys * sizeof(int16_t));
|
||||||
lastrowColIds = taosMemoryMalloc(num_keys * sizeof(int16_t));
|
lastrowColIds = taosMemoryMalloc(num_keys * sizeof(int16_t));
|
||||||
lastrowSlotIds = taosMemoryMalloc(num_keys * sizeof(int16_t));
|
lastrowSlotIds = taosMemoryMalloc(num_keys * sizeof(int16_t));
|
||||||
SArray *lastTmpColArray = NULL;
|
SArray *lastTmpColArray = NULL, *lastTmpIndexArray = NULL, *lastrowTmpColArray = NULL, *lastrowTmpIndexArray = NULL;
|
||||||
SArray *lastTmpIndexArray = NULL;
|
|
||||||
SArray *lastrowTmpColArray = NULL;
|
|
||||||
SArray *lastrowTmpIndexArray = NULL;
|
|
||||||
|
|
||||||
int lastIndex = 0;
|
int lastIndex = 0;
|
||||||
int lastrowIndex = 0;
|
int lastrowIndex = 0;
|
||||||
|
@ -1795,7 +1792,12 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr
|
||||||
|
|
||||||
for (int i = 0; i < num_keys; ++i) {
|
for (int i = 0; i < num_keys; ++i) {
|
||||||
SIdxKey *idxKey = taosArrayGet(remainCols, i);
|
SIdxKey *idxKey = taosArrayGet(remainCols, i);
|
||||||
slotIds[i] = pr->pSlotIds[idxKey->idx];
|
if (extraTS && !i) {
|
||||||
|
slotIds[i] = 0;
|
||||||
|
} else {
|
||||||
|
slotIds[i] = pr->pSlotIds[idxKey->idx];
|
||||||
|
}
|
||||||
|
|
||||||
if (IS_LAST_KEY(idxKey->key)) {
|
if (IS_LAST_KEY(idxKey->key)) {
|
||||||
if (NULL == lastTmpIndexArray) {
|
if (NULL == lastTmpIndexArray) {
|
||||||
lastTmpIndexArray = taosArrayInit(num_keys, sizeof(int32_t));
|
lastTmpIndexArray = taosArrayInit(num_keys, sizeof(int32_t));
|
||||||
|
@ -1807,7 +1809,11 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr
|
||||||
TAOS_CHECK_EXIT(terrno);
|
TAOS_CHECK_EXIT(terrno);
|
||||||
}
|
}
|
||||||
lastColIds[lastIndex] = idxKey->key.cid;
|
lastColIds[lastIndex] = idxKey->key.cid;
|
||||||
lastSlotIds[lastIndex] = pr->pSlotIds[idxKey->idx];
|
if (extraTS && !i) {
|
||||||
|
lastSlotIds[lastIndex] = 0;
|
||||||
|
} else {
|
||||||
|
lastSlotIds[lastIndex] = pr->pSlotIds[idxKey->idx];
|
||||||
|
}
|
||||||
lastIndex++;
|
lastIndex++;
|
||||||
} else {
|
} else {
|
||||||
if (NULL == lastrowTmpIndexArray) {
|
if (NULL == lastrowTmpIndexArray) {
|
||||||
|
@ -1820,7 +1826,11 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr
|
||||||
TAOS_CHECK_EXIT(terrno);
|
TAOS_CHECK_EXIT(terrno);
|
||||||
}
|
}
|
||||||
lastrowColIds[lastrowIndex] = idxKey->key.cid;
|
lastrowColIds[lastrowIndex] = idxKey->key.cid;
|
||||||
lastrowSlotIds[lastrowIndex] = pr->pSlotIds[idxKey->idx];
|
if (extraTS && !i) {
|
||||||
|
lastrowSlotIds[lastrowIndex] = 0;
|
||||||
|
} else {
|
||||||
|
lastrowSlotIds[lastrowIndex] = pr->pSlotIds[idxKey->idx];
|
||||||
|
}
|
||||||
lastrowIndex++;
|
lastrowIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1867,7 +1877,9 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr
|
||||||
pLastCol = &noneCol;
|
pLastCol = &noneCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArraySet(pLastArray, idxKey->idx, pLastCol);
|
if (!extraTS || i > 0) {
|
||||||
|
taosArraySet(pLastArray, idxKey->idx, pLastCol);
|
||||||
|
}
|
||||||
// taosArrayRemove(remainCols, i);
|
// taosArrayRemove(remainCols, i);
|
||||||
|
|
||||||
if (/*!pTmpColArray*/ lastTmpIndexArray && !lastTmpColArray) {
|
if (/*!pTmpColArray*/ lastTmpIndexArray && !lastTmpColArray) {
|
||||||
|
|
|
@ -145,6 +145,7 @@ sql alter database $db cachemodel 'both'
|
||||||
sql alter database $db cachesize 2
|
sql alter database $db cachesize 2
|
||||||
sleep 11000
|
sleep 11000
|
||||||
|
|
||||||
|
run tsim/parser/last_both_no_ts.tsim
|
||||||
run tsim/parser/last_both_query.sim
|
run tsim/parser/last_both_query.sim
|
||||||
|
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
$db = testdb
|
||||||
|
sql use $db
|
||||||
|
print "test tb1"
|
||||||
|
|
||||||
|
sql select last_row(f1, f2, f3, f4) from st2
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data00 != 6 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data01 != NULL then
|
||||||
|
print expect NULL actual: $data02
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data02 != NULL then
|
||||||
|
print expect NULL actual: $data02
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data03 != @70-01-01 07:59:57.000@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql select last_row(*) from st2
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data00 != @21-05-12 10:10:12.000@ then
|
||||||
|
print $data00
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data01 != 6 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data02 != NULL then
|
||||||
|
print expect NULL actual: $data02
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data03 != NULL then
|
||||||
|
print expect NULL actual: $data02
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data04 != @70-01-01 07:59:57.000@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql select last(f1, f2, f3, f4) from st2
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data00 != 6 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data01 != 37.000000000 then
|
||||||
|
print expect 37.000000000 actual: $data02
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data02 != 27 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data03 != @70-01-01 07:59:57.000@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql select last(*) from st2
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data00 != @21-05-12 10:10:12.000@ then
|
||||||
|
print $data00
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data01 != 6 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data02 != 37.000000000 then
|
||||||
|
print expect 37.000000000 actual: $data02
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data03 != 27 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data04 != @70-01-01 07:59:57.000@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
Loading…
Reference in New Issue