From 2de7f87c743850dcfc7cb86905e8cd98af0c54cb Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Thu, 29 Feb 2024 17:06:53 +0800 Subject: [PATCH] more code --- include/common/tdataformat.h | 2 +- source/common/src/tdataformat.c | 17 +++++++++++++---- source/dnode/vnode/src/tsdb/tsdbSttFileRW.c | 2 +- source/dnode/vnode/src/tsdb/tsdbUtil.c | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index c05dae7635..08e41b2115 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -124,7 +124,7 @@ int32_t tRowSort(SArray *aRowP); int32_t tRowMerge(SArray *aRowP, STSchema *pTSchema, int8_t flag); int32_t tRowUpsertColData(SRow *pRow, STSchema *pTSchema, SColData *aColData, int32_t nColData, int32_t flag); void tRowGetKey(SRow *pRow, SRowKey *key); -int32_t tRowKeyCmpr(const void *p1, const void *p2); +int32_t tRowKeyCompare(const void *p1, const void *p2); // SRowIter ================================ int32_t tRowIterOpen(SRow *pRow, STSchema *pTSchema, SRowIter **ppIter); diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index d8ade164d1..0f4a896ae2 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -1243,7 +1243,10 @@ int32_t tValueCompare(const SValue *tv1, const SValue *tv2) { return 0; } -int32_t tRowKeyCmpr(const void *p1, const void *p2) { +// NOTE: +// set key->numOfPKs to 0 as the smallest key with ts +// set key->numOfPKs to (TD_MAX_PK_COLS + 1) as the largest key with ts +int32_t tRowKeyCompare(const void *p1, const void *p2) { SRowKey *key1 = (SRowKey *)p1; SRowKey *key2 = (SRowKey *)p2; @@ -1253,9 +1256,15 @@ int32_t tRowKeyCmpr(const void *p1, const void *p2) { return 1; } - for (uint8_t iKey = 0; iKey < key1->numOfPKs; iKey++) { - int32_t ret = tValueCompare(&key1->pks[iKey], &key2->pks[iKey]); - if (ret) return ret; + if (key1->numOfPKs == key2->numOfPKs) { + for (uint8_t iKey = 0; iKey < key1->numOfPKs; iKey++) { + int32_t ret = tValueCompare(&key1->pks[iKey], &key2->pks[iKey]); + if (ret) return ret; + } + } else if (key1->numOfPKs < key2->numOfPKs) { + return -1; + } else { + return 1; } return 0; diff --git a/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c b/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c index dcf365fc9e..3464bb08a6 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c +++ b/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c @@ -1033,7 +1033,7 @@ int32_t tsdbSttFileWriteRow(SSttFileWriter *writer, SRowInfo *row) { tStatisBlockGet(writer->staticBlock, writer->staticBlock->numOfRecords, &record); - if (tRowKeyCmpr(&key.key, &record.lastKey) > 0) { + if (tRowKeyCompare(&key.key, &record.lastKey) > 0) { // TODO: update count and last key // TARRAY2_LAST(writer->staticBlock->count)++; // TARRAY2_LAST(writer->staticBlock->lastKey) = key->ts; diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index 523aff0374..9922d9e6b2 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -625,7 +625,7 @@ void tsdbRowGetKey(TSDBROW *row, STsdbRowKey *key) { } int32_t tsdbRowKeyCmpr(const STsdbRowKey *key1, const STsdbRowKey *key2) { - int32_t c = tRowKeyCmpr(&key1->key, &key2->key); + int32_t c = tRowKeyCompare(&key1->key, &key2->key); if (c) { return c;