add ts column for last cache
This commit is contained in:
parent
2851d24860
commit
545fa5ebcb
|
@ -4159,8 +4159,10 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
|
|||
|
||||
lastRowScanOptSetLastTargets(pScan->node.pTargets, cxt.pLastCols, pLastRowCols, false, cxt.pkBytes);
|
||||
lastRowScanOptRemoveUslessTargets(pScan->node.pTargets, cxt.pLastCols, cxt.pOtherCols, pLastRowCols);
|
||||
if (pPKTsCol && ((pScan->node.pTargets->length == 1) || (pScan->node.pTargets->length == 2 && cxt.pkBytes > 0))) {
|
||||
// when select last(ts),ts from ..., we add another ts to targets
|
||||
if (pPKTsCol &&
|
||||
((cxt.pLastCols->length == 1 && nodesEqualNode((SNode*)pPKTsCol, nodesListGetNode(cxt.pLastCols, 0))) ||
|
||||
(pScan->node.pTargets->length == 2 && cxt.pkBytes > 0))) {
|
||||
// when select last(ts),tbname,ts from ..., we add another ts to targets
|
||||
sprintf(pPKTsCol->colName, "#sel_val.%p", pPKTsCol);
|
||||
nodesListAppend(pScan->node.pTargets, nodesCloneNode((SNode*)pPKTsCol));
|
||||
}
|
||||
|
|
|
@ -101,5 +101,248 @@ if $rows != 1 then
|
|||
return -1
|
||||
endi
|
||||
|
||||
print step 2-------------------------------
|
||||
|
||||
sql drop database if exists test;
|
||||
sql create database test cachemodel 'both';
|
||||
sql use test;
|
||||
sql create table stb (ts timestamp,a int,b int,c int) tags(ta int,tb int,tc int);
|
||||
|
||||
sql create table t1 using stb tags(1,1,1);
|
||||
sql create table t2 using stb tags(2,2,2);
|
||||
sql insert into t1 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 t2 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 select last(ts) ts1,ts from stb;
|
||||
|
||||
if $data00 != $data01 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select last(ts) ts1,ts from stb group by tbname;
|
||||
|
||||
if $data00 != $data01 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select last(ts) ts1,tbname, ts from stb;
|
||||
|
||||
if $data00 != $data02 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != t2 then
|
||||
print $data01
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select last(ts) ts1,tbname, ts from stb group by tbname;
|
||||
|
||||
if $data00 != $data02 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != t2 then
|
||||
print $data01
|
||||
return -1
|
||||
endi
|
||||
|
||||
print step 3-------------------------------
|
||||
|
||||
sql drop database if exists test1;
|
||||
sql create database test1 cachemodel 'both';
|
||||
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 t1 using stb tags(1,1,1);
|
||||
sql create table t2 using stb tags(2,2,2);
|
||||
sql insert into t1 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 t2 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 select last(ts) ts1,ts from stb;
|
||||
|
||||
if $data00 != $data01 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data00 != @24-06-05 14:00:00.000@ then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select last(ts) ts1,ts from stb group by tbname;
|
||||
|
||||
if $data00 != $data01 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data00 != @24-06-05 14:00:00.000@ then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select last(ts) ts1,tbname, ts from stb;
|
||||
|
||||
if $data00 != $data02 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data00 != @24-06-05 14:00:00.000@ then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != t2 then
|
||||
print $data01
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select last(ts) ts1,tbname, ts from stb group by tbname;
|
||||
|
||||
if $data00 != $data02 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data00 != @24-06-05 14:00:00.000@ then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != t2 then
|
||||
print $data01
|
||||
return -1
|
||||
endi
|
||||
|
||||
print step 4-------------------------------
|
||||
|
||||
sql select last(a) a,ts from stb;
|
||||
|
||||
if $data00 != 4 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != @24-06-05 14:00:00.000@ then
|
||||
print $data01
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select last(a) a,ts from stb group by tbname;
|
||||
|
||||
if $data00 != 4 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != @24-06-05 14:00:00.000@ then
|
||||
print $data01
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select last(a) a,tbname, ts from stb;
|
||||
|
||||
if $data00 != 4 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != t2 then
|
||||
print $data01
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data02 != @24-06-05 14:00:00.000@ then
|
||||
print $data02
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select last(a) a,tbname, ts from stb group by tbname;
|
||||
|
||||
if $data00 != 4 then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != t2 then
|
||||
print $data01
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data02 != @24-06-05 14:00:00.000@ then
|
||||
print $data02
|
||||
return -1
|
||||
endi
|
||||
|
||||
print step 5-------------------------------
|
||||
|
||||
sql select last(ts) ts1,a from stb;
|
||||
|
||||
if $data00 != @24-06-05 14:00:00.000@ then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != 4 then
|
||||
print $data01
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select last(ts) ts1,a from stb group by tbname;
|
||||
|
||||
if $data00 != @24-06-05 14:00:00.000@ then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != 4 then
|
||||
print $data01
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select last(ts) ts1,tbname, a from stb;
|
||||
|
||||
if $data00 != @24-06-05 14:00:00.000@ then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != t2 then
|
||||
print $data01
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data02 != 4 then
|
||||
print $data02
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select last(ts) ts1,tbname, a from stb group by tbname;
|
||||
|
||||
if $data00 != @24-06-05 14:00:00.000@ then
|
||||
print $data00
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != t2 then
|
||||
print $data01
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data02 != 4 then
|
||||
print $data02
|
||||
return -1
|
||||
endi
|
||||
|
||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||
|
|
Loading…
Reference in New Issue