Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9d830206
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看板
未验证
提交
9d830206
编写于
11月 07, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
11月 07, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17926 from taosdata/feature/3_liaohj
enh(query): add cache for table meta entry in table scan.
上级
b8dd3843
0e11d344
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
140 addition
and
43 deletion
+140
-43
source/dnode/vnode/src/meta/metaQuery.c
source/dnode/vnode/src/meta/metaQuery.c
+3
-3
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+9
-3
source/libs/executor/src/cachescanoperator.c
source/libs/executor/src/cachescanoperator.c
+2
-2
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+108
-24
source/libs/executor/src/sortoperator.c
source/libs/executor/src/sortoperator.c
+18
-11
未找到文件。
source/dnode/vnode/src/meta/metaQuery.c
浏览文件 @
9d830206
...
...
@@ -153,7 +153,7 @@ bool metaIsTableExist(SMeta *pMeta, tb_uid_t uid) {
int
metaGetTableEntryByUid
(
SMetaReader
*
pReader
,
tb_uid_t
uid
)
{
SMeta
*
pMeta
=
pReader
->
pMeta
;
int64_t
version
;
int64_t
version
1
;
// query uid.idx
if
(
tdbTbGet
(
pMeta
->
pUidIdx
,
&
uid
,
sizeof
(
uid
),
&
pReader
->
pBuf
,
&
pReader
->
szBuf
)
<
0
)
{
...
...
@@ -161,8 +161,8 @@ int metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid) {
return
-
1
;
}
version
=
((
SUidIdxVal
*
)
pReader
->
pBuf
)[
0
].
version
;
return
metaGetTableEntryByVersion
(
pReader
,
version
,
uid
);
version
1
=
((
SUidIdxVal
*
)
pReader
->
pBuf
)[
0
].
version
;
return
metaGetTableEntryByVersion
(
pReader
,
version
1
,
uid
);
}
int
metaGetTableEntryByName
(
SMetaReader
*
pReader
,
const
char
*
name
)
{
...
...
source/libs/executor/inc/executorimpl.h
浏览文件 @
9d830206
...
...
@@ -298,6 +298,12 @@ typedef struct {
SExprSupp
*
pExprSup
;
// expr supporter of aggregate operator
}
SAggOptrPushDownInfo
;
typedef
struct
STableMetaCacheInfo
{
SLRUCache
*
pTableMetaEntryCache
;
// 100 by default
uint64_t
metaFetch
;
uint64_t
cacheHit
;
}
STableMetaCacheInfo
;
typedef
struct
STableScanInfo
{
STsdbReader
*
dataReader
;
SReadHandle
readHandle
;
...
...
@@ -317,6 +323,7 @@ typedef struct STableScanInfo {
int8_t
scanMode
;
SAggOptrPushDownInfo
pdInfo
;
int8_t
assignBlockUid
;
STableMetaCacheInfo
metaCache
;
}
STableScanInfo
;
typedef
struct
STableMergeScanInfo
{
...
...
@@ -325,7 +332,6 @@ typedef struct STableMergeScanInfo {
int32_t
tableEndIndex
;
bool
hasGroupId
;
uint64_t
groupId
;
SArray
*
dataReaders
;
// array of tsdbReaderT*
SArray
*
queryConds
;
// array of queryTableDataCond
STsdbReader
*
pReader
;
SReadHandle
readHandle
;
...
...
@@ -877,8 +883,8 @@ int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaul
void
doSetOperatorCompleted
(
SOperatorInfo
*
pOperator
);
void
doFilter
(
SSDataBlock
*
pBlock
,
SFilterInfo
*
pFilterInfo
,
SColMatchInfo
*
pColMatchInfo
);
int32_t
addTagPseudoColumnData
(
SReadHandle
*
pHandle
,
SExprInfo
*
pPseudoExpr
,
int32_t
numOfPseudo
Expr
,
SSDataBlock
*
pBlock
,
int32_t
rows
,
const
char
*
idStr
);
int32_t
addTagPseudoColumnData
(
SReadHandle
*
pHandle
,
const
SExprInfo
*
pExpr
,
int32_t
numOf
Expr
,
SSDataBlock
*
pBlock
,
int32_t
rows
,
const
char
*
idStr
,
STableMetaCacheInfo
*
pCache
);
void
cleanupAggSup
(
SAggSupporter
*
pAggSup
);
void
appendOneRowToDataBlock
(
SSDataBlock
*
pBlock
,
STupleHandle
*
pTupleHandle
);
...
...
source/libs/executor/src/cachescanoperator.c
浏览文件 @
9d830206
...
...
@@ -172,7 +172,7 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
SExprSupp
*
pSup
=
&
pInfo
->
pseudoExprSup
;
int32_t
code
=
addTagPseudoColumnData
(
&
pInfo
->
readHandle
,
pSup
->
pExprInfo
,
pSup
->
numOfExprs
,
pRes
,
pRes
->
info
.
rows
,
GET_TASKID
(
pTaskInfo
));
pRes
->
info
.
rows
,
GET_TASKID
(
pTaskInfo
)
,
NULL
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
pTaskInfo
->
code
=
code
;
return
NULL
;
...
...
@@ -221,7 +221,7 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
pInfo
->
pRes
->
info
.
uid
=
*
(
tb_uid_t
*
)
taosArrayGet
(
pInfo
->
pUidList
,
0
);
code
=
addTagPseudoColumnData
(
&
pInfo
->
readHandle
,
pSup
->
pExprInfo
,
pSup
->
numOfExprs
,
pInfo
->
pRes
,
pInfo
->
pRes
->
info
.
rows
,
GET_TASKID
(
pTaskInfo
));
GET_TASKID
(
pTaskInfo
)
,
NULL
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
pTaskInfo
->
code
=
code
;
return
NULL
;
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
9d830206
...
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <vnode.h>
#include "executorimpl.h"
#include "filter.h"
#include "function.h"
...
...
@@ -335,7 +336,7 @@ static void doSetTagColumnData(STableScanInfo* pTableScanInfo, SSDataBlock* pBlo
SExprSupp
*
pSup
=
&
pTableScanInfo
->
pseudoSup
;
int32_t
code
=
addTagPseudoColumnData
(
&
pTableScanInfo
->
readHandle
,
pSup
->
pExprInfo
,
pSup
->
numOfExprs
,
pBlock
,
rows
,
GET_TASKID
(
pTaskInfo
));
GET_TASKID
(
pTaskInfo
)
,
&
pTableScanInfo
->
metaCache
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
T_LONG_JMP
(
pTaskInfo
->
env
,
code
);
}
...
...
@@ -491,51 +492,128 @@ static void prepareForDescendingScan(STableScanInfo* pTableScanInfo, SqlFunction
SET_REVERSE_SCAN_FLAG
(
pTableScanInfo
);
switchCtxOrder
(
pCtx
,
numOfOutput
);
// setupQueryRangeForReverseScan(pTableScanInfo);
pTableScanInfo
->
cond
.
order
=
TSDB_ORDER_DESC
;
STimeWindow
*
pTWindow
=
&
pTableScanInfo
->
cond
.
twindows
;
TSWAP
(
pTWindow
->
skey
,
pTWindow
->
ekey
);
}
int32_t
addTagPseudoColumnData
(
SReadHandle
*
pHandle
,
SExprInfo
*
pPseudoExpr
,
int32_t
numOfPseudoExpr
,
SSDataBlock
*
pBlock
,
int32_t
rows
,
const
char
*
idStr
)
{
typedef
struct
STableCachedVal
{
const
char
*
pName
;
STag
*
pTags
;
}
STableCachedVal
;
static
void
freeTableCachedVal
(
void
*
param
)
{
if
(
param
==
NULL
)
{
return
;
}
STableCachedVal
*
pVal
=
param
;
taosMemoryFree
((
void
*
)
pVal
->
pName
);
taosMemoryFree
(
pVal
->
pTags
);
taosMemoryFree
(
pVal
);
}
//const void *key, size_t keyLen, void *value
static
void
freeCachedMetaItem
(
const
void
*
key
,
size_t
keyLen
,
void
*
value
)
{
freeTableCachedVal
(
value
);
}
int32_t
addTagPseudoColumnData
(
SReadHandle
*
pHandle
,
const
SExprInfo
*
pExpr
,
int32_t
numOfExpr
,
SSDataBlock
*
pBlock
,
int32_t
rows
,
const
char
*
idStr
,
STableMetaCacheInfo
*
pCache
)
{
// currently only the tbname pseudo column
if
(
numOf
Pseudo
Expr
<=
0
)
{
if
(
numOfExpr
<=
0
)
{
return
TSDB_CODE_SUCCESS
;
}
int32_t
code
=
0
;
// backup the rows
int32_t
backupRows
=
pBlock
->
info
.
rows
;
pBlock
->
info
.
rows
=
rows
;
bool
freeReader
=
false
;
STableCachedVal
val
=
{
0
};
SMetaReader
mr
=
{
0
};
LRUHandle
*
h
=
NULL
;
// 1. check if it is existed in meta cache
if
(
pCache
==
NULL
)
{
metaReaderInit
(
&
mr
,
pHandle
->
meta
,
0
);
int32_t
code
=
metaGetTableEntryByUid
(
&
mr
,
pBlock
->
info
.
uid
);
code
=
metaGetTableEntryByUid
(
&
mr
,
pBlock
->
info
.
uid
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
qError
(
"failed to get table meta, uid:0x%"
PRIx64
", code:%s, %s"
,
pBlock
->
info
.
uid
,
tstrerror
(
terrno
),
idStr
);
metaReaderClear
(
&
mr
);
return
terrno
;
}
metaReaderReleaseLock
(
&
mr
);
val
.
pName
=
mr
.
me
.
name
;
val
.
pTags
=
(
STag
*
)
mr
.
me
.
ctbEntry
.
pTags
;
freeReader
=
true
;
}
else
{
pCache
->
metaFetch
+=
1
;
h
=
taosLRUCacheLookup
(
pCache
->
pTableMetaEntryCache
,
&
pBlock
->
info
.
uid
,
sizeof
(
pBlock
->
info
.
uid
));
if
(
h
==
NULL
)
{
metaReaderInit
(
&
mr
,
pHandle
->
meta
,
0
);
code
=
metaGetTableEntryByUid
(
&
mr
,
pBlock
->
info
.
uid
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
qError
(
"failed to get table meta, uid:0x%"
PRIx64
", code:%s, %s"
,
pBlock
->
info
.
uid
,
tstrerror
(
terrno
),
idStr
);
metaReaderClear
(
&
mr
);
return
terrno
;
}
for
(
int32_t
j
=
0
;
j
<
numOfPseudoExpr
;
++
j
)
{
SExprInfo
*
pExpr
=
&
pPseudoExpr
[
j
];
int32_t
dstSlotId
=
pExpr
->
base
.
resSchema
.
slotId
;
metaReaderReleaseLock
(
&
mr
);
STableCachedVal
*
pVal
=
taosMemoryMalloc
(
sizeof
(
STableCachedVal
));
pVal
->
pName
=
strdup
(
mr
.
me
.
name
);
pVal
->
pTags
=
NULL
;
// only child table has tag value
if
(
mr
.
me
.
type
==
TSDB_CHILD_TABLE
)
{
STag
*
pTag
=
(
STag
*
)
mr
.
me
.
ctbEntry
.
pTags
;
pVal
->
pTags
=
taosMemoryMalloc
(
pTag
->
len
);
memcpy
(
pVal
->
pTags
,
mr
.
me
.
ctbEntry
.
pTags
,
pTag
->
len
);
}
val
=
*
pVal
;
freeReader
=
true
;
int32_t
ret
=
taosLRUCacheInsert
(
pCache
->
pTableMetaEntryCache
,
&
pBlock
->
info
.
uid
,
sizeof
(
uint64_t
),
pVal
,
sizeof
(
STableCachedVal
),
freeCachedMetaItem
,
NULL
,
TAOS_LRU_PRIORITY_LOW
);
if
(
ret
!=
TAOS_LRU_STATUS_OK
)
{
qError
(
"failed to put meta into lru cache, code:%d, %s"
,
ret
,
idStr
);
freeTableCachedVal
(
pVal
);
}
}
else
{
pCache
->
cacheHit
+=
1
;
STableCachedVal
*
pVal
=
taosLRUCacheValue
(
pCache
->
pTableMetaEntryCache
,
h
);
val
=
*
pVal
;
taosLRUCacheRelease
(
pCache
->
pTableMetaEntryCache
,
h
,
false
);
}
qDebug
(
"retrieve table meta from cache:%"
PRIu64
", hit:%"
PRIu64
" miss:%"
PRIu64
", %s"
,
pCache
->
metaFetch
,
pCache
->
cacheHit
,
(
pCache
->
metaFetch
-
pCache
->
cacheHit
),
idStr
);
}
for
(
int32_t
j
=
0
;
j
<
numOfExpr
;
++
j
)
{
const
SExprInfo
*
pExpr1
=
&
pExpr
[
j
];
int32_t
dstSlotId
=
pExpr1
->
base
.
resSchema
.
slotId
;
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pBlock
->
pDataBlock
,
dstSlotId
);
colInfoDataCleanup
(
pColInfoData
,
pBlock
->
info
.
rows
);
int32_t
functionId
=
pExpr
->
pExpr
->
_function
.
functionId
;
int32_t
functionId
=
pExpr
1
->
pExpr
->
_function
.
functionId
;
// this is to handle the tbname
if
(
fmIsScanPseudoColumnFunc
(
functionId
))
{
setTbNameColData
(
pBlock
,
pColInfoData
,
functionId
,
mr
.
me
.
n
ame
);
setTbNameColData
(
pBlock
,
pColInfoData
,
functionId
,
val
.
pN
ame
);
}
else
{
// these are tags
STagVal
tagVal
=
{
0
};
tagVal
.
cid
=
pExpr
->
base
.
pParam
[
0
].
pCol
->
colId
;
const
char
*
p
=
metaGetTableTagVal
(
mr
.
me
.
ctbEntry
.
pTags
,
pColInfoData
->
info
.
type
,
&
tagVal
);
tagVal
.
cid
=
pExpr
1
->
base
.
pParam
[
0
].
pCol
->
colId
;
const
char
*
p
=
metaGetTableTagVal
(
val
.
pTags
,
pColInfoData
->
info
.
type
,
&
tagVal
);
char
*
data
=
NULL
;
if
(
pColInfoData
->
info
.
type
!=
TSDB_DATA_TYPE_JSON
&&
p
!=
NULL
)
{
...
...
@@ -560,10 +638,12 @@ int32_t addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int
}
}
metaReaderClear
(
&
mr
);
// restore the rows
pBlock
->
info
.
rows
=
backupRows
;
if
(
freeReader
)
{
metaReaderClear
(
&
mr
);
}
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -811,6 +891,7 @@ static void destroyTableScanOperatorInfo(void* param) {
taosArrayDestroy
(
pTableScanInfo
->
matchInfo
.
pList
);
}
taosLRUCacheCleanup
(
pTableScanInfo
->
metaCache
.
pTableMetaEntryCache
);
cleanupExprSupp
(
&
pTableScanInfo
->
pseudoSup
);
taosMemoryFreeClear
(
param
);
}
...
...
@@ -874,6 +955,9 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode,
pOperator
->
exprSupp
.
numOfExprs
=
numOfCols
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pInfo
->
metaCache
.
pTableMetaEntryCache
=
taosLRUCacheInit
(
1024
*
128
,
-
1
,
.
5
);
taosLRUCacheSetStrictCapacity
(
pInfo
->
metaCache
.
pTableMetaEntryCache
,
false
);
pOperator
->
fpSet
=
createOperatorFpSet
(
operatorDummyOpenFn
,
doTableScan
,
NULL
,
NULL
,
destroyTableScanOperatorInfo
,
getTableScannerExecInfo
);
...
...
@@ -1624,7 +1708,7 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock
// currently only the tbname pseudo column
if
(
pInfo
->
numOfPseudoExpr
>
0
)
{
int32_t
code
=
addTagPseudoColumnData
(
&
pInfo
->
readHandle
,
pInfo
->
pPseudoExpr
,
pInfo
->
numOfPseudoExpr
,
pInfo
->
pRes
,
pInfo
->
pRes
->
info
.
rows
,
GET_TASKID
(
pTaskInfo
));
pInfo
->
pRes
->
info
.
rows
,
GET_TASKID
(
pTaskInfo
)
,
NULL
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
blockDataFreeRes
((
SSDataBlock
*
)
pBlock
);
T_LONG_JMP
(
pTaskInfo
->
env
,
code
);
...
...
@@ -4362,7 +4446,7 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc
SExprSupp
*
pSup
=
&
pTableScanInfo
->
pseudoSup
;
int32_t
code
=
addTagPseudoColumnData
(
&
pTableScanInfo
->
readHandle
,
pSup
->
pExprInfo
,
pSup
->
numOfExprs
,
pBlock
,
pBlock
->
info
.
rows
,
GET_TASKID
(
pTaskInfo
));
pBlock
->
info
.
rows
,
GET_TASKID
(
pTaskInfo
)
,
NULL
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
T_LONG_JMP
(
pTaskInfo
->
env
,
code
);
}
...
...
source/libs/executor/src/sortoperator.c
浏览文件 @
9d830206
...
...
@@ -482,24 +482,31 @@ SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSort
SExecTaskInfo
*
pTaskInfo
)
{
SGroupSortOperatorInfo
*
pInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SGroupSortOperatorInfo
));
SOperatorInfo
*
pOperator
=
taosMemoryCalloc
(
1
,
sizeof
(
SOperatorInfo
));
if
(
pInfo
==
NULL
||
pOperator
==
NULL
/* || rowSize > 100 * 1024 * 1024*/
)
{
if
(
pInfo
==
NULL
||
pOperator
==
NULL
)
{
goto
_error
;
}
SExprSupp
*
pSup
=
&
pOperator
->
exprSupp
;
SDataBlockDescNode
*
pDescNode
=
pSortPhyNode
->
node
.
pOutputDataBlockDesc
;
int32_t
numOfCols
=
0
;
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pDescNode
);
SExprInfo
*
pExprInfo
=
createExprInfo
(
pSortPhyNode
->
pExprs
,
NULL
,
&
numOfCols
);
int32_t
numOfOutputCols
=
0
;
int32_t
code
=
extractColMatchInfo
(
pSortPhyNode
->
pTargets
,
pDescNode
,
&
numOfOutputCols
,
COL_MATCH_FROM_SLOT_ID
,
&
pInfo
->
matchInfo
);
pSup
->
pExprInfo
=
pExprInfo
;
pSup
->
numOfExprs
=
numOfCols
;
initResultSizeInfo
(
&
pOperator
->
resultInfo
,
1024
);
pOperator
->
exprSupp
.
pCtx
=
createSqlFunctionCtx
(
pExprInfo
,
numOfCols
,
&
pOperator
->
exprSupp
.
rowEntryInfoOffset
);
pInfo
->
binfo
.
pRes
=
pResBlock
;
initResultSizeInfo
(
&
pOperator
->
resultInfo
,
1024
);
pInfo
->
binfo
.
pRes
=
createResDataBlock
(
pDescNode
);
blockDataEnsureCapacity
(
pInfo
->
binfo
.
pRes
,
pOperator
->
resultInfo
.
capacity
);
int32_t
numOfOutputCols
=
0
;
int32_t
code
=
extractColMatchInfo
(
pSortPhyNode
->
pTargets
,
pDescNode
,
&
numOfOutputCols
,
COL_MATCH_FROM_SLOT_ID
,
&
pInfo
->
matchInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
pInfo
->
pSortInfo
=
createSortInfo
(
pSortPhyNode
->
pSortKeys
);
...
...
@@ -508,8 +515,6 @@ SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSort
pOperator
->
blocking
=
false
;
pOperator
->
status
=
OP_NOT_OPENED
;
pOperator
->
info
=
pInfo
;
pOperator
->
exprSupp
.
pExprInfo
=
pExprInfo
;
pOperator
->
exprSupp
.
numOfExprs
=
numOfCols
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
fpSet
=
createOperatorFpSet
(
operatorDummyOpenFn
,
doGroupSort
,
NULL
,
NULL
,
destroyGroupSortOperatorInfo
,
...
...
@@ -523,8 +528,10 @@ SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSort
return
pOperator
;
_error:
pTaskInfo
->
code
=
TSDB_CODE_OUT_OF_MEMORY
;
taosMemoryFree
(
pInfo
);
pTaskInfo
->
code
=
code
;
if
(
pInfo
!=
NULL
)
{
destroyGroupSortOperatorInfo
(
pInfo
);
}
taosMemoryFree
(
pOperator
);
return
NULL
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录