Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
82f4db30
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
82f4db30
编写于
1月 14, 2023
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: do some internal refactor.
上级
7aee35c4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
37 deletion
+48
-37
source/dnode/vnode/src/meta/metaQuery.c
source/dnode/vnode/src/meta/metaQuery.c
+15
-11
source/libs/executor/src/executil.c
source/libs/executor/src/executil.c
+33
-26
未找到文件。
source/dnode/vnode/src/meta/metaQuery.c
浏览文件 @
82f4db30
...
...
@@ -1368,7 +1368,7 @@ int32_t metaGetTableTagsByUids(SMeta *pMeta, int64_t suid, SArray *uidList, SHas
taosHashPut
(
tags
,
id
,
sizeof
(
tb_uid_t
),
val
,
len
);
tdbFree
(
val
);
}
else
{
metaError
(
"vgId:%d, failed to table
ID
s, suid: %"
PRId64
", uid: %"
PRId64
""
,
TD_VID
(
pMeta
->
pVnode
),
suid
,
metaError
(
"vgId:%d, failed to table
tag
s, suid: %"
PRId64
", uid: %"
PRId64
""
,
TD_VID
(
pMeta
->
pVnode
),
suid
,
*
id
);
}
}
...
...
@@ -1381,31 +1381,35 @@ int32_t metaGetTableTagsByUids(SMeta *pMeta, int64_t suid, SArray *uidList, SHas
int32_t
metaGetTableTags
(
SMeta
*
pMeta
,
uint64_t
suid
,
SArray
*
uidList
,
SHashObj
*
tags
)
{
SMCtbCursor
*
pCur
=
metaOpenCtbCursor
(
pMeta
,
suid
,
1
);
SHashObj
*
uHash
=
NULL
;
size_t
len
=
taosArrayGetSize
(
uidList
);
// len > 0 means there already have uids
// If len > 0 means there already have uids, and we only want the
// tags of the specified tables, of which uid in the uid list. Otherwise, all table tags are retrieved and kept
// in the hash map, that may require a lot of memory
SHashObj
*
pSepecifiedUidMap
=
NULL
;
size_t
len
=
taosArrayGetSize
(
uidList
);
if
(
len
>
0
)
{
uHash
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
,
HASH_NO_LOCK
);
pSepecifiedUidMap
=
taosHashInit
(
len
/
0
.
7
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
,
HASH_NO_LOCK
);
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
int64_t
*
uid
=
taosArrayGet
(
uidList
,
i
);
taosHashPut
(
uHash
,
uid
,
sizeof
(
int64_t
),
&
i
,
sizeof
(
i
)
);
taosHashPut
(
pSepecifiedUidMap
,
uid
,
sizeof
(
int64_t
),
0
,
0
);
}
}
while
(
1
)
{
tb_uid_t
id
=
metaCtbCursorNext
(
pCur
);
if
(
id
==
0
)
{
tb_uid_t
u
id
=
metaCtbCursorNext
(
pCur
);
if
(
u
id
==
0
)
{
break
;
}
if
(
len
>
0
&&
taosHashGet
(
uHash
,
&
id
,
sizeof
(
int64_t
))
==
NULL
)
{
if
(
len
>
0
&&
taosHashGet
(
pSepecifiedUidMap
,
&
u
id
,
sizeof
(
int64_t
))
==
NULL
)
{
continue
;
}
else
if
(
len
==
0
)
{
taosArrayPush
(
uidList
,
&
id
);
taosArrayPush
(
uidList
,
&
u
id
);
}
taosHashPut
(
tags
,
&
id
,
sizeof
(
int64_t
),
pCur
->
pVal
,
pCur
->
vLen
);
taosHashPut
(
tags
,
&
uid
,
sizeof
(
u
int64_t
),
pCur
->
pVal
,
pCur
->
vLen
);
}
taosHashCleanup
(
uHash
);
taosHashCleanup
(
pSepecifiedUidMap
);
metaCloseCtbCursor
(
pCur
,
1
);
return
TSDB_CODE_SUCCESS
;
}
...
...
source/libs/executor/src/executil.c
浏览文件 @
82f4db30
...
...
@@ -43,9 +43,9 @@ typedef struct tagFilterAssist {
SArray
*
cInfoList
;
}
tagFilterAssist
;
static
int32_t
removeInvalid
Table
(
SArray
*
uids
,
SHashObj
*
tags
);
static
int32_t
removeInvalid
Uid
(
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
*
l
ist
,
SNode
*
pTagCond
);
static
int32_t
optimizeTbnameInCondImpl
(
void
*
metaHandle
,
int64_t
suid
,
SArray
*
pExistedUidL
ist
,
SNode
*
pTagCond
);
static
int32_t
getTableList
(
void
*
metaHandle
,
void
*
pVnode
,
SScanPhysiNode
*
pScanNode
,
SNode
*
pTagCond
,
SNode
*
pTagIndexCond
,
STableListInfo
*
pListInfo
);
...
...
@@ -433,6 +433,7 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, int64_t suid, SArray*
int32_t
filter
=
optimizeTbnameInCond
(
metaHandle
,
suid
,
uidList
,
pTagCond
,
tags
);
if
(
filter
==
-
1
)
{
// here we retrieve all tags from the vnode table-meta store
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
);
...
...
@@ -440,22 +441,23 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, int64_t suid, SArray*
goto
end
;
}
}
if
(
suid
!=
0
)
{
removeInvalid
Table
(
uidList
,
tags
);
removeInvalid
Uid
(
uidList
,
tags
);
}
int32_t
rows
=
taosArrayGetSize
(
uidList
);
if
(
rows
==
0
)
{
int32_t
size
=
taosArrayGetSize
(
uidList
);
if
(
size
==
0
)
{
goto
end
;
}
code
=
blockDataEnsureCapacity
(
pResBlock
,
rows
);
code
=
blockDataEnsureCapacity
(
pResBlock
,
size
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
code
;
goto
end
;
}
for
(
int32_t
i
=
0
;
i
<
rows
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
int64_t
*
uid
=
taosArrayGet
(
uidList
,
i
);
for
(
int32_t
j
=
0
;
j
<
taosArrayGetSize
(
pResBlock
->
pDataBlock
);
j
++
)
{
SColumnInfoData
*
pColInfo
=
(
SColumnInfoData
*
)
taosArrayGet
(
pResBlock
->
pDataBlock
,
j
);
...
...
@@ -468,13 +470,14 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, int64_t suid, SArray*
qDebug
(
"tagfilter uid:%ld, tbname:%s"
,
*
uid
,
str
+
2
);
#endif
}
else
{
void
*
tag
=
taosHashGet
(
tags
,
uid
,
sizeof
(
int64_t
));
if
(
tag
==
NULL
)
{
void
*
pTagsVal
=
taosHashGet
(
tags
,
uid
,
sizeof
(
u
int64_t
));
if
(
pTagsVal
==
NULL
)
{
continue
;
}
STagVal
tagVal
=
{
0
};
tagVal
.
cid
=
pColInfo
->
info
.
colId
;
const
char
*
p
=
metaGetTableTagVal
(
tag
,
pColInfo
->
info
.
type
,
&
tagVal
);
const
char
*
p
=
metaGetTableTagVal
(
pTagsVal
,
pColInfo
->
info
.
type
,
&
tagVal
);
if
(
p
==
NULL
||
(
pColInfo
->
info
.
type
==
TSDB_DATA_TYPE_JSON
&&
((
STag
*
)
p
)
->
nTag
==
0
))
{
colDataAppend
(
pColInfo
,
i
,
p
,
true
);
...
...
@@ -504,7 +507,7 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, int64_t suid, SArray*
}
}
pResBlock
->
info
.
rows
=
rows
;
pResBlock
->
info
.
rows
=
size
;
// int64_t st1 = taosGetTimestampUs();
// qDebug("generate tag block rows:%d, cost:%ld us", rows, st1-st);
...
...
@@ -513,7 +516,7 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, int64_t suid, SArray*
taosArrayPush
(
pBlockList
,
&
pResBlock
);
SDataType
type
=
{.
type
=
TSDB_DATA_TYPE_BOOL
,
.
bytes
=
sizeof
(
bool
)};
code
=
createResultData
(
&
type
,
rows
,
&
output
);
code
=
createResultData
(
&
type
,
size
,
&
output
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
code
;
qError
(
"failed to create result, reason:%s"
,
tstrerror
(
code
));
...
...
@@ -850,7 +853,7 @@ static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list
ret
=
optimizeTbnameInCondImpl
(
metaHandle
,
suid
,
list
,
cond
);
if
(
ret
!=
-
1
)
{
metaGetTableTagsByUids
(
metaHandle
,
suid
,
list
,
tags
);
removeInvalid
Table
(
list
,
tags
);
removeInvalid
Uid
(
list
,
tags
);
}
}
...
...
@@ -882,7 +885,7 @@ static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list
if
(
hasTbnameCond
)
{
ret
=
metaGetTableTagsByUids
(
metaHandle
,
suid
,
list
,
tags
);
removeInvalid
Table
(
list
,
tags
);
removeInvalid
Uid
(
list
,
tags
);
}
return
ret
;
...
...
@@ -891,12 +894,15 @@ static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list
/*
* handle invalid uid
*/
static
int32_t
removeInvalidTable
(
SArray
*
uids
,
SHashObj
*
tags
)
{
if
(
taosArrayGetSize
(
uids
)
<=
0
)
return
0
;
static
int32_t
removeInvalidUid
(
SArray
*
uids
,
SHashObj
*
tags
)
{
int32_t
size
=
taosArrayGetSize
(
uids
);
if
(
size
<=
0
)
{
return
0
;
}
SArray
*
validUid
=
taosArrayInit
(
taosArrayGetSize
(
uids
)
,
sizeof
(
int64_t
));
SArray
*
validUid
=
taosArrayInit
(
size
,
sizeof
(
int64_t
));
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
uids
)
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
int64_t
*
uid
=
taosArrayGet
(
uids
,
i
);
if
(
taosHashGet
(
tags
,
uid
,
sizeof
(
int64_t
))
!=
NULL
)
{
taosArrayPush
(
validUid
,
uid
);
...
...
@@ -908,7 +914,8 @@ static int32_t removeInvalidTable(SArray* uids, SHashObj* tags) {
return
0
;
}
static
int32_t
optimizeTbnameInCondImpl
(
void
*
metaHandle
,
int64_t
suid
,
SArray
*
list
,
SNode
*
pTagCond
)
{
// only return uid that does not contained in pExistedUidList
static
int32_t
optimizeTbnameInCondImpl
(
void
*
metaHandle
,
int64_t
suid
,
SArray
*
pExistedUidList
,
SNode
*
pTagCond
)
{
if
(
nodeType
(
pTagCond
)
!=
QUERY_NODE_OPERATOR
)
{
return
-
1
;
}
...
...
@@ -931,11 +938,11 @@ static int32_t optimizeTbnameInCondImpl(void* metaHandle, int64_t suid, SArray*
SArray
*
pTbList
=
getTableNameList
(
pList
);
int32_t
numOfTables
=
taosArrayGetSize
(
pTbList
);
SHashObj
*
uHash
=
NULL
;
size_t
listlen
=
taosArrayGetSize
(
l
ist
);
// len > 0 means there already have uids
if
(
listlen
>
0
)
{
uHash
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
,
HASH_NO_LOCK
);
for
(
int
i
=
0
;
i
<
listlen
;
i
++
)
{
int64_t
*
uid
=
taosArrayGet
(
l
ist
,
i
);
size_t
numOfExisted
=
taosArrayGetSize
(
pExistedUidL
ist
);
// len > 0 means there already have uids
if
(
numOfExisted
>
0
)
{
uHash
=
taosHashInit
(
numOfExisted
/
0
.
7
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
,
HASH_NO_LOCK
);
for
(
int
i
=
0
;
i
<
numOfExisted
;
i
++
)
{
int64_t
*
uid
=
taosArrayGet
(
pExistedUidL
ist
,
i
);
taosHashPut
(
uHash
,
uid
,
sizeof
(
int64_t
),
&
i
,
sizeof
(
i
));
}
}
...
...
@@ -948,7 +955,7 @@ static int32_t optimizeTbnameInCondImpl(void* metaHandle, int64_t suid, SArray*
ETableType
tbType
=
TSDB_TABLE_MAX
;
if
(
metaGetTableTypeByName
(
metaHandle
,
name
,
&
tbType
)
==
0
&&
tbType
==
TSDB_CHILD_TABLE
)
{
if
(
NULL
==
uHash
||
taosHashGet
(
uHash
,
&
uid
,
sizeof
(
uid
))
==
NULL
)
{
taosArrayPush
(
l
ist
,
&
uid
);
taosArrayPush
(
pExistedUidL
ist
,
&
uid
);
}
}
else
{
taosArrayDestroy
(
pTbList
);
...
...
@@ -1057,7 +1064,7 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode,
goto
_end
;
}
if
(
!
pTagCond
)
{
// no tag condition exists, let's fetch all tables of this super table
if
(
!
pTagCond
)
{
// no tag
filter
condition exists, let's fetch all tables of this super table
ASSERT
(
pTagIndexCond
==
NULL
);
vnodeGetCtbIdList
(
pVnode
,
pScanNode
->
suid
,
res
);
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录