diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index 959654d1585b13c31e96ab7972d0aa2782a51901..e8c076099759ffe683c78b55a54848cf765daada 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -283,12 +283,37 @@ typedef struct { #define keyCol(pCols) (&((pCols)->cols[0])) // Key column #define dataColsTKeyAt(pCols, idx) ((TKEY *)(keyCol(pCols)->pData))[(idx)] #define dataColsKeyAt(pCols, idx) tdGetKey(dataColsTKeyAt(pCols, idx)) -#define dataColsTKeyFirst(pCols) (((pCols)->numOfRows == 0) ? TKEY_INVALID : dataColsTKeyAt(pCols, 0)) -#define dataColsKeyFirst(pCols) (((pCols)->numOfRows == 0) ? TSDB_DATA_TIMESTAMP_NULL : dataColsKeyAt(pCols, 0)) -#define dataColsTKeyLast(pCols) \ - (((pCols)->numOfRows == 0) ? TKEY_INVALID : dataColsTKeyAt(pCols, (pCols)->numOfRows - 1)) -#define dataColsKeyLast(pCols) \ - (((pCols)->numOfRows == 0) ? TSDB_DATA_TIMESTAMP_NULL : dataColsKeyAt(pCols, (pCols)->numOfRows - 1)) +static FORCE_INLINE TKEY dataColsTKeyFirst(SDataCols *pCols) { + if (pCols->numOfRows) { + return dataColsTKeyAt(pCols, 0); + } else { + return TKEY_INVALID; + } +} + +static FORCE_INLINE TSKEY dataColsKeyFirst(SDataCols *pCols) { + if (pCols->numOfRows) { + return dataColsKeyAt(pCols, 0); + } else { + return TSDB_DATA_TIMESTAMP_NULL; + } +} + +static FORCE_INLINE TKEY dataColsTKeyLast(SDataCols *pCols) { + if (pCols->numOfRows) { + return dataColsTKeyAt(pCols, pCols->numOfRows - 1); + } else { + return TKEY_INVALID; + } +} + +static FORCE_INLINE TSKEY dataColsKeyLast(SDataCols *pCols) { + if (pCols->numOfRows) { + return dataColsKeyAt(pCols, pCols->numOfRows - 1); + } else { + return TSDB_DATA_TIMESTAMP_NULL; + } +} SDataCols *tdNewDataCols(int maxRowSize, int maxCols, int maxRows); void tdResetDataCols(SDataCols *pCols); diff --git a/src/tsdb/src/tsdbCommit.c b/src/tsdb/src/tsdbCommit.c index a4cc316725d60510441c4badb77ce9a2805c08ca..a1ed0796a6e628a55ebe81fd87396ada990b7e73 100644 --- a/src/tsdb/src/tsdbCommit.c +++ b/src/tsdb/src/tsdbCommit.c @@ -15,7 +15,13 @@ #include "tsdbint.h" #define TSDB_MAX_SUBBLOCKS 8 -#define TSDB_KEY_FID(key, days, precision) ((key) / tsMsPerDay[(precision)] / (days)) +static FORCE_INLINE int TSDB_KEY_FID(TSKEY key, int32_t days, int8_t precision) { + if (key < 0) { + return (int)(-((-key) / tsMsPerDay[precision] / days + 1)); + } else { + return (int)((key / tsMsPerDay[precision] / days)); + } +} typedef struct { SRtn rtn; // retention snapshot