Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a9d88b74
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
未验证
提交
a9d88b74
编写于
8月 18, 2023
作者:
D
dapan1121
提交者:
GitHub
8月 18, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #22443 from taosdata/szhou/select-tags-scan
feature: tags scan with select tags
上级
8ac2ee20
4e2a26e8
变更
18
展开全部
隐藏空白更改
内联
并排
Showing
18 changed file
with
2580 addition
and
2372 deletion
+2580
-2372
include/common/ttokendef.h
include/common/ttokendef.h
+99
-100
include/libs/executor/storageapi.h
include/libs/executor/storageapi.h
+5
-1
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+3
-1
source/dnode/vnode/src/meta/metaQuery.c
source/dnode/vnode/src/meta/metaQuery.c
+57
-22
source/dnode/vnode/src/vnd/vnodeInitApi.c
source/dnode/vnode/src/vnd/vnodeInitApi.c
+2
-0
source/dnode/vnode/src/vnd/vnodeQuery.c
source/dnode/vnode/src/vnd/vnodeQuery.c
+3
-3
source/libs/executor/inc/executil.h
source/libs/executor/inc/executil.h
+1
-1
source/libs/executor/src/cachescanoperator.c
source/libs/executor/src/cachescanoperator.c
+1
-1
source/libs/executor/src/executil.c
source/libs/executor/src/executil.c
+1
-1
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+19
-13
source/libs/nodes/src/nodesCloneFuncs.c
source/libs/nodes/src/nodesCloneFuncs.c
+1
-0
source/libs/parser/inc/parAst.h
source/libs/parser/inc/parAst.h
+1
-0
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+9
-3
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+7
-0
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+2232
-2223
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+55
-2
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+2
-1
tests/script/tsim/query/tag_scan.sim
tests/script/tsim/query/tag_scan.sim
+82
-0
未找到文件。
include/common/ttokendef.h
浏览文件 @
a9d88b74
...
...
@@ -16,105 +16,105 @@
#ifndef _TD_COMMON_TOKEN_H_
#define _TD_COMMON_TOKEN_H_
#define TK_OR 1
#define TK_AND 2
#define TK_UNION 3
#define TK_ALL 4
#define TK_MINUS 5
#define TK_EXCEPT 6
#define TK_INTERSECT 7
#define TK_NK_BITAND 8
#define TK_NK_BITOR 9
#define TK_NK_LSHIFT 10
#define TK_NK_RSHIFT 11
#define TK_NK_PLUS 12
#define TK_NK_MINUS 13
#define TK_NK_STAR 14
#define TK_NK_SLASH 15
#define TK_NK_REM 16
#define TK_NK_CONCAT 17
#define TK_CREATE 18
#define TK_ACCOUNT 19
#define TK_NK_ID 20
#define TK_PASS 21
#define TK_NK_STRING 22
#define TK_ALTER 23
#define TK_PPS 24
#define TK_TSERIES 25
#define TK_STORAGE 26
#define TK_STREAMS 27
#define TK_QTIME 28
#define TK_DBS 29
#define TK_USERS 30
#define TK_CONNS 31
#define TK_STATE 32
#define TK_USER 33
#define TK_ENABLE 34
#define TK_NK_INTEGER 35
#define TK_SYSINFO 36
#define TK_DROP 37
#define TK_GRANT 38
#define TK_ON 39
#define TK_TO 40
#define TK_REVOKE 41
#define TK_FROM 42
#define TK_SUBSCRIBE 43
#define TK_NK_COMMA 44
#define TK_READ 45
#define TK_WRITE 46
#define TK_NK_DOT 47
#define TK_WITH 48
#define TK_DNODE 49
#define TK_PORT 50
#define TK_DNODES 51
#define TK_RESTORE 52
#define TK_NK_IPTOKEN 53
#define TK_FORCE 54
#define TK_UNSAFE 55
#define TK_LOCAL 56
#define TK_QNODE 57
#define TK_BNODE 58
#define TK_SNODE 59
#define TK_MNODE 60
#define TK_VNODE 61
#define TK_DATABASE 62
#define TK_USE 63
#define TK_FLUSH 64
#define TK_TRIM 65
#define TK_COMPACT 66
#define TK_IF 67
#define TK_NOT 68
#define TK_EXISTS 69
#define TK_BUFFER 70
#define TK_CACHEMODEL 71
#define TK_CACHESIZE 72
#define TK_COMP 73
#define TK_DURATION 74
#define TK_NK_VARIABLE 75
#define TK_MAXROWS 76
#define TK_MINROWS 77
#define TK_KEEP 78
#define TK_PAGES 79
#define TK_PAGESIZE 80
#define TK_TSDB_PAGESIZE 81
#define TK_PRECISION 82
#define TK_REPLICA 83
#define TK_VGROUPS 84
#define TK_SINGLE_STABLE 85
#define TK_RETENTIONS 86
#define TK_SCHEMALESS 87
#define TK_WAL_LEVEL 88
#define TK_WAL_FSYNC_PERIOD 89
#define TK_WAL_RETENTION_PERIOD 90
#define TK_WAL_RETENTION_SIZE 91
#define TK_WAL_ROLL_PERIOD 92
#define TK_WAL_SEGMENT_SIZE 93
#define TK_STT_TRIGGER 94
#define TK_TABLE_PREFIX 95
#define TK_TABLE_SUFFIX 96
#define TK_NK_COLON 97
#define TK_MAX_SPEED 98
#define TK_START 99
#define TK_OR
1
#define TK_AND
2
#define TK_UNION
3
#define TK_ALL
4
#define TK_MINUS
5
#define TK_EXCEPT
6
#define TK_INTERSECT
7
#define TK_NK_BITAND
8
#define TK_NK_BITOR
9
#define TK_NK_LSHIFT
10
#define TK_NK_RSHIFT
11
#define TK_NK_PLUS
12
#define TK_NK_MINUS
13
#define TK_NK_STAR
14
#define TK_NK_SLASH
15
#define TK_NK_REM
16
#define TK_NK_CONCAT
17
#define TK_CREATE
18
#define TK_ACCOUNT
19
#define TK_NK_ID
20
#define TK_PASS
21
#define TK_NK_STRING
22
#define TK_ALTER
23
#define TK_PPS
24
#define TK_TSERIES
25
#define TK_STORAGE
26
#define TK_STREAMS
27
#define TK_QTIME
28
#define TK_DBS
29
#define TK_USERS
30
#define TK_CONNS
31
#define TK_STATE
32
#define TK_USER
33
#define TK_ENABLE
34
#define TK_NK_INTEGER
35
#define TK_SYSINFO
36
#define TK_DROP
37
#define TK_GRANT
38
#define TK_ON
39
#define TK_TO
40
#define TK_REVOKE
41
#define TK_FROM
42
#define TK_SUBSCRIBE
43
#define TK_NK_COMMA
44
#define TK_READ
45
#define TK_WRITE
46
#define TK_NK_DOT
47
#define TK_WITH
48
#define TK_DNODE
49
#define TK_PORT
50
#define TK_DNODES
51
#define TK_RESTORE
52
#define TK_NK_IPTOKEN
53
#define TK_FORCE
54
#define TK_UNSAFE
55
#define TK_LOCAL
56
#define TK_QNODE
57
#define TK_BNODE
58
#define TK_SNODE
59
#define TK_MNODE
60
#define TK_VNODE
61
#define TK_DATABASE
62
#define TK_USE
63
#define TK_FLUSH
64
#define TK_TRIM
65
#define TK_COMPACT
66
#define TK_IF
67
#define TK_NOT
68
#define TK_EXISTS
69
#define TK_BUFFER
70
#define TK_CACHEMODEL
71
#define TK_CACHESIZE
72
#define TK_COMP
73
#define TK_DURATION
74
#define TK_NK_VARIABLE
75
#define TK_MAXROWS
76
#define TK_MINROWS
77
#define TK_KEEP
78
#define TK_PAGES
79
#define TK_PAGESIZE
80
#define TK_TSDB_PAGESIZE
81
#define TK_PRECISION
82
#define TK_REPLICA
83
#define TK_VGROUPS
84
#define TK_SINGLE_STABLE
85
#define TK_RETENTIONS
86
#define TK_SCHEMALESS
87
#define TK_WAL_LEVEL
88
#define TK_WAL_FSYNC_PERIOD
89
#define TK_WAL_RETENTION_PERIOD
90
#define TK_WAL_RETENTION_SIZE
91
#define TK_WAL_ROLL_PERIOD
92
#define TK_WAL_SEGMENT_SIZE
93
#define TK_STT_TRIGGER
94
#define TK_TABLE_PREFIX
95
#define TK_TABLE_SUFFIX
96
#define TK_NK_COLON
97
#define TK_MAX_SPEED
98
#define TK_START
99
#define TK_TIMESTAMP 100
#define TK_END 101
#define TK_TABLE 102
...
...
@@ -354,7 +354,6 @@
#define TK_VIEW 336
#define TK_WAL 337
#define TK_NK_SPACE 600
#define TK_NK_COMMENT 601
#define TK_NK_ILLEGAL 602
...
...
include/libs/executor/storageapi.h
浏览文件 @
a9d88b74
...
...
@@ -106,6 +106,8 @@ typedef struct SMCtbCursor {
void
*
pVal
;
int
kLen
;
int
vLen
;
int8_t
paused
;
int
lock
;
}
SMCtbCursor
;
typedef
struct
SRowBuffPos
{
...
...
@@ -295,7 +297,9 @@ int32_t vnodeGetCtbIdListByFilter(void *pVnode, int64_t suid, SArray *list, bool
int32_t vnodeGetStbIdList(void *pVnode, int64_t suid, SArray *list);
*/
SMCtbCursor
*
(
*
openCtbCursor
)(
void
*
pVnode
,
tb_uid_t
uid
,
int
lock
);
void
(
*
closeCtbCursor
)(
SMCtbCursor
*
pCtbCur
,
int
lock
);
int32_t
(
*
resumeCtbCursor
)(
SMCtbCursor
*
pCtbCur
,
int8_t
first
);
void
(
*
pauseCtbCursor
)(
SMCtbCursor
*
pCtbCur
);
void
(
*
closeCtbCursor
)(
SMCtbCursor
*
pCtbCur
);
tb_uid_t
(
*
ctbCursorNext
)(
SMCtbCursor
*
pCur
);
}
SStoreMeta
;
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
a9d88b74
...
...
@@ -168,7 +168,9 @@ int metaDropIndexFromSTable(SMeta* pMeta, int64_t version, SDropIndexReq* pReq);
int64_t
metaGetTimeSeriesNum
(
SMeta
*
pMeta
);
SMCtbCursor
*
metaOpenCtbCursor
(
void
*
pVnode
,
tb_uid_t
uid
,
int
lock
);
void
metaCloseCtbCursor
(
SMCtbCursor
*
pCtbCur
,
int
lock
);
int32_t
metaResumeCtbCursor
(
SMCtbCursor
*
pCtbCur
,
int8_t
first
);
void
metaPauseCtbCursor
(
SMCtbCursor
*
pCtbCur
);
void
metaCloseCtbCursor
(
SMCtbCursor
*
pCtbCur
);
tb_uid_t
metaCtbCursorNext
(
SMCtbCursor
*
pCtbCur
);
SMStbCursor
*
metaOpenStbCursor
(
SMeta
*
pMeta
,
tb_uid_t
uid
);
void
metaCloseStbCursor
(
SMStbCursor
*
pStbCur
);
...
...
source/dnode/vnode/src/meta/metaQuery.c
浏览文件 @
a9d88b74
...
...
@@ -423,40 +423,75 @@ SMCtbCursor *metaOpenCtbCursor(void* pVnode, tb_uid_t uid, int lock) {
pCtbCur
->
pMeta
=
pMeta
;
pCtbCur
->
suid
=
uid
;
if
(
lock
)
{
metaRLock
(
pMeta
);
}
pCtbCur
->
lock
=
lock
;
pCtbCur
->
paused
=
1
;
ret
=
tdbTbcOpen
(
pMeta
->
pCtbIdx
,
(
TBC
**
)
&
pCtbCur
->
pCur
,
NULL
);
ret
=
metaResumeCtbCursor
(
pCtbCur
,
1
);
if
(
ret
<
0
)
{
metaULock
(
pMeta
);
taosMemoryFree
(
pCtbCur
);
return
NULL
;
}
return
pCtbCur
;
}
// move to the suid
ctbIdxKey
.
suid
=
uid
;
ctbIdxKey
.
uid
=
INT64_MIN
;
tdbTbcMoveTo
(
pCtbCur
->
pCur
,
&
ctbIdxKey
,
sizeof
(
ctbIdxKey
),
&
c
);
if
(
c
>
0
)
{
tdbTbcMoveToNext
(
pCtbCur
->
pCur
);
void
metaCloseCtbCursor
(
SMCtbCursor
*
pCtbCur
)
{
if
(
pCtbCur
)
{
if
(
!
pCtbCur
->
paused
)
{
if
(
pCtbCur
->
pMeta
&&
pCtbCur
->
lock
)
metaULock
(
pCtbCur
->
pMeta
);
if
(
pCtbCur
->
pCur
)
{
tdbTbcClose
(
pCtbCur
->
pCur
);
}
}
tdbFree
(
pCtbCur
->
pKey
);
tdbFree
(
pCtbCur
->
pVal
);
}
taosMemoryFree
(
pCtbCur
);
}
return
pCtbCur
;
void
metaPauseCtbCursor
(
SMCtbCursor
*
pCtbCur
)
{
if
(
!
pCtbCur
->
paused
)
{
tdbTbcClose
((
TBC
*
)
pCtbCur
->
pCur
);
if
(
pCtbCur
->
lock
)
{
metaULock
(
pCtbCur
->
pMeta
);
}
pCtbCur
->
paused
=
1
;
}
}
void
metaCloseCtbCursor
(
SMCtbCursor
*
pCtbCur
,
int
lock
)
{
if
(
pCtbCur
)
{
if
(
pCtbCur
->
pMeta
&&
lock
)
metaULock
(
pCtbCur
->
pMeta
);
if
(
pCtbCur
->
pCur
)
{
tdbTbcClose
(
pCtbCur
->
pCur
);
int32_t
metaResumeCtbCursor
(
SMCtbCursor
*
pCtbCur
,
int8_t
first
)
{
if
(
pCtbCur
->
paused
)
{
pCtbCur
->
paused
=
0
;
tdbFree
(
pCtbCur
->
pKey
);
tdbFree
(
pCtbCur
->
pVal
);
if
(
pCtbCur
->
lock
)
{
metaRLock
(
pCtbCur
->
pMeta
);
}
int
ret
=
0
;
ret
=
tdbTbcOpen
(
pCtbCur
->
pMeta
->
pCtbIdx
,
(
TBC
**
)
&
pCtbCur
->
pCur
,
NULL
);
if
(
ret
<
0
)
{
metaCloseCtbCursor
(
pCtbCur
);
return
-
1
;
}
taosMemoryFree
(
pCtbCur
);
if
(
first
)
{
SCtbIdxKey
ctbIdxKey
;
// move to the suid
ctbIdxKey
.
suid
=
pCtbCur
->
suid
;
ctbIdxKey
.
uid
=
INT64_MIN
;
int
c
=
0
;
tdbTbcMoveTo
(
pCtbCur
->
pCur
,
&
ctbIdxKey
,
sizeof
(
ctbIdxKey
),
&
c
);
if
(
c
>
0
)
{
tdbTbcMoveToNext
(
pCtbCur
->
pCur
);
}
}
else
{
int
c
=
0
;
ret
=
tdbTbcMoveTo
(
pCtbCur
->
pCur
,
pCtbCur
->
pKey
,
pCtbCur
->
kLen
,
&
c
);
if
(
c
<
0
)
{
tdbTbcMoveToPrev
(
pCtbCur
->
pCur
);
}
else
{
tdbTbcMoveToNext
(
pCtbCur
->
pCur
);
}
}
}
return
0
;
}
tb_uid_t
metaCtbCursorNext
(
SMCtbCursor
*
pCtbCur
)
{
...
...
@@ -1414,7 +1449,7 @@ int32_t metaGetTableTags(void *pVnode, uint64_t suid, SArray *pUidTagInfo) {
}
taosHashCleanup
(
pSepecifiedUidMap
);
metaCloseCtbCursor
(
pCur
,
1
);
metaCloseCtbCursor
(
pCur
);
return
TSDB_CODE_SUCCESS
;
}
...
...
source/dnode/vnode/src/vnd/vnodeInitApi.c
浏览文件 @
a9d88b74
...
...
@@ -98,6 +98,8 @@ void initMetadataAPI(SStoreMeta* pMeta) {
pMeta
->
metaPutTbGroupToCache
=
metaPutTbGroupToCache
;
pMeta
->
openCtbCursor
=
metaOpenCtbCursor
;
pMeta
->
resumeCtbCursor
=
metaResumeCtbCursor
;
pMeta
->
pauseCtbCursor
=
metaPauseCtbCursor
;
pMeta
->
closeCtbCursor
=
metaCloseCtbCursor
;
pMeta
->
ctbCursorNext
=
metaCtbCursorNext
;
}
...
...
source/dnode/vnode/src/vnd/vnodeQuery.c
浏览文件 @
a9d88b74
...
...
@@ -455,7 +455,7 @@ int32_t vnodeGetAllTableList(SVnode *pVnode, uint64_t uid, SArray *list) {
taosArrayPush
(
list
,
&
info
);
}
metaCloseCtbCursor
(
pCur
,
1
);
metaCloseCtbCursor
(
pCur
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -476,7 +476,7 @@ int32_t vnodeGetCtbIdList(void *pVnode, int64_t suid, SArray *list) {
taosArrayPush
(
list
,
&
id
);
}
metaCloseCtbCursor
(
pCur
,
1
);
metaCloseCtbCursor
(
pCur
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -539,7 +539,7 @@ int32_t vnodeGetCtbNum(SVnode *pVnode, int64_t suid, int64_t *num) {
++
(
*
num
);
}
metaCloseCtbCursor
(
pCur
,
0
);
metaCloseCtbCursor
(
pCur
);
return
TSDB_CODE_SUCCESS
;
}
...
...
source/libs/executor/inc/executil.h
浏览文件 @
a9d88b74
...
...
@@ -117,7 +117,7 @@ void* tableListDestroy(STableListInfo* pTableListInfo);
void
tableListClear
(
STableListInfo
*
pTableListInfo
);
int32_t
tableListGetOutputGroups
(
const
STableListInfo
*
pTableList
);
bool
oneTableForEachGroup
(
const
STableListInfo
*
pTableList
);
uint64_t
g
etTableGroupId
(
const
STableListInfo
*
pTableList
,
uint64_t
tableUid
);
uint64_t
tableListG
etTableGroupId
(
const
STableListInfo
*
pTableList
,
uint64_t
tableUid
);
int32_t
tableListAddTableInfo
(
STableListInfo
*
pTableList
,
uint64_t
uid
,
uint64_t
gid
);
int32_t
tableListGetGroupList
(
const
STableListInfo
*
pTableList
,
int32_t
ordinalIndex
,
STableKeyInfo
**
pKeyInfo
,
int32_t
*
num
);
...
...
source/libs/executor/src/cachescanoperator.c
浏览文件 @
a9d88b74
...
...
@@ -218,7 +218,7 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
return
NULL
;
}
pRes
->
info
.
id
.
groupId
=
g
etTableGroupId
(
pTableList
,
pRes
->
info
.
id
.
uid
);
pRes
->
info
.
id
.
groupId
=
tableListG
etTableGroupId
(
pTableList
,
pRes
->
info
.
id
.
uid
);
pInfo
->
indexOfBufferedRes
+=
1
;
return
pRes
;
}
else
{
...
...
source/libs/executor/src/executil.c
浏览文件 @
a9d88b74
...
...
@@ -1931,7 +1931,7 @@ void tableListGetSourceTableInfo(const STableListInfo* pTableList, uint64_t* psu
*
type
=
pTableList
->
idInfo
.
tableType
;
}
uint64_t
g
etTableGroupId
(
const
STableListInfo
*
pTableList
,
uint64_t
tableUid
)
{
uint64_t
tableListG
etTableGroupId
(
const
STableListInfo
*
pTableList
,
uint64_t
tableUid
)
{
int32_t
*
slot
=
taosHashGet
(
pTableList
->
map
,
&
tableUid
,
sizeof
(
tableUid
));
ASSERT
(
pTableList
->
map
!=
NULL
&&
slot
!=
NULL
);
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
a9d88b74
...
...
@@ -693,7 +693,7 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) {
}
if
(
pBlock
->
info
.
id
.
uid
)
{
pBlock
->
info
.
id
.
groupId
=
g
etTableGroupId
(
pTableScanInfo
->
base
.
pTableListInfo
,
pBlock
->
info
.
id
.
uid
);
pBlock
->
info
.
id
.
groupId
=
tableListG
etTableGroupId
(
pTableScanInfo
->
base
.
pTableListInfo
,
pBlock
->
info
.
id
.
uid
);
}
uint32_t
status
=
0
;
...
...
@@ -1088,7 +1088,7 @@ static SSDataBlock* readPreVersionData(SOperatorInfo* pTableScanOp, uint64_t tbU
if
(
hasNext
)
{
/*SSDataBlock* p = */
pAPI
->
tsdReader
.
tsdReaderRetrieveDataBlock
(
pReader
,
NULL
);
doSetTagColumnData
(
&
pTableScanInfo
->
base
,
pBlock
,
pTaskInfo
,
pBlock
->
info
.
rows
);
pBlock
->
info
.
id
.
groupId
=
g
etTableGroupId
(
pTableScanInfo
->
base
.
pTableListInfo
,
pBlock
->
info
.
id
.
uid
);
pBlock
->
info
.
id
.
groupId
=
tableListG
etTableGroupId
(
pTableScanInfo
->
base
.
pTableListInfo
,
pBlock
->
info
.
id
.
uid
);
}
pAPI
->
tsdReader
.
tsdReaderClose
(
pReader
);
...
...
@@ -1110,7 +1110,7 @@ static uint64_t getGroupIdByCol(SStreamScanInfo* pInfo, uint64_t uid, TSKEY ts,
static
uint64_t
getGroupIdByUid
(
SStreamScanInfo
*
pInfo
,
uint64_t
uid
)
{
STableScanInfo
*
pTableScanInfo
=
pInfo
->
pTableScanOp
->
info
;
return
g
etTableGroupId
(
pTableScanInfo
->
base
.
pTableListInfo
,
uid
);
return
tableListG
etTableGroupId
(
pTableScanInfo
->
base
.
pTableListInfo
,
uid
);
}
static
uint64_t
getGroupIdByData
(
SStreamScanInfo
*
pInfo
,
uint64_t
uid
,
TSKEY
ts
,
int64_t
maxVersion
)
{
...
...
@@ -1651,7 +1651,7 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock
pBlockInfo
->
version
=
pBlock
->
info
.
version
;
STableScanInfo
*
pTableScanInfo
=
pInfo
->
pTableScanOp
->
info
;
pBlockInfo
->
id
.
groupId
=
g
etTableGroupId
(
pTableScanInfo
->
base
.
pTableListInfo
,
pBlock
->
info
.
id
.
uid
);
pBlockInfo
->
id
.
groupId
=
tableListG
etTableGroupId
(
pTableScanInfo
->
base
.
pTableListInfo
,
pBlock
->
info
.
id
.
uid
);
// todo extract method
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pInfo
->
matchInfo
.
pList
);
++
i
)
{
...
...
@@ -2761,11 +2761,6 @@ static void tagScanFilterByTagCond(SArray* aUidTags, SNode* pTagCond, SArray* aF
static
void
tagScanFillOneCellWithTag
(
const
STUidTagInfo
*
pUidTagInfo
,
SExprInfo
*
pExprInfo
,
SColumnInfoData
*
pColInfo
,
int
rowIndex
,
const
SStorageAPI
*
pAPI
,
void
*
pVnode
)
{
if
(
fmIsScanPseudoColumnFunc
(
pExprInfo
->
pExpr
->
_function
.
functionId
))
{
// tbname
char
str
[
TSDB_TABLE_FNAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
// if (pUidTagInfo->name != NULL) {
// STR_TO_VARSTR(str, pUidTagInfo->name);
// } else { // name is not retrieved during filter
// pAPI->metaFn.getTableNameByUid(pVnode, pUidTagInfo->uid, str);
// }
STR_TO_VARSTR
(
str
,
"ctbidx"
);
colDataSetVal
(
pColInfo
,
rowIndex
,
str
,
false
);
...
...
@@ -2834,12 +2829,14 @@ static SSDataBlock* doTagScanFromCtbIdx(SOperatorInfo* pOperator) {
if
(
pInfo
->
pCtbCursor
==
NULL
)
{
pInfo
->
pCtbCursor
=
pAPI
->
metaFn
.
openCtbCursor
(
pInfo
->
readHandle
.
vnode
,
pInfo
->
suid
,
1
);
}
else
{
pAPI
->
metaFn
.
resumeCtbCursor
(
pInfo
->
pCtbCursor
,
0
);
}
SArray
*
aUidTags
=
pInfo
->
aUidTags
;
SArray
*
aFilterIdxs
=
pInfo
->
aFilterIdxs
;
int32_t
count
=
0
;
bool
ctbCursorFinished
=
false
;
while
(
1
)
{
taosArrayClearEx
(
aUidTags
,
tagScanFreeUidTag
);
taosArrayClear
(
aFilterIdxs
);
...
...
@@ -2849,6 +2846,7 @@ static SSDataBlock* doTagScanFromCtbIdx(SOperatorInfo* pOperator) {
SMCtbCursor
*
pCur
=
pInfo
->
pCtbCursor
;
tb_uid_t
uid
=
pAPI
->
metaFn
.
ctbCursorNext
(
pInfo
->
pCtbCursor
);
if
(
uid
==
0
)
{
ctbCursorFinished
=
true
;
break
;
}
STUidTagInfo
info
=
{.
uid
=
uid
,
.
pTagVal
=
pCur
->
pVal
};
...
...
@@ -2877,7 +2875,15 @@ static SSDataBlock* doTagScanFromCtbIdx(SOperatorInfo* pOperator) {
break
;
}
}
if
(
count
>
0
)
{
pAPI
->
metaFn
.
pauseCtbCursor
(
pInfo
->
pCtbCursor
);
}
if
(
count
==
0
||
ctbCursorFinished
)
{
pAPI
->
metaFn
.
closeCtbCursor
(
pInfo
->
pCtbCursor
);
pInfo
->
pCtbCursor
=
NULL
;
setOperatorCompleted
(
pOperator
);
}
pRes
->
info
.
rows
=
count
;
pOperator
->
resultInfo
.
totalRows
+=
count
;
return
(
pRes
->
info
.
rows
==
0
)
?
NULL
:
pInfo
->
pRes
;
...
...
@@ -2942,7 +2948,7 @@ static SSDataBlock* doTagScanFromMetaEntry(SOperatorInfo* pOperator) {
static
void
destroyTagScanOperatorInfo
(
void
*
param
)
{
STagScanInfo
*
pInfo
=
(
STagScanInfo
*
)
param
;
if
(
pInfo
->
pCtbCursor
!=
NULL
)
{
pInfo
->
pStorageAPI
->
metaFn
.
closeCtbCursor
(
pInfo
->
pCtbCursor
,
1
);
pInfo
->
pStorageAPI
->
metaFn
.
closeCtbCursor
(
pInfo
->
pCtbCursor
);
}
taosHashCleanup
(
pInfo
->
filterCtx
.
colHash
);
taosArrayDestroy
(
pInfo
->
filterCtx
.
cInfoList
);
...
...
@@ -3072,7 +3078,7 @@ static SSDataBlock* getBlockForTableMergeScan(void* param) {
continue
;
}
pBlock
->
info
.
id
.
groupId
=
g
etTableGroupId
(
pInfo
->
base
.
pTableListInfo
,
pBlock
->
info
.
id
.
uid
);
pBlock
->
info
.
id
.
groupId
=
tableListG
etTableGroupId
(
pInfo
->
base
.
pTableListInfo
,
pBlock
->
info
.
id
.
uid
);
pOperator
->
resultInfo
.
totalRows
+=
pBlock
->
info
.
rows
;
pInfo
->
base
.
readRecorder
.
elapsedTime
+=
(
taosGetTimestampUs
()
-
st
)
/
1000
.
0
;
...
...
source/libs/nodes/src/nodesCloneFuncs.c
浏览文件 @
a9d88b74
...
...
@@ -399,6 +399,7 @@ static int32_t logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) {
CLONE_NODE_FIELD
(
pSubtable
);
COPY_SCALAR_FIELD
(
igLastNull
);
COPY_SCALAR_FIELD
(
groupOrderScan
);
COPY_SCALAR_FIELD
(
onlyMetaCtbIdx
);
return
TSDB_CODE_SUCCESS
;
}
...
...
source/libs/parser/inc/parAst.h
浏览文件 @
a9d88b74
...
...
@@ -143,6 +143,7 @@ SNode* addRangeClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pRange);
SNode
*
addEveryClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pEvery
);
SNode
*
addFillClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pFill
);
SNode
*
createSelectStmt
(
SAstCreateContext
*
pCxt
,
bool
isDistinct
,
SNodeList
*
pProjectionList
,
SNode
*
pTable
);
SNode
*
setSelectStmtTagMode
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
bool
bSelectTags
);
SNode
*
createSetOperator
(
SAstCreateContext
*
pCxt
,
ESetOperatorType
type
,
SNode
*
pLeft
,
SNode
*
pRight
);
SDataType
createDataType
(
uint8_t
type
);
...
...
source/libs/parser/inc/sql.y
浏览文件 @
a9d88b74
...
...
@@ -1009,10 +1009,11 @@ join_type(A) ::= INNER.
/************************************************ query_specification *************************************************/
query_specification(A) ::=
SELECT
set_quantifier_opt(B) select_list(C) from_clause_opt(D)
where_clause_opt(E) partition_by_clause_opt(F) range_opt(J) every_opt(K)
fill_opt(L) twindow_clause_opt(G) group_by_clause_opt(H) having_clause_opt(I). {
SELECT
tag_mode_opt(M) set_quantifier_opt(B) select_list(C) from_clause_opt(D)
where_clause_opt(E) partition_by_clause_opt(F) range_opt(J) every_opt(K)
fill_opt(L) twindow_clause_opt(G) group_by_clause_opt(H) having_clause_opt(I). {
A = createSelectStmt(pCxt, B, C, D);
A = setSelectStmtTagMode(pCxt, A, M);
A = addWhereClause(pCxt, A, E);
A = addPartitionByClause(pCxt, A, F);
A = addWindowClauseClause(pCxt, A, G);
...
...
@@ -1023,6 +1024,11 @@ query_specification(A) ::=
A = addFillClause(pCxt, A, L);
}
%type tag_mode_opt { bool }
%destructor tag_mode_opt { }
tag_mode_opt(A) ::= . { A = false; }
tag_mode_opt(A) ::= TAGS. { A = true; }
%type set_quantifier_opt { bool }
%destructor set_quantifier_opt { }
set_quantifier_opt(A) ::= . { A = false; }
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
a9d88b74
...
...
@@ -852,6 +852,13 @@ SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pPr
return
select
;
}
SNode
*
setSelectStmtTagMode
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
bool
bSelectTags
)
{
if
(
pStmt
&&
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
((
SSelectStmt
*
)
pStmt
)
->
tagScan
=
bSelectTags
;
}
return
pStmt
;
}
static
void
setSubquery
(
SNode
*
pStmt
)
{
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
((
SSelectStmt
*
)
pStmt
)
->
isSubquery
=
true
;
...
...
source/libs/parser/src/sql.c
浏览文件 @
a9d88b74
此差异已折叠。
点击以展开。
source/libs/planner/src/planLogicCreater.c
浏览文件 @
a9d88b74
...
...
@@ -14,7 +14,7 @@
*/
#include "planInt.h"
#include "filter.h"
#include "functionMgt.h"
typedef
struct
SLogicPlanContext
{
...
...
@@ -253,7 +253,7 @@ static EScanType getScanType(SLogicPlanContext* pCxt, SNodeList* pScanPseudoCols
return
SCAN_TYPE_SYSTEM_TABLE
;
}
if
(
tagScan
)
{
if
(
tagScan
&&
0
==
LIST_LENGTH
(
pScanCols
)
&&
0
!=
LIST_LENGTH
(
pScanPseudoCols
)
)
{
return
SCAN_TYPE_TAG
;
}
...
...
@@ -344,6 +344,55 @@ static int32_t makeScanLogicNode(SLogicPlanContext* pCxt, SRealTableNode* pRealT
static
bool
needScanDefaultCol
(
EScanType
scanType
)
{
return
SCAN_TYPE_TABLE_COUNT
!=
scanType
;
}
static
EDealRes
tagScanNodeHasTbnameFunc
(
SNode
*
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
)
&&
FUNCTION_TYPE_TBNAME
==
((
SFunctionNode
*
)
pNode
)
->
funcType
||
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
)
&&
COLUMN_TYPE_TBNAME
==
((
SColumnNode
*
)
pNode
)
->
colType
))
{
*
(
bool
*
)
pContext
=
true
;
return
DEAL_RES_END
;
}
return
DEAL_RES_CONTINUE
;
}
static
bool
tagScanNodeListHasTbname
(
SNodeList
*
pCols
)
{
bool
hasTbname
=
false
;
nodesWalkExprs
(
pCols
,
tagScanNodeHasTbnameFunc
,
&
hasTbname
);
return
hasTbname
;
}
static
bool
tagScanNodeHasTbname
(
SNode
*
pKeys
)
{
bool
hasTbname
=
false
;
nodesWalkExpr
(
pKeys
,
tagScanNodeHasTbnameFunc
,
&
hasTbname
);
return
hasTbname
;
}
static
int32_t
tagScanSetExecutionMode
(
SScanLogicNode
*
pScan
)
{
pScan
->
onlyMetaCtbIdx
=
false
;
if
(
tagScanNodeListHasTbname
(
pScan
->
pScanPseudoCols
))
{
pScan
->
onlyMetaCtbIdx
=
false
;
return
TSDB_CODE_SUCCESS
;
}
if
(
pScan
->
node
.
pConditions
==
NULL
)
{
pScan
->
onlyMetaCtbIdx
=
true
;
return
TSDB_CODE_SUCCESS
;
}
SNode
*
pCond
=
nodesCloneNode
(
pScan
->
node
.
pConditions
);
SNode
*
pTagCond
=
NULL
;
SNode
*
pTagIndexCond
=
NULL
;
filterPartitionCond
(
&
pCond
,
NULL
,
&
pTagIndexCond
,
&
pTagCond
,
NULL
);
if
(
pTagIndexCond
||
tagScanNodeHasTbname
(
pTagCond
))
{
pScan
->
onlyMetaCtbIdx
=
false
;
}
else
{
pScan
->
onlyMetaCtbIdx
=
true
;
}
nodesDestroyNode
(
pCond
);
nodesDestroyNode
(
pTagIndexCond
);
nodesDestroyNode
(
pTagCond
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
createScanLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SRealTableNode
*
pRealTable
,
SLogicNode
**
pLogicNode
)
{
SScanLogicNode
*
pScan
=
NULL
;
...
...
@@ -411,6 +460,10 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
code
=
createColumnByRewriteExprs
(
pScan
->
pScanPseudoCols
,
&
pScan
->
node
.
pTargets
);
}
if
(
pScan
->
scanType
==
SCAN_TYPE_TAG
)
{
code
=
tagScanSetExecutionMode
(
pScan
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pLogicNode
=
(
SLogicNode
*
)
pScan
;
}
else
{
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
a9d88b74
...
...
@@ -1563,7 +1563,8 @@ static bool planOptNodeListHasTbname(SNodeList* pKeys) {
static
bool
partTagsIsOptimizableNode
(
SLogicNode
*
pNode
)
{
bool
ret
=
1
==
LIST_LENGTH
(
pNode
->
pChildren
)
&&
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
nodesListGetNode
(
pNode
->
pChildren
,
0
));
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
nodesListGetNode
(
pNode
->
pChildren
,
0
))
&&
SCAN_TYPE_TAG
!=
((
SScanLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
0
))
->
scanType
;
if
(
!
ret
)
return
ret
;
switch
(
nodeType
(
pNode
))
{
case
QUERY_NODE_LOGIC_PLAN_PARTITION
:
{
...
...
tests/script/tsim/query/tag_scan.sim
浏览文件 @
a9d88b74
...
...
@@ -45,4 +45,86 @@ if $rows != 4 then
return -1
endi
sql create table stt1(ts timestamp, f int) tags (t int, b varchar(10));
sql insert into ctt11 using stt1 tags(1, '1aa') values(now, 1);
sql insert into ctt12 using stt1 tags(2, '1bb') values(now, 2);
sql insert into ctt13 using stt1 tags(3, '1cc') values(now, 3);
sql insert into ctt14 using stt1 tags(4, '1dd') values(now, 4);
sql insert into ctt14 values(now, 5);
sql create table stt2(ts timestamp, f int) tags (t int, b varchar(10));
sql insert into ctt21 using stt2 tags(1, '2aa') values(now, 1);
sql insert into ctt22 using stt2 tags(2, '2bb') values(now, 2);
sql insert into ctt23 using stt2 tags(3, '2cc') values(now, 3);
sql insert into ctt24 using stt2 tags(4, '2dd') values(now, 4);
sql select tags t, b from stt1 order by t
print $rows
print $data00 $data01 $data10 $data11 $data20 $data21 $data30 $data31
if $rows != 4 then
return -1
endi
if $data31 != @1dd@ then
return -1
endi
sql select tags t, b from stt2 order by t
print $rows
print $data00 $data01 $data10 $data11 $data20 $data21 $data30 $data31
if $rows != 4 then
return -1
endi
if $data31 != @2dd@ then
return -1
endi
sql select tags t,b,f from stt1 order by t
print $rows
print $data00 $data01 $data02 $data10 $data11 $data12 $data20 $data21 $data22 $data30 $data31 $data32 $data40 $data41 $data42
if $rows != 5 then
return -1
endi
if $data42 != 5 then
return -1
endi
sql select tags tbname,t,b from stt1 order by t
print $rows
print $data00 $data01 $data02 $data10 $data11 $data12 $data20 $data21 $data22 $data30 $data31 $data32
if $rows != 4 then
return -1
endi
if $data30 != @ctt14@ then
return -1
endi
if $data32 != @1dd@ then
return -1
endi
sql select tags t,b from stt1 where t=1
print $rows
print $data00 $data01
if $rows != 1 then
return -1
endi
if $data00 != @1@ then
return -1
endi
if $data01 != @1aa@ then
return -1
endi
sql select tags t,b from stt1 where tbname='ctt11'
print $rows
print $data00 $data01
if $rows != 1 then
return -1
endi
if $data00 != @1@ then
return -1
endi
if $data01 != @1aa@ then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录