Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c1fa46d5
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
c1fa46d5
编写于
7月 19, 2021
作者:
H
Haojun Liao
提交者:
GitHub
7月 19, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6706 from taosdata/feature/TD-4666
Feature/td 4666
上级
411a035c
567ecdc4
变更
30
展开全部
隐藏空白更改
内联
并排
Showing
30 changed file
with
1998 addition
and
369 deletion
+1998
-369
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+11
-1
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+47
-10
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+608
-57
src/client/src/tscPrepare.c
src/client/src/tscPrepare.c
+215
-9
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+12
-4
src/client/src/tscServer.c
src/client/src/tscServer.c
+7
-6
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+3
-3
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+138
-27
src/common/inc/tdataformat.h
src/common/inc/tdataformat.h
+230
-25
src/common/src/tdataformat.c
src/common/src/tdataformat.c
+137
-10
src/cq/src/cqMain.c
src/cq/src/cqMain.c
+8
-6
src/inc/taosdef.h
src/inc/taosdef.h
+11
-4
src/inc/ttype.h
src/inc/ttype.h
+4
-2
src/query/inc/qExtbuffer.h
src/query/inc/qExtbuffer.h
+2
-2
src/query/inc/qUtil.h
src/query/inc/qUtil.h
+2
-1
src/query/src/qAggMain.c
src/query/src/qAggMain.c
+2
-2
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+2
-2
src/tsdb/inc/tsdbMemTable.h
src/tsdb/inc/tsdbMemTable.h
+6
-6
src/tsdb/inc/tsdbMeta.h
src/tsdb/inc/tsdbMeta.h
+2
-2
src/tsdb/src/tsdbCommit.c
src/tsdb/src/tsdbCommit.c
+12
-11
src/tsdb/src/tsdbMain.c
src/tsdb/src/tsdbMain.c
+14
-12
src/tsdb/src/tsdbMemTable.c
src/tsdb/src/tsdbMemTable.c
+81
-65
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+181
-98
src/tsdb/tests/tsdbTests.cpp
src/tsdb/tests/tsdbTests.cpp
+2
-2
tests/examples/lua/luaconnector.so
tests/examples/lua/luaconnector.so
+0
-0
tests/pytest/fulltest.sh
tests/pytest/fulltest.sh
+1
-1
tests/pytest/table/max_table_length.py
tests/pytest/table/max_table_length.py
+1
-1
tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.csv
...tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.csv
+10
-0
tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.json
...ools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.json
+112
-0
tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.py
.../tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.py
+137
-0
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
c1fa46d5
...
...
@@ -94,11 +94,21 @@ typedef struct SVgroupTableInfo {
SArray
*
itemList
;
// SArray<STableIdInfo>
}
SVgroupTableInfo
;
typedef
struct
SBlockKeyTuple
{
TSKEY
skey
;
void
*
payloadAddr
;
}
SBlockKeyTuple
;
typedef
struct
SBlockKeyInfo
{
int32_t
maxBytesAlloc
;
SBlockKeyTuple
*
pKeyTuple
;
}
SBlockKeyInfo
;
int32_t
converToStr
(
char
*
str
,
int
type
,
void
*
buf
,
int32_t
bufSize
,
int32_t
*
len
);
int32_t
tscCreateDataBlock
(
size_t
initialSize
,
int32_t
rowSize
,
int32_t
startOffset
,
SName
*
name
,
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
);
void
tscDestroyDataBlock
(
STableDataBlocks
*
pDataBlock
,
bool
removeMeta
);
void
tscSortRemoveDataBlockDupRows
(
STableDataBlocks
*
dataBuf
);
int
tscSortRemoveDataBlockDupRows
(
STableDataBlocks
*
dataBuf
,
SBlockKeyInfo
*
pBlkKeyInfo
);
void
tscDestroyBoundColumnInfo
(
SParsedDataColInfo
*
pColInfo
);
void
doRetrieveSubqueryData
(
SSchedMsg
*
pMsg
);
...
...
src/client/inc/tsclient.h
浏览文件 @
c1fa46d5
...
...
@@ -88,13 +88,43 @@ typedef struct SBoundColumn {
int32_t
offset
;
// all column offset value
}
SBoundColumn
;
typedef
struct
{
uint16_t
schemaColIdx
;
uint16_t
boundIdx
;
uint16_t
finalIdx
;
}
SBoundIdxInfo
;
typedef
enum
_COL_ORDER_STATUS
{
ORDER_STATUS_UNKNOWN
=
0
,
ORDER_STATUS_ORDERED
=
1
,
ORDER_STATUS_DISORDERED
=
2
,
}
EOrderStatus
;
typedef
struct
SParsedDataColInfo
{
int16_t
numOfCols
;
int16_t
numOfBound
;
int32_t
*
boundedColumns
;
SBoundColumn
*
cols
;
int16_t
numOfCols
;
int16_t
numOfBound
;
int32_t
*
boundedColumns
;
// bounded column idx according to schema
SBoundColumn
*
cols
;
SBoundIdxInfo
*
colIdxInfo
;
int8_t
orderStatus
;
// bounded columns:
}
SParsedDataColInfo
;
#define IS_DATA_COL_ORDERED(s) ((s) == (int8_t)ORDER_STATUS_ORDERED)
typedef
struct
{
SSchema
*
pSchema
;
int16_t
sversion
;
int32_t
flen
;
uint16_t
nCols
;
void
*
buf
;
void
*
pDataBlock
;
SSubmitBlk
*
pSubmitBlk
;
}
SMemRowBuilder
;
typedef
struct
{
TDRowLenT
allNullLen
;
}
SMemRowHelper
;
typedef
struct
STableDataBlocks
{
SName
tableName
;
int8_t
tsSource
;
// where does the UNIX timestamp come from, server or client
...
...
@@ -109,12 +139,13 @@ typedef struct STableDataBlocks {
STableMeta
*
pTableMeta
;
// the tableMeta of current table, the table meta will be used during submit, keep a ref to avoid to be removed from cache
char
*
pData
;
SParsedDataColInfo
boundColumnInfo
;
SParsedDataColInfo
boundColumnInfo
;
// for parameter ('?') binding
uint32_t
numOfAllocedParams
;
uint32_t
numOfParams
;
SParamInfo
*
params
;
uint32_t
numOfAllocedParams
;
uint32_t
numOfParams
;
SParamInfo
*
params
;
SMemRowHelper
rowHelper
;
}
STableDataBlocks
;
typedef
struct
{
...
...
@@ -243,6 +274,7 @@ typedef struct SSqlObj {
void
*
pStream
;
void
*
pSubscription
;
char
*
sqlstr
;
void
*
pBuf
;
// table meta buffer
char
parseRetry
;
char
retry
;
char
maxRetry
;
...
...
@@ -382,12 +414,17 @@ extern int tscRefId;
extern
int
tscNumOfObj
;
// number of existed sqlObj in current process.
extern
int
(
*
tscBuildMsg
[
TSDB_SQL_MAX
])(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
);
void
tscBuildVgroupTableInfo
(
SSqlObj
*
pSql
,
STableMetaInfo
*
pTableMetaInfo
,
SArray
*
tables
);
int16_t
getNewResColId
(
SSqlCmd
*
pCmd
);
int32_t
schemaIdxCompar
(
const
void
*
lhs
,
const
void
*
rhs
);
int32_t
boundIdxCompar
(
const
void
*
lhs
,
const
void
*
rhs
);
int
initSMemRowHelper
(
SMemRowHelper
*
pHelper
,
SSchema
*
pSSchema
,
uint16_t
nCols
,
uint16_t
allNullColsLen
);
int32_t
getExtendedRowSize
(
STableComInfo
*
tinfo
);
#ifdef __cplusplus
}
#endif
#endif
#endif
\ No newline at end of file
src/client/src/tscParseInsert.c
浏览文件 @
c1fa46d5
此差异已折叠。
点击以展开。
src/client/src/tscPrepare.c
浏览文件 @
c1fa46d5
...
...
@@ -291,6 +291,7 @@ static char* normalStmtBuildSql(STscStmt* stmt) {
return
taosStringBuilderGetResult
(
&
sb
,
NULL
);
}
#if 0
static int fillColumnsNull(STableDataBlocks* pBlock, int32_t rowNum) {
SParsedDataColInfo* spd = &pBlock->boundColumnInfo;
int32_t offset = 0;
...
...
@@ -318,8 +319,129 @@ static int fillColumnsNull(STableDataBlocks* pBlock, int32_t rowNum) {
return TSDB_CODE_SUCCESS;
}
#endif
/**
* input:
* - schema:
* - payload:
* - spd:
* output:
* - pBlock with data block replaced by K-V format
*/
static
int
refactorPayload
(
STableDataBlocks
*
pBlock
,
int32_t
rowNum
)
{
SParsedDataColInfo
*
spd
=
&
pBlock
->
boundColumnInfo
;
SSchema
*
schema
=
(
SSchema
*
)
pBlock
->
pTableMeta
->
schema
;
SMemRowHelper
*
pHelper
=
&
pBlock
->
rowHelper
;
STableMeta
*
pTableMeta
=
pBlock
->
pTableMeta
;
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMeta
);
int
code
=
TSDB_CODE_SUCCESS
;
int32_t
extendedRowSize
=
getExtendedRowSize
(
&
tinfo
);
TDRowTLenT
destPayloadSize
=
sizeof
(
SSubmitBlk
);
ASSERT
(
pHelper
->
allNullLen
>=
8
);
TDRowTLenT
destAllocSize
=
sizeof
(
SSubmitBlk
)
+
rowNum
*
extendedRowSize
;
SSubmitBlk
*
pDestBlock
=
tcalloc
(
destAllocSize
,
1
);
if
(
pDestBlock
==
NULL
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
memcpy
(
pDestBlock
,
pBlock
->
pData
,
sizeof
(
SSubmitBlk
));
char
*
destPayload
=
(
char
*
)
pDestBlock
+
sizeof
(
SSubmitBlk
);
char
*
srcPayload
=
(
char
*
)
pBlock
->
pData
+
sizeof
(
SSubmitBlk
);
for
(
int
n
=
0
;
n
<
rowNum
;
++
n
)
{
payloadSetNCols
(
destPayload
,
spd
->
numOfBound
);
TDRowTLenT
dataRowLen
=
pHelper
->
allNullLen
;
TDRowTLenT
kvRowLen
=
TD_MEM_ROW_KV_VER_SIZE
+
sizeof
(
SColIdx
)
*
spd
->
numOfBound
;
TDRowTLenT
payloadValOffset
=
payloadValuesOffset
(
destPayload
);
// rely on payloadNCols
TDRowLenT
colValOffset
=
0
;
char
*
kvPrimaryKeyStart
=
destPayload
+
PAYLOAD_HEADER_LEN
;
// primaryKey in 1st column tuple
char
*
kvStart
=
kvPrimaryKeyStart
+
PAYLOAD_COL_HEAD_LEN
;
// the column tuple behind the primaryKey
for
(
int32_t
i
=
0
;
i
<
spd
->
numOfBound
;
++
i
)
{
int32_t
colIndex
=
spd
->
boundedColumns
[
i
];
ASSERT
(
spd
->
cols
[
colIndex
].
hasVal
);
char
*
start
=
srcPayload
+
spd
->
cols
[
colIndex
].
offset
;
SSchema
*
pSchema
=
&
schema
[
colIndex
];
// get colId here
bool
isPrimaryKey
=
(
colIndex
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
);
// the primary key locates in 1st column
if
(
!
IS_DATA_COL_ORDERED
(
spd
->
orderStatus
))
{
ASSERT
(
spd
->
colIdxInfo
!=
NULL
);
if
(
!
isPrimaryKey
)
{
kvStart
=
POINTER_SHIFT
(
kvPrimaryKeyStart
,
spd
->
colIdxInfo
[
i
].
finalIdx
*
PAYLOAD_COL_HEAD_LEN
);
}
else
{
ASSERT
(
spd
->
colIdxInfo
[
i
].
finalIdx
==
0
);
}
}
if
(
isPrimaryKey
)
{
payloadColSetId
(
kvPrimaryKeyStart
,
pSchema
->
colId
);
payloadColSetType
(
kvPrimaryKeyStart
,
pSchema
->
type
);
payloadColSetOffset
(
kvPrimaryKeyStart
,
colValOffset
);
memcpy
(
POINTER_SHIFT
(
destPayload
,
payloadValOffset
+
colValOffset
),
start
,
TYPE_BYTES
[
pSchema
->
type
]);
colValOffset
+=
TYPE_BYTES
[
pSchema
->
type
];
kvRowLen
+=
TYPE_BYTES
[
pSchema
->
type
];
}
else
{
payloadColSetId
(
kvStart
,
pSchema
->
colId
);
payloadColSetType
(
kvStart
,
pSchema
->
type
);
payloadColSetOffset
(
kvStart
,
colValOffset
);
if
(
IS_VAR_DATA_TYPE
(
pSchema
->
type
))
{
varDataCopy
(
POINTER_SHIFT
(
destPayload
,
payloadValOffset
+
colValOffset
),
start
);
colValOffset
+=
varDataTLen
(
start
);
kvRowLen
+=
varDataTLen
(
start
);
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_BINARY
)
{
dataRowLen
+=
(
varDataLen
(
start
)
-
CHAR_BYTES
);
}
else
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
dataRowLen
+=
(
varDataLen
(
start
)
-
TSDB_NCHAR_SIZE
);
}
else
{
ASSERT
(
0
);
}
}
else
{
memcpy
(
POINTER_SHIFT
(
destPayload
,
payloadValOffset
+
colValOffset
),
start
,
TYPE_BYTES
[
pSchema
->
type
]);
colValOffset
+=
TYPE_BYTES
[
pSchema
->
type
];
kvRowLen
+=
TYPE_BYTES
[
pSchema
->
type
];
}
if
(
IS_DATA_COL_ORDERED
(
spd
->
orderStatus
))
{
kvStart
+=
PAYLOAD_COL_HEAD_LEN
;
// move to next column
}
}
}
// end of column
if
(
kvRowLen
<
dataRowLen
)
{
payloadSetType
(
destPayload
,
SMEM_ROW_KV
);
}
else
{
payloadSetType
(
destPayload
,
SMEM_ROW_DATA
);
}
ASSERT
(
colValOffset
<=
TSDB_MAX_BYTES_PER_ROW
);
TDRowTLenT
len
=
payloadValOffset
+
colValOffset
;
payloadSetTLen
(
destPayload
,
len
);
// next loop
srcPayload
+=
pBlock
->
rowSize
;
destPayload
+=
len
;
destPayloadSize
+=
len
;
}
// end of row
ASSERT
(
destPayloadSize
<=
destAllocSize
);
tfree
(
pBlock
->
pData
);
pBlock
->
pData
=
(
char
*
)
pDestBlock
;
pBlock
->
nAllocSize
=
destAllocSize
;
pBlock
->
size
=
destPayloadSize
;
return
code
;
}
#if 0
int32_t fillTablesColumnsNull(SSqlObj* pSql) {
SSqlCmd* pCmd = &pSql->cmd;
...
...
@@ -342,17 +464,98 @@ int32_t fillTablesColumnsNull(SSqlObj* pSql) {
return TSDB_CODE_SUCCESS;
}
#endif
/**
* check and sort
*/
static
int
initPayloadEnv
(
STableDataBlocks
*
pBlock
,
int32_t
rowNum
)
{
SParsedDataColInfo
*
spd
=
&
pBlock
->
boundColumnInfo
;
if
(
spd
->
orderStatus
!=
ORDER_STATUS_UNKNOWN
)
{
return
TSDB_CODE_SUCCESS
;
}
bool
isOrdered
=
true
;
int32_t
lastColIdx
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
spd
->
numOfBound
;
++
i
)
{
ASSERT
(
spd
->
cols
[
i
].
hasVal
);
int32_t
colIdx
=
spd
->
boundedColumns
[
i
];
if
(
isOrdered
)
{
if
(
lastColIdx
>
colIdx
)
{
isOrdered
=
false
;
break
;
}
else
{
lastColIdx
=
colIdx
;
}
}
}
////////////////////////////////////////////////////////////////////////////////
// functions for insertion statement preparation
static
int
doBindParam
(
STableDataBlocks
*
pBlock
,
char
*
data
,
SParamInfo
*
param
,
TAOS_BIND
*
bind
,
int32_t
colNum
)
{
if
(
bind
->
is_null
!=
NULL
&&
*
(
bind
->
is_null
))
{
setNull
(
data
+
param
->
offset
,
param
->
type
,
param
->
bytes
);
return
TSDB_CODE_SUCCESS
;
spd
->
orderStatus
=
isOrdered
?
ORDER_STATUS_ORDERED
:
ORDER_STATUS_DISORDERED
;
if
(
isOrdered
)
{
spd
->
colIdxInfo
=
NULL
;
}
else
{
spd
->
colIdxInfo
=
calloc
(
spd
->
numOfBound
,
sizeof
(
SBoundIdxInfo
));
if
(
spd
->
colIdxInfo
==
NULL
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
SBoundIdxInfo
*
pColIdx
=
spd
->
colIdxInfo
;
for
(
uint16_t
i
=
0
;
i
<
spd
->
numOfBound
;
++
i
)
{
pColIdx
[
i
].
schemaColIdx
=
(
uint16_t
)
spd
->
boundedColumns
[
i
];
pColIdx
[
i
].
boundIdx
=
i
;
}
qsort
(
pColIdx
,
spd
->
numOfBound
,
sizeof
(
SBoundIdxInfo
),
schemaIdxCompar
);
for
(
uint16_t
i
=
0
;
i
<
spd
->
numOfBound
;
++
i
)
{
pColIdx
[
i
].
finalIdx
=
i
;
}
qsort
(
pColIdx
,
spd
->
numOfBound
,
sizeof
(
SBoundIdxInfo
),
boundIdxCompar
);
}
return
TSDB_CODE_SUCCESS
;
}
/**
* Refactor the raw payload structure to K-V format as the in tsParseOneRow()
*/
int32_t
fillTablesPayload
(
SSqlObj
*
pSql
)
{
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
int
code
=
TSDB_CODE_SUCCESS
;
STableDataBlocks
**
p
=
taosHashIterate
(
pCmd
->
insertParam
.
pTableBlockHashList
,
NULL
);
STableDataBlocks
*
pOneTableBlock
=
*
p
;
while
(
pOneTableBlock
)
{
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
pOneTableBlock
->
pData
;
if
(
pBlocks
->
numOfRows
>
0
)
{
initSMemRowHelper
(
&
pOneTableBlock
->
rowHelper
,
tscGetTableSchema
(
pOneTableBlock
->
pTableMeta
),
tscGetNumOfColumns
(
pOneTableBlock
->
pTableMeta
),
0
);
if
((
code
=
initPayloadEnv
(
pOneTableBlock
,
pBlocks
->
numOfRows
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
if
((
code
=
refactorPayload
(
pOneTableBlock
,
pBlocks
->
numOfRows
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
};
}
p
=
taosHashIterate
(
pCmd
->
insertParam
.
pTableBlockHashList
,
p
);
if
(
p
==
NULL
)
{
break
;
}
pOneTableBlock
=
*
p
;
}
return
code
;
}
////////////////////////////////////////////////////////////////////////////////
// functions for insertion statement preparation
static
int
doBindParam
(
STableDataBlocks
*
pBlock
,
char
*
data
,
SParamInfo
*
param
,
TAOS_BIND
*
bind
,
int32_t
colNum
)
{
if
(
bind
->
is_null
!=
NULL
&&
*
(
bind
->
is_null
))
{
setNull
(
data
+
param
->
offset
,
param
->
type
,
param
->
bytes
);
return
TSDB_CODE_SUCCESS
;
}
#if 0
if (0) {
// allow user bind param data with different type
...
...
@@ -1106,9 +1309,12 @@ static int insertStmtExecute(STscStmt* stmt) {
pBlk
->
uid
=
pTableMeta
->
id
.
uid
;
pBlk
->
tid
=
pTableMeta
->
id
.
tid
;
fillTablesColumnsNull
(
stmt
->
pSql
);
int
code
=
fillTablesPayload
(
stmt
->
pSql
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
int
code
=
tscMergeTableDataBlocks
(
&
stmt
->
pSql
->
cmd
.
insertParam
,
false
);
code
=
tscMergeTableDataBlocks
(
&
stmt
->
pSql
->
cmd
.
insertParam
,
false
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -1185,7 +1391,7 @@ static int insertBatchStmtExecute(STscStmt* pStmt) {
return
TSDB_CODE_TSC_APP_ERROR
;
}
fillTables
ColumnsNull
(
pStmt
->
pSql
);
fillTables
Payload
(
pStmt
->
pSql
);
if
((
code
=
tscMergeTableDataBlocks
(
&
pStmt
->
pSql
->
cmd
.
insertParam
,
false
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
...
...
src/client/src/tscSQLParser.c
浏览文件 @
c1fa46d5
...
...
@@ -1396,12 +1396,16 @@ static bool validateTableColumnInfo(SArray* pFieldList, SSqlCmd* pCmd) {
const
char
*
msg4
=
"invalid data type"
;
const
char
*
msg5
=
"invalid binary/nchar column length"
;
const
char
*
msg6
=
"invalid column name"
;
const
char
*
msg7
=
"too many columns"
;
// number of fields no less than 2
size_t
numOfCols
=
taosArrayGetSize
(
pFieldList
);
if
(
numOfCols
<=
1
||
numOfCols
>
TSDB_MAX_COLUMNS
)
{
if
(
numOfCols
<=
1
)
{
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
);
return
false
;
}
else
if
(
numOfCols
>
TSDB_MAX_COLUMNS
)
{
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
return
false
;
}
// first column must be timestamp
...
...
@@ -8055,8 +8059,12 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) {
uint32_t
maxSize
=
tscGetTableMetaMaxSize
();
char
name
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
char
buf
[
80
*
1024
]
=
{
0
};
assert
(
maxSize
<
80
*
1024
);
assert
(
maxSize
<
80
*
TSDB_MAX_COLUMNS
);
if
(
!
pSql
->
pBuf
)
{
if
(
NULL
==
(
pSql
->
pBuf
=
tcalloc
(
1
,
80
*
TSDB_MAX_COLUMNS
)))
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
}
pTableMeta
=
calloc
(
1
,
maxSize
);
plist
=
taosArrayInit
(
4
,
POINTER_BYTES
);
...
...
@@ -8073,7 +8081,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if
(
pTableMeta
->
id
.
uid
>
0
)
{
if
(
pTableMeta
->
tableType
==
TSDB_CHILD_TABLE
)
{
code
=
tscCreateTableMetaFromSTableMeta
(
pTableMeta
,
name
,
b
uf
);
code
=
tscCreateTableMetaFromSTableMeta
(
pTableMeta
,
name
,
pSql
->
pB
uf
);
// create the child table meta from super table failed, try load it from mnode
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
src/client/src/tscServer.c
浏览文件 @
c1fa46d5
...
...
@@ -2804,22 +2804,24 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool
taosHashGetClone
(
tscTableMetaInfo
,
name
,
len
,
NULL
,
pTableMetaInfo
->
pTableMeta
,
-
1
);
// TODO resize the tableMeta
char
buf
[
80
*
1024
]
=
{
0
};
assert
(
size
<
80
*
1024
);
assert
(
size
<
80
*
TSDB_MAX_COLUMNS
);
if
(
!
pSql
->
pBuf
)
{
if
(
NULL
==
(
pSql
->
pBuf
=
tcalloc
(
1
,
80
*
TSDB_MAX_COLUMNS
)))
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
}
STableMeta
*
pMeta
=
pTableMetaInfo
->
pTableMeta
;
if
(
pMeta
->
id
.
uid
>
0
)
{
// in case of child table, here only get the
if
(
pMeta
->
tableType
==
TSDB_CHILD_TABLE
)
{
int32_t
code
=
tscCreateTableMetaFromSTableMeta
(
pTableMetaInfo
->
pTableMeta
,
name
,
b
uf
);
int32_t
code
=
tscCreateTableMetaFromSTableMeta
(
pTableMetaInfo
->
pTableMeta
,
name
,
pSql
->
pB
uf
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
getTableMetaFromMnode
(
pSql
,
pTableMetaInfo
,
autocreate
);
}
}
return
TSDB_CODE_SUCCESS
;
}
return
getTableMetaFromMnode
(
pSql
,
pTableMetaInfo
,
autocreate
);
}
...
...
@@ -2934,7 +2936,6 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, SQueryInfo* pQueryInfo) {
if
(
allVgroupInfoRetrieved
(
pQueryInfo
))
{
return
TSDB_CODE_SUCCESS
;
}
SSqlObj
*
pNew
=
calloc
(
1
,
sizeof
(
SSqlObj
));
pNew
->
pTscObj
=
pSql
->
pTscObj
;
pNew
->
signature
=
pNew
;
...
...
src/client/src/tscSubquery.c
浏览文件 @
c1fa46d5
...
...
@@ -2436,9 +2436,9 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
tOrderDescriptor
*
pDesc
=
NULL
;
pRes
->
qId
=
0x1
;
// hack the qhandle check
const
uint32_t
nBufferSize
=
(
1u
<<
1
6u
);
// 64
KB
const
uint32_t
nBufferSize
=
(
1u
<<
1
8u
);
// 256
KB
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfo
(
pCmd
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
SSubqueryState
*
pState
=
&
pSql
->
subState
;
...
...
src/client/src/tscUtil.c
浏览文件 @
c1fa46d5
...
...
@@ -1488,6 +1488,7 @@ void tscFreeSqlObj(SSqlObj* pSql) {
pSql
->
signature
=
NULL
;
pSql
->
fp
=
NULL
;
tfree
(
pSql
->
sqlstr
);
tfree
(
pSql
->
pBuf
);
tfree
(
pSql
->
pSubs
);
pSql
->
subState
.
numOfSub
=
0
;
...
...
@@ -1499,7 +1500,7 @@ void tscFreeSqlObj(SSqlObj* pSql) {
memset
(
pCmd
->
payload
,
0
,
(
size_t
)
pCmd
->
allocSize
);
tfree
(
pCmd
->
payload
);
pCmd
->
allocSize
=
0
;
tsem_destroy
(
&
pSql
->
rspSem
);
memset
(
pSql
,
0
,
sizeof
(
*
pSql
));
free
(
pSql
);
...
...
@@ -1508,6 +1509,7 @@ void tscFreeSqlObj(SSqlObj* pSql) {
void
tscDestroyBoundColumnInfo
(
SParsedDataColInfo
*
pColInfo
)
{
tfree
(
pColInfo
->
boundedColumns
);
tfree
(
pColInfo
->
cols
);
tfree
(
pColInfo
->
colIdxInfo
);
}
void
tscDestroyDataBlock
(
STableDataBlocks
*
pDataBlock
,
bool
removeMeta
)
{
...
...
@@ -1762,11 +1764,107 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i
return
TSDB_CODE_SUCCESS
;
}
static
int
trimDataBlock
(
void
*
pDataBlock
,
STableDataBlocks
*
pTableDataBlock
,
bool
includeSchema
)
{
static
SMemRow
tdGenMemRowFromBuilder
(
SMemRowBuilder
*
pBuilder
)
{
SSchema
*
pSchema
=
pBuilder
->
pSchema
;
char
*
p
=
(
char
*
)
pBuilder
->
buf
;
int
toffset
=
0
;
uint16_t
nCols
=
pBuilder
->
nCols
;
uint8_t
memRowType
=
payloadType
(
p
);
uint16_t
nColsBound
=
payloadNCols
(
p
);
if
(
pBuilder
->
nCols
<=
0
||
nColsBound
<=
0
)
{
return
NULL
;
}
char
*
pVals
=
POINTER_SHIFT
(
p
,
payloadValuesOffset
(
p
));
SMemRow
*
memRow
=
(
SMemRow
)
pBuilder
->
pDataBlock
;
memRowSetType
(
memRow
,
memRowType
);
// ----------------- Raw payload structure for row:
/* |<------------ Head ------------->|<----------- body of column data tuple ------------------->|
* | |<----------------- flen ------------->|<--- value part --->|
* |SMemRowType| dataTLen | nCols | colId | colType | offset | ... | value |...|...|... |
* +-----------+----------+----------+--------------------------------------|--------------------|
* | uint8_t | uint32_t | uint16_t | int16_t | uint8_t | uint16_t | ... |.......|...|...|... |
* +-----------+----------+----------+--------------------------------------+--------------------|
* 1. offset in column data tuple starts from the value part in case of uint16_t overflow.
* 2. dataTLen: total length including the header and body.
*/
if
(
memRowType
==
SMEM_ROW_DATA
)
{
SDataRow
trow
=
(
SDataRow
)
memRowDataBody
(
memRow
);
dataRowSetLen
(
trow
,
(
TDRowLenT
)(
TD_DATA_ROW_HEAD_SIZE
+
pBuilder
->
flen
));
dataRowSetVersion
(
trow
,
pBuilder
->
sversion
);
p
=
(
char
*
)
payloadBody
(
pBuilder
->
buf
);
uint16_t
i
=
0
,
j
=
0
;
while
(
j
<
nCols
)
{
if
(
i
>=
nColsBound
)
{
break
;
}
int16_t
colId
=
payloadColId
(
p
);
if
(
colId
==
pSchema
[
j
].
colId
)
{
// ASSERT(payloadColType(p) == pSchema[j].type);
tdAppendColVal
(
trow
,
POINTER_SHIFT
(
pVals
,
payloadColOffset
(
p
)),
pSchema
[
j
].
type
,
toffset
);
toffset
+=
TYPE_BYTES
[
pSchema
[
j
].
type
];
p
=
payloadNextCol
(
p
);
++
i
;
++
j
;
}
else
if
(
colId
<
pSchema
[
j
].
colId
)
{
p
=
payloadNextCol
(
p
);
++
i
;
}
else
{
tdAppendColVal
(
trow
,
tdGetNullVal
(
pSchema
[
j
].
type
),
pSchema
[
j
].
type
,
toffset
);
toffset
+=
TYPE_BYTES
[
pSchema
[
j
].
type
];
++
j
;
}
}
while
(
j
<
nCols
)
{
tdAppendColVal
(
trow
,
tdGetNullVal
(
pSchema
[
j
].
type
),
pSchema
[
j
].
type
,
toffset
);
toffset
+=
TYPE_BYTES
[
pSchema
[
j
].
type
];
++
j
;
}
#if 0 // no need anymore
while (i < nColsBound) {
p = payloadNextCol(p);
++i;
}
#endif
}
else
if
(
memRowType
==
SMEM_ROW_KV
)
{
SKVRow
kvRow
=
(
SKVRow
)
memRowKvBody
(
memRow
);
kvRowSetLen
(
kvRow
,
(
TDRowLenT
)(
TD_KV_ROW_HEAD_SIZE
+
sizeof
(
SColIdx
)
*
nColsBound
));
kvRowSetNCols
(
kvRow
,
nColsBound
);
memRowSetKvVersion
(
memRow
,
pBuilder
->
sversion
);
p
=
(
char
*
)
payloadBody
(
pBuilder
->
buf
);
int
i
=
0
;
while
(
i
<
nColsBound
)
{
int16_t
colId
=
payloadColId
(
p
);
uint8_t
colType
=
payloadColType
(
p
);
tdAppendKvColVal
(
kvRow
,
POINTER_SHIFT
(
pVals
,
payloadColOffset
(
p
)),
colId
,
colType
,
toffset
);
toffset
+=
sizeof
(
SColIdx
);
p
=
payloadNextCol
(
p
);
++
i
;
}
}
else
{
ASSERT
(
0
);
}
int32_t
rowTLen
=
memRowTLen
(
memRow
);
pBuilder
->
pDataBlock
=
(
char
*
)
pBuilder
->
pDataBlock
+
rowTLen
;
// next row
pBuilder
->
pSubmitBlk
->
dataLen
+=
rowTLen
;
return
memRow
;
}
// Erase the empty space reserved for binary data
static
int
trimDataBlock
(
void
*
pDataBlock
,
STableDataBlocks
*
pTableDataBlock
,
bool
includeSchema
,
SBlockKeyTuple
*
blkKeyTuple
)
{
// TODO: optimize this function, handle the case while binary is not presented
STableMeta
*
pTableMeta
=
pTableDataBlock
->
pTableMeta
;
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMeta
);
SSchema
*
pSchema
=
tscGetTableSchema
(
pTableMeta
);
STableMeta
*
pTableMeta
=
pTableDataBlock
->
pTableMeta
;
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMeta
);
SSchema
*
pSchema
=
tscGetTableSchema
(
pTableMeta
);
SSubmitBlk
*
pBlock
=
pDataBlock
;
memcpy
(
pDataBlock
,
pTableDataBlock
->
pData
,
sizeof
(
SSubmitBlk
));
...
...
@@ -1801,21 +1899,19 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bo
char
*
p
=
pTableDataBlock
->
pData
+
sizeof
(
SSubmitBlk
);
pBlock
->
dataLen
=
0
;
int32_t
numOfRows
=
htons
(
pBlock
->
numOfRows
);
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
SDataRow
trow
=
(
SDataRow
)
pDataBlock
;
dataRowSetLen
(
trow
,
(
uint16_t
)(
TD_DATA_ROW_HEAD_SIZE
+
flen
));
dataRowSetVersion
(
trow
,
pTableMeta
->
sversion
);
int
toffset
=
0
;
for
(
int32_t
j
=
0
;
j
<
tinfo
.
numOfColumns
;
j
++
)
{
tdAppendColVal
(
trow
,
p
,
pSchema
[
j
].
type
,
pSchema
[
j
].
bytes
,
toffset
);
toffset
+=
TYPE_BYTES
[
pSchema
[
j
].
type
];
p
+=
pSchema
[
j
].
bytes
;
}
SMemRowBuilder
rowBuilder
;
rowBuilder
.
pSchema
=
pSchema
;
rowBuilder
.
sversion
=
pTableMeta
->
sversion
;
rowBuilder
.
flen
=
flen
;
rowBuilder
.
nCols
=
tinfo
.
numOfColumns
;
rowBuilder
.
pDataBlock
=
pDataBlock
;
rowBuilder
.
pSubmitBlk
=
pBlock
;
rowBuilder
.
buf
=
p
;
pDataBlock
=
(
char
*
)
pDataBlock
+
dataRowLen
(
trow
);
pBlock
->
dataLen
+=
dataRowLen
(
trow
);
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
rowBuilder
.
buf
=
(
blkKeyTuple
+
i
)
->
payloadAddr
;
tdGenMemRowFromBuilder
(
&
rowBuilder
);
}
int32_t
len
=
pBlock
->
dataLen
+
pBlock
->
schemaLen
;
...
...
@@ -1826,7 +1922,7 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bo
}
static
int32_t
getRowExpandSize
(
STableMeta
*
pTableMeta
)
{
int32_t
result
=
TD_DATA_ROW
_HEAD_SIZE
;
int32_t
result
=
TD_MEM_ROW_DATA
_HEAD_SIZE
;
int32_t
columns
=
tscGetNumOfColumns
(
pTableMeta
);
SSchema
*
pSchema
=
tscGetTableSchema
(
pTableMeta
);
for
(
int32_t
i
=
0
;
i
<
columns
;
i
++
)
{
...
...
@@ -1862,13 +1958,16 @@ static void extractTableNameList(SInsertStatementParam *pInsertParam, bool freeB
int32_t
tscMergeTableDataBlocks
(
SInsertStatementParam
*
pInsertParam
,
bool
freeBlockMap
)
{
const
int
INSERT_HEAD_SIZE
=
sizeof
(
SMsgDesc
)
+
sizeof
(
SSubmitMsg
);
void
*
pVnodeDataBlockHashList
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
false
);
SArray
*
pVnodeDataBlockList
=
taosArrayInit
(
8
,
POINTER_BYTES
);
int
code
=
0
;
void
*
pVnodeDataBlockHashList
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
false
);
SArray
*
pVnodeDataBlockList
=
taosArrayInit
(
8
,
POINTER_BYTES
);
STableDataBlocks
**
p
=
taosHashIterate
(
pInsertParam
->
pTableBlockHashList
,
NULL
);
STableDataBlocks
*
pOneTableBlock
=
*
p
;
SBlockKeyInfo
blkKeyInfo
=
{
0
};
// share by pOneTableBlock
while
(
pOneTableBlock
)
{
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
pOneTableBlock
->
pData
;
if
(
pBlocks
->
numOfRows
>
0
)
{
...
...
@@ -1882,6 +1981,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
tscError
(
"0x%"
PRIx64
" failed to prepare the data block buffer for merging table data, code:%d"
,
pInsertParam
->
objectId
,
ret
);
taosHashCleanup
(
pVnodeDataBlockHashList
);
tscDestroyBlockArrayList
(
pVnodeDataBlockList
);
tfree
(
blkKeyInfo
.
pKeyTuple
);
return
ret
;
}
...
...
@@ -1902,16 +2002,26 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
taosHashCleanup
(
pVnodeDataBlockHashList
);
tscDestroyBlockArrayList
(
pVnodeDataBlockList
);
tfree
(
dataBuf
->
pData
);
tfree
(
blkKeyInfo
.
pKeyTuple
);
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
}
tscSortRemoveDataBlockDupRows
(
pOneTableBlock
);
char
*
ekey
=
(
char
*
)
pBlocks
->
data
+
pOneTableBlock
->
rowSize
*
(
pBlocks
->
numOfRows
-
1
);
if
((
code
=
tscSortRemoveDataBlockDupRows
(
pOneTableBlock
,
&
blkKeyInfo
))
!=
0
)
{
taosHashCleanup
(
pVnodeDataBlockHashList
);
tscDestroyBlockArrayList
(
pVnodeDataBlockList
);
tfree
(
dataBuf
->
pData
);
tfree
(
blkKeyInfo
.
pKeyTuple
);
return
code
;
}
ASSERT
(
blkKeyInfo
.
pKeyTuple
!=
NULL
&&
pBlocks
->
numOfRows
>
0
);
tscDebug
(
"0x%"
PRIx64
" name:%s, tid:%d rows:%d sversion:%d skey:%"
PRId64
", ekey:%"
PRId64
,
pInsertParam
->
objectId
,
tNameGetTableName
(
&
pOneTableBlock
->
tableName
),
pBlocks
->
tid
,
pBlocks
->
numOfRows
,
pBlocks
->
sversion
,
GET_INT64_VAL
(
pBlocks
->
data
),
GET_INT64_VAL
(
ekey
));
SBlockKeyTuple
*
pLastKeyTuple
=
blkKeyInfo
.
pKeyTuple
+
pBlocks
->
numOfRows
-
1
;
tscDebug
(
"0x%"
PRIx64
" name:%s, tid:%d rows:%d sversion:%d skey:%"
PRId64
", ekey:%"
PRId64
,
pInsertParam
->
objectId
,
tNameGetTableName
(
&
pOneTableBlock
->
tableName
),
pBlocks
->
tid
,
pBlocks
->
numOfRows
,
pBlocks
->
sversion
,
blkKeyInfo
.
pKeyTuple
->
skey
,
pLastKeyTuple
->
skey
);
int32_t
len
=
pBlocks
->
numOfRows
*
(
pOneTableBlock
->
rowSize
+
expandSize
)
+
sizeof
(
STColumn
)
*
tscGetNumOfColumns
(
pOneTableBlock
->
pTableMeta
);
...
...
@@ -1922,7 +2032,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
pBlocks
->
schemaLen
=
0
;
// erase the empty space reserved for binary data
int32_t
finalLen
=
trimDataBlock
(
dataBuf
->
pData
+
dataBuf
->
size
,
pOneTableBlock
,
pInsertParam
->
schemaAttached
);
int32_t
finalLen
=
trimDataBlock
(
dataBuf
->
pData
+
dataBuf
->
size
,
pOneTableBlock
,
pInsertParam
->
schemaAttached
,
blkKeyInfo
.
pKeyTuple
);
assert
(
finalLen
<=
len
);
dataBuf
->
size
+=
(
finalLen
+
sizeof
(
SSubmitBlk
));
...
...
@@ -1950,6 +2060,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
// free the table data blocks;
pInsertParam
->
pDataBlocks
=
pVnodeDataBlockList
;
taosHashCleanup
(
pVnodeDataBlockHashList
);
tfree
(
blkKeyInfo
.
pKeyTuple
);
return
TSDB_CODE_SUCCESS
;
}
...
...
src/common/inc/tdataformat.h
浏览文件 @
c1fa46d5
...
...
@@ -24,6 +24,35 @@
extern
"C"
{
#endif
#pragma pack(push, 1)
typedef
struct
{
VarDataLenT
len
;
uint8_t
data
;
}
SBinaryNullT
;
typedef
struct
{
VarDataLenT
len
;
uint32_t
data
;
}
SNCharNullT
;
#pragma pack(pop)
extern
const
uint8_t
BoolNull
;
extern
const
uint8_t
TinyintNull
;
extern
const
uint16_t
SmallintNull
;
extern
const
uint32_t
IntNull
;
extern
const
uint64_t
BigintNull
;
extern
const
uint64_t
TimestampNull
;
extern
const
uint8_t
UTinyintNull
;
extern
const
uint16_t
USmallintNull
;
extern
const
uint32_t
UIntNull
;
extern
const
uint64_t
UBigintNull
;
extern
const
uint32_t
FloatNull
;
extern
const
uint64_t
DoubleNull
;
extern
const
SBinaryNullT
BinaryNull
;
extern
const
SNCharNullT
NcharNull
;
const
void
*
tdGetNullVal
(
int8_t
type
);
#define STR_TO_VARSTR(x, str) \
do { \
VarDataLenT __len = (VarDataLenT)strlen(str); \
...
...
@@ -53,10 +82,10 @@ extern "C" {
// ----------------- TSDB COLUMN DEFINITION
typedef
struct
{
int8_t
type
;
// Column type
int16_t
colId
;
// column ID
int16_t
bytes
;
// column bytes
int16_t
offset
;
// point offset in SDataRow after the header part
int8_t
type
;
// Column type
int16_t
colId
;
// column ID
u
int16_t
bytes
;
// column bytes
uint16_t
offset
;
// point offset in SDataRow after the header part.
}
STColumn
;
#define colType(col) ((col)->type)
...
...
@@ -167,10 +196,11 @@ static FORCE_INLINE int tkeyComparFn(const void *tkey1, const void *tkey2) {
return
0
;
}
}
// ----------------- Data row structure
/* A data row, the format is like below:
* |<--------------------
+
--------------------------- len ---------------------------------->|
* |<--------------------
-
--------------------------- len ---------------------------------->|
* |<-- Head -->|<--------- flen -------------->| |
* +---------------------+---------------------------------+---------------------------------+
* | uint16_t | int16_t | | |
...
...
@@ -184,8 +214,8 @@ typedef void *SDataRow;
#define TD_DATA_ROW_HEAD_SIZE (sizeof(uint16_t) + sizeof(int16_t))
#define dataRowLen(r) (*(
uint16_t *)(r))
#define dataRowVersion(r)
*(int16_t *)POINTER_SHIFT(r, sizeof(int16_t
))
#define dataRowLen(r) (*(
TDRowLenT *)(r)) // 0~65535
#define dataRowVersion(r)
(*(int16_t *)POINTER_SHIFT(r, sizeof(int16_t)
))
#define dataRowTuple(r) POINTER_SHIFT(r, TD_DATA_ROW_HEAD_SIZE)
#define dataRowTKey(r) (*(TKEY *)(dataRowTuple(r)))
#define dataRowKey(r) tdGetKey(dataRowTKey(r))
...
...
@@ -201,20 +231,19 @@ void tdInitDataRow(SDataRow row, STSchema *pSchema);
SDataRow
tdDataRowDup
(
SDataRow
row
);
// offset here not include dataRow header length
static
FORCE_INLINE
int
tdAppendColVal
(
SDataRow
row
,
void
*
value
,
int8_t
type
,
int32_t
bytes
,
int32_t
offset
)
{
static
FORCE_INLINE
int
tdAppendColVal
(
SDataRow
row
,
const
void
*
value
,
int8_t
type
,
int32_t
offset
)
{
ASSERT
(
value
!=
NULL
);
int32_t
toffset
=
offset
+
TD_DATA_ROW_HEAD_SIZE
;
char
*
ptr
=
(
char
*
)
POINTER_SHIFT
(
row
,
dataRowLen
(
row
));
if
(
IS_VAR_DATA_TYPE
(
type
))
{
*
(
VarDataOffsetT
*
)
POINTER_SHIFT
(
row
,
toffset
)
=
dataRowLen
(
row
);
memcpy
(
ptr
,
value
,
varDataTLen
(
value
));
memcpy
(
POINTER_SHIFT
(
row
,
dataRowLen
(
row
))
,
value
,
varDataTLen
(
value
));
dataRowLen
(
row
)
+=
varDataTLen
(
value
);
}
else
{
if
(
offset
==
0
)
{
ASSERT
(
type
==
TSDB_DATA_TYPE_TIMESTAMP
);
TKEY
tvalue
=
tdGetTKEY
(
*
(
TSKEY
*
)
value
);
memcpy
(
POINTER_SHIFT
(
row
,
toffset
),
(
void
*
)(
&
tvalue
),
TYPE_BYTES
[
type
]);
memcpy
(
POINTER_SHIFT
(
row
,
toffset
),
(
const
void
*
)(
&
tvalue
),
TYPE_BYTES
[
type
]);
}
else
{
memcpy
(
POINTER_SHIFT
(
row
,
toffset
),
value
,
TYPE_BYTES
[
type
]);
}
...
...
@@ -245,17 +274,21 @@ typedef struct SDataCol {
TSKEY
ts
;
// only used in last NULL column
}
SDataCol
;
#define isAllRowsNull(pCol) ((pCol)->len == 0)
static
FORCE_INLINE
void
dataColReset
(
SDataCol
*
pDataCol
)
{
pDataCol
->
len
=
0
;
}
void
dataColInit
(
SDataCol
*
pDataCol
,
STColumn
*
pCol
,
void
**
pBuf
,
int
maxPoints
);
void
dataColAppendVal
(
SDataCol
*
pCol
,
void
*
value
,
int
numOfRows
,
int
maxPoints
);
void
dataColAppendVal
(
SDataCol
*
pCol
,
const
void
*
value
,
int
numOfRows
,
int
maxPoints
);
void
dataColSetOffset
(
SDataCol
*
pCol
,
int
nEle
);
bool
isNEleNull
(
SDataCol
*
pCol
,
int
nEle
);
void
dataColSetNEleNull
(
SDataCol
*
pCol
,
int
nEle
,
int
maxPoints
);
// Get the data pointer from a column-wised data
static
FORCE_INLINE
void
*
tdGetColDataOfRow
(
SDataCol
*
pCol
,
int
row
)
{
static
FORCE_INLINE
const
void
*
tdGetColDataOfRow
(
SDataCol
*
pCol
,
int
row
)
{
if
(
isAllRowsNull
(
pCol
))
{
return
tdGetNullVal
(
pCol
->
type
);
}
if
(
IS_VAR_DATA_TYPE
(
pCol
->
type
))
{
return
POINTER_SHIFT
(
pCol
->
pData
,
pCol
->
dataOff
[
row
]);
}
else
{
...
...
@@ -287,7 +320,7 @@ typedef struct {
}
SDataCols
;
#define keyCol(pCols) (&((pCols)->cols[0])) // Key column
#define dataColsTKeyAt(pCols, idx) ((TKEY *)(keyCol(pCols)->pData))[(idx)]
#define dataColsTKeyAt(pCols, idx) ((TKEY *)(keyCol(pCols)->pData))[(idx)]
// the idx row of column-wised data
#define dataColsKeyAt(pCols, idx) tdGetKey(dataColsTKeyAt(pCols, idx))
static
FORCE_INLINE
TKEY
dataColsTKeyFirst
(
SDataCols
*
pCols
)
{
if
(
pCols
->
numOfRows
)
{
...
...
@@ -331,13 +364,13 @@ void tdResetDataCols(SDataCols *pCols);
int
tdInitDataCols
(
SDataCols
*
pCols
,
STSchema
*
pSchema
);
SDataCols
*
tdDupDataCols
(
SDataCols
*
pCols
,
bool
keepData
);
SDataCols
*
tdFreeDataCols
(
SDataCols
*
pCols
);
void
tdAppendDataRowToDataCol
(
SDataRow
row
,
STSchema
*
pSchema
,
SDataCols
*
pCols
);
int
tdMergeDataCols
(
SDataCols
*
target
,
SDataCols
*
source
,
int
rowsToMerge
,
int
*
pOffset
);
// ----------------- K-V data row structure
/*
/* |<-------------------------------------- len -------------------------------------------->|
* |<----- header ----->|<--------------------------- body -------------------------------->|
* +----------+----------+---------------------------------+---------------------------------+
* |
int16_t | int16_t | | |
* |
u
int16_t | int16_t | | |
* +----------+----------+---------------------------------+---------------------------------+
* | len | ncols | cols index | data part |
* +----------+----------+---------------------------------+---------------------------------+
...
...
@@ -345,14 +378,14 @@ int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge
typedef
void
*
SKVRow
;
typedef
struct
{
int16_t
colId
;
int16_t
offset
;
int16_t
colId
;
u
int16_t
offset
;
}
SColIdx
;
#define TD_KV_ROW_HEAD_SIZE (
2 *
sizeof(int16_t))
#define TD_KV_ROW_HEAD_SIZE (
sizeof(uint16_t) +
sizeof(int16_t))
#define kvRowLen(r) (*(
int16_t
*)(r))
#define kvRowNCols(r) (*(int16_t *)POINTER_SHIFT(r, sizeof(int16_t)))
#define kvRowLen(r) (*(
TDRowLenT
*)(r))
#define kvRowNCols(r) (*(int16_t *)POINTER_SHIFT(r, sizeof(
u
int16_t)))
#define kvRowSetLen(r, len) kvRowLen(r) = (len)
#define kvRowSetNCols(r, n) kvRowNCols(r) = (n)
#define kvRowColIdx(r) (SColIdx *)POINTER_SHIFT(r, TD_KV_ROW_HEAD_SIZE)
...
...
@@ -362,6 +395,9 @@ typedef struct {
#define kvRowColIdxAt(r, i) (kvRowColIdx(r) + (i))
#define kvRowFree(r) tfree(r)
#define kvRowEnd(r) POINTER_SHIFT(r, kvRowLen(r))
#define kvRowTKey(r) (*(TKEY *)(kvRowValues(r)))
#define kvRowKey(r) tdGetKey(kvRowTKey(r))
#define kvRowDeleted(r) TKEY_IS_DELETED(kvRowTKey(r))
SKVRow
tdKVRowDup
(
SKVRow
row
);
int
tdSetKVRowDataOfCol
(
SKVRow
*
orow
,
int16_t
colId
,
int8_t
type
,
void
*
value
);
...
...
@@ -385,13 +421,44 @@ static FORCE_INLINE void *tdGetKVRowValOfCol(SKVRow row, int16_t colId) {
return
kvRowColVal
(
row
,
(
SColIdx
*
)
ret
);
}
static
FORCE_INLINE
void
*
tdGetKVRowIdxOfCol
(
SKVRow
row
,
int16_t
colId
)
{
return
taosbsearch
(
&
colId
,
kvRowColIdx
(
row
),
kvRowNCols
(
row
),
sizeof
(
SColIdx
),
comparTagId
,
TD_EQ
);
}
// offset here not include kvRow header length
static
FORCE_INLINE
int
tdAppendKvColVal
(
SKVRow
row
,
const
void
*
value
,
int16_t
colId
,
int8_t
type
,
int32_t
offset
)
{
ASSERT
(
value
!=
NULL
);
int32_t
toffset
=
offset
+
TD_KV_ROW_HEAD_SIZE
;
SColIdx
*
pColIdx
=
(
SColIdx
*
)
POINTER_SHIFT
(
row
,
toffset
);
char
*
ptr
=
(
char
*
)
POINTER_SHIFT
(
row
,
kvRowLen
(
row
));
pColIdx
->
colId
=
colId
;
pColIdx
->
offset
=
kvRowLen
(
row
);
// offset of pColIdx including the TD_KV_ROW_HEAD_SIZE
if
(
IS_VAR_DATA_TYPE
(
type
))
{
memcpy
(
ptr
,
value
,
varDataTLen
(
value
));
kvRowLen
(
row
)
+=
varDataTLen
(
value
);
}
else
{
if
(
offset
==
0
)
{
ASSERT
(
type
==
TSDB_DATA_TYPE_TIMESTAMP
);
TKEY
tvalue
=
tdGetTKEY
(
*
(
TSKEY
*
)
value
);
memcpy
(
ptr
,
(
void
*
)(
&
tvalue
),
TYPE_BYTES
[
type
]);
}
else
{
memcpy
(
ptr
,
value
,
TYPE_BYTES
[
type
]);
}
kvRowLen
(
row
)
+=
TYPE_BYTES
[
type
];
}
return
0
;
}
// ----------------- K-V data row builder
typedef
struct
{
int16_t
tCols
;
int16_t
nCols
;
SColIdx
*
pColIdx
;
int16_t
alloc
;
int16_t
size
;
uint16_t
alloc
;
uint16_t
size
;
void
*
buf
;
}
SKVRowBuilder
;
...
...
@@ -427,8 +494,146 @@ static FORCE_INLINE int tdAddColToKVRow(SKVRowBuilder *pBuilder, int16_t colId,
return
0
;
}
// ----------------- SMemRow appended with sequential data row structure
/*
* |---------|------------------------------------------------- len ---------------------------------->|
* |<-------- Head ------>|<--------- flen -------------->| |
* |---------+---------------------+---------------------------------+---------------------------------+
* | uint8_t | uint16_t | int16_t | | |
* |---------+----------+----------+---------------------------------+---------------------------------+
* | flag | len | sversion | First part | Second part |
* +---------+----------+----------+---------------------------------+---------------------------------+
*
* NOTE: timestamp in this row structure is TKEY instead of TSKEY
*/
// ----------------- SMemRow appended with extended K-V data row structure
/* |--------------------|------------------------------------------------ len ---------------------------------->|
* |<------------- Head ------------>|<--------- flen -------------->| |
* |--------------------+----------+--------------------------------------------+---------------------------------+
* | uint8_t | int16_t | uint16_t | int16_t | | |
* |---------+----------+----------+----------+---------------------------------+---------------------------------+
* | flag | sversion | len | ncols | cols index | data part |
* |---------+----------+----------+----------+---------------------------------+---------------------------------+
*/
typedef
void
*
SMemRow
;
#define TD_MEM_ROW_TYPE_SIZE sizeof(uint8_t)
#define TD_MEM_ROW_KV_VER_SIZE sizeof(int16_t)
#define TD_MEM_ROW_KV_TYPE_VER_SIZE (TD_MEM_ROW_TYPE_SIZE + TD_MEM_ROW_KV_VER_SIZE)
#define TD_MEM_ROW_DATA_HEAD_SIZE (TD_MEM_ROW_TYPE_SIZE + TD_DATA_ROW_HEAD_SIZE)
// #define TD_MEM_ROW_KV_HEAD_SIZE (TD_MEM_ROW_TYPE_SIZE + TD_MEM_ROW_KV_VER_SIZE + TD_KV_ROW_HEAD_SIZE)
#define SMEM_ROW_DATA 0U // SDataRow
#define SMEM_ROW_KV 1U // SKVRow
#define memRowType(r) (*(uint8_t *)(r))
#define isDataRow(r) (SMEM_ROW_DATA == memRowType(r))
#define isKvRow(r) (SMEM_ROW_KV == memRowType(r))
#define memRowDataBody(r) POINTER_SHIFT(r, TD_MEM_ROW_TYPE_SIZE) // section after flag
#define memRowKvBody(r) \
POINTER_SHIFT(r, TD_MEM_ROW_KV_TYPE_VER_SIZE) // section after flag + sversion as to reuse SKVRow
#define memRowDataLen(r) (*(TDRowLenT *)memRowDataBody(r)) // 0~65535
#define memRowKvLen(r) (*(TDRowLenT *)memRowKvBody(r)) // 0~65535
#define memRowDataTLen(r) \
((TDRowTLenT)(memRowDataLen(r) + TD_MEM_ROW_TYPE_SIZE)) // using uint32_t/int32_t to store the TLen
#define memRowKvTLen(r) ((TDRowTLenT)(memRowKvLen(r) + TD_MEM_ROW_KV_TYPE_VER_SIZE))
#define memRowLen(r) (isDataRow(r) ? memRowDataLen(r) : memRowKvLen(r))
#define memRowTLen(r) (isDataRow(r) ? memRowDataTLen(r) : memRowKvTLen(r)) // using uint32_t/int32_t to store the TLen
#define memRowDataVersion(r) dataRowVersion(memRowDataBody(r))
#define memRowKvVersion(r) (*(int16_t *)POINTER_SHIFT(r, TD_MEM_ROW_TYPE_SIZE))
#define memRowVersion(r) (isDataRow(r) ? memRowDataVersion(r) : memRowKvVersion(r)) // schema version
#define memRowSetKvVersion(r, v) (memRowKvVersion(r) = (v))
#define memRowTuple(r) (isDataRow(r) ? dataRowTuple(memRowDataBody(r)) : kvRowValues(memRowKvBody(r)))
#define memRowTKey(r) (isDataRow(r) ? dataRowTKey(memRowDataBody(r)) : kvRowTKey(memRowKvBody(r)))
#define memRowKey(r) (isDataRow(r) ? dataRowKey(memRowDataBody(r)) : kvRowKey(memRowKvBody(r)))
#define memRowSetTKey(r, k) \
do { \
if (isDataRow(r)) { \
dataRowTKey(memRowDataBody(r)) = (k); \
} else { \
kvRowTKey(memRowKvBody(r)) = (k); \
} \
} while (0)
#define memRowSetType(r, t) (memRowType(r) = (t))
#define memRowSetLen(r, l) (isDataRow(r) ? memRowDataLen(r) = (l) : memRowKvLen(r) = (l))
#define memRowSetVersion(r, v) (isDataRow(r) ? dataRowSetVersion(memRowDataBody(r), v) : memRowKvSetVersion(r, v))
#define memRowCpy(dst, r) memcpy((dst), (r), memRowTLen(r))
#define memRowMaxBytesFromSchema(s) (schemaTLen(s) + TD_MEM_ROW_DATA_HEAD_SIZE)
#define memRowDeleted(r) TKEY_IS_DELETED(memRowTKey(r))
SMemRow
tdMemRowDup
(
SMemRow
row
);
void
tdAppendMemRowToDataCol
(
SMemRow
row
,
STSchema
*
pSchema
,
SDataCols
*
pCols
);
// NOTE: offset here including the header size
static
FORCE_INLINE
void
*
tdGetKvRowDataOfCol
(
void
*
row
,
int32_t
offset
)
{
return
POINTER_SHIFT
(
row
,
offset
);
}
// NOTE: offset here including the header size
static
FORCE_INLINE
void
*
tdGetMemRowDataOfCol
(
void
*
row
,
int8_t
type
,
int32_t
offset
)
{
if
(
isDataRow
(
row
))
{
return
tdGetRowDataOfCol
(
row
,
type
,
offset
);
}
else
if
(
isKvRow
(
row
))
{
return
tdGetKvRowDataOfCol
(
row
,
offset
);
}
else
{
ASSERT
(
0
);
}
return
NULL
;
}
// ----------------- Raw payload structure for row:
/* |<------------ Head ------------->|<----------- body of column data tuple ------------------->|
* | |<----------------- flen ------------->|<--- value part --->|
* |SMemRowType| dataTLen | nCols | colId | colType | offset | ... | value |...|...|... |
* +-----------+----------+----------+--------------------------------------|--------------------|
* | uint8_t | uint32_t | uint16_t | int16_t | uint8_t | uint16_t | ... |.......|...|...|... |
* +-----------+----------+----------+--------------------------------------+--------------------|
* 1. offset in column data tuple starts from the value part in case of uint16_t overflow.
* 2. dataTLen: total length including the header and body.
*/
#define PAYLOAD_NCOLS_LEN sizeof(uint16_t)
#define PAYLOAD_NCOLS_OFFSET (sizeof(uint8_t) + sizeof(TDRowTLenT))
#define PAYLOAD_HEADER_LEN (PAYLOAD_NCOLS_OFFSET + PAYLOAD_NCOLS_LEN)
#define PAYLOAD_ID_LEN sizeof(int16_t)
#define PAYLOAD_ID_TYPE_LEN (sizeof(int16_t) + sizeof(uint8_t))
#define PAYLOAD_COL_HEAD_LEN (PAYLOAD_ID_TYPE_LEN + sizeof(uint16_t))
#define PAYLOAD_PRIMARY_COL_LEN (PAYLOAD_ID_TYPE_LEN + sizeof(TSKEY))
#define payloadBody(r) POINTER_SHIFT(r, PAYLOAD_HEADER_LEN)
#define payloadType(r) (*(uint8_t *)(r))
#define payloadSetType(r, t) (payloadType(r) = (t))
#define payloadTLen(r) (*(TDRowTLenT *)POINTER_SHIFT(r, TD_MEM_ROW_TYPE_SIZE)) // including total header
#define payloadSetTLen(r, l) (payloadTLen(r) = (l))
#define payloadNCols(r) (*(TDRowLenT *)POINTER_SHIFT(r, PAYLOAD_NCOLS_OFFSET))
#define payloadSetNCols(r, n) (payloadNCols(r) = (n))
#define payloadValuesOffset(r) \
(PAYLOAD_HEADER_LEN + payloadNCols(r) * PAYLOAD_COL_HEAD_LEN) // avoid using the macro in loop
#define payloadValues(r) POINTER_SHIFT(r, payloadValuesOffset(r)) // avoid using the macro in loop
#define payloadColId(c) (*(int16_t *)(c))
#define payloadColType(c) (*(uint8_t *)POINTER_SHIFT(c, PAYLOAD_ID_LEN))
#define payloadColOffset(c) (*(uint16_t *)POINTER_SHIFT(c, PAYLOAD_ID_TYPE_LEN))
#define payloadColValue(c) POINTER_SHIFT(c, payloadColOffset(c))
#define payloadColSetId(c, i) (payloadColId(c) = (i))
#define payloadColSetType(c, t) (payloadColType(c) = (t))
#define payloadColSetOffset(c, o) (payloadColOffset(c) = (o))
#define payloadTSKey(r) (*(TSKEY *)POINTER_SHIFT(r, payloadValuesOffset(r)))
#define payloadTKey(r) (*(TKEY *)POINTER_SHIFT(r, payloadValuesOffset(r)))
#define payloadKey(r) tdGetKey(payloadTKey(r))
static
FORCE_INLINE
char
*
payloadNextCol
(
char
*
pCol
)
{
return
(
char
*
)
POINTER_SHIFT
(
pCol
,
PAYLOAD_COL_HEAD_LEN
);
}
#ifdef __cplusplus
}
#endif
#endif // _TD_DATA_FORMAT_H_
#endif // _TD_DATA_FORMAT_H_
\ No newline at end of file
src/common/src/tdataformat.c
浏览文件 @
c1fa46d5
...
...
@@ -18,6 +18,21 @@
#include "tcoding.h"
#include "wchar.h"
const
uint8_t
BoolNull
=
TSDB_DATA_BOOL_NULL
;
const
uint8_t
TinyintNull
=
TSDB_DATA_TINYINT_NULL
;
const
uint16_t
SmallintNull
=
TSDB_DATA_SMALLINT_NULL
;
const
uint32_t
IntNull
=
TSDB_DATA_INT_NULL
;
const
uint64_t
BigintNull
=
TSDB_DATA_BIGINT_NULL
;
const
uint64_t
TimestampNull
=
TSDB_DATA_BIGINT_NULL
;
const
uint8_t
UTinyintNull
=
TSDB_DATA_UTINYINT_NULL
;
const
uint16_t
USmallintNull
=
TSDB_DATA_USMALLINT_NULL
;
const
uint32_t
UIntNull
=
TSDB_DATA_UINT_NULL
;
const
uint64_t
UBigintNull
=
TSDB_DATA_UBIGINT_NULL
;
const
uint32_t
FloatNull
=
TSDB_DATA_FLOAT_NULL
;
const
uint64_t
DoubleNull
=
TSDB_DATA_DOUBLE_NULL
;
const
SBinaryNullT
BinaryNull
=
{
1
,
TSDB_DATA_BINARY_NULL
};
const
SNCharNullT
NcharNull
=
{
4
,
TSDB_DATA_NCHAR_NULL
};
static
void
tdMergeTwoDataCols
(
SDataCols
*
target
,
SDataCols
*
src1
,
int
*
iter1
,
int
limit1
,
SDataCols
*
src2
,
int
*
iter2
,
int
limit2
,
int
tRows
);
...
...
@@ -198,6 +213,14 @@ SDataRow tdDataRowDup(SDataRow row) {
return
trow
;
}
SMemRow
tdMemRowDup
(
SMemRow
row
)
{
SMemRow
trow
=
malloc
(
memRowTLen
(
row
));
if
(
trow
==
NULL
)
return
NULL
;
memRowCpy
(
trow
,
row
);
return
trow
;
}
void
dataColInit
(
SDataCol
*
pDataCol
,
STColumn
*
pCol
,
void
**
pBuf
,
int
maxPoints
)
{
pDataCol
->
type
=
colType
(
pCol
);
pDataCol
->
colId
=
colColId
(
pCol
);
...
...
@@ -217,11 +240,22 @@ void dataColInit(SDataCol *pDataCol, STColumn *pCol, void **pBuf, int maxPoints)
*
pBuf
=
POINTER_SHIFT
(
*
pBuf
,
pDataCol
->
spaceSize
);
}
}
// value from timestamp should be TKEY here instead of TSKEY
void
dataColAppendVal
(
SDataCol
*
pCol
,
void
*
value
,
int
numOfRows
,
int
maxPoints
)
{
void
dataColAppendVal
(
SDataCol
*
pCol
,
const
void
*
value
,
int
numOfRows
,
int
maxPoints
)
{
ASSERT
(
pCol
!=
NULL
&&
value
!=
NULL
);
if
(
isAllRowsNull
(
pCol
))
{
if
(
isNull
(
value
,
pCol
->
type
))
{
// all null value yet, just return
return
;
}
if
(
numOfRows
>
0
)
{
// Find the first not null value, fill all previouse values as NULL
dataColSetNEleNull
(
pCol
,
numOfRows
,
maxPoints
);
}
}
if
(
IS_VAR_DATA_TYPE
(
pCol
->
type
))
{
// set offset
pCol
->
dataOff
[
numOfRows
]
=
pCol
->
len
;
...
...
@@ -243,7 +277,7 @@ bool isNEleNull(SDataCol *pCol, int nEle) {
return
true
;
}
void
dataColSetNullAt
(
SDataCol
*
pCol
,
int
index
)
{
FORCE_INLINE
void
dataColSetNullAt
(
SDataCol
*
pCol
,
int
index
)
{
if
(
IS_VAR_DATA_TYPE
(
pCol
->
type
))
{
pCol
->
dataOff
[
index
]
=
pCol
->
len
;
char
*
ptr
=
POINTER_SHIFT
(
pCol
->
pData
,
pCol
->
len
);
...
...
@@ -399,8 +433,7 @@ void tdResetDataCols(SDataCols *pCols) {
}
}
}
void
tdAppendDataRowToDataCol
(
SDataRow
row
,
STSchema
*
pSchema
,
SDataCols
*
pCols
)
{
static
void
tdAppendDataRowToDataCol
(
SDataRow
row
,
STSchema
*
pSchema
,
SDataCols
*
pCols
)
{
ASSERT
(
pCols
->
numOfRows
==
0
||
dataColsKeyLast
(
pCols
)
<
dataRowKey
(
row
));
int
rcol
=
0
;
...
...
@@ -419,7 +452,8 @@ void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols *pCols)
while
(
dcol
<
pCols
->
numOfCols
)
{
SDataCol
*
pDataCol
=
&
(
pCols
->
cols
[
dcol
]);
if
(
rcol
>=
schemaNCols
(
pSchema
))
{
dataColSetNullAt
(
pDataCol
,
pCols
->
numOfRows
);
// dataColSetNullAt(pDataCol, pCols->numOfRows);
dataColAppendVal
(
pDataCol
,
tdGetNullVal
(
pDataCol
->
type
),
pCols
->
numOfRows
,
pCols
->
maxPoints
);
dcol
++
;
continue
;
}
...
...
@@ -433,7 +467,8 @@ void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols *pCols)
}
else
if
(
pRowCol
->
colId
<
pDataCol
->
colId
)
{
rcol
++
;
}
else
{
dataColSetNullAt
(
pDataCol
,
pCols
->
numOfRows
);
// dataColSetNullAt(pDataCol, pCols->numOfRows);
dataColAppendVal
(
pDataCol
,
tdGetNullVal
(
pDataCol
->
type
),
pCols
->
numOfRows
,
pCols
->
maxPoints
);
dcol
++
;
}
}
...
...
@@ -441,6 +476,62 @@ void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols *pCols)
pCols
->
numOfRows
++
;
}
static
void
tdAppendKvRowToDataCol
(
SKVRow
row
,
STSchema
*
pSchema
,
SDataCols
*
pCols
)
{
ASSERT
(
pCols
->
numOfRows
==
0
||
dataColsKeyLast
(
pCols
)
<
kvRowKey
(
row
));
int
rcol
=
0
;
int
dcol
=
0
;
if
(
kvRowDeleted
(
row
))
{
for
(;
dcol
<
pCols
->
numOfCols
;
dcol
++
)
{
SDataCol
*
pDataCol
=
&
(
pCols
->
cols
[
dcol
]);
if
(
dcol
==
0
)
{
dataColAppendVal
(
pDataCol
,
kvRowValues
(
row
),
pCols
->
numOfRows
,
pCols
->
maxPoints
);
}
else
{
dataColSetNullAt
(
pDataCol
,
pCols
->
numOfRows
);
}
}
}
else
{
int
nRowCols
=
kvRowNCols
(
row
);
while
(
dcol
<
pCols
->
numOfCols
)
{
SDataCol
*
pDataCol
=
&
(
pCols
->
cols
[
dcol
]);
if
(
rcol
>=
nRowCols
||
rcol
>=
schemaNCols
(
pSchema
))
{
// dataColSetNullAt(pDataCol, pCols->numOfRows);
dataColAppendVal
(
pDataCol
,
tdGetNullVal
(
pDataCol
->
type
),
pCols
->
numOfRows
,
pCols
->
maxPoints
);
++
dcol
;
continue
;
}
SColIdx
*
colIdx
=
kvRowColIdxAt
(
row
,
rcol
);
if
(
colIdx
->
colId
==
pDataCol
->
colId
)
{
void
*
value
=
tdGetKvRowDataOfCol
(
row
,
colIdx
->
offset
);
dataColAppendVal
(
pDataCol
,
value
,
pCols
->
numOfRows
,
pCols
->
maxPoints
);
++
dcol
;
++
rcol
;
}
else
if
(
colIdx
->
colId
<
pDataCol
->
colId
)
{
++
rcol
;
}
else
{
// dataColSetNullAt(pDataCol, pCols->numOfRows);
dataColAppendVal
(
pDataCol
,
tdGetNullVal
(
pDataCol
->
type
),
pCols
->
numOfRows
,
pCols
->
maxPoints
);
++
dcol
;
}
}
}
pCols
->
numOfRows
++
;
}
void
tdAppendMemRowToDataCol
(
SMemRow
row
,
STSchema
*
pSchema
,
SDataCols
*
pCols
)
{
if
(
isDataRow
(
row
))
{
tdAppendDataRowToDataCol
(
memRowDataBody
(
row
),
pSchema
,
pCols
);
}
else
if
(
isKvRow
(
row
))
{
tdAppendKvRowToDataCol
(
memRowKvBody
(
row
),
pSchema
,
pCols
);
}
else
{
ASSERT
(
0
);
}
}
int
tdMergeDataCols
(
SDataCols
*
target
,
SDataCols
*
source
,
int
rowsToMerge
,
int
*
pOffset
)
{
ASSERT
(
rowsToMerge
>
0
&&
rowsToMerge
<=
source
->
numOfRows
);
ASSERT
(
target
->
numOfCols
==
source
->
numOfCols
);
...
...
@@ -563,7 +654,7 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) {
nrow
=
malloc
(
kvRowLen
(
row
)
+
sizeof
(
SColIdx
)
+
diff
);
if
(
nrow
==
NULL
)
return
-
1
;
kvRowSetLen
(
nrow
,
kvRowLen
(
row
)
+
(
int16_t
)
sizeof
(
SColIdx
)
+
diff
);
kvRowSetLen
(
nrow
,
kvRowLen
(
row
)
+
(
u
int16_t
)
sizeof
(
SColIdx
)
+
diff
);
kvRowSetNCols
(
nrow
,
kvRowNCols
(
row
)
+
1
);
if
(
ptr
==
NULL
)
{
...
...
@@ -605,8 +696,8 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) {
if
(
varDataTLen
(
value
)
==
varDataTLen
(
pOldVal
))
{
// just update the column value in place
memcpy
(
pOldVal
,
value
,
varDataTLen
(
value
));
}
else
{
// need to reallocate the memory
int16_t
diff
=
varDataTLen
(
value
)
-
varDataTLen
(
pOldVal
);
int16_t
nlen
=
kvRowLen
(
row
)
+
diff
;
u
int16_t
diff
=
varDataTLen
(
value
)
-
varDataTLen
(
pOldVal
);
u
int16_t
nlen
=
kvRowLen
(
row
)
+
diff
;
ASSERT
(
nlen
>
0
);
nrow
=
malloc
(
nlen
);
if
(
nrow
==
NULL
)
return
-
1
;
...
...
@@ -709,3 +800,39 @@ SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder) {
return
row
;
}
const
void
*
tdGetNullVal
(
int8_t
type
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
return
&
BoolNull
;
case
TSDB_DATA_TYPE_TINYINT
:
return
&
TinyintNull
;
case
TSDB_DATA_TYPE_SMALLINT
:
return
&
SmallintNull
;
case
TSDB_DATA_TYPE_INT
:
return
&
IntNull
;
case
TSDB_DATA_TYPE_BIGINT
:
return
&
BigintNull
;
case
TSDB_DATA_TYPE_FLOAT
:
return
&
FloatNull
;
case
TSDB_DATA_TYPE_DOUBLE
:
return
&
DoubleNull
;
case
TSDB_DATA_TYPE_BINARY
:
return
&
BinaryNull
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
return
&
TimestampNull
;
case
TSDB_DATA_TYPE_NCHAR
:
return
&
NcharNull
;
case
TSDB_DATA_TYPE_UTINYINT
:
return
&
UTinyintNull
;
case
TSDB_DATA_TYPE_USMALLINT
:
return
&
USmallintNull
;
case
TSDB_DATA_TYPE_UINT
:
return
&
UIntNull
;
case
TSDB_DATA_TYPE_UBIGINT
:
return
&
UBigintNull
;
default:
ASSERT
(
0
);
return
NULL
;
}
}
\ No newline at end of file
src/cq/src/cqMain.c
浏览文件 @
c1fa46d5
...
...
@@ -476,15 +476,17 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) {
cDebug
(
"vgId:%d, id:%d CQ:%s stream result is ready"
,
pContext
->
vgId
,
pObj
->
tid
,
pObj
->
sqlStr
);
int32_t
size
=
sizeof
(
SWalHead
)
+
sizeof
(
SSubmitMsg
)
+
sizeof
(
SSubmitBlk
)
+
TD_
DATA_ROW
_HEAD_SIZE
+
pObj
->
rowSize
;
int32_t
size
=
sizeof
(
SWalHead
)
+
sizeof
(
SSubmitMsg
)
+
sizeof
(
SSubmitBlk
)
+
TD_
MEM_ROW_DATA
_HEAD_SIZE
+
pObj
->
rowSize
;
char
*
buffer
=
calloc
(
size
,
1
);
SWalHead
*
pHead
=
(
SWalHead
*
)
buffer
;
SSubmitMsg
*
pMsg
=
(
SSubmitMsg
*
)
(
buffer
+
sizeof
(
SWalHead
));
SSubmitBlk
*
pBlk
=
(
SSubmitBlk
*
)
(
buffer
+
sizeof
(
SWalHead
)
+
sizeof
(
SSubmitMsg
));
SDataRow
trow
=
(
SDataRow
)
pBlk
->
data
;
tdInitDataRow
(
trow
,
pSchema
);
SMemRow
trow
=
(
SMemRow
)
pBlk
->
data
;
SDataRow
dataRow
=
(
SDataRow
)
memRowDataBody
(
trow
);
memRowSetType
(
trow
,
SMEM_ROW_DATA
);
tdInitDataRow
(
dataRow
,
pSchema
);
for
(
int32_t
i
=
0
;
i
<
pSchema
->
numOfCols
;
i
++
)
{
STColumn
*
c
=
pSchema
->
columns
+
i
;
...
...
@@ -500,9 +502,9 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) {
memcpy
((
char
*
)
val
+
sizeof
(
VarDataLenT
),
buf
,
len
);
varDataLen
(
val
)
=
len
;
}
tdAppendColVal
(
trow
,
val
,
c
->
type
,
c
->
bytes
,
c
->
offset
);
tdAppendColVal
(
dataRow
,
val
,
c
->
type
,
c
->
offset
);
}
pBlk
->
dataLen
=
htonl
(
dataRow
Len
(
trow
));
pBlk
->
dataLen
=
htonl
(
memRowDataT
Len
(
trow
));
pBlk
->
schemaLen
=
0
;
pBlk
->
uid
=
htobe64
(
pObj
->
uid
);
...
...
@@ -511,7 +513,7 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) {
pBlk
->
sversion
=
htonl
(
pSchema
->
version
);
pBlk
->
padding
=
0
;
pHead
->
len
=
sizeof
(
SSubmitMsg
)
+
sizeof
(
SSubmitBlk
)
+
dataRow
Len
(
trow
);
pHead
->
len
=
sizeof
(
SSubmitMsg
)
+
sizeof
(
SSubmitBlk
)
+
memRowDataT
Len
(
trow
);
pMsg
->
header
.
vgId
=
htonl
(
pContext
->
vgId
);
pMsg
->
header
.
contLen
=
htonl
(
pHead
->
len
);
...
...
src/inc/taosdef.h
浏览文件 @
c1fa46d5
...
...
@@ -180,7 +180,7 @@ do { \
// this is the length of its string representation, including the terminator zero
#define TSDB_ACCT_ID_LEN 11
#define TSDB_MAX_COLUMNS
1024
#define TSDB_MAX_COLUMNS
4096
#define TSDB_MIN_COLUMNS 2 //PRIMARY COLUMN(timestamp) + other columns
#define TSDB_NODE_NAME_LEN 64
...
...
@@ -199,7 +199,13 @@ do { \
#define TSDB_APPNAME_LEN TSDB_UNI_LEN
#define TSDB_MAX_BYTES_PER_ROW 16384
/**
* In some scenarios uint16_t (0~65535) is used to store the row len.
* - Firstly, we use 65531(65535 - 4), as the SDataRow/SKVRow contains 4 bits header.
* - Secondly, if all cols are VarDataT type except primary key, we need 4 bits to store the offset, thus
* the final value is 65531-(4096-1)*4 = 49151.
*/
#define TSDB_MAX_BYTES_PER_ROW 49151
#define TSDB_MAX_TAGS_LEN 16384
#define TSDB_MAX_TAGS 128
#define TSDB_MAX_TAG_CONDITIONS 1024
...
...
@@ -327,8 +333,9 @@ do { \
#define TSDB_MAX_JOIN_TABLE_NUM 10
#define TSDB_MAX_UNION_CLAUSE 5
#define TSDB_MAX_BINARY_LEN (TSDB_MAX_BYTES_PER_ROW-TSDB_KEYSIZE)
#define TSDB_MAX_NCHAR_LEN (TSDB_MAX_BYTES_PER_ROW-TSDB_KEYSIZE)
#define TSDB_MAX_FIELD_LEN 16384
#define TSDB_MAX_BINARY_LEN (TSDB_MAX_FIELD_LEN-TSDB_KEYSIZE) // keep 16384
#define TSDB_MAX_NCHAR_LEN (TSDB_MAX_FIELD_LEN-TSDB_KEYSIZE) // keep 16384
#define PRIMARYKEY_TIMESTAMP_COL_INDEX 0
#define TSDB_MAX_RPC_THREADS 5
...
...
src/inc/ttype.h
浏览文件 @
c1fa46d5
...
...
@@ -10,8 +10,10 @@ extern "C" {
#include "taosdef.h"
// ----------------- For variable data types such as TSDB_DATA_TYPE_BINARY and TSDB_DATA_TYPE_NCHAR
typedef
int32_t
VarDataOffsetT
;
typedef
int16_t
VarDataLenT
;
typedef
int32_t
VarDataOffsetT
;
typedef
int16_t
VarDataLenT
;
// maxVarDataLen: 32767
typedef
uint16_t
TDRowLenT
;
// not including overhead: 0 ~ 65535
typedef
uint32_t
TDRowTLenT
;
// total length, including overhead
typedef
struct
tstr
{
VarDataLenT
len
;
...
...
src/query/inc/qExtbuffer.h
浏览文件 @
c1fa46d5
...
...
@@ -77,13 +77,13 @@ typedef struct tFilePagesItem {
typedef
struct
SSchemaEx
{
struct
SSchema
field
;
int
16
_t
offset
;
int
32
_t
offset
;
}
SSchemaEx
;
typedef
struct
SColumnModel
{
int32_t
capacity
;
int32_t
numOfCols
;
int
16
_t
rowSize
;
int
32
_t
rowSize
;
SSchemaEx
*
pFields
;
}
SColumnModel
;
...
...
src/query/inc/qUtil.h
浏览文件 @
c1fa46d5
...
...
@@ -66,7 +66,8 @@ static FORCE_INLINE SResultRow *getResultRow(SResultRowInfo *pResultRowInfo, int
return
pResultRowInfo
->
pResult
[
slot
];
}
static
FORCE_INLINE
char
*
getPosInResultPage
(
SQueryAttr
*
pQueryAttr
,
tFilePage
*
page
,
int32_t
rowOffset
,
int16_t
offset
)
{
static
FORCE_INLINE
char
*
getPosInResultPage
(
SQueryAttr
*
pQueryAttr
,
tFilePage
*
page
,
int32_t
rowOffset
,
int32_t
offset
)
{
assert
(
rowOffset
>=
0
&&
pQueryAttr
!=
NULL
);
int32_t
numOfRows
=
(
int32_t
)
GET_ROW_PARAM_FOR_MULTIOUTPUT
(
pQueryAttr
,
pQueryAttr
->
topBotQuery
,
pQueryAttr
->
stableQuery
);
...
...
src/query/src/qAggMain.c
浏览文件 @
c1fa46d5
...
...
@@ -3982,7 +3982,7 @@ void blockInfo_func(SQLFunctionCtx* pCtx) {
int32_t
len
=
*
(
int32_t
*
)
pCtx
->
pInput
;
blockDistInfoFromBinary
((
char
*
)
pCtx
->
pInput
+
sizeof
(
int32_t
),
len
,
pDist
);
pDist
->
rowSize
=
(
int16_t
)
pCtx
->
param
[
0
].
i64
;
pDist
->
rowSize
=
(
uint16_t
)
pCtx
->
param
[
0
].
i64
;
memcpy
(
pCtx
->
pOutput
,
pCtx
->
pInput
,
sizeof
(
int32_t
)
+
len
);
...
...
@@ -4129,7 +4129,7 @@ void blockinfo_func_finalizer(SQLFunctionCtx* pCtx) {
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
STableBlockDist
*
pDist
=
(
STableBlockDist
*
)
GET_ROWCELL_INTERBUF
(
pResInfo
);
pDist
->
rowSize
=
(
int16_t
)
pCtx
->
param
[
0
].
i64
;
pDist
->
rowSize
=
(
u
int16_t
)
pCtx
->
param
[
0
].
i64
;
generateBlockDistResult
(
pDist
,
pCtx
->
pOutput
);
// cannot set the numOfIteratedElems again since it is set during previous iteration
...
...
src/query/src/qExecutor.c
浏览文件 @
c1fa46d5
...
...
@@ -3583,7 +3583,7 @@ void setResultRowOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pRe
// Note: pResult->pos[i]->num == 0, there is only fixed number of results for each group
tFilePage
*
bufPage
=
getResBufPage
(
pRuntimeEnv
->
pResultBuf
,
pResult
->
pageId
);
int
16
_t
offset
=
0
;
int
32
_t
offset
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
pCtx
[
i
].
resultInfo
=
getResultCell
(
pResult
,
i
,
rowCellInfoOffset
);
...
...
@@ -3897,7 +3897,7 @@ static int32_t doCopyToSDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SGroupResInfo*
tFilePage
*
page
=
getResBufPage
(
pRuntimeEnv
->
pResultBuf
,
pRow
->
pageId
);
int
16
_t
offset
=
0
;
int
32
_t
offset
=
0
;
for
(
int32_t
j
=
0
;
j
<
pBlock
->
info
.
numOfCols
;
++
j
)
{
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pBlock
->
pDataBlock
,
j
);
int32_t
bytes
=
pColInfoData
->
info
.
bytes
;
...
...
src/tsdb/inc/tsdbMemTable.h
浏览文件 @
c1fa46d5
...
...
@@ -71,27 +71,27 @@ int tsdbLoadDataFromCache(STable* pTable, SSkipListIterator* pIter, TSKEY maxK
TKEY
*
filterKeys
,
int
nFilterKeys
,
bool
keepDup
,
SMergeInfo
*
pMergeInfo
);
void
*
tsdbCommitData
(
STsdbRepo
*
pRepo
);
static
FORCE_INLINE
S
Data
Row
tsdbNextIterRow
(
SSkipListIterator
*
pIter
)
{
static
FORCE_INLINE
S
Mem
Row
tsdbNextIterRow
(
SSkipListIterator
*
pIter
)
{
if
(
pIter
==
NULL
)
return
NULL
;
SSkipListNode
*
node
=
tSkipListIterGet
(
pIter
);
if
(
node
==
NULL
)
return
NULL
;
return
(
S
Data
Row
)
SL_GET_NODE_DATA
(
node
);
return
(
S
Mem
Row
)
SL_GET_NODE_DATA
(
node
);
}
static
FORCE_INLINE
TSKEY
tsdbNextIterKey
(
SSkipListIterator
*
pIter
)
{
S
Data
Row
row
=
tsdbNextIterRow
(
pIter
);
S
Mem
Row
row
=
tsdbNextIterRow
(
pIter
);
if
(
row
==
NULL
)
return
TSDB_DATA_TIMESTAMP_NULL
;
return
data
RowKey
(
row
);
return
mem
RowKey
(
row
);
}
static
FORCE_INLINE
TKEY
tsdbNextIterTKey
(
SSkipListIterator
*
pIter
)
{
S
Data
Row
row
=
tsdbNextIterRow
(
pIter
);
S
Mem
Row
row
=
tsdbNextIterRow
(
pIter
);
if
(
row
==
NULL
)
return
TKEY_NULL
;
return
data
RowTKey
(
row
);
return
mem
RowTKey
(
row
);
}
#endif
/* _TD_TSDB_MEMTABLE_H_ */
\ No newline at end of file
src/tsdb/inc/tsdbMeta.h
浏览文件 @
c1fa46d5
...
...
@@ -32,7 +32,7 @@ typedef struct STable {
void
*
eventHandler
;
// TODO
void
*
streamHandler
;
// TODO
TSKEY
lastKey
;
S
DataRow
lastRow
;
S
MemRow
lastRow
;
char
*
sql
;
void
*
cqhandle
;
SRWLatch
latch
;
// TODO: implementa latch functions
...
...
@@ -148,7 +148,7 @@ static FORCE_INLINE STSchema *tsdbGetTableTagSchema(STable *pTable) {
}
static
FORCE_INLINE
TSKEY
tsdbGetTableLastKeyImpl
(
STable
*
pTable
)
{
ASSERT
(
pTable
->
lastRow
==
NULL
||
pTable
->
lastKey
==
dataRowKey
(
pTable
->
lastRow
));
ASSERT
(
(
pTable
->
lastRow
==
NULL
)
||
(
pTable
->
lastKey
==
memRowKey
(
pTable
->
lastRow
)
));
return
pTable
->
lastKey
;
}
...
...
src/tsdb/src/tsdbCommit.c
浏览文件 @
c1fa46d5
...
...
@@ -920,7 +920,8 @@ int tsdbWriteBlockImpl(STsdbRepo *pRepo, STable *pTable, SDFile *pDFile, SDataCo
SDataCol
*
pDataCol
=
pDataCols
->
cols
+
ncol
;
SBlockCol
*
pBlockCol
=
pBlockData
->
cols
+
nColsNotAllNull
;
if
(
isNEleNull
(
pDataCol
,
rowsToWrite
))
{
// all data to commit are NULL, just ignore it
// if (isNEleNull(pDataCol, rowsToWrite)) { // all data to commit are NULL, just ignore it
if
(
isAllRowsNull
(
pDataCol
))
{
// all data to commit are NULL, just ignore it
continue
;
}
...
...
@@ -1264,12 +1265,12 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
while
(
true
)
{
key1
=
(
*
iter
>=
pDataCols
->
numOfRows
)
?
INT64_MAX
:
dataColsKeyAt
(
pDataCols
,
*
iter
);
bool
isRowDel
=
false
;
S
Data
Row
row
=
tsdbNextIterRow
(
pCommitIter
->
pIter
);
if
(
row
==
NULL
||
data
RowKey
(
row
)
>
maxKey
)
{
S
Mem
Row
row
=
tsdbNextIterRow
(
pCommitIter
->
pIter
);
if
(
row
==
NULL
||
mem
RowKey
(
row
)
>
maxKey
)
{
key2
=
INT64_MAX
;
}
else
{
key2
=
data
RowKey
(
row
);
isRowDel
=
data
RowDeleted
(
row
);
key2
=
mem
RowKey
(
row
);
isRowDel
=
mem
RowDeleted
(
row
);
}
if
(
key1
==
INT64_MAX
&&
key2
==
INT64_MAX
)
break
;
...
...
@@ -1284,24 +1285,24 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
(
*
iter
)
++
;
}
else
if
(
key1
>
key2
)
{
if
(
!
isRowDel
)
{
if
(
pSchema
==
NULL
||
schemaVersion
(
pSchema
)
!=
data
RowVersion
(
row
))
{
pSchema
=
tsdbGetTableSchemaImpl
(
pCommitIter
->
pTable
,
false
,
false
,
data
RowVersion
(
row
));
if
(
pSchema
==
NULL
||
schemaVersion
(
pSchema
)
!=
mem
RowVersion
(
row
))
{
pSchema
=
tsdbGetTableSchemaImpl
(
pCommitIter
->
pTable
,
false
,
false
,
mem
RowVersion
(
row
));
ASSERT
(
pSchema
!=
NULL
);
}
tdAppend
Data
RowToDataCol
(
row
,
pSchema
,
pTarget
);
tdAppend
Mem
RowToDataCol
(
row
,
pSchema
,
pTarget
);
}
tSkipListIterNext
(
pCommitIter
->
pIter
);
}
else
{
if
(
update
)
{
if
(
!
isRowDel
)
{
if
(
pSchema
==
NULL
||
schemaVersion
(
pSchema
)
!=
data
RowVersion
(
row
))
{
pSchema
=
tsdbGetTableSchemaImpl
(
pCommitIter
->
pTable
,
false
,
false
,
data
RowVersion
(
row
));
if
(
pSchema
==
NULL
||
schemaVersion
(
pSchema
)
!=
mem
RowVersion
(
row
))
{
pSchema
=
tsdbGetTableSchemaImpl
(
pCommitIter
->
pTable
,
false
,
false
,
mem
RowVersion
(
row
));
ASSERT
(
pSchema
!=
NULL
);
}
tdAppend
Data
RowToDataCol
(
row
,
pSchema
,
pTarget
);
tdAppend
Mem
RowToDataCol
(
row
,
pSchema
,
pTarget
);
}
}
else
{
ASSERT
(
!
isRowDel
);
...
...
src/tsdb/src/tsdbMain.c
浏览文件 @
c1fa46d5
...
...
@@ -641,7 +641,7 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea
int
numColumns
;
int32_t
blockIdx
;
SDataStatis
*
pBlockStatis
=
NULL
;
S
DataRow
row
=
NULL
;
S
MemRow
row
=
NULL
;
// restore last column data with last schema
int
err
=
0
;
...
...
@@ -657,13 +657,15 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea
}
}
row
=
taosTMalloc
(
data
RowMaxBytesFromSchema
(
pSchema
));
row
=
taosTMalloc
(
mem
RowMaxBytesFromSchema
(
pSchema
));
if
(
row
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
err
=
-
1
;
goto
out
;
}
tdInitDataRow
(
row
,
pSchema
);
memRowSetType
(
row
,
SMEM_ROW_DATA
);
tdInitDataRow
(
memRowDataBody
(
row
),
pSchema
);
// first load block index info
if
(
tsdbLoadBlockInfo
(
pReadh
,
NULL
)
<
0
)
{
...
...
@@ -720,9 +722,9 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea
// OK,let's load row from backward to get not-null column
for
(
int32_t
rowId
=
pBlock
->
numOfRows
-
1
;
rowId
>=
0
;
rowId
--
)
{
SDataCol
*
pDataCol
=
pReadh
->
pDCols
[
0
]
->
cols
+
i
;
tdAppendColVal
(
row
,
tdGetColDataOfRow
(
pDataCol
,
rowId
),
pCol
->
type
,
pCol
->
bytes
,
pCol
->
offset
);
tdAppendColVal
(
memRowDataBody
(
row
),
tdGetColDataOfRow
(
pDataCol
,
rowId
),
pCol
->
type
,
pCol
->
offset
);
//SDataCol *pDataCol = readh.pDCols[0]->cols + j;
void
*
value
=
tdGetRowDataOfCol
(
row
,
(
int8_t
)
pCol
->
type
,
TD_DATA_ROW_HEAD_SIZE
+
pCol
->
offset
);
void
*
value
=
tdGetRowDataOfCol
(
memRowDataBody
(
row
)
,
(
int8_t
)
pCol
->
type
,
TD_DATA_ROW_HEAD_SIZE
+
pCol
->
offset
);
if
(
isNull
(
value
,
pCol
->
type
))
{
continue
;
}
...
...
@@ -742,8 +744,8 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea
// save row ts(in column 0)
pDataCol
=
pReadh
->
pDCols
[
0
]
->
cols
+
0
;
pCol
=
schemaColAt
(
pSchema
,
0
);
tdAppendColVal
(
row
,
tdGetColDataOfRow
(
pDataCol
,
rowId
),
pCol
->
type
,
pCol
->
bytes
,
pCol
->
offset
);
pLastCol
->
ts
=
data
RowKey
(
row
);
tdAppendColVal
(
memRowDataBody
(
row
),
tdGetColDataOfRow
(
pDataCol
,
rowId
),
pCol
->
type
,
pCol
->
offset
);
pLastCol
->
ts
=
mem
RowKey
(
row
);
pTable
->
restoreColumnNum
+=
1
;
...
...
@@ -779,18 +781,18 @@ static int tsdbRestoreLastRow(STsdbRepo *pRepo, STable *pTable, SReadH* pReadh,
// Get the data in row
STSchema
*
pSchema
=
tsdbGetTableSchema
(
pTable
);
pTable
->
lastRow
=
taosTMalloc
(
data
RowMaxBytesFromSchema
(
pSchema
));
pTable
->
lastRow
=
taosTMalloc
(
mem
RowMaxBytesFromSchema
(
pSchema
));
if
(
pTable
->
lastRow
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
-
1
;
}
tdInitDataRow
(
pTable
->
lastRow
,
pSchema
);
memRowSetType
(
pTable
->
lastRow
,
SMEM_ROW_DATA
);
tdInitDataRow
(
memRowDataBody
(
pTable
->
lastRow
)
,
pSchema
);
for
(
int
icol
=
0
;
icol
<
schemaNCols
(
pSchema
);
icol
++
)
{
STColumn
*
pCol
=
schemaColAt
(
pSchema
,
icol
);
SDataCol
*
pDataCol
=
pReadh
->
pDCols
[
0
]
->
cols
+
icol
;
tdAppendColVal
(
pTable
->
lastRow
,
tdGetColDataOfRow
(
pDataCol
,
pBlock
->
numOfRows
-
1
),
pCol
->
type
,
pCol
->
bytes
,
pCol
->
offset
);
tdAppendColVal
(
memRowDataBody
(
pTable
->
lastRow
),
tdGetColDataOfRow
(
pDataCol
,
pBlock
->
numOfRows
-
1
),
pCol
->
type
,
pCol
->
offset
);
}
return
0
;
...
...
src/tsdb/src/tsdbMemTable.c
浏览文件 @
c1fa46d5
...
...
@@ -21,7 +21,7 @@
typedef
struct
{
int32_t
totalLen
;
int32_t
len
;
S
DataRow
row
;
S
MemRow
row
;
}
SSubmitBlkIter
;
typedef
struct
{
...
...
@@ -36,20 +36,19 @@ static STableData *tsdbNewTableData(STsdbCfg *pCfg, STable *pTable);
static
void
tsdbFreeTableData
(
STableData
*
pTableData
);
static
char
*
tsdbGetTsTupleKey
(
const
void
*
data
);
static
int
tsdbAdjustMemMaxTables
(
SMemTable
*
pMemTable
,
int
maxTables
);
static
int
tsdbAppendTableRowToCols
(
STable
*
pTable
,
SDataCols
*
pCols
,
STSchema
**
ppSchema
,
SData
Row
row
);
static
int
tsdbAppendTableRowToCols
(
STable
*
pTable
,
SDataCols
*
pCols
,
STSchema
**
ppSchema
,
SMem
Row
row
);
static
int
tsdbInitSubmitBlkIter
(
SSubmitBlk
*
pBlock
,
SSubmitBlkIter
*
pIter
);
static
S
DataRow
tsdbGetSubmitBlkNext
(
SSubmitBlkIter
*
pIter
);
static
S
MemRow
tsdbGetSubmitBlkNext
(
SSubmitBlkIter
*
pIter
);
static
int
tsdbScanAndConvertSubmitMsg
(
STsdbRepo
*
pRepo
,
SSubmitMsg
*
pMsg
);
static
int
tsdbInsertDataToTable
(
STsdbRepo
*
pRepo
,
SSubmitBlk
*
pBlock
,
int32_t
*
affectedrows
);
static
int
tsdbCopyRowToMem
(
STsdbRepo
*
pRepo
,
SData
Row
row
,
STable
*
pTable
,
void
**
ppRow
);
static
int
tsdbCopyRowToMem
(
STsdbRepo
*
pRepo
,
SMem
Row
row
,
STable
*
pTable
,
void
**
ppRow
);
static
int
tsdbInitSubmitMsgIter
(
SSubmitMsg
*
pMsg
,
SSubmitMsgIter
*
pIter
);
static
int
tsdbGetSubmitMsgNext
(
SSubmitMsgIter
*
pIter
,
SSubmitBlk
**
pPBlock
);
static
int
tsdbCheckTableSchema
(
STsdbRepo
*
pRepo
,
SSubmitBlk
*
pBlock
,
STable
*
pTable
);
static
int
tsdbInsertDataToTableImpl
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
void
**
rows
,
int
rowCounter
);
static
void
tsdbFreeRows
(
STsdbRepo
*
pRepo
,
void
**
rows
,
int
rowCounter
);
static
int
tsdbUpdateTableLatestInfo
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
SDataRow
row
);
static
FORCE_INLINE
int
tsdbCheckRowRange
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
SDataRow
row
,
TSKEY
minKey
,
TSKEY
maxKey
,
static
int
tsdbUpdateTableLatestInfo
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
SMemRow
row
);
static
FORCE_INLINE
int
tsdbCheckRowRange
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
SMemRow
row
,
TSKEY
minKey
,
TSKEY
maxKey
,
TSKEY
now
);
int32_t
tsdbInsertData
(
STsdbRepo
*
repo
,
SSubmitMsg
*
pMsg
,
SShellSubmitRspMsg
*
pRsp
)
{
...
...
@@ -354,7 +353,7 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey
TSKEY
fKey
=
0
;
bool
isRowDel
=
false
;
int
filterIter
=
0
;
S
DataRow
row
=
NULL
;
S
MemRow
row
=
NULL
;
SMergeInfo
mInfo
;
if
(
pMergeInfo
==
NULL
)
pMergeInfo
=
&
mInfo
;
...
...
@@ -365,12 +364,12 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey
if
(
pCols
)
tdResetDataCols
(
pCols
);
row
=
tsdbNextIterRow
(
pIter
);
if
(
row
==
NULL
||
data
RowKey
(
row
)
>
maxKey
)
{
if
(
row
==
NULL
||
mem
RowKey
(
row
)
>
maxKey
)
{
rowKey
=
INT64_MAX
;
isRowDel
=
false
;
}
else
{
rowKey
=
data
RowKey
(
row
);
isRowDel
=
data
RowDeleted
(
row
);
rowKey
=
mem
RowKey
(
row
);
isRowDel
=
mem
RowDeleted
(
row
);
}
if
(
filterIter
>=
nFilterKeys
)
{
...
...
@@ -407,12 +406,12 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey
tSkipListIterNext
(
pIter
);
row
=
tsdbNextIterRow
(
pIter
);
if
(
row
==
NULL
||
data
RowKey
(
row
)
>
maxKey
)
{
if
(
row
==
NULL
||
mem
RowKey
(
row
)
>
maxKey
)
{
rowKey
=
INT64_MAX
;
isRowDel
=
false
;
}
else
{
rowKey
=
data
RowKey
(
row
);
isRowDel
=
data
RowDeleted
(
row
);
rowKey
=
mem
RowKey
(
row
);
isRowDel
=
mem
RowDeleted
(
row
);
}
}
else
{
if
(
isRowDel
)
{
...
...
@@ -437,12 +436,12 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey
tSkipListIterNext
(
pIter
);
row
=
tsdbNextIterRow
(
pIter
);
if
(
row
==
NULL
||
data
RowKey
(
row
)
>
maxKey
)
{
if
(
row
==
NULL
||
mem
RowKey
(
row
)
>
maxKey
)
{
rowKey
=
INT64_MAX
;
isRowDel
=
false
;
}
else
{
rowKey
=
data
RowKey
(
row
);
isRowDel
=
data
RowDeleted
(
row
);
rowKey
=
mem
RowKey
(
row
);
isRowDel
=
mem
RowDeleted
(
row
);
}
filterIter
++
;
...
...
@@ -548,7 +547,7 @@ static void tsdbFreeTableData(STableData *pTableData) {
}
}
static
char
*
tsdbGetTsTupleKey
(
const
void
*
data
)
{
return
dataRowTuple
((
SData
Row
)
data
);
}
static
char
*
tsdbGetTsTupleKey
(
const
void
*
data
)
{
return
memRowTuple
((
SMem
Row
)
data
);
}
static
int
tsdbAdjustMemMaxTables
(
SMemTable
*
pMemTable
,
int
maxTables
)
{
ASSERT
(
pMemTable
->
maxTables
<
maxTables
);
...
...
@@ -572,17 +571,17 @@ static int tsdbAdjustMemMaxTables(SMemTable *pMemTable, int maxTables) {
return
0
;
}
static
int
tsdbAppendTableRowToCols
(
STable
*
pTable
,
SDataCols
*
pCols
,
STSchema
**
ppSchema
,
S
Data
Row
row
)
{
static
int
tsdbAppendTableRowToCols
(
STable
*
pTable
,
SDataCols
*
pCols
,
STSchema
**
ppSchema
,
S
Mem
Row
row
)
{
if
(
pCols
)
{
if
(
*
ppSchema
==
NULL
||
schemaVersion
(
*
ppSchema
)
!=
data
RowVersion
(
row
))
{
*
ppSchema
=
tsdbGetTableSchemaImpl
(
pTable
,
false
,
false
,
data
RowVersion
(
row
));
if
(
*
ppSchema
==
NULL
||
schemaVersion
(
*
ppSchema
)
!=
mem
RowVersion
(
row
))
{
*
ppSchema
=
tsdbGetTableSchemaImpl
(
pTable
,
false
,
false
,
mem
RowVersion
(
row
));
if
(
*
ppSchema
==
NULL
)
{
ASSERT
(
false
);
return
-
1
;
}
}
tdAppend
Data
RowToDataCol
(
row
,
*
ppSchema
,
pCols
);
tdAppend
Mem
RowToDataCol
(
row
,
*
ppSchema
,
pCols
);
}
return
0
;
...
...
@@ -592,31 +591,32 @@ static int tsdbInitSubmitBlkIter(SSubmitBlk *pBlock, SSubmitBlkIter *pIter) {
if
(
pBlock
->
dataLen
<=
0
)
return
-
1
;
pIter
->
totalLen
=
pBlock
->
dataLen
;
pIter
->
len
=
0
;
pIter
->
row
=
(
S
DataRow
)(
pBlock
->
data
+
pBlock
->
schemaLen
);
pIter
->
row
=
(
S
MemRow
)(
pBlock
->
data
+
pBlock
->
schemaLen
);
return
0
;
}
static
S
Data
Row
tsdbGetSubmitBlkNext
(
SSubmitBlkIter
*
pIter
)
{
S
DataRow
row
=
pIter
->
row
;
static
S
Mem
Row
tsdbGetSubmitBlkNext
(
SSubmitBlkIter
*
pIter
)
{
S
MemRow
row
=
pIter
->
row
;
// firstly, get current row
if
(
row
==
NULL
)
return
NULL
;
pIter
->
len
+=
dataRow
Len
(
row
);
if
(
pIter
->
len
>=
pIter
->
totalLen
)
{
pIter
->
len
+=
memRowT
Len
(
row
);
if
(
pIter
->
len
>=
pIter
->
totalLen
)
{
// reach the end
pIter
->
row
=
NULL
;
}
else
{
pIter
->
row
=
(
char
*
)
row
+
dataRowLen
(
row
);
pIter
->
row
=
(
char
*
)
row
+
memRowTLen
(
row
);
// secondly, move to next row
}
return
row
;
}
static
FORCE_INLINE
int
tsdbCheckRowRange
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
S
Data
Row
row
,
TSKEY
minKey
,
TSKEY
maxKey
,
static
FORCE_INLINE
int
tsdbCheckRowRange
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
S
Mem
Row
row
,
TSKEY
minKey
,
TSKEY
maxKey
,
TSKEY
now
)
{
if
(
dataRowKey
(
row
)
<
minKey
||
dataRowKey
(
row
)
>
maxKey
)
{
TSKEY
rowKey
=
memRowKey
(
row
);
if
(
rowKey
<
minKey
||
rowKey
>
maxKey
)
{
tsdbError
(
"vgId:%d table %s tid %d uid %"
PRIu64
" timestamp is out of range! now %"
PRId64
" minKey %"
PRId64
" maxKey %"
PRId64
" row key %"
PRId64
,
REPO_ID
(
pRepo
),
TABLE_CHAR_NAME
(
pTable
),
TABLE_TID
(
pTable
),
TABLE_UID
(
pTable
),
now
,
minKey
,
maxKey
,
dataRowKey
(
row
)
);
rowKey
);
terrno
=
TSDB_CODE_TDB_TIMESTAMP_OUT_OF_RANGE
;
return
-
1
;
}
...
...
@@ -630,7 +630,7 @@ static int tsdbScanAndConvertSubmitMsg(STsdbRepo *pRepo, SSubmitMsg *pMsg) {
SSubmitMsgIter
msgIter
=
{
0
};
SSubmitBlk
*
pBlock
=
NULL
;
SSubmitBlkIter
blkIter
=
{
0
};
S
DataRow
row
=
NULL
;
S
MemRow
row
=
NULL
;
TSKEY
now
=
taosGetTimestamp
(
pRepo
->
config
.
precision
);
TSKEY
minKey
=
now
-
tsTickPerDay
[
pRepo
->
config
.
precision
]
*
pRepo
->
config
.
keep
;
TSKEY
maxKey
=
now
+
tsTickPerDay
[
pRepo
->
config
.
precision
]
*
pRepo
->
config
.
daysPerFile
;
...
...
@@ -698,7 +698,7 @@ static int tsdbInsertDataToTable(STsdbRepo *pRepo, SSubmitBlk *pBlock, int32_t *
int64_t
points
=
0
;
STable
*
pTable
=
NULL
;
SSubmitBlkIter
blkIter
=
{
0
};
S
DataRow
row
=
NULL
;
S
MemRow
row
=
NULL
;
void
*
rows
[
TSDB_MAX_INSERT_BATCH
]
=
{
0
};
int
rowCounter
=
0
;
...
...
@@ -744,10 +744,10 @@ _err:
return
-
1
;
}
static
int
tsdbCopyRowToMem
(
STsdbRepo
*
pRepo
,
S
Data
Row
row
,
STable
*
pTable
,
void
**
ppRow
)
{
static
int
tsdbCopyRowToMem
(
STsdbRepo
*
pRepo
,
S
Mem
Row
row
,
STable
*
pTable
,
void
**
ppRow
)
{
STsdbCfg
*
pCfg
=
&
pRepo
->
config
;
TKEY
tkey
=
data
RowTKey
(
row
);
TSKEY
key
=
data
RowKey
(
row
);
TKEY
tkey
=
mem
RowTKey
(
row
);
TSKEY
key
=
mem
RowKey
(
row
);
bool
isRowDelete
=
TKEY_IS_DELETED
(
tkey
);
if
(
isRowDelete
)
{
...
...
@@ -765,15 +765,15 @@ static int tsdbCopyRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable, void
}
}
void
*
pRow
=
tsdbAllocBytes
(
pRepo
,
dataRow
Len
(
row
));
void
*
pRow
=
tsdbAllocBytes
(
pRepo
,
memRowT
Len
(
row
));
if
(
pRow
==
NULL
)
{
tsdbError
(
"vgId:%d failed to insert row with key %"
PRId64
" to table %s while allocate %
d
bytes since %s"
,
REPO_ID
(
pRepo
),
key
,
TABLE_CHAR_NAME
(
pTable
),
dataRow
Len
(
row
),
tstrerror
(
terrno
));
tsdbError
(
"vgId:%d failed to insert row with key %"
PRId64
" to table %s while allocate %
"
PRIu32
"
bytes since %s"
,
REPO_ID
(
pRepo
),
key
,
TABLE_CHAR_NAME
(
pTable
),
memRowT
Len
(
row
),
tstrerror
(
terrno
));
return
-
1
;
}
data
RowCpy
(
pRow
,
row
);
ppRow
[
0
]
=
pRow
;
mem
RowCpy
(
pRow
,
row
);
ppRow
[
0
]
=
pRow
;
// save the memory address of data rows
tsdbTrace
(
"vgId:%d a row is %s table %s tid %d uid %"
PRIu64
" key %"
PRIu64
,
REPO_ID
(
pRepo
),
isRowDelete
?
"deleted from"
:
"updated in"
,
TABLE_CHAR_NAME
(
pTable
),
TABLE_TID
(
pTable
),
TABLE_UID
(
pTable
),
...
...
@@ -932,13 +932,15 @@ static int tsdbInsertDataToTableImpl(STsdbRepo *pRepo, STable *pTable, void **ro
int64_t
osize
=
SL_SIZE
(
pTableData
->
pData
);
tSkipListPutBatch
(
pTableData
->
pData
,
rows
,
rowCounter
);
int64_t
dsize
=
SL_SIZE
(
pTableData
->
pData
)
-
osize
;
TSKEY
keyFirstRow
=
memRowKey
(
rows
[
0
]);
TSKEY
keyLastRow
=
memRowKey
(
rows
[
rowCounter
-
1
]);
if
(
pMemTable
->
keyFirst
>
dataRowKey
(
rows
[
0
]))
pMemTable
->
keyFirst
=
dataRowKey
(
rows
[
0
])
;
if
(
pMemTable
->
keyLast
<
dataRowKey
(
rows
[
rowCounter
-
1
]))
pMemTable
->
keyLast
=
dataRowKey
(
rows
[
rowCounter
-
1
])
;
if
(
pMemTable
->
keyFirst
>
keyFirstRow
)
pMemTable
->
keyFirst
=
keyFirstRow
;
if
(
pMemTable
->
keyLast
<
keyLastRow
)
pMemTable
->
keyLast
=
keyLastRow
;
pMemTable
->
numOfRows
+=
dsize
;
if
(
pTableData
->
keyFirst
>
dataRowKey
(
rows
[
0
]))
pTableData
->
keyFirst
=
dataRowKey
(
rows
[
0
])
;
if
(
pTableData
->
keyLast
<
dataRowKey
(
rows
[
rowCounter
-
1
]))
pTableData
->
keyLast
=
dataRowKey
(
rows
[
rowCounter
-
1
])
;
if
(
pTableData
->
keyFirst
>
keyFirstRow
)
pTableData
->
keyFirst
=
keyFirstRow
;
if
(
pTableData
->
keyLast
<
keyLastRow
)
pTableData
->
keyLast
=
keyLastRow
;
pTableData
->
numOfRows
+=
dsize
;
// update table latest info
...
...
@@ -954,8 +956,8 @@ static void tsdbFreeRows(STsdbRepo *pRepo, void **rows, int rowCounter) {
STsdbBufPool
*
pBufPool
=
pRepo
->
pPool
;
for
(
int
i
=
rowCounter
-
1
;
i
>=
0
;
--
i
)
{
S
DataRow
row
=
(
SData
Row
)
rows
[
i
];
int
bytes
=
(
int
)
dataRow
Len
(
row
);
S
MemRow
row
=
(
SMem
Row
)
rows
[
i
];
int
bytes
=
(
int
)
memRowT
Len
(
row
);
if
(
pRepo
->
mem
->
extraBuffList
==
NULL
)
{
STsdbBufBlock
*
pBufBlock
=
tsdbGetCurrBufBlock
(
pRepo
);
...
...
@@ -988,21 +990,23 @@ static void tsdbFreeRows(STsdbRepo *pRepo, void **rows, int rowCounter) {
}
}
static
void
updateTableLatestColumn
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
SDataRow
row
)
{
tsdbDebug
(
"vgId:%d updateTableLatestColumn, %s row version:%d"
,
REPO_ID
(
pRepo
),
pTable
->
name
->
data
,
dataRowVersion
(
row
));
static
void
updateTableLatestColumn
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
SMemRow
row
)
{
tsdbDebug
(
"vgId:%d updateTableLatestColumn, %s row version:%d"
,
REPO_ID
(
pRepo
),
pTable
->
name
->
data
,
memRowVersion
(
row
));
STSchema
*
pSchema
=
tsdbGetTableLatestSchema
(
pTable
);
if
(
tsdbUpdateLastColSchema
(
pTable
,
pSchema
)
<
0
)
{
return
;
}
pSchema
=
tsdbGetTableSchemaByVersion
(
pTable
,
data
RowVersion
(
row
));
pSchema
=
tsdbGetTableSchemaByVersion
(
pTable
,
mem
RowVersion
(
row
));
if
(
pSchema
==
NULL
)
{
return
;
}
SDataCol
*
pLatestCols
=
pTable
->
lastCols
;
bool
isDataRow
=
isDataRow
(
row
);
for
(
int16_t
j
=
0
;
j
<
schemaNCols
(
pSchema
);
j
++
)
{
STColumn
*
pTCol
=
schemaColAt
(
pSchema
,
j
);
// ignore not exist colId
...
...
@@ -1010,9 +1014,21 @@ static void updateTableLatestColumn(STsdbRepo *pRepo, STable *pTable, SDataRow r
if
(
idx
==
-
1
)
{
continue
;
}
void
*
value
=
tdGetRowDataOfCol
(
row
,
(
int8_t
)
pTCol
->
type
,
TD_DATA_ROW_HEAD_SIZE
+
pSchema
->
columns
[
j
].
offset
);
if
(
isNull
(
value
,
pTCol
->
type
))
{
void
*
value
=
NULL
;
if
(
isDataRow
)
{
value
=
tdGetRowDataOfCol
(
memRowDataBody
(
row
),
(
int8_t
)
pTCol
->
type
,
TD_DATA_ROW_HEAD_SIZE
+
pSchema
->
columns
[
j
].
offset
);
}
else
{
// SKVRow
SColIdx
*
pColIdx
=
tdGetKVRowIdxOfCol
(
memRowKvBody
(
row
),
pTCol
->
colId
);
if
(
pColIdx
)
{
value
=
tdGetKvRowDataOfCol
(
memRowKvBody
(
row
),
pColIdx
->
offset
);
}
}
if
((
value
==
NULL
)
||
isNull
(
value
,
pTCol
->
type
))
{
continue
;
}
...
...
@@ -1027,11 +1043,11 @@ static void updateTableLatestColumn(STsdbRepo *pRepo, STable *pTable, SDataRow r
memcpy
(
pDataCol
->
pData
,
value
,
pDataCol
->
bytes
);
//tsdbInfo("updateTableLatestColumn vgId:%d cache column %d for %d,%s", REPO_ID(pRepo), j, pDataCol->bytes, (char*)pDataCol->pData);
pDataCol
->
ts
=
data
RowKey
(
row
);
pDataCol
->
ts
=
mem
RowKey
(
row
);
}
}
static
int
tsdbUpdateTableLatestInfo
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
S
Data
Row
row
)
{
static
int
tsdbUpdateTableLatestInfo
(
STsdbRepo
*
pRepo
,
STable
*
pTable
,
S
Mem
Row
row
)
{
STsdbCfg
*
pCfg
=
&
pRepo
->
config
;
// if cacheLastRow config has been reset, free the lastRow
...
...
@@ -1042,31 +1058,31 @@ static int tsdbUpdateTableLatestInfo(STsdbRepo *pRepo, STable *pTable, SDataRow
TSDB_WUNLOCK_TABLE
(
pTable
);
}
if
(
tsdbGetTableLastKeyImpl
(
pTable
)
<
data
RowKey
(
row
))
{
if
(
tsdbGetTableLastKeyImpl
(
pTable
)
<
mem
RowKey
(
row
))
{
if
(
CACHE_LAST_ROW
(
pCfg
)
||
pTable
->
lastRow
!=
NULL
)
{
S
Data
Row
nrow
=
pTable
->
lastRow
;
if
(
taosTSizeof
(
nrow
)
<
dataRow
Len
(
row
))
{
S
Data
Row
orow
=
nrow
;
nrow
=
taosTMalloc
(
dataRow
Len
(
row
));
S
Mem
Row
nrow
=
pTable
->
lastRow
;
if
(
taosTSizeof
(
nrow
)
<
memRowT
Len
(
row
))
{
S
Mem
Row
orow
=
nrow
;
nrow
=
taosTMalloc
(
memRowT
Len
(
row
));
if
(
nrow
==
NULL
)
{
terrno
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
return
-
1
;
}
data
RowCpy
(
nrow
,
row
);
mem
RowCpy
(
nrow
,
row
);
TSDB_WLOCK_TABLE
(
pTable
);
pTable
->
lastKey
=
data
RowKey
(
row
);
pTable
->
lastKey
=
mem
RowKey
(
row
);
pTable
->
lastRow
=
nrow
;
TSDB_WUNLOCK_TABLE
(
pTable
);
taosTZfree
(
orow
);
}
else
{
TSDB_WLOCK_TABLE
(
pTable
);
pTable
->
lastKey
=
data
RowKey
(
row
);
data
RowCpy
(
nrow
,
row
);
pTable
->
lastKey
=
mem
RowKey
(
row
);
mem
RowCpy
(
nrow
,
row
);
TSDB_WUNLOCK_TABLE
(
pTable
);
}
}
else
{
pTable
->
lastKey
=
data
RowKey
(
row
);
pTable
->
lastKey
=
mem
RowKey
(
row
);
}
if
(
CACHE_LAST_NULL_COLUMN
(
pCfg
))
{
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
c1fa46d5
...
...
@@ -147,7 +147,7 @@ typedef struct STableGroupSupporter {
static
STimeWindow
updateLastrowForEachGroup
(
STableGroupInfo
*
groupList
);
static
int32_t
checkForCachedLastRow
(
STsdbQueryHandle
*
pQueryHandle
,
STableGroupInfo
*
groupList
);
static
int32_t
checkForCachedLast
(
STsdbQueryHandle
*
pQueryHandle
);
static
int32_t
tsdbGetCachedLastRow
(
STable
*
pTable
,
S
Data
Row
*
pRes
,
TSKEY
*
lastKey
);
static
int32_t
tsdbGetCachedLastRow
(
STable
*
pTable
,
S
Mem
Row
*
pRes
,
TSKEY
*
lastKey
);
static
void
changeQueryHandleForInterpQuery
(
TsdbQueryHandleT
pHandle
);
static
void
doMergeTwoLevelData
(
STsdbQueryHandle
*
pQueryHandle
,
STableCheckInfo
*
pCheckInfo
,
SBlock
*
pBlock
);
...
...
@@ -734,8 +734,8 @@ static bool initTableMemIterator(STsdbQueryHandle* pHandle, STableCheckInfo* pCh
SSkipListNode
*
node
=
tSkipListIterGet
(
pCheckInfo
->
iter
);
assert
(
node
!=
NULL
);
S
DataRow
row
=
(
SData
Row
)
SL_GET_NODE_DATA
(
node
);
TSKEY
key
=
data
RowKey
(
row
);
// first timestamp in buffer
S
MemRow
row
=
(
SMem
Row
)
SL_GET_NODE_DATA
(
node
);
TSKEY
key
=
mem
RowKey
(
row
);
// first timestamp in buffer
tsdbDebug
(
"%p uid:%"
PRId64
", tid:%d check data in mem from skey:%"
PRId64
", order:%d, ts range in buf:%"
PRId64
"-%"
PRId64
", lastKey:%"
PRId64
", numOfRows:%"
PRId64
", 0x%"
PRIx64
,
pHandle
,
pCheckInfo
->
tableId
.
uid
,
pCheckInfo
->
tableId
.
tid
,
key
,
order
,
pMem
->
keyFirst
,
pMem
->
keyLast
,
...
...
@@ -756,8 +756,8 @@ static bool initTableMemIterator(STsdbQueryHandle* pHandle, STableCheckInfo* pCh
SSkipListNode
*
node
=
tSkipListIterGet
(
pCheckInfo
->
iiter
);
assert
(
node
!=
NULL
);
S
DataRow
row
=
(
SData
Row
)
SL_GET_NODE_DATA
(
node
);
TSKEY
key
=
data
RowKey
(
row
);
// first timestamp in buffer
S
MemRow
row
=
(
SMem
Row
)
SL_GET_NODE_DATA
(
node
);
TSKEY
key
=
mem
RowKey
(
row
);
// first timestamp in buffer
tsdbDebug
(
"%p uid:%"
PRId64
", tid:%d check data in imem from skey:%"
PRId64
", order:%d, ts range in buf:%"
PRId64
"-%"
PRId64
", lastKey:%"
PRId64
", numOfRows:%"
PRId64
", 0x%"
PRIx64
,
pHandle
,
pCheckInfo
->
tableId
.
uid
,
pCheckInfo
->
tableId
.
tid
,
key
,
order
,
pIMem
->
keyFirst
,
pIMem
->
keyLast
,
...
...
@@ -781,19 +781,19 @@ static void destroyTableMemIterator(STableCheckInfo* pCheckInfo) {
tSkipListDestroyIter
(
pCheckInfo
->
iiter
);
}
static
S
Data
Row
getSDataRowInTableMem
(
STableCheckInfo
*
pCheckInfo
,
int32_t
order
,
int32_t
update
)
{
S
Data
Row
rmem
=
NULL
,
rimem
=
NULL
;
static
S
Mem
Row
getSDataRowInTableMem
(
STableCheckInfo
*
pCheckInfo
,
int32_t
order
,
int32_t
update
)
{
S
Mem
Row
rmem
=
NULL
,
rimem
=
NULL
;
if
(
pCheckInfo
->
iter
)
{
SSkipListNode
*
node
=
tSkipListIterGet
(
pCheckInfo
->
iter
);
if
(
node
!=
NULL
)
{
rmem
=
(
S
Data
Row
)
SL_GET_NODE_DATA
(
node
);
rmem
=
(
S
Mem
Row
)
SL_GET_NODE_DATA
(
node
);
}
}
if
(
pCheckInfo
->
iiter
)
{
SSkipListNode
*
node
=
tSkipListIterGet
(
pCheckInfo
->
iiter
);
if
(
node
!=
NULL
)
{
rimem
=
(
S
Data
Row
)
SL_GET_NODE_DATA
(
node
);
rimem
=
(
S
Mem
Row
)
SL_GET_NODE_DATA
(
node
);
}
}
...
...
@@ -811,8 +811,8 @@ static SDataRow getSDataRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order
return
rimem
;
}
TSKEY
r1
=
data
RowKey
(
rmem
);
TSKEY
r2
=
data
RowKey
(
rimem
);
TSKEY
r1
=
mem
RowKey
(
rmem
);
TSKEY
r2
=
mem
RowKey
(
rimem
);
if
(
r1
==
r2
)
{
// data ts are duplicated, ignore the data in mem
if
(
!
update
)
{
...
...
@@ -891,12 +891,12 @@ static bool hasMoreDataInCache(STsdbQueryHandle* pHandle) {
initTableMemIterator
(
pHandle
,
pCheckInfo
);
}
S
Data
Row
row
=
getSDataRowInTableMem
(
pCheckInfo
,
pHandle
->
order
,
pCfg
->
update
);
S
Mem
Row
row
=
getSDataRowInTableMem
(
pCheckInfo
,
pHandle
->
order
,
pCfg
->
update
);
if
(
row
==
NULL
)
{
return
false
;
}
pCheckInfo
->
lastKey
=
data
RowKey
(
row
);
// first timestamp in buffer
pCheckInfo
->
lastKey
=
mem
RowKey
(
row
);
// first timestamp in buffer
tsdbDebug
(
"%p uid:%"
PRId64
", tid:%d check data in buffer from skey:%"
PRId64
", order:%d, 0x%"
PRIx64
,
pHandle
,
pCheckInfo
->
tableId
.
uid
,
pCheckInfo
->
tableId
.
tid
,
pCheckInfo
->
lastKey
,
pHandle
->
order
,
pHandle
->
qId
);
...
...
@@ -1155,11 +1155,11 @@ static int32_t handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SBlock* p
int32_t
code
=
TSDB_CODE_SUCCESS
;
/*bool hasData = */
initTableMemIterator
(
pQueryHandle
,
pCheckInfo
);
S
Data
Row
row
=
getSDataRowInTableMem
(
pCheckInfo
,
pQueryHandle
->
order
,
pCfg
->
update
);
S
Mem
Row
row
=
getSDataRowInTableMem
(
pCheckInfo
,
pQueryHandle
->
order
,
pCfg
->
update
);
assert
(
cur
->
pos
>=
0
&&
cur
->
pos
<=
binfo
.
rows
);
TSKEY
key
=
(
row
!=
NULL
)
?
dataRowKey
(
row
)
:
TSKEY_INITIAL_VAL
;
TSKEY
key
=
(
row
!=
NULL
)
?
memRowKey
(
row
)
:
TSKEY_INITIAL_VAL
;
if
(
key
!=
TSKEY_INITIAL_VAL
)
{
tsdbDebug
(
"%p key in mem:%"
PRId64
", 0x%"
PRIx64
,
pQueryHandle
,
key
,
pQueryHandle
->
qId
);
}
else
{
...
...
@@ -1401,7 +1401,7 @@ int32_t doCopyRowsFromFileBlock(STsdbQueryHandle* pQueryHandle, int32_t capacity
// todo refactor, only copy one-by-one
for
(
int32_t
k
=
start
;
k
<
num
+
start
;
++
k
)
{
char
*
p
=
tdGetColDataOfRow
(
src
,
k
);
c
onst
c
har
*
p
=
tdGetColDataOfRow
(
src
,
k
);
memcpy
(
dst
,
p
,
varDataTLen
(
p
));
dst
+=
bytes
;
}
...
...
@@ -1452,88 +1452,170 @@ int32_t doCopyRowsFromFileBlock(STsdbQueryHandle* pQueryHandle, int32_t capacity
return
numOfRows
+
num
;
}
static
void
copyOneRowFromMem
(
STsdbQueryHandle
*
pQueryHandle
,
int32_t
capacity
,
int32_t
numOfRows
,
S
Data
Row
row
,
static
void
copyOneRowFromMem
(
STsdbQueryHandle
*
pQueryHandle
,
int32_t
capacity
,
int32_t
numOfRows
,
S
Mem
Row
row
,
int32_t
numOfCols
,
STable
*
pTable
,
STSchema
*
pSchema
)
{
char
*
pData
=
NULL
;
// the schema version info is embed
ed in SData
Row
// the schema version info is embed
ded in SDataRow, and use latest schema version for SKV
Row
int32_t
numOfRowCols
=
0
;
if
(
pSchema
==
NULL
)
{
pSchema
=
tsdbGetTableSchemaByVersion
(
pTable
,
data
RowVersion
(
row
));
pSchema
=
tsdbGetTableSchemaByVersion
(
pTable
,
mem
RowVersion
(
row
));
numOfRowCols
=
schemaNCols
(
pSchema
);
}
else
{
numOfRowCols
=
schemaNCols
(
pSchema
);
}
int32_t
i
=
0
,
j
=
0
;
while
(
i
<
numOfCols
&&
j
<
numOfRowCols
)
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pQueryHandle
->
pColumns
,
i
);
if
(
pSchema
->
columns
[
j
].
colId
<
pColInfo
->
info
.
colId
)
{
j
++
;
continue
;
}
if
(
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
))
{
pData
=
(
char
*
)
pColInfo
->
pData
+
numOfRows
*
pColInfo
->
info
.
bytes
;
}
else
{
pData
=
(
char
*
)
pColInfo
->
pData
+
(
capacity
-
numOfRows
-
1
)
*
pColInfo
->
info
.
bytes
;
int32_t
i
=
0
;
if
(
isDataRow
(
row
))
{
SDataRow
dataRow
=
memRowDataBody
(
row
);
int32_t
j
=
0
;
while
(
i
<
numOfCols
&&
j
<
numOfRowCols
)
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pQueryHandle
->
pColumns
,
i
);
if
(
pSchema
->
columns
[
j
].
colId
<
pColInfo
->
info
.
colId
)
{
j
++
;
continue
;
}
if
(
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
))
{
pData
=
(
char
*
)
pColInfo
->
pData
+
numOfRows
*
pColInfo
->
info
.
bytes
;
}
else
{
pData
=
(
char
*
)
pColInfo
->
pData
+
(
capacity
-
numOfRows
-
1
)
*
pColInfo
->
info
.
bytes
;
}
if
(
pSchema
->
columns
[
j
].
colId
==
pColInfo
->
info
.
colId
)
{
void
*
value
=
tdGetRowDataOfCol
(
dataRow
,
(
int8_t
)
pColInfo
->
info
.
type
,
TD_DATA_ROW_HEAD_SIZE
+
pSchema
->
columns
[
j
].
offset
);
switch
(
pColInfo
->
info
.
type
)
{
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
memcpy
(
pData
,
value
,
varDataTLen
(
value
));
break
;
case
TSDB_DATA_TYPE_NULL
:
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_UTINYINT
:
*
(
uint8_t
*
)
pData
=
*
(
uint8_t
*
)
value
;
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
*
(
uint16_t
*
)
pData
=
*
(
uint16_t
*
)
value
;
break
;
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UINT
:
*
(
uint32_t
*
)
pData
=
*
(
uint32_t
*
)
value
;
break
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
*
(
uint64_t
*
)
pData
=
*
(
uint64_t
*
)
value
;
break
;
case
TSDB_DATA_TYPE_FLOAT
:
SET_FLOAT_PTR
(
pData
,
value
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
SET_DOUBLE_PTR
(
pData
,
value
);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
if
(
pColInfo
->
info
.
colId
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
*
(
TSKEY
*
)
pData
=
tdGetKey
(
*
(
TKEY
*
)
value
);
}
else
{
*
(
TSKEY
*
)
pData
=
*
(
TSKEY
*
)
value
;
}
break
;
default:
memcpy
(
pData
,
value
,
pColInfo
->
info
.
bytes
);
}
j
++
;
i
++
;
}
else
{
// pColInfo->info.colId < pSchema->columns[j].colId, it is a NULL data
if
(
pColInfo
->
info
.
type
==
TSDB_DATA_TYPE_BINARY
||
pColInfo
->
info
.
type
==
TSDB_DATA_TYPE_NCHAR
)
{
setVardataNull
(
pData
,
pColInfo
->
info
.
type
);
}
else
{
setNull
(
pData
,
pColInfo
->
info
.
type
,
pColInfo
->
info
.
bytes
);
}
i
++
;
}
}
}
else
if
(
isKvRow
(
row
))
{
SKVRow
kvRow
=
memRowKvBody
(
row
);
int32_t
k
=
0
;
int32_t
nKvRowCols
=
kvRowNCols
(
kvRow
);
if
(
pSchema
->
columns
[
j
].
colId
==
pColInfo
->
info
.
colId
)
{
void
*
value
=
tdGetRowDataOfCol
(
row
,
(
int8_t
)
pColInfo
->
info
.
type
,
TD_DATA_ROW_HEAD_SIZE
+
pSchema
->
columns
[
j
].
offset
);
switch
(
pColInfo
->
info
.
type
)
{
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
memcpy
(
pData
,
value
,
varDataTLen
(
value
));
break
;
case
TSDB_DATA_TYPE_NULL
:
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_UTINYINT
:
*
(
uint8_t
*
)
pData
=
*
(
uint8_t
*
)
value
;
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
*
(
uint16_t
*
)
pData
=
*
(
uint16_t
*
)
value
;
break
;
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UINT
:
*
(
uint32_t
*
)
pData
=
*
(
uint32_t
*
)
value
;
break
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
*
(
uint64_t
*
)
pData
=
*
(
uint64_t
*
)
value
;
break
;
case
TSDB_DATA_TYPE_FLOAT
:
SET_FLOAT_PTR
(
pData
,
value
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
SET_DOUBLE_PTR
(
pData
,
value
);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
if
(
pColInfo
->
info
.
colId
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
*
(
TSKEY
*
)
pData
=
tdGetKey
(
*
(
TKEY
*
)
value
);
}
else
{
*
(
TSKEY
*
)
pData
=
*
(
TSKEY
*
)
value
;
}
break
;
default:
memcpy
(
pData
,
value
,
pColInfo
->
info
.
bytes
);
while
(
i
<
numOfCols
&&
k
<
nKvRowCols
)
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pQueryHandle
->
pColumns
,
i
);
SColIdx
*
pColIdx
=
kvRowColIdxAt
(
kvRow
,
k
);
if
(
pColIdx
->
colId
<
pColInfo
->
info
.
colId
)
{
++
k
;
continue
;
}
j
++
;
i
++
;
}
else
{
// pColInfo->info.colId < pSchema->columns[j].colId, it is a NULL data
if
(
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
))
{
pData
=
(
char
*
)
pColInfo
->
pData
+
numOfRows
*
pColInfo
->
info
.
bytes
;
}
else
{
pData
=
(
char
*
)
pColInfo
->
pData
+
(
capacity
-
numOfRows
-
1
)
*
pColInfo
->
info
.
bytes
;
}
if
(
pColIdx
->
colId
==
pColInfo
->
info
.
colId
)
{
// offset of pColIdx for SKVRow including the TD_KV_ROW_HEAD_SIZE
void
*
value
=
tdGetKvRowDataOfCol
(
kvRow
,
pColIdx
->
offset
);
switch
(
pColInfo
->
info
.
type
)
{
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_NCHAR
:
memcpy
(
pData
,
value
,
varDataTLen
(
value
));
break
;
case
TSDB_DATA_TYPE_NULL
:
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_UTINYINT
:
*
(
uint8_t
*
)
pData
=
*
(
uint8_t
*
)
value
;
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
*
(
uint16_t
*
)
pData
=
*
(
uint16_t
*
)
value
;
break
;
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UINT
:
*
(
uint32_t
*
)
pData
=
*
(
uint32_t
*
)
value
;
break
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
*
(
uint64_t
*
)
pData
=
*
(
uint64_t
*
)
value
;
break
;
case
TSDB_DATA_TYPE_FLOAT
:
SET_FLOAT_PTR
(
pData
,
value
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
SET_DOUBLE_PTR
(
pData
,
value
);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
if
(
pColInfo
->
info
.
colId
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
*
(
TSKEY
*
)
pData
=
tdGetKey
(
*
(
TKEY
*
)
value
);
}
else
{
*
(
TSKEY
*
)
pData
=
*
(
TSKEY
*
)
value
;
}
break
;
default:
memcpy
(
pData
,
value
,
pColInfo
->
info
.
bytes
);
}
++
k
;
++
i
;
continue
;
}
// If (pColInfo->info.colId < pColIdx->colId), it is NULL data
if
(
pColInfo
->
info
.
type
==
TSDB_DATA_TYPE_BINARY
||
pColInfo
->
info
.
type
==
TSDB_DATA_TYPE_NCHAR
)
{
setVardataNull
(
pData
,
pColInfo
->
info
.
type
);
}
else
{
setNull
(
pData
,
pColInfo
->
info
.
type
,
pColInfo
->
info
.
bytes
);
}
i
++
;
++
i
;
}
}
else
{
ASSERT
(
0
);
}
while
(
i
<
numOfCols
)
{
// the remain columns are all null data
while
(
i
<
numOfCols
)
{
// the remain columns are all null data
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pQueryHandle
->
pColumns
,
i
);
if
(
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
))
{
pData
=
(
char
*
)
pColInfo
->
pData
+
numOfRows
*
pColInfo
->
info
.
bytes
;
...
...
@@ -1550,7 +1632,6 @@ static void copyOneRowFromMem(STsdbQueryHandle* pQueryHandle, int32_t capacity,
i
++
;
}
}
static
void
moveDataToFront
(
STsdbQueryHandle
*
pQueryHandle
,
int32_t
numOfRows
,
int32_t
numOfCols
)
{
if
(
numOfRows
==
0
||
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
))
{
return
;
...
...
@@ -1730,12 +1811,12 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo*
}
else
if
(
pCheckInfo
->
iter
!=
NULL
||
pCheckInfo
->
iiter
!=
NULL
)
{
SSkipListNode
*
node
=
NULL
;
do
{
S
Data
Row
row
=
getSDataRowInTableMem
(
pCheckInfo
,
pQueryHandle
->
order
,
pCfg
->
update
);
S
Mem
Row
row
=
getSDataRowInTableMem
(
pCheckInfo
,
pQueryHandle
->
order
,
pCfg
->
update
);
if
(
row
==
NULL
)
{
break
;
}
TSKEY
key
=
data
RowKey
(
row
);
TSKEY
key
=
mem
RowKey
(
row
);
if
((
key
>
pQueryHandle
->
window
.
ekey
&&
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
))
||
(
key
<
pQueryHandle
->
window
.
ekey
&&
!
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
)))
{
break
;
...
...
@@ -1748,11 +1829,11 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo*
if
((
key
<
tsArray
[
pos
]
&&
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
))
||
(
key
>
tsArray
[
pos
]
&&
!
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
)))
{
if
(
rv
!=
data
RowVersion
(
row
))
{
pSchema
=
tsdbGetTableSchemaByVersion
(
pTable
,
data
RowVersion
(
row
));
rv
=
data
RowVersion
(
row
);
}
if
(
rv
!=
mem
RowVersion
(
row
))
{
pSchema
=
tsdbGetTableSchemaByVersion
(
pTable
,
mem
RowVersion
(
row
));
rv
=
mem
RowVersion
(
row
);
}
copyOneRowFromMem
(
pQueryHandle
,
pQueryHandle
->
outputCapacity
,
numOfRows
,
row
,
numOfCols
,
pTable
,
pSchema
);
numOfRows
+=
1
;
if
(
cur
->
win
.
skey
==
TSKEY_INITIAL_VAL
)
{
...
...
@@ -1766,11 +1847,11 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo*
moveToNextRowInMem
(
pCheckInfo
);
}
else
if
(
key
==
tsArray
[
pos
])
{
// data in buffer has the same timestamp of data in file block, ignore it
if
(
pCfg
->
update
)
{
if
(
rv
!=
data
RowVersion
(
row
))
{
pSchema
=
tsdbGetTableSchemaByVersion
(
pTable
,
data
RowVersion
(
row
));
rv
=
data
RowVersion
(
row
);
if
(
rv
!=
mem
RowVersion
(
row
))
{
pSchema
=
tsdbGetTableSchemaByVersion
(
pTable
,
mem
RowVersion
(
row
));
rv
=
mem
RowVersion
(
row
);
}
copyOneRowFromMem
(
pQueryHandle
,
pQueryHandle
->
outputCapacity
,
numOfRows
,
row
,
numOfCols
,
pTable
,
pSchema
);
numOfRows
+=
1
;
if
(
cur
->
win
.
skey
==
TSKEY_INITIAL_VAL
)
{
...
...
@@ -1820,8 +1901,10 @@ static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo*
* copy them all to result buffer, since it may be overlapped with file data block.
*/
if
(
node
==
NULL
||
((
dataRowKey
((
SDataRow
)
SL_GET_NODE_DATA
(
node
))
>
pQueryHandle
->
window
.
ekey
)
&&
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
))
||
((
dataRowKey
((
SDataRow
)
SL_GET_NODE_DATA
(
node
))
<
pQueryHandle
->
window
.
ekey
)
&&
!
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
)))
{
((
memRowKey
((
SMemRow
)
SL_GET_NODE_DATA
(
node
))
>
pQueryHandle
->
window
.
ekey
)
&&
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
))
||
((
memRowKey
((
SMemRow
)
SL_GET_NODE_DATA
(
node
))
<
pQueryHandle
->
window
.
ekey
)
&&
!
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
)))
{
// no data in cache or data in cache is greater than the ekey of time window, load data from file block
if
(
cur
->
win
.
skey
==
TSKEY_INITIAL_VAL
)
{
cur
->
win
.
skey
=
tsArray
[
pos
];
...
...
@@ -2407,12 +2490,12 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
STSchema
*
pSchema
=
NULL
;
do
{
S
Data
Row
row
=
getSDataRowInTableMem
(
pCheckInfo
,
pQueryHandle
->
order
,
pCfg
->
update
);
S
Mem
Row
row
=
getSDataRowInTableMem
(
pCheckInfo
,
pQueryHandle
->
order
,
pCfg
->
update
);
if
(
row
==
NULL
)
{
break
;
}
TSKEY
key
=
data
RowKey
(
row
);
TSKEY
key
=
mem
RowKey
(
row
);
if
((
key
>
maxKey
&&
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
))
||
(
key
<
maxKey
&&
!
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
)))
{
tsdbDebug
(
"%p key:%"
PRIu64
" beyond qrange:%"
PRId64
" - %"
PRId64
", no more data in buffer"
,
pQueryHandle
,
key
,
pQueryHandle
->
window
.
skey
,
pQueryHandle
->
window
.
ekey
);
...
...
@@ -2425,9 +2508,9 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
}
win
->
ekey
=
key
;
if
(
rv
!=
data
RowVersion
(
row
))
{
pSchema
=
tsdbGetTableSchemaByVersion
(
pTable
,
data
RowVersion
(
row
));
rv
=
data
RowVersion
(
row
);
if
(
rv
!=
mem
RowVersion
(
row
))
{
pSchema
=
tsdbGetTableSchemaByVersion
(
pTable
,
mem
RowVersion
(
row
));
rv
=
mem
RowVersion
(
row
);
}
copyOneRowFromMem
(
pQueryHandle
,
maxRowsToRead
,
numOfRows
,
row
,
numOfCols
,
pTable
,
pSchema
);
...
...
@@ -2544,7 +2627,7 @@ static bool loadCachedLastRow(STsdbQueryHandle* pQueryHandle) {
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
S
DataRow
pRow
=
NULL
;
S
MemRow
pRow
=
NULL
;
TSKEY
key
=
TSKEY_INITIAL_VAL
;
int32_t
step
=
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
)
?
1
:-
1
;
...
...
@@ -2954,7 +3037,7 @@ bool tsdbGetExternalRow(TsdbQueryHandleT pHandle) {
* if lastRow == NULL, return TSDB_CODE_TDB_NO_CACHE_LAST_ROW
* else set pRes and return TSDB_CODE_SUCCESS and save lastKey
*/
int32_t
tsdbGetCachedLastRow
(
STable
*
pTable
,
S
Data
Row
*
pRes
,
TSKEY
*
lastKey
)
{
int32_t
tsdbGetCachedLastRow
(
STable
*
pTable
,
S
Mem
Row
*
pRes
,
TSKEY
*
lastKey
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
TSDB_RLOCK_TABLE
(
pTable
);
...
...
@@ -2965,7 +3048,7 @@ int32_t tsdbGetCachedLastRow(STable* pTable, SDataRow* pRes, TSKEY* lastKey) {
}
if
(
pRes
)
{
*
pRes
=
td
Data
RowDup
(
pTable
->
lastRow
);
*
pRes
=
td
Mem
RowDup
(
pTable
->
lastRow
);
if
(
*
pRes
==
NULL
)
{
code
=
TSDB_CODE_TDB_OUT_OF_MEMORY
;
}
...
...
src/tsdb/tests/tsdbTests.cpp
浏览文件 @
c1fa46d5
...
...
@@ -55,10 +55,10 @@ static int insertData(SInsertInfo *pInfo) {
for
(
int
j
=
0
;
j
<
schemaNCols
(
pInfo
->
pSchema
);
j
++
)
{
STColumn
*
pTCol
=
schemaColAt
(
pInfo
->
pSchema
,
j
);
if
(
j
==
0
)
{
// Just for timestamp
tdAppendColVal
(
row
,
(
void
*
)(
&
start_time
),
pTCol
->
type
,
pTCol
->
bytes
,
pTCol
->
offset
);
tdAppendColVal
(
row
,
(
void
*
)(
&
start_time
),
pTCol
->
type
,
pTCol
->
offset
);
}
else
{
// For int
int
val
=
10
;
tdAppendColVal
(
row
,
(
void
*
)(
&
val
),
pTCol
->
type
,
pTCol
->
bytes
,
pTCol
->
offset
);
tdAppendColVal
(
row
,
(
void
*
)(
&
val
),
pTCol
->
type
,
pTCol
->
offset
);
}
}
pBlock
->
dataLen
+=
dataRowLen
(
row
);
...
...
tests/examples/lua/luaconnector.so
0 → 100755
浏览文件 @
c1fa46d5
文件已添加
tests/pytest/fulltest.sh
浏览文件 @
c1fa46d5
...
...
@@ -352,7 +352,7 @@ python3 ./test.py -f alter/alter_debugFlag.py
python3 ./test.py
-f
query/queryBetweenAnd.py
python3 ./test.py
-f
tag_lite/alter_tag.py
python3 test.py
-f
tools/taosdemoAllTest/taosdemoTestInsertWithJson.py
#
python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJson.py
python3 test.py
-f
tools/taosdemoAllTest/taosdemoTestQueryWithJson.py
python3 test.py
-f
tools/taosdemoAllTest/TD-4985/query-limit-offset.py
python3 ./test.py
-f
tag_lite/drop_auto_create.py
...
...
tests/pytest/table/max_table_length.py
浏览文件 @
c1fa46d5
...
...
@@ -42,7 +42,7 @@ class TDTestCase:
print
(
"==============step3"
)
tdLog
.
info
(
"check int & binary"
)
tdSql
.
error
(
"create table anal2 (ts timestamp ,i binary(16371),j int)"
)
#
tdSql.error("create table anal2 (ts timestamp ,i binary(16371),j int)")
tdSql
.
execute
(
"create table anal2 (ts timestamp ,i binary(16370),j int)"
)
tdSql
.
execute
(
"create table anal3 (ts timestamp ,i binary(16366), j int, k int)"
)
...
...
tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.csv
0 → 100755
浏览文件 @
c1fa46d5
0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,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,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
\ No newline at end of file
tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.json
0 → 100755
浏览文件 @
c1fa46d5
{
"filetype"
:
"insert"
,
"cfgdir"
:
"/etc/taos"
,
"host"
:
"127.0.0.1"
,
"port"
:
6030
,
"user"
:
"root"
,
"password"
:
"taosdata"
,
"thread_count"
:
10
,
"thread_count_create_tbl"
:
10
,
"result_file"
:
"./insert_res.txt"
,
"confirm_parameter_prompt"
:
"no"
,
"insert_interval"
:
0
,
"interlace_rows"
:
10
,
"num_of_records_per_req"
:
1
,
"max_sql_len"
:
102400000
,
"databases"
:
[{
"dbinfo"
:
{
"name"
:
"db"
,
"drop"
:
"yes"
,
"replica"
:
1
,
"days"
:
10
,
"cache"
:
50
,
"blocks"
:
8
,
"precision"
:
"ms"
,
"keep"
:
365
,
"minRows"
:
100
,
"maxRows"
:
4096
,
"comp"
:
2
,
"walLevel"
:
1
,
"cachelast"
:
0
,
"quorum"
:
1
,
"fsync"
:
3000
,
"update"
:
0
},
"super_tables"
:
[{
"name"
:
"stb_old"
,
"child_table_exists"
:
"no"
,
"childtable_count"
:
10
,
"childtable_prefix"
:
"stb_old_"
,
"auto_create_table"
:
"no"
,
"batch_create_tbl_num"
:
5
,
"data_source"
:
"sample"
,
"insert_mode"
:
"taosc"
,
"insert_rows"
:
100
,
"childtable_limit"
:
0
,
"childtable_offset"
:
0
,
"multi_thread_write_one_tbl"
:
"no"
,
"interlace_rows"
:
0
,
"insert_interval"
:
0
,
"max_sql_len"
:
1024000
,
"disorder_ratio"
:
0
,
"disorder_range"
:
1000
,
"timestamp_step"
:
1
,
"start_timestamp"
:
"2020-10-01 00:00:00.000"
,
"sample_format"
:
"csv"
,
"sample_file"
:
"./tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.csv"
,
"tags_file"
:
""
,
"columns"
:
[{
"type"
:
"INT"
,
"count"
:
4000
},
{
"type"
:
"BINARY"
,
"len"
:
16
,
"count"
:
1
}],
"tags"
:
[{
"type"
:
"TINYINT"
,
"count"
:
2
},
{
"type"
:
"BINARY"
,
"len"
:
16
,
"count"
:
1
}]
},{
"name"
:
"stb_new"
,
"child_table_exists"
:
"no"
,
"childtable_count"
:
10
,
"childtable_prefix"
:
"stb_new_"
,
"auto_create_table"
:
"no"
,
"batch_create_tbl_num"
:
5
,
"data_source"
:
"rand"
,
"insert_mode"
:
"taosc"
,
"insert_rows"
:
100
,
"childtable_limit"
:
0
,
"childtable_offset"
:
0
,
"multi_thread_write_one_tbl"
:
"no"
,
"interlace_rows"
:
0
,
"insert_interval"
:
0
,
"max_sql_len"
:
1024000
,
"disorder_ratio"
:
0
,
"disorder_range"
:
1000
,
"timestamp_step"
:
1
,
"start_timestamp"
:
"2020-10-01 00:00:00.000"
,
"sample_format"
:
"csv"
,
"sample_file"
:
"./tools/taosdemoAllTest/sample.csv"
,
"tags_file"
:
""
,
"columns"
:
[{
"type"
:
"DOUBLE"
,
"count"
:
1020
}],
"tags"
:
[{
"type"
:
"TINYINT"
,
"count"
:
2
},
{
"type"
:
"BINARY"
,
"len"
:
16
,
"count"
:
1
}]
},{
"name"
:
"stb_int"
,
"child_table_exists"
:
"no"
,
"childtable_count"
:
10
,
"childtable_prefix"
:
"stb_int_"
,
"auto_create_table"
:
"no"
,
"batch_create_tbl_num"
:
5
,
"data_source"
:
"rand"
,
"insert_mode"
:
"taosc"
,
"insert_rows"
:
100
,
"childtable_limit"
:
0
,
"childtable_offset"
:
0
,
"multi_thread_write_one_tbl"
:
"no"
,
"interlace_rows"
:
0
,
"insert_interval"
:
0
,
"max_sql_len"
:
1024000
,
"disorder_ratio"
:
0
,
"disorder_range"
:
1000
,
"timestamp_step"
:
1
,
"start_timestamp"
:
"2020-10-01 00:00:00.000"
,
"sample_format"
:
"csv"
,
"sample_file"
:
"./tools/taosdemoAllTest/sample.csv"
,
"tags_file"
:
""
,
"columns"
:
[{
"type"
:
"int"
,
"count"
:
1020
}],
"tags"
:
[{
"type"
:
"TINYINT"
,
"count"
:
2
},
{
"type"
:
"BINARY"
,
"len"
:
16
,
"count"
:
1
}]
}]
}]
}
tests/pytest/tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.py
0 → 100755
浏览文件 @
c1fa46d5
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import
sys
import
os
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
from
util.dnodes
import
*
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
"start to execute %s"
%
__file__
)
tdSql
.
init
(
conn
.
cursor
(),
logSql
)
def
getBuildPath
(
self
):
selfPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
if
(
"community"
in
selfPath
):
projPath
=
selfPath
[:
selfPath
.
find
(
"community"
)]
else
:
projPath
=
selfPath
[:
selfPath
.
find
(
"tests"
)]
for
root
,
dirs
,
files
in
os
.
walk
(
projPath
):
if
(
"taosd"
in
files
):
rootRealPath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
root
))
if
(
"packaging"
not
in
rootRealPath
):
buildPath
=
root
[:
len
(
root
)
-
len
(
"/build/bin"
)]
break
return
buildPath
def
run
(
self
):
buildPath
=
self
.
getBuildPath
()
if
(
buildPath
==
""
):
tdLog
.
exit
(
"taosd not found!"
)
else
:
tdLog
.
info
(
"taosd found in %s"
%
buildPath
)
binPath
=
buildPath
+
"/build/bin/"
# insert: create one or mutiple tables per sql and insert multiple rows per sql
# test case for https://jira.taosdata.com:18080/browse/TD-5213
os
.
system
(
"%staosdemo -f tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.json -y "
%
binPath
)
tdSql
.
execute
(
"use db"
)
tdSql
.
query
(
"select count (tbname) from stb_old"
)
tdSql
.
checkData
(
0
,
0
,
10
)
# tdSql.query("select * from stb_old")
# tdSql.checkRows(10)
# tdSql.checkCols(1024)
# tdSql.query("select count (tbname) from stb_new")
# tdSql.checkData(0, 0, 10)
# tdSql.query("select * from stb_new")
# tdSql.checkRows(10)
# tdSql.checkCols(4096)
# tdLog.info("stop dnode to commit data to disk")
# tdDnodes.stop(1)
# tdDnodes.start(1)
#regular table
sql
=
"create table tb(ts timestamp, "
for
i
in
range
(
1022
):
sql
+=
"col%d binary(14), "
%
(
i
+
1
)
sql
+=
"col1023 binary(22))"
tdSql
.
execute
(
sql
)
for
i
in
range
(
4
):
sql
=
"insert into tb values(%d, "
for
j
in
range
(
1022
):
str
=
"'%s', "
%
self
.
get_random_string
(
14
)
sql
+=
str
sql
+=
"'%s')"
%
self
.
get_random_string
(
22
)
tdSql
.
execute
(
sql
%
(
self
.
ts
+
i
))
time
.
sleep
(
10
)
tdSql
.
query
(
"select count(*) from tb"
)
tdSql
.
checkData
(
0
,
0
,
4
)
tdDnodes
.
stop
(
1
)
tdDnodes
.
start
(
1
)
time
.
sleep
(
1
)
tdSql
.
query
(
"select count(*) from tb"
)
tdSql
.
checkData
(
0
,
0
,
4
)
sql
=
"create table tb1(ts timestamp, "
for
i
in
range
(
4094
):
sql
+=
"col%d binary(14), "
%
(
i
+
1
)
sql
+=
"col4095 binary(22))"
tdSql
.
execute
(
sql
)
for
i
in
range
(
4
):
sql
=
"insert into tb1 values(%d, "
for
j
in
range
(
4094
):
str
=
"'%s', "
%
self
.
get_random_string
(
14
)
sql
+=
str
sql
+=
"'%s')"
%
self
.
get_random_string
(
22
)
tdSql
.
execute
(
sql
%
(
self
.
ts
+
i
))
time
.
sleep
(
10
)
tdSql
.
query
(
"select count(*) from tb1"
)
tdSql
.
checkData
(
0
,
0
,
4
)
tdDnodes
.
stop
(
1
)
tdDnodes
.
start
(
1
)
time
.
sleep
(
1
)
tdSql
.
query
(
"select count(*) from tb1"
)
tdSql
.
checkData
(
0
,
0
,
4
)
#os.system("rm -rf tools/taosdemoAllTest/TD-5213/insertSigcolumnsNum4096.py.sql")
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
"%s successfully executed"
%
__file__
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录