Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
电商架构修炼
TDengine
提交
84c8fc9e
TDengine
项目概览
电商架构修炼
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
84c8fc9e
编写于
7月 02, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-4865]<enhance>: support group by in the outer query.
上级
71367b78
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
172 addition
and
147 deletion
+172
-147
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+85
-78
src/client/src/tscServer.c
src/client/src/tscServer.c
+6
-5
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+56
-50
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+1
-0
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+18
-13
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+1
-1
tests/script/general/parser/nestquery.sim
tests/script/general/parser/nestquery.sim
+5
-0
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
84c8fc9e
此差异已折叠。
点击以展开。
src/client/src/tscServer.c
浏览文件 @
84c8fc9e
...
...
@@ -2398,11 +2398,12 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) {
}
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
if
(
pCmd
->
command
==
TSDB_SQL_RETRIEVE
)
{
tscSetResRawPtr
(
pRes
,
pQueryInfo
);
}
else
if
((
UTIL_TABLE_IS_CHILD_TABLE
(
pTableMetaInfo
)
||
UTIL_TABLE_IS_NORMAL_TABLE
(
pTableMetaInfo
))
&&
!
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_SUBQUERY
))
{
tscSetResRawPtr
(
pRes
,
pQueryInfo
);
}
else
if
(
tscNonOrderedProjectionQueryOnSTable
(
pQueryInfo
,
0
)
&&
!
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_JOIN_QUERY
)
&&
!
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
))
{
if
((
pCmd
->
command
==
TSDB_SQL_RETRIEVE
)
||
((
UTIL_TABLE_IS_CHILD_TABLE
(
pTableMetaInfo
)
||
UTIL_TABLE_IS_NORMAL_TABLE
(
pTableMetaInfo
))
&&
!
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_SUBQUERY
))
||
(
tscNonOrderedProjectionQueryOnSTable
(
pQueryInfo
,
0
)
&&
!
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_JOIN_QUERY
)
&&
!
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
)))
{
tscSetResRawPtr
(
pRes
,
pQueryInfo
);
}
...
...
src/client/src/tscUtil.c
浏览文件 @
84c8fc9e
...
...
@@ -578,70 +578,72 @@ int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) {
return
TSDB_CODE_SUCCESS
;
}
void
tscSetResRawPtr
(
SSqlRes
*
pRes
,
SQueryInfo
*
pQueryInfo
)
{
assert
(
pRes
->
numOfCols
>
0
);
static
void
setResRawPtrImpl
(
SSqlRes
*
pRes
,
SInternalField
*
pInfo
,
int32_t
i
,
bool
convertNchar
)
{
// generated the user-defined column result
if
(
pInfo
->
pExpr
->
pExpr
==
NULL
&&
TSDB_COL_IS_UD_COL
(
pInfo
->
pExpr
->
base
.
colInfo
.
flag
))
{
if
(
pInfo
->
pExpr
->
base
.
param
[
1
].
nType
==
TSDB_DATA_TYPE_NULL
)
{
setNullN
(
pRes
->
urow
[
i
],
pInfo
->
field
.
type
,
pInfo
->
field
.
bytes
,
(
int32_t
)
pRes
->
numOfRows
);
}
else
{
if
(
pInfo
->
field
.
type
==
TSDB_DATA_TYPE_NCHAR
||
pInfo
->
field
.
type
==
TSDB_DATA_TYPE_BINARY
)
{
assert
(
pInfo
->
pExpr
->
base
.
param
[
1
].
nLen
<=
pInfo
->
field
.
bytes
);
int32_t
offset
=
0
;
for
(
int32_t
k
=
0
;
k
<
pRes
->
numOfRows
;
++
k
)
{
char
*
p
=
((
char
**
)
pRes
->
urow
)[
i
]
+
k
*
pInfo
->
field
.
bytes
;
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
fieldsInfo
.
numOfOutput
;
++
i
)
{
SInternalField
*
pInfo
=
(
SInternalField
*
)
TARRAY_GET_ELEM
(
pQueryInfo
->
fieldsInfo
.
internalField
,
i
);
memcpy
(
varDataVal
(
p
),
pInfo
->
pExpr
->
base
.
param
[
1
].
pz
,
pInfo
->
pExpr
->
base
.
param
[
1
].
nLen
);
varDataSetLen
(
p
,
pInfo
->
pExpr
->
base
.
param
[
1
].
nLen
);
}
}
else
{
for
(
int32_t
k
=
0
;
k
<
pRes
->
numOfRows
;
++
k
)
{
char
*
p
=
((
char
**
)
pRes
->
urow
)[
i
]
+
k
*
pInfo
->
field
.
bytes
;
memcpy
(
p
,
&
pInfo
->
pExpr
->
base
.
param
[
1
].
i64
,
pInfo
->
field
.
bytes
);
}
}
}
pRes
->
urow
[
i
]
=
pRes
->
data
+
offset
*
pRes
->
numOfRows
;
pRes
->
length
[
i
]
=
pInfo
->
field
.
bytes
;
}
else
if
(
convertNchar
&&
pInfo
->
field
.
type
==
TSDB_DATA_TYPE_NCHAR
)
{
// convert unicode to native code in a temporary buffer extra one byte for terminated symbol
pRes
->
buffer
[
i
]
=
realloc
(
pRes
->
buffer
[
i
],
pInfo
->
field
.
bytes
*
pRes
->
numOfRows
);
offset
+=
pInfo
->
field
.
bytes
;
// string terminated char for binary data
memset
(
pRes
->
buffer
[
i
],
0
,
pInfo
->
field
.
bytes
*
pRes
->
numOfRows
);
// generated the user-defined column result
if
(
pInfo
->
pExpr
->
pExpr
==
NULL
&&
TSDB_COL_IS_UD_COL
(
pInfo
->
pExpr
->
base
.
colInfo
.
flag
))
{
if
(
pInfo
->
pExpr
->
base
.
param
[
1
].
nType
==
TSDB_DATA_TYPE_NULL
)
{
setNullN
(
pRes
->
urow
[
i
],
pInfo
->
field
.
type
,
pInfo
->
field
.
bytes
,
(
int32_t
)
pRes
->
numOfRows
);
}
else
{
if
(
pInfo
->
field
.
type
==
TSDB_DATA_TYPE_NCHAR
||
pInfo
->
field
.
type
==
TSDB_DATA_TYPE_BINARY
)
{
assert
(
pInfo
->
pExpr
->
base
.
param
[
1
].
nLen
<=
pInfo
->
field
.
bytes
);
char
*
p
=
pRes
->
urow
[
i
];
for
(
int32_t
k
=
0
;
k
<
pRes
->
numOfRows
;
++
k
)
{
char
*
dst
=
pRes
->
buffer
[
i
]
+
k
*
pInfo
->
field
.
bytes
;
for
(
int32_t
k
=
0
;
k
<
pRes
->
numOfRows
;
++
k
)
{
char
*
p
=
((
char
**
)
pRes
->
urow
)[
i
]
+
k
*
pInfo
->
field
.
bytes
;
if
(
isNull
(
p
,
TSDB_DATA_TYPE_NCHAR
))
{
memcpy
(
dst
,
p
,
varDataTLen
(
p
));
}
else
if
(
varDataLen
(
p
)
>
0
)
{
int32_t
length
=
taosUcs4ToMbs
(
varDataVal
(
p
),
varDataLen
(
p
),
varDataVal
(
dst
));
varDataSetLen
(
dst
,
length
);
memcpy
(
varDataVal
(
p
),
pInfo
->
pExpr
->
base
.
param
[
1
].
pz
,
pInfo
->
pExpr
->
base
.
param
[
1
].
nLen
);
varDataSetLen
(
p
,
pInfo
->
pExpr
->
base
.
param
[
1
].
nLen
);
}
}
else
{
for
(
int32_t
k
=
0
;
k
<
pRes
->
numOfRows
;
++
k
)
{
char
*
p
=
((
char
**
)
pRes
->
urow
)[
i
]
+
k
*
pInfo
->
field
.
bytes
;
memcpy
(
p
,
&
pInfo
->
pExpr
->
base
.
param
[
1
].
i64
,
pInfo
->
field
.
bytes
);
}
if
(
length
==
0
)
{
tscError
(
"charset:%s to %s. val:%s convert failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
(
char
*
)
p
);
}
}
else
{
varDataSetLen
(
dst
,
0
);
}
}
else
if
(
pInfo
->
field
.
type
==
TSDB_DATA_TYPE_NCHAR
)
{
// convert unicode to native code in a temporary buffer extra one byte for terminated symbol
pRes
->
buffer
[
i
]
=
realloc
(
pRes
->
buffer
[
i
],
pInfo
->
field
.
bytes
*
pRes
->
numOfRows
);
// string terminated char for binary data
memset
(
pRes
->
buffer
[
i
],
0
,
pInfo
->
field
.
bytes
*
pRes
->
numOfRows
);
p
+=
pInfo
->
field
.
bytes
;
}
char
*
p
=
pRes
->
urow
[
i
]
;
for
(
int32_t
k
=
0
;
k
<
pRes
->
numOfRows
;
++
k
)
{
char
*
dst
=
pRes
->
buffer
[
i
]
+
k
*
pInfo
->
field
.
bytes
;
memcpy
(
pRes
->
urow
[
i
],
pRes
->
buffer
[
i
],
pInfo
->
field
.
bytes
*
pRes
->
numOfRows
)
;
}
}
if
(
isNull
(
p
,
TSDB_DATA_TYPE_NCHAR
))
{
memcpy
(
dst
,
p
,
varDataTLen
(
p
));
}
else
if
(
varDataLen
(
p
)
>
0
)
{
int32_t
length
=
taosUcs4ToMbs
(
varDataVal
(
p
),
varDataLen
(
p
),
varDataVal
(
dst
));
varDataSetLen
(
dst
,
length
);
void
tscSetResRawPtr
(
SSqlRes
*
pRes
,
SQueryInfo
*
pQueryInfo
)
{
assert
(
pRes
->
numOfCols
>
0
);
if
(
length
==
0
)
{
tscError
(
"charset:%s to %s. val:%s convert failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
(
char
*
)
p
);
}
}
else
{
varDataSetLen
(
dst
,
0
);
}
int32_t
offset
=
0
;
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
fieldsInfo
.
numOfOutput
;
++
i
)
{
SInternalField
*
pInfo
=
(
SInternalField
*
)
TARRAY_GET_ELEM
(
pQueryInfo
->
fieldsInfo
.
internalField
,
i
);
p
+=
pInfo
->
field
.
byte
s
;
}
pRes
->
urow
[
i
]
=
pRes
->
data
+
offset
*
pRes
->
numOfRow
s
;
pRes
->
length
[
i
]
=
pInfo
->
field
.
bytes
;
memcpy
(
pRes
->
urow
[
i
],
pRes
->
buffer
[
i
],
pInfo
->
field
.
bytes
*
pRes
->
numOfRows
)
;
}
offset
+=
pInfo
->
field
.
bytes
;
setResRawPtrImpl
(
pRes
,
pInfo
,
i
,
true
);
}
}
...
...
@@ -656,6 +658,8 @@ void tscSetResRawPtrRv(SSqlRes* pRes, SQueryInfo* pQueryInfo, SSDataBlock* pBloc
pRes
->
urow
[
i
]
=
pColData
->
pData
;
pRes
->
length
[
i
]
=
pInfo
->
field
.
bytes
;
setResRawPtrImpl
(
pRes
,
pInfo
,
i
,
convertNchar
);
/*
// generated the user-defined column result
if (pInfo->pExpr->pExpr == NULL && TSDB_COL_IS_UD_COL(pInfo->pExpr->base.colInfo.flag)) {
if (pInfo->pExpr->base.param[1].nType == TSDB_DATA_TYPE_NULL) {
...
...
@@ -706,7 +710,7 @@ void tscSetResRawPtrRv(SSqlRes* pRes, SQueryInfo* pQueryInfo, SSDataBlock* pBloc
}
memcpy(pRes->urow[i], pRes->buffer[i], pInfo->field.bytes * pRes->numOfRows);
}
}
*/
}
}
...
...
@@ -989,6 +993,8 @@ static void destroyDummyInputOperator(void* param, int32_t numOfOutput) {
pInfo
->
block
=
destroyOutputBuf
(
pInfo
->
block
);
pInfo
->
pSql
=
NULL
;
doDestroyFilterInfo
(
pInfo
->
pFilterInfo
,
pInfo
->
numOfFilterCols
);
cleanupResultRowInfo
(
&
pInfo
->
pTableQueryInfo
->
resInfo
);
tfree
(
pInfo
->
pTableQueryInfo
);
}
...
...
src/query/inc/qExecutor.h
浏览文件 @
84c8fc9e
...
...
@@ -571,6 +571,7 @@ void doCompactSDataBlock(SSDataBlock* pBlock, int32_t numOfRows, int8_t* p);
SSDataBlock
*
createOutputBuf
(
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
int32_t
numOfRows
);
void
*
destroyOutputBuf
(
SSDataBlock
*
pBlock
);
void
*
doDestroyFilterInfo
(
SSingleColumnFilterInfo
*
pFilterInfo
,
int32_t
numOfFilterCols
);
void
setInputDataBlock
(
SOperatorInfo
*
pOperator
,
SQLFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
,
int32_t
order
);
int32_t
getNumOfResult
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
numOfOutput
);
...
...
src/query/src/qExecutor.c
浏览文件 @
84c8fc9e
...
...
@@ -179,7 +179,6 @@ static STsdbQueryCond createTsdbQueryCond(SQueryAttr* pQueryAttr, STimeWindow* w
static
STableIdInfo
createTableIdInfo
(
STableQueryInfo
*
pTableQueryInfo
);
static
void
setTableScanFilterOperatorInfo
(
STableScanInfo
*
pTableScanInfo
,
SOperatorInfo
*
pDownstream
);
static
void
*
doDestroyFilterInfo
(
SSingleColumnFilterInfo
*
pFilterInfo
,
int32_t
numOfFilterCols
);
static
int32_t
getNumOfScanTimes
(
SQueryAttr
*
pQueryAttr
);
...
...
@@ -237,37 +236,41 @@ static int compareRowData(const void *a, const void *b, const void *userData) {
static
void
sortGroupResByOrderList
(
SGroupResInfo
*
pGroupResInfo
,
SQueryRuntimeEnv
*
pRuntimeEnv
,
SSDataBlock
*
pDataBlock
)
{
SArray
*
columnOrderList
=
getOrderCheckColumns
(
pRuntimeEnv
->
pQueryAttr
);
if
(
taosArrayGetSize
(
columnOrderList
)
<=
0
)
{
size_t
size
=
taosArrayGetSize
(
columnOrderList
);
taosArrayDestroy
(
columnOrderList
);
if
(
size
<=
0
)
{
return
;
}
int32_t
orderId
=
pRuntimeEnv
->
pQueryAttr
->
order
.
orderColId
;
if
(
orderId
<=
0
)
{
return
;
}
}
bool
found
=
false
;
int16_t
dataOffset
=
0
;
//SColIndex *index = taosArrayGet(columnOrderList, 0);
for
(
int32_t
j
=
0
;
j
<
pDataBlock
->
info
.
numOfCols
;
++
j
)
{
SColumnInfoData
*
pColInfoData
=
(
SColumnInfoData
*
)
taosArrayGet
(
pDataBlock
->
pDataBlock
,
j
);
if
(
orderId
==
j
)
{
found
=
true
;
break
;
}
dataOffset
+=
pColInfoData
->
info
.
bytes
;
}
if
(
found
==
false
)
{
return
;
}
int16_t
type
=
pRuntimeEnv
->
pQueryAttr
->
pExpr1
[
orderId
].
base
.
resType
;
SRowCompSupporter
support
=
{.
pRuntimeEnv
=
pRuntimeEnv
,
.
dataOffset
=
dataOffset
,
.
comFunc
=
getComparFunc
(
type
,
0
)};
taosArraySortPWithExt
(
pGroupResInfo
->
pRows
,
compareRowData
,
&
support
);
return
;
}
//setup the output buffer for each operator
SSDataBlock
*
createOutputBuf
(
SExprInfo
*
pExpr
,
int32_t
numOfOutput
,
int32_t
numOfRows
)
{
const
static
int32_t
minSize
=
8
;
...
...
@@ -1798,7 +1801,9 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf
pRuntimeEnv
->
prevRow
[
i
]
=
pRuntimeEnv
->
prevRow
[
i
-
1
]
+
pQueryAttr
->
tableCols
[
i
-
1
].
bytes
;
}
*
(
int64_t
*
)
pRuntimeEnv
->
prevRow
[
0
]
=
INT64_MIN
;
if
(
pQueryAttr
->
tableCols
[
0
].
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
*
(
int64_t
*
)
pRuntimeEnv
->
prevRow
[
0
]
=
INT64_MIN
;
}
}
qDebug
(
"QInfo:0x%"
PRIx64
" init runtime environment completed"
,
GET_QID
(
pRuntimeEnv
));
...
...
@@ -1832,7 +1837,11 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf
case
OP_Groupby
:
{
pRuntimeEnv
->
proot
=
createGroupbyOperatorInfo
(
pRuntimeEnv
,
pRuntimeEnv
->
proot
,
pQueryAttr
->
pExpr1
,
pQueryAttr
->
numOfOutput
);
setTableScanFilterOperatorInfo
(
pRuntimeEnv
->
proot
->
upstream
[
0
]
->
info
,
pRuntimeEnv
->
proot
);
int32_t
opType
=
pRuntimeEnv
->
proot
->
upstream
[
0
]
->
operatorType
;
if
(
opType
!=
OP_DummyInput
)
{
setTableScanFilterOperatorInfo
(
pRuntimeEnv
->
proot
->
upstream
[
0
]
->
info
,
pRuntimeEnv
->
proot
);
}
break
;
}
case
OP_SessionWindow
:
{
...
...
@@ -2683,10 +2692,6 @@ static uint32_t doFilterByBlockTimeWindow(STableScanInfo* pTableScanInfo, SSData
}
void
doSetFilterColumnInfo
(
SSingleColumnFilterInfo
*
pFilterInfo
,
int32_t
numOfFilterCols
,
SSDataBlock
*
pBlock
)
{
if
(
numOfFilterCols
>
0
&&
pFilterInfo
[
0
].
pData
!=
NULL
)
{
return
;
}
// set the initial static data value filter expression
for
(
int32_t
i
=
0
;
i
<
numOfFilterCols
;
++
i
)
{
for
(
int32_t
j
=
0
;
j
<
pBlock
->
info
.
numOfCols
;
++
j
)
{
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
84c8fc9e
...
...
@@ -364,7 +364,7 @@ static int64_t getEarliestValidTimestamp(STsdbRepo* pTsdb) {
STsdbCfg
*
pCfg
=
&
pTsdb
->
config
;
int64_t
now
=
taosGetTimestamp
(
pCfg
->
precision
);
return
now
-
(
tsTickPerDay
[
pCfg
->
precision
]
*
pCfg
->
keep
)
;
return
now
-
(
tsTickPerDay
[
pCfg
->
precision
]
*
pCfg
->
keep
)
+
1
;
// needs to add one tick
}
static
void
setQueryTimewindow
(
STsdbQueryHandle
*
pQueryHandle
,
STsdbQueryCond
*
pCond
)
{
...
...
tests/script/general/parser/nestquery.sim
浏览文件 @
84c8fc9e
...
...
@@ -426,4 +426,9 @@ endi
sql_error select last_row(*) from (select * from nest_tb0) having c1 > 0
print ===========>td-4805
sql_error select tbname, i from (select * from nest_tb0) group by i;
sql select count(*),c1 from (select * from nest_tb0) where c1 < 2 group by c1;
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录