提交 91a5378f 编写于 作者: K kailixu

tiny code optimization

上级 c329bb4d
...@@ -49,13 +49,11 @@ static FORCE_INLINE int32_t getExtendedRowSize(STableComInfo *tinfo) { ...@@ -49,13 +49,11 @@ static FORCE_INLINE int32_t getExtendedRowSize(STableComInfo *tinfo) {
return tinfo->rowSize + PAYLOAD_HEADER_LEN + PAYLOAD_COL_HEAD_LEN * tinfo->numOfColumns; return tinfo->rowSize + PAYLOAD_HEADER_LEN + PAYLOAD_COL_HEAD_LEN * tinfo->numOfColumns;
} }
int initSMemRowHelper(SMemRowHelper *pHelper, SSchema *pSSchema, uint16_t nCols, uint16_t allNullColsLen) { int initSMemRowHelper(SMemRowHelper *pHelper, SSchema *pSSchema, uint16_t nCols, uint16_t allNullColsLen) {
ASSERT(nCols > 0);
pHelper->allNullLen = allNullColsLen; // TODO: get allNullColsLen when creating or altering table meta pHelper->allNullLen = allNullColsLen; // TODO: get allNullColsLen when creating or altering table meta
if (pHelper->allNullLen == 0) { if (pHelper->allNullLen == 0) {
for (uint16_t i = 0; i < nCols; ++i) { for (uint16_t i = 0; i < nCols; ++i) {
uint8_t type = pSSchema[i].type; uint8_t type = pSSchema[i].type;
int32_t typeLen = TYPE_BYTES[type]; int32_t typeLen = TYPE_BYTES[type];
ASSERT(typeLen > 0);
pHelper->allNullLen += typeLen; pHelper->allNullLen += typeLen;
if (TSDB_DATA_TYPE_BINARY == type) { if (TSDB_DATA_TYPE_BINARY == type) {
pHelper->allNullLen += (sizeof(VarDataLenT) + CHAR_BYTES); pHelper->allNullLen += (sizeof(VarDataLenT) + CHAR_BYTES);
...@@ -787,14 +785,12 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i ...@@ -787,14 +785,12 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i
SParsedDataColInfo *spd = &pDataBlocks->boundColumnInfo; SParsedDataColInfo *spd = &pDataBlocks->boundColumnInfo;
SSchema * schema = tscGetTableSchema(pDataBlocks->pTableMeta); SSchema * schema = tscGetTableSchema(pDataBlocks->pTableMeta);
TDRowTLenT dataRowLen = pHelper->allNullLen;
int32_t rowSize = 0; TDRowTLenT kvRowLen = TD_MEM_ROW_KV_VER_SIZE;
int32_t dataRowLen = pHelper->allNullLen;
int32_t kvRowLen = TD_MEM_ROW_KV_VER_SIZE;
TDRowTLenT payloadValOffset = 0; TDRowTLenT payloadValOffset = 0;
TDRowLenT colValOffset = 0; TDRowLenT colValOffset = 0;
ASSERT(dataRowLen > 0); ASSERT(dataRowLen > 0);
payloadSetNCols(payload, spd->numOfBound); payloadSetNCols(payload, spd->numOfBound);
payloadValOffset = payloadValuesOffset(payload); // rely on payloadNCols payloadValOffset = payloadValuesOffset(payload); // rely on payloadNCols
payloadSetTLen(payload, payloadValOffset); payloadSetTLen(payload, payloadValOffset);
...@@ -810,7 +806,6 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i ...@@ -810,7 +806,6 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i
char *start = payload + spd->cols[colIndex].offset; char *start = payload + spd->cols[colIndex].offset;
SSchema *pSchema = &schema[colIndex]; // get colId here SSchema *pSchema = &schema[colIndex]; // get colId here
rowSize += pSchema->bytes;
index = 0; index = 0;
sToken = tStrGetToken(*str, &index, true); sToken = tStrGetToken(*str, &index, true);
...@@ -879,9 +874,7 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i ...@@ -879,9 +874,7 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i
} else { } else {
ASSERT(spd->colIdxInfo[i].finalIdx == 0); ASSERT(spd->colIdxInfo[i].finalIdx == 0);
} }
} else { }
ASSERT(spd->colIdxInfo == NULL);
}
// the primary key locates in 1st column // the primary key locates in 1st column
int32_t ret = tsParseOneColumnKV(pSchema, &sToken, payload, kvPrimaryKeyStart, kvStart, pInsertParam->msg, str, int32_t ret = tsParseOneColumnKV(pSchema, &sToken, payload, kvPrimaryKeyStart, kvStart, pInsertParam->msg, str,
isPrimaryKey, timePrec, payloadValOffset + colValOffset, &colValAppended, isPrimaryKey, timePrec, payloadValOffset + colValOffset, &colValAppended,
...@@ -1050,7 +1043,7 @@ int32_t tscAllocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int3 ...@@ -1050,7 +1043,7 @@ int32_t tscAllocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int3
// expand the allocated size // expand the allocated size
if (remain < rowSize * factor) { if (remain < rowSize * factor) {
while (remain < rowSize * factor) { while (remain < rowSize * factor) {
pDataBlock->nAllocSize = (uint32_t)(pDataBlock->nAllocSize * 2); pDataBlock->nAllocSize = (uint32_t)(pDataBlock->nAllocSize * 1.5);
remain = pDataBlock->nAllocSize - pDataBlock->size; remain = pDataBlock->nAllocSize - pDataBlock->size;
} }
...@@ -1553,7 +1546,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat ...@@ -1553,7 +1546,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
int32_t index = 0; int32_t index = 0;
SStrToken sToken = tStrGetToken(str, &index, false); SStrToken sToken = tStrGetToken(str, &index, false);
str += index; str += index;
...@@ -1561,6 +1554,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat ...@@ -1561,6 +1554,7 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat
code = tscSQLSyntaxErrMsg(pInsertParam->msg, "( is expected", sToken.z); code = tscSQLSyntaxErrMsg(pInsertParam->msg, "( is expected", sToken.z);
goto _clean; goto _clean;
} }
bool isOrdered = true; bool isOrdered = true;
int32_t lastColIdx = -1; int32_t lastColIdx = -1;
while (1) { while (1) {
...@@ -1621,13 +1615,13 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat ...@@ -1621,13 +1615,13 @@ static int32_t parseBoundColumns(SInsertStatementParam *pInsertParam, SParsedDat
goto _clean; goto _clean;
} }
SBoundIdxInfo *pColIdx = pColInfo->colIdxInfo; SBoundIdxInfo *pColIdx = pColInfo->colIdxInfo;
for (int i = 0; i < pColInfo->numOfBound; ++i) { for (uint16_t i = 0; i < pColInfo->numOfBound; ++i) {
pColIdx[i].schemaColIdx = (uint16_t)pColInfo->boundedColumns[i]; pColIdx[i].schemaColIdx = (uint16_t)pColInfo->boundedColumns[i];
pColIdx[i].boundIdx = (uint16_t)i; pColIdx[i].boundIdx = i;
} }
qsort(pColIdx, pColInfo->numOfBound, sizeof(SBoundIdxInfo), schemaIdxCompar); qsort(pColIdx, pColInfo->numOfBound, sizeof(SBoundIdxInfo), schemaIdxCompar);
for (int i = 0; i < pColInfo->numOfBound; ++i) { for (uint16_t i = 0; i < pColInfo->numOfBound; ++i) {
pColIdx[i].finalIdx = (uint16_t)i; pColIdx[i].finalIdx = i;
} }
qsort(pColIdx, pColInfo->numOfBound, sizeof(SBoundIdxInfo), boundIdxCompar); qsort(pColIdx, pColInfo->numOfBound, sizeof(SBoundIdxInfo), boundIdxCompar);
} }
......
...@@ -1755,7 +1755,7 @@ static SMemRow tdGenMemRowFromBuilder(SMemRowBuilder* pBuilder) { ...@@ -1755,7 +1755,7 @@ static SMemRow tdGenMemRowFromBuilder(SMemRowBuilder* pBuilder) {
#endif #endif
} else if (memRowType == SMEM_ROW_KV) { } else if (memRowType == SMEM_ROW_KV) {
ASSERT(nColsBound <= nCols); ASSERT(nColsBound < nCols);
SKVRow kvRow = (SKVRow)memRowKvBody(memRow); SKVRow kvRow = (SKVRow)memRowKvBody(memRow);
kvRowSetLen(kvRow, (TDRowLenT)(TD_KV_ROW_HEAD_SIZE + sizeof(SColIdx) * nColsBound)); kvRowSetLen(kvRow, (TDRowLenT)(TD_KV_ROW_HEAD_SIZE + sizeof(SColIdx) * nColsBound));
kvRowSetNCols(kvRow, nColsBound); kvRowSetNCols(kvRow, nColsBound);
...@@ -1846,7 +1846,6 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bo ...@@ -1846,7 +1846,6 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bo
} }
static int32_t getRowExpandSize(STableMeta* pTableMeta) { static int32_t getRowExpandSize(STableMeta* pTableMeta) {
// add prefix len of KV type SMemRow(we may use SDataRow or SKVRow)
int32_t result = TD_MEM_ROW_DATA_HEAD_SIZE; int32_t result = TD_MEM_ROW_DATA_HEAD_SIZE;
int32_t columns = tscGetNumOfColumns(pTableMeta); int32_t columns = tscGetNumOfColumns(pTableMeta);
SSchema* pSchema = tscGetTableSchema(pTableMeta); SSchema* pSchema = tscGetTableSchema(pTableMeta);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册