more code

This commit is contained in:
Hongze Cheng 2024-02-28 14:34:37 +08:00
parent 8a4b9db172
commit 81d6a1479d
8 changed files with 74 additions and 66 deletions

View File

@ -28,23 +28,25 @@
extern "C" {
#endif
typedef struct SSchema SSchema;
typedef struct SSchema2 SSchema2;
typedef struct STColumn STColumn;
typedef struct STSchema STSchema;
typedef struct SValue SValue;
typedef struct SColVal SColVal;
typedef struct SRow SRow;
typedef struct SRowIter SRowIter;
typedef struct STagVal STagVal;
typedef struct STag STag;
typedef struct SColData SColData;
typedef struct SSchema SSchema;
typedef struct SSchema2 SSchema2;
typedef struct STColumn STColumn;
typedef struct STSchema STSchema;
typedef struct SValue SValue;
typedef struct SColVal SColVal;
typedef struct SRow SRow;
typedef struct SRowIter SRowIter;
typedef struct STagVal STagVal;
typedef struct STag STag;
typedef struct SColData SColData;
typedef struct SRowKey SRowKey;
typedef struct SValueColumn SValueColumn;
#define HAS_NONE ((uint8_t)0x1)
#define HAS_NULL ((uint8_t)0x2)
#define HAS_VALUE ((uint8_t)0x4)
#define HAS_NONE ((uint8_t)0x1)
#define HAS_NULL ((uint8_t)0x2)
#define HAS_VALUE ((uint8_t)0x4)
#define HAS_MULTI_KEY ((uint8_t)0x8)
// bitmap ================================
@ -162,20 +164,22 @@ typedef struct {
} SColDataCompressInfo;
typedef void *(*xMallocFn)(void *, int32_t);
void tColDataDestroy(void *ph);
void tColDataInit(SColData *pColData, int16_t cid, int8_t type, int8_t cflag);
void tColDataClear(SColData *pColData);
void tColDataDeepClear(SColData *pColData);
int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal);
int32_t tColDataUpdateValue(SColData *pColData, SColVal *pColVal, bool forward);
void tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal);
uint8_t tColDataGetBitValue(const SColData *pColData, int32_t iVal);
int32_t tColDataCopy(SColData *pColDataFrom, SColData *pColData, xMallocFn xMalloc, void *arg);
int32_t tColDataCompress(SColData *colData, SColDataCompressInfo *info, void *output, int32_t outputSize,
SBuffer *buffer);
int32_t tColDataDecompress(void *input, int32_t inputSize, const SColDataCompressInfo *info, SColData *colData,
SBuffer *helperBuffer);
extern void (*tColDataCalcSMA[])(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, int16_t *numOfNull);
void tColDataDestroy(void *ph);
void tColDataInit(SColData *pColData, int16_t cid, int8_t type, int8_t cflag);
void tColDataClear(SColData *pColData);
void tColDataDeepClear(SColData *pColData);
int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal);
int32_t tColDataUpdateValue(SColData *pColData, SColVal *pColVal, bool forward);
void tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal);
uint8_t tColDataGetBitValue(const SColData *pColData, int32_t iVal);
int32_t tColDataCopy(SColData *pColDataFrom, SColData *pColData, xMallocFn xMalloc, void *arg);
extern void (*tColDataCalcSMA[])(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, int16_t *numOfNull);
int32_t tColDataCompress(SColData *colData, SColDataCompressInfo *info, void *output, int32_t outputSize,
SBuffer *buffer);
int32_t tColDataDecompress(void *input, int32_t inputSize, const SColDataCompressInfo *info, SColData *colData,
SBuffer *helperBuffer);
// for stmt bind
int32_t tColDataAddValueByBind(SColData *pColData, TAOS_MULTI_BIND *pBind, int32_t buffMaxLen);
@ -205,7 +209,7 @@ struct STSchema {
STColumn columns[];
};
/*
/* TODO: here may change
* 1. Tuple format:
* SRow + [bit map +] fix-length data + [var-length data +] [(type + offset) * numPrimaryKeyCols + fixedLen +
* numOfCols + numPrimaryKeyCols]
@ -234,11 +238,11 @@ struct SValue {
};
};
#define TD_MAX_PRIMARY_KEY_COL 8
#define TD_MAX_PK_COLS 2
struct SRowKey {
TSKEY ts;
uint8_t numOfPKs;
SValue pks[TD_MAX_PRIMARY_KEY_COL];
SValue pks[TD_MAX_PK_COLS];
};
struct SColVal {

View File

@ -17,8 +17,8 @@
#include "trow.h"
#include "tlog.h"
static bool tdSTSRowIterGetTpVal(STSRowIter *pIter, col_type_t colType, int32_t offset, SCellVal *pVal);
static bool tdSTSRowIterGetKvVal(STSRowIter *pIter, col_id_t colId, col_id_t *nIdx, SCellVal *pVal);
static bool tdSTSRowIterGetTpVal(STSRowIter *pIter, col_type_t colType, int32_t offset, SCellVal *pVal);
static bool tdSTSRowIterGetKvVal(STSRowIter *pIter, col_id_t colId, col_id_t *nIdx, SCellVal *pVal);
void tdSTSRowIterInit(STSRowIter *pIter, STSchema *pSchema) {
pIter->pSchema = pSchema;
@ -416,6 +416,7 @@ bool tdSTpRowGetVal(STSRow *pRow, col_id_t colId, col_type_t colType, int32_t fl
return true;
}
bool tdSTSRowIterNext(STSRowIter *pIter, SCellVal *pVal) {
if (pIter->colIdx >= pIter->pSchema->numOfCols) {
return false;
@ -480,8 +481,7 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
}
} else {
varDataLen += sizeof(VarDataLenT);
if (pTColumn->type == TSDB_DATA_TYPE_VARCHAR || pTColumn->type == TSDB_DATA_TYPE_VARBINARY ||
pTColumn->type == TSDB_DATA_TYPE_GEOMETRY) {
if (pTColumn->type == TSDB_DATA_TYPE_VARCHAR || pTColumn->type == TSDB_DATA_TYPE_VARBINARY || pTColumn->type == TSDB_DATA_TYPE_GEOMETRY) {
varDataLen += CHAR_BYTES;
if (maxVarDataLen < CHAR_BYTES + sizeof(VarDataLenT)) {
maxVarDataLen = CHAR_BYTES + sizeof(VarDataLenT);
@ -494,7 +494,7 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
}
}
} else {
if (pColVal && COL_VAL_IS_VALUE(pColVal)) {
if(pColVal && COL_VAL_IS_VALUE(pColVal)) {
nonVarDataLen += TYPE_BYTES[pTColumn->type];
}
}
@ -1084,6 +1084,8 @@ int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TDRowValT valType, int
return TSDB_CODE_SUCCESS;
}
void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColVal) {
STColumn *pTColumn = &pTSchema->columns[iCol];
SCellVal cv = {0};
@ -1104,9 +1106,9 @@ void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColV
*pColVal = COL_VAL_NULL(pTColumn->colId, pTColumn->type);
} else {
pColVal->cid = pTColumn->colId;
pColVal->value.type = pTColumn->type;
pColVal->flag = CV_FLAG_VALUE;
pColVal->value.type = pTColumn->type;
if (IS_VAR_DATA_TYPE(pTColumn->type)) {
pColVal->value.nData = varDataLen(cv.val);
pColVal->value.pData = varDataVal(cv.val);

View File

@ -268,7 +268,7 @@ int32_t tsdbDataFileReadBlockDataByColumn(SDataFileReader *reader, const SBrinRe
int32_t lino = 0;
int32_t n = 0;
SDiskDataHdr hdr;
SBlockCol primaryKeyBlockCols[TD_MAX_PRIMARY_KEY_COL];
SBlockCol primaryKeyBlockCols[TD_MAX_PK_COLS];
// read key part
code = tRealloc(&reader->config->bufArr[0], record->blockKeySize);

View File

@ -200,7 +200,7 @@ int32_t tsdbSttFileReadBlockDataByColumn(SSttFileReader *reader, const SSttBlk *
int32_t lino = 0;
int32_t n = 0;
SDiskDataHdr hdr;
SBlockCol primaryKeyBlockCols[TD_MAX_PRIMARY_KEY_COL];
SBlockCol primaryKeyBlockCols[TD_MAX_PK_COLS];
// load key part
code = tRealloc(&reader->config->bufArr[0], sttBlk->bInfo.szKey);
@ -501,8 +501,8 @@ int32_t tsdbSttFileReadStatisBlock(SSttFileReader *reader, const SStatisBlk *sta
}
if (statisBlk->numOfPKs > 0) {
SValueColumnCompressInfo firstKeyInfos[TD_MAX_PRIMARY_KEY_COL];
SValueColumnCompressInfo lastKeyInfos[TD_MAX_PRIMARY_KEY_COL];
SValueColumnCompressInfo firstKeyInfos[TD_MAX_PK_COLS];
SValueColumnCompressInfo lastKeyInfos[TD_MAX_PK_COLS];
SBufferReader bfReader;
tBufferReaderInit(&bfReader, true, size, &reader->buffers[0]);

View File

@ -1384,7 +1384,7 @@ SColData *tBlockDataGetColData(SBlockData *pBlockData, int16_t cid) {
int32_t tCmprBlockData(SBlockData *pBlockData, int8_t cmprAlg, uint8_t **ppOut, int32_t *szOut, uint8_t *aBuf[],
int32_t aBufSize[]) {
int32_t code = 0;
SBlockCol primaryKeyBlockCols[TD_MAX_PRIMARY_KEY_COL];
SBlockCol primaryKeyBlockCols[TD_MAX_PK_COLS];
SDiskDataHdr hdr = {
.delimiter = TSDB_FILE_DLMT,
.fmtVer = 0,
@ -1511,7 +1511,7 @@ int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uin
int32_t n = 0;
SDiskDataHdr hdr = {0};
SBlockCol primaryKeyBlockCols[TD_MAX_PRIMARY_KEY_COL];
SBlockCol primaryKeyBlockCols[TD_MAX_PK_COLS];
// SDiskDataHdr
n += tGetDiskDataHdr(pIn + n, &hdr);

View File

@ -71,7 +71,7 @@ int32_t tStatisBlockInit(STbStatisBlock *statisBlock) {
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
tBufferInit(&statisBlock->buffers[i]);
}
for (int32_t i = 0; i < TD_MAX_PRIMARY_KEY_COL; ++i) {
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
tValueColumnInit(&statisBlock->firstKeyPKs[i]);
tValueColumnInit(&statisBlock->lastKeyPKs[i]);
}
@ -84,7 +84,7 @@ int32_t tStatisBlockDestroy(STbStatisBlock *statisBlock) {
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
tBufferDestroy(&statisBlock->buffers[i]);
}
for (int32_t i = 0; i < TD_MAX_PRIMARY_KEY_COL; ++i) {
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
tValueColumnDestroy(&statisBlock->firstKeyPKs[i]);
tValueColumnDestroy(&statisBlock->lastKeyPKs[i]);
}
@ -97,7 +97,7 @@ int32_t tStatisBlockClear(STbStatisBlock *statisBlock) {
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
tBufferClear(&statisBlock->buffers[i]);
}
for (int32_t i = 0; i < TD_MAX_PRIMARY_KEY_COL; ++i) {
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
tValueColumnClear(&statisBlock->firstKeyPKs[i]);
tValueColumnClear(&statisBlock->lastKeyPKs[i]);
}
@ -173,7 +173,7 @@ int32_t tBrinBlockInit(SBrinBlock *brinBlock) {
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
tBufferInit(&brinBlock->buffers[i]);
}
for (int32_t i = 0; i < TD_MAX_PRIMARY_KEY_COL; ++i) {
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
tValueColumnInit(&brinBlock->firstKeyPKs[i]);
tValueColumnInit(&brinBlock->lastKeyPKs[i]);
}
@ -186,7 +186,7 @@ int32_t tBrinBlockDestroy(SBrinBlock *brinBlock) {
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
tBufferDestroy(&brinBlock->buffers[i]);
}
for (int32_t i = 0; i < TD_MAX_PRIMARY_KEY_COL; ++i) {
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
tValueColumnDestroy(&brinBlock->firstKeyPKs[i]);
tValueColumnDestroy(&brinBlock->lastKeyPKs[i]);
}
@ -199,7 +199,7 @@ int32_t tBrinBlockClear(SBrinBlock *brinBlock) {
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
tBufferClear(&brinBlock->buffers[i]);
}
for (int32_t i = 0; i < TD_MAX_PRIMARY_KEY_COL; ++i) {
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
tValueColumnClear(&brinBlock->firstKeyPKs[i]);
tValueColumnClear(&brinBlock->lastKeyPKs[i]);
}
@ -364,8 +364,8 @@ int32_t tBrinBlockEncode(SBrinBlock *brinBlock, SBrinBlk *brinBlk, SBuffer *buff
}
// encode primary keys
SValueColumnCompressInfo firstKeyPKsInfos[TD_MAX_PRIMARY_KEY_COL];
SValueColumnCompressInfo lastKeyPKsInfos[TD_MAX_PRIMARY_KEY_COL];
SValueColumnCompressInfo firstKeyPKsInfos[TD_MAX_PK_COLS];
SValueColumnCompressInfo lastKeyPKsInfos[TD_MAX_PK_COLS];
for (int32_t i = 0; i < brinBlk->numOfPKs; ++i) {
SValueColumn *vc = &brinBlock->firstKeyPKs[i];

View File

@ -91,8 +91,8 @@ typedef struct {
SBuffer counts;
};
};
SValueColumn firstKeyPKs[TD_MAX_PRIMARY_KEY_COL];
SValueColumn lastKeyPKs[TD_MAX_PRIMARY_KEY_COL];
SValueColumn firstKeyPKs[TD_MAX_PK_COLS];
SValueColumn lastKeyPKs[TD_MAX_PK_COLS];
} STbStatisBlock;
typedef struct {
@ -154,8 +154,8 @@ typedef struct {
SBuffer counts;
};
};
SValueColumn firstKeyPKs[TD_MAX_PRIMARY_KEY_COL];
SValueColumn lastKeyPKs[TD_MAX_PRIMARY_KEY_COL];
SValueColumn firstKeyPKs[TD_MAX_PK_COLS];
SValueColumn lastKeyPKs[TD_MAX_PK_COLS];
} SBrinBlock;
typedef struct {

View File

@ -17,13 +17,13 @@
#define _XOPEN_SOURCE
#define _DEFAULT_SOURCE
#include "tcompare.h"
#include "osString.h"
#include "regex.h"
#include "tdef.h"
#include "thash.h"
#include "tlog.h"
#include "tutil.h"
#include "types.h"
#include "osString.h"
int32_t setChkInBytes1(const void *pLeft, const void *pRight) {
return NULL != taosHashGet((SHashObj *)pRight, pLeft, 1) ? 1 : 0;
@ -209,11 +209,11 @@ int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight) {
int32_t len1 = varDataLen(pLeft);
int32_t len2 = varDataLen(pRight);
int32_t ret = tasoUcs4Compare((TdUcs4 *)varDataVal(pLeft), (TdUcs4 *)varDataVal(pRight), len1 > len2 ? len2 : len1);
int32_t ret = tasoUcs4Compare((TdUcs4 *)varDataVal(pLeft), (TdUcs4 *)varDataVal(pRight), len1>len2 ? len2:len1);
if (ret == 0) {
if (len1 > len2)
return 1;
else if (len1 < len2)
else if(len1 < len2)
return -1;
else
return 0;
@ -242,7 +242,9 @@ int32_t compareLenBinaryVal(const void *pLeft, const void *pRight) {
}
}
int32_t compareLenBinaryValDesc(const void *pLeft, const void *pRight) { return compareLenBinaryVal(pRight, pLeft); }
int32_t compareLenBinaryValDesc(const void *pLeft, const void *pRight) {
return compareLenBinaryVal(pRight, pLeft);
}
// string > number > bool > null
// ref: https://dev.mysql.com/doc/refman/8.0/en/json.html#json-comparison
@ -326,7 +328,7 @@ int32_t compareInt8Uint16(const void *pLeft, const void *pRight) {
}
int32_t compareInt8Uint32(const void *pLeft, const void *pRight) {
int8_t left = GET_INT8_VAL(pLeft);
int8_t left = GET_INT8_VAL(pLeft);
if (left < 0) return -1;
uint32_t right = GET_UINT32_VAL(pRight);
if ((uint32_t)left > right) return 1;
@ -335,7 +337,7 @@ int32_t compareInt8Uint32(const void *pLeft, const void *pRight) {
}
int32_t compareInt8Uint64(const void *pLeft, const void *pRight) {
int8_t left = GET_INT8_VAL(pLeft);
int8_t left = GET_INT8_VAL(pLeft);
if (left < 0) return -1;
uint64_t right = GET_UINT64_VAL(pRight);
if ((uint64_t)left > right) return 1;
@ -400,7 +402,7 @@ int32_t compareInt16Uint16(const void *pLeft, const void *pRight) {
}
int32_t compareInt16Uint32(const void *pLeft, const void *pRight) {
int16_t left = GET_INT16_VAL(pLeft);
int16_t left = GET_INT16_VAL(pLeft);
if (left < 0) return -1;
uint32_t right = GET_UINT32_VAL(pRight);
if ((uint32_t)left > right) return 1;
@ -409,7 +411,7 @@ int32_t compareInt16Uint32(const void *pLeft, const void *pRight) {
}
int32_t compareInt16Uint64(const void *pLeft, const void *pRight) {
int16_t left = GET_INT16_VAL(pLeft);
int16_t left = GET_INT16_VAL(pLeft);
if (left < 0) return -1;
uint64_t right = GET_UINT64_VAL(pRight);
if ((uint64_t)left > right) return 1;
@ -474,7 +476,7 @@ int32_t compareInt32Uint16(const void *pLeft, const void *pRight) {
}
int32_t compareInt32Uint32(const void *pLeft, const void *pRight) {
int32_t left = GET_INT32_VAL(pLeft);
int32_t left = GET_INT32_VAL(pLeft);
if (left < 0) return -1;
uint32_t right = GET_UINT32_VAL(pRight);
if ((uint32_t)left > right) return 1;
@ -483,7 +485,7 @@ int32_t compareInt32Uint32(const void *pLeft, const void *pRight) {
}
int32_t compareInt32Uint64(const void *pLeft, const void *pRight) {
int32_t left = GET_INT32_VAL(pLeft);
int32_t left = GET_INT32_VAL(pLeft);
if (left < 0) return -1;
uint64_t right = GET_UINT64_VAL(pRight);
if ((uint64_t)left > right) return 1;
@ -556,7 +558,7 @@ int32_t compareInt64Uint32(const void *pLeft, const void *pRight) {
}
int32_t compareInt64Uint64(const void *pLeft, const void *pRight) {
int64_t left = GET_INT64_VAL(pLeft);
int64_t left = GET_INT64_VAL(pLeft);
if (left < 0) return -1;
uint64_t right = GET_UINT64_VAL(pRight);
if ((uint64_t)left > right) return 1;