Merge pull request #26351 from taosdata/fix/TS-5105-1
fix(query):adj second param for last_row
This commit is contained in:
commit
2f970dbc03
|
@ -4056,11 +4056,18 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
|
||||||
pScan->igLastNull = pAgg->hasLast ? true : false;
|
pScan->igLastNull = pAgg->hasLast ? true : false;
|
||||||
SArray* isDuplicateCol = taosArrayInit(pScan->pScanCols->length, sizeof(bool));
|
SArray* isDuplicateCol = taosArrayInit(pScan->pScanCols->length, sizeof(bool));
|
||||||
SNodeList* pLastRowCols = NULL;
|
SNodeList* pLastRowCols = NULL;
|
||||||
|
bool adjLastRowTsColName = false;
|
||||||
|
char tsColName[TSDB_COL_NAME_LEN] = {0};
|
||||||
|
|
||||||
FOREACH(pNode, pAgg->pAggFuncs) {
|
FOREACH(pNode, pAgg->pAggFuncs) {
|
||||||
SFunctionNode* pFunc = (SFunctionNode*)pNode;
|
SFunctionNode* pFunc = (SFunctionNode*)pNode;
|
||||||
int32_t funcType = pFunc->funcType;
|
int32_t funcType = pFunc->funcType;
|
||||||
SNode* pParamNode = nodesListGetNode(pFunc->pParameterList, 0);
|
SNode* pParamNode = NULL;
|
||||||
|
if (FUNCTION_TYPE_LAST == funcType) {
|
||||||
|
nodesListErase(pFunc->pParameterList, nodesListGetCell(pFunc->pParameterList, 1));
|
||||||
|
nodesWalkExpr(nodesListGetNode(pFunc->pParameterList, 0), lastRowScanOptSetColDataType, &cxt);
|
||||||
|
}
|
||||||
|
FOREACH(pParamNode, pFunc->pParameterList) {
|
||||||
if (FUNCTION_TYPE_LAST_ROW == funcType || FUNCTION_TYPE_LAST == funcType) {
|
if (FUNCTION_TYPE_LAST_ROW == funcType || FUNCTION_TYPE_LAST == funcType) {
|
||||||
int32_t len = snprintf(pFunc->functionName, sizeof(pFunc->functionName),
|
int32_t len = snprintf(pFunc->functionName, sizeof(pFunc->functionName),
|
||||||
FUNCTION_TYPE_LAST_ROW == funcType ? "_cache_last_row" : "_cache_last");
|
FUNCTION_TYPE_LAST_ROW == funcType ? "_cache_last_row" : "_cache_last");
|
||||||
|
@ -4093,6 +4100,17 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
|
||||||
SNode* newColNode = nodesCloneNode(pColNode);
|
SNode* newColNode = nodesCloneNode(pColNode);
|
||||||
sprintf(((SColumnNode*)newColNode)->colName, "#dup_col.%p", newColNode);
|
sprintf(((SColumnNode*)newColNode)->colName, "#dup_col.%p", newColNode);
|
||||||
sprintf(((SColumnNode*)pParamNode)->colName, "#dup_col.%p", newColNode);
|
sprintf(((SColumnNode*)pParamNode)->colName, "#dup_col.%p", newColNode);
|
||||||
|
if (FUNCTION_TYPE_LAST_ROW == funcType &&
|
||||||
|
((SColumnNode*)pParamNode)->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||||
|
if (!adjLastRowTsColName) {
|
||||||
|
adjLastRowTsColName = true;
|
||||||
|
strncpy(tsColName, ((SColumnNode*)pParamNode)->colName, TSDB_COL_NAME_LEN);
|
||||||
|
} else {
|
||||||
|
strncpy(((SColumnNode*)pParamNode)->colName, tsColName, TSDB_COL_NAME_LEN);
|
||||||
|
nodesDestroyNode(newColNode);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nodesListAppend(pScan->pScanCols, newColNode);
|
nodesListAppend(pScan->pScanCols, newColNode);
|
||||||
isDup = true;
|
isDup = true;
|
||||||
|
@ -4133,10 +4151,6 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FUNCTION_TYPE_LAST == funcType) {
|
|
||||||
nodesWalkExpr(nodesListGetNode(pFunc->pParameterList, 0), lastRowScanOptSetColDataType, &cxt);
|
|
||||||
nodesListErase(pFunc->pParameterList, nodesListGetCell(pFunc->pParameterList, 1));
|
|
||||||
}
|
|
||||||
if (pFunc->hasPk) {
|
if (pFunc->hasPk) {
|
||||||
nodesListMakeAppend(&cxt.pOtherCols, nodesListGetNode(pFunc->pParameterList, LIST_LENGTH(pFunc->pParameterList) - 1));
|
nodesListMakeAppend(&cxt.pOtherCols, nodesListGetNode(pFunc->pParameterList, LIST_LENGTH(pFunc->pParameterList) - 1));
|
||||||
}
|
}
|
||||||
|
@ -4156,6 +4170,7 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (NULL != cxt.pLastCols) {
|
if (NULL != cxt.pLastCols) {
|
||||||
cxt.doAgg = false;
|
cxt.doAgg = false;
|
||||||
|
|
|
@ -141,7 +141,7 @@ if $data01 != t2 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql select last(ts) ts1,tbname, ts from stb group by tbname;
|
sql select last(ts) ts1,tbname, ts from stb group by tbname order by 1 desc;
|
||||||
|
|
||||||
if $data00 != $data02 then
|
if $data00 != $data02 then
|
||||||
print $data00
|
print $data00
|
||||||
|
@ -156,16 +156,16 @@ endi
|
||||||
print step 3-------------------------------
|
print step 3-------------------------------
|
||||||
|
|
||||||
sql drop database if exists test1;
|
sql drop database if exists test1;
|
||||||
sql create database test1 cachemodel 'both';
|
sql create database test1 cachemodel 'both' vgroups 4;
|
||||||
sql use test1;
|
sql use test1;
|
||||||
sql create table stb (ts timestamp,a int primary key,b int,c int) tags(ta int,tb int,tc int);
|
sql create table stb (ts timestamp,a int primary key,b int,c int) tags(ta int,tb int,tc int);
|
||||||
|
|
||||||
sql create table t1 using stb tags(1,1,1);
|
sql create table aaat1 using stb tags(1,1,1);
|
||||||
sql create table t2 using stb tags(2,2,2);
|
sql create table bbbt2 using stb tags(2,2,2);
|
||||||
sql insert into t1 values('2024-06-05 11:00:00',1,2,3);
|
sql insert into aaat1 values('2024-06-05 11:00:00',1,2,3);
|
||||||
sql insert into t1 values('2024-06-05 12:00:00',2,2,3);
|
sql insert into aaat1 values('2024-06-05 12:00:00',2,2,3);
|
||||||
sql insert into t2 values('2024-06-05 13:00:00',3,2,3);
|
sql insert into bbbt2 values('2024-06-05 13:00:00',3,2,3);
|
||||||
sql insert into t2 values('2024-06-05 14:00:00',4,2,3);
|
sql insert into bbbt2 values('2024-06-05 14:00:00',4,2,3);
|
||||||
|
|
||||||
sql select last(ts) ts1,ts from stb;
|
sql select last(ts) ts1,ts from stb;
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ if $data00 != @24-06-05 14:00:00.000@ then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql select last(ts) ts1,ts from stb group by tbname;
|
sql select last(ts) ts1,ts from stb group by tbname order by 1 desc;
|
||||||
|
|
||||||
if $data00 != $data01 then
|
if $data00 != $data01 then
|
||||||
print $data00
|
print $data00
|
||||||
|
@ -203,12 +203,12 @@ if $data00 != @24-06-05 14:00:00.000@ then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data01 != t2 then
|
if $data01 != bbbt2 then
|
||||||
print $data01
|
print $data01
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql select last(ts) ts1,tbname, ts from stb group by tbname;
|
sql select last(ts) ts1,tbname, ts from stb group by tbname order by 1 desc;
|
||||||
|
|
||||||
if $data00 != $data02 then
|
if $data00 != $data02 then
|
||||||
print $data00
|
print $data00
|
||||||
|
@ -220,7 +220,7 @@ if $data00 != @24-06-05 14:00:00.000@ then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data01 != t2 then
|
if $data01 != bbbt2 then
|
||||||
print $data01
|
print $data01
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
@ -239,7 +239,7 @@ if $data01 != @24-06-05 14:00:00.000@ then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql select last(a) a,ts from stb group by tbname;
|
sql select last(a) a,ts from stb group by tbname order by 1 desc;
|
||||||
|
|
||||||
if $data00 != 4 then
|
if $data00 != 4 then
|
||||||
print $data00
|
print $data00
|
||||||
|
@ -258,7 +258,7 @@ if $data00 != 4 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data01 != t2 then
|
if $data01 != bbbt2 then
|
||||||
print $data01
|
print $data01
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
@ -268,14 +268,14 @@ if $data02 != @24-06-05 14:00:00.000@ then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql select last(a) a,tbname, ts from stb group by tbname;
|
sql select last(a) a,tbname, ts from stb group by tbname order by 1 desc;
|
||||||
|
|
||||||
if $data00 != 4 then
|
if $data00 != 4 then
|
||||||
print $data00
|
print $data00
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data01 != t2 then
|
if $data01 != bbbt2 then
|
||||||
print $data01
|
print $data01
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
@ -299,7 +299,7 @@ if $data01 != 4 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql select last(ts) ts1,a from stb group by tbname;
|
sql select last(ts) ts1,a from stb group by tbname order by 1 desc;
|
||||||
|
|
||||||
if $data00 != @24-06-05 14:00:00.000@ then
|
if $data00 != @24-06-05 14:00:00.000@ then
|
||||||
print $data00
|
print $data00
|
||||||
|
@ -318,7 +318,7 @@ if $data00 != @24-06-05 14:00:00.000@ then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data01 != t2 then
|
if $data01 != bbbt2 then
|
||||||
print $data01
|
print $data01
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
@ -328,14 +328,14 @@ if $data02 != 4 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql select last(ts) ts1,tbname, a from stb group by tbname;
|
sql select last(ts) ts1,tbname, a from stb group by tbname order by 1 desc;
|
||||||
|
|
||||||
if $data00 != @24-06-05 14:00:00.000@ then
|
if $data00 != @24-06-05 14:00:00.000@ then
|
||||||
print $data00
|
print $data00
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data01 != t2 then
|
if $data01 != bbbt2 then
|
||||||
print $data01
|
print $data01
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
@ -345,4 +345,25 @@ if $data02 != 4 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
|
loop0:
|
||||||
|
|
||||||
|
sql select last(ts), last_row(ts) from stb;
|
||||||
|
|
||||||
|
if $data00 != $data01 then
|
||||||
|
print ====data00=$data00
|
||||||
|
print ====data01=$data01
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
$loop_count = $loop_count + 1
|
||||||
|
if $loop_count < 10 then
|
||||||
|
sleep 200
|
||||||
|
print ====checktimes=$loop_count
|
||||||
|
goto loop0
|
||||||
|
endi
|
||||||
|
|
||||||
|
print ------------------------end
|
||||||
|
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||||
|
|
Loading…
Reference in New Issue