Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e102f81f
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e102f81f
编写于
8月 12, 2022
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
opti:use suid+uid->tags index to optimize time cost
上级
32f9bc0d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
101 addition
and
57 deletion
+101
-57
source/dnode/vnode/inc/vnode.h
source/dnode/vnode/inc/vnode.h
+2
-2
source/dnode/vnode/src/meta/metaQuery.c
source/dnode/vnode/src/meta/metaQuery.c
+63
-7
source/dnode/vnode/src/meta/metaTable.c
source/dnode/vnode/src/meta/metaTable.c
+4
-1
source/libs/executor/src/executil.c
source/libs/executor/src/executil.c
+30
-45
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+2
-2
未找到文件。
source/dnode/vnode/inc/vnode.h
浏览文件 @
e102f81f
...
...
@@ -91,9 +91,9 @@ typedef struct SMetaEntry SMetaEntry;
void
metaReaderInit
(
SMetaReader
*
pReader
,
SMeta
*
pMeta
,
int32_t
flags
);
void
metaReaderClear
(
SMetaReader
*
pReader
);
int32_t
metaGetTableEntryByUid
(
SMetaReader
*
pReader
,
tb_uid_t
uid
);
//int32_t metaGetTableEntryByUidTest(void *pReader, SArray *uidList
);
int32_t
metaGetTableTags
(
SMeta
*
pMeta
,
uint64_t
suid
,
SArray
*
uidList
,
SArray
*
tags
);
int32_t
metaReadNext
(
SMetaReader
*
pReader
);
const
void
*
metaGetTableTagVal
(
SMetaEntry
*
pEntry
,
int16_t
type
,
STagVal
*
tagVal
);
const
void
*
metaGetTableTagVal
(
void
*
tag
,
int16_t
type
,
STagVal
*
tagVal
);
int
metaGetTableNameByUid
(
void
*
meta
,
uint64_t
uid
,
char
*
tbName
);
typedef
struct
SMetaFltParam
{
...
...
source/dnode/vnode/src/meta/metaQuery.c
浏览文件 @
e102f81f
...
...
@@ -59,6 +59,7 @@ int metaGetTableEntryByUidTest(void* meta, SArray *uidList) {
SArray
*
uidVersion
=
taosArrayInit
(
taosArrayGetSize
(
uidList
),
sizeof
(
STbDbKey
));
SMeta
*
pMeta
=
meta
;
int64_t
version
;
SHashObj
*
uHash
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
,
HASH_NO_LOCK
);
int64_t
stt1
=
taosGetTimestampUs
();
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
uidList
);
i
++
)
{
...
...
@@ -73,10 +74,31 @@ int metaGetTableEntryByUidTest(void* meta, SArray *uidList) {
STbDbKey
tbDbKey
=
{.
version
=
version
,
.
uid
=
*
uid
};
taosArrayPush
(
uidVersion
,
&
tbDbKey
);
taosHashPut
(
uHash
,
uid
,
sizeof
(
int64_t
),
ppVal
,
sizeof
(
int64_t
));
}
int64_t
stt2
=
taosGetTimestampUs
();
qDebug
(
"metaGetTableEntryByUidTest1 rows:%d, cost:%ld us"
,
taosArrayGetSize
(
uidList
),
stt2
-
stt1
);
TBC
*
pCur
=
NULL
;
tdbTbcOpen
(
pMeta
->
pTbDb
,
&
pCur
,
NULL
);
tdbTbcMoveToFirst
(
pCur
);
void
*
pKey
=
NULL
;
int
kLen
=
0
;
while
(
1
){
SMetaReader
pReader
=
{
0
};
int32_t
ret
=
tdbTbcNext
(
pCur
,
&
pKey
,
&
kLen
,
&
pReader
.
pBuf
,
&
pReader
.
szBuf
);
if
(
ret
<
0
)
break
;
STbDbKey
*
tmp
=
(
STbDbKey
*
)
pKey
;
int64_t
*
ver
=
(
int64_t
*
)
taosHashGet
(
uHash
,
&
tmp
->
uid
,
sizeof
(
int64_t
));
if
(
ver
==
NULL
||
*
ver
!=
tmp
->
version
)
continue
;
taosArrayPush
(
readerList
,
&
pReader
);
}
tdbTbcClose
(
pCur
);
taosArrayClear
(
readerList
);
int64_t
stt3
=
taosGetTimestampUs
();
qDebug
(
"metaGetTableEntryByUidTest2 rows:%d, cost:%ld us"
,
taosArrayGetSize
(
uidList
),
stt3
-
stt2
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
uidVersion
);
i
++
)
{
SMetaReader
pReader
=
{
0
};
...
...
@@ -87,8 +109,8 @@ int metaGetTableEntryByUidTest(void* meta, SArray *uidList) {
}
taosArrayPush
(
readerList
,
&
pReader
);
}
int64_t
stt
3
=
taosGetTimestampUs
();
qDebug
(
"metaGetTableEntryByUidTest
2 rows:%d, cost:%ld us"
,
taosArrayGetSize
(
uidList
),
stt3
-
stt2
);
int64_t
stt
4
=
taosGetTimestampUs
();
qDebug
(
"metaGetTableEntryByUidTest
3 rows:%d, cost:%ld us"
,
taosArrayGetSize
(
uidList
),
stt4
-
stt3
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
readerList
);
i
++
){
SMetaReader
*
pReader
=
taosArrayGet
(
readerList
,
i
);
...
...
@@ -100,8 +122,8 @@ int metaGetTableEntryByUidTest(void* meta, SArray *uidList) {
}
metaReaderClear
(
pReader
);
}
int64_t
stt
4
=
taosGetTimestampUs
();
qDebug
(
"metaGetTableEntryByUidTest
3 rows:%d, cost:%ld us"
,
taosArrayGetSize
(
readerList
),
stt4
-
stt3
);
int64_t
stt
5
=
taosGetTimestampUs
();
qDebug
(
"metaGetTableEntryByUidTest
4 rows:%d, cost:%ld us"
,
taosArrayGetSize
(
readerList
),
stt5
-
stt4
);
return
0
;
}
...
...
@@ -801,9 +823,8 @@ SArray *metaGetSmaTbUids(SMeta *pMeta) {
#endif
const
void
*
metaGetTableTagVal
(
SMetaEntry
*
pEntry
,
int16_t
type
,
STagVal
*
val
)
{
ASSERT
(
pEntry
->
type
==
TSDB_CHILD_TABLE
);
STag
*
tag
=
(
STag
*
)
pEntry
->
ctbEntry
.
pTags
;
const
void
*
metaGetTableTagVal
(
void
*
pTag
,
int16_t
type
,
STagVal
*
val
)
{
STag
*
tag
=
(
STag
*
)
pTag
;
if
(
type
==
TSDB_DATA_TYPE_JSON
)
{
return
tag
;
}
...
...
@@ -940,3 +961,38 @@ END:
return
ret
;
}
int32_t
metaGetTableTags
(
SMeta
*
pMeta
,
uint64_t
suid
,
SArray
*
uidList
,
SArray
*
tags
)
{
SMCtbCursor
*
pCur
=
metaOpenCtbCursor
(
pMeta
,
suid
);
SHashObj
*
uHash
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
,
HASH_NO_LOCK
);
size_t
len
=
taosArrayGetSize
(
uidList
);
if
(
len
>
0
){
for
(
int
i
=
0
;
i
<
len
;
i
++
){
int64_t
*
uid
=
taosArrayGet
(
uidList
,
i
);
taosHashPut
(
uHash
,
uid
,
sizeof
(
int64_t
),
&
i
,
sizeof
(
i
));
}
}
while
(
1
)
{
tb_uid_t
id
=
metaCtbCursorNext
(
pCur
);
if
(
id
==
0
)
{
break
;
}
if
(
len
>
0
&&
taosHashGet
(
uHash
,
&
id
,
sizeof
(
int64_t
))
==
NULL
){
continue
;
}
void
*
tag
=
taosMemoryMalloc
(
pCur
->
vLen
);
memcpy
(
tag
,
pCur
->
pVal
,
pCur
->
vLen
);
taosArrayPush
(
tags
,
&
tag
);
if
(
len
==
0
){
taosArrayPush
(
uidList
,
&
id
);
}
}
taosHashCleanup
(
uHash
);
metaCloseCtbCursor
(
pCur
);
return
TSDB_CODE_SUCCESS
;
}
source/dnode/vnode/src/meta/metaTable.c
浏览文件 @
e102f81f
...
...
@@ -864,6 +864,9 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
metaUpdateTagIdx
(
pMeta
,
&
ctbEntry
);
}
SCtbIdxKey
ctbIdxKey
=
{.
suid
=
ctbEntry
.
ctbEntry
.
suid
,
.
uid
=
uid
};
tdbTbUpsert
(
pMeta
->
pCtbIdx
,
&
ctbIdxKey
,
sizeof
(
ctbIdxKey
),
ctbEntry
.
ctbEntry
.
pTags
,
((
STag
*
)(
ctbEntry
.
ctbEntry
.
pTags
))
->
len
,
&
pMeta
->
txn
);
tDecoderClear
(
&
dc1
);
tDecoderClear
(
&
dc2
);
if
(
ctbEntry
.
ctbEntry
.
pTags
)
taosMemoryFree
((
void
*
)
ctbEntry
.
ctbEntry
.
pTags
);
...
...
@@ -1061,7 +1064,7 @@ static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
static
int
metaUpdateCtbIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
SCtbIdxKey
ctbIdxKey
=
{.
suid
=
pME
->
ctbEntry
.
suid
,
.
uid
=
pME
->
uid
};
return
tdbTbInsert
(
pMeta
->
pCtbIdx
,
&
ctbIdxKey
,
sizeof
(
ctbIdxKey
),
NULL
,
0
,
&
pMeta
->
txn
);
return
tdbTbInsert
(
pMeta
->
pCtbIdx
,
&
ctbIdxKey
,
sizeof
(
ctbIdxKey
),
pME
->
ctbEntry
.
pTags
,
((
STag
*
)(
pME
->
ctbEntry
.
pTags
))
->
len
,
&
pMeta
->
txn
);
}
int
metaCreateTagIdxKey
(
tb_uid_t
suid
,
int32_t
cid
,
const
void
*
pTagData
,
int32_t
nTagData
,
int8_t
type
,
tb_uid_t
uid
,
...
...
source/libs/executor/src/executil.c
浏览文件 @
e102f81f
...
...
@@ -221,7 +221,7 @@ EDealRes doTranslateTagExpr(SNode** pNode, void* pContext) {
STagVal
tagVal
=
{
0
};
tagVal
.
cid
=
pSColumnNode
->
colId
;
const
char
*
p
=
metaGetTableTagVal
(
&
mr
->
me
,
pSColumnNode
->
node
.
resType
.
type
,
&
tagVal
);
const
char
*
p
=
metaGetTableTagVal
(
mr
->
me
.
ctbEntry
.
pTags
,
pSColumnNode
->
node
.
resType
.
type
,
&
tagVal
);
if
(
p
==
NULL
)
{
res
->
node
.
resType
.
type
=
TSDB_DATA_TYPE_NULL
;
}
else
if
(
pSColumnNode
->
node
.
resType
.
type
==
TSDB_DATA_TYPE_JSON
)
{
...
...
@@ -343,10 +343,11 @@ static int32_t createResultData(SDataType* pType, int32_t numOfRows, SScalarPara
return
TSDB_CODE_SUCCESS
;
}
SColumnInfoData
*
getColInfoResult
(
void
*
metaHandle
,
SArray
*
pTable
List
,
SNode
*
pTagCond
){
SColumnInfoData
*
getColInfoResult
(
void
*
metaHandle
,
uint64_t
suid
,
SArray
*
uid
List
,
SNode
*
pTagCond
){
int32_t
code
=
TSDB_CODE_SUCCESS
;
SArray
*
pBlockList
=
NULL
;
SSDataBlock
*
pResBlock
=
NULL
;
SArray
*
tags
=
NULL
;
SScalarParam
output
=
{
0
};
tagFilterAssist
ctx
=
{
0
};
...
...
@@ -375,35 +376,30 @@ SColumnInfoData* getColInfoResult(void* metaHandle, SArray* pTableList, SNode* p
blockDataAppendColInfo
(
pResBlock
,
&
colInfo
);
}
int32_t
rows
=
taosArrayGetSize
(
pTableList
);
code
=
blockDataEnsureCapacity
(
pResBlock
,
rows
);
int64_t
stt
=
taosGetTimestampUs
();
tags
=
taosArrayInit
(
8
,
POINTER_BYTES
);
code
=
metaGetTableTags
(
metaHandle
,
suid
,
uidList
,
tags
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
code
;
goto
end
;
}
// int64_t stt = taosGetTimestampUs();
// SArray* arrAssist = taosArrayInit(rows, sizeof(SMetaReader));
// SArray* uidList = taosArrayInit(rows, sizeof(uint64_t));
// for (int32_t i = 0; i < rows; i++) {
// STableKeyInfo* info = taosArrayGet(pTableList, i);
// taosArrayPush(uidList, &info->uid);
// }
int32_t
rows
=
taosArrayGetSize
(
uidList
);
// code = metaGetTableEntryByUidTest(metaHandle, uidList);
int64_t
stt1
=
taosGetTimestampUs
();
qDebug
(
"generate tag meta rows:%d, cost:%ld us"
,
rows
,
stt1
-
stt
);
//
// int64_t stt1 = taosGetTimestampUs();
// qDebug("generate tag meta rows:%d, cost:%ld us", rows, stt1-stt);
code
=
blockDataEnsureCapacity
(
pResBlock
,
rows
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
code
;
goto
end
;
}
int64_t
st
=
taosGetTimestampUs
();
for
(
int32_t
i
=
0
;
i
<
rows
;
i
++
)
{
STableKeyInfo
*
info
=
taosArrayGet
(
pTable
List
,
i
);
uint64_t
*
uid
=
taosArrayGet
(
uid
List
,
i
);
void
*
tag
=
taosArrayGet
(
tags
,
i
);
// int64_t stt = taosGetTimestampUs();
SMetaReader
mr
=
{
0
};
metaReaderInit
(
&
mr
,
metaHandle
,
0
);
code
=
metaGetTableEntryByUid
(
&
mr
,
info
->
uid
);
// int64_t stt1 = taosGetTimestampUs();
// qDebug("generate tag get meta rows:%d, cost:%ld ms", rows, stt1-stt);
// SMetaReader *mr = taosArrayGet(arrAssist, i);
...
...
@@ -412,7 +408,7 @@ SColumnInfoData* getColInfoResult(void* metaHandle, SArray* pTableList, SNode* p
STagVal
tagVal
=
{
0
};
tagVal
.
cid
=
pColInfo
->
info
.
colId
;
// int64_t t1 = taosGetTimestampUs();
const
char
*
p
=
metaGetTableTagVal
(
&
mr
.
me
,
pColInfo
->
info
.
type
,
&
tagVal
);
const
char
*
p
=
metaGetTableTagVal
(
tag
,
pColInfo
->
info
.
type
,
&
tagVal
);
// int64_t t2 = taosGetTimestampUs();
// qDebug("generate tag inner1 rows:%d, cost:%ld ms", rows, t2-t1);
...
...
@@ -430,7 +426,6 @@ SColumnInfoData* getColInfoResult(void* metaHandle, SArray* pTableList, SNode* p
}
// int64_t stt2 = taosGetTimestampUs();
// qDebug("generate tag get block rows:%d, cost:%ld us", rows, stt2-stt1);
metaReaderClear
(
&
mr
);
}
pResBlock
->
info
.
rows
=
rows
;
...
...
@@ -454,6 +449,7 @@ SColumnInfoData* getColInfoResult(void* metaHandle, SArray* pTableList, SNode* p
qDebug
(
"calculate tag block rows:%d, cost:%ld us"
,
rows
,
st2
-
st1
);
end:
taosArrayDestroy
(
tags
);
taosHashCleanup
(
ctx
.
colHash
);
taosArrayDestroy
(
ctx
.
cInfoList
);
blockDataDestroy
(
pResBlock
);
...
...
@@ -471,8 +467,8 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode,
}
uint64_t
tableUid
=
pScanNode
->
uid
;
pListInfo
->
suid
=
pScanNode
->
suid
;
SArray
*
res
=
taosArrayInit
(
8
,
sizeof
(
uint64_t
));
if
(
pScanNode
->
tableType
==
TSDB_SUPER_TABLE
)
{
if
(
pTagIndexCond
)
{
...
...
@@ -480,42 +476,24 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode,
.
metaEx
=
metaHandle
,
.
idx
=
tsdbGetIdx
(
metaHandle
),
.
ivtIdx
=
tsdbGetIvtIdx
(
metaHandle
),
.
suid
=
tableUid
};
int64_t
stt
=
taosGetTimestampUs
();
SArray
*
res
=
taosArrayInit
(
8
,
sizeof
(
uint64_t
));
SIdxFltStatus
status
=
SFLT_NOT_INDEX
;
code
=
doFilterTag
(
pTagIndexCond
,
&
metaArg
,
res
,
&
status
);
if
(
code
!=
0
||
status
==
SFLT_NOT_INDEX
)
{
qError
(
"failed to get tableIds from index, reason:%s, suid:%"
PRIu64
,
tstrerror
(
code
),
tableUid
);
// code = TSDB_CODE_INDEX_REBUILDING;
code
=
vnodeGetAllTableList
(
pVnode
,
tableUid
,
pListInfo
->
pTableList
);
}
else
{
qDebug
(
"success to get tableIds, size:%d, suid:%"
PRIu64
,
(
int
)
taosArrayGetSize
(
res
),
tableUid
);
}
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
res
);
i
++
)
{
STableKeyInfo
info
=
{.
uid
=
*
(
uint64_t
*
)
taosArrayGet
(
res
,
i
),
.
groupId
=
0
};
taosArrayPush
(
pListInfo
->
pTableList
,
&
info
);
}
taosArrayDestroy
(
res
);
int64_t
stt1
=
taosGetTimestampUs
();
qDebug
(
"generate table list, cost:%ld us"
,
stt1
-
stt
);
}
else
{
code
=
vnodeGetAllTableList
(
pVnode
,
tableUid
,
pListInfo
->
pTableList
);
}
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
qError
(
"failed to get tableIds, reason:%s, suid:%"
PRIu64
,
tstrerror
(
code
),
tableUid
);
terrno
=
code
;
return
code
;
}
}
else
{
// Create one table group.
STableKeyInfo
info
=
{.
uid
=
tableUid
,
.
groupId
=
0
};
taosArrayPush
(
pListInfo
->
pTableList
,
&
info
);
taosArrayPush
(
res
,
&
tableUid
);
}
if
(
pTagCond
&&
taosArrayGetSize
(
pListInfo
->
pTableList
)
>
0
)
{
SColumnInfoData
*
pColInfoData
=
getColInfoResult
(
metaHandle
,
pListInfo
->
pTableList
,
pTagCond
);
if
(
pTagCond
)
{
SColumnInfoData
*
pColInfoData
=
getColInfoResult
(
metaHandle
,
pListInfo
->
suid
,
res
,
pTagCond
);
if
(
terrno
!=
TDB_CODE_SUCCESS
){
colDataDestroy
(
pColInfoData
);
taosArrayDestroy
(
res
);
return
terrno
;
}
...
...
@@ -532,6 +510,13 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode,
colDataDestroy
(
pColInfoData
);
}
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
res
);
i
++
)
{
STableKeyInfo
info
=
{.
uid
=
*
(
uint64_t
*
)
taosArrayGet
(
res
,
i
),
.
groupId
=
0
};
taosArrayPush
(
pListInfo
->
pTableList
,
&
info
);
}
taosArrayDestroy
(
res
);
pListInfo
->
pGroupList
=
taosArrayInit
(
4
,
POINTER_BYTES
);
if
(
pListInfo
->
pGroupList
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
e102f81f
...
...
@@ -439,7 +439,7 @@ int32_t addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int
}
else
{
// these are tags
STagVal
tagVal
=
{
0
};
tagVal
.
cid
=
pExpr
->
base
.
pParam
[
0
].
pCol
->
colId
;
const
char
*
p
=
metaGetTableTagVal
(
&
mr
.
me
,
pColInfoData
->
info
.
type
,
&
tagVal
);
const
char
*
p
=
metaGetTableTagVal
(
mr
.
me
.
ctbEntry
.
pTags
,
pColInfoData
->
info
.
type
,
&
tagVal
);
char
*
data
=
NULL
;
if
(
pColInfoData
->
info
.
type
!=
TSDB_DATA_TYPE_JSON
&&
p
!=
NULL
)
{
...
...
@@ -2569,7 +2569,7 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) {
}
else
{
// it is a tag value
STagVal
val
=
{
0
};
val
.
cid
=
pExprInfo
[
j
].
base
.
pParam
[
0
].
pCol
->
colId
;
const
char
*
p
=
metaGetTableTagVal
(
&
mr
.
me
,
pDst
->
info
.
type
,
&
val
);
const
char
*
p
=
metaGetTableTagVal
(
mr
.
me
.
ctbEntry
.
pTags
,
pDst
->
info
.
type
,
&
val
);
char
*
data
=
NULL
;
if
(
pDst
->
info
.
type
!=
TSDB_DATA_TYPE_JSON
&&
p
!=
NULL
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录