Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a5ef854e
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
a5ef854e
编写于
8月 11, 2022
作者:
C
Cary Xu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
row: code optimization
上级
cfb61d66
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
133 addition
and
68 deletion
+133
-68
include/common/trow.h
include/common/trow.h
+7
-16
source/common/src/trow.c
source/common/src/trow.c
+125
-51
source/dnode/vnode/src/tq/tqRead.c
source/dnode/vnode/src/tq/tqRead.c
+1
-1
未找到文件。
include/common/trow.h
浏览文件 @
a5ef854e
...
...
@@ -195,12 +195,6 @@ static FORCE_INLINE void tdRowSetVal(SCellVal *pVal, uint8_t valType, void *val)
pVal
->
valType
=
valType
;
pVal
->
val
=
val
;
}
/**
* @brief Primary TS column not included.
*
* @param pRow
* @return FORCE_INLINE
*/
static
FORCE_INLINE
col_id_t
tdRowGetNCols
(
STSRow
*
pRow
)
{
return
*
(
col_id_t
*
)
TD_ROW_NCOLS
(
pRow
);
}
static
FORCE_INLINE
void
tdRowCpy
(
void
*
dst
,
const
STSRow
*
pRow
)
{
memcpy
(
dst
,
pRow
,
TD_ROW_LEN
(
pRow
));
}
static
FORCE_INLINE
const
char
*
tdRowEnd
(
STSRow
*
pRow
)
{
return
(
const
char
*
)
POINTER_SHIFT
(
pRow
,
TD_ROW_LEN
(
pRow
));
}
...
...
@@ -325,20 +319,17 @@ typedef struct {
col_id_t
kvIdx
;
// [0, nKvCols)
}
STSRowIter
;
void
tdSTSRowIterReset
(
STSRowIter
*
pIter
,
STSRow
*
pRow
);
void
tdSTSRowIterInit
(
STSRowIter
*
pIter
,
STSchema
*
pSchema
);
void
tdSTSRowIterInit
(
STSRowIter
*
pIter
,
STSchema
*
pSchema
);
void
tdSTSRowIterReset
(
STSRowIter
*
pIter
,
STSRow
*
pRow
);
bool
tdSTSRowIterFetch
(
STSRowIter
*
pIter
,
col_id_t
colId
,
col_type_t
colType
,
SCellVal
*
pVal
);
bool
tdSTSRowIterNext
(
STSRowIter
*
pIter
,
SCellVal
*
pVal
);
int32_t
tdSTSRowNew
(
SArray
*
pArray
,
STSchema
*
pTSchema
,
STSRow
**
ppRow
);
bool
tdGetTpRowDataOfCol
(
STSRowIter
*
pIter
,
col_type_t
colType
,
int32_t
offset
,
SCellVal
*
pVal
);
bool
tdGetKvRowValOfColEx
(
STSRowIter
*
pIter
,
col_id_t
colId
,
col_id_t
*
nIdx
,
SCellVal
*
pVal
);
bool
tdSTSRowIterNext
(
STSRowIter
*
pIter
,
SCellVal
*
pVal
);
bool
tdSTpRowGetVal
(
STSRow
*
pRow
,
col_id_t
colId
,
col_type_t
colType
,
int32_t
flen
,
uint32_t
offset
,
col_id_t
colIdx
,
SCellVal
*
pVal
);
bool
tdSKvRowGetVal
(
STSRow
*
pRow
,
col_id_t
colId
,
col_id_t
colIdx
,
SCellVal
*
pVal
);
void
tdSCellValPrint
(
SCellVal
*
pVal
,
int8_t
colType
);
bool
tdSTSRowGetVal
(
STSRowIter
*
pIter
,
col_id_t
colId
,
col_type_t
colType
,
SCellVal
*
pVal
);
void
tdSRowPrint
(
STSRow
*
row
,
STSchema
*
pSchema
,
const
char
*
tag
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_COMMON_ROW_H_*/
#endif
/*_TD_COMMON_ROW_H_*/
\ No newline at end of file
source/common/src/trow.c
浏览文件 @
a5ef854e
...
...
@@ -32,9 +32,13 @@ const uint8_t tdVTypeByte[2][3] = {{
};
// declaration
static
uint8_t
tdGetBitmapByte
(
uint8_t
byte
);
static
int32_t
tdCompareColId
(
const
void
*
arg1
,
const
void
*
arg2
);
static
FORCE_INLINE
int32_t
compareKvRowColId
(
const
void
*
key1
,
const
void
*
key2
);
static
uint8_t
tdGetBitmapByte
(
uint8_t
byte
);
static
bool
tdSTSRowIterGetTpVal
(
STSRowIter
*
pIter
,
col_type_t
colType
,
int32_t
offset
,
SCellVal
*
pVal
);
static
bool
tdSTSRowIterGetKvVal
(
STSRowIter
*
pIter
,
col_id_t
colId
,
col_id_t
*
nIdx
,
SCellVal
*
pVal
);
static
bool
tdSTpRowGetVal
(
STSRow
*
pRow
,
col_id_t
colId
,
col_type_t
colType
,
int32_t
flen
,
uint32_t
offset
,
col_id_t
colIdx
,
SCellVal
*
pVal
);
static
bool
tdSKvRowGetVal
(
STSRow
*
pRow
,
col_id_t
colId
,
col_id_t
colIdx
,
SCellVal
*
pVal
);
static
void
tdSCellValPrint
(
SCellVal
*
pVal
,
int8_t
colType
);
// implementation
/**
...
...
@@ -330,7 +334,6 @@ void tdSRowPrint(STSRow *row, STSchema *pSchema, const char *tag) {
tdSTSRowIterInit
(
&
iter
,
pSchema
);
tdSTSRowIterReset
(
&
iter
,
row
);
printf
(
"%s >>>type:%d,sver:%d "
,
tag
,
(
int32_t
)
TD_ROW_TYPE
(
row
),
(
int32_t
)
TD_ROW_SVER
(
row
));
STColumn
*
cols
=
(
STColumn
*
)
&
iter
.
pSchema
->
columns
;
while
(
true
)
{
SCellVal
sVal
=
{.
valType
=
255
,
NULL
};
...
...
@@ -340,7 +343,6 @@ void tdSRowPrint(STSRow *row, STSchema *pSchema, const char *tag) {
ASSERT
(
sVal
.
valType
==
0
||
sVal
.
valType
==
1
||
sVal
.
valType
==
2
);
tdSCellValPrint
(
&
sVal
,
cols
[
iter
.
colIdx
-
1
].
type
);
}
printf
(
"
\n
"
);
}
...
...
@@ -422,6 +424,16 @@ void tdSCellValPrint(SCellVal *pVal, int8_t colType) {
}
}
static
FORCE_INLINE
int32_t
compareKvRowColId
(
const
void
*
key1
,
const
void
*
key2
)
{
if
(
*
(
col_id_t
*
)
key1
>
((
SKvRowIdx
*
)
key2
)
->
colId
)
{
return
1
;
}
else
if
(
*
(
col_id_t
*
)
key1
<
((
SKvRowIdx
*
)
key2
)
->
colId
)
{
return
-
1
;
}
else
{
return
0
;
}
}
bool
tdSKvRowGetVal
(
STSRow
*
pRow
,
col_id_t
colId
,
col_id_t
colIdx
,
SCellVal
*
pVal
)
{
if
(
colId
==
PRIMARYKEY_TIMESTAMP_COL_ID
)
{
tdRowSetVal
(
pVal
,
TD_VTYPE_NORM
,
TD_ROW_KEY_ADDR
(
pRow
));
...
...
@@ -458,6 +470,39 @@ bool tdSTpRowGetVal(STSRow *pRow, col_id_t colId, col_type_t colType, int32_t fl
return
true
;
}
bool
tdSTSRowIterFetch
(
STSRowIter
*
pIter
,
col_id_t
colId
,
col_type_t
colType
,
SCellVal
*
pVal
)
{
if
(
colId
==
PRIMARYKEY_TIMESTAMP_COL_ID
)
{
pVal
->
val
=
&
pIter
->
pRow
->
ts
;
pVal
->
valType
=
TD_VTYPE_NORM
;
return
true
;
}
if
(
TD_IS_TP_ROW
(
pIter
->
pRow
))
{
STColumn
*
pCol
=
NULL
;
STSchema
*
pSchema
=
pIter
->
pSchema
;
while
(
pIter
->
colIdx
<
pSchema
->
numOfCols
)
{
pCol
=
&
pSchema
->
columns
[
pIter
->
colIdx
];
// 1st column of schema is primary TS key
if
(
colId
==
pCol
->
colId
)
{
break
;
}
else
if
(
pCol
->
colId
<
colId
)
{
++
pIter
->
colIdx
;
continue
;
}
else
{
return
false
;
}
}
tdSTSRowIterGetTpVal
(
pIter
,
pCol
->
type
,
pCol
->
offset
-
sizeof
(
TSKEY
),
pVal
);
++
pIter
->
colIdx
;
}
else
if
(
TD_IS_KV_ROW
(
pIter
->
pRow
))
{
return
tdSTSRowIterGetKvVal
(
pIter
,
colId
,
&
pIter
->
kvIdx
,
pVal
);
}
else
{
pVal
->
valType
=
TD_VTYPE_NONE
;
terrno
=
TSDB_CODE_INVALID_PARA
;
if
(
COL_REACH_END
(
colId
,
pIter
->
maxColId
))
return
false
;
}
return
true
;
}
bool
tdSTSRowIterNext
(
STSRowIter
*
pIter
,
SCellVal
*
pVal
)
{
if
(
pIter
->
colIdx
>=
pIter
->
pSchema
->
numOfCols
)
{
return
false
;
...
...
@@ -473,9 +518,10 @@ bool tdSTSRowIterNext(STSRowIter *pIter, SCellVal *pVal) {
}
if
(
TD_IS_TP_ROW
(
pIter
->
pRow
))
{
td
GetTpRowDataOfCo
l
(
pIter
,
pCol
->
type
,
pCol
->
offset
-
sizeof
(
TSKEY
),
pVal
);
td
STSRowIterGetTpVa
l
(
pIter
,
pCol
->
type
,
pCol
->
offset
-
sizeof
(
TSKEY
),
pVal
);
}
else
if
(
TD_IS_KV_ROW
(
pIter
->
pRow
))
{
tdGetKvRowValOfColEx
(
pIter
,
pCol
->
colId
,
&
pIter
->
kvIdx
,
pVal
);
tdSTSRowIterGetKvVal
(
pIter
,
pCol
->
colId
,
&
pIter
->
kvIdx
,
pVal
);
ASSERT
(
0
);
}
else
{
ASSERT
(
0
);
}
...
...
@@ -484,13 +530,40 @@ bool tdSTSRowIterNext(STSRowIter *pIter, SCellVal *pVal) {
return
true
;
}
bool
tdGetKvRowValOfColEx
(
STSRowIter
*
pIter
,
col_id_t
colId
,
col_id_t
*
nIdx
,
SCellVal
*
pVal
)
{
bool
tdSTSRowIterGetTpVal
(
STSRowIter
*
pIter
,
col_type_t
colType
,
int32_t
offset
,
SCellVal
*
pVal
)
{
STSRow
*
pRow
=
pIter
->
pRow
;
if
(
pRow
->
statis
==
0
)
{
pVal
->
valType
=
TD_VTYPE_NORM
;
if
(
IS_VAR_DATA_TYPE
(
colType
))
{
pVal
->
val
=
POINTER_SHIFT
(
pRow
,
*
(
VarDataOffsetT
*
)
POINTER_SHIFT
(
TD_ROW_DATA
(
pRow
),
offset
));
}
else
{
pVal
->
val
=
POINTER_SHIFT
(
TD_ROW_DATA
(
pRow
),
offset
);
}
return
TSDB_CODE_SUCCESS
;
}
if
(
tdGetBitmapValType
(
pIter
->
pBitmap
,
pIter
->
colIdx
-
1
,
&
pVal
->
valType
,
0
)
!=
TSDB_CODE_SUCCESS
)
{
pVal
->
valType
=
TD_VTYPE_NONE
;
return
terrno
;
}
if
(
pVal
->
valType
==
TD_VTYPE_NORM
)
{
if
(
IS_VAR_DATA_TYPE
(
colType
))
{
pVal
->
val
=
POINTER_SHIFT
(
pRow
,
*
(
VarDataOffsetT
*
)
POINTER_SHIFT
(
TD_ROW_DATA
(
pRow
),
offset
));
}
else
{
pVal
->
val
=
POINTER_SHIFT
(
TD_ROW_DATA
(
pRow
),
offset
);
}
}
return
true
;
}
bool
tdSTSRowIterGetKvVal
(
STSRowIter
*
pIter
,
col_id_t
colId
,
col_id_t
*
nIdx
,
SCellVal
*
pVal
)
{
STSRow
*
pRow
=
pIter
->
pRow
;
SKvRowIdx
*
pKvIdx
=
NULL
;
bool
colFound
=
false
;
col_id_t
kvNCols
=
tdRowGetNCols
(
pRow
)
-
1
;
void
*
pColIdx
=
TD_ROW_COL_IDX
(
pRow
);
while
(
*
nIdx
<
kvNCols
)
{
pKvIdx
=
(
SKvRowIdx
*
)
POINTER_SHIFT
(
pColIdx
,
*
nIdx
*
sizeof
(
SKvRowIdx
));
if
(
pKvIdx
->
colId
==
colId
)
{
...
...
@@ -515,51 +588,13 @@ bool tdGetKvRowValOfColEx(STSRowIter *pIter, col_id_t colId, col_id_t *nIdx, SCe
}
}
if
(
tdGetBitmapValType
(
pIter
->
pBitmap
,
(
*
nIdx
)
-
1
,
&
pVal
->
valType
,
0
)
!=
TSDB_CODE_SUCCESS
)
{
pVal
->
valType
=
TD_VTYPE_NONE
;
}
return
true
;
}
bool
tdGetTpRowDataOfCol
(
STSRowIter
*
pIter
,
col_type_t
colType
,
int32_t
offset
,
SCellVal
*
pVal
)
{
STSRow
*
pRow
=
pIter
->
pRow
;
if
(
pRow
->
statis
==
0
)
{
pVal
->
valType
=
TD_VTYPE_NORM
;
if
(
IS_VAR_DATA_TYPE
(
colType
))
{
pVal
->
val
=
POINTER_SHIFT
(
pRow
,
*
(
VarDataOffsetT
*
)
POINTER_SHIFT
(
TD_ROW_DATA
(
pRow
),
offset
));
}
else
{
pVal
->
val
=
POINTER_SHIFT
(
TD_ROW_DATA
(
pRow
),
offset
);
}
return
TSDB_CODE_SUCCESS
;
}
if
(
tdGetBitmapValType
(
pIter
->
pBitmap
,
pIter
->
colIdx
-
1
,
&
pVal
->
valType
,
0
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tdGetBitmapValType
(
pIter
->
pBitmap
,
pIter
->
kvIdx
-
1
,
&
pVal
->
valType
,
0
)
!=
TSDB_CODE_SUCCESS
)
{
pVal
->
valType
=
TD_VTYPE_NONE
;
return
terrno
;
}
if
(
pVal
->
valType
==
TD_VTYPE_NORM
)
{
if
(
IS_VAR_DATA_TYPE
(
colType
))
{
pVal
->
val
=
POINTER_SHIFT
(
pRow
,
*
(
VarDataOffsetT
*
)
POINTER_SHIFT
(
TD_ROW_DATA
(
pRow
),
offset
));
}
else
{
pVal
->
val
=
POINTER_SHIFT
(
TD_ROW_DATA
(
pRow
),
offset
);
}
}
return
true
;
}
static
FORCE_INLINE
int32_t
compareKvRowColId
(
const
void
*
key1
,
const
void
*
key2
)
{
if
(
*
(
col_id_t
*
)
key1
>
((
SKvRowIdx
*
)
key2
)
->
colId
)
{
return
1
;
}
else
if
(
*
(
col_id_t
*
)
key1
<
((
SKvRowIdx
*
)
key2
)
->
colId
)
{
return
-
1
;
}
else
{
return
0
;
}
}
int32_t
tdSTSRowNew
(
SArray
*
pArray
,
STSchema
*
pTSchema
,
STSRow
**
ppRow
)
{
STColumn
*
pTColumn
;
SColVal
*
pColVal
;
...
...
@@ -673,7 +708,7 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow) {
return
0
;
}
static
int32_t
tdCompareColId
(
const
void
*
arg1
,
const
void
*
arg2
)
{
static
FORCE_INLINE
int32_t
tdCompareColId
(
const
void
*
arg1
,
const
void
*
arg2
)
{
int32_t
colId
=
*
(
int32_t
*
)
arg1
;
STColumn
*
pCol
=
(
STColumn
*
)
arg2
;
...
...
@@ -686,6 +721,45 @@ static int32_t tdCompareColId(const void *arg1, const void *arg2) {
}
}
bool
tdSTSRowGetVal
(
STSRowIter
*
pIter
,
col_id_t
colId
,
col_type_t
colType
,
SCellVal
*
pVal
)
{
if
(
colId
==
PRIMARYKEY_TIMESTAMP_COL_ID
)
{
pVal
->
val
=
&
pIter
->
pRow
->
ts
;
pVal
->
valType
=
TD_VTYPE_NORM
;
return
true
;
}
STSRow
*
pRow
=
pIter
->
pRow
;
int16_t
colIdx
=
-
1
;
if
(
TD_IS_TP_ROW
(
pRow
))
{
STSchema
*
pSchema
=
pIter
->
pSchema
;
STColumn
*
pCol
=
(
STColumn
*
)
taosbsearch
(
&
colId
,
pSchema
->
columns
,
pSchema
->
numOfCols
,
sizeof
(
STColumn
),
tdCompareColId
,
TD_EQ
);
if
(
!
pCol
)
{
pVal
->
valType
=
TD_VTYPE_NONE
;
if
(
COL_REACH_END
(
colId
,
pIter
->
maxColId
))
return
false
;
return
true
;
}
#ifdef TD_SUPPORT_BITMAP
colIdx
=
POINTER_DISTANCE
(
pCol
,
pSchema
->
columns
)
/
sizeof
(
STColumn
);
#endif
tdGetTpRowValOfCol
(
pVal
,
pRow
,
pIter
->
pBitmap
,
pCol
->
type
,
pCol
->
offset
-
sizeof
(
TSKEY
),
colIdx
-
1
);
}
else
if
(
TD_IS_KV_ROW
(
pRow
))
{
SKvRowIdx
*
pIdx
=
(
SKvRowIdx
*
)
taosbsearch
(
&
colId
,
TD_ROW_COL_IDX
(
pRow
),
tdRowGetNCols
(
pRow
),
sizeof
(
SKvRowIdx
),
compareKvRowColId
,
TD_EQ
);
#ifdef TD_SUPPORT_BITMAP
if
(
pIdx
)
{
colIdx
=
POINTER_DISTANCE
(
pIdx
,
TD_ROW_COL_IDX
(
pRow
))
/
sizeof
(
SKvRowIdx
);
}
#endif
tdGetKvRowValOfCol
(
pVal
,
pRow
,
pIter
->
pBitmap
,
pIdx
?
pIdx
->
offset
:
-
1
,
colIdx
);
}
else
{
if
(
COL_REACH_END
(
colId
,
pIter
->
maxColId
))
return
false
;
pVal
->
valType
=
TD_VTYPE_NONE
;
}
return
true
;
}
int32_t
tdGetBitmapValTypeII
(
const
void
*
pBitmap
,
int16_t
colIdx
,
TDRowValT
*
pValType
)
{
if
(
!
pBitmap
||
colIdx
<
0
)
{
TASSERT
(
0
);
...
...
@@ -1250,7 +1324,7 @@ void tdSTSRowIterReset(STSRowIter *pIter, STSRow *pRow) {
pIter
->
pRow
=
pRow
;
pIter
->
pBitmap
=
tdGetBitmapAddr
(
pRow
,
pRow
->
type
,
pIter
->
pSchema
->
flen
,
tdRowGetNCols
(
pRow
));
pIter
->
offset
=
0
;
pIter
->
colIdx
=
0
;
pIter
->
colIdx
=
0
;
// PRIMARYKEY_TIMESTAMP_COL_ID;
pIter
->
kvIdx
=
0
;
}
...
...
@@ -1288,4 +1362,4 @@ void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColV
*
pColVal
=
COL_VAL_VALUE
(
pTColumn
->
colId
,
pTColumn
->
type
,
value
);
}
}
}
\ No newline at end of file
source/dnode/vnode/src/tq/tqRead.c
浏览文件 @
a5ef854e
...
...
@@ -325,7 +325,7 @@ int32_t tqRetrieveDataBlock(SSDataBlock* pBlock, STqReader* pReader) {
for
(
int32_t
i
=
0
;
i
<
colActual
;
i
++
)
{
SColumnInfoData
*
pColData
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
SCellVal
sVal
=
{
0
};
if
(
!
tdSTSRowIter
Next
(
&
iter
,
&
sVal
))
{
if
(
!
tdSTSRowIter
Fetch
(
&
iter
,
pColData
->
info
.
colId
,
pColData
->
info
.
type
,
&
sVal
))
{
break
;
}
if
(
colDataAppend
(
pColData
,
curRow
,
sVal
.
val
,
sVal
.
valType
!=
TD_VTYPE_NORM
)
<
0
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录