Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e86cdc8c
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1181
Star
22014
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
e86cdc8c
编写于
10月 23, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
10月 23, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17381 from taosdata/feature/addIdxToSysTable
Feature/addIdxToSysTable
上级
e9e0165a
5e19f2d2
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
1156 addition
and
168 deletion
+1156
-168
include/common/ttypes.h
include/common/ttypes.h
+1
-1
source/dnode/vnode/inc/vnode.h
source/dnode/vnode/inc/vnode.h
+4
-0
source/dnode/vnode/src/inc/meta.h
source/dnode/vnode/src/inc/meta.h
+16
-2
source/dnode/vnode/src/meta/metaOpen.c
source/dnode/vnode/src/meta/metaOpen.c
+58
-0
source/dnode/vnode/src/meta/metaQuery.c
source/dnode/vnode/src/meta/metaQuery.c
+140
-1
source/dnode/vnode/src/meta/metaTable.c
source/dnode/vnode/src/meta/metaTable.c
+65
-0
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+7
-0
source/libs/executor/src/executil.c
source/libs/executor/src/executil.c
+5
-16
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+848
-137
source/libs/transport/src/trans.c
source/libs/transport/src/trans.c
+1
-0
tests/script/tsim/parser/where.sim
tests/script/tsim/parser/where.sim
+11
-11
未找到文件。
include/common/ttypes.h
浏览文件 @
e86cdc8c
...
...
@@ -340,7 +340,7 @@ typedef struct tDataTypeDescriptor {
}
tDataTypeDescriptor
;
extern
tDataTypeDescriptor
tDataTypes
[
TSDB_DATA_TYPE_MAX
];
bool
isValidDataType
(
int32_t
type
);
bool
isValidDataType
(
int32_t
type
);
void
assignVal
(
char
*
val
,
const
char
*
src
,
int32_t
len
,
int32_t
type
);
void
operateVal
(
void
*
dst
,
void
*
s1
,
void
*
s2
,
int32_t
optr
,
int32_t
type
);
...
...
source/dnode/vnode/inc/vnode.h
浏览文件 @
e86cdc8c
...
...
@@ -120,7 +120,11 @@ typedef struct SMetaFltParam {
}
SMetaFltParam
;
// TODO, refactor later
int32_t
metaFilterTableIds
(
SMeta
*
pMeta
,
SMetaFltParam
*
param
,
SArray
*
results
);
int32_t
metaFilterCreateTime
(
SMeta
*
pMeta
,
SMetaFltParam
*
parm
,
SArray
*
pUids
);
int32_t
metaFilterTableName
(
SMeta
*
pMeta
,
SMetaFltParam
*
param
,
SArray
*
pUids
);
int32_t
metaFilterTtl
(
SMeta
*
pMeta
,
SMetaFltParam
*
param
,
SArray
*
pUids
);
#if 1 // refact APIs below (TODO)
typedef
SVCreateTbReq
STbCfg
;
...
...
source/dnode/vnode/src/inc/meta.h
浏览文件 @
e86cdc8c
...
...
@@ -86,8 +86,12 @@ struct SMeta {
TTB
*
pSuidIdx
;
// ivt idx and idx
void
*
pTagIvtIdx
;
TTB
*
pTagIdx
;
TTB
*
pTtlIdx
;
TTB
*
pTagIdx
;
TTB
*
pTtlIdx
;
TTB
*
pCtimeIdx
;
// table created time idx
TTB
*
pNcolIdx
;
// ncol of table idx, normal table only
TTB
*
pSmaIdx
;
...
...
@@ -142,6 +146,16 @@ typedef struct {
int64_t
smaUid
;
}
SSmaIdxKey
;
typedef
struct
{
int64_t
ctime
;
tb_uid_t
uid
;
}
SCtimeIdxKey
;
typedef
struct
{
int64_t
ncol
;
tb_uid_t
uid
;
}
SNcolIdxKey
;
// metaTable ==================
int
metaCreateTagIdxKey
(
tb_uid_t
suid
,
int32_t
cid
,
const
void
*
pTagData
,
int32_t
nTagData
,
int8_t
type
,
tb_uid_t
uid
,
STagIdxKey
**
ppTagIdxKey
,
int32_t
*
nTagIdxKey
);
...
...
source/dnode/vnode/src/meta/metaOpen.c
浏览文件 @
e86cdc8c
...
...
@@ -24,6 +24,9 @@ static int uidIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kL
static
int
smaIdxKeyCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
);
static
int
taskIdxKeyCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
);
static
int
ctimeIdxCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
);
static
int
ncolIdxCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
);
static
int32_t
metaInitLock
(
SMeta
*
pMeta
)
{
return
taosThreadRwlockInit
(
&
pMeta
->
lock
,
NULL
);
}
static
int32_t
metaDestroyLock
(
SMeta
*
pMeta
)
{
return
taosThreadRwlockDestroy
(
&
pMeta
->
lock
);
}
...
...
@@ -139,6 +142,20 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) {
goto
_err
;
}
// idx table create time
ret
=
tdbTbOpen
(
"ctime.idx"
,
sizeof
(
SCtimeIdxKey
),
0
,
ctimeIdxCmpr
,
pMeta
->
pEnv
,
&
pMeta
->
pCtimeIdx
,
0
);
if
(
ret
<
0
)
{
metaError
(
"vgId:%d, failed to open meta ctime index since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
goto
_err
;
}
// idx num of col, normal table only
ret
=
tdbTbOpen
(
"ncol.idx"
,
sizeof
(
SNcolIdxKey
),
0
,
ncolIdxCmpr
,
pMeta
->
pEnv
,
&
pMeta
->
pNcolIdx
,
0
);
if
(
ret
<
0
)
{
metaError
(
"vgId:%d, failed to open meta ncol index since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
goto
_err
;
}
ret
=
tdbTbOpen
(
"stream.task.db"
,
sizeof
(
int64_t
),
-
1
,
taskIdxKeyCmpr
,
pMeta
->
pEnv
,
&
pMeta
->
pStreamDb
,
0
);
if
(
ret
<
0
)
{
metaError
(
"vgId:%d, failed to open meta stream task index since %s"
,
TD_VID
(
pVnode
),
tstrerror
(
terrno
));
...
...
@@ -166,6 +183,8 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) {
_err:
if
(
pMeta
->
pIdx
)
metaCloseIdx
(
pMeta
);
if
(
pMeta
->
pStreamDb
)
tdbTbClose
(
pMeta
->
pStreamDb
);
if
(
pMeta
->
pNcolIdx
)
tdbTbClose
(
pMeta
->
pNcolIdx
);
if
(
pMeta
->
pCtimeIdx
)
tdbTbClose
(
pMeta
->
pCtimeIdx
);
if
(
pMeta
->
pSmaIdx
)
tdbTbClose
(
pMeta
->
pSmaIdx
);
if
(
pMeta
->
pTtlIdx
)
tdbTbClose
(
pMeta
->
pTtlIdx
);
if
(
pMeta
->
pTagIvtIdx
)
indexClose
(
pMeta
->
pTagIvtIdx
);
...
...
@@ -187,6 +206,8 @@ int metaClose(SMeta *pMeta) {
if
(
pMeta
->
pCache
)
metaCacheClose
(
pMeta
);
if
(
pMeta
->
pIdx
)
metaCloseIdx
(
pMeta
);
if
(
pMeta
->
pStreamDb
)
tdbTbClose
(
pMeta
->
pStreamDb
);
if
(
pMeta
->
pNcolIdx
)
tdbTbClose
(
pMeta
->
pNcolIdx
);
if
(
pMeta
->
pCtimeIdx
)
tdbTbClose
(
pMeta
->
pCtimeIdx
);
if
(
pMeta
->
pSmaIdx
)
tdbTbClose
(
pMeta
->
pSmaIdx
);
if
(
pMeta
->
pTtlIdx
)
tdbTbClose
(
pMeta
->
pTtlIdx
);
if
(
pMeta
->
pTagIvtIdx
)
indexClose
(
pMeta
->
pTagIvtIdx
);
...
...
@@ -391,6 +412,43 @@ static int ttlIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kL
return
0
;
}
static
int
ctimeIdxCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
)
{
SCtimeIdxKey
*
pCtimeIdxKey1
=
(
SCtimeIdxKey
*
)
pKey1
;
SCtimeIdxKey
*
pCtimeIdxKey2
=
(
SCtimeIdxKey
*
)
pKey2
;
if
(
pCtimeIdxKey1
->
ctime
>
pCtimeIdxKey2
->
ctime
)
{
return
1
;
}
else
if
(
pCtimeIdxKey1
->
ctime
<
pCtimeIdxKey2
->
ctime
)
{
return
-
1
;
}
if
(
pCtimeIdxKey1
->
uid
>
pCtimeIdxKey2
->
uid
)
{
return
1
;
}
else
if
(
pCtimeIdxKey1
->
uid
<
pCtimeIdxKey2
->
uid
)
{
return
-
1
;
}
return
0
;
}
static
int
ncolIdxCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
)
{
SNcolIdxKey
*
pNcolIdxKey1
=
(
SNcolIdxKey
*
)
pKey1
;
SNcolIdxKey
*
pNcolIdxKey2
=
(
SNcolIdxKey
*
)
pKey2
;
if
(
pNcolIdxKey1
->
ncol
>
pNcolIdxKey2
->
ncol
)
{
return
1
;
}
else
if
(
pNcolIdxKey1
->
ncol
<
pNcolIdxKey2
->
ncol
)
{
return
-
1
;
}
if
(
pNcolIdxKey1
->
uid
>
pNcolIdxKey2
->
uid
)
{
return
1
;
}
else
if
(
pNcolIdxKey1
->
uid
<
pNcolIdxKey2
->
uid
)
{
return
-
1
;
}
return
0
;
}
static
int
smaIdxKeyCmpr
(
const
void
*
pKey1
,
int
kLen1
,
const
void
*
pKey2
,
int
kLen2
)
{
SSmaIdxKey
*
pSmaIdxKey1
=
(
SSmaIdxKey
*
)
pKey1
;
SSmaIdxKey
*
pSmaIdxKey2
=
(
SSmaIdxKey
*
)
pKey2
;
...
...
source/dnode/vnode/src/meta/metaQuery.c
浏览文件 @
e86cdc8c
...
...
@@ -1038,6 +1038,143 @@ typedef struct {
int32_t
vLen
;
}
SIdxCursor
;
int32_t
metaFilterCreateTime
(
SMeta
*
pMeta
,
SMetaFltParam
*
param
,
SArray
*
pUids
)
{
int32_t
ret
=
0
;
SIdxCursor
*
pCursor
=
NULL
;
pCursor
=
(
SIdxCursor
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SIdxCursor
));
pCursor
->
pMeta
=
pMeta
;
pCursor
->
suid
=
param
->
suid
;
pCursor
->
cid
=
param
->
cid
;
pCursor
->
type
=
param
->
type
;
metaRLock
(
pMeta
);
ret
=
tdbTbcOpen
(
pMeta
->
pCtimeIdx
,
&
pCursor
->
pCur
,
NULL
);
if
(
ret
!=
0
)
{
goto
END
;
}
int64_t
uidLimit
=
param
->
reverse
?
INT64_MAX
:
0
;
SCtimeIdxKey
ctimeKey
=
{.
ctime
=
*
(
int64_t
*
)(
param
->
val
),
.
uid
=
uidLimit
};
SCtimeIdxKey
*
pCtimeKey
=
&
ctimeKey
;
int
cmp
=
0
;
if
(
tdbTbcMoveTo
(
pCursor
->
pCur
,
&
ctimeKey
,
sizeof
(
ctimeKey
),
&
cmp
)
<
0
)
{
goto
END
;
}
bool
first
=
true
;
int32_t
valid
=
0
;
while
(
1
)
{
void
*
entryKey
=
NULL
;
int32_t
nEntryKey
=
-
1
;
valid
=
tdbTbcGet
(
pCursor
->
pCur
,
(
const
void
**
)
&
entryKey
,
&
nEntryKey
,
NULL
,
NULL
);
if
(
valid
<
0
)
break
;
SCtimeIdxKey
*
p
=
entryKey
;
int32_t
cmp
=
(
*
param
->
filterFunc
)((
void
*
)
&
p
->
ctime
,
(
void
*
)
&
pCtimeKey
->
ctime
,
param
->
type
);
if
(
cmp
==
0
)
taosArrayPush
(
pUids
,
&
p
->
uid
);
if
(
cmp
==
-
1
)
break
;
valid
=
param
->
reverse
?
tdbTbcMoveToPrev
(
pCursor
->
pCur
)
:
tdbTbcMoveToNext
(
pCursor
->
pCur
);
if
(
valid
<
0
)
break
;
}
END:
if
(
pCursor
->
pMeta
)
metaULock
(
pCursor
->
pMeta
);
if
(
pCursor
->
pCur
)
tdbTbcClose
(
pCursor
->
pCur
);
taosMemoryFree
(
pCursor
);
return
ret
;
}
int32_t
metaFilterTableName
(
SMeta
*
pMeta
,
SMetaFltParam
*
param
,
SArray
*
pUids
)
{
int32_t
ret
=
0
;
char
*
buf
=
NULL
;
STagIdxKey
*
pKey
=
NULL
;
int32_t
nKey
=
0
;
SIdxCursor
*
pCursor
=
NULL
;
pCursor
=
(
SIdxCursor
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SIdxCursor
));
pCursor
->
pMeta
=
pMeta
;
pCursor
->
suid
=
param
->
suid
;
pCursor
->
cid
=
param
->
cid
;
pCursor
->
type
=
param
->
type
;
char
*
pName
=
param
->
val
;
metaRLock
(
pMeta
);
ret
=
tdbTbcOpen
(
pMeta
->
pNameIdx
,
&
pCursor
->
pCur
,
NULL
);
if
(
ret
!=
0
)
{
goto
END
;
}
int
cmp
=
0
;
if
(
tdbTbcMoveTo
(
pCursor
->
pCur
,
pName
,
strlen
(
pName
)
+
1
,
&
cmp
)
<
0
)
{
goto
END
;
}
bool
first
=
true
;
int32_t
valid
=
0
;
while
(
1
)
{
void
*
pEntryKey
=
NULL
,
*
pEntryVal
=
NULL
;
int32_t
nEntryKey
=
-
1
,
nEntryVal
=
0
;
valid
=
tdbTbcGet
(
pCursor
->
pCur
,
(
const
void
**
)
pEntryKey
,
&
nEntryKey
,
(
const
void
**
)
&
pEntryVal
,
&
nEntryVal
);
if
(
valid
<
0
)
break
;
char
*
pTableKey
=
(
char
*
)
pEntryKey
;
int32_t
cmp
=
(
*
param
->
filterFunc
)(
pTableKey
,
pName
,
pCursor
->
type
);
if
(
cmp
==
0
)
{
tb_uid_t
tuid
=
*
(
tb_uid_t
*
)
pEntryVal
;
taosArrayPush
(
pUids
,
&
tuid
);
}
else
if
(
cmp
==
1
)
{
// next
}
else
{
break
;
}
valid
=
param
->
reverse
?
tdbTbcMoveToPrev
(
pCursor
->
pCur
)
:
tdbTbcMoveToNext
(
pCursor
->
pCur
);
if
(
valid
<
0
)
{
break
;
}
}
END:
if
(
pCursor
->
pMeta
)
metaULock
(
pCursor
->
pMeta
);
if
(
pCursor
->
pCur
)
tdbTbcClose
(
pCursor
->
pCur
);
taosMemoryFree
(
buf
);
taosMemoryFree
(
pKey
);
taosMemoryFree
(
pCursor
);
return
ret
;
}
int32_t
metaFilterTtl
(
SMeta
*
pMeta
,
SMetaFltParam
*
param
,
SArray
*
pUids
)
{
int32_t
ret
=
0
;
char
*
buf
=
NULL
;
STtlIdxKey
*
pKey
=
NULL
;
int32_t
nKey
=
0
;
SIdxCursor
*
pCursor
=
NULL
;
pCursor
=
(
SIdxCursor
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SIdxCursor
));
pCursor
->
pMeta
=
pMeta
;
pCursor
->
suid
=
param
->
suid
;
pCursor
->
cid
=
param
->
cid
;
pCursor
->
type
=
param
->
type
;
metaRLock
(
pMeta
);
ret
=
tdbTbcOpen
(
pMeta
->
pTtlIdx
,
&
pCursor
->
pCur
,
NULL
);
END:
if
(
pCursor
->
pMeta
)
metaULock
(
pCursor
->
pMeta
);
if
(
pCursor
->
pCur
)
tdbTbcClose
(
pCursor
->
pCur
);
taosMemoryFree
(
buf
);
taosMemoryFree
(
pKey
);
taosMemoryFree
(
pCursor
);
return
ret
;
// impl later
return
0
;
}
int32_t
metaFilterTableIds
(
SMeta
*
pMeta
,
SMetaFltParam
*
param
,
SArray
*
pUids
)
{
int32_t
ret
=
0
;
char
*
buf
=
NULL
;
...
...
@@ -1053,7 +1190,7 @@ int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
pCursor
->
type
=
param
->
type
;
metaRLock
(
pMeta
);
ret
=
tdbTbcOpen
(
pMeta
->
p
Tag
Idx
,
&
pCursor
->
pCur
,
NULL
);
ret
=
tdbTbcOpen
(
pMeta
->
p
Ctime
Idx
,
&
pCursor
->
pCur
,
NULL
);
if
(
ret
<
0
)
{
goto
END
;
}
...
...
@@ -1064,6 +1201,7 @@ int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
if
(
param
->
val
==
NULL
)
{
metaError
(
"vgId:%d, failed to filter NULL data"
,
TD_VID
(
pMeta
->
pVnode
));
ret
=
-
1
;
goto
END
;
}
else
{
if
(
IS_VAR_DATA_TYPE
(
param
->
type
))
{
...
...
@@ -1104,6 +1242,7 @@ 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
;
...
...
source/dnode/vnode/src/meta/metaTable.c
浏览文件 @
e86cdc8c
...
...
@@ -27,6 +27,11 @@ static int metaUpdateSuidIdx(SMeta *pMeta, const SMetaEntry *pME);
static
int
metaUpdateTagIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pCtbEntry
);
static
int
metaDropTableByUid
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
int
*
type
);
static
void
metaDestroyTagIdxKey
(
STagIdxKey
*
pTagIdxKey
);
// opt ins_tables query
static
int
metaUpdateCtimeIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
int
metaDeleteCtimeIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
int
metaUpdateNcolIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
int
metaDeleteNcolIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
);
static
void
metaGetEntryInfo
(
const
SMetaEntry
*
pEntry
,
SMetaInfo
*
pInfo
)
{
pInfo
->
uid
=
pEntry
->
uid
;
...
...
@@ -551,6 +556,26 @@ static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME) {
ttlKey
->
dtime
=
ctime
/
1000
+
ttlDays
*
tsTtlUnit
;
ttlKey
->
uid
=
pME
->
uid
;
}
static
int
metaBuildCtimeIdxKey
(
SCtimeIdxKey
*
ctimeKey
,
const
SMetaEntry
*
pME
)
{
int64_t
ctime
;
if
(
pME
->
type
==
TSDB_CHILD_TABLE
)
{
ctime
=
pME
->
ctbEntry
.
ctime
;
}
else
if
(
pME
->
type
==
TSDB_NORMAL_TABLE
)
{
ctime
=
pME
->
ntbEntry
.
ctime
;
}
else
{
return
-
1
;
}
ctimeKey
->
ctime
=
ctime
;
ctimeKey
->
uid
=
pME
->
uid
;
return
0
;
}
static
int
metaBuildNColIdxKey
(
SNcolIdxKey
*
ncolKey
,
const
SMetaEntry
*
pME
)
{
ncolKey
->
ncol
=
pME
->
ntbEntry
.
schemaRow
.
nCols
;
ncolKey
->
uid
=
pME
->
uid
;
return
0
;
}
static
int
metaDeleteTtlIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
STtlIdxKey
ttlKey
=
{
0
};
...
...
@@ -632,6 +657,9 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
tdbTbDelete
(
pMeta
->
pNameIdx
,
e
.
name
,
strlen
(
e
.
name
)
+
1
,
&
pMeta
->
txn
);
tdbTbDelete
(
pMeta
->
pUidIdx
,
&
uid
,
sizeof
(
uid
),
&
pMeta
->
txn
);
if
(
e
.
type
==
TSDB_CHILD_TABLE
||
e
.
type
==
TSDB_NORMAL_TABLE
)
metaDeleteCtimeIdx
(
pMeta
,
&
e
);
if
(
e
.
type
==
TSDB_NORMAL_TABLE
)
metaDeleteNcolIdx
(
pMeta
,
&
e
);
if
(
e
.
type
!=
TSDB_SUPER_TABLE
)
metaDeleteTtlIdx
(
pMeta
,
&
e
);
if
(
e
.
type
==
TSDB_CHILD_TABLE
)
{
...
...
@@ -658,6 +686,37 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
return
0
;
}
// opt ins_tables
int
metaUpdateCtimeIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
SCtimeIdxKey
ctimeKey
=
{
0
};
if
(
metaBuildCtimeIdxKey
(
&
ctimeKey
,
pME
)
<
0
)
{
return
0
;
}
return
tdbTbInsert
(
pMeta
->
pCtimeIdx
,
&
ctimeKey
,
sizeof
(
ctimeKey
),
NULL
,
0
,
&
pMeta
->
txn
);
}
int
metaDeleteCtimeIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
SCtimeIdxKey
ctimeKey
=
{
0
};
if
(
metaBuildCtimeIdxKey
(
&
ctimeKey
,
pME
)
<
0
)
{
return
0
;
}
return
tdbTbDelete
(
pMeta
->
pCtimeIdx
,
&
ctimeKey
,
sizeof
(
ctimeKey
),
&
pMeta
->
txn
);
}
int
metaUpdateNcolIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
SNcolIdxKey
ncolKey
=
{
0
};
if
(
metaBuildNColIdxKey
(
&
ncolKey
,
pME
)
<
0
)
{
return
0
;
}
return
tdbTbInsert
(
pMeta
->
pNcolIdx
,
&
ncolKey
,
sizeof
(
ncolKey
),
NULL
,
0
,
&
pMeta
->
txn
);
}
int
metaDeleteNcolIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
SNcolIdxKey
ncolKey
=
{
0
};
if
(
metaBuildNColIdxKey
(
&
ncolKey
,
pME
)
<
0
)
{
return
0
;
}
return
tdbTbDelete
(
pMeta
->
pNcolIdx
,
&
ncolKey
,
sizeof
(
ncolKey
),
&
pMeta
->
txn
);
}
static
int
metaAlterTableColumn
(
SMeta
*
pMeta
,
int64_t
version
,
SVAlterTbReq
*
pAlterTbReq
,
STableMetaRsp
*
pMetaRsp
)
{
void
*
pVal
=
NULL
;
...
...
@@ -1372,6 +1431,12 @@ int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME) {
}
}
if
(
metaUpdateCtimeIdx
(
pMeta
,
pME
)
<
0
)
goto
_err
;
if
(
pME
->
type
==
TSDB_NORMAL_TABLE
)
{
if
(
metaUpdateNcolIdx
(
pMeta
,
pME
)
<
0
)
goto
_err
;
}
if
(
pME
->
type
!=
TSDB_SUPER_TABLE
)
{
if
(
metaUpdateTtlIdx
(
pMeta
,
pME
)
<
0
)
goto
_err
;
}
...
...
source/libs/executor/inc/executorimpl.h
浏览文件 @
e86cdc8c
...
...
@@ -541,6 +541,12 @@ typedef struct {
SSnapContext
*
sContext
;
}
SStreamRawScanInfo
;
typedef
struct
SSysTableIndex
{
int8_t
init
;
SArray
*
uids
;
int32_t
lastIdx
;
}
SSysTableIndex
;
typedef
struct
SSysTableScanInfo
{
SRetrieveMetaTableRsp
*
pRsp
;
SRetrieveTableReq
req
;
...
...
@@ -553,6 +559,7 @@ typedef struct SSysTableScanInfo {
bool
showRewrite
;
SNode
*
pCondition
;
// db_name filter condition, to discard data that are not in current database
SMTbCursor
*
pCur
;
// cursor for iterate the local table meta store.
SSysTableIndex
*
pIdx
;
// idx for local table meta
SArray
*
scanCols
;
// SArray<int16_t> scan column id list
SName
name
;
SSDataBlock
*
pRes
;
...
...
source/libs/executor/src/executil.c
浏览文件 @
e86cdc8c
...
...
@@ -422,16 +422,6 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, int64_t suid, SArray*
goto
end
;
}
}
/*else {
code = metaGetTableTagsByUids(metaHandle, suid, uidList, tags);
if (code != 0) {
terrno = code;
qError("failed to get table from meta idx, reason: %s, suid:%" PRId64, tstrerror(code), suid);
goto end;
} else {
qInfo("succ to get table from meta idx, suid:%" PRId64, suid);
}
}*/
int32_t
rows
=
taosArrayGetSize
(
uidList
);
if
(
rows
==
0
)
{
...
...
@@ -1212,11 +1202,10 @@ void createExprFromOneNode(SExprInfo* pExp, SNode* pNode, int16_t slotId) {
#if 1
// todo refactor: add the parameter for tbname function
const
char
*
name
=
"tbname"
;
int32_t
len
=
strlen
(
name
);
int32_t
len
=
strlen
(
name
);
if
(
!
pFuncNode
->
pParameterList
&&
(
memcmp
(
pExprNode
->
_function
.
functionName
,
name
,
len
)
==
0
)
&&
pExprNode
->
_function
.
functionName
[
len
]
==
0
)
{
pFuncNode
->
pParameterList
=
nodesMakeList
();
ASSERT
(
LIST_LENGTH
(
pFuncNode
->
pParameterList
)
==
0
);
SValueNode
*
res
=
(
SValueNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
...
...
@@ -1261,13 +1250,13 @@ void createExprFromOneNode(SExprInfo* pExp, SNode* pNode, int16_t slotId) {
}
else
if
(
type
==
QUERY_NODE_CASE_WHEN
)
{
pExp
->
pExpr
->
nodeType
=
QUERY_NODE_OPERATOR
;
SCaseWhenNode
*
pCaseNode
=
(
SCaseWhenNode
*
)
pNode
;
pExp
->
base
.
pParam
=
taosMemoryCalloc
(
1
,
sizeof
(
SFunctParam
));
pExp
->
base
.
numOfParams
=
1
;
SDataType
*
pType
=
&
pCaseNode
->
node
.
resType
;
pExp
->
base
.
resSchema
=
createResSchema
(
pType
->
type
,
pType
->
bytes
,
slotId
,
pType
->
scale
,
pType
->
precision
,
pCaseNode
->
node
.
aliasName
);
pExp
->
base
.
resSchema
=
createResSchema
(
pType
->
type
,
pType
->
bytes
,
slotId
,
pType
->
scale
,
pType
->
precision
,
pCaseNode
->
node
.
aliasName
);
pExp
->
pExpr
->
_optrRoot
.
pRootNode
=
pNode
;
}
else
{
ASSERT
(
0
);
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
e86cdc8c
...
...
@@ -39,6 +39,64 @@ static int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo, int32_t capac
static
int32_t
buildDbTableInfoBlock
(
bool
sysInfo
,
const
SSDataBlock
*
p
,
const
SSysTableMeta
*
pSysDbTableMeta
,
size_t
size
,
const
char
*
dbName
);
static
char
*
SYSTABLE_IDX_COLUMN
[]
=
{
"table_name"
,
"db_name"
,
"create_time"
,
"columns"
,
"ttl"
,
"stable_name"
,
"vgroup_id', 'uid"
,
"type"
};
static
char
*
SYSTABLE_IDX_EXCEPT
[]
=
{
"db_name"
,
"vgroup_id"
};
typedef
int32_t
(
*
__sys_filte
)(
void
*
pMeta
,
SNode
*
cond
,
SArray
*
result
);
typedef
int32_t
(
*
__sys_check
)(
SNode
*
cond
);
typedef
struct
{
const
char
*
name
;
__sys_check
chkFunc
;
__sys_filte
fltFunc
;
}
SSTabFltFuncDef
;
typedef
struct
{
void
*
pMeta
;
void
*
pVnode
;
}
SSTabFltArg
;
static
int32_t
sysChkFilter__Comm
(
SNode
*
pNode
);
static
int32_t
sysChkFilter__DBName
(
SNode
*
pNode
);
static
int32_t
sysChkFilter__VgroupId
(
SNode
*
pNode
);
static
int32_t
sysChkFilter__TableName
(
SNode
*
pNode
);
static
int32_t
sysChkFilter__CreateTime
(
SNode
*
pNode
);
static
int32_t
sysChkFilter__Ncolumn
(
SNode
*
pNode
);
static
int32_t
sysChkFilter__Ttl
(
SNode
*
pNode
);
static
int32_t
sysChkFilter__STableName
(
SNode
*
pNode
);
static
int32_t
sysChkFilter__Uid
(
SNode
*
pNode
);
static
int32_t
sysChkFilter__Type
(
SNode
*
pNode
);
static
int32_t
sysFilte__DbName
(
void
*
pMeta
,
SNode
*
pNode
,
SArray
*
result
);
static
int32_t
sysFilte__VgroupId
(
void
*
pMeta
,
SNode
*
pNode
,
SArray
*
result
);
static
int32_t
sysFilte__TableName
(
void
*
pMeta
,
SNode
*
pNode
,
SArray
*
result
);
static
int32_t
sysFilte__CreateTime
(
void
*
pMeta
,
SNode
*
pNode
,
SArray
*
result
);
static
int32_t
sysFilte__Ncolumn
(
void
*
pMeta
,
SNode
*
pNode
,
SArray
*
result
);
static
int32_t
sysFilte__Ttl
(
void
*
pMeta
,
SNode
*
pNode
,
SArray
*
result
);
static
int32_t
sysFilte__STableName
(
void
*
pMeta
,
SNode
*
pNode
,
SArray
*
result
);
static
int32_t
sysFilte__Uid
(
void
*
pMeta
,
SNode
*
pNode
,
SArray
*
result
);
static
int32_t
sysFilte__Type
(
void
*
pMeta
,
SNode
*
pNode
,
SArray
*
result
);
const
SSTabFltFuncDef
filterDict
[]
=
{
{.
name
=
"table_name"
,
.
chkFunc
=
sysChkFilter__TableName
,
.
fltFunc
=
sysFilte__TableName
},
{.
name
=
"db_name"
,
.
chkFunc
=
sysChkFilter__DBName
,
.
fltFunc
=
sysFilte__DbName
},
{.
name
=
"create_time"
,
.
chkFunc
=
sysChkFilter__CreateTime
,
.
fltFunc
=
sysFilte__CreateTime
},
{.
name
=
"columns"
,
.
chkFunc
=
sysChkFilter__Ncolumn
,
.
fltFunc
=
sysFilte__Ncolumn
},
{.
name
=
"ttl"
,
.
chkFunc
=
sysChkFilter__Ttl
,
.
fltFunc
=
sysFilte__Ttl
},
{.
name
=
"stable_name"
,
.
chkFunc
=
sysChkFilter__STableName
,
.
fltFunc
=
sysFilte__STableName
},
{.
name
=
"vgroup_id"
,
.
chkFunc
=
sysChkFilter__VgroupId
,
.
fltFunc
=
sysFilte__VgroupId
},
{.
name
=
"uid"
,
.
chkFunc
=
sysChkFilter__Uid
,
.
fltFunc
=
sysFilte__Uid
},
{.
name
=
"type"
,
.
chkFunc
=
sysChkFilter__Type
,
.
fltFunc
=
sysFilte__Type
}};
#define SYSTAB_FILTER_DICT_SIZE (sizeof(filterDict) / sizeof(filterDict[0]))
static
int32_t
optSysTabFilte
(
void
*
arg
,
SNode
*
cond
,
SArray
*
result
);
static
int32_t
optSysTabFilteImpl
(
void
*
arg
,
SNode
*
cond
,
SArray
*
result
);
static
int32_t
optSysCheckOper
(
SNode
*
pOpear
);
static
int32_t
optSysMergeRslt
(
SArray
*
multiRslt
,
SArray
*
reslt
);
static
bool
processBlockWithProbability
(
const
SSampleExecInfo
*
pInfo
);
static
int32_t
sysTableUserTagsFillOneTableTags
(
const
SSysTableScanInfo
*
pInfo
,
SMetaReader
*
smrSuperTable
,
...
...
@@ -2323,6 +2381,11 @@ static void destroySysScanOperator(void* param) {
metaCloseTbCursor
(
pInfo
->
pCur
);
pInfo
->
pCur
=
NULL
;
}
if
(
pInfo
->
pIdx
)
{
taosArrayDestroy
(
pInfo
->
pIdx
->
uids
);
taosMemoryFree
(
pInfo
->
pIdx
);
pInfo
->
pIdx
=
NULL
;
}
taosArrayDestroy
(
pInfo
->
scanCols
);
taosMemoryFreeClear
(
pInfo
->
pUser
);
...
...
@@ -2790,174 +2853,754 @@ static int32_t sysTableUserTagsFillOneTableTags(const SSysTableScanInfo* pInfo,
return
TSDB_CODE_SUCCESS
;
}
static
SSDataBlock
*
sysTableScanUserTables
(
SOperatorInfo
*
pOperator
)
{
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SSysTableScanInfo
*
pInfo
=
pOperator
->
info
;
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
return
NULL
;
typedef
int
(
*
__optSysFilter
)(
void
*
a
,
void
*
b
,
int16_t
dtype
);
int
optSysDoCompare
(
__compar_fn_t
func
,
int8_t
comparType
,
void
*
a
,
void
*
b
)
{
int32_t
cmp
=
func
(
a
,
b
);
switch
(
comparType
)
{
case
OP_TYPE_LOWER_THAN
:
if
(
cmp
<
0
)
return
0
;
break
;
case
OP_TYPE_LOWER_EQUAL
:
{
if
(
cmp
<=
0
)
return
0
;
break
;
}
case
OP_TYPE_GREATER_THAN
:
{
if
(
cmp
>
0
)
return
0
;
break
;
}
case
OP_TYPE_GREATER_EQUAL
:
{
if
(
cmp
>=
0
)
return
0
;
break
;
}
case
OP_TYPE_EQUAL
:
{
if
(
cmp
==
0
)
return
0
;
break
;
}
default:
return
-
1
;
}
return
1
;
}
// the retrieve is executed on the mnode, so return tables that belongs to the information schema database.
if
(
pInfo
->
readHandle
.
mnd
!=
NULL
)
{
buildSysDbTableInfo
(
pInfo
,
pOperator
->
resultInfo
.
capacity
);
static
int
optSysFilterFuncImpl__LowerThan
(
void
*
a
,
void
*
b
,
int16_t
dtype
)
{
__compar_fn_t
func
=
getComparFunc
(
dtype
,
0
);
return
optSysDoCompare
(
func
,
OP_TYPE_LOWER_THAN
,
a
,
b
);
}
static
int
optSysFilterFuncImpl__LowerEqual
(
void
*
a
,
void
*
b
,
int16_t
dtype
)
{
__compar_fn_t
func
=
getComparFunc
(
dtype
,
0
);
return
optSysDoCompare
(
func
,
OP_TYPE_LOWER_EQUAL
,
a
,
b
);
}
static
int
optSysFilterFuncImpl__GreaterThan
(
void
*
a
,
void
*
b
,
int16_t
dtype
)
{
__compar_fn_t
func
=
getComparFunc
(
dtype
,
0
);
return
optSysDoCompare
(
func
,
OP_TYPE_GREATER_THAN
,
a
,
b
);
}
static
int
optSysFilterFuncImpl__GreaterEqual
(
void
*
a
,
void
*
b
,
int16_t
dtype
)
{
__compar_fn_t
func
=
getComparFunc
(
dtype
,
0
);
return
optSysDoCompare
(
func
,
OP_TYPE_GREATER_EQUAL
,
a
,
b
);
}
static
int
optSysFilterFuncImpl__Equal
(
void
*
a
,
void
*
b
,
int16_t
dtype
)
{
__compar_fn_t
func
=
getComparFunc
(
dtype
,
0
);
return
optSysDoCompare
(
func
,
OP_TYPE_EQUAL
,
a
,
b
);
}
doFilterResult
(
pInfo
);
pInfo
->
loadInfo
.
totalRows
+=
pInfo
->
pRes
->
info
.
rows
;
static
int
optSysFilterFuncImpl__NoEqual
(
void
*
a
,
void
*
b
,
int16_t
dtype
)
{
__compar_fn_t
func
=
getComparFunc
(
dtype
,
0
);
return
optSysDoCompare
(
func
,
OP_TYPE_NOT_EQUAL
,
a
,
b
);
}
static
__optSysFilter
optSysGetFilterFunc
(
int32_t
ctype
,
bool
*
reverse
)
{
if
(
ctype
==
OP_TYPE_LOWER_EQUAL
||
ctype
==
OP_TYPE_LOWER_THAN
)
{
*
reverse
=
true
;
}
if
(
ctype
==
OP_TYPE_LOWER_THAN
)
return
optSysFilterFuncImpl__LowerThan
;
else
if
(
ctype
==
OP_TYPE_LOWER_EQUAL
)
return
optSysFilterFuncImpl__LowerEqual
;
else
if
(
ctype
==
OP_TYPE_GREATER_THAN
)
return
optSysFilterFuncImpl__GreaterThan
;
else
if
(
ctype
==
OP_TYPE_GREATER_EQUAL
)
return
optSysFilterFuncImpl__GreaterEqual
;
else
if
(
ctype
==
OP_TYPE_EQUAL
)
return
optSysFilterFuncImpl__Equal
;
else
if
(
ctype
==
OP_TYPE_NOT_EQUAL
)
return
optSysFilterFuncImpl__NoEqual
;
return
NULL
;
}
static
int32_t
sysFilte__DbName
(
void
*
arg
,
SNode
*
pNode
,
SArray
*
result
)
{
void
*
pVnode
=
((
SSTabFltArg
*
)
arg
)
->
pVnode
;
doSetOperatorCompleted
(
pOperator
);
return
(
pInfo
->
pRes
->
info
.
rows
==
0
)
?
NULL
:
pInfo
->
pRes
;
}
else
{
if
(
pInfo
->
pCur
==
NULL
)
{
pInfo
->
pCur
=
metaOpenTbCursor
(
pInfo
->
readHandle
.
meta
);
const
char
*
db
=
NULL
;
vnodeGetInfo
(
pVnode
,
&
db
,
NULL
);
SName
sn
=
{
0
};
char
dbname
[
TSDB_DB_FNAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
tNameFromString
(
&
sn
,
db
,
T_NAME_ACCT
|
T_NAME_DB
);
tNameGetDbName
(
&
sn
,
varDataVal
(
dbname
));
varDataSetLen
(
dbname
,
strlen
(
varDataVal
(
dbname
)));
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
bool
reverse
=
false
;
__optSysFilter
func
=
optSysGetFilterFunc
(
pOper
->
opType
,
&
reverse
);
if
(
func
==
NULL
)
return
-
1
;
int
ret
=
func
(
dbname
,
pVal
->
datum
.
p
,
TSDB_DATA_TYPE_VARCHAR
);
if
(
ret
==
0
)
return
0
;
return
-
2
;
}
static
int32_t
sysFilte__VgroupId
(
void
*
arg
,
SNode
*
pNode
,
SArray
*
result
)
{
void
*
pVnode
=
((
SSTabFltArg
*
)
arg
)
->
pVnode
;
int64_t
vgId
=
0
;
vnodeGetInfo
(
pVnode
,
NULL
,
(
int32_t
*
)
&
vgId
);
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
bool
reverse
=
false
;
__optSysFilter
func
=
optSysGetFilterFunc
(
pOper
->
opType
,
&
reverse
);
if
(
func
==
NULL
)
return
-
1
;
int
ret
=
func
(
&
vgId
,
&
pVal
->
datum
.
i
,
TSDB_DATA_TYPE_BIGINT
);
if
(
ret
==
0
)
return
0
;
return
-
1
;
}
static
int32_t
sysFilte__TableName
(
void
*
arg
,
SNode
*
pNode
,
SArray
*
result
)
{
void
*
pMeta
=
((
SSTabFltArg
*
)
arg
)
->
pMeta
;
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
bool
reverse
=
false
;
__optSysFilter
func
=
optSysGetFilterFunc
(
pOper
->
opType
,
&
reverse
);
if
(
func
==
NULL
)
return
-
1
;
SMetaFltParam
param
=
{.
suid
=
0
,
.
cid
=
0
,
.
type
=
TSDB_DATA_TYPE_VARCHAR
,
.
val
=
pVal
->
datum
.
p
,
.
reverse
=
reverse
,
.
filterFunc
=
func
};
int32_t
ret
=
metaFilterCreateTime
(
pMeta
,
&
param
,
result
);
if
(
ret
==
0
)
return
0
;
return
-
1
;
}
static
int32_t
sysFilte__CreateTime
(
void
*
arg
,
SNode
*
pNode
,
SArray
*
result
)
{
void
*
pMeta
=
((
SSTabFltArg
*
)
arg
)
->
pMeta
;
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
bool
reverse
=
false
;
__optSysFilter
func
=
optSysGetFilterFunc
(
pOper
->
opType
,
&
reverse
);
SMetaFltParam
param
=
{.
suid
=
0
,
.
cid
=
0
,
.
type
=
TSDB_DATA_TYPE_BIGINT
,
.
val
=
&
pVal
->
datum
.
i
,
.
reverse
=
reverse
,
.
filterFunc
=
func
};
int32_t
ret
=
metaFilterCreateTime
(
pMeta
,
&
param
,
result
);
if
(
func
==
NULL
)
return
-
1
;
return
0
;
}
static
int32_t
sysFilte__Ncolumn
(
void
*
arg
,
SNode
*
pNode
,
SArray
*
result
)
{
void
*
pMeta
=
((
SSTabFltArg
*
)
arg
)
->
pMeta
;
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
bool
reverse
=
false
;
__optSysFilter
func
=
optSysGetFilterFunc
(
pOper
->
opType
,
&
reverse
);
if
(
func
==
NULL
)
return
-
1
;
return
-
1
;
}
static
int32_t
sysFilte__Ttl
(
void
*
arg
,
SNode
*
pNode
,
SArray
*
result
)
{
void
*
pMeta
=
((
SSTabFltArg
*
)
arg
)
->
pMeta
;
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
bool
reverse
=
false
;
__optSysFilter
func
=
optSysGetFilterFunc
(
pOper
->
opType
,
&
reverse
);
if
(
func
==
NULL
)
return
-
1
;
return
-
1
;
}
static
int32_t
sysFilte__STableName
(
void
*
arg
,
SNode
*
pNode
,
SArray
*
result
)
{
void
*
pMeta
=
((
SSTabFltArg
*
)
arg
)
->
pMeta
;
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
bool
reverse
=
false
;
__optSysFilter
func
=
optSysGetFilterFunc
(
pOper
->
opType
,
&
reverse
);
if
(
func
==
NULL
)
return
-
1
;
return
-
1
;
}
static
int32_t
sysFilte__Uid
(
void
*
arg
,
SNode
*
pNode
,
SArray
*
result
)
{
void
*
pMeta
=
((
SSTabFltArg
*
)
arg
)
->
pMeta
;
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
bool
reverse
=
false
;
__optSysFilter
func
=
optSysGetFilterFunc
(
pOper
->
opType
,
&
reverse
);
if
(
func
==
NULL
)
return
-
1
;
return
-
1
;
}
static
int32_t
sysFilte__Type
(
void
*
arg
,
SNode
*
pNode
,
SArray
*
result
)
{
void
*
pMeta
=
((
SSTabFltArg
*
)
arg
)
->
pMeta
;
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
bool
reverse
=
false
;
__optSysFilter
func
=
optSysGetFilterFunc
(
pOper
->
opType
,
&
reverse
);
if
(
func
==
NULL
)
return
-
1
;
return
-
1
;
}
static
int32_t
sysChkFilter__Comm
(
SNode
*
pNode
)
{
// impl
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
EOperatorType
opType
=
pOper
->
opType
;
if
(
opType
!=
OP_TYPE_EQUAL
&&
opType
!=
OP_TYPE_LOWER_EQUAL
&&
opType
!=
OP_TYPE_LOWER_THAN
&&
OP_TYPE_GREATER_EQUAL
&&
opType
!=
OP_TYPE_GREATER_THAN
)
{
return
-
1
;
}
return
0
;
}
static
int32_t
sysChkFilter__DBName
(
SNode
*
pNode
)
{
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
if
(
pOper
->
opType
!=
OP_TYPE_EQUAL
&&
pOper
->
opType
!=
OP_TYPE_NOT_EQUAL
)
{
return
-
1
;
}
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
if
(
!
IS_STR_DATA_TYPE
(
pVal
->
node
.
resType
.
type
))
{
return
-
1
;
}
return
0
;
}
static
int32_t
sysChkFilter__VgroupId
(
SNode
*
pNode
)
{
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
if
(
!
IS_INTEGER_TYPE
(
pVal
->
node
.
resType
.
type
))
{
return
-
1
;
}
return
sysChkFilter__Comm
(
pNode
);
}
static
int32_t
sysChkFilter__TableName
(
SNode
*
pNode
)
{
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
if
(
!
IS_STR_DATA_TYPE
(
pVal
->
node
.
resType
.
type
))
{
return
-
1
;
}
return
sysChkFilter__Comm
(
pNode
);
}
static
int32_t
sysChkFilter__CreateTime
(
SNode
*
pNode
)
{
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
if
(
!
IS_TIMESTAMP_TYPE
(
pVal
->
node
.
resType
.
type
))
{
return
-
1
;
}
return
sysChkFilter__Comm
(
pNode
);
}
static
int32_t
sysChkFilter__Ncolumn
(
SNode
*
pNode
)
{
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
if
(
!
IS_INTEGER_TYPE
(
pVal
->
node
.
resType
.
type
))
{
return
-
1
;
}
return
sysChkFilter__Comm
(
pNode
);
}
static
int32_t
sysChkFilter__Ttl
(
SNode
*
pNode
)
{
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
if
(
!
IS_INTEGER_TYPE
(
pVal
->
node
.
resType
.
type
))
{
return
-
1
;
}
return
sysChkFilter__Comm
(
pNode
);
}
static
int32_t
sysChkFilter__STableName
(
SNode
*
pNode
)
{
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
if
(
!
IS_STR_DATA_TYPE
(
pVal
->
node
.
resType
.
type
))
{
return
-
1
;
}
return
sysChkFilter__Comm
(
pNode
);
}
static
int32_t
sysChkFilter__Uid
(
SNode
*
pNode
)
{
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
if
(
!
IS_INTEGER_TYPE
(
pVal
->
node
.
resType
.
type
))
{
return
-
1
;
}
return
sysChkFilter__Comm
(
pNode
);
}
static
int32_t
sysChkFilter__Type
(
SNode
*
pNode
)
{
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pNode
;
SValueNode
*
pVal
=
(
SValueNode
*
)
pOper
->
pRight
;
if
(
!
IS_INTEGER_TYPE
(
pVal
->
node
.
resType
.
type
))
{
return
-
1
;
}
return
sysChkFilter__Comm
(
pNode
);
}
static
int32_t
optSysTabFilteImpl
(
void
*
arg
,
SNode
*
cond
,
SArray
*
result
)
{
if
(
optSysCheckOper
(
cond
)
!=
0
)
return
-
1
;
SOperatorNode
*
pNode
=
(
SOperatorNode
*
)
cond
;
int8_t
i
=
0
;
for
(;
i
<
SYSTAB_FILTER_DICT_SIZE
;
i
++
)
{
if
(
strcmp
(
filterDict
[
i
].
name
,
((
SColumnNode
*
)(
pNode
->
pLeft
))
->
colName
)
==
0
)
{
break
;
}
}
if
(
i
>=
SYSTAB_FILTER_DICT_SIZE
)
return
-
1
;
blockDataCleanup
(
pInfo
->
pRes
);
int32_t
numOfRows
=
0
;
if
(
filterDict
[
i
].
chkFunc
(
cond
)
!=
0
)
return
-
1
;
const
char
*
db
=
NULL
;
int32_t
vgId
=
0
;
vnodeGetInfo
(
pInfo
->
readHandle
.
vnode
,
&
db
,
&
vgId
);
return
filterDict
[
i
].
fltFunc
(
arg
,
cond
,
result
);
}
SName
sn
=
{
0
};
char
dbname
[
TSDB_DB_FNAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
tNameFromString
(
&
sn
,
db
,
T_NAME_ACCT
|
T_NAME_DB
);
static
int32_t
optSysCheckOper
(
SNode
*
pOpear
)
{
if
(
nodeType
(
pOpear
)
!=
QUERY_NODE_OPERATOR
)
return
-
1
;
tNameGetDbName
(
&
sn
,
varDataVal
(
dbname
));
varDataSetLen
(
dbname
,
strlen
(
varDataVal
(
dbname
)));
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pOpear
;
if
(
pOper
->
opType
<
OP_TYPE_GREATER_THAN
||
pOper
->
opType
>
OP_TYPE_NOT_EQUAL
)
{
return
-
1
;
}
SSDataBlock
*
p
=
buildInfoSchemaTableMetaBlock
(
TSDB_INS_TABLE_TABLES
);
blockDataEnsureCapacity
(
p
,
pOperator
->
resultInfo
.
capacity
);
if
(
nodeType
(
pOper
->
pLeft
)
!=
QUERY_NODE_COLUMN
||
nodeType
(
pOper
->
pRight
)
!=
QUERY_NODE_VALUE
)
{
return
-
1
;
}
return
0
;
}
static
int32_t
optSysMergeRslt
(
SArray
*
mRslt
,
SArray
*
rslt
)
{
// TODO, find comm mem from mRslt
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
mRslt
);
i
++
)
{
SArray
*
aRslt
=
taosArrayGetP
(
mRslt
,
i
);
taosArrayAddAll
(
rslt
,
aRslt
);
}
return
0
;
}
char
n
[
TSDB_TABLE_NAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
static
int32_t
optSysTabFilte
(
void
*
arg
,
SNode
*
cond
,
SArray
*
result
)
{
int
ret
=
-
1
;
if
(
nodeType
(
cond
)
==
QUERY_NODE_OPERATOR
)
{
ret
=
optSysTabFilteImpl
(
arg
,
cond
,
result
);
if
(
ret
==
0
)
{
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
cond
;
SColumnNode
*
pCol
=
(
SColumnNode
*
)
pOper
->
pLeft
;
if
(
0
==
strcmp
(
pCol
->
colName
,
"create_time"
))
{
return
0
;
}
return
-
1
;
}
return
ret
;
}
int32_t
ret
=
0
;
while
((
ret
=
metaTbCursorNext
(
pInfo
->
pCur
))
==
0
)
{
STR_TO_VARSTR
(
n
,
pInfo
->
pCur
->
mr
.
me
.
name
);
if
(
nodeType
(
cond
)
!=
QUERY_NODE_LOGIC_CONDITION
||
((
SLogicConditionNode
*
)
cond
)
->
condType
!=
LOGIC_COND_TYPE_AND
)
{
return
ret
;
}
// table name
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
0
);
colDataAppend
(
pColInfoData
,
numOfRows
,
n
,
false
);
SLogicConditionNode
*
pNode
=
(
SLogicConditionNode
*
)
cond
;
SNodeList
*
pList
=
(
SNodeList
*
)
pNode
->
pParameterList
;
// database name
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
1
);
colDataAppend
(
pColInfoData
,
numOfRows
,
dbname
,
false
);
// vgId
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
6
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
vgId
,
false
);
int32_t
tableType
=
pInfo
->
pCur
->
mr
.
me
.
type
;
if
(
tableType
==
TSDB_CHILD_TABLE
)
{
// create time
int64_t
ts
=
pInfo
->
pCur
->
mr
.
me
.
ctbEntry
.
ctime
;
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
2
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
ts
,
false
);
SMetaReader
mr
=
{
0
};
metaReaderInit
(
&
mr
,
pInfo
->
readHandle
.
meta
,
META_READER_NOLOCK
);
uint64_t
suid
=
pInfo
->
pCur
->
mr
.
me
.
ctbEntry
.
suid
;
int32_t
code
=
metaGetTableEntryByUid
(
&
mr
,
suid
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
qError
(
"failed to get super table meta, cname:%s, suid:0x%"
PRIx64
", code:%s, %s"
,
pInfo
->
pCur
->
mr
.
me
.
name
,
suid
,
tstrerror
(
terrno
),
GET_TASKID
(
pTaskInfo
));
metaReaderClear
(
&
mr
);
metaCloseTbCursor
(
pInfo
->
pCur
);
pInfo
->
pCur
=
NULL
;
T_LONG_JMP
(
pTaskInfo
->
env
,
terrno
);
}
int32_t
len
=
LIST_LENGTH
(
pList
);
if
(
len
<=
0
)
return
ret
;
bool
hasIdx
=
false
;
bool
hasRslt
=
true
;
SArray
*
mRslt
=
taosArrayInit
(
len
,
POINTER_BYTES
);
SListCell
*
cell
=
pList
->
pHead
;
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
if
(
cell
==
NULL
)
break
;
// number of columns
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
3
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
mr
.
me
.
stbEntry
.
schemaRow
.
nCols
,
false
);
SArray
*
aRslt
=
taosArrayInit
(
16
,
sizeof
(
int64_t
));
ret
=
optSysTabFilteImpl
(
arg
,
cell
->
pNode
,
aRslt
);
if
(
ret
==
0
)
{
// has index
hasIdx
=
true
;
taosArrayPush
(
mRslt
,
&
aRslt
);
}
else
if
(
ret
==
-
2
)
{
// current vg
hasIdx
=
true
;
hasRslt
=
false
;
taosArrayDestroy
(
aRslt
);
break
;
}
else
{
taosArrayDestroy
(
aRslt
);
}
cell
=
cell
->
pNext
;
}
if
(
hasRslt
&&
hasIdx
)
{
optSysMergeRslt
(
mRslt
,
result
);
}
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
mRslt
);
i
++
)
{
SArray
*
aRslt
=
taosArrayGetP
(
mRslt
,
i
);
taosArrayDestroy
(
aRslt
);
}
taosArrayDestroy
(
mRslt
);
if
(
hasRslt
==
false
)
{
return
-
2
;
}
if
(
hasRslt
&&
hasIdx
)
{
cell
=
pList
->
pHead
;
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
if
(
cell
==
NULL
)
break
;
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
cell
->
pNode
;
SColumnNode
*
pCol
=
(
SColumnNode
*
)
pOper
->
pLeft
;
if
(
0
==
strcmp
(
pCol
->
colName
,
"create_time"
))
{
return
0
;
}
cell
=
cell
->
pNext
;
}
return
-
1
;
}
return
-
1
;
}
static
SSDataBlock
*
sysTableBuildUserTablesByUids
(
SOperatorInfo
*
pOperator
)
{
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SSysTableScanInfo
*
pInfo
=
pOperator
->
info
;
SSysTableIndex
*
pIdx
=
pInfo
->
pIdx
;
blockDataCleanup
(
pInfo
->
pRes
);
int32_t
numOfRows
=
0
;
int
ret
=
0
;
const
char
*
db
=
NULL
;
int32_t
vgId
=
0
;
vnodeGetInfo
(
pInfo
->
readHandle
.
vnode
,
&
db
,
&
vgId
);
SName
sn
=
{
0
};
char
dbname
[
TSDB_DB_FNAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
tNameFromString
(
&
sn
,
db
,
T_NAME_ACCT
|
T_NAME_DB
);
// super table name
STR_TO_VARSTR
(
n
,
mr
.
me
.
name
);
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
4
);
colDataAppend
(
pColInfoData
,
numOfRows
,
n
,
false
);
tNameGetDbName
(
&
sn
,
varDataVal
(
dbname
));
varDataSetLen
(
dbname
,
strlen
(
varDataVal
(
dbname
)));
SSDataBlock
*
p
=
buildInfoSchemaTableMetaBlock
(
TSDB_INS_TABLE_TABLES
);
blockDataEnsureCapacity
(
p
,
pOperator
->
resultInfo
.
capacity
);
char
n
[
TSDB_TABLE_NAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
int32_t
i
=
pIdx
->
lastIdx
;
for
(;
i
<
taosArrayGetSize
(
pIdx
->
uids
);
i
++
)
{
tb_uid_t
*
uid
=
taosArrayGet
(
pIdx
->
uids
,
i
);
SMetaReader
mr
=
{
0
};
metaReaderInit
(
&
mr
,
pInfo
->
readHandle
.
meta
,
0
);
int32_t
ret
=
metaGetTableEntryByUid
(
&
mr
,
*
uid
);
if
(
ret
<
0
)
{
metaReaderClear
(
&
mr
);
continue
;
}
STR_TO_VARSTR
(
n
,
mr
.
me
.
name
);
// table name
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
0
);
colDataAppend
(
pColInfoData
,
numOfRows
,
n
,
false
);
// database name
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
1
);
colDataAppend
(
pColInfoData
,
numOfRows
,
dbname
,
false
);
// vgId
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
6
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
vgId
,
false
);
int32_t
tableType
=
mr
.
me
.
type
;
if
(
tableType
==
TSDB_CHILD_TABLE
)
{
// create time
int64_t
ts
=
mr
.
me
.
ctbEntry
.
ctime
;
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
2
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
ts
,
false
);
SMetaReader
mr1
=
{
0
};
metaReaderInit
(
&
mr1
,
pInfo
->
readHandle
.
meta
,
META_READER_NOLOCK
);
int64_t
suid
=
mr
.
me
.
ctbEntry
.
suid
;
int32_t
code
=
metaGetTableEntryByUid
(
&
mr1
,
suid
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
qError
(
"failed to get super table meta, cname:%s, suid:0x%"
PRIx64
", code:%s, %s"
,
pInfo
->
pCur
->
mr
.
me
.
name
,
suid
,
tstrerror
(
terrno
),
GET_TASKID
(
pTaskInfo
));
metaReaderClear
(
&
mr1
);
metaReaderClear
(
&
mr
);
T_LONG_JMP
(
pTaskInfo
->
env
,
terrno
);
}
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
3
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
mr1
.
me
.
stbEntry
.
schemaRow
.
nCols
,
false
);
// table comment
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
8
);
if
(
pInfo
->
pCur
->
mr
.
me
.
ctbEntry
.
commentLen
>
0
)
{
char
comment
[
TSDB_TB_COMMENT_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
STR_TO_VARSTR
(
comment
,
pInfo
->
pCur
->
mr
.
me
.
ctbEntry
.
comment
);
colDataAppend
(
pColInfoData
,
numOfRows
,
comment
,
false
);
}
else
if
(
pInfo
->
pCur
->
mr
.
me
.
ctbEntry
.
commentLen
==
0
)
{
char
comment
[
VARSTR_HEADER_SIZE
+
VARSTR_HEADER_SIZE
]
=
{
0
};
STR_TO_VARSTR
(
comment
,
""
);
colDataAppend
(
pColInfoData
,
numOfRows
,
comment
,
false
);
}
else
{
colDataAppendNULL
(
pColInfoData
,
numOfRows
);
}
// super table name
STR_TO_VARSTR
(
n
,
mr1
.
me
.
name
);
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
4
);
colDataAppend
(
pColInfoData
,
numOfRows
,
n
,
false
);
metaReaderClear
(
&
mr1
);
// table comment
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
8
);
if
(
mr
.
me
.
ctbEntry
.
commentLen
>
0
)
{
char
comment
[
TSDB_TB_COMMENT_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
STR_TO_VARSTR
(
comment
,
mr
.
me
.
ctbEntry
.
comment
);
colDataAppend
(
pColInfoData
,
numOfRows
,
comment
,
false
);
}
else
if
(
mr
.
me
.
ctbEntry
.
commentLen
==
0
)
{
char
comment
[
VARSTR_HEADER_SIZE
+
VARSTR_HEADER_SIZE
]
=
{
0
};
STR_TO_VARSTR
(
comment
,
""
);
colDataAppend
(
pColInfoData
,
numOfRows
,
comment
,
false
);
}
else
{
colDataAppendNULL
(
pColInfoData
,
numOfRows
);
}
// uid
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
5
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
uid
,
false
);
// uid
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
5
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
mr
.
me
.
uid
,
false
);
// ttl
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
7
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
ctbEntry
.
ttlDays
,
false
);
// ttl
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
7
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
mr
.
me
.
ctbEntry
.
ttlDays
,
false
);
STR_TO_VARSTR
(
n
,
"CHILD_TABLE"
);
}
else
if
(
tableType
==
TSDB_NORMAL_TABLE
)
{
// create time
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
2
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
ctime
,
false
);
STR_TO_VARSTR
(
n
,
"CHILD_TABLE"
);
// number of columns
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
3
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
schemaRow
.
nCols
,
false
);
}
else
if
(
tableType
==
TSDB_NORMAL_TABLE
)
{
// create time
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
2
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
ctime
,
false
);
// number of columns
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
3
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
schemaRow
.
nCols
,
false
);
// super table name
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
4
);
colDataAppendNULL
(
pColInfoData
,
numOfRows
);
// super table name
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
4
);
// table comment
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
8
);
if
(
mr
.
me
.
ntbEntry
.
commentLen
>
0
)
{
char
comment
[
TSDB_TB_COMMENT_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
STR_TO_VARSTR
(
comment
,
mr
.
me
.
ntbEntry
.
comment
);
colDataAppend
(
pColInfoData
,
numOfRows
,
comment
,
false
);
}
else
if
(
mr
.
me
.
ntbEntry
.
commentLen
==
0
)
{
char
comment
[
VARSTR_HEADER_SIZE
+
VARSTR_HEADER_SIZE
]
=
{
0
};
STR_TO_VARSTR
(
comment
,
""
);
colDataAppend
(
pColInfoData
,
numOfRows
,
comment
,
false
);
}
else
{
colDataAppendNULL
(
pColInfoData
,
numOfRows
);
}
// table comment
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
8
);
if
(
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
commentLen
>
0
)
{
char
comment
[
TSDB_TB_COMMENT_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
STR_TO_VARSTR
(
comment
,
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
comment
);
colDataAppend
(
pColInfoData
,
numOfRows
,
comment
,
false
);
}
else
if
(
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
commentLen
==
0
)
{
char
comment
[
VARSTR_HEADER_SIZE
+
VARSTR_HEADER_SIZE
]
=
{
0
};
STR_TO_VARSTR
(
comment
,
""
);
colDataAppend
(
pColInfoData
,
numOfRows
,
comment
,
false
);
}
else
{
colDataAppendNULL
(
pColInfoData
,
numOfRows
);
}
// uid
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
5
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
mr
.
me
.
uid
,
false
);
// ttl
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
7
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
mr
.
me
.
ntbEntry
.
ttlDays
,
false
);
// uid
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
5
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
uid
,
false
);
STR_TO_VARSTR
(
n
,
"NORMAL_TABLE"
);
// impl later
}
metaReaderClear
(
&
mr
);
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
9
);
colDataAppend
(
pColInfoData
,
numOfRows
,
n
,
false
);
// ttl
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
7
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
ttlDays
,
false
);
if
(
++
numOfRows
>=
pOperator
->
resultInfo
.
capacity
)
{
p
->
info
.
rows
=
numOfRows
;
pInfo
->
pRes
->
info
.
rows
=
numOfRows
;
relocateColumnData
(
pInfo
->
pRes
,
pInfo
->
scanCols
,
p
->
pDataBlock
,
false
);
doFilterResult
(
pInfo
);
STR_TO_VARSTR
(
n
,
"NORMAL_TABLE"
);
blockDataCleanup
(
p
);
numOfRows
=
0
;
if
(
pInfo
->
pRes
->
info
.
rows
>
0
)
{
break
;
}
}
}
if
(
numOfRows
>
0
)
{
p
->
info
.
rows
=
numOfRows
;
pInfo
->
pRes
->
info
.
rows
=
numOfRows
;
relocateColumnData
(
pInfo
->
pRes
,
pInfo
->
scanCols
,
p
->
pDataBlock
,
false
);
doFilterResult
(
pInfo
);
blockDataCleanup
(
p
);
numOfRows
=
0
;
}
if
(
i
>=
taosArrayGetSize
(
pIdx
->
uids
))
{
doSetOperatorCompleted
(
pOperator
);
}
else
{
pIdx
->
lastIdx
=
i
;
}
blockDataDestroy
(
p
);
pInfo
->
loadInfo
.
totalRows
+=
pInfo
->
pRes
->
info
.
rows
;
return
(
pInfo
->
pRes
->
info
.
rows
==
0
)
?
NULL
:
pInfo
->
pRes
;
}
static
SSDataBlock
*
sysTableBuildUserTables
(
SOperatorInfo
*
pOperator
)
{
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SSysTableScanInfo
*
pInfo
=
pOperator
->
info
;
if
(
pInfo
->
pCur
==
NULL
)
{
pInfo
->
pCur
=
metaOpenTbCursor
(
pInfo
->
readHandle
.
meta
);
}
blockDataCleanup
(
pInfo
->
pRes
);
int32_t
numOfRows
=
0
;
const
char
*
db
=
NULL
;
int32_t
vgId
=
0
;
vnodeGetInfo
(
pInfo
->
readHandle
.
vnode
,
&
db
,
&
vgId
);
SName
sn
=
{
0
};
char
dbname
[
TSDB_DB_FNAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
tNameFromString
(
&
sn
,
db
,
T_NAME_ACCT
|
T_NAME_DB
);
tNameGetDbName
(
&
sn
,
varDataVal
(
dbname
));
varDataSetLen
(
dbname
,
strlen
(
varDataVal
(
dbname
)));
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
9
);
SSDataBlock
*
p
=
buildInfoSchemaTableMetaBlock
(
TSDB_INS_TABLE_TABLES
);
blockDataEnsureCapacity
(
p
,
pOperator
->
resultInfo
.
capacity
);
char
n
[
TSDB_TABLE_NAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
int32_t
ret
=
0
;
while
((
ret
=
metaTbCursorNext
(
pInfo
->
pCur
))
==
0
)
{
STR_TO_VARSTR
(
n
,
pInfo
->
pCur
->
mr
.
me
.
name
);
// table name
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
0
);
colDataAppend
(
pColInfoData
,
numOfRows
,
n
,
false
);
// database name
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
1
);
colDataAppend
(
pColInfoData
,
numOfRows
,
dbname
,
false
);
// vgId
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
6
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
vgId
,
false
);
int32_t
tableType
=
pInfo
->
pCur
->
mr
.
me
.
type
;
if
(
tableType
==
TSDB_CHILD_TABLE
)
{
// create time
int64_t
ts
=
pInfo
->
pCur
->
mr
.
me
.
ctbEntry
.
ctime
;
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
2
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
ts
,
false
);
SMetaReader
mr
=
{
0
};
metaReaderInit
(
&
mr
,
pInfo
->
readHandle
.
meta
,
META_READER_NOLOCK
);
uint64_t
suid
=
pInfo
->
pCur
->
mr
.
me
.
ctbEntry
.
suid
;
int32_t
code
=
metaGetTableEntryByUid
(
&
mr
,
suid
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
qError
(
"failed to get super table meta, cname:%s, suid:0x%"
PRIx64
", code:%s, %s"
,
pInfo
->
pCur
->
mr
.
me
.
name
,
suid
,
tstrerror
(
terrno
),
GET_TASKID
(
pTaskInfo
));
metaReaderClear
(
&
mr
);
metaCloseTbCursor
(
pInfo
->
pCur
);
pInfo
->
pCur
=
NULL
;
T_LONG_JMP
(
pTaskInfo
->
env
,
terrno
);
}
// number of columns
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
3
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
mr
.
me
.
stbEntry
.
schemaRow
.
nCols
,
false
);
// super table name
STR_TO_VARSTR
(
n
,
mr
.
me
.
name
);
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
4
);
colDataAppend
(
pColInfoData
,
numOfRows
,
n
,
false
);
metaReaderClear
(
&
mr
);
if
(
++
numOfRows
>=
pOperator
->
resultInfo
.
capacity
)
{
p
->
info
.
rows
=
numOfRows
;
pInfo
->
pRes
->
info
.
rows
=
numOfRows
;
// table comment
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
8
);
if
(
pInfo
->
pCur
->
mr
.
me
.
ctbEntry
.
commentLen
>
0
)
{
char
comment
[
TSDB_TB_COMMENT_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
STR_TO_VARSTR
(
comment
,
pInfo
->
pCur
->
mr
.
me
.
ctbEntry
.
comment
);
colDataAppend
(
pColInfoData
,
numOfRows
,
comment
,
false
);
}
else
if
(
pInfo
->
pCur
->
mr
.
me
.
ctbEntry
.
commentLen
==
0
)
{
char
comment
[
VARSTR_HEADER_SIZE
+
VARSTR_HEADER_SIZE
]
=
{
0
};
STR_TO_VARSTR
(
comment
,
""
);
colDataAppend
(
pColInfoData
,
numOfRows
,
comment
,
false
);
}
else
{
colDataAppendNULL
(
pColInfoData
,
numOfRows
);
}
relocateColumnData
(
pInfo
->
pRes
,
pInfo
->
scanCols
,
p
->
pDataBlock
,
false
);
doFilterResult
(
pInfo
);
// uid
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
5
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
uid
,
false
);
blockDataCleanup
(
p
);
numOfRows
=
0
;
// ttl
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
7
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
ctbEntry
.
ttlDays
,
false
);
if
(
pInfo
->
pRes
->
info
.
rows
>
0
)
{
break
;
}
STR_TO_VARSTR
(
n
,
"CHILD_TABLE"
);
}
else
if
(
tableType
==
TSDB_NORMAL_TABLE
)
{
// create time
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
2
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
ctime
,
false
);
// number of columns
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
3
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
schemaRow
.
nCols
,
false
);
// super table name
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
4
);
colDataAppendNULL
(
pColInfoData
,
numOfRows
);
// table comment
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
8
);
if
(
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
commentLen
>
0
)
{
char
comment
[
TSDB_TB_COMMENT_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
STR_TO_VARSTR
(
comment
,
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
comment
);
colDataAppend
(
pColInfoData
,
numOfRows
,
comment
,
false
);
}
else
if
(
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
commentLen
==
0
)
{
char
comment
[
VARSTR_HEADER_SIZE
+
VARSTR_HEADER_SIZE
]
=
{
0
};
STR_TO_VARSTR
(
comment
,
""
);
colDataAppend
(
pColInfoData
,
numOfRows
,
comment
,
false
);
}
else
{
colDataAppendNULL
(
pColInfoData
,
numOfRows
);
}
// uid
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
5
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
uid
,
false
);
// ttl
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
7
);
colDataAppend
(
pColInfoData
,
numOfRows
,
(
char
*
)
&
pInfo
->
pCur
->
mr
.
me
.
ntbEntry
.
ttlDays
,
false
);
STR_TO_VARSTR
(
n
,
"NORMAL_TABLE"
);
}
if
(
numOfRows
>
0
)
{
pColInfoData
=
taosArrayGet
(
p
->
pDataBlock
,
9
);
colDataAppend
(
pColInfoData
,
numOfRows
,
n
,
false
);
if
(
++
numOfRows
>=
pOperator
->
resultInfo
.
capacity
)
{
p
->
info
.
rows
=
numOfRows
;
pInfo
->
pRes
->
info
.
rows
=
numOfRows
;
...
...
@@ -2966,20 +3609,88 @@ static SSDataBlock* sysTableScanUserTables(SOperatorInfo* pOperator) {
blockDataCleanup
(
p
);
numOfRows
=
0
;
if
(
pInfo
->
pRes
->
info
.
rows
>
0
)
{
break
;
}
}
}
blockDataDestroy
(
p
);
if
(
numOfRows
>
0
)
{
p
->
info
.
rows
=
numOfRows
;
pInfo
->
pRes
->
info
.
rows
=
numOfRows
;
// todo temporarily free the cursor here, the true reason why the free is not valid needs to be found
if
(
ret
!=
0
)
{
metaCloseTbCursor
(
pInfo
->
pCur
);
pInfo
->
pCur
=
NULL
;
doSetOperatorCompleted
(
pOperator
);
}
relocateColumnData
(
pInfo
->
pRes
,
pInfo
->
scanCols
,
p
->
pDataBlock
,
false
);
doFilterResult
(
pInfo
);
blockDataCleanup
(
p
);
numOfRows
=
0
;
}
blockDataDestroy
(
p
);
// todo temporarily free the cursor here, the true reason why the free is not valid needs to be found
if
(
ret
!=
0
)
{
metaCloseTbCursor
(
pInfo
->
pCur
);
pInfo
->
pCur
=
NULL
;
doSetOperatorCompleted
(
pOperator
);
}
pInfo
->
loadInfo
.
totalRows
+=
pInfo
->
pRes
->
info
.
rows
;
return
(
pInfo
->
pRes
->
info
.
rows
==
0
)
?
NULL
:
pInfo
->
pRes
;
}
static
SSDataBlock
*
sysTableScanUserTables
(
SOperatorInfo
*
pOperator
)
{
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SSysTableScanInfo
*
pInfo
=
pOperator
->
info
;
SNode
*
pCondition
=
pInfo
->
pCondition
;
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
return
NULL
;
}
// the retrieve is executed on the mnode, so return tables that belongs to the information schema database.
if
(
pInfo
->
readHandle
.
mnd
!=
NULL
)
{
buildSysDbTableInfo
(
pInfo
,
pOperator
->
resultInfo
.
capacity
);
doFilterResult
(
pInfo
);
pInfo
->
loadInfo
.
totalRows
+=
pInfo
->
pRes
->
info
.
rows
;
doSetOperatorCompleted
(
pOperator
);
return
(
pInfo
->
pRes
->
info
.
rows
==
0
)
?
NULL
:
pInfo
->
pRes
;
}
else
{
if
(
pInfo
->
showRewrite
==
false
)
{
if
(
pCondition
!=
NULL
&&
pInfo
->
pIdx
==
NULL
)
{
SSTabFltArg
arg
=
{.
pMeta
=
pInfo
->
readHandle
.
meta
,
.
pVnode
=
pInfo
->
readHandle
.
vnode
};
SSysTableIndex
*
idx
=
taosMemoryMalloc
(
sizeof
(
SSysTableIndex
));
idx
->
init
=
0
;
idx
->
uids
=
taosArrayInit
(
128
,
sizeof
(
int64_t
));
idx
->
lastIdx
=
0
;
pInfo
->
pIdx
=
idx
;
// set idx arg
int
flt
=
optSysTabFilte
(
&
arg
,
pCondition
,
idx
->
uids
);
if
(
flt
==
0
)
{
pInfo
->
pIdx
->
init
=
1
;
SSDataBlock
*
blk
=
sysTableBuildUserTablesByUids
(
pOperator
);
return
blk
;
}
else
if
(
flt
==
-
2
)
{
qDebug
(
"%s failed to get sys table info by idx, empty result"
,
GET_TASKID
(
pTaskInfo
));
return
NULL
;
}
else
if
(
flt
==
-
1
)
{
// not idx
qDebug
(
"%s failed to get sys table info by idx, scan sys table one by one"
,
GET_TASKID
(
pTaskInfo
));
}
}
else
if
(
pCondition
!=
NULL
&&
(
pInfo
->
pIdx
!=
NULL
&&
pInfo
->
pIdx
->
init
==
1
))
{
SSDataBlock
*
blk
=
sysTableBuildUserTablesByUids
(
pOperator
);
return
blk
;
}
}
return
sysTableBuildUserTables
(
pOperator
);
}
return
NULL
;
}
static
SSDataBlock
*
sysTableScanUserSTables
(
SOperatorInfo
*
pOperator
)
{
...
...
source/libs/transport/src/trans.c
浏览文件 @
e86cdc8c
...
...
@@ -69,6 +69,7 @@ void* rpcOpen(const SRpcInit* pInit) {
pRpc
->
idleTime
=
pInit
->
idleTime
;
pRpc
->
tcphandle
=
(
*
taosInitHandle
[
pRpc
->
connType
])(
ip
,
pInit
->
localPort
,
pRpc
->
label
,
pRpc
->
numOfThreads
,
NULL
,
pRpc
);
if
(
pRpc
->
tcphandle
==
NULL
)
{
taosMemoryFree
(
pRpc
);
return
NULL
;
...
...
tests/script/tsim/parser/where.sim
浏览文件 @
e86cdc8c
...
...
@@ -87,17 +87,17 @@ if $rows != 2 then
return -1
endi
print $tbPrefix
$tb = $tbPrefix . 0
if $data00 != wh_tb1 then
print expect wh_tb1, actual:$data00
return -1
endi
$tb = $tbPrefix . 1
if $data10 != wh_tb0 then
print expect wh_tb0, actual:$data00
return -1
endi
#
print $tbPrefix
#
$tb = $tbPrefix . 0
#
if $data00 != wh_tb1 then
#
print expect wh_tb1, actual:$data00
#
return -1
#
endi
#
$tb = $tbPrefix . 1
#
if $data10 != wh_tb0 then
#
print expect wh_tb0, actual:$data00
#
return -1
#
endi
## select specified columns
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录