TDengine/include/common/tcommon.h

435 lines
11 KiB
C
Raw Normal View History

2021-10-08 02:25:09 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-02-28 09:39:07 +00:00
#ifndef _TD_COMMON_DEF_H_
#define _TD_COMMON_DEF_H_
2024-04-25 05:58:02 +00:00
2021-10-21 03:20:07 +00:00
#include "tarray.h"
2022-02-15 02:11:34 +00:00
#include "tmsg.h"
#include "tvariant.h"
2022-02-28 09:39:07 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2022-07-07 05:56:47 +00:00
// clang-format off
#define IS_META_MSG(x) ( \
x == TDMT_VND_CREATE_STB \
|| x == TDMT_VND_ALTER_STB \
|| x == TDMT_VND_DROP_STB \
|| x == TDMT_VND_CREATE_TABLE \
|| x == TDMT_VND_ALTER_TABLE \
|| x == TDMT_VND_DROP_TABLE \
2022-07-26 09:43:22 +00:00
|| x == TDMT_VND_DELETE \
2022-07-07 05:56:47 +00:00
)
// clang-format on
typedef bool (*state_key_cmpr_fn)(void* pKey1, void* pKey2);
typedef struct STableKeyInfo {
uint64_t uid;
uint64_t groupId;
} STableKeyInfo;
2022-10-18 09:44:00 +00:00
typedef struct SWinKey {
uint64_t groupId;
TSKEY ts;
} SWinKey;
2022-10-18 09:44:00 +00:00
typedef struct SSessionKey {
STimeWindow win;
uint64_t groupId;
} SSessionKey;
2024-01-17 06:22:19 +00:00
typedef int64_t COUNT_TYPE;
typedef struct SVersionRange {
int64_t minVer;
int64_t maxVer;
} SVersionRange;
2022-10-18 09:44:00 +00:00
static inline int winKeyCmprImpl(const void* pKey1, const void* pKey2) {
SWinKey* pWin1 = (SWinKey*)pKey1;
SWinKey* pWin2 = (SWinKey*)pKey2;
if (pWin1->groupId > pWin2->groupId) {
return 1;
} else if (pWin1->groupId < pWin2->groupId) {
return -1;
}
if (pWin1->ts > pWin2->ts) {
return 1;
} else if (pWin1->ts < pWin2->ts) {
return -1;
}
return 0;
}
static inline int winKeyCmpr(const void* pKey1, int kLen1, const void* pKey2, int kLen2) {
2022-10-18 09:44:00 +00:00
return winKeyCmprImpl(pKey1, pKey2);
}
typedef struct {
uint64_t groupId;
TSKEY ts;
int32_t exprIdx;
} STupleKey;
2022-10-17 09:59:43 +00:00
typedef struct STuplePos {
union {
struct {
int32_t pageId;
int32_t offset;
};
2023-05-15 08:26:24 +00:00
SWinKey streamTupleKey;
2022-10-17 09:59:43 +00:00
};
} STuplePos;
typedef struct SFirstLastRes {
bool hasResult;
// used for last_row function only, isNullRes in SResultRowEntry can not be passed to downstream.So,
// this attribute is required
bool isNull;
int32_t bytes;
int64_t ts;
2024-03-15 10:34:41 +00:00
char* pkData;
int32_t pkBytes;
int8_t pkType;
2022-10-17 09:59:43 +00:00
STuplePos pos;
char buf[];
} SFirstLastRes;
static inline int STupleKeyCmpr(const void* pKey1, int kLen1, const void* pKey2, int kLen2) {
STupleKey* pTuple1 = (STupleKey*)pKey1;
STupleKey* pTuple2 = (STupleKey*)pKey2;
if (pTuple1->groupId > pTuple2->groupId) {
return 1;
} else if (pTuple1->groupId < pTuple2->groupId) {
return -1;
}
if (pTuple1->ts > pTuple2->ts) {
return 1;
} else if (pTuple1->ts < pTuple2->ts) {
return -1;
}
if (pTuple1->exprIdx > pTuple2->exprIdx) {
return 1;
} else if (pTuple1->exprIdx < pTuple2->exprIdx) {
return -1;
}
return 0;
}
2022-03-01 07:56:11 +00:00
enum {
TMQ_MSG_TYPE__POLL_DATA_RSP = 0,
2022-06-21 05:50:33 +00:00
TMQ_MSG_TYPE__POLL_META_RSP,
2022-03-01 07:56:11 +00:00
TMQ_MSG_TYPE__EP_RSP,
TMQ_MSG_TYPE__POLL_DATA_META_RSP,
TMQ_MSG_TYPE__WALINFO_RSP,
2024-05-23 09:35:54 +00:00
TMQ_MSG_TYPE__POLL_BATCH_META_RSP,
2022-03-01 07:56:11 +00:00
};
2022-06-29 12:57:15 +00:00
enum {
STREAM_INPUT__DATA_SUBMIT = 1,
STREAM_INPUT__DATA_BLOCK,
STREAM_INPUT__MERGED_SUBMIT,
2022-07-08 09:48:34 +00:00
STREAM_INPUT__TQ_SCAN,
2022-06-29 12:57:15 +00:00
STREAM_INPUT__DATA_RETRIEVE,
2022-07-15 09:48:48 +00:00
STREAM_INPUT__GET_RES,
2022-06-29 12:57:15 +00:00
STREAM_INPUT__CHECKPOINT,
2023-08-12 09:20:10 +00:00
STREAM_INPUT__CHECKPOINT_TRIGGER,
STREAM_INPUT__TRANS_STATE,
2022-09-21 03:54:44 +00:00
STREAM_INPUT__REF_DATA_BLOCK,
2022-08-17 11:19:58 +00:00
STREAM_INPUT__DESTROY,
2022-06-29 12:57:15 +00:00
};
2022-05-05 11:50:11 +00:00
typedef enum EStreamType {
STREAM_NORMAL = 1,
STREAM_INVERT,
2022-06-25 08:12:00 +00:00
STREAM_CLEAR,
2022-05-05 11:50:11 +00:00
STREAM_INVALID,
2022-06-11 06:27:45 +00:00
STREAM_GET_ALL,
STREAM_DELETE_RESULT,
STREAM_DELETE_DATA,
2022-06-22 09:56:46 +00:00
STREAM_RETRIEVE,
2022-06-29 13:11:25 +00:00
STREAM_PULL_DATA,
STREAM_PULL_OVER,
STREAM_FILL_OVER,
2023-08-12 11:16:20 +00:00
STREAM_CHECKPOINT,
2023-01-10 02:13:56 +00:00
STREAM_CREATE_CHILD_TABLE,
2023-08-11 15:51:52 +00:00
STREAM_TRANS_STATE,
2024-01-31 10:09:13 +00:00
STREAM_MID_RETRIEVE,
2024-04-22 02:41:01 +00:00
STREAM_PARTITION_DELETE_DATA,
2022-05-05 11:50:11 +00:00
} EStreamType;
2022-07-01 15:10:46 +00:00
#pragma pack(push, 1)
typedef struct SColumnDataAgg {
int16_t colId;
int16_t numOfNull;
2022-04-02 10:25:57 +00:00
int64_t sum;
int64_t max;
int64_t min;
} SColumnDataAgg;
2022-07-01 15:10:46 +00:00
#pragma pack(pop)
2022-11-28 04:32:40 +00:00
typedef struct SBlockID {
// The uid of table, from which current data block comes. And it is always 0, if current block is the
// result of calculation.
uint64_t uid;
// Block id, acquired and assigned from executor, which created according to the hysical planner. Block id is used
// to mark the stage of exec task.
uint64_t blockId;
// Generated by group/partition by [value|tags]. Created and assigned by table-scan operator, group-by operator,
// and partition by operator.
uint64_t groupId;
} SBlockID;
2024-04-12 05:51:29 +00:00
typedef struct SPkInfo {
int8_t type;
int32_t bytes;
union {
int64_t val;
uint8_t* pData;
} skey;
union {
int64_t val;
uint8_t* pData;
} ekey;
} SPkInfo;
typedef struct SDataBlockInfo {
2022-03-31 07:52:54 +00:00
STimeWindow window;
int32_t rowSize;
2023-03-29 02:46:56 +00:00
int64_t rows; // todo hide this attribute
uint32_t capacity;
2022-11-28 04:32:40 +00:00
SBlockID id;
int16_t hasVarCol;
2022-12-21 03:34:24 +00:00
int16_t dataLoad; // denote if the data is loaded or not
uint8_t scanFlag;
2024-01-30 09:34:06 +00:00
bool blankFill;
SValue pks[2];
2022-11-28 04:32:40 +00:00
2022-06-06 08:34:12 +00:00
// TODO: optimize and remove following
int64_t version; // used for stream, and need serialization
int32_t childId; // used for stream, do not serialize
EStreamType type; // used for stream, do not serialize
STimeWindow calWin; // used for stream, do not serialize
TSKEY watermark; // used for stream
2023-02-23 06:46:34 +00:00
char parTbName[TSDB_TABLE_NAME_LEN]; // used for stream partition
} SDataBlockInfo;
typedef struct SSDataBlock {
2024-06-04 03:39:47 +00:00
SColumnDataAgg* pBlockAgg;
SArray* pDataBlock; // SArray<SColumnInfoData>
SDataBlockInfo info;
} SSDataBlock;
2022-02-04 14:41:54 +00:00
typedef struct SVarColAttr {
2022-02-23 08:04:06 +00:00
int32_t* offset; // start position for each entry in the list
2022-02-04 14:41:54 +00:00
uint32_t length; // used buffer size that contain the valid data
uint32_t allocLen; // allocated buffer size
} SVarColAttr;
// pBlockAgg->numOfNull == info.rows, all data are null
// pBlockAgg->numOfNull == 0, no data are null.
typedef struct SColumnInfoData {
2022-12-21 03:34:24 +00:00
char* pData; // the corresponding block data in memory
2022-02-04 14:41:54 +00:00
union {
2022-02-23 08:04:06 +00:00
char* nullbitmap; // bitmap, one bit for each item in the list
2022-02-04 14:41:54 +00:00
SVarColAttr varmeta;
};
2024-03-20 08:51:40 +00:00
SColumnInfo info; // column info
bool hasNull; // if current column data has null value.
bool reassigned; // if current column data is reassigned.
} SColumnInfoData;
typedef struct SQueryTableDataCond {
2022-06-06 12:22:21 +00:00
uint64_t suid;
2022-12-21 03:34:24 +00:00
int32_t order; // desc|asc order to iterate the data block
int32_t numOfCols;
2022-06-06 12:22:21 +00:00
SColumnInfo* colList;
2022-12-21 03:34:24 +00:00
int32_t* pSlotList; // the column output destation slot, and it may be null
int32_t type; // data block load type:
2023-11-07 11:59:05 +00:00
bool skipRollup;
2022-07-25 03:18:30 +00:00
STimeWindow twindows;
int64_t startVersion;
int64_t endVersion;
2024-03-20 08:51:40 +00:00
bool notLoadData; // response the actual data, not only the rows in the attribute of info.row of ssdatablock
} SQueryTableDataCond;
2022-03-17 06:58:53 +00:00
int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock);
void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock);
2022-02-11 07:50:20 +00:00
2024-03-20 08:51:40 +00:00
void colDataDestroy(SColumnInfoData* pColData);
2022-03-22 10:00:03 +00:00
//======================================================================================================================
// the following structure shared by parser and executor
typedef struct SColumn {
2022-03-09 02:22:53 +00:00
union {
uint64_t uid;
int64_t dataBlockId;
};
2022-03-22 08:03:42 +00:00
int16_t colId;
int16_t slotId;
2022-03-09 02:22:53 +00:00
2022-03-10 08:18:35 +00:00
char name[TSDB_COL_NAME_LEN];
int16_t colType; // column type: normal column, tag, or window column
2022-03-09 02:22:53 +00:00
int16_t type;
int32_t bytes;
uint8_t precision;
uint8_t scale;
} SColumn;
2022-04-02 07:08:48 +00:00
typedef struct STableBlockDistInfo {
uint32_t rowSize;
2022-04-26 09:08:42 +00:00
uint16_t numOfFiles;
uint32_t numOfTables;
uint32_t numOfBlocks;
2022-04-26 09:08:42 +00:00
uint64_t totalSize;
uint64_t totalRows;
int32_t maxRows;
int32_t minRows;
int32_t defMinRows;
int32_t defMaxRows;
2022-04-26 09:08:42 +00:00
int32_t firstSeekTimeUs;
uint32_t numOfInmemRows;
uint32_t numOfSttRows;
2023-02-23 06:46:34 +00:00
uint32_t numOfVgroups;
int32_t blockRowsHisto[20];
2022-04-02 07:08:48 +00:00
} STableBlockDistInfo;
int32_t tSerializeBlockDistInfo(void* buf, int32_t bufLen, const STableBlockDistInfo* pInfo);
int32_t tDeserializeBlockDistInfo(void* buf, int32_t bufLen, STableBlockDistInfo* pInfo);
2022-03-29 09:30:44 +00:00
enum {
2022-03-31 09:36:51 +00:00
FUNC_PARAM_TYPE_VALUE = 0x1,
2022-04-26 09:08:42 +00:00
FUNC_PARAM_TYPE_COLUMN = 0x2,
2022-03-29 09:30:44 +00:00
};
2022-03-09 02:22:53 +00:00
typedef struct SFunctParam {
int32_t type;
2022-03-21 13:39:16 +00:00
SColumn* pCol;
2022-03-09 02:22:53 +00:00
SVariant param;
} SFunctParam;
2022-02-04 14:41:54 +00:00
2022-03-09 02:22:53 +00:00
// the structure for sql function in select clause
2022-03-10 08:18:35 +00:00
typedef struct SResSchame {
int8_t type;
int32_t slotId;
2022-03-10 08:18:35 +00:00
int32_t bytes;
int32_t precision;
int32_t scale;
char name[TSDB_COL_NAME_LEN];
} SResSchema;
2022-03-09 02:22:53 +00:00
typedef struct SExprBasicInfo {
2022-03-10 08:18:35 +00:00
SResSchema resSchema;
2022-03-09 02:22:53 +00:00
int16_t numOfParams; // argument value of each function
2022-03-21 13:39:16 +00:00
SFunctParam* pParam;
2022-03-09 02:22:53 +00:00
} SExprBasicInfo;
typedef struct SExprInfo {
2022-03-21 13:39:16 +00:00
struct SExprBasicInfo base;
struct tExprNode* pExpr;
} SExprInfo;
2022-04-27 13:29:25 +00:00
typedef struct {
2022-06-06 12:22:21 +00:00
const char* key;
2023-02-23 06:46:34 +00:00
size_t keyLen;
2022-06-06 12:22:21 +00:00
uint8_t type;
union {
2022-04-29 02:58:46 +00:00
const char* value;
2022-05-13 03:34:40 +00:00
int64_t i;
uint64_t u;
double d;
float f;
2022-04-29 02:58:46 +00:00
};
size_t length;
2024-03-20 08:51:40 +00:00
bool keyEscaped;
bool valueEscaped;
2022-04-27 13:29:25 +00:00
} SSmlKv;
2022-04-26 09:08:42 +00:00
#define QUERY_ASC_FORWARD_STEP 1
#define QUERY_DESC_FORWARD_STEP -1
#define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) == TSDB_ORDER_ASC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP)
2022-06-06 12:22:21 +00:00
#define SORT_QSORT_T 0x1
#define SORT_SPILLED_MERGE_SORT_T 0x2
typedef struct SSortExecInfo {
int32_t sortMethod;
int32_t sortBuffer;
int32_t loops; // loop count
int32_t writeBytes; // write io bytes
int32_t readBytes; // read io bytes
} SSortExecInfo;
2023-11-07 01:23:06 +00:00
typedef struct SNonSortExecInfo {
2023-11-10 03:47:02 +00:00
int32_t blkNums;
2023-11-07 01:23:06 +00:00
} SNonSortExecInfo;
typedef struct STUidTagInfo {
2023-02-02 02:11:36 +00:00
char* name;
uint64_t uid;
void* pTagVal;
} STUidTagInfo;
2023-02-02 02:11:36 +00:00
// stream special block column
#define START_TS_COLUMN_INDEX 0
#define END_TS_COLUMN_INDEX 1
#define UID_COLUMN_INDEX 2
#define GROUPID_COLUMN_INDEX 3
#define CALCULATE_START_TS_COLUMN_INDEX 4
#define CALCULATE_END_TS_COLUMN_INDEX 5
#define TABLE_NAME_COLUMN_INDEX 6
2024-03-26 08:38:24 +00:00
#define PRIMARY_KEY_COLUMN_INDEX 7
2023-01-10 02:13:56 +00:00
// stream create table block column
2023-02-23 06:46:34 +00:00
#define UD_TABLE_NAME_COLUMN_INDEX 0
#define UD_GROUPID_COLUMN_INDEX 1
#define UD_TAG_COLUMN_INDEX 2
2023-01-10 02:13:56 +00:00
2024-03-20 08:51:40 +00:00
int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t startTime);
2024-04-25 05:58:02 +00:00
int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol);
2024-01-31 06:20:49 +00:00
#define TSMA_RES_STB_POSTFIX "_tsma_res_stb_"
2024-03-26 03:08:16 +00:00
#define MD5_OUTPUT_LEN 32
2024-04-07 09:24:01 +00:00
#define TSMA_RES_STB_EXTRA_COLUMN_NUM 4 // 3 columns: _wstart, _wend, _wduration, 1 tag: tbname
2024-01-31 06:20:49 +00:00
static inline bool isTsmaResSTb(const char* stbName) {
const char* pos = strstr(stbName, TSMA_RES_STB_POSTFIX);
if (pos && strlen(stbName) == (pos - stbName) + strlen(TSMA_RES_STB_POSTFIX)) {
return true;
}
return false;
}
2022-02-04 14:41:54 +00:00
#ifdef __cplusplus
}
#endif
2022-03-03 03:41:49 +00:00
#endif /*_TD_COMMON_DEF_H_*/