Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
fa0b70b1
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1193
Star
22018
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看板
提交
fa0b70b1
编写于
1月 31, 2023
作者:
dengyihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
opt tag filter
上级
6100a0d5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
52 addition
and
23 deletion
+52
-23
source/dnode/vnode/src/meta/metaQuery.c
source/dnode/vnode/src/meta/metaQuery.c
+18
-15
source/libs/executor/src/executil.c
source/libs/executor/src/executil.c
+34
-8
未找到文件。
source/dnode/vnode/src/meta/metaQuery.c
浏览文件 @
fa0b70b1
...
...
@@ -1261,7 +1261,7 @@ int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
goto
END
;
}
bool
first
=
true
;
int
count
=
0
;
int32_t
valid
=
0
;
while
(
1
)
{
void
*
entryKey
=
NULL
,
*
entryVal
=
NULL
;
...
...
@@ -1269,24 +1269,26 @@ int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
valid
=
tdbTbcGet
(
pCursor
->
pCur
,
(
const
void
**
)
&
entryKey
,
&
nEntryKey
,
(
const
void
**
)
&
entryVal
,
&
nEntryVal
);
if
(
valid
<
0
)
{
tdbFree
(
entryVal
);
break
;
}
STagIdxKey
*
p
=
entryKey
;
if
(
p
==
NULL
)
break
;
if
(
p
->
type
!=
pCursor
->
type
)
{
if
(
first
)
{
valid
=
param
->
reverse
?
tdbTbcMoveToPrev
(
pCursor
->
pCur
)
:
tdbTbcMoveToNext
(
pCursor
->
pCur
);
if
(
valid
<
0
)
break
;
continue
;
}
else
{
if
(
count
>=
2
)
{
if
(
p
->
type
!=
pCursor
->
type
||
p
->
suid
!=
pCursor
->
suid
)
{
break
;
}
}
else
{
count
++
;
if
(
p
->
type
!=
pCursor
->
type
)
{
valid
=
param
->
reverse
?
tdbTbcMoveToPrev
(
pCursor
->
pCur
)
:
tdbTbcMoveToNext
(
pCursor
->
pCur
);
if
(
valid
<
0
)
{
break
;
}
else
{
continue
;
}
}
}
if
(
p
->
suid
!=
pKey
->
suid
)
{
break
;
}
first
=
false
;
int32_t
cmp
=
(
*
param
->
filterFunc
)(
p
->
data
,
pKey
->
data
,
pKey
->
type
);
if
(
cmp
==
0
)
{
// match
...
...
@@ -1298,11 +1300,13 @@ int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
}
taosArrayPush
(
pUids
,
&
tuid
);
}
else
if
(
cmp
==
1
)
{
if
(
count
>=
2
)
break
;
// not match but should continue to iter
}
else
{
// not match and no more result
break
;
if
(
count
>=
2
)
break
;
}
count
++
;
valid
=
param
->
reverse
?
tdbTbcMoveToPrev
(
pCursor
->
pCur
)
:
tdbTbcMoveToNext
(
pCursor
->
pCur
);
if
(
valid
<
0
)
{
break
;
...
...
@@ -1335,7 +1339,7 @@ static int32_t metaGetTableTagByUid(SMeta *pMeta, int64_t suid, int64_t uid, voi
return
ret
;
}
int32_t
metaGetTableTagsByUids
(
SMeta
*
pMeta
,
int64_t
suid
,
SArray
*
uidList
,
SHashObj
*
tags
)
{
const
int32_t
LIMIT
=
128
;
const
int32_t
LIMIT
=
4096
;
int32_t
isLock
=
false
;
int32_t
sz
=
uidList
?
taosArrayGetSize
(
uidList
)
:
0
;
...
...
@@ -1377,7 +1381,6 @@ int32_t metaGetTableTags(SMeta *pMeta, uint64_t suid, SArray *uidList, SHashObj
int64_t
*
uid
=
taosArrayGet
(
uidList
,
i
);
taosHashPut
(
uHash
,
uid
,
sizeof
(
int64_t
),
&
i
,
sizeof
(
i
));
}
return
0
;
}
while
(
1
)
{
...
...
source/libs/executor/src/executil.c
浏览文件 @
fa0b70b1
...
...
@@ -43,7 +43,14 @@ typedef struct tagFilterAssist {
SArray
*
cInfoList
;
}
tagFilterAssist
;
static
int32_t
removeInvalidTable
(
SArray
*
uids
,
SHashObj
*
tags
);
typedef
enum
{
FILTER_NO_LOGIC
=
1
,
FILTER_AND
,
FILTER_OTHER
,
}
FilterCondType
;
static
FilterCondType
checkTagCond
(
SNode
*
cond
);
static
int32_t
removeInvalidTable
(
SArray
*
uids
,
SHashObj
*
tags
);
static
int32_t
optimizeTbnameInCond
(
void
*
metaHandle
,
int64_t
suid
,
SArray
*
list
,
SNode
*
pTagCond
,
SHashObj
*
tags
);
static
int32_t
optimizeTbnameInCondImpl
(
void
*
metaHandle
,
int64_t
suid
,
SArray
*
list
,
SNode
*
pTagCond
);
static
int32_t
getTableList
(
void
*
metaHandle
,
void
*
pVnode
,
SScanPhysiNode
*
pScanNode
,
SNode
*
pTagCond
,
...
...
@@ -392,7 +399,8 @@ static int32_t createResultData(SDataType* pType, int32_t numOfRows, SScalarPara
return
TSDB_CODE_SUCCESS
;
}
static
SColumnInfoData
*
getColInfoResult
(
void
*
metaHandle
,
int64_t
suid
,
SArray
*
uidList
,
SNode
*
pTagCond
)
{
static
SColumnInfoData
*
getColInfoResult
(
void
*
metaHandle
,
int64_t
suid
,
SArray
*
uidList
,
SNode
*
pTagCond
,
SIdxFltStatus
status
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
SArray
*
pBlockList
=
NULL
;
SSDataBlock
*
pResBlock
=
NULL
;
...
...
@@ -430,14 +438,22 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, int64_t suid, SArray*
// int64_t stt = taosGetTimestampUs();
tags
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
,
HASH_NO_LOCK
);
FilterCondType
condType
=
checkTagCond
(
pTagCond
);
int32_t
filter
=
optimizeTbnameInCond
(
metaHandle
,
suid
,
uidList
,
pTagCond
,
tags
);
if
(
filter
==
-
1
)
{
code
=
metaGetTableTags
(
metaHandle
,
suid
,
uidList
,
tags
);
if
((
condType
==
FILTER_NO_LOGIC
||
condType
==
FILTER_AND
)
&&
status
!=
SFLT_NOT_INDEX
)
{
code
=
metaGetTableTagsByUids
(
metaHandle
,
suid
,
uidList
,
tags
);
}
else
{
code
=
metaGetTableTags
(
metaHandle
,
suid
,
uidList
,
tags
);
}
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
qError
(
"failed to get table tags from meta, reason:%s, suid:%"
PRIu64
,
tstrerror
(
code
),
suid
);
terrno
=
code
;
goto
end
;
}
}
else
{
qDebug
(
"succ to get table tags from meta by tbname in cond, suid:%"
PRIu64
,
suid
);
}
if
(
suid
!=
0
)
{
removeInvalidTable
(
uidList
,
tags
);
...
...
@@ -842,6 +858,15 @@ static int tableUidCompare(const void* a, const void* b) {
return
u1
<
u2
?
-
1
:
1
;
}
static
FilterCondType
checkTagCond
(
SNode
*
cond
)
{
if
(
nodeType
(
cond
)
==
QUERY_NODE_OPERATOR
)
{
return
FILTER_NO_LOGIC
;
}
if
(
nodeType
(
cond
)
!=
QUERY_NODE_LOGIC_CONDITION
||
((
SLogicConditionNode
*
)
cond
)
->
condType
!=
LOGIC_COND_TYPE_AND
)
{
return
FILTER_AND
;
}
return
FILTER_OTHER
;
}
static
int32_t
optimizeTbnameInCond
(
void
*
metaHandle
,
int64_t
suid
,
SArray
*
list
,
SNode
*
cond
,
SHashObj
*
tags
)
{
int32_t
ret
=
-
1
;
if
(
nodeType
(
cond
)
==
QUERY_NODE_OPERATOR
)
{
...
...
@@ -983,13 +1008,14 @@ static void genTagFilterDigest(const SNode* pTagCond, T_MD5_CTX* pContext) {
taosMemoryFree
(
payload
);
}
static
int32_t
doFilterByTagCond
(
STableListInfo
*
pListInfo
,
SArray
*
res
,
SNode
*
pTagCond
,
void
*
metaHandle
)
{
static
int32_t
doFilterByTagCond
(
STableListInfo
*
pListInfo
,
SArray
*
res
,
SNode
*
pTagCond
,
void
*
metaHandle
,
SIdxFltStatus
status
)
{
if
(
pTagCond
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
terrno
=
TDB_CODE_SUCCESS
;
SColumnInfoData
*
pColInfoData
=
getColInfoResult
(
metaHandle
,
pListInfo
->
suid
,
res
,
pTagCond
);
SColumnInfoData
*
pColInfoData
=
getColInfoResult
(
metaHandle
,
pListInfo
->
suid
,
res
,
pTagCond
,
status
);
if
(
terrno
!=
TDB_CODE_SUCCESS
)
{
colDataDestroy
(
pColInfoData
);
taosMemoryFreeClear
(
pColInfoData
);
...
...
@@ -1034,12 +1060,13 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode,
pListInfo
->
suid
=
pScanNode
->
suid
;
SArray
*
res
=
taosArrayInit
(
8
,
sizeof
(
uint64_t
));
SIdxFltStatus
status
=
SFLT_NOT_INDEX
;
if
(
pScanNode
->
tableType
!=
TSDB_SUPER_TABLE
)
{
if
(
metaIsTableExist
(
metaHandle
,
tableUid
))
{
taosArrayPush
(
res
,
&
tableUid
);
}
code
=
doFilterByTagCond
(
pListInfo
,
res
,
pTagCond
,
metaHandle
);
code
=
doFilterByTagCond
(
pListInfo
,
res
,
pTagCond
,
metaHandle
,
status
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -1064,7 +1091,6 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode,
SIndexMetaArg
metaArg
=
{
.
metaEx
=
metaHandle
,
.
idx
=
tsdbGetIdx
(
metaHandle
),
.
ivtIdx
=
tsdbGetIvtIdx
(
metaHandle
),
.
suid
=
tableUid
};
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
);
...
...
@@ -1073,7 +1099,7 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode,
}
}
code
=
doFilterByTagCond
(
pListInfo
,
res
,
pTagCond
,
metaHandle
);
code
=
doFilterByTagCond
(
pListInfo
,
res
,
pTagCond
,
metaHandle
,
status
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录