fix: join scan range error issue
This commit is contained in:
parent
d4dddb5fd7
commit
f8798e33b4
|
@ -2811,10 +2811,17 @@ static bool joinCondMayBeOptimized(SLogicNode* pNode, void* pCtx) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (pJoin->pPrimKeyEqCond && QUERY_NODE_OPERATOR == nodeType(pJoin->pPrimKeyEqCond)) {
|
||||
SOperatorNode* pOp = (SOperatorNode*)pJoin->pPrimKeyEqCond;
|
||||
if ((pOp->pLeft && QUERY_NODE_COLUMN != nodeType(pOp->pLeft)) || (pOp->pRight && QUERY_NODE_COLUMN != nodeType(pOp->pRight))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void joinCondMergeScanRand(STimeWindow* pDst, STimeWindow* pSrc) {
|
||||
static void joinCondMergeScanRange(STimeWindow* pDst, STimeWindow* pSrc) {
|
||||
if (pSrc->skey > pDst->skey) {
|
||||
pDst->skey = pSrc->skey;
|
||||
}
|
||||
|
@ -2842,7 +2849,7 @@ static int32_t joinCondOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSub
|
|||
}
|
||||
SNode* pNode = NULL;
|
||||
STimeWindow scanRange = TSWINDOW_INITIALIZER;
|
||||
FOREACH(pNode, pScanList) { joinCondMergeScanRand(&scanRange, &((SScanLogicNode*)pNode)->scanRange); }
|
||||
FOREACH(pNode, pScanList) { joinCondMergeScanRange(&scanRange, &((SScanLogicNode*)pNode)->scanRange); }
|
||||
FOREACH(pNode, pScanList) {
|
||||
((SScanLogicNode*)pNode)->scanRange.skey = scanRange.skey;
|
||||
((SScanLogicNode*)pNode)->scanRange.ekey = scanRange.ekey;
|
||||
|
@ -2859,7 +2866,7 @@ static int32_t joinCondOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSub
|
|||
if (NULL == pLScan || NULL == pRScan) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
joinCondMergeScanRand(&pRScan->scanRange, &pLScan->scanRange);
|
||||
joinCondMergeScanRange(&pRScan->scanRange, &pLScan->scanRange);
|
||||
break;
|
||||
}
|
||||
case JOIN_TYPE_RIGHT: {
|
||||
|
@ -2871,7 +2878,7 @@ static int32_t joinCondOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSub
|
|||
if (NULL == pLScan || NULL == pRScan) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
joinCondMergeScanRand(&pLScan->scanRange, &pRScan->scanRange);
|
||||
joinCondMergeScanRange(&pLScan->scanRange, &pRScan->scanRange);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
from os import system
|
||||
from util.log import *
|
||||
from util.sql import *
|
||||
from util.cases import *
|
||||
from util.sqlset import *
|
||||
class TDTestCase:
|
||||
def init(self, conn, logSql, replicaVar=1):
|
||||
tdLog.debug("start to execute %s" % __file__)
|
||||
tdSql.init(conn.cursor(),True)
|
||||
|
||||
def test_join(self):
|
||||
sql_file = './2-query/join_cond.sql'
|
||||
|
||||
os.system(f'taos -f {sql_file}')
|
||||
tdSql.query('use csv_import')
|
||||
tdSql.query('SELECT * FROM trans,candle WHERE trans.tradeTime BETWEEN to_timestamp("2010-01-01", "yyyy-mm-dd") AND to_timestamp("2010-01-21", "yyyy-mm-dd")+1d-1a AND candle.date BETWEEN to_timestamp("2010-01-01", "yyyy-mm-dd") AND to_timestamp("2010-01-21", "yyyy-mm-dd") AND timetruncate(trans.tradeTime, 1d) = candle.date AND trans.securityId = cast(substring_index(candle.order_book_id, ".", 1) as INT) AND trans.securityid = 600884;', queryTimes=1)
|
||||
tdSql.checkRows(570)
|
||||
tdSql.query('SELECT * FROM (SELECT * FROM trans WHERE tradeTime BETWEEN to_timestamp("2010-01-01", "yyyy-mm-dd") AND to_timestamp("2010-01-21", "yyyy-mm-dd")+1d-1a AND securityid = 600884) as t INNER JOIN(SELECT * FROM candle WHERE date BETWEEN to_timestamp("2010-01-01", "yyyy-mm-dd") AND to_timestamp("2010-01-21", "yyyy-mm-dd") ) as c ON timetruncate(t.tradeTime, 1d) = c.date AND t.securityId = cast(substring_index(c.order_book_id, ".", 1) as INT);', queryTimes=1)
|
||||
tdSql.checkRows(570)
|
||||
|
||||
def run(self):
|
||||
self.test_join()
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
tdLog.success("%s successfully executed" % __file__)
|
||||
|
||||
|
||||
tdCases.addWindows(__file__, TDTestCase())
|
||||
tdCases.addLinux(__file__, TDTestCase())
|
|
@ -0,0 +1,8 @@
|
|||
"candle_XSHG_600592","600592.XSHG","2010-01-04 00:00:00",0,20418867,0,211797052,0,6.2908,6.2609,6.0982,6.0916,"2025-01-08 20:16:49"
|
||||
"candle_XSHG_600884","600884.XSHG","2010-01-04 00:00:00",0,20418867,0,211797052,0,6.2908,6.2609,6.0982,6.0916,"2025-01-08 20:16:49"
|
||||
"candle_XSHG_600019","600019.XSHG","2010-01-04 00:00:00",0,20418867,0,211797052,0,6.2908,6.2609,6.0982,6.0916,"2025-01-08 20:16:49"
|
||||
"candle_XSHG_600905","600905.XSHG","2010-01-04 00:00:00",0,20418867,0,211797052,0,6.2908,6.2609,6.0982,6.0916,"2025-01-08 20:16:49"
|
||||
"candle_XSHG_600592","600592.XSHG","2010-01-21 00:00:00",0,20418867,0,211797052,0,6.2908,6.2609,6.0982,6.0916,"2025-01-08 20:16:49"
|
||||
"candle_XSHG_600884","600884.XSHG","2010-01-21 00:00:00",0,20418867,0,211797052,0,6.2908,6.2609,6.0982,6.0916,"2025-01-08 20:16:49"
|
||||
"candle_XSHG_600019","600019.XSHG","2010-01-21 00:00:00",0,20418867,0,211797052,0,6.2908,6.2609,6.0982,6.0916,"2025-01-08 20:16:49"
|
||||
"candle_XSHG_600905","600905.XSHG","2010-01-21 00:00:00",0,20418867,0,211797052,0,6.2908,6.2609,6.0982,6.0916,"2025-01-08 20:16:49"
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue