Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
cca70151
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
cca70151
编写于
12月 24, 2020
作者:
H
haojun Liao
提交者:
GitHub
12月 24, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4681 from taosdata/feature/query
Feature/query
上级
6f1b9747
a8fc69c8
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
508 addition
and
758 deletion
+508
-758
src/client/src/tscAsync.c
src/client/src/tscAsync.c
+1
-1
src/client/src/tscFunctionImpl.c
src/client/src/tscFunctionImpl.c
+15
-3
src/common/src/tglobal.c
src/common/src/tglobal.c
+1
-1
src/connector/grafanaplugin
src/connector/grafanaplugin
+1
-1
src/connector/nodejs/nodetaos/cinterface.js
src/connector/nodejs/nodetaos/cinterface.js
+4
-4
src/inc/ttype.h
src/inc/ttype.h
+1
-1
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+6
-8
src/query/inc/qHistogram.h
src/query/inc/qHistogram.h
+1
-1
src/query/inc/qUtil.h
src/query/inc/qUtil.h
+0
-1
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+367
-674
src/query/src/qHistogram.c
src/query/src/qHistogram.c
+5
-4
src/query/src/qUtil.c
src/query/src/qUtil.c
+4
-19
src/tsdb/inc/tsdbMain.h
src/tsdb/inc/tsdbMain.h
+10
-10
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+64
-24
src/util/src/tcache.c
src/util/src/tcache.c
+5
-4
src/util/src/tskiplist.c
src/util/src/tskiplist.c
+6
-1
tests/script/general/parser/mixed_blocks.sim
tests/script/general/parser/mixed_blocks.sim
+17
-1
未找到文件。
src/client/src/tscAsync.c
浏览文件 @
cca70151
...
@@ -388,10 +388,10 @@ void tscQueueAsyncRes(SSqlObj *pSql) {
...
@@ -388,10 +388,10 @@ void tscQueueAsyncRes(SSqlObj *pSql) {
return
;
return
;
}
}
assert
(
pSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
);
tscError
(
"%p add into queued async res, code:%s"
,
pSql
,
tstrerror
(
pSql
->
res
.
code
));
tscError
(
"%p add into queued async res, code:%s"
,
pSql
,
tstrerror
(
pSql
->
res
.
code
));
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
if
(
pSql
->
fp
==
NULL
||
pSql
->
fetchFp
==
NULL
){
if
(
pSql
->
fp
==
NULL
||
pSql
->
fetchFp
==
NULL
){
return
;
return
;
}
}
...
...
src/client/src/tscFunctionImpl.c
浏览文件 @
cca70151
...
@@ -2597,14 +2597,23 @@ static void percentile_next_step(SQLFunctionCtx *pCtx) {
...
@@ -2597,14 +2597,23 @@ static void percentile_next_step(SQLFunctionCtx *pCtx) {
}
}
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
static
void
buildHistogramInfo
(
SAPercentileInfo
*
pInfo
)
{
pInfo
->
pHisto
=
(
SHistogramInfo
*
)
((
char
*
)
pInfo
+
sizeof
(
SAPercentileInfo
));
pInfo
->
pHisto
->
elems
=
(
SHistBin
*
)
((
char
*
)
pInfo
->
pHisto
+
sizeof
(
SHistogramInfo
));
}
static
SAPercentileInfo
*
getAPerctInfo
(
SQLFunctionCtx
*
pCtx
)
{
static
SAPercentileInfo
*
getAPerctInfo
(
SQLFunctionCtx
*
pCtx
)
{
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SAPercentileInfo
*
pInfo
=
NULL
;
if
(
pCtx
->
stableQuery
&&
pCtx
->
currentStage
!=
SECONDARY_STAGE_MERGE
)
{
if
(
pCtx
->
stableQuery
&&
pCtx
->
currentStage
!=
SECONDARY_STAGE_MERGE
)
{
return
(
SAPercentileInfo
*
)
pCtx
->
aOutputBuf
;
pInfo
=
(
SAPercentileInfo
*
)
pCtx
->
aOutputBuf
;
}
else
{
}
else
{
return
GET_ROWCELL_INTERBUF
(
pResInfo
);
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
}
}
buildHistogramInfo
(
pInfo
);
return
pInfo
;
}
}
static
bool
apercentile_function_setup
(
SQLFunctionCtx
*
pCtx
)
{
static
bool
apercentile_function_setup
(
SQLFunctionCtx
*
pCtx
)
{
...
@@ -2616,6 +2625,7 @@ static bool apercentile_function_setup(SQLFunctionCtx *pCtx) {
...
@@ -2616,6 +2625,7 @@ static bool apercentile_function_setup(SQLFunctionCtx *pCtx) {
char
*
tmp
=
(
char
*
)
pInfo
+
sizeof
(
SAPercentileInfo
);
char
*
tmp
=
(
char
*
)
pInfo
+
sizeof
(
SAPercentileInfo
);
pInfo
->
pHisto
=
tHistogramCreateFrom
(
tmp
,
MAX_HISTOGRAM_BIN
);
pInfo
->
pHisto
=
tHistogramCreateFrom
(
tmp
,
MAX_HISTOGRAM_BIN
);
printf
(
"%p, %p
\n
"
,
pInfo
->
pHisto
,
pInfo
->
pHisto
->
elems
);
return
true
;
return
true
;
}
}
...
@@ -2624,6 +2634,8 @@ static void apercentile_function(SQLFunctionCtx *pCtx) {
...
@@ -2624,6 +2634,8 @@ static void apercentile_function(SQLFunctionCtx *pCtx) {
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SAPercentileInfo
*
pInfo
=
getAPerctInfo
(
pCtx
);
SAPercentileInfo
*
pInfo
=
getAPerctInfo
(
pCtx
);
assert
(
pInfo
->
pHisto
->
elems
!=
NULL
);
for
(
int32_t
i
=
0
;
i
<
pCtx
->
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pCtx
->
size
;
++
i
)
{
char
*
data
=
GET_INPUT_CHAR_INDEX
(
pCtx
,
i
);
char
*
data
=
GET_INPUT_CHAR_INDEX
(
pCtx
,
i
);
...
...
src/common/src/tglobal.c
浏览文件 @
cca70151
...
@@ -221,7 +221,7 @@ int32_t uDebugFlag = 131;
...
@@ -221,7 +221,7 @@ int32_t uDebugFlag = 131;
int32_t
debugFlag
=
0
;
int32_t
debugFlag
=
0
;
int32_t
sDebugFlag
=
135
;
int32_t
sDebugFlag
=
135
;
int32_t
wDebugFlag
=
135
;
int32_t
wDebugFlag
=
135
;
int32_t
tsdbDebugFlag
=
131
;
u
int32_t
tsdbDebugFlag
=
131
;
int32_t
cqDebugFlag
=
131
;
int32_t
cqDebugFlag
=
131
;
int32_t
(
*
monStartSystemFp
)()
=
NULL
;
int32_t
(
*
monStartSystemFp
)()
=
NULL
;
...
...
grafanaplugin
@
ec77d904
比较
32e2c97a
...
ec77d904
Subproject commit
32e2c97a4cf7bedaa99f5d6dd8cb036e7f4470df
Subproject commit
ec77d9049a719dabfd1a7c1122a209e201861944
src/connector/nodejs/nodetaos/cinterface.js
浏览文件 @
cca70151
...
@@ -349,11 +349,12 @@ CTaosInterface.prototype.useResult = function useResult(result) {
...
@@ -349,11 +349,12 @@ CTaosInterface.prototype.useResult = function useResult(result) {
return
fields
;
return
fields
;
}
}
CTaosInterface
.
prototype
.
fetchBlock
=
function
fetchBlock
(
result
,
fields
)
{
CTaosInterface
.
prototype
.
fetchBlock
=
function
fetchBlock
(
result
,
fields
)
{
let
pblock
=
ref
.
ref
(
ref
.
ref
(
ref
.
NULL
));
// equal to our raw data
//
let pblock = ref.ref(ref.ref(ref.NULL)); // equal to our raw data
let
num_of_rows
=
this
.
libtaos
.
taos_fetch_block
(
result
,
pblock
)
let
pblock
=
this
.
libtaos
.
taos_fetch_row
(
result
);
if
(
num_of_rows
==
0
)
{
if
(
pblock
==
null
)
{
return
{
block
:
null
,
num_of_rows
:
0
};
return
{
block
:
null
,
num_of_rows
:
0
};
}
}
var
fieldL
=
this
.
libtaos
.
taos_fetch_lengths
(
result
);
var
fieldL
=
this
.
libtaos
.
taos_fetch_lengths
(
result
);
let
isMicro
=
(
this
.
libtaos
.
taos_result_precision
(
result
)
==
FieldTypes
.
C_TIMESTAMP_MICRO
);
let
isMicro
=
(
this
.
libtaos
.
taos_result_precision
(
result
)
==
FieldTypes
.
C_TIMESTAMP_MICRO
);
...
@@ -361,7 +362,6 @@ CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) {
...
@@ -361,7 +362,6 @@ CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) {
var
fieldlens
=
[];
var
fieldlens
=
[];
if
(
ref
.
isNull
(
fieldL
)
==
false
)
{
if
(
ref
.
isNull
(
fieldL
)
==
false
)
{
for
(
let
i
=
0
;
i
<
fields
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
fields
.
length
;
i
++
)
{
let
plen
=
ref
.
reinterpret
(
fieldL
,
4
,
i
*
4
);
let
plen
=
ref
.
reinterpret
(
fieldL
,
4
,
i
*
4
);
let
len
=
plen
.
readInt32LE
(
0
);
let
len
=
plen
.
readInt32LE
(
0
);
...
...
src/inc/ttype.h
浏览文件 @
cca70151
...
@@ -28,7 +28,7 @@ extern "C" {
...
@@ -28,7 +28,7 @@ extern "C" {
default: \
default: \
(_v) = (_finalType)GET_INT32_VAL(_data); \
(_v) = (_finalType)GET_INT32_VAL(_data); \
break; \
break; \
}
;
}
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
src/query/inc/qExecutor.h
浏览文件 @
cca70151
...
@@ -33,13 +33,6 @@ struct SColumnFilterElem;
...
@@ -33,13 +33,6 @@ struct SColumnFilterElem;
typedef
bool
(
*
__filter_func_t
)(
struct
SColumnFilterElem
*
pFilter
,
char
*
val1
,
char
*
val2
);
typedef
bool
(
*
__filter_func_t
)(
struct
SColumnFilterElem
*
pFilter
,
char
*
val1
,
char
*
val2
);
typedef
int32_t
(
*
__block_search_fn_t
)(
char
*
data
,
int32_t
num
,
int64_t
key
,
int32_t
order
);
typedef
int32_t
(
*
__block_search_fn_t
)(
char
*
data
,
int32_t
num
,
int64_t
key
,
int32_t
order
);
typedef
struct
SGroupResInfo
{
int32_t
groupId
;
int32_t
numOfDataPages
;
int32_t
pageId
;
int32_t
rowId
;
}
SGroupResInfo
;
typedef
struct
SResultRowPool
{
typedef
struct
SResultRowPool
{
int32_t
elemSize
;
int32_t
elemSize
;
int32_t
blockSize
;
int32_t
blockSize
;
...
@@ -72,6 +65,12 @@ typedef struct SResultRow {
...
@@ -72,6 +65,12 @@ typedef struct SResultRow {
union
{
STimeWindow
win
;
char
*
key
;};
// start key of current time window
union
{
STimeWindow
win
;
char
*
key
;};
// start key of current time window
}
SResultRow
;
}
SResultRow
;
typedef
struct
SGroupResInfo
{
int32_t
rowId
;
int32_t
index
;
SArray
*
pRows
;
// SArray<SResultRow*>
}
SGroupResInfo
;
/**
/**
* If the number of generated results is greater than this value,
* If the number of generated results is greater than this value,
* query query will be halt and return results to client immediate.
* query query will be halt and return results to client immediate.
...
@@ -89,7 +88,6 @@ typedef struct SResultRowInfo {
...
@@ -89,7 +88,6 @@ typedef struct SResultRowInfo {
int32_t
size
:
24
;
// number of result set
int32_t
size
:
24
;
// number of result set
int32_t
capacity
;
// max capacity
int32_t
capacity
;
// max capacity
int32_t
curIndex
;
// current start active index
int32_t
curIndex
;
// current start active index
int64_t
startTime
;
// start time of the first time window for sliding query
int64_t
prevSKey
;
// previous (not completed) sliding window start key
int64_t
prevSKey
;
// previous (not completed) sliding window start key
}
SResultRowInfo
;
}
SResultRowInfo
;
...
...
src/query/inc/qHistogram.h
浏览文件 @
cca70151
...
@@ -67,7 +67,7 @@ void tHistogramDestroy(SHistogramInfo** pHisto);
...
@@ -67,7 +67,7 @@ void tHistogramDestroy(SHistogramInfo** pHisto);
void
tHistogramPrint
(
SHistogramInfo
*
pHisto
);
void
tHistogramPrint
(
SHistogramInfo
*
pHisto
);
int32_t
vnodeHistob
inarySearch
(
SHistBin
*
pEntry
,
int32_t
len
,
double
val
);
//int32_t histoB
inarySearch(SHistBin* pEntry, int32_t len, double val);
SHeapEntry
*
tHeapCreate
(
int32_t
numOfEntries
);
SHeapEntry
*
tHeapCreate
(
int32_t
numOfEntries
);
void
tHeapSort
(
SHeapEntry
*
pEntry
,
int32_t
len
);
void
tHeapSort
(
SHeapEntry
*
pEntry
,
int32_t
len
);
...
...
src/query/inc/qUtil.h
浏览文件 @
cca70151
...
@@ -77,7 +77,6 @@ void* destroyResultRowPool(SResultRowPool* p);
...
@@ -77,7 +77,6 @@ void* destroyResultRowPool(SResultRowPool* p);
int32_t
getNumOfAllocatedResultRows
(
SResultRowPool
*
p
);
int32_t
getNumOfAllocatedResultRows
(
SResultRowPool
*
p
);
int32_t
getNumOfUsedResultRows
(
SResultRowPool
*
p
);
int32_t
getNumOfUsedResultRows
(
SResultRowPool
*
p
);
uint64_t
getResultInfoUId
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
bool
isPointInterpoQuery
(
SQuery
*
pQuery
);
bool
isPointInterpoQuery
(
SQuery
*
pQuery
);
...
...
src/query/src/qExecutor.c
浏览文件 @
cca70151
...
@@ -53,7 +53,7 @@
...
@@ -53,7 +53,7 @@
#define TIME_WINDOW_COPY(_dst, _src) do {\
#define TIME_WINDOW_COPY(_dst, _src) do {\
(_dst).skey = (_src).skey;\
(_dst).skey = (_src).skey;\
(_dst).ekey = (_src).ekey;\
(_dst).ekey = (_src).ekey;\
} while (0)
;
} while (0)
enum
{
enum
{
// when query starts to execute, this status will set
// when query starts to execute, this status will set
...
@@ -178,11 +178,10 @@ static void getNextTimeWindow(SQuery* pQuery, STimeWindow* tw) {
...
@@ -178,11 +178,10 @@ static void getNextTimeWindow(SQuery* pQuery, STimeWindow* tw) {
#define IS_STASBLE_QUERY_OVER(_q) ((_q)->tableIndex >= (int32_t)((_q)->tableqinfoGroupInfo.numOfTables))
#define IS_STASBLE_QUERY_OVER(_q) ((_q)->tableIndex >= (int32_t)((_q)->tableqinfoGroupInfo.numOfTables))
// todo move to utility
// todo move to utility
static
int32_t
mergeIntoGroupResultImpl
(
S
QInfo
*
pQInfo
,
SArray
*
group
);
static
int32_t
mergeIntoGroupResultImpl
(
S
GroupResInfo
*
pGroupResInfo
,
SArray
*
pTableList
,
SQInfo
*
pQInfo
);
static
void
setResultOutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResult
);
static
void
setResultOutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResult
);
static
void
setResultRowOutputBufInitCtx
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResult
);
static
void
setResultRowOutputBufInitCtx
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResult
);
static
void
resetMergeResultBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
SResultRow
*
pRow
);
static
bool
functionNeedToExecute
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
functionId
);
static
bool
functionNeedToExecute
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
int32_t
functionId
);
static
void
setExecParams
(
SQuery
*
pQuery
,
SQLFunctionCtx
*
pCtx
,
void
*
inputData
,
TSKEY
*
tsCol
,
SDataBlockInfo
*
pBlockInfo
,
static
void
setExecParams
(
SQuery
*
pQuery
,
SQLFunctionCtx
*
pCtx
,
void
*
inputData
,
TSKEY
*
tsCol
,
SDataBlockInfo
*
pBlockInfo
,
...
@@ -195,7 +194,6 @@ static bool hasMainOutput(SQuery *pQuery);
...
@@ -195,7 +194,6 @@ static bool hasMainOutput(SQuery *pQuery);
static
void
buildTagQueryResult
(
SQInfo
*
pQInfo
);
static
void
buildTagQueryResult
(
SQInfo
*
pQInfo
);
static
int32_t
setAdditionalInfo
(
SQInfo
*
pQInfo
,
void
*
pTable
,
STableQueryInfo
*
pTableQueryInfo
);
static
int32_t
setAdditionalInfo
(
SQInfo
*
pQInfo
,
void
*
pTable
,
STableQueryInfo
*
pTableQueryInfo
);
static
int32_t
flushFromResultBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
);
static
int32_t
checkForQueryBuf
(
size_t
numOfTables
);
static
int32_t
checkForQueryBuf
(
size_t
numOfTables
);
static
void
releaseQueryBuf
(
size_t
numOfTables
);
static
void
releaseQueryBuf
(
size_t
numOfTables
);
static
int32_t
binarySearchForKey
(
char
*
pValue
,
int
num
,
TSKEY
key
,
int
order
);
static
int32_t
binarySearchForKey
(
char
*
pValue
,
int
num
,
TSKEY
key
,
int
order
);
...
@@ -291,7 +289,7 @@ void updateNumOfResult(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOfRes) {
...
@@ -291,7 +289,7 @@ void updateNumOfResult(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOfRes) {
}
}
}
}
static
int32_t
getMergeResultGroupId
(
int32_t
groupIndex
)
{
static
UNUSED_FUNC
int32_t
getMergeResultGroupId
(
int32_t
groupIndex
)
{
int32_t
base
=
50000000
;
int32_t
base
=
50000000
;
return
base
+
(
groupIndex
*
10000
);
return
base
+
(
groupIndex
*
10000
);
}
}
...
@@ -466,16 +464,34 @@ static bool hasNullValue(SColIndex* pColIndex, SDataStatis *pStatis, SDataStatis
...
@@ -466,16 +464,34 @@ static bool hasNullValue(SColIndex* pColIndex, SDataStatis *pStatis, SDataStatis
static
SResultRow
*
doPrepareResultRowFromKey
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
char
*
pData
,
static
SResultRow
*
doPrepareResultRowFromKey
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
char
*
pData
,
int16_t
bytes
,
bool
masterscan
,
uint64_t
uid
)
{
int16_t
bytes
,
bool
masterscan
,
uint64_t
uid
)
{
bool
existed
=
false
;
SET_RES_WINDOW_KEY
(
pRuntimeEnv
->
keyBuf
,
pData
,
bytes
,
uid
);
SET_RES_WINDOW_KEY
(
pRuntimeEnv
->
keyBuf
,
pData
,
bytes
,
uid
);
int32_t
*
p1
=
(
int32_t
*
)
taosHashGet
(
pRuntimeEnv
->
pResultRowHashTable
,
pRuntimeEnv
->
keyBuf
,
GET_RES_WINDOW_KEY_LEN
(
bytes
));
SResultRow
**
p1
=
if
(
p1
!=
NULL
)
{
(
SResultRow
**
)
taosHashGet
(
pRuntimeEnv
->
pResultRowHashTable
,
pRuntimeEnv
->
keyBuf
,
GET_RES_WINDOW_KEY_LEN
(
bytes
));
pResultRowInfo
->
curIndex
=
*
p1
;
// in case of repeat scan/reverse scan, no new time window added.
if
(
QUERY_IS_INTERVAL_QUERY
(
pRuntimeEnv
->
pQuery
))
{
if
(
!
masterscan
)
{
// the *p1 may be NULL in case of sliding+offset exists.
return
(
p1
!=
NULL
)
?
*
p1
:
NULL
;
}
if
(
p1
!=
NULL
)
{
for
(
int32_t
i
=
pResultRowInfo
->
size
-
1
;
i
>=
0
;
--
i
)
{
if
(
pResultRowInfo
->
pResult
[
i
]
==
(
*
p1
))
{
pResultRowInfo
->
curIndex
=
i
;
existed
=
true
;
break
;
}
}
}
}
else
{
}
else
{
if
(
!
masterscan
)
{
// not master scan, do not add new timewindow
if
(
p1
!=
NULL
)
{
// group by column query
return
NULL
;
return
*
p1
;
}
}
}
if
(
!
existed
)
{
// TODO refactor
// TODO refactor
// more than the capacity, reallocate the resources
// more than the capacity, reallocate the resources
if
(
pResultRowInfo
->
size
>=
pResultRowInfo
->
capacity
)
{
if
(
pResultRowInfo
->
size
>=
pResultRowInfo
->
capacity
)
{
...
@@ -499,17 +515,23 @@ static SResultRow *doPrepareResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SRes
...
@@ -499,17 +515,23 @@ static SResultRow *doPrepareResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SRes
pResultRowInfo
->
capacity
=
(
int32_t
)
newCapacity
;
pResultRowInfo
->
capacity
=
(
int32_t
)
newCapacity
;
}
}
SResultRow
*
pResult
=
getNewResultRow
(
pRuntimeEnv
->
pool
);
SResultRow
*
pResult
=
NULL
;
pResultRowInfo
->
pResult
[
pResultRowInfo
->
size
]
=
pResult
;
int32_t
ret
=
initResultRow
(
pResult
);
if
(
p1
==
NULL
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
pResult
=
getNewResultRow
(
pRuntimeEnv
->
pool
);
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_OUT_OF_MEMORY
);
int32_t
ret
=
initResultRow
(
pResult
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
// add a new result set for a new group
taosHashPut
(
pRuntimeEnv
->
pResultRowHashTable
,
pRuntimeEnv
->
keyBuf
,
GET_RES_WINDOW_KEY_LEN
(
bytes
),
&
pResult
,
POINTER_BYTES
);
}
else
{
pResult
=
*
p1
;
}
}
// add a new result set for a new group
pResultRowInfo
->
pResult
[
pResultRowInfo
->
size
]
=
pResult
;
pResultRowInfo
->
curIndex
=
pResultRowInfo
->
size
++
;
pResultRowInfo
->
curIndex
=
pResultRowInfo
->
size
++
;
taosHashPut
(
pRuntimeEnv
->
pResultRowHashTable
,
pRuntimeEnv
->
keyBuf
,
GET_RES_WINDOW_KEY_LEN
(
bytes
),
(
char
*
)
&
pResultRowInfo
->
curIndex
,
sizeof
(
int32_t
));
}
}
// too many time window in query
// too many time window in query
...
@@ -591,7 +613,6 @@ static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedResultBuf
...
@@ -591,7 +613,6 @@ static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedResultBuf
if
(
pData
->
num
>=
numOfRowsPerPage
)
{
if
(
pData
->
num
>=
numOfRowsPerPage
)
{
// release current page first, and prepare the next one
// release current page first, and prepare the next one
releaseResBufPageInfo
(
pResultBuf
,
pi
);
releaseResBufPageInfo
(
pResultBuf
,
pi
);
pData
=
getNewDataBuf
(
pResultBuf
,
tid
,
&
pageId
);
pData
=
getNewDataBuf
(
pResultBuf
,
tid
,
&
pageId
);
if
(
pData
!=
NULL
)
{
if
(
pData
!=
NULL
)
{
assert
(
pData
->
num
==
0
);
// number of elements must be 0 for new allocated buffer
assert
(
pData
->
num
==
0
);
// number of elements must be 0 for new allocated buffer
...
@@ -614,24 +635,20 @@ static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedResultBuf
...
@@ -614,24 +635,20 @@ static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedResultBuf
return
0
;
return
0
;
}
}
static
int32_t
setWindowOutputBufByKey
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
S
DataBlockInfo
*
pBockInfo
,
static
int32_t
setWindowOutputBufByKey
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRowInfo
*
pResultRowInfo
,
S
TimeWindow
*
win
,
STimeWindow
*
win
,
bool
masterscan
,
bool
*
newWind
,
SResultRow
**
pResult
)
{
bool
masterscan
,
SResultRow
**
pResult
,
int64_t
groupId
)
{
assert
(
win
->
skey
<=
win
->
ekey
);
assert
(
win
->
skey
<=
win
->
ekey
);
SDiskbasedResultBuf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
SDiskbasedResultBuf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
// todo refactor
SResultRow
*
pResultRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
pResultRowInfo
,
(
char
*
)
&
win
->
skey
,
TSDB_KEYSIZE
,
masterscan
,
groupId
);
int64_t
uid
=
getResultInfoUId
(
pRuntimeEnv
);
SResultRow
*
pResultRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
pResultRowInfo
,
(
char
*
)
&
win
->
skey
,
TSDB_KEYSIZE
,
masterscan
,
uid
);
if
(
pResultRow
==
NULL
)
{
if
(
pResultRow
==
NULL
)
{
*
newWind
=
false
;
*
pResult
=
NULL
;
return
masterscan
?
-
1
:
0
;
// no master scan, no result generated means error occurs
return
TSDB_CODE_SUCCESS
;
}
}
*
newWind
=
true
;
// not assign result buffer yet, add new result buffer
// not assign result buffer yet, add new result buffer
if
(
pResultRow
->
pageId
==
-
1
)
{
if
(
pResultRow
->
pageId
==
-
1
)
{
int32_t
ret
=
addNewWindowResultBuf
(
pResultRow
,
pResultBuf
,
pBockInfo
->
ti
d
,
pRuntimeEnv
->
numOfRowsPerPage
);
int32_t
ret
=
addNewWindowResultBuf
(
pResultRow
,
pResultBuf
,
(
int32_t
)
groupI
d
,
pRuntimeEnv
->
numOfRowsPerPage
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
-
1
;
return
-
1
;
}
}
...
@@ -701,81 +718,47 @@ static FORCE_INLINE int32_t getForwardStepsInBlock(int32_t numOfRows, __block_se
...
@@ -701,81 +718,47 @@ static FORCE_INLINE int32_t getForwardStepsInBlock(int32_t numOfRows, __block_se
return
forwardStep
;
return
forwardStep
;
}
}
static
int32_t
updateResultRowCurrentIndex
(
SResultRowInfo
*
pWindowResInfo
,
TSKEY
lastKey
,
bool
ascQuery
)
{
static
void
doUpdateResultRowIndex
(
SResultRowInfo
*
pResultRowInfo
,
TSKEY
lastKey
,
bool
ascQuery
)
{
int32_t
i
=
0
;
int64_t
skey
=
TSKEY_INITIAL_VAL
;
int64_t
skey
=
TSKEY_INITIAL_VAL
;
int32_t
i
=
0
;
int32_t
numOfClosed
=
0
;
for
(
i
=
pResultRowInfo
->
size
-
1
;
i
>=
0
;
--
i
)
{
for
(
i
=
0
;
i
<
pWindowResInfo
->
size
;
++
i
)
{
SResultRow
*
pResult
=
pResultRowInfo
->
pResult
[
i
];
SResultRow
*
pResult
=
pWindowResInfo
->
pResult
[
i
];
if
(
pResult
->
closed
)
{
if
(
pResult
->
closed
)
{
numOfClosed
+=
1
;
break
;
continue
;
}
}
TSKEY
ekey
=
pResult
->
win
.
ekey
;
// new closed result rows
if
((
ekey
<=
lastKey
&&
ascQuery
)
||
(
pResult
->
win
.
skey
>=
lastKey
&&
!
ascQuery
))
{
if
((
pResult
->
win
.
ekey
<=
lastKey
&&
ascQuery
)
||
(
pResult
->
win
.
skey
>=
lastKey
&&
!
ascQuery
))
{
closeResultRow
(
p
WindowRes
Info
,
i
);
closeResultRow
(
p
ResultRow
Info
,
i
);
}
else
{
}
else
{
skey
=
pResult
->
win
.
skey
;
skey
=
pResult
->
win
.
skey
;
break
;
}
}
}
}
// all
wind
ows are closed, set the last one to be the skey
// all
result r
ows are closed, set the last one to be the skey
if
(
skey
==
TSKEY_INITIAL_VAL
)
{
if
(
skey
==
TSKEY_INITIAL_VAL
)
{
assert
(
i
==
pWindowResInfo
->
size
);
pResultRowInfo
->
curIndex
=
pResultRowInfo
->
size
-
1
;
pWindowResInfo
->
curIndex
=
pWindowResInfo
->
size
-
1
;
}
else
{
}
else
{
pWindowResInfo
->
curIndex
=
i
;
pWindowResInfo
->
prevSKey
=
pWindowResInfo
->
pResult
[
pWindowResInfo
->
curIndex
]
->
win
.
skey
;
}
return
numOfClosed
;
}
/**
* NOTE: the query status only set for the first scan of master scan.
*/
static
int32_t
doCheckQueryCompleted
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
TSKEY
lastKey
,
SResultRowInfo
*
pWindowResInfo
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
if
(
pRuntimeEnv
->
scanFlag
!=
MASTER_SCAN
||
pWindowResInfo
->
size
==
0
)
{
return
pWindowResInfo
->
size
;
}
// no qualified results exist, abort check
int32_t
numOfClosed
=
0
;
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pQuery
);
// query completed
if
((
lastKey
>=
pQuery
->
current
->
win
.
ekey
&&
ascQuery
)
||
(
lastKey
<=
pQuery
->
current
->
win
.
ekey
&&
(
!
ascQuery
)))
{
closeAllResultRows
(
pWindowResInfo
);
pWindowResInfo
->
curIndex
=
pWindowResInfo
->
size
-
1
;
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
|
QUERY_RESBUF_FULL
);
}
else
{
// set the current index to be the last unclosed window
numOfClosed
=
updateResultRowCurrentIndex
(
pWindowResInfo
,
lastKey
,
ascQuery
);
// the number of completed slots are larger than the threshold, return current generated results to client.
if
(
numOfClosed
>
pQuery
->
rec
.
threshold
)
{
qDebug
(
"QInfo:%p total result window:%d closed:%d, reached the output threshold %d, return"
,
GET_QINFO_ADDR
(
pRuntimeEnv
),
pWindowResInfo
->
size
,
numOfClosed
,
pQuery
->
rec
.
threshold
);
setQueryStatus
(
pQuery
,
QUERY_RESBUF_FULL
);
for
(
i
=
pResultRowInfo
->
size
-
1
;
i
>=
0
;
--
i
)
{
}
else
{
SResultRow
*
pResult
=
pResultRowInfo
->
pResult
[
i
];
qDebug
(
"QInfo:%p total result window:%d already closed:%d"
,
GET_QINFO_ADDR
(
pRuntimeEnv
),
pWindowResInfo
->
size
,
if
(
pResult
->
closed
)
{
numOfClosed
);
break
;
}
}
}
}
// output has reached the limitation, set query completed
pResultRowInfo
->
curIndex
=
i
+
1
;
// current not closed result object
if
(
pQuery
->
limit
.
limit
>
0
&&
(
pQuery
->
limit
.
limit
+
pQuery
->
limit
.
offset
)
<=
numOfClosed
&&
pResultRowInfo
->
prevSKey
=
pResultRowInfo
->
pResult
[
pResultRowInfo
->
curIndex
]
->
win
.
skey
;
pRuntimeEnv
->
scanFlag
==
MASTER_SCAN
)
{
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
}
}
}
assert
(
pWindowResInfo
->
prevSKey
!=
TSKEY_INITIAL_VAL
);
static
void
updateResultRowIndex
(
SResultRowInfo
*
pResultRowInfo
,
STableQueryInfo
*
pTableQueryInfo
,
bool
ascQuery
)
{
return
numOfClosed
;
if
((
pTableQueryInfo
->
lastKey
>=
pTableQueryInfo
->
win
.
ekey
&&
ascQuery
)
||
(
pTableQueryInfo
->
lastKey
<=
pTableQueryInfo
->
win
.
ekey
&&
(
!
ascQuery
)))
{
closeAllResultRows
(
pResultRowInfo
);
pResultRowInfo
->
curIndex
=
pResultRowInfo
->
size
-
1
;
}
else
{
doUpdateResultRowIndex
(
pResultRowInfo
,
pTableQueryInfo
->
lastKey
,
ascQuery
);
}
}
}
static
int32_t
getNumOfRowsInTimeWindow
(
SQuery
*
pQuery
,
SDataBlockInfo
*
pDataBlockInfo
,
TSKEY
*
pPrimaryColumn
,
static
int32_t
getNumOfRowsInTimeWindow
(
SQuery
*
pQuery
,
SDataBlockInfo
*
pDataBlockInfo
,
TSKEY
*
pPrimaryColumn
,
...
@@ -818,52 +801,47 @@ static int32_t getNumOfRowsInTimeWindow(SQuery *pQuery, SDataBlockInfo *pDataBlo
...
@@ -818,52 +801,47 @@ static int32_t getNumOfRowsInTimeWindow(SQuery *pQuery, SDataBlockInfo *pDataBlo
return
num
;
return
num
;
}
}
static
void
doBlockwiseApplyFunctions
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
bool
closed
,
STimeWindow
*
pWin
,
int32_t
offset
,
static
void
doBlockwiseApplyFunctions
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
STimeWindow
*
pWin
,
int32_t
offset
,
int32_t
forwardStep
,
TSKEY
*
tsCol
,
int32_t
numOfTotal
)
{
int32_t
forwardStep
,
TSKEY
*
tsCol
,
int32_t
numOfTotal
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQLFunctionCtx
*
pCtx
=
pRuntimeEnv
->
pCtx
;
SQLFunctionCtx
*
pCtx
=
pRuntimeEnv
->
pCtx
;
bool
hasPrev
=
pCtx
[
0
].
preAggVals
.
isSet
;
bool
hasPrev
=
pCtx
[
0
].
preAggVals
.
isSet
;
if
(
IS_MASTER_SCAN
(
pRuntimeEnv
)
||
closed
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutput
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutput
;
++
k
)
{
pCtx
[
k
].
nStartQueryTimestamp
=
pWin
->
skey
;
pCtx
[
k
].
nStartQueryTimestamp
=
pWin
->
skey
;
pCtx
[
k
].
size
=
forwardStep
;
pCtx
[
k
].
size
=
forwardStep
;
pCtx
[
k
].
startOffset
=
(
QUERY_IS_ASC_QUERY
(
pQuery
))
?
offset
:
offset
-
(
forwardStep
-
1
);
pCtx
[
k
].
startOffset
=
(
QUERY_IS_ASC_QUERY
(
pQuery
))
?
offset
:
offset
-
(
forwardStep
-
1
);
int32_t
functionId
=
pQuery
->
pExpr1
[
k
].
base
.
functionId
;
if
((
aAggs
[
functionId
].
nStatus
&
TSDB_FUNCSTATE_SELECTIVITY
)
!=
0
)
{
pCtx
[
k
].
ptsList
=
&
tsCol
[
pCtx
[
k
].
startOffset
];
}
// not a whole block involved in query processing, statistics data can not be used
int32_t
functionId
=
pQuery
->
pExpr1
[
k
].
base
.
functionId
;
// NOTE: the original value of isSet have been changed here
if
((
aAggs
[
functionId
].
nStatus
&
TSDB_FUNCSTATE_SELECTIVITY
)
!=
0
)
{
if
(
pCtx
[
k
].
preAggVals
.
isSet
&&
forwardStep
<
numOfTotal
)
{
pCtx
[
k
].
ptsList
=
&
tsCol
[
pCtx
[
k
].
startOffset
];
pCtx
[
k
].
preAggVals
.
isSet
=
false
;
}
}
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
],
functionId
))
{
// not a whole block involved in query processing, statistics data can not be used
aAggs
[
functionId
].
xFunction
(
&
pCtx
[
k
]);
// NOTE: the original value of isSet have been changed here
}
if
(
pCtx
[
k
].
preAggVals
.
isSet
&&
forwardStep
<
numOfTotal
)
{
pCtx
[
k
].
preAggVals
.
isSet
=
false
;
}
// restore it
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
],
functionId
))
{
pCtx
[
k
].
preAggVals
.
isSet
=
hasPrev
;
aAggs
[
functionId
].
xFunction
(
&
pCtx
[
k
])
;
}
}
// restore it
pCtx
[
k
].
preAggVals
.
isSet
=
hasPrev
;
}
}
}
}
static
void
doRowwiseApplyFunctions
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
bool
closed
,
STimeWindow
*
pWin
,
int32_t
offset
)
{
static
void
doRowwiseApplyFunctions
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
STimeWindow
*
pWin
,
int32_t
offset
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQLFunctionCtx
*
pCtx
=
pRuntimeEnv
->
pCtx
;
SQLFunctionCtx
*
pCtx
=
pRuntimeEnv
->
pCtx
;
if
(
IS_MASTER_SCAN
(
pRuntimeEnv
)
||
closed
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutput
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutput
;
++
k
)
{
pCtx
[
k
].
nStartQueryTimestamp
=
pWin
->
skey
;
pCtx
[
k
].
nStartQueryTimestamp
=
pWin
->
skey
;
int32_t
functionId
=
pQuery
->
pExpr1
[
k
].
base
.
functionId
;
int32_t
functionId
=
pQuery
->
pExpr1
[
k
].
base
.
functionId
;
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
],
functionId
))
{
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
],
functionId
))
{
aAggs
[
functionId
].
xFunctionF
(
&
pCtx
[
k
],
offset
);
aAggs
[
functionId
].
xFunctionF
(
&
pCtx
[
k
],
offset
);
}
}
}
}
}
}
}
...
@@ -1124,6 +1102,45 @@ static TSKEY getStartTsKey(SQuery* pQuery, SDataBlockInfo* pDataBlockInfo, TSKEY
...
@@ -1124,6 +1102,45 @@ static TSKEY getStartTsKey(SQuery* pQuery, SDataBlockInfo* pDataBlockInfo, TSKEY
return
ts
;
return
ts
;
}
}
static
void
doWindowBorderInterpolation
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SDataBlockInfo
*
pDataBlockInfo
,
SArray
*
pDataBlock
,
SResultRow
*
pResult
,
STimeWindow
*
win
,
int32_t
startPos
,
int32_t
forwardStep
)
{
if
(
!
pRuntimeEnv
->
timeWindowInterpo
)
{
return
;
}
assert
(
pDataBlock
!=
NULL
);
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pQuery
->
order
.
order
);
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pDataBlock
,
0
);
TSKEY
*
tsCols
=
(
TSKEY
*
)(
pColInfo
->
pData
);
bool
done
=
resultRowInterpolated
(
pResult
,
RESULT_ROW_START_INTERP
);
if
(
!
done
)
{
int32_t
startRowIndex
=
startPos
;
bool
interp
=
setTimeWindowInterpolationStartTs
(
pRuntimeEnv
,
startRowIndex
,
pDataBlockInfo
->
rows
,
pDataBlock
,
tsCols
,
win
);
if
(
interp
)
{
setResultRowInterpo
(
pResult
,
RESULT_ROW_START_INTERP
);
}
}
else
{
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfOutput
,
RESULT_ROW_START_INTERP
);
}
done
=
resultRowInterpolated
(
pResult
,
RESULT_ROW_END_INTERP
);
if
(
!
done
)
{
int32_t
endRowIndex
=
startPos
+
(
forwardStep
-
1
)
*
step
;
TSKEY
endKey
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
pDataBlockInfo
->
window
.
ekey
:
pDataBlockInfo
->
window
.
skey
;
bool
interp
=
setTimeWindowInterpolationEndTs
(
pRuntimeEnv
,
endRowIndex
,
pDataBlock
,
tsCols
,
endKey
,
win
);
if
(
interp
)
{
setResultRowInterpo
(
pResult
,
RESULT_ROW_END_INTERP
);
}
}
else
{
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfOutput
,
RESULT_ROW_END_INTERP
);
}
}
/**
/**
* todo set the last value for pQueryTableInfo as in rowwiseapplyfunctions
* todo set the last value for pQueryTableInfo as in rowwiseapplyfunctions
* @param pRuntimeEnv
* @param pRuntimeEnv
...
@@ -1139,7 +1156,9 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
...
@@ -1139,7 +1156,9 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
SQLFunctionCtx
*
pCtx
=
pRuntimeEnv
->
pCtx
;
SQLFunctionCtx
*
pCtx
=
pRuntimeEnv
->
pCtx
;
bool
masterScan
=
IS_MASTER_SCAN
(
pRuntimeEnv
);
bool
masterScan
=
IS_MASTER_SCAN
(
pRuntimeEnv
);
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
int64_t
groupId
=
pQuery
->
current
->
groupIndex
;
TSKEY
*
tsCols
=
NULL
;
TSKEY
*
tsCols
=
NULL
;
if
(
pDataBlock
!=
NULL
)
{
if
(
pDataBlock
!=
NULL
)
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pDataBlock
,
0
);
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pDataBlock
,
0
);
...
@@ -1164,80 +1183,46 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
...
@@ -1164,80 +1183,46 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
TSKEY
ts
=
getStartTsKey
(
pQuery
,
pDataBlockInfo
,
tsCols
,
step
);
TSKEY
ts
=
getStartTsKey
(
pQuery
,
pDataBlockInfo
,
tsCols
,
step
);
STimeWindow
win
=
getActiveTimeWindow
(
pWindowResInfo
,
ts
,
pQuery
);
STimeWindow
win
=
getActiveTimeWindow
(
pWindowResInfo
,
ts
,
pQuery
);
bool
hasTimeWindow
=
false
;
SResultRow
*
pResult
=
NULL
;
SResultRow
*
pResult
=
NULL
;
int32_t
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
win
,
masterScan
,
&
hasTimeWindow
,
&
pResult
);
int32_t
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
&
win
,
masterScan
,
&
pResult
,
groupId
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
||
pResult
==
NULL
)
{
tfree
(
sasArray
);
goto
_end
;
return
;
}
}
int32_t
forwardStep
=
0
;
int32_t
forwardStep
=
0
;
int32_t
startPos
=
pQuery
->
pos
;
int32_t
startPos
=
pQuery
->
pos
;
// in case of repeat scan/reverse scan, no new time window added.
TSKEY
ekey
=
reviseWindowEkey
(
pQuery
,
&
win
);
if
(
hasTimeWindow
)
{
forwardStep
=
getNumOfRowsInTimeWindow
(
pQuery
,
pDataBlockInfo
,
tsCols
,
pQuery
->
pos
,
ekey
,
searchFn
,
true
);
TSKEY
ekey
=
reviseWindowEkey
(
pQuery
,
&
win
);
forwardStep
=
getNumOfRowsInTimeWindow
(
pQuery
,
pDataBlockInfo
,
tsCols
,
pQuery
->
pos
,
ekey
,
searchFn
,
true
);
// prev time window not interpolation yet.
// prev time window not interpolation yet.
int32_t
curIndex
=
curTimeWindowIndex
(
pWindowResInfo
);
int32_t
curIndex
=
curTimeWindowIndex
(
pWindowResInfo
);
if
(
prevIndex
!=
-
1
&&
prevIndex
<
curIndex
&&
pRuntimeEnv
->
timeWindowInterpo
)
{
if
(
prevIndex
!=
-
1
&&
prevIndex
<
curIndex
&&
pRuntimeEnv
->
timeWindowInterpo
)
{
for
(
int32_t
j
=
prevIndex
;
j
<
curIndex
;
++
j
)
{
for
(
int32_t
j
=
prevIndex
;
j
<
curIndex
;
++
j
)
{
SResultRow
*
pRes
=
pWindowResInfo
->
pResult
[
j
];
SResultRow
*
pRes
=
pWindowResInfo
->
pResult
[
j
];
STimeWindow
w
=
pRes
->
win
;
STimeWindow
w
=
pRes
->
win
;
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
w
,
masterScan
,
&
hasTimeWindow
,
&
pResult
);
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
&
w
,
masterScan
,
&
pResult
,
groupId
);
assert
(
ret
==
TSDB_CODE_SUCCESS
&&
!
resultRowInterpolated
(
pResult
,
RESULT_ROW_END_INTERP
));
assert
(
ret
==
TSDB_CODE_SUCCESS
&&
!
resultRowInterpolated
(
pResult
,
RESULT_ROW_END_INTERP
));
int32_t
p
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
0
:
pDataBlockInfo
->
rows
-
1
;
int32_t
p
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
0
:
pDataBlockInfo
->
rows
-
1
;
doRowwiseTimeWindowInterpolation
(
pRuntimeEnv
,
pDataBlock
,
*
(
TSKEY
*
)
pRuntimeEnv
->
prevRow
[
0
],
-
1
,
tsCols
[
0
],
p
,
w
.
ekey
,
RESULT_ROW_END_INTERP
);
doRowwiseTimeWindowInterpolation
(
pRuntimeEnv
,
pDataBlock
,
*
(
TSKEY
*
)
pRuntimeEnv
->
prevRow
[
0
],
-
1
,
tsCols
[
0
],
p
,
w
.
ekey
,
RESULT_ROW_END_INTERP
);
setResultRowInterpo
(
pResult
,
RESULT_ROW_END_INTERP
);
setResultRowInterpo
(
pResult
,
RESULT_ROW_END_INTERP
);
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfOutput
,
RESULT_ROW_START_INTERP
);
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfOutput
,
RESULT_ROW_START_INTERP
);
bool
closed
=
getResultRowStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
doBlockwiseApplyFunctions
(
pRuntimeEnv
,
&
w
,
startPos
,
0
,
tsCols
,
pDataBlockInfo
->
rows
);
doBlockwiseApplyFunctions
(
pRuntimeEnv
,
closed
,
&
w
,
startPos
,
0
,
tsCols
,
pDataBlockInfo
->
rows
);
}
// restore current time window
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
win
,
masterScan
,
&
hasTimeWindow
,
&
pResult
);
assert
(
ret
==
TSDB_CODE_SUCCESS
);
// null data, too many state code
}
}
// window start key interpolation
// restore current time window
if
(
pRuntimeEnv
->
timeWindowInterpo
)
{
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
&
win
,
masterScan
,
&
pResult
,
groupId
);
bool
done
=
resultRowInterpolated
(
pResult
,
RESULT_ROW_START_INTERP
);
assert
(
ret
==
TSDB_CODE_SUCCESS
);
if
(
!
done
)
{
int32_t
startRowIndex
=
pQuery
->
pos
;
bool
interp
=
setTimeWindowInterpolationStartTs
(
pRuntimeEnv
,
startRowIndex
,
pDataBlockInfo
->
rows
,
pDataBlock
,
tsCols
,
&
win
);
if
(
interp
)
{
setResultRowInterpo
(
pResult
,
RESULT_ROW_START_INTERP
);
}
}
else
{
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfOutput
,
RESULT_ROW_START_INTERP
);
}
done
=
resultRowInterpolated
(
pResult
,
RESULT_ROW_END_INTERP
);
if
(
!
done
)
{
int32_t
endRowIndex
=
pQuery
->
pos
+
(
forwardStep
-
1
)
*
step
;
TSKEY
endKey
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
pDataBlockInfo
->
window
.
ekey
:
pDataBlockInfo
->
window
.
skey
;
bool
interp
=
setTimeWindowInterpolationEndTs
(
pRuntimeEnv
,
endRowIndex
,
pDataBlock
,
tsCols
,
endKey
,
&
win
);
if
(
interp
)
{
setResultRowInterpo
(
pResult
,
RESULT_ROW_END_INTERP
);
}
}
else
{
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfOutput
,
RESULT_ROW_END_INTERP
);
}
}
bool
pStatus
=
getResultRowStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
doBlockwiseApplyFunctions
(
pRuntimeEnv
,
pStatus
,
&
win
,
startPos
,
forwardStep
,
tsCols
,
pDataBlockInfo
->
rows
);
}
}
int32_t
index
=
pWindowResInfo
->
curIndex
;
// window start key interpolation
STimeWindow
nextWin
=
win
;
doWindowBorderInterpolation
(
pRuntimeEnv
,
pDataBlockInfo
,
pDataBlock
,
pResult
,
&
win
,
pQuery
->
pos
,
forwardStep
);
doBlockwiseApplyFunctions
(
pRuntimeEnv
,
&
win
,
startPos
,
forwardStep
,
tsCols
,
pDataBlockInfo
->
rows
);
STimeWindow
nextWin
=
win
;
while
(
1
)
{
while
(
1
)
{
int32_t
prevEndPos
=
(
forwardStep
-
1
)
*
step
+
startPos
;
int32_t
prevEndPos
=
(
forwardStep
-
1
)
*
step
+
startPos
;
startPos
=
getNextQualifiedWindow
(
pRuntimeEnv
,
&
nextWin
,
pDataBlockInfo
,
tsCols
,
searchFn
,
prevEndPos
);
startPos
=
getNextQualifiedWindow
(
pRuntimeEnv
,
&
nextWin
,
pDataBlockInfo
,
tsCols
,
searchFn
,
prevEndPos
);
...
@@ -1246,50 +1231,19 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
...
@@ -1246,50 +1231,19 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
}
}
// null data, failed to allocate more memory buffer
// null data, failed to allocate more memory buffer
hasTimeWindow
=
false
;
int32_t
code
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
&
nextWin
,
masterScan
,
&
pResult
,
groupId
);
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
nextWin
,
masterScan
,
&
hasTimeWindow
,
&
pResult
)
!=
if
(
code
!=
TSDB_CODE_SUCCESS
||
pResult
==
NULL
)
{
TSDB_CODE_SUCCESS
)
{
break
;
break
;
}
}
if
(
!
hasTimeWindow
)
{
ekey
=
reviseWindowEkey
(
pQuery
,
&
nextWin
);
continue
;
}
TSKEY
ekey
=
reviseWindowEkey
(
pQuery
,
&
nextWin
);
forwardStep
=
getNumOfRowsInTimeWindow
(
pQuery
,
pDataBlockInfo
,
tsCols
,
startPos
,
ekey
,
searchFn
,
true
);
forwardStep
=
getNumOfRowsInTimeWindow
(
pQuery
,
pDataBlockInfo
,
tsCols
,
startPos
,
ekey
,
searchFn
,
true
);
// window start(end) key interpolation
// window start(end) key interpolation
if
(
pRuntimeEnv
->
timeWindowInterpo
)
{
doWindowBorderInterpolation
(
pRuntimeEnv
,
pDataBlockInfo
,
pDataBlock
,
pResult
,
&
nextWin
,
startPos
,
forwardStep
);
bool
done
=
resultRowInterpolated
(
pResult
,
RESULT_ROW_START_INTERP
);
doBlockwiseApplyFunctions
(
pRuntimeEnv
,
&
nextWin
,
startPos
,
forwardStep
,
tsCols
,
pDataBlockInfo
->
rows
);
if
(
!
done
)
{
int32_t
startRowIndex
=
startPos
;
bool
interp
=
setTimeWindowInterpolationStartTs
(
pRuntimeEnv
,
startRowIndex
,
pDataBlockInfo
->
rows
,
pDataBlock
,
tsCols
,
&
nextWin
);
if
(
interp
)
{
setResultRowInterpo
(
pResult
,
RESULT_ROW_START_INTERP
);
}
}
else
{
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfOutput
,
RESULT_ROW_START_INTERP
);
}
done
=
resultRowInterpolated
(
pResult
,
RESULT_ROW_END_INTERP
);
if
(
!
done
)
{
int32_t
endRowIndex
=
startPos
+
(
forwardStep
-
1
)
*
step
;
TSKEY
endKey
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
pDataBlockInfo
->
window
.
ekey
:
pDataBlockInfo
->
window
.
skey
;
bool
interp
=
setTimeWindowInterpolationEndTs
(
pRuntimeEnv
,
endRowIndex
,
pDataBlock
,
tsCols
,
endKey
,
&
nextWin
);
if
(
interp
)
{
setResultRowInterpo
(
pResult
,
RESULT_ROW_END_INTERP
);
}
}
else
{
setNotInterpoWindowKey
(
pRuntimeEnv
->
pCtx
,
pQuery
->
numOfOutput
,
RESULT_ROW_END_INTERP
);
}
}
bool
closed
=
getResultRowStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
doBlockwiseApplyFunctions
(
pRuntimeEnv
,
closed
,
&
nextWin
,
startPos
,
forwardStep
,
tsCols
,
pDataBlockInfo
->
rows
);
}
}
pWindowResInfo
->
curIndex
=
index
;
}
else
{
}
else
{
/*
/*
* the sqlfunctionCtx parameters should be set done before all functions are invoked,
* the sqlfunctionCtx parameters should be set done before all functions are invoked,
...
@@ -1305,6 +1259,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
...
@@ -1305,6 +1259,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
}
}
}
}
_end:
if
(
pRuntimeEnv
->
timeWindowInterpo
)
{
if
(
pRuntimeEnv
->
timeWindowInterpo
)
{
saveDataBlockLastRow
(
pRuntimeEnv
,
pDataBlockInfo
,
pDataBlock
);
saveDataBlockLastRow
(
pRuntimeEnv
,
pDataBlockInfo
,
pDataBlock
);
}
}
...
@@ -1325,8 +1280,6 @@ static int32_t setGroupResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, char *pDat
...
@@ -1325,8 +1280,6 @@ static int32_t setGroupResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, char *pDat
return
-
1
;
return
-
1
;
}
}
int32_t
GROUPRESULTID
=
1
;
SDiskbasedResultBuf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
SDiskbasedResultBuf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
// not assign result buffer yet, add new result buffer, TODO remove it
// not assign result buffer yet, add new result buffer, TODO remove it
...
@@ -1342,11 +1295,8 @@ static int32_t setGroupResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, char *pDat
...
@@ -1342,11 +1295,8 @@ static int32_t setGroupResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, char *pDat
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_APP_ERROR
);
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_APP_ERROR
);
}
}
uint64_t
uid
=
groupIndex
;
SResultRow
*
pResultRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
&
pRuntimeEnv
->
windowResInfo
,
d
,
len
,
true
,
groupIndex
);
SResultRow
*
pResultRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
&
pRuntimeEnv
->
windowResInfo
,
d
,
len
,
true
,
uid
);
assert
(
pResultRow
!=
NULL
);
if
(
pResultRow
==
NULL
)
{
return
-
1
;
}
int64_t
v
=
-
1
;
int64_t
v
=
-
1
;
GET_TYPED_DATA
(
v
,
int64_t
,
type
,
pData
);
GET_TYPED_DATA
(
v
,
int64_t
,
type
,
pData
);
...
@@ -1363,7 +1313,7 @@ static int32_t setGroupResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, char *pDat
...
@@ -1363,7 +1313,7 @@ static int32_t setGroupResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, char *pDat
}
}
if
(
pResultRow
->
pageId
==
-
1
)
{
if
(
pResultRow
->
pageId
==
-
1
)
{
int32_t
ret
=
addNewWindowResultBuf
(
pResultRow
,
pResultBuf
,
GROUPRESULTID
,
pRuntimeEnv
->
numOfRowsPerPage
);
int32_t
ret
=
addNewWindowResultBuf
(
pResultRow
,
pResultBuf
,
groupIndex
,
pRuntimeEnv
->
numOfRowsPerPage
);
if
(
ret
!=
0
)
{
if
(
ret
!=
0
)
{
return
-
1
;
return
-
1
;
}
}
...
@@ -1498,7 +1448,7 @@ void doRowwiseTimeWindowInterpolation(SQueryRuntimeEnv* pRuntimeEnv, SArray* pDa
...
@@ -1498,7 +1448,7 @@ void doRowwiseTimeWindowInterpolation(SQueryRuntimeEnv* pRuntimeEnv, SArray* pDa
double
v1
=
0
,
v2
=
0
,
v
=
0
;
double
v1
=
0
,
v2
=
0
,
v
=
0
;
if
(
prevRowIndex
==
-
1
)
{
if
(
prevRowIndex
==
-
1
)
{
GET_TYPED_DATA
(
v1
,
double
,
pColInfo
->
info
.
type
,
(
char
*
)
pRuntimeEnv
->
prevRow
[
k
]);
GET_TYPED_DATA
(
v1
,
double
,
pColInfo
->
info
.
type
,
(
char
*
)
pRuntimeEnv
->
prevRow
[
index
]);
}
else
{
}
else
{
GET_TYPED_DATA
(
v1
,
double
,
pColInfo
->
info
.
type
,
(
char
*
)
pColInfo
->
pData
+
prevRowIndex
*
pColInfo
->
info
.
bytes
);
GET_TYPED_DATA
(
v1
,
double
,
pColInfo
->
info
.
type
,
(
char
*
)
pColInfo
->
pData
+
prevRowIndex
*
pColInfo
->
info
.
bytes
);
}
}
...
@@ -1565,6 +1515,8 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
...
@@ -1565,6 +1515,8 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
STableQueryInfo
*
item
=
pQuery
->
current
;
STableQueryInfo
*
item
=
pQuery
->
current
;
int64_t
groupId
=
item
->
groupIndex
;
SColumnInfoData
*
pColumnInfoData
=
(
SColumnInfoData
*
)
taosArrayGet
(
pDataBlock
,
0
);
SColumnInfoData
*
pColumnInfoData
=
(
SColumnInfoData
*
)
taosArrayGet
(
pDataBlock
,
0
);
TSKEY
*
tsCols
=
(
pColumnInfoData
->
info
.
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
?
(
TSKEY
*
)
pColumnInfoData
->
pData
:
NULL
;
TSKEY
*
tsCols
=
(
pColumnInfoData
->
info
.
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
?
(
TSKEY
*
)
pColumnInfoData
->
pData
:
NULL
;
...
@@ -1635,15 +1587,10 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
...
@@ -1635,15 +1587,10 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
STimeWindow
win
=
getActiveTimeWindow
(
pWindowResInfo
,
ts
,
pQuery
);
STimeWindow
win
=
getActiveTimeWindow
(
pWindowResInfo
,
ts
,
pQuery
);
bool
hasTimeWindow
=
false
;
SResultRow
*
pResult
=
NULL
;
SResultRow
*
pResult
=
NULL
;
int32_t
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
win
,
masterScan
,
&
hasTimeWindow
,
&
pResult
);
int32_t
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
&
win
,
masterScan
,
&
pResult
,
groupId
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
// null data, too many state code
if
(
ret
!=
TSDB_CODE_SUCCESS
||
pResult
==
NULL
)
{
// null data, too many state code
continue
;
goto
_end
;
}
if
(
!
hasTimeWindow
)
{
continue
;
}
}
// window start key interpolation
// window start key interpolation
...
@@ -1654,18 +1601,15 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
...
@@ -1654,18 +1601,15 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
for
(
int32_t
k
=
prevWindowIndex
;
k
<
curIndex
;
++
k
)
{
for
(
int32_t
k
=
prevWindowIndex
;
k
<
curIndex
;
++
k
)
{
SResultRow
*
pRes
=
pWindowResInfo
->
pResult
[
k
];
SResultRow
*
pRes
=
pWindowResInfo
->
pResult
[
k
];
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
pRes
->
win
,
masterScan
,
&
hasTimeWindow
,
&
pResult
);
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
&
pRes
->
win
,
masterScan
,
&
pResult
,
groupId
);
assert
(
ret
==
TSDB_CODE_SUCCESS
&&
!
resultRowInterpolated
(
pResult
,
RESULT_ROW_END_INTERP
));
assert
(
ret
==
TSDB_CODE_SUCCESS
&&
!
resultRowInterpolated
(
pResult
,
RESULT_ROW_END_INTERP
));
setTimeWindowEKeyInterp
(
pRuntimeEnv
,
pDataBlock
,
prevTs
,
prevRowIndex
,
ts
,
offset
,
pResult
,
&
pRes
->
win
);
setTimeWindowEKeyInterp
(
pRuntimeEnv
,
pDataBlock
,
prevTs
,
prevRowIndex
,
ts
,
offset
,
pResult
,
&
pRes
->
win
);
doRowwiseApplyFunctions
(
pRuntimeEnv
,
&
pRes
->
win
,
offset
);
bool
closed
=
getResultRowStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
doRowwiseApplyFunctions
(
pRuntimeEnv
,
closed
,
&
pRes
->
win
,
offset
);
}
}
// restore current time window
// restore current time window
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
win
,
masterScan
,
&
hasTimeWindow
,
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
&
win
,
masterScan
,
&
pResult
,
groupId
);
&
pResult
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
// null data, too many state code
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
// null data, too many state code
continue
;
continue
;
}
}
...
@@ -1674,8 +1618,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
...
@@ -1674,8 +1618,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
setTimeWindowSKeyInterp
(
pRuntimeEnv
,
pDataBlock
,
prevTs
,
prevRowIndex
,
ts
,
offset
,
pResult
,
&
win
);
setTimeWindowSKeyInterp
(
pRuntimeEnv
,
pDataBlock
,
prevTs
,
prevRowIndex
,
ts
,
offset
,
pResult
,
&
win
);
}
}
bool
closed
=
getResultRowStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
doRowwiseApplyFunctions
(
pRuntimeEnv
,
&
win
,
offset
);
doRowwiseApplyFunctions
(
pRuntimeEnv
,
closed
,
&
win
,
offset
);
STimeWindow
nextWin
=
win
;
STimeWindow
nextWin
=
win
;
int32_t
index
=
pWindowResInfo
->
curIndex
;
int32_t
index
=
pWindowResInfo
->
curIndex
;
...
@@ -1692,16 +1635,13 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
...
@@ -1692,16 +1635,13 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
}
}
// null data, failed to allocate more memory buffer
// null data, failed to allocate more memory buffer
hasTimeWindow
=
false
;
int32_t
code
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
&
nextWin
,
masterScan
,
&
pResult
,
groupId
)
;
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
nextWin
,
masterScan
,
&
hasTimeWindow
,
&
pResult
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
||
pResult
==
NULL
)
{
break
;
break
;
}
}
if
(
hasTimeWindow
)
{
setTimeWindowSKeyInterp
(
pRuntimeEnv
,
pDataBlock
,
prevTs
,
prevRowIndex
,
ts
,
offset
,
pResult
,
&
nextWin
);
setTimeWindowSKeyInterp
(
pRuntimeEnv
,
pDataBlock
,
prevTs
,
prevRowIndex
,
ts
,
offset
,
pResult
,
&
nextWin
);
doRowwiseApplyFunctions
(
pRuntimeEnv
,
&
nextWin
,
offset
);
closed
=
getResultRowStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
doRowwiseApplyFunctions
(
pRuntimeEnv
,
closed
,
&
nextWin
,
offset
);
}
}
}
pWindowResInfo
->
curIndex
=
index
;
pWindowResInfo
->
curIndex
=
index
;
...
@@ -1736,6 +1676,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
...
@@ -1736,6 +1676,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
}
}
}
}
_end:
assert
(
offset
>=
0
);
assert
(
offset
>=
0
);
if
(
tsCols
!=
NULL
)
{
if
(
tsCols
!=
NULL
)
{
item
->
lastKey
=
tsCols
[
offset
]
+
step
;
item
->
lastKey
=
tsCols
[
offset
]
+
step
;
...
@@ -1763,28 +1704,26 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBl
...
@@ -1763,28 +1704,26 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBl
SDataStatis
*
pStatis
,
__block_search_fn_t
searchFn
,
SArray
*
pDataBlock
)
{
SDataStatis
*
pStatis
,
__block_search_fn_t
searchFn
,
SArray
*
pDataBlock
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
STableQueryInfo
*
pTableQInfo
=
pQuery
->
current
;
STableQueryInfo
*
pTableQ
uery
Info
=
pQuery
->
current
;
SResultRowInfo
*
p
WindowRes
Info
=
&
pRuntimeEnv
->
windowResInfo
;
SResultRowInfo
*
p
ResultRow
Info
=
&
pRuntimeEnv
->
windowResInfo
;
if
(
pQuery
->
numOfFilterCols
>
0
||
pRuntimeEnv
->
pTsBuf
!=
NULL
||
pRuntimeEnv
->
groupbyNormalCol
)
{
if
(
pQuery
->
numOfFilterCols
>
0
||
pRuntimeEnv
->
pTsBuf
!=
NULL
||
pRuntimeEnv
->
groupbyNormalCol
)
{
rowwiseApplyFunctions
(
pRuntimeEnv
,
pStatis
,
pDataBlockInfo
,
p
WindowRes
Info
,
pDataBlock
);
rowwiseApplyFunctions
(
pRuntimeEnv
,
pStatis
,
pDataBlockInfo
,
p
ResultRow
Info
,
pDataBlock
);
}
else
{
}
else
{
blockwiseApplyFunctions
(
pRuntimeEnv
,
pStatis
,
pDataBlockInfo
,
p
WindowRes
Info
,
searchFn
,
pDataBlock
);
blockwiseApplyFunctions
(
pRuntimeEnv
,
pStatis
,
pDataBlockInfo
,
p
ResultRow
Info
,
searchFn
,
pDataBlock
);
}
}
// update the lastkey of current table
// update the lastkey of current table
TSKEY
lastKey
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
pDataBlockInfo
->
window
.
ekey
:
pDataBlockInfo
->
window
.
skey
;
TSKEY
lastKey
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
pDataBlockInfo
->
window
.
ekey
:
pDataBlockInfo
->
window
.
skey
;
pTableQInfo
->
lastKey
=
lastKey
+
GET_FORWARD_DIRECTION_FACTOR
(
pQuery
->
order
.
order
);
pTableQ
uery
Info
->
lastKey
=
lastKey
+
GET_FORWARD_DIRECTION_FACTOR
(
pQuery
->
order
.
order
);
// interval query with limit applied
// interval query with limit applied
int32_t
numOfRes
=
0
;
int32_t
numOfRes
=
0
;
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
))
{
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
)
||
pRuntimeEnv
->
groupbyNormalCol
)
{
numOfRes
=
doCheckQueryCompleted
(
pRuntimeEnv
,
lastKey
,
pWindowResInfo
);
numOfRes
=
pResultRowInfo
->
size
;
}
else
if
(
pRuntimeEnv
->
groupbyNormalCol
)
{
updateResultRowIndex
(
pResultRowInfo
,
pTableQueryInfo
,
QUERY_IS_ASC_QUERY
(
pQuery
));
closeAllResultRows
(
pWindowResInfo
);
numOfRes
=
pWindowResInfo
->
size
;
}
else
{
// projection query
}
else
{
// projection query
numOfRes
=
(
int32_t
)
getNumOfResult
(
pRuntimeEnv
);
numOfRes
=
(
int32_t
)
getNumOfResult
(
pRuntimeEnv
);
// update the number of output result
// update the number of output result
if
(
numOfRes
>
0
&&
pQuery
->
checkBuffer
==
1
)
{
if
(
numOfRes
>
0
&&
pQuery
->
checkBuffer
==
1
)
{
...
@@ -1799,8 +1738,8 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBl
...
@@ -1799,8 +1738,8 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBl
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
}
}
if
(((
pTableQ
Info
->
lastKey
>
pTableQ
Info
->
win
.
ekey
)
&&
QUERY_IS_ASC_QUERY
(
pQuery
))
||
if
(((
pTableQ
ueryInfo
->
lastKey
>
pTableQuery
Info
->
win
.
ekey
)
&&
QUERY_IS_ASC_QUERY
(
pQuery
))
||
((
pTableQ
Info
->
lastKey
<
pTableQ
Info
->
win
.
ekey
)
&&
(
!
QUERY_IS_ASC_QUERY
(
pQuery
))))
{
((
pTableQ
ueryInfo
->
lastKey
<
pTableQuery
Info
->
win
.
ekey
)
&&
(
!
QUERY_IS_ASC_QUERY
(
pQuery
))))
{
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
}
}
}
}
...
@@ -2182,8 +2121,8 @@ static bool isFixedOutputQuery(SQueryRuntimeEnv* pRuntimeEnv) {
...
@@ -2182,8 +2121,8 @@ static bool isFixedOutputQuery(SQueryRuntimeEnv* pRuntimeEnv) {
// todo refactor with isLastRowQuery
// todo refactor with isLastRowQuery
bool
isPointInterpoQuery
(
SQuery
*
pQuery
)
{
bool
isPointInterpoQuery
(
SQuery
*
pQuery
)
{
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
int32_t
functionI
D
=
pQuery
->
pExpr1
[
i
].
base
.
functionId
;
int32_t
functionI
d
=
pQuery
->
pExpr1
[
i
].
base
.
functionId
;
if
(
functionI
D
==
TSDB_FUNC_INTERP
)
{
if
(
functionI
d
==
TSDB_FUNC_INTERP
)
{
return
true
;
return
true
;
}
}
}
}
...
@@ -2618,6 +2557,8 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo * pW
...
@@ -2618,6 +2557,8 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo * pW
*
status
=
BLK_DATA_NO_NEEDED
;
*
status
=
BLK_DATA_NO_NEEDED
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
int64_t
groupId
=
pQuery
->
current
->
groupIndex
;
SQueryCostInfo
*
pCost
=
&
pRuntimeEnv
->
summary
;
SQueryCostInfo
*
pCost
=
&
pRuntimeEnv
->
summary
;
if
(
pQuery
->
numOfFilterCols
>
0
||
pRuntimeEnv
->
pTsBuf
>
0
)
{
if
(
pQuery
->
numOfFilterCols
>
0
||
pRuntimeEnv
->
pTsBuf
>
0
)
{
...
@@ -2634,15 +2575,13 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo * pW
...
@@ -2634,15 +2575,13 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo * pW
// the pCtx[i] result is belonged to previous time window since the outputBuf has not been set yet,
// the pCtx[i] result is belonged to previous time window since the outputBuf has not been set yet,
// the filter result may be incorrect. So in case of interval query, we need to set the correct time output buffer
// the filter result may be incorrect. So in case of interval query, we need to set the correct time output buffer
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
))
{
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
))
{
bool
hasTimeWindow
=
false
;
SResultRow
*
pResult
=
NULL
;
SResultRow
*
pResult
=
NULL
;
bool
masterScan
=
IS_MASTER_SCAN
(
pRuntimeEnv
);
bool
masterScan
=
IS_MASTER_SCAN
(
pRuntimeEnv
);
TSKEY
k
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
pBlockInfo
->
window
.
skey
:
pBlockInfo
->
window
.
ekey
;
TSKEY
k
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
pBlockInfo
->
window
.
skey
:
pBlockInfo
->
window
.
ekey
;
STimeWindow
win
=
getActiveTimeWindow
(
pWindowResInfo
,
k
,
pQuery
);
STimeWindow
win
=
getActiveTimeWindow
(
pWindowResInfo
,
k
,
pQuery
);
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pBlockInfo
,
&
win
,
masterScan
,
&
hasTimeWindow
,
&
pResult
)
!=
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
&
win
,
masterScan
,
&
pResult
,
groupId
)
!=
TSDB_CODE_SUCCESS
)
{
TSDB_CODE_SUCCESS
)
{
// todo handle error in set result for timewindow
// todo handle error in set result for timewindow
}
}
}
}
...
@@ -2840,13 +2779,9 @@ static void doSetInitialTimewindow(SQueryRuntimeEnv* pRuntimeEnv, SDataBlockInfo
...
@@ -2840,13 +2779,9 @@ static void doSetInitialTimewindow(SQueryRuntimeEnv* pRuntimeEnv, SDataBlockInfo
if
(
QUERY_IS_ASC_QUERY
(
pQuery
))
{
if
(
QUERY_IS_ASC_QUERY
(
pQuery
))
{
getAlignQueryTimeWindow
(
pQuery
,
pBlockInfo
->
window
.
skey
,
pBlockInfo
->
window
.
skey
,
pQuery
->
window
.
ekey
,
&
w
);
getAlignQueryTimeWindow
(
pQuery
,
pBlockInfo
->
window
.
skey
,
pBlockInfo
->
window
.
skey
,
pQuery
->
window
.
ekey
,
&
w
);
pWindowResInfo
->
startTime
=
w
.
skey
;
pWindowResInfo
->
prevSKey
=
w
.
skey
;
pWindowResInfo
->
prevSKey
=
w
.
skey
;
}
else
{
}
else
{
// the start position of the first time window in the endpoint that spreads beyond the queried last timestamp
// the start position of the first time window in the endpoint that spreads beyond the queried last timestamp
getAlignQueryTimeWindow
(
pQuery
,
pBlockInfo
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pBlockInfo
->
window
.
ekey
,
&
w
);
getAlignQueryTimeWindow
(
pQuery
,
pBlockInfo
->
window
.
ekey
,
pQuery
->
window
.
ekey
,
pBlockInfo
->
window
.
ekey
,
&
w
);
pWindowResInfo
->
startTime
=
pQuery
->
window
.
skey
;
pWindowResInfo
->
prevSKey
=
w
.
skey
;
pWindowResInfo
->
prevSKey
=
w
.
skey
;
}
}
}
}
...
@@ -2916,13 +2851,9 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -2916,13 +2851,9 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
}
}
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
)
&&
(
IS_MASTER_SCAN
(
pRuntimeEnv
)
||
pRuntimeEnv
->
scanFlag
==
REPEAT_SCAN
))
{
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
))
{
if
(
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_COMPLETED
))
{
closeAllResultRows
(
&
pRuntimeEnv
->
windowResInfo
);
closeAllResultRows
(
&
pRuntimeEnv
->
windowResInfo
);
pRuntimeEnv
->
windowResInfo
.
curIndex
=
pRuntimeEnv
->
windowResInfo
.
size
-
1
;
// point to the last time window
pRuntimeEnv
->
windowResInfo
.
curIndex
=
pRuntimeEnv
->
windowResInfo
.
size
-
1
;
// point to the last time window
}
else
{
assert
(
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_RESBUF_FULL
));
}
}
}
return
0
;
return
0
;
...
@@ -3027,7 +2958,7 @@ void setTagVal(SQueryRuntimeEnv *pRuntimeEnv, void *pTable, void *tsdb) {
...
@@ -3027,7 +2958,7 @@ void setTagVal(SQueryRuntimeEnv *pRuntimeEnv, void *pTable, void *tsdb) {
}
}
}
}
static
void
doMerge
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
int64_t
timestamp
,
SResultRow
*
pWindowRes
,
bool
mergeFlag
)
{
static
UNUSED_FUNC
void
doMerge
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
int64_t
timestamp
,
SResultRow
*
pWindowRes
,
bool
mergeFlag
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQLFunctionCtx
*
pCtx
=
pRuntimeEnv
->
pCtx
;
SQLFunctionCtx
*
pCtx
=
pRuntimeEnv
->
pCtx
;
...
@@ -3176,19 +3107,18 @@ void UNUSED_FUNC displayInterResult(tFilePage **pdata, SQueryRuntimeEnv* pRuntim
...
@@ -3176,19 +3107,18 @@ void UNUSED_FUNC displayInterResult(tFilePage **pdata, SQueryRuntimeEnv* pRuntim
typedef
struct
SCompSupporter
{
typedef
struct
SCompSupporter
{
STableQueryInfo
**
pTableQueryInfo
;
STableQueryInfo
**
pTableQueryInfo
;
int32_t
*
position
;
int32_t
*
rowIndex
;
SQInfo
*
pQInfo
;
int32_t
order
;
}
SCompSupporter
;
}
SCompSupporter
;
int32_t
tableResultComparFn
(
const
void
*
pLeft
,
const
void
*
pRight
,
void
*
param
)
{
int32_t
tableResultComparFn
(
const
void
*
pLeft
,
const
void
*
pRight
,
void
*
param
)
{
int32_t
left
=
*
(
int32_t
*
)
pLeft
;
int32_t
left
=
*
(
int32_t
*
)
pLeft
;
int32_t
right
=
*
(
int32_t
*
)
pRight
;
int32_t
right
=
*
(
int32_t
*
)
pRight
;
SCompSupporter
*
supporter
=
(
SCompSupporter
*
)
param
;
SCompSupporter
*
supporter
=
(
SCompSupporter
*
)
param
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
supporter
->
pQInfo
->
runtimeEnv
;
int32_t
leftPos
=
supporter
->
position
[
left
];
int32_t
leftPos
=
supporter
->
rowIndex
[
left
];
int32_t
rightPos
=
supporter
->
position
[
right
];
int32_t
rightPos
=
supporter
->
rowIndex
[
right
];
/* left source is exhausted */
/* left source is exhausted */
if
(
leftPos
==
-
1
)
{
if
(
leftPos
==
-
1
)
{
...
@@ -3200,53 +3130,55 @@ int32_t tableResultComparFn(const void *pLeft, const void *pRight, void *param)
...
@@ -3200,53 +3130,55 @@ int32_t tableResultComparFn(const void *pLeft, const void *pRight, void *param)
return
-
1
;
return
-
1
;
}
}
SResultRowInfo
*
pWindowResInfo1
=
&
supporter
->
pTableQueryInfo
[
left
]
->
windowResInfo
;
STableQueryInfo
**
pList
=
supporter
->
pTableQueryInfo
;
SResultRow
*
pWindowRes1
=
getResultRow
(
pWindowResInfo1
,
leftPos
);
tFilePage
*
page1
=
getResBufPage
(
pRuntimeEnv
->
pResultBuf
,
pWindowRes1
->
pageId
);
char
*
b1
=
getPosInResultPage
(
pRuntimeEnv
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
,
pWindowRes1
,
page1
);
SResultRowInfo
*
pWindowResInfo1
=
&
(
pList
[
left
]
->
windowResInfo
);
TSKEY
leftTimestamp
=
GET_INT64_VAL
(
b1
);
SResultRow
*
pWindowRes1
=
getResultRow
(
pWindowResInfo1
,
leftPos
);
TSKEY
leftTimestamp
=
pWindowRes1
->
win
.
skey
;
SResultRowInfo
*
pWindowResInfo2
=
&
supporter
->
pTableQueryInfo
[
right
]
->
windowResInfo
;
SResultRowInfo
*
pWindowResInfo2
=
&
(
pList
[
right
]
->
windowResInfo
)
;
SResultRow
*
pWindowRes2
=
getResultRow
(
pWindowResInfo2
,
rightPos
);
SResultRow
*
pWindowRes2
=
getResultRow
(
pWindowResInfo2
,
rightPos
);
tFilePage
*
page2
=
getResBufPage
(
pRuntimeEnv
->
pResultBuf
,
pWindowRes2
->
pageId
);
TSKEY
rightTimestamp
=
pWindowRes2
->
win
.
skey
;
char
*
b2
=
getPosInResultPage
(
pRuntimeEnv
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
,
pWindowRes2
,
page2
);
TSKEY
rightTimestamp
=
GET_INT64_VAL
(
b2
);
if
(
leftTimestamp
==
rightTimestamp
)
{
if
(
leftTimestamp
==
rightTimestamp
)
{
return
0
;
return
0
;
}
}
return
leftTimestamp
>
rightTimestamp
?
1
:
-
1
;
if
(
supporter
->
order
==
TSDB_ORDER_ASC
)
{
return
(
leftTimestamp
>
rightTimestamp
)
?
1
:-
1
;
}
else
{
return
(
leftTimestamp
<
rightTimestamp
)
?
1
:-
1
;
}
}
}
int32_t
merge
Into
GroupResult
(
SQInfo
*
pQInfo
)
{
int32_t
mergeGroupResult
(
SQInfo
*
pQInfo
)
{
int64_t
st
=
taosGetTimestampUs
();
int64_t
st
=
taosGetTimestampUs
();
int32_t
ret
=
TSDB_CODE_SUCCESS
;
int32_t
numOfGroups
=
(
int32_t
)(
GET_NUM_OF_TABLEGROUP
(
pQInfo
))
;
SGroupResInfo
*
pGroupResInfo
=
&
pQInfo
->
groupResInfo
;
int32_t
numOfGroups
=
(
int32_t
)(
GET_NUM_OF_TABLEGROUP
(
pQInfo
));
while
(
pQInfo
->
groupIndex
<
numOfGroups
)
{
while
(
pQInfo
->
groupIndex
<
numOfGroups
)
{
SArray
*
group
=
GET_TABLEGROUP
(
pQInfo
,
pQInfo
->
groupIndex
);
SArray
*
group
=
GET_TABLEGROUP
(
pQInfo
,
pQInfo
->
groupIndex
);
ret
=
mergeIntoGroupResultImpl
(
pQInfo
,
group
);
if
(
ret
<
0
)
{
// not enough disk space to save the data into disk
int32_t
ret
=
mergeIntoGroupResultImpl
(
pGroupResInfo
,
group
,
pQInfo
);
if
(
ret
<
0
)
{
return
-
1
;
return
-
1
;
}
}
pQInfo
->
groupIndex
+=
1
;
// this group generates at least one result, return results
// this group generates at least one result, return results
if
(
ret
>
0
)
{
pQInfo
->
groupIndex
+=
1
;
if
(
taosArrayGetSize
(
pGroupResInfo
->
pRows
)
>
0
)
{
break
;
break
;
}
}
assert
(
pQInfo
->
groupResInfo
.
numOfDataPages
==
0
);
qDebug
(
"QInfo:%p no result in group %d, continue"
,
pQInfo
,
pQInfo
->
groupIndex
-
1
);
qDebug
(
"QInfo:%p no result in group %d, continue"
,
pQInfo
,
pQInfo
->
groupIndex
-
1
);
taosArrayClear
(
pGroupResInfo
->
pRows
);
pGroupResInfo
->
index
=
0
;
pGroupResInfo
->
rowId
=
0
;
}
}
SGroupResInfo
*
info
=
&
pQInfo
->
groupResInfo
;
if
(
pQInfo
->
groupIndex
==
numOfGroups
&&
taosArrayGetSize
(
pGroupResInfo
->
pRows
)
==
0
)
{
if
(
pQInfo
->
groupIndex
==
numOfGroups
&&
info
->
pageId
==
info
->
numOfDataPages
)
{
SET_STABLE_QUERY_OVER
(
pQInfo
);
SET_STABLE_QUERY_OVER
(
pQInfo
);
}
}
...
@@ -3258,89 +3190,28 @@ int32_t mergeIntoGroupResult(SQInfo *pQInfo) {
...
@@ -3258,89 +3190,28 @@ int32_t mergeIntoGroupResult(SQInfo *pQInfo) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
doCopyToSData
(
SQInfo
*
pQInfo
,
SResultRow
**
pRows
,
int32_t
numOfRows
,
int32_t
*
index
,
int32_t
orderType
);
void
copyResToQueryResultBuf
(
SQInfo
*
pQInfo
,
SQuery
*
pQuery
)
{
void
copyResToQueryResultBuf
(
SQInfo
*
pQInfo
,
SQuery
*
pQuery
)
{
SGroupResInfo
*
pGroupResInfo
=
&
pQInfo
->
groupResInfo
;
SGroupResInfo
*
pGroupResInfo
=
&
pQInfo
->
groupResInfo
;
// all results have been return to client, try next group
// all results in current group have been returned to client, try next group
if
(
pGroupResInfo
->
pageId
==
pGroupResInfo
->
numOfDataPages
)
{
if
(
pGroupResInfo
->
index
>=
taosArrayGetSize
(
pGroupResInfo
->
pRows
))
{
pGroupResInfo
->
numOfDataPages
=
0
;
pGroupResInfo
->
pageId
=
0
;
pGroupResInfo
->
rowId
=
0
;
// current results of group has been sent to client, try next group
// current results of group has been sent to client, try next group
if
(
merge
Into
GroupResult
(
pQInfo
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
mergeGroupResult
(
pQInfo
)
!=
TSDB_CODE_SUCCESS
)
{
return
;
// failed to save data in the disk
return
;
// failed to save data in the disk
}
}
// check if all results has been sent to client
// check if all results has been sent to client
int32_t
numOfGroup
=
(
int32_t
)(
GET_NUM_OF_TABLEGROUP
(
pQInfo
));
int32_t
numOfGroup
=
(
int32_t
)(
GET_NUM_OF_TABLEGROUP
(
pQInfo
));
if
(
pGroupResInfo
->
numOfDataPages
==
0
&&
pQInfo
->
groupIndex
==
numOfGroup
)
{
if
(
taosArrayGetSize
(
pGroupResInfo
->
pRows
)
==
0
&&
pQInfo
->
groupIndex
==
numOfGroup
)
{
SET_STABLE_QUERY_OVER
(
pQInfo
);
SET_STABLE_QUERY_OVER
(
pQInfo
);
return
;
return
;
}
}
}
}
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
int32_t
size
=
(
int32_t
)
taosArrayGetSize
(
pGroupResInfo
->
pRows
);
SDiskbasedResultBuf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
pQuery
->
rec
.
rows
=
doCopyToSData
(
pQInfo
,
pGroupResInfo
->
pRows
->
pData
,
(
int32_t
)
size
,
&
pGroupResInfo
->
index
,
TSDB_ORDER_ASC
);
int32_t
id
=
pQInfo
->
groupResInfo
.
groupId
;
SIDList
list
=
getDataBufPagesIdList
(
pResultBuf
,
id
);
int32_t
offset
=
0
;
int32_t
numOfCopiedRows
=
0
;
size_t
size
=
taosArrayGetSize
(
list
);
assert
(
size
==
pGroupResInfo
->
numOfDataPages
);
bool
done
=
false
;
//TODO add API for release none-dirty pages
// SPageInfo* prev = NULL;
for
(
int32_t
j
=
pGroupResInfo
->
pageId
;
j
<
size
;
++
j
)
{
SPageInfo
*
pi
=
*
(
SPageInfo
**
)
taosArrayGet
(
list
,
j
);
tFilePage
*
pData
=
getResBufPage
(
pResultBuf
,
pi
->
pageId
);
// release previous buffer pages
// if (prev == NULL) {
// prev = pi;
// } else {
// if (prev->pageId != pi->pageId) {
// releaseResBufPageInfo(pResultBuf, prev);
// prev = pi;
// }
// }
assert
(
pData
->
num
>
0
&&
pData
->
num
<=
pRuntimeEnv
->
numOfRowsPerPage
&&
pGroupResInfo
->
rowId
<
pData
->
num
);
int32_t
numOfRes
=
(
int32_t
)(
pData
->
num
-
pGroupResInfo
->
rowId
);
if
(
numOfRes
>
pQuery
->
rec
.
capacity
-
offset
)
{
numOfCopiedRows
=
(
int32_t
)(
pQuery
->
rec
.
capacity
-
offset
);
pGroupResInfo
->
rowId
+=
numOfCopiedRows
;
done
=
true
;
}
else
{
numOfCopiedRows
=
(
int32_t
)
pData
->
num
;
pGroupResInfo
->
pageId
+=
1
;
pGroupResInfo
->
rowId
=
0
;
}
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
int32_t
bytes
=
pRuntimeEnv
->
pCtx
[
i
].
outputBytes
;
char
*
pDest
=
pQuery
->
sdata
[
i
]
->
data
;
memcpy
(
pDest
+
offset
*
bytes
,
pData
->
data
+
pRuntimeEnv
->
offset
[
i
]
*
pRuntimeEnv
->
numOfRowsPerPage
,
(
size_t
)
bytes
*
numOfCopiedRows
);
}
offset
+=
numOfCopiedRows
;
if
(
done
)
{
break
;
}
}
assert
(
pQuery
->
rec
.
rows
==
0
);
pQuery
->
rec
.
rows
+=
offset
;
}
}
int64_t
getNumOfResultWindowRes
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResultRow
)
{
int64_t
getNumOfResultWindowRes
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pResultRow
)
{
...
@@ -3368,155 +3239,99 @@ int64_t getNumOfResultWindowRes(SQueryRuntimeEnv* pRuntimeEnv, SResultRow *pResu
...
@@ -3368,155 +3239,99 @@ int64_t getNumOfResultWindowRes(SQueryRuntimeEnv* pRuntimeEnv, SResultRow *pResu
return
0
;
return
0
;
}
}
int32_t
mergeIntoGroupResultImpl
(
S
QInfo
*
pQInfo
,
SArray
*
pGroup
)
{
int32_t
mergeIntoGroupResultImpl
(
S
GroupResInfo
*
pGroupResInfo
,
SArray
*
pTableList
,
SQInfo
*
pQInfo
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pRuntimeEnv
->
pQuery
)
;
size_t
size
=
taosArrayGetSize
(
pGroup
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
tFilePage
**
buffer
=
pQuery
->
sdata
;
int32_t
*
posList
=
calloc
(
size
,
sizeof
(
int32_t
));
int32_t
*
posList
=
NULL
;
STableQueryInfo
**
pTableList
=
malloc
(
POINTER_BYTES
*
size
);
SLoserTreeInfo
*
pTree
=
NULL
;
STableQueryInfo
**
pTableQueryInfoList
=
NULL
;
size_t
size
=
taosArrayGetSize
(
pTableList
);
if
(
pGroupResInfo
->
pRows
==
NULL
)
{
pGroupResInfo
->
pRows
=
taosArrayInit
(
100
,
POINTER_BYTES
);
}
if
(
pTableList
==
NULL
||
posList
==
NULL
)
{
posList
=
calloc
(
size
,
sizeof
(
int32_t
));
tfree
(
posList
);
pTableQueryInfoList
=
malloc
(
POINTER_BYTES
*
size
);
tfree
(
pTableList
);
if
(
pTableQueryInfoList
==
NULL
||
posList
==
NULL
)
{
qError
(
"QInfo:%p failed alloc memory"
,
pQInfo
);
qError
(
"QInfo:%p failed alloc memory"
,
pQInfo
);
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_OUT_OF_MEMORY
);
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
goto
_end
;
}
}
// todo opt for the case of one table per group
int32_t
numOfTables
=
0
;
int32_t
numOfTables
=
0
;
SIDList
pageList
=
NULL
;
int32_t
tid
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
STableQueryInfo
*
item
=
taosArrayGetP
(
pGroup
,
i
);
STableQueryInfo
*
item
=
taosArrayGetP
(
pTableList
,
i
);
if
(
item
->
windowResInfo
.
size
>
0
)
{
SIDList
list
=
getDataBufPagesIdList
(
pRuntimeEnv
->
pResultBuf
,
TSDB_TABLEID
(
item
->
pTable
)
->
tid
);
pTableQueryInfoList
[
numOfTables
++
]
=
item
;
if
(
taosArrayGetSize
(
list
)
>
0
&&
item
->
windowResInfo
.
size
>
0
)
{
pTableList
[
numOfTables
++
]
=
item
;
tid
=
TSDB_TABLEID
(
item
->
pTable
)
->
tid
;
pageList
=
list
;
}
}
}
}
// there is no data in current group
// there is no data in current group
// no need to merge results since only one table in each group
if
(
numOfTables
==
0
)
{
if
(
numOfTables
==
0
)
{
tfree
(
posList
);
goto
_end
;
tfree
(
pTableList
);
return
0
;
}
else
if
(
numOfTables
==
1
)
{
// no need to merge results since only one table in each group
tfree
(
posList
);
tfree
(
pTableList
);
SGroupResInfo
*
pGroupResInfo
=
&
pQInfo
->
groupResInfo
;
pGroupResInfo
->
numOfDataPages
=
(
int32_t
)
taosArrayGetSize
(
pageList
);
pGroupResInfo
->
groupId
=
tid
;
pGroupResInfo
->
pageId
=
0
;
pGroupResInfo
->
rowId
=
0
;
return
pGroupResInfo
->
numOfDataPages
;
}
}
SCompSupporter
cs
=
{
pTableList
,
posList
,
pQInfo
};
SCompSupporter
cs
=
{
pTableQueryInfoList
,
posList
,
pRuntimeEnv
->
pQuery
->
order
.
order
};
SLoserTreeInfo
*
pTree
=
NULL
;
tLoserTreeCreate
(
&
pTree
,
numOfTables
,
&
cs
,
tableResultComparFn
);
SResultRow
*
pRow
=
getNewResultRow
(
pRuntimeEnv
->
pool
);
resetMergeResultBuf
(
pRuntimeEnv
,
pRuntimeEnv
->
pCtx
,
pRow
);
pQInfo
->
groupResInfo
.
groupId
=
getMergeResultGroupId
(
pQInfo
->
groupIndex
);
int32_t
ret
=
tLoserTreeCreate
(
&
pTree
,
numOfTables
,
&
cs
,
tableResultComparFn
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
goto
_end
;
}
// todo add windowRes iterator
int64_t
lastTimestamp
=
ascQuery
?
INT64_MIN
:
INT64_MAX
;
int64_t
lastTimestamp
=
-
1
;
int64_t
startt
=
taosGetTimestampMs
();
int64_t
startt
=
taosGetTimestampMs
();
while
(
1
)
{
while
(
1
)
{
if
(
isQueryKilled
(
pQInfo
))
{
if
(
isQueryKilled
(
pQInfo
))
{
qDebug
(
"QInfo:%p it is already killed, abort"
,
pQInfo
);
qDebug
(
"QInfo:%p it is already killed, abort"
,
pQInfo
);
code
=
TSDB_CODE_TSC_QUERY_CANCELLED
;
tfree
(
pTableList
);
goto
_end
;
tfree
(
posList
);
tfree
(
pTree
);
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_TSC_QUERY_CANCELLED
);
}
}
int32_t
pos
=
pTree
->
pNode
[
0
].
index
;
int32_t
tableIndex
=
pTree
->
pNode
[
0
].
index
;
SResultRowInfo
*
pWindowResInfo
=
&
pTableList
[
pos
]
->
windowResInfo
;
SResultRow
*
pWindowRes
=
getResultRow
(
pWindowResInfo
,
cs
.
position
[
pos
]);
tFilePage
*
page
=
getResBufPage
(
pRuntimeEnv
->
pResultBuf
,
pWindowRes
->
pageId
);
char
*
b
=
getPosInResultPage
(
pRuntimeEnv
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
,
pWindowRes
,
page
)
;
SResultRowInfo
*
pWindowResInfo
=
&
pTableQueryInfoList
[
tableIndex
]
->
windowResInfo
;
TSKEY
ts
=
GET_INT64_VAL
(
b
);
SResultRow
*
pWindowRes
=
getResultRow
(
pWindowResInfo
,
cs
.
rowIndex
[
tableIndex
]
);
assert
(
ts
==
pWindowRes
->
win
.
skey
);
int64_t
num
=
getNumOfResultWindowRes
(
pRuntimeEnv
,
pWindowRes
);
int64_t
num
=
getNumOfResultWindowRes
(
pRuntimeEnv
,
pWindowRes
);
if
(
num
<=
0
)
{
if
(
num
<=
0
)
{
cs
.
position
[
pos
]
+=
1
;
cs
.
rowIndex
[
tableIndex
]
+=
1
;
if
(
cs
.
position
[
pos
]
>=
pWindowResInfo
->
size
)
{
if
(
cs
.
rowIndex
[
tableIndex
]
>=
pWindowResInfo
->
size
)
{
cs
.
position
[
pos
]
=
-
1
;
cs
.
rowIndex
[
tableIndex
]
=
-
1
;
if
(
--
numOfTables
==
0
)
{
// all input sources are exhausted
// all input sources are exhausted
if
(
--
numOfTables
==
0
)
{
break
;
break
;
}
}
}
}
}
else
{
}
else
{
if
(
ts
==
lastTimestamp
)
{
// merge with the last one
assert
((
pWindowRes
->
win
.
skey
>=
lastTimestamp
&&
ascQuery
)
||
(
pWindowRes
->
win
.
skey
<=
lastTimestamp
&&
!
ascQuery
));
doMerge
(
pRuntimeEnv
,
ts
,
pWindowRes
,
true
);
}
else
{
// copy data to disk buffer
if
(
buffer
[
0
]
->
num
==
pQuery
->
rec
.
capacity
)
{
if
(
flushFromResultBuf
(
pRuntimeEnv
,
&
pQInfo
->
groupResInfo
)
!=
TSDB_CODE_SUCCESS
)
{
return
-
1
;
}
resetMergeResultBuf
(
pRuntimeEnv
,
pRuntimeEnv
->
pCtx
,
pRow
);
}
doMerge
(
pRuntimeEnv
,
ts
,
pWindowRes
,
false
);
if
(
pWindowRes
->
win
.
skey
!=
lastTimestamp
)
{
buffer
[
0
]
->
num
+=
1
;
taosArrayPush
(
pGroupResInfo
->
pRows
,
&
pWindowRes
);
pWindowRes
->
numOfRows
=
(
uint32_t
)
num
;
}
}
lastTimestamp
=
ts
;
lastTimestamp
=
pWindowRes
->
win
.
skey
;
// move to the next element of current entry
// move to the next row of current entry
int32_t
currentPageId
=
pWindowRes
->
pageId
;
if
((
++
cs
.
rowIndex
[
tableIndex
])
>=
pWindowResInfo
->
size
)
{
cs
.
rowIndex
[
tableIndex
]
=
-
1
;
cs
.
position
[
pos
]
+=
1
;
if
(
cs
.
position
[
pos
]
>=
pWindowResInfo
->
size
)
{
cs
.
position
[
pos
]
=
-
1
;
// all input sources are exhausted
// all input sources are exhausted
if
(
--
numOfTables
==
0
)
{
if
(
(
--
numOfTables
)
==
0
)
{
break
;
break
;
}
}
}
else
{
// current page is not needed anymore
SResultRow
*
pNextWindowRes
=
getResultRow
(
pWindowResInfo
,
cs
.
position
[
pos
]);
if
(
pNextWindowRes
->
pageId
!=
currentPageId
)
{
releaseResBufPage
(
pRuntimeEnv
->
pResultBuf
,
page
);
}
}
}
}
}
tLoserTreeAdjust
(
pTree
,
pos
+
pTree
->
numOfEntries
);
tLoserTreeAdjust
(
pTree
,
tableIndex
+
pTree
->
numOfEntries
);
}
if
(
buffer
[
0
]
->
num
!=
0
)
{
// there are data in buffer
if
(
flushFromResultBuf
(
pRuntimeEnv
,
&
pQInfo
->
groupResInfo
)
!=
TSDB_CODE_SUCCESS
)
{
qError
(
"QInfo:%p failed to flush data into temp file, abort query"
,
pQInfo
);
tfree
(
pTree
);
tfree
(
pTableList
);
tfree
(
posList
);
return
-
1
;
}
}
}
int64_t
endt
=
taosGetTimestampMs
();
int64_t
endt
=
taosGetTimestampMs
();
...
@@ -3527,65 +3342,16 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) {
...
@@ -3527,65 +3342,16 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) {
qDebug
(
"QInfo:%p result merge completed for group:%d, elapsed time:%"
PRId64
" ms"
,
pQInfo
,
pQInfo
->
groupIndex
,
endt
-
startt
);
qDebug
(
"QInfo:%p result merge completed for group:%d, elapsed time:%"
PRId64
" ms"
,
pQInfo
,
pQInfo
->
groupIndex
,
endt
-
startt
);
tfree
(
pTableList
);
_end:
tfree
(
pTableQueryInfoList
);
tfree
(
posList
);
tfree
(
posList
);
tfree
(
pTree
);
tfree
(
pTree
);
// tfree(pResultInfo);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
// tfree(buf);
longjmp
(
pRuntimeEnv
->
env
,
code
);
return
pQInfo
->
groupResInfo
.
numOfDataPages
;
}
int32_t
flushFromResultBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SDiskbasedResultBuf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
// the base value for group result, since the maximum number of table for each vnode will not exceed 100,000.
int32_t
pageId
=
-
1
;
int32_t
capacity
=
pResultBuf
->
numOfRowsPerPage
;
int32_t
remain
=
(
int32_t
)
pQuery
->
sdata
[
0
]
->
num
;
int32_t
offset
=
0
;
while
(
remain
>
0
)
{
int32_t
rows
=
(
remain
>
capacity
)
?
capacity
:
remain
;
assert
(
rows
>
0
);
// get the output buffer page
tFilePage
*
buf
=
getNewDataBuf
(
pResultBuf
,
pGroupResInfo
->
groupId
,
&
pageId
);
buf
->
num
=
rows
;
// pagewisely copy to dest buffer
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
int32_t
bytes
=
pRuntimeEnv
->
pCtx
[
i
].
outputBytes
;
char
*
output
=
buf
->
data
+
pRuntimeEnv
->
offset
[
i
]
*
pRuntimeEnv
->
numOfRowsPerPage
;
char
*
src
=
((
char
*
)
pQuery
->
sdata
[
i
]
->
data
)
+
offset
*
bytes
;
memcpy
(
output
,
src
,
(
size_t
)(
buf
->
num
*
bytes
));
}
offset
+=
rows
;
remain
-=
rows
;
pGroupResInfo
->
numOfDataPages
+=
1
;
}
}
return
TSDB_CODE_SUCCESS
;
return
code
;
}
void
resetMergeResultBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SQLFunctionCtx
*
pCtx
,
SResultRow
*
pRow
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutput
;
++
k
)
{
pCtx
[
k
].
aOutputBuf
=
pQuery
->
sdata
[
k
]
->
data
-
pCtx
[
k
].
outputBytes
;
pCtx
[
k
].
size
=
1
;
pCtx
[
k
].
startOffset
=
0
;
pCtx
[
k
].
resultInfo
=
getResultCell
(
pRuntimeEnv
,
pRow
,
k
);
pQuery
->
sdata
[
k
]
->
num
=
0
;
}
}
}
static
void
updateTableQueryInfoForReverseScan
(
SQuery
*
pQuery
,
STableQueryInfo
*
pTableQueryInfo
)
{
static
void
updateTableQueryInfoForReverseScan
(
SQuery
*
pQuery
,
STableQueryInfo
*
pTableQueryInfo
)
{
...
@@ -3706,7 +3472,7 @@ void resetDefaultResInfoOutputBuf(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -3706,7 +3472,7 @@ void resetDefaultResInfoOutputBuf(SQueryRuntimeEnv *pRuntimeEnv) {
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
int32_t
tid
=
0
;
int32_t
tid
=
0
;
int64_t
uid
=
getResultInfoUId
(
pRuntimeEnv
)
;
int64_t
uid
=
0
;
SResultRow
*
pRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
&
pRuntimeEnv
->
windowResInfo
,
(
char
*
)
&
tid
,
sizeof
(
tid
),
true
,
uid
);
SResultRow
*
pRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
&
pRuntimeEnv
->
windowResInfo
,
(
char
*
)
&
tid
,
sizeof
(
tid
),
true
,
uid
);
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
...
@@ -3838,12 +3604,8 @@ bool needScanDataBlocksAgain(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -3838,12 +3604,8 @@ bool needScanDataBlocksAgain(SQueryRuntimeEnv *pRuntimeEnv) {
for
(
int32_t
i
=
0
;
i
<
pWindowResInfo
->
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pWindowResInfo
->
size
;
++
i
)
{
SResultRow
*
pResult
=
getResultRow
(
pWindowResInfo
,
i
);
SResultRow
*
pResult
=
getResultRow
(
pWindowResInfo
,
i
);
if
(
!
pResult
->
closed
)
{
continue
;
}
setResultOutputBuf
(
pRuntimeEnv
,
pResult
);
setResultOutputBuf
(
pRuntimeEnv
,
pResult
);
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutput
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutput
;
++
j
)
{
int16_t
functId
=
pQuery
->
pExpr1
[
j
].
base
.
functionId
;
int16_t
functId
=
pQuery
->
pExpr1
[
j
].
base
.
functionId
;
if
(
functId
==
TSDB_FUNC_TS
)
{
if
(
functId
==
TSDB_FUNC_TS
)
{
...
@@ -4127,9 +3889,9 @@ void destroyTableQueryInfoImpl(STableQueryInfo *pTableQueryInfo) {
...
@@ -4127,9 +3889,9 @@ void destroyTableQueryInfoImpl(STableQueryInfo *pTableQueryInfo) {
* @param pDataBlockInfo
* @param pDataBlockInfo
*/
*/
void
setExecutionContext
(
SQInfo
*
pQInfo
,
int32_t
groupIndex
,
TSKEY
nextKey
)
{
void
setExecutionContext
(
SQInfo
*
pQInfo
,
int32_t
groupIndex
,
TSKEY
nextKey
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
pQuery
->
current
;
STableQueryInfo
*
pTableQueryInfo
=
pRuntimeEnv
->
pQuery
->
current
;
SResultRowInfo
*
pWindowResInfo
=
&
pRuntimeEnv
->
windowResInfo
;
SResultRowInfo
*
pWindowResInfo
=
&
pRuntimeEnv
->
windowResInfo
;
// lastKey needs to be updated
// lastKey needs to be updated
pTableQueryInfo
->
lastKey
=
nextKey
;
pTableQueryInfo
->
lastKey
=
nextKey
;
...
@@ -4142,12 +3904,10 @@ void setExecutionContext(SQInfo *pQInfo, int32_t groupIndex, TSKEY nextKey) {
...
@@ -4142,12 +3904,10 @@ void setExecutionContext(SQInfo *pQInfo, int32_t groupIndex, TSKEY nextKey) {
return
;
return
;
}
}
uint64_t
uid
=
getResultInfoUId
(
pRuntimeEnv
)
;
int64_t
uid
=
0
;
SResultRow
*
pResultRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
pWindowResInfo
,
(
char
*
)
&
groupIndex
,
SResultRow
*
pResultRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
pWindowResInfo
,
(
char
*
)
&
groupIndex
,
sizeof
(
groupIndex
),
true
,
uid
);
sizeof
(
groupIndex
),
true
,
uid
);
if
(
pResultRow
==
NULL
)
{
assert
(
pResultRow
!=
NULL
);
return
;
}
/*
/*
* not assign result buffer yet, add new result buffer
* not assign result buffer yet, add new result buffer
...
@@ -4293,7 +4053,7 @@ void setIntervalQueryRange(SQInfo *pQInfo, TSKEY key) {
...
@@ -4293,7 +4053,7 @@ void setIntervalQueryRange(SQInfo *pQInfo, TSKEY key) {
/**
/**
* In handling the both ascending and descending order super table query, we need to find the first qualified
* In handling the both ascending and descending order super table query, we need to find the first qualified
* timestamp of this table, and then set the first qualified start timestamp.
* timestamp of this table, and then set the first qualified start timestamp.
* In ascending query, key is the first qualified timestamp. However, in the descending order query, additional
* In ascending query,
the
key is the first qualified timestamp. However, in the descending order query, additional
* operations involve.
* operations involve.
*/
*/
STimeWindow
w
=
TSWINDOW_INITIALIZER
;
STimeWindow
w
=
TSWINDOW_INITIALIZER
;
...
@@ -4302,7 +4062,6 @@ void setIntervalQueryRange(SQInfo *pQInfo, TSKEY key) {
...
@@ -4302,7 +4062,6 @@ void setIntervalQueryRange(SQInfo *pQInfo, TSKEY key) {
TSKEY
sk
=
MIN
(
win
.
skey
,
win
.
ekey
);
TSKEY
sk
=
MIN
(
win
.
skey
,
win
.
ekey
);
TSKEY
ek
=
MAX
(
win
.
skey
,
win
.
ekey
);
TSKEY
ek
=
MAX
(
win
.
skey
,
win
.
ekey
);
getAlignQueryTimeWindow
(
pQuery
,
win
.
skey
,
sk
,
ek
,
&
w
);
getAlignQueryTimeWindow
(
pQuery
,
win
.
skey
,
sk
,
ek
,
&
w
);
pWindowResInfo
->
startTime
=
pTableQueryInfo
->
win
.
skey
;
// windowSKey may be 0 in case of 1970 timestamp
if
(
pWindowResInfo
->
prevSKey
==
TSKEY_INITIAL_VAL
)
{
if
(
pWindowResInfo
->
prevSKey
==
TSKEY_INITIAL_VAL
)
{
if
(
!
QUERY_IS_ASC_QUERY
(
pQuery
))
{
if
(
!
QUERY_IS_ASC_QUERY
(
pQuery
))
{
...
@@ -4341,36 +4100,33 @@ bool needPrimaryTimestampCol(SQuery *pQuery, SDataBlockInfo *pDataBlockInfo) {
...
@@ -4341,36 +4100,33 @@ bool needPrimaryTimestampCol(SQuery *pQuery, SDataBlockInfo *pDataBlockInfo) {
return
loadPrimaryTS
;
return
loadPrimaryTS
;
}
}
static
int32_t
doCopyToSData
(
SQInfo
*
pQInfo
,
SResultRow
Info
*
pResultInfo
,
int32_t
orderType
)
{
static
int32_t
doCopyToSData
(
SQInfo
*
pQInfo
,
SResultRow
**
pRows
,
int32_t
numOfRows
,
int32_t
*
index
,
int32_t
orderType
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
int32_t
numOfResult
=
0
;
int32_t
numOfResult
=
0
;
int32_t
start
Idx
=
0
;
int32_t
start
=
0
;
int32_t
step
=
-
1
;
int32_t
step
=
-
1
;
qDebug
(
"QInfo:%p start to copy data from windowResInfo to query buf"
,
pQInfo
);
qDebug
(
"QInfo:%p start to copy data from windowResInfo to query buf"
,
pQInfo
);
int32_t
totalSet
=
numOfClosedResultRows
(
pResultInfo
);
SResultRow
**
result
=
pResultInfo
->
pResult
;
if
(
orderType
==
TSDB_ORDER_ASC
)
{
if
(
orderType
==
TSDB_ORDER_ASC
)
{
start
Idx
=
pQInfo
->
groupIndex
;
start
=
(
*
index
)
;
step
=
1
;
step
=
1
;
}
else
{
// desc order copy all data
}
else
{
// desc order copy all data
start
Idx
=
totalSet
-
pQInfo
->
groupIndex
-
1
;
start
=
numOfRows
-
(
*
index
)
-
1
;
step
=
-
1
;
step
=
-
1
;
}
}
SGroupResInfo
*
pGroupResInfo
=
&
pQInfo
->
groupResInfo
;
SGroupResInfo
*
pGroupResInfo
=
&
pQInfo
->
groupResInfo
;
for
(
int32_t
i
=
start
Idx
;
(
i
<
totalSet
)
&&
(
i
>=
0
);
i
+=
step
)
{
for
(
int32_t
i
=
start
;
(
i
<
numOfRows
)
&&
(
i
>=
0
);
i
+=
step
)
{
if
(
result
[
i
]
->
numOfRows
==
0
)
{
if
(
pRows
[
i
]
->
numOfRows
==
0
)
{
pQInfo
->
groupIndex
+=
1
;
(
*
index
)
+=
1
;
pGroupResInfo
->
rowId
=
0
;
pGroupResInfo
->
rowId
=
0
;
continue
;
continue
;
}
}
int32_t
numOfRowsToCopy
=
result
[
i
]
->
numOfRows
-
pGroupResInfo
->
rowId
;
int32_t
numOfRowsToCopy
=
pRows
[
i
]
->
numOfRows
-
pGroupResInfo
->
rowId
;
int32_t
oldOffset
=
pGroupResInfo
->
rowId
;
int32_t
oldOffset
=
pGroupResInfo
->
rowId
;
/*
/*
...
@@ -4382,16 +4138,16 @@ static int32_t doCopyToSData(SQInfo *pQInfo, SResultRowInfo *pResultInfo, int32_
...
@@ -4382,16 +4138,16 @@ static int32_t doCopyToSData(SQInfo *pQInfo, SResultRowInfo *pResultInfo, int32_
pGroupResInfo
->
rowId
+=
numOfRowsToCopy
;
pGroupResInfo
->
rowId
+=
numOfRowsToCopy
;
}
else
{
}
else
{
pGroupResInfo
->
rowId
=
0
;
pGroupResInfo
->
rowId
=
0
;
pQInfo
->
groupIndex
+=
1
;
(
*
index
)
+=
1
;
}
}
tFilePage
*
page
=
getResBufPage
(
pRuntimeEnv
->
pResultBuf
,
result
[
i
]
->
pageId
);
tFilePage
*
page
=
getResBufPage
(
pRuntimeEnv
->
pResultBuf
,
pRows
[
i
]
->
pageId
);
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutput
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutput
;
++
j
)
{
int32_t
size
=
pRuntimeEnv
->
pCtx
[
j
].
outputBytes
;
int32_t
size
=
pRuntimeEnv
->
pCtx
[
j
].
outputBytes
;
char
*
out
=
pQuery
->
sdata
[
j
]
->
data
+
numOfResult
*
size
;
char
*
out
=
pQuery
->
sdata
[
j
]
->
data
+
numOfResult
*
size
;
char
*
in
=
getPosInResultPage
(
pRuntimeEnv
,
j
,
result
[
i
],
page
);
char
*
in
=
getPosInResultPage
(
pRuntimeEnv
,
j
,
pRows
[
i
],
page
);
memcpy
(
out
,
in
+
oldOffset
*
size
,
size
*
numOfRowsToCopy
);
memcpy
(
out
,
in
+
oldOffset
*
size
,
size
*
numOfRowsToCopy
);
}
}
...
@@ -4422,10 +4178,9 @@ void copyFromWindowResToSData(SQInfo *pQInfo, SResultRowInfo *pResultInfo) {
...
@@ -4422,10 +4178,9 @@ void copyFromWindowResToSData(SQInfo *pQInfo, SResultRowInfo *pResultInfo) {
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
int32_t
orderType
=
(
pQuery
->
pGroupbyExpr
!=
NULL
)
?
pQuery
->
pGroupbyExpr
->
orderType
:
TSDB_ORDER_ASC
;
int32_t
orderType
=
(
pQuery
->
pGroupbyExpr
!=
NULL
)
?
pQuery
->
pGroupbyExpr
->
orderType
:
TSDB_ORDER_ASC
;
int32_t
numOfResult
=
doCopyToSData
(
pQInfo
,
pResultInfo
,
orderType
);
int32_t
numOfResult
=
doCopyToSData
(
pQInfo
,
pResultInfo
->
pResult
,
pResultInfo
->
size
,
&
pQInfo
->
groupIndex
,
orderType
);
pQuery
->
rec
.
rows
+=
numOfResult
;
pQuery
->
rec
.
rows
+=
numOfResult
;
assert
(
pQuery
->
rec
.
rows
<=
pQuery
->
rec
.
capacity
);
assert
(
pQuery
->
rec
.
rows
<=
pQuery
->
rec
.
capacity
);
}
}
...
@@ -4457,25 +4212,17 @@ static void stableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBloc
...
@@ -4457,25 +4212,17 @@ static void stableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBloc
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
STableQueryInfo
*
pTableQueryInfo
=
pQuery
->
current
;
STableQueryInfo
*
pTableQueryInfo
=
pQuery
->
current
;
SResultRowInfo
*
p
WindowRes
Info
=
&
pTableQueryInfo
->
windowResInfo
;
SResultRowInfo
*
p
ResultRow
Info
=
&
pTableQueryInfo
->
windowResInfo
;
pQuery
->
pos
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
0
:
pDataBlockInfo
->
rows
-
1
;
pQuery
->
pos
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
0
:
pDataBlockInfo
->
rows
-
1
;
if
(
pQuery
->
numOfFilterCols
>
0
||
pRuntimeEnv
->
pTsBuf
!=
NULL
||
pRuntimeEnv
->
groupbyNormalCol
)
{
if
(
pQuery
->
numOfFilterCols
>
0
||
pRuntimeEnv
->
pTsBuf
!=
NULL
||
pRuntimeEnv
->
groupbyNormalCol
)
{
rowwiseApplyFunctions
(
pRuntimeEnv
,
pStatis
,
pDataBlockInfo
,
p
WindowRes
Info
,
pDataBlock
);
rowwiseApplyFunctions
(
pRuntimeEnv
,
pStatis
,
pDataBlockInfo
,
p
ResultRow
Info
,
pDataBlock
);
}
else
{
}
else
{
blockwiseApplyFunctions
(
pRuntimeEnv
,
pStatis
,
pDataBlockInfo
,
p
WindowRes
Info
,
searchFn
,
pDataBlock
);
blockwiseApplyFunctions
(
pRuntimeEnv
,
pStatis
,
pDataBlockInfo
,
p
ResultRow
Info
,
searchFn
,
pDataBlock
);
}
}
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
))
{
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
))
{
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pQuery
);
updateResultRowIndex
(
pResultRowInfo
,
pTableQueryInfo
,
QUERY_IS_ASC_QUERY
(
pQuery
));
// TODO refactor
if
((
pTableQueryInfo
->
lastKey
>=
pTableQueryInfo
->
win
.
ekey
&&
ascQuery
)
||
(
pTableQueryInfo
->
lastKey
<=
pTableQueryInfo
->
win
.
ekey
&&
(
!
ascQuery
)))
{
closeAllResultRows
(
pWindowResInfo
);
pWindowResInfo
->
curIndex
=
pWindowResInfo
->
size
-
1
;
}
else
{
updateResultRowCurrentIndex
(
pWindowResInfo
,
pTableQueryInfo
->
lastKey
,
ascQuery
);
}
}
}
}
}
...
@@ -4809,13 +4556,10 @@ static bool skipTimeInterval(SQueryRuntimeEnv *pRuntimeEnv, TSKEY* start) {
...
@@ -4809,13 +4556,10 @@ static bool skipTimeInterval(SQueryRuntimeEnv *pRuntimeEnv, TSKEY* start) {
if
(
QUERY_IS_ASC_QUERY
(
pQuery
))
{
if
(
QUERY_IS_ASC_QUERY
(
pQuery
))
{
if
(
pWindowResInfo
->
prevSKey
==
TSKEY_INITIAL_VAL
)
{
if
(
pWindowResInfo
->
prevSKey
==
TSKEY_INITIAL_VAL
)
{
getAlignQueryTimeWindow
(
pQuery
,
blockInfo
.
window
.
skey
,
blockInfo
.
window
.
skey
,
pQuery
->
window
.
ekey
,
&
w
);
getAlignQueryTimeWindow
(
pQuery
,
blockInfo
.
window
.
skey
,
blockInfo
.
window
.
skey
,
pQuery
->
window
.
ekey
,
&
w
);
pWindowResInfo
->
startTime
=
w
.
skey
;
pWindowResInfo
->
prevSKey
=
w
.
skey
;
pWindowResInfo
->
prevSKey
=
w
.
skey
;
}
}
}
else
{
}
else
{
getAlignQueryTimeWindow
(
pQuery
,
blockInfo
.
window
.
ekey
,
pQuery
->
window
.
ekey
,
blockInfo
.
window
.
ekey
,
&
w
);
getAlignQueryTimeWindow
(
pQuery
,
blockInfo
.
window
.
ekey
,
pQuery
->
window
.
ekey
,
blockInfo
.
window
.
ekey
,
&
w
);
pWindowResInfo
->
startTime
=
pQuery
->
window
.
skey
;
pWindowResInfo
->
prevSKey
=
w
.
skey
;
pWindowResInfo
->
prevSKey
=
w
.
skey
;
}
}
...
@@ -5766,6 +5510,7 @@ static void doRestoreContext(SQInfo *pQInfo) {
...
@@ -5766,6 +5510,7 @@ static void doRestoreContext(SQInfo *pQInfo) {
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
SWAP
(
pQuery
->
window
.
skey
,
pQuery
->
window
.
ekey
,
TSKEY
);
SWITCH_ORDER
(
pQuery
->
order
.
order
);
if
(
pRuntimeEnv
->
pTsBuf
!=
NULL
)
{
if
(
pRuntimeEnv
->
pTsBuf
!=
NULL
)
{
SWITCH_ORDER
(
pRuntimeEnv
->
pTsBuf
->
cur
.
order
);
SWITCH_ORDER
(
pRuntimeEnv
->
pTsBuf
->
cur
.
order
);
...
@@ -5805,9 +5550,6 @@ static void multiTableQueryProcess(SQInfo *pQInfo) {
...
@@ -5805,9 +5550,6 @@ static void multiTableQueryProcess(SQInfo *pQInfo) {
*/
*/
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
))
{
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
))
{
copyResToQueryResultBuf
(
pQInfo
,
pQuery
);
copyResToQueryResultBuf
(
pQInfo
,
pQuery
);
#ifdef _DEBUG_VIEW
displayInterResult
(
pQuery
->
sdata
,
pRuntimeEnv
,
pQuery
->
sdata
[
0
]
->
num
);
#endif
}
else
{
}
else
{
copyFromWindowResToSData
(
pQInfo
,
&
pRuntimeEnv
->
windowResInfo
);
copyFromWindowResToSData
(
pQInfo
,
&
pRuntimeEnv
->
windowResInfo
);
}
}
...
@@ -5852,7 +5594,7 @@ static void multiTableQueryProcess(SQInfo *pQInfo) {
...
@@ -5852,7 +5594,7 @@ static void multiTableQueryProcess(SQInfo *pQInfo) {
}
}
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
)
||
isSumAvgRateQuery
(
pQuery
))
{
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
)
||
isSumAvgRateQuery
(
pQuery
))
{
if
(
merge
Into
GroupResult
(
pQInfo
)
==
TSDB_CODE_SUCCESS
)
{
if
(
mergeGroupResult
(
pQInfo
)
==
TSDB_CODE_SUCCESS
)
{
copyResToQueryResultBuf
(
pQInfo
,
pQuery
);
copyResToQueryResultBuf
(
pQInfo
,
pQuery
);
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
...
@@ -6024,33 +5766,6 @@ static void tableMultiOutputProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo)
...
@@ -6024,33 +5766,6 @@ static void tableMultiOutputProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo)
}
}
}
}
static
void
tableIntervalProcessImpl
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
TSKEY
start
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
while
(
1
)
{
scanOneTableDataBlocks
(
pRuntimeEnv
,
start
);
assert
(
!
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_NOT_COMPLETED
));
finalizeQueryResult
(
pRuntimeEnv
);
// here we can ignore the records in case of no interpolation
// todo handle offset, in case of top/bottom interval query
if
((
pQuery
->
numOfFilterCols
>
0
||
pRuntimeEnv
->
pTsBuf
!=
NULL
)
&&
pQuery
->
limit
.
offset
>
0
&&
pQuery
->
fillType
==
TSDB_FILL_NONE
)
{
// maxOutput <= 0, means current query does not generate any results
int32_t
numOfClosed
=
numOfClosedResultRows
(
&
pRuntimeEnv
->
windowResInfo
);
int32_t
c
=
(
int32_t
)(
MIN
(
numOfClosed
,
pQuery
->
limit
.
offset
));
popFrontResultRow
(
pRuntimeEnv
,
&
pRuntimeEnv
->
windowResInfo
,
c
);
pQuery
->
limit
.
offset
-=
c
;
}
if
(
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_COMPLETED
|
QUERY_RESBUF_FULL
))
{
break
;
}
}
}
// handle time interval query on table
// handle time interval query on table
static
void
tableIntervalProcess
(
SQInfo
*
pQInfo
,
STableQueryInfo
*
pTableInfo
)
{
static
void
tableIntervalProcess
(
SQInfo
*
pQInfo
,
STableQueryInfo
*
pTableInfo
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
(
pQInfo
->
runtimeEnv
);
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
(
pQInfo
->
runtimeEnv
);
...
@@ -6058,7 +5773,6 @@ static void tableIntervalProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo) {
...
@@ -6058,7 +5773,6 @@ static void tableIntervalProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo) {
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
pQuery
->
current
=
pTableInfo
;
pQuery
->
current
=
pTableInfo
;
int32_t
numOfFilled
=
0
;
TSKEY
newStartKey
=
TSKEY_INITIAL_VAL
;
TSKEY
newStartKey
=
TSKEY_INITIAL_VAL
;
// skip blocks without load the actual data block from file if no filter condition present
// skip blocks without load the actual data block from file if no filter condition present
...
@@ -6070,59 +5784,39 @@ static void tableIntervalProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo) {
...
@@ -6070,59 +5784,39 @@ static void tableIntervalProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo) {
}
}
}
}
while
(
1
)
{
scanOneTableDataBlocks
(
pRuntimeEnv
,
newStartKey
);
tableIntervalProcessImpl
(
pRuntimeEnv
,
newStartKey
);
assert
(
!
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_NOT_COMPLETED
)
);
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
))
{
finalizeQueryResult
(
pRuntimeEnv
);
pQInfo
->
groupIndex
=
0
;
// always start from 0
pQuery
->
rec
.
rows
=
0
;
copyFromWindowResToSData
(
pQInfo
,
&
pRuntimeEnv
->
windowResInfo
);
popFrontResultRow
(
pRuntimeEnv
,
&
pRuntimeEnv
->
windowResInfo
,
pQInfo
->
groupIndex
);
// skip offset result rows
}
pQuery
->
rec
.
rows
=
0
;
// no result generated, abort
if
(
pQuery
->
fillType
==
TSDB_FILL_NONE
)
{
if
(
pQuery
->
rec
.
rows
==
0
||
pRuntimeEnv
->
groupbyNormalCol
)
{
// all data scanned, the group by normal column can return
break
;
int32_t
numOfClosed
=
numOfClosedResultRows
(
&
pRuntimeEnv
->
windowResInfo
);
if
(
pQuery
->
limit
.
offset
>
numOfClosed
)
{
return
;
}
}
doSecondaryArithmeticProcess
(
pQuery
);
pQInfo
->
groupIndex
=
(
int32_t
)
pQuery
->
limit
.
offset
;
// the offset is handled at prepare stage if no interpolation involved
if
(
pQuery
->
fillType
==
TSDB_FILL_NONE
)
{
limitResults
(
pRuntimeEnv
);
break
;
}
else
{
taosFillSetStartInfo
(
pRuntimeEnv
->
pFillInfo
,
(
int32_t
)
pQuery
->
rec
.
rows
,
pQuery
->
window
.
ekey
);
taosFillCopyInputDataFromFilePage
(
pRuntimeEnv
->
pFillInfo
,
(
const
tFilePage
**
)
pQuery
->
sdata
);
numOfFilled
=
0
;
pQuery
->
rec
.
rows
=
doFillGapsInResults
(
pRuntimeEnv
,
(
tFilePage
**
)
pQuery
->
sdata
,
&
numOfFilled
);
copyFromWindowResToSData
(
pQInfo
,
&
pRuntimeEnv
->
windowResInfo
);
if
(
pQuery
->
rec
.
rows
>
0
||
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_COMPLETED
))
{
doSecondaryArithmeticProcess
(
pQuery
);
limitResults
(
pRuntimeEnv
);
break
;
}
// no result generated yet, continue retrieve data
limitResults
(
pRuntimeEnv
);
pQuery
->
rec
.
rows
=
0
;
}
else
{
}
}
// all data scanned, the group by normal column can return
copyFromWindowResToSData
(
pQInfo
,
&
pRuntimeEnv
->
windowResInfo
);
if
(
pRuntimeEnv
->
groupbyNormalCol
)
{
// todo refactor with merge interval time result
doSecondaryArithmeticProcess
(
pQuery
);
// maxOutput <= 0, means current query does not generate any results
int32_t
numOfClosed
=
numOfClosedResultRows
(
&
pRuntimeEnv
->
windowResInfo
);
if
((
pQuery
->
limit
.
offset
>
0
&&
pQuery
->
limit
.
offset
<
numOfClosed
)
||
pQuery
->
limit
.
offset
==
0
)
{
taosFillSetStartInfo
(
pRuntimeEnv
->
pFillInfo
,
(
int32_t
)
pQuery
->
rec
.
rows
,
pQuery
->
window
.
ekey
);
// skip offset result rows
taosFillCopyInputDataFromFilePage
(
pRuntimeEnv
->
pFillInfo
,
(
const
tFilePage
**
)
pQuery
->
sdata
);
popFrontResultRow
(
pRuntimeEnv
,
&
pRuntimeEnv
->
windowResInfo
,
(
int32_t
)
pQuery
->
limit
.
offset
);
pQuery
->
rec
.
rows
=
0
;
int32_t
numOfFilled
=
0
;
pQInfo
->
groupIndex
=
0
;
pQuery
->
rec
.
rows
=
doFillGapsInResults
(
pRuntimeEnv
,
(
tFilePage
**
)
pQuery
->
sdata
,
&
numOfFilled
);
copyFromWindowResToSData
(
pQInfo
,
&
pRuntimeEnv
->
windowResInfo
);
popFrontResultRow
(
pRuntimeEnv
,
&
pRuntimeEnv
->
windowResInfo
,
pQInfo
->
groupIndex
);
doSecondaryArithmeticProcess
(
pQuery
);
if
(
pQuery
->
rec
.
rows
>
0
||
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_COMPLETED
))
{
limitResults
(
pRuntimeEnv
);
limitResults
(
pRuntimeEnv
);
}
}
}
}
...
@@ -6133,7 +5827,6 @@ static void tableQueryImpl(SQInfo *pQInfo) {
...
@@ -6133,7 +5827,6 @@ static void tableQueryImpl(SQInfo *pQInfo) {
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
if
(
queryHasRemainResForTableQuery
(
pRuntimeEnv
))
{
if
(
queryHasRemainResForTableQuery
(
pRuntimeEnv
))
{
if
(
pQuery
->
fillType
!=
TSDB_FILL_NONE
)
{
if
(
pQuery
->
fillType
!=
TSDB_FILL_NONE
)
{
/*
/*
* There are remain results that are not returned due to result interpolation
* There are remain results that are not returned due to result interpolation
...
@@ -6150,23 +5843,23 @@ static void tableQueryImpl(SQInfo *pQInfo) {
...
@@ -6150,23 +5843,23 @@ static void tableQueryImpl(SQInfo *pQInfo) {
return
;
return
;
}
else
{
}
else
{
pQuery
->
rec
.
rows
=
0
;
pQuery
->
rec
.
rows
=
0
;
pQInfo
->
groupIndex
=
0
;
// always start from 0
assert
(
pRuntimeEnv
->
windowResInfo
.
size
>
0
);
if
(
p
RuntimeEnv
->
windowResInfo
.
size
>
0
)
{
if
(
p
QInfo
->
groupIndex
<
pRuntimeEnv
->
windowResInfo
.
size
)
{
copyFromWindowResToSData
(
pQInfo
,
&
pRuntimeEnv
->
windowResInfo
);
copyFromWindowResToSData
(
pQInfo
,
&
pRuntimeEnv
->
windowResInfo
);
popFrontResultRow
(
pRuntimeEnv
,
&
pRuntimeEnv
->
windowResInfo
,
pQInfo
->
groupIndex
);
}
if
(
pQuery
->
rec
.
rows
>
0
)
{
qDebug
(
"QInfo:%p %"
PRId64
" rows returned from group results, total:%"
PRId64
""
,
pQInfo
,
pQuery
->
rec
.
rows
,
pQuery
->
rec
.
total
);
// there are not data remains
if
(
pQuery
->
rec
.
rows
>
0
)
{
if
(
pRuntimeEnv
->
windowResInfo
.
size
<=
0
)
{
qDebug
(
"QInfo:%p %"
PRId64
" rows returned from group results, total:%"
PRId64
""
,
pQInfo
,
pQuery
->
rec
.
rows
,
qDebug
(
"QInfo:%p query over, %"
PRId64
" rows are returned"
,
pQInfo
,
pQuery
->
rec
.
total
);
pQuery
->
rec
.
total
);
}
}
return
;
// there are not data remains
}
if
(
pQuery
->
rec
.
rows
<=
0
||
pRuntimeEnv
->
windowResInfo
.
size
<=
pQInfo
->
groupIndex
)
{
qDebug
(
"QInfo:%p query over, %"
PRId64
" rows are returned"
,
pQInfo
,
pQuery
->
rec
.
total
);
}
}
return
;
}
}
}
}
...
@@ -7284,6 +6977,8 @@ static void freeQInfo(SQInfo *pQInfo) {
...
@@ -7284,6 +6977,8 @@ static void freeQInfo(SQInfo *pQInfo) {
tsdbDestroyTableGroup
(
&
pQInfo
->
tableGroupInfo
);
tsdbDestroyTableGroup
(
&
pQInfo
->
tableGroupInfo
);
taosHashCleanup
(
pQInfo
->
arrTableIdInfo
);
taosHashCleanup
(
pQInfo
->
arrTableIdInfo
);
taosArrayDestroy
(
pQInfo
->
groupResInfo
.
pRows
);
pQInfo
->
signature
=
0
;
pQInfo
->
signature
=
0
;
qDebug
(
"QInfo:%p QInfo is freed"
,
pQInfo
);
qDebug
(
"QInfo:%p QInfo is freed"
,
pQInfo
);
...
@@ -7703,7 +7398,7 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co
...
@@ -7703,7 +7398,7 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co
(
*
pRsp
)
->
completed
=
1
;
// notify no more result to client
(
*
pRsp
)
->
completed
=
1
;
// notify no more result to client
}
else
{
}
else
{
*
continueExec
=
true
;
*
continueExec
=
true
;
qDebug
(
"QInfo:%p has more results
waits for client
retrieve"
,
pQInfo
);
qDebug
(
"QInfo:%p has more results
to
retrieve"
,
pQInfo
);
}
}
return
pQInfo
->
code
;
return
pQInfo
->
code
;
...
@@ -7981,9 +7676,9 @@ void qQueryMgmtNotifyClosed(void* pQMgmt) {
...
@@ -7981,9 +7676,9 @@ void qQueryMgmtNotifyClosed(void* pQMgmt) {
SQueryMgmt
*
pQueryMgmt
=
pQMgmt
;
SQueryMgmt
*
pQueryMgmt
=
pQMgmt
;
qDebug
(
"vgId:%d, set querymgmt closed, wait for all queries cancelled"
,
pQueryMgmt
->
vgId
);
qDebug
(
"vgId:%d, set querymgmt closed, wait for all queries cancelled"
,
pQueryMgmt
->
vgId
);
//
pthread_mutex_lock(&pQueryMgmt->lock);
pthread_mutex_lock
(
&
pQueryMgmt
->
lock
);
pQueryMgmt
->
closed
=
true
;
pQueryMgmt
->
closed
=
true
;
//
pthread_mutex_unlock(&pQueryMgmt->lock);
pthread_mutex_unlock
(
&
pQueryMgmt
->
lock
);
taosCacheRefresh
(
pQueryMgmt
->
qinfoPool
,
queryMgmtKillQueryFn
);
taosCacheRefresh
(
pQueryMgmt
->
qinfoPool
,
queryMgmtKillQueryFn
);
}
}
...
@@ -8021,9 +7716,9 @@ void** qRegisterQInfo(void* pMgmt, uint64_t qInfo) {
...
@@ -8021,9 +7716,9 @@ void** qRegisterQInfo(void* pMgmt, uint64_t qInfo) {
return
NULL
;
return
NULL
;
}
}
//
pthread_mutex_lock(&pQueryMgmt->lock);
pthread_mutex_lock
(
&
pQueryMgmt
->
lock
);
if
(
pQueryMgmt
->
closed
)
{
if
(
pQueryMgmt
->
closed
)
{
//
pthread_mutex_unlock(&pQueryMgmt->lock);
pthread_mutex_unlock
(
&
pQueryMgmt
->
lock
);
qError
(
"QInfo:%p failed to add qhandle into cache, since qMgmt is colsing"
,
(
void
*
)
qInfo
);
qError
(
"QInfo:%p failed to add qhandle into cache, since qMgmt is colsing"
,
(
void
*
)
qInfo
);
terrno
=
TSDB_CODE_VND_INVALID_VGROUP_ID
;
terrno
=
TSDB_CODE_VND_INVALID_VGROUP_ID
;
return
NULL
;
return
NULL
;
...
@@ -8031,7 +7726,7 @@ void** qRegisterQInfo(void* pMgmt, uint64_t qInfo) {
...
@@ -8031,7 +7726,7 @@ void** qRegisterQInfo(void* pMgmt, uint64_t qInfo) {
TSDB_CACHE_PTR_TYPE
handleVal
=
(
TSDB_CACHE_PTR_TYPE
)
qInfo
;
TSDB_CACHE_PTR_TYPE
handleVal
=
(
TSDB_CACHE_PTR_TYPE
)
qInfo
;
void
**
handle
=
taosCachePut
(
pQueryMgmt
->
qinfoPool
,
&
handleVal
,
sizeof
(
TSDB_CACHE_PTR_TYPE
),
&
qInfo
,
sizeof
(
TSDB_CACHE_PTR_TYPE
),
void
**
handle
=
taosCachePut
(
pQueryMgmt
->
qinfoPool
,
&
handleVal
,
sizeof
(
TSDB_CACHE_PTR_TYPE
),
&
qInfo
,
sizeof
(
TSDB_CACHE_PTR_TYPE
),
(
getMaximumIdleDurationSec
()
*
1000
));
(
getMaximumIdleDurationSec
()
*
1000
));
//
pthread_mutex_unlock(&pQueryMgmt->lock);
pthread_mutex_unlock
(
&
pQueryMgmt
->
lock
);
return
handle
;
return
handle
;
}
}
...
@@ -8068,6 +7763,4 @@ void** qReleaseQInfo(void* pMgmt, void* pQInfo, bool freeHandle) {
...
@@ -8068,6 +7763,4 @@ void** qReleaseQInfo(void* pMgmt, void* pQInfo, bool freeHandle) {
taosCacheRelease
(
pQueryMgmt
->
qinfoPool
,
pQInfo
,
freeHandle
);
taosCacheRelease
(
pQueryMgmt
->
qinfoPool
,
pQInfo
,
freeHandle
);
return
0
;
return
0
;
}
}
\ No newline at end of file
src/query/src/qHistogram.c
浏览文件 @
cca70151
...
@@ -120,6 +120,7 @@
...
@@ -120,6 +120,7 @@
//}
//}
static
int32_t
histogramCreateBin
(
SHistogramInfo
*
pHisto
,
int32_t
index
,
double
val
);
static
int32_t
histogramCreateBin
(
SHistogramInfo
*
pHisto
,
int32_t
index
,
double
val
);
static
int32_t
histoBinarySearch
(
SHistBin
*
pEntry
,
int32_t
len
,
double
val
);
SHistogramInfo
*
tHistogramCreate
(
int32_t
numOfEntries
)
{
SHistogramInfo
*
tHistogramCreate
(
int32_t
numOfEntries
)
{
/* need one redundant slot */
/* need one redundant slot */
...
@@ -158,8 +159,8 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
...
@@ -158,8 +159,8 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
}
}
#if defined(USE_ARRAYLIST)
#if defined(USE_ARRAYLIST)
int32_t
idx
=
vnodeHistob
inarySearch
((
*
pHisto
)
->
elems
,
(
*
pHisto
)
->
numOfEntries
,
val
);
int32_t
idx
=
histoB
inarySearch
((
*
pHisto
)
->
elems
,
(
*
pHisto
)
->
numOfEntries
,
val
);
assert
(
idx
>=
0
&&
idx
<=
(
*
pHisto
)
->
maxEntries
);
assert
(
idx
>=
0
&&
idx
<=
(
*
pHisto
)
->
maxEntries
&&
(
*
pHisto
)
->
elems
!=
NULL
);
if
((
*
pHisto
)
->
elems
[
idx
].
val
==
val
&&
idx
>=
0
)
{
if
((
*
pHisto
)
->
elems
[
idx
].
val
==
val
&&
idx
>=
0
)
{
(
*
pHisto
)
->
elems
[
idx
].
num
+=
1
;
(
*
pHisto
)
->
elems
[
idx
].
num
+=
1
;
...
@@ -356,7 +357,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
...
@@ -356,7 +357,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
return
0
;
return
0
;
}
}
int32_t
vnodeHistob
inarySearch
(
SHistBin
*
pEntry
,
int32_t
len
,
double
val
)
{
int32_t
histoB
inarySearch
(
SHistBin
*
pEntry
,
int32_t
len
,
double
val
)
{
int32_t
end
=
len
-
1
;
int32_t
end
=
len
-
1
;
int32_t
start
=
0
;
int32_t
start
=
0
;
...
@@ -466,7 +467,7 @@ void tHistogramPrint(SHistogramInfo* pHisto) {
...
@@ -466,7 +467,7 @@ void tHistogramPrint(SHistogramInfo* pHisto) {
*/
*/
int64_t
tHistogramSum
(
SHistogramInfo
*
pHisto
,
double
v
)
{
int64_t
tHistogramSum
(
SHistogramInfo
*
pHisto
,
double
v
)
{
#if defined(USE_ARRAYLIST)
#if defined(USE_ARRAYLIST)
int32_t
slotIdx
=
vnodeHistob
inarySearch
(
pHisto
->
elems
,
pHisto
->
numOfEntries
,
v
);
int32_t
slotIdx
=
histoB
inarySearch
(
pHisto
->
elems
,
pHisto
->
numOfEntries
,
v
);
if
(
pHisto
->
elems
[
slotIdx
].
val
!=
v
)
{
if
(
pHisto
->
elems
[
slotIdx
].
val
!=
v
)
{
slotIdx
-=
1
;
slotIdx
-=
1
;
...
...
src/query/src/qUtil.c
浏览文件 @
cca70151
...
@@ -96,8 +96,6 @@ void resetResultRowInfo(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRo
...
@@ -96,8 +96,6 @@ void resetResultRowInfo(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRo
pResultRowInfo
->
curIndex
=
-
1
;
pResultRowInfo
->
curIndex
=
-
1
;
pResultRowInfo
->
size
=
0
;
pResultRowInfo
->
size
=
0
;
pResultRowInfo
->
startTime
=
TSKEY_INITIAL_VAL
;
pResultRowInfo
->
prevSKey
=
TSKEY_INITIAL_VAL
;
pResultRowInfo
->
prevSKey
=
TSKEY_INITIAL_VAL
;
}
}
...
@@ -110,7 +108,7 @@ void popFrontResultRow(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRow
...
@@ -110,7 +108,7 @@ void popFrontResultRow(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRow
assert
(
num
>=
0
&&
num
<=
numOfClosed
);
assert
(
num
>=
0
&&
num
<=
numOfClosed
);
int16_t
type
=
pResultRowInfo
->
type
;
int16_t
type
=
pResultRowInfo
->
type
;
int64_t
uid
=
getResultInfoUId
(
pRuntimeEnv
)
;
int64_t
uid
=
0
;
char
*
key
=
NULL
;
char
*
key
=
NULL
;
int16_t
bytes
=
-
1
;
int16_t
bytes
=
-
1
;
...
@@ -181,11 +179,12 @@ void closeAllResultRows(SResultRowInfo *pResultRowInfo) {
...
@@ -181,11 +179,12 @@ void closeAllResultRows(SResultRowInfo *pResultRowInfo) {
assert
(
pResultRowInfo
->
size
>=
0
&&
pResultRowInfo
->
capacity
>=
pResultRowInfo
->
size
);
assert
(
pResultRowInfo
->
size
>=
0
&&
pResultRowInfo
->
capacity
>=
pResultRowInfo
->
size
);
for
(
int32_t
i
=
0
;
i
<
pResultRowInfo
->
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pResultRowInfo
->
size
;
++
i
)
{
if
(
pResultRowInfo
->
pResult
[
i
]
->
closed
)
{
SResultRow
*
pRow
=
pResultRowInfo
->
pResult
[
i
];
if
(
pRow
->
closed
)
{
continue
;
continue
;
}
}
pR
esultRowInfo
->
pResult
[
i
]
->
closed
=
true
;
pR
ow
->
closed
=
true
;
}
}
}
}
...
@@ -383,18 +382,4 @@ void* destroyResultRowPool(SResultRowPool* p) {
...
@@ -383,18 +382,4 @@ void* destroyResultRowPool(SResultRowPool* p) {
tfree
(
p
);
tfree
(
p
);
return
NULL
;
return
NULL
;
}
uint64_t
getResultInfoUId
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
if
(
!
pRuntimeEnv
->
stableQuery
)
{
return
0
;
// for simple table query, the uid is always set to be 0;
}
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
if
(
pQuery
->
interval
.
interval
==
0
||
isPointInterpoQuery
(
pQuery
)
||
pRuntimeEnv
->
groupbyNormalCol
)
{
return
0
;
}
STableId
*
id
=
TSDB_TABLEID
(
pRuntimeEnv
->
pQuery
->
current
->
pTable
);
return
id
->
uid
;
}
}
\ No newline at end of file
src/tsdb/inc/tsdbMain.h
浏览文件 @
cca70151
...
@@ -31,19 +31,19 @@
...
@@ -31,19 +31,19 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
extern
in
t
tsdbDebugFlag
;
extern
uint32_
t
tsdbDebugFlag
;
#define tsdbFatal(...)
{ if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TDB FATAL ", 255, __VA_ARGS__); }}
#define tsdbFatal(...)
do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TDB FATAL ", 255, __VA_ARGS__); }} while(0)
#define tsdbError(...)
{ if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TDB ERROR ", 255, __VA_ARGS__); }}
#define tsdbError(...)
do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TDB ERROR ", 255, __VA_ARGS__); }} while(0)
#define tsdbWarn(...)
{ if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TDB WARN ", 255, __VA_ARGS__); }}
#define tsdbWarn(...)
do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TDB WARN ", 255, __VA_ARGS__); }} while(0)
#define tsdbInfo(...)
{ if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TDB ", 255, __VA_ARGS__); }}
#define tsdbInfo(...)
do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TDB ", 255, __VA_ARGS__); }} while(0)
#define tsdbDebug(...)
{ if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }}
#define tsdbDebug(...)
do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }} while(0)
#define tsdbTrace(...)
{ if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }}
#define tsdbTrace(...)
do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TDB ", tsdbDebugFlag, __VA_ARGS__); }} while(0)
#define TSDB_MAX_TABLE_SCHEMAS 16
#define TSDB_MAX_TABLE_SCHEMAS 16
#define TSDB_FILE_HEAD_SIZE 512
#define TSDB_FILE_HEAD_SIZE
512
#define TSDB_FILE_DELIMITER 0xF00AFA0F
#define TSDB_FILE_DELIMITER
0xF00AFA0F
#define TSDB_FILE_INIT_MAGIC 0xFFFFFFFF
#define TSDB_FILE_INIT_MAGIC
0xFFFFFFFF
#define TAOS_IN_RANGE(key, keyMin, keyLast) (((key) >= (keyMin)) && ((key) <= (keyMax)))
#define TAOS_IN_RANGE(key, keyMin, keyLast) (((key) >= (keyMin)) && ((key) <= (keyMax)))
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
cca70151
...
@@ -956,9 +956,9 @@ static int32_t loadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBl
...
@@ -956,9 +956,9 @@ static int32_t loadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBl
return
code
;
return
code
;
}
}
SDataCols
*
pT
S
Col
=
pQueryHandle
->
rhelper
.
pDataCols
[
0
];
SDataCols
*
pT
s
Col
=
pQueryHandle
->
rhelper
.
pDataCols
[
0
];
if
(
pCheckInfo
->
lastKey
<
pBlock
->
keyLast
)
{
if
(
pCheckInfo
->
lastKey
<
pBlock
->
keyLast
)
{
cur
->
pos
=
binarySearchForKey
(
pT
S
Col
->
cols
[
0
].
pData
,
pBlock
->
numOfRows
,
pCheckInfo
->
lastKey
,
pQueryHandle
->
order
);
cur
->
pos
=
binarySearchForKey
(
pT
s
Col
->
cols
[
0
].
pData
,
pBlock
->
numOfRows
,
pCheckInfo
->
lastKey
,
pQueryHandle
->
order
);
}
else
{
}
else
{
cur
->
pos
=
pBlock
->
numOfRows
-
1
;
cur
->
pos
=
pBlock
->
numOfRows
-
1
;
}
}
...
@@ -1704,7 +1704,32 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO
...
@@ -1704,7 +1704,32 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
getDataBlocksInFilesImpl
(
STsdbQueryHandle
*
pQueryHandle
,
bool
*
exists
)
{
static
int32_t
getFirstFileDataBlock
(
STsdbQueryHandle
*
pQueryHandle
,
bool
*
exists
);
static
int32_t
getDataBlockRv
(
STsdbQueryHandle
*
pQueryHandle
,
STableBlockInfo
*
pNext
,
bool
*
exists
)
{
int32_t
step
=
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
)
?
1
:
-
1
;
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
while
(
1
)
{
int32_t
code
=
loadFileDataBlock
(
pQueryHandle
,
pNext
->
compBlock
,
pNext
->
pTableCheckInfo
,
exists
);
if
(
code
!=
TSDB_CODE_SUCCESS
||
*
exists
)
{
return
code
;
}
if
((
cur
->
slot
==
pQueryHandle
->
numOfBlocks
-
1
&&
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
))
||
(
cur
->
slot
==
0
&&
!
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
)))
{
// all data blocks in current file has been checked already, try next file if exists
return
getFirstFileDataBlock
(
pQueryHandle
,
exists
);
}
else
{
// next block of the same file
cur
->
slot
+=
step
;
cur
->
mixBlock
=
false
;
cur
->
blockCompleted
=
false
;
pNext
=
&
pQueryHandle
->
pDataBlockInfo
[
cur
->
slot
];
}
}
}
static
int32_t
getFirstFileDataBlock
(
STsdbQueryHandle
*
pQueryHandle
,
bool
*
exists
)
{
pQueryHandle
->
numOfBlocks
=
0
;
pQueryHandle
->
numOfBlocks
=
0
;
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
...
@@ -1789,7 +1814,23 @@ static int32_t getDataBlocksInFilesImpl(STsdbQueryHandle* pQueryHandle, bool* ex
...
@@ -1789,7 +1814,23 @@ static int32_t getDataBlocksInFilesImpl(STsdbQueryHandle* pQueryHandle, bool* ex
cur
->
fid
=
pQueryHandle
->
pFileGroup
->
fileId
;
cur
->
fid
=
pQueryHandle
->
pFileGroup
->
fileId
;
STableBlockInfo
*
pBlockInfo
=
&
pQueryHandle
->
pDataBlockInfo
[
cur
->
slot
];
STableBlockInfo
*
pBlockInfo
=
&
pQueryHandle
->
pDataBlockInfo
[
cur
->
slot
];
return
loadFileDataBlock
(
pQueryHandle
,
pBlockInfo
->
compBlock
,
pBlockInfo
->
pTableCheckInfo
,
exists
);
return
getDataBlockRv
(
pQueryHandle
,
pBlockInfo
,
exists
);
}
static
bool
isEndFileDataBlock
(
SQueryFilePos
*
cur
,
int32_t
numOfBlocks
,
bool
ascTrav
)
{
assert
(
cur
!=
NULL
&&
numOfBlocks
>
0
);
return
(
cur
->
slot
==
numOfBlocks
-
1
&&
ascTrav
)
||
(
cur
->
slot
==
0
&&
!
ascTrav
);
}
static
void
moveToNextDataBlockInCurrentFile
(
STsdbQueryHandle
*
pQueryHandle
)
{
int32_t
step
=
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
)
?
1
:
-
1
;
SQueryFilePos
*
cur
=
&
pQueryHandle
->
cur
;
assert
(
cur
->
slot
<
pQueryHandle
->
numOfBlocks
&&
cur
->
slot
>=
0
);
cur
->
slot
+=
step
;
cur
->
mixBlock
=
false
;
cur
->
blockCompleted
=
false
;
}
}
static
int32_t
getDataBlocksInFiles
(
STsdbQueryHandle
*
pQueryHandle
,
bool
*
exists
)
{
static
int32_t
getDataBlocksInFiles
(
STsdbQueryHandle
*
pQueryHandle
,
bool
*
exists
)
{
...
@@ -1800,14 +1841,14 @@ static int32_t getDataBlocksInFiles(STsdbQueryHandle* pQueryHandle, bool* exists
...
@@ -1800,14 +1841,14 @@ static int32_t getDataBlocksInFiles(STsdbQueryHandle* pQueryHandle, bool* exists
if
(
!
pQueryHandle
->
locateStart
)
{
if
(
!
pQueryHandle
->
locateStart
)
{
pQueryHandle
->
locateStart
=
true
;
pQueryHandle
->
locateStart
=
true
;
STsdbCfg
*
pCfg
=
&
pQueryHandle
->
pTsdb
->
config
;
STsdbCfg
*
pCfg
=
&
pQueryHandle
->
pTsdb
->
config
;
int32_t
fid
=
getFileIdFromKey
(
pQueryHandle
->
window
.
skey
,
pCfg
->
daysPerFile
,
pCfg
->
precision
);
int32_t
fid
=
getFileIdFromKey
(
pQueryHandle
->
window
.
skey
,
pCfg
->
daysPerFile
,
pCfg
->
precision
);
pthread_rwlock_rdlock
(
&
pQueryHandle
->
pTsdb
->
tsdbFileH
->
fhlock
);
pthread_rwlock_rdlock
(
&
pQueryHandle
->
pTsdb
->
tsdbFileH
->
fhlock
);
tsdbInitFileGroupIter
(
pFileHandle
,
&
pQueryHandle
->
fileIter
,
pQueryHandle
->
order
);
tsdbInitFileGroupIter
(
pFileHandle
,
&
pQueryHandle
->
fileIter
,
pQueryHandle
->
order
);
tsdbSeekFileGroupIter
(
&
pQueryHandle
->
fileIter
,
fid
);
tsdbSeekFileGroupIter
(
&
pQueryHandle
->
fileIter
,
fid
);
pthread_rwlock_unlock
(
&
pQueryHandle
->
pTsdb
->
tsdbFileH
->
fhlock
);
pthread_rwlock_unlock
(
&
pQueryHandle
->
pTsdb
->
tsdbFileH
->
fhlock
);
return
get
DataBlocksInFilesImpl
(
pQueryHandle
,
exists
);
return
get
FirstFileDataBlock
(
pQueryHandle
,
exists
);
}
else
{
}
else
{
// check if current file block is all consumed
// check if current file block is all consumed
STableBlockInfo
*
pBlockInfo
=
&
pQueryHandle
->
pDataBlockInfo
[
cur
->
slot
];
STableBlockInfo
*
pBlockInfo
=
&
pQueryHandle
->
pDataBlockInfo
[
cur
->
slot
];
...
@@ -1815,27 +1856,26 @@ static int32_t getDataBlocksInFiles(STsdbQueryHandle* pQueryHandle, bool* exists
...
@@ -1815,27 +1856,26 @@ static int32_t getDataBlocksInFiles(STsdbQueryHandle* pQueryHandle, bool* exists
// current block is done, try next
// current block is done, try next
if
((
!
cur
->
mixBlock
)
||
cur
->
blockCompleted
)
{
if
((
!
cur
->
mixBlock
)
||
cur
->
blockCompleted
)
{
if
((
cur
->
slot
==
pQueryHandle
->
numOfBlocks
-
1
&&
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
))
||
// all data blocks in current file has been checked already, try next file if exists
(
cur
->
slot
==
0
&&
!
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
)))
{
// all data blocks in current file has been checked already, try next file if exists
return
getDataBlocksInFilesImpl
(
pQueryHandle
,
exists
);
}
else
{
// next block of the same file
int32_t
step
=
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
)
?
1
:
-
1
;
cur
->
slot
+=
step
;
cur
->
mixBlock
=
false
;
cur
->
blockCompleted
=
false
;
STableBlockInfo
*
pNext
=
&
pQueryHandle
->
pDataBlockInfo
[
cur
->
slot
];
return
loadFileDataBlock
(
pQueryHandle
,
pNext
->
compBlock
,
pNext
->
pTableCheckInfo
,
exists
);
}
}
else
{
}
else
{
tsdbDebug
(
"%p continue in current data block, index:%d, pos:%d, %p"
,
pQueryHandle
,
cur
->
slot
,
cur
->
pos
,
pQueryHandle
->
qinfo
);
tsdbDebug
(
"%p continue in current data block, index:%d, pos:%d, %p"
,
pQueryHandle
,
cur
->
slot
,
cur
->
pos
,
pQueryHandle
->
qinfo
);
int32_t
code
=
handleDataMergeIfNeeded
(
pQueryHandle
,
pBlockInfo
->
compBlock
,
pCheckInfo
);
int32_t
code
=
handleDataMergeIfNeeded
(
pQueryHandle
,
pBlockInfo
->
compBlock
,
pCheckInfo
);
*
exists
=
pQueryHandle
->
realNumOfRows
>
0
;
*
exists
=
(
pQueryHandle
->
realNumOfRows
>
0
)
;
return
code
;
if
(
code
!=
TSDB_CODE_SUCCESS
||
*
exists
)
{
return
code
;
}
}
// current block is empty, try next block in file
// all data blocks in current file has been checked already, try next file if exists
if
(
isEndFileDataBlock
(
cur
,
pQueryHandle
->
numOfBlocks
,
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
)))
{
return
getFirstFileDataBlock
(
pQueryHandle
,
exists
);
}
else
{
moveToNextDataBlockInCurrentFile
(
pQueryHandle
);
STableBlockInfo
*
pNext
=
&
pQueryHandle
->
pDataBlockInfo
[
cur
->
slot
];
return
getDataBlockRv
(
pQueryHandle
,
pNext
,
exists
);
}
}
}
}
}
}
...
...
src/util/src/tcache.c
浏览文件 @
cca70151
...
@@ -547,13 +547,14 @@ void taosAddToTrashcan(SCacheObj *pCacheObj, SCacheDataNode *pNode) {
...
@@ -547,13 +547,14 @@ void taosAddToTrashcan(SCacheObj *pCacheObj, SCacheDataNode *pNode) {
return
;
return
;
}
}
__cache_wr_lock
(
pCacheObj
);
STrashElem
*
pElem
=
calloc
(
1
,
sizeof
(
STrashElem
));
STrashElem
*
pElem
=
calloc
(
1
,
sizeof
(
STrashElem
));
pElem
->
pData
=
pNode
;
pElem
->
pData
=
pNode
;
pElem
->
prev
=
NULL
;
pElem
->
prev
=
NULL
;
pElem
->
next
=
NULL
;
pNode
->
inTrashcan
=
true
;
pNode
->
inTrashcan
=
true
;
pNode
->
pTNodeHeader
=
pElem
;
pNode
->
pTNodeHeader
=
pElem
;
__cache_wr_lock
(
pCacheObj
);
pElem
->
next
=
pCacheObj
->
pTrash
;
pElem
->
next
=
pCacheObj
->
pTrash
;
if
(
pCacheObj
->
pTrash
)
{
if
(
pCacheObj
->
pTrash
)
{
pCacheObj
->
pTrash
->
prev
=
pElem
;
pCacheObj
->
pTrash
->
prev
=
pElem
;
...
@@ -563,8 +564,8 @@ void taosAddToTrashcan(SCacheObj *pCacheObj, SCacheDataNode *pNode) {
...
@@ -563,8 +564,8 @@ void taosAddToTrashcan(SCacheObj *pCacheObj, SCacheDataNode *pNode) {
pCacheObj
->
numOfElemsInTrash
++
;
pCacheObj
->
numOfElemsInTrash
++
;
__cache_unlock
(
pCacheObj
);
__cache_unlock
(
pCacheObj
);
uDebug
(
"cache:%s key:%p, %p move to trashcan, pTrashElem:%p, numOfElem in trashcan:%d"
,
pCacheObj
->
name
,
uDebug
(
"cache:%s key:%p, %p move to trashcan, pTrashElem:%p, numOfElem in trashcan:%d"
,
pCacheObj
->
name
,
pNode
->
key
,
pNode
->
key
,
pNode
->
data
,
pElem
,
pCacheObj
->
numOfElemsInTrash
);
pNode
->
data
,
pElem
,
pCacheObj
->
numOfElemsInTrash
);
}
}
void
taosTrashcanEmpty
(
SCacheObj
*
pCacheObj
,
bool
force
)
{
void
taosTrashcanEmpty
(
SCacheObj
*
pCacheObj
,
bool
force
)
{
...
...
src/util/src/tskiplist.c
浏览文件 @
cca70151
...
@@ -280,10 +280,13 @@ bool tSkipListIterNext(SSkipListIterator *iter) {
...
@@ -280,10 +280,13 @@ bool tSkipListIterNext(SSkipListIterator *iter) {
tSkipListRLock
(
pSkipList
);
tSkipListRLock
(
pSkipList
);
if
(
iter
->
order
==
TSDB_ORDER_ASC
)
{
if
(
iter
->
order
==
TSDB_ORDER_ASC
)
{
if
(
iter
->
cur
==
pSkipList
->
pTail
)
{
// no data in the skip list
if
(
iter
->
cur
==
pSkipList
->
pTail
||
iter
->
next
==
NULL
)
{
iter
->
cur
=
pSkipList
->
pTail
;
tSkipListUnlock
(
pSkipList
);
tSkipListUnlock
(
pSkipList
);
return
false
;
return
false
;
}
}
iter
->
cur
=
SL_NODE_GET_FORWARD_POINTER
(
iter
->
cur
,
0
);
iter
->
cur
=
SL_NODE_GET_FORWARD_POINTER
(
iter
->
cur
,
0
);
// a new node is inserted into between iter->cur and iter->next, ignore it
// a new node is inserted into between iter->cur and iter->next, ignore it
...
@@ -295,9 +298,11 @@ bool tSkipListIterNext(SSkipListIterator *iter) {
...
@@ -295,9 +298,11 @@ bool tSkipListIterNext(SSkipListIterator *iter) {
iter
->
step
++
;
iter
->
step
++
;
}
else
{
}
else
{
if
(
iter
->
cur
==
pSkipList
->
pHead
)
{
if
(
iter
->
cur
==
pSkipList
->
pHead
)
{
iter
->
cur
=
pSkipList
->
pHead
;
tSkipListUnlock
(
pSkipList
);
tSkipListUnlock
(
pSkipList
);
return
false
;
return
false
;
}
}
iter
->
cur
=
SL_NODE_GET_BACKWARD_POINTER
(
iter
->
cur
,
0
);
iter
->
cur
=
SL_NODE_GET_BACKWARD_POINTER
(
iter
->
cur
,
0
);
// a new node is inserted into between iter->cur and iter->next, ignore it
// a new node is inserted into between iter->cur and iter->next, ignore it
...
...
tests/script/general/parser/mixed_blocks.sim
浏览文件 @
cca70151
...
@@ -144,4 +144,20 @@ if $data03 != 319 then
...
@@ -144,4 +144,20 @@ if $data03 != 319 then
return -1
return -1
endi
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
print ===================> TD-2488
\ No newline at end of file
sql create table m1(ts timestamp, k int) tags(a int);
sql create table t1 using m1 tags(1);
sql create table t2 using m1 tags(2);
sql insert into t1 values('2020-1-1 1:1:1', 1);
sql insert into t1 values('2020-1-1 1:10:1', 2);
sql insert into t2 values('2020-1-1 1:5:1', 99);
print ================== restart server to commit data into disk
system sh/exec.sh -n dnode1 -s stop -x SIGINT
sleep 3000
system sh/exec.sh -n dnode1 -s start
print ================== server restart completed
sql select ts from m1 where ts='2020-1-1 1:5:1'
if $rows != 1 then
return -1
endi
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录