diff --git a/README-CN.md b/README-CN.md index 189b7a059a..12ac7b9ee7 100644 --- a/README-CN.md +++ b/README-CN.md @@ -352,4 +352,4 @@ TDengine 提供了丰富的应用程序开发接口,其中包括 C/C++、Java # 加入技术交流群 -TDengine 官方社群「物联网大数据群」对外开放,欢迎您加入讨论。搜索微信号 "tdengine",加小 T 为好友,即可入群。 +TDengine 官方社群「物联网大数据群」对外开放,欢迎您加入讨论。搜索微信号 "tdengine1",加小 T 为好友,即可入群。 diff --git a/cmake/taostools_CMakeLists.txt.in b/cmake/taostools_CMakeLists.txt.in index 4838e97dd7..d9d2f12069 100644 --- a/cmake/taostools_CMakeLists.txt.in +++ b/cmake/taostools_CMakeLists.txt.in @@ -2,7 +2,7 @@ # taos-tools ExternalProject_Add(taos-tools GIT_REPOSITORY https://github.com/taosdata/taos-tools.git - GIT_TAG ffc2e6f + GIT_TAG 4378702 SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools" BINARY_DIR "" #BUILD_IN_SOURCE TRUE diff --git a/docs/en/12-taos-sql/24-show.md b/docs/en/12-taos-sql/24-show.md index 886214df0e..7b3da109ca 100644 --- a/docs/en/12-taos-sql/24-show.md +++ b/docs/en/12-taos-sql/24-show.md @@ -197,7 +197,7 @@ show table distributed d0\G; Show Example

 *************************** 1.row ***************************
-_block_dist: Total_Blocks=[5] Total_Size=[93.65 Kb] Average_size=[18.73 Kb] Compression_Ratio=[23.98 %]
+_block_dist: Total_Blocks=[5] Total_Size=[93.65 KB] Average_size=[18.73 KB] Compression_Ratio=[23.98 %]
 
 Total_Blocks :  Table `d0` contains total 5 blocks
 
diff --git a/docs/zh/12-taos-sql/24-show.md b/docs/zh/12-taos-sql/24-show.md
index 53692ef4c0..12ad665e42 100644
--- a/docs/zh/12-taos-sql/24-show.md
+++ b/docs/zh/12-taos-sql/24-show.md
@@ -197,7 +197,7 @@ SHOW TABLE DISTRIBUTED table_name;
 
 *************************** 1.row ***************************
 
-_block_dist: Total_Blocks=[5] Total_Size=[93.65 Kb] Average_size=[18.73 Kb] Compression_Ratio=[23.98 %]
+_block_dist: Total_Blocks=[5] Total_Size=[93.65 KB] Average_size=[18.73 KB] Compression_Ratio=[23.98 %]
 
 Total_Blocks:  表 d0 占用的 block 个数为 5 个
 
diff --git a/examples/JDBC/taosdemo/pom.xml b/examples/JDBC/taosdemo/pom.xml
index 4731d8e237..0d47663bba 100644
--- a/examples/JDBC/taosdemo/pom.xml
+++ b/examples/JDBC/taosdemo/pom.xml
@@ -10,7 +10,7 @@
     Demo project for TDengine
 
     
-        5.3.26
+        5.3.27
     
 
     
diff --git a/include/client/taos.h b/include/client/taos.h
index 44703c2797..2d3b78a3b6 100644
--- a/include/client/taos.h
+++ b/include/client/taos.h
@@ -230,6 +230,9 @@ DLL_EXPORT int taos_get_tables_vgId(TAOS *taos, const char *db, const char *tabl
 
 DLL_EXPORT int taos_load_table_info(TAOS *taos, const char *tableNameList);
 
+// set heart beat thread quit mode , if quicByKill 1 then kill thread else quit from inner
+DLL_EXPORT void taos_set_hb_quit(int8_t quitByKill);
+
 DLL_EXPORT int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type);
 
 /*  --------------------------schemaless INTERFACE------------------------------- */
diff --git a/include/common/systable.h b/include/common/systable.h
index 558a1ca297..ea18338e9e 100644
--- a/include/common/systable.h
+++ b/include/common/systable.h
@@ -12,7 +12,7 @@
  * You should have received a copy of the GNU Affero General Public License
  * along with this program. If not, see .
  */
- 
+
 #ifndef TDENGINE_SYSTABLE_H
 #define TDENGINE_SYSTABLE_H
 
diff --git a/include/common/tcommon.h b/include/common/tcommon.h
index 3d0dac7c3d..0544247da2 100644
--- a/include/common/tcommon.h
+++ b/include/common/tcommon.h
@@ -213,14 +213,6 @@ enum {
   FETCH_TYPE__NONE,
 };
 
-typedef struct {
-  int8_t       fetchType;
-  union {
-    SSDataBlock data;
-    void*       meta;
-  };
-} SFetchRet;
-
 typedef struct SVarColAttr {
   int32_t* offset;    // start position for each entry in the list
   uint32_t length;    // used buffer size that contain the valid data
@@ -342,6 +334,8 @@ typedef struct {
     float       f;
   };
   size_t length;
+  bool keyEscaped;
+  bool valueEscaped;
 } SSmlKv;
 
 #define QUERY_ASC_FORWARD_STEP  1
@@ -380,6 +374,8 @@ typedef struct STUidTagInfo {
 #define UD_GROUPID_COLUMN_INDEX    1
 #define UD_TAG_COLUMN_INDEX        2
 
+int32_t taosGenCrashJsonMsg(int signum, char **pMsg, int64_t clusterId, int64_t startTime);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/common/tmsg.h b/include/common/tmsg.h
index b71d5c3a52..6b9603ac19 100644
--- a/include/common/tmsg.h
+++ b/include/common/tmsg.h
@@ -416,7 +416,7 @@ static FORCE_INLINE SSchemaWrapper* tCloneSSchemaWrapper(const SSchemaWrapper* p
   return pSW;
 }
 
-static FORCE_INLINE void tDeleteSSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
+static FORCE_INLINE void tDeleteSchemaWrapper(SSchemaWrapper* pSchemaWrapper) {
   if (pSchemaWrapper) {
     taosMemoryFree(pSchemaWrapper->pSchema);
     taosMemoryFree(pSchemaWrapper);
@@ -691,6 +691,7 @@ typedef struct {
 
 int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
 int32_t tDeserializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
+void    tFreeSAlterUserReq(SAlterUserReq* pReq);
 
 typedef struct {
   char user[TSDB_USER_LEN];
@@ -2121,7 +2122,6 @@ static FORCE_INLINE void* tDeserializeSMVSubscribeReq(void* buf, SMVSubscribeReq
 
 typedef struct {
   char    key[TSDB_SUBSCRIBE_KEY_LEN];
-  SArray* lostConsumers;     // SArray
   SArray* removedConsumers;  // SArray
   SArray* newConsumers;      // SArray
 } SMqRebInfo;
@@ -2132,10 +2132,6 @@ static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
     return NULL;
   }
   tstrncpy(pRebInfo->key, key, TSDB_SUBSCRIBE_KEY_LEN);
-  pRebInfo->lostConsumers = taosArrayInit(0, sizeof(int64_t));
-  if (pRebInfo->lostConsumers == NULL) {
-    goto _err;
-  }
   pRebInfo->removedConsumers = taosArrayInit(0, sizeof(int64_t));
   if (pRebInfo->removedConsumers == NULL) {
     goto _err;
@@ -2146,7 +2142,6 @@ static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
   }
   return pRebInfo;
 _err:
-  taosArrayDestroy(pRebInfo->lostConsumers);
   taosArrayDestroy(pRebInfo->removedConsumers);
   taosArrayDestroy(pRebInfo->newConsumers);
   taosMemoryFreeClear(pRebInfo);
@@ -3452,10 +3447,10 @@ typedef struct {
   char     data[];  // SSubmitReq2
 } SSubmitReq2Msg;
 
-int32_t tEncodeSSubmitReq2(SEncoder* pCoder, const SSubmitReq2* pReq);
-int32_t tDecodeSSubmitReq2(SDecoder* pCoder, SSubmitReq2* pReq);
-void    tDestroySSubmitTbData(SSubmitTbData* pTbData, int32_t flag);
-void    tDestroySSubmitReq2(SSubmitReq2* pReq, int32_t flag);
+int32_t tEncodeSubmitReq(SEncoder* pCoder, const SSubmitReq2* pReq);
+int32_t tDecodeSubmitReq(SDecoder* pCoder, SSubmitReq2* pReq);
+void    tDestroySubmitTbData(SSubmitTbData* pTbData, int32_t flag);
+void    tDestroySubmitReq(SSubmitReq2* pReq, int32_t flag);
 
 typedef struct {
   int32_t affectedRows;
diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h
index 2c684f8f76..d7084cfac4 100644
--- a/include/libs/catalog/catalog.h
+++ b/include/libs/catalog/catalog.h
@@ -82,6 +82,7 @@ typedef struct SCatalogReq {
   SArray* pUser;          // element is SUserAuthInfo
   SArray* pTableIndex;    // element is SNAME
   SArray* pTableCfg;      // element is SNAME
+  SArray* pTableTag;      // element is SNAME
   bool    qNodeRequired;  // valid qnode
   bool    dNodeRequired;  // valid dnode
   bool    svrVerRequired;
@@ -105,6 +106,7 @@ typedef struct SMetaData {
   SArray*   pUser;        // pRes = SUserAuthRes*
   SArray*   pQnodeList;   // pRes = SArray*
   SArray*   pTableCfg;    // pRes = STableCfg*
+  SArray*   pTableTag;    // pRes = SArray*
   SArray*   pDnodeList;   // pRes = SArray*
   SMetaRes* pSvrVer;      // pRes = char*
 } SMetaData;
@@ -122,8 +124,8 @@ typedef struct SSTableVersion {
   char     stbName[TSDB_TABLE_NAME_LEN];
   uint64_t dbId;
   uint64_t suid;
-  int16_t  sversion;
-  int16_t  tversion;
+  int32_t  sversion;
+  int32_t  tversion;
   int32_t  smaVer;
 } SSTableVersion;
 
@@ -312,6 +314,8 @@ int32_t catalogGetIndexMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const char*
 
 int32_t catalogGetTableIndex(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SArray** pRes);
 
+int32_t catalogGetTableTag(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SArray** pRes);
+
 int32_t catalogRefreshGetTableCfg(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, STableCfg** pCfg);
 
 int32_t catalogUpdateTableIndex(SCatalog* pCtg, STableIndexRsp* pRsp);
diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h
index 34372dc2ff..b7e6c42e3b 100644
--- a/include/libs/executor/executor.h
+++ b/include/libs/executor/executor.h
@@ -190,9 +190,9 @@ STimeWindow getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int
 
 SArray* qGetQueriedTableListInfo(qTaskInfo_t tinfo);
 
-int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subType);
+void verifyOffset(void *pWalReader, STqOffsetVal* pOffset);
 
-int32_t qStreamSetScanMemData(qTaskInfo_t tinfo, SPackedData submit);
+int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subType);
 
 void qStreamSetOpen(qTaskInfo_t tinfo);
 
@@ -208,8 +208,6 @@ void* qExtractReaderFromStreamScanner(void* scanner);
 
 int32_t qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner);
 
-int32_t qStreamInput(qTaskInfo_t tinfo, void* pItem);
-
 int32_t qStreamSetParamForRecover(qTaskInfo_t tinfo);
 int32_t qStreamSourceRecoverStep1(qTaskInfo_t tinfo, int64_t ver);
 int32_t qStreamSourceRecoverStep2(qTaskInfo_t tinfo, int64_t ver);
diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h
index 480912a8cf..9569cfe055 100644
--- a/include/libs/nodes/querynodes.h
+++ b/include/libs/nodes/querynodes.h
@@ -379,6 +379,8 @@ typedef struct SVnodeModifyOpStmt {
   SName                 usingTableName;
   const char*           pBoundCols;
   struct STableMeta*    pTableMeta;
+  SNode*                pTagCond;
+  SArray*               pTableTag;
   SHashObj*             pVgroupsHashObj;
   SHashObj*             pTableBlockHashObj;  // SHashObj
   SHashObj*             pSubTableHashObj;
diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h
index cfc6ef2025..3841210076 100644
--- a/include/libs/qcom/query.h
+++ b/include/libs/qcom/query.h
@@ -116,8 +116,8 @@ typedef struct STableMeta {
 
   // if the table is TSDB_CHILD_TABLE, the following information is acquired from the corresponding super table meta
   // info
-  int16_t       sversion;
-  int16_t       tversion;
+  int32_t       sversion;
+  int32_t       tversion;
   STableComInfo tableInfo;
   SSchema       schema[];
 } STableMeta;
diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h
index aade34e965..5fd9a8b12b 100644
--- a/include/libs/stream/tstream.h
+++ b/include/libs/stream/tstream.h
@@ -50,7 +50,6 @@ enum {
   TASK_STATUS__RECOVER_PREPARE,
   TASK_STATUS__RECOVER1,
   TASK_STATUS__RECOVER2,
-  TASK_STATUS__RESTORE,  // only available for source task to replay WAL from the checkpoint
 };
 
 enum {
@@ -273,6 +272,7 @@ typedef struct SStreamId {
 typedef struct SCheckpointInfo {
   int64_t id;
   int64_t version;   // offset in WAL
+  int64_t currentVer;// current offset in WAL, not serialize it
 } SCheckpointInfo;
 
 typedef struct SStreamStatus {
@@ -340,12 +340,13 @@ typedef struct SStreamMeta {
   TTB*         pTaskDb;
   TTB*         pCheckpointDb;
   SHashObj*    pTasks;
+  SArray*      pTaskList;   // SArray
   void*        ahandle;
   TXN*         txn;
   FTaskExpand* expandFunc;
   int32_t      vgId;
   SRWLatch     lock;
-  int8_t       walScan;
+  int32_t      walScanCounter;
 } SStreamMeta;
 
 int32_t tEncodeStreamEpInfo(SEncoder* pEncoder, const SStreamChildEpInfo* pInfo);
@@ -537,14 +538,16 @@ void    streamTaskInputFail(SStreamTask* pTask);
 int32_t streamTryExec(SStreamTask* pTask);
 int32_t streamSchedExec(SStreamTask* pTask);
 int32_t streamTaskOutput(SStreamTask* pTask, SStreamDataBlock* pBlock);
+bool    streamTaskShouldStop(const SStreamStatus* pStatus);
 
 int32_t streamScanExec(SStreamTask* pTask, int32_t batchSz);
 
 // recover and fill history
 int32_t streamTaskCheckDownstream(SStreamTask* pTask, int64_t version);
 int32_t streamTaskLaunchRecover(SStreamTask* pTask, int64_t version);
-int32_t streamProcessTaskCheckReq(SStreamTask* pTask, const SStreamTaskCheckReq* pReq);
+int32_t streamTaskCheckStatus(SStreamTask* pTask);
 int32_t streamProcessTaskCheckRsp(SStreamTask* pTask, const SStreamTaskCheckRsp* pRsp, int64_t version);
+
 // common
 int32_t streamSetParamForRecover(SStreamTask* pTask);
 int32_t streamRestoreParam(SStreamTask* pTask);
diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h
index 1e3974f5cc..c8a6eeea8e 100644
--- a/include/libs/wal/wal.h
+++ b/include/libs/wal/wal.h
@@ -147,8 +147,6 @@ typedef struct SWalReader {
   int64_t        curFileFirstVer;
   int64_t        curVersion;
   int64_t        capacity;
-//  int8_t         curInvalid;
-//  int8_t         curStopped;
   TdThreadMutex  mutex;
   SWalFilterCond cond;
   // TODO remove it
diff --git a/include/util/taoserror.h b/include/util/taoserror.h
index c94d2b4094..fec38f1e98 100644
--- a/include/util/taoserror.h
+++ b/include/util/taoserror.h
@@ -147,7 +147,7 @@ int32_t* taosGetErrno();
 #define TSDB_CODE_TSC_CONN_KILLED               TAOS_DEF_ERROR_CODE(0, 0x0215)
 #define TSDB_CODE_TSC_SQL_SYNTAX_ERROR          TAOS_DEF_ERROR_CODE(0, 0x0216)
 #define TSDB_CODE_TSC_DB_NOT_SELECTED           TAOS_DEF_ERROR_CODE(0, 0x0217)
-#define TSDB_CODE_TSC_INVALID_TABLE_NAME        TAOS_DEF_ERROR_CODE(0, 0x0218)
+//#define TSDB_CODE_TSC_INVALID_TABLE_NAME        TAOS_DEF_ERROR_CODE(0, 0x0218)
 #define TSDB_CODE_TSC_EXCEED_SQL_LIMIT          TAOS_DEF_ERROR_CODE(0, 0x0219)
 #define TSDB_CODE_TSC_FILE_EMPTY                TAOS_DEF_ERROR_CODE(0, 0x021A)
 #define TSDB_CODE_TSC_LINE_SYNTAX_ERROR         TAOS_DEF_ERROR_CODE(0, 0x021B)
@@ -262,6 +262,7 @@ int32_t* taosGetErrno();
 // #define TSDB_CODE_MND_INVALID_STABLE_NAME    TAOS_DEF_ERROR_CODE(0, 0x036D) // 2.x
 #define TSDB_CODE_MND_INVALID_STB_OPTION        TAOS_DEF_ERROR_CODE(0, 0x036E)
 #define TSDB_CODE_MND_INVALID_ROW_BYTES         TAOS_DEF_ERROR_CODE(0, 0x036F)
+#define TSDB_CODE_MND_FIELD_VALUE_OVERFLOW           TAOS_DEF_ERROR_CODE(0, 0x0370)
 
 
 // mnode-func
diff --git a/include/util/tdef.h b/include/util/tdef.h
index 71fb91dbcb..427a49fd4e 100644
--- a/include/util/tdef.h
+++ b/include/util/tdef.h
@@ -368,11 +368,11 @@ typedef enum ELogicConditionType {
 #define TSDB_MIN_STT_TRIGGER            1
 #define TSDB_MAX_STT_TRIGGER            16
 #define TSDB_DEFAULT_SST_TRIGGER        1
-#define TSDB_MIN_HASH_PREFIX            0
-#define TSDB_MAX_HASH_PREFIX            128
+#define TSDB_MIN_HASH_PREFIX            (2 - TSDB_TABLE_NAME_LEN)
+#define TSDB_MAX_HASH_PREFIX            (TSDB_TABLE_NAME_LEN - 2)
 #define TSDB_DEFAULT_HASH_PREFIX        0
-#define TSDB_MIN_HASH_SUFFIX            0
-#define TSDB_MAX_HASH_SUFFIX            128
+#define TSDB_MIN_HASH_SUFFIX            (2 - TSDB_TABLE_NAME_LEN)
+#define TSDB_MAX_HASH_SUFFIX            (TSDB_TABLE_NAME_LEN - 2)
 #define TSDB_DEFAULT_HASH_SUFFIX        0
 
 #define TSDB_DB_MIN_WAL_RETENTION_PERIOD -1
diff --git a/include/util/tlog.h b/include/util/tlog.h
index d267d5876a..5a421033c9 100644
--- a/include/util/tlog.h
+++ b/include/util/tlog.h
@@ -108,7 +108,6 @@ bool taosAssertRelease(bool condition);
 void    taosLogCrashInfo(char *nodeType, char *pMsg, int64_t msgLen, int signum, void *sigInfo);
 void    taosReadCrashInfo(char *filepath, char **pMsg, int64_t *pMsgLen, TdFilePtr *pFd);
 void    taosReleaseCrashLogFile(TdFilePtr pFile, bool truncateFile);
-int32_t taosGenCrashJsonMsg(int signum, char **pMsg, int64_t clusterId, int64_t startTime);
 
 // clang-format off
 #define uFatal(...) { if (uDebugFlag & DEBUG_FATAL) { taosPrintLog("UTL FATAL", DEBUG_FATAL, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }}
diff --git a/include/util/tutil.h b/include/util/tutil.h
index e0801e5295..7a59aa170a 100644
--- a/include/util/tutil.h
+++ b/include/util/tutil.h
@@ -81,14 +81,22 @@ static FORCE_INLINE void taosEncryptPass_c(uint8_t *inBuf, size_t len, char *tar
 
 static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen, int32_t method, int32_t prefix,
                                              int32_t suffix) {
-  if (prefix == 0 && suffix == 0) {
+  if ((prefix == 0 && suffix == 0) || (tblen <= (prefix + suffix)) || (tblen <= -1 * (prefix + suffix)) || prefix * suffix < 0) {
     return MurmurHash3_32(tbname, tblen);
+  } else if (prefix > 0 || suffix > 0) {
+    return MurmurHash3_32(tbname + prefix, tblen - prefix - suffix);
   } else {
-    if (tblen <= (prefix + suffix)) {
-      return MurmurHash3_32(tbname, tblen);
-    } else {
-      return MurmurHash3_32(tbname + prefix, tblen - prefix - suffix);
+    char tbName[TSDB_TABLE_FNAME_LEN];
+    int32_t offset = 0;
+    if (prefix < 0) {
+      offset = -1 * prefix;
+      strncpy(tbName, tbname, offset);
     }
+    if (suffix < 0) {
+      strncpy(tbName + offset, tbname + tblen + suffix, -1 * suffix);
+      offset += -1 *suffix;
+    }
+    return MurmurHash3_32(tbName, offset);
   }
 }
 
@@ -98,6 +106,8 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
     goto LABEL;                            \
   }
 
+#define VND_CHECK_CODE(CODE, LINO, LABEL) TSDB_CHECK_CODE(CODE, LINO, LABEL)
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/packaging/deb/DEBIAN/preinst b/packaging/deb/DEBIAN/preinst
index 8a1a7d4d81..904a946e20 100644
--- a/packaging/deb/DEBIAN/preinst
+++ b/packaging/deb/DEBIAN/preinst
@@ -26,6 +26,38 @@ if pidof taosd &> /dev/null; then
     sleep 1
 fi
 
+# Stop adapter service if running
+if pidof taosadapter &> /dev/null; then
+    if pidof systemd &> /dev/null; then
+        ${csudo}systemctl stop taosadapter || :
+    elif $(which service  &> /dev/null); then
+        ${csudo}service taosadapter stop || :
+    else
+        pid=$(ps -ef | grep "taosadapter" | grep -v "grep" | awk '{print $2}')
+        if [ -n "$pid" ]; then
+           ${csudo}kill -9 $pid   || :
+        fi
+    fi
+    echo "Stop taosadapter service success!"
+    sleep 1
+fi
+
+# Stop keeper service if running
+if pidof taoskeeper &> /dev/null; then
+    if pidof systemd &> /dev/null; then
+        ${csudo}systemctl stop taoskeeper || :
+    elif $(which service  &> /dev/null); then
+        ${csudo}service taoskeeper stop || :
+    else
+        pid=$(ps -ef | grep "taoskeeper" | grep -v "grep" | awk '{print $2}')
+        if [ -n "$pid" ]; then
+           ${csudo}kill -9 $pid   || :
+        fi
+    fi
+    echo "Stop taoskeeper service success!"
+    sleep 1
+fi
+
 # if taos.cfg already softlink, remove it
 cfg_install_dir="/etc/taos"
 install_main_dir="/usr/local/taos"
@@ -41,6 +73,11 @@ if [ -f "${install_main_dir}/taosadapter.service" ]; then
     ${csudo}rm -f ${install_main_dir}/cfg/taosadapter.service || :
 fi
 
+if [ -f "${install_main_dir}/taoskeeper.toml" ]; then
+    ${csudo}rm -f ${install_main_dir}/cfg/taoskeeper.toml     || :
+fi
+
+
 # there can not libtaos.so*, otherwise ln -s  error
 ${csudo}rm -f ${install_main_dir}/driver/libtaos.*   || :
 [ -f ${install_main_dir}/driver/libtaosws.so ] && ${csudo}rm -f ${install_main_dir}/driver/libtaosws.so   || :
diff --git a/packaging/deb/DEBIAN/prerm b/packaging/deb/DEBIAN/prerm
index 65f261db2c..0d63115a04 100644
--- a/packaging/deb/DEBIAN/prerm
+++ b/packaging/deb/DEBIAN/prerm
@@ -32,6 +32,7 @@ else
     ${csudo}rm -f ${bin_link_dir}/udfd       || :
     ${csudo}rm -f ${bin_link_dir}/taosadapter       || :
     ${csudo}rm -f ${bin_link_dir}/taosdemo   || :
+    ${csudo}rm -f ${bin_link_dir}/taoskeeper   || :
     ${csudo}rm -f ${cfg_link_dir}/*          || :
     ${csudo}rm -f ${inc_link_dir}/taos.h     || :
     ${csudo}rm -f ${inc_link_dir}/taosdef.h     || :
diff --git a/packaging/deb/makedeb.sh b/packaging/deb/makedeb.sh
index 94a24a4148..9f49cf345a 100755
--- a/packaging/deb/makedeb.sh
+++ b/packaging/deb/makedeb.sh
@@ -44,8 +44,31 @@ mkdir -p ${pkg_dir}${install_home_path}/include
 #mkdir -p ${pkg_dir}${install_home_path}/init.d
 mkdir -p ${pkg_dir}${install_home_path}/script
 
+# download taoskeeper and build
+if [ "$cpuType" = "x64" ] || [ "$cpuType" = "x86_64" ] || [ "$cpuType" = "amd64" ]; then
+  arch=amd64
+elif [ "$cpuType" = "x32" ] || [ "$cpuType" = "i386" ] || [ "$cpuType" = "i686" ]; then
+  arch=386
+elif [ "$cpuType" = "arm" ] || [ "$cpuType" = "aarch32" ]; then
+  arch=arm
+elif [ "$cpuType" = "arm64" ] || [ "$cpuType" = "aarch64" ]; then
+  arch=arm64
+else
+  arch=$cpuType
+fi
+
+echo "${top_dir}/../enterprise/packaging/build_taoskeeper.sh -r ${arch} -e taoskeeper"
+echo "$top_dir=${top_dir}"
+taoskeeper_binary=`${top_dir}/../enterprise/packaging/build_taoskeeper.sh -r $arch -e taoskeeper`
+echo "taoskeeper_binary: ${taoskeeper_binary}"
+
+# copy config files
+cp $(dirname ${taoskeeper_binary})/config/taoskeeper.toml ${pkg_dir}${install_home_path}/cfg
+cp $(dirname ${taoskeeper_binary})/taoskeeper.service ${pkg_dir}${install_home_path}/cfg
+
 cp ${compile_dir}/../packaging/cfg/taos.cfg         ${pkg_dir}${install_home_path}/cfg
 cp ${compile_dir}/../packaging/cfg/taosd.service    ${pkg_dir}${install_home_path}/cfg
+
 if [ -f "${compile_dir}/test/cfg/taosadapter.toml" ]; then
     cp ${compile_dir}/test/cfg/taosadapter.toml		${pkg_dir}${install_home_path}/cfg || :
 fi
@@ -53,6 +76,7 @@ if [ -f "${compile_dir}/test/cfg/taosadapter.service" ]; then
     cp ${compile_dir}/test/cfg/taosadapter.service	${pkg_dir}${install_home_path}/cfg || :
 fi
 
+cp ${taoskeeper_binary}                      ${pkg_dir}${install_home_path}/bin
 #cp ${compile_dir}/../packaging/deb/taosd            ${pkg_dir}${install_home_path}/init.d
 cp ${compile_dir}/../packaging/tools/post.sh        ${pkg_dir}${install_home_path}/script
 cp ${compile_dir}/../packaging/tools/preun.sh       ${pkg_dir}${install_home_path}/script
@@ -143,6 +167,7 @@ else
   exit 1
 fi
 
+rm -rf ${pkg_dir}/build-taoskeeper
 # make deb package
 dpkg -b ${pkg_dir} $debname
 echo "make deb package success!"
@@ -150,4 +175,5 @@ echo "make deb package success!"
 cp ${pkg_dir}/*.deb ${output_dir}
 
 # clean temp dir
+
 rm -rf ${pkg_dir}
diff --git a/packaging/docker/bin/entrypoint.sh b/packaging/docker/bin/entrypoint.sh
index f4be349c0d..a60254d7ef 100755
--- a/packaging/docker/bin/entrypoint.sh
+++ b/packaging/docker/bin/entrypoint.sh
@@ -42,8 +42,9 @@ if [ "$DISABLE_ADAPTER" = "0" ]; then
     done
 fi
 
-# if has mnode ep set or the host is first ep or not for cluster, just start.
-if [ -f "$DATA_DIR/dnode/mnodeEpSet.json" ] ||
+# if dnode has been created or has mnode ep set or the host is first ep or not for cluster, just start.
+if [ -f "$DATA_DIR/dnode/dnode.json" ] ||
+    [ -f "$DATA_DIR/dnode/mnodeEpSet.json" ] ||
     [ "$TAOS_FQDN" = "$FIRST_EP_HOST" ]; then
     $@
 # others will first wait the first ep ready.
@@ -54,7 +55,7 @@ else
         exit $?
     fi
     while true; do
-        es=$(taos -h $FIRST_EP_HOST -P $FIRST_EP_PORT --check)
+        es=$(taos -h $FIRST_EP_HOST -P $FIRST_EP_PORT --check | grep "^[0-9]*:")
         echo ${es}
         if [ "${es%%:*}" -eq 2 ]; then
             echo "execute create dnode"
diff --git a/packaging/docker/bin/taos-check b/packaging/docker/bin/taos-check
index 5dc06b6018..349187da9b 100755
--- a/packaging/docker/bin/taos-check
+++ b/packaging/docker/bin/taos-check
@@ -1,5 +1,5 @@
 #!/bin/sh
-es=$(taos --check)
+es=$(taos --check | grep "^[0-9]*:")
 code=${es%%:*}
 if [ "$code" -ne "0" ] && [ "$code" -ne "4" ]; then
     exit 0
diff --git a/packaging/rpm/makerpm.sh b/packaging/rpm/makerpm.sh
index 4ac67ec754..9cf00364aa 100755
--- a/packaging/rpm/makerpm.sh
+++ b/packaging/rpm/makerpm.sh
@@ -35,14 +35,16 @@ function cp_rpm_package() {
     local cur_dir
     cd $1
     cur_dir=$(pwd)
-
+    echo "cp_rpm_package cd: ${cur_dir}"
     for dirlist in "$(ls ${cur_dir})"; do
         if test -d ${dirlist}; then
             cd ${dirlist}
+            echo 'cp_rpm_package ${cur_dir}/${dirlist}'
             cp_rpm_package ${cur_dir}/${dirlist}
             cd ..
         fi
         if test -e ${dirlist}; then
+            echo "${cur_dir}/${dirlist} ${output_dir}/TDengine-${tdengine_ver}.rpm"
             cp ${cur_dir}/${dirlist} ${output_dir}/TDengine-${tdengine_ver}.rpm
         fi
     done
@@ -54,6 +56,25 @@ fi
 ${csudo}mkdir -p ${pkg_dir}
 cd ${pkg_dir}
 
+# download taoskeeper and build
+if [ "$cpuType" = "x64" ] || [ "$cpuType" = "x86_64" ] || [ "$cpuType" = "amd64" ]; then
+  arch=amd64
+elif [ "$cpuType" = "x32" ] || [ "$cpuType" = "i386" ] || [ "$cpuType" = "i686" ]; then
+  arch=386
+elif [ "$cpuType" = "arm" ] || [ "$cpuType" = "aarch32" ]; then
+  arch=arm
+elif [ "$cpuType" = "arm64" ] || [ "$cpuType" = "aarch64" ]; then
+  arch=arm64
+else
+  arch=$cpuType
+fi
+
+cd ${top_dir}
+echo "${top_dir}/../enterprise/packaging/build_taoskeeper.sh -r ${arch} -e taoskeeper"
+taoskeeper_binary=`${top_dir}/../enterprise/packaging/build_taoskeeper.sh -r $arch -e taoskeeper`
+echo "taoskeeper_binary: ${taoskeeper_binary}"
+cd ${package_dir}
+
 ${csudo}mkdir -p BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
 
 ${csudo}rpmbuild --define="_version ${tdengine_ver}" --define="_topdir ${pkg_dir}" --define="_compiledir ${compile_dir}" -bb ${spec_file}
@@ -85,3 +106,4 @@ mv ${output_dir}/TDengine-${tdengine_ver}.rpm ${output_dir}/${rpmname}
 
 cd ..
 ${csudo}rm -rf ${pkg_dir}
+rm -rf ${top_dir}/build-taoskeeper
\ No newline at end of file
diff --git a/packaging/rpm/tdengine.spec b/packaging/rpm/tdengine.spec
index c21063e6a4..52d5335003 100644
--- a/packaging/rpm/tdengine.spec
+++ b/packaging/rpm/tdengine.spec
@@ -3,6 +3,7 @@
 %define cfg_install_dir  /etc/taos
 %define __strip /bin/true
 %global __python /usr/bin/python3
+%global _build_id_links none
 
 Name:		tdengine
 Version:	%{_version}
@@ -62,6 +63,15 @@ fi
 if [ -f %{_compiledir}/test/cfg/taosadapter.service ]; then
     cp %{_compiledir}/test/cfg/taosadapter.service %{buildroot}%{homepath}/cfg
 fi
+
+if [ -f %{_compiledir}/../build-taoskeeper/config/taoskeeper.toml ]; then
+    cp %{_compiledir}/../build-taoskeeper/config/taoskeeper.toml %{buildroot}%{homepath}/cfg ||:
+fi
+
+if [ -f %{_compiledir}/../build-taoskeeper/taoskeeper.service ]; then
+    cp %{_compiledir}/../build-taoskeeper/taoskeeper.service %{buildroot}%{homepath}/cfg ||:
+fi
+
 #cp %{_compiledir}/../packaging/rpm/taosd            %{buildroot}%{homepath}/init.d
 cp %{_compiledir}/../packaging/tools/post.sh        %{buildroot}%{homepath}/script
 cp %{_compiledir}/../packaging/tools/preun.sh       %{buildroot}%{homepath}/script
@@ -73,8 +83,12 @@ cp %{_compiledir}/build/bin/taosd                   %{buildroot}%{homepath}/bin
 cp %{_compiledir}/build/bin/udfd                    %{buildroot}%{homepath}/bin
 cp %{_compiledir}/build/bin/taosBenchmark           %{buildroot}%{homepath}/bin
 
+if [ -f %{_compiledir}/../build-taoskeeper/taoskeeper ]; then
+    cp %{_compiledir}/../build-taoskeeper/taoskeeper %{buildroot}%{homepath}/bin
+fi
+
 if [ -f %{_compiledir}/build/bin/taosadapter ]; then
-    cp %{_compiledir}/build/bin/taosadapter                    %{buildroot}%{homepath}/bin ||:
+    cp %{_compiledir}/build/bin/taosadapter                    %{buildroot}%{homepath}/bin
 fi
 cp %{_compiledir}/build/lib/${libfile}              %{buildroot}%{homepath}/driver
 [ -f %{_compiledir}/build/lib/${wslibfile} ] && cp %{_compiledir}/build/lib/${wslibfile}            %{buildroot}%{homepath}/driver ||:
@@ -119,7 +133,9 @@ if [ -f %{_compiledir}/build/bin/jemalloc-config ]; then
         cp %{_compiledir}/build/lib/pkgconfig/jemalloc.pc %{buildroot}%{homepath}/jemalloc/lib/pkgconfig
     fi
 fi
-
+ls -al %{buildroot}%{homepath}/bin
+tree -L 5
+echo "==============================copying files done"
 #Scripts executed before installation
 %pre
 if [ -f /var/lib/taos/dnode/dnodeCfg.json ]; then
@@ -196,6 +212,7 @@ if [ $1 -eq 0 ];then
     ${csudo}rm -f ${bin_link_dir}/taosd      || :
     ${csudo}rm -f ${bin_link_dir}/udfd       || :
     ${csudo}rm -f ${bin_link_dir}/taosadapter       || :
+    ${csudo}rm -f ${bin_link_dir}/taoskeeper       || :
     ${csudo}rm -f ${cfg_link_dir}/*          || :
     ${csudo}rm -f ${inc_link_dir}/taos.h     || :
     ${csudo}rm -f ${inc_link_dir}/taosdef.h     || :
diff --git a/packaging/tools/makeclient.sh b/packaging/tools/makeclient.sh
index 1dbfc897bc..28dc770755 100755
--- a/packaging/tools/makeclient.sh
+++ b/packaging/tools/makeclient.sh
@@ -197,8 +197,8 @@ if [[ $productName == "TDengine" ]]; then
       mkdir -p ${install_dir}/connector
       if [[ "$pagMode" != "lite" ]] && [[ "$cpuType" != "aarch32" ]]; then
           if [ "$osType" != "Darwin" ]; then
-                jars=$(ls ${build_dir}/lib/*.jar 2>/dev/null|wc -l)
-                [ "${jars}" != "0" ] && cp ${build_dir}/lib/*.jar ${install_dir}/connector || :
+              jars=$(ls ${build_dir}/lib/*.jar 2>/dev/null|wc -l)
+              [ "${jars}" != "0" ] && cp ${build_dir}/lib/*.jar ${install_dir}/connector || :
           fi
           git clone --depth 1 https://github.com/taosdata/driver-go ${install_dir}/connector/go
           rm -rf ${install_dir}/connector/go/.git ||:
diff --git a/packaging/tools/post.sh b/packaging/tools/post.sh
index 3a013ade2c..fc392c9684 100755
--- a/packaging/tools/post.sh
+++ b/packaging/tools/post.sh
@@ -436,7 +436,7 @@ function local_fqdn_check() {
 
 function install_taosadapter_config() {
     if [ ! -f "${cfg_install_dir}/taosadapter.toml" ]; then
-        [ ! -d %{cfg_install_dir} ] &&
+        [ ! -d ${cfg_install_dir} ] &&
             ${csudo}${csudo}mkdir -p ${cfg_install_dir}
         [ -f ${cfg_dir}/taosadapter.toml ] && ${csudo}cp ${cfg_dir}/taosadapter.toml ${cfg_install_dir}
         [ -f ${cfg_install_dir}/taosadapter.toml ] &&
@@ -451,19 +451,26 @@ function install_taosadapter_config() {
 }
 
 function install_taoskeeper_config() {
-    if [ ! -f "${cfg_install_dir}/keeper.toml" ]; then
-        [ ! -d %{cfg_install_dir} ] &&
-            ${csudo}${csudo}mkdir -p ${cfg_install_dir}
-        [ -f ${cfg_dir}/keeper.toml ] && ${csudo}cp ${cfg_dir}/keeper.toml ${cfg_install_dir}
-        [ -f ${cfg_install_dir}/keeper.toml ] &&
-            ${csudo}chmod 644 ${cfg_install_dir}/keeper.toml
+    # if new environment without taoskeeper
+    if [[ ! -f "${cfg_install_dir}/keeper.toml" ]] && [[ ! -f "${cfg_install_dir}/taoskeeper.toml" ]]; then
+        [ ! -d ${cfg_install_dir} ] && ${csudo}${csudo}mkdir -p ${cfg_install_dir}
+        [ -f ${cfg_dir}/taoskeeper.toml ] && ${csudo}cp ${cfg_dir}/taoskeeper.toml ${cfg_install_dir}
+        [ -f ${cfg_install_dir}/taoskeeper.toml ] &&
+            ${csudo}chmod 644 ${cfg_install_dir}/taoskeeper.toml
+    fi
+    # if old machine with taoskeeper.toml file
+    if [ -f ${cfg_install_dir}/taoskeeper.toml ]; then
+        ${csudo}mv ${cfg_dir}/taoskeeper.toml ${cfg_dir}/taoskeeper.toml.new
     fi
 
-    [ -f ${cfg_dir}/keeper.toml ] &&
-        ${csudo}mv ${cfg_dir}/keeper.toml ${cfg_dir}/keeper.toml.new
+    if [ -f ${cfg_install_dir}/keeper.toml ]; then
+        echo "The file keeper.toml will be renamed to taoskeeper.toml"
+        ${csudo}mv ${cfg_install_dir}/keeper.toml ${cfg_install_dir}/taoskeeper.toml
+        ${csudo}mv ${cfg_dir}/taoskeeper.toml ${cfg_dir}/taoskeeper.toml.new
+    fi
 
-    [ -f ${cfg_install_dir}/keeper.toml ] &&
-        ${csudo}ln -s ${cfg_install_dir}/keeper.toml ${cfg_dir}
+    [ -f ${cfg_install_dir}/taoskeeper.toml ] &&
+        ${csudo}ln -s ${cfg_install_dir}/taoskeeper.toml ${cfg_dir}
 }
 
 function install_config() {
@@ -655,6 +662,15 @@ function install_taosadapter_service() {
     fi
 }
 
+function install_taoskeeper_service() {
+    if ((${service_mod}==0)); then
+        [ -f ${script_dir}/../cfg/taoskeeper.service ] &&\
+            ${csudo}cp ${script_dir}/../cfg/taoskeeper.service \
+            ${service_config_dir}/ || :
+        ${csudo}systemctl daemon-reload
+    fi
+}
+
 function install_service() {
   log_print "start install service"
   if [ "$osType" != "Darwin" ]; then
@@ -732,6 +748,7 @@ function install_TDengine() {
     install_taosadapter_config
     install_taoskeeper_config
     install_taosadapter_service
+    install_taoskeeper_service
     install_service
     install_app
 
diff --git a/packaging/tools/preun.sh b/packaging/tools/preun.sh
index 0e96c71d5d..68f6b53c45 100755
--- a/packaging/tools/preun.sh
+++ b/packaging/tools/preun.sh
@@ -17,7 +17,7 @@ cfg_link_dir="/usr/local/taos/cfg"
 
 service_config_dir="/etc/systemd/system"
 taos_service_name="taosd"
-
+taoskeeper_service_name="taoskeeper"
 csudo=""
 if command -v sudo > /dev/null; then
     csudo="sudo "
@@ -57,6 +57,13 @@ function kill_taosd() {
   fi
 }
 
+function kill_taoskeeper() {
+  pid=$(ps -ef | grep "taoskeeper" | grep -v "grep" | awk '{print $2}')
+  if [ -n "$pid" ]; then
+    ${csudo}kill -9 $pid   || :
+  fi
+}
+
 function clean_service_on_systemd() {
     taosadapter_service_config="${service_config_dir}/taosadapter.service"
     if systemctl is-active --quiet taosadapter; then
@@ -76,6 +83,12 @@ function clean_service_on_systemd() {
 
     [ -f ${taosadapter_service_config} ] && ${csudo}rm -f ${taosadapter_service_config}
 
+    taoskeeper_service_config="${service_config_dir}/${taoskeeper_service_name}.service"
+    if systemctl is-active --quiet ${taoskeeper_service_name}; then
+        echo "TDengine taoskeeper is running, stopping it..."
+        ${csudo}systemctl stop ${taoskeeper_service_name} &> /dev/null || echo &> /dev/null
+    fi
+    [ -f ${taoskeeper_service_config} ] && ${csudo}rm -f ${taoskeeper_service_config}
 }
 
 function clean_service_on_sysvinit() {
@@ -111,6 +124,7 @@ function clean_service() {
         # must manual stop taosd
         kill_taosadapter
         kill_taosd
+        kill_taoskeeper
     fi
 }
 
@@ -124,6 +138,7 @@ ${csudo}rm -f ${bin_link_dir}/taosadapter       || :
 ${csudo}rm -f ${bin_link_dir}/taosBenchmark || :
 ${csudo}rm -f ${bin_link_dir}/taosdemo   || :
 ${csudo}rm -f ${bin_link_dir}/set_core   || :
+${csudo}rm -f ${bin_link_dir}/taoskeeper  || :
 ${csudo}rm -f ${cfg_link_dir}/*.new      || :
 ${csudo}rm -f ${inc_link_dir}/taos.h     || :
 ${csudo}rm -f ${inc_link_dir}/taosdef.h  || :
diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h
index ab8e20b85e..18891bb932 100644
--- a/source/client/inc/clientInt.h
+++ b/source/client/inc/clientInt.h
@@ -81,6 +81,7 @@ typedef struct {
   int64_t appId;
   // ctl
   int8_t        threadStop;
+  int8_t        quitByKill;
   TdThread      thread;
   TdThreadMutex lock;  // used when app init and cleanup
   SHashObj*     appSummary;
diff --git a/source/client/inc/clientSml.h b/source/client/inc/clientSml.h
index 92896e6f23..b20fc6f57a 100644
--- a/source/client/inc/clientSml.h
+++ b/source/client/inc/clientSml.h
@@ -70,7 +70,7 @@ extern "C" {
 #define VALUE_LEN 6
 
 #define OTD_JSON_FIELDS_NUM     4
-#define MAX_RETRY_TIMES 100
+#define MAX_RETRY_TIMES 10
 typedef TSDB_SML_PROTOCOL_TYPE SMLProtocolType;
 
 typedef enum {
@@ -107,6 +107,7 @@ typedef struct {
   int32_t colsLen;
   int32_t timestampLen;
 
+  bool    measureEscaped;
   SArray *colArray;
 } SSmlLineInfo;
 
@@ -168,6 +169,7 @@ typedef struct {
   int32_t         uid; // used for automatic create child table
 
   SHashObj *childTables;
+  SHashObj *tableUids;
   SHashObj *superTables;
   SHashObj *pVgHash;
 
@@ -206,6 +208,19 @@ typedef struct {
 
 #define IS_SAME_KEY (maxKV->keyLen == kv.keyLen && memcmp(maxKV->key, kv.key, kv.keyLen) == 0)
 
+#define IS_SLASH_LETTER_IN_MEASUREMENT(sql)                                                           \
+  (*((sql)-1) == SLASH && (*(sql) == COMMA || *(sql) == SPACE))
+
+#define MOVE_FORWARD_ONE(sql, len) (memmove((void *)((sql)-1), (sql), len))
+
+#define PROCESS_SLASH_IN_MEASUREMENT(key, keyLen)           \
+  for (int i = 1; i < keyLen; ++i) {         \
+    if (IS_SLASH_LETTER_IN_MEASUREMENT(key + i)) {          \
+      MOVE_FORWARD_ONE(key + i, keyLen - i); \
+      keyLen--;                              \
+    }                                        \
+  }
+
 extern int64_t smlFactorNS[3];
 extern int64_t smlFactorS[3];
 
@@ -228,6 +243,7 @@ int8_t        smlGetTsTypeByLen(int32_t len);
 SSmlTableInfo*    smlBuildTableInfo(int numRows, const char* measure, int32_t measureLen);
 SSmlSTableMeta*   smlBuildSTableMeta(bool isDataFormat);
 int32_t           smlSetCTableName(SSmlTableInfo *oneTable);
+void              getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo);
 STableMeta*       smlGetMeta(SSmlHandle *info, const void* measure, int32_t measureLen);
 int32_t           is_same_child_table_telnet(const void *a, const void *b);
 int64_t           smlParseOpenTsdbTime(SSmlHandle *info, const char *data, int32_t len);
@@ -237,6 +253,7 @@ uint8_t           smlGetTimestampLen(int64_t num);
 void              clearColValArray(SArray* pCols);
 void              smlDestroyTableInfo(SSmlHandle *info, SSmlTableInfo *tag);
 
+void freeSSmlKv(void* data);
 int32_t smlParseInfluxString(SSmlHandle *info, char *sql, char *sqlEnd, SSmlLineInfo *elements);
 int32_t smlParseTelnetString(SSmlHandle *info, char *sql, char *sqlEnd, SSmlLineInfo *elements);
 int32_t smlParseJSON(SSmlHandle *info, char *payload);
diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c
index 203aad8068..7ebf428b2d 100644
--- a/source/client/src/clientHb.c
+++ b/source/client/src/clientHb.c
@@ -976,7 +976,12 @@ static void hbStopThread() {
     return;
   }
 
-  taosThreadJoin(clientHbMgr.thread, NULL);
+  // thread quit mode kill or inner exit from self-thread
+  if (clientHbMgr.quitByKill) {
+    taosThreadKill(clientHbMgr.thread, 0);
+  } else {
+    taosThreadJoin(clientHbMgr.thread, NULL);
+  }
 
   tscDebug("hb thread stopped");
 }
@@ -1175,4 +1180,9 @@ void hbDeregisterConn(STscObj *pTscObj, SClientHbKey connKey) {
     atomic_sub_fetch_32(&pAppHbMgr->passKeyCnt, 1);
   }
   taosThreadMutexUnlock(&pTscObj->mutex);
-}
\ No newline at end of file
+}
+
+// set heart beat thread quit mode , if quicByKill 1 then kill thread else quit from inner
+void taos_set_hb_quit(int8_t quitByKill) {
+  clientHbMgr.quitByKill = quitByKill;
+}
diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c
index 243a84ca93..55337d4a0b 100644
--- a/source/client/src/clientMain.c
+++ b/source/client/src/clientMain.c
@@ -108,7 +108,7 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha
   if (pass == NULL) {
     pass = TSDB_DEFAULT_PASS;
   }
-  
+
   STscObj *pObj = taos_connect_internal(ip, user, pass, NULL, db, port, CONN_TYPE__QUERY);
   if (pObj) {
     int64_t *rid = taosMemoryCalloc(1, sizeof(int64_t));
@@ -228,7 +228,7 @@ void taos_free_result(TAOS_RES *res) {
     taosArrayDestroyP(pRsp->rsp.blockData, taosMemoryFree);
     taosArrayDestroy(pRsp->rsp.blockDataLen);
     taosArrayDestroyP(pRsp->rsp.blockTbName, taosMemoryFree);
-    taosArrayDestroyP(pRsp->rsp.blockSchema, (FDelete)tDeleteSSchemaWrapper);
+    taosArrayDestroyP(pRsp->rsp.blockSchema, (FDelete)tDeleteSchemaWrapper);
     // taosx
     taosArrayDestroy(pRsp->rsp.createTableLen);
     taosArrayDestroyP(pRsp->rsp.createTableReq, taosMemoryFree);
@@ -241,7 +241,7 @@ void taos_free_result(TAOS_RES *res) {
     taosArrayDestroyP(pRsp->rsp.blockData, taosMemoryFree);
     taosArrayDestroy(pRsp->rsp.blockDataLen);
     taosArrayDestroyP(pRsp->rsp.blockTbName, taosMemoryFree);
-    taosArrayDestroyP(pRsp->rsp.blockSchema, (FDelete)tDeleteSSchemaWrapper);
+    taosArrayDestroyP(pRsp->rsp.blockSchema, (FDelete)tDeleteSchemaWrapper);
     pRsp->resInfo.pRspMsg = NULL;
     doFreeReqResultInfo(&pRsp->resInfo);
     taosMemoryFree(pRsp);
@@ -396,11 +396,11 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
       case TSDB_DATA_TYPE_NCHAR: {
         int32_t charLen = varDataLen((char *)row[i] - VARSTR_HEADER_SIZE);
         if (fields[i].type == TSDB_DATA_TYPE_BINARY) {
-          if(ASSERT(charLen <= fields[i].bytes && charLen >= 0)){
+          if (ASSERT(charLen <= fields[i].bytes && charLen >= 0)) {
             tscError("taos_print_row error binary. charLen:%d, fields[i].bytes:%d", charLen, fields[i].bytes);
           }
         } else {
-          if(ASSERT(charLen <= fields[i].bytes * TSDB_NCHAR_SIZE && charLen >= 0)){
+          if (ASSERT(charLen <= fields[i].bytes * TSDB_NCHAR_SIZE && charLen >= 0)) {
             tscError("taos_print_row error. charLen:%d, fields[i].bytes:%d", charLen, fields[i].bytes);
           }
         }
@@ -742,16 +742,16 @@ int taos_get_current_db(TAOS *taos, char *database, int len, int *required) {
 
   int code = TSDB_CODE_SUCCESS;
   taosThreadMutexLock(&pTscObj->mutex);
-  if(database == NULL || len <= 0){
-    if(required != NULL) *required = strlen(pTscObj->db) + 1;
+  if (database == NULL || len <= 0) {
+    if (required != NULL) *required = strlen(pTscObj->db) + 1;
     terrno = TSDB_CODE_INVALID_PARA;
     code = -1;
-  }else if(len < strlen(pTscObj->db) + 1){
+  } else if (len < strlen(pTscObj->db) + 1) {
     tstrncpy(database, pTscObj->db, len);
-    if(required) *required = strlen(pTscObj->db) + 1;
+    if (required) *required = strlen(pTscObj->db) + 1;
     terrno = TSDB_CODE_INVALID_PARA;
     code = -1;
-  }else{
+  } else {
     strcpy(database, pTscObj->db);
     code = 0;
   }
@@ -778,6 +778,7 @@ static void destoryCatalogReq(SCatalogReq *pCatalogReq) {
   taosArrayDestroy(pCatalogReq->pUser);
   taosArrayDestroy(pCatalogReq->pTableIndex);
   taosArrayDestroy(pCatalogReq->pTableCfg);
+  taosArrayDestroy(pCatalogReq->pTableTag);
   taosMemoryFree(pCatalogReq);
 }
 
@@ -1012,8 +1013,10 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) {
 
   if (TSDB_CODE_SUCCESS == code) {
     pRequest->stmtType = pRequest->pQuery->pRoot->type;
-    phaseAsyncQuery(pWrapper);
-  } else {
+    code = phaseAsyncQuery(pWrapper);
+  }
+
+  if (TSDB_CODE_SUCCESS != code) {
     tscError("0x%" PRIx64 " error happens, code:%d - %s, reqId:0x%" PRIx64, pRequest->self, code, tstrerror(code),
              pRequest->requestId);
     destorySqlCallbackWrapper(pWrapper);
@@ -1079,11 +1082,11 @@ static void fetchCallback(void *pResult, void *param, int32_t code) {
 }
 
 void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
-  if(ASSERT(res != NULL && fp != NULL)){
+  if (ASSERT(res != NULL && fp != NULL)) {
     tscError("taos_fetch_rows_a invalid paras");
     return;
   }
-  if(ASSERT(TD_RES_QUERY(res))){
+  if (ASSERT(TD_RES_QUERY(res))) {
     tscError("taos_fetch_rows_a res is NULL");
     return;
   }
@@ -1129,11 +1132,11 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
 }
 
 void taos_fetch_raw_block_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
-  if(ASSERT(res != NULL && fp != NULL)){
+  if (ASSERT(res != NULL && fp != NULL)) {
     tscError("taos_fetch_rows_a invalid paras");
     return;
   }
-  if(ASSERT(TD_RES_QUERY(res))){
+  if (ASSERT(TD_RES_QUERY(res))) {
     tscError("taos_fetch_rows_a res is NULL");
     return;
   }
@@ -1148,11 +1151,11 @@ void taos_fetch_raw_block_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
 }
 
 const void *taos_get_raw_block(TAOS_RES *res) {
-  if(ASSERT(res != NULL)){
+  if (ASSERT(res != NULL)) {
     tscError("taos_fetch_rows_a invalid paras");
     return NULL;
   }
-  if(ASSERT(TD_RES_QUERY(res))){
+  if (ASSERT(TD_RES_QUERY(res))) {
     tscError("taos_fetch_rows_a res is NULL");
     return NULL;
   }
@@ -1310,7 +1313,6 @@ _return:
   return code;
 }
 
-
 int taos_load_table_info(TAOS *taos, const char *tableNameList) {
   if (NULL == taos) {
     terrno = TSDB_CODE_TSC_DISCONNECTED;
diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c
index 52c5fc7940..6d53f2b4c5 100644
--- a/source/client/src/clientMsgHandler.c
+++ b/source/client/src/clientMsgHandler.c
@@ -92,7 +92,6 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) {
     goto End;
   }
 
-  /*assert(connectRsp.epSet.numOfEps > 0);*/
   if (connectRsp.epSet.numOfEps == 0) {
     setErrno(pRequest, TSDB_CODE_APP_ERROR);
     tsem_post(&pRequest->body.rspSem);
diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c
index d12e0b5c19..f8c819c407 100644
--- a/source/client/src/clientSml.c
+++ b/source/client/src/clientSml.c
@@ -195,6 +195,20 @@ int32_t smlSetCTableName(SSmlTableInfo *oneTable) {
   return TSDB_CODE_SUCCESS;
 }
 
+void getTableUid(SSmlHandle *info, SSmlLineInfo *currElement, SSmlTableInfo *tinfo){
+  char key[TSDB_TABLE_NAME_LEN * 2 + 1] = {0};
+  size_t nLen = strlen(tinfo->childTableName);
+  memcpy(key, currElement->measure, currElement->measureLen);
+  memcpy(key + currElement->measureLen + 1, tinfo->childTableName, nLen);
+  void *uid = taosHashGet(info->tableUids, key, currElement->measureLen + 1 + nLen);    // use \0 as separator for stable name and child table name
+  if (uid == NULL) {
+    tinfo->uid = info->uid++;
+    taosHashPut(info->tableUids, key, currElement->measureLen + 1 + nLen, &tinfo->uid, sizeof(uint64_t));
+  }else{
+    tinfo->uid = *(uint64_t*)uid;
+  }
+}
+
 SSmlSTableMeta *smlBuildSTableMeta(bool isDataFormat) {
   SSmlSTableMeta *meta = (SSmlSTableMeta *)taosMemoryCalloc(sizeof(SSmlSTableMeta), 1);
   if (!meta) {
@@ -534,8 +548,8 @@ static int32_t smlGenerateSchemaAction(SSchema *colField, SHashObj *colHash, SSm
   uint16_t *index = colHash ? (uint16_t *)taosHashGet(colHash, kv->key, kv->keyLen) : NULL;
   if (index) {
     if (colField[*index].type != kv->type) {
-      uError("SML:0x%" PRIx64 " point type and db type mismatch. point type: %d, db type: %d, key: %s", info->id, colField[*index].type, kv->type, kv->key);
-      return TSDB_CODE_TSC_INVALID_VALUE;
+      uError("SML:0x%" PRIx64 " point type and db type mismatch. db type: %d, point type: %d, key: %s", info->id, colField[*index].type, kv->type, kv->key);
+      return TSDB_CODE_SML_INVALID_DATA;
     }
 
     if ((colField[*index].type == TSDB_DATA_TYPE_VARCHAR &&
@@ -662,7 +676,7 @@ static int32_t smlBuildFieldsList(SSmlHandle *info, SSchema *schemaField, SHashO
     SField *field = taosArrayGet(results, j);
     len += field->bytes;
   }
-  if (len > maxLen) {
+  if(len > maxLen){
     return isTag ? TSDB_CODE_PAR_INVALID_TAGS_LENGTH : TSDB_CODE_PAR_INVALID_ROW_LENGTH;
   }
 
@@ -786,8 +800,12 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
 
     size_t superTableLen = 0;
     void  *superTable = taosHashGetKey(tmp, &superTableLen);
+    char* measure = taosMemoryMalloc(superTableLen);
+    memcpy(measure, superTable, superTableLen);
+    PROCESS_SLASH_IN_MEASUREMENT(measure, superTableLen);
     memset(pName.tname, 0, TSDB_TABLE_NAME_LEN);
-    memcpy(pName.tname, superTable, superTableLen);
+    memcpy(pName.tname, measure, superTableLen);
+    taosMemoryFree(measure);
 
     code = catalogGetSTableMeta(info->pCatalog, &conn, &pName, &pTableMeta);
 
@@ -1101,7 +1119,7 @@ void smlDestroyTableInfo(SSmlHandle *info, SSmlTableInfo *tag) {
   //  }
   //  taosMemoryFree(tag->key);
   taosArrayDestroy(tag->cols);
-  taosArrayDestroy(tag->tags);
+  taosArrayDestroyEx(tag->tags, freeSSmlKv);
   taosMemoryFree(tag);
 }
 
@@ -1115,6 +1133,12 @@ void clearColValArray(SArray *pCols) {
   }
 }
 
+void freeSSmlKv(void* data){
+  SSmlKv *kv = (SSmlKv*)data;
+  if(kv->keyEscaped) taosMemoryFree((void*)(kv->key));
+  if(kv->valueEscaped) taosMemoryFree((void*)(kv->value));
+}
+
 void smlDestroyInfo(SSmlHandle *info) {
   if (!info) return;
   qDestroyQuery(info->pQuery);
@@ -1137,6 +1161,7 @@ void smlDestroyInfo(SSmlHandle *info) {
   taosHashCleanup(info->pVgHash);
   taosHashCleanup(info->childTables);
   taosHashCleanup(info->superTables);
+  taosHashCleanup(info->tableUids);
 
   for (int i = 0; i < taosArrayGetSize(info->tagJsonArray); i++) {
     cJSON *tags = (cJSON *)taosArrayGetP(info->tagJsonArray, i);
@@ -1150,11 +1175,11 @@ void smlDestroyInfo(SSmlHandle *info) {
   }
   taosArrayDestroy(info->valueJsonArray);
 
-  taosArrayDestroy(info->preLineTagKV);
+  taosArrayDestroyEx(info->preLineTagKV, freeSSmlKv);
 
   if (!info->dataFormat) {
     for (int i = 0; i < info->lineNum; i++) {
-      taosArrayDestroy(info->lines[i].colArray);
+      taosArrayDestroyEx(info->lines[i].colArray, freeSSmlKv);
       if (info->parseJsonByLib) {
         taosMemoryFree(info->lines[i].tags);
       }
@@ -1187,6 +1212,7 @@ SSmlHandle *smlBuildSmlInfo(TAOS *taos) {
 
   info->pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
   info->childTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
+  info->tableUids = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
   info->superTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
 
   info->id = smlGenId();
@@ -1197,7 +1223,7 @@ SSmlHandle *smlBuildSmlInfo(TAOS *taos) {
   info->valueJsonArray = taosArrayInit(8, POINTER_BYTES);
   info->preLineTagKV = taosArrayInit(8, sizeof(SSmlKv));
 
-  if (NULL == info->pVgHash || NULL == info->childTables || NULL == info->superTables) {
+  if (NULL == info->pVgHash || NULL == info->childTables || NULL == info->superTables || NULL == info->tableUids) {
     uError("create SSmlHandle failed");
     goto cleanup;
   }
@@ -1217,6 +1243,7 @@ static int32_t smlPushCols(SArray *colsArray, SArray *cols) {
   }
   for (size_t i = 0; i < taosArrayGetSize(cols); i++) {
     SSmlKv *kv = (SSmlKv *)taosArrayGet(cols, i);
+    terrno = 0;
     taosHashPut(kvHash, kv->key, kv->keyLen, &kv, POINTER_BYTES);
     if (terrno == TSDB_CODE_DUP_KEY) {
       taosHashCleanup(kvHash);
@@ -1294,6 +1321,7 @@ static int32_t smlParseLineBottom(SSmlHandle *info) {
              info->lineNum);
       SSmlSTableMeta *meta = smlBuildSTableMeta(info->dataFormat);
       taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES);
+      terrno = 0;
       smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags);
       if (terrno == TSDB_CODE_DUP_KEY) {
         return terrno;
@@ -1313,23 +1341,23 @@ static int32_t smlInsertData(SSmlHandle *info) {
   if (info->pRequest->dbList == NULL) {
     info->pRequest->dbList = taosArrayInit(1, TSDB_DB_FNAME_LEN);
   }
-  void *data = taosArrayReserve(info->pRequest->dbList, 1);
-  memcpy(data, info->pRequest->pDb,
-         TSDB_DB_FNAME_LEN > strlen(info->pRequest->pDb) ? strlen(info->pRequest->pDb) : TSDB_DB_FNAME_LEN);
+  char *data = (char*)taosArrayReserve(info->pRequest->dbList, 1);
+  SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
+  tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname));
+  tNameGetFullDbName(&pName, data);
 
   SSmlTableInfo **oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL);
   while (oneTable) {
     SSmlTableInfo *tableData = *oneTable;
-
-    SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}};
-    tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname));
-    memcpy(pName.tname, tableData->childTableName, strlen(tableData->childTableName));
+    tstrncpy(pName.tname, tableData->sTableName, tableData->sTableNameLen + 1);
 
     if (info->pRequest->tableList == NULL) {
       info->pRequest->tableList = taosArrayInit(1, sizeof(SName));
     }
     taosArrayPush(info->pRequest->tableList, &pName);
 
+    strcpy(pName.tname, tableData->childTableName);
+
     SRequestConnInfo conn = {0};
     conn.pTrans = info->taos->pAppInfo->pTransporter;
     conn.requestId = info->pRequest->requestId;
@@ -1357,9 +1385,15 @@ static int32_t smlInsertData(SSmlHandle *info) {
     uDebug("SML:0x%" PRIx64 " smlInsertData table:%s, uid:%" PRIu64 ", format:%d", info->id, pName.tname,
            tableData->uid, info->dataFormat);
 
+    int   measureLen = tableData->sTableNameLen;
+    char* measure = (char*)taosMemoryMalloc(tableData->sTableNameLen);
+    memcpy(measure, tableData->sTableName, tableData->sTableNameLen);
+    PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
+
     code = smlBindData(info->pQuery, info->dataFormat, tableData->tags, (*pMeta)->cols, tableData->cols,
-                       (*pMeta)->tableMeta, tableData->childTableName, tableData->sTableName, tableData->sTableNameLen,
+                       (*pMeta)->tableMeta, tableData->childTableName, measure, measureLen,
                        info->ttl, info->msgBuf.buf, info->msgBuf.len);
+    taosMemoryFree(measure);
     if (code != TSDB_CODE_SUCCESS) {
       uError("SML:0x%" PRIx64 " smlBindData failed", info->id);
       return code;
@@ -1415,6 +1449,7 @@ int32_t smlClearForRerun(SSmlHandle *info) {
 
   taosHashClear(info->childTables);
   taosHashClear(info->superTables);
+  taosHashClear(info->tableUids);
 
   if (!info->dataFormat) {
     if (unlikely(info->lines != NULL)) {
@@ -1473,14 +1508,14 @@ static int32_t smlParseLine(SSmlHandle *info, char *lines[], char *rawLine, char
 
     char cTmp = 0;  // for print tmp if is raw
     if (info->isRawLine) {
-      cTmp = tmp[len - 1];
-      tmp[len - 1] = '\0';
+      cTmp = tmp[len];
+      tmp[len] = '\0';
     }
 
     uDebug("SML:0x%" PRIx64 " smlParseLine israw:%d, numLines:%d, protocol:%d, len:%d, sql:%s", info->id,
            info->isRawLine, numLines, info->protocol, len, tmp);
     if (info->isRawLine) {
-      tmp[len - 1] = cTmp;
+      tmp[len] = cTmp;
     }
 
     if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
@@ -1502,6 +1537,7 @@ static int32_t smlParseLine(SSmlHandle *info, char *lines[], char *rawLine, char
       code = TSDB_CODE_SML_INVALID_PROTOCOL_TYPE;
     }
     if (code != TSDB_CODE_SUCCESS) {
+      tmp[len] = '\0';
       uError("SML:0x%" PRIx64 " smlParseLine failed. line %d : %s", info->id, i, tmp);
       return code;
     }
@@ -1547,10 +1583,11 @@ static int smlProcess(SSmlHandle *info, char *lines[], char *rawLine, char *rawL
 
   do {
     code = smlModifyDBSchemas(info);
-    if (code == 0 || code == TSDB_CODE_SML_INVALID_DATA || code == TSDB_CODE_PAR_TOO_MANY_COLUMNS ||
-        code == TSDB_CODE_PAR_INVALID_TAGS_NUM || code == TSDB_CODE_PAR_INVALID_ROW_LENGTH ||
-        code == TSDB_CODE_PAR_INVALID_TAGS_LENGTH)
+    if (code == 0 || code == TSDB_CODE_SML_INVALID_DATA || code == TSDB_CODE_PAR_TOO_MANY_COLUMNS
+        || code == TSDB_CODE_PAR_INVALID_TAGS_NUM || code == TSDB_CODE_PAR_INVALID_TAGS_LENGTH
+        || code == TSDB_CODE_PAR_INVALID_ROW_LENGTH || code == TSDB_CODE_MND_FIELD_VALUE_OVERFLOW) {
       break;
+    }
     taosMsleep(100);
     uInfo("SML:0x%" PRIx64 " smlModifyDBSchemas retry code:%s, times:%d", info->id, tstrerror(code), retryNum);
   } while (retryNum++ < taosHashGetSize(info->superTables) * MAX_RETRY_TIMES);
@@ -1575,7 +1612,7 @@ void smlSetReqSQL(SRequestObj *request, char *lines[], char *rawLine, char *rawL
     int32_t len = 0;
     int32_t rlen = 0;
     char* p = NULL;
-    
+
     if (lines && lines[0]) {
       len = strlen(lines[0]);
       p = lines[0];
@@ -1591,7 +1628,7 @@ void smlSetReqSQL(SRequestObj *request, char *lines[], char *rawLine, char *rawL
     if (NULL == p) {
       return;
     }
-    
+
     rlen = TMIN(len, TSDB_MAX_ALLOWED_SQL_LEN);
     rlen = TMAX(rlen, 0);
 
@@ -1675,7 +1712,8 @@ TAOS_RES *taos_schemaless_insert_inner(TAOS *taos, char *lines[], char *rawLine,
     info->cost.endTime = taosGetTimestampUs();
     info->cost.code = code;
     if (code == TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER || code == TSDB_CODE_SDB_OBJ_CREATING ||
-        code == TSDB_CODE_PAR_VALUE_TOO_LONG || code == TSDB_CODE_MND_TRANS_CONFLICT) {
+        code == TSDB_CODE_PAR_VALUE_TOO_LONG || code == TSDB_CODE_MND_TRANS_CONFLICT ||
+        code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
       if (cnt++ >= 10) {
         uInfo("SML:%" PRIx64 " retry:%d/10 end code:%d, msg:%s", info->id, cnt, code, tstrerror(code));
         break;
diff --git a/source/client/src/clientSmlJson.c b/source/client/src/clientSmlJson.c
index b0ae316031..7ccf930964 100644
--- a/source/client/src/clientSmlJson.c
+++ b/source/client/src/clientSmlJson.c
@@ -778,7 +778,7 @@ static int32_t smlParseTagsFromJSON(SSmlHandle *info, cJSON *tags, SSmlLineInfo
     tinfo->tags = taosArrayDup(preLineKV, NULL);
 
     smlSetCTableName(tinfo);
-    tinfo->uid = info->uid++;
+    getTableUid(info, elements, tinfo);
     if (info->dataFormat) {
       info->currSTableMeta->uid = tinfo->uid;
       tinfo->tableDataCtx = smlInitTableDataCtx(info->pQuery, info->currSTableMeta);
diff --git a/source/client/src/clientSmlLine.c b/source/client/src/clientSmlLine.c
index db2f2bd9fe..2f7e8a0f97 100644
--- a/source/client/src/clientSmlLine.c
+++ b/source/client/src/clientSmlLine.c
@@ -21,32 +21,33 @@
 #include "clientSml.h"
 
 // comma ,
-// #define IS_SLASH_COMMA(sql) (*(sql) == COMMA && *((sql)-1) == SLASH)
 #define IS_COMMA(sql) (*(sql) == COMMA && *((sql)-1) != SLASH)
 // space
-// #define IS_SLASH_SPACE(sql) (*(sql) == SPACE && *((sql)-1) == SLASH)
 #define IS_SPACE(sql) (*(sql) == SPACE && *((sql)-1) != SLASH)
 // equal =
-// #define IS_SLASH_EQUAL(sql) (*(sql) == EQUAL && *((sql)-1) == SLASH)
 #define IS_EQUAL(sql) (*(sql) == EQUAL && *((sql)-1) != SLASH)
 // quote "
-// #define IS_SLASH_QUOTE(sql) (*(sql) == QUOTE && *((sql)-1) == SLASH)
-#define IS_QUOTE(sql) (*(sql) == QUOTE && *((sql)-1) != SLASH)
+//#define IS_QUOTE(sql) (*(sql) == QUOTE && *((sql)-1) != SLASH)
 // SLASH
-// #define IS_SLASH_SLASH(sql) (*(sql) == SLASH && *((sql)-1) == SLASH)
 
-#define IS_SLASH_LETTER(sql)                                                                           \
-  (*((sql)-1) == SLASH && (*(sql) == COMMA || *(sql) == SPACE || *(sql) == EQUAL || *(sql) == QUOTE || \
-                           *(sql) == SLASH))  //  (IS_SLASH_COMMA(sql) || IS_SLASH_SPACE(sql) || IS_SLASH_EQUAL(sql) ||
-                                              //  IS_SLASH_QUOTE(sql) || IS_SLASH_SLASH(sql))
+#define IS_SLASH_LETTER_IN_FIELD_VALUE(sql)                                                           \
+  (*((sql)-1) == SLASH && (*(sql) == QUOTE || *(sql) == SLASH))
 
-#define MOVE_FORWARD_ONE(sql, len) (memmove((void *)((sql)-1), (sql), len))
+#define IS_SLASH_LETTER_IN_TAG_FIELD_KEY(sql)                                                         \
+  (*((sql)-1) == SLASH && (*(sql) == COMMA || *(sql) == SPACE || *(sql) == EQUAL))
 
-#define PROCESS_SLASH(key, keyLen)           \
-  for (int i = 1; i < keyLen; ++i) {         \
-    if (IS_SLASH_LETTER(key + i)) {          \
+#define PROCESS_SLASH_IN_FIELD_VALUE(key, keyLen)           \
+  for (int i = 1; i < keyLen; ++i) {                        \
+    if (IS_SLASH_LETTER_IN_FIELD_VALUE(key + i)) {          \
+      MOVE_FORWARD_ONE(key + i, keyLen - i); \
+      keyLen--;                              \
+    }                                        \
+  }
+
+#define PROCESS_SLASH_IN_TAG_FIELD_KEY(key, keyLen)           \
+  for (int i = 1; i < keyLen; ++i) {         \
+    if (IS_SLASH_LETTER_IN_TAG_FIELD_KEY(key + i)) {          \
       MOVE_FORWARD_ONE(key + i, keyLen - i); \
-      i--;                                   \
       keyLen--;                              \
     }                                        \
   }
@@ -151,7 +152,17 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
 
       SSmlSTableMeta *sMeta = NULL;
       if (unlikely(tmp == NULL)) {
-        STableMeta *pTableMeta = smlGetMeta(info, currElement->measure, currElement->measureLen);
+        char* measure = currElement->measure;
+        int   measureLen = currElement->measureLen;
+        if(currElement->measureEscaped){
+          measure = (char*)taosMemoryMalloc(currElement->measureLen);
+          memcpy(measure, currElement->measure, currElement->measureLen);
+          PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
+        }
+        STableMeta *pTableMeta = smlGetMeta(info, measure, measureLen);
+        if(currElement->measureEscaped){
+          taosMemoryFree(measure);
+        }
         if (pTableMeta == NULL) {
           info->dataFormat = false;
           info->reRun = true;
@@ -171,17 +182,18 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
       info->maxTagKVs = (*tmp)->tags;
     }
   }
-  taosArrayClear(preLineKV);
+  taosArrayClearEx(preLineKV, freeSSmlKv);
 
   while (*sql < sqlEnd) {
     if (unlikely(IS_SPACE(*sql))) {
       break;
     }
 
-    bool hasSlash = false;
     // parse key
     const char *key = *sql;
     size_t      keyLen = 0;
+    bool        keyEscaped = false;
+    size_t      keyLenEscaped = 0;
     while (*sql < sqlEnd) {
       if (unlikely(IS_COMMA(*sql))) {
         smlBuildInvalidDataMsg(&info->msgBuf, "invalid data", *sql);
@@ -192,16 +204,14 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
         (*sql)++;
         break;
       }
-      if (!hasSlash) {
-        hasSlash = (*(*sql) == SLASH);
+      if (IS_SLASH_LETTER_IN_TAG_FIELD_KEY(*sql)) {
+        keyLenEscaped++;
+        keyEscaped = true;
       }
       (*sql)++;
     }
-    if (unlikely(hasSlash)) {
-      PROCESS_SLASH(key, keyLen)
-    }
 
-    if (unlikely(IS_INVALID_COL_LEN(keyLen))) {
+    if (unlikely(IS_INVALID_COL_LEN(keyLen - keyLenEscaped))) {
       smlBuildInvalidDataMsg(&info->msgBuf, "invalid key or key is too long than 64", key);
       return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
     }
@@ -209,7 +219,8 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
     // parse value
     const char *value = *sql;
     size_t      valueLen = 0;
-    hasSlash = false;
+    bool        valueEscaped = false;
+    size_t      valueLenEscaped = 0;
     while (*sql < sqlEnd) {
       // parse value
       if (unlikely(IS_SPACE(*sql) || IS_COMMA(*sql))) {
@@ -219,8 +230,9 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
         return TSDB_CODE_SML_INVALID_DATA;
       }
 
-      if (!hasSlash) {
-        hasSlash = (*(*sql) == SLASH);
+      if (IS_SLASH_LETTER_IN_TAG_FIELD_KEY(*sql)) {
+        valueLenEscaped++;
+        valueEscaped = true;
       }
 
       (*sql)++;
@@ -232,15 +244,24 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
       return TSDB_CODE_SML_INVALID_DATA;
     }
 
-    if (unlikely(hasSlash)) {
-      PROCESS_SLASH(value, valueLen)
-    }
-
-    if (unlikely(valueLen > (TSDB_MAX_TAGS_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE)) {
+    if (unlikely(valueLen - valueLenEscaped > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE)) {
       return TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN;
     }
 
-    SSmlKv kv = {.key = key, .keyLen = keyLen, .type = TSDB_DATA_TYPE_NCHAR, .value = value, .length = valueLen};
+    if (keyEscaped){
+      char *tmp = (char*)taosMemoryMalloc(keyLen);
+      memcpy(tmp, key, keyLen);
+      PROCESS_SLASH_IN_TAG_FIELD_KEY(tmp, keyLen);
+      key = tmp;
+    }
+    if (valueEscaped){
+      char *tmp = (char*)taosMemoryMalloc(valueLen);
+      memcpy(tmp, value, valueLen);
+      PROCESS_SLASH_IN_TAG_FIELD_KEY(tmp, valueLen);
+      value = tmp;
+    }
+    SSmlKv kv = {.key = key, .keyLen = keyLen, .type = TSDB_DATA_TYPE_NCHAR, .value = value, .length = valueLen, .keyEscaped = keyEscaped, .valueEscaped = valueEscaped};
+    taosArrayPush(preLineKV, &kv);
     if (info->dataFormat) {
       if (unlikely(cnt + 1 > info->currSTableMeta->tableInfo.numOfTags)) {
         info->dataFormat = false;
@@ -266,7 +287,6 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
         info->needModifySchema = true;
       }
     }
-    taosArrayPush(preLineKV, &kv);
 
     cnt++;
     if (IS_SPACE(*sql)) {
@@ -285,9 +305,14 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
     return TSDB_CODE_OUT_OF_MEMORY;
   }
   tinfo->tags = taosArrayDup(preLineKV, NULL);
+  for(size_t i = 0; i < taosArrayGetSize(preLineKV); i++){
+    SSmlKv *kv = (SSmlKv *)taosArrayGet(preLineKV, i);
+    if(kv->keyEscaped)kv->key = NULL;
+    if(kv->valueEscaped)kv->value = NULL;
+  }
 
   smlSetCTableName(tinfo);
-  tinfo->uid = info->uid++;
+  getTableUid(info, currElement, tinfo);
   if (info->dataFormat) {
     info->currSTableMeta->uid = tinfo->uid;
     tinfo->tableDataCtx = smlInitTableDataCtx(info->pQuery, info->currSTableMeta);
@@ -321,7 +346,17 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
       SSmlSTableMeta **tmp =
           (SSmlSTableMeta **)taosHashGet(info->superTables, currElement->measure, currElement->measureLen);
       if (unlikely(tmp == NULL)) {
-        STableMeta *pTableMeta = smlGetMeta(info, currElement->measure, currElement->measureLen);
+        char* measure = currElement->measure;
+        int   measureLen = currElement->measureLen;
+        if(currElement->measureEscaped){
+          measure = (char*)taosMemoryMalloc(currElement->measureLen);
+          memcpy(measure, currElement->measure, currElement->measureLen);
+          PROCESS_SLASH_IN_MEASUREMENT(measure, measureLen);
+        }
+        STableMeta *pTableMeta = smlGetMeta(info, measure, measureLen);
+        if(currElement->measureEscaped){
+          taosMemoryFree(measure);
+        }
         if (pTableMeta == NULL) {
           info->dataFormat = false;
           info->reRun = true;
@@ -352,10 +387,11 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
       break;
     }
 
-    bool hasSlash = false;
     // parse key
     const char *key = *sql;
     size_t      keyLen = 0;
+    bool        keyEscaped = false;
+    size_t      keyLenEscaped = 0;
     while (*sql < sqlEnd) {
       if (unlikely(IS_COMMA(*sql))) {
         smlBuildInvalidDataMsg(&info->msgBuf, "invalid data", *sql);
@@ -366,16 +402,14 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
         (*sql)++;
         break;
       }
-      if (!hasSlash) {
-        hasSlash = (*(*sql) == SLASH);
+      if (IS_SLASH_LETTER_IN_TAG_FIELD_KEY(*sql)) {
+        keyLenEscaped++;
+        keyEscaped = true;
       }
       (*sql)++;
     }
-    if (unlikely(hasSlash)) {
-      PROCESS_SLASH(key, keyLen)
-    }
 
-    if (unlikely(IS_INVALID_COL_LEN(keyLen))) {
+    if (unlikely(IS_INVALID_COL_LEN(keyLen - keyLenEscaped))) {
       smlBuildInvalidDataMsg(&info->msgBuf, "invalid key or key is too long than 64", key);
       return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
     }
@@ -383,11 +417,13 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
     // parse value
     const char *value = *sql;
     size_t      valueLen = 0;
-    hasSlash = false;
-    bool isInQuote = false;
+    bool        valueEscaped = false;
+    size_t      valueLenEscaped = 0;
+    bool        isInQuote = false;
+    const char *escapeChar = NULL;
     while (*sql < sqlEnd) {
       // parse value
-      if (unlikely(IS_QUOTE(*sql))) {
+      if (unlikely(*(*sql) == QUOTE && (*(*sql - 1) != SLASH || (*sql - 1) == escapeChar))) {
         isInQuote = !isInQuote;
         (*sql)++;
         continue;
@@ -395,13 +431,12 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
       if (!isInQuote) {
         if (unlikely(IS_SPACE(*sql) || IS_COMMA(*sql))) {
           break;
-        } else if (unlikely(IS_EQUAL(*sql))) {
-          smlBuildInvalidDataMsg(&info->msgBuf, "invalid data", *sql);
-          return TSDB_CODE_SML_INVALID_DATA;
         }
       }
-      if (!hasSlash) {
-        hasSlash = (*(*sql) == SLASH);
+      if (IS_SLASH_LETTER_IN_FIELD_VALUE(*sql) && (*sql - 1) != escapeChar) {
+        escapeChar = *sql;
+        valueEscaped = true;
+        valueLenEscaped++;
       }
 
       (*sql)++;
@@ -416,9 +451,6 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
       smlBuildInvalidDataMsg(&info->msgBuf, "invalid value", value);
       return TSDB_CODE_SML_INVALID_DATA;
     }
-    if (unlikely(hasSlash)) {
-      PROCESS_SLASH(value, valueLen)
-    }
 
     SSmlKv  kv = {.key = key, .keyLen = keyLen, .value = value, .length = valueLen};
     int32_t ret = smlParseValue(&kv, &info->msgBuf);
@@ -427,11 +459,28 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
       return ret;
     }
 
+    if (keyEscaped){
+      char *tmp = (char*)taosMemoryMalloc(kv.keyLen);
+      memcpy(tmp, key, kv.keyLen);
+      PROCESS_SLASH_IN_TAG_FIELD_KEY(tmp, kv.keyLen);
+      kv.key = tmp;
+      kv.keyEscaped = keyEscaped;
+    }
+
+    if (valueEscaped){
+      char *tmp = (char*)taosMemoryMalloc(kv.length);
+      memcpy(tmp, kv.value, kv.length);
+      PROCESS_SLASH_IN_FIELD_VALUE(tmp, kv.length);
+      kv.value = tmp;
+      kv.valueEscaped = valueEscaped;
+    }
+
     if (info->dataFormat) {
       // cnt begin 0, add ts so + 2
       if (unlikely(cnt + 2 > info->currSTableMeta->tableInfo.numOfColumns)) {
         info->dataFormat = false;
         info->reRun = true;
+        freeSSmlKv(&kv);
         return TSDB_CODE_SUCCESS;
       }
       // bind data
@@ -440,22 +489,26 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
         uDebug("smlBuildCol error, retry");
         info->dataFormat = false;
         info->reRun = true;
+        freeSSmlKv(&kv);
         return TSDB_CODE_SUCCESS;
       }
       if (cnt >= taosArrayGetSize(info->masColKVs)) {
         info->dataFormat = false;
         info->reRun = true;
+        freeSSmlKv(&kv);
         return TSDB_CODE_SUCCESS;
       }
       SSmlKv *maxKV = (SSmlKv *)taosArrayGet(info->masColKVs, cnt);
       if (kv.type != maxKV->type) {
         info->dataFormat = false;
         info->reRun = true;
+        freeSSmlKv(&kv);
         return TSDB_CODE_SUCCESS;
       }
       if (unlikely(!IS_SAME_KEY)) {
         info->dataFormat = false;
         info->reRun = true;
+        freeSSmlKv(&kv);
         return TSDB_CODE_SUCCESS;
       }
 
@@ -463,6 +516,7 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
         maxKV->length = kv.length;
         info->needModifySchema = true;
       }
+      freeSSmlKv(&kv);
     } else {
       if (currElement->colArray == NULL) {
         currElement->colArray = taosArrayInit_s(sizeof(SSmlKv), 1);
@@ -487,10 +541,12 @@ int32_t smlParseInfluxString(SSmlHandle *info, char *sql, char *sqlEnd, SSmlLine
   elements->measure = sql;
 
   // parse measure
+  size_t measureLenEscaped = 0;
   while (sql < sqlEnd) {
-    if (unlikely((sql != elements->measure) && IS_SLASH_LETTER(sql))) {
-      MOVE_FORWARD_ONE(sql, sqlEnd - sql);
-      sqlEnd--;
+    if (unlikely((sql != elements->measure) && IS_SLASH_LETTER_IN_MEASUREMENT(sql))) {
+      elements->measureEscaped = true;
+      measureLenEscaped++;
+      sql++;
       continue;
     }
     if (unlikely(IS_COMMA(sql))) {
@@ -503,7 +559,7 @@ int32_t smlParseInfluxString(SSmlHandle *info, char *sql, char *sqlEnd, SSmlLine
     sql++;
   }
   elements->measureLen = sql - elements->measure;
-  if (unlikely(IS_INVALID_TABLE_LEN(elements->measureLen))) {
+  if (unlikely(IS_INVALID_TABLE_LEN(elements->measureLen - measureLenEscaped))) {
     smlBuildInvalidDataMsg(&info->msgBuf, "measure is empty or too large than 192", NULL);
     return TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH;
   }
@@ -581,7 +637,9 @@ int32_t smlParseInfluxString(SSmlHandle *info, char *sql, char *sqlEnd, SSmlLine
                .keyLen = TS_LEN,
                .type = TSDB_DATA_TYPE_TIMESTAMP,
                .i = ts,
-               .length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes};
+               .length = (size_t)tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes,
+               .keyEscaped = false,
+               .valueEscaped = false};
   if (info->dataFormat) {
     uDebug("SML:0x%" PRIx64 " smlParseInfluxString format true, ts:%" PRId64, info->id, ts);
     ret = smlBuildCol(info->currTableDataCtx, info->currSTableMeta->schema, &kv, 0);
diff --git a/source/client/src/clientSmlTelnet.c b/source/client/src/clientSmlTelnet.c
index 3a9aad4e81..42b8001e59 100644
--- a/source/client/src/clientSmlTelnet.c
+++ b/source/client/src/clientSmlTelnet.c
@@ -206,7 +206,7 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS
     tinfo->tags = taosArrayDup(preLineKV, NULL);
 
     smlSetCTableName(tinfo);
-    tinfo->uid = info->uid++;
+    getTableUid(info, elements, tinfo);
     if (info->dataFormat) {
       info->currSTableMeta->uid = tinfo->uid;
       tinfo->tableDataCtx = smlInitTableDataCtx(info->pQuery, info->currSTableMeta);
diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c
index 6e529f1a0b..975b304bf4 100644
--- a/source/client/src/clientStmt.c
+++ b/source/client/src/clientStmt.c
@@ -325,7 +325,7 @@ int32_t stmtCleanExecInfo(STscStmt* pStmt, bool keepTable, bool deepClean) {
   taosHashCleanup(pStmt->exec.pBlockHash);
   pStmt->exec.pBlockHash = NULL;
 
-  tDestroySSubmitTbData(pStmt->exec.pCurrTbData, TSDB_MSG_FLG_ENCODE);
+  tDestroySubmitTbData(pStmt->exec.pCurrTbData, TSDB_MSG_FLG_ENCODE);
   taosMemoryFreeClear(pStmt->exec.pCurrTbData);
 
   STMT_ERR_RET(stmtCleanBindInfo(pStmt));
@@ -895,7 +895,7 @@ int stmtExec(TAOS_STMT* stmt) {
   if (STMT_TYPE_QUERY == pStmt->sql.type) {
     launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, true, NULL);
   } else {
-    tDestroySSubmitTbData(pStmt->exec.pCurrTbData, TSDB_MSG_FLG_ENCODE);
+    tDestroySubmitTbData(pStmt->exec.pCurrTbData, TSDB_MSG_FLG_ENCODE);
     taosMemoryFreeClear(pStmt->exec.pCurrTbData);
 
     STMT_ERR_RET(qCloneCurrentTbData(pStmt->exec.pCurrBlock, &pStmt->exec.pCurrTbData));
diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c
index b9d4e4edab..87aee4a8a3 100644
--- a/source/client/src/clientTmq.c
+++ b/source/client/src/clientTmq.c
@@ -397,9 +397,6 @@ int32_t tmq_list_append(tmq_list_t* list, const char* src) {
   SArray* container = &list->container;
   if (src == NULL || src[0] == 0) return -1;
   char* topic = taosStrdup(src);
-  if (topic[0] != '`') {
-    strtolower(topic, src);
-  }
   if (taosArrayPush(container, &topic) == NULL) return -1;
   return 0;
 }
@@ -898,7 +895,7 @@ static void* tmqFreeRspWrapper(SMqRspWrapper* rspWrapper) {
     taosArrayDestroyP(pRsp->dataRsp.blockData, taosMemoryFree);
     taosArrayDestroy(pRsp->dataRsp.blockDataLen);
     taosArrayDestroyP(pRsp->dataRsp.blockTbName, taosMemoryFree);
-    taosArrayDestroyP(pRsp->dataRsp.blockSchema, (FDelete)tDeleteSSchemaWrapper);
+    taosArrayDestroyP(pRsp->dataRsp.blockSchema, (FDelete)tDeleteSchemaWrapper);
   } else if (rspWrapper->tmqRspType == TMQ_MSG_TYPE__POLL_META_RSP) {
     SMqPollRspWrapper* pRsp = (SMqPollRspWrapper*)rspWrapper;
     taosMemoryFreeClear(pRsp->pEpset);
@@ -911,7 +908,7 @@ static void* tmqFreeRspWrapper(SMqRspWrapper* rspWrapper) {
     taosArrayDestroyP(pRsp->taosxRsp.blockData, taosMemoryFree);
     taosArrayDestroy(pRsp->taosxRsp.blockDataLen);
     taosArrayDestroyP(pRsp->taosxRsp.blockTbName, taosMemoryFree);
-    taosArrayDestroyP(pRsp->taosxRsp.blockSchema, (FDelete)tDeleteSSchemaWrapper);
+    taosArrayDestroyP(pRsp->taosxRsp.blockSchema, (FDelete)tDeleteSchemaWrapper);
     // taosx
     taosArrayDestroy(pRsp->taosxRsp.createTableLen);
     taosArrayDestroyP(pRsp->taosxRsp.createTableReq, taosMemoryFree);
@@ -1265,9 +1262,6 @@ static int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
   taosMemoryFree(pParam);
 
   if (code != 0) {
-    tscWarn("consumer:0x%" PRIx64 " msg from vgId:%d discarded, epoch %d, since %s, reqId:0x%" PRIx64, tmq->consumerId,
-            vgId, epoch, tstrerror(code), requestId);
-
     if (pMsg->pData) taosMemoryFree(pMsg->pData);
     if (pMsg->pEpSet) taosMemoryFree(pMsg->pEpSet);
 
@@ -1289,6 +1283,9 @@ static int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
       taosWriteQitem(tmq->mqueue, pRspWrapper);
     } else if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {  // poll data while insert
       taosMsleep(500);
+    } else{
+      tscError("consumer:0x%" PRIx64 " msg from vgId:%d discarded, epoch %d, since %s, reqId:0x%" PRIx64, tmq->consumerId,
+               vgId, epoch, tstrerror(code), requestId);
     }
 
     goto CREATE_MSG_FAIL;
@@ -1402,7 +1399,7 @@ static void initClientTopicFromRsp(SMqClientTopic* pTopic, SMqSubTopicEp* pTopic
   tstrncpy(pTopic->topicName, pTopicEp->topic, TSDB_TOPIC_FNAME_LEN);
   tstrncpy(pTopic->db, pTopicEp->db, TSDB_DB_FNAME_LEN);
 
-  tscDebug("consumer:0x%" PRIx64 ", update topic:%s, numOfVgs:%d", tmq->consumerId, pTopic->topicName, vgNumGet);
+  tscDebug("consumer:0x%" PRIx64 ", update topic:%s, new numOfVgs:%d", tmq->consumerId, pTopic->topicName, vgNumGet);
   pTopic->vgs = taosArrayInit(vgNumGet, sizeof(SMqClientVg));
 
   for (int32_t j = 0; j < vgNumGet; j++) {
@@ -1475,7 +1472,7 @@ static bool doUpdateLocalEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp)
     SMqClientTopic* pTopicCur = taosArrayGet(tmq->clientTopics, i);
     if (pTopicCur->vgs) {
       int32_t vgNumCur = taosArrayGetSize(pTopicCur->vgs);
-      tscDebug("consumer:0x%" PRIx64 ", new vg num: %d", tmq->consumerId, vgNumCur);
+      tscDebug("consumer:0x%" PRIx64 ", current vg num: %d", tmq->consumerId, vgNumCur);
       for (int32_t j = 0; j < vgNumCur; j++) {
         SMqClientVg* pVgCur = taosArrayGet(pTopicCur->vgs, j);
         makeTopicVgroupKey(vgKey, pTopicCur->topicName, pVgCur->vgId);
@@ -1827,12 +1824,13 @@ static void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
                    " total:%" PRId64 " reqId:0x%" PRIx64,
                    tmq->consumerId, pVg->vgId, buf, pVg->numOfRows, tmq->totalRows, pollRspWrapper->reqId);
           pRspWrapper = tmqFreeRspWrapper(pRspWrapper);
+          pVg->emptyBlockReceiveTs = taosGetTimestampMs();
           taosFreeQitem(pollRspWrapper);
         } else {  // build rsp
           int64_t    numOfRows = 0;
           SMqRspObj* pRsp = tmqBuildRspFromWrapper(pollRspWrapper, pVg, &numOfRows);
           tmq->totalRows += numOfRows;
-
+          pVg->emptyBlockReceiveTs = 0;
           tscDebug("consumer:0x%" PRIx64 " process poll rsp, vgId:%d, offset:%s, blocks:%d, rows:%" PRId64
                    " vg total:%" PRId64 " total:%" PRId64 ", reqId:0x%" PRIx64,
                    tmq->consumerId, pVg->vgId, buf, pDataRsp->blockNum, numOfRows, pVg->numOfRows, tmq->totalRows,
@@ -1855,7 +1853,9 @@ static void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
 
       if (pollRspWrapper->metaRsp.head.epoch == consumerEpoch) {
         SMqClientVg* pVg = pollRspWrapper->vgHandle;
-        pVg->offsetInfo.currentOffset = pollRspWrapper->metaRsp.rspOffset;
+        if(pollRspWrapper->metaRsp.rspOffset.type != 0){    // if offset is validate
+          pVg->offsetInfo.currentOffset = pollRspWrapper->metaRsp.rspOffset;
+        }
         atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE);
         // build rsp
         SMqMetaRspObj* pRsp = tmqBuildMetaRspFromWrapper(pollRspWrapper);
@@ -1873,7 +1873,9 @@ static void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
 
       if (pollRspWrapper->taosxRsp.head.epoch == consumerEpoch) {
         SMqClientVg* pVg = pollRspWrapper->vgHandle;
-        pVg->offsetInfo.currentOffset = pollRspWrapper->taosxRsp.rspOffset;
+        if(pollRspWrapper->taosxRsp.rspOffset.type != 0){    // if offset is validate
+          pVg->offsetInfo.currentOffset = pollRspWrapper->taosxRsp.rspOffset;
+        }
         atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE);
 
         if (pollRspWrapper->taosxRsp.blockNum == 0) {
diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp
index f1d1ad0865..b04727bfc0 100644
--- a/source/client/test/clientTests.cpp
+++ b/source/client/test/clientTests.cpp
@@ -186,7 +186,7 @@ void* queryThread(void* arg) {
 int32_t numOfThreads = 1;
 
 void tmq_commit_cb_print(tmq_t* pTmq, int32_t code, void* param) {
-  printf("auto commit success, code:%d\n\n\n\n", code);
+//  printf("auto commit success, code:%d\n", code);
 }
 
 void* doConsumeData(void* param) {
@@ -1080,9 +1080,14 @@ TEST(clientCase, sub_tb_test) {
   ASSERT_NE(pConn, nullptr);
 
   tmq_conf_t* conf = tmq_conf_new();
-  tmq_conf_set(conf, "enable.auto.commit", "false");
-  tmq_conf_set(conf, "auto.commit.interval.ms", "1000");
-  tmq_conf_set(conf, "group.id", "cgrpName1024");
+
+  int32_t ts = taosGetTimestampMs()%INT32_MAX;
+  char consumerGroupid[128] = {0};
+  sprintf(consumerGroupid, "group_id_%d", ts);
+
+  tmq_conf_set(conf, "enable.auto.commit", "true");
+  tmq_conf_set(conf, "auto.commit.interval.ms", "2000");
+  tmq_conf_set(conf, "group.id", consumerGroupid);
   tmq_conf_set(conf, "td.connect.user", "root");
   tmq_conf_set(conf, "td.connect.pass", "taosdata");
   tmq_conf_set(conf, "auto.offset.reset", "earliest");
@@ -1106,7 +1111,7 @@ TEST(clientCase, sub_tb_test) {
   int32_t     precision = 0;
   int32_t     totalRows = 0;
   int32_t     msgCnt = 0;
-  int32_t     timeout = 25000;
+  int32_t     timeout = 2500000;
 
   int32_t count = 0;
 
@@ -1126,14 +1131,16 @@ TEST(clientCase, sub_tb_test) {
 
   while (1) {
     TAOS_RES* pRes = tmq_consumer_poll(tmq, timeout);
-    if (pRes != NULL) {
-      const char* topicName = tmq_get_topic_name(pRes);
-      const char* dbName = tmq_get_db_name(pRes);
-      int32_t     vgroupId = tmq_get_vgroup_id(pRes);
+    if (pRes) {
+      char buf[128];
 
-      printf("topic: %s\n", topicName);
-      printf("db: %s\n", dbName);
-      printf("vgroup id: %d\n", vgroupId);
+      const char* topicName = tmq_get_topic_name(pRes);
+//      const char* dbName = tmq_get_db_name(pRes);
+//      int32_t     vgroupId = tmq_get_vgroup_id(pRes);
+//
+//      printf("topic: %s\n", topicName);
+//      printf("db: %s\n", dbName);
+//      printf("vgroup id: %d\n", vgroupId);
 
       printSubResults(pRes, &totalRows);
     } else {
@@ -1144,6 +1151,11 @@ TEST(clientCase, sub_tb_test) {
     tmq_commit_sync(tmq, pRes);
     if (pRes != NULL) {
       taos_free_result(pRes);
+      //      if ((++count) > 1) {
+      //        break;
+      //      }
+    } else {
+      break;
     }
 
     tmq_offset_seek(tmq, "topic_t1", pAssign[0].vgId, pAssign[0].begin);
diff --git a/source/client/test/smlTest.cpp b/source/client/test/smlTest.cpp
index 76911e229a..1578b8b607 100644
--- a/source/client/test/smlTest.cpp
+++ b/source/client/test/smlTest.cpp
@@ -50,8 +50,9 @@ TEST(testCase, smlParseInfluxString_Test) {
   int ret = smlParseInfluxString(info, sql, sql + strlen(sql), &elements);
   ASSERT_EQ(ret, 0);
   ASSERT_EQ(elements.measure, sql);
-  ASSERT_EQ(elements.measureLen, strlen(",st"));
-  ASSERT_EQ(elements.measureTagsLen, strlen(",st,t1=3,t2=4,t3=t3"));
+  ASSERT_EQ(elements.measureLen, strlen("\\,st"));
+  ASSERT_EQ(elements.measureEscaped, true);
+  ASSERT_EQ(elements.measureTagsLen, strlen("\\,st,t1=3,t2=4,t3=t3"));
 
   ASSERT_EQ(elements.tags, sql + elements.measureLen + 1);
   ASSERT_EQ(elements.tagsLen, strlen("t1=3,t2=4,t3=t3"));
@@ -204,7 +205,26 @@ TEST(testCase, smlParseCols_Error_Test) {
                         "st,t=1 c=-3.402823466e+39u64 1626006833639000000",
                         "st,t=1 c=-339u64 1626006833639000000",
                         "st,t=1 c=18446744073709551616u64 1626006833639000000",
-                        "st,t=1 c=1=2 1626006833639000000"};
+                        "st,t=1 c=1=2 1626006833639000000,",
+                        // escape error test
+                        // measure comma,space
+                        "s,t,t=1 c=1 1626006833639000000,",
+                        "s t,t=1 c=1 1626006833639000000,",
+                        //tag key comma,equal,space
+                        "st,t,t=1 c=2 1626006833639000000,",
+                        "st,t=t=1 c=2 1626006833639000000,",
+                        "st,t t=1 c=2 1626006833639000000,",
+                        //tag value comma,equal,space
+                        "st,tt=a,a c=2 1626006833639000000,",
+                        "st,t=t=a a c=2 1626006833639000000,",
+                        "st,t t=a=a c=2 1626006833639000000,",
+                        //field key comma,equal,space
+                        "st,tt=aa c,1=2 1626006833639000000,",
+                        "st,tt=aa c=1=2 1626006833639000000,",
+                        "st,tt=aa c 1=2 1626006833639000000,",
+                        //field value    double quote,slash
+                        "st,tt=aa c=\"a\"a\" 1626006833639000000,",
+  };
 
   SSmlHandle *info = smlBuildSmlInfo(NULL);
   info->protocol = TSDB_SML_LINE_PROTOCOL;
@@ -256,16 +276,18 @@ TEST(testCase, smlParseCols_Test) {
   ASSERT_EQ(strncasecmp(kv->key, "cb=in", 5), 0);
   ASSERT_EQ(kv->keyLen, 5);
   ASSERT_EQ(kv->type, TSDB_DATA_TYPE_BINARY);
-  ASSERT_EQ(kv->length, 17);
-  ASSERT_EQ(strncasecmp(kv->value, "pass,it ", 8), 0);
+  ASSERT_EQ(kv->length, 18);
+  ASSERT_EQ(kv->keyEscaped, true);
+  ASSERT_EQ(kv->valueEscaped, false);
+  ASSERT_EQ(strncasecmp(kv->value, "pass\\,it ", 9), 0);
 
   // nchar
   kv = (SSmlKv *)taosArrayGet(elements.colArray, 2);
   ASSERT_EQ(strncasecmp(kv->key, "cnch", 4), 0);
   ASSERT_EQ(kv->keyLen, 4);
   ASSERT_EQ(kv->type, TSDB_DATA_TYPE_NCHAR);
-  ASSERT_EQ(kv->length, 8);
-  ASSERT_EQ(strncasecmp(kv->value, "ii=sd", 5), 0);
+  ASSERT_EQ(kv->length, 9);
+  ASSERT_EQ(strncasecmp(kv->value, "ii\\=sd", 5), 0);
 
   // bool
   kv = (SSmlKv *)taosArrayGet(elements.colArray, 3);
diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c
index f4d2ed01b0..5f7e43668a 100644
--- a/source/common/src/tdatablock.c
+++ b/source/common/src/tdatablock.c
@@ -120,6 +120,7 @@ int32_t colDataSetVal(SColumnInfoData* pColumnInfoData, uint32_t rowIndex, const
     pColumnInfoData->varmeta.length += dataLen;
   } else {
     memcpy(pColumnInfoData->pData + pColumnInfoData->info.bytes * rowIndex, pData, pColumnInfoData->info.bytes);
+    colDataClearNull_f(pColumnInfoData->nullbitmap, rowIndex);
   }
 
   return 0;
@@ -1949,12 +1950,11 @@ void blockDebugShowDataBlocks(const SArray* dataBlocks, const char* flag) {
     }
   }
 }
-
 #endif
 
 // for debug
 char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf) {
-  int32_t size = 2048;
+  int32_t size = 2048*1024;
   *pDataBuf = taosMemoryCalloc(size, 1);
   char*   dumpBuf = *pDataBuf;
   char    pBuf[128] = {0};
@@ -1970,7 +1970,7 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf)
   if (len >= size - 1) return dumpBuf;
 
   for (int32_t j = 0; j < rows; j++) {
-    len += snprintf(dumpBuf + len, size - len, "%s |", flag);
+    len += snprintf(dumpBuf + len, size - len, "%s %d|", flag, j);
     if (len >= size - 1) return dumpBuf;
 
     for (int32_t k = 0; k < colNum; k++) {
@@ -2374,7 +2374,7 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq2** ppReq, const SSDataBlock* pDat
       }
       SRow* pRow = NULL;
       if ((terrno = tRowBuild(pVals, pTSchema, &pRow)) < 0) {
-        tDestroySSubmitTbData(&tbData, TSDB_MSG_FLG_ENCODE);
+        tDestroySubmitTbData(&tbData, TSDB_MSG_FLG_ENCODE);
         goto _end;
       }
       ASSERT(pRow);
@@ -2388,7 +2388,7 @@ _end:
   if (terrno != 0) {
     *ppReq = NULL;
     if (pReq) {
-      tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
+      tDestroySubmitReq(pReq, TSDB_MSG_FLG_ENCODE);
       taosMemoryFreeClear(pReq);
     }
 
diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c
index 62f837f3b6..846ca44b83 100644
--- a/source/common/src/tdataformat.c
+++ b/source/common/src/tdataformat.c
@@ -1509,7 +1509,9 @@ void tTagSetCid(const STag *pTag, int16_t iTag, int16_t cid) {
 // STSchema ========================================
 STSchema *tBuildTSchema(SSchema *aSchema, int32_t numOfCols, int32_t version) {
   STSchema *pTSchema = taosMemoryCalloc(1, sizeof(STSchema) + sizeof(STColumn) * numOfCols);
-  if (pTSchema == NULL) return NULL;
+  if (pTSchema == NULL) {
+    return NULL;
+  }
 
   pTSchema->numOfCols = numOfCols;
   pTSchema->version = version;
diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c
index 0a29a415f0..55d42aa4ef 100644
--- a/source/common/src/tglobal.c
+++ b/source/common/src/tglobal.c
@@ -84,7 +84,7 @@ bool     tsMonitorComp = false;
 // telem
 bool     tsEnableTelem = true;
 int32_t  tsTelemInterval = 43200;
-char     tsTelemServer[TSDB_FQDN_LEN] = "telemetry.taosdata.com";
+char     tsTelemServer[TSDB_FQDN_LEN] = "telemetry.tdengine.com";
 uint16_t tsTelemPort = 80;
 char    *tsTelemUri = "/report";
 
@@ -202,7 +202,7 @@ int32_t tsTransPullupInterval = 2;
 int32_t tsMqRebalanceInterval = 2;
 int32_t tsStreamCheckpointTickInterval = 1;
 int32_t tsTtlUnit = 86400;
-int32_t tsTtlPushInterval = 86400;
+int32_t tsTtlPushInterval = 3600;
 int32_t tsGrantHBInterval = 60;
 int32_t tsUptimeInterval = 300;    // seconds
 char    tsUdfdResFuncs[512] = "";  // udfd resident funcs that teardown when udfd exits
diff --git a/source/common/src/tmisce.c b/source/common/src/tmisce.c
index 59afce1bbb..c195f5387c 100644
--- a/source/common/src/tmisce.c
+++ b/source/common/src/tmisce.c
@@ -15,6 +15,7 @@
 
 #define _DEFAULT_SOURCE
 #include "tmisce.h"
+#include "tjson.h"
 #include "tglobal.h"
 #include "tlog.h"
 #include "tname.h"
@@ -87,3 +88,63 @@ SEpSet getEpSet_s(SCorEpSet* pEpSet) {
 
   return ep;
 }
+
+int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t startTime) {
+  SJson* pJson = tjsonCreateObject();
+  if (pJson == NULL) return -1;
+  char tmp[4096] = {0};
+
+  tjsonAddDoubleToObject(pJson, "reportVersion", 1);
+
+  tjsonAddIntegerToObject(pJson, "clusterId", clusterId);
+  tjsonAddIntegerToObject(pJson, "startTime", startTime);
+
+  // Do NOT invoke the taosGetFqdn here.
+  // this function may be invoked when memory exception occurs,so we should assume that it is running in a memory locked
+  // environment. The lock operation by taosGetFqdn may cause this program deadlock.
+  tjsonAddStringToObject(pJson, "fqdn", tsLocalFqdn);
+
+  tjsonAddIntegerToObject(pJson, "pid", taosGetPId());
+
+  taosGetAppName(tmp, NULL);
+  tjsonAddStringToObject(pJson, "appName", tmp);
+
+  if (taosGetOsReleaseName(tmp, sizeof(tmp)) == 0) {
+    tjsonAddStringToObject(pJson, "os", tmp);
+  }
+
+  float numOfCores = 0;
+  if (taosGetCpuInfo(tmp, sizeof(tmp), &numOfCores) == 0) {
+    tjsonAddStringToObject(pJson, "cpuModel", tmp);
+    tjsonAddDoubleToObject(pJson, "numOfCpu", numOfCores);
+  } else {
+    tjsonAddDoubleToObject(pJson, "numOfCpu", tsNumOfCores);
+  }
+
+  snprintf(tmp, sizeof(tmp), "%" PRId64 " kB", tsTotalMemoryKB);
+  tjsonAddStringToObject(pJson, "memory", tmp);
+
+  tjsonAddStringToObject(pJson, "version", version);
+  tjsonAddStringToObject(pJson, "buildInfo", buildinfo);
+  tjsonAddStringToObject(pJson, "gitInfo", gitinfo);
+
+  tjsonAddIntegerToObject(pJson, "crashSig", signum);
+  tjsonAddIntegerToObject(pJson, "crashTs", taosGetTimestampUs());
+
+#ifdef _TD_DARWIN_64
+  taosLogTraceToBuf(tmp, sizeof(tmp), 4);
+#elif !defined(WINDOWS)
+  taosLogTraceToBuf(tmp, sizeof(tmp), 3);
+#else
+  taosLogTraceToBuf(tmp, sizeof(tmp), 8);
+#endif
+
+  tjsonAddStringToObject(pJson, "stackInfo", tmp);
+
+  char* pCont = tjsonToString(pJson);
+  tjsonDelete(pJson);
+
+  *pMsg = pCont;
+
+  return TSDB_CODE_SUCCESS;
+}
diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c
index 9face5ee3f..6612be75cf 100644
--- a/source/common/src/tmsg.c
+++ b/source/common/src/tmsg.c
@@ -1409,6 +1409,8 @@ int32_t tDeserializeSAlterUserReq(void *buf, int32_t bufLen, SAlterUserReq *pReq
   return 0;
 }
 
+void tFreeSAlterUserReq(SAlterUserReq *pReq) { taosMemoryFreeClear(pReq->tagCond); }
+
 int32_t tSerializeSGetUserAuthReq(void *buf, int32_t bufLen, SGetUserAuthReq *pReq) {
   SEncoder encoder = {0};
   tEncoderInit(&encoder, buf, bufLen);
@@ -1635,6 +1637,7 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs
       int32_t ref = 0;
       if (tDecodeI32(pDecoder, &ref) < 0) return -1;
       taosHashPut(pRsp->useDbs, key, strlen(key), &ref, sizeof(ref));
+      taosMemoryFree(key);
     }
   }
 
@@ -1858,7 +1861,6 @@ int32_t tSerializeSCreateFuncReq(void *buf, int32_t bufLen, SCreateFuncReq *pReq
     if (tEncodeCStr(&encoder, pReq->pComment) < 0) return -1;
   }
 
-
   if (tEncodeI8(&encoder, pReq->orReplace) < 0) return -1;
 
   tEndEncode(&encoder);
@@ -1903,7 +1905,6 @@ int32_t tDeserializeSCreateFuncReq(void *buf, int32_t bufLen, SCreateFuncReq *pR
     if (tDecodeCStrTo(&decoder, pReq->pComment) < 0) return -1;
   }
 
-
   if (!tDecodeIsEnd(&decoder)) {
     if (tDecodeI8(&decoder, &pReq->orReplace) < 0) return -1;
   } else {
@@ -2080,12 +2081,12 @@ int32_t tDeserializeSRetrieveFuncRsp(void *buf, int32_t bufLen, SRetrieveFuncRsp
   if (pRsp->pFuncExtraInfos == NULL) return -1;
   if (tDecodeIsEnd(&decoder)) {
     for (int32_t i = 0; i < pRsp->numOfFuncs; ++i) {
-      SFuncExtraInfo  extraInfo  = { 0 };
+      SFuncExtraInfo extraInfo = {0};
       taosArrayPush(pRsp->pFuncExtraInfos, &extraInfo);
     }
   } else {
     for (int32_t i = 0; i < pRsp->numOfFuncs; ++i) {
-      SFuncExtraInfo extraInfo = { 0 };
+      SFuncExtraInfo extraInfo = {0};
       if (tDecodeI32(&decoder, &extraInfo.funcVersion) < 0) return -1;
       if (tDecodeI64(&decoder, &extraInfo.funcCreatedTime) < 0) return -1;
       taosArrayPush(pRsp->pFuncExtraInfos, &extraInfo);
@@ -5458,9 +5459,9 @@ int32_t tSerializeSMqPollReq(void *buf, int32_t bufLen, SMqPollReq *pReq) {
 int32_t tDeserializeSMqPollReq(void *buf, int32_t bufLen, SMqPollReq *pReq) {
   int32_t headLen = sizeof(SMsgHead);
 
-  SMsgHead *pHead = buf;
-  pHead->vgId = pReq->head.vgId;
-  pHead->contLen = pReq->head.contLen;
+//  SMsgHead *pHead = buf;
+//  pHead->vgId = pReq->head.vgId;
+//  pHead->contLen = pReq->head.contLen;
 
   SDecoder decoder = {0};
   tDecoderInit(&decoder, (char *)buf + headLen, bufLen - headLen);
@@ -6968,10 +6969,8 @@ int32_t tEncodeSTqOffsetVal(SEncoder *pEncoder, const STqOffsetVal *pOffsetVal)
     if (tEncodeI64(pEncoder, pOffsetVal->ts) < 0) return -1;
   } else if (pOffsetVal->type == TMQ_OFFSET__LOG) {
     if (tEncodeI64(pEncoder, pOffsetVal->version) < 0) return -1;
-  } else if (pOffsetVal->type < 0) {
-    // do nothing
   } else {
-    ASSERT(0);
+    // do nothing
   }
   return 0;
 }
@@ -6983,10 +6982,8 @@ int32_t tDecodeSTqOffsetVal(SDecoder *pDecoder, STqOffsetVal *pOffsetVal) {
     if (tDecodeI64(pDecoder, &pOffsetVal->ts) < 0) return -1;
   } else if (pOffsetVal->type == TMQ_OFFSET__LOG) {
     if (tDecodeI64(pDecoder, &pOffsetVal->version) < 0) return -1;
-  } else if (pOffsetVal->type < 0) {
-    // do nothing
   } else {
-    ASSERT(0);
+    // do nothing
   }
   return 0;
 }
@@ -7203,7 +7200,7 @@ void tDeleteMqDataRsp(SMqDataRsp *pRsp) {
   pRsp->blockDataLen = taosArrayDestroy(pRsp->blockDataLen);
   taosArrayDestroyP(pRsp->blockData, (FDelete)taosMemoryFree);
   pRsp->blockData = NULL;
-  taosArrayDestroyP(pRsp->blockSchema, (FDelete)tDeleteSSchemaWrapper);
+  taosArrayDestroyP(pRsp->blockSchema, (FDelete)tDeleteSchemaWrapper);
   pRsp->blockSchema = NULL;
   taosArrayDestroyP(pRsp->blockTbName, (FDelete)taosMemoryFree);
   pRsp->blockTbName = NULL;
@@ -7303,7 +7300,7 @@ void tDeleteSTaosxRsp(STaosxRsp *pRsp) {
   pRsp->blockDataLen = taosArrayDestroy(pRsp->blockDataLen);
   taosArrayDestroyP(pRsp->blockData, (FDelete)taosMemoryFree);
   pRsp->blockData = NULL;
-  taosArrayDestroyP(pRsp->blockSchema, (FDelete)tDeleteSSchemaWrapper);
+  taosArrayDestroyP(pRsp->blockSchema, (FDelete)tDeleteSchemaWrapper);
   pRsp->blockSchema = NULL;
   taosArrayDestroyP(pRsp->blockTbName, (FDelete)taosMemoryFree);
   pRsp->blockTbName = NULL;
@@ -7475,7 +7472,7 @@ _exit:
   return 0;
 }
 
-int32_t tEncodeSSubmitReq2(SEncoder *pCoder, const SSubmitReq2 *pReq) {
+int32_t tEncodeSubmitReq(SEncoder *pCoder, const SSubmitReq2 *pReq) {
   if (tStartEncode(pCoder) < 0) return -1;
 
   if (tEncodeU64v(pCoder, taosArrayGetSize(pReq->aSubmitTbData)) < 0) return -1;
@@ -7487,7 +7484,7 @@ int32_t tEncodeSSubmitReq2(SEncoder *pCoder, const SSubmitReq2 *pReq) {
   return 0;
 }
 
-int32_t tDecodeSSubmitReq2(SDecoder *pCoder, SSubmitReq2 *pReq) {
+int32_t tDecodeSubmitReq(SDecoder *pCoder, SSubmitReq2 *pReq) {
   int32_t code = 0;
 
   memset(pReq, 0, sizeof(*pReq));
@@ -7530,7 +7527,7 @@ _exit:
   return code;
 }
 
-void tDestroySSubmitTbData(SSubmitTbData *pTbData, int32_t flag) {
+void tDestroySubmitTbData(SSubmitTbData *pTbData, int32_t flag) {
   if (NULL == pTbData) {
     return;
   }
@@ -7576,14 +7573,14 @@ void tDestroySSubmitTbData(SSubmitTbData *pTbData, int32_t flag) {
   }
 }
 
-void tDestroySSubmitReq2(SSubmitReq2 *pReq, int32_t flag) {
+void tDestroySubmitReq(SSubmitReq2 *pReq, int32_t flag) {
   if (pReq->aSubmitTbData == NULL) return;
 
   int32_t        nSubmitTbData = TARRAY_SIZE(pReq->aSubmitTbData);
   SSubmitTbData *aSubmitTbData = (SSubmitTbData *)TARRAY_DATA(pReq->aSubmitTbData);
 
   for (int32_t i = 0; i < nSubmitTbData; i++) {
-    tDestroySSubmitTbData(&aSubmitTbData[i], flag);
+    tDestroySubmitTbData(&aSubmitTbData[i], flag);
   }
   taosArrayDestroy(pReq->aSubmitTbData);
   pReq->aSubmitTbData = NULL;
diff --git a/source/common/src/tname.c b/source/common/src/tname.c
index e5ed7a3728..c6210ca8c9 100644
--- a/source/common/src/tname.c
+++ b/source/common/src/tname.c
@@ -122,10 +122,8 @@ int32_t tNameLen(const SName* name) {
   int32_t len2 = (int32_t)strlen(name->tname);
 
   if (name->type == TSDB_DB_NAME_T) {
-    ASSERT(len2 == 0);
     return len + len1 + TSDB_NAME_DELIMITER_LEN;
   } else {
-    ASSERT(len2 > 0);
     return len + len1 + len2 + TSDB_NAME_DELIMITER_LEN * 2;
   }
 }
diff --git a/source/common/src/ttszip.c b/source/common/src/ttszip.c
index 0faa6eb4c8..f415bd20cd 100644
--- a/source/common/src/ttszip.c
+++ b/source/common/src/ttszip.c
@@ -982,7 +982,6 @@ void tsBufSetCursor(STSBuf* pTSBuf, STSCursor* pCur) {
     return;
   }
 
-  //  assert(pCur->vgroupIndex != -1 && pCur->tsIndex >= 0 && pCur->blockIndex >= 0);
   if (pCur->vgroupIndex != -1) {
     tsBufGetBlock(pTSBuf, pCur->vgroupIndex, pCur->blockIndex);
   }
diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c
index f0e020edfe..989bff3984 100644
--- a/source/dnode/mgmt/exe/dmMain.c
+++ b/source/dnode/mgmt/exe/dmMain.c
@@ -87,18 +87,6 @@ static void dmStopDnode(int signum, void *sigInfo, void *context) {
 }
 
 void dmLogCrash(int signum, void *sigInfo, void *context) {
-  taosIgnSignal(SIGTERM);
-  taosIgnSignal(SIGHUP);
-  taosIgnSignal(SIGINT);
-  taosIgnSignal(SIGBREAK);
-
-#ifndef WINDOWS
-  taosIgnSignal(SIGBUS);
-#endif
-  taosIgnSignal(SIGABRT);
-  taosIgnSignal(SIGFPE);
-  taosIgnSignal(SIGSEGV);
-
   char       *pMsg = NULL;
   const char *flags = "UTL FATAL ";
   ELogLevel   level = DEBUG_FATAL;
diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
index 51f91c3922..988a2a9118 100644
--- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
+++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
@@ -212,7 +212,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
         ", wal fsync:%d level:%d retentionPeriod:%d retentionSize:%" PRId64 " rollPeriod:%d segSize:%" PRId64
         ", hash method:%d begin:%u end:%u prefix:%d surfix:%d replica:%d selfIndex:%d "
         "learnerReplica:%d learnerSelfIndex:%d strict:%d",
-        req.vgId, TMSG_INFO(pMsg->msgType), req.pages, req.pageSize, req.buffer, req.pageSize * 1024, 
+        req.vgId, TMSG_INFO(pMsg->msgType), req.pages, req.pageSize, req.buffer, req.pageSize * 1024,
         (uint64_t)req.buffer * 1024 * 1024,
         req.cacheLast, req.cacheLastSize, req.sstTrigger, req.tsdbPageSize, req.tsdbPageSize * 1024, req.db, req.dbUid,
         req.daysPerFile, req.daysToKeep0, req.daysToKeep1, req.daysToKeep2, req.isTsma, req.precision, req.compression,
@@ -224,7 +224,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
           req.replicas[i].id);
   }
   for (int32_t i = 0; i < req.learnerReplica; ++i) {
-    dInfo("vgId:%d, learnerReplica:%d ep:%s:%u dnode:%d", req.vgId, i, req.learnerReplicas[i].fqdn, 
+    dInfo("vgId:%d, learnerReplica:%d ep:%s:%u dnode:%d", req.vgId, i, req.learnerReplicas[i].fqdn,
                                                   req.learnerReplicas[i].port, req.replicas[i].id);
   }
 
@@ -278,7 +278,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
       return -1;
     }
   }
-  
+
 if (vnodeCreate(path, &vnodeCfg, pMgmt->pTfs) < 0) {
     tFreeSCreateVnodeReq(&req);
     dError("vgId:%d, failed to create vnode since %s", req.vgId, terrstr());
@@ -326,7 +326,7 @@ _OVER:
     vnodeClose(pImpl);
     vnodeDestroy(path, pMgmt->pTfs);
   } else {
-    dInfo("vgId:%d, vnode management handle msgType:%s, end to create vnode, vnode is created", 
+    dInfo("vgId:%d, vnode management handle msgType:%s, end to create vnode, vnode is created",
             req.vgId, TMSG_INFO(pMsg->msgType));
   }
 
@@ -346,7 +346,7 @@ int32_t vmProcessAlterVnodeTypeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
     req.learnerSelfIndex = -1;
   }
 
-  dInfo("vgId:%d, vnode management handle msgType:%s, start to process alter-node-type-request", 
+  dInfo("vgId:%d, vnode management handle msgType:%s, start to process alter-node-type-request",
           req.vgId, TMSG_INFO(pMsg->msgType));
 
   SVnodeObj *pVnode = vmAcquireVnode(pMgmt, req.vgId);
@@ -386,8 +386,8 @@ int32_t vmProcessAlterVnodeTypeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
     dInfo("vgId:%d, learnerReplicas:%d ep:%s:%u dnode:%d", vgId, i, pReplica->fqdn, pReplica->port, pReplica->id);
   }
 
-  if (req.replica <= 0 || 
-      (req.selfIndex < 0 && req.learnerSelfIndex <0)|| 
+  if (req.replica <= 0 ||
+      (req.selfIndex < 0 && req.learnerSelfIndex <0)||
       req.selfIndex >= req.replica || req.learnerSelfIndex >= req.learnerReplica) {
     terrno = TSDB_CODE_INVALID_MSG;
     dError("vgId:%d, failed to alter replica since invalid msg", vgId);
@@ -402,7 +402,7 @@ int32_t vmProcessAlterVnodeTypeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
   else{
     pReplica = &req.learnerReplicas[req.learnerSelfIndex];
   }
-  
+
   if (pReplica->id != pMgmt->pData->dnodeId || pReplica->port != tsServerPort ||
       strcmp(pReplica->fqdn, tsLocalFqdn) != 0) {
     terrno = TSDB_CODE_INVALID_MSG;
@@ -447,7 +447,7 @@ int32_t vmProcessAlterVnodeTypeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
     return -1;
   }
 
-  dInfo("vgId:%d, vnode management handle msgType:%s, end to process alter-node-type-request, vnode config is altered", 
+  dInfo("vgId:%d, vnode management handle msgType:%s, end to process alter-node-type-request, vnode config is altered",
           req.vgId, TMSG_INFO(pMsg->msgType));
   return 0;
 }
@@ -552,7 +552,7 @@ int32_t vmProcessAlterVnodeReplicaReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
 
   int32_t vgId = alterReq.vgId;
   dInfo("vgId:%d,vnode management handle msgType:%s, start to alter vnode replica:%d selfIndex:%d leanerReplica:%d "
-        "learnerSelfIndex:%d strict:%d", 
+        "learnerSelfIndex:%d strict:%d",
                         vgId, TMSG_INFO(pMsg->msgType), alterReq.replica, alterReq.selfIndex, alterReq.learnerReplica,
                         alterReq.learnerSelfIndex, alterReq.strict);
   for (int32_t i = 0; i < alterReq.replica; ++i) {
@@ -563,9 +563,9 @@ int32_t vmProcessAlterVnodeReplicaReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
     SReplica *pReplica = &alterReq.learnerReplicas[i];
     dInfo("vgId:%d, learnerReplicas:%d ep:%s:%u dnode:%d", vgId, i, pReplica->fqdn, pReplica->port, pReplica->port);
   }
-  
-  if (alterReq.replica <= 0 || 
-      (alterReq.selfIndex < 0 && alterReq.learnerSelfIndex <0)|| 
+
+  if (alterReq.replica <= 0 ||
+      (alterReq.selfIndex < 0 && alterReq.learnerSelfIndex <0)||
       alterReq.selfIndex >= alterReq.replica || alterReq.learnerSelfIndex >= alterReq.learnerReplica) {
     terrno = TSDB_CODE_INVALID_MSG;
     dError("vgId:%d, failed to alter replica since invalid msg", vgId);
@@ -579,7 +579,7 @@ int32_t vmProcessAlterVnodeReplicaReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
   else{
     pReplica = &alterReq.learnerReplicas[alterReq.learnerSelfIndex];
   }
-  
+
   if (pReplica->id != pMgmt->pData->dnodeId || pReplica->port != tsServerPort ||
       strcmp(pReplica->fqdn, tsLocalFqdn) != 0) {
     terrno = TSDB_CODE_INVALID_MSG;
@@ -631,7 +631,7 @@ int32_t vmProcessAlterVnodeReplicaReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
   }
 
   dInfo("vgId:%d, vnode management handle msgType:%s, end to alter vnode replica:%d selfIndex:%d leanerReplica:%d "
-        "learnerSelfIndex:%d strict:%d", 
+        "learnerSelfIndex:%d strict:%d",
                         vgId, TMSG_INFO(pMsg->msgType), alterReq.replica, alterReq.selfIndex, alterReq.learnerReplica,
                         alterReq.learnerSelfIndex, alterReq.strict);
   return 0;
@@ -711,7 +711,7 @@ SArray *vmGetMsgHandles() {
   if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_SEEK_TO_OFFSET, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
   if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_ADD_CHECKINFO, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
   if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_DEL_CHECKINFO, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
-  if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_CONSUME, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
+  if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_CONSUME, vmPutMsgToQueryQueue, 0) == NULL) goto _OVER;
   if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_VG_WALINFO, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
   if (dmSetMgmtHandle(pArray, TDMT_VND_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
   if (dmSetMgmtHandle(pArray, TDMT_VND_BATCH_DEL, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c
index 0244a4fd6e..16e7ffc536 100644
--- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c
+++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c
@@ -119,6 +119,7 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode, bool commitAndRemoveWal)
         pVnode->pFetchQ->threadId);
   while (!taosQueueEmpty(pVnode->pFetchQ)) taosMsleep(10);
 
+  tqNotifyClose(pVnode->pImpl->pTq);
   dInfo("vgId:%d, wait for vnode stream queue:%p is empty", pVnode->vgId, pVnode->pStreamQ);
   while (!taosQueueEmpty(pVnode->pStreamQ)) taosMsleep(10);
 
@@ -141,7 +142,6 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode, bool commitAndRemoveWal)
   dInfo("vgId:%d, vnode is closed", pVnode->vgId);
 
   if (commitAndRemoveWal) {
-    char path[TSDB_FILENAME_LEN] = {0};
     snprintf(path, TSDB_FILENAME_LEN, "vnode%svnode%d%swal", TD_DIRSEP, pVnode->vgId, TD_DIRSEP);
     dInfo("vgId:%d, remove all wals, path:%s", pVnode->vgId, path);
     tfsRmdir(pMgmt->pTfs, path);
diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
index ef4a2b52bb..a5f53c8703 100644
--- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
+++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
@@ -116,8 +116,16 @@ static void vmProcessFetchQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
 
     int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo);
     if (code != 0) {
-      if (terrno != 0) code = terrno;
-      dGError("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
+      if (terrno != 0) {
+        code = terrno;
+      }
+
+      if (code == TSDB_CODE_WAL_LOG_NOT_EXIST) {
+        dGDebug("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
+      } else {
+        dGError("vnodeProcessFetchMsg vgId:%d, msg:%p failed to fetch since %s", pVnode->vgId, pMsg, terrstr());
+      }
+
       vmSendRsp(pMsg, code);
     }
 
diff --git a/source/dnode/mgmt/node_mgmt/src/dmNodes.c b/source/dnode/mgmt/node_mgmt/src/dmNodes.c
index 16931ab6df..19d5e06c5b 100644
--- a/source/dnode/mgmt/node_mgmt/src/dmNodes.c
+++ b/source/dnode/mgmt/node_mgmt/src/dmNodes.c
@@ -132,11 +132,15 @@ int32_t dmRunDnode(SDnode *pDnode) {
   int32_t count = 0;
   if (dmOpenNodes(pDnode) != 0) {
     dError("failed to open nodes since %s", terrstr());
+    dmCloseNodes(pDnode);
     return -1;
   }
 
   if (dmStartNodes(pDnode) != 0) {
     dError("failed to start nodes since %s", terrstr());
+    dmSetStatus(pDnode, DND_STAT_STOPPED);
+    dmStopNodes(pDnode);
+    dmCloseNodes(pDnode);
     return -1;
   }
 
diff --git a/source/dnode/mnode/impl/inc/mndConsumer.h b/source/dnode/mnode/impl/inc/mndConsumer.h
index aa38b94fd7..96401511d2 100644
--- a/source/dnode/mnode/impl/inc/mndConsumer.h
+++ b/source/dnode/mnode/impl/inc/mndConsumer.h
@@ -23,13 +23,12 @@ extern "C" {
 #endif
 
 enum {
-  MQ_CONSUMER_STATUS__MODIFY = 1,
+  MQ_CONSUMER_STATUS_REBALANCE = 1,
 //  MQ_CONSUMER_STATUS__MODIFY_IN_REB,     // this value is not used anymore
   MQ_CONSUMER_STATUS__READY,
   MQ_CONSUMER_STATUS__LOST,
 //  MQ_CONSUMER_STATUS__LOST_IN_REB,       // this value is not used anymore
   MQ_CONSUMER_STATUS__LOST_REBD,
-  MQ_CONSUMER_STATUS__REMOVED,
 };
 
 int32_t mndInitConsumer(SMnode *pMnode);
diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h
index 8d1a811f14..b14f7a9023 100644
--- a/source/dnode/mnode/impl/inc/mndDef.h
+++ b/source/dnode/mnode/impl/inc/mndDef.h
@@ -137,12 +137,12 @@ typedef enum {
 } EDndReason;
 
 typedef enum {
-  CONSUMER_UPDATE__TOUCH = 1,
+  CONSUMER_UPDATE__TOUCH = 1,   // rebalance req do not need change consume topic
   CONSUMER_UPDATE__ADD,
   CONSUMER_UPDATE__REMOVE,
   CONSUMER_UPDATE__LOST,
   CONSUMER_UPDATE__RECOVER,
-  CONSUMER_UPDATE__MODIFY,
+  CONSUMER_UPDATE__REBALANCE,      // subscribe req need change consume topic
 } ECsmUpdateType;
 
 typedef struct {
@@ -631,7 +631,7 @@ typedef struct {
   SArray*               rebVgs;            // SArray
   SArray*               newConsumers;      // SArray
   SArray*               removedConsumers;  // SArray
-  SArray*               touchedConsumers;  // SArray
+  SArray*               modifyConsumers;   // SArray
   SMqSubscribeObj*      pSub;
   SMqSubActionLogEntry* pLogEntry;
 } SMqRebOutputObj;
diff --git a/source/dnode/mnode/impl/inc/mndVgroup.h b/source/dnode/mnode/impl/inc/mndVgroup.h
index 2ece0da5eb..fb8b3c62aa 100644
--- a/source/dnode/mnode/impl/inc/mndVgroup.h
+++ b/source/dnode/mnode/impl/inc/mndVgroup.h
@@ -55,6 +55,8 @@ int32_t mndBuildRestoreAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj
 
 int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj *pVgroup);
 
+int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj *pVgroup);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c
index 0d75b5fd68..117c1082a5 100644
--- a/source/dnode/mnode/impl/src/mndConsumer.c
+++ b/source/dnode/mnode/impl/src/mndConsumer.c
@@ -192,15 +192,18 @@ FAIL:
   return -1;
 }
 
+// todo check the clear process
 static int32_t mndProcessConsumerClearMsg(SRpcMsg *pMsg) {
   SMnode              *pMnode = pMsg->info.node;
   SMqConsumerClearMsg *pClearMsg = pMsg->pCont;
-  SMqConsumerObj      *pConsumer = mndAcquireConsumer(pMnode, pClearMsg->consumerId);
+
+  SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pClearMsg->consumerId);
   if (pConsumer == NULL) {
+    mError("consumer:0x%"PRIx64" failed to be found to clear it", pClearMsg->consumerId);
     return 0;
   }
 
-  mInfo("receive consumer clear msg, consumer id %" PRId64 ", status %s", pClearMsg->consumerId,
+  mInfo("consumer:0x%" PRIx64 " needs to be cleared, status %s", pClearMsg->consumerId,
         mndConsumerStatusName(pConsumer->status));
 
   if (pConsumer->status != MQ_CONSUMER_STATUS__LOST_REBD) {
@@ -215,6 +218,8 @@ static int32_t mndProcessConsumerClearMsg(SRpcMsg *pMsg) {
 
   STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pMsg, "clear-csm");
   if (pTrans == NULL) goto FAIL;
+
+  // this is the drop action, not the update action
   if (mndSetConsumerDropLogs(pMnode, pTrans, pConsumerNew) != 0) goto FAIL;
   if (mndTransPrepare(pMnode, pTrans) != 0) goto FAIL;
 
@@ -247,7 +252,6 @@ static SMqRebInfo *mndGetOrCreateRebSub(SHashObj *pHash, const char *key) {
 
 static void freeRebalanceItem(void *param) {
   SMqRebInfo *pInfo = param;
-  taosArrayDestroy(pInfo->lostConsumers);
   taosArrayDestroy(pInfo->newConsumers);
   taosArrayDestroy(pInfo->removedConsumers);
 }
@@ -300,28 +304,36 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) {
     if (status == MQ_CONSUMER_STATUS__READY) {
       if (hbStatus > MND_CONSUMER_LOST_HB_CNT) {
         SMqConsumerLostMsg *pLostMsg = rpcMallocCont(sizeof(SMqConsumerLostMsg));
+        if (pLostMsg == NULL) {
+          mError("consumer:0x%"PRIx64" failed to transfer consumer status to lost due to out of memory. alloc size:%d",
+              pConsumer->consumerId, (int32_t)sizeof(SMqConsumerLostMsg));
+          continue;
+        }
 
         pLostMsg->consumerId = pConsumer->consumerId;
         SRpcMsg rpcMsg = {
-            .msgType = TDMT_MND_TMQ_CONSUMER_LOST,
-            .pCont = pLostMsg,
-            .contLen = sizeof(SMqConsumerLostMsg),
-        };
+            .msgType = TDMT_MND_TMQ_CONSUMER_LOST, .pCont = pLostMsg, .contLen = sizeof(SMqConsumerLostMsg)};
 
+        mDebug("consumer:0x%"PRIx64" hb not received beyond threshold %d, set to lost", pConsumer->consumerId,
+            MND_CONSUMER_LOST_HB_CNT);
         tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
       }
     } else if (status == MQ_CONSUMER_STATUS__LOST_REBD) {
       // if the client is lost longer than one day, clear it. Otherwise, do nothing about the lost consumers.
       if (hbStatus > MND_CONSUMER_LOST_CLEAR_THRESHOLD) {
         SMqConsumerClearMsg *pClearMsg = rpcMallocCont(sizeof(SMqConsumerClearMsg));
+        if (pClearMsg == NULL) {
+          mError("consumer:0x%"PRIx64" failed to clear consumer due to out of memory. alloc size:%d",
+                 pConsumer->consumerId, (int32_t)sizeof(SMqConsumerClearMsg));
+          continue;
+        }
 
         pClearMsg->consumerId = pConsumer->consumerId;
         SRpcMsg rpcMsg = {
-            .msgType = TDMT_MND_TMQ_LOST_CONSUMER_CLEAR,
-            .pCont = pClearMsg,
-            .contLen = sizeof(SMqConsumerClearMsg),
-        };
+            .msgType = TDMT_MND_TMQ_LOST_CONSUMER_CLEAR, .pCont = pClearMsg, .contLen = sizeof(SMqConsumerClearMsg)};
 
+        mDebug("consumer:0x%" PRIx64 " lost beyond threshold %d, clear it", pConsumer->consumerId,
+               MND_CONSUMER_LOST_CLEAR_THRESHOLD);
         tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
       }
     } else if (status == MQ_CONSUMER_STATUS__LOST) {
@@ -335,7 +347,7 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) {
         taosArrayPush(pRebSub->removedConsumers, &pConsumer->consumerId);
       }
       taosRUnLockLatch(&pConsumer->lock);
-    } else if (status == MQ_CONSUMER_STATUS__MODIFY) {
+    } else {  // MQ_CONSUMER_STATUS_REBALANCE
       taosRLockLatch(&pConsumer->lock);
 
       int32_t newTopicNum = taosArrayGetSize(pConsumer->rebNewTopics);
@@ -356,8 +368,6 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) {
         taosArrayPush(pRebSub->removedConsumers, &pConsumer->consumerId);
       }
       taosRUnLockLatch(&pConsumer->lock);
-    } else {
-      // do nothing
     }
 
     mndReleaseConsumer(pMnode, pConsumer);
@@ -452,7 +462,6 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) {
   // 1. check consumer status
   int32_t status = atomic_load_32(&pConsumer->status);
 
-#if 1
   if (status == MQ_CONSUMER_STATUS__LOST_REBD) {
     mInfo("try to recover consumer:0x%" PRIx64, consumerId);
     SMqConsumerRecoverMsg *pRecoverMsg = rpcMallocCont(sizeof(SMqConsumerRecoverMsg));
@@ -466,7 +475,6 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) {
 
     tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &pRpcMsg);
   }
-#endif
 
   if (status != MQ_CONSUMER_STATUS__READY) {
     mInfo("consumer:0x%" PRIx64 " not ready, status: %s", consumerId, mndConsumerStatusName(status));
@@ -668,7 +676,7 @@ int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
     tstrncpy(pConsumerNew->clientId, subscribe.clientId, tListLen(pConsumerNew->clientId));
 
     // set the update type
-    pConsumerNew->updateType = CONSUMER_UPDATE__MODIFY;
+    pConsumerNew->updateType = CONSUMER_UPDATE__REBALANCE;
     taosArrayDestroy(pConsumerNew->assignedTopics);
     pConsumerNew->assignedTopics = taosArrayDup(pTopicList, topicNameDup);
 
@@ -681,7 +689,6 @@ int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
     if (mndTransPrepare(pMnode, pTrans) != 0) goto _over;
 
   } else {
-    /*taosRLockLatch(&pExistedConsumer->lock);*/
     int32_t status = atomic_load_32(&pExistedConsumer->status);
 
     mInfo("receive subscribe request from existed consumer:0x%" PRIx64
@@ -699,7 +706,7 @@ int32_t mndProcessSubscribeReq(SRpcMsg *pMsg) {
     }
 
     // set the update type
-    pConsumerNew->updateType = CONSUMER_UPDATE__MODIFY;
+    pConsumerNew->updateType = CONSUMER_UPDATE__REBALANCE;
     taosArrayDestroy(pConsumerNew->assignedTopics);
     pConsumerNew->assignedTopics = taosArrayDup(pTopicList, topicNameDup);
 
@@ -809,6 +816,7 @@ SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw) {
   SMqConsumerObj *pConsumer = NULL;
   void           *buf = NULL;
 
+  terrno = 0;
   int8_t sver = 0;
   if (sdbGetRawSoftVer(pRaw, &sver) != 0) {
     goto CM_DECODE_OVER;
@@ -878,9 +886,10 @@ static void updateConsumerStatus(SMqConsumerObj *pConsumer) {
   int32_t status = pConsumer->status;
 
   if (taosArrayGetSize(pConsumer->rebNewTopics) == 0 && taosArrayGetSize(pConsumer->rebRemovedTopics) == 0) {
-    if (status == MQ_CONSUMER_STATUS__MODIFY) {
+    if (status == MQ_CONSUMER_STATUS_REBALANCE) {
       pConsumer->status = MQ_CONSUMER_STATUS__READY;
     } else if (status == MQ_CONSUMER_STATUS__LOST) {
+      ASSERT(taosArrayGetSize(pConsumer->currentTopics) == 0);
       pConsumer->status = MQ_CONSUMER_STATUS__LOST_REBD;
     }
   }
@@ -889,7 +898,7 @@ static void updateConsumerStatus(SMqConsumerObj *pConsumer) {
 // remove from new topic
 static void removeFromNewTopicList(SMqConsumerObj *pConsumer, const char *pTopic) {
   int32_t size = taosArrayGetSize(pConsumer->rebNewTopics);
-  for (int32_t i = 0; i < taosArrayGetSize(pConsumer->rebNewTopics); i++) {
+  for (int32_t i = 0; i < size; i++) {
     char *p = taosArrayGetP(pConsumer->rebNewTopics, i);
     if (strcmp(pTopic, p) == 0) {
       taosArrayRemove(pConsumer->rebNewTopics, i);
@@ -910,46 +919,59 @@ static void removeFromRemoveTopicList(SMqConsumerObj *pConsumer, const char *pTo
     if (strcmp(pTopic, p) == 0) {
       taosArrayRemove(pConsumer->rebRemovedTopics, i);
       taosMemoryFree(p);
+
+      mDebug("consumer:0x%" PRIx64 " remove topic:%s in the removed topic list, remain removedTopics:%d",
+             pConsumer->consumerId, pTopic, (int)taosArrayGetSize(pConsumer->rebRemovedTopics));
       break;
     }
   }
 }
 
+static void removeFromCurrentTopicList(SMqConsumerObj *pConsumer, const char *pTopic) {
+  int32_t sz = taosArrayGetSize(pConsumer->currentTopics);
+  for (int32_t i = 0; i < sz; i++) {
+    char *topic = taosArrayGetP(pConsumer->currentTopics, i);
+    if (strcmp(pTopic, topic) == 0) {
+      taosArrayRemove(pConsumer->currentTopics, i);
+      taosMemoryFree(topic);
+
+      mDebug("consumer:0x%" PRIx64 " remove topic:%s in the current topic list, remain currentTopics:%d",
+             pConsumer->consumerId, pTopic, (int)taosArrayGetSize(pConsumer->currentTopics));
+      break;
+    }
+  }
+}
+
+static bool existInCurrentTopicList(const SMqConsumerObj* pConsumer, const char* pTopic) {
+  bool    existing = false;
+  int32_t size = taosArrayGetSize(pConsumer->currentTopics);
+  for (int32_t i = 0; i < size; i++) {
+    char *topic = taosArrayGetP(pConsumer->currentTopics, i);
+
+    if (strcmp(topic, pTopic) == 0) {
+      existing = true;
+      break;
+    }
+  }
+
+  return existing;
+}
+
 static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer, SMqConsumerObj *pNewConsumer) {
   mDebug("consumer:0x%" PRIx64 " perform update action, update type:%d, subscribe-time:%" PRId64 ", uptime:%" PRId64,
          pOldConsumer->consumerId, pNewConsumer->updateType, pOldConsumer->subscribeTime, pOldConsumer->upTime);
 
   taosWLockLatch(&pOldConsumer->lock);
 
-  if (pNewConsumer->updateType == CONSUMER_UPDATE__MODIFY) {
-    /*A(taosArrayGetSize(pOldConsumer->rebNewTopics) == 0);*/
-    /*A(taosArrayGetSize(pOldConsumer->rebRemovedTopics) == 0);*/
+  if (pNewConsumer->updateType == CONSUMER_UPDATE__REBALANCE) {
+    TSWAP(pOldConsumer->rebNewTopics, pNewConsumer->rebNewTopics);
+    TSWAP(pOldConsumer->rebRemovedTopics, pNewConsumer->rebRemovedTopics);
+    TSWAP(pOldConsumer->assignedTopics, pNewConsumer->assignedTopics);
 
-    // this new consumer has identical topics with one existed consumers.
-    if (taosArrayGetSize(pNewConsumer->rebNewTopics) == 0 && taosArrayGetSize(pNewConsumer->rebRemovedTopics) == 0) {
-      pOldConsumer->status = MQ_CONSUMER_STATUS__READY;
-    } else {
-      SArray *tmp = pOldConsumer->rebNewTopics;
-      pOldConsumer->rebNewTopics = pNewConsumer->rebNewTopics;
-      pNewConsumer->rebNewTopics = tmp;
-
-      tmp = pOldConsumer->rebRemovedTopics;
-      pOldConsumer->rebRemovedTopics = pNewConsumer->rebRemovedTopics;
-      pNewConsumer->rebRemovedTopics = tmp;
-
-      tmp = pOldConsumer->assignedTopics;
-      pOldConsumer->assignedTopics = pNewConsumer->assignedTopics;
-      pNewConsumer->assignedTopics = tmp;
-
-      pOldConsumer->subscribeTime = pNewConsumer->upTime;
-      pOldConsumer->status = MQ_CONSUMER_STATUS__MODIFY;
-    }
+    pOldConsumer->subscribeTime = pNewConsumer->upTime;
+    pOldConsumer->status = MQ_CONSUMER_STATUS_REBALANCE;
   } else if (pNewConsumer->updateType == CONSUMER_UPDATE__LOST) {
-    /*A(taosArrayGetSize(pOldConsumer->rebNewTopics) == 0);*/
-    /*A(taosArrayGetSize(pOldConsumer->rebRemovedTopics) == 0);*/
-
     int32_t sz = taosArrayGetSize(pOldConsumer->currentTopics);
-    /*pOldConsumer->rebRemovedTopics = taosArrayInit(sz, sizeof(void *));*/
     for (int32_t i = 0; i < sz; i++) {
       char *topic = taosStrdup(taosArrayGetP(pOldConsumer->currentTopics, i));
       taosArrayPush(pOldConsumer->rebRemovedTopics, &topic);
@@ -957,15 +979,12 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer,
 
     pOldConsumer->rebalanceTime = pNewConsumer->upTime;
 
-    int32_t status = pOldConsumer->status;
+    int32_t prevStatus = pOldConsumer->status;
     pOldConsumer->status = MQ_CONSUMER_STATUS__LOST;
     mDebug("consumer:0x%" PRIx64 " state %s -> %s, reb-time:%" PRId64 ", reb-removed-topics:%d",
-           pOldConsumer->consumerId, mndConsumerStatusName(status), mndConsumerStatusName(pOldConsumer->status),
+           pOldConsumer->consumerId, mndConsumerStatusName(prevStatus), mndConsumerStatusName(pOldConsumer->status),
            pOldConsumer->rebalanceTime, (int)taosArrayGetSize(pOldConsumer->rebRemovedTopics));
   } else if (pNewConsumer->updateType == CONSUMER_UPDATE__RECOVER) {
-    /*A(taosArrayGetSize(pOldConsumer->currentTopics) == 0);*/
-    /*A(taosArrayGetSize(pOldConsumer->rebNewTopics) == 0);*/
-
     int32_t sz = taosArrayGetSize(pOldConsumer->assignedTopics);
     for (int32_t i = 0; i < sz; i++) {
       char *topic = taosStrdup(taosArrayGetP(pOldConsumer->assignedTopics, i));
@@ -973,35 +992,25 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer,
     }
 
     pOldConsumer->rebalanceTime = pNewConsumer->upTime;
-
-    pOldConsumer->status = MQ_CONSUMER_STATUS__MODIFY;
+    pOldConsumer->status = MQ_CONSUMER_STATUS_REBALANCE;
   } else if (pNewConsumer->updateType == CONSUMER_UPDATE__TOUCH) {
     atomic_add_fetch_32(&pOldConsumer->epoch, 1);
 
     pOldConsumer->rebalanceTime = pNewConsumer->upTime;
 
   } else if (pNewConsumer->updateType == CONSUMER_UPDATE__ADD) {
-    ASSERT(taosArrayGetSize(pNewConsumer->rebNewTopics) == 1 && taosArrayGetSize(pNewConsumer->rebRemovedTopics) == 0);
     char *pNewTopic = taosStrdup(taosArrayGetP(pNewConsumer->rebNewTopics, 0));
 
-    // not exist in current topic
-    bool    existing = false;
-    int32_t numOfExistedTopics = taosArrayGetSize(pOldConsumer->currentTopics);
-    for (int32_t i = 0; i < numOfExistedTopics; i++) {
-      char *topic = taosArrayGetP(pOldConsumer->currentTopics, i);
-      if (strcmp(topic, pNewTopic) == 0) {
-        existing = true;
-      }
-    }
-
+    // check if exist in current topic
     removeFromNewTopicList(pOldConsumer, pNewTopic);
 
     // add to current topic
-    if (!existing) {
+    bool existing = existInCurrentTopicList(pOldConsumer, pNewTopic);
+    if (existing) {
+      taosMemoryFree(pNewTopic);
+    } else {  // added into current topic list
       taosArrayPush(pOldConsumer->currentTopics, &pNewTopic);
       taosArraySort(pOldConsumer->currentTopics, taosArrayCompareString);
-    } else {
-      taosMemoryFree(pNewTopic);
     }
 
     // set status
@@ -1020,30 +1029,13 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer,
            (int)taosArrayGetSize(pOldConsumer->rebRemovedTopics));
 
   } else if (pNewConsumer->updateType == CONSUMER_UPDATE__REMOVE) {
-    /*A(taosArrayGetSize(pNewConsumer->rebNewTopics) == 0);*/
-    /*A(taosArrayGetSize(pNewConsumer->rebRemovedTopics) == 1);*/
     char *removedTopic = taosArrayGetP(pNewConsumer->rebRemovedTopics, 0);
-#if 0
-    for (int32_t i = 0; i < taosArrayGetSize(pOldConsumer->rebNewTopics); i++) {
-      char *topic = taosArrayGetP(pOldConsumer->rebNewTopics, i);
-      A(strcmp(topic, removedTopic) != 0);
-    }
-#endif
 
     // remove from removed topic
     removeFromRemoveTopicList(pOldConsumer, removedTopic);
 
     // remove from current topic
-    int32_t i = 0;
-    int32_t sz = taosArrayGetSize(pOldConsumer->currentTopics);
-    for (i = 0; i < sz; i++) {
-      char *topic = taosArrayGetP(pOldConsumer->currentTopics, i);
-      if (strcmp(removedTopic, topic) == 0) {
-        taosArrayRemove(pOldConsumer->currentTopics, i);
-        taosMemoryFree(topic);
-        break;
-      }
-    }
+    removeFromCurrentTopicList(pOldConsumer, removedTopic);
 
     // set status
     int32_t status = pOldConsumer->status;
@@ -1192,7 +1184,7 @@ static const char *mndConsumerStatusName(int status) {
     case MQ_CONSUMER_STATUS__LOST:
     case MQ_CONSUMER_STATUS__LOST_REBD:
       return "lost";
-    case MQ_CONSUMER_STATUS__MODIFY:
+    case MQ_CONSUMER_STATUS_REBALANCE:
       return "rebalancing";
     default:
       return "unknown";
diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c
index df22034068..23b2b9d7c6 100644
--- a/source/dnode/mnode/impl/src/mndDb.c
+++ b/source/dnode/mnode/impl/src/mndDb.c
@@ -373,6 +373,8 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
   if (pCfg->sstTrigger < TSDB_MIN_STT_TRIGGER || pCfg->sstTrigger > TSDB_MAX_STT_TRIGGER) return -1;
   if (pCfg->hashPrefix < TSDB_MIN_HASH_PREFIX || pCfg->hashPrefix > TSDB_MAX_HASH_PREFIX) return -1;
   if (pCfg->hashSuffix < TSDB_MIN_HASH_SUFFIX || pCfg->hashSuffix > TSDB_MAX_HASH_SUFFIX) return -1;
+  if ((pCfg->hashSuffix * pCfg->hashPrefix) < 0) return -1;
+  if ((pCfg->hashPrefix + pCfg->hashSuffix) >= (TSDB_TABLE_NAME_LEN - 1)) return -1;
   if (pCfg->tsdbPageSize < TSDB_MIN_TSDB_PAGESIZE || pCfg->tsdbPageSize > TSDB_MAX_TSDB_PAGESIZE) return -1;
   if (taosArrayGetSize(pCfg->pRetensions) != pCfg->numOfRetensions) return -1;
 
@@ -409,8 +411,6 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) {
   if (pCfg->walRollPeriod < 0) pCfg->walRollPeriod = TSDB_REPS_DEF_DB_WAL_ROLL_PERIOD;
   if (pCfg->walSegmentSize < 0) pCfg->walSegmentSize = TSDB_DEFAULT_DB_WAL_SEGMENT_SIZE;
   if (pCfg->sstTrigger <= 0) pCfg->sstTrigger = TSDB_DEFAULT_SST_TRIGGER;
-  if (pCfg->hashPrefix < 0) pCfg->hashPrefix = TSDB_DEFAULT_HASH_PREFIX;
-  if (pCfg->hashSuffix < 0) pCfg->hashSuffix = TSDB_DEFAULT_HASH_SUFFIX;
   if (pCfg->tsdbPageSize <= 0) pCfg->tsdbPageSize = TSDB_DEFAULT_TSDB_PAGESIZE;
 }
 
@@ -553,6 +553,10 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate,
     int32_t dbLen = strlen(dbObj.name) + 1;
     mInfo("db:%s, hashPrefix adjust from %d to %d", dbObj.name, dbObj.cfg.hashPrefix, dbObj.cfg.hashPrefix + dbLen);
     dbObj.cfg.hashPrefix += dbLen;
+  } else if (dbObj.cfg.hashPrefix < 0) {
+    int32_t dbLen = strlen(dbObj.name) + 1;
+    mInfo("db:%s, hashPrefix adjust from %d to %d", dbObj.name, dbObj.cfg.hashPrefix, dbObj.cfg.hashPrefix - dbLen);
+    dbObj.cfg.hashPrefix -= dbLen;
   }
 
   SVgObj *pVgroups = NULL;
@@ -1437,7 +1441,7 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs,
   return 0;
 }
 
-static int32_t mndTrimDb(SMnode *pMnode, SDbObj *pDb, SRpcMsg *pReq) {
+static int32_t mndTrimDb(SMnode *pMnode, SDbObj *pDb) {
   SSdb       *pSdb = pMnode->pSdb;
   SVgObj     *pVgroup = NULL;
   void       *pIter = NULL;
@@ -1459,7 +1463,7 @@ static int32_t mndTrimDb(SMnode *pMnode, SDbObj *pDb, SRpcMsg *pReq) {
     pHead->vgId = htonl(pVgroup->vgId);
     tSerializeSVTrimDbReq((char *)pHead + sizeof(SMsgHead), contLen, &trimReq);
 
-    SRpcMsg rpcMsg = {.msgType = TDMT_VND_TRIM, .pCont = pHead, .contLen = contLen, .info = pReq->info};
+    SRpcMsg rpcMsg = {.msgType = TDMT_VND_TRIM, .pCont = pHead, .contLen = contLen};
     SEpSet  epSet = mndGetVgroupEpset(pMnode, pVgroup);
     int32_t code = tmsgSendReq(&epSet, &rpcMsg);
     if (code != 0) {
@@ -1495,7 +1499,7 @@ static int32_t mndProcessTrimDbReq(SRpcMsg *pReq) {
     goto _OVER;
   }
 
-  code = mndTrimDb(pMnode, pDb, pReq);
+  code = mndTrimDb(pMnode, pDb);
 
 _OVER:
   if (code != 0) {
@@ -1788,6 +1792,8 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
     int16_t hashPrefix = pDb->cfg.hashPrefix;
     if (hashPrefix > 0) {
       hashPrefix = pDb->cfg.hashPrefix - strlen(pDb->name) - 1;
+    } else if (hashPrefix < 0) {
+      hashPrefix = pDb->cfg.hashPrefix + strlen(pDb->name) + 1;
     }
     colDataSetVal(pColInfo, rows, (const char *)&hashPrefix, false);
 
diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c
index c69f08eb6b..6dab018236 100644
--- a/source/dnode/mnode/impl/src/mndDef.c
+++ b/source/dnode/mnode/impl/src/mndDef.c
@@ -225,7 +225,7 @@ SMqConsumerObj *tNewSMqConsumerObj(int64_t consumerId, char cgroup[TSDB_CGROUP_L
   memcpy(pConsumer->cgroup, cgroup, TSDB_CGROUP_LEN);
 
   pConsumer->epoch = 0;
-  pConsumer->status = MQ_CONSUMER_STATUS__MODIFY;
+  pConsumer->status = MQ_CONSUMER_STATUS_REBALANCE;
   pConsumer->hbStatus = 0;
 
   taosInitRWLatch(&pConsumer->lock);
diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c
index a9f52128a6..381b1e64ed 100644
--- a/source/dnode/mnode/impl/src/mndMain.c
+++ b/source/dnode/mnode/impl/src/mndMain.c
@@ -124,11 +124,7 @@ static void mndCalMqRebalance(SMnode *pMnode) {
   int32_t contLen = 0;
   void   *pReq = mndBuildTimerMsg(&contLen);
   if (pReq != NULL) {
-    SRpcMsg rpcMsg = {
-        .msgType = TDMT_MND_TMQ_TIMER,
-        .pCont = pReq,
-        .contLen = contLen,
-    };
+    SRpcMsg rpcMsg = { .msgType = TDMT_MND_TMQ_TIMER, .pCont = pReq, .contLen = contLen };
     tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg);
   }
 }
diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c
index 2ebb5aeb99..d0f88940a9 100644
--- a/source/dnode/mnode/impl/src/mndProfile.c
+++ b/source/dnode/mnode/impl/src/mndProfile.c
@@ -256,10 +256,13 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) {
     snprintf(db, TSDB_DB_FNAME_LEN, "%d%s%s", pUser->acctId, TS_PATH_DELIMITER, connReq.db);
     pDb = mndAcquireDb(pMnode, db);
     if (pDb == NULL) {
-      terrno = TSDB_CODE_MND_INVALID_DB;
-      mGError("user:%s, failed to login from %s while use db:%s since %s", pReq->info.conn.user, ip, connReq.db,
-              terrstr());
-      goto _OVER;
+      if (0 != strcmp(connReq.db, TSDB_INFORMATION_SCHEMA_DB) &&
+          (0 != strcmp(connReq.db, TSDB_PERFORMANCE_SCHEMA_DB))) {
+        terrno = TSDB_CODE_MND_INVALID_DB;
+        mGError("user:%s, failed to login from %s while use db:%s since %s", pReq->info.conn.user, ip, connReq.db,
+                terrstr());
+        goto _OVER;
+      }
     }
 
     if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_READ_OR_WRITE_DB, pDb) != 0) {
diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c
index 63bcef2a5b..8b708c3e0f 100644
--- a/source/dnode/mnode/impl/src/mndStb.c
+++ b/source/dnode/mnode/impl/src/mndStb.c
@@ -797,6 +797,11 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat
     return -1;
   }
 
+  if(pDst->nextColId < 0 || pDst->nextColId >= 0x7fff - pDst->numOfColumns - pDst->numOfTags){
+    terrno = TSDB_CODE_MND_FIELD_VALUE_OVERFLOW;
+    return -1;
+  }
+
   for (int32_t i = 0; i < pDst->numOfColumns; ++i) {
     SField  *pField = taosArrayGet(pCreate->pColumns, i);
     SSchema *pSchema = &pDst->pColumns[i];
@@ -927,6 +932,11 @@ static int32_t mndBuildStbFromAlter(SStbObj *pStb, SStbObj *pDst, SMCreateStbReq
     return -1;
   }
 
+  if(pDst->nextColId < 0 || pDst->nextColId >= 0x7fff - pDst->numOfColumns - pDst->numOfTags){
+    terrno = TSDB_CODE_MND_FIELD_VALUE_OVERFLOW;
+    return -1;
+  }
+
   for (int32_t i = 0; i < pDst->numOfColumns; ++i) {
     SField  *pField = taosArrayGet(createReq->pColumns, i);
     SSchema *pSchema = &pDst->pColumns[i];
@@ -1153,6 +1163,11 @@ static int32_t mndAddSuperTableTag(const SStbObj *pOld, SStbObj *pNew, SArray *p
   if (mndAllocStbSchemas(pOld, pNew) != 0) {
     return -1;
   }
+ 
+  if(pNew->nextColId < 0 || pNew->nextColId >= 0x7fff - ntags){
+    terrno = TSDB_CODE_MND_FIELD_VALUE_OVERFLOW;
+    return -1;
+  }
 
   for (int32_t i = 0; i < ntags; i++) {
     SField *pField = taosArrayGet(pFields, i);
@@ -1461,6 +1476,11 @@ static int32_t mndAddSuperTableColumn(const SStbObj *pOld, SStbObj *pNew, SArray
     return -1;
   }
 
+  if(pNew->nextColId < 0 || pNew->nextColId >= 0x7fff - ncols){
+    terrno = TSDB_CODE_MND_FIELD_VALUE_OVERFLOW;
+    return -1;
+  }
+
   for (int32_t i = 0; i < ncols; i++) {
     SField *pField = taosArrayGet(pFields, i);
     if (mndFindSuperTableColumnIndex(pOld, pField->name) >= 0) {
@@ -2524,6 +2544,9 @@ int32_t mndValidateStbInfo(SMnode *pMnode, SSTableVersion *pStbVersions, int32_t
     if (mndBuildStbSchema(pMnode, pStbVersion->dbFName, pStbVersion->stbName, &metaRsp, &smaVer) != 0) {
       metaRsp.numOfColumns = -1;
       metaRsp.suid = pStbVersion->suid;
+      tstrncpy(metaRsp.dbFName, pStbVersion->dbFName, sizeof(metaRsp.dbFName));
+      tstrncpy(metaRsp.tbName, pStbVersion->stbName, sizeof(metaRsp.tbName));
+      tstrncpy(metaRsp.stbName, pStbVersion->stbName, sizeof(metaRsp.stbName));
       taosArrayPush(hbRsp.pMetaRsp, &metaRsp);
       continue;
     }
diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c
index 49921c9a1a..e62102fa77 100644
--- a/source/dnode/mnode/impl/src/mndSubscribe.c
+++ b/source/dnode/mnode/impl/src/mndSubscribe.c
@@ -133,10 +133,10 @@ static int32_t mndBuildSubChangeReq(void **pBuf, int32_t *pLen, const SMqSubscri
 
 static int32_t mndPersistSubChangeVgReq(SMnode *pMnode, STrans *pTrans, const SMqSubscribeObj *pSub,
                                         const SMqRebOutputVg *pRebVg) {
-  if (pRebVg->oldConsumerId == pRebVg->newConsumerId) {
-    terrno = TSDB_CODE_MND_INVALID_SUB_OPTION;
-    return -1;
-  }
+//  if (pRebVg->oldConsumerId == pRebVg->newConsumerId) {
+//    terrno = TSDB_CODE_MND_INVALID_SUB_OPTION;
+//    return -1;
+//  }
 
   void   *buf;
   int32_t tlen;
@@ -197,7 +197,7 @@ static SMqRebInfo *mndGetOrCreateRebSub(SHashObj *pHash, const char *key) {
   return pRebSub;
 }
 
-static void doRemoveExistedConsumers(SMqRebOutputObj *pOutput, SHashObj *pHash, const SMqRebInputObj *pInput) {
+static void doRemoveLostConsumers(SMqRebOutputObj *pOutput, SHashObj *pHash, const SMqRebInputObj *pInput) {
   int32_t     numOfRemoved = taosArrayGetSize(pInput->pRebInfo->removedConsumers);
   const char *pSubKey = pOutput->pSub->key;
 
@@ -213,13 +213,9 @@ static void doRemoveExistedConsumers(SMqRebOutputObj *pOutput, SHashObj *pHash,
 
       int32_t consumerVgNum = taosArrayGetSize(pConsumerEp->vgs);
       for (int32_t j = 0; j < consumerVgNum; j++) {
-        SMqVgEp       *pVgEp = taosArrayGetP(pConsumerEp->vgs, j);
-        SMqRebOutputVg outputVg = {
-            .oldConsumerId = consumerId,
-            .newConsumerId = -1,
-            .pVgEp = pVgEp,
-        };
+        SMqVgEp *pVgEp = taosArrayGetP(pConsumerEp->vgs, j);
 
+        SMqRebOutputVg outputVg = {.oldConsumerId = consumerId, .newConsumerId = -1, .pVgEp = pVgEp};
         taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &outputVg, sizeof(SMqRebOutputVg));
         mInfo("sub:%s mq re-balance remove vgId:%d from consumer:%" PRIx64, pSubKey, pVgEp->vgId, consumerId);
       }
@@ -269,7 +265,19 @@ static void addUnassignedVgroups(SMqRebOutputObj *pOutput, SHashObj *pHash) {
     };
 
     taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &rebOutput, sizeof(SMqRebOutputVg));
-    mInfo("sub:%s mq re-balance remove vgId:%d from unassigned", pSubKey, pVgEp->vgId);
+    mInfo("sub:%s mq re-balance addUnassignedVgroups vgId:%d from unassigned", pSubKey, pVgEp->vgId);
+  }
+}
+
+static void putNoTransferToOutput(SMqRebOutputObj *pOutput, SMqConsumerEp *pConsumerEp){
+  for(int i = 0; i < taosArrayGetSize(pConsumerEp->vgs); i++){
+    SMqVgEp       *pVgEp = (SMqVgEp *)taosArrayGetP(pConsumerEp->vgs, i);
+    SMqRebOutputVg outputVg = {
+        .oldConsumerId = pConsumerEp->consumerId,
+        .newConsumerId = pConsumerEp->consumerId,
+        .pVgEp = pVgEp,
+    };
+    taosArrayPush(pOutput->rebVgs, &outputVg);
   }
 }
 
@@ -289,29 +297,24 @@ static void transferVgroupsForConsumers(SMqRebOutputObj *pOutput, SHashObj *pHas
     SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter;
     int32_t        consumerVgNum = taosArrayGetSize(pConsumerEp->vgs);
 
-    // all old consumers still existing are touched
-    // TODO optimize: touch only consumer whose vgs changed
-    taosArrayPush(pOutput->touchedConsumers, &pConsumerEp->consumerId);
+    // all old consumers still existing need to be modified
+    // TODO optimize: modify only consumer whose vgs changed
+    taosArrayPush(pOutput->modifyConsumers, &pConsumerEp->consumerId);
     if (consumerVgNum > minVgCnt) {
       if (imbCnt < imbConsumerNum) {
-        if (consumerVgNum == minVgCnt + 1) {
-          imbCnt++;
-          continue;
-        } else {
-          // pop until equal minVg + 1
-          while (taosArrayGetSize(pConsumerEp->vgs) > minVgCnt + 1) {
-            SMqVgEp       *pVgEp = *(SMqVgEp **)taosArrayPop(pConsumerEp->vgs);
-            SMqRebOutputVg outputVg = {
-                .oldConsumerId = pConsumerEp->consumerId,
-                .newConsumerId = -1,
-                .pVgEp = pVgEp,
-            };
-            taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &outputVg, sizeof(SMqRebOutputVg));
-            mInfo("sub:%s mq rebalance remove vgId:%d from consumer:0x%" PRIx64 ",(first scan)", pSubKey, pVgEp->vgId,
-                  pConsumerEp->consumerId);
-          }
-          imbCnt++;
+        // pop until equal minVg + 1
+        while (taosArrayGetSize(pConsumerEp->vgs) > minVgCnt + 1) {
+          SMqVgEp       *pVgEp = *(SMqVgEp **)taosArrayPop(pConsumerEp->vgs);
+          SMqRebOutputVg outputVg = {
+              .oldConsumerId = pConsumerEp->consumerId,
+              .newConsumerId = -1,
+              .pVgEp = pVgEp,
+          };
+          taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &outputVg, sizeof(SMqRebOutputVg));
+          mInfo("sub:%s mq rebalance remove vgId:%d from consumer:0x%" PRIx64 ",(first scan)", pSubKey, pVgEp->vgId,
+                pConsumerEp->consumerId);
         }
+        imbCnt++;
       } else {
         // all the remain consumers should only have the number of vgroups, which is equalled to the value of minVg
         while (taosArrayGetSize(pConsumerEp->vgs) > minVgCnt) {
@@ -327,6 +330,7 @@ static void transferVgroupsForConsumers(SMqRebOutputObj *pOutput, SHashObj *pHas
         }
       }
     }
+    putNoTransferToOutput(pOutput, pConsumerEp);
   }
 }
 
@@ -339,13 +343,13 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
   mInfo("sub:%s mq re-balance %d vgroups, existed consumers:%d, added:%d, removed:%d", pSubKey, totalVgNum,
         pInput->oldConsumerNum, numOfAdded, numOfRemoved);
 
-  // 1. build temporary hash(vgId -> SMqRebOutputVg) to store modified vg
+  // 1. build temporary hash(vgId -> SMqRebOutputVg) to store vg that need to be assigned
   SHashObj *pHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
 
-  // 2. check and get actual removed consumers, put their vg into hash
-  doRemoveExistedConsumers(pOutput, pHash, pInput);
+  // 2. check and get actual removed consumers, put their vg into pHash
+  doRemoveLostConsumers(pOutput, pHash, pInput);
 
-  // 3. if previously no consumer, there are vgs not assigned
+  // 3. if previously no consumer, there are vgs not assigned, put these vg into pHash
   addUnassignedVgroups(pOutput, pHash);
 
   // 4. calc vg number of each consumer
@@ -364,19 +368,17 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
     mInfo("sub:%s no consumer subscribe this topic", pSubKey);
   }
 
-  // 5. first scan: remove vgroups from te consumers, who have more vgroups than the threashold value that is
-  // minVgCnt, and then put them into the recycled hash list
+  // 5. remove vgroups from consumers who have more vgroups than the threshold value(minVgCnt or minVgCnt + 1), and then another vg into pHash
   transferVgroupsForConsumers(pOutput, pHash, minVgCnt, imbConsumerNum);
 
   // 6. add new consumer into sub
   doAddNewConsumers(pOutput, pInput);
 
-  // 7. second scan: find consumer do not have enough vgroups, extract from temporary hash and assign to them
-  // All related vg should be put into rebVgs
   SMqRebOutputVg *pRebVg = NULL;
   void           *pRemovedIter = NULL;
   void           *pIter = NULL;
 
+  // 7. extract bgroups from pHash and assign to consumers that do not have enough vgroups
   while (1) {
     pIter = taosHashIterate(pOutput->pSub->consumerHash, pIter);
     if (pIter == NULL) {
@@ -390,68 +392,52 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
       // iter hash and find one vg
       pRemovedIter = taosHashIterate(pHash, pRemovedIter);
       if (pRemovedIter == NULL) {
-        mError("sub:%s removed iter is null", pSubKey);
+        mError("sub:%s removed iter is null, never can reach hear", pSubKey);
         break;
       }
 
       pRebVg = (SMqRebOutputVg *)pRemovedIter;
-      // push
-      taosArrayPush(pConsumerEp->vgs, &pRebVg->pVgEp);
       pRebVg->newConsumerId = pConsumerEp->consumerId;
-      taosArrayPush(pOutput->rebVgs, pRebVg);
-      mInfo("mq rebalance: add vgId:%d to consumer:0x%" PRIx64 " (second scan) (not enough)", pRebVg->pVgEp->vgId,
-            pConsumerEp->consumerId);
+      taosArrayPush(pConsumerEp->vgs, &pRebVg->pVgEp);
+      mInfo("mq rebalance: add vgId:%d to consumer:0x%" PRIx64 " for average", pRebVg->pVgEp->vgId, pConsumerEp->consumerId);
     }
   }
 
-  // 7. handle unassigned vg
-  if (taosHashGetSize(pOutput->pSub->consumerHash) != 0) {
-    // if has consumer, assign all left vg
-    while (1) {
-      SMqConsumerEp *pConsumerEp = NULL;
+  while (1) {
+    pIter = taosHashIterate(pOutput->pSub->consumerHash, pIter);
+    if (pIter == NULL) {
+      break;
+    }
+    SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter;
+
+    if (taosArrayGetSize(pConsumerEp->vgs) == minVgCnt) {
       pRemovedIter = taosHashIterate(pHash, pRemovedIter);
       if (pRemovedIter == NULL) {
-        if (pIter != NULL) {
-          taosHashCancelIterate(pOutput->pSub->consumerHash, pIter);
-          pIter = NULL;
-        }
+        mInfo("sub:%s removed iter is null", pSubKey);
         break;
       }
-      while (1) {
-        pIter = taosHashIterate(pOutput->pSub->consumerHash, pIter);
-        pConsumerEp = (SMqConsumerEp *)pIter;
 
-        if (taosArrayGetSize(pConsumerEp->vgs) == minVgCnt) {
-          break;
-        }
-      }
       pRebVg = (SMqRebOutputVg *)pRemovedIter;
-      taosArrayPush(pConsumerEp->vgs, &pRebVg->pVgEp);
       pRebVg->newConsumerId = pConsumerEp->consumerId;
-      if (pRebVg->newConsumerId == pRebVg->oldConsumerId) {
-        mInfo("mq rebalance: skip vg %d for same consumer:0x%" PRIx64 " (second scan)", pRebVg->pVgEp->vgId,
-              pConsumerEp->consumerId);
-        continue;
-      }
-      taosArrayPush(pOutput->rebVgs, pRebVg);
-      mInfo("mq rebalance: add vgId:%d to consumer:0x%" PRIx64 " (second scan) (unassigned)", pRebVg->pVgEp->vgId,
-            pConsumerEp->consumerId);
+      taosArrayPush(pConsumerEp->vgs, &pRebVg->pVgEp);
+      mInfo("mq rebalance: add vgId:%d to consumer:0x%" PRIx64 " for average + 1", pRebVg->pVgEp->vgId, pConsumerEp->consumerId);
     }
-  } else {
-    // if all consumer is removed, put all vg into unassigned
-    pIter = NULL;
-    SMqRebOutputVg *pRebOutput = NULL;
-    while (1) {
-      pIter = taosHashIterate(pHash, pIter);
-      if (pIter == NULL) {
-        break;
-      }
+  }
 
-      pRebOutput = (SMqRebOutputVg *)pIter;
+  // All assigned vg should be put into pOutput->rebVgs
+  if(pRemovedIter != NULL){
+    mError("sub:%s error pRemovedIter should be NULL", pSubKey);
+  }
+  while (1) {
+    pRemovedIter = taosHashIterate(pHash, pRemovedIter);
+    if (pRemovedIter == NULL) {
+      break;
+    }
 
+    SMqRebOutputVg* pRebOutput = (SMqRebOutputVg *)pRemovedIter;
+    taosArrayPush(pOutput->rebVgs, pRebOutput);
+    if(taosHashGetSize(pOutput->pSub->consumerHash) == 0){    // if all consumer is removed, put all vg into unassigned
       taosArrayPush(pOutput->pSub->unassignedVgs, &pRebOutput->pVgEp);
-      taosArrayPush(pOutput->rebVgs, pRebOutput);
-      mInfo("sub:%s mq re-balance unassign vgId:%d (second scan)", pSubKey, pRebOutput->pVgEp->vgId);
     }
   }
 
@@ -462,19 +448,18 @@ static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqR
     mInfo("sub:%s mq re-balance vgId:%d, moved from consumer:0x%" PRIx64 ", to consumer:0x%" PRIx64, pSubKey,
           pOutputRebVg->pVgEp->vgId, pOutputRebVg->oldConsumerId, pOutputRebVg->newConsumerId);
   }
-  {
-    pIter = NULL;
-    while (1) {
-      pIter = taosHashIterate(pOutput->pSub->consumerHash, pIter);
-      if (pIter == NULL) break;
-      SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter;
-      int32_t        sz = taosArrayGetSize(pConsumerEp->vgs);
-      mInfo("sub:%s mq re-balance final cfg: consumer:0x%" PRIx64 " has %d vg", pSubKey, pConsumerEp->consumerId, sz);
-      for (int32_t i = 0; i < sz; i++) {
-        SMqVgEp *pVgEp = taosArrayGetP(pConsumerEp->vgs, i);
-        mInfo("sub:%s mq re-balance final cfg: vg %d to consumer:0x%" PRIx64, pSubKey, pVgEp->vgId,
-              pConsumerEp->consumerId);
-      }
+
+  pIter = NULL;
+  while (1) {
+    pIter = taosHashIterate(pOutput->pSub->consumerHash, pIter);
+    if (pIter == NULL) break;
+    SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter;
+    int32_t        sz = taosArrayGetSize(pConsumerEp->vgs);
+    mInfo("sub:%s mq re-balance final cfg: consumer:0x%" PRIx64 " has %d vg", pSubKey, pConsumerEp->consumerId, sz);
+    for (int32_t i = 0; i < sz; i++) {
+      SMqVgEp *pVgEp = taosArrayGetP(pConsumerEp->vgs, i);
+      mInfo("sub:%s mq re-balance final cfg: vg %d to consumer:0x%" PRIx64, pSubKey, pVgEp->vgId,
+            pConsumerEp->consumerId);
     }
   }
 
@@ -503,21 +488,23 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu
   for (int32_t i = 0; i < vgNum; i++) {
     SMqRebOutputVg *pRebVg = taosArrayGet(rebVgs, i);
     if (mndPersistSubChangeVgReq(pMnode, pTrans, pOutput->pSub, pRebVg) < 0) {
-      goto REB_FAIL;
+      mndTransDrop(pTrans);
+      return -1;
     }
   }
 
   // 2. redo log: subscribe and vg assignment
   // subscribe
   if (mndSetSubCommitLogs(pMnode, pTrans, pOutput->pSub) != 0) {
-    goto REB_FAIL;
+    mndTransDrop(pTrans);
+    return -1;
   }
 
   // 3. commit log: consumer to update status and epoch
   // 3.1 set touched consumer
-  int32_t consumerNum = taosArrayGetSize(pOutput->touchedConsumers);
+  int32_t consumerNum = taosArrayGetSize(pOutput->modifyConsumers);
   for (int32_t i = 0; i < consumerNum; i++) {
-    int64_t         consumerId = *(int64_t *)taosArrayGet(pOutput->touchedConsumers, i);
+    int64_t         consumerId = *(int64_t *)taosArrayGet(pOutput->modifyConsumers, i);
     SMqConsumerObj *pConsumerOld = mndAcquireConsumer(pMnode, consumerId);
     SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumerOld->consumerId, pConsumerOld->cgroup);
     pConsumerNew->updateType = CONSUMER_UPDATE__TOUCH;
@@ -525,11 +512,15 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu
     if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) {
       tDeleteSMqConsumerObj(pConsumerNew);
       taosMemoryFree(pConsumerNew);
-      goto REB_FAIL;
+
+      mndTransDrop(pTrans);
+      return -1;
     }
+
     tDeleteSMqConsumerObj(pConsumerNew);
     taosMemoryFree(pConsumerNew);
   }
+
   // 3.2 set new consumer
   consumerNum = taosArrayGetSize(pOutput->newConsumers);
   for (int32_t i = 0; i < consumerNum; i++) {
@@ -546,8 +537,11 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu
     if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) {
       tDeleteSMqConsumerObj(pConsumerNew);
       taosMemoryFree(pConsumerNew);
-      goto REB_FAIL;
+
+      mndTransDrop(pTrans);
+      return -1;
     }
+
     tDeleteSMqConsumerObj(pConsumerNew);
     taosMemoryFree(pConsumerNew);
   }
@@ -568,8 +562,11 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu
     if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) {
       tDeleteSMqConsumerObj(pConsumerNew);
       taosMemoryFree(pConsumerNew);
-      goto REB_FAIL;
+
+      mndTransDrop(pTrans);
+      return -1;
     }
+
     tDeleteSMqConsumerObj(pConsumerNew);
     taosMemoryFree(pConsumerNew);
   }
@@ -582,44 +579,50 @@ static int32_t mndPersistRebResult(SMnode *pMnode, SRpcMsg *pMsg, const SMqRebOu
   // 6. execution
   if (mndTransPrepare(pMnode, pTrans) != 0) {
     mError("failed to prepare trans rebalance since %s", terrstr());
-    goto REB_FAIL;
+    mndTransDrop(pTrans);
+    return -1;
   }
 
   mndTransDrop(pTrans);
   return 0;
-
-REB_FAIL:
-  mndTransDrop(pTrans);
-  return -1;
 }
 
 static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
   SMnode            *pMnode = pMsg->info.node;
   SMqDoRebalanceMsg *pReq = pMsg->pCont;
   void              *pIter = NULL;
-  bool               rebalanceOnce = false;  // to ensure only once.
+//  bool               rebalanceOnce = false;  // to ensure only once.
 
   mInfo("mq re-balance start, total required re-balanced trans:%d", taosHashGetSize(pReq->rebSubHash));
 
   // here we only handle one topic rebalance requirement to ensure the atomic execution of this transaction.
   while (1) {
-    if (rebalanceOnce) {
-      break;
-    }
-
     pIter = taosHashIterate(pReq->rebSubHash, pIter);
     if (pIter == NULL) {
       break;
     }
 
-    // todo handle the malloc failure
     SMqRebInputObj  rebInput = {0};
     SMqRebOutputObj rebOutput = {0};
     rebOutput.newConsumers = taosArrayInit(0, sizeof(int64_t));
     rebOutput.removedConsumers = taosArrayInit(0, sizeof(int64_t));
-    rebOutput.touchedConsumers = taosArrayInit(0, sizeof(int64_t));
+    rebOutput.modifyConsumers = taosArrayInit(0, sizeof(int64_t));
     rebOutput.rebVgs = taosArrayInit(0, sizeof(SMqRebOutputVg));
 
+    if (rebOutput.newConsumers == NULL || rebOutput.removedConsumers == NULL || rebOutput.modifyConsumers == NULL ||
+        rebOutput.rebVgs == NULL) {
+      taosArrayDestroy(rebOutput.newConsumers);
+      taosArrayDestroy(rebOutput.removedConsumers);
+      taosArrayDestroy(rebOutput.modifyConsumers);
+      taosArrayDestroy(rebOutput.rebVgs);
+
+      terrno = TSDB_CODE_OUT_OF_MEMORY;
+      mInfo("mq re-balance failed, due to out of memory");
+      taosHashCleanup(pReq->rebSubHash);
+      mndRebEnd();
+      return -1;
+    }
+
     SMqRebInfo      *pRebInfo = (SMqRebInfo *)pIter;
     SMqSubscribeObj *pSub = mndAcquireSubscribeByKey(pMnode, pRebInfo->key);
 
@@ -653,13 +656,14 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
       mndReleaseTopic(pMnode, pTopic);
 
       rebInput.oldConsumerNum = 0;
-      mInfo("topic:%s has no consumers sub yet", topic);
+      mInfo("sub topic:%s has no consumers sub yet", pRebInfo->key);
     } else {
       taosRLockLatch(&pSub->lock);
       rebInput.oldConsumerNum = taosHashGetSize(pSub->consumerHash);
       rebOutput.pSub = tCloneSubscribeObj(pSub);
       taosRUnLockLatch(&pSub->lock);
-      mInfo("topic:%s has %d consumers sub till now", pRebInfo->key, rebInput.oldConsumerNum);
+
+      mInfo("sub topic:%s has %d consumers sub till now", pRebInfo->key, rebInput.oldConsumerNum);
       mndReleaseSubscribe(pMnode, pSub);
     }
 
@@ -675,13 +679,11 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) {
     }
 
     taosArrayDestroy(rebOutput.newConsumers);
-    taosArrayDestroy(rebOutput.touchedConsumers);
+    taosArrayDestroy(rebOutput.modifyConsumers);
     taosArrayDestroy(rebOutput.removedConsumers);
     taosArrayDestroy(rebOutput.rebVgs);
     tDeleteSubscribeObj(rebOutput.pSub);
     taosMemoryFree(rebOutput.pSub);
-
-    rebalanceOnce = true;
   }
 
   // reset flag
diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c
index f6e5895cda..3da594109a 100644
--- a/source/dnode/mnode/impl/src/mndUser.c
+++ b/source/dnode/mnode/impl/src/mndUser.c
@@ -237,7 +237,7 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
     SDB_SET_BINARY(pRaw, dataPos, key, keyLen, _OVER);
 
     SDB_SET_INT32(pRaw, dataPos, *useDb, _OVER)
-    useDb = taosHashIterate(pUser->writeTbs, useDb);
+    useDb = taosHashIterate(pUser->useDbs, useDb);
   }
 
   SDB_SET_RESERVE(pRaw, dataPos, USER_RESERVE_SIZE, _OVER)
@@ -394,6 +394,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
       SDB_GET_INT32(pRaw, dataPos, &ref, _OVER);
 
       taosHashPut(pUser->useDbs, key, keyLen, &ref, sizeof(ref));
+      taosMemoryFree(key);
     }
   }
 
@@ -965,6 +966,7 @@ _OVER:
     mError("user:%s, failed to alter since %s", alterReq.user, terrstr());
   }
 
+  tFreeSAlterUserReq(&alterReq);
   mndReleaseUser(pMnode, pOperUser);
   mndReleaseUser(pMnode, pUser);
   mndUserFreeObj(&newUser);
diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c
index 2afae04551..a8e9db28e9 100644
--- a/source/dnode/mnode/impl/src/mndVgroup.c
+++ b/source/dnode/mnode/impl/src/mndVgroup.c
@@ -298,7 +298,7 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg
     }
 
     if(pVgroup->vnodeGid[v].nodeRole == TAOS_SYNC_ROLE_VOTER){
-      createReq.replica++; 
+      createReq.replica++;
     }
     else{
       createReq.learnerReplica++;
@@ -310,14 +310,14 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg
     return NULL;
   }
 
-  mInfo("vgId:%d, build create vnode req, replica:%d selfIndex:%d learnerReplica:%d learnerSelfIndex:%d strict:%d", 
+  mInfo("vgId:%d, build create vnode req, replica:%d selfIndex:%d learnerReplica:%d learnerSelfIndex:%d strict:%d",
                           createReq.vgId, createReq.replica, createReq.selfIndex, createReq.learnerReplica,
                           createReq.learnerReplica, createReq.strict);
   for (int32_t i = 0; i < createReq.replica; ++i) {
     mInfo("vgId:%d, replica:%d ep:%s:%u", createReq.vgId, i, createReq.replicas[i].fqdn, createReq.replicas[i].port);
   }
   for (int32_t i = 0; i < createReq.learnerReplica; ++i) {
-    mInfo("vgId:%d, replica:%d ep:%s:%u", createReq.vgId, i, createReq.learnerReplicas[i].fqdn, 
+    mInfo("vgId:%d, replica:%d ep:%s:%u", createReq.vgId, i, createReq.learnerReplicas[i].fqdn,
                                                                 createReq.learnerReplicas[i].port);
   }
 
@@ -397,13 +397,13 @@ static void *mndBuildAlterVnodeReplicaReq(SMnode *pMnode, SDbObj *pDb, SVgObj *p
 
     if(pVgroup->vnodeGid[v].nodeRole == TAOS_SYNC_ROLE_VOTER){
       pReplica = &alterReq.replicas[alterReq.replica];
-      alterReq.replica++; 
+      alterReq.replica++;
     }
     else{
       pReplica = &alterReq.learnerReplicas[alterReq.learnerReplica];
       alterReq.learnerReplica++;
     }
-    
+
     SVnodeGid *pVgid = &pVgroup->vnodeGid[v];
     SDnodeObj *pVgidDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
     if (pVgidDnode == NULL) return NULL;
@@ -425,14 +425,14 @@ static void *mndBuildAlterVnodeReplicaReq(SMnode *pMnode, SDbObj *pDb, SVgObj *p
     }
   }
 
-  mInfo("vgId:%d, build alter vnode req, replica:%d selfIndex:%d learnerReplica:%d learnerSelfIndex:%d strict:%d", 
-                    alterReq.vgId, alterReq.replica, alterReq.selfIndex, alterReq.learnerReplica, 
+  mInfo("vgId:%d, build alter vnode req, replica:%d selfIndex:%d learnerReplica:%d learnerSelfIndex:%d strict:%d",
+                    alterReq.vgId, alterReq.replica, alterReq.selfIndex, alterReq.learnerReplica,
                                                       alterReq.learnerSelfIndex, alterReq.strict);
   for (int32_t i = 0; i < alterReq.replica; ++i) {
     mInfo("vgId:%d, replica:%d ep:%s:%u", alterReq.vgId, i, alterReq.replicas[i].fqdn, alterReq.replicas[i].port);
   }
   for (int32_t i = 0; i < alterReq.learnerReplica; ++i) {
-    mInfo("vgId:%d, learnerReplica:%d ep:%s:%u", alterReq.vgId, i, 
+    mInfo("vgId:%d, learnerReplica:%d ep:%s:%u", alterReq.vgId, i,
                 alterReq.learnerReplicas[i].fqdn, alterReq.learnerReplicas[i].port);
   }
 
@@ -1296,7 +1296,7 @@ int32_t mndAddAlterVnodeTypeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb,
   return 0;
 }
 
-int32_t mndRestoreAddAlterVnodeTypeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, 
+int32_t mndRestoreAddAlterVnodeTypeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup,
                                           SDnodeObj *pDnode) {
   STransAction action = {0};
   action.epSet = mndGetDnodeEpset(pDnode);
@@ -2023,7 +2023,7 @@ int32_t mndAddVgroupBalanceToTrans(SMnode *pMnode, SVgObj *pVgroup, STrans *pTra
   }
   else
   {
-    mInfo("trans:%d, vgid:%d cant be balanced to dnode:%d, exist:%d, online:%d", 
+    mInfo("trans:%d, vgid:%d cant be balanced to dnode:%d, exist:%d, online:%d",
                               pTrans->id, vgid, dnodeId, exist, online);
   }
 
@@ -2158,7 +2158,7 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
   return 0;
 }
 
-int32_t mndBuildRestoreAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *db, SVgObj *pVgroup, 
+int32_t mndBuildRestoreAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *db, SVgObj *pVgroup,
                                         SDnodeObj *pDnode) {
   SVgObj newVgroup = {0};
   memcpy(&newVgroup, pVgroup, sizeof(SVgObj));
@@ -2169,7 +2169,7 @@ int32_t mndBuildRestoreAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj
   if(newVgroup.replica == 1){
     int selected = 0;
     for(int i = 0; i < newVgroup.replica; i++){
-      newVgroup.vnodeGid[i].nodeRole = TAOS_SYNC_ROLE_VOTER; 
+      newVgroup.vnodeGid[i].nodeRole = TAOS_SYNC_ROLE_VOTER;
       if(newVgroup.vnodeGid[i].dnodeId == pDnode->id){
         selected = i;
       }
@@ -2183,12 +2183,12 @@ int32_t mndBuildRestoreAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj
       }
       else{
         newVgroup.vnodeGid[i].nodeRole = TAOS_SYNC_ROLE_VOTER;
-      }  
+      }
     }
     if (mndRestoreAddCreateVnodeAction(pMnode, pTrans, db, &newVgroup, pDnode) != 0) return -1;
 
     for(int i = 0; i < newVgroup.replica; i++){
-      newVgroup.vnodeGid[i].nodeRole = TAOS_SYNC_ROLE_VOTER; 
+      newVgroup.vnodeGid[i].nodeRole = TAOS_SYNC_ROLE_VOTER;
     if(newVgroup.vnodeGid[i].dnodeId == pDnode->id){
       }
     }
@@ -2531,11 +2531,11 @@ _OVER:
 
 bool mndVgroupInDb(SVgObj *pVgroup, int64_t dbUid) { return !pVgroup->isTsma && pVgroup->dbUid == dbUid; }
 
-bool mndVgroupInDnode(SVgObj *pVgroup, int32_t dnodeId) { 
+bool mndVgroupInDnode(SVgObj *pVgroup, int32_t dnodeId) {
   for(int i = 0; i < pVgroup->replica; i++){
     if(pVgroup->vnodeGid[i].dnodeId == dnodeId) return true;
   }
-  return false; 
+  return false;
 }
 
 static void *mndBuildCompactVnodeReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen, int64_t compactTs,
diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c
index 569c78a68c..f1cee6395b 100644
--- a/source/dnode/mnode/sdb/src/sdbHash.c
+++ b/source/dnode/mnode/sdb/src/sdbHash.c
@@ -196,13 +196,13 @@ static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *
   SSdbRow *pOldRow = *ppOldRow;
   pOldRow->status = pRaw->status;
   sdbPrintOper(pSdb, pOldRow, "update");
-  sdbUnLock(pSdb, type);
 
   int32_t     code = 0;
   SdbUpdateFp updateFp = pSdb->updateFps[type];
   if (updateFp != NULL) {
     code = (*updateFp)(pSdb, pOldRow->pObj, pNewRow->pObj);
   }
+  sdbUnLock(pSdb, type);
 
   // sdbUnLock(pSdb, type);
   sdbFreeRow(pSdb, pNewRow, false);
diff --git a/source/dnode/snode/src/snode.c b/source/dnode/snode/src/snode.c
index cefc4fa63e..7352bbc0fe 100644
--- a/source/dnode/snode/src/snode.c
+++ b/source/dnode/snode/src/snode.c
@@ -153,11 +153,15 @@ int32_t sndProcessTaskDeployReq(SSnode *pSnode, char *msg, int32_t msgLen) {
   ASSERT(pTask->taskLevel == TASK_LEVEL__AGG);
 
   // 2.save task
+  taosWLockLatch(&pSnode->pMeta->lock);
   code = streamMetaAddDeployedTask(pSnode->pMeta, -1, pTask);
   if (code < 0) {
+    taosWUnLockLatch(&pSnode->pMeta->lock);
     return -1;
   }
 
+  taosWUnLockLatch(&pSnode->pMeta->lock);
+
   // 3.go through recover steps to fill history
   if (pTask->fillHistory) {
     streamSetParamForRecover(pTask);
diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h
index 34536d453c..cc9c4b96dc 100644
--- a/source/dnode/vnode/inc/vnode.h
+++ b/source/dnode/vnode/inc/vnode.h
@@ -164,7 +164,6 @@ int32_t     metaTbCursorPrev(SMTbCursor *pTbCur, ETableType jumpTableType);
 #endif
 
 // tsdb
-// typedef struct STsdb STsdb;
 typedef struct STsdbReader STsdbReader;
 
 #define TSDB_DEFAULT_STT_FILE  8
@@ -193,7 +192,10 @@ int32_t      tsdbGetFileBlocksDistInfo(STsdbReader *pReader, STableBlockDistInfo
 int64_t      tsdbGetNumOfRowsInMemTable(STsdbReader *pHandle);
 void        *tsdbGetIdx(SMeta *pMeta);
 void        *tsdbGetIvtIdx(SMeta *pMeta);
-uint64_t     getReaderMaxVersion(STsdbReader *pReader);
+uint64_t     tsdbGetReaderMaxVersion(STsdbReader *pReader);
+int32_t      tsdbSetTableList(STsdbReader *pReader, const void *pTableList, int32_t num);
+void         tsdbReaderSetId(STsdbReader *pReader, const char *idstr);
+void         tsdbReaderSetCloseFlag(STsdbReader *pReader);
 
 int32_t tsdbCacherowsReaderOpen(void *pVnode, int32_t type, void *pTableIdList, int32_t numOfTables, int32_t numOfCols,
                                 SArray *pCidList, int32_t *pSlotIds, uint64_t suid, void **pReader, const char *idstr);
@@ -235,26 +237,22 @@ typedef struct SSnapContext {
 } SSnapContext;
 
 typedef struct STqReader {
-  SPackedData msg2;
-
-  SSubmitReq2 submit;
-  int32_t     nextBlk;
-
-  int64_t lastBlkUid;
-
-  SWalReader *pWalReader;
-
-  SMeta    *pVnodeMeta;
-  SHashObj *tbIdHash;
-  SArray   *pColIdList;  // SArray
-
+  SPackedData     msg;
+  SSubmitReq2     submit;
+  int32_t         nextBlk;
+  int64_t         lastBlkUid;
+  SWalReader     *pWalReader;
+  SMeta          *pVnodeMeta;
+  SHashObj       *tbIdHash;
+  SArray         *pColIdList;  // SArray
   int32_t         cachedSchemaVer;
   int64_t         cachedSchemaSuid;
+  int64_t         cachedSchemaUid;
   SSchemaWrapper *pSchemaWrapper;
-  STSchema       *pSchema;
+  SSDataBlock    *pResBlock;
 } STqReader;
 
-STqReader *tqOpenReader(SVnode *pVnode);
+STqReader *tqReaderOpen(SVnode *pVnode);
 void       tqCloseReader(STqReader *);
 
 void    tqReaderSetColIdList(STqReader *pReader, SArray *pColIdList);
@@ -263,17 +261,14 @@ int32_t tqReaderAddTbUidList(STqReader *pReader, const SArray *pTableUidList);
 int32_t tqReaderRemoveTbUidList(STqReader *pReader, const SArray *tbUidList);
 
 int32_t tqSeekVer(STqReader *pReader, int64_t ver, const char *id);
-void    tqNextBlock(STqReader *pReader, SFetchRet *ret);
-int32_t extractSubmitMsgFromWal(SWalReader *pReader, SPackedData *pPackedData);
+int32_t tqNextBlockInWal(STqReader* pReader);
+bool    tqNextBlockImpl(STqReader *pReader);
 
+int32_t extractSubmitMsgFromWal(SWalReader *pReader, SPackedData *pPackedData);
 int32_t tqReaderSetSubmitMsg(STqReader *pReader, void *msgStr, int32_t msgLen, int64_t ver);
-// int32_t tqReaderSetDataMsg(STqReader *pReader, const SSubmitReq *pMsg, int64_t ver);
-bool    tqNextDataBlock(STqReader *pReader);
-bool    tqNextDataBlockFilterOut2(STqReader *pReader, SHashObj *filterOutUids);
-int32_t tqRetrieveDataBlock2(SSDataBlock *pBlock, STqReader *pReader, SSubmitTbData **pSubmitTbDataRet);
-int32_t tqRetrieveTaosxBlock2(STqReader *pReader, SArray *blocks, SArray *schemas, SSubmitTbData **pSubmitTbDataRet);
-// int32_t tqRetrieveDataBlock(SSDataBlock *pBlock, STqReader *pReader);
-// int32_t tqRetrieveTaosxBlock(STqReader *pReader, SArray *blocks, SArray *schemas);
+bool    tqNextDataBlockFilterOut(STqReader *pReader, SHashObj *filterOutUids);
+int32_t tqRetrieveDataBlock(STqReader *pReader, SSubmitTbData **pSubmitTbDataRet);
+int32_t tqRetrieveTaosxBlock(STqReader *pReader, SArray *blocks, SArray *schemas, SSubmitTbData **pSubmitTbDataRet);
 
 int32_t vnodeEnqueueStreamMsg(SVnode *pVnode, SRpcMsg *pMsg);
 
diff --git a/source/dnode/vnode/src/inc/tq.h b/source/dnode/vnode/src/inc/tq.h
index 142a1f6fb3..b74d866863 100644
--- a/source/dnode/vnode/src/inc/tq.h
+++ b/source/dnode/vnode/src/inc/tq.h
@@ -100,21 +100,17 @@ typedef struct {
   SWalRef*      pRef;
   STqPushHandle pushHandle;    // push
   STqExecHandle execHandle;    // exec
+  SRpcMsg*      msg;
+  int32_t       noDataPollCnt;
+  int8_t        exec;
 } STqHandle;
 
-typedef struct {
-  SMqDataRsp*    pDataRsp;
-  char           subKey[TSDB_SUBSCRIBE_KEY_LEN];
-  SRpcHandleInfo info;
-  STqHandle*     pHandle;
-} STqPushEntry;
-
 struct STQ {
   SVnode*         pVnode;
   char*           path;
   int64_t         walLogLastVer;
   SRWLatch        lock;
-  SHashObj*       pPushMgr;    // consumerId -> STqPushEntry
+  SHashObj*       pPushMgr;    // subKey -> STqHandle
   SHashObj*       pHandle;     // subKey -> STqHandle
   SHashObj*       pCheckInfo;  // topic -> SAlterCheckInfo
   STqOffsetStore* pOffsetStore;
@@ -146,9 +142,9 @@ int32_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHea
 // tqExec
 int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, STaosxRsp* pRsp, int32_t* totalRows);
 int32_t tqAddBlockDataToRsp(const SSDataBlock* pBlock, SMqDataRsp* pRsp, int32_t numOfCols, int8_t precision);
-int32_t tqSendDataRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqDataRsp* pRsp,
-                      int32_t type, int32_t vgId);
-int32_t tqPushDataRsp(STqPushEntry* pPushEntry, int32_t vgId);
+int32_t tqSendDataRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqDataRsp* pRsp, int32_t type,
+                      int32_t vgId);
+int32_t tqPushDataRsp(STqHandle* pHandle, int32_t vgId);
 
 // tqMeta
 int32_t tqMetaOpen(STQ* pTq);
@@ -182,17 +178,12 @@ int32_t tqStreamTasksScanWal(STQ* pTq);
 
 // tq util
 char*   createStreamTaskIdStr(int64_t streamId, int32_t taskId);
-void    createStreamTaskOffsetKey(char* dst, uint64_t streamId, uint32_t taskId);
 int32_t tqAddInputBlockNLaunchTask(SStreamTask* pTask, SStreamQueueItem* pQueueItem, int64_t ver);
 int32_t tqExtractDataForMq(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest, SRpcMsg* pMsg);
 int32_t tqDoSendDataRsp(const SRpcHandleInfo* pRpcHandleInfo, const SMqDataRsp* pRsp, int32_t epoch, int64_t consumerId,
-                      int32_t type, int64_t sver, int64_t ever);
-
+                        int32_t type, int64_t sver, int64_t ever);
 int32_t tqInitDataRsp(SMqDataRsp* pRsp, const SMqPollReq* pReq);
-void    doSaveTaskOffset(STqOffsetStore* pOffsetStore, const char* pKey, int64_t ver);
-void    saveOffsetForAllTasks(STQ* pTq, int64_t ver);
-void    initOffsetForAllRestoreTasks(STQ* pTq);
-
+bool    tqIsHandleExecuting(STqHandle* pHandle);
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h
index 95bce32196..b2bc9abf33 100644
--- a/source/dnode/vnode/src/inc/tsdb.h
+++ b/source/dnode/vnode/src/inc/tsdb.h
@@ -16,6 +16,7 @@
 #ifndef _TD_VNODE_TSDB_H_
 #define _TD_VNODE_TSDB_H_
 
+#include "tsimplehash.h"
 #include "vnodeInt.h"
 
 #ifdef __cplusplus
@@ -122,14 +123,14 @@ int32_t tsdbRowCmprFn(const void *p1, const void *p2);
 int32_t  tsdbRowIterOpen(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema);
 void     tsdbRowClose(STSDBRowIter *pIter);
 SColVal *tsdbRowIterNext(STSDBRowIter *pIter);
-// SRowMerger
-int32_t tsdbRowMergerInit(SRowMerger *pMerger, STSchema *pResTSchema, TSDBROW *pRow, STSchema *pTSchema);
-int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
 
-// int32_t tsdbRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
-void tsdbRowMergerClear(SRowMerger *pMerger);
-// int32_t tsdbRowMerge(SRowMerger *pMerger, TSDBROW *pRow);
+// SRowMerger
+int32_t tsdbRowMergerInit(SRowMerger *pMerger, STSchema *pSchema);
+int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema);
 int32_t tsdbRowMergerGetRow(SRowMerger *pMerger, SRow **ppRow);
+void    tsdbRowMergerClear(SRowMerger *pMerger);
+void    tsdbRowMergerCleanup(SRowMerger *pMerger);
+
 // TABLEID
 int32_t tTABLEIDCmprFn(const void *p1, const void *p2);
 // TSDBKEY
@@ -224,7 +225,7 @@ int32_t tsdbTbDataIterCreate(STbData *pTbData, TSDBKEY *pFrom, int8_t backward,
 void   *tsdbTbDataIterDestroy(STbDataIter *pIter);
 void    tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter *pIter);
 bool    tsdbTbDataIterNext(STbDataIter *pIter);
-void    tsdbMemTableCountRows(SMemTable *pMemTable, SHashObj *pTableMap, int64_t *rowsNum);
+void    tsdbMemTableCountRows(SMemTable *pMemTable, SSHashObj *pTableMap, int64_t *rowsNum);
 
 // STbData
 int32_t tsdbGetNRowsInTbData(STbData *pTbData);
@@ -322,8 +323,9 @@ int32_t tGnrtDiskData(SDiskDataBuilder *pBuilder, const SDiskData **ppDiskData,
 #define TSDB_STT_FILE_DATA_ITER  2
 #define TSDB_TOMB_FILE_DATA_ITER 3
 
-#define TSDB_FILTER_FLAG_BY_VERSION 0x1
-#define TSDB_FILTER_FLAG_BY_TABLEID 0x2
+#define TSDB_FILTER_FLAG_BY_VERSION           0x1
+#define TSDB_FILTER_FLAG_BY_TABLEID           0x2
+#define TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE 0x4
 
 #define TSDB_RBTN_TO_DATA_ITER(pNode) ((STsdbDataIter2 *)(((char *)pNode) - offsetof(STsdbDataIter2, rbtn)))
 /* open */
@@ -716,7 +718,6 @@ typedef struct SSttBlockLoadInfo {
 typedef struct SMergeTree {
   int8_t             backward;
   SRBTree            rbt;
-  SArray            *pIterList;
   SLDataIter        *pIter;
   bool               destroyLoadInfo;
   SSttBlockLoadInfo *pLoadInfo;
@@ -762,13 +763,29 @@ struct SDiskDataBuilder {
   SBlkInfo     bi;
 };
 
+typedef struct SLDataIter {
+  SRBTreeNode        node;
+  SSttBlk           *pSttBlk;
+  SDataFReader      *pReader;
+  int32_t            iStt;
+  int8_t             backward;
+  int32_t            iSttBlk;
+  int32_t            iRow;
+  SRowInfo           rInfo;
+  uint64_t           uid;
+  STimeWindow        timeWindow;
+  SVersionRange      verRange;
+  SSttBlockLoadInfo *pBlockLoadInfo;
+  bool               ignoreEarlierTs;
+} SLDataIter;
+
+#define tMergeTreeGetRow(_t) (&((_t)->pIter->rInfo.row))
 int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFReader, uint64_t suid, uint64_t uid,
                        STimeWindow *pTimeWindow, SVersionRange *pVerRange, SSttBlockLoadInfo *pBlockLoadInfo,
-                       bool destroyLoadInfo, const char *idStr, bool strictTimeRange);
+                       bool destroyLoadInfo, const char *idStr, bool strictTimeRange, SLDataIter* pLDataIter);
 void    tMergeTreeAddIter(SMergeTree *pMTree, SLDataIter *pIter);
 bool    tMergeTreeNext(SMergeTree *pMTree);
 bool    tMergeTreeIgnoreEarlierTs(SMergeTree *pMTree);
-TSDBROW tMergeTreeGetRow(SMergeTree *pMTree);
 void    tMergeTreeClose(SMergeTree *pMTree);
 
 SSttBlockLoadInfo *tCreateLastBlockLoadInfo(STSchema *pSchema, int16_t *colList, int32_t numOfCols, int32_t numOfStt);
@@ -795,6 +812,7 @@ typedef struct SCacheRowsReader {
   STableKeyInfo     *pTableList;  // table id list
   int32_t            numOfTables;
   SSttBlockLoadInfo *pLoadInfo;
+  SLDataIter        *pDataIter;
   STsdbReadSnap     *pReadSnap;
   SDataFReader      *pDataFReader;
   SDataFReader      *pDataFReaderLast;
diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h
index 94e5f253bf..fb0334263e 100644
--- a/source/dnode/vnode/src/inc/vnodeInt.h
+++ b/source/dnode/vnode/src/inc/vnodeInt.h
@@ -192,12 +192,12 @@ int32_t tsdbSetKeepCfg(STsdb* pTsdb, STsdbCfg* pCfg);
 int  tqInit();
 void tqCleanUp();
 STQ* tqOpen(const char* path, SVnode* pVnode);
+void tqNotifyClose(STQ*);
 void tqClose(STQ*);
 int  tqPushMsg(STQ*, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver);
-int  tqRegisterPushHandle(STQ* pTq, void* pHandle, const SMqPollReq* pRequest, SRpcMsg* pRpcMsg, SMqDataRsp* pDataRsp,
-                          int32_t type);
-int  tqUnregisterPushHandle(STQ* pTq, const char* pKey, int32_t keyLen, uint64_t consumerId, bool rspConsumer);
-int  tqStartStreamTasks(STQ* pTq);  // restore all stream tasks after vnode launching completed.
+int  tqRegisterPushHandle(STQ* pTq, void* handle, SRpcMsg* pMsg);
+int  tqUnregisterPushHandle(STQ* pTq, void* pHandle);
+int  tqStartStreamTasks(STQ* pTq);    // restore all stream tasks after vnode launching completed.
 
 int     tqCommit(STQ*);
 int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd);
@@ -217,7 +217,7 @@ int32_t tqProcessTaskDeployReq(STQ* pTq, int64_t version, char* msg, int32_t msg
 int32_t tqProcessTaskDropReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
 int32_t tqProcessStreamTaskCheckReq(STQ* pTq, SRpcMsg* pMsg);
 int32_t tqProcessStreamTaskCheckRsp(STQ* pTq, int64_t version, char* msg, int32_t msgLen);
-int32_t tqProcessSubmitReq(STQ* pTq, SPackedData submit);
+int32_t tqProcessSubmitReqForSubscribe(STQ* pTq);
 int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver);
 int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg);
 int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg, bool exec);
diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c
index 2359a165b7..d464f64de3 100644
--- a/source/dnode/vnode/src/meta/metaQuery.c
+++ b/source/dnode/vnode/src/meta/metaQuery.c
@@ -639,7 +639,6 @@ tb_uid_t metaStbCursorNext(SMStbCursor *pStbCur) {
 STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, int lock) {
   STSchema       *pTSchema = NULL;
   SSchemaWrapper *pSW = NULL;
-  SSchema        *pSchema = NULL;
 
   pSW = metaGetTableSchema(pMeta, uid, sver, lock);
   if (!pSW) return NULL;
diff --git a/source/dnode/vnode/src/meta/metaSnapshot.c b/source/dnode/vnode/src/meta/metaSnapshot.c
index 0126d29cc9..707dd66e30 100644
--- a/source/dnode/vnode/src/meta/metaSnapshot.c
+++ b/source/dnode/vnode/src/meta/metaSnapshot.c
@@ -187,23 +187,24 @@ _err:
 
 int32_t metaSnapWrite(SMetaSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
   int32_t    code = 0;
+  int32_t    line = 0;
   SMeta*     pMeta = pWriter->pMeta;
   SMetaEntry metaEntry = {0};
   SDecoder*  pDecoder = &(SDecoder){0};
 
   tDecoderInit(pDecoder, pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr));
   code = metaDecodeEntry(pDecoder, &metaEntry);
-  if (code) goto _err;
+  VND_CHECK_CODE(code, line, _err);
 
   code = metaHandleEntry(pMeta, &metaEntry);
-  if (code) goto _err;
+  VND_CHECK_CODE(code, line, _err);
 
   tDecoderClear(pDecoder);
   return code;
 
 _err:
   tDecoderClear(pDecoder);
-  metaError("vgId:%d, vnode snapshot meta write failed since %s", TD_VID(pMeta->pVnode), tstrerror(code));
+  metaError("vgId:%d, vnode snapshot meta write failed since %s at line:%d", TD_VID(pMeta->pVnode), terrstr(), line);
   return code;
 }
 
@@ -216,8 +217,8 @@ typedef struct STableInfoForChildTable {
 static void destroySTableInfoForChildTable(void* data) {
   STableInfoForChildTable* pData = (STableInfoForChildTable*)data;
   taosMemoryFree(pData->tableName);
-  tDeleteSSchemaWrapper(pData->schemaRow);
-  tDeleteSSchemaWrapper(pData->tagRow);
+  tDeleteSchemaWrapper(pData->schemaRow);
+  tDeleteSchemaWrapper(pData->tagRow);
 }
 
 static void MoveToSnapShotVersion(SSnapContext* ctx) {
diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c
index 3325f4055c..83f2ece571 100644
--- a/source/dnode/vnode/src/meta/metaTable.c
+++ b/source/dnode/vnode/src/meta/metaTable.c
@@ -673,8 +673,8 @@ int metaDropIndexFromSTable(SMeta *pMeta, int64_t version, SDropIndexReq *pReq)
   metaUpdateUidIdx(pMeta, &nStbEntry);
   metaULock(pMeta);
 
-  tDeleteSSchemaWrapper(tag);
-  tDeleteSSchemaWrapper(row);
+  tDeleteSchemaWrapper(tag);
+  tDeleteSchemaWrapper(row);
 
   if (oStbEntry.pBuf) taosMemoryFree(oStbEntry.pBuf);
   tDecoderClear(&dc);
@@ -936,8 +936,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
     int   tLen = 0;
 
     if (tdbTbGet(pMeta->pUidIdx, &e.ctbEntry.suid, sizeof(tb_uid_t), &tData, &tLen) == 0) {
-      version = ((SUidIdxVal *)tData)[0].version;
-      STbDbKey tbDbKey = {.uid = e.ctbEntry.suid, .version = version};
+      STbDbKey tbDbKey = {.uid = e.ctbEntry.suid, .version = ((SUidIdxVal *)tData)[0].version};
       if (tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &tData, &tLen) == 0) {
         SDecoder   tdc = {0};
         SMetaEntry stbEntry = {0};
@@ -1029,7 +1028,7 @@ int metaUpdateCtimeIdx(SMeta *pMeta, const SMetaEntry *pME) {
   metaTrace("vgId:%d, start to save version:%" PRId64 " uid:%" PRId64 " ctime:%" PRId64, TD_VID(pMeta->pVnode),
             pME->version, pME->uid, ctimeKey.ctime);
 
-  return tdbTbInsert(pMeta->pCtimeIdx, &ctimeKey, sizeof(ctimeKey), NULL, 0, pMeta->txn);
+  return tdbTbUpsert(pMeta->pCtimeIdx, &ctimeKey, sizeof(ctimeKey), NULL, 0, pMeta->txn);
 }
 
 int metaDeleteCtimeIdx(SMeta *pMeta, const SMetaEntry *pME) {
@@ -1044,7 +1043,7 @@ int metaUpdateNcolIdx(SMeta *pMeta, const SMetaEntry *pME) {
   if (metaBuildNColIdxKey(&ncolKey, pME) < 0) {
     return 0;
   }
-  return tdbTbInsert(pMeta->pNcolIdx, &ncolKey, sizeof(ncolKey), NULL, 0, pMeta->txn);
+  return tdbTbUpsert(pMeta->pNcolIdx, &ncolKey, sizeof(ncolKey), NULL, 0, pMeta->txn);
 }
 
 int metaDeleteNcolIdx(SMeta *pMeta, const SMetaEntry *pME) {
@@ -1878,24 +1877,24 @@ static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME) {
 }
 
 static int metaUpdateSuidIdx(SMeta *pMeta, const SMetaEntry *pME) {
-  return tdbTbInsert(pMeta->pSuidIdx, &pME->uid, sizeof(tb_uid_t), NULL, 0, pMeta->txn);
+  return tdbTbUpsert(pMeta->pSuidIdx, &pME->uid, sizeof(tb_uid_t), NULL, 0, pMeta->txn);
 }
 
 static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME) {
-  return tdbTbInsert(pMeta->pNameIdx, pME->name, strlen(pME->name) + 1, &pME->uid, sizeof(tb_uid_t), pMeta->txn);
+  return tdbTbUpsert(pMeta->pNameIdx, pME->name, strlen(pME->name) + 1, &pME->uid, sizeof(tb_uid_t), pMeta->txn);
 }
 
 static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
   STtlIdxKey ttlKey = {0};
   metaBuildTtlIdxKey(&ttlKey, pME);
   if (ttlKey.dtime == 0) return 0;
-  return tdbTbInsert(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, pMeta->txn);
+  return tdbTbUpsert(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, pMeta->txn);
 }
 
 static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME) {
   SCtbIdxKey ctbIdxKey = {.suid = pME->ctbEntry.suid, .uid = pME->uid};
 
-  return tdbTbInsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), pME->ctbEntry.pTags,
+  return tdbTbUpsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), pME->ctbEntry.pTags,
                      ((STag *)(pME->ctbEntry.pTags))->len, pMeta->txn);
 }
 
@@ -2065,49 +2064,66 @@ _exit:
 }
 
 int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME) {
+  int32_t code = 0;
+  int32_t line = 0;
   metaWLock(pMeta);
 
   // save to table.db
-  if (metaSaveToTbDb(pMeta, pME) < 0) goto _err;
+  code = metaSaveToTbDb(pMeta, pME);
+  VND_CHECK_CODE(code, line, _err);
 
   // update uid.idx
-  if (metaUpdateUidIdx(pMeta, pME) < 0) goto _err;
+  code = metaUpdateUidIdx(pMeta, pME);
+  VND_CHECK_CODE(code, line, _err);
 
   // update name.idx
-  if (metaUpdateNameIdx(pMeta, pME) < 0) goto _err;
+  code = metaUpdateNameIdx(pMeta, pME);
+  VND_CHECK_CODE(code, line, _err);
 
   if (pME->type == TSDB_CHILD_TABLE) {
     // update ctb.idx
-    if (metaUpdateCtbIdx(pMeta, pME) < 0) goto _err;
+    code = metaUpdateCtbIdx(pMeta, pME);
+    VND_CHECK_CODE(code, line, _err);
 
     // update tag.idx
-    if (metaUpdateTagIdx(pMeta, pME) < 0) goto _err;
+    code = metaUpdateTagIdx(pMeta, pME);
+    VND_CHECK_CODE(code, line, _err);
   } else {
     // update schema.db
-    if (metaSaveToSkmDb(pMeta, pME) < 0) goto _err;
+    code = metaSaveToSkmDb(pMeta, pME);
+    VND_CHECK_CODE(code, line, _err);
 
     if (pME->type == TSDB_SUPER_TABLE) {
-      if (metaUpdateSuidIdx(pMeta, pME) < 0) goto _err;
+      code = metaUpdateSuidIdx(pMeta, pME);
+      VND_CHECK_CODE(code, line, _err);
     }
   }
 
-  if (metaUpdateCtimeIdx(pMeta, pME) < 0) goto _err;
+  code = metaUpdateCtimeIdx(pMeta, pME);
+  VND_CHECK_CODE(code, line, _err);
 
   if (pME->type == TSDB_NORMAL_TABLE) {
-    if (metaUpdateNcolIdx(pMeta, pME) < 0) goto _err;
+    code = metaUpdateNcolIdx(pMeta, pME);
+    VND_CHECK_CODE(code, line, _err);
   }
 
   if (pME->type != TSDB_SUPER_TABLE) {
-    if (metaUpdateTtlIdx(pMeta, pME) < 0) goto _err;
+    code = metaUpdateTtlIdx(pMeta, pME);
+    VND_CHECK_CODE(code, line, _err);
   }
 
   metaULock(pMeta);
+  metaDebug("vgId:%d, handle meta entry, ver:%" PRId64 ", uid:%" PRId64 ", name:%s", TD_VID(pMeta->pVnode),
+            pME->version, pME->uid, pME->name);
   return 0;
 
 _err:
   metaULock(pMeta);
+  metaError("vgId:%d, failed to handle meta entry since %s at line:%d, ver:%" PRId64 ", uid:%" PRId64 ", name:%s",
+            TD_VID(pMeta->pVnode), terrstr(), line, pME->version, pME->uid, pME->name);
   return -1;
 }
+
 // refactor later
 void *metaGetIdx(SMeta *pMeta) { return pMeta->pTagIdx; }
 void *metaGetIvtIdx(SMeta *pMeta) { return pMeta->pTagIvtIdx; }
diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c
index ce987ca88e..20e04f122b 100644
--- a/source/dnode/vnode/src/sma/smaRollup.c
+++ b/source/dnode/vnode/src/sma/smaRollup.c
@@ -684,7 +684,7 @@ static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSma
       }
 
       if (pReq && tdProcessSubmitReq(sinkTsdb, output->info.version, pReq) < 0) {
-        tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
+        tDestroySubmitReq(pReq, TSDB_MSG_FLG_ENCODE);
         taosMemoryFree(pReq);
         smaError("vgId:%d, process submit req for rsma suid:%" PRIu64 ", uid:%" PRIu64 " level %" PRIi8
                  " failed since %s",
@@ -696,7 +696,7 @@ static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSma
                SMA_VID(pSma), suid, output->info.id.groupId, pItem->level, output->info.version);
 
       if (pReq) {
-        tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
+        tDestroySubmitReq(pReq, TSDB_MSG_FLG_ENCODE);
         taosMemoryFree(pReq);
       }
     }
diff --git a/source/dnode/vnode/src/sma/smaTimeRange.c b/source/dnode/vnode/src/sma/smaTimeRange.c
index 5058a7fc76..6a4bddc991 100644
--- a/source/dnode/vnode/src/sma/smaTimeRange.c
+++ b/source/dnode/vnode/src/sma/smaTimeRange.c
@@ -299,7 +299,7 @@ int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *
       }
       SRow *pRow = NULL;
       if ((terrno = tRowBuild(pVals, (STSchema *)pTSchema, &pRow)) < 0) {
-        tDestroySSubmitTbData(&tbData, TSDB_MSG_FLG_ENCODE);
+        tDestroySubmitTbData(&tbData, TSDB_MSG_FLG_ENCODE);
         goto _end;
       }
       taosArrayPush(tbData.aRowP, &pRow);
@@ -309,7 +309,7 @@ int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *
   }
 
   // encode
-  tEncodeSize(tEncodeSSubmitReq2, pReq, len, terrno);
+  tEncodeSize(tEncodeSubmitReq, pReq, len, terrno);
   if (TSDB_CODE_SUCCESS == terrno) {
     SEncoder encoder;
     len += sizeof(SSubmitReq2Msg);
@@ -321,7 +321,7 @@ int32_t smaBlockToSubmit(SVnode *pVnode, const SArray *pBlocks, const STSchema *
     ((SSubmitReq2Msg *)pBuf)->header.contLen = htonl(len);
     ((SSubmitReq2Msg *)pBuf)->version = htobe64(1);
     tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SSubmitReq2Msg)), len - sizeof(SSubmitReq2Msg));
-    if (tEncodeSSubmitReq2(&encoder, pReq) < 0) {
+    if (tEncodeSubmitReq(&encoder, pReq) < 0) {
       terrno = TSDB_CODE_OUT_OF_MEMORY;
       /*vError("failed to encode submit req since %s", terrstr());*/
     }
@@ -332,7 +332,7 @@ _end:
   taosArrayDestroy(tagArray);
   taosArrayDestroy(pVals);
   if (pReq) {
-    tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
+    tDestroySubmitReq(pReq, TSDB_MSG_FLG_ENCODE);
     taosMemoryFree(pReq);
   }
 
diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c
index 1000f82d8f..5874062dff 100644
--- a/source/dnode/vnode/src/tq/tq.c
+++ b/source/dnode/vnode/src/tq/tq.c
@@ -71,18 +71,11 @@ static void destroyTqHandle(void* data) {
     walCloseReader(pData->pWalReader);
     tqCloseReader(pData->execHandle.pTqReader);
   }
-}
-
-static void tqPushEntryFree(void* data) {
-  STqPushEntry* p = *(void**)data;
-  if (p->pDataRsp->head.mqMsgType == TMQ_MSG_TYPE__POLL_RSP) {
-    tDeleteMqDataRsp(p->pDataRsp);
-  } else if (p->pDataRsp->head.mqMsgType == TMQ_MSG_TYPE__TAOSX_RSP) {
-    tDeleteSTaosxRsp((STaosxRsp*)p->pDataRsp);
+  if(pData->msg != NULL) {
+    rpcFreeCont(pData->msg->pCont);
+    taosMemoryFree(pData->msg);
+    pData->msg = NULL;
   }
-
-  taosMemoryFree(p->pDataRsp);
-  taosMemoryFree(p);
 }
 
 static bool tqOffsetLessOrEqual(const STqOffset* pLeft, const STqOffset* pRight) {
@@ -105,14 +98,18 @@ STQ* tqOpen(const char* path, SVnode* pVnode) {
   taosHashSetFreeFp(pTq->pHandle, destroyTqHandle);
 
   taosInitRWLatch(&pTq->lock);
-  pTq->pPushMgr = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
-  taosHashSetFreeFp(pTq->pPushMgr, tqPushEntryFree);
+  pTq->pPushMgr = taosHashInit(64, MurmurHash3_32, false, HASH_NO_LOCK);
 
   pTq->pCheckInfo = taosHashInit(64, MurmurHash3_32, true, HASH_ENTRY_LOCK);
   taosHashSetFreeFp(pTq->pCheckInfo, (FDelete)tDeleteSTqCheckInfo);
 
-  tqInitialize(pTq);
-  return pTq;
+  int32_t code = tqInitialize(pTq);
+  if (code != TSDB_CODE_SUCCESS) {
+    tqClose(pTq);
+    return NULL;
+  } else {
+    return pTq;
+  }
 }
 
 int32_t tqInitialize(STQ* pTq) {
@@ -154,21 +151,96 @@ void tqClose(STQ* pTq) {
   taosMemoryFree(pTq);
 }
 
-int32_t tqPushDataRsp(STqPushEntry* pPushEntry, int32_t vgId) {
-  SMqDataRsp* pRsp = pPushEntry->pDataRsp;
-  SMqRspHead* pHeader = &pPushEntry->pDataRsp->head;
+void tqNotifyClose(STQ* pTq) {
+  if (pTq != NULL) {
+    taosWLockLatch(&pTq->pStreamMeta->lock);
+
+    void* pIter = NULL;
+    while (1) {
+      pIter = taosHashIterate(pTq->pStreamMeta->pTasks, pIter);
+      if (pIter == NULL) {
+        break;
+      }
+
+      SStreamTask* pTask = *(SStreamTask**)pIter;
+      tqDebug("vgId:%d s-task:%s set dropping flag", pTq->pStreamMeta->vgId, pTask->id.idStr);
+      pTask->status.taskStatus = TASK_STATUS__STOP;
+
+      int64_t st = taosGetTimestampMs();
+      qKillTask(pTask->exec.pExecutor, TSDB_CODE_SUCCESS);
+      int64_t el = taosGetTimestampMs() - st;
+      tqDebug("vgId:%d s-task:%s is closed in %" PRId64 "ms", pTq->pStreamMeta->vgId, pTask->id.idStr, el);
+    }
+
+    taosWUnLockLatch(&pTq->pStreamMeta->lock);
+  }
+}
+
+static int32_t doSendDataRsp(const SRpcHandleInfo* pRpcHandleInfo, const SMqDataRsp* pRsp, int32_t epoch,
+                             int64_t consumerId, int32_t type) {
+  int32_t len = 0;
+  int32_t code = 0;
+
+  if (type == TMQ_MSG_TYPE__POLL_RSP) {
+    tEncodeSize(tEncodeMqDataRsp, pRsp, len, code);
+  } else if (type == TMQ_MSG_TYPE__TAOSX_RSP) {
+    tEncodeSize(tEncodeSTaosxRsp, (STaosxRsp*)pRsp, len, code);
+  }
+
+  if (code < 0) {
+    return -1;
+  }
+
+  int32_t tlen = sizeof(SMqRspHead) + len;
+  void*   buf = rpcMallocCont(tlen);
+  if (buf == NULL) {
+    return -1;
+  }
+
+  ((SMqRspHead*)buf)->mqMsgType = type;
+  ((SMqRspHead*)buf)->epoch = epoch;
+  ((SMqRspHead*)buf)->consumerId = consumerId;
+
+  void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
+
+  SEncoder encoder = {0};
+  tEncoderInit(&encoder, abuf, len);
+
+  if (type == TMQ_MSG_TYPE__POLL_RSP) {
+    tEncodeMqDataRsp(&encoder, pRsp);
+  } else if (type == TMQ_MSG_TYPE__TAOSX_RSP) {
+    tEncodeSTaosxRsp(&encoder, (STaosxRsp*)pRsp);
+  }
+
+  tEncoderClear(&encoder);
+
+  SRpcMsg rsp = {
+      .info = *pRpcHandleInfo,
+      .pCont = buf,
+      .contLen = tlen,
+      .code = 0,
+  };
+
+  tmsgSendRsp(&rsp);
+  return 0;
+}
+
+int32_t tqPushDataRsp(STqHandle* pHandle, int32_t vgId) {
+  SMqDataRsp dataRsp = {0};
+  dataRsp.head.consumerId = pHandle->consumerId;
+  dataRsp.head.epoch = pHandle->epoch;
+  dataRsp.head.mqMsgType = TMQ_MSG_TYPE__POLL_RSP;
 
   int64_t sver = 0, ever = 0;
-  walReaderValidVersionRange(pPushEntry->pHandle->execHandle.pTqReader->pWalReader, &sver, &ever);
-
-  tqDoSendDataRsp(&pPushEntry->info, pRsp, pHeader->epoch, pHeader->consumerId, pHeader->mqMsgType, sver, ever);
+  walReaderValidVersionRange(pHandle->execHandle.pTqReader->pWalReader, &sver, &ever);
+  tqDoSendDataRsp(&pHandle->msg->info, &dataRsp, pHandle->epoch, pHandle->consumerId, TMQ_MSG_TYPE__POLL_RSP, sver, ever);
 
   char buf1[80] = {0};
   char buf2[80] = {0};
-  tFormatOffset(buf1, tListLen(buf1), &pRsp->reqOffset);
-  tFormatOffset(buf2, tListLen(buf2), &pRsp->rspOffset);
+  tFormatOffset(buf1, tListLen(buf1), &dataRsp.reqOffset);
+  tFormatOffset(buf2, tListLen(buf2), &dataRsp.rspOffset);
   tqDebug("vgId:%d, from consumer:0x%" PRIx64 " (epoch %d) push rsp, block num: %d, req:%s, rsp:%s",
-          vgId, pRsp->head.consumerId, pRsp->head.epoch, pRsp->blockNum, buf1, buf2);
+          vgId, dataRsp.head.consumerId, dataRsp.head.epoch, dataRsp.blockNum, buf1, buf2);
   return 0;
 }
 
@@ -367,7 +439,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) {
   taosRLockLatch(&pTq->lock);
   if (pHandle->consumerId != consumerId) {
     tqDebug("ERROR tmq poll: consumer:0x%" PRIx64 " vgId:%d, subkey %s, mismatch for saved handle consumer:0x%" PRIx64,
-            consumerId, TD_VID(pTq->pVnode), req.subKey, pHandle->consumerId);
+            consumerId, vgId, req.subKey, pHandle->consumerId);
     terrno = TSDB_CODE_TMQ_CONSUMER_MISMATCH;
     taosRUnLockLatch(&pTq->lock);
     return -1;
@@ -426,6 +498,8 @@ int32_t tqProcessVgWalInfoReq(STQ* pTq, SRpcMsg* pMsg) {
   int64_t sver = 0, ever = 0;
   walReaderValidVersionRange(pHandle->execHandle.pTqReader->pWalReader, &sver, &ever);
 
+  int64_t currentVer = walReaderGetCurrentVer(pHandle->execHandle.pTqReader->pWalReader);
+
   SMqDataRsp dataRsp = {0};
   tqInitDataRsp(&dataRsp, &req);
 
@@ -450,8 +524,10 @@ int32_t tqProcessVgWalInfoReq(STQ* pTq, SRpcMsg* pMsg) {
 
     dataRsp.rspOffset.type = TMQ_OFFSET__LOG;
 
-    if (reqOffset.type == TMQ_OFFSET__RESET_EARLIEAST) {
-      dataRsp.rspOffset.version = sver;
+    if (reqOffset.type == TMQ_OFFSET__LOG) {
+      dataRsp.rspOffset.version = currentVer; // return current consume offset value
+    } else if (reqOffset.type == TMQ_OFFSET__RESET_EARLIEAST) {
+      dataRsp.rspOffset.version = sver;  // not consume yet, set the earliest position
     } else if (reqOffset.type == TMQ_OFFSET__RESET_LATEST) {
       dataRsp.rspOffset.version = ever;
     } else {
@@ -469,15 +545,16 @@ int32_t tqProcessVgWalInfoReq(STQ* pTq, SRpcMsg* pMsg) {
 
 int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t sversion, char* msg, int32_t msgLen) {
   SMqVDeleteReq* pReq = (SMqVDeleteReq*)msg;
+  int32_t vgId = TD_VID(pTq->pVnode);
 
-  tqDebug("vgId:%d, tq process delete sub req %s", pTq->pVnode->config.vgId, pReq->subKey);
-
-  taosWLockLatch(&pTq->lock);
-  int32_t code = taosHashRemove(pTq->pPushMgr, pReq->subKey, strlen(pReq->subKey));
-  if (code != 0) {
-    tqDebug("vgId:%d, tq remove push handle %s", pTq->pVnode->config.vgId, pReq->subKey);
-  }
-  taosWUnLockLatch(&pTq->lock);
+  tqDebug("vgId:%d, tq process delete sub req %s", vgId, pReq->subKey);
+  int32_t code = 0;
+//  taosWLockLatch(&pTq->lock);
+//  int32_t code = taosHashRemove(pTq->pPushMgr, pReq->subKey, strlen(pReq->subKey));
+//  if (code != 0) {
+//    tqDebug("vgId:%d, tq remove push handle %s", pTq->pVnode->config.vgId, pReq->subKey);
+//  }
+//  taosWUnLockLatch(&pTq->lock);
 
   STqHandle* pHandle = taosHashGet(pTq->pHandle, pReq->subKey, strlen(pReq->subKey));
   if (pHandle) {
@@ -485,6 +562,12 @@ int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
     if (pHandle->pRef) {
       walCloseRef(pTq->pVnode->pWal, pHandle->pRef->refId);
     }
+
+    while (tqIsHandleExecuting(pHandle)) {
+      tqDebug("vgId:%d, topic:%s, subscription is executing, wait for 5ms and retry", vgId, pHandle->subKey);
+      taosMsleep(5);
+    }
+
     code = taosHashRemove(pTq->pHandle, pReq->subKey, strlen(pReq->subKey));
     if (code != 0) {
       tqError("cannot process tq delete req %s, since no such handle", pReq->subKey);
@@ -535,6 +618,7 @@ int32_t tqProcessDelCheckInfoReq(STQ* pTq, int64_t sversion, char* msg, int32_t
 }
 
 int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msgLen) {
+  int ret = 0;
   SMqRebVgReq req = {0};
   tDecodeSMqRebVgReq(msg, &req);
 
@@ -553,8 +637,7 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
 
     if (req.newConsumerId == -1) {
       tqError("vgId:%d, tq invalid re-balance request, new consumerId %" PRId64 "", req.vgId, req.newConsumerId);
-      taosMemoryFree(req.qmsg);
-      return 0;
+      goto end;
     }
 
     STqHandle tqHandle = {0};
@@ -571,8 +654,8 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
     // TODO version should be assigned and refed during preprocess
     SWalRef* pRef = walRefCommittedVer(pVnode->pWal);
     if (pRef == NULL) {
-      taosMemoryFree(req.qmsg);
-      return -1;
+      ret = -1;
+      goto end;
     }
 
     int64_t ver = pRef->refVer;
@@ -593,7 +676,7 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
       pHandle->execHandle.pTqReader = qExtractReaderFromStreamScanner(scanner);
     } else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) {
       pHandle->pWalReader = walOpenReader(pVnode->pWal, NULL);
-      pHandle->execHandle.pTqReader = tqOpenReader(pVnode);
+      pHandle->execHandle.pTqReader = tqReaderOpen(pVnode);
 
       pHandle->execHandle.execDb.pFilterOutTbUid =
           taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
@@ -612,7 +695,7 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
         int64_t tbUid = *(int64_t*)taosArrayGet(tbUidList, i);
         tqDebug("vgId:%d, idx %d, uid:%" PRId64, vgId, i, tbUid);
       }
-      pHandle->execHandle.pTqReader = tqOpenReader(pVnode);
+      pHandle->execHandle.pTqReader = tqReaderOpen(pVnode);
       tqReaderSetTbUidList(pHandle->execHandle.pTqReader, tbUidList);
       taosArrayDestroy(tbUidList);
 
@@ -624,50 +707,42 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
     taosHashPut(pTq->pHandle, req.subKey, strlen(req.subKey), pHandle, sizeof(STqHandle));
     tqDebug("try to persist handle %s consumer:0x%" PRIx64 " , old consumer:0x%" PRIx64, req.subKey,
             pHandle->consumerId, oldConsumerId);
-    if (tqMetaSaveHandle(pTq, req.subKey, pHandle) < 0) {
-      taosMemoryFree(req.qmsg);
-      return -1;
-    }
+    ret = tqMetaSaveHandle(pTq, req.subKey, pHandle);
+    goto end;
   } else {
     if (pHandle->consumerId == req.newConsumerId) {  // do nothing
       tqInfo("vgId:%d consumer:0x%" PRIx64 " remains, no switch occurs", req.vgId, req.newConsumerId);
-      atomic_store_32(&pHandle->epoch, -1);
       atomic_add_fetch_32(&pHandle->epoch, 1);
-      taosMemoryFree(req.qmsg);
-      return tqMetaSaveHandle(pTq, req.subKey, pHandle);
+
     } else {
       tqInfo("vgId:%d switch consumer from Id:0x%" PRIx64 " to Id:0x%" PRIx64, req.vgId, pHandle->consumerId,
              req.newConsumerId);
-
-      // kill executing task
-      qTaskInfo_t pTaskInfo = pHandle->execHandle.task;
-      if (pTaskInfo != NULL) {
-        qKillTask(pTaskInfo, TSDB_CODE_SUCCESS);
-      }
-
-      taosWLockLatch(&pTq->lock);
-      atomic_store_32(&pHandle->epoch, -1);
-
-      // remove if it has been register in the push manager, and return one empty block to consumer
-      tqUnregisterPushHandle(pTq, req.subKey, (int32_t)strlen(req.subKey), pHandle->consumerId, true);
-
       atomic_store_64(&pHandle->consumerId, req.newConsumerId);
-      atomic_add_fetch_32(&pHandle->epoch, 1);
-
-      if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
-        qStreamCloseTsdbReader(pTaskInfo);
-      }
-
-      taosWUnLockLatch(&pTq->lock);
-      if (tqMetaSaveHandle(pTq, req.subKey, pHandle) < 0) {
-        taosMemoryFree(req.qmsg);
-        return -1;
-      }
+      atomic_store_32(&pHandle->epoch, 0);
     }
+    // kill executing task
+    qTaskInfo_t pTaskInfo = pHandle->execHandle.task;
+    if (pTaskInfo != NULL) {
+      qKillTask(pTaskInfo, TSDB_CODE_SUCCESS);
+    }
+
+    taosWLockLatch(&pTq->lock);
+    // remove if it has been register in the push manager, and return one empty block to consumer
+    tqUnregisterPushHandle(pTq, pHandle);
+
+
+    if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
+      qStreamCloseTsdbReader(pTaskInfo);
+    }
+
+    taosWUnLockLatch(&pTq->lock);
+    ret = tqMetaSaveHandle(pTq, req.subKey, pHandle);
+    goto end;
   }
 
+end:
   taosMemoryFree(req.qmsg);
-  return 0;
+  return ret;
 }
 
 int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int64_t ver) {
@@ -687,13 +762,10 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int64_t ver) {
   pTask->pMsgCb = &pTq->pVnode->msgCb;
   pTask->pMeta = pTq->pStreamMeta;
   pTask->chkInfo.version = ver;
+  pTask->chkInfo.currentVer = ver;
 
   // expand executor
-  if (pTask->fillHistory) {
-    pTask->status.taskStatus = TASK_STATUS__WAIT_DOWNSTREAM;
-  } else {
-    pTask->status.taskStatus = TASK_STATUS__RESTORE;
-  }
+  pTask->status.taskStatus = (pTask->fillHistory)? TASK_STATUS__WAIT_DOWNSTREAM:TASK_STATUS__NORMAL;
 
   if (pTask->taskLevel == TASK_LEVEL__SOURCE) {
     pTask->pState = streamStateOpen(pTq->pStreamMeta->path, pTask, false, -1, -1);
@@ -752,6 +824,7 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int64_t ver) {
   }
 
   streamSetupTrigger(pTask);
+
   tqInfo("vgId:%d expand stream task, s-task:%s, checkpoint ver:%" PRId64 " child id:%d, level:%d", vgId, pTask->id.idStr,
          pTask->chkInfo.version, pTask->selfChildId, pTask->taskLevel);
 
@@ -781,8 +854,9 @@ int32_t tqProcessStreamTaskCheckReq(STQ* pTq, SRpcMsg* pMsg) {
   };
 
   SStreamTask* pTask = streamMetaAcquireTask(pTq->pStreamMeta, taskId);
+
   if (pTask) {
-    rsp.status = (atomic_load_8(&pTask->status.taskStatus) == TASK_STATUS__NORMAL) ? 1 : 0;
+    rsp.status = streamTaskCheckStatus(pTask);
     streamMetaReleaseTask(pTq->pStreamMeta, pTask);
 
     tqDebug("tq recv task check req(reqId:0x%" PRIx64
@@ -846,11 +920,9 @@ int32_t tqProcessStreamTaskCheckRsp(STQ* pTq, int64_t sversion, char* msg, int32
 }
 
 int32_t tqProcessTaskDeployReq(STQ* pTq, int64_t sversion, char* msg, int32_t msgLen) {
-  int32_t code;
-#if 0
-  code = streamMetaAddSerializedTask(pTq->pStreamMeta, version, msg, msgLen);
-  if (code < 0) return code;
-#endif
+  int32_t code = 0;
+  int32_t vgId = TD_VID(pTq->pVnode);
+
   if (tsDisableStream) {
     return 0;
   }
@@ -873,20 +945,24 @@ int32_t tqProcessTaskDeployReq(STQ* pTq, int64_t sversion, char* msg, int32_t ms
   tDecoderClear(&decoder);
 
   // 2.save task, use the newest commit version as the initial start version of stream task.
+  taosWLockLatch(&pTq->pStreamMeta->lock);
   code = streamMetaAddDeployedTask(pTq->pStreamMeta, sversion, pTask);
   if (code < 0) {
-    tqError("vgId:%d failed to add s-task:%s, total:%d", TD_VID(pTq->pVnode), pTask->id.idStr,
+    tqError("vgId:%d failed to add s-task:%s, total:%d", vgId, pTask->id.idStr,
             streamMetaGetNumOfTasks(pTq->pStreamMeta));
+    taosWUnLockLatch(&pTq->pStreamMeta->lock);
     return -1;
   }
 
+  taosWUnLockLatch(&pTq->pStreamMeta->lock);
+
   // 3.go through recover steps to fill history
   if (pTask->fillHistory) {
     streamTaskCheckDownstream(pTask, sversion);
   }
 
-  tqDebug("vgId:%d s-task:%s is deployed and add meta from mnd, status:%d, total:%d", TD_VID(pTq->pVnode),
-          pTask->id.idStr, pTask->status.taskStatus, streamMetaGetNumOfTasks(pTq->pStreamMeta));
+  tqDebug("vgId:%d s-task:%s is deployed and add meta from mnd, status:%d, total:%d", vgId, pTask->id.idStr,
+          pTask->status.taskStatus, streamMetaGetNumOfTasks(pTq->pStreamMeta));
   return 0;
 }
 
@@ -909,13 +985,18 @@ int32_t tqProcessTaskRecover1Req(STQ* pTq, SRpcMsg* pMsg) {
   }
 
   // do recovery step 1
-  streamSourceRecoverScanStep1(pTask);
+  tqDebug("s-task:%s start recover step 1 scan", pTask->id.idStr);
+  int64_t st = taosGetTimestampMs();
 
+  streamSourceRecoverScanStep1(pTask);
   if (atomic_load_8(&pTask->status.taskStatus) == TASK_STATUS__DROPPING) {
     streamMetaReleaseTask(pTq->pStreamMeta, pTask);
     return 0;
   }
 
+  double el = (taosGetTimestampMs() - st) / 1000.0;
+  tqDebug("s-task:%s recover step 1 ended, elapsed time:%.2fs", pTask->id.idStr, el);
+
   // build msg to launch next step
   SStreamRecoverStep2Req req;
   code = streamBuildSourceRecover2Req(pTask, &req);
@@ -941,20 +1022,17 @@ int32_t tqProcessTaskRecover1Req(STQ* pTq, SRpcMsg* pMsg) {
   memcpy(serializedReq, &req, len);
 
   // dispatch msg
+  tqDebug("s-task:%s start recover block stage", pTask->id.idStr);
+
   SRpcMsg rpcMsg = {
-      .code = 0,
-      .contLen = len,
-      .msgType = TDMT_VND_STREAM_RECOVER_BLOCKING_STAGE,
-      .pCont = serializedReq,
-  };
-
+      .code = 0, .contLen = len, .msgType = TDMT_VND_STREAM_RECOVER_BLOCKING_STAGE, .pCont = serializedReq};
   tmsgPutToQueue(&pTq->pVnode->msgCb, WRITE_QUEUE, &rpcMsg);
-
   return 0;
 }
 
 int32_t tqProcessTaskRecover2Req(STQ* pTq, int64_t sversion, char* msg, int32_t msgLen) {
-  int32_t                 code;
+  int32_t code = 0;
+
   SStreamRecoverStep2Req* pReq = (SStreamRecoverStep2Req*)msg;
   SStreamTask*            pTask = streamMetaAcquireTask(pTq->pStreamMeta, pReq->taskId);
   if (pTask == NULL) {
@@ -1080,14 +1158,21 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
   int32_t* pRef = taosMemoryMalloc(sizeof(int32_t));
   *pRef = 1;
 
+  taosWLockLatch(&pTq->pStreamMeta->lock);
+
   void* pIter = NULL;
   while (1) {
     pIter = taosHashIterate(pTq->pStreamMeta->pTasks, pIter);
-    if (pIter == NULL) break;
-    SStreamTask* pTask = *(SStreamTask**)pIter;
-    if (pTask->taskLevel != TASK_LEVEL__SOURCE) continue;
+    if (pIter == NULL) {
+      break;
+    }
 
-    qDebug("delete req enqueue stream task: %d, ver: %" PRId64, pTask->id.taskId, ver);
+    SStreamTask* pTask = *(SStreamTask**)pIter;
+    if (pTask->taskLevel != TASK_LEVEL__SOURCE) {
+      continue;
+    }
+
+    qDebug("s-task:%s delete req enqueue, ver: %" PRId64, pTask->id.idStr, ver);
 
     if (!failed) {
       SStreamRefDataBlock* pRefBlock = taosAllocateQitem(sizeof(SStreamRefDataBlock), DEF_QITEM, 0);
@@ -1097,15 +1182,13 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
       atomic_add_fetch_32(pRefBlock->dataRef, 1);
 
       if (tAppendDataToInputQueue(pTask, (SStreamQueueItem*)pRefBlock) < 0) {
-        qError("stream task input del failed, task id %d", pTask->id.taskId);
-
         atomic_sub_fetch_32(pRef, 1);
         taosFreeQitem(pRefBlock);
         continue;
       }
 
       if (streamSchedExec(pTask) < 0) {
-        qError("stream task launch failed, task id %d", pTask->id.taskId);
+        qError("s-task:%s stream task launch failed", pTask->id.idStr);
         continue;
       }
 
@@ -1114,8 +1197,9 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
     }
   }
 
+  taosWUnLockLatch(&pTq->pStreamMeta->lock);
+
   int32_t ref = atomic_sub_fetch_32(pRef, 1);
-  /*A(ref >= 0);*/
   if (ref == 0) {
     blockDataDestroy(pDelBlock);
     taosMemoryFree(pRef);
@@ -1146,84 +1230,39 @@ int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) {
   }
   blockDataDestroy(pDelBlock);
 #endif
-
   return 0;
 }
 
-static int32_t addSubmitBlockNLaunchTask(STqOffsetStore* pOffsetStore, SStreamTask* pTask, SStreamDataSubmit2* pSubmit,
-                                         const char* key, int64_t ver) {
-  doSaveTaskOffset(pOffsetStore, key, ver);
-  int32_t code = tqAddInputBlockNLaunchTask(pTask, (SStreamQueueItem*)pSubmit, ver);
+int32_t tqProcessSubmitReqForSubscribe(STQ* pTq) {
+  int32_t vgId = TD_VID(pTq->pVnode);
 
-  // remove the offset, if all functions are completed successfully.
-  if (code == TSDB_CODE_SUCCESS) {
-    tqOffsetDelete(pOffsetStore, key);
-  }
+  taosWLockLatch(&pTq->lock);
 
-  return code;
-}
+  if (taosHashGetSize(pTq->pPushMgr) > 0) {
+    void* pIter = taosHashIterate(pTq->pPushMgr, NULL);
 
-int32_t tqProcessSubmitReq(STQ* pTq, SPackedData submit) {
-#if 0
-  void* pIter = NULL;
-  SStreamDataSubmit2* pSubmit = streamDataSubmitNew(submit, STREAM_INPUT__DATA_SUBMIT);
-  if (pSubmit == NULL) {
-    terrno = TSDB_CODE_OUT_OF_MEMORY;
-    tqError("failed to create data submit for stream since out of memory");
-    saveOffsetForAllTasks(pTq, submit.ver);
-    return -1;
-  }
+    while (pIter) {
+      STqHandle* pHandle = *(STqHandle**)pIter;
+      tqDebug("vgId:%d start set submit for pHandle:%p, consumer:0x%" PRIx64, vgId, pHandle, pHandle->consumerId);
 
-  SArray* pInputQueueFullTasks = taosArrayInit(4, POINTER_BYTES);
-
-  while (1) {
-    pIter = taosHashIterate(pTq->pStreamMeta->pTasks, pIter);
-    if (pIter == NULL) {
-      break;
-    }
-
-    SStreamTask* pTask = *(SStreamTask**)pIter;
-    if (pTask->taskLevel != TASK_LEVEL__SOURCE) {
-      continue;
-    }
-
-    if (pTask->status.taskStatus == TASK_STATUS__RECOVER_PREPARE || pTask->status.taskStatus == TASK_STATUS__WAIT_DOWNSTREAM) {
-      tqDebug("stream task:%d skip push data, not ready for processing, status %d", pTask->id.taskId,
-              pTask->status.taskStatus);
-      continue;
-    }
-
-    // check if offset value exists
-    char key[128] = {0};
-    createStreamTaskOffsetKey(key, pTask->id.streamId, pTask->id.taskId);
-
-    if (tInputQueueIsFull(pTask)) {
-      STqOffset* pOffset = tqOffsetRead(pTq->pOffsetStore, key);
-
-      int64_t ver = submit.ver;
-      if (pOffset == NULL) {
-        doSaveTaskOffset(pTq->pOffsetStore, key, submit.ver);
-      } else {
-        ver = pOffset->val.version;
+      if (ASSERT(pHandle->msg != NULL)) {
+        tqError("pHandle->msg should not be null");
+        break;
+      }else{
+        SRpcMsg msg = {.msgType = TDMT_VND_TMQ_CONSUME, .pCont = pHandle->msg->pCont, .contLen = pHandle->msg->contLen, .info = pHandle->msg->info};
+        tmsgPutToQueue(&pTq->pVnode->msgCb, QUERY_QUEUE, &msg);
+        taosMemoryFree(pHandle->msg);
+        pHandle->msg = NULL;
       }
 
-      tqDebug("s-task:%s input queue is full, discard submit block, ver:%" PRId64, pTask->id.idStr, ver);
-      taosArrayPush(pInputQueueFullTasks, &pTask);
-      continue;
+      pIter = taosHashIterate(pTq->pPushMgr, pIter);
     }
 
-    // check if offset value exists
-    STqOffset* pOffset = tqOffsetRead(pTq->pOffsetStore, key);
-    ASSERT(pOffset == NULL);
-
-    addSubmitBlockNLaunchTask(pTq->pOffsetStore, pTask, pSubmit, key, submit.ver);
+    taosHashClear(pTq->pPushMgr);
   }
 
-  streamDataSubmitDestroy(pSubmit);
-  taosFreeQitem(pSubmit);
-#endif
-
-  tqStartStreamTasks(pTq);
+  // unlock
+  taosWUnLockLatch(&pTq->lock);
   return 0;
 }
 
@@ -1241,9 +1280,6 @@ int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg) {
   SStreamTask* pTask = streamMetaAcquireTask(pTq->pStreamMeta, taskId);
   if (pTask != NULL) {
     if (pTask->status.taskStatus == TASK_STATUS__NORMAL) {
-      tqDebug("vgId:%d s-task:%s start to process run req", vgId, pTask->id.idStr);
-      streamProcessRunReq(pTask);
-    } else if (pTask->status.taskStatus == TASK_STATUS__RESTORE) {
       tqDebug("vgId:%d s-task:%s start to process block from wal, last chk point:%" PRId64, vgId,
               pTask->id.idStr, pTask->chkInfo.version);
       streamProcessRunReq(pTask);
@@ -1276,6 +1312,7 @@ int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg, bool exec) {
     streamMetaReleaseTask(pTq->pStreamMeta, pTask);
     return 0;
   } else {
+    tDeleteStreamDispatchReq(&req);
     return -1;
   }
 }
@@ -1318,6 +1355,7 @@ int32_t tqProcessTaskRetrieveReq(STQ* pTq, SRpcMsg* pMsg) {
     tDeleteStreamRetrieveReq(&req);
     return 0;
   } else {
+    tDeleteStreamRetrieveReq(&req);
     return -1;
   }
 }
@@ -1394,21 +1432,22 @@ FAIL:
 int32_t tqCheckLogInWal(STQ* pTq, int64_t sversion) { return sversion <= pTq->walLogLastVer; }
 
 int32_t tqStartStreamTasks(STQ* pTq) {
-  int32_t vgId = TD_VID(pTq->pVnode);
-
+  int32_t      vgId = TD_VID(pTq->pVnode);
   SStreamMeta* pMeta = pTq->pStreamMeta;
+
   taosWLockLatch(&pMeta->lock);
-  int32_t numOfTasks = taosHashGetSize(pTq->pStreamMeta->pTasks);
+
+  int32_t numOfTasks = taosArrayGetSize(pMeta->pTaskList);
   if (numOfTasks == 0) {
     tqInfo("vgId:%d no stream tasks exists", vgId);
     taosWUnLockLatch(&pTq->pStreamMeta->lock);
     return 0;
   }
 
-  pMeta->walScan += 1;
+  pMeta->walScanCounter += 1;
 
-  if (pMeta->walScan > 1) {
-    tqDebug("vgId:%d wal read task has been launched, remain scan times:%d", vgId, pMeta->walScan);
+  if (pMeta->walScanCounter > 1) {
+    tqDebug("vgId:%d wal read task has been launched, remain scan times:%d", vgId, pMeta->walScanCounter);
     taosWUnLockLatch(&pTq->pStreamMeta->lock);
     return 0;
   }
@@ -1421,9 +1460,7 @@ int32_t tqStartStreamTasks(STQ* pTq) {
     return -1;
   }
 
-  tqInfo("vgId:%d start wal scan stream tasks, tasks:%d", vgId, numOfTasks);
-  initOffsetForAllRestoreTasks(pTq);
-
+  tqDebug("vgId:%d start wal scan stream tasks, tasks:%d", vgId, numOfTasks);
   pRunReq->head.vgId = vgId;
   pRunReq->streamId = 0;
   pRunReq->taskId = WAL_READ_TASKS_ID;
diff --git a/source/dnode/vnode/src/tq/tqMeta.c b/source/dnode/vnode/src/tq/tqMeta.c
index cd8cefb307..f3ecaa08f6 100644
--- a/source/dnode/vnode/src/tq/tqMeta.c
+++ b/source/dnode/vnode/src/tq/tqMeta.c
@@ -328,7 +328,7 @@ int32_t tqMetaRestoreHandle(STQ* pTq) {
       }
     } else if (handle.execHandle.subType == TOPIC_SUB_TYPE__DB) {
       handle.pWalReader = walOpenReader(pTq->pVnode->pWal, NULL);
-      handle.execHandle.pTqReader = tqOpenReader(pTq->pVnode);
+      handle.execHandle.pTqReader = tqReaderOpen(pTq->pVnode);
 
       buildSnapContext(reader.meta, reader.version, 0, handle.execHandle.subType, handle.fetchMeta,
                        (SSnapContext**)(&reader.sContext));
@@ -343,7 +343,7 @@ int32_t tqMetaRestoreHandle(STQ* pTq) {
         int64_t tbUid = *(int64_t*)taosArrayGet(tbUidList, i);
         tqDebug("vgId:%d, idx %d, uid:%" PRId64, vgId, i, tbUid);
       }
-      handle.execHandle.pTqReader = tqOpenReader(pTq->pVnode);
+      handle.execHandle.pTqReader = tqReaderOpen(pTq->pVnode);
       tqReaderSetTbUidList(handle.execHandle.pTqReader, tbUidList);
       taosArrayDestroy(tbUidList);
 
diff --git a/source/dnode/vnode/src/tq/tqOffset.c b/source/dnode/vnode/src/tq/tqOffset.c
index e8051a1406..34e93cec2d 100644
--- a/source/dnode/vnode/src/tq/tqOffset.c
+++ b/source/dnode/vnode/src/tq/tqOffset.c
@@ -31,57 +31,67 @@ char* tqOffsetBuildFName(const char* path, int32_t fVer) {
 
 int32_t tqOffsetRestoreFromFile(STqOffsetStore* pStore, const char* fname) {
   TdFilePtr pFile = taosOpenFile(fname, TD_FILE_READ);
-  if (pFile != NULL) {
-    STqOffsetHead head = {0};
-    int64_t       code;
+  if (pFile == NULL) {
+    return TSDB_CODE_SUCCESS;
+  }
 
-    while (1) {
-      if ((code = taosReadFile(pFile, &head, sizeof(STqOffsetHead))) != sizeof(STqOffsetHead)) {
-        if (code == 0) {
-          break;
-        } else {
-          return -1;
-        }
-      }
-      int32_t size = htonl(head.size);
-      void*   memBuf = taosMemoryCalloc(1, size);
-      if (memBuf == NULL) {
+  int32_t vgId = TD_VID(pStore->pTq->pVnode);
+  int64_t code = 0;
+
+  STqOffsetHead head = {0};
+
+  while (1) {
+    if ((code = taosReadFile(pFile, &head, sizeof(STqOffsetHead))) != sizeof(STqOffsetHead)) {
+      if (code == 0) {
+        break;
+      } else {
         return -1;
       }
-      if ((code = taosReadFile(pFile, memBuf, size)) != size) {
-        taosMemoryFree(memBuf);
-        return -1;
-      }
-      STqOffset offset;
-      SDecoder  decoder;
-      tDecoderInit(&decoder, memBuf, size);
-      if (tDecodeSTqOffset(&decoder, &offset) < 0) {
-        taosMemoryFree(memBuf);
-        tDecoderClear(&decoder);
-        return -1;
-      }
-
-      tDecoderClear(&decoder);
-      if (taosHashPut(pStore->pHash, offset.subKey, strlen(offset.subKey), &offset, sizeof(STqOffset)) < 0) {
-        return -1;
-      }
-
-      if (offset.val.type == TMQ_OFFSET__LOG) {
-        STqHandle* pHandle = taosHashGet(pStore->pTq->pHandle, offset.subKey, strlen(offset.subKey));
-        if (pHandle) {
-          if (walRefVer(pHandle->pRef, offset.val.version) < 0) {
-            tqError("vgId: %d, tq handle %s ref ver %" PRId64 "error", pStore->pTq->pVnode->config.vgId,
-                    pHandle->subKey, offset.val.version);
-          }
-        }
-      }
-
-      taosMemoryFree(memBuf);
     }
 
-    taosCloseFile(&pFile);
+    int32_t size = htonl(head.size);
+    void*   pMemBuf = taosMemoryCalloc(1, size);
+    if (pMemBuf == NULL) {
+      tqError("vgId:%d failed to restore offset from file, since out of memory, malloc size:%d", vgId, size);
+      terrno = TSDB_CODE_OUT_OF_MEMORY;
+      return -1;
+    }
+
+    if ((code = taosReadFile(pFile, pMemBuf, size)) != size) {
+      taosMemoryFree(pMemBuf);
+      return -1;
+    }
+
+    STqOffset offset;
+    SDecoder  decoder;
+    tDecoderInit(&decoder, pMemBuf, size);
+    if (tDecodeSTqOffset(&decoder, &offset) < 0) {
+      taosMemoryFree(pMemBuf);
+      tDecoderClear(&decoder);
+      return code;
+    }
+
+    tDecoderClear(&decoder);
+    if (taosHashPut(pStore->pHash, offset.subKey, strlen(offset.subKey), &offset, sizeof(STqOffset)) < 0) {
+      return -1;
+    }
+
+    // todo remove this
+    if (offset.val.type == TMQ_OFFSET__LOG) {
+      STqHandle* pHandle = taosHashGet(pStore->pTq->pHandle, offset.subKey, strlen(offset.subKey));
+      if (pHandle) {
+        if (walRefVer(pHandle->pRef, offset.val.version) < 0) {
+//          tqError("vgId: %d, tq handle %s ref ver %" PRId64 "error", pStore->pTq->pVnode->config.vgId, pHandle->subKey,
+//                  offset.val.version);
+        }
+      }
+    }
+
+    taosMemoryFree(pMemBuf);
   }
-  return 0;
+
+  taosCloseFile(&pFile);
+  return TSDB_CODE_SUCCESS;
 }
 
 STqOffsetStore* tqOffsetOpen(STQ* pTq) {
@@ -89,6 +99,7 @@ STqOffsetStore* tqOffsetOpen(STQ* pTq) {
   if (pStore == NULL) {
     return NULL;
   }
+
   pStore->pTq = pTq;
   pStore->needCommit = 0;
   pTq->pOffsetStore = pStore;
@@ -98,12 +109,14 @@ STqOffsetStore* tqOffsetOpen(STQ* pTq) {
     taosMemoryFree(pStore);
     return NULL;
   }
+
   char* fname = tqOffsetBuildFName(pStore->pTq->path, 0);
   if (tqOffsetRestoreFromFile(pStore, fname) < 0) {
     taosMemoryFree(fname);
     taosMemoryFree(pStore);
     return NULL;
   }
+
   taosMemoryFree(fname);
   return pStore;
 }
diff --git a/source/dnode/vnode/src/tq/tqPush.c b/source/dnode/vnode/src/tq/tqPush.c
index 43463f67b7..e1e9bec348 100644
--- a/source/dnode/vnode/src/tq/tqPush.c
+++ b/source/dnode/vnode/src/tq/tqPush.c
@@ -16,342 +16,26 @@
 #include "tq.h"
 #include "vnd.h"
 
-#if 0
-void tqTmrRspFunc(void* param, void* tmrId) {
-  STqHandle* pHandle = (STqHandle*)param;
-  atomic_store_8(&pHandle->pushHandle.tmrStopped, 1);
-}
-
-static int32_t tqLoopExecFromQueue(STQ* pTq, STqHandle* pHandle, SStreamDataSubmit** ppSubmit, SMqDataRsp* pRsp) {
-  SStreamDataSubmit* pSubmit = *ppSubmit;
-  while (pSubmit != NULL) {
-    if (tqLogScanExec(pTq, &pHandle->execHandle, pSubmit->data, pRsp, 0) < 0) {
-    }
-    // update processed
-    atomic_store_64(&pHandle->pushHandle.processedVer, pSubmit->ver);
-    streamQueueProcessSuccess(&pHandle->pushHandle.inputQ);
-    streamDataSubmitDestroy(pSubmit);
-    if (pRsp->blockNum > 0) {
-      *ppSubmit = pSubmit;
-      return 0;
-    } else {
-      pSubmit = streamQueueNextItem(&pHandle->pushHandle.inputQ);
-    }
-  }
-  *ppSubmit = pSubmit;
-  return -1;
-}
-
-int32_t tqExecFromInputQ(STQ* pTq, STqHandle* pHandle) {
-  SMqDataRsp rsp = {0};
-  // 1. guard and set status executing
-  int8_t execStatus = atomic_val_compare_exchange_8(&pHandle->pushHandle.execStatus, TASK_EXEC_STATUS__IDLE,
-                                                    TASK_EXEC_STATUS__EXECUTING);
-  if (execStatus == TASK_EXEC_STATUS__IDLE) {
-    SStreamDataSubmit* pSubmit = NULL;
-    // 2. check processedVer
-    // 2.1. if not missed, get msg from queue
-    // 2.2. if missed, scan wal
-    pSubmit = streamQueueNextItem(&pHandle->pushHandle.inputQ);
-    while (pHandle->pushHandle.processedVer <= pSubmit->ver) {
-      // read from wal
-    }
-    while (pHandle->pushHandle.processedVer > pSubmit->ver + 1) {
-      streamQueueProcessSuccess(&pHandle->pushHandle.inputQ);
-      streamDataSubmitDestroy(pSubmit);
-      pSubmit = streamQueueNextItem(&pHandle->pushHandle.inputQ);
-      if (pSubmit == NULL) break;
-    }
-    // 3. exec, after each success, update processed ver
-    // first run
-    if (tqLoopExecFromQueue(pTq, pHandle, &pSubmit, &rsp) == 0) {
-      goto SEND_RSP;
-    }
-    // set exec status closing
-    atomic_store_8(&pHandle->pushHandle.execStatus, TASK_EXEC_STATUS__CLOSING);
-    // second run
-    if (tqLoopExecFromQueue(pTq, pHandle, &pSubmit, &rsp) == 0) {
-      goto SEND_RSP;
-    }
-    // set exec status idle
-    atomic_store_8(&pHandle->pushHandle.execStatus, TASK_EXEC_STATUS__IDLE);
-  }
-SEND_RSP:
-  // 4. if get result
-  // 4.1 set exec input status blocked and exec status idle
-  atomic_store_8(&pHandle->pushHandle.execStatus, TASK_EXEC_STATUS__IDLE);
-  // 4.2 rpc send
-  rsp.rspOffset = pHandle->pushHandle.processedVer;
-  /*if (tqSendPollRsp(pTq, pMsg, pReq, &rsp) < 0) {*/
-  /*return -1;*/
-  /*}*/
-  // 4.3 clear rpc info
-  memset(&pHandle->pushHandle.rpcInfo, 0, sizeof(SRpcHandleInfo));
-  return 0;
-}
-
-int32_t tqOpenPushHandle(STQ* pTq, STqHandle* pHandle) {
-  memset(&pHandle->pushHandle, 0, sizeof(STqPushHandle));
-  pHandle->pushHandle.inputQ.queue = taosOpenQueue();
-  pHandle->pushHandle.inputQ.qall = taosAllocateQall();
-  if (pHandle->pushHandle.inputQ.queue == NULL || pHandle->pushHandle.inputQ.qall == NULL) {
-    if (pHandle->pushHandle.inputQ.queue) {
-      taosCloseQueue(pHandle->pushHandle.inputQ.queue);
-    }
-    if (pHandle->pushHandle.inputQ.qall) {
-      taosFreeQall(pHandle->pushHandle.inputQ.qall);
-    }
-    return -1;
-  }
-  return 0;
-}
-
-int32_t tqPreparePush(STQ* pTq, STqHandle* pHandle, int64_t reqId, const SRpcHandleInfo* pInfo, int64_t processedVer,
-                      int64_t timeout) {
-  memcpy(&pHandle->pushHandle.rpcInfo, pInfo, sizeof(SRpcHandleInfo));
-  atomic_store_64(&pHandle->pushHandle.reqId, reqId);
-  atomic_store_64(&pHandle->pushHandle.processedVer, processedVer);
-  atomic_store_8(&pHandle->pushHandle.inputStatus, TASK_INPUT_STATUS__NORMAL);
-  atomic_store_8(&pHandle->pushHandle.tmrStopped, 0);
-  taosTmrReset(tqTmrRspFunc, (int32_t)timeout, pHandle, tqMgmt.timer, &pHandle->pushHandle.timerId);
-  return 0;
-}
-
-int32_t tqEnqueue(STqHandle* pHandle, SStreamDataSubmit* pSubmit) {
-  int8_t inputStatus = atomic_load_8(&pHandle->pushHandle.inputStatus);
-  if (inputStatus == TASK_INPUT_STATUS__NORMAL) {
-    SStreamDataSubmit* pSubmitClone = streamSubmitBlockClone(pSubmit);
-    if (pSubmitClone == NULL) {
-      return -1;
-    }
-    taosWriteQitem(pHandle->pushHandle.inputQ.queue, pSubmitClone);
-    return 0;
-  }
-  return -1;
-}
-
-int32_t tqSendExecReq(STQ* pTq, STqHandle* pHandle) {
-  //
-  return 0;
-}
-
-int32_t tqPushMsgNew(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver, SRpcHandleInfo handleInfo) {
-  if (msgType != TDMT_VND_SUBMIT) return 0;
-  void*       pIter = NULL;
-  STqHandle*  pHandle = NULL;
-  SSubmitReq* pReq = (SSubmitReq*)msg;
-  int32_t     workerId = 4;
-  int64_t     fetchOffset = ver;
-
-  while (1) {
-    pIter = taosHashIterate(pTq->pushMgr, pIter);
-    if (pIter == NULL) break;
-    pHandle = *(STqHandle**)pIter;
-
-    taosWLockLatch(&pHandle->pushHandle.lock);
-
-    SMqDataRsp rsp = {0};
-    rsp.reqOffset = pHandle->pushHandle.reqOffset;
-    rsp.blockData = taosArrayInit(0, sizeof(void*));
-    rsp.blockDataLen = taosArrayInit(0, sizeof(int32_t));
-
-    if (msgType == TDMT_VND_SUBMIT) {
-      tqLogScanExec(pTq, &pHandle->execHandle, pReq, &rsp, workerId);
-    } else {
-      tqError("tq push unexpected msg type %d", msgType);
-    }
-
-    if (rsp.blockNum == 0) {
-      taosWUnLockLatch(&pHandle->pushHandle.lock);
-      continue;
-    }
-
-    rsp.rspOffset = fetchOffset;
-
-    int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqDataBlkRsp(NULL, &rsp);
-    void*   buf = rpcMallocCont(tlen);
-    if (buf == NULL) {
-      // todo free
-      return -1;
-    }
-
-    ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP;
-    ((SMqRspHead*)buf)->epoch = pHandle->pushHandle.epoch;
-    ((SMqRspHead*)buf)->consumerId = pHandle->pushHandle.consumerId;
-
-    void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead));
-    tEncodeSMqDataBlkRsp(&abuf, &rsp);
-
-    SRpcMsg resp = {
-        .info = pHandle->pushHandle.rpcInfo,
-        .pCont = buf,
-        .contLen = tlen,
-        .code = 0,
-    };
-    tmsgSendRsp(&resp);
-
-    memset(&pHandle->pushHandle.rpcInfo, 0, sizeof(SRpcHandleInfo));
-    taosWUnLockLatch(&pHandle->pushHandle.lock);
-
-    tqDebug("vgId:%d offset %" PRId64 " from consumer:%" PRId64 ", (epoch %d) send rsp, block num: %d, req:%" PRId64 ", rsp:%" PRId64,
-            TD_VID(pTq->pVnode), fetchOffset, pHandle->pushHandle.consumerId, pHandle->pushHandle.epoch, rsp.blockNum,
-            rsp.reqOffset, rsp.rspOffset);
-
-    // TODO destroy
-    taosArrayDestroy(rsp.blockData);
-    taosArrayDestroy(rsp.blockDataLen);
-  }
-
-  return 0;
-}
-#endif
-
-typedef struct {
-  void*   pKey;
-  int64_t keyLen;
-} SItem;
-
-static void recordPushedEntry(SArray* cachedKey, void* pIter);
-static void doRemovePushedEntry(SArray* pCachedKeys, STQ* pTq);
-
-static void freeItem(void* param) {
-  SItem* p = (SItem*)param;
-  taosMemoryFree(p->pKey);
-}
-
-static void doPushDataForEntry(void* pIter, STqExecHandle* pExec, STQ* pTq, int64_t ver, int32_t vgId, char* pData,
-                               int32_t dataLen, SArray* pCachedKey) {
-  STqPushEntry* pPushEntry = *(STqPushEntry**)pIter;
-
-  SMqDataRsp* pRsp = pPushEntry->pDataRsp;
-  if (pRsp->reqOffset.version >= ver) {
-    tqDebug("vgId:%d, push entry req version %" PRId64 ", while push version %" PRId64 ", skip", vgId,
-            pRsp->reqOffset.version, ver);
-    return;
-  }
-
-  qTaskInfo_t pTaskInfo = pExec->task;
-
-  // prepare scan mem data
-  SPackedData submit = {.msgStr = pData, .msgLen = dataLen, .ver = ver};
-
-  if (qStreamSetScanMemData(pTaskInfo, submit) != 0) {
-    return;
-  }
-  qStreamSetOpen(pTaskInfo);
-  // here start to scan submit block to extract the subscribed data
-  int32_t totalRows = 0;
-
-  while (1) {
-    SSDataBlock* pDataBlock = NULL;
-    uint64_t     ts = 0;
-    if (qExecTask(pTaskInfo, &pDataBlock, &ts) < 0) {
-      tqDebug("vgId:%d, tq exec error since %s", vgId, terrstr());
-    }
-
-    if (pDataBlock == NULL) {
-      break;
-    }
-
-    tqAddBlockDataToRsp(pDataBlock, pRsp, pExec->numOfCols, pTq->pVnode->config.tsdbCfg.precision);
-    pRsp->blockNum++;
-    totalRows += pDataBlock->info.rows;
-  }
-
-  tqDebug("vgId:%d, tq handle push, subkey:%s, block num:%d, rows:%d", vgId, pPushEntry->subKey, pRsp->blockNum,
-          totalRows);
-
-  if (pRsp->blockNum > 0) {
-    tqOffsetResetToLog(&pRsp->rspOffset, ver);
-    tqPushDataRsp(pPushEntry, vgId);
-    recordPushedEntry(pCachedKey, pIter);
-  }
-}
-
 int32_t tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver) {
-  void*   pReq = POINTER_SHIFT(msg, sizeof(SSubmitReq2Msg));
-  int32_t len = msgLen - sizeof(SSubmitReq2Msg);
-  int32_t vgId = TD_VID(pTq->pVnode);
 
   if (msgType == TDMT_VND_SUBMIT) {
-    // lock push mgr to avoid potential msg lost
-    taosWLockLatch(&pTq->lock);
-
-    int32_t numOfRegisteredPush = taosHashGetSize(pTq->pPushMgr);
-    if (numOfRegisteredPush > 0) {
-      tqDebug("vgId:%d tq push msg version:%" PRId64 " type:%s, head:%p, body:%p len:%d, numOfPushed consumers:%d",
-              vgId, ver, TMSG_INFO(msgType), msg, pReq, len, numOfRegisteredPush);
-
-      void* data = taosMemoryMalloc(len);
-      if (data == NULL) {
-        terrno = TSDB_CODE_OUT_OF_MEMORY;
-        tqError("failed to copy data for stream since out of memory, vgId:%d", vgId);
-        taosWUnLockLatch(&pTq->lock);
-        return -1;
-      }
-
-      memcpy(data, pReq, len);
-
-      SArray* cachedKey = taosArrayInit(0, sizeof(SItem));
-      void*   pIter = NULL;
-
-      while (1) {
-        pIter = taosHashIterate(pTq->pPushMgr, pIter);
-        if (pIter == NULL) {
-          break;
-        }
-
-        STqPushEntry* pPushEntry = *(STqPushEntry**)pIter;
-
-        STqHandle* pHandle = taosHashGet(pTq->pHandle, pPushEntry->subKey, strlen(pPushEntry->subKey));
-        if (pHandle == NULL) {
-          tqDebug("vgId:%d, failed to find handle %s in pushing data to consumer, ignore", pTq->pVnode->config.vgId,
-                  pPushEntry->subKey);
-          continue;
-        }
-
-        STqExecHandle* pExec = &pHandle->execHandle;
-        doPushDataForEntry(pIter, pExec, pTq, ver, vgId, data, len, cachedKey);
-      }
-
-      doRemovePushedEntry(cachedKey, pTq);
-      taosArrayDestroyEx(cachedKey, freeItem);
-      taosMemoryFree(data);
-    }
-
-    // unlock
-    taosWUnLockLatch(&pTq->lock);
+    tqProcessSubmitReqForSubscribe(pTq);
   }
 
-  tqDebug("handle submit, restore:%d, size:%d", pTq->pVnode->restored, (int)taosHashGetSize(pTq->pStreamMeta->pTasks));
+  int32_t numOfTasks = streamMetaGetNumOfTasks(pTq->pStreamMeta);
+  tqDebug("handle submit, restore:%d, size:%d", pTq->pVnode->restored, numOfTasks);
 
   // push data for stream processing:
   // 1. the vnode has already been restored.
   // 2. the vnode should be the leader.
   // 3. the stream is not suspended yet.
   if (!tsDisableStream && vnodeIsRoleLeader(pTq->pVnode) && pTq->pVnode->restored) {
-    if (taosHashGetSize(pTq->pStreamMeta->pTasks) == 0) {
+    if (numOfTasks == 0) {
       return 0;
     }
 
     if (msgType == TDMT_VND_SUBMIT) {
-#if 0
-      void* data = taosMemoryMalloc(len);
-      if (data == NULL) {
-        // todo: for all stream in this vnode, keep this offset in the offset files, and wait for a moment, and then retry
-        terrno = TSDB_CODE_OUT_OF_MEMORY;
-        tqError("vgId:%d, failed to copy submit data for stream processing, since out of memory", vgId);
-        return -1;
-      }
-
-      memcpy(data, pReq, len);
-      SPackedData submit = {.msgStr = data, .msgLen = len, .ver = ver};
-
-      tqDebug("vgId:%d tq copy submit msg:%p len:%d ver:%" PRId64 " from %p for stream", vgId, data, len, ver, pReq);
-      tqProcessSubmitReq(pTq, submit);
-#endif
-      SPackedData submit = {0};
-      tqProcessSubmitReq(pTq, submit);
+      tqStartStreamTasks(pTq);
     }
 
     if (msgType == TDMT_VND_DELETE) {
@@ -362,85 +46,43 @@ int32_t tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t v
   return 0;
 }
 
-int32_t tqRegisterPushHandle(STQ* pTq, void* pHandle, const SMqPollReq* pRequest, SRpcMsg* pRpcMsg, SMqDataRsp* pDataRsp,
-                            int32_t type) {
-  uint64_t   consumerId = pRequest->consumerId;
+int32_t tqRegisterPushHandle(STQ* pTq, void* handle, SRpcMsg* pMsg) {
   int32_t    vgId = TD_VID(pTq->pVnode);
-  STqHandle* pTqHandle = pHandle;
+  STqHandle* pHandle = (STqHandle*)handle;
 
-  STqPushEntry* pPushEntry = taosMemoryCalloc(1, sizeof(STqPushEntry));
-  if (pPushEntry == NULL) {
-    tqDebug("tmq poll: consumer:0x%" PRIx64 ", vgId:%d failed to malloc, size:%d", consumerId, vgId,
-            (int32_t)sizeof(STqPushEntry));
-    terrno = TSDB_CODE_OUT_OF_MEMORY;
-    return -1;
+  if (pHandle->msg == NULL) {
+    pHandle->msg = taosMemoryCalloc(1, sizeof(SRpcMsg));
+    memcpy(pHandle->msg, pMsg, sizeof(SRpcMsg));
+    pHandle->msg->pCont = rpcMallocCont(pMsg->contLen);
+  } else {
+    tqPushDataRsp(pHandle, vgId);
+    void* tmp = pHandle->msg->pCont;
+    memcpy(pHandle->msg, pMsg, sizeof(SRpcMsg));
+    pHandle->msg->pCont = tmp;
   }
 
-  pPushEntry->pHandle = pHandle;
-  pPushEntry->info = pRpcMsg->info;
-  memcpy(pPushEntry->subKey, pTqHandle->subKey, TSDB_SUBSCRIBE_KEY_LEN);
-
-  if (type == TMQ_MSG_TYPE__TAOSX_RSP) {
-    pPushEntry->pDataRsp = taosMemoryCalloc(1, sizeof(STaosxRsp));
-    memcpy(pPushEntry->pDataRsp, pDataRsp, sizeof(STaosxRsp));
-  } else if (type == TMQ_MSG_TYPE__POLL_RSP) {
-    pPushEntry->pDataRsp = taosMemoryCalloc(1, sizeof(SMqDataRsp));
-    memcpy(pPushEntry->pDataRsp, pDataRsp, sizeof(SMqDataRsp));
-  }
-
-  SMqRspHead* pHead = &pPushEntry->pDataRsp->head;
-
-  pHead->consumerId = consumerId;
-  pHead->epoch = pRequest->epoch;
-  pHead->mqMsgType = type;
-
-  taosHashPut(pTq->pPushMgr, pTqHandle->subKey, strlen(pTqHandle->subKey), &pPushEntry, sizeof(void*));
-
-  tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s offset:%" PRId64 ", vgId:%d save handle to push mgr, total:%d",
-          consumerId, pTqHandle->subKey, pDataRsp->reqOffset.version, vgId, taosHashGetSize(pTq->pPushMgr));
+  memcpy(pHandle->msg->pCont, pMsg->pCont, pMsg->contLen);
+  pHandle->msg->contLen = pMsg->contLen;
+  int32_t ret = taosHashPut(pTq->pPushMgr, pHandle->subKey, strlen(pHandle->subKey), &pHandle, POINTER_BYTES);
+  tqDebug("vgId:%d data is over, ret:%d, consumerId:0x%" PRIx64 ", register to pHandle:%p, pCont:%p, len:%d", vgId, ret,
+          pHandle->consumerId, pHandle, pHandle->msg->pCont, pHandle->msg->contLen);
   return 0;
 }
 
-int32_t tqUnregisterPushHandle(STQ* pTq, const char* pKey, int32_t keyLen, uint64_t consumerId, bool rspConsumer) {
-  int32_t        vgId = TD_VID(pTq->pVnode);
-  STqPushEntry** pEntry = taosHashGet(pTq->pPushMgr, pKey, keyLen);
+int32_t tqUnregisterPushHandle(STQ* pTq, void *handle) {
+  STqHandle *pHandle = (STqHandle*)handle;
+  int32_t    vgId = TD_VID(pTq->pVnode);
 
-  if (pEntry != NULL) {
-    uint64_t cId = (*pEntry)->pDataRsp->head.consumerId;
-    ASSERT(consumerId == cId);
+  int32_t ret = taosHashRemove(pTq->pPushMgr, pHandle->subKey, strlen(pHandle->subKey));
+  tqError("vgId:%d remove pHandle:%p,ret:%d consumer Id:0x%" PRIx64, vgId, pHandle, ret, pHandle->consumerId);
 
-    tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s vgId:%d remove from push mgr, remains:%d", consumerId,
-            (*pEntry)->subKey, vgId, taosHashGetSize(pTq->pPushMgr) - 1);
+  if(pHandle->msg != NULL) {
+    tqPushDataRsp(pHandle, vgId);
 
-    if (rspConsumer) {  // rsp the old consumer with empty block.
-      tqPushDataRsp(*pEntry, vgId);
-    }
-
-    taosHashRemove(pTq->pPushMgr, pKey, keyLen);
+    rpcFreeCont(pHandle->msg->pCont);
+    taosMemoryFree(pHandle->msg);
+    pHandle->msg = NULL;
   }
 
   return 0;
 }
-
-void recordPushedEntry(SArray* cachedKey, void* pIter) {
-  size_t kLen = 0;
-  void*  key = taosHashGetKey(pIter, &kLen);
-  SItem  item = {.pKey = strndup(key, kLen), .keyLen = kLen};
-  taosArrayPush(cachedKey, &item);
-}
-
-void doRemovePushedEntry(SArray* pCachedKeys, STQ* pTq) {
-  int32_t vgId = TD_VID(pTq->pVnode);
-  int32_t numOfKeys = (int32_t)taosArrayGetSize(pCachedKeys);
-
-  for (int32_t i = 0; i < numOfKeys; i++) {
-    SItem* pItem = taosArrayGet(pCachedKeys, i);
-    if (taosHashRemove(pTq->pPushMgr, pItem->pKey, pItem->keyLen) != 0) {
-      tqError("vgId:%d, tq push hash remove key error, key: %s", vgId, (char*)pItem->pKey);
-    }
-  }
-
-  if (numOfKeys > 0) {
-    tqDebug("vgId:%d, pushed %d items and remain:%d", vgId, numOfKeys, (int32_t)taosHashGetSize(pTq->pPushMgr));
-  }
-}
diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c
index 25ab7209d2..1fbdb25528 100644
--- a/source/dnode/vnode/src/tq/tqRead.c
+++ b/source/dnode/vnode/src/tq/tqRead.c
@@ -13,6 +13,7 @@
  * along with this program. If not, see .
  */
 
+#include "tmsg.h"
 #include "tq.h"
 
 bool isValValidForTable(STqHandle* pHandle, SWalCont* pHead) {
@@ -249,7 +250,7 @@ END:
   return code;
 }
 
-STqReader* tqOpenReader(SVnode* pVnode) {
+STqReader* tqReaderOpen(SVnode* pVnode) {
   STqReader* pReader = taosMemoryCalloc(1, sizeof(STqReader));
   if (pReader == NULL) {
     return NULL;
@@ -265,9 +266,9 @@ STqReader* tqOpenReader(SVnode* pVnode) {
   pReader->pColIdList = NULL;
   pReader->cachedSchemaVer = 0;
   pReader->cachedSchemaSuid = 0;
-  pReader->pSchema = NULL;
   pReader->pSchemaWrapper = NULL;
   pReader->tbIdHash = NULL;
+  pReader->pResBlock = createDataBlock();
   return pReader;
 }
 
@@ -276,19 +277,19 @@ void tqCloseReader(STqReader* pReader) {
   if (pReader->pWalReader) {
     walCloseReader(pReader->pWalReader);
   }
-  // free cached schema
-  if (pReader->pSchema) {
-    taosMemoryFree(pReader->pSchema);
-  }
+
   if (pReader->pSchemaWrapper) {
-    tDeleteSSchemaWrapper(pReader->pSchemaWrapper);
+    tDeleteSchemaWrapper(pReader->pSchemaWrapper);
   }
+
   if (pReader->pColIdList) {
     taosArrayDestroy(pReader->pColIdList);
   }
+
   // free hash
+  blockDataDestroy(pReader->pResBlock);
   taosHashCleanup(pReader->tbIdHash);
-  tDestroySSubmitReq2(&pReader->submit, TSDB_MSG_FLG_DECODE);
+  tDestroySubmitReq(&pReader->submit, TSDB_MSG_FLG_DECODE);
   taosMemoryFree(pReader);
 }
 
@@ -322,60 +323,111 @@ int32_t extractSubmitMsgFromWal(SWalReader* pReader, SPackedData* pPackedData) {
   return 0;
 }
 
-void tqNextBlock(STqReader* pReader, SFetchRet* ret) {
-  while (1) {
-    if (pReader->msg2.msgStr == NULL) {
-      if (walNextValidMsg(pReader->pWalReader) < 0) {
-        ret->fetchType = FETCH_TYPE__NONE;
-        return;
+// todo ignore the error in wal?
+int32_t tqNextBlockInWal(STqReader* pReader) {
+  SWalReader* pWalReader = pReader->pWalReader;
+
+  while(1) {
+    SArray* pBlockList = pReader->submit.aSubmitTbData;
+    if (pBlockList == NULL || pReader->nextBlk >= taosArrayGetSize(pBlockList)) {
+
+      // try next message in wal file
+      // todo always retry to avoid read failure caused by wal file deletion
+      if (walNextValidMsg(pWalReader) < 0) {
+        return FETCH_TYPE__NONE;
       }
 
-      void*   pBody = POINTER_SHIFT(pReader->pWalReader->pHead->head.body, sizeof(SSubmitReq2Msg));
-      int32_t bodyLen = pReader->pWalReader->pHead->head.bodyLen - sizeof(SSubmitReq2Msg);
-      int64_t ver = pReader->pWalReader->pHead->head.version;
+      void*   pBody = POINTER_SHIFT(pWalReader->pHead->head.body, sizeof(SSubmitReq2Msg));
+      int32_t bodyLen = pWalReader->pHead->head.bodyLen - sizeof(SSubmitReq2Msg);
+      int64_t ver = pWalReader->pHead->head.version;
 
-      tqReaderSetSubmitMsg(pReader, pBody, bodyLen, ver);
-    }
+      SDecoder decoder = {0};
+      tDecoderInit(&decoder, pBody, bodyLen);
 
-    while (tqNextDataBlock(pReader)) {
-      memset(&ret->data, 0, sizeof(SSDataBlock));
-      int32_t code = tqRetrieveDataBlock2(&ret->data, pReader, NULL);
-      if (code != 0 || ret->data.info.rows == 0) {
-        continue;
+      {
+        int32_t nSubmitTbData = taosArrayGetSize(pReader->submit.aSubmitTbData);
+        for (int32_t i = 0; i < nSubmitTbData; i++) {
+          SSubmitTbData* pData = taosArrayGet(pReader->submit.aSubmitTbData, i);
+          if (pData->pCreateTbReq != NULL) {
+            taosArrayDestroy(pData->pCreateTbReq->ctb.tagName);
+            taosMemoryFreeClear(pData->pCreateTbReq);
+          }
+          pData->aRowP = taosArrayDestroy(pData->aRowP);
+        }
+        pReader->submit.aSubmitTbData = taosArrayDestroy(pReader->submit.aSubmitTbData);
       }
 
-      ret->fetchType = FETCH_TYPE__DATA;
-      return;
+      if (tDecodeSubmitReq(&decoder, &pReader->submit) < 0) {
+        tDecoderClear(&decoder);
+        tqError("decode wal file error, msgLen:%d, ver:%"PRId64, bodyLen, ver);
+        return FETCH_TYPE__NONE;
+      }
+
+      tDecoderClear(&decoder);
+      pReader->nextBlk = 0;
     }
+
+    size_t numOfBlocks = taosArrayGetSize(pReader->submit.aSubmitTbData);
+    while (pReader->nextBlk < numOfBlocks) {
+      tqDebug("tq reader next data block %p, %d %" PRId64 " %d", pReader->msg.msgStr, pReader->msg.msgLen,
+              pReader->msg.ver, pReader->nextBlk);
+
+      SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
+
+      if (pReader->tbIdHash == NULL) {
+        int32_t code = tqRetrieveDataBlock(pReader, NULL);
+        if (code == TSDB_CODE_SUCCESS && pReader->pResBlock->info.rows > 0) {
+          return FETCH_TYPE__DATA;
+        }
+      }
+
+      void* ret = taosHashGet(pReader->tbIdHash, &pSubmitTbData->uid, sizeof(int64_t));
+      if (ret != NULL) {
+        tqDebug("tq reader return submit block, uid:%"PRId64", ver:%"PRId64, pSubmitTbData->uid, pReader->msg.ver);
+
+        int32_t code = tqRetrieveDataBlock(pReader, NULL);
+        if (code == TSDB_CODE_SUCCESS && pReader->pResBlock->info.rows > 0) {
+          return FETCH_TYPE__DATA;
+        }
+      } else {
+        pReader->nextBlk += 1;
+        tqDebug("tq reader discard submit block, uid:%"PRId64", continue", pSubmitTbData->uid);
+      }
+    }
+
+    tDestroySubmitReq(&pReader->submit, TSDB_MSG_FLG_DECODE);
+    pReader->msg.msgStr = NULL;
   }
 }
 
 int32_t tqReaderSetSubmitMsg(STqReader* pReader, void* msgStr, int32_t msgLen, int64_t ver) {
-  pReader->msg2.msgStr = msgStr;
-  pReader->msg2.msgLen = msgLen;
-  pReader->msg2.ver = ver;
+  pReader->msg.msgStr = msgStr;
+  pReader->msg.msgLen = msgLen;
+  pReader->msg.ver = ver;
 
   tqDebug("tq reader set msg %p %d", msgStr, msgLen);
   SDecoder decoder;
-  tDecoderInit(&decoder, pReader->msg2.msgStr, pReader->msg2.msgLen);
-  if (tDecodeSSubmitReq2(&decoder, &pReader->submit) < 0) {
+
+  tDecoderInit(&decoder, pReader->msg.msgStr, pReader->msg.msgLen);
+  if (tDecodeSubmitReq(&decoder, &pReader->submit) < 0) {
     tDecoderClear(&decoder);
     tqError("DecodeSSubmitReq2 error, msgLen:%d, ver:%"PRId64, msgLen, ver);
     return -1;
   }
+
   tDecoderClear(&decoder);
   return 0;
 }
 
-bool tqNextDataBlock(STqReader* pReader) {
-  if (pReader->msg2.msgStr == NULL) {
+bool tqNextBlockImpl(STqReader* pReader) {
+  if (pReader->msg.msgStr == NULL) {
     return false;
   }
 
   int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
   while (pReader->nextBlk < blockSz) {
-    tqDebug("tq reader next data block %p, %d %" PRId64 " %d", pReader->msg2.msgStr, pReader->msg2.msgLen,
-            pReader->msg2.ver, pReader->nextBlk);
+    tqDebug("tq reader next data block %p, %d %" PRId64 " %d", pReader->msg.msgStr, pReader->msg.msgLen,
+            pReader->msg.ver, pReader->nextBlk);
 
     SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
     if (pReader->tbIdHash == NULL) {
@@ -384,24 +436,24 @@ bool tqNextDataBlock(STqReader* pReader) {
 
     void* ret = taosHashGet(pReader->tbIdHash, &pSubmitTbData->uid, sizeof(int64_t));
     if (ret != NULL) {
-      tqDebug("tq reader block found, ver:%"PRId64", uid:%"PRId64, pReader->msg2.ver, pSubmitTbData->uid);
+      tqDebug("tq reader block found, ver:%"PRId64", uid:%"PRId64, pReader->msg.ver, pSubmitTbData->uid);
       return true;
     } else {
-      tqDebug("tq reader discard block, uid:%"PRId64", continue", pSubmitTbData->uid);
+      tqDebug("tq reader discard submit block, uid:%"PRId64", continue", pSubmitTbData->uid);
     }
 
     pReader->nextBlk++;
   }
 
-  tDestroySSubmitReq2(&pReader->submit, TSDB_MSG_FLG_DECODE);
+  tDestroySubmitReq(&pReader->submit, TSDB_MSG_FLG_DECODE);
   pReader->nextBlk = 0;
-  pReader->msg2.msgStr = NULL;
+  pReader->msg.msgStr = NULL;
 
   return false;
 }
 
-bool tqNextDataBlockFilterOut2(STqReader* pReader, SHashObj* filterOutUids) {
-  if (pReader->msg2.msgStr == NULL) return false;
+bool tqNextDataBlockFilterOut(STqReader* pReader, SHashObj* filterOutUids) {
+  if (pReader->msg.msgStr == NULL) return false;
 
   int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
   while (pReader->nextBlk < blockSz) {
@@ -415,9 +467,9 @@ bool tqNextDataBlockFilterOut2(STqReader* pReader, SHashObj* filterOutUids) {
     pReader->nextBlk++;
   }
 
-  tDestroySSubmitReq2(&pReader->submit, TSDB_MSG_FLG_DECODE);
+  tDestroySubmitReq(&pReader->submit, TSDB_MSG_FLG_DECODE);
   pReader->nextBlk = 0;
-  pReader->msg2.msgStr = NULL;
+  pReader->msg.msgStr = NULL;
 
   return false;
 }
@@ -451,212 +503,219 @@ int32_t tqMaskBlock(SSchemaWrapper* pDst, SSDataBlock* pBlock, const SSchemaWrap
   return 0;
 }
 
-int32_t tqRetrieveDataBlock2(SSDataBlock* pBlock, STqReader* pReader, SSubmitTbData** pSubmitTbDataRet) {
-  tqDebug("tq reader retrieve data block %p, index:%d", pReader->msg2.msgStr, pReader->nextBlk);
-  SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
-  pReader->nextBlk++;
+int32_t tqRetrieveDataBlock(STqReader* pReader, SSubmitTbData** pSubmitTbDataRet) {
+  tqDebug("tq reader retrieve data block %p, index:%d", pReader->msg.msgStr, pReader->nextBlk);
 
+  SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk++);
   if (pSubmitTbDataRet) {
     *pSubmitTbDataRet = pSubmitTbData;
   }
 
+  SSDataBlock* pBlock = pReader->pResBlock;
+  blockDataCleanup(pBlock);
+
   int32_t sversion = pSubmitTbData->sver;
   int64_t suid = pSubmitTbData->suid;
   int64_t uid = pSubmitTbData->uid;
   pReader->lastBlkUid = uid;
 
   pBlock->info.id.uid = uid;
-  pBlock->info.version = pReader->msg2.ver;
+  pBlock->info.version = pReader->msg.ver;
 
-  if (pReader->cachedSchemaSuid == 0 || pReader->cachedSchemaVer != sversion || pReader->cachedSchemaSuid != suid) {
-    taosMemoryFree(pReader->pSchema);
-    pReader->pSchema = metaGetTbTSchema(pReader->pVnodeMeta, uid, sversion, 1);
-    if (pReader->pSchema == NULL) {
-      tqWarn("vgId:%d, cannot found tsschema for table: uid:%" PRId64 " (suid:%" PRId64
-             "), version %d, possibly dropped table",
-             pReader->pWalReader->pWal->cfg.vgId, uid, suid, sversion);
-      pReader->cachedSchemaSuid = 0;
-      terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
-      return -1;
-    }
+  if ((suid != 0 && pReader->cachedSchemaSuid != suid) || (suid == 0 && pReader->cachedSchemaUid != uid) || (pReader->cachedSchemaVer != sversion)) {
+    tDeleteSchemaWrapper(pReader->pSchemaWrapper);
 
-    tDeleteSSchemaWrapper(pReader->pSchemaWrapper);
     pReader->pSchemaWrapper = metaGetTableSchema(pReader->pVnodeMeta, uid, sversion, 1);
     if (pReader->pSchemaWrapper == NULL) {
-      tqWarn("vgId:%d, cannot found schema wrapper for table: suid:%" PRId64 ", version %d, possibly dropped table",
-             pReader->pWalReader->pWal->cfg.vgId, uid, pReader->cachedSchemaVer);
+      tqWarn("vgId:%d, cannot found schema wrapper for table: suid:%" PRId64 ", uid:%" PRId64 "version %d, possibly dropped table",
+             pReader->pWalReader->pWal->cfg.vgId, suid, uid, pReader->cachedSchemaVer);
       pReader->cachedSchemaSuid = 0;
       terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
       return -1;
     }
 
-    STSchema*       pTschema = pReader->pSchema;
+    pReader->cachedSchemaUid = uid;
+    pReader->cachedSchemaSuid = suid;
+    pReader->cachedSchemaVer = sversion;
+
     SSchemaWrapper* pSchemaWrapper = pReader->pSchemaWrapper;
+    if (blockDataGetNumOfCols(pBlock) > 0) {
+      blockDataDestroy(pReader->pResBlock);
+      pReader->pResBlock = createDataBlock();
+      pBlock = pReader->pResBlock;
 
-    int32_t colNumNeed = taosArrayGetSize(pReader->pColIdList);
+      pBlock->info.id.uid = uid;
+      pBlock->info.version = pReader->msg.ver;
+    }
 
-    if (colNumNeed == 0) {
-      int32_t colMeta = 0;
-      while (colMeta < pSchemaWrapper->nCols) {
-        SSchema*        pColSchema = &pSchemaWrapper->pSchema[colMeta];
+    int32_t numOfCols = taosArrayGetSize(pReader->pColIdList);
+    if (numOfCols == 0) {  // all columns are required
+      for (int32_t i = 0; i < pSchemaWrapper->nCols; ++i) {
+        SSchema*        pColSchema = &pSchemaWrapper->pSchema[i];
         SColumnInfoData colInfo = createColumnInfoData(pColSchema->type, pColSchema->bytes, pColSchema->colId);
-        int32_t         code = blockDataAppendColInfo(pBlock, &colInfo);
+
+        int32_t code = blockDataAppendColInfo(pBlock, &colInfo);
         if (code != TSDB_CODE_SUCCESS) {
-          goto FAIL;
+          blockDataFreeRes(pBlock);
+          return -1;
         }
-        colMeta++;
       }
     } else {
-      if (colNumNeed > pSchemaWrapper->nCols) {
-        colNumNeed = pSchemaWrapper->nCols;
+      if (numOfCols > pSchemaWrapper->nCols) {
+        numOfCols = pSchemaWrapper->nCols;
       }
 
-      int32_t colMeta = 0;
-      int32_t colNeed = 0;
-      while (colMeta < pSchemaWrapper->nCols && colNeed < colNumNeed) {
-        SSchema* pColSchema = &pSchemaWrapper->pSchema[colMeta];
+      int32_t i = 0;
+      int32_t j = 0;
+      while (i < pSchemaWrapper->nCols && j < numOfCols) {
+        SSchema* pColSchema = &pSchemaWrapper->pSchema[i];
         col_id_t colIdSchema = pColSchema->colId;
-        col_id_t colIdNeed = *(col_id_t*)taosArrayGet(pReader->pColIdList, colNeed);
+
+        col_id_t colIdNeed = *(col_id_t*)taosArrayGet(pReader->pColIdList, j);
         if (colIdSchema < colIdNeed) {
-          colMeta++;
+          i++;
         } else if (colIdSchema > colIdNeed) {
-          colNeed++;
+          j++;
         } else {
           SColumnInfoData colInfo = createColumnInfoData(pColSchema->type, pColSchema->bytes, pColSchema->colId);
           int32_t         code = blockDataAppendColInfo(pBlock, &colInfo);
           if (code != TSDB_CODE_SUCCESS) {
-            goto FAIL;
+            return -1;
           }
-          colMeta++;
-          colNeed++;
+          i++;
+          j++;
         }
       }
     }
+  }
 
-    int32_t numOfRows = 0;
+  int32_t numOfRows = 0;
+  if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
+    SColData* pCol = taosArrayGet(pSubmitTbData->aCol, 0);
+    numOfRows = pCol->nVal;
+  } else {
+    numOfRows = taosArrayGetSize(pSubmitTbData->aRowP);
+  }
 
-    if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
-      SArray*   pCols = pSubmitTbData->aCol;
-      SColData* pCol = taosArrayGet(pCols, 0);
-      numOfRows = pCol->nVal;
-    } else {
-      SArray* pRows = pSubmitTbData->aRowP;
-      numOfRows = taosArrayGetSize(pRows);
+  if (blockDataEnsureCapacity(pBlock, numOfRows) < 0) {
+    terrno = TSDB_CODE_OUT_OF_MEMORY;
+    return -1;
+  }
+
+  pBlock->info.rows = numOfRows;
+
+  int32_t colActual = blockDataGetNumOfCols(pBlock);
+
+  // convert and scan one block
+  if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
+    SArray* pCols = pSubmitTbData->aCol;
+    int32_t numOfCols = taosArrayGetSize(pCols);
+    int32_t targetIdx = 0;
+    int32_t sourceIdx = 0;
+    while (targetIdx < colActual) {
+      if (sourceIdx >= numOfCols) {
+        tqError("tqRetrieveDataBlock sourceIdx:%d >= numOfCols:%d", sourceIdx, numOfCols);
+        return -1;
+      }
+
+      SColData*        pCol = taosArrayGet(pCols, sourceIdx);
+      SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
+      SColVal          colVal;
+
+      if (pCol->nVal != numOfRows) {
+        tqError("tqRetrieveDataBlock pCol->nVal:%d != numOfRows:%d", pCol->nVal, numOfRows);
+        return -1;
+      }
+
+      if (pCol->cid < pColData->info.colId) {
+        sourceIdx++;
+      } else if (pCol->cid == pColData->info.colId) {
+        for (int32_t i = 0; i < pCol->nVal; i++) {
+          tColDataGetValue(pCol, i, &colVal);
+          if (IS_STR_DATA_TYPE(colVal.type)) {
+            if (colVal.value.pData != NULL) {
+              char val[65535 + 2] = {0};
+              memcpy(varDataVal(val), colVal.value.pData, colVal.value.nData);
+              varDataSetLen(val, colVal.value.nData);
+              if (colDataAppend(pColData, i, val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
+                return -1;
+              }
+            } else {
+              colDataSetNULL(pColData, i);
+            }
+          } else {
+            if (colDataAppend(pColData, i, (void*)&colVal.value.val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
+              return -1;
+            }
+          }
+        }
+        sourceIdx++;
+        targetIdx++;
+      } else {
+        for (int32_t i = 0; i < pCol->nVal; i++) {
+          colDataSetNULL(pColData, i);
+        }
+
+        targetIdx++;
+      }
     }
+  } else {
+    SArray*         pRows = pSubmitTbData->aRowP;
+    SSchemaWrapper* pWrapper = pReader->pSchemaWrapper;
+    STSchema*       pTSchema = tBuildTSchema(pWrapper->pSchema, pWrapper->nCols, pWrapper->version);
 
-    if (blockDataEnsureCapacity(pBlock, numOfRows) < 0) {
-      terrno = TSDB_CODE_OUT_OF_MEMORY;
-      goto FAIL;
-    }
-    pBlock->info.rows = numOfRows;
-
-    int32_t colActual = blockDataGetNumOfCols(pBlock);
-
-    // convert and scan one block
-    if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
-      SArray* pCols = pSubmitTbData->aCol;
-      int32_t numOfCols = taosArrayGetSize(pCols);
-      int32_t targetIdx = 0;
+    for (int32_t i = 0; i < numOfRows; i++) {
+      SRow*   pRow = taosArrayGetP(pRows, i);
       int32_t sourceIdx = 0;
-      while (targetIdx < colActual) {
-        if(sourceIdx >= numOfCols){
-          tqError("tqRetrieveDataBlock2 sourceIdx:%d >= numOfCols:%d", sourceIdx, numOfCols);
-          goto FAIL;
-        }
-        SColData*        pCol = taosArrayGet(pCols, sourceIdx);
-        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
-        SColVal          colVal;
 
-        if(pCol->nVal != numOfRows){
-          tqError("tqRetrieveDataBlock2 pCol->nVal:%d != numOfRows:%d", pCol->nVal, numOfRows);
-          goto FAIL;
-        }
+      for (int32_t j = 0; j < colActual; j++) {
+        SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, j);
+        while (1) {
+          SColVal colVal;
+          tqDebug("start to extract column id:%d, index:%d", pColData->info.colId, sourceIdx);
 
-        if (pCol->cid < pColData->info.colId) {
-          sourceIdx++;
-        } else if (pCol->cid == pColData->info.colId) {
-          for (int32_t i = 0; i < pCol->nVal; i++) {
-            tColDataGetValue(pCol, i, &colVal);
+          tRowGet(pRow, pTSchema, sourceIdx, &colVal);
+          if (colVal.cid < pColData->info.colId) {
+            tqDebug("colIndex:%d column id:%d in row, ignore, the required colId:%d, total cols in schema:%d",
+                    sourceIdx, colVal.cid, pColData->info.colId, pTSchema->numOfCols);
+            sourceIdx++;
+            continue;
+          } else if (colVal.cid == pColData->info.colId) {
             if (IS_STR_DATA_TYPE(colVal.type)) {
               if (colVal.value.pData != NULL) {
                 char val[65535 + 2] = {0};
                 memcpy(varDataVal(val), colVal.value.pData, colVal.value.nData);
                 varDataSetLen(val, colVal.value.nData);
                 if (colDataAppend(pColData, i, val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
-                  goto FAIL;
+                  return -1;
                 }
               } else {
                 colDataSetNULL(pColData, i);
               }
             } else {
               if (colDataAppend(pColData, i, (void*)&colVal.value.val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
-                goto FAIL;
+                return -1;
               }
             }
-          }
-          sourceIdx++;
-          targetIdx++;
-        } else {
-          for (int32_t i = 0; i < pCol->nVal; i++) {
+
+            sourceIdx++;
+            break;
+          } else {
             colDataSetNULL(pColData, i);
-          }
-          targetIdx++;
-        }
-      }
-    } else {
-      SArray* pRows = pSubmitTbData->aRowP;
-
-      for (int32_t i = 0; i < numOfRows; i++) {
-        SRow*   pRow = taosArrayGetP(pRows, i);
-        int32_t sourceIdx = 0;
-
-        for (int32_t j = 0; j < colActual; j++) {
-          SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, j);
-          while (1) {
-            SColVal colVal;
-            tRowGet(pRow, pTschema, sourceIdx, &colVal);
-            if (colVal.cid < pColData->info.colId) {
-              sourceIdx++;
-              continue;
-            } else if (colVal.cid == pColData->info.colId) {
-              if (IS_STR_DATA_TYPE(colVal.type)) {
-                if (colVal.value.pData != NULL) {
-                  char val[65535 + 2] = {0};
-                  memcpy(varDataVal(val), colVal.value.pData, colVal.value.nData);
-                  varDataSetLen(val, colVal.value.nData);
-                  if (colDataAppend(pColData, i, val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
-                    goto FAIL;
-                  }
-                } else {
-                  colDataSetNULL(pColData, i);
-                }
-              } else {
-                if (colDataAppend(pColData, i, (void*)&colVal.value.val, !COL_VAL_IS_VALUE(&colVal)) < 0) {
-                  goto FAIL;
-                }
-              }
-
-              sourceIdx++;
-              break;
-            } else {
-              colDataSetNULL(pColData, i);
-              break;
-            }
+            break;
           }
         }
       }
     }
+
+    taosMemoryFreeClear(pTSchema);
   }
 
   return 0;
-
-FAIL:
-  blockDataFreeRes(pBlock);
-  return -1;
 }
 
-int32_t tqRetrieveTaosxBlock2(STqReader* pReader, SArray* blocks, SArray* schemas, SSubmitTbData** pSubmitTbDataRet) {
-  tqDebug("tq reader retrieve data block %p, %d", pReader->msg2.msgStr, pReader->nextBlk);
+int32_t tqRetrieveTaosxBlock(STqReader* pReader, SArray* blocks, SArray* schemas, SSubmitTbData** pSubmitTbDataRet) {
+  tqDebug("tq reader retrieve data block %p, %d", pReader->msg.msgStr, pReader->nextBlk);
 
   SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
   pReader->nextBlk++;
@@ -667,18 +726,7 @@ int32_t tqRetrieveTaosxBlock2(STqReader* pReader, SArray* blocks, SArray* schema
   int64_t uid = pSubmitTbData->uid;
   pReader->lastBlkUid = uid;
 
-  taosMemoryFree(pReader->pSchema);
-  pReader->pSchema = metaGetTbTSchema(pReader->pVnodeMeta, uid, sversion, 1);
-  if (pReader->pSchema == NULL) {
-    tqWarn("vgId:%d, cannot found tsschema for table: uid:%" PRId64 " (suid:%" PRId64
-           "), version %d, possibly dropped table",
-           pReader->pWalReader->pWal->cfg.vgId, uid, suid, sversion);
-    pReader->cachedSchemaSuid = 0;
-    terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
-    return -1;
-  }
-
-  tDeleteSSchemaWrapper(pReader->pSchemaWrapper);
+  tDeleteSchemaWrapper(pReader->pSchemaWrapper);
   pReader->pSchemaWrapper = metaGetTableSchema(pReader->pVnodeMeta, uid, sversion, 1);
   if (pReader->pSchemaWrapper == NULL) {
     tqWarn("vgId:%d, cannot found schema wrapper for table: suid:%" PRId64 ", version %d, possibly dropped table",
@@ -688,7 +736,6 @@ int32_t tqRetrieveTaosxBlock2(STqReader* pReader, SArray* blocks, SArray* schema
     return -1;
   }
 
-  STSchema*       pTschema = pReader->pSchema;
   SSchemaWrapper* pSchemaWrapper = pReader->pSchemaWrapper;
   int32_t         numOfRows = 0;
 
@@ -745,18 +792,18 @@ int32_t tqRetrieveTaosxBlock2(STqReader* pReader, SArray* blocks, SArray* schema
 
         if (tqMaskBlock(pSW, &block, pSchemaWrapper, assigned) < 0) {
           blockDataFreeRes(&block);
-          tDeleteSSchemaWrapper(pSW);
+          tDeleteSchemaWrapper(pSW);
           goto FAIL;
         }
         tqDebug("vgId:%d, build new block, col %d", pReader->pWalReader->pWal->cfg.vgId,
                 (int32_t)taosArrayGetSize(block.pDataBlock));
 
         block.info.id.uid = uid;
-        block.info.version = pReader->msg2.ver;
+        block.info.version = pReader->msg.ver;
         if (blockDataEnsureCapacity(&block, numOfRows - curRow) < 0) {
           terrno = TSDB_CODE_OUT_OF_MEMORY;
           blockDataFreeRes(&block);
-          tDeleteSSchemaWrapper(pSW);
+          tDeleteSchemaWrapper(pSW);
           goto FAIL;
         }
         taosArrayPush(blocks, &block);
@@ -805,14 +852,17 @@ int32_t tqRetrieveTaosxBlock2(STqReader* pReader, SArray* blocks, SArray* schema
       curRow++;
     }
   } else {
+    SSchemaWrapper* pWrapper = pReader->pSchemaWrapper;
+    STSchema* pTSchema = tBuildTSchema(pWrapper->pSchema, pWrapper->nCols, pWrapper->version);
     SArray* pRows = pSubmitTbData->aRowP;
+
     for (int32_t i = 0; i < numOfRows; i++) {
       SRow* pRow = taosArrayGetP(pRows, i);
       bool  buildNew = false;
 
-      for (int32_t j = 0; j < pTschema->numOfCols; j++) {
+      for (int32_t j = 0; j < pTSchema->numOfCols; j++) {
         SColVal colVal;
-        tRowGet(pRow, pTschema, j, &colVal);
+        tRowGet(pRow, pTSchema, j, &colVal);
         if (curRow == 0) {
           assigned[j] = !COL_VAL_IS_NONE(&colVal);
           buildNew = true;
@@ -841,18 +891,18 @@ int32_t tqRetrieveTaosxBlock2(STqReader* pReader, SArray* blocks, SArray* schema
 
         if (tqMaskBlock(pSW, &block, pSchemaWrapper, assigned) < 0) {
           blockDataFreeRes(&block);
-          tDeleteSSchemaWrapper(pSW);
+          tDeleteSchemaWrapper(pSW);
           goto FAIL;
         }
         tqDebug("vgId:%d, build new block, col %d", pReader->pWalReader->pWal->cfg.vgId,
                 (int32_t)taosArrayGetSize(block.pDataBlock));
 
         block.info.id.uid = uid;
-        block.info.version = pReader->msg2.ver;
+        block.info.version = pReader->msg.ver;
         if (blockDataEnsureCapacity(&block, numOfRows - curRow) < 0) {
           terrno = TSDB_CODE_OUT_OF_MEMORY;
           blockDataFreeRes(&block);
-          tDeleteSSchemaWrapper(pSW);
+          tDeleteSchemaWrapper(pSW);
           goto FAIL;
         }
         taosArrayPush(blocks, &block);
@@ -870,7 +920,7 @@ int32_t tqRetrieveTaosxBlock2(STqReader* pReader, SArray* blocks, SArray* schema
       while (targetIdx < colActual) {
         SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
         SColVal          colVal;
-        tRowGet(pRow, pTschema, sourceIdx, &colVal);
+        tRowGet(pRow, pTSchema, sourceIdx, &colVal);
 
         if (colVal.cid < pColData->info.colId) {
           sourceIdx++;
@@ -897,6 +947,8 @@ int32_t tqRetrieveTaosxBlock2(STqReader* pReader, SArray* blocks, SArray* schema
       }
       curRow++;
     }
+
+    taosMemoryFreeClear(pTSchema);
   }
 
   SSDataBlock* pLastBlock = taosArrayGetLast(blocks);
@@ -1023,6 +1075,7 @@ int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) {
   }
 
   // update the table list handle for each stream scanner/wal reader
+  taosWLockLatch(&pTq->pStreamMeta->lock);
   while (1) {
     pIter = taosHashIterate(pTq->pStreamMeta->pTasks, pIter);
     if (pIter == NULL) {
@@ -1039,5 +1092,6 @@ int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) {
     }
   }
 
+  taosWUnLockLatch(&pTq->pStreamMeta->lock);
   return 0;
 }
diff --git a/source/dnode/vnode/src/tq/tqRestore.c b/source/dnode/vnode/src/tq/tqRestore.c
index 54fcc04b62..0bb33b1215 100644
--- a/source/dnode/vnode/src/tq/tqRestore.c
+++ b/source/dnode/vnode/src/tq/tqRestore.c
@@ -15,100 +15,120 @@
 
 #include "tq.h"
 
-static int32_t streamTaskReplayWal(SStreamMeta* pStreamMeta, STqOffsetStore* pOffsetStore, bool* pScanIdle);
-static int32_t transferToNormalTask(SStreamMeta* pStreamMeta, SArray* pTaskList);
+static int32_t createStreamRunReq(SStreamMeta* pStreamMeta, bool* pScanIdle);
 
 // this function should be executed by stream threads.
-// there is a case that the WAL increases more fast than the restore procedure, and this restore procedure
-// will not stop eventually.
-int tqStreamTasksScanWal(STQ* pTq) {
-  int32_t vgId = TD_VID(pTq->pVnode);
+// extract submit block from WAL, and add them into the input queue for the sources tasks.
+int32_t tqStreamTasksScanWal(STQ* pTq) {
+  int32_t      vgId = TD_VID(pTq->pVnode);
   SStreamMeta* pMeta = pTq->pStreamMeta;
-  int64_t st = taosGetTimestampMs();
+  int64_t      st = taosGetTimestampMs();
 
   while (1) {
-    tqInfo("vgId:%d continue check if data in wal are available", vgId);
+    int32_t scan = pMeta->walScanCounter;
+    tqDebug("vgId:%d continue check if data in wal are available, walScanCounter:%d", vgId, scan);
 
     // check all restore tasks
-    bool allFull = true;
-    streamTaskReplayWal(pTq->pStreamMeta, pTq->pOffsetStore, &allFull);
+    bool shouldIdle = true;
+    createStreamRunReq(pTq->pStreamMeta, &shouldIdle);
 
     int32_t times = 0;
 
-    if (allFull) {
+    if (shouldIdle) {
       taosWLockLatch(&pMeta->lock);
-      pMeta->walScan -= 1;
-      times = pMeta->walScan;
 
-      if (pMeta->walScan <= 0) {
+      pMeta->walScanCounter -= 1;
+      times = pMeta->walScanCounter;
+
+      ASSERT(pMeta->walScanCounter >= 0);
+
+      if (pMeta->walScanCounter <= 0) {
         taosWUnLockLatch(&pMeta->lock);
         break;
       }
 
       taosWUnLockLatch(&pMeta->lock);
-      tqInfo("vgId:%d scan wal for stream tasks for %d times", vgId, times);
+      tqDebug("vgId:%d scan wal for stream tasks for %d times", vgId, times);
     }
   }
 
-  double el = (taosGetTimestampMs() - st) / 1000.0;
-  tqInfo("vgId:%d scan wal for stream tasks completed, elapsed time:%.2f sec", vgId, el);
+  int64_t el = (taosGetTimestampMs() - st);
+  tqDebug("vgId:%d scan wal for stream tasks completed, elapsed time:%"PRId64" ms", vgId, el);
   return 0;
 }
 
-int32_t streamTaskReplayWal(SStreamMeta* pStreamMeta, STqOffsetStore* pOffsetStore, bool* pScanIdle) {
-  void*   pIter = NULL;
+int32_t createStreamRunReq(SStreamMeta* pStreamMeta, bool* pScanIdle) {
+  *pScanIdle = true;
+  bool    noNewDataInWal = true;
   int32_t vgId = pStreamMeta->vgId;
 
-  *pScanIdle = true;
+  int32_t numOfTasks = taosArrayGetSize(pStreamMeta->pTaskList);
+  if (numOfTasks == 0) {
+    return TSDB_CODE_SUCCESS;
+  }
 
-  bool allWalChecked = true;
-  tqDebug("vgId:%d start to check wal to extract new submit block", vgId);
+  SArray* pTaskList = NULL;
+  taosWLockLatch(&pStreamMeta->lock);
+  pTaskList = taosArrayDup(pStreamMeta->pTaskList, NULL);
+  taosWUnLockLatch(&pStreamMeta->lock);
 
-  while (1) {
-    pIter = taosHashIterate(pStreamMeta->pTasks, pIter);
-    if (pIter == NULL) {
-      break;
+  tqDebug("vgId:%d start to check wal to extract new submit block for %d tasks", vgId, numOfTasks);
+
+  // update the new task number
+  numOfTasks = taosArrayGetSize(pTaskList);
+
+  for (int32_t i = 0; i < numOfTasks; ++i) {
+    int32_t*     pTaskId = taosArrayGet(pTaskList, i);
+    SStreamTask* pTask = streamMetaAcquireTask(pStreamMeta, *pTaskId);
+    if (pTask == NULL) {
+      continue;
     }
 
-    SStreamTask* pTask = *(SStreamTask**)pIter;
+    int32_t status = pTask->status.taskStatus;
     if (pTask->taskLevel != TASK_LEVEL__SOURCE) {
+      tqDebug("s-task:%s not source task, no need to start", pTask->id.idStr);
+      streamMetaReleaseTask(pStreamMeta, pTask);
       continue;
     }
 
-    int8_t status = pTask->status.taskStatus;
-    if (status == TASK_STATUS__RECOVER_PREPARE || status == TASK_STATUS__WAIT_DOWNSTREAM) {
-      tqDebug("s-task:%s skip push data, not ready for processing, status %d", pTask->id.idStr,
-              pTask->status.taskStatus);
+    if (streamTaskShouldStop(&pTask->status) || status == TASK_STATUS__RECOVER_PREPARE ||
+        status == TASK_STATUS__WAIT_DOWNSTREAM) {
+      tqDebug("s-task:%s not ready for new submit block from wal, status:%d", pTask->id.idStr, status);
+      streamMetaReleaseTask(pStreamMeta, pTask);
       continue;
     }
 
-    // check if offset value exists
-    char key[128] = {0};
-    createStreamTaskOffsetKey(key, pTask->id.streamId, pTask->id.taskId);
-
     if (tInputQueueIsFull(pTask)) {
       tqDebug("vgId:%d s-task:%s input queue is full, do nothing", vgId, pTask->id.idStr);
+      streamMetaReleaseTask(pStreamMeta, pTask);
       continue;
     }
 
     *pScanIdle = false;
 
-    // check if offset value exists
-    STqOffset* pOffset = tqOffsetRead(pOffsetStore, key);
-    ASSERT(pOffset != NULL);
-
     // seek the stored version and extract data from WAL
-    int32_t code = walReadSeekVer(pTask->exec.pWalReader, pOffset->val.version);
+    int32_t code = walReadSeekVer(pTask->exec.pWalReader, pTask->chkInfo.currentVer);
     if (code != TSDB_CODE_SUCCESS) {  // no data in wal, quit
+      SWal *pWal = pTask->exec.pWalReader->pWal;
+      if (pTask->chkInfo.currentVer < pWal->vers.firstVer ) {
+        pTask->chkInfo.currentVer = pWal->vers.firstVer;
+        code = walReadSeekVer(pTask->exec.pWalReader, pTask->chkInfo.currentVer);
+        if (code != TSDB_CODE_SUCCESS) {
+          streamMetaReleaseTask(pStreamMeta, pTask);
+          continue;
+        }
+      }
+      streamMetaReleaseTask(pStreamMeta, pTask);
       continue;
     }
 
     // append the data for the stream
-    tqDebug("vgId:%d wal reader seek to ver:%" PRId64 " %s", vgId, pOffset->val.version, pTask->id.idStr);
+    tqDebug("vgId:%d s-task:%s wal reader seek to ver:%" PRId64, vgId, pTask->id.idStr, pTask->chkInfo.currentVer);
 
     SPackedData packData = {0};
     code = extractSubmitMsgFromWal(pTask->exec.pWalReader, &packData);
     if (code != TSDB_CODE_SUCCESS) {  // failed, continue
+      streamMetaReleaseTask(pStreamMeta, pTask);
       continue;
     }
 
@@ -116,28 +136,32 @@ int32_t streamTaskReplayWal(SStreamMeta* pStreamMeta, STqOffsetStore* pOffsetSto
     if (p == NULL) {
       terrno = TSDB_CODE_OUT_OF_MEMORY;
       tqError("%s failed to create data submit for stream since out of memory", pTask->id.idStr);
+      streamMetaReleaseTask(pStreamMeta, pTask);
       continue;
     }
 
-    allWalChecked = false;
+    noNewDataInWal = false;
 
-    tqDebug("s-task:%s submit data extracted from WAL", pTask->id.idStr);
     code = tqAddInputBlockNLaunchTask(pTask, (SStreamQueueItem*)p, packData.ver);
     if (code == TSDB_CODE_SUCCESS) {
-      pOffset->val.version = walReaderGetCurrentVer(pTask->exec.pWalReader);
+      pTask->chkInfo.currentVer = walReaderGetCurrentVer(pTask->exec.pWalReader);
       tqDebug("s-task:%s set the ver:%" PRId64 " from WALReader after extract block from WAL", pTask->id.idStr,
-              pOffset->val.version);
+              pTask->chkInfo.currentVer);
     } else {
-      // do nothing
+      tqError("s-task:%s append input queue failed, ver:%"PRId64, pTask->id.idStr, pTask->chkInfo.currentVer);
     }
 
     streamDataSubmitDestroy(p);
     taosFreeQitem(p);
+    streamMetaReleaseTask(pStreamMeta, pTask);
   }
 
-  if (allWalChecked) {
+  // all wal are checked, and no new data available in wal.
+  if (noNewDataInWal) {
     *pScanIdle = true;
   }
+
+  taosArrayDestroy(pTaskList);
   return 0;
 }
 
diff --git a/source/dnode/vnode/src/tq/tqScan.c b/source/dnode/vnode/src/tq/tqScan.c
index 27db66f048..800bcc8b71 100644
--- a/source/dnode/vnode/src/tq/tqScan.c
+++ b/source/dnode/vnode/src/tq/tqScan.c
@@ -66,15 +66,15 @@ static int32_t tqAddTbNameToRsp(const STQ* pTq, int64_t uid, STaosxRsp* pRsp, in
 
 int32_t tqScanData(STQ* pTq, const STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal* pOffset) {
   const int32_t MAX_ROWS_TO_RETURN = 4096;
-  int32_t       vgId = TD_VID(pTq->pVnode);
-  int32_t       code = 0;
-  int32_t       totalRows = 0;
+
+  int32_t vgId = TD_VID(pTq->pVnode);
+  int32_t code = 0;
+  int32_t totalRows = 0;
 
   const STqExecHandle* pExec = &pHandle->execHandle;
   qTaskInfo_t          task = pExec->task;
 
   if (qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType) < 0) {
-    tqError("prepare scan failed, return");
     return -1;
   }
 
@@ -119,7 +119,6 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMeta
   qTaskInfo_t          task = pExec->task;
 
   if (qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType) < 0) {
-    tqDebug("tqScanTaosx prepare scan failed, return");
     return -1;
   }
 
@@ -132,6 +131,7 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqMeta
       tqError("vgId:%d, task exec error since %s", pTq->pVnode->config.vgId, terrstr());
       return -1;
     }
+
     tqDebug("tmqsnap task execute end, get %p", pDataBlock);
 
     if (pDataBlock != NULL && pDataBlock->info.rows > 0) {
@@ -205,18 +205,18 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, STaosxR
   if (pExec->subType == TOPIC_SUB_TYPE__TABLE) {
     STqReader* pReader = pExec->pTqReader;
     tqReaderSetSubmitMsg(pReader, submit.msgStr, submit.msgLen, submit.ver);
-    while (tqNextDataBlock(pReader)) {
+    while (tqNextBlockImpl(pReader)) {
       taosArrayClear(pBlocks);
       taosArrayClear(pSchemas);
       SSubmitTbData* pSubmitTbDataRet = NULL;
-      if (tqRetrieveTaosxBlock2(pReader, pBlocks, pSchemas, &pSubmitTbDataRet) < 0) {
+      if (tqRetrieveTaosxBlock(pReader, pBlocks, pSchemas, &pSubmitTbDataRet) < 0) {
         if (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) continue;
       }
       if (pRsp->withTbName) {
         int64_t uid = pExec->pTqReader->lastBlkUid;
         if (tqAddTbNameToRsp(pTq, uid, pRsp, taosArrayGetSize(pBlocks)) < 0) {
           taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
-          taosArrayDestroyP(pSchemas, (FDelete)tDeleteSSchemaWrapper);
+          taosArrayDestroyP(pSchemas, (FDelete)tDeleteSchemaWrapper);
           pBlocks = taosArrayInit(0, sizeof(SSDataBlock));
           pSchemas = taosArrayInit(0, sizeof(void*));
           continue;
@@ -264,18 +264,18 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, STaosxR
   } else if (pExec->subType == TOPIC_SUB_TYPE__DB) {
     STqReader* pReader = pExec->pTqReader;
     tqReaderSetSubmitMsg(pReader, submit.msgStr, submit.msgLen, submit.ver);
-    while (tqNextDataBlockFilterOut2(pReader, pExec->execDb.pFilterOutTbUid)) {
+    while (tqNextDataBlockFilterOut(pReader, pExec->execDb.pFilterOutTbUid)) {
       taosArrayClear(pBlocks);
       taosArrayClear(pSchemas);
       SSubmitTbData* pSubmitTbDataRet = NULL;
-      if (tqRetrieveTaosxBlock2(pReader, pBlocks, pSchemas, &pSubmitTbDataRet) < 0) {
+      if (tqRetrieveTaosxBlock(pReader, pBlocks, pSchemas, &pSubmitTbDataRet) < 0) {
         if (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) continue;
       }
       if (pRsp->withTbName) {
         int64_t uid = pExec->pTqReader->lastBlkUid;
         if (tqAddTbNameToRsp(pTq, uid, pRsp, taosArrayGetSize(pBlocks)) < 0) {
           taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
-          taosArrayDestroyP(pSchemas, (FDelete)tDeleteSSchemaWrapper);
+          taosArrayDestroyP(pSchemas, (FDelete)tDeleteSchemaWrapper);
           pBlocks = taosArrayInit(0, sizeof(SSDataBlock));
           pSchemas = taosArrayInit(0, sizeof(void*));
           continue;
diff --git a/source/dnode/vnode/src/tq/tqSink.c b/source/dnode/vnode/src/tq/tqSink.c
index 62b81305b7..33d1e08c9c 100644
--- a/source/dnode/vnode/src/tq/tqSink.c
+++ b/source/dnode/vnode/src/tq/tqSink.c
@@ -672,7 +672,7 @@ void tqSinkToTablePipeline2(SStreamTask* pTask, void* vnode, int64_t ver, void*
         }
         SRow* pRow = NULL;
         if ((terrno = tRowBuild(pVals, (STSchema*)pTSchema, &pRow)) < 0) {
-          tDestroySSubmitTbData(&tbData, TSDB_MSG_FLG_ENCODE);
+          tDestroySubmitTbData(&tbData, TSDB_MSG_FLG_ENCODE);
           goto _end;
         }
         ASSERT(pRow);
@@ -681,7 +681,7 @@ void tqSinkToTablePipeline2(SStreamTask* pTask, void* vnode, int64_t ver, void*
 
       SSubmitReq2 submitReq = {0};
       if (!(submitReq.aSubmitTbData = taosArrayInit(1, sizeof(SSubmitTbData)))) {
-        tDestroySSubmitTbData(&tbData, TSDB_MSG_FLG_ENCODE);
+        tDestroySubmitTbData(&tbData, TSDB_MSG_FLG_ENCODE);
         goto _end;
       }
 
@@ -690,28 +690,28 @@ void tqSinkToTablePipeline2(SStreamTask* pTask, void* vnode, int64_t ver, void*
       // encode
       int32_t len;
       int32_t code;
-      tEncodeSize(tEncodeSSubmitReq2, &submitReq, len, code);
+      tEncodeSize(tEncodeSubmitReq, &submitReq, len, code);
       SEncoder encoder;
       len += sizeof(SSubmitReq2Msg);
       pBuf = rpcMallocCont(len);
       if (NULL == pBuf) {
-        tDestroySSubmitReq2(&submitReq, TSDB_MSG_FLG_ENCODE);
+        tDestroySubmitReq(&submitReq, TSDB_MSG_FLG_ENCODE);
         goto _end;
       }
       ((SSubmitReq2Msg*)pBuf)->header.vgId = TD_VID(pVnode);
       ((SSubmitReq2Msg*)pBuf)->header.contLen = htonl(len);
       ((SSubmitReq2Msg*)pBuf)->version = htobe64(1);
       tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SSubmitReq2Msg)), len - sizeof(SSubmitReq2Msg));
-      if (tEncodeSSubmitReq2(&encoder, &submitReq) < 0) {
+      if (tEncodeSubmitReq(&encoder, &submitReq) < 0) {
         terrno = TSDB_CODE_OUT_OF_MEMORY;
         tqError("failed to encode submit req since %s", terrstr());
         tEncoderClear(&encoder);
         rpcFreeCont(pBuf);
-        tDestroySSubmitReq2(&submitReq, TSDB_MSG_FLG_ENCODE);
+        tDestroySubmitReq(&submitReq, TSDB_MSG_FLG_ENCODE);
         continue;
       }
       tEncoderClear(&encoder);
-      tDestroySSubmitReq2(&submitReq, TSDB_MSG_FLG_ENCODE);
+      tDestroySubmitReq(&submitReq, TSDB_MSG_FLG_ENCODE);
 
       SRpcMsg msg = {
           .msgType = TDMT_VND_SUBMIT,
diff --git a/source/dnode/vnode/src/tq/tqUtil.c b/source/dnode/vnode/src/tq/tqUtil.c
index c09a8a030e..bcfd96d9c9 100644
--- a/source/dnode/vnode/src/tq/tqUtil.c
+++ b/source/dnode/vnode/src/tq/tqUtil.c
@@ -16,6 +16,7 @@
 #include "tq.h"
 
 #define IS_OFFSET_RESET_TYPE(_t)  ((_t) < 0)
+#define NO_POLL_CNT 5
 
 static int32_t tqSendMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqMetaRsp* pRsp, int32_t vgId);
 
@@ -25,21 +26,6 @@ char* createStreamTaskIdStr(int64_t streamId, int32_t taskId) {
   return taosStrdup(buf);
 }
 
-// stream_task:stream_id:task_id
-void createStreamTaskOffsetKey(char* dst, uint64_t streamId, uint32_t taskId) {
-  int32_t n = 12;
-  char* p = dst;
-
-  memcpy(p, "stream_task:", n);
-  p += n;
-
-  int32_t inc = tintToHex(streamId, p);
-  p += inc;
-
-  *(p++) = ':';
-  tintToHex(taskId, p);
-}
-
 int32_t tqAddInputBlockNLaunchTask(SStreamTask* pTask, SStreamQueueItem* pQueueItem, int64_t ver) {
   int32_t code = tAppendDataToInputQueue(pTask, pQueueItem);
   if (code < 0) {
@@ -55,75 +41,6 @@ int32_t tqAddInputBlockNLaunchTask(SStreamTask* pTask, SStreamQueueItem* pQueueI
   return TSDB_CODE_SUCCESS;
 }
 
-void initOffsetForAllRestoreTasks(STQ* pTq) {
-  void* pIter = NULL;
-
-  while(1) {
-    pIter = taosHashIterate(pTq->pStreamMeta->pTasks, pIter);
-    if (pIter == NULL) {
-      break;
-    }
-
-    SStreamTask* pTask = *(SStreamTask**)pIter;
-    if (pTask->taskLevel != TASK_LEVEL__SOURCE) {
-      continue;
-    }
-
-    if (pTask->status.taskStatus == TASK_STATUS__RECOVER_PREPARE || pTask->status.taskStatus == TASK_STATUS__WAIT_DOWNSTREAM) {
-      tqDebug("s-task:%s skip push data, since not ready, status %d", pTask->id.idStr, pTask->status.taskStatus);
-      continue;
-    }
-
-    char key[128] = {0};
-    createStreamTaskOffsetKey(key, pTask->id.streamId, pTask->id.taskId);
-
-    STqOffset* pOffset = tqOffsetRead(pTq->pOffsetStore, key);
-    if (pOffset == NULL) {
-      doSaveTaskOffset(pTq->pOffsetStore, key, pTask->chkInfo.version);
-    }
-  }
-}
-
-void saveOffsetForAllTasks(STQ* pTq, int64_t ver) {
-  void* pIter = NULL;
-
-  while(1) {
-    pIter = taosHashIterate(pTq->pStreamMeta->pTasks, pIter);
-    if (pIter == NULL) {
-      break;
-    }
-
-    SStreamTask* pTask = *(SStreamTask**)pIter;
-    if (pTask->taskLevel != TASK_LEVEL__SOURCE) {
-      continue;
-    }
-
-    if (pTask->status.taskStatus == TASK_STATUS__RECOVER_PREPARE || pTask->status.taskStatus == TASK_STATUS__WAIT_DOWNSTREAM) {
-      tqDebug("s-task:%s skip push data, not ready for processing, status %d", pTask->id.idStr,
-              pTask->status.taskStatus);
-      continue;
-    }
-
-    char key[128] = {0};
-    createStreamTaskOffsetKey(key, pTask->id.streamId, pTask->id.taskId);
-
-    STqOffset* pOffset = tqOffsetRead(pTq->pOffsetStore, key);
-    if (pOffset == NULL) {
-      doSaveTaskOffset(pTq->pOffsetStore, key, ver);
-    }
-  }
-}
-
-void doSaveTaskOffset(STqOffsetStore* pOffsetStore, const char* pKey, int64_t ver) {
-  STqOffset offset = {0};
-  tqOffsetResetToLog(&offset.val, ver);
-
-  tstrncpy(offset.subKey, pKey, tListLen(offset.subKey));
-
-  // keep the offset info in the offset store
-  tqOffsetWrite(pOffsetStore, &offset);
-}
-
 int32_t tqInitDataRsp(SMqDataRsp* pRsp, const SMqPollReq* pReq) {
   pRsp->reqOffset = pReq->reqOffset;
 
@@ -245,57 +162,95 @@ static int32_t extractResetOffsetVal(STqOffsetVal* pOffsetVal, STQ* pTq, STqHand
   return 0;
 }
 
+bool tqIsHandleExecuting(STqHandle* pHandle) { return 1 == atomic_load_8(&pHandle->exec); }
+
 static int32_t extractDataAndRspForNormalSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
                                                    SRpcMsg* pMsg, STqOffsetVal* pOffset) {
-  char     buf[80] = {0};
   uint64_t consumerId = pRequest->consumerId;
   int32_t  vgId = TD_VID(pTq->pVnode);
+  int      code = 0;
 
   SMqDataRsp dataRsp = {0};
   tqInitDataRsp(&dataRsp, pRequest);
+//  qTaskInfo_t task = pHandle->execHandle.task;
+//  if (qTaskIsExecuting(task)) {
+//    code = tqSendDataRsp(pHandle, pMsg, pRequest, &dataRsp, TMQ_MSG_TYPE__POLL_RSP, vgId);
+//    tDeleteMqDataRsp(&dataRsp);
+//    return code;
+//  }
 
-  // lock
-  taosWLockLatch(&pTq->lock);
-
-  qSetTaskId(pHandle->execHandle.task, consumerId, pRequest->reqId);
-
-  int code = tqScanData(pTq, pHandle, &dataRsp, pOffset);
-  if (code == 0) {
-
-    // till now, all data has been transferred to consumer, new data needs to push client once arrived.
-    if (dataRsp.blockNum == 0 && dataRsp.reqOffset.type == TMQ_OFFSET__LOG &&
-        dataRsp.reqOffset.version == dataRsp.rspOffset.version && pHandle->consumerId == pRequest->consumerId) {
-      code = tqRegisterPushHandle(pTq, pHandle, pRequest, pMsg, &dataRsp, TMQ_MSG_TYPE__POLL_RSP);
-      taosWUnLockLatch(&pTq->lock);
-      return code;
-    }
-
-    // NOTE: this pHandle->consumerId may have been changed already.
-    code = tqSendDataRsp(pHandle, pMsg, pRequest, (SMqDataRsp*)&dataRsp, TMQ_MSG_TYPE__POLL_RSP, vgId);
+  // todo add more status check to avoid race condition
+  while (tqIsHandleExecuting(pHandle)) {
+    tqDebug("vgId:%d, topic:%s, subscription is executing, wait for 5ms and retry", vgId, pHandle->subKey);
+    taosMsleep(5);
   }
 
-  tFormatOffset(buf, 80, &dataRsp.rspOffset);
-  tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, rsp block:%d, rsp offset type:%s, reqId:0x%" PRIx64
-          " code:%d",
-          consumerId, pHandle->subKey, vgId, dataRsp.blockNum, buf, pRequest->reqId, code);
-  taosWUnLockLatch(&pTq->lock);
-  tDeleteMqDataRsp(&dataRsp);
+  atomic_store_8(&pHandle->exec, 1);
 
+  qSetTaskId(pHandle->execHandle.task, consumerId, pRequest->reqId);
+  code = tqScanData(pTq, pHandle, &dataRsp, pOffset);
+  if (code != 0) {
+    goto end;
+  }
+
+  //   till now, all data has been transferred to consumer, new data needs to push client once arrived.
+  if (dataRsp.blockNum == 0 && dataRsp.reqOffset.type == TMQ_OFFSET__LOG &&
+      dataRsp.reqOffset.version == dataRsp.rspOffset.version && pHandle->consumerId == pRequest->consumerId) {
+    if (pHandle->noDataPollCnt >= NO_POLL_CNT) {  // send poll result to client if no data 5 times to avoid lost data
+      pHandle->noDataPollCnt = 0;
+      // lock
+      taosWLockLatch(&pTq->lock);
+      code = tqRegisterPushHandle(pTq, pHandle, pMsg);
+      taosWUnLockLatch(&pTq->lock);
+      tDeleteMqDataRsp(&dataRsp);
+      atomic_store_8(&pHandle->exec, 0);
+      return code;
+    } else {
+      pHandle->noDataPollCnt++;
+    }
+  }
+
+  // NOTE: this pHandle->consumerId may have been changed already.
+  code = tqSendDataRsp(pHandle, pMsg, pRequest, (SMqDataRsp*)&dataRsp, TMQ_MSG_TYPE__POLL_RSP, vgId);
+
+  end:
+  {
+    char buf[80] = {0};
+    tFormatOffset(buf, 80, &dataRsp.rspOffset);
+    tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, rsp block:%d, rsp offset type:%s, reqId:0x%" PRIx64 " code:%d",
+            consumerId, pHandle->subKey, vgId, dataRsp.blockNum, buf, pRequest->reqId, code);
+    tDeleteMqDataRsp(&dataRsp);
+  }
+
+  atomic_store_8(&pHandle->exec, 0);
   return code;
 }
 
 static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest, SRpcMsg* pMsg, STqOffsetVal *offset) {
-  int code = 0;
+  int          code = 0;
   int32_t      vgId = TD_VID(pTq->pVnode);
   SWalCkHead*  pCkHead = NULL;
   SMqMetaRsp metaRsp = {0};
   STaosxRsp taosxRsp = {0};
   tqInitTaosxRsp(&taosxRsp, pRequest);
+//  qTaskInfo_t task = pHandle->execHandle.task;
+//  if(qTaskIsExecuting(task)){
+//    code = tqSendDataRsp(pHandle, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP, vgId);
+//    tDeleteSTaosxRsp(&taosxRsp);
+//    return code;
+//  }
+
+  while (tqIsHandleExecuting(pHandle)) {
+    tqDebug("vgId:%d, topic:%s, subscription is executing, wait for 5ms and retry", vgId, pHandle->subKey);
+    taosMsleep(5);
+  }
+
+  atomic_store_8(&pHandle->exec, 1);
 
   if (offset->type != TMQ_OFFSET__LOG) {
     if (tqScanTaosx(pTq, pHandle, &taosxRsp, &metaRsp, offset) < 0) {
-      tDeleteSTaosxRsp(&taosxRsp);
-      return -1;
+      code = -1;
+      goto end;
     }
 
     if (metaRsp.metaRspLen > 0) {
@@ -303,8 +258,7 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
       tqDebug("tmq poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send meta offset type:%d,uid:%" PRId64 ",ts:%" PRId64,
               pRequest->consumerId, pHandle->subKey, vgId, metaRsp.rspOffset.type, metaRsp.rspOffset.uid, metaRsp.rspOffset.ts);
       taosMemoryFree(metaRsp.metaRsp);
-      tDeleteSTaosxRsp(&taosxRsp);
-      return code;
+      goto end;
     }
 
     tqDebug("taosx poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send data blockNum:%d, offset type:%d,uid:%" PRId64
@@ -312,6 +266,7 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
     if (taosxRsp.blockNum > 0) {
       code = tqSendDataRsp(pHandle, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP, vgId);
       tDeleteSTaosxRsp(&taosxRsp);
+      atomic_store_8(&pHandle->exec, 0);
       return code;
     }else {
       *offset = taosxRsp.rspOffset;
@@ -319,13 +274,15 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
   }
 
   if (offset->type == TMQ_OFFSET__LOG) {
+    verifyOffset(pHandle->pWalReader, offset);
     int64_t fetchVer = offset->version + 1;
     pCkHead = taosMemoryMalloc(sizeof(SWalCkHead) + 2048);
     if (pCkHead == NULL) {
-      tDeleteSTaosxRsp(&taosxRsp);
       terrno = TSDB_CODE_OUT_OF_MEMORY;
-      return -1;
+      code = -1;
+      goto end;
     }
+
     walSetReaderCapacity(pHandle->pWalReader, 2048);
     int totalRows = 0;
     while (1) {
@@ -340,9 +297,7 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
       if (tqFetchLog(pTq, pHandle, &fetchVer, &pCkHead, pRequest->reqId) < 0) {
         tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer);
         code = tqSendDataRsp(pHandle, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP, vgId);
-        tDeleteSTaosxRsp(&taosxRsp);
-        taosMemoryFreeClear(pCkHead);
-        return code;
+        goto end;
       }
 
       SWalCont* pHead = &pCkHead->head;
@@ -354,9 +309,7 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
         if(totalRows > 0) {
           tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer - 1);
           code = tqSendDataRsp(pHandle, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP, vgId);
-          tDeleteSTaosxRsp(&taosxRsp);
-          taosMemoryFreeClear(pCkHead);
-          return code;
+          goto end;
         }
 
         tqDebug("fetch meta msg, ver:%" PRId64 ", type:%s", pHead->version, TMSG_INFO(pHead->msgType));
@@ -364,17 +317,8 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
         metaRsp.resMsgType = pHead->msgType;
         metaRsp.metaRspLen = pHead->bodyLen;
         metaRsp.metaRsp = pHead->body;
-        if (tqSendMetaPollRsp(pHandle, pMsg, pRequest, &metaRsp, vgId) < 0) {
-          code = -1;
-          taosMemoryFreeClear(pCkHead);
-          tDeleteSTaosxRsp(&taosxRsp);
-          return code;
-        }
-
-        code = 0;
-        taosMemoryFreeClear(pCkHead);
-        tDeleteSTaosxRsp(&taosxRsp);
-        return code;
+        code = tqSendMetaPollRsp(pHandle, pMsg, pRequest, &metaRsp, vgId);
+        goto end;
       }
 
       // process data
@@ -384,29 +328,28 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
           .ver = pHead->version,
       };
 
-      if (tqTaosxScanLog(pTq, pHandle, submit, &taosxRsp, &totalRows) < 0) {
-        tqError("tmq poll: tqTaosxScanLog error %" PRId64 ", in vgId:%d, subkey %s", pRequest->consumerId, vgId,
-                pRequest->subKey);
-        taosMemoryFreeClear(pCkHead);
-        tDeleteSTaosxRsp(&taosxRsp);
-        return -1;
+      code = tqTaosxScanLog(pTq, pHandle, submit, &taosxRsp, &totalRows);
+      if (code < 0) {
+        tqError("tmq poll: tqTaosxScanLog error %" PRId64 ", in vgId:%d, subkey %s", pRequest->consumerId, vgId, pRequest->subKey);
+        goto end;
       }
 
       if (totalRows >= 4096 || taosxRsp.createTableNum > 0) {
         tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer);
         code = tqSendDataRsp(pHandle, pMsg, pRequest, (SMqDataRsp*)&taosxRsp, TMQ_MSG_TYPE__TAOSX_RSP, vgId);
-        tDeleteSTaosxRsp(&taosxRsp);
-        taosMemoryFreeClear(pCkHead);
-        return code;
+        goto end;
       } else {
         fetchVer++;
       }
     }
   }
 
+end:
+  atomic_store_8(&pHandle->exec, 0);
+
   tDeleteSTaosxRsp(&taosxRsp);
   taosMemoryFreeClear(pCkHead);
-  return 0;
+  return code;
 }
 
 int32_t tqExtractDataForMq(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest, SRpcMsg* pMsg) {
@@ -435,11 +378,10 @@ int32_t tqExtractDataForMq(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequ
   // this is a normal subscribe requirement
   if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
     return extractDataAndRspForNormalSubscribe(pTq, pHandle, pRequest, pMsg, &offset);
+  } else { // todo handle the case where re-balance occurs.
+    // for taosx
+    return extractDataAndRspForDbStbSubscribe(pTq, pHandle, pRequest, pMsg, &offset);
   }
-
-  // todo handle the case where re-balance occurs.
-  // for taosx
-  return extractDataAndRspForDbStbSubscribe(pTq, pHandle, pRequest, pMsg, &offset);
 }
 
 static void initMqRspHead(SMqRspHead* pMsgHead, int32_t type, int32_t epoch, int64_t consumerId, int64_t sver,
diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c
index b3999caace..c0a8de5743 100644
--- a/source/dnode/vnode/src/tsdb/tsdbCache.c
+++ b/source/dnode/vnode/src/tsdb/tsdbCache.c
@@ -1111,6 +1111,7 @@ typedef struct {
   SMergeTree         mergeTree;
   SMergeTree        *pMergeTree;
   SSttBlockLoadInfo *pLoadInfo;
+  SLDataIter*        pDataIter;
   int64_t            lastTs;
 } SFSLastNextRowIter;
 
@@ -1158,7 +1159,7 @@ static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow, bool *pIgnoreEa
       }
       tMergeTreeOpen(&state->mergeTree, 1, *state->pDataFReader, state->suid, state->uid,
                      &(STimeWindow){.skey = state->lastTs, .ekey = TSKEY_MAX},
-                     &(SVersionRange){.minVer = 0, .maxVer = UINT64_MAX}, state->pLoadInfo, false, NULL, true);
+                     &(SVersionRange){.minVer = 0, .maxVer = UINT64_MAX}, state->pLoadInfo, false, NULL, true, state->pDataIter);
       state->pMergeTree = &state->mergeTree;
       state->state = SFSLASTNEXTROW_BLOCKROW;
     }
@@ -1180,7 +1181,7 @@ static int32_t getNextRowFromFSLast(void *iter, TSDBROW **ppRow, bool *pIgnoreEa
         state->state = SFSLASTNEXTROW_FILESET;
         goto _next_fileset;
       }
-      state->row = tMergeTreeGetRow(&state->mergeTree);
+      state->row = *tMergeTreeGetRow(&state->mergeTree);
       *ppRow = &state->row;
 
       if (TSDBROW_TS(&state->row) <= state->lastTs) {
@@ -1729,7 +1730,7 @@ typedef struct {
 } CacheNextRowIter;
 
 static int32_t nextRowIterOpen(CacheNextRowIter *pIter, tb_uid_t uid, STsdb *pTsdb, STSchema *pTSchema, tb_uid_t suid,
-                               SSttBlockLoadInfo *pLoadInfo, STsdbReadSnap *pReadSnap, SDataFReader **pDataFReader,
+                               SSttBlockLoadInfo *pLoadInfo, SLDataIter* pLDataIter, STsdbReadSnap *pReadSnap, SDataFReader **pDataFReader,
                                SDataFReader **pDataFReaderLast, int64_t lastTs) {
   int code = 0;
 
@@ -1792,6 +1793,7 @@ static int32_t nextRowIterOpen(CacheNextRowIter *pIter, tb_uid_t uid, STsdb *pTs
   pIter->fsLastState.pLoadInfo = pLoadInfo;
   pIter->fsLastState.pDataFReader = pDataFReaderLast;
   pIter->fsLastState.lastTs = lastTs;
+  pIter->fsLastState.pDataIter = pLDataIter;
 
   pIter->fsState.state = SFSNEXTROW_FS;
   pIter->fsState.pTsdb = pTsdb;
@@ -1998,7 +2000,7 @@ static int32_t mergeLastRow(tb_uid_t uid, STsdb *pTsdb, bool *dup, SArray **ppCo
   TSKEY lastRowTs = TSKEY_MAX;
 
   CacheNextRowIter iter = {0};
-  nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->suid, pr->pLoadInfo, pr->pReadSnap, &pr->pDataFReader,
+  nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->suid, pr->pLoadInfo, pr->pDataIter, pr->pReadSnap, &pr->pDataFReader,
                   &pr->pDataFReaderLast, pr->lastTs);
 
   do {
@@ -2155,7 +2157,7 @@ static int32_t mergeLast(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SCach
   TSKEY lastRowTs = TSKEY_MAX;
 
   CacheNextRowIter iter = {0};
-  nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->suid, pr->pLoadInfo, pr->pReadSnap, &pr->pDataFReader,
+  nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->suid, pr->pLoadInfo, pr->pDataIter, pr->pReadSnap, &pr->pDataFReader,
                   &pr->pDataFReaderLast, pr->lastTs);
 
   do {
@@ -2323,7 +2325,7 @@ static int32_t mergeLastCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray, SC
   TSKEY lastRowTs = TSKEY_MAX;
 
   CacheNextRowIter iter = {0};
-  nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->suid, pr->pLoadInfo, pr->pReadSnap, &pr->pDataFReader,
+  nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->suid, pr->pLoadInfo, pr->pDataIter, pr->pReadSnap, &pr->pDataFReader,
                   &pr->pDataFReaderLast, pr->lastTs);
 
   do {
@@ -2491,7 +2493,7 @@ static int32_t mergeLastRowCid(tb_uid_t uid, STsdb *pTsdb, SArray **ppLastArray,
   TSKEY lastRowTs = TSKEY_MAX;
 
   CacheNextRowIter iter = {0};
-  nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->suid, pr->pLoadInfo, pr->pReadSnap, &pr->pDataFReader,
+  nextRowIterOpen(&iter, uid, pTsdb, pTSchema, pr->suid, pr->pLoadInfo, pr->pDataIter, pr->pReadSnap, &pr->pDataFReader,
                   &pr->pDataFReaderLast, pr->lastTs);
 
   do {
diff --git a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c
index 0d47940582..53103e9fbb 100644
--- a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c
+++ b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c
@@ -167,13 +167,21 @@ int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, void* pTableIdList,
     }
   }
 
-  int32_t numOfStt = ((SVnode*)pVnode)->config.sttTrigger;
+  SVnodeCfg* pCfg = &((SVnode*)pVnode)->config;
+
+  int32_t numOfStt = pCfg->sttTrigger;
   p->pLoadInfo = tCreateLastBlockLoadInfo(p->pSchema, NULL, 0, numOfStt);
   if (p->pLoadInfo == NULL) {
     tsdbCacherowsReaderClose(p);
     return TSDB_CODE_OUT_OF_MEMORY;
   }
 
+  p->pDataIter = taosMemoryCalloc(pCfg->sttTrigger, sizeof(SLDataIter));
+  if (p->pDataIter == NULL) {
+    tsdbCacherowsReaderClose(p);
+    return TSDB_CODE_OUT_OF_MEMORY;
+  }
+
   p->idstr = taosStrdup(idstr);
   taosThreadMutexInit(&p->readerMutex, NULL);
 
@@ -195,6 +203,7 @@ void* tsdbCacherowsReaderClose(void* pReader) {
     taosMemoryFree(p->pSchema);
   }
 
+  taosMemoryFreeClear(p->pDataIter);
   taosMemoryFree(p->pCurrSchema);
 
   destroyLastBlockLoadInfo(p->pLoadInfo);
diff --git a/source/dnode/vnode/src/tsdb/tsdbDataIter.c b/source/dnode/vnode/src/tsdb/tsdbDataIter.c
index 3299a2f497..e27aec5b1b 100644
--- a/source/dnode/vnode/src/tsdb/tsdbDataIter.c
+++ b/source/dnode/vnode/src/tsdb/tsdbDataIter.c
@@ -14,6 +14,7 @@
  */
 
 #include "tsdb.h"
+#include "vnodeInt.h"
 
 // STsdbDataIter2
 /* open */
@@ -202,13 +203,6 @@ static int32_t tsdbDataFileDataIterNext(STsdbDataIter2* pIter, STsdbFilterInfo*
   for (;;) {
     while (pIter->dIter.iRow < pIter->dIter.bData.nRow) {
       if (pFilterInfo) {
-        if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_TABLEID) {
-          if (pFilterInfo->tbid.uid == pIter->dIter.bData.uid) {
-            pIter->dIter.iRow = pIter->dIter.bData.nRow;
-            continue;
-          }
-        }
-
         if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_VERSION) {
           if (pIter->dIter.bData.aVersion[pIter->dIter.iRow] < pFilterInfo->sver ||
               pIter->dIter.bData.aVersion[pIter->dIter.iRow] > pFilterInfo->ever) {
@@ -232,13 +226,6 @@ static int32_t tsdbDataFileDataIterNext(STsdbDataIter2* pIter, STsdbFilterInfo*
 
         // filter
         if (pFilterInfo) {
-          if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_TABLEID) {
-            if (tTABLEIDCmprFn(&pFilterInfo->tbid, &pIter->rowInfo) == 0) {
-              pIter->dIter.iDataBlk = pIter->dIter.mDataBlk.nItem;
-              continue;
-            }
-          }
-
           if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_VERSION) {
             if (pFilterInfo->sver > dataBlk.maxVer || pFilterInfo->ever < dataBlk.minVer) {
               pIter->dIter.iDataBlk++;
@@ -262,13 +249,23 @@ static int32_t tsdbDataFileDataIterNext(STsdbDataIter2* pIter, STsdbFilterInfo*
         if (pIter->dIter.iBlockIdx < taosArrayGetSize(pIter->dIter.aBlockIdx)) {
           SBlockIdx* pBlockIdx = taosArrayGet(pIter->dIter.aBlockIdx, pIter->dIter.iBlockIdx);
 
-          if (pFilterInfo && (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_TABLEID)) {
-            int32_t c = tTABLEIDCmprFn(pBlockIdx, &pFilterInfo->tbid);
-            if (c == 0) {
-              pIter->dIter.iBlockIdx++;
-              continue;
-            } else if (c < 0) {
-              ASSERT(0);
+          if (pFilterInfo) {
+            if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_TABLEID) {
+              int32_t c = tTABLEIDCmprFn(pBlockIdx, &pFilterInfo->tbid);
+              if (c == 0) {
+                pIter->dIter.iBlockIdx++;
+                continue;
+              } else if (c < 0) {
+                ASSERT(0);
+              }
+            }
+
+            if (pFilterInfo->flag & TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE) {
+              SMetaInfo info;
+              if (metaGetInfo(pIter->dIter.pReader->pTsdb->pVnode->pMeta, pBlockIdx->uid, &info, NULL)) {
+                pIter->dIter.iBlockIdx++;
+                continue;
+              }
             }
           }
 
@@ -304,14 +301,24 @@ static int32_t tsdbSttFileDataIterNext(STsdbDataIter2* pIter, STsdbFilterInfo* p
   for (;;) {
     while (pIter->sIter.iRow < pIter->sIter.bData.nRow) {
       if (pFilterInfo) {
+        int64_t uid = pIter->sIter.bData.uid ? pIter->sIter.bData.uid : pIter->sIter.bData.aUid[pIter->sIter.iRow];
         if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_TABLEID) {
-          int64_t uid = pIter->sIter.bData.uid ? pIter->sIter.bData.uid : pIter->sIter.bData.aUid[pIter->sIter.iRow];
           if (pFilterInfo->tbid.uid == uid) {
             pIter->sIter.iRow++;
             continue;
           }
         }
 
+        if (pFilterInfo->flag & TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE) {
+          if (pIter->rowInfo.uid != uid) {
+            SMetaInfo info;
+            if (metaGetInfo(pIter->sIter.pReader->pTsdb->pVnode->pMeta, uid, &info, NULL)) {
+              pIter->sIter.iRow++;
+              continue;
+            }
+          }
+        }
+
         if (pFilterInfo->flag & TSDB_FILTER_FLAG_BY_VERSION) {
           if (pFilterInfo->sver > pIter->sIter.bData.aVersion[pIter->sIter.iRow] ||
               pFilterInfo->ever < pIter->sIter.bData.aVersion[pIter->sIter.iRow]) {
@@ -395,6 +402,16 @@ static int32_t tsdbTombFileDataIterNext(STsdbDataIter2* pIter, STsdbFilterInfo*
       if (pIter->tIter.iDelIdx < taosArrayGetSize(pIter->tIter.aDelIdx)) {
         SDelIdx* pDelIdx = taosArrayGet(pIter->tIter.aDelIdx, pIter->tIter.iDelIdx);
 
+        if (pFilterInfo) {
+          if (pFilterInfo->flag & TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE) {
+            SMetaInfo info;
+            if (metaGetInfo(pIter->dIter.pReader->pTsdb->pVnode->pMeta, pDelIdx->uid, &info, NULL)) {
+              pIter->tIter.iDelIdx++;
+              continue;
+            }
+          }
+        }
+
         code = tsdbReadDelData(pIter->tIter.pReader, pDelIdx, pIter->tIter.aDelData);
         TSDB_CHECK_CODE(code, lino, _exit);
 
diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c
index b6141abcf9..921343d355 100644
--- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c
+++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c
@@ -13,6 +13,7 @@
  * along with this program. If not, see .
  */
 
+#include 
 #include "tsdb.h"
 
 #define MEM_MIN_HASH 1024
@@ -301,12 +302,12 @@ int64_t tsdbCountTbDataRows(STbData *pTbData) {
   return rowsNum;
 }
 
-void tsdbMemTableCountRows(SMemTable *pMemTable, SHashObj *pTableMap, int64_t *rowsNum) {
+void tsdbMemTableCountRows(SMemTable *pMemTable, SSHashObj* pTableMap, int64_t *rowsNum) {
   taosRLockLatch(&pMemTable->latch);
   for (int32_t i = 0; i < pMemTable->nBucket; ++i) {
     STbData *pTbData = pMemTable->aBucket[i];
     while (pTbData) {
-      void *p = taosHashGet(pTableMap, &pTbData->uid, sizeof(pTbData->uid));
+      void* p = tSimpleHashGet(pTableMap, &pTbData->uid, sizeof(pTbData->uid));
       if (p == NULL) {
         pTbData = pTbData->next;
         continue;
diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c
index fa8870835c..79f4a17f65 100644
--- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c
+++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c
@@ -16,22 +16,6 @@
 #include "tsdb.h"
 
 // SLDataIter =================================================
-struct SLDataIter {
-  SRBTreeNode        node;
-  SSttBlk           *pSttBlk;
-  SDataFReader      *pReader;
-  int32_t            iStt;
-  int8_t             backward;
-  int32_t            iSttBlk;
-  int32_t            iRow;
-  SRowInfo           rInfo;
-  uint64_t           uid;
-  STimeWindow        timeWindow;
-  SVersionRange      verRange;
-  SSttBlockLoadInfo *pBlockLoadInfo;
-  bool               ignoreEarlierTs;
-};
-
 SSttBlockLoadInfo *tCreateLastBlockLoadInfo(STSchema *pSchema, int16_t *colList, int32_t numOfCols,
                                             int32_t numOfSttTrigger) {
   SSttBlockLoadInfo *pLoadInfo = taosMemoryCalloc(numOfSttTrigger, sizeof(SSttBlockLoadInfo));
@@ -88,6 +72,10 @@ void getLastBlockLoadInfo(SSttBlockLoadInfo *pLoadInfo, int64_t *blocks, double
 }
 
 void *destroyLastBlockLoadInfo(SSttBlockLoadInfo *pLoadInfo) {
+  if (pLoadInfo == NULL) {
+    return NULL;
+  }
+
   for (int32_t i = 0; i < pLoadInfo->numOfStt; ++i) {
     pLoadInfo[i].currentLoadBlockIndex = 1;
     pLoadInfo[i].blockIndex[0] = -1;
@@ -264,25 +252,21 @@ static int32_t binarySearchForStartRowIndex(uint64_t *uidList, int32_t num, uint
   }
 }
 
-int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t iStt, int8_t backward, uint64_t suid,
+int32_t tLDataIterOpen(struct SLDataIter *pIter, SDataFReader *pReader, int32_t iStt, int8_t backward, uint64_t suid,
                        uint64_t uid, STimeWindow *pTimeWindow, SVersionRange *pRange, SSttBlockLoadInfo *pBlockLoadInfo,
                        const char *idStr, bool strictTimeRange) {
   int32_t code = TSDB_CODE_SUCCESS;
 
-  *pIter = taosMemoryCalloc(1, sizeof(SLDataIter));
-  if (*pIter == NULL) {
-    code = TSDB_CODE_OUT_OF_MEMORY;
-    goto _exit;
-  }
+  pIter->uid = uid;
+  pIter->pReader = pReader;
+  pIter->iStt = iStt;
+  pIter->backward = backward;
+  pIter->verRange.minVer = pRange->minVer;
+  pIter->verRange.maxVer = pRange->maxVer;
+  pIter->timeWindow.skey = pTimeWindow->skey;
+  pIter->timeWindow.ekey = pTimeWindow->ekey;
 
-  (*pIter)->uid = uid;
-  (*pIter)->pReader = pReader;
-  (*pIter)->iStt = iStt;
-  (*pIter)->backward = backward;
-  (*pIter)->verRange = *pRange;
-  (*pIter)->timeWindow = *pTimeWindow;
-
-  (*pIter)->pBlockLoadInfo = pBlockLoadInfo;
+  pIter->pBlockLoadInfo = pBlockLoadInfo;
 
   if (!pBlockLoadInfo->sttBlockLoaded) {
     int64_t st = taosGetTimestampUs();
@@ -290,7 +274,7 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t
 
     code = tsdbReadSttBlk(pReader, iStt, pBlockLoadInfo->aSttBlk);
     if (code) {
-      goto _exit;
+      return code;
     }
 
     // only apply to the child tables, ordinary tables will not incur this filter procedure.
@@ -306,7 +290,7 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t
           // no qualified stt block existed
           taosArrayClear(pBlockLoadInfo->aSttBlk);
 
-          (*pIter)->iSttBlk = -1;
+          pIter->iSttBlk = -1;
           double el = (taosGetTimestampUs() - st) / 1000.0;
           tsdbDebug("load the last file info completed, elapsed time:%.2fms, %s", el, idStr);
           return code;
@@ -339,31 +323,27 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t
   size_t size = taosArrayGetSize(pBlockLoadInfo->aSttBlk);
 
   // find the start block
-  (*pIter)->iSttBlk = binarySearchForStartBlock(pBlockLoadInfo->aSttBlk->pData, size, uid, backward);
-  if ((*pIter)->iSttBlk != -1) {
-    (*pIter)->pSttBlk = taosArrayGet(pBlockLoadInfo->aSttBlk, (*pIter)->iSttBlk);
-    (*pIter)->iRow = ((*pIter)->backward) ? (*pIter)->pSttBlk->nRow : -1;
+  pIter->iSttBlk = binarySearchForStartBlock(pBlockLoadInfo->aSttBlk->pData, size, uid, backward);
+  if (pIter->iSttBlk != -1) {
+    pIter->pSttBlk = taosArrayGet(pBlockLoadInfo->aSttBlk, pIter->iSttBlk);
+    pIter->iRow = (pIter->backward) ? pIter->pSttBlk->nRow : -1;
 
-    if ((!backward) && ((strictTimeRange && (*pIter)->pSttBlk->minKey >= (*pIter)->timeWindow.ekey) ||
-                        (!strictTimeRange && (*pIter)->pSttBlk->minKey > (*pIter)->timeWindow.ekey))) {
-      (*pIter)->pSttBlk = NULL;
+    if ((!backward) && ((strictTimeRange && pIter->pSttBlk->minKey >= pIter->timeWindow.ekey) ||
+                        (!strictTimeRange && pIter->pSttBlk->minKey > pIter->timeWindow.ekey))) {
+      pIter->pSttBlk = NULL;
     }
 
-    if (backward && ((strictTimeRange && (*pIter)->pSttBlk->maxKey <= (*pIter)->timeWindow.skey) ||
-                     (!strictTimeRange && (*pIter)->pSttBlk->maxKey < (*pIter)->timeWindow.skey))) {
-      (*pIter)->pSttBlk = NULL;
-      (*pIter)->ignoreEarlierTs = true;
+    if (backward && ((strictTimeRange && pIter->pSttBlk->maxKey <= pIter->timeWindow.skey) ||
+                     (!strictTimeRange && pIter->pSttBlk->maxKey < pIter->timeWindow.skey))) {
+      pIter->pSttBlk = NULL;
+      pIter->ignoreEarlierTs = true;
     }
   }
 
   return code;
-
-_exit:
-  taosMemoryFree(*pIter);
-  return code;
 }
 
-void tLDataIterClose(SLDataIter *pIter) { taosMemoryFree(pIter); }
+void tLDataIterClose(SLDataIter *pIter) { /*taosMemoryFree(pIter); */}
 
 void tLDataIterNextBlock(SLDataIter *pIter, const char *idStr) {
   int32_t step = pIter->backward ? -1 : 1;
@@ -590,43 +570,38 @@ static FORCE_INLINE int32_t tLDataIterDescCmprFn(const SRBTreeNode *p1, const SR
 
 int32_t tMergeTreeOpen(SMergeTree *pMTree, int8_t backward, SDataFReader *pFReader, uint64_t suid, uint64_t uid,
                        STimeWindow *pTimeWindow, SVersionRange *pVerRange, SSttBlockLoadInfo *pBlockLoadInfo,
-                       bool destroyLoadInfo, const char *idStr, bool strictTimeRange) {
+                       bool destroyLoadInfo, const char *idStr, bool strictTimeRange, SLDataIter* pLDataIter) {
+  int32_t code = TSDB_CODE_SUCCESS;
+
   pMTree->backward = backward;
   pMTree->pIter = NULL;
-  pMTree->pIterList = taosArrayInit(4, POINTER_BYTES);
-  if (pMTree->pIterList == NULL) {
-    return TSDB_CODE_OUT_OF_MEMORY;
-  }
-
   pMTree->idStr = idStr;
+
   if (!pMTree->backward) {  // asc
     tRBTreeCreate(&pMTree->rbt, tLDataIterCmprFn);
   } else {  // desc
     tRBTreeCreate(&pMTree->rbt, tLDataIterDescCmprFn);
   }
-  int32_t code = TSDB_CODE_SUCCESS;
 
   pMTree->pLoadInfo = pBlockLoadInfo;
   pMTree->destroyLoadInfo = destroyLoadInfo;
   pMTree->ignoreEarlierTs = false;
 
   for (int32_t i = 0; i < pFReader->pSet->nSttF; ++i) {  // open all last file
-    struct SLDataIter *pIter = NULL;
-    code = tLDataIterOpen(&pIter, pFReader, i, pMTree->backward, suid, uid, pTimeWindow, pVerRange,
+    memset(&pLDataIter[i], 0, sizeof(SLDataIter));
+    code = tLDataIterOpen(&pLDataIter[i], pFReader, i, pMTree->backward, suid, uid, pTimeWindow, pVerRange,
                           &pMTree->pLoadInfo[i], pMTree->idStr, strictTimeRange);
     if (code != TSDB_CODE_SUCCESS) {
       goto _end;
     }
 
-    bool hasVal = tLDataIterNextRow(pIter, pMTree->idStr);
+    bool hasVal = tLDataIterNextRow(&pLDataIter[i], pMTree->idStr);
     if (hasVal) {
-      taosArrayPush(pMTree->pIterList, &pIter);
-      tMergeTreeAddIter(pMTree, pIter);
+      tMergeTreeAddIter(pMTree, &pLDataIter[i]);
     } else {
       if (!pMTree->ignoreEarlierTs) {
-        pMTree->ignoreEarlierTs = pIter->ignoreEarlierTs;
+        pMTree->ignoreEarlierTs = pLDataIter[i].ignoreEarlierTs;
       }
-      tLDataIterClose(pIter);
     }
   }
 
@@ -674,18 +649,8 @@ bool tMergeTreeNext(SMergeTree *pMTree) {
   return pMTree->pIter != NULL;
 }
 
-TSDBROW tMergeTreeGetRow(SMergeTree *pMTree) { return pMTree->pIter->rInfo.row; }
-
 void tMergeTreeClose(SMergeTree *pMTree) {
-  size_t size = taosArrayGetSize(pMTree->pIterList);
-  for (int32_t i = 0; i < size; ++i) {
-    SLDataIter *pIter = taosArrayGetP(pMTree->pIterList, i);
-    tLDataIterClose(pIter);
-  }
-
-  pMTree->pIterList = taosArrayDestroy(pMTree->pIterList);
   pMTree->pIter = NULL;
-
   if (pMTree->destroyLoadInfo) {
     pMTree->pLoadInfo = destroyLastBlockLoadInfo(pMTree->pLoadInfo);
     pMTree->destroyLoadInfo = false;
diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c
index 362dc51ad5..2fc2b8cdd6 100644
--- a/source/dnode/vnode/src/tsdb/tsdbRead.c
+++ b/source/dnode/vnode/src/tsdb/tsdbRead.c
@@ -18,6 +18,12 @@
 #include "tsimplehash.h"
 
 #define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC)
+#define getCurrentKeyInLastBlock(_r) ((_r)->currentKey)
+
+typedef enum {
+  READER_STATUS_SUSPEND = 0x1,
+  READER_STATUS_NORMAL = 0x2,
+} EReaderStatus;
 
 typedef enum {
   EXTERNAL_ROWS_PREV = 0x1,
@@ -108,6 +114,7 @@ typedef struct SLastBlockReader {
   uint64_t           uid;
   SMergeTree         mergeTree;
   SSttBlockLoadInfo* pInfo;
+  int64_t            currentKey;
 } SLastBlockReader;
 
 typedef struct SFilesetIter {
@@ -125,12 +132,12 @@ typedef struct SFileDataBlockInfo {
 } SFileDataBlockInfo;
 
 typedef struct SDataBlockIter {
-  int32_t   numOfBlocks;
-  int32_t   index;
-  SArray*   blockList;  // SArray
-  int32_t   order;
-  SDataBlk  block;  // current SDataBlk data
-  SHashObj* pTableMap;
+  int32_t    numOfBlocks;
+  int32_t    index;
+  SArray*    blockList;  // SArray
+  int32_t    order;
+  SDataBlk   block;  // current SDataBlk data
+  SSHashObj* pTableMap;
 } SDataBlockIter;
 
 typedef struct SFileBlockDumpInfo {
@@ -148,7 +155,8 @@ typedef struct STableUidList {
 typedef struct SReaderStatus {
   bool                  loadFromFile;       // check file stage
   bool                  composedDataBlock;  // the returned data block is a composed block or not
-  SHashObj*             pTableMap;          // SHash
+  bool                  mapDataCleaned;     // mapData has been cleaned up alreay or not
+  SSHashObj*            pTableMap;          // SHash
   STableBlockScanInfo** pTableIter;         // table iterator used in building in-memory buffer data blocks.
   STableUidList         uidList;            // check tables in uid order, to avoid the repeatly load of blocks in STT.
   SFileBlockDumpInfo    fBlockDumpInfo;
@@ -156,6 +164,9 @@ typedef struct SReaderStatus {
   SBlockData            fileBlockData;
   SFilesetIter          fileIter;
   SDataBlockIter        blockIter;
+  SLDataIter*           pLDataIter;
+  SRowMerger            merger;
+  SColumnInfoData*      pPrimaryTsCol;      // primary time stamp output col info data
 } SReaderStatus;
 
 typedef struct SBlockInfoBuf {
@@ -165,56 +176,68 @@ typedef struct SBlockInfoBuf {
   int32_t numOfTables;
 } SBlockInfoBuf;
 
+typedef struct STsdbReaderAttr {
+  STSchema*     pSchema;
+  EReadMode     readMode;
+  uint64_t      rowsNum;
+  STimeWindow   window;
+  bool          freeBlock;
+  SVersionRange verRange;
+  int16_t       order;
+} STsdbReaderAttr;
+
+typedef struct SResultBlockInfo {
+  SSDataBlock* pResBlock;
+  bool         freeBlock;
+  int64_t      capacity;
+} SResultBlockInfo;
+
 struct STsdbReader {
   STsdb*             pTsdb;
   SVersionRange      verRange;
   TdThreadMutex      readerMutex;
-  bool               suspended;
+  EReaderStatus      flag;
+  int32_t            code;
   uint64_t           suid;
   int16_t            order;
-  bool               freeBlock;
   EReadMode          readMode;
   uint64_t           rowsNum;
   STimeWindow        window;  // the primary query time window that applies to all queries
-  SSDataBlock*       pResBlock;
-  int32_t            capacity;
+  SResultBlockInfo   resBlockInfo;
   SReaderStatus      status;
   char*              idStr;  // query info handle, for debug purpose
   int32_t            type;   // query type: 1. retrieve all data blocks, 2. retrieve direct prev|next rows
   SBlockLoadSuppInfo suppInfo;
   STsdbReadSnap*     pReadSnap;
   SIOCostSummary     cost;
-  STSchema*          pSchema;  // the newest version schema
-  //  STSchema*          pMemSchema;   // the previous schema for in-memory data, to avoid load schema too many times
-  SSHashObj*    pSchemaMap;   // keep the retrieved schema info, to avoid the overhead by repeatly load schema
-  SDataFReader* pFileReader;  // the file reader
-  SDelFReader*  pDelFReader;  // the del file reader
-  SArray*       pDelIdx;      // del file block index;
-  SBlockInfoBuf blockInfoBuf;
-  int32_t       step;
-  STsdbReader*  innerReader[2];
+  STSchema*          pSchema;      // the newest version schema
+  SSHashObj*         pSchemaMap;   // keep the retrieved schema info, to avoid the overhead by repeatly load schema
+  SDataFReader*      pFileReader;  // the file reader
+  SDelFReader*       pDelFReader;  // the del file reader
+  SArray*            pDelIdx;      // del file block index;
+  SBlockInfoBuf      blockInfoBuf;
+  EContentData       step;
+  STsdbReader*       innerReader[2];
 };
 
 static SFileDataBlockInfo* getCurrentBlockInfo(SDataBlockIter* pBlockIter);
 static int      buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t endKey, int32_t capacity,
                                           STsdbReader* pReader);
 static TSDBROW* getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* pReader);
-static int32_t  doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pScanInfo, STsdbReader* pReader,
-                                        SRowMerger* pMerger);
+static int32_t  doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pScanInfo, STsdbReader* pReader);
 static int32_t  doMergeRowsInLastBlock(SLastBlockReader* pLastBlockReader, STableBlockScanInfo* pScanInfo, int64_t ts,
                                        SRowMerger* pMerger, SVersionRange* pVerRange, const char* id);
-static int32_t  doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, int64_t ts, SArray* pDelList, SRowMerger* pMerger,
-                                 STsdbReader* pReader);
+static int32_t  doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, int64_t ts, SArray* pDelList, STsdbReader* pReader);
 static int32_t  doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, SRow* pTSRow,
-                                     STableBlockScanInfo* pInfo);
+                                     STableBlockScanInfo* pScanInfo);
 static int32_t  doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, SBlockData* pBlockData,
                                          int32_t rowIndex);
 static void     setComposedBlockFlag(STsdbReader* pReader, bool composed);
-static bool     hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey, int32_t order,
+static bool     hasBeenDropped(const SArray* pDelList, int32_t* index, int64_t key, int64_t ver, int32_t order,
                                SVersionRange* pVerRange);
 
 static int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter, SArray* pDelList,
-                                        TSDBROW* pTSRow, STsdbReader* pReader, bool* freeTSRow);
+                                        TSDBROW* pResRow, STsdbReader* pReader, bool* freeTSRow);
 static int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* pBlockScanInfo,
                                   STsdbReader* pReader, SRow** pTSRow);
 static int32_t mergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pBlockScanInfo, int64_t key,
@@ -225,7 +248,6 @@ static int32_t initDelSkylineIterator(STableBlockScanInfo* pBlockScanInfo, STsdb
 static STsdb*  getTsdbByRetentions(SVnode* pVnode, TSKEY winSKey, SRetention* retentions, const char* idstr,
                                    int8_t* pLevel);
 static SVersionRange getQueryVerRange(SVnode* pVnode, SQueryTableDataCond* pCond, int8_t level);
-static int64_t       getCurrentKeyInLastBlock(SLastBlockReader* pLastBlockReader);
 static bool          hasDataInLastBlock(SLastBlockReader* pLastBlockReader);
 static int32_t       doBuildDataBlock(STsdbReader* pReader);
 static TSDBKEY       getCurrentKeyInBuf(STableBlockScanInfo* pScanInfo, STsdbReader* pReader);
@@ -233,9 +255,7 @@ static bool          hasDataInFileBlock(const SBlockData* pBlockData, const SFil
 static void          initBlockDumpInfo(STsdbReader* pReader, SDataBlockIter* pBlockIter);
 static int32_t       getInitialDelIndex(const SArray* pDelSkyline, int32_t order);
 
-static STableBlockScanInfo* getTableBlockScanInfo(SHashObj* pTableMap, uint64_t uid, const char* id);
-
-static FORCE_INLINE STSchema* getLatestTableSchema(STsdbReader* pReader, uint64_t uid);
+static STableBlockScanInfo* getTableBlockScanInfo(SSHashObj* pTableMap, uint64_t uid, const char* id);
 
 static bool outOfTimeWindow(int64_t ts, STimeWindow* pWindow) { return (ts > pWindow->ekey) || (ts < pWindow->skey); }
 
@@ -384,12 +404,11 @@ static int32_t uidComparFunc(const void* p1, const void* p2) {
 }
 
 // NOTE: speedup the whole processing by preparing the buffer for STableBlockScanInfo in batch model
-static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, SBlockInfoBuf* pBuf, const STableKeyInfo* idList,
+static SSHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, SBlockInfoBuf* pBuf, const STableKeyInfo* idList,
                                          STableUidList* pUidList, int32_t numOfTables) {
   // allocate buffer in order to load data blocks from file
   // todo use simple hash instead, optimize the memory consumption
-  SHashObj* pTableMap =
-      taosHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
+  SSHashObj* pTableMap = tSimpleHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
   if (pTableMap == NULL) {
     return NULL;
   }
@@ -399,7 +418,7 @@ static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, SBlockInfoBuf
 
   pUidList->tableUidList = taosMemoryMalloc(numOfTables * sizeof(uint64_t));
   if (pUidList->tableUidList == NULL) {
-    taosHashCleanup(pTableMap);
+    tSimpleHashCleanup(pTableMap);
     return NULL;
   }
 
@@ -421,7 +440,7 @@ static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, SBlockInfoBuf
       pScanInfo->lastKeyInStt = ekey;
     }
 
-    taosHashPut(pTableMap, &pScanInfo->uid, sizeof(uint64_t), &pScanInfo, POINTER_BYTES);
+    tSimpleHashPut(pTableMap, &pScanInfo->uid, sizeof(uint64_t), &pScanInfo, POINTER_BYTES);
     tsdbTrace("%p check table uid:%" PRId64 " from lastKey:%" PRId64 " %s", pTsdbReader, pScanInfo->uid,
               pScanInfo->lastKey, pTsdbReader->idStr);
   }
@@ -436,9 +455,11 @@ static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, SBlockInfoBuf
   return pTableMap;
 }
 
-static void resetAllDataBlockScanInfo(SHashObj* pTableMap, int64_t ts, int32_t step) {
-  STableBlockScanInfo** p = NULL;
-  while ((p = taosHashIterate(pTableMap, p)) != NULL) {
+static void resetAllDataBlockScanInfo(SSHashObj* pTableMap, int64_t ts, int32_t step) {
+  void   *p = NULL;
+  int32_t iter = 0;
+
+  while ((p = tSimpleHashIterate(pTableMap, p, &iter)) != NULL) {
     STableBlockScanInfo* pInfo = *(STableBlockScanInfo**)p;
 
     pInfo->iterInit = false;
@@ -478,13 +499,15 @@ static void clearBlockScanInfo(STableBlockScanInfo* p) {
   tMapDataClear(&p->mapData);
 }
 
-static void destroyAllBlockScanInfo(SHashObj* pTableMap) {
+static void destroyAllBlockScanInfo(SSHashObj* pTableMap) {
   void* p = NULL;
-  while ((p = taosHashIterate(pTableMap, p)) != NULL) {
+  int32_t iter = 0;
+
+  while ((p = tSimpleHashIterate(pTableMap, p, &iter)) != NULL) {
     clearBlockScanInfo(*(STableBlockScanInfo**)p);
   }
 
-  taosHashCleanup(pTableMap);
+  tSimpleHashCleanup(pTableMap);
 }
 
 static bool isEmptyQueryTimeWindow(STimeWindow* pWindow) { return pWindow->skey > pWindow->ekey; }
@@ -715,6 +738,21 @@ void tsdbReleaseDataBlock(STsdbReader* pReader) {
   }
 }
 
+static int32_t initResBlockInfo(SResultBlockInfo* pResBlockInfo, int64_t capacity, SSDataBlock* pResBlock, SQueryTableDataCond* pCond) {
+  pResBlockInfo->capacity = capacity;
+  pResBlockInfo->pResBlock = pResBlock;
+  terrno = 0;
+
+  if (pResBlockInfo->pResBlock == NULL) {
+    pResBlockInfo->freeBlock = true;
+    pResBlockInfo->pResBlock = createResBlock(pCond, pResBlockInfo->capacity);
+  } else {
+    pResBlockInfo->freeBlock = false;
+  }
+
+  return terrno;
+}
+
 static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, STsdbReader** ppReader, int32_t capacity,
                                 SSDataBlock* pResBlock, const char* idstr) {
   int32_t      code = 0;
@@ -734,21 +772,16 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, STsd
   pReader->pTsdb = getTsdbByRetentions(pVnode, pCond->twindows.skey, pVnode->config.tsdbCfg.retentions, idstr, &level);
   pReader->suid = pCond->suid;
   pReader->order = pCond->order;
-  pReader->capacity = capacity;
-  pReader->pResBlock = pResBlock;
+
   pReader->idStr = (idstr != NULL) ? taosStrdup(idstr) : NULL;
   pReader->verRange = getQueryVerRange(pVnode, pCond, level);
   pReader->type = pCond->type;
   pReader->window = updateQueryTimeWindow(pReader->pTsdb, &pCond->twindows);
   pReader->blockInfoBuf.numPerBucket = 1000;  // 1000 tables per bucket
 
-  if (pReader->pResBlock == NULL) {
-    pReader->freeBlock = true;
-    pReader->pResBlock = createResBlock(pCond, pReader->capacity);
-    if (pReader->pResBlock == NULL) {
-      code = terrno;
-      goto _end;
-    }
+  code = initResBlockInfo(&pReader->resBlockInfo, capacity, pResBlock, pCond);
+  if (code != TSDB_CODE_SUCCESS) {
+    goto _end;
   }
 
   if (pCond->numOfCols <= 0) {
@@ -766,6 +799,7 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, STsd
   }
 
   pSup->tsColAgg.colId = PRIMARYKEY_TIMESTAMP_COL_ID;
+  setColumnIdSlotList(pSup, pCond->colList, pCond->pSlotList, pCond->numOfCols);
 
   code = tBlockDataCreate(&pReader->status.fileBlockData);
   if (code != TSDB_CODE_SUCCESS) {
@@ -773,7 +807,20 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, STsd
     goto _end;
   }
 
-  setColumnIdSlotList(pSup, pCond->colList, pCond->pSlotList, pCond->numOfCols);
+  if (pReader->suppInfo.colId[0] != PRIMARYKEY_TIMESTAMP_COL_ID) {
+    tsdbError("the first column isn't primary timestamp, %d, %s", pReader->suppInfo.colId[0], pReader->idStr);
+    terrno = TSDB_CODE_INVALID_PARA;
+    goto _end;
+  }
+
+  pReader->status.pPrimaryTsCol = taosArrayGet(pReader->resBlockInfo.pResBlock->pDataBlock, pSup->slotId[0]);
+  int32_t type = pReader->status.pPrimaryTsCol->info.type;
+  if (type != TSDB_DATA_TYPE_TIMESTAMP) {
+    tsdbError("the first column isn't primary timestamp in result block, actual: %s, %s", tDataTypes[type].name,
+              pReader->idStr);
+    terrno = TSDB_CODE_INVALID_PARA;
+    goto _end;
+  }
 
   tsdbInitReaderLock(pReader);
 
@@ -794,7 +841,7 @@ static int32_t doLoadBlockIndex(STsdbReader* pReader, SDataFReader* pFileReader,
     goto _end;
   }
 
-  int32_t numOfTables = taosHashGetSize(pReader->status.pTableMap);
+  int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap);
 
   SArray* aBlockIdx = (SArray*)taosLRUCacheValue(pFileReader->pTsdb->biCache, handle);
   size_t  num = taosArrayGetSize(aBlockIdx);
@@ -858,28 +905,42 @@ _end:
   return code;
 }
 
-static void cleanupTableScanInfo(SHashObj* pTableMap) {
+static void doCleanupTableScanInfo(STableBlockScanInfo* pScanInfo) {
+  // reset the index in last block when handing a new file
+  tMapDataClear(&pScanInfo->mapData);
+  taosArrayClear(pScanInfo->pBlockList);
+}
+
+static void cleanupTableScanInfo(SReaderStatus* pStatus) {
+  if (pStatus->mapDataCleaned) {
+    return;
+  }
+
+  SSHashObj* pTableMap = pStatus->pTableMap;
   STableBlockScanInfo** px = NULL;
+  int32_t iter = 0;
+
   while (1) {
-    px = taosHashIterate(pTableMap, px);
+    px = tSimpleHashIterate(pTableMap, px, &iter);
     if (px == NULL) {
       break;
     }
 
-    // reset the index in last block when handing a new file
-    tMapDataClear(&(*px)->mapData);
-    taosArrayClear((*px)->pBlockList);
+    doCleanupTableScanInfo(*px);
   }
+
+  pStatus->mapDataCleaned = true;
 }
 
-static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockNumber* pBlockNum) {
-  int32_t numOfQTable = 0;
+static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockNumber* pBlockNum, SArray* pTableScanInfoList) {
   size_t  sizeInDisk = 0;
   size_t  numOfTables = taosArrayGetSize(pIndexList);
 
   int64_t st = taosGetTimestampUs();
-  cleanupTableScanInfo(pReader->status.pTableMap);
+  cleanupTableScanInfo(&pReader->status);
 
+  // set the flag for the new file
+  pReader->status.mapDataCleaned = false;
   for (int32_t i = 0; i < numOfTables; ++i) {
     SBlockIdx*           pBlockIdx = taosArrayGet(pIndexList, i);
     STableBlockScanInfo* pScanInfo = getTableBlockScanInfo(pReader->status.pTableMap, pBlockIdx->uid, pReader->idStr);
@@ -933,7 +994,7 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
     }
 
     if (taosArrayGetSize(pScanInfo->pBlockList) > 0) {
-      numOfQTable += 1;
+      taosArrayPush(pTableScanInfoList, &pScanInfo);
     }
   }
 
@@ -944,8 +1005,8 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN
   tsdbDebug(
       "load block of %ld tables completed, blocks:%d in %d tables, last-files:%d, block-info-size:%.2f Kb, elapsed "
       "time:%.2f ms %s",
-      numOfTables, pBlockNum->numOfBlocks, numOfQTable, pBlockNum->numOfLastFiles, sizeInDisk / 1000.0, el,
-      pReader->idStr);
+      numOfTables, pBlockNum->numOfBlocks, (int32_t)taosArrayGetSize(pTableScanInfoList), pBlockNum->numOfLastFiles,
+      sizeInDisk / 1000.0, el, pReader->idStr);
 
   pReader->cost.numOfBlocks += total;
   pReader->cost.headFileLoadTime += el;
@@ -1181,7 +1242,7 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
   SBlockData*         pBlockData = &pStatus->fileBlockData;
   SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter);
   SDataBlk*           pBlock = getCurrentBlock(pBlockIter);
-  SSDataBlock*        pResBlock = pReader->pResBlock;
+  SSDataBlock*        pResBlock = pReader->resBlockInfo.pResBlock;
   int32_t             numOfOutputCols = pSupInfo->numOfCols;
   int32_t             code = TSDB_CODE_SUCCESS;
 
@@ -1229,8 +1290,8 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
 
   endIndex += step;
   int32_t dumpedRows = asc ? (endIndex - pDumpInfo->rowIndex) : (pDumpInfo->rowIndex - endIndex);
-  if (dumpedRows > pReader->capacity) {  // output buffer check
-    dumpedRows = pReader->capacity;
+  if (dumpedRows > pReader->resBlockInfo.capacity) {  // output buffer check
+    dumpedRows = pReader->resBlockInfo.capacity;
   }
 
   int32_t i = 0;
@@ -1312,16 +1373,40 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader) {
   return TSDB_CODE_SUCCESS;
 }
 
+static FORCE_INLINE STSchema* getTableSchemaImpl(STsdbReader* pReader, uint64_t uid) {
+  ASSERT(pReader->pSchema == NULL);
+
+  int32_t code = metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, pReader->suid, uid, -1, &pReader->pSchema);
+  if (code != TSDB_CODE_SUCCESS || pReader->pSchema == NULL) {
+    terrno = code;
+    tsdbError("failed to get table schema, uid:%" PRIu64 ", it may have been dropped, ver:-1, %s", uid, pReader->idStr);
+    return NULL;
+  }
+
+  code = tsdbRowMergerInit(&pReader->status.merger, pReader->pSchema);
+  if (code != TSDB_CODE_SUCCESS) {
+    terrno = code;
+    tsdbError("failed to init merger, code:%s, %s", tstrerror(code), pReader->idStr);
+    return NULL;
+  }
+
+  return pReader->pSchema;
+}
+
 static int32_t doLoadFileBlockData(STsdbReader* pReader, SDataBlockIter* pBlockIter, SBlockData* pBlockData,
                                    uint64_t uid) {
-  int32_t code = 0;
-  int64_t st = taosGetTimestampUs();
+  int32_t   code = 0;
+  STSchema* pSchema = pReader->pSchema;
+  int64_t   st = taosGetTimestampUs();
 
   tBlockDataReset(pBlockData);
-  STSchema* pSchema = getLatestTableSchema(pReader, uid);
-  if (pSchema == NULL) {
-    tsdbDebug("%p table uid:%" PRIu64 " has been dropped, no data existed, %s", pReader, uid, pReader->idStr);
-    return code;
+
+  if (pReader->pSchema == NULL) {
+    pSchema = getTableSchemaImpl(pReader, uid);
+    if (pSchema == NULL) {
+      tsdbDebug("%p table uid:%" PRIu64 " has been dropped, no data existed, %s", pReader, uid, pReader->idStr);
+      return code;
+    }
   }
 
   SBlockLoadSuppInfo* pSup = &pReader->suppInfo;
@@ -1424,7 +1509,7 @@ static int32_t doSetCurrentBlock(SDataBlockIter* pBlockIter, const char* idStr)
   return TSDB_CODE_SUCCESS;
 }
 
-static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIter, int32_t numOfBlocks) {
+static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIter, int32_t numOfBlocks, SArray* pTableList) {
   bool asc = ASCENDING_TRAVERSE(pReader->order);
 
   SBlockOrderSupporter sup = {0};
@@ -1433,7 +1518,7 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte
   pBlockIter->pTableMap = pReader->status.pTableMap;
 
   // access data blocks according to the offset of each block in asc/desc order.
-  int32_t numOfTables = (int32_t)taosHashGetSize(pReader->status.pTableMap);
+  int32_t numOfTables = taosArrayGetSize(pTableList);
 
   int64_t st = taosGetTimestampUs();
   int32_t code = initBlockOrderSupporter(&sup, numOfTables);
@@ -1442,17 +1527,10 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte
   }
 
   int32_t cnt = 0;
-  void*   ptr = NULL;
-  while (1) {
-    ptr = taosHashIterate(pReader->status.pTableMap, ptr);
-    if (ptr == NULL) {
-      break;
-    }
 
-    STableBlockScanInfo* pTableScanInfo = *(STableBlockScanInfo**)ptr;
-    if (pTableScanInfo->pBlockList == NULL || taosArrayGetSize(pTableScanInfo->pBlockList) == 0) {
-      continue;
-    }
+  for (int32_t i = 0; i < numOfTables; ++i) {
+    STableBlockScanInfo* pTableScanInfo = taosArrayGetP(pTableList, i);
+    ASSERT(pTableScanInfo->pBlockList != NULL && taosArrayGetSize(pTableScanInfo->pBlockList) > 0);
 
     size_t num = taosArrayGetSize(pTableScanInfo->pBlockList);
     sup.numOfBlocksPerTable[sup.numOfTables] = num;
@@ -1728,7 +1806,7 @@ static void getBlockToLoadInfo(SDataBlockToLoadInfo* pInfo, SFileDataBlockInfo*
     pInfo->overlapWithLastBlock = !(pBlock->maxKey.ts < tsLast || pBlock->minKey.ts > tsLast);
   }
 
-  pInfo->moreThanCapcity = pBlock->nRow > pReader->capacity;
+  pInfo->moreThanCapcity = pBlock->nRow > pReader->resBlockInfo.capacity;
   pInfo->partiallyRequired = dataBlockPartiallyRequired(&pReader->window, &pReader->verRange, pBlock);
   pInfo->overlapWithKeyInBuf = keyOverlapFileBlock(keyInBuf, pBlock, &pReader->verRange);
 }
@@ -1775,10 +1853,10 @@ static int32_t buildDataBlockFromBuf(STsdbReader* pReader, STableBlockScanInfo*
     return TSDB_CODE_SUCCESS;
   }
 
-  SSDataBlock* pBlock = pReader->pResBlock;
+  SSDataBlock* pBlock = pReader->resBlockInfo.pResBlock;
 
   int64_t st = taosGetTimestampUs();
-  int32_t code = buildDataBlockFromBufImpl(pBlockScanInfo, endKey, pReader->capacity, pReader);
+  int32_t code = buildDataBlockFromBufImpl(pBlockScanInfo, endKey, pReader->resBlockInfo.capacity, pReader);
 
   blockDataUpdateTsWindow(pBlock, pReader->suppInfo.slotId[0]);
   pBlock->info.id.uid = pBlockScanInfo->uid;
@@ -1809,7 +1887,7 @@ static bool tryCopyDistinctRowFromFileBlock(STsdbReader* pReader, SBlockData* pB
 
     int64_t nextKey = pBlockData->aTSKEY[pDumpInfo->rowIndex + step];
     if (nextKey != key) {  // merge is not needed
-      code = doAppendRowFromFileBlock(pReader->pResBlock, pReader, pBlockData, pDumpInfo->rowIndex);
+      code = doAppendRowFromFileBlock(pReader->resBlockInfo.pResBlock, pReader, pBlockData, pDumpInfo->rowIndex);
       if (code) {
         return code;
       }
@@ -1832,13 +1910,14 @@ static bool nextRowFromLastBlocks(SLastBlockReader* pLastBlockReader, STableBloc
       return false;
     }
 
-    TSDBROW row = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
-    TSDBKEY k = TSDBROW_KEY(&row);
-    pScanInfo->lastKeyInStt = k.ts;
+    TSDBROW* pRow = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
+    int64_t key = pRow->pBlockData->aTSKEY[pRow->iRow];
+    int64_t ver = pRow->pBlockData->aVersion[pRow->iRow];
 
-    if (!hasBeenDropped(pScanInfo->delSkyline, &pScanInfo->lastBlockDelIndex, &k, pLastBlockReader->order, pVerRange)) {
-      // the qualifed ts may equal to k.ts, only a greater version one.
-      // here we need to fallback one step.
+    pLastBlockReader->currentKey = key;
+    pScanInfo->lastKeyInStt = key;
+
+    if (!hasBeenDropped(pScanInfo->delSkyline, &pScanInfo->lastBlockDelIndex, key, ver, pLastBlockReader->order, pVerRange)) {
       return true;
     }
   }
@@ -1855,7 +1934,7 @@ static bool tryCopyDistinctRowFromSttBlock(TSDBROW* fRow, SLastBlockReader* pLas
   if (hasVal) {
     int64_t next1 = getCurrentKeyInLastBlock(pLastBlockReader);
     if (next1 != ts) {
-      code = doAppendRowFromFileBlock(pReader->pResBlock, pReader, fRow->pBlockData, fRow->iRow);
+      code = doAppendRowFromFileBlock(pReader->resBlockInfo.pResBlock, pReader, fRow->pBlockData, fRow->iRow);
       if (code) {
         return code;
       }
@@ -1864,7 +1943,7 @@ static bool tryCopyDistinctRowFromSttBlock(TSDBROW* fRow, SLastBlockReader* pLas
       return code;
     }
   } else {
-    code = doAppendRowFromFileBlock(pReader->pResBlock, pReader, fRow->pBlockData, fRow->iRow);
+    code = doAppendRowFromFileBlock(pReader->resBlockInfo.pResBlock, pReader, fRow->pBlockData, fRow->iRow);
     if (code) {
       return code;
     }
@@ -1876,27 +1955,11 @@ static bool tryCopyDistinctRowFromSttBlock(TSDBROW* fRow, SLastBlockReader* pLas
   return code;
 }
 
-static FORCE_INLINE STSchema* getLatestTableSchema(STsdbReader* pReader, uint64_t uid) {
-  if (pReader->pSchema != NULL) {
-    return pReader->pSchema;
-  }
-
-  int32_t code = metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, pReader->suid, uid, -1, &pReader->pSchema);
-  if (code != TSDB_CODE_SUCCESS || pReader->pSchema == NULL) {
-    tsdbError("failed to get table schema, uid:%" PRIu64 ", it may have been dropped, ver:-1, %s", uid, pReader->idStr);
-  }
-
-  return pReader->pSchema;
-}
-
 static FORCE_INLINE STSchema* doGetSchemaForTSRow(int32_t sversion, STsdbReader* pReader, uint64_t uid) {
-  int32_t code = 0;
-
   // always set the newest schema version in pReader->pSchema
   if (pReader->pSchema == NULL) {
-    code = metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, pReader->suid, uid, -1, &pReader->pSchema);
-    if (code != TSDB_CODE_SUCCESS) {
-      terrno = code;
+    STSchema* ps = getTableSchemaImpl(pReader, uid);
+    if (ps == NULL) {
       return NULL;
     }
   }
@@ -1911,7 +1974,7 @@ static FORCE_INLINE STSchema* doGetSchemaForTSRow(int32_t sversion, STsdbReader*
   }
 
   STSchema* ptr = NULL;
-  code = metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, pReader->suid, uid, sversion, &ptr);
+  int32_t code = metaGetTbTSchemaEx(pReader->pTsdb->pVnode->pMeta, pReader->suid, uid, sversion, &ptr);
   if (code != TSDB_CODE_SUCCESS) {
     terrno = code;
     return NULL;
@@ -1927,7 +1990,7 @@ static FORCE_INLINE STSchema* doGetSchemaForTSRow(int32_t sversion, STsdbReader*
 
 static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo, TSDBROW* pRow,
                                      SIterInfo* pIter, int64_t key, SLastBlockReader* pLastBlockReader) {
-  SRowMerger          merge = {0};
+  SRowMerger*         pMerger = &pReader->status.merger;
   SRow*               pTSRow = NULL;
   SBlockData*         pBlockData = &pReader->status.fileBlockData;
   SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
@@ -1940,6 +2003,15 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
   TSDBKEY k = TSDBROW_KEY(pRow);
   TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
 
+  // merge is not initialized yet, due to the fact that the pReader->pSchema is not initialized
+  if (pMerger->pArray == NULL) {
+    ASSERT(pReader->pSchema == NULL);
+    STSchema* ps = getTableSchemaImpl(pReader, pBlockScanInfo->uid);
+    if (ps == NULL) {
+      return terrno;
+    }
+  }
+
   int64_t minKey = 0;
   if (pReader->order == TSDB_ORDER_ASC) {
     minKey = INT64_MAX;  // chosen the minimum value
@@ -1969,32 +2041,33 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
     }
   }
 
+  // todo remove init
   bool init = false;
 
   // ASC: file block ---> last block -----> imem -----> mem
   // DESC: mem -----> imem -----> last block -----> file block
   if (pReader->order == TSDB_ORDER_ASC) {
     if (minKey == key) {
-      init = true;  // todo check if pReader->pSchema is null or not
-      int32_t code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
+      init = true;
+      int32_t code = tsdbRowMergerAdd(pMerger, &fRow, pReader->pSchema);
       if (code != TSDB_CODE_SUCCESS) {
         return code;
       }
-      doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
+      doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader);
     }
 
     if (minKey == tsLast) {
-      TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
+      TSDBROW* fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
       if (init) {
-        tsdbRowMergerAdd(&merge, &fRow1, NULL);
+        tsdbRowMergerAdd(pMerger, fRow1, NULL);
       } else {
         init = true;
-        int32_t code = tsdbRowMergerInit(&merge, NULL, &fRow1, pReader->pSchema);
+        int32_t code = tsdbRowMergerAdd(pMerger, fRow1, pReader->pSchema);
         if (code != TSDB_CODE_SUCCESS) {
           return code;
         }
       }
-      doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLast, &merge, &pReader->verRange, pReader->idStr);
+      doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLast, pMerger, &pReader->verRange, pReader->idStr);
     }
 
     if (minKey == k.ts) {
@@ -2003,15 +2076,15 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
         return terrno;
       }
       if (init) {
-        tsdbRowMergerAdd(&merge, pRow, pSchema);
+        tsdbRowMergerAdd(pMerger, pRow, pSchema);
       } else {
         init = true;
-        int32_t code = tsdbRowMergerInit(&merge, NULL, pRow, pSchema);
+        int32_t code = tsdbRowMergerAdd(pMerger, pRow, pSchema);
         if (code != TSDB_CODE_SUCCESS) {
           return code;
         }
       }
-      int32_t code = doMergeRowsInBuf(pIter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, &merge, pReader);
+      int32_t code = doMergeRowsInBuf(pIter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, pReader);
       if (code != TSDB_CODE_SUCCESS) {
         return code;
       }
@@ -2024,54 +2097,54 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
         return terrno;
       }
 
-      int32_t   code = tsdbRowMergerInit(&merge, NULL, pRow, pSchema);
+      int32_t   code = tsdbRowMergerAdd(pMerger, pRow, pSchema);
       if (code != TSDB_CODE_SUCCESS) {
         return code;
       }
 
-      code = doMergeRowsInBuf(pIter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, &merge, pReader);
-      if (code != TSDB_CODE_SUCCESS || merge.pTSchema == NULL) {
+      code = doMergeRowsInBuf(pIter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, pReader);
+      if (code != TSDB_CODE_SUCCESS || pMerger->pTSchema == NULL) {
         return code;
       }
     }
 
     if (minKey == tsLast) {
-      TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
+      TSDBROW* fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
       if (init) {
-        tsdbRowMergerAdd(&merge, &fRow1, NULL);
+        tsdbRowMergerAdd(pMerger, fRow1, NULL);
       } else {
         init = true;
-        int32_t code = tsdbRowMergerInit(&merge, NULL, &fRow1, pReader->pSchema);
+        int32_t code = tsdbRowMergerAdd(pMerger, fRow1, pReader->pSchema);
         if (code != TSDB_CODE_SUCCESS) {
           return code;
         }
       }
-      doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLast, &merge, &pReader->verRange, pReader->idStr);
+      doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLast, pMerger, &pReader->verRange, pReader->idStr);
     }
 
     if (minKey == key) {
       if (init) {
-        tsdbRowMergerAdd(&merge, &fRow, NULL);
+        tsdbRowMergerAdd(pMerger, &fRow, NULL);
       } else {
         init = true;
-        int32_t code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
+        int32_t code = tsdbRowMergerAdd(pMerger, &fRow, pReader->pSchema);
         if (code != TSDB_CODE_SUCCESS) {
           return code;
         }
       }
-      doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
+      doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader);
     }
   }
 
-  int32_t code = tsdbRowMergerGetRow(&merge, &pTSRow);
+  int32_t code = tsdbRowMergerGetRow(pMerger, &pTSRow);
   if (code != TSDB_CODE_SUCCESS) {
     return code;
   }
 
-  code = doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
+  code = doAppendRowFromTSRow(pReader->resBlockInfo.pResBlock, pReader, pTSRow, pBlockScanInfo);
 
   taosMemoryFree(pTSRow);
-  tsdbRowMergerClear(&merge);
+  tsdbRowMergerClear(pMerger);
 
   return code;
 }
@@ -2079,14 +2152,19 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo*
 static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader, STsdbReader* pReader,
                                             STableBlockScanInfo* pBlockScanInfo, SBlockData* pBlockData,
                                             bool mergeBlockData) {
+  SRowMerger* pMerger = &pReader->status.merger;
   SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
-  int64_t             tsLastBlock = getCurrentKeyInLastBlock(pLastBlockReader);
-  bool                copied = false;
-  int32_t             code = TSDB_CODE_SUCCESS;
-  SRow*               pTSRow = NULL;
-  SRowMerger          merge = {0};
-  TSDBROW             fRow = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
-  tsdbTrace("fRow ptr:%p, %d, uid:%" PRIu64 ", %s", fRow.pBlockData, fRow.iRow, pLastBlockReader->uid, pReader->idStr);
+
+  int64_t  tsLastBlock = getCurrentKeyInLastBlock(pLastBlockReader);
+  bool     copied = false;
+  int32_t  code = TSDB_CODE_SUCCESS;
+  SRow*    pTSRow = NULL;
+  TSDBROW* pRow = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
+
+  // create local variable to hold the row value
+  TSDBROW  fRow = {.iRow = pRow->iRow, .type = TSDBROW_COL_FMT, .pBlockData = pRow->pBlockData};
+
+  tsdbTrace("fRow ptr:%p, %d, uid:%" PRIu64 ", %s", pRow->pBlockData, pRow->iRow, pLastBlockReader->uid, pReader->idStr);
 
   // only last block exists
   if ((!mergeBlockData) || (tsLastBlock != pBlockData->aTSKEY[pDumpInfo->rowIndex])) {
@@ -2099,51 +2177,51 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader,
       pBlockScanInfo->lastKey = tsLastBlock;
       return TSDB_CODE_SUCCESS;
     } else {
-      code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
+      code = tsdbRowMergerAdd(pMerger, &fRow, pReader->pSchema);
       if (code != TSDB_CODE_SUCCESS) {
         return code;
       }
 
-      TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
-      tsdbRowMergerAdd(&merge, &fRow1, NULL);
-      doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, &merge, &pReader->verRange, pReader->idStr);
+      TSDBROW* pRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
+      tsdbRowMergerAdd(pMerger, pRow1, NULL);
+      doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, pMerger, &pReader->verRange, pReader->idStr);
 
-      code = tsdbRowMergerGetRow(&merge, &pTSRow);
+      code = tsdbRowMergerGetRow(pMerger, &pTSRow);
       if (code != TSDB_CODE_SUCCESS) {
         return code;
       }
 
-      code = doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
+      code = doAppendRowFromTSRow(pReader->resBlockInfo.pResBlock, pReader, pTSRow, pBlockScanInfo);
 
       taosMemoryFree(pTSRow);
-      tsdbRowMergerClear(&merge);
+      tsdbRowMergerClear(pMerger);
 
       if (code != TSDB_CODE_SUCCESS) {
         return code;
       }
     }
   } else {  // not merge block data
-    code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
+    code = tsdbRowMergerAdd(pMerger, &fRow, pReader->pSchema);
     if (code != TSDB_CODE_SUCCESS) {
       return code;
     }
 
-    doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, &merge, &pReader->verRange, pReader->idStr);
+    doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, pMerger, &pReader->verRange, pReader->idStr);
 
     // merge with block data if ts == key
     if (tsLastBlock == pBlockData->aTSKEY[pDumpInfo->rowIndex]) {
-      doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
+      doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader);
     }
 
-    code = tsdbRowMergerGetRow(&merge, &pTSRow);
+    code = tsdbRowMergerGetRow(pMerger, &pTSRow);
     if (code != TSDB_CODE_SUCCESS) {
       return code;
     }
 
-    code = doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
+    code = doAppendRowFromTSRow(pReader->resBlockInfo.pResBlock, pReader, pTSRow, pBlockScanInfo);
 
     taosMemoryFree(pTSRow);
-    tsdbRowMergerClear(&merge);
+    tsdbRowMergerClear(pMerger);
 
     if (code != TSDB_CODE_SUCCESS) {
       return code;
@@ -2156,6 +2234,16 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader,
 static int32_t mergeFileBlockAndLastBlock(STsdbReader* pReader, SLastBlockReader* pLastBlockReader, int64_t key,
                                           STableBlockScanInfo* pBlockScanInfo, SBlockData* pBlockData) {
   SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
+  SRowMerger* pMerger = &pReader->status.merger;
+
+  // merge is not initialized yet, due to the fact that the pReader->pSchema is not initialized
+  if (pMerger->pArray == NULL) {
+    ASSERT(pReader->pSchema == NULL);
+    STSchema* ps = getTableSchemaImpl(pReader, pBlockScanInfo->uid);
+    if (ps == NULL) {
+      return terrno;
+    }
+  }
 
   if (hasDataInFileBlock(pBlockData, pDumpInfo)) {
     // no last block available, only data block exists
@@ -2172,30 +2260,28 @@ static int32_t mergeFileBlockAndLastBlock(STsdbReader* pReader, SLastBlockReader
       if (key < ts) {  // imem, mem are all empty, file blocks (data blocks and last block) exist
         return mergeRowsInFileBlocks(pBlockData, pBlockScanInfo, key, pReader);
       } else if (key == ts) {
-        SRow*      pTSRow = NULL;
-        SRowMerger merge = {0};
-
-        int32_t code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
+        SRow*       pTSRow = NULL;
+        int32_t code = tsdbRowMergerAdd(pMerger, &fRow, pReader->pSchema);
         if (code != TSDB_CODE_SUCCESS) {
           return code;
         }
 
-        doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
+        doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader);
 
-        TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
-        tsdbRowMergerAdd(&merge, &fRow1, NULL);
+        TSDBROW* pRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
+        tsdbRowMergerAdd(pMerger, pRow1, NULL);
 
-        doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, ts, &merge, &pReader->verRange, pReader->idStr);
+        doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, ts, pMerger, &pReader->verRange, pReader->idStr);
 
-        code = tsdbRowMergerGetRow(&merge, &pTSRow);
+        code = tsdbRowMergerGetRow(pMerger, &pTSRow);
         if (code != TSDB_CODE_SUCCESS) {
           return code;
         }
 
-        code = doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
+        code = doAppendRowFromTSRow(pReader->resBlockInfo.pResBlock, pReader, pTSRow, pBlockScanInfo);
 
         taosMemoryFree(pTSRow);
-        tsdbRowMergerClear(&merge);
+        tsdbRowMergerClear(pMerger);
         return code;
       } else {
         return TSDB_CODE_SUCCESS;
@@ -2210,7 +2296,7 @@ static int32_t mergeFileBlockAndLastBlock(STsdbReader* pReader, SLastBlockReader
 
 static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo, SBlockData* pBlockData,
                                      SLastBlockReader* pLastBlockReader) {
-  SRowMerger          merge = {0};
+  SRowMerger*         pMerger = &pReader->status.merger;
   SRow*               pTSRow = NULL;
   int32_t             code = TSDB_CODE_SUCCESS;
   SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
@@ -2238,6 +2324,15 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
     return code;
   }
 
+  // merge is not initialized yet, due to the fact that the pReader->pSchema is not initialized
+  if (pMerger->pArray == NULL) {
+    ASSERT(pReader->pSchema == NULL);
+    STSchema* ps = getTableSchemaImpl(pReader, pBlockScanInfo->uid);
+    if (ps == NULL) {
+      return terrno;
+    }
+  }
+
   int64_t minKey = 0;
   if (ASCENDING_TRAVERSE(pReader->order)) {
     minKey = INT64_MAX;  // let's find the minimum
@@ -2283,42 +2378,41 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
     if (minKey == key) {
       init = true;
       TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
-      code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
+      code = tsdbRowMergerAdd(pMerger, &fRow, pReader->pSchema);
       if (code != TSDB_CODE_SUCCESS) {
         return code;
       }
 
-      doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
+      doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader);
     }
 
     if (minKey == tsLast) {
-      TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
+      TSDBROW* pRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
       if (init) {
-        tsdbRowMergerAdd(&merge, &fRow1, NULL);
+        tsdbRowMergerAdd(pMerger, pRow1, NULL);
       } else {
         init = true;
-        code = tsdbRowMergerInit(&merge, NULL, &fRow1, pReader->pSchema);
+        code = tsdbRowMergerAdd(pMerger, pRow1, pReader->pSchema);
         if (code != TSDB_CODE_SUCCESS) {
           return code;
         }
       }
 
-      doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLast, &merge, &pReader->verRange, pReader->idStr);
+      doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLast, pMerger, &pReader->verRange, pReader->idStr);
     }
 
     if (minKey == ik.ts) {
       if (init) {
-        tsdbRowMergerAdd(&merge, piRow, piSchema);
+        tsdbRowMergerAdd(pMerger, piRow, piSchema);
       } else {
         init = true;
-        code = tsdbRowMergerInit(&merge, pSchema, piRow, piSchema);
+        code = tsdbRowMergerAdd(pMerger, piRow, piSchema);
         if (code != TSDB_CODE_SUCCESS) {
           return code;
         }
       }
 
-      code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, &merge,
-                              pReader);
+      code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, pReader);
       if (code != TSDB_CODE_SUCCESS) {
         return code;
       }
@@ -2326,20 +2420,15 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
 
     if (minKey == k.ts) {
       if (init) {
-        if (merge.pTSchema == NULL) {
-          return code;
-        }
-
-        tsdbRowMergerAdd(&merge, pRow, pSchema);
+        tsdbRowMergerAdd(pMerger, pRow, pSchema);
       } else {
         // STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(pRow), pReader, pBlockScanInfo->uid);
-        code = tsdbRowMergerInit(&merge, NULL, pRow, pSchema);
+        code = tsdbRowMergerAdd(pMerger, pRow, pSchema);
         if (code != TSDB_CODE_SUCCESS) {
           return code;
         }
       }
-      code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, &merge,
-                              pReader);
+      code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, pReader);
       if (code != TSDB_CODE_SUCCESS) {
         return code;
       }
@@ -2347,13 +2436,12 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
   } else {
     if (minKey == k.ts) {
       init = true;
-      code = tsdbRowMergerInit(&merge, NULL, pRow, pSchema);
+      code = tsdbRowMergerAdd(pMerger, pRow, pSchema);
       if (code != TSDB_CODE_SUCCESS) {
         return code;
       }
 
-      code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, &merge,
-                              pReader);
+      code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, pReader);
       if (code != TSDB_CODE_SUCCESS) {
         return code;
       }
@@ -2361,66 +2449,57 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo*
 
     if (minKey == ik.ts) {
       if (init) {
-        tsdbRowMergerAdd(&merge, piRow, piSchema);
+        tsdbRowMergerAdd(pMerger, piRow, piSchema);
       } else {
         init = true;
-        // STSchema* pSchema = doGetSchemaForTSRow(TSDBROW_SVERSION(piRow), pReader, pBlockScanInfo->uid);
-        code = tsdbRowMergerInit(&merge, pSchema, piRow, piSchema);
+        code = tsdbRowMergerAdd(pMerger, piRow, piSchema);
         if (code != TSDB_CODE_SUCCESS) {
           return code;
         }
       }
-      code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, &merge,
-                              pReader);
+      code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, pReader);
       if (code != TSDB_CODE_SUCCESS) {
         return code;
       }
     }
 
     if (minKey == tsLast) {
-      TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
+      TSDBROW* pRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
       if (init) {
-        tsdbRowMergerAdd(&merge, &fRow1, NULL);
+        tsdbRowMergerAdd(pMerger, pRow1, NULL);
       } else {
         init = true;
-        code = tsdbRowMergerInit(&merge, NULL, &fRow1, pReader->pSchema);
+        code = tsdbRowMergerAdd(pMerger, pRow1, pReader->pSchema);
         if (code != TSDB_CODE_SUCCESS) {
           return code;
         }
       }
-      doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLast, &merge, &pReader->verRange, pReader->idStr);
+      doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLast, pMerger, &pReader->verRange, pReader->idStr);
     }
 
     if (minKey == key) {
       TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
       if (!init) {
-        code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
+        code = tsdbRowMergerAdd(pMerger, &fRow, pReader->pSchema);
         if (code != TSDB_CODE_SUCCESS) {
           return code;
         }
       } else {
-        if (merge.pTSchema == NULL) {
-          return code;
-        }
-        tsdbRowMergerAdd(&merge, &fRow, NULL);
+        tsdbRowMergerAdd(pMerger, &fRow, NULL);
       }
-      doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
+      doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader);
     }
   }
 
-  if (merge.pTSchema == NULL) {
-    return code;
-  }
-
-  code = tsdbRowMergerGetRow(&merge, &pTSRow);
+  code = tsdbRowMergerGetRow(pMerger, &pTSRow);
   if (code != TSDB_CODE_SUCCESS) {
     return code;
   }
 
-  code = doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
+  code = doAppendRowFromTSRow(pReader->resBlockInfo.pResBlock, pReader, pTSRow, pBlockScanInfo);
 
   taosMemoryFree(pTSRow);
-  tsdbRowMergerClear(&merge);
+  tsdbRowMergerClear(pMerger);
   return code;
 }
 
@@ -2514,8 +2593,7 @@ static bool isValidFileBlockRow(SBlockData* pBlockData, SFileBlockDumpInfo* pDum
     return false;
   }
 
-  TSDBKEY k = {.ts = ts, .version = ver};
-  if (hasBeenDropped(pBlockScanInfo->delSkyline, &pBlockScanInfo->fileDelIndex, &k, pReader->order,
+  if (hasBeenDropped(pBlockScanInfo->delSkyline, &pBlockScanInfo->fileDelIndex, ts, ver, pReader->order,
                      &pReader->verRange)) {
     return false;
   }
@@ -2547,7 +2625,7 @@ static bool initLastBlockReader(SLastBlockReader* pLBlockReader, STableBlockScan
             pScanInfo->uid, pReader->idStr);
   int32_t code = tMergeTreeOpen(&pLBlockReader->mergeTree, (pLBlockReader->order == TSDB_ORDER_DESC),
                                 pReader->pFileReader, pReader->suid, pScanInfo->uid, &w, &pLBlockReader->verRange,
-                                pLBlockReader->pInfo, false, pReader->idStr, false);
+                                pLBlockReader->pInfo, false, pReader->idStr, false, pReader->status.pLDataIter);
   if (code != TSDB_CODE_SUCCESS) {
     return false;
   }
@@ -2555,11 +2633,6 @@ static bool initLastBlockReader(SLastBlockReader* pLBlockReader, STableBlockScan
   return nextRowFromLastBlocks(pLBlockReader, pScanInfo, &pReader->verRange);
 }
 
-static int64_t getCurrentKeyInLastBlock(SLastBlockReader* pLastBlockReader) {
-  TSDBROW row = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
-  return TSDBROW_TS(&row);
-}
-
 static bool hasDataInLastBlock(SLastBlockReader* pLastBlockReader) { return pLastBlockReader->mergeTree.pIter != NULL; }
 
 bool hasDataInFileBlock(const SBlockData* pBlockData, const SFileBlockDumpInfo* pDumpInfo) {
@@ -2571,6 +2644,7 @@ bool hasDataInFileBlock(const SBlockData* pBlockData, const SFileBlockDumpInfo*
 
 int32_t mergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pBlockScanInfo, int64_t key,
                               STsdbReader* pReader) {
+  SRowMerger*         pMerger = &pReader->status.merger;
   SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
   bool                copied = false;
   int32_t             code = tryCopyDistinctRowFromFileBlock(pReader, pBlockData, key, pDumpInfo, &copied);
@@ -2578,6 +2652,15 @@ int32_t mergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pBloc
     return code;
   }
 
+  // merge is not initialized yet, due to the fact that the pReader->pSchema is not initialized
+  if (pMerger->pArray == NULL) {
+    ASSERT(pReader->pSchema == NULL);
+    STSchema* ps = getTableSchemaImpl(pReader, pBlockScanInfo->uid);
+    if (ps == NULL) {
+      return terrno;
+    }
+  }
+
   if (copied) {
     pBlockScanInfo->lastKey = key;
     return TSDB_CODE_SUCCESS;
@@ -2585,23 +2668,21 @@ int32_t mergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pBloc
     TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex);
 
     SRow*      pTSRow = NULL;
-    SRowMerger merge = {0};
-
-    code = tsdbRowMergerInit(&merge, NULL, &fRow, pReader->pSchema);
+    code = tsdbRowMergerAdd(pMerger, &fRow, pReader->pSchema);
     if (code != TSDB_CODE_SUCCESS) {
       return code;
     }
 
-    doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge);
-    code = tsdbRowMergerGetRow(&merge, &pTSRow);
+    doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader);
+    code = tsdbRowMergerGetRow(pMerger, &pTSRow);
     if (code != TSDB_CODE_SUCCESS) {
       return code;
     }
 
-    code = doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo);
+    code = doAppendRowFromTSRow(pReader->resBlockInfo.pResBlock, pReader, pTSRow, pBlockScanInfo);
 
     taosMemoryFree(pTSRow);
-    tsdbRowMergerClear(&merge);
+    tsdbRowMergerClear(pMerger);
     return code;
   }
 }
@@ -2680,7 +2761,7 @@ static int32_t loadNeighborIfOverlap(SFileDataBlockInfo* pBlockInfo, STableBlock
 }
 
 static void updateComposedBlockInfo(STsdbReader* pReader, double el, STableBlockScanInfo* pBlockScanInfo) {
-  SSDataBlock* pResBlock = pReader->pResBlock;
+  SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock;
 
   pResBlock->info.id.uid = (pBlockScanInfo != NULL) ? pBlockScanInfo->uid : 0;
   pResBlock->info.dataLoad = 1;
@@ -2695,7 +2776,7 @@ static void updateComposedBlockInfo(STsdbReader* pReader, double el, STableBlock
 static int32_t buildComposedDataBlock(STsdbReader* pReader) {
   int32_t code = TSDB_CODE_SUCCESS;
 
-  SSDataBlock* pResBlock = pReader->pResBlock;
+  SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock;
 
   SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(&pReader->status.blockIter);
   SLastBlockReader*   pLastBlockReader = pReader->status.fileIter.pLastBlockReader;
@@ -2717,7 +2798,7 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) {
 
     // it is a clean block, load it directly
     if (isCleanFileDataBlock(pReader, pBlockInfo, pBlock, pBlockScanInfo, keyInBuf, pLastBlockReader) &&
-        pBlock->nRow <= pReader->capacity) {
+        pBlock->nRow <= pReader->resBlockInfo.capacity) {
       if (asc || ((!asc) && (!hasDataInLastBlock(pLastBlockReader)))) {
         code = copyBlockDataToSDataBlock(pReader);
         if (code) {
@@ -2781,7 +2862,7 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) {
       break;
     }
 
-    if (pResBlock->info.rows >= pReader->capacity) {
+    if (pResBlock->info.rows >= pReader->resBlockInfo.capacity) {
       break;
     }
   }
@@ -2905,18 +2986,24 @@ TSDBKEY getCurrentKeyInBuf(STableBlockScanInfo* pScanInfo, STsdbReader* pReader)
   }
 }
 
-static int32_t moveToNextFile(STsdbReader* pReader, SBlockNumber* pBlockNum) {
+static int32_t moveToNextFile(STsdbReader* pReader, SBlockNumber* pBlockNum, SArray* pTableList) {
   SReaderStatus* pStatus = &pReader->status;
   pBlockNum->numOfBlocks = 0;
   pBlockNum->numOfLastFiles = 0;
 
-  size_t  numOfTables = taosHashGetSize(pReader->status.pTableMap);
+  size_t  numOfTables = tSimpleHashGetSize(pReader->status.pTableMap);
   SArray* pIndexList = taosArrayInit(numOfTables, sizeof(SBlockIdx));
 
   while (1) {
+    // only check here, since the iterate data in memory is very fast.
+    if (pReader->code != TSDB_CODE_SUCCESS) {
+      tsdbWarn("tsdb reader is stopped ASAP, code:%s, %s", strerror(pReader->code), pReader->idStr);
+      return pReader->code;
+    }
+
     bool    hasNext = false;
     int32_t code = filesetIteratorNext(&pStatus->fileIter, pReader, &hasNext);
-    if (code) {
+    if (code != TSDB_CODE_SUCCESS) {
       taosArrayDestroy(pIndexList);
       return code;
     }
@@ -2933,7 +3020,7 @@ static int32_t moveToNextFile(STsdbReader* pReader, SBlockNumber* pBlockNum) {
     }
 
     if (taosArrayGetSize(pIndexList) > 0 || pReader->pFileReader->pSet->nSttF > 0) {
-      code = doLoadFileBlock(pReader, pIndexList, pBlockNum);
+      code = doLoadFileBlock(pReader, pIndexList, pBlockNum, pTableList);
       if (code != TSDB_CODE_SUCCESS) {
         taosArrayDestroy(pIndexList);
         return code;
@@ -2979,18 +3066,18 @@ static void resetTableListIndex(SReaderStatus* pStatus) {
 
   pList->currentIndex = 0;
   uint64_t uid = pList->tableUidList[0];
-  pStatus->pTableIter = taosHashGet(pStatus->pTableMap, &uid, sizeof(uid));
+  pStatus->pTableIter = tSimpleHashGet(pStatus->pTableMap, &uid, sizeof(uid));
 }
 
 static bool moveToNextTable(STableUidList* pOrderedCheckInfo, SReaderStatus* pStatus) {
   pOrderedCheckInfo->currentIndex += 1;
-  if (pOrderedCheckInfo->currentIndex >= taosHashGetSize(pStatus->pTableMap)) {
+  if (pOrderedCheckInfo->currentIndex >= tSimpleHashGetSize(pStatus->pTableMap)) {
     pStatus->pTableIter = NULL;
     return false;
   }
 
   uint64_t uid = pOrderedCheckInfo->tableUidList[pOrderedCheckInfo->currentIndex];
-  pStatus->pTableIter = taosHashGet(pStatus->pTableMap, &uid, sizeof(uid));
+  pStatus->pTableIter = tSimpleHashGet(pStatus->pTableMap, &uid, sizeof(uid));
   return (pStatus->pTableIter != NULL);
 }
 
@@ -3000,18 +3087,27 @@ static int32_t doLoadLastBlockSequentially(STsdbReader* pReader) {
   STableUidList*    pUidList = &pStatus->uidList;
   int32_t           code = TSDB_CODE_SUCCESS;
 
-  if (taosHashGetSize(pStatus->pTableMap) == 0) {
+  if (tSimpleHashGetSize(pStatus->pTableMap) == 0) {
     return TSDB_CODE_SUCCESS;
   }
 
-  SSDataBlock* pResBlock = pReader->pResBlock;
+  SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock;
 
   while (1) {
+    if (pReader->code != TSDB_CODE_SUCCESS) {
+      tsdbWarn("tsdb reader is stopped ASAP, code:%s, %s", strerror(pReader->code), pReader->idStr);
+      return pReader->code;
+    }
+
     // load the last data block of current table
     STableBlockScanInfo* pScanInfo = *(STableBlockScanInfo**)pStatus->pTableIter;
 
-    bool hasVal = initLastBlockReader(pLastBlockReader, pScanInfo, pReader);
-    if (!hasVal) {
+    // reset the index in last block when handing a new file
+    doCleanupTableScanInfo(pScanInfo);
+    pStatus->mapDataCleaned = true;
+
+    bool hasDataInLastFile = initLastBlockReader(pLastBlockReader, pScanInfo, pReader);
+    if (!hasDataInLastFile) {
       bool hasNexTable = moveToNextTable(pUidList, pStatus);
       if (!hasNexTable) {
         return TSDB_CODE_SUCCESS;
@@ -3034,7 +3130,7 @@ static int32_t doLoadLastBlockSequentially(STsdbReader* pReader) {
         return code;
       }
 
-      if (pResBlock->info.rows >= pReader->capacity) {
+      if (pResBlock->info.rows >= pReader->resBlockInfo.capacity) {
         break;
       }
     }
@@ -3100,7 +3196,7 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
       SBlockData* pBData = &pReader->status.fileBlockData;
       tBlockDataReset(pBData);
 
-      SSDataBlock* pResBlock = pReader->pResBlock;
+      SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock;
       tsdbDebug("load data in last block firstly, due to desc scan data, %s", pReader->idStr);
 
       int64_t st = taosGetTimestampUs();
@@ -3118,7 +3214,7 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
           return code;
         }
 
-        if (pResBlock->info.rows >= pReader->capacity) {
+        if (pResBlock->info.rows >= pReader->resBlockInfo.capacity) {
           break;
         }
       }
@@ -3133,7 +3229,7 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
                   pResBlock->info.rows, el, pReader->idStr);
       }
     } else {  // whole block is required, return it directly
-      SDataBlockInfo* pInfo = &pReader->pResBlock->info;
+      SDataBlockInfo* pInfo = &pReader->resBlockInfo.pResBlock->info;
       pInfo->rows = pBlock->nRow;
       pInfo->id.uid = pScanInfo->uid;
       pInfo->dataLoad = 0;
@@ -3151,7 +3247,7 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
     }
   }
 
-  return code;
+  return (pReader->code != TSDB_CODE_SUCCESS)? pReader->code:code;
 }
 
 static int32_t doSumFileBlockRows(STsdbReader* pReader, SDataFReader* pFileReader) {
@@ -3162,7 +3258,7 @@ static int32_t doSumFileBlockRows(STsdbReader* pReader, SDataFReader* pFileReade
     goto _end;
   }
 
-  int32_t numOfTables = taosHashGetSize(pReader->status.pTableMap);
+  int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap);
 
   SArray* aBlockIdx = (SArray*)taosLRUCacheValue(pFileReader->pTsdb->biCache, handle);
   size_t  num = taosArrayGetSize(aBlockIdx);
@@ -3172,14 +3268,13 @@ static int32_t doSumFileBlockRows(STsdbReader* pReader, SDataFReader* pFileReade
   }
 
   SBlockIdx* pBlockIdx = NULL;
-  int32_t    i = 0;
   for (int32_t i = 0; i < num; ++i) {
     pBlockIdx = (SBlockIdx*)taosArrayGet(aBlockIdx, i);
     if (pBlockIdx->suid != pReader->suid) {
       continue;
     }
 
-    STableBlockScanInfo** p = taosHashGet(pReader->status.pTableMap, &pBlockIdx->uid, sizeof(pBlockIdx->uid));
+    STableBlockScanInfo** p = tSimpleHashGet(pReader->status.pTableMap, &pBlockIdx->uid, sizeof(pBlockIdx->uid));
     if (p == NULL) {
       continue;
     }
@@ -3225,13 +3320,13 @@ static int32_t doSumSttBlockRows(STsdbReader* pReader) {
           taosArrayClear(pBlockLoadInfo->aSttBlk);
           continue;
         }
-        for (int32_t i = 0; i < size; ++i) {
-          SSttBlk* p = taosArrayGet(pBlockLoadInfo->aSttBlk, i);
+        for (int32_t j = 0; j < size; ++j) {
+          SSttBlk* p = taosArrayGet(pBlockLoadInfo->aSttBlk, j);
           pReader->rowsNum += p->nRow;
         }
       } else {
-        for (int32_t i = 0; i < size; ++i) {
-          SSttBlk* p = taosArrayGet(pBlockLoadInfo->aSttBlk, i);
+        for (int32_t j = 0; j < size; ++j) {
+          SSttBlk* p = taosArrayGet(pBlockLoadInfo->aSttBlk, j);
           uint64_t s = p->suid;
           if (s < pReader->suid) {
             continue;
@@ -3301,12 +3396,10 @@ static int32_t buildBlockFromBufferSequentially(STsdbReader* pReader) {
   STableUidList* pUidList = &pStatus->uidList;
 
   while (1) {
-    //    if (pStatus->pTableIter == NULL) {
-    //      pStatus->pTableIter = taosHashIterate(pStatus->pTableMap, NULL);
-    //      if (pStatus->pTableIter == NULL) {
-    //        return TSDB_CODE_SUCCESS;
-    //      }
-    //    }
+    if (pReader->code != TSDB_CODE_SUCCESS) {
+      tsdbWarn("tsdb reader is stopped ASAP, code:%s, %s", strerror(pReader->code), pReader->idStr);
+      return pReader->code;
+    }
 
     STableBlockScanInfo** pBlockScanInfo = pStatus->pTableIter;
     initMemDataIterator(*pBlockScanInfo, pReader);
@@ -3317,7 +3410,7 @@ static int32_t buildBlockFromBufferSequentially(STsdbReader* pReader) {
       return code;
     }
 
-    if (pReader->pResBlock->info.rows > 0) {
+    if (pReader->resBlockInfo.pResBlock->info.rows > 0) {
       return TSDB_CODE_SUCCESS;
     }
 
@@ -3335,7 +3428,7 @@ static void initBlockDumpInfo(STsdbReader* pReader, SDataBlockIter* pBlockIter)
   SDataBlk*           pBlock = getCurrentBlock(pBlockIter);
   SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter);
   if (pBlockInfo) {
-    STableBlockScanInfo* pScanInfo = taosHashGet(pBlockIter->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
+    STableBlockScanInfo* pScanInfo = tSimpleHashGet(pBlockIter->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
     if (pScanInfo) {
       lastKey = pScanInfo->lastKey;
     }
@@ -3352,20 +3445,24 @@ static void initBlockDumpInfo(STsdbReader* pReader, SDataBlockIter* pBlockIter)
 
 static int32_t initForFirstBlockInFile(STsdbReader* pReader, SDataBlockIter* pBlockIter) {
   SBlockNumber num = {0};
-  int32_t      code = moveToNextFile(pReader, &num);
+  SArray* pTableList = taosArrayInit(40, POINTER_BYTES);
+
+  int32_t code = moveToNextFile(pReader, &num, pTableList);
   if (code != TSDB_CODE_SUCCESS) {
+    taosArrayDestroy(pTableList);
     return code;
   }
 
   // all data files are consumed, try data in buffer
   if (num.numOfBlocks + num.numOfLastFiles == 0) {
     pReader->status.loadFromFile = false;
+    taosArrayDestroy(pTableList);
     return code;
   }
 
   // initialize the block iterator for a new fileset
   if (num.numOfBlocks > 0) {
-    code = initBlockIterator(pReader, pBlockIter, num.numOfBlocks);
+    code = initBlockIterator(pReader, pBlockIter, num.numOfBlocks, pTableList);
   } else {  // no block data, only last block exists
     tBlockDataReset(&pReader->status.fileBlockData);
     resetDataBlockIterator(pBlockIter, pReader->order);
@@ -3374,6 +3471,7 @@ static int32_t initForFirstBlockInFile(STsdbReader* pReader, SDataBlockIter* pBl
 
   // set the correct start position according to the query time window
   initBlockDumpInfo(pReader, pBlockIter);
+  taosArrayDestroy(pTableList);
   return code;
 }
 
@@ -3382,47 +3480,65 @@ static bool fileBlockPartiallyRead(SFileBlockDumpInfo* pDumpInfo, bool asc) {
          ((pDumpInfo->rowIndex > 0 && asc) || (pDumpInfo->rowIndex < (pDumpInfo->totalRows - 1) && (!asc)));
 }
 
+typedef enum {
+  TSDB_READ_RETURN = 0x1,
+  TSDB_READ_CONTINUE = 0x2,
+} ERetrieveType;
+
+static ERetrieveType doReadDataFromLastFiles(STsdbReader* pReader) {
+  int32_t         code = TSDB_CODE_SUCCESS;
+  SSDataBlock*    pResBlock = pReader->resBlockInfo.pResBlock;
+  SDataBlockIter* pBlockIter = &pReader->status.blockIter;
+
+  while(1) {
+    terrno = 0;
+
+    code = doLoadLastBlockSequentially(pReader);
+    if (code != TSDB_CODE_SUCCESS) {
+      terrno = code;
+      return TSDB_READ_RETURN;
+    }
+
+    if (pResBlock->info.rows > 0) {
+      return TSDB_READ_RETURN;
+    }
+
+    // all data blocks are checked in this last block file, now let's try the next file
+    ASSERT(pReader->status.pTableIter == NULL);
+    code = initForFirstBlockInFile(pReader, pBlockIter);
+
+    // error happens or all the data files are completely checked
+    if ((code != TSDB_CODE_SUCCESS) || (pReader->status.loadFromFile == false)) {
+      terrno = code;
+      return TSDB_READ_RETURN;
+    }
+
+    if (pBlockIter->numOfBlocks > 0) { // there are data blocks existed.
+      return TSDB_READ_CONTINUE;
+    } else {  // all blocks in data file are checked, let's check the data in last files
+      resetTableListIndex(&pReader->status);
+    }
+  }
+}
+
 static int32_t buildBlockFromFiles(STsdbReader* pReader) {
   int32_t code = TSDB_CODE_SUCCESS;
   bool    asc = ASCENDING_TRAVERSE(pReader->order);
 
   SDataBlockIter* pBlockIter = &pReader->status.blockIter;
+  SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock;
 
   if (pBlockIter->numOfBlocks == 0) {
-  _begin:
-    code = doLoadLastBlockSequentially(pReader);
-    if (code != TSDB_CODE_SUCCESS) {
-      return code;
-    }
-
-    if (pReader->pResBlock->info.rows > 0) {
-      return TSDB_CODE_SUCCESS;
-    }
-
-    // all data blocks are checked in this last block file, now let's try the next file
-    if (pReader->status.pTableIter == NULL) {
-      code = initForFirstBlockInFile(pReader, pBlockIter);
-
-      // error happens or all the data files are completely checked
-      if ((code != TSDB_CODE_SUCCESS) || (pReader->status.loadFromFile == false)) {
-        return code;
-      }
-
-      // this file does not have data files, let's start check the last block file if exists
-      if (pBlockIter->numOfBlocks == 0) {
-        resetTableListIndex(&pReader->status);
-        goto _begin;
-      }
+    // let's try to extract data from stt files.
+    ERetrieveType type = doReadDataFromLastFiles(pReader);
+    if (type == TSDB_READ_RETURN) {
+      return terrno;
     }
 
     code = doBuildDataBlock(pReader);
-    if (code != TSDB_CODE_SUCCESS) {
+    if (code != TSDB_CODE_SUCCESS || pResBlock->info.rows > 0) {
       return code;
     }
-
-    if (pReader->pResBlock->info.rows > 0) {
-      return TSDB_CODE_SUCCESS;
-    }
   }
 
   while (1) {
@@ -3438,30 +3554,22 @@ static int32_t buildBlockFromFiles(STsdbReader* pReader) {
         if (hasNext) {  // check for the next block in the block accessed order list
           initBlockDumpInfo(pReader, pBlockIter);
         } else {
-          if (pReader->status.pCurrentFileset->nSttF > 0) {
-            // data blocks in current file are exhausted, let's try the next file now
-            SBlockData* pBlockData = &pReader->status.fileBlockData;
-            if (pBlockData->uid != 0) {
-              tBlockDataClear(pBlockData);
-            }
+          // all data blocks in files are checked, let's check the data in last files.
+          ASSERT(pReader->status.pCurrentFileset->nSttF > 0);
 
-            tBlockDataReset(pBlockData);
-            resetDataBlockIterator(pBlockIter, pReader->order);
-            resetTableListIndex(&pReader->status);
-            goto _begin;
-          } else {
-            code = initForFirstBlockInFile(pReader, pBlockIter);
+          // data blocks in current file are exhausted, let's try the next file now
+          SBlockData* pBlockData = &pReader->status.fileBlockData;
+          if (pBlockData->uid != 0) {
+            tBlockDataClear(pBlockData);
+          }
 
-            // error happens or all the data files are completely checked
-            if ((code != TSDB_CODE_SUCCESS) || (pReader->status.loadFromFile == false)) {
-              return code;
-            }
+          tBlockDataReset(pBlockData);
+          resetDataBlockIterator(pBlockIter, pReader->order);
+          resetTableListIndex(&pReader->status);
 
-            // this file does not have blocks, let's start check the last block file
-            if (pBlockIter->numOfBlocks == 0) {
-              resetTableListIndex(&pReader->status);
-              goto _begin;
-            }
+          ERetrieveType type = doReadDataFromLastFiles(pReader);
+          if (type == TSDB_READ_RETURN) {
+            return terrno;
           }
         }
       }
@@ -3469,13 +3577,9 @@ static int32_t buildBlockFromFiles(STsdbReader* pReader) {
       code = doBuildDataBlock(pReader);
     }
 
-    if (code != TSDB_CODE_SUCCESS) {
+    if (code != TSDB_CODE_SUCCESS || pResBlock->info.rows > 0) {
       return code;
     }
-
-    if (pReader->pResBlock->info.rows > 0) {
-      return TSDB_CODE_SUCCESS;
-    }
   }
 }
 
@@ -3537,7 +3641,7 @@ SVersionRange getQueryVerRange(SVnode* pVnode, SQueryTableDataCond* pCond, int8_
   return (SVersionRange){.minVer = startVer, .maxVer = endVer};
 }
 
-bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey, int32_t order, SVersionRange* pVerRange) {
+bool hasBeenDropped(const SArray* pDelList, int32_t* index, int64_t key, int64_t ver, int32_t order, SVersionRange* pVerRange) {
   if (pDelList == NULL) {
     return false;
   }
@@ -3549,29 +3653,29 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey, int32
   if (asc) {
     if (*index >= num - 1) {
       TSDBKEY* last = taosArrayGetLast(pDelList);
-      ASSERT(pKey->ts >= last->ts);
+      ASSERT(key >= last->ts);
 
-      if (pKey->ts > last->ts) {
+      if (key > last->ts) {
         return false;
-      } else if (pKey->ts == last->ts) {
+      } else if (key == last->ts) {
         TSDBKEY* prev = taosArrayGet(pDelList, num - 2);
-        return (prev->version >= pKey->version && prev->version <= pVerRange->maxVer &&
+        return (prev->version >= ver && prev->version <= pVerRange->maxVer &&
                 prev->version >= pVerRange->minVer);
       }
     } else {
       TSDBKEY* pCurrent = taosArrayGet(pDelList, *index);
       TSDBKEY* pNext = taosArrayGet(pDelList, (*index) + 1);
 
-      if (pKey->ts < pCurrent->ts) {
+      if (key < pCurrent->ts) {
         return false;
       }
 
-      if (pCurrent->ts <= pKey->ts && pNext->ts >= pKey->ts && pCurrent->version >= pKey->version &&
+      if (pCurrent->ts <= key && pNext->ts >= key && pCurrent->version >= ver &&
           pVerRange->maxVer >= pCurrent->version) {
         return true;
       }
 
-      while (pNext->ts <= pKey->ts && (*index) < num - 1) {
+      while (pNext->ts <= key && (*index) < num - 1) {
         (*index) += 1;
 
         if ((*index) < num - 1) {
@@ -3583,7 +3687,7 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey, int32
             continue;
           }
 
-          if (pCurrent->ts <= pKey->ts && pNext->ts >= pKey->ts && pCurrent->version >= pKey->version &&
+          if (pCurrent->ts <= key && pNext->ts >= key && pCurrent->version >= ver &&
               pVerRange->maxVer >= pCurrent->version) {
             return true;
           }
@@ -3596,10 +3700,10 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey, int32
     if (*index <= 0) {
       TSDBKEY* pFirst = taosArrayGet(pDelList, 0);
 
-      if (pKey->ts < pFirst->ts) {
+      if (key < pFirst->ts) {
         return false;
-      } else if (pKey->ts == pFirst->ts) {
-        return pFirst->version >= pKey->version;
+      } else if (key == pFirst->ts) {
+        return pFirst->version >= ver;
       } else {
         ASSERT(0);
       }
@@ -3607,15 +3711,15 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey, int32
       TSDBKEY* pCurrent = taosArrayGet(pDelList, *index);
       TSDBKEY* pPrev = taosArrayGet(pDelList, (*index) - 1);
 
-      if (pKey->ts > pCurrent->ts) {
+      if (key > pCurrent->ts) {
         return false;
       }
 
-      if (pPrev->ts <= pKey->ts && pCurrent->ts >= pKey->ts && pPrev->version >= pKey->version) {
+      if (pPrev->ts <= key && pCurrent->ts >= key && pPrev->version >= ver) {
         return true;
       }
 
-      while (pPrev->ts >= pKey->ts && (*index) > 1) {
+      while (pPrev->ts >= key && (*index) > 1) {
         (*index) += step;
 
         if ((*index) >= 1) {
@@ -3627,7 +3731,7 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey, int32
             continue;
           }
 
-          if (pPrev->ts <= pKey->ts && pCurrent->ts >= pKey->ts && pPrev->version >= pKey->version) {
+          if (pPrev->ts <= key && pCurrent->ts >= key && pPrev->version >= ver) {
             return true;
           }
         }
@@ -3655,7 +3759,7 @@ TSDBROW* getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* p
 
   // it is a valid data version
   if ((key.version <= pReader->verRange.maxVer && key.version >= pReader->verRange.minVer) &&
-      (!hasBeenDropped(pDelList, &pIter->index, &key, pReader->order, &pReader->verRange))) {
+      (!hasBeenDropped(pDelList, &pIter->index, key.ts, key.version, pReader->order, &pReader->verRange))) {
     return pRow;
   }
 
@@ -3674,14 +3778,15 @@ TSDBROW* getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* p
     }
 
     if (key.version <= pReader->verRange.maxVer && key.version >= pReader->verRange.minVer &&
-        (!hasBeenDropped(pDelList, &pIter->index, &key, pReader->order, &pReader->verRange))) {
+        (!hasBeenDropped(pDelList, &pIter->index, key.ts, key.version, pReader->order, &pReader->verRange))) {
       return pRow;
     }
   }
 }
 
-int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, int64_t ts, SArray* pDelList, SRowMerger* pMerger,
-                         STsdbReader* pReader) {
+int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, int64_t ts, SArray* pDelList, STsdbReader* pReader) {
+  SRowMerger* pMerger = &pReader->status.merger;
+
   while (1) {
     pIter->hasVal = tsdbTbDataIterNext(pIter->iter);
     if (!pIter->hasVal) {
@@ -3760,10 +3865,10 @@ static int32_t checkForNeighborFileBlock(STsdbReader* pReader, STableBlockScanIn
   return code;
 }
 
-int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pScanInfo, STsdbReader* pReader,
-                                SRowMerger* pMerger) {
+int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pScanInfo, STsdbReader* pReader) {
   SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo;
 
+  SRowMerger* pMerger = &pReader->status.merger;
   bool    asc = ASCENDING_TRAVERSE(pReader->order);
   int64_t key = pBlockData->aTSKEY[pDumpInfo->rowIndex];
   int32_t step = asc ? 1 : -1;
@@ -3801,8 +3906,8 @@ int32_t doMergeRowsInLastBlock(SLastBlockReader* pLastBlockReader, STableBlockSc
   while (nextRowFromLastBlocks(pLastBlockReader, pScanInfo, pVerRange)) {
     int64_t next1 = getCurrentKeyInLastBlock(pLastBlockReader);
     if (next1 == ts) {
-      TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
-      tsdbRowMergerAdd(pMerger, &fRow1, NULL);
+      TSDBROW* pRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree);
+      tsdbRowMergerAdd(pMerger, pRow1, NULL);
     } else {
       tsdbTrace("uid:%" PRIu64 " last del index:%d, del range:%d, lastKeyInStt:%" PRId64 ", %s", pScanInfo->uid,
                 pScanInfo->lastBlockDelIndex, (int32_t)taosArrayGetSize(pScanInfo->delSkyline), pScanInfo->lastKeyInStt,
@@ -3842,7 +3947,6 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
     }
   }
 
-  SRowMerger merge = {0};
   terrno = 0;
   int32_t code = 0;
 
@@ -3854,8 +3958,7 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
       return terrno;
     }
 
-    STSchema* ps = (pReader->pSchema != NULL)? pReader->pSchema:pTSchema;
-    code = tsdbRowMergerInit(&merge, ps, ¤t, pTSchema);
+    code = tsdbRowMergerAdd(&pReader->status.merger, ¤t, pTSchema);
     if (code != TSDB_CODE_SUCCESS) {
       return code;
     }
@@ -3865,28 +3968,28 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
       return terrno;
     }
 
-    tsdbRowMergerAdd(&merge, pNextRow, pTSchema1);
+    tsdbRowMergerAdd(&pReader->status.merger,pNextRow, pTSchema1);
   } else {  // let's merge rows in file block
-    code = tsdbRowMergerInit(&merge, NULL, ¤t, pReader->pSchema);
+    code = tsdbRowMergerAdd(&pReader->status.merger, ¤t, pReader->pSchema);
     if (code != TSDB_CODE_SUCCESS) {
       return code;
     }
 
-    tsdbRowMergerAdd(&merge, pNextRow, NULL);
+    tsdbRowMergerAdd(&pReader->status.merger,pNextRow, NULL);
   }
 
-  code = doMergeRowsInBuf(pIter, uid, TSDBROW_TS(¤t), pDelList, &merge, pReader);
+  code = doMergeRowsInBuf(pIter, uid, TSDBROW_TS(¤t), pDelList, pReader);
   if (code != TSDB_CODE_SUCCESS) {
     return code;
   }
 
-  code = tsdbRowMergerGetRow(&merge, &pResRow->pTSRow);
+  code = tsdbRowMergerGetRow(&pReader->status.merger, &pResRow->pTSRow);
   if (code != TSDB_CODE_SUCCESS) {
     return code;
   }
 
   pResRow->type = TSDBROW_ROW_FMT;
-  tsdbRowMergerClear(&merge);
+  tsdbRowMergerClear(&pReader->status.merger);
   *freeTSRow = true;
 
   return TSDB_CODE_SUCCESS;
@@ -3894,7 +3997,7 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
 
 int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader,
                            SRow** pTSRow) {
-  SRowMerger merge = {0};
+  SRowMerger* pMerger = &pReader->status.merger;
 
   TSDBKEY   k = TSDBROW_KEY(pRow);
   TSDBKEY   ik = TSDBROW_KEY(piRow);
@@ -3909,46 +4012,43 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
   }
 
   if (ASCENDING_TRAVERSE(pReader->order)) {  // ascending order imem --> mem
-    int32_t code = tsdbRowMergerInit(&merge, pSchema, piRow, piSchema);
+    int32_t code = tsdbRowMergerAdd(&pReader->status.merger, piRow, piSchema);
     if (code != TSDB_CODE_SUCCESS) {
       return code;
     }
 
-    code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, &merge,
-                            pReader);
+    code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, pReader);
     if (code != TSDB_CODE_SUCCESS) {
       return code;
     }
 
-    tsdbRowMergerAdd(&merge, pRow, pSchema);
+    tsdbRowMergerAdd(&pReader->status.merger,pRow, pSchema);
     code =
-        doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, &merge, pReader);
+        doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, pReader);
     if (code != TSDB_CODE_SUCCESS) {
       return code;
     }
 
   } else {
-    int32_t code = tsdbRowMergerInit(&merge, NULL, pRow, pSchema);
-    if (code != TSDB_CODE_SUCCESS || merge.pTSchema == NULL) {
+    int32_t code = tsdbRowMergerAdd(&pReader->status.merger, pRow, pSchema);
+    if (code != TSDB_CODE_SUCCESS || pMerger->pTSchema == NULL) {
       return code;
     }
 
-    code =
-        doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, &merge, pReader);
+    code = doMergeRowsInBuf(&pBlockScanInfo->iter, pBlockScanInfo->uid, k.ts, pBlockScanInfo->delSkyline, pReader);
     if (code != TSDB_CODE_SUCCESS) {
       return code;
     }
 
-    tsdbRowMergerAdd(&merge, piRow, piSchema);
-    code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, &merge,
-                            pReader);
+    tsdbRowMergerAdd(&pReader->status.merger, piRow, piSchema);
+    code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, pReader);
     if (code != TSDB_CODE_SUCCESS) {
       return code;
     }
   }
 
-  int32_t code = tsdbRowMergerGetRow(&merge, pTSRow);
-  tsdbRowMergerClear(&merge);
+  int32_t code = tsdbRowMergerGetRow(pMerger, pTSRow);
+  tsdbRowMergerClear(pMerger);
   return code;
 }
 
@@ -4073,11 +4173,8 @@ int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, S
   int32_t code = TSDB_CODE_SUCCESS;
 
   SBlockLoadSuppInfo* pSupInfo = &pReader->suppInfo;
-  if (pReader->suppInfo.colId[i] == PRIMARYKEY_TIMESTAMP_COL_ID) {
-    SColumnInfoData* pColData = taosArrayGet(pResBlock->pDataBlock, pSupInfo->slotId[i]);
-    ((int64_t*)pColData->pData)[outputRowIndex] = pBlockData->aTSKEY[rowIndex];
-    i += 1;
-  }
+  ((int64_t*)pReader->status.pPrimaryTsCol->pData)[outputRowIndex] = pBlockData->aTSKEY[rowIndex];
+  i += 1;
 
   SColVal cv = {0};
   int32_t numOfInputCols = pBlockData->nColData;
@@ -4119,7 +4216,7 @@ int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, S
 
 int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t endKey, int32_t capacity,
                                   STsdbReader* pReader) {
-  SSDataBlock* pBlock = pReader->pResBlock;
+  SSDataBlock* pBlock = pReader->resBlockInfo.pResBlock;
   int32_t      code = TSDB_CODE_SUCCESS;
 
   do {
@@ -4163,10 +4260,12 @@ int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t e
 
 // TODO refactor: with createDataBlockScanInfo
 int32_t tsdbSetTableList(STsdbReader* pReader, const void* pTableList, int32_t num) {
-  int32_t size = taosHashGetSize(pReader->status.pTableMap);
+  int32_t size = tSimpleHashGetSize(pReader->status.pTableMap);
 
   STableBlockScanInfo** p = NULL;
-  while ((p = taosHashIterate(pReader->status.pTableMap, p)) != NULL) {
+  int32_t iter = 0;
+
+  while ((p = tSimpleHashIterate(pReader->status.pTableMap, p, &iter)) != NULL) {
     clearBlockScanInfo(*p);
   }
 
@@ -4184,7 +4283,7 @@ int32_t tsdbSetTableList(STsdbReader* pReader, const void* pTableList, int32_t n
     pReader->status.uidList.tableUidList = (uint64_t*)p1;
   }
 
-  taosHashClear(pReader->status.pTableMap);
+  tSimpleHashClear(pReader->status.pTableMap);
   STableUidList* pUidList = &pReader->status.uidList;
   pUidList->currentIndex = 0;
 
@@ -4205,7 +4304,7 @@ int32_t tsdbSetTableList(STsdbReader* pReader, const void* pTableList, int32_t n
       pInfo->lastKeyInStt = ekey;
     }
 
-    taosHashPut(pReader->status.pTableMap, &pInfo->uid, sizeof(uint64_t), &pInfo, POINTER_BYTES);
+    tSimpleHashPut(pReader->status.pTableMap, &pInfo->uid, sizeof(uint64_t), &pInfo, POINTER_BYTES);
   }
 
   return TDB_CODE_SUCCESS;
@@ -4225,7 +4324,7 @@ void* tsdbGetIvtIdx(SMeta* pMeta) {
   return metaGetIvtIdx(pMeta);
 }
 
-uint64_t getReaderMaxVersion(STsdbReader* pReader) { return pReader->verRange.maxVer; }
+uint64_t tsdbGetReaderMaxVersion(STsdbReader* pReader) { return pReader->verRange.maxVer; }
 
 static int32_t doOpenReaderImpl(STsdbReader* pReader) {
   SReaderStatus*  pStatus = &pReader->status;
@@ -4251,8 +4350,8 @@ static int32_t doOpenReaderImpl(STsdbReader* pReader) {
 }
 
 static void freeSchemaFunc(void* param) {
-  void* p = *(void**)param;
-  taosMemoryFree(p);
+  void **p = (void **)param;
+  taosMemoryFreeClear(*p);
 }
 
 // ====================================== EXPOSED APIs ======================================
@@ -4327,6 +4426,10 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, void* pTableL
     }
   }
 
+  if (pReader->pSchema != NULL) {
+    tsdbRowMergerInit(&pReader->status.merger, pReader->pSchema);
+  }
+
   pReader->pSchemaMap = tSimpleHashInit(8, taosFastHash);
   if (pReader->pSchemaMap == NULL) {
     tsdbError("failed init schema hash for reader %s", pReader->idStr);
@@ -4351,7 +4454,13 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, void* pTableL
     goto _err;
   }
 
-  pReader->suspended = true;
+  pReader->status.pLDataIter = taosMemoryCalloc(pVnode->config.sttTrigger, sizeof(SLDataIter));
+  if (pReader->status.pLDataIter == NULL) {
+    terrno = TSDB_CODE_OUT_OF_MEMORY;
+    goto _err;
+  }
+
+  pReader->flag = READER_STATUS_SUSPEND;
 
   if (countOnly) {
     pReader->readMode = READ_MODE_COUNT_ONLY;
@@ -4367,29 +4476,42 @@ _err:
   return code;
 }
 
+static void clearSharedPtr(STsdbReader* p) {
+  p->status.pLDataIter = NULL;
+  p->status.pTableMap = NULL;
+  p->status.uidList.tableUidList = NULL;
+  p->pReadSnap = NULL;
+  p->pSchema = NULL;
+  p->pSchemaMap = NULL;
+}
+
+static void setSharedPtr(STsdbReader* pDst, const STsdbReader* pSrc) {
+  pDst->status.pTableMap = pSrc->status.pTableMap;
+  pDst->status.pLDataIter = pSrc->status.pLDataIter;
+  pDst->status.uidList = pSrc->status.uidList;
+  pDst->pSchema = pSrc->pSchema;
+  pDst->pSchemaMap = pSrc->pSchemaMap;
+  pDst->pReadSnap = pSrc->pReadSnap;
+
+  if (pDst->pSchema) {
+    tsdbRowMergerInit(&pDst->status.merger, pDst->pSchema);
+  }
+}
+
 void tsdbReaderClose(STsdbReader* pReader) {
   if (pReader == NULL) {
     return;
   }
 
   tsdbAcquireReader(pReader);
+
   {
     if (pReader->innerReader[0] != NULL || pReader->innerReader[1] != NULL) {
       STsdbReader* p = pReader->innerReader[0];
-
-      p->status.pTableMap = NULL;
-      p->status.uidList.tableUidList = NULL;
-      p->pReadSnap = NULL;
-      p->pSchema = NULL;
-      p->pSchemaMap = NULL;
+      clearSharedPtr(p);
 
       p = pReader->innerReader[1];
-
-      p->status.pTableMap = NULL;
-      p->status.uidList.tableUidList = NULL;
-      p->pReadSnap = NULL;
-      p->pSchema = NULL;
-      p->pSchemaMap = NULL;
+      clearSharedPtr(p);
 
       tsdbReaderClose(pReader->innerReader[0]);
       tsdbReaderClose(pReader->innerReader[1]);
@@ -4405,15 +4527,15 @@ void tsdbReaderClose(STsdbReader* pReader) {
     }
   }
 
-  if (pReader->freeBlock) {
-    pReader->pResBlock = blockDataDestroy(pReader->pResBlock);
+  if (pReader->resBlockInfo.freeBlock) {
+    pReader->resBlockInfo.pResBlock = blockDataDestroy(pReader->resBlockInfo.pResBlock);
   }
 
   taosMemoryFree(pSupInfo->colId);
   tBlockDataDestroy(&pReader->status.fileBlockData);
   cleanupDataBlockIterator(&pReader->status.blockIter);
 
-  size_t numOfTables = taosHashGetSize(pReader->status.pTableMap);
+  size_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap);
   if (pReader->status.pTableMap != NULL) {
     destroyAllBlockScanInfo(pReader->status.pTableMap);
     clearBlockScanInfoBuf(&pReader->blockInfoBuf);
@@ -4440,7 +4562,8 @@ void tsdbReaderClose(STsdbReader* pReader) {
 
   tsdbUninitReaderLock(pReader);
 
-  taosMemoryFree(pReader->status.uidList.tableUidList);
+  taosMemoryFreeClear(pReader->status.pLDataIter);
+  taosMemoryFreeClear(pReader->status.uidList.tableUidList);
   SIOCostSummary* pCost = &pReader->cost;
 
   SFilesetIter* pFilesetIter = &pReader->status.fileIter;
@@ -4467,6 +4590,8 @@ void tsdbReaderClose(STsdbReader* pReader) {
       pCost->initDelSkylineIterTime, pReader->idStr);
 
   taosMemoryFree(pReader->idStr);
+
+  tsdbRowMergerCleanup(&pReader->status.merger);
   taosMemoryFree(pReader->pSchema);
 
   tSimpleHashCleanup(pReader->pSchemaMap);
@@ -4495,8 +4620,9 @@ int32_t tsdbReaderSuspend(STsdbReader* pReader) {
 
     // resetDataBlockScanInfo excluding lastKey
     STableBlockScanInfo** p = NULL;
+    int32_t iter = 0;
 
-    while ((p = taosHashIterate(pStatus->pTableMap, p)) != NULL) {
+    while ((p = tSimpleHashIterate(pStatus->pTableMap, p, &iter)) != NULL) {
       STableBlockScanInfo* pInfo = *(STableBlockScanInfo**)p;
 
       pInfo->iterInit = false;
@@ -4512,13 +4638,13 @@ int32_t tsdbReaderSuspend(STsdbReader* pReader) {
       }
 
       pInfo->delSkyline = taosArrayDestroy(pInfo->delSkyline);
-      // pInfo->lastKey = ts;
     }
   } else {
     // resetDataBlockScanInfo excluding lastKey
     STableBlockScanInfo** p = NULL;
+    int32_t iter = 0;
 
-    while ((p = taosHashIterate(pStatus->pTableMap, p)) != NULL) {
+    while ((p = tSimpleHashIterate(pStatus->pTableMap, p, &iter)) != NULL) {
       STableBlockScanInfo* pInfo = *(STableBlockScanInfo**)p;
 
       pInfo->iterInit = false;
@@ -4534,13 +4660,12 @@ int32_t tsdbReaderSuspend(STsdbReader* pReader) {
       }
 
       pInfo->delSkyline = taosArrayDestroy(pInfo->delSkyline);
-      // pInfo->lastKey = ts;
     }
 
     pBlockScanInfo = pStatus->pTableIter == NULL ? NULL : *pStatus->pTableIter;
     if (pBlockScanInfo) {
       // save lastKey to restore memory iterator
-      STimeWindow w = pReader->pResBlock->info.window;
+      STimeWindow w = pReader->resBlockInfo.pResBlock->info.window;
       pBlockScanInfo->lastKey = ASCENDING_TRAVERSE(pReader->order) ? w.ekey : w.skey;
 
       // reset current current table's data block scan info,
@@ -4564,8 +4689,7 @@ int32_t tsdbReaderSuspend(STsdbReader* pReader) {
 
   tsdbUntakeReadSnap(pReader, pReader->pReadSnap, false);
   pReader->pReadSnap = NULL;
-
-  pReader->suspended = true;
+  pReader->flag = READER_STATUS_SUSPEND;
 
   tsdbDebug("reader: %p suspended uid %" PRIu64 " in this query %s", pReader, pBlockScanInfo ? pBlockScanInfo->uid : 0,
             pReader->idStr);
@@ -4582,7 +4706,7 @@ static int32_t tsdbSetQueryReseek(void* pQHandle) {
 
   code = tsdbTryAcquireReader(pReader);
   if (code == 0) {
-    if (pReader->suspended) {
+    if (pReader->flag == READER_STATUS_SUSPEND) {
       tsdbReleaseReader(pReader);
       return code;
     }
@@ -4607,7 +4731,7 @@ int32_t tsdbReaderResume(STsdbReader* pReader) {
 
   //  restore reader's state
   //  task snapshot
-  int32_t numOfTables = taosHashGetSize(pReader->status.pTableMap);
+  int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap);
   if (numOfTables > 0) {
     qTrace("tsdb/reader: %p, take snapshot", pReader);
     code = tsdbTakeReadSnap(pReader, tsdbSetQueryReseek, &pReader->pReadSnap);
@@ -4625,19 +4749,11 @@ int32_t tsdbReaderResume(STsdbReader* pReader) {
       STsdbReader* pNextReader = pReader->innerReader[1];
 
       // we need only one row
-      pPrevReader->capacity = 1;
-      pPrevReader->status.pTableMap = pReader->status.pTableMap;
-      pPrevReader->status.uidList = pReader->status.uidList;
-      pPrevReader->pSchema = pReader->pSchema;
-      pPrevReader->pSchemaMap = pReader->pSchemaMap;
-      pPrevReader->pReadSnap = pReader->pReadSnap;
+      pPrevReader->resBlockInfo.capacity = 1;
+      setSharedPtr(pPrevReader, pReader);
 
-      pNextReader->capacity = 1;
-      pNextReader->status.pTableMap = pReader->status.pTableMap;
-      pNextReader->status.uidList = pReader->status.uidList;
-      pNextReader->pSchema = pReader->pSchema;
-      pNextReader->pSchemaMap = pReader->pSchemaMap;
-      pNextReader->pReadSnap = pReader->pReadSnap;
+      pNextReader->resBlockInfo.capacity = 1;
+      setSharedPtr(pNextReader, pReader);
 
       code = doOpenReaderImpl(pPrevReader);
       if (code != TSDB_CODE_SUCCESS) {
@@ -4646,8 +4762,7 @@ int32_t tsdbReaderResume(STsdbReader* pReader) {
     }
   }
 
-  pReader->suspended = false;
-
+  pReader->flag = READER_STATUS_NORMAL;
   tsdbDebug("reader: %p resumed uid %" PRIu64 ", numOfTable:%" PRId32 ", in this query %s", pReader,
             pBlockScanInfo ? (*pBlockScanInfo)->uid : 0, numOfTables, pReader->idStr);
   return code;
@@ -4659,7 +4774,7 @@ _err:
 
 static bool tsdbReadRowsCountOnly(STsdbReader* pReader) {
   int32_t      code = TSDB_CODE_SUCCESS;
-  SSDataBlock* pBlock = pReader->pResBlock;
+  SSDataBlock* pBlock = pReader->resBlockInfo.pResBlock;
 
   if (pReader->status.loadFromFile == false) {
     return false;
@@ -4688,13 +4803,13 @@ static int32_t doTsdbNextDataBlock(STsdbReader* pReader, bool* hasNext) {
   int32_t code = TSDB_CODE_SUCCESS;
 
   // cleanup the data that belongs to the previous data block
-  SSDataBlock* pBlock = pReader->pResBlock;
+  SSDataBlock* pBlock = pReader->resBlockInfo.pResBlock;
   blockDataCleanup(pBlock);
 
   *hasNext = false;
 
   SReaderStatus* pStatus = &pReader->status;
-  if (taosHashGetSize(pStatus->pTableMap) == 0) {
+  if (tSimpleHashGetSize(pStatus->pTableMap) == 0) {
     return code;
   }
 
@@ -4726,8 +4841,8 @@ int32_t tsdbNextDataBlock(STsdbReader* pReader, bool* hasNext) {
 
   *hasNext = false;
 
-  if (isEmptyQueryTimeWindow(&pReader->window) || pReader->step == EXTERNAL_ROWS_NEXT) {
-    return code;
+  if (isEmptyQueryTimeWindow(&pReader->window) || pReader->step == EXTERNAL_ROWS_NEXT || pReader->code != TSDB_CODE_SUCCESS) {
+    return (pReader->code != TSDB_CODE_SUCCESS)? pReader->code:code;
   }
 
   SReaderStatus* pStatus = &pReader->status;
@@ -4735,8 +4850,12 @@ int32_t tsdbNextDataBlock(STsdbReader* pReader, bool* hasNext) {
   code = tsdbAcquireReader(pReader);
   qTrace("tsdb/read: %p, take read mutex, code: %d", pReader, code);
 
-  if (pReader->suspended) {
-    tsdbReaderResume(pReader);
+  if (pReader->flag == READER_STATUS_SUSPEND) {
+    code = tsdbReaderResume(pReader);
+    if (code != TSDB_CODE_SUCCESS) {
+      tsdbReleaseReader(pReader);
+      return code;
+    }
   }
 
   if (pReader->innerReader[0] != NULL && pReader->step == 0) {
@@ -4873,7 +4992,7 @@ int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SSDataBlock* pDataBlock,
   SFileDataBlockInfo* pFBlock = getCurrentBlockInfo(&pReader->status.blockIter);
   SBlockLoadSuppInfo* pSup = &pReader->suppInfo;
 
-  if (pReader->pResBlock->info.id.uid != pFBlock->uid) {
+  if (pReader->resBlockInfo.pResBlock->info.id.uid != pFBlock->uid) {
     return TSDB_CODE_SUCCESS;
   }
 
@@ -4899,8 +5018,8 @@ int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SSDataBlock* pDataBlock,
 
   pTsAgg->numOfNull = 0;
   pTsAgg->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
-  pTsAgg->min = pReader->pResBlock->info.window.skey;
-  pTsAgg->max = pReader->pResBlock->info.window.ekey;
+  pTsAgg->min = pReader->resBlockInfo.pResBlock->info.window.skey;
+  pTsAgg->max = pReader->resBlockInfo.pResBlock->info.window.ekey;
 
   // update the number of NULL data rows
   size_t numOfCols = pSup->numOfCols;
@@ -4911,7 +5030,7 @@ int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SSDataBlock* pDataBlock,
     taosArrayEnsureCap(pSup->pColAgg, colsNum);
   }
 
-  SSDataBlock* pResBlock = pReader->pResBlock;
+  SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock;
   if (pResBlock->pBlockAgg == NULL) {
     size_t num = taosArrayGetSize(pResBlock->pDataBlock);
     pResBlock->pBlockAgg = taosMemoryCalloc(num, POINTER_BYTES);
@@ -4947,11 +5066,11 @@ int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SSDataBlock* pDataBlock,
   return code;
 }
 
-STableBlockScanInfo* getTableBlockScanInfo(SHashObj* pTableMap, uint64_t uid, const char* id) {
-  STableBlockScanInfo** p = taosHashGet(pTableMap, &uid, sizeof(uid));
+STableBlockScanInfo* getTableBlockScanInfo(SSHashObj* pTableMap, uint64_t uid, const char* id) {
+  STableBlockScanInfo** p = tSimpleHashGet(pTableMap, &uid, sizeof(uid));
   if (p == NULL || *p == NULL) {
     terrno = TSDB_CODE_INVALID_PARA;
-    int32_t size = taosHashGetSize(pTableMap);
+    int32_t size = tSimpleHashGetSize(pTableMap);
     tsdbError("failed to locate the uid:%" PRIu64 " in query table uid list, total tables:%d, %s", uid, size, id);
     return NULL;
   }
@@ -4982,7 +5101,7 @@ static SSDataBlock* doRetrieveDataBlock(STsdbReader* pReader) {
     return NULL;
   }
 
-  return pReader->pResBlock;
+  return pReader->resBlockInfo.pResBlock;
 }
 
 SSDataBlock* tsdbRetrieveDataBlock(STsdbReader* pReader, SArray* pIdList) {
@@ -4997,7 +5116,7 @@ SSDataBlock* tsdbRetrieveDataBlock(STsdbReader* pReader, SArray* pIdList) {
 
   SReaderStatus* pStatus = &pTReader->status;
   if (pStatus->composedDataBlock) {
-    return pTReader->pResBlock;
+    return pTReader->resBlockInfo.pResBlock;
   }
 
   SSDataBlock* ret = doRetrieveDataBlock(pTReader);
@@ -5009,11 +5128,17 @@ SSDataBlock* tsdbRetrieveDataBlock(STsdbReader* pReader, SArray* pIdList) {
 }
 
 int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) {
+  int32_t code = TSDB_CODE_SUCCESS;
+
   qTrace("tsdb/reader-reset: %p, take read mutex", pReader);
   tsdbAcquireReader(pReader);
 
-  if (pReader->suspended) {
-    tsdbReaderResume(pReader);
+  if (pReader->flag == READER_STATUS_SUSPEND) {
+    code = tsdbReaderResume(pReader);
+    if (code != TSDB_CODE_SUCCESS) {
+      tsdbReleaseReader(pReader);
+      return code;
+    }
   }
 
   if (isEmptyQueryTimeWindow(&pReader->window) || pReader->pReadSnap == NULL) {
@@ -5037,7 +5162,7 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) {
   pReader->suppInfo.tsColAgg.colId = PRIMARYKEY_TIMESTAMP_COL_ID;
   tsdbDataFReaderClose(&pReader->pFileReader);
 
-  int32_t numOfTables = taosHashGetSize(pStatus->pTableMap);
+  int32_t numOfTables = tSimpleHashGetSize(pStatus->pTableMap);
 
   initFilesetIterator(&pStatus->fileIter, pReader->pReadSnap->fs.aDFileSet, pReader);
   resetDataBlockIterator(pBlockIter, pReader->order);
@@ -5048,8 +5173,6 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) {
   int64_t ts = asc ? pReader->window.skey - 1 : pReader->window.ekey + 1;
   resetAllDataBlockScanInfo(pStatus->pTableMap, ts, step);
 
-  int32_t code = 0;
-
   // no data in files, let's try buffer in memory
   if (pStatus->fileIter.numOfFiles == 0) {
     pStatus->loadFromFile = false;
@@ -5091,12 +5214,14 @@ int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTa
 
   const int32_t numOfBuckets = 20.0;
 
-  // find the start data block in file
-
   // find the start data block in file
   tsdbAcquireReader(pReader);
-  if (pReader->suspended) {
-    tsdbReaderResume(pReader);
+  if (pReader->flag == READER_STATUS_SUSPEND) {
+    code = tsdbReaderResume(pReader);
+    if (code != TSDB_CODE_SUCCESS) {
+      tsdbReleaseReader(pReader);
+      return code;
+    }
   }
   SReaderStatus* pStatus = &pReader->status;
 
@@ -5108,7 +5233,7 @@ int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTa
 
   pTableBlockInfo->numOfFiles += 1;
 
-  int32_t numOfTables = (int32_t)taosHashGetSize(pStatus->pTableMap);
+  int32_t numOfTables = (int32_t)tSimpleHashGetSize(pStatus->pTableMap);
   int     defaultRows = 4096;
 
   SDataBlockIter* pBlockIter = &pStatus->blockIter;
@@ -5164,15 +5289,21 @@ int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTa
 }
 
 int64_t tsdbGetNumOfRowsInMemTable(STsdbReader* pReader) {
+  int32_t code = TSDB_CODE_SUCCESS;
   int64_t rows = 0;
 
   SReaderStatus* pStatus = &pReader->status;
   tsdbAcquireReader(pReader);
-  if (pReader->suspended) {
-    tsdbReaderResume(pReader);
+  if (pReader->flag == READER_STATUS_SUSPEND) {
+    code = tsdbReaderResume(pReader);
+    if (code != TSDB_CODE_SUCCESS) {
+      tsdbReleaseReader(pReader);
+      return code;
+    }
   }
 
-  pStatus->pTableIter = taosHashIterate(pStatus->pTableMap, NULL);
+  int32_t iter = 0;
+  pStatus->pTableIter = tSimpleHashIterate(pStatus->pTableMap, NULL, &iter);
 
   while (pStatus->pTableIter != NULL) {
     STableBlockScanInfo* pBlockScanInfo = *(STableBlockScanInfo**)pStatus->pTableIter;
@@ -5194,7 +5325,7 @@ int64_t tsdbGetNumOfRowsInMemTable(STsdbReader* pReader) {
     }
 
     // current table is exhausted, let's try the next table
-    pStatus->pTableIter = taosHashIterate(pStatus->pTableMap, pStatus->pTableIter);
+    pStatus->pTableIter = tSimpleHashIterate(pStatus->pTableMap, pStatus->pTableIter, &iter);
   }
 
   tsdbReleaseReader(pReader);
@@ -5333,3 +5464,5 @@ void tsdbReaderSetId(STsdbReader* pReader, const char* idstr) {
   taosMemoryFreeClear(pReader->idStr);
   pReader->idStr = taosStrdup(idstr);
 }
+
+void tsdbReaderSetCloseFlag(STsdbReader* pReader) { pReader->code = TSDB_CODE_TSC_QUERY_CANCELLED; }
diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c
index aed863d194..dfea125cc1 100644
--- a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c
+++ b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c
@@ -70,10 +70,11 @@ static int32_t tsdbSnapReadFileDataStart(STsdbSnapReader* pReader) {
 
   if (pReader->pIter) {
     // iter to next with filter info (sver, ever)
-    code = tsdbDataIterNext2(pReader->pIter,
-                             &(STsdbFilterInfo){.flag = TSDB_FILTER_FLAG_BY_VERSION,  // flag
-                                                .sver = pReader->sver,
-                                                .ever = pReader->ever});
+    code = tsdbDataIterNext2(
+        pReader->pIter,
+        &(STsdbFilterInfo){.flag = TSDB_FILTER_FLAG_BY_VERSION | TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE,  // flag
+                           .sver = pReader->sver,
+                           .ever = pReader->ever});
     TSDB_CHECK_CODE(code, lino, _exit);
 
     if (pReader->pIter->rowInfo.suid || pReader->pIter->rowInfo.uid) {
@@ -94,10 +95,11 @@ static int32_t tsdbSnapReadFileDataStart(STsdbSnapReader* pReader) {
 
     if (pReader->pIter) {
       // iter to valid row
-      code = tsdbDataIterNext2(pReader->pIter,
-                               &(STsdbFilterInfo){.flag = TSDB_FILTER_FLAG_BY_VERSION,  // flag
-                                                  .sver = pReader->sver,
-                                                  .ever = pReader->ever});
+      code = tsdbDataIterNext2(
+          pReader->pIter,
+          &(STsdbFilterInfo){.flag = TSDB_FILTER_FLAG_BY_VERSION | TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE,  // flag
+                             .sver = pReader->sver,
+                             .ever = pReader->ever});
       TSDB_CHECK_CODE(code, lino, _exit);
 
       if (pReader->pIter->rowInfo.suid || pReader->pIter->rowInfo.uid) {
@@ -139,7 +141,8 @@ static int32_t tsdbSnapReadNextRow(STsdbSnapReader* pReader, SRowInfo** ppRowInf
   int32_t lino = 0;
 
   if (pReader->pIter) {
-    code = tsdbDataIterNext2(pReader->pIter, &(STsdbFilterInfo){.flag = TSDB_FILTER_FLAG_BY_VERSION,  // flag
+    code = tsdbDataIterNext2(pReader->pIter, &(STsdbFilterInfo){.flag = TSDB_FILTER_FLAG_BY_VERSION |
+                                                                        TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE,  // flag
                                                                 .sver = pReader->sver,
                                                                 .ever = pReader->ever});
     TSDB_CHECK_CODE(code, lino, _exit);
@@ -346,8 +349,9 @@ static int32_t tsdbSnapReadNextTombData(STsdbSnapReader* pReader, SDelInfo** ppD
   int32_t lino = 0;
 
   code = tsdbDataIterNext2(
-      pReader->pTIter,
-      &(STsdbFilterInfo){.flag = TSDB_FILTER_FLAG_BY_VERSION, .sver = pReader->sver, .ever = pReader->ever});
+      pReader->pTIter, &(STsdbFilterInfo){.flag = TSDB_FILTER_FLAG_BY_VERSION | TSDB_FILTER_FLAG_IGNORE_DROPPED_TABLE,
+                                          .sver = pReader->sver,
+                                          .ever = pReader->ever});
   TSDB_CHECK_CODE(code, lino, _exit);
 
   if (ppDelInfo) {
diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c
index 8e778da877..556ec33526 100644
--- a/source/dnode/vnode/src/tsdb/tsdbUtil.c
+++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c
@@ -637,201 +637,157 @@ SColVal *tsdbRowIterNext(STSDBRowIter *pIter) {
 }
 
 // SRowMerger ======================================================
-
-int32_t tsdbRowMergerInit(SRowMerger *pMerger, STSchema *pResTSchema, TSDBROW *pRow, STSchema *pTSchema) {
-  int32_t   code = 0;
-  TSDBKEY   key = TSDBROW_KEY(pRow);
-  SColVal  *pColVal = &(SColVal){0};
-  STColumn *pTColumn;
-  int32_t   iCol, jCol = 0;
-
-  if (NULL == pResTSchema) {
-    pResTSchema = pTSchema;
-  }
-
-  pMerger->pTSchema = pResTSchema;
-  pMerger->version = key.version;
-
-  pMerger->pArray = taosArrayInit(pResTSchema->numOfCols, sizeof(SColVal));
-  if (pMerger->pArray == NULL) {
-    code = TSDB_CODE_OUT_OF_MEMORY;
-    goto _exit;
-  }
-
-  // ts
-  pTColumn = &pTSchema->columns[jCol++];
-
-  ASSERT(pTColumn->type == TSDB_DATA_TYPE_TIMESTAMP);
-
-  *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.val = key.ts});
-  if (taosArrayPush(pMerger->pArray, pColVal) == NULL) {
-    code = TSDB_CODE_OUT_OF_MEMORY;
-    goto _exit;
-  }
-
-  // other
-  for (iCol = 1; jCol < pTSchema->numOfCols && iCol < pResTSchema->numOfCols; ++iCol) {
-    pTColumn = &pResTSchema->columns[iCol];
-    if (pTSchema->columns[jCol].colId < pTColumn->colId) {
-      ++jCol;
-      --iCol;
-      continue;
-    } else if (pTSchema->columns[jCol].colId > pTColumn->colId) {
-      taosArrayPush(pMerger->pArray, &COL_VAL_NONE(pTColumn->colId, pTColumn->type));
-      continue;
-    }
-
-    tsdbRowGetColVal(pRow, pTSchema, jCol++, pColVal);
-    if ((!COL_VAL_IS_NONE(pColVal)) && (!COL_VAL_IS_NULL(pColVal)) && IS_VAR_DATA_TYPE(pColVal->type)) {
-      uint8_t *pVal = pColVal->value.pData;
-
-      pColVal->value.pData = NULL;
-      code = tRealloc(&pColVal->value.pData, pColVal->value.nData);
-      if (code) goto _exit;
-
-      if (pColVal->value.nData) {
-        memcpy(pColVal->value.pData, pVal, pColVal->value.nData);
-      }
-    }
-
-    if (taosArrayPush(pMerger->pArray, pColVal) == NULL) {
-      code = TSDB_CODE_OUT_OF_MEMORY;
-      goto _exit;
-    }
-  }
-
-  for (; iCol < pResTSchema->numOfCols; ++iCol) {
-    pTColumn = &pResTSchema->columns[iCol];
-    taosArrayPush(pMerger->pArray, &COL_VAL_NONE(pTColumn->colId, pTColumn->type));
-  }
-
-_exit:
-  return code;
-}
-
 int32_t tsdbRowMergerAdd(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
   int32_t   code = 0;
   TSDBKEY   key = TSDBROW_KEY(pRow);
-  SColVal  *pColVal = &(SColVal){0};
+  SColVal * pColVal = &(SColVal){0};
   STColumn *pTColumn;
   int32_t   iCol, jCol = 1;
 
   if (NULL == pTSchema) {
     pTSchema = pMerger->pTSchema;
   }
-  ASSERT(((SColVal *)pMerger->pArray->pData)->value.val == key.ts);
 
-  for (iCol = 1; iCol < pMerger->pTSchema->numOfCols && jCol < pTSchema->numOfCols; ++iCol) {
-    pTColumn = &pMerger->pTSchema->columns[iCol];
-    if (pTSchema->columns[jCol].colId < pTColumn->colId) {
-      ++jCol;
-      --iCol;
-      continue;
-    } else if (pTSchema->columns[jCol].colId > pTColumn->colId) {
-      continue;
-    }
+  if (taosArrayGetSize(pMerger->pArray) == 0) {
+    // ts
+    jCol = 0;
+    pTColumn = &pTSchema->columns[jCol++];
 
-    tsdbRowGetColVal(pRow, pTSchema, jCol++, pColVal);
-
-    if (key.version > pMerger->version) {
-      if (!COL_VAL_IS_NONE(pColVal)) {
-        if (IS_VAR_DATA_TYPE(pColVal->type)) {
-          SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
-          if (!COL_VAL_IS_NULL(pColVal)) {
-            code = tRealloc(&pTColVal->value.pData, pColVal->value.nData);
-            if (code) return code;
-
-            pTColVal->value.nData = pColVal->value.nData;
-            if (pTColVal->value.nData) {
-              memcpy(pTColVal->value.pData, pColVal->value.pData, pTColVal->value.nData);
-            }
-            pTColVal->flag = 0;
-          } else {
-            tFree(pTColVal->value.pData);
-            taosArraySet(pMerger->pArray, iCol, pColVal);
-          }
-        } else {
-          taosArraySet(pMerger->pArray, iCol, pColVal);
-        }
-      }
-    } else if (key.version < pMerger->version) {
-      SColVal *tColVal = (SColVal *)taosArrayGet(pMerger->pArray, iCol);
-      if (COL_VAL_IS_NONE(tColVal) && !COL_VAL_IS_NONE(pColVal)) {
-        if ((!COL_VAL_IS_NULL(pColVal)) && IS_VAR_DATA_TYPE(pColVal->type)) {
-          code = tRealloc(&tColVal->value.pData, pColVal->value.nData);
-          if (code) return code;
-
-          tColVal->value.nData = pColVal->value.nData;
-          if (pColVal->value.nData) {
-            memcpy(tColVal->value.pData, pColVal->value.pData, pColVal->value.nData);
-          }
-          tColVal->flag = 0;
-        } else {
-          taosArraySet(pMerger->pArray, iCol, pColVal);
-        }
-      }
-    } else {
-      ASSERT(0 && "dup versions not allowed");
-    }
-  }
-
-  pMerger->version = key.version;
-  return code;
-}
-/*
-int32_t tsdbRowMergerInit(SRowMerger *pMerger, TSDBROW *pRow, STSchema *pTSchema) {
-  int32_t   code = 0;
-  TSDBKEY   key = TSDBROW_KEY(pRow);
-  SColVal  *pColVal = &(SColVal){0};
-  STColumn *pTColumn;
-
-  pMerger->pTSchema = pTSchema;
-  pMerger->version = key.version;
-
-  pMerger->pArray = taosArrayInit(pTSchema->numOfCols, sizeof(SColVal));
-  if (pMerger->pArray == NULL) {
-    code = TSDB_CODE_OUT_OF_MEMORY;
-    goto _exit;
-  }
-
-  // ts
-  pTColumn = &pTSchema->columns[0];
-
-  ASSERT(pTColumn->type == TSDB_DATA_TYPE_TIMESTAMP);
-
-  *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.val = key.ts});
-  if (taosArrayPush(pMerger->pArray, pColVal) == NULL) {
-    code = TSDB_CODE_OUT_OF_MEMORY;
-    goto _exit;
-  }
-
-  // other
-  for (int16_t iCol = 1; iCol < pTSchema->numOfCols; iCol++) {
-    tsdbRowGetColVal(pRow, pTSchema, iCol, pColVal);
-    if ((!COL_VAL_IS_NONE(pColVal)) && (!COL_VAL_IS_NULL(pColVal)) && IS_VAR_DATA_TYPE(pColVal->type)) {
-      uint8_t *pVal = pColVal->value.pData;
-
-      pColVal->value.pData = NULL;
-      code = tRealloc(&pColVal->value.pData, pColVal->value.nData);
-      if (code) goto _exit;
-
-      if (pColVal->value.nData) {
-        memcpy(pColVal->value.pData, pVal, pColVal->value.nData);
-      }
-    }
+    ASSERT(pTColumn->type == TSDB_DATA_TYPE_TIMESTAMP);
 
+    *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, (SValue){.val = key.ts});
     if (taosArrayPush(pMerger->pArray, pColVal) == NULL) {
       code = TSDB_CODE_OUT_OF_MEMORY;
-      goto _exit;
+      return code;
+      //      goto _exit;
+    }
+
+    // other
+    for (iCol = 1; jCol < pTSchema->numOfCols && iCol < pMerger->pTSchema->numOfCols; ++iCol) {
+      pTColumn = &pMerger->pTSchema->columns[iCol];
+      if (pTSchema->columns[jCol].colId < pTColumn->colId) {
+        ++jCol;
+        --iCol;
+        continue;
+      } else if (pTSchema->columns[jCol].colId > pTColumn->colId) {
+        taosArrayPush(pMerger->pArray, &COL_VAL_NONE(pTColumn->colId, pTColumn->type));
+        continue;
+      }
+
+      tsdbRowGetColVal(pRow, pTSchema, jCol++, pColVal);
+      if ((!COL_VAL_IS_NONE(pColVal)) && (!COL_VAL_IS_NULL(pColVal)) && IS_VAR_DATA_TYPE(pColVal->type)) {
+        uint8_t *pVal = pColVal->value.pData;
+
+        pColVal->value.pData = NULL;
+        code = tRealloc(&pColVal->value.pData, pColVal->value.nData);
+        if (code) {
+          return TSDB_CODE_OUT_OF_MEMORY;
+        }
+
+        if (pColVal->value.nData) {
+          memcpy(pColVal->value.pData, pVal, pColVal->value.nData);
+        }
+      }
+
+      if (taosArrayPush(pMerger->pArray, pColVal) == NULL) {
+        code = TSDB_CODE_OUT_OF_MEMORY;
+        return code;
+      }
+    }
+
+    for (; iCol < pMerger->pTSchema->numOfCols; ++iCol) {
+      pTColumn = &pMerger->pTSchema->columns[iCol];
+      taosArrayPush(pMerger->pArray, &COL_VAL_NONE(pTColumn->colId, pTColumn->type));
+    }
+
+    pMerger->version = key.version;
+    return 0;
+  } else {
+    ASSERT(((SColVal *)pMerger->pArray->pData)->value.val == key.ts);
+
+    for (iCol = 1; iCol < pMerger->pTSchema->numOfCols && jCol < pTSchema->numOfCols; ++iCol) {
+      pTColumn = &pMerger->pTSchema->columns[iCol];
+      if (pTSchema->columns[jCol].colId < pTColumn->colId) {
+        ++jCol;
+        --iCol;
+        continue;
+      } else if (pTSchema->columns[jCol].colId > pTColumn->colId) {
+        continue;
+      }
+
+      tsdbRowGetColVal(pRow, pTSchema, jCol++, pColVal);
+
+      if (key.version > pMerger->version) {
+        if (!COL_VAL_IS_NONE(pColVal)) {
+          if (IS_VAR_DATA_TYPE(pColVal->type)) {
+            SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
+            if (!COL_VAL_IS_NULL(pColVal)) {
+              code = tRealloc(&pTColVal->value.pData, pColVal->value.nData);
+              if (code) return code;
+
+              pTColVal->value.nData = pColVal->value.nData;
+              if (pTColVal->value.nData) {
+                memcpy(pTColVal->value.pData, pColVal->value.pData, pTColVal->value.nData);
+              }
+              pTColVal->flag = 0;
+            } else {
+              tFree(pTColVal->value.pData);
+              taosArraySet(pMerger->pArray, iCol, pColVal);
+            }
+          } else {
+            taosArraySet(pMerger->pArray, iCol, pColVal);
+          }
+        }
+      } else if (key.version < pMerger->version) {
+        SColVal *tColVal = (SColVal *)taosArrayGet(pMerger->pArray, iCol);
+        if (COL_VAL_IS_NONE(tColVal) && !COL_VAL_IS_NONE(pColVal)) {
+          if ((!COL_VAL_IS_NULL(pColVal)) && IS_VAR_DATA_TYPE(pColVal->type)) {
+            code = tRealloc(&tColVal->value.pData, pColVal->value.nData);
+            if (code) return code;
+
+            tColVal->value.nData = pColVal->value.nData;
+            if (pColVal->value.nData) {
+              memcpy(tColVal->value.pData, pColVal->value.pData, pColVal->value.nData);
+            }
+            tColVal->flag = 0;
+          } else {
+            taosArraySet(pMerger->pArray, iCol, pColVal);
+          }
+        }
+      } else {
+        ASSERT(0 && "dup versions not allowed");
+      }
+    }
+
+    pMerger->version = key.version;
+    return code;
+  }
+}
+
+int32_t tsdbRowMergerInit(SRowMerger* pMerger, STSchema *pSchema) {
+  pMerger->pTSchema = pSchema;
+  pMerger->pArray = taosArrayInit(pSchema->numOfCols, sizeof(SColVal));
+  if (pMerger->pArray == NULL) {
+    return TSDB_CODE_OUT_OF_MEMORY;
+  } else {
+    return TSDB_CODE_SUCCESS;
+  }
+}
+
+void tsdbRowMergerClear(SRowMerger* pMerger) {
+  for (int32_t iCol = 1; iCol < pMerger->pTSchema->numOfCols; iCol++) {
+    SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
+    if (IS_VAR_DATA_TYPE(pTColVal->type)) {
+      tFree(pTColVal->value.pData);
     }
   }
 
-_exit:
-  return code;
+  taosArrayClear(pMerger->pArray);
 }
-*/
-void tsdbRowMergerClear(SRowMerger *pMerger) {
-  for (int32_t iCol = 1; iCol < pMerger->pTSchema->numOfCols; iCol++) {
+
+void tsdbRowMergerCleanup(SRowMerger* pMerger) {
+  int32_t numOfCols = taosArrayGetSize(pMerger->pArray);
+  for (int32_t iCol = 1; iCol < numOfCols; iCol++) {
     SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
     if (IS_VAR_DATA_TYPE(pTColVal->type)) {
       tFree(pTColVal->value.pData);
@@ -840,72 +796,7 @@ void tsdbRowMergerClear(SRowMerger *pMerger) {
 
   taosArrayDestroy(pMerger->pArray);
 }
-/*
-int32_t tsdbRowMerge(SRowMerger *pMerger, TSDBROW *pRow) {
-  int32_t  code = 0;
-  TSDBKEY  key = TSDBROW_KEY(pRow);
-  SColVal *pColVal = &(SColVal){0};
 
-  ASSERT(((SColVal *)pMerger->pArray->pData)->value.val == key.ts);
-
-  for (int32_t iCol = 1; iCol < pMerger->pTSchema->numOfCols; iCol++) {
-    tsdbRowGetColVal(pRow, pMerger->pTSchema, iCol, pColVal);
-
-    if (key.version > pMerger->version) {
-      if (!COL_VAL_IS_NONE(pColVal)) {
-        if (IS_VAR_DATA_TYPE(pColVal->type)) {
-          SColVal *pTColVal = taosArrayGet(pMerger->pArray, iCol);
-          if (!COL_VAL_IS_NULL(pColVal)) {
-            code = tRealloc(&pTColVal->value.pData, pColVal->value.nData);
-            if (code) goto _exit;
-
-            pTColVal->value.nData = pColVal->value.nData;
-            if (pTColVal->value.nData) {
-              memcpy(pTColVal->value.pData, pColVal->value.pData, pTColVal->value.nData);
-            }
-            pTColVal->flag = 0;
-          } else {
-            tFree(pTColVal->value.pData);
-            pTColVal->value.pData = NULL;
-            taosArraySet(pMerger->pArray, iCol, pColVal);
-          }
-        } else {
-          taosArraySet(pMerger->pArray, iCol, pColVal);
-        }
-      }
-    } else if (key.version < pMerger->version) {
-      SColVal *tColVal = (SColVal *)taosArrayGet(pMerger->pArray, iCol);
-      if (COL_VAL_IS_NONE(tColVal) && !COL_VAL_IS_NONE(pColVal)) {
-        if (IS_VAR_DATA_TYPE(pColVal->type)) {
-          if (!COL_VAL_IS_NULL(pColVal)) {
-            code = tRealloc(&tColVal->value.pData, pColVal->value.nData);
-            if (code) goto _exit;
-
-            tColVal->value.nData = pColVal->value.nData;
-            if (tColVal->value.nData) {
-              memcpy(tColVal->value.pData, pColVal->value.pData, tColVal->value.nData);
-            }
-            tColVal->flag = 0;
-          } else {
-            tFree(tColVal->value.pData);
-            tColVal->value.pData = NULL;
-            taosArraySet(pMerger->pArray, iCol, pColVal);
-          }
-        } else {
-          taosArraySet(pMerger->pArray, iCol, pColVal);
-        }
-      }
-    } else {
-      ASSERT(0);
-    }
-  }
-
-  pMerger->version = key.version;
-
-_exit:
-  return code;
-}
-*/
 int32_t tsdbRowMergerGetRow(SRowMerger *pMerger, SRow **ppRow) {
   return tRowBuild(pMerger->pArray, pMerger->pTSchema, ppRow);
 }
@@ -1160,8 +1051,6 @@ int32_t tBlockDataCreate(SBlockData *pBlockData) {
   pBlockData->aTSKEY = NULL;
   pBlockData->nColData = 0;
   pBlockData->aColData = NULL;
-
-_exit:
   return code;
 }
 
@@ -1218,9 +1107,10 @@ int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema,
     int32_t   iColumn = 1;
     STColumn *pTColumn = &pTSchema->columns[iColumn];
     for (int32_t iCid = 0; iCid < nCid; iCid++) {
-      if (ASSERTS(pTColumn != NULL, "invalid input param")) {
-        code = TSDB_CODE_INVALID_PARA;
-        goto _exit;
+
+      // aCid array (from taos client catalog) contains columns that does not exist in the pTSchema. the pTSchema is newer
+      if (pTColumn == NULL) {
+        continue;
       }
 
       while (pTColumn->colId < aCid[iCid]) {
@@ -1229,9 +1119,8 @@ int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema,
         pTColumn = &pTSchema->columns[iColumn];
       }
 
-      if (ASSERTS(pTColumn->colId == aCid[iCid], "invalid input param")) {
-        code = TSDB_CODE_INVALID_PARA;
-        goto _exit;
+      if (pTColumn->colId != aCid[iCid]) {
+        continue;
       }
 
       tColDataInit(&pBlockData->aColData[iCid], pTColumn->colId, pTColumn->type,
diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c
index a8511eedfd..4948f75052 100644
--- a/source/dnode/vnode/src/vnd/vnodeSvr.c
+++ b/source/dnode/vnode/src/vnd/vnodeSvr.c
@@ -456,7 +456,6 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
   walApplyVer(pVnode->pWal, version);
 
   if (tqPushMsg(pVnode->pTq, pMsg->pCont, pMsg->contLen, pMsg->msgType, version) < 0) {
-    /*vInfo("vgId:%d, push msg end", pVnode->config.vgId);*/
     vError("vgId:%d, failed to push msg to TQ since %s", TD_VID(pVnode), tstrerror(terrno));
     return -1;
   }
@@ -495,11 +494,16 @@ int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
 
 int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
   vTrace("message in vnode query queue is processing");
-  if ((pMsg->msgType == TDMT_SCH_QUERY) && !syncIsReadyForRead(pVnode->sync)) {
+  if ((pMsg->msgType == TDMT_SCH_QUERY || pMsg->msgType == TDMT_VND_TMQ_CONSUME) && !syncIsReadyForRead(pVnode->sync)) {
     vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
     return 0;
   }
 
+  if (pMsg->msgType == TDMT_VND_TMQ_CONSUME && !pVnode->restored) {
+    vnodeRedirectRpcMsg(pVnode, pMsg, TSDB_CODE_SYN_RESTORING);
+    return 0;
+  }
+
   SReadHandle handle = {.meta = pVnode->pMeta, .config = &pVnode->config, .vnode = pVnode, .pMsgCb = &pVnode->msgCb};
   switch (pMsg->msgType) {
     case TDMT_SCH_QUERY:
@@ -507,6 +511,8 @@ int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
       return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
     case TDMT_SCH_QUERY_CONTINUE:
       return qWorkerProcessCQueryMsg(&handle, pVnode->pQuery, pMsg, 0);
+    case TDMT_VND_TMQ_CONSUME:
+      return tqProcessPollReq(pVnode->pTq, pMsg);
     default:
       vError("unknown msg type:%d in query queue", pMsg->msgType);
       return TSDB_CODE_APP_ERROR;
@@ -516,17 +522,12 @@ int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
 int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
   vTrace("vgId:%d, msg:%p in fetch queue is processing", pVnode->config.vgId, pMsg);
   if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || pMsg->msgType == TDMT_VND_TABLE_CFG ||
-       pMsg->msgType == TDMT_VND_BATCH_META || pMsg->msgType == TDMT_VND_TMQ_CONSUME) &&
+       pMsg->msgType == TDMT_VND_BATCH_META) &&
       !syncIsReadyForRead(pVnode->sync)) {
     vnodeRedirectRpcMsg(pVnode, pMsg, terrno);
     return 0;
   }
 
-  if (pMsg->msgType == TDMT_VND_TMQ_CONSUME && !pVnode->restored) {
-    vnodeRedirectRpcMsg(pVnode, pMsg, TSDB_CODE_SYN_RESTORING);
-    return 0;
-  }
-
   switch (pMsg->msgType) {
     case TDMT_SCH_FETCH:
     case TDMT_SCH_MERGE_FETCH:
@@ -1017,7 +1018,7 @@ static int32_t vnodeResetTableCxt(SMeta *pMeta, SSubmitReqConvertCxt *pCxt) {
   }
   tdSTSRowIterInit(&pCxt->rowIter, pCxt->pTbSchema);
 
-  tDestroySSubmitTbData(pCxt->pTbData, TSDB_MSG_FLG_ENCODE);
+  tDestroySubmitTbData(pCxt->pTbData, TSDB_MSG_FLG_ENCODE);
   if (NULL == pCxt->pTbData) {
     pCxt->pTbData = taosMemoryCalloc(1, sizeof(SSubmitTbData));
     if (NULL == pCxt->pTbData) {
@@ -1049,7 +1050,7 @@ static int32_t vnodeResetTableCxt(SMeta *pMeta, SSubmitReqConvertCxt *pCxt) {
 
 static void vnodeDestroySubmitReqConvertCxt(SSubmitReqConvertCxt *pCxt) {
   taosMemoryFreeClear(pCxt->pTbSchema);
-  tDestroySSubmitTbData(pCxt->pTbData, TSDB_MSG_FLG_ENCODE);
+  tDestroySubmitTbData(pCxt->pTbData, TSDB_MSG_FLG_ENCODE);
   taosMemoryFreeClear(pCxt->pTbData);
   taosArrayDestroy(pCxt->pColValues);
 }
@@ -1159,7 +1160,7 @@ static int32_t vnodeRebuildSubmitReqMsg(SSubmitReq2 *pSubmitReq, void **ppMsg) {
   int32_t  code = TSDB_CODE_SUCCESS;
   char    *pMsg = NULL;
   uint32_t msglen = 0;
-  tEncodeSize(tEncodeSSubmitReq2, pSubmitReq, msglen, code);
+  tEncodeSize(tEncodeSubmitReq, pSubmitReq, msglen, code);
   if (TSDB_CODE_SUCCESS == code) {
     pMsg = taosMemoryMalloc(msglen);
     if (NULL == pMsg) {
@@ -1169,7 +1170,7 @@ static int32_t vnodeRebuildSubmitReqMsg(SSubmitReq2 *pSubmitReq, void **ppMsg) {
   if (TSDB_CODE_SUCCESS == code) {
     SEncoder encoder;
     tEncoderInit(&encoder, pMsg, msglen);
-    code = tEncodeSSubmitReq2(&encoder, pSubmitReq);
+    code = tEncodeSubmitReq(&encoder, pSubmitReq);
     tEncoderClear(&encoder);
   }
   if (TSDB_CODE_SUCCESS == code) {
@@ -1209,7 +1210,7 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq
     len -= sizeof(SSubmitReq2Msg);
     SDecoder dc = {0};
     tDecoderInit(&dc, pReq, len);
-    if (tDecodeSSubmitReq2(&dc, pSubmitReq) < 0) {
+    if (tDecodeSubmitReq(&dc, pSubmitReq) < 0) {
       code = TSDB_CODE_INVALID_MSG;
       goto _exit;
     }
@@ -1358,6 +1359,7 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq
           code = terrno;
           goto _exit;
         }
+        terrno = 0;
         pSubmitTbData->uid = pSubmitTbData->pCreateTbReq->uid;  // update uid if table exist for using below
       }
     }
@@ -1397,7 +1399,7 @@ _exit:
 
   // clear
   taosArrayDestroy(newTbUids);
-  tDestroySSubmitReq2(pSubmitReq, 0 == pMsg->version ? TSDB_MSG_FLG_CMPT : TSDB_MSG_FLG_DECODE);
+  tDestroySubmitReq(pSubmitReq, 0 == pMsg->version ? TSDB_MSG_FLG_CMPT : TSDB_MSG_FLG_DECODE);
   tDestroySSubmitRsp2(pSubmitRsp, TSDB_MSG_FLG_ENCODE);
 
   if (code) terrno = code;
diff --git a/source/dnode/vnode/src/vnd/vnodeSync.c b/source/dnode/vnode/src/vnd/vnodeSync.c
index ba73c5fd4c..4ea5e3c6ec 100644
--- a/source/dnode/vnode/src/vnd/vnodeSync.c
+++ b/source/dnode/vnode/src/vnd/vnodeSync.c
@@ -550,7 +550,12 @@ static void vnodeRestoreFinish(const SSyncFSM *pFsm, const SyncIndex commitIdx)
   vInfo("vgId:%d, sync restore finished, start to restore stream tasks by replay wal", pVnode->config.vgId);
 
   // start to restore all stream tasks
-  tqStartStreamTasks(pVnode->pTq);
+  if (tsDisableStream) {
+    vInfo("vgId:%d, not restore stream tasks, since disabled", pVnode->config.vgId);
+  } else {
+    vInfo("vgId:%d start to restore stream tasks", pVnode->config.vgId);
+    tqStartStreamTasks(pVnode->pTq);
+  }
 }
 
 static void vnodeBecomeFollower(const SSyncFSM *pFsm) {
diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h
index 85a130d293..c548a6c696 100644
--- a/source/libs/catalog/inc/catalogInt.h
+++ b/source/libs/catalog/inc/catalogInt.h
@@ -58,6 +58,7 @@ typedef enum {
   CTG_CI_OTHERTABLE_META,
   CTG_CI_TBL_SMA,
   CTG_CI_TBL_CFG,
+  CTG_CI_TBL_TAG,
   CTG_CI_INDEX_INFO,
   CTG_CI_USER,
   CTG_CI_UDF,
@@ -110,6 +111,7 @@ typedef enum {
   CTG_TASK_GET_SVR_VER,
   CTG_TASK_GET_TB_META_BATCH,
   CTG_TASK_GET_TB_HASH_BATCH,
+  CTG_TASK_GET_TB_TAG,
 } CTG_TASK_TYPE;
 
 typedef enum {
@@ -152,6 +154,11 @@ typedef struct SCtgTbCacheInfo {
   int32_t  tbType;
 } SCtgTbCacheInfo;
 
+typedef struct SCtgTbMetaParam {
+  SName*  pName;
+  int32_t flag;
+} SCtgTbMetaParam;
+
 typedef struct SCtgTbMetaCtx {
   SCtgTbCacheInfo tbInfo;
   int32_t         vgId;
@@ -186,6 +193,11 @@ typedef struct SCtgTbCfgCtx {
   SVgroupInfo* pVgInfo;
 } SCtgTbCfgCtx;
 
+typedef struct SCtgTbTagCtx {
+  SName*       pName;
+  SVgroupInfo* pVgInfo;
+} SCtgTbTagCtx;
+
 typedef struct SCtgDbVgCtx {
   char dbFName[TSDB_DB_FNAME_LEN];
 } SCtgDbVgCtx;
@@ -304,6 +316,7 @@ typedef struct SCtgJob {
   catalogCallback  userFp;
   int32_t          tbMetaNum;
   int32_t          tbHashNum;
+  int32_t          tbTagNum;
   int32_t          dbVgNum;
   int32_t          udfNum;
   int32_t          qnodeNum;
@@ -346,6 +359,7 @@ typedef struct SCtgSubRes {
 
 struct SCtgTask {
   CTG_TASK_TYPE   type;
+  bool            subTask;
   int32_t         taskId;
   SCtgJob*        pJob;
   void*           taskCtx;
@@ -623,6 +637,7 @@ typedef struct SCtgCacheItemInfo {
 #define CTG_FLAG_SYS_DB       0x8
 #define CTG_FLAG_FORCE_UPDATE 0x10
 #define CTG_FLAG_ONLY_CACHE   0x20
+#define CTG_FLAG_SYNC_OP      0x40
 
 #define CTG_FLAG_SET(_flag, _v) ((_flag) |= (_v))
 
@@ -925,6 +940,10 @@ void    ctgReleaseVgMetaToCache(SCatalog* pCtg, SCtgDBCache* dbCache, SCtgTbCach
 void    ctgReleaseTbMetaToCache(SCatalog* pCtg, SCtgDBCache* dbCache, SCtgTbCache* pCache);
 void    ctgGetGlobalCacheStat(SCtgCacheStat* pStat);
 int32_t ctgChkSetAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res);
+int32_t ctgGetTbMeta(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta);
+int32_t ctgGetCachedStbNameFromSuid(SCatalog* pCtg, char* dbFName, uint64_t suid, char **stbName);
+int32_t ctgGetTbTagCb(SCtgTask* pTask);
+int32_t ctgGetUserCb(SCtgTask* pTask);
 
 extern SCatalogMgmt      gCtgMgmt;
 extern SCtgDebug         gCTGDebug;
diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c
index bddc6c01a7..976a38c03d 100644
--- a/source/libs/catalog/src/catalog.c
+++ b/source/libs/catalog/src/catalog.c
@@ -208,7 +208,7 @@ int32_t ctgGetTbMeta(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbMetaCtx* ctx
   }
 
   while (true) {
-    CTG_ERR_JRET(ctgRefreshTbMeta(pCtg, pConn, ctx, &output, false));
+    CTG_ERR_JRET(ctgRefreshTbMeta(pCtg, pConn, ctx, &output, ctx->flag & CTG_FLAG_SYNC_OP));
 
     if (CTG_IS_META_TABLE(output->metaType)) {
       *pTableMeta = output->tbMeta;
@@ -429,6 +429,48 @@ int32_t ctgGetTbCfg(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pTableName,
   CTG_RET(TSDB_CODE_SUCCESS);
 }
 
+int32_t ctgGetTbTag(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pTableName, SArray** pRes) {
+  SVgroupInfo vgroupInfo = {0};
+  STableCfg* pCfg = NULL;
+  int32_t code = 0;
+
+  CTG_ERR_RET(ctgGetTbHashVgroup(pCtg, pConn, pTableName, &vgroupInfo, NULL));
+  CTG_ERR_RET(ctgGetTableCfgFromVnode(pCtg, pConn, pTableName, &vgroupInfo, &pCfg, NULL));
+
+  if (NULL == pCfg->pTags || pCfg->tagsLen <= 0) {
+    ctgError("invalid tag in tbCfg rsp, pTags:%p, len:%d", pCfg->pTags, pCfg->tagsLen);
+    CTG_ERR_JRET(TSDB_CODE_INVALID_MSG);
+  }
+
+  SArray* pTagVals = NULL;
+  STag*   pTag = (STag*)pCfg->pTags;
+
+  if (tTagIsJson(pTag)) {
+    pTagVals = taosArrayInit(1, sizeof(STagVal));
+    if (NULL == pTagVals) {
+      CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
+    }
+
+    char* pJson = parseTagDatatoJson(pTag);
+    STagVal tagVal;
+    tagVal.cid = 0;
+    tagVal.type = TSDB_DATA_TYPE_JSON;
+    tagVal.pData = pJson;
+    tagVal.nData = strlen(pJson);
+    taosArrayPush(pTagVals, &tagVal);
+  } else {
+    CTG_ERR_JRET(tTagToValArray((const STag*)pCfg->pTags, &pTagVals));
+  }
+
+  *pRes = pTagVals;
+
+_return:
+
+  tFreeSTableCfgRsp((STableCfgRsp*)pCfg);
+  
+  CTG_RET(code);
+}
+
 int32_t ctgGetTbDistVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, SName* pTableName, SArray** pVgList) {
   STableMeta*   tbMeta = NULL;
   int32_t       code = 0;
@@ -1414,6 +1456,21 @@ _return:
   CTG_API_LEAVE(code);
 }
 
+int32_t catalogGetTableTag(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SArray** pRes) {
+  CTG_API_ENTER();
+
+  if (NULL == pCtg || NULL == pConn || NULL == pTableName || NULL == pRes) {
+    CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
+  }
+
+  int32_t code = 0;
+  CTG_ERR_JRET(ctgGetTbTag(pCtg, pConn, (SName*)pTableName, pRes));
+
+_return:
+
+  CTG_API_LEAVE(code);
+}
+
 int32_t catalogRefreshGetTableCfg(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, STableCfg** pCfg) {
   CTG_API_ENTER();
 
diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c
index f2a354997d..9e654e89d9 100644
--- a/source/libs/catalog/src/ctgAsync.c
+++ b/source/libs/catalog/src/ctgAsync.c
@@ -21,7 +21,8 @@
 #include "trpc.h"
 
 int32_t ctgInitGetTbMetaTask(SCtgJob* pJob, int32_t taskIdx, void* param) {
-  SName*   name = (SName*)param;
+  SCtgTbMetaParam* pParam = (SCtgTbMetaParam*)param;
+  SName*   name = pParam->pName;
   SCtgTask task = {0};
 
   task.type = CTG_TASK_GET_TB_META;
@@ -41,7 +42,7 @@ int32_t ctgInitGetTbMetaTask(SCtgJob* pJob, int32_t taskIdx, void* param) {
   }
 
   memcpy(ctx->pName, name, sizeof(*name));
-  ctx->flag = CTG_FLAG_UNKNOWN_STB;
+  ctx->flag = pParam->flag | CTG_FLAG_UNKNOWN_STB;
 
   taosArrayPush(pJob->pTasks, &task);
 
@@ -386,6 +387,37 @@ int32_t ctgInitGetTbCfgTask(SCtgJob* pJob, int32_t taskIdx, void* param) {
   return TSDB_CODE_SUCCESS;
 }
 
+int32_t ctgInitGetTbTagTask(SCtgJob* pJob, int32_t taskIdx, void* param) {
+  SName*   name = (SName*)param;
+  SCtgTask task = {0};
+
+  task.type = CTG_TASK_GET_TB_TAG;
+  task.taskId = taskIdx;
+  task.pJob = pJob;
+
+  task.taskCtx = taosMemoryCalloc(1, sizeof(SCtgTbTagCtx));
+  if (NULL == task.taskCtx) {
+    CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
+  }
+
+  SCtgTbTagCtx* ctx = task.taskCtx;
+  ctx->pName = taosMemoryMalloc(sizeof(*name));
+  if (NULL == ctx->pName) {
+    taosMemoryFree(task.taskCtx);
+    CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
+  }
+
+  memcpy(ctx->pName, name, sizeof(*name));
+
+  taosArrayPush(pJob->pTasks, &task);
+
+  qDebug("QID:0x%" PRIx64 " the %dth task type %s initialized, tbName:%s", pJob->queryId, taskIdx,
+         ctgTaskTypeStr(task.type), name->tname);
+
+  return TSDB_CODE_SUCCESS;
+}
+
+
 int32_t ctgHandleForceUpdate(SCatalog* pCtg, int32_t taskNum, SCtgJob* pJob, const SCatalogReq* pReq) {
   SHashObj* pDb = taosHashInit(taskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
   SHashObj* pTb = taosHashInit(taskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
@@ -437,6 +469,15 @@ int32_t ctgHandleForceUpdate(SCatalog* pCtg, int32_t taskNum, SCtgJob* pJob, con
     char   dbFName[TSDB_DB_FNAME_LEN];
     tNameGetFullDbName(name, dbFName);
     taosHashPut(pDb, dbFName, strlen(dbFName), dbFName, TSDB_DB_FNAME_LEN);
+    taosHashPut(pTb, name, sizeof(SName), name, sizeof(SName));
+  }
+
+  for (int32_t i = 0; i < pJob->tbTagNum; ++i) {
+    SName* name = taosArrayGet(pReq->pTableTag, i);
+    char   dbFName[TSDB_DB_FNAME_LEN];
+    tNameGetFullDbName(name, dbFName);
+    taosHashPut(pDb, dbFName, strlen(dbFName), dbFName, TSDB_DB_FNAME_LEN);
+    taosHashPut(pTb, name, sizeof(SName), name, sizeof(SName));
   }
 
   char* dbFName = taosHashIterate(pDb, NULL);
@@ -505,9 +546,10 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const
   int32_t dbInfoNum = (int32_t)taosArrayGetSize(pReq->pDbInfo);
   int32_t tbIndexNum = (int32_t)taosArrayGetSize(pReq->pTableIndex);
   int32_t tbCfgNum = (int32_t)taosArrayGetSize(pReq->pTableCfg);
+  int32_t tbTagNum = (int32_t)taosArrayGetSize(pReq->pTableTag);
 
   int32_t taskNum = tbMetaNum + dbVgNum + udfNum + tbHashNum + qnodeNum + dnodeNum + svrVerNum + dbCfgNum + indexNum +
-                    userNum + dbInfoNum + tbIndexNum + tbCfgNum;
+                    userNum + dbInfoNum + tbIndexNum + tbCfgNum + tbTagNum;
 
   *job = taosMemoryCalloc(1, sizeof(SCtgJob));
   if (NULL == *job) {
@@ -537,6 +579,7 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const
   pJob->tbIndexNum = tbIndexNum;
   pJob->tbCfgNum = tbCfgNum;
   pJob->svrVerNum = svrVerNum;
+  pJob->tbTagNum = tbTagNum;
 
 #if CTG_BATCH_FETCH
   pJob->pBatchs =
@@ -604,6 +647,12 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const
     CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_TB_CFG, name, NULL));
   }
 
+  for (int32_t i = 0; i < tbTagNum; ++i) {
+    SName* name = taosArrayGet(pReq->pTableTag, i);
+    CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_TB_TAG, name, NULL));
+  }
+
+
   for (int32_t i = 0; i < indexNum; ++i) {
     char* indexName = taosArrayGet(pReq->pIndex, i);
     CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_INDEX_INFO, indexName, NULL));
@@ -650,6 +699,10 @@ _return:
 }
 
 int32_t ctgDumpTbMetaRes(SCtgTask* pTask) {
+  if (pTask->subTask) {
+    return TSDB_CODE_SUCCESS;
+  }
+  
   SCtgJob* pJob = pTask->pJob;
   if (NULL == pJob->jobRes.pTableMeta) {
     pJob->jobRes.pTableMeta = taosArrayInit(pJob->tbMetaNum, sizeof(SMetaRes));
@@ -665,6 +718,10 @@ int32_t ctgDumpTbMetaRes(SCtgTask* pTask) {
 }
 
 int32_t ctgDumpTbMetasRes(SCtgTask* pTask) {
+  if (pTask->subTask) {
+    return TSDB_CODE_SUCCESS;
+  }
+
   SCtgJob* pJob = pTask->pJob;
 
   pJob->jobRes.pTableMeta = pTask->res;
@@ -673,6 +730,10 @@ int32_t ctgDumpTbMetasRes(SCtgTask* pTask) {
 }
 
 int32_t ctgDumpDbVgRes(SCtgTask* pTask) {
+  if (pTask->subTask) {
+    return TSDB_CODE_SUCCESS;
+  }
+
   SCtgJob* pJob = pTask->pJob;
   if (NULL == pJob->jobRes.pDbVgroup) {
     pJob->jobRes.pDbVgroup = taosArrayInit(pJob->dbVgNum, sizeof(SMetaRes));
@@ -688,6 +749,10 @@ int32_t ctgDumpDbVgRes(SCtgTask* pTask) {
 }
 
 int32_t ctgDumpTbHashRes(SCtgTask* pTask) {
+  if (pTask->subTask) {
+    return TSDB_CODE_SUCCESS;
+  }
+
   SCtgJob* pJob = pTask->pJob;
   if (NULL == pJob->jobRes.pTableHash) {
     pJob->jobRes.pTableHash = taosArrayInit(pJob->tbHashNum, sizeof(SMetaRes));
@@ -703,6 +768,10 @@ int32_t ctgDumpTbHashRes(SCtgTask* pTask) {
 }
 
 int32_t ctgDumpTbHashsRes(SCtgTask* pTask) {
+  if (pTask->subTask) {
+    return TSDB_CODE_SUCCESS;
+  }
+
   SCtgJob* pJob = pTask->pJob;
 
   pJob->jobRes.pTableHash = pTask->res;
@@ -711,9 +780,17 @@ int32_t ctgDumpTbHashsRes(SCtgTask* pTask) {
 }
 
 int32_t ctgDumpTbIndexRes(SCtgTask* pTask) {
+  if (pTask->subTask) {
+    return TSDB_CODE_SUCCESS;
+  }
+
   SCtgJob* pJob = pTask->pJob;
   if (NULL == pJob->jobRes.pTableIndex) {
-    pJob->jobRes.pTableIndex = taosArrayInit(pJob->tbIndexNum, sizeof(SMetaRes));
+    SArray* pRes = taosArrayInit(pJob->tbIndexNum, sizeof(SMetaRes));
+    if (atomic_val_compare_exchange_ptr(&pJob->jobRes.pTableIndex, NULL, pRes)) {
+      taosArrayDestroy(pRes);
+    }
+
     if (NULL == pJob->jobRes.pTableIndex) {
       CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
     }
@@ -726,9 +803,17 @@ int32_t ctgDumpTbIndexRes(SCtgTask* pTask) {
 }
 
 int32_t ctgDumpTbCfgRes(SCtgTask* pTask) {
+  if (pTask->subTask) {
+    return TSDB_CODE_SUCCESS;
+  }
+
   SCtgJob* pJob = pTask->pJob;
   if (NULL == pJob->jobRes.pTableCfg) {
-    pJob->jobRes.pTableCfg = taosArrayInit(pJob->tbCfgNum, sizeof(SMetaRes));
+    SArray* pRes = taosArrayInit(pJob->tbCfgNum, sizeof(SMetaRes));
+    if (atomic_val_compare_exchange_ptr(&pJob->jobRes.pTableCfg, NULL, pRes)) {
+      taosArrayDestroy(pRes);
+    }
+
     if (NULL == pJob->jobRes.pTableCfg) {
       CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
     }
@@ -740,7 +825,35 @@ int32_t ctgDumpTbCfgRes(SCtgTask* pTask) {
   return TSDB_CODE_SUCCESS;
 }
 
+int32_t ctgDumpTbTagRes(SCtgTask* pTask) {
+  if (pTask->subTask) {
+    return TSDB_CODE_SUCCESS;
+  }
+
+  SCtgJob* pJob = pTask->pJob;
+  if (NULL == pJob->jobRes.pTableTag) {
+    SArray* pRes = taosArrayInit(pJob->tbTagNum, sizeof(SMetaRes));
+    if (atomic_val_compare_exchange_ptr(&pJob->jobRes.pTableTag, NULL, pRes)) {
+      taosArrayDestroy(pRes);
+    }
+    
+    if (NULL == pJob->jobRes.pTableTag) {
+      CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
+    }
+  }
+
+  SMetaRes res = {.code = pTask->code, .pRes = pTask->res};
+  taosArrayPush(pJob->jobRes.pTableTag, &res);
+
+  return TSDB_CODE_SUCCESS;
+}
+
+
 int32_t ctgDumpIndexRes(SCtgTask* pTask) {
+  if (pTask->subTask) {
+    return TSDB_CODE_SUCCESS;
+  }
+
   SCtgJob* pJob = pTask->pJob;
   if (NULL == pJob->jobRes.pIndex) {
     pJob->jobRes.pIndex = taosArrayInit(pJob->indexNum, sizeof(SMetaRes));
@@ -756,6 +869,10 @@ int32_t ctgDumpIndexRes(SCtgTask* pTask) {
 }
 
 int32_t ctgDumpQnodeRes(SCtgTask* pTask) {
+  if (pTask->subTask) {
+    return TSDB_CODE_SUCCESS;
+  }
+
   SCtgJob* pJob = pTask->pJob;
   if (NULL == pJob->jobRes.pQnodeList) {
     pJob->jobRes.pQnodeList = taosArrayInit(1, sizeof(SMetaRes));
@@ -771,6 +888,10 @@ int32_t ctgDumpQnodeRes(SCtgTask* pTask) {
 }
 
 int32_t ctgDumpDnodeRes(SCtgTask* pTask) {
+  if (pTask->subTask) {
+    return TSDB_CODE_SUCCESS;
+  }
+
   SCtgJob* pJob = pTask->pJob;
   if (NULL == pJob->jobRes.pDnodeList) {
     pJob->jobRes.pDnodeList = taosArrayInit(1, sizeof(SMetaRes));
@@ -786,6 +907,10 @@ int32_t ctgDumpDnodeRes(SCtgTask* pTask) {
 }
 
 int32_t ctgDumpDbCfgRes(SCtgTask* pTask) {
+  if (pTask->subTask) {
+    return TSDB_CODE_SUCCESS;
+  }
+
   SCtgJob* pJob = pTask->pJob;
   if (NULL == pJob->jobRes.pDbCfg) {
     pJob->jobRes.pDbCfg = taosArrayInit(pJob->dbCfgNum, sizeof(SMetaRes));
@@ -801,6 +926,10 @@ int32_t ctgDumpDbCfgRes(SCtgTask* pTask) {
 }
 
 int32_t ctgDumpDbInfoRes(SCtgTask* pTask) {
+  if (pTask->subTask) {
+    return TSDB_CODE_SUCCESS;
+  }
+
   SCtgJob* pJob = pTask->pJob;
   if (NULL == pJob->jobRes.pDbInfo) {
     pJob->jobRes.pDbInfo = taosArrayInit(pJob->dbInfoNum, sizeof(SMetaRes));
@@ -816,6 +945,10 @@ int32_t ctgDumpDbInfoRes(SCtgTask* pTask) {
 }
 
 int32_t ctgDumpUdfRes(SCtgTask* pTask) {
+  if (pTask->subTask) {
+    return TSDB_CODE_SUCCESS;
+  }
+
   SCtgJob* pJob = pTask->pJob;
   if (NULL == pJob->jobRes.pUdfList) {
     pJob->jobRes.pUdfList = taosArrayInit(pJob->udfNum, sizeof(SMetaRes));
@@ -831,6 +964,10 @@ int32_t ctgDumpUdfRes(SCtgTask* pTask) {
 }
 
 int32_t ctgDumpUserRes(SCtgTask* pTask) {
+  if (pTask->subTask) {
+    return TSDB_CODE_SUCCESS;
+  }
+
   SCtgJob* pJob = pTask->pJob;
   if (NULL == pJob->jobRes.pUser) {
     pJob->jobRes.pUser = taosArrayInit(pJob->userNum, sizeof(SMetaRes));
@@ -846,6 +983,10 @@ int32_t ctgDumpUserRes(SCtgTask* pTask) {
 }
 
 int32_t ctgDumpSvrVer(SCtgTask* pTask) {
+  if (pTask->subTask) {
+    return TSDB_CODE_SUCCESS;
+  }
+
   SCtgJob* pJob = pTask->pJob;
   if (NULL == pJob->jobRes.pSvrVer) {
     pJob->jobRes.pSvrVer = taosMemoryCalloc(1, sizeof(SMetaRes));
@@ -1075,7 +1216,7 @@ int32_t ctgHandleGetTbMetaRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf
 
   STableMetaOutput* pOut = (STableMetaOutput*)pMsgCtx->out;
 
-  ctgUpdateTbMetaToCache(pCtg, pOut, false);
+  ctgUpdateTbMetaToCache(pCtg, pOut, flag & CTG_FLAG_SYNC_OP);
 
   if (CTG_IS_META_BOTH(pOut->metaType)) {
     memcpy(pOut->tbMeta, &pOut->ctbMeta, sizeof(pOut->ctbMeta));
@@ -1296,12 +1437,12 @@ _return:
     SMetaRes* pRes = taosArrayGet(ctx->pResList, pFetch->resIdx);
     pRes->code = code;
     pRes->pRes = NULL;
+    ctgTaskError("Get table %d.%s.%s meta failed with error %s", pName->acctId, pName->dbname, pName->tname,
+                 tstrerror(code));
     if (0 == atomic_sub_fetch_32(&ctx->fetchNum, 1)) {
       TSWAP(pTask->res, ctx->pResList);
       taskDone = true;
     }
-    ctgTaskError("Get table %d.%s.%s meta failed with error %s", pName->acctId, pName->dbname, pName->tname,
-                 tstrerror(code));
   }
 
   if (pTask->res && taskDone) {
@@ -1473,6 +1614,49 @@ _return:
   CTG_RET(code);
 }
 
+
+int32_t ctgHandleGetTbTagRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf* pMsg, int32_t rspCode) {
+  int32_t   code = 0;
+  SCtgTask* pTask = tReq->pTask;
+  SCatalog* pCtg = pTask->pJob->pCtg;
+  CTG_ERR_JRET(ctgProcessRspMsg(&pTask->msgCtx.out, reqType, pMsg->pData, pMsg->len, rspCode, pTask->msgCtx.target));
+
+  STableCfgRsp* pRsp = (STableCfgRsp*)pTask->msgCtx.out;
+  if (NULL == pRsp->pTags || pRsp->tagsLen <= 0) {
+    ctgError("invalid tag in tbCfg rsp, pTags:%p, len:%d", pRsp->pTags, pRsp->tagsLen);
+    CTG_ERR_JRET(TSDB_CODE_INVALID_MSG);
+  }
+
+  SArray* pTagVals = NULL;
+  STag*   pTag = (STag*)pRsp->pTags;
+
+  if (tTagIsJson(pTag)) {
+    pTagVals = taosArrayInit(1, sizeof(STagVal));
+    if (NULL == pTagVals) {
+      CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
+    }
+
+    char* pJson = parseTagDatatoJson(pTag);
+    STagVal tagVal;
+    tagVal.cid = 0;
+    tagVal.type = TSDB_DATA_TYPE_JSON;
+    tagVal.pData = pJson;
+    tagVal.nData = strlen(pJson);
+    taosArrayPush(pTagVals, &tagVal);
+  } else {
+    CTG_ERR_JRET(tTagToValArray((const STag*)pRsp->pTags, &pTagVals));
+  }
+  
+  pTask->res = pTagVals;
+
+_return:
+
+  ctgHandleTaskEnd(pTask, code);
+
+  CTG_RET(code);
+}
+
+
 int32_t ctgHandleGetDbCfgRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf* pMsg, int32_t rspCode) {
   int32_t   code = 0;
   SCtgTask* pTask = tReq->pTask;
@@ -1905,7 +2089,10 @@ int32_t ctgLaunchGetTbCfgTask(SCtgTask* pTask) {
   if (pCtx->tbType <= 0) {
     CTG_ERR_JRET(ctgReadTbTypeFromCache(pCtg, dbFName, pCtx->pName->tname, &pCtx->tbType));
     if (pCtx->tbType <= 0) {
-      CTG_ERR_JRET(ctgLaunchSubTask(pTask, CTG_TASK_GET_TB_META, ctgGetTbCfgCb, pCtx->pName));
+      SCtgTbMetaParam param;
+      param.pName = pCtx->pName;
+      param.flag = 0;
+      CTG_ERR_JRET(ctgLaunchSubTask(pTask, CTG_TASK_GET_TB_META, ctgGetTbCfgCb, ¶m));
       return TSDB_CODE_SUCCESS;
     }
   }
@@ -1935,6 +2122,45 @@ _return:
   CTG_RET(code);
 }
 
+
+int32_t ctgLaunchGetTbTagTask(SCtgTask* pTask) {
+  int32_t           code = 0;
+  SCatalog*         pCtg = pTask->pJob->pCtg;
+  SRequestConnInfo* pConn = &pTask->pJob->conn;
+  SCtgTbTagCtx*     pCtx = (SCtgTbTagCtx*)pTask->taskCtx;
+  SArray*           pRes = NULL;
+  char              dbFName[TSDB_DB_FNAME_LEN];
+  tNameGetFullDbName(pCtx->pName, dbFName);
+  SCtgJob*    pJob = pTask->pJob;
+  SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, -1);
+  if (NULL == pMsgCtx->pBatchs) {
+    pMsgCtx->pBatchs = pJob->pBatchs;
+  }
+
+  if (NULL == pCtx->pVgInfo) {
+    CTG_ERR_JRET(ctgGetTbHashVgroupFromCache(pCtg, pCtx->pName, &pCtx->pVgInfo));
+    if (NULL == pCtx->pVgInfo) {
+      CTG_ERR_JRET(ctgLaunchSubTask(pTask, CTG_TASK_GET_DB_VGROUP, ctgGetTbTagCb, dbFName));
+      return TSDB_CODE_SUCCESS;
+    }
+  }
+
+  CTG_CACHE_NHIT_INC(CTG_CI_TBL_TAG, 1);
+
+  CTG_ERR_JRET(ctgGetTableCfgFromVnode(pCtg, pConn, pCtx->pName, pCtx->pVgInfo, NULL, pTask));
+
+  return TSDB_CODE_SUCCESS;
+
+_return:
+
+  if (CTG_TASK_LAUNCHED == pTask->status) {
+    ctgHandleTaskEnd(pTask, code);
+  }
+
+  CTG_RET(code);
+}
+
+
 int32_t ctgLaunchGetQnodeTask(SCtgTask* pTask) {
   SCatalog*         pCtg = pTask->pJob->pCtg;
   SRequestConnInfo* pConn = &pTask->pJob->conn;
@@ -2077,6 +2303,8 @@ int32_t ctgLaunchGetUserTask(SCtgTask* pTask) {
   if (inCache) {
     pTask->res = rsp.pRawRes;
 
+    ctgTaskDebug("Final res got, pass:%d, pCond:%p", rsp.pRawRes->pass, rsp.pRawRes->pCond);
+
     CTG_ERR_RET(ctgHandleTaskEnd(pTask, 0));
     return TSDB_CODE_SUCCESS;
   }
@@ -2084,7 +2312,10 @@ int32_t ctgLaunchGetUserTask(SCtgTask* pTask) {
   taosMemoryFreeClear(rsp.pRawRes);
 
   if (rsp.metaNotExists) {
-    CTG_ERR_RET(ctgLaunchSubTask(pTask, CTG_TASK_GET_TB_META, ctgGetTbCfgCb, &pCtx->user.tbName));
+    SCtgTbMetaParam param;
+    param.pName = &pCtx->user.tbName;
+    param.flag = CTG_FLAG_SYNC_OP;
+    CTG_ERR_RET(ctgLaunchSubTask(pTask, CTG_TASK_GET_TB_META, ctgGetUserCb, ¶m));
   } else {
     CTG_ERR_RET(ctgGetUserDbAuthFromMnode(pCtg, pConn, pCtx->user.user, NULL, pTask));
   }
@@ -2138,6 +2369,27 @@ _return:
   CTG_RET(ctgHandleTaskEnd(pTask, pTask->subRes.code));
 }
 
+int32_t ctgGetTbTagCb(SCtgTask* pTask) {
+  int32_t code = 0;
+
+  CTG_ERR_JRET(pTask->subRes.code);
+
+  SCtgTbTagCtx* pCtx = (SCtgTbTagCtx*)pTask->taskCtx;
+  SDBVgInfo* pDb = (SDBVgInfo*)pTask->subRes.res;
+
+  if (NULL == pCtx->pVgInfo) {
+    pCtx->pVgInfo = taosMemoryCalloc(1, sizeof(SVgroupInfo));
+    CTG_ERR_JRET(ctgGetVgInfoFromHashValue(pTask->pJob->pCtg, pDb, pCtx->pName, pCtx->pVgInfo));
+  }
+  
+  CTG_RET(ctgLaunchGetTbTagTask(pTask));
+
+_return:
+
+  CTG_RET(ctgHandleTaskEnd(pTask, pTask->subRes.code));
+}
+
+
 
 int32_t ctgGetUserCb(SCtgTask* pTask) {
   int32_t code = 0;
@@ -2162,8 +2414,12 @@ int32_t ctgCompDbVgTasks(SCtgTask* pTask, void* param, bool* equal) {
 
 int32_t ctgCompTbMetaTasks(SCtgTask* pTask, void* param, bool* equal) {
   SCtgTbMetaCtx* ctx = pTask->taskCtx;
+  SCtgTbMetaParam* pParam = (SCtgTbMetaParam*)param;
 
-  *equal = tNameTbNameEqual(ctx->pName, (SName*)param);
+  *equal = tNameTbNameEqual(ctx->pName, (SName*)pParam->pName);
+  if (*equal) {
+    ctx->flag |= pParam->flag;
+  }
 
   return TSDB_CODE_SUCCESS;
 }
@@ -2197,6 +2453,7 @@ SCtgAsyncFps gCtgAsyncFps[] = {
     {ctgInitGetSvrVerTask, ctgLaunchGetSvrVerTask, ctgHandleGetSvrVerRsp, ctgDumpSvrVer, NULL, NULL},
     {ctgInitGetTbMetasTask, ctgLaunchGetTbMetasTask, ctgHandleGetTbMetasRsp, ctgDumpTbMetasRes, NULL, NULL},
     {ctgInitGetTbHashsTask, ctgLaunchGetTbHashsTask, ctgHandleGetTbHashsRsp, ctgDumpTbHashsRes, NULL, NULL},
+    {ctgInitGetTbTagTask, ctgLaunchGetTbTagTask, ctgHandleGetTbTagRsp, ctgDumpTbTagRes, NULL, NULL},
 };
 
 int32_t ctgMakeAsyncRes(SCtgJob* pJob) {
@@ -2284,6 +2541,9 @@ int32_t ctgLaunchSubTask(SCtgTask* pTask, CTG_TASK_TYPE type, ctgSubTaskCbFp fp,
   }
 
   SCtgTask* pSub = taosArrayGet(pJob->pTasks, subTaskId);
+  if (newTask) {
+    pSub->subTask = true;
+  }
 
   CTG_ERR_RET(ctgSetSubTaskCb(pSub, pTask));
 
diff --git a/source/libs/catalog/src/ctgCache.c b/source/libs/catalog/src/ctgCache.c
index 592b6e9c72..433eacd30e 100644
--- a/source/libs/catalog/src/ctgCache.c
+++ b/source/libs/catalog/src/ctgCache.c
@@ -703,7 +703,31 @@ _return:
   CTG_RET(code);
 }
 
+int32_t ctgGetCachedStbNameFromSuid(SCatalog* pCtg, char* dbFName, uint64_t suid, char **stbName) {
+  *stbName = NULL;
+
+  SCtgDBCache *dbCache = NULL;
+  ctgAcquireDBCache(pCtg, dbFName, &dbCache);
+  if (NULL == dbCache) {
+    ctgDebug("db %s not in cache", dbFName);
+    return TSDB_CODE_SUCCESS;
+  }  
+  
+  char *stb = taosHashAcquire(dbCache->stbCache, &suid, sizeof(suid));
+  if (NULL == stb) {
+    ctgDebug("stb 0x%" PRIx64 " not in cache, dbFName:%s", suid, dbFName);
+    return TSDB_CODE_SUCCESS;
+  }
+
+  *stbName = taosStrdup(stb);
+
+  taosHashRelease(dbCache->stbCache, stb);
+
+  return TSDB_CODE_SUCCESS;
+}
+
 int32_t ctgChkAuthFromCache(SCatalog *pCtg, SUserAuthInfo *pReq, bool *inCache, SCtgAuthRsp *pRes) {
+  int32_t code = 0;
   if (IS_SYS_DBNAME(pReq->tbName.dbname)) {
     *inCache = true;
     pRes->pRawRes->pass = true;
@@ -728,7 +752,7 @@ int32_t ctgChkAuthFromCache(SCatalog *pCtg, SUserAuthInfo *pReq, bool *inCache,
 
   CTG_LOCK(CTG_READ, &pUser->lock);
   memcpy(&req.authInfo, &pUser->userAuth, sizeof(pUser->userAuth));
-  int32_t code = ctgChkSetAuthRes(pCtg, &req, pRes);
+  code = ctgChkSetAuthRes(pCtg, &req, pRes);
   CTG_UNLOCK(CTG_READ, &pUser->lock);
   CTG_ERR_JRET(code);
 
@@ -742,8 +766,9 @@ _return:
 
   *inCache = false;
   CTG_CACHE_NHIT_INC(CTG_CI_USER, 1);
+  ctgDebug("Get user from cache failed, user:%s, metaNotExists:%d, code:%d", pReq->user, pRes->metaNotExists, code);
 
-  return TSDB_CODE_SUCCESS;
+  return code;
 }
 
 void ctgDequeue(SCtgCacheOperation **op) {
@@ -1057,7 +1082,7 @@ int32_t ctgUpdateUserEnqueue(SCatalog *pCtg, SGetUserAuthRsp *pAuth, bool syncOp
   if (NULL == msg) {
     ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateUserMsg));
     taosMemoryFree(op);
-    CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
+    CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
   }
 
   msg->pCtg = pCtg;
diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c
index b2b2b5a87e..9274c1ef92 100644
--- a/source/libs/catalog/src/ctgUtil.c
+++ b/source/libs/catalog/src/ctgUtil.c
@@ -170,6 +170,9 @@ void ctgFreeSMetaData(SMetaData* pData) {
   taosArrayDestroy(pData->pTableCfg);
   pData->pTableCfg = NULL;
 
+  taosArrayDestroy(pData->pTableTag);
+  pData->pTableTag = NULL;
+
   taosMemoryFreeClear(pData->pSvrVer);
 }
 
@@ -486,6 +489,18 @@ void ctgFreeBatchHash(void* hash) {
   taosMemoryFreeClear(pRes->pRes);
 }
 
+void ctgFreeJsonTagVal(void* val) {
+  if (NULL == val) {
+    return;
+  }
+
+  STagVal* pVal = (STagVal*)val;
+
+  if (TSDB_DATA_TYPE_JSON == pVal->type) {
+    taosMemoryFree(pVal->pData);
+  }
+}
+
 void ctgFreeTaskRes(CTG_TASK_TYPE type, void** pRes) {
   switch (type) {
     case CTG_TASK_GET_QNODE:
@@ -516,16 +531,32 @@ void ctgFreeTaskRes(CTG_TASK_TYPE type, void** pRes) {
       }
       break;
     }
+    case CTG_TASK_GET_USER: {
+      if (*pRes) {
+        SUserAuthRes* pAuth = (SUserAuthRes*)*pRes;
+        nodesDestroyNode(pAuth->pCond);
+        taosMemoryFreeClear(*pRes);
+      }
+      break;
+    }
     case CTG_TASK_GET_TB_HASH:
     case CTG_TASK_GET_DB_INFO:
     case CTG_TASK_GET_INDEX_INFO:
     case CTG_TASK_GET_UDF:
-    case CTG_TASK_GET_USER:
     case CTG_TASK_GET_SVR_VER:
     case CTG_TASK_GET_TB_META: {
       taosMemoryFreeClear(*pRes);
       break;
     }
+    case CTG_TASK_GET_TB_TAG: {
+      if (1 == taosArrayGetSize(*pRes)) {
+        taosArrayDestroyEx(*pRes, ctgFreeJsonTagVal);
+      } else {
+        taosArrayDestroy(*pRes);
+      }
+      *pRes = NULL;
+      break;
+    }
     case CTG_TASK_GET_TB_META_BATCH: {
       SArray* pArray = (SArray*)*pRes;
       int32_t num = taosArrayGetSize(pArray);
@@ -679,6 +710,13 @@ void ctgFreeTaskCtx(SCtgTask* pTask) {
       taosMemoryFreeClear(pTask->taskCtx);
       break;
     }
+    case CTG_TASK_GET_TB_TAG: {
+      SCtgTbTagCtx* taskCtx = (SCtgTbTagCtx*)pTask->taskCtx;
+      taosMemoryFreeClear(taskCtx->pName);
+      taosMemoryFreeClear(taskCtx->pVgInfo);
+      taosMemoryFreeClear(taskCtx);
+      break;
+    }
     case CTG_TASK_GET_DB_VGROUP:
     case CTG_TASK_GET_DB_CFG:
     case CTG_TASK_GET_DB_INFO:
@@ -1336,57 +1374,75 @@ int32_t ctgChkSetTbAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
   STableMeta*      pMeta = NULL;
   SGetUserAuthRsp* pInfo = &req->authInfo;
   SHashObj*        pTbs = (AUTH_TYPE_READ == req->singleType) ? pInfo->readTbs : pInfo->writeTbs;
+  char*            stbName = NULL;
 
-  char tbFullName[TSDB_TABLE_FNAME_LEN];
-  tNameExtractFullName(&req->pRawReq->tbName, tbFullName);
-  char* pCond = taosHashGet(pTbs, tbFullName, strlen(tbFullName));
-  if (pCond) {
-    if (strlen(pCond) > 1) {
-      CTG_ERR_RET(nodesStringToNode(pCond, &res->pRawRes->pCond));
+  char tbFName[TSDB_TABLE_FNAME_LEN];
+  char dbFName[TSDB_DB_FNAME_LEN];
+  tNameExtractFullName(&req->pRawReq->tbName, tbFName);
+  tNameGetFullDbName(&req->pRawReq->tbName, dbFName);
+
+  while (true) {
+    taosMemoryFreeClear(pMeta);
+
+    char* pCond = taosHashGet(pTbs, tbFName, strlen(tbFName));
+    if (pCond) {
+      if (strlen(pCond) > 1) {
+        CTG_ERR_JRET(nodesStringToNode(pCond, &res->pRawRes->pCond));
+      }
+
+      res->pRawRes->pass = true;
+      goto _return;
     }
 
-    res->pRawRes->pass = true;
-    return TSDB_CODE_SUCCESS;
+    if (stbName) {
+      res->pRawRes->pass = false;
+      goto _return;
+    }
+
+    CTG_ERR_JRET(catalogGetCachedTableMeta(pCtg, &req->pRawReq->tbName, &pMeta));
+    if (NULL == pMeta) {
+      if (req->onlyCache) {
+        res->metaNotExists = true;
+        ctgDebug("db %s tb %s meta not in cache for auth", req->pRawReq->tbName.dbname, req->pRawReq->tbName.tname);
+        goto _return;
+      }
+
+      SCtgTbMetaCtx ctx = {0};
+      ctx.pName = (SName*)&req->pRawReq->tbName;
+      ctx.flag = CTG_FLAG_UNKNOWN_STB | CTG_FLAG_SYNC_OP;
+
+      CTG_ERR_JRET(ctgGetTbMeta(pCtg, req->pConn, &ctx, &pMeta));
+    }
+
+    if (TSDB_SUPER_TABLE == pMeta->tableType || TSDB_NORMAL_TABLE == pMeta->tableType) {
+      res->pRawRes->pass = false;
+      goto _return;
+    }
+
+    if (TSDB_CHILD_TABLE == pMeta->tableType) {
+      CTG_ERR_JRET(ctgGetCachedStbNameFromSuid(pCtg, dbFName, pMeta->suid, &stbName));
+      if (NULL == stbName) {
+        if (req->onlyCache) {
+          res->metaNotExists = true;
+          ctgDebug("suid %" PRIu64 " name not in cache for auth", pMeta->suid);
+          goto _return;
+        }
+
+        continue;
+      }
+
+      sprintf(tbFName, "%s.%s", dbFName, stbName);
+      continue;
+    }
+
+    ctgError("Invalid table type %d for %s", pMeta->tableType, tbFName);
+    CTG_ERR_JRET(TSDB_CODE_INVALID_PARA);
   }
 
-  res->pRawRes->pass = false;
-
-  // CTG_ERR_RET(catalogGetCachedTableMeta(pCtg, &req->pRawReq->tbName, &pMeta));
-  // if (NULL == pMeta) {
-  //   if (req->onlyCache) {
-  //     res->metaNotExists = true;
-  //     ctgDebug("db %s tb %s meta not in cache for auth", req->pRawReq->tbName.dbname, req->pRawReq->tbName.tname);
-  //     return TSDB_CODE_SUCCESS;
-  //   }
-
-  //   CTG_ERR_RET(catalogGetTableMeta(pCtg, req->pConn, &req->pRawReq->tbName, &pMeta));
-  // }
-
-  // if (TSDB_SUPER_TABLE == pMeta->tableType || TSDB_NORMAL_TABLE == pMeta->tableType) {
-  //   res->pRawRes->pass = false;
-  //   goto _return;
-  // }
-
-  // if (TSDB_CHILD_TABLE == pMeta->tableType) {
-  //   res->pRawRes->pass = true;
-
-  //   /*
-  //       char stbName[TSDB_TABLE_NAME_LEN] = {0};
-  //       CTG_ERR_JRET(ctgGetCachedStbNameFromSuid(pCtg, pMeta->suid, stbName));
-  //       if (0 == stbName[0]) {
-  //         if (req->onlyCache) {
-  //           res->notExists = true;
-  //           return TSDB_CODE_SUCCESS;
-  //         }
-
-  //         CTG_ERR_RET(catalogRefreshTableMeta(pCtg, req->pConn, &req->pRawReq->tbName, 0));
-  //       }
-  //   */
-  // }
-
 _return:
 
   taosMemoryFree(pMeta);
+  taosMemoryFree(stbName);
 
   CTG_RET(code);
 }
@@ -1423,7 +1479,7 @@ int32_t ctgChkSetAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
       if (pInfo->readTbs && taosHashGetSize(pInfo->readTbs) > 0) {
         req->singleType = AUTH_TYPE_READ;
         CTG_ERR_RET(ctgChkSetTbAuthRes(pCtg, req, res));
-        if (pRes->pass) {
+        if (pRes->pass || res->metaNotExists) {
           return TSDB_CODE_SUCCESS;
         }
       }
@@ -1439,7 +1495,7 @@ int32_t ctgChkSetAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
       if (pInfo->writeTbs && taosHashGetSize(pInfo->writeTbs) > 0) {
         req->singleType = AUTH_TYPE_WRITE;
         CTG_ERR_RET(ctgChkSetTbAuthRes(pCtg, req, res));
-        if (pRes->pass) {
+        if (pRes->pass || res->metaNotExists) {
           return TSDB_CODE_SUCCESS;
         }
       }
diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c
index 58c43829cf..6efdd8d8eb 100644
--- a/source/libs/command/src/command.c
+++ b/source/libs/command/src/command.c
@@ -278,7 +278,12 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, ch
 
   char* retentions = buildRetension(pCfg->pRetensions);
   int32_t dbFNameLen = strlen(dbFName);
-  int32_t hashPrefix = (pCfg->hashPrefix > (dbFNameLen + 1)) ? (pCfg->hashPrefix - dbFNameLen - 1) : 0;
+  int32_t hashPrefix = 0;
+  if (pCfg->hashPrefix > 0) {
+    hashPrefix = pCfg->hashPrefix - dbFNameLen - 1;
+  } else if (pCfg->hashPrefix < 0) {
+    hashPrefix = pCfg->hashPrefix + dbFNameLen + 1;
+  }
 
   len += sprintf(
       buf2 + VARSTR_HEADER_SIZE,
diff --git a/source/libs/executor/inc/executil.h b/source/libs/executor/inc/executil.h
index 2e92f9e396..5a9f079c15 100644
--- a/source/libs/executor/inc/executil.h
+++ b/source/libs/executor/inc/executil.h
@@ -39,8 +39,6 @@
 
 #define GET_RES_WINDOW_KEY_LEN(_l)     ((_l) + sizeof(uint64_t))
 
-#define GET_TASKID(_t) (((SExecTaskInfo*)(_t))->id.str)
-
 typedef struct SGroupResInfo {
   int32_t index;
   SArray* pRows;  // SArray
diff --git a/source/libs/executor/inc/executorInt.h b/source/libs/executor/inc/executorInt.h
index d22a7460bb..f31910ae7e 100644
--- a/source/libs/executor/inc/executorInt.h
+++ b/source/libs/executor/inc/executorInt.h
@@ -12,14 +12,75 @@
  * You should have received a copy of the GNU Affero General Public License
  * along with this program. If not, see .
  */
-
-#ifndef _TD_EXECUTOR_INT_H
-#define _TD_EXECUTOR_INT_H
+#ifndef TDENGINE_EXECUTORINT_H
+#define TDENGINE_EXECUTORINT_H
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#include "os.h"
+#include "tcommon.h"
+#include "tlosertree.h"
+#include "tsort.h"
+#include "ttszip.h"
+#include "tvariant.h"
+
+#include "dataSinkMgt.h"
+#include "executil.h"
+#include "executor.h"
+#include "planner.h"
+#include "scalar.h"
+#include "taosdef.h"
+#include "tarray.h"
+#include "tfill.h"
+#include "thash.h"
+#include "tlockfree.h"
+#include "tmsg.h"
+#include "tpagedbuf.h"
+#include "tstream.h"
+#include "tstreamUpdate.h"
+
+#include "vnode.h"
+
+typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int32_t order);
+
+#define IS_VALID_SESSION_WIN(winInfo)        ((winInfo).sessionWin.win.skey > 0)
+#define SET_SESSION_WIN_INVALID(winInfo)     ((winInfo).sessionWin.win.skey = INT64_MIN)
+#define IS_INVALID_SESSION_WIN_KEY(winKey)   ((winKey).win.skey <= 0)
+#define SET_SESSION_WIN_KEY_INVALID(pWinKey) ((pWinKey)->win.skey = INT64_MIN)
+
+/**
+ * If the number of generated results is greater than this value,
+ * query query will be halt and return results to client immediate.
+ */
+typedef struct SResultInfo {  // TODO refactor
+  int64_t totalRows;          // total generated result size in rows
+  int64_t totalBytes;         // total results in bytes.
+  int32_t capacity;           // capacity of current result output buffer
+  int32_t threshold;          // result size threshold in rows.
+} SResultInfo;
+
+typedef struct STableQueryInfo {
+  TSKEY              lastKey;  // last check ts, todo remove it later
+  SResultRowPosition pos;      // current active time window
+} STableQueryInfo;
+
+typedef struct SLimit {
+  int64_t limit;
+  int64_t offset;
+} SLimit;
+
+typedef struct STableScanAnalyzeInfo SFileBlockLoadRecorder;
+
+enum {
+  STREAM_RECOVER_STEP__NONE = 0,
+  STREAM_RECOVER_STEP__PREPARE1,
+  STREAM_RECOVER_STEP__PREPARE2,
+  STREAM_RECOVER_STEP__SCAN1,
+  STREAM_RECOVER_STEP__SCAN2,
+};
+
 extern int32_t exchangeObjRefPool;
 
 typedef struct {
@@ -29,9 +90,585 @@ typedef struct {
   int32_t bytes;
 } SGroupKeys, SStateKeys;
 
+typedef struct {
+  char*           tablename;
+  char*           dbname;
+  int32_t         tversion;
+  SSchemaWrapper* sw;
+  SSchemaWrapper* qsw;
+} SSchemaInfo;
+
+typedef struct SExchangeOpStopInfo {
+  int32_t operatorType;
+  int64_t refId;
+} SExchangeOpStopInfo;
+
+typedef struct SExprSupp {
+  SExprInfo*      pExprInfo;
+  int32_t         numOfExprs;  // the number of scalar expression in group operator
+  SqlFunctionCtx* pCtx;
+  int32_t*        rowEntryInfoOffset;  // offset value for each row result cell info
+  SFilterInfo*    pFilterInfo;
+} SExprSupp;
+
+typedef enum {
+  EX_SOURCE_DATA_NOT_READY = 0x1,
+  EX_SOURCE_DATA_READY = 0x2,
+  EX_SOURCE_DATA_EXHAUSTED = 0x3,
+} EX_SOURCE_STATUS;
+
+#define COL_MATCH_FROM_COL_ID  0x1
+#define COL_MATCH_FROM_SLOT_ID 0x2
+
+typedef struct SLoadRemoteDataInfo {
+  uint64_t totalSize;     // total load bytes from remote
+  uint64_t totalRows;     // total number of rows
+  uint64_t totalElapsed;  // total elapsed time
+} SLoadRemoteDataInfo;
+
+typedef struct SLimitInfo {
+  SLimit   limit;
+  SLimit   slimit;
+  uint64_t currentGroupId;
+  int64_t  remainGroupOffset;
+  int64_t  numOfOutputGroups;
+  int64_t  remainOffset;
+  int64_t  numOfOutputRows;
+} SLimitInfo;
+
+typedef struct SExchangeInfo {
+  SArray* pSources;
+  SArray* pSourceDataInfo;
+  tsem_t  ready;
+  void*   pTransporter;
+
+  // SArray, result block list, used to keep the multi-block that
+  // passed by downstream operator
+  SArray*      pResultBlockList;
+  SArray*      pRecycledBlocks;  // build a pool for small data block to avoid to repeatly create and then destroy.
+  SSDataBlock* pDummyBlock;      // dummy block, not keep data
+  bool         seqLoadData;      // sequential load data or not, false by default
+  int32_t      current;
+  SLoadRemoteDataInfo loadInfo;
+  uint64_t            self;
+  SLimitInfo          limitInfo;
+  int64_t             openedTs;  // start exec time stamp, todo: move to SLoadRemoteDataInfo
+} SExchangeInfo;
+
+typedef struct SScanInfo {
+  int32_t numOfAsc;
+  int32_t numOfDesc;
+} SScanInfo;
+
+typedef struct SSampleExecInfo {
+  double   sampleRatio;  // data block sample ratio, 1 by default
+  uint32_t seed;         // random seed value
+} SSampleExecInfo;
+
+enum {
+  TABLE_SCAN__TABLE_ORDER = 1,
+  TABLE_SCAN__BLOCK_ORDER = 2,
+};
+
+typedef struct SAggSupporter {
+  SSHashObj*     pResultRowHashTable;  // quick locate the window object for each result
+  char*          keyBuf;               // window key buffer
+  SDiskbasedBuf* pResultBuf;           // query result buffer based on blocked-wised disk file
+  int32_t        resultRowSize;  // the result buffer size for each result row, with the meta data size for each row
+  int32_t        currentPageId;  // current write page id
+} SAggSupporter;
+
+typedef struct {
+  // if the upstream is an interval operator, the interval info is also kept here to get the time window to check if
+  // current data block needs to be loaded.
+  SInterval      interval;
+  SAggSupporter* pAggSup;
+  SExprSupp*     pExprSup;  // expr supporter of aggregate operator
+} SAggOptrPushDownInfo;
+
+typedef struct STableMetaCacheInfo {
+  SLRUCache* pTableMetaEntryCache;  // 100 by default
+  uint64_t   metaFetch;
+  uint64_t   cacheHit;
+} STableMetaCacheInfo;
+
+typedef struct STableScanBase {
+  STsdbReader*           dataReader;
+  SFileBlockLoadRecorder readRecorder;
+  SQueryTableDataCond    cond;
+  SAggOptrPushDownInfo   pdInfo;
+  SColMatchInfo          matchInfo;
+  SReadHandle            readHandle;
+  SExprSupp              pseudoSup;
+  STableMetaCacheInfo    metaCache;
+  int32_t                scanFlag;  // table scan flag to denote if it is a repeat/reverse/main scan
+  int32_t                dataBlockLoadFlag;
+  SLimitInfo             limitInfo;
+  // there are more than one table list exists in one task, if only one vnode exists.
+  STableListInfo* pTableListInfo;
+} STableScanBase;
+
+typedef struct STableScanInfo {
+  STableScanBase  base;
+  SScanInfo       scanInfo;
+  int32_t         scanTimes;
+  SSDataBlock*    pResBlock;
+  SSampleExecInfo sample;  // sample execution info
+  int32_t         currentGroupId;
+  int32_t         currentTable;
+  int8_t          scanMode;
+  int8_t          assignBlockUid;
+  bool            hasGroupByTag;
+  bool            countOnly;
+} STableScanInfo;
+
+typedef struct STableMergeScanInfo {
+  int32_t         tableStartIndex;
+  int32_t         tableEndIndex;
+  bool            hasGroupId;
+  uint64_t        groupId;
+  SArray*         queryConds;  // array of queryTableDataCond
+  STableScanBase  base;
+  int32_t         bufPageSize;
+  uint32_t        sortBufSize;  // max buffer size for in-memory sort
+  SArray*         pSortInfo;
+  SSortHandle*    pSortHandle;
+  SSDataBlock*    pSortInputBlock;
+  int64_t         startTs;  // sort start time
+  SArray*         sortSourceParams;
+  SLimitInfo      limitInfo;
+  int64_t         numOfRows;
+  SScanInfo       scanInfo;
+  int32_t         scanTimes;
+  SSDataBlock*    pResBlock;
+  SSampleExecInfo sample;  // sample execution info
+  SSortExecInfo   sortExecInfo;
+} STableMergeScanInfo;
+
+typedef struct STagScanInfo {
+  SColumnInfo*    pCols;
+  SSDataBlock*    pRes;
+  SColMatchInfo   matchInfo;
+  int32_t         curPos;
+  SLimitNode*     pSlimit;
+  SReadHandle     readHandle;
+  STableListInfo* pTableListInfo;
+} STagScanInfo;
+
+typedef enum EStreamScanMode {
+  STREAM_SCAN_FROM_READERHANDLE = 1,
+  STREAM_SCAN_FROM_RES,
+  STREAM_SCAN_FROM_UPDATERES,
+  STREAM_SCAN_FROM_DELETE_DATA,
+  STREAM_SCAN_FROM_DATAREADER_RETRIEVE,
+  STREAM_SCAN_FROM_DATAREADER_RANGE,
+} EStreamScanMode;
+
+enum {
+  PROJECT_RETRIEVE_CONTINUE = 0x1,
+  PROJECT_RETRIEVE_DONE = 0x2,
+};
+
+typedef struct SStreamAggSupporter {
+  int32_t         resultRowSize;  // the result buffer size for each result row, with the meta data size for each row
+  SSDataBlock*    pScanBlock;
+  SStreamState*   pState;
+  int64_t         gap;        // stream session window gap
+  SqlFunctionCtx* pDummyCtx;  // for combine
+  SSHashObj*      pResultRows;
+  int32_t         stateKeySize;
+  int16_t         stateKeyType;
+  SDiskbasedBuf*  pResultBuf;
+} SStreamAggSupporter;
+
+typedef struct SWindowSupporter {
+  SStreamAggSupporter* pStreamAggSup;
+  int64_t              gap;
+  uint16_t             parentType;
+  SAggSupporter*       pIntervalAggSup;
+} SWindowSupporter;
+
+typedef struct SPartitionBySupporter {
+  SArray* pGroupCols;     // group by columns, SArray
+  SArray* pGroupColVals;  // current group column values, SArray
+  char*   keyBuf;         // group by keys for hash
+  bool    needCalc;       // partition by column
+} SPartitionBySupporter;
+
+typedef struct SPartitionDataInfo {
+  uint64_t groupId;
+  char*    tbname;
+  SArray*  tags;
+  SArray*  rowIds;
+} SPartitionDataInfo;
+
+typedef struct STimeWindowAggSupp {
+  int8_t          calTrigger;
+  int8_t          calTriggerSaved;
+  int64_t         deleteMark;
+  int64_t         deleteMarkSaved;
+  int64_t         waterMark;
+  TSKEY           maxTs;
+  TSKEY           minTs;
+  SColumnInfoData timeWindowData;  // query time window info for scalar function execution.
+} STimeWindowAggSupp;
+
+typedef struct SStreamScanInfo {
+  SExprInfo*    pPseudoExpr;
+  int32_t       numOfPseudoExpr;
+  SExprSupp     tbnameCalSup;
+  SExprSupp     tagCalSup;
+  int32_t       primaryTsIndex;  // primary time stamp slot id
+  SReadHandle   readHandle;
+  SInterval     interval;  // if the upstream is an interval operator, the interval info is also kept here.
+  SColMatchInfo matchInfo;
+
+  SArray*      pBlockLists;  // multiple SSDatablock.
+  SSDataBlock* pRes;         // result SSDataBlock
+  SSDataBlock* pUpdateRes;   // update SSDataBlock
+  int32_t      updateResIndex;
+  int32_t      blockType;        // current block type
+  int32_t      validBlockIndex;  // Is current data has returned?
+  uint64_t     numOfExec;        // execution times
+  STqReader*   tqReader;
+
+  uint64_t     groupId;
+  SUpdateInfo* pUpdateInfo;
+
+  EStreamScanMode       scanMode;
+  struct SOperatorInfo*        pStreamScanOp;
+  struct SOperatorInfo*        pTableScanOp;
+  SArray*               childIds;
+  SWindowSupporter      windowSup;
+  SPartitionBySupporter partitionSup;
+  SExprSupp*            pPartScalarSup;
+  bool                  assignBlockUid;  // assign block uid to groupId, temporarily used for generating rollup SMA.
+  int32_t               scanWinIndex;    // for state operator
+  int32_t               pullDataResIndex;
+  SSDataBlock*          pPullDataRes;    // pull data SSDataBlock
+  SSDataBlock*          pDeleteDataRes;  // delete data SSDataBlock
+  int32_t               deleteDataIndex;
+  STimeWindow           updateWin;
+  STimeWindowAggSupp    twAggSup;
+  SSDataBlock*          pUpdateDataRes;
+  // status for tmq
+  SNodeList* pGroupTags;
+  SNode*     pTagCond;
+  SNode*     pTagIndexCond;
+
+  // recover
+  int32_t      blockRecoverContiCnt;
+  int32_t      blockRecoverTotCnt;
+  SSDataBlock* pRecoverRes;
+
+  SSDataBlock* pCreateTbRes;
+  int8_t       igCheckUpdate;
+  int8_t       igExpired;
+} SStreamScanInfo;
+
+typedef struct {
+  SVnode*         vnode;
+  SSDataBlock     pRes;  // result SSDataBlock
+  STsdbReader*    dataReader;
+  SSnapContext*   sContext;
+  STableListInfo* pTableListInfo;
+} SStreamRawScanInfo;
+
+typedef struct STableCountScanSupp {
+  int16_t dbNameSlotId;
+  int16_t stbNameSlotId;
+  int16_t tbCountSlotId;
+  bool    groupByDbName;
+  bool    groupByStbName;
+  char    dbNameFilter[TSDB_DB_NAME_LEN];
+  char    stbNameFilter[TSDB_TABLE_NAME_LEN];
+} STableCountScanSupp;
+
+typedef struct SOptrBasicInfo {
+  SResultRowInfo resultRowInfo;
+  SSDataBlock*   pRes;
+  bool           mergeResultBlock;
+} SOptrBasicInfo;
+
+typedef struct SIntervalAggOperatorInfo {
+  SOptrBasicInfo     binfo;              // basic info
+  SAggSupporter      aggSup;             // aggregate supporter
+  SExprSupp          scalarSupp;         // supporter for perform scalar function
+  SGroupResInfo      groupResInfo;       // multiple results build supporter
+  SInterval          interval;           // interval info
+  int32_t            primaryTsIndex;     // primary time stamp slot id from result of downstream operator.
+  STimeWindow        win;                // query time range
+  bool               timeWindowInterpo;  // interpolation needed or not
+  SArray*            pInterpCols;        // interpolation columns
+  int32_t            resultTsOrder;      // result timestamp order
+  int32_t            inputOrder;         // input data ts order
+  EOPTR_EXEC_MODEL   execModel;          // operator execution model [batch model|stream model]
+  STimeWindowAggSupp twAggSup;
+  SArray*            pPrevValues;  //  SArray used to keep the previous not null value for interpolation.
+} SIntervalAggOperatorInfo;
+
+typedef struct SMergeAlignedIntervalAggOperatorInfo {
+  SIntervalAggOperatorInfo* intervalAggOperatorInfo;
+
+  uint64_t     groupId;  // current groupId
+  int64_t      curTs;    // current ts
+  SSDataBlock* prefetchedBlock;
+  SResultRow*  pResultRow;
+} SMergeAlignedIntervalAggOperatorInfo;
+
+typedef struct SStreamIntervalOperatorInfo {
+  SOptrBasicInfo     binfo;           // basic info
+  SAggSupporter      aggSup;          // aggregate supporter
+  SExprSupp          scalarSupp;      // supporter for perform scalar function
+  SGroupResInfo      groupResInfo;    // multiple results build supporter
+  SInterval          interval;        // interval info
+  int32_t            primaryTsIndex;  // primary time stamp slot id from result of downstream operator.
+  STimeWindowAggSupp twAggSup;
+  bool               invertible;
+  bool               ignoreExpiredData;
+  bool               ignoreExpiredDataSaved;
+  SArray*            pDelWins;  // SWinRes
+  int32_t            delIndex;
+  SSDataBlock*       pDelRes;
+  SPhysiNode*        pPhyNode;  // create new child
+  SHashObj*          pPullDataMap;
+  SArray*            pPullWins;  // SPullWindowInfo
+  int32_t            pullIndex;
+  SSDataBlock*       pPullDataRes;
+  bool               isFinal;
+  SArray*            pChildren;
+  SStreamState*      pState;
+  SWinKey            delKey;
+  uint64_t           numOfDatapack;
+  SArray*            pUpdated;
+  SSHashObj*         pUpdatedMap;
+  int64_t            dataVersion;
+} SStreamIntervalOperatorInfo;
+
+typedef struct SDataGroupInfo {
+  uint64_t groupId;
+  int64_t  numOfRows;
+  SArray*  pPageList;
+} SDataGroupInfo;
+
+typedef struct SWindowRowsSup {
+  STimeWindow win;
+  TSKEY       prevTs;
+  int32_t     startRowIndex;
+  int32_t     numOfRows;
+  uint64_t    groupId;
+} SWindowRowsSup;
+
+typedef struct SResultWindowInfo {
+  void*       pOutputBuf;
+  SSessionKey sessionWin;
+  bool        isOutput;
+} SResultWindowInfo;
+
+typedef struct SStreamSessionAggOperatorInfo {
+  SOptrBasicInfo      binfo;
+  SStreamAggSupporter streamAggSup;
+  SExprSupp           scalarSupp;  // supporter for perform scalar function
+  SGroupResInfo       groupResInfo;
+  int32_t             primaryTsIndex;  // primary timestamp slot id
+  int32_t             endTsIndex;      // window end timestamp slot id
+  int32_t             order;           // current SSDataBlock scan order
+  STimeWindowAggSupp  twAggSup;
+  SSDataBlock*        pWinBlock;   // window result
+  SSDataBlock*        pDelRes;     // delete result
+  SSDataBlock*        pUpdateRes;  // update window
+  bool                returnUpdate;
+  SSHashObj*          pStDeleted;
+  void*               pDelIterator;
+  SArray*             pChildren;  // cache for children's result; final stream operator
+  SPhysiNode*         pPhyNode;   // create new child
+  bool                isFinal;
+  bool                ignoreExpiredData;
+  bool                ignoreExpiredDataSaved;
+  SArray*             pUpdated;
+  SSHashObj*          pStUpdated;
+  int64_t             dataVersion;
+} SStreamSessionAggOperatorInfo;
+
+typedef struct SStreamStateAggOperatorInfo {
+  SOptrBasicInfo      binfo;
+  SStreamAggSupporter streamAggSup;
+  SExprSupp           scalarSupp;  // supporter for perform scalar function
+  SGroupResInfo       groupResInfo;
+  int32_t             primaryTsIndex;  // primary timestamp slot id
+  STimeWindowAggSupp  twAggSup;
+  SColumn             stateCol;
+  SSDataBlock*        pDelRes;
+  SSHashObj*          pSeDeleted;
+  void*               pDelIterator;
+  SArray*             pChildren;  // cache for children's result;
+  bool                ignoreExpiredData;
+  bool                ignoreExpiredDataSaved;
+  SArray*             pUpdated;
+  SSHashObj*          pSeUpdated;
+  int64_t             dataVersion;
+} SStreamStateAggOperatorInfo;
+
+typedef struct SStreamPartitionOperatorInfo {
+  SOptrBasicInfo        binfo;
+  SPartitionBySupporter partitionSup;
+  SExprSupp             scalarSup;
+  SExprSupp             tbnameCalSup;
+  SExprSupp             tagCalSup;
+  SHashObj*             pPartitions;
+  void*                 parIte;
+  void*                 pTbNameIte;
+  SSDataBlock*          pInputDataBlock;
+  int32_t               tsColIndex;
+  SSDataBlock*          pDelRes;
+  SSDataBlock*          pCreateTbRes;
+} SStreamPartitionOperatorInfo;
+
+typedef struct SStreamFillSupporter {
+  int32_t        type;  // fill type
+  SInterval      interval;
+  SResultRowData prev;
+  SResultRowData cur;
+  SResultRowData next;
+  SResultRowData nextNext;
+  SFillColInfo*  pAllColInfo;  // fill exprs and not fill exprs
+  SExprSupp      notFillExprSup;
+  int32_t        numOfAllCols;  // number of all exprs, including the tags columns
+  int32_t        numOfFillCols;
+  int32_t        numOfNotFillCols;
+  int32_t        rowSize;
+  SSHashObj*     pResMap;
+  bool           hasDelete;
+} SStreamFillSupporter;
+
+typedef struct SStreamFillOperatorInfo {
+  SStreamFillSupporter* pFillSup;
+  SSDataBlock*          pRes;
+  SSDataBlock*          pSrcBlock;
+  int32_t               srcRowIndex;
+  SSDataBlock*          pSrcDelBlock;
+  int32_t               srcDelRowIndex;
+  SSDataBlock*          pDelRes;
+  SColMatchInfo         matchInfo;
+  int32_t               primaryTsCol;
+  int32_t               primarySrcSlotId;
+  SStreamFillInfo*      pFillInfo;
+} SStreamFillOperatorInfo;
+
+#define OPTR_IS_OPENED(_optr)  (((_optr)->status & OP_OPENED) == OP_OPENED)
+#define OPTR_SET_OPENED(_optr) ((_optr)->status |= OP_OPENED)
+
+SSchemaWrapper* extractQueriedColumnSchema(SScanPhysiNode* pScanNode);
+int32_t initQueriedTableSchemaInfo(SReadHandle* pHandle, SScanPhysiNode* pScanNode, const char* dbName, SExecTaskInfo* pTaskInfo);
+void    cleanupQueriedTableScanInfo(SSchemaInfo* pSchemaInfo);
+
+void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock);
+void cleanupBasicInfo(SOptrBasicInfo* pInfo);
+
+int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr);
+void    cleanupExprSupp(SExprSupp* pSup);
+
+void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs);
+
+int32_t initAggSup(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, size_t keyBufSize,
+                   const char* pkey, void* pState);
+void    cleanupAggSup(SAggSupporter* pAggSup);
+
+void initResultSizeInfo(SResultInfo* pResultInfo, int32_t numOfRows);
+
+void doBuildStreamResBlock(struct SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo,
+                           SDiskbasedBuf* pBuf);
+void doBuildResultDatablock(struct SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo,
+                            SDiskbasedBuf* pBuf);
+
+bool hasLimitOffsetInfo(SLimitInfo* pLimitInfo);
+bool hasSlimitOffsetInfo(SLimitInfo* pLimitInfo);
+void initLimitInfo(const SNode* pLimit, const SNode* pSLimit, SLimitInfo* pLimitInfo);
+void resetLimitInfoForNextGroup(SLimitInfo* pLimitInfo);
+bool applyLimitOffset(SLimitInfo* pLimitInfo, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
+
+void applyAggFunctionOnPartialTuples(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, SColumnInfoData* pTimeWindowData,
+                                     int32_t offset, int32_t forwardStep, int32_t numOfTotal, int32_t numOfOutput);
+
+int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, char* pData, SArray* pColList, char** pNextStart);
+void    updateLoadRemoteInfo(SLoadRemoteDataInfo* pInfo, int64_t numOfRows, int32_t dataLen, int64_t startTs,
+                             struct SOperatorInfo* pOperator);
+
+STimeWindow getFirstQualifiedTimeWindow(int64_t ts, STimeWindow* pWindow, SInterval* pInterval, int32_t order);
+int32_t     getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaultBufsz);
+
+extern void doDestroyExchangeOperatorInfo(void* param);
+
+void    doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo);
+int32_t addTagPseudoColumnData(SReadHandle* pHandle, const SExprInfo* pExpr, int32_t numOfExpr, SSDataBlock* pBlock,
+                               int32_t rows, const char* idStr, STableMetaCacheInfo* pCache);
+
+void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle);
+void setTbNameColData(const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId, const char* name);
+
+void setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowEntryInfoOffset);
+void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput);
+
+SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pResultRowInfo, char* pData,
+                                   int16_t bytes, bool masterscan, uint64_t groupId, SExecTaskInfo* pTaskInfo,
+                                   bool isIntervalQuery, SAggSupporter* pSup, bool keepGroup);
+
+int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx,
+                              int32_t numOfOutput, SArray* pPseudoList);
+
+void setInputDataBlock(SExprSupp* pExprSupp, SSDataBlock* pBlock, int32_t order, int32_t scanFlag, bool createDummyCol);
+
+int32_t checkForQueryBuf(size_t numOfTables);
+
+int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pTask, SReadHandle* readHandle);
+
+STimeWindow getActiveTimeWindow(SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int64_t ts, SInterval* pInterval,
+                                int32_t order);
+int32_t getNumOfRowsInTimeWindow(SDataBlockInfo* pDataBlockInfo, TSKEY* pPrimaryColumn, int32_t startPos, TSKEY ekey,
+                                 __block_search_fn_t searchFn, STableQueryInfo* item, int32_t order);
+int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order);
+SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int32_t* currentPageId, int32_t interBufSize);
+void getCurSessionWindow(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endTs, uint64_t groupId, SSessionKey* pKey);
+bool isInTimeWindow(STimeWindow* pWin, TSKEY ts, int64_t gap);
+bool functionNeedToExecute(SqlFunctionCtx* pCtx);
+bool isOverdue(TSKEY ts, STimeWindowAggSupp* pSup);
+bool isCloseWindow(STimeWindow* pWin, STimeWindowAggSupp* pSup);
+bool isDeletedStreamWindow(STimeWindow* pWin, uint64_t groupId, SStreamState* pState, STimeWindowAggSupp* pTwSup);
+void appendOneRowToStreamSpecialBlock(SSDataBlock* pBlock, TSKEY* pStartTs, TSKEY* pEndTs, uint64_t* pUid,
+                                      uint64_t* pGp, void* pTbName);
+uint64_t calGroupIdByData(SPartitionBySupporter* pParSup, SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t rowId);
+
+int32_t finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPosition, SExprSupp* pSup,
+                           SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
+
+bool    groupbyTbname(SNodeList* pGroupList);
+int32_t buildDataBlockFromGroupRes(struct SOperatorInfo* pOperator, SStreamState* pState, SSDataBlock* pBlock, SExprSupp* pSup,
+                                   SGroupResInfo* pGroupResInfo);
+int32_t saveSessionDiscBuf(SStreamState* pState, SSessionKey* key, void* buf, int32_t size);
+int32_t buildSessionResultDataBlock(struct SOperatorInfo* pOperator, SStreamState* pState, SSDataBlock* pBlock,
+                                    SExprSupp* pSup, SGroupResInfo* pGroupResInfo);
+int32_t setOutputBuf(SStreamState* pState, STimeWindow* win, SResultRow** pResult, int64_t tableGroupId,
+                     SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowEntryInfoOffset, SAggSupporter* pAggSup);
+int32_t releaseOutputBuf(SStreamState* pState, SWinKey* pKey, SResultRow* pResult);
+int32_t saveOutputBuf(SStreamState* pState, SWinKey* pKey, SResultRow* pResult, int32_t resSize);
+void    getNextIntervalWindow(SInterval* pInterval, STimeWindow* tw, int32_t order);
+int32_t getForwardStepsInBlock(int32_t numOfRows, __block_search_fn_t searchFn, TSKEY ekey, int32_t pos, int32_t order,
+                               int64_t* pData);
+void    appendCreateTableRow(SStreamState* pState, SExprSupp* pTableSup, SExprSupp* pTagSup, uint64_t groupId,
+                             SSDataBlock* pSrcBlock, int32_t rowId, SSDataBlock* pDestBlock);
+
+SSDataBlock* buildCreateTableBlock(SExprSupp* tbName, SExprSupp* tag);
+SExprInfo*   createExpr(SNodeList* pNodeList, int32_t* numOfExprs);
+
+void copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
+                              SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo);
+void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset);
+void doClearBufferedBlocks(SStreamScanInfo* pInfo);
+
 uint64_t calcGroupId(char* pData, int32_t len);
+
 #ifdef __cplusplus
 }
 #endif
 
-#endif /*_TD_EXECUTOR_INT_H*/
\ No newline at end of file
+#endif  // TDENGINE_EXECUTORINT_H
diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h
index 43ee54f65d..e69de29bb2 100644
--- a/source/libs/executor/inc/executorimpl.h
+++ b/source/libs/executor/inc/executorimpl.h
@@ -1,886 +0,0 @@
-/*
- * Copyright (c) 2019 TAOS Data, Inc. 
- *
- * This program is free software: you can use, redistribute, and/or modify
- * it under the terms of the GNU Affero General Public License, version 3
- * or later ("AGPL"), as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-#ifndef TDENGINE_EXECUTORIMPL_H
-#define TDENGINE_EXECUTORIMPL_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "os.h"
-#include "tcommon.h"
-#include "tlosertree.h"
-#include "tsort.h"
-#include "ttszip.h"
-#include "tvariant.h"
-
-#include "dataSinkMgt.h"
-#include "executil.h"
-#include "executor.h"
-#include "planner.h"
-#include "scalar.h"
-#include "taosdef.h"
-#include "tarray.h"
-#include "tfill.h"
-#include "thash.h"
-#include "tlockfree.h"
-#include "tmsg.h"
-#include "tpagedbuf.h"
-#include "tstream.h"
-#include "tstreamUpdate.h"
-
-#include "executorInt.h"
-#include "vnode.h"
-
-typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int32_t order);
-
-#define IS_VALID_SESSION_WIN(winInfo)        ((winInfo).sessionWin.win.skey > 0)
-#define SET_SESSION_WIN_INVALID(winInfo)     ((winInfo).sessionWin.win.skey = INT64_MIN)
-#define IS_INVALID_SESSION_WIN_KEY(winKey)   ((winKey).win.skey <= 0)
-#define SET_SESSION_WIN_KEY_INVALID(pWinKey) ((pWinKey)->win.skey = INT64_MIN)
-
-enum {
-  // when this task starts to execute, this status will set
-  TASK_NOT_COMPLETED = 0x1u,
-
-  /* Task is over
-   * 1. this status is used in one row result query process, e.g., count/sum/first/last/ avg...etc.
-   * 2. when all data within queried time window, it is also denoted as query_completed
-   */
-  TASK_COMPLETED = 0x2u,
-};
-
-/**
- * If the number of generated results is greater than this value,
- * query query will be halt and return results to client immediate.
- */
-typedef struct SResultInfo {  // TODO refactor
-  int64_t totalRows;          // total generated result size in rows
-  int64_t totalBytes;         // total results in bytes.
-  int32_t capacity;           // capacity of current result output buffer
-  int32_t threshold;          // result size threshold in rows.
-} SResultInfo;
-
-typedef struct STableQueryInfo {
-  TSKEY              lastKey;  // last check ts, todo remove it later
-  SResultRowPosition pos;      // current active time window
-} STableQueryInfo;
-
-typedef struct SLimit {
-  int64_t limit;
-  int64_t offset;
-} SLimit;
-
-typedef struct STableScanAnalyzeInfo SFileBlockLoadRecorder;
-
-typedef struct STaskCostInfo {
-  int64_t                 created;
-  int64_t                 start;
-  uint64_t                elapsedTime;
-  double                  extractListTime;
-  double                  groupIdMapTime;
-  SFileBlockLoadRecorder* pRecoder;
-} STaskCostInfo;
-
-typedef struct SOperatorCostInfo {
-  double openCost;
-  double totalCost;
-} SOperatorCostInfo;
-
-struct SOperatorInfo;
-
-typedef int32_t (*__optr_encode_fn_t)(struct SOperatorInfo* pOperator, char** result, int32_t* length);
-typedef int32_t (*__optr_decode_fn_t)(struct SOperatorInfo* pOperator, char* result);
-
-typedef int32_t (*__optr_open_fn_t)(struct SOperatorInfo* pOptr);
-typedef SSDataBlock* (*__optr_fn_t)(struct SOperatorInfo* pOptr);
-typedef void (*__optr_close_fn_t)(void* param);
-typedef int32_t (*__optr_explain_fn_t)(struct SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len);
-typedef int32_t (*__optr_reqBuf_fn_t)(struct SOperatorInfo* pOptr);
-
-typedef struct STaskIdInfo {
-  uint64_t queryId;  // this is also a request id
-  uint64_t subplanId;
-  uint64_t templateId;
-  char*    str;
-  int32_t  vgId;
-} STaskIdInfo;
-
-enum {
-  STREAM_RECOVER_STEP__NONE = 0,
-  STREAM_RECOVER_STEP__PREPARE1,
-  STREAM_RECOVER_STEP__PREPARE2,
-  STREAM_RECOVER_STEP__SCAN1,
-  STREAM_RECOVER_STEP__SCAN2,
-};
-
-typedef struct {
-  STqOffsetVal        currentOffset;  // for tmq
-  SMqMetaRsp          metaRsp;        // for tmq fetching meta
-  int64_t             snapshotVer;
-  SPackedData         submit;
-  SSchemaWrapper*     schema;
-  char                tbName[TSDB_TABLE_NAME_LEN];
-  int8_t              recoverStep;
-  int8_t              recoverScanFinished;
-  SQueryTableDataCond tableCond;
-  int64_t             fillHistoryVer1;
-  int64_t             fillHistoryVer2;
-  SStreamState*       pState;
-  int64_t             dataVersion;
-  int64_t             checkPointId;
-} SStreamTaskInfo;
-
-typedef struct {
-  char*           tablename;
-  char*           dbname;
-  int32_t         tversion;
-  SSchemaWrapper* sw;
-  SSchemaWrapper* qsw;
-} SSchemaInfo;
-
-typedef struct SExchangeOpStopInfo {
-  int32_t operatorType;
-  int64_t refId;
-} SExchangeOpStopInfo;
-
-typedef struct STaskStopInfo {
-  SRWLatch lock;
-  SArray*  pStopInfo;
-} STaskStopInfo;
-
-struct SExecTaskInfo {
-  STaskIdInfo           id;
-  uint32_t              status;
-  STimeWindow           window;
-  STaskCostInfo         cost;
-  int64_t               owner;  // if it is in execution
-  int32_t               code;
-  int32_t               qbufQuota;  // total available buffer (in KB) during execution query
-  int64_t               version;    // used for stream to record wal version, why not move to sschemainfo
-  SStreamTaskInfo       streamInfo;
-  SSchemaInfo           schemaInfo;
-  const char*           sql;        // query sql string
-  jmp_buf               env;        // jump to this position when error happens.
-  EOPTR_EXEC_MODEL      execModel;  // operator execution model [batch model|stream model]
-  SSubplan*             pSubplan;
-  struct SOperatorInfo* pRoot;
-  SLocalFetch           localFetch;
-  SArray*               pResultBlockList;  // result block list
-  STaskStopInfo         stopInfo;
-  SRWLatch              lock;  // secure the access of STableListInfo
-};
-
-enum {
-  OP_NOT_OPENED = 0x0,
-  OP_OPENED = 0x1,
-  OP_RES_TO_RETURN = 0x5,
-  OP_EXEC_DONE = 0x9,
-};
-
-typedef struct SOperatorFpSet {
-  __optr_open_fn_t    _openFn;  // DO NOT invoke this function directly
-  __optr_fn_t         getNextFn;
-  __optr_fn_t         cleanupFn;  // call this function to release the allocated resources ASAP
-  __optr_close_fn_t   closeFn;
-  __optr_reqBuf_fn_t  reqBufFn;  // total used buffer for blocking operator
-  __optr_encode_fn_t  encodeResultRow;
-  __optr_decode_fn_t  decodeResultRow;
-  __optr_explain_fn_t getExplainFn;
-} SOperatorFpSet;
-
-typedef struct SExprSupp {
-  SExprInfo*      pExprInfo;
-  int32_t         numOfExprs;  // the number of scalar expression in group operator
-  SqlFunctionCtx* pCtx;
-  int32_t*        rowEntryInfoOffset;  // offset value for each row result cell info
-  SFilterInfo*    pFilterInfo;
-} SExprSupp;
-
-typedef struct SOperatorInfo {
-  uint16_t               operatorType;
-  int16_t                resultDataBlockId;
-  bool                   blocking;  // block operator or not
-  uint8_t                status;    // denote if current operator is completed
-  char*                  name;      // name, for debug purpose
-  void*                  info;      // extension attribution
-  SExprSupp              exprSupp;
-  SExecTaskInfo*         pTaskInfo;
-  SOperatorCostInfo      cost;
-  SResultInfo            resultInfo;
-  struct SOperatorInfo** pDownstream;      // downstram pointer list
-  int32_t                numOfDownstream;  // number of downstream. The value is always ONE expect for join operator
-  SOperatorFpSet         fpSet;
-} SOperatorInfo;
-
-typedef enum {
-  EX_SOURCE_DATA_NOT_READY = 0x1,
-  EX_SOURCE_DATA_READY = 0x2,
-  EX_SOURCE_DATA_EXHAUSTED = 0x3,
-} EX_SOURCE_STATUS;
-
-#define COL_MATCH_FROM_COL_ID  0x1
-#define COL_MATCH_FROM_SLOT_ID 0x2
-
-typedef struct SLoadRemoteDataInfo {
-  uint64_t totalSize;     // total load bytes from remote
-  uint64_t totalRows;     // total number of rows
-  uint64_t totalElapsed;  // total elapsed time
-} SLoadRemoteDataInfo;
-
-typedef struct SLimitInfo {
-  SLimit   limit;
-  SLimit   slimit;
-  uint64_t currentGroupId;
-  int64_t  remainGroupOffset;
-  int64_t  numOfOutputGroups;
-  int64_t  remainOffset;
-  int64_t  numOfOutputRows;
-} SLimitInfo;
-
-typedef struct SExchangeInfo {
-  SArray* pSources;
-  SArray* pSourceDataInfo;
-  tsem_t  ready;
-  void*   pTransporter;
-
-  // SArray, result block list, used to keep the multi-block that
-  // passed by downstream operator
-  SArray*      pResultBlockList;
-  SArray*      pRecycledBlocks;  // build a pool for small data block to avoid to repeatly create and then destroy.
-  SSDataBlock* pDummyBlock;      // dummy block, not keep data
-  bool         seqLoadData;      // sequential load data or not, false by default
-  int32_t      current;
-  SLoadRemoteDataInfo loadInfo;
-  uint64_t            self;
-  SLimitInfo          limitInfo;
-  int64_t             openedTs;  // start exec time stamp, todo: move to SLoadRemoteDataInfo
-} SExchangeInfo;
-
-typedef struct SScanInfo {
-  int32_t numOfAsc;
-  int32_t numOfDesc;
-} SScanInfo;
-
-typedef struct SSampleExecInfo {
-  double   sampleRatio;  // data block sample ratio, 1 by default
-  uint32_t seed;         // random seed value
-} SSampleExecInfo;
-
-enum {
-  TABLE_SCAN__TABLE_ORDER = 1,
-  TABLE_SCAN__BLOCK_ORDER = 2,
-};
-
-typedef struct SAggSupporter {
-  SSHashObj*     pResultRowHashTable;  // quick locate the window object for each result
-  char*          keyBuf;               // window key buffer
-  SDiskbasedBuf* pResultBuf;           // query result buffer based on blocked-wised disk file
-  int32_t        resultRowSize;  // the result buffer size for each result row, with the meta data size for each row
-  int32_t        currentPageId;  // current write page id
-} SAggSupporter;
-
-typedef struct {
-  // if the upstream is an interval operator, the interval info is also kept here to get the time window to check if
-  // current data block needs to be loaded.
-  SInterval      interval;
-  SAggSupporter* pAggSup;
-  SExprSupp*     pExprSup;  // expr supporter of aggregate operator
-} SAggOptrPushDownInfo;
-
-typedef struct STableMetaCacheInfo {
-  SLRUCache* pTableMetaEntryCache;  // 100 by default
-  uint64_t   metaFetch;
-  uint64_t   cacheHit;
-} STableMetaCacheInfo;
-
-typedef struct STableScanBase {
-  STsdbReader*           dataReader;
-  SFileBlockLoadRecorder readRecorder;
-  SQueryTableDataCond    cond;
-  SAggOptrPushDownInfo   pdInfo;
-  SColMatchInfo          matchInfo;
-  SReadHandle            readHandle;
-  SExprSupp              pseudoSup;
-  STableMetaCacheInfo    metaCache;
-  int32_t                scanFlag;  // table scan flag to denote if it is a repeat/reverse/main scan
-  int32_t                dataBlockLoadFlag;
-  SLimitInfo             limitInfo;
-  // there are more than one table list exists in one task, if only one vnode exists.
-  STableListInfo* pTableListInfo;
-} STableScanBase;
-
-typedef struct STableScanInfo {
-  STableScanBase  base;
-  SScanInfo       scanInfo;
-  int32_t         scanTimes;
-  SSDataBlock*    pResBlock;
-  SSampleExecInfo sample;  // sample execution info
-  int32_t         currentGroupId;
-  int32_t         currentTable;
-  int8_t          scanMode;
-  int8_t          assignBlockUid;
-  bool            hasGroupByTag;
-  bool            countOnly;
-} STableScanInfo;
-
-typedef struct STableMergeScanInfo {
-  int32_t         tableStartIndex;
-  int32_t         tableEndIndex;
-  bool            hasGroupId;
-  uint64_t        groupId;
-  SArray*         queryConds;  // array of queryTableDataCond
-  STableScanBase  base;
-  int32_t         bufPageSize;
-  uint32_t        sortBufSize;  // max buffer size for in-memory sort
-  SArray*         pSortInfo;
-  SSortHandle*    pSortHandle;
-  SSDataBlock*    pSortInputBlock;
-  int64_t         startTs;  // sort start time
-  SArray*         sortSourceParams;
-  SLimitInfo      limitInfo;
-  int64_t         numOfRows;
-  SScanInfo       scanInfo;
-  int32_t         scanTimes;
-  SSDataBlock*    pResBlock;
-  SSampleExecInfo sample;  // sample execution info
-  SSortExecInfo   sortExecInfo;
-} STableMergeScanInfo;
-
-typedef struct STagScanInfo {
-  SColumnInfo*    pCols;
-  SSDataBlock*    pRes;
-  SColMatchInfo   matchInfo;
-  int32_t         curPos;
-  SReadHandle     readHandle;
-  STableListInfo* pTableListInfo;
-  SLimitNode*     pSlimit;
-} STagScanInfo;
-
-typedef enum EStreamScanMode {
-  STREAM_SCAN_FROM_READERHANDLE = 1,
-  STREAM_SCAN_FROM_RES,
-  STREAM_SCAN_FROM_UPDATERES,
-  STREAM_SCAN_FROM_DELETE_DATA,
-  STREAM_SCAN_FROM_DATAREADER_RETRIEVE,
-  STREAM_SCAN_FROM_DATAREADER_RANGE,
-} EStreamScanMode;
-
-enum {
-  PROJECT_RETRIEVE_CONTINUE = 0x1,
-  PROJECT_RETRIEVE_DONE = 0x2,
-};
-
-typedef struct SStreamAggSupporter {
-  int32_t         resultRowSize;  // the result buffer size for each result row, with the meta data size for each row
-  SSDataBlock*    pScanBlock;
-  SStreamState*   pState;
-  int64_t         gap;        // stream session window gap
-  SqlFunctionCtx* pDummyCtx;  // for combine
-  SSHashObj*      pResultRows;
-  int32_t         stateKeySize;
-  int16_t         stateKeyType;
-  SDiskbasedBuf*  pResultBuf;
-} SStreamAggSupporter;
-
-typedef struct SWindowSupporter {
-  SStreamAggSupporter* pStreamAggSup;
-  int64_t              gap;
-  uint16_t             parentType;
-  SAggSupporter*       pIntervalAggSup;
-} SWindowSupporter;
-
-typedef struct SPartitionBySupporter {
-  SArray* pGroupCols;     // group by columns, SArray
-  SArray* pGroupColVals;  // current group column values, SArray
-  char*   keyBuf;         // group by keys for hash
-  bool    needCalc;       // partition by column
-} SPartitionBySupporter;
-
-typedef struct SPartitionDataInfo {
-  uint64_t groupId;
-  char*    tbname;
-  SArray*  tags;
-  SArray*  rowIds;
-} SPartitionDataInfo;
-
-typedef struct STimeWindowAggSupp {
-  int8_t          calTrigger;
-  int8_t          calTriggerSaved;
-  int64_t         deleteMark;
-  int64_t         deleteMarkSaved;
-  int64_t         waterMark;
-  TSKEY           maxTs;
-  TSKEY           minTs;
-  SColumnInfoData timeWindowData;  // query time window info for scalar function execution.
-} STimeWindowAggSupp;
-
-typedef struct SStreamScanInfo {
-  SExprInfo*    pPseudoExpr;
-  int32_t       numOfPseudoExpr;
-  SExprSupp     tbnameCalSup;
-  SExprSupp     tagCalSup;
-  int32_t       primaryTsIndex;  // primary time stamp slot id
-  SReadHandle   readHandle;
-  SInterval     interval;  // if the upstream is an interval operator, the interval info is also kept here.
-  SColMatchInfo matchInfo;
-
-  SArray*      pBlockLists;  // multiple SSDatablock.
-  SSDataBlock* pRes;         // result SSDataBlock
-  SSDataBlock* pUpdateRes;   // update SSDataBlock
-  int32_t      updateResIndex;
-  int32_t      blockType;        // current block type
-  int32_t      validBlockIndex;  // Is current data has returned?
-  uint64_t     numOfExec;        // execution times
-  STqReader*   tqReader;
-
-  uint64_t     groupId;
-  SUpdateInfo* pUpdateInfo;
-
-  EStreamScanMode       scanMode;
-  SOperatorInfo*        pStreamScanOp;
-  SOperatorInfo*        pTableScanOp;
-  SArray*               childIds;
-  SWindowSupporter      windowSup;
-  SPartitionBySupporter partitionSup;
-  SExprSupp*            pPartScalarSup;
-  bool                  assignBlockUid;  // assign block uid to groupId, temporarily used for generating rollup SMA.
-  int32_t               scanWinIndex;    // for state operator
-  int32_t               pullDataResIndex;
-  SSDataBlock*          pPullDataRes;    // pull data SSDataBlock
-  SSDataBlock*          pDeleteDataRes;  // delete data SSDataBlock
-  int32_t               deleteDataIndex;
-  STimeWindow           updateWin;
-  STimeWindowAggSupp    twAggSup;
-  SSDataBlock*          pUpdateDataRes;
-  // status for tmq
-  SNodeList* pGroupTags;
-  SNode*     pTagCond;
-  SNode*     pTagIndexCond;
-
-  // recover
-  int32_t      blockRecoverContiCnt;
-  int32_t      blockRecoverTotCnt;
-  SSDataBlock* pRecoverRes;
-
-  SSDataBlock* pCreateTbRes;
-  int8_t       igCheckUpdate;
-  int8_t       igExpired;
-} SStreamScanInfo;
-
-typedef struct {
-  SVnode*         vnode;
-  SSDataBlock     pRes;  // result SSDataBlock
-  STsdbReader*    dataReader;
-  SSnapContext*   sContext;
-  STableListInfo* pTableListInfo;
-} SStreamRawScanInfo;
-
-typedef struct STableCountScanSupp {
-  int16_t dbNameSlotId;
-  int16_t stbNameSlotId;
-  int16_t tbCountSlotId;
-  bool    groupByDbName;
-  bool    groupByStbName;
-  char    dbNameFilter[TSDB_DB_NAME_LEN];
-  char    stbNameFilter[TSDB_TABLE_NAME_LEN];
-} STableCountScanSupp;
-
-typedef struct SOptrBasicInfo {
-  SResultRowInfo resultRowInfo;
-  SSDataBlock*   pRes;
-  bool           mergeResultBlock;
-} SOptrBasicInfo;
-
-typedef struct SIntervalAggOperatorInfo {
-  SOptrBasicInfo     binfo;              // basic info
-  SAggSupporter      aggSup;             // aggregate supporter
-  SExprSupp          scalarSupp;         // supporter for perform scalar function
-  SGroupResInfo      groupResInfo;       // multiple results build supporter
-  SInterval          interval;           // interval info
-  int32_t            primaryTsIndex;     // primary time stamp slot id from result of downstream operator.
-  STimeWindow        win;                // query time range
-  bool               timeWindowInterpo;  // interpolation needed or not
-  SArray*            pInterpCols;        // interpolation columns
-  int32_t            resultTsOrder;      // result timestamp order
-  int32_t            inputOrder;         // input data ts order
-  EOPTR_EXEC_MODEL   execModel;          // operator execution model [batch model|stream model]
-  STimeWindowAggSupp twAggSup;
-  SArray*            pPrevValues;  //  SArray used to keep the previous not null value for interpolation.
-} SIntervalAggOperatorInfo;
-
-typedef struct SMergeAlignedIntervalAggOperatorInfo {
-  SIntervalAggOperatorInfo* intervalAggOperatorInfo;
-
-  uint64_t     groupId;  // current groupId
-  int64_t      curTs;    // current ts
-  SSDataBlock* prefetchedBlock;
-  SResultRow*  pResultRow;
-} SMergeAlignedIntervalAggOperatorInfo;
-
-typedef struct SStreamIntervalOperatorInfo {
-  SOptrBasicInfo     binfo;           // basic info
-  SAggSupporter      aggSup;          // aggregate supporter
-  SExprSupp          scalarSupp;      // supporter for perform scalar function
-  SGroupResInfo      groupResInfo;    // multiple results build supporter
-  SInterval          interval;        // interval info
-  int32_t            primaryTsIndex;  // primary time stamp slot id from result of downstream operator.
-  STimeWindowAggSupp twAggSup;
-  bool               invertible;
-  bool               ignoreExpiredData;
-  bool               ignoreExpiredDataSaved;
-  SArray*            pDelWins;  // SWinRes
-  int32_t            delIndex;
-  SSDataBlock*       pDelRes;
-  SPhysiNode*        pPhyNode;  // create new child
-  SHashObj*          pPullDataMap;
-  SArray*            pPullWins;  // SPullWindowInfo
-  int32_t            pullIndex;
-  SSDataBlock*       pPullDataRes;
-  bool               isFinal;
-  SArray*            pChildren;
-  SStreamState*      pState;
-  SWinKey            delKey;
-  uint64_t           numOfDatapack;
-  SArray*            pUpdated;
-  SSHashObj*         pUpdatedMap;
-  int64_t            dataVersion;
-} SStreamIntervalOperatorInfo;
-
-typedef struct SDataGroupInfo {
-  uint64_t groupId;
-  int64_t  numOfRows;
-  SArray*  pPageList;
-} SDataGroupInfo;
-
-typedef struct SWindowRowsSup {
-  STimeWindow win;
-  TSKEY       prevTs;
-  int32_t     startRowIndex;
-  int32_t     numOfRows;
-  uint64_t    groupId;
-} SWindowRowsSup;
-
-typedef struct SResultWindowInfo {
-  void*       pOutputBuf;
-  SSessionKey sessionWin;
-  bool        isOutput;
-} SResultWindowInfo;
-
-typedef struct SStateWindowInfo {
-  SResultWindowInfo winInfo;
-  SStateKeys*       pStateKey;
-} SStateWindowInfo;
-
-typedef struct SStreamSessionAggOperatorInfo {
-  SOptrBasicInfo      binfo;
-  SStreamAggSupporter streamAggSup;
-  SExprSupp           scalarSupp;  // supporter for perform scalar function
-  SGroupResInfo       groupResInfo;
-  int32_t             primaryTsIndex;  // primary timestamp slot id
-  int32_t             endTsIndex;      // window end timestamp slot id
-  int32_t             order;           // current SSDataBlock scan order
-  STimeWindowAggSupp  twAggSup;
-  SSDataBlock*        pWinBlock;   // window result
-  SSDataBlock*        pDelRes;     // delete result
-  SSDataBlock*        pUpdateRes;  // update window
-  bool                returnUpdate;
-  SSHashObj*          pStDeleted;
-  void*               pDelIterator;
-  SArray*             pChildren;  // cache for children's result; final stream operator
-  SPhysiNode*         pPhyNode;   // create new child
-  bool                isFinal;
-  bool                ignoreExpiredData;
-  bool                ignoreExpiredDataSaved;
-  SArray*             pUpdated;
-  SSHashObj*          pStUpdated;
-  int64_t             dataVersion;
-} SStreamSessionAggOperatorInfo;
-
-typedef struct SStreamStateAggOperatorInfo {
-  SOptrBasicInfo      binfo;
-  SStreamAggSupporter streamAggSup;
-  SExprSupp           scalarSupp;  // supporter for perform scalar function
-  SGroupResInfo       groupResInfo;
-  int32_t             primaryTsIndex;  // primary timestamp slot id
-  STimeWindowAggSupp  twAggSup;
-  SColumn             stateCol;
-  SSDataBlock*        pDelRes;
-  SSHashObj*          pSeDeleted;
-  void*               pDelIterator;
-  SArray*             pChildren;  // cache for children's result;
-  bool                ignoreExpiredData;
-  bool                ignoreExpiredDataSaved;
-  SArray*             pUpdated;
-  SSHashObj*          pSeUpdated;
-  int64_t             dataVersion;
-} SStreamStateAggOperatorInfo;
-
-typedef struct SStreamPartitionOperatorInfo {
-  SOptrBasicInfo        binfo;
-  SPartitionBySupporter partitionSup;
-  SExprSupp             scalarSup;
-  SExprSupp             tbnameCalSup;
-  SExprSupp             tagCalSup;
-  SHashObj*             pPartitions;
-  void*                 parIte;
-  void*                 pTbNameIte;
-  SSDataBlock*          pInputDataBlock;
-  int32_t               tsColIndex;
-  SSDataBlock*          pDelRes;
-  SSDataBlock*          pCreateTbRes;
-} SStreamPartitionOperatorInfo;
-
-typedef struct SStreamFillSupporter {
-  int32_t        type;  // fill type
-  SInterval      interval;
-  SResultRowData prev;
-  SResultRowData cur;
-  SResultRowData next;
-  SResultRowData nextNext;
-  SFillColInfo*  pAllColInfo;  // fill exprs and not fill exprs
-  SExprSupp      notFillExprSup;
-  int32_t        numOfAllCols;  // number of all exprs, including the tags columns
-  int32_t        numOfFillCols;
-  int32_t        numOfNotFillCols;
-  int32_t        rowSize;
-  SSHashObj*     pResMap;
-  bool           hasDelete;
-} SStreamFillSupporter;
-
-typedef struct SStreamFillOperatorInfo {
-  SStreamFillSupporter* pFillSup;
-  SSDataBlock*          pRes;
-  SSDataBlock*          pSrcBlock;
-  int32_t               srcRowIndex;
-  SSDataBlock*          pSrcDelBlock;
-  int32_t               srcDelRowIndex;
-  SSDataBlock*          pDelRes;
-  SColMatchInfo         matchInfo;
-  int32_t               primaryTsCol;
-  int32_t               primarySrcSlotId;
-  SStreamFillInfo*      pFillInfo;
-} SStreamFillOperatorInfo;
-
-#define OPTR_IS_OPENED(_optr)  (((_optr)->status & OP_OPENED) == OP_OPENED)
-#define OPTR_SET_OPENED(_optr) ((_optr)->status |= OP_OPENED)
-
-SExecTaskInfo* doCreateExecTaskInfo(uint64_t queryId, uint64_t taskId, int32_t vgId, EOPTR_EXEC_MODEL model,
-                                    char* dbFName);
-
-SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t cleanup,
-                                   __optr_close_fn_t closeFn, __optr_reqBuf_fn_t reqBufFn, __optr_explain_fn_t explain);
-int32_t        optrDummyOpenFn(SOperatorInfo* pOperator);
-int32_t        appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t num);
-void           setOperatorCompleted(SOperatorInfo* pOperator);
-void           setOperatorInfo(SOperatorInfo* pOperator, const char* name, int32_t type, bool blocking, int32_t status,
-                               void* pInfo, SExecTaskInfo* pTaskInfo);
-void           destroyOperatorInfo(SOperatorInfo* pOperator);
-int32_t        optrDefaultBufFn(SOperatorInfo* pOperator);
-
-void initBasicInfo(SOptrBasicInfo* pInfo, SSDataBlock* pBlock);
-void cleanupBasicInfo(SOptrBasicInfo* pInfo);
-
-int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr);
-void    cleanupExprSupp(SExprSupp* pSup);
-
-void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs);
-
-int32_t initAggSup(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, size_t keyBufSize,
-                   const char* pkey, void* pState);
-void    cleanupAggSup(SAggSupporter* pAggSup);
-
-void initResultSizeInfo(SResultInfo* pResultInfo, int32_t numOfRows);
-
-void doBuildStreamResBlock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo,
-                           SDiskbasedBuf* pBuf);
-void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo,
-                            SDiskbasedBuf* pBuf);
-
-bool hasLimitOffsetInfo(SLimitInfo* pLimitInfo);
-bool hasSlimitOffsetInfo(SLimitInfo* pLimitInfo);
-void initLimitInfo(const SNode* pLimit, const SNode* pSLimit, SLimitInfo* pLimitInfo);
-void resetLimitInfoForNextGroup(SLimitInfo* pLimitInfo);
-bool applyLimitOffset(SLimitInfo* pLimitInfo, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
-
-void applyAggFunctionOnPartialTuples(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, SColumnInfoData* pTimeWindowData,
-                                     int32_t offset, int32_t forwardStep, int32_t numOfTotal, int32_t numOfOutput);
-
-int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, char* pData, SArray* pColList, char** pNextStart);
-void    updateLoadRemoteInfo(SLoadRemoteDataInfo* pInfo, int64_t numOfRows, int32_t dataLen, int64_t startTs,
-                             SOperatorInfo* pOperator);
-
-STimeWindow getFirstQualifiedTimeWindow(int64_t ts, STimeWindow* pWindow, SInterval* pInterval, int32_t order);
-
-SOperatorInfo* extractOperatorInTree(SOperatorInfo* pOperator, int32_t type, const char* id);
-int32_t        getTableScanInfo(SOperatorInfo* pOperator, int32_t* order, int32_t* scanFlag, bool inheritUsOrder);
-int32_t        getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaultBufsz);
-
-extern void doDestroyExchangeOperatorInfo(void* param);
-
-void    doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo);
-int32_t addTagPseudoColumnData(SReadHandle* pHandle, const SExprInfo* pExpr, int32_t numOfExpr, SSDataBlock* pBlock,
-                               int32_t rows, const char* idStr, STableMetaCacheInfo* pCache);
-
-void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle);
-void setTbNameColData(const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId, const char* name);
-
-void setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowEntryInfoOffset);
-void clearResultRowInitFlag(SqlFunctionCtx* pCtx, int32_t numOfOutput);
-
-SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pResultRowInfo, char* pData,
-                                   int16_t bytes, bool masterscan, uint64_t groupId, SExecTaskInfo* pTaskInfo,
-                                   bool isIntervalQuery, SAggSupporter* pSup, bool keepGroup);
-// operator creater functions
-// clang-format off
-SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode* pExNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, STableListInfo* pTableList, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* readHandle, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysiNode* pPhyNode, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNode* pScanPhyNode, const char* pUser, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createTableCountScanOperatorInfo(SReadHandle* handle, STableCountScanPhysiNode* pNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhysiNode* pProjPhyNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode* pSortNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** dowStreams, size_t numStreams, SMergePhysiNode* pMergePhysiNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pTableScanNode, SReadHandle* readHandle, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SIntervalPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createMergeIntervalOperatorInfo(SOperatorInfo* downstream, SMergeIntervalPhysiNode* pIntervalPhyNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream, SMergeAlignedIntervalPhysiNode* pNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, int32_t numOfChild);
-
-SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SSessionWinodwPhysiNode* pSessionNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pAggNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createDataBlockInfoScanOperator(SReadHandle* readHandle, SBlockDistScanPhysiNode* pBlockScanNode, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhysiNode* pTableScanNode, SNode* pTagCond, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createRawScanOperatorInfo(SReadHandle* pHandle, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pPhyFillNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SStateWinodwPhysiNode* pStateNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartitionPhysiNode* pPartNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createStreamPartitionOperatorInfo(SOperatorInfo* downstream, SStreamPartitionPhysiNode* pPartNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfDownstream, SSortMergeJoinPhysiNode* pJoinNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createStreamFinalSessionAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, int32_t numOfChild);
-
-SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createStreamFillOperatorInfo(SOperatorInfo* downstream, SStreamFillPhysiNode* pPhyFillNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSortPhysiNode* pSortPhyNode, SExecTaskInfo* pTaskInfo);
-
-SOperatorInfo* createEventwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* physiNode, SExecTaskInfo* pTaskInfo);
-// clang-format on
-
-int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx,
-                              int32_t numOfOutput, SArray* pPseudoList);
-
-void setInputDataBlock(SExprSupp* pExprSupp, SSDataBlock* pBlock, int32_t order, int32_t scanFlag, bool createDummyCol);
-
-int32_t checkForQueryBuf(size_t numOfTables);
-
-bool isTaskKilled(SExecTaskInfo* pTaskInfo);
-void setTaskKilled(SExecTaskInfo* pTaskInfo, int32_t rspCode);
-void doDestroyTask(SExecTaskInfo* pTaskInfo);
-void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status);
-
-void buildTaskId(uint64_t taskId, uint64_t queryId, char* dst);
-
-SArray* getTableListInfo(const SExecTaskInfo* pTaskInfo);
-
-int32_t createExecTaskInfo(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId,
-                           int32_t vgId, char* sql, EOPTR_EXEC_MODEL model);
-int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pTask, SReadHandle* readHandle);
-int32_t getOperatorExplainExecInfo(SOperatorInfo* operatorInfo, SArray* pExecInfoList);
-
-STimeWindow getActiveTimeWindow(SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int64_t ts, SInterval* pInterval,
-                                int32_t order);
-int32_t getNumOfRowsInTimeWindow(SDataBlockInfo* pDataBlockInfo, TSKEY* pPrimaryColumn, int32_t startPos, TSKEY ekey,
-                                 __block_search_fn_t searchFn, STableQueryInfo* item, int32_t order);
-int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order);
-SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int32_t* currentPageId, int32_t interBufSize);
-void getCurSessionWindow(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endTs, uint64_t groupId, SSessionKey* pKey);
-bool isInTimeWindow(STimeWindow* pWin, TSKEY ts, int64_t gap);
-bool functionNeedToExecute(SqlFunctionCtx* pCtx);
-bool isOverdue(TSKEY ts, STimeWindowAggSupp* pSup);
-bool isCloseWindow(STimeWindow* pWin, STimeWindowAggSupp* pSup);
-bool isDeletedStreamWindow(STimeWindow* pWin, uint64_t groupId, SStreamState* pState, STimeWindowAggSupp* pTwSup);
-void appendOneRowToStreamSpecialBlock(SSDataBlock* pBlock, TSKEY* pStartTs, TSKEY* pEndTs, uint64_t* pUid,
-                                      uint64_t* pGp, void* pTbName);
-uint64_t calGroupIdByData(SPartitionBySupporter* pParSup, SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t rowId);
-
-int32_t finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPosition, SExprSupp* pSup,
-                           SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
-
-bool    groupbyTbname(SNodeList* pGroupList);
-int32_t buildDataBlockFromGroupRes(SOperatorInfo* pOperator, SStreamState* pState, SSDataBlock* pBlock, SExprSupp* pSup,
-                                   SGroupResInfo* pGroupResInfo);
-int32_t saveSessionDiscBuf(SStreamState* pState, SSessionKey* key, void* buf, int32_t size);
-int32_t buildSessionResultDataBlock(SOperatorInfo* pOperator, SStreamState* pState, SSDataBlock* pBlock,
-                                    SExprSupp* pSup, SGroupResInfo* pGroupResInfo);
-int32_t setOutputBuf(SStreamState* pState, STimeWindow* win, SResultRow** pResult, int64_t tableGroupId,
-                     SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowEntryInfoOffset, SAggSupporter* pAggSup);
-int32_t releaseOutputBuf(SStreamState* pState, SWinKey* pKey, SResultRow* pResult);
-int32_t saveOutputBuf(SStreamState* pState, SWinKey* pKey, SResultRow* pResult, int32_t resSize);
-void    getNextIntervalWindow(SInterval* pInterval, STimeWindow* tw, int32_t order);
-int32_t qAppendTaskStopInfo(SExecTaskInfo* pTaskInfo, SExchangeOpStopInfo* pInfo);
-int32_t getForwardStepsInBlock(int32_t numOfRows, __block_search_fn_t searchFn, TSKEY ekey, int32_t pos, int32_t order,
-                               int64_t* pData);
-void    appendCreateTableRow(SStreamState* pState, SExprSupp* pTableSup, SExprSupp* pTagSup, uint64_t groupId,
-                             SSDataBlock* pSrcBlock, int32_t rowId, SSDataBlock* pDestBlock);
-
-SSDataBlock* buildCreateTableBlock(SExprSupp* tbName, SExprSupp* tag);
-SExprInfo*   createExpr(SNodeList* pNodeList, int32_t* numOfExprs);
-
-void copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx,
-                              SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo);
-void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset);
-void doClearBufferedBlocks(SStreamScanInfo* pInfo);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif  // TDENGINE_EXECUTORIMPL_H
diff --git a/source/libs/executor/inc/operator.h b/source/libs/executor/inc/operator.h
new file mode 100644
index 0000000000..632b817a07
--- /dev/null
+++ b/source/libs/executor/inc/operator.h
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc. 
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef TDENGINE_OPERATOR_H
+#define TDENGINE_OPERATOR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct SOperatorCostInfo {
+  double openCost;
+  double totalCost;
+} SOperatorCostInfo;
+
+struct SOperatorInfo;
+
+typedef int32_t (*__optr_encode_fn_t)(struct SOperatorInfo* pOperator, char** result, int32_t* length);
+typedef int32_t (*__optr_decode_fn_t)(struct SOperatorInfo* pOperator, char* result);
+
+typedef int32_t (*__optr_open_fn_t)(struct SOperatorInfo* pOptr);
+typedef SSDataBlock* (*__optr_fn_t)(struct SOperatorInfo* pOptr);
+typedef void (*__optr_close_fn_t)(void* param);
+typedef int32_t (*__optr_explain_fn_t)(struct SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len);
+typedef int32_t (*__optr_reqBuf_fn_t)(struct SOperatorInfo* pOptr);
+
+typedef struct SOperatorFpSet {
+  __optr_open_fn_t    _openFn;  // DO NOT invoke this function directly
+  __optr_fn_t         getNextFn;
+  __optr_fn_t         cleanupFn;  // call this function to release the allocated resources ASAP
+  __optr_close_fn_t   closeFn;
+  __optr_reqBuf_fn_t  reqBufFn;  // total used buffer for blocking operator
+  __optr_encode_fn_t  encodeResultRow;
+  __optr_decode_fn_t  decodeResultRow;
+  __optr_explain_fn_t getExplainFn;
+} SOperatorFpSet;
+
+enum {
+  OP_NOT_OPENED = 0x0,
+  OP_OPENED = 0x1,
+  OP_RES_TO_RETURN = 0x5,
+  OP_EXEC_DONE = 0x9,
+};
+
+typedef struct SOperatorInfo {
+  uint16_t               operatorType;
+  int16_t                resultDataBlockId;
+  bool                   blocking;  // block operator or not
+  uint8_t                status;    // denote if current operator is completed
+  char*                  name;      // name, for debug purpose
+  void*                  info;      // extension attribution
+  SExprSupp              exprSupp;
+  SExecTaskInfo*         pTaskInfo;
+  SOperatorCostInfo      cost;
+  SResultInfo            resultInfo;
+  struct SOperatorInfo** pDownstream;      // downstram pointer list
+  int32_t                numOfDownstream;  // number of downstream. The value is always ONE expect for join operator
+  SOperatorFpSet         fpSet;
+} SOperatorInfo;
+
+// operator creater functions
+// clang-format off
+SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode* pExNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle, STableListInfo* pTableList, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanNode, SReadHandle* readHandle, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysiNode* pPhyNode, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNode* pScanPhyNode, const char* pUser, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createTableCountScanOperatorInfo(SReadHandle* handle, STableCountScanPhysiNode* pNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhysiNode* pProjPhyNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode* pSortNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** dowStreams, size_t numStreams, SMergePhysiNode* pMergePhysiNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pTableScanNode, SReadHandle* readHandle, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SIntervalPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createMergeIntervalOperatorInfo(SOperatorInfo* downstream, SMergeIntervalPhysiNode* pIntervalPhyNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream, SMergeAlignedIntervalPhysiNode* pNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, int32_t numOfChild);
+
+SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SSessionWinodwPhysiNode* pSessionNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pAggNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createDataBlockInfoScanOperator(SReadHandle* readHandle, SBlockDistScanPhysiNode* pBlockScanNode, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhysiNode* pTableScanNode, SNode* pTagCond, STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createRawScanOperatorInfo(SReadHandle* pHandle, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pPhyFillNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SStateWinodwPhysiNode* pStateNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartitionPhysiNode* pPartNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createStreamPartitionOperatorInfo(SOperatorInfo* downstream, SStreamPartitionPhysiNode* pPartNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfDownstream, SSortMergeJoinPhysiNode* pJoinNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createStreamFinalSessionAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, int32_t numOfChild);
+
+SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createStreamFillOperatorInfo(SOperatorInfo* downstream, SStreamFillPhysiNode* pPhyFillNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSortPhysiNode* pSortPhyNode, SExecTaskInfo* pTaskInfo);
+
+SOperatorInfo* createEventwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* physiNode, SExecTaskInfo* pTaskInfo);
+// clang-format on
+
+SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t cleanup,
+                                   __optr_close_fn_t closeFn, __optr_reqBuf_fn_t reqBufFn, __optr_explain_fn_t explain);
+int32_t        optrDummyOpenFn(SOperatorInfo* pOperator);
+int32_t        appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t num);
+void           setOperatorCompleted(SOperatorInfo* pOperator);
+void           setOperatorInfo(SOperatorInfo* pOperator, const char* name, int32_t type, bool blocking, int32_t status,
+                               void* pInfo, SExecTaskInfo* pTaskInfo);
+int32_t        optrDefaultBufFn(SOperatorInfo* pOperator);
+
+SOperatorInfo* createOperator(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, SNode* pTagCond,
+                              SNode* pTagIndexCond, const char* pUser, const char* dbname);
+void           destroyOperator(SOperatorInfo* pOperator);
+
+SOperatorInfo* extractOperatorInTree(SOperatorInfo* pOperator, int32_t type, const char* id);
+int32_t        getTableScanInfo(SOperatorInfo* pOperator, int32_t* order, int32_t* scanFlag, bool inheritUsOrder);
+int32_t        stopTableScanOperator(SOperatorInfo* pOperator, const char* pIdStr);
+int32_t        getOperatorExplainExecInfo(struct SOperatorInfo* operatorInfo, SArray* pExecInfoList);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  // TDENGINE_OPERATOR_H
\ No newline at end of file
diff --git a/source/libs/executor/inc/querytask.h b/source/libs/executor/inc/querytask.h
new file mode 100644
index 0000000000..37c93fef5c
--- /dev/null
+++ b/source/libs/executor/inc/querytask.h
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc. 
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef TDENGINE_QUERYTASK_H
+#define TDENGINE_QUERYTASK_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define GET_TASKID(_t) (((SExecTaskInfo*)(_t))->id.str)
+
+enum {
+  // when this task starts to execute, this status will set
+      TASK_NOT_COMPLETED = 0x1u,
+
+  /* Task is over
+   * 1. this status is used in one row result query process, e.g., count/sum/first/last/ avg...etc.
+   * 2. when all data within queried time window, it is also denoted as query_completed
+   */
+      TASK_COMPLETED = 0x2u,
+};
+
+typedef struct STaskIdInfo {
+  uint64_t queryId;  // this is also a request id
+  uint64_t subplanId;
+  uint64_t templateId;
+  char*    str;
+  int32_t  vgId;
+} STaskIdInfo;
+
+typedef struct STaskCostInfo {
+  int64_t                 created;
+  int64_t                 start;
+  uint64_t                elapsedTime;
+  double                  extractListTime;
+  double                  groupIdMapTime;
+  SFileBlockLoadRecorder* pRecoder;
+} STaskCostInfo;
+
+typedef struct STaskStopInfo {
+  SRWLatch lock;
+  SArray*  pStopInfo;
+} STaskStopInfo;
+
+typedef struct {
+  STqOffsetVal        currentOffset;  // for tmq
+  SMqMetaRsp          metaRsp;        // for tmq fetching meta
+  int64_t             snapshotVer;
+//  SPackedData         submit;  // todo remove it
+  SSchemaWrapper*     schema;
+  char                tbName[TSDB_TABLE_NAME_LEN];   // this is the current scan table: todo refactor
+  int8_t              recoverStep;
+  int8_t              recoverScanFinished;
+  SQueryTableDataCond tableCond;
+  int64_t             fillHistoryVer1;
+  int64_t             fillHistoryVer2;
+  SStreamState*       pState;
+  int64_t             dataVersion;
+  int64_t             checkPointId;
+} SStreamTaskInfo;
+
+struct SExecTaskInfo {
+  STaskIdInfo           id;
+  uint32_t              status;
+  STimeWindow           window;
+  STaskCostInfo         cost;
+  int64_t               owner;  // if it is in execution
+  int32_t               code;
+  int32_t               qbufQuota;  // total available buffer (in KB) during execution query
+  int64_t               version;    // used for stream to record wal version, why not move to sschemainfo
+  SStreamTaskInfo       streamInfo;
+  SSchemaInfo           schemaInfo;
+  const char*           sql;        // query sql string
+  jmp_buf               env;        // jump to this position when error happens.
+  EOPTR_EXEC_MODEL      execModel;  // operator execution model [batch model|stream model]
+  SSubplan*             pSubplan;
+  struct SOperatorInfo* pRoot;
+  SLocalFetch           localFetch;
+  SArray*               pResultBlockList;  // result block list
+  STaskStopInfo         stopInfo;
+  SRWLatch              lock;  // secure the access of STableListInfo
+};
+
+void           buildTaskId(uint64_t taskId, uint64_t queryId, char* dst);
+SExecTaskInfo* doCreateTask(uint64_t queryId, uint64_t taskId, int32_t vgId, EOPTR_EXEC_MODEL model);
+void           doDestroyTask(SExecTaskInfo* pTaskInfo);
+bool           isTaskKilled(SExecTaskInfo* pTaskInfo);
+void           setTaskKilled(SExecTaskInfo* pTaskInfo, int32_t rspCode);
+void           setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status);
+int32_t        createExecTaskInfo(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId,
+                                  int32_t vgId, char* sql, EOPTR_EXEC_MODEL model);
+int32_t        qAppendTaskStopInfo(SExecTaskInfo* pTaskInfo, SExchangeOpStopInfo* pInfo);
+SArray*        getTableListInfo(const SExecTaskInfo* pTaskInfo);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  // TDENGINE_QUERYTASK_H
diff --git a/source/libs/executor/src/aggregateoperator.c b/source/libs/executor/src/aggregateoperator.c
index 1f170552db..5cd95d3311 100644
--- a/source/libs/executor/src/aggregateoperator.c
+++ b/source/libs/executor/src/aggregateoperator.c
@@ -15,24 +15,21 @@
 
 #include "filter.h"
 #include "function.h"
-#include "functionMgt.h"
 #include "os.h"
 #include "querynodes.h"
 #include "tfill.h"
 #include "tname.h"
 
+#include "executorInt.h"
+#include "index.h"
+#include "operator.h"
+#include "query.h"
+#include "querytask.h"
+#include "tcompare.h"
 #include "tdatablock.h"
 #include "tglobal.h"
-#include "tmsg.h"
-#include "ttime.h"
-
-#include "executorimpl.h"
-#include "index.h"
-#include "query.h"
-#include "tcompare.h"
 #include "thash.h"
 #include "ttypes.h"
-#include "vnode.h"
 
 typedef struct {
   bool    hasAgg;
diff --git a/source/libs/executor/src/cachescanoperator.c b/source/libs/executor/src/cachescanoperator.c
index 925e305450..430b0b11ed 100644
--- a/source/libs/executor/src/cachescanoperator.c
+++ b/source/libs/executor/src/cachescanoperator.c
@@ -20,7 +20,9 @@
 #include "tdatablock.h"
 #include "tmsg.h"
 
-#include "executorimpl.h"
+#include "executorInt.h"
+#include "operator.h"
+#include "querytask.h"
 #include "tcompare.h"
 #include "thash.h"
 #include "ttypes.h"
diff --git a/source/libs/executor/src/dataDeleter.c b/source/libs/executor/src/dataDeleter.c
index d693faf7f1..11074b0e94 100644
--- a/source/libs/executor/src/dataDeleter.c
+++ b/source/libs/executor/src/dataDeleter.c
@@ -15,7 +15,7 @@
 
 #include "dataSinkInt.h"
 #include "dataSinkMgt.h"
-#include "executorimpl.h"
+#include "executorInt.h"
 #include "planner.h"
 #include "tcompression.h"
 #include "tdatablock.h"
@@ -179,7 +179,7 @@ static void getDataLength(SDataSinkHandle* pHandle, int64_t* pLen, bool* pQueryE
 static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) {
   SDataDeleterHandle* pDeleter = (SDataDeleterHandle*)pHandle;
   if (NULL == pDeleter->nextOutput.pData) {
-    assert(pDeleter->queryEnd);
+    ASSERT(pDeleter->queryEnd);
     pOutput->useconds = pDeleter->useconds;
     pOutput->precision = pDeleter->pSchema->precision;
     pOutput->bufStatus = DS_BUF_EMPTY;
diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c
index d8efcf50ca..ce8dc898a5 100644
--- a/source/libs/executor/src/dataDispatcher.c
+++ b/source/libs/executor/src/dataDispatcher.c
@@ -15,7 +15,7 @@
 
 #include "dataSinkInt.h"
 #include "dataSinkMgt.h"
-#include "executorimpl.h"
+#include "executorInt.h"
 #include "planner.h"
 #include "tcompression.h"
 #include "tdatablock.h"
@@ -181,7 +181,7 @@ static void getDataLength(SDataSinkHandle* pHandle, int64_t* pLen, bool* pQueryE
 static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) {
   SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
   if (NULL == pDispatcher->nextOutput.pData) {
-    assert(pDispatcher->queryEnd);
+    ASSERT(pDispatcher->queryEnd);
     pOutput->useconds = pDispatcher->useconds;
     pOutput->precision = pDispatcher->pSchema->precision;
     pOutput->bufStatus = DS_BUF_EMPTY;
diff --git a/source/libs/executor/src/dataInserter.c b/source/libs/executor/src/dataInserter.c
index 90d740bebd..d31ac0bc51 100644
--- a/source/libs/executor/src/dataInserter.c
+++ b/source/libs/executor/src/dataInserter.c
@@ -15,7 +15,7 @@
 
 #include "dataSinkInt.h"
 #include "dataSinkMgt.h"
-#include "executorimpl.h"
+#include "executorInt.h"
 #include "planner.h"
 #include "tcompression.h"
 #include "tdatablock.h"
@@ -126,7 +126,7 @@ static int32_t submitReqToMsg(int32_t vgId, SSubmitReq2* pReq, void** pData, int
   int32_t code = TSDB_CODE_SUCCESS;
   int32_t len = 0;
   void*   pBuf = NULL;
-  tEncodeSize(tEncodeSSubmitReq2, pReq, len, code);
+  tEncodeSize(tEncodeSubmitReq, pReq, len, code);
   if (TSDB_CODE_SUCCESS == code) {
     SEncoder encoder;
     len += sizeof(SSubmitReq2Msg);
@@ -138,7 +138,7 @@ static int32_t submitReqToMsg(int32_t vgId, SSubmitReq2* pReq, void** pData, int
     ((SSubmitReq2Msg*)pBuf)->header.contLen = htonl(len);
     ((SSubmitReq2Msg*)pBuf)->version = htobe64(1);
     tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SSubmitReq2Msg)), len - sizeof(SSubmitReq2Msg));
-    code = tEncodeSSubmitReq2(&encoder, pReq);
+    code = tEncodeSubmitReq(&encoder, pReq);
     tEncoderClear(&encoder);
   }
 
@@ -281,7 +281,7 @@ int32_t buildSubmitReqFromBlock(SDataInserterHandle* pInserter, SSubmitReq2** pp
 
     SRow* pRow = NULL;
     if ((terrno = tRowBuild(pVals, pTSchema, &pRow)) < 0) {
-      tDestroySSubmitTbData(&tbData, TSDB_MSG_FLG_ENCODE);
+      tDestroySubmitTbData(&tbData, TSDB_MSG_FLG_ENCODE);
       goto _end;
     }
     taosArrayPush(tbData.aRowP, &pRow);
@@ -301,7 +301,7 @@ _end:
   if (terrno != 0) {
     *ppReq = NULL;
     if (pReq) {
-      tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
+      tDestroySubmitReq(pReq, TSDB_MSG_FLG_ENCODE);
       taosMemoryFree(pReq);
     }
     return terrno;
@@ -326,7 +326,7 @@ int32_t dataBlocksToSubmitReq(SDataInserterHandle* pInserter, void** pMsg, int32
     code = buildSubmitReqFromBlock(pInserter, &pReq, pDataBlock, pTSchema, uid, vgId, suid);
     if (code) {
       if (pReq) {
-        tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
+        tDestroySubmitReq(pReq, TSDB_MSG_FLG_ENCODE);
         taosMemoryFree(pReq);
       }
 
@@ -335,7 +335,7 @@ int32_t dataBlocksToSubmitReq(SDataInserterHandle* pInserter, void** pMsg, int32
   }
 
   code = submitReqToMsg(vgId, pReq, pMsg, msgLen);
-  tDestroySSubmitReq2(pReq, TSDB_MSG_FLG_ENCODE);
+  tDestroySubmitReq(pReq, TSDB_MSG_FLG_ENCODE);
   taosMemoryFree(pReq);
 
   return code;
diff --git a/source/libs/executor/src/eventwindowoperator.c b/source/libs/executor/src/eventwindowoperator.c
index 559fce5224..956d5b714d 100644
--- a/source/libs/executor/src/eventwindowoperator.c
+++ b/source/libs/executor/src/eventwindowoperator.c
@@ -13,10 +13,12 @@
  * along with this program. If not, see .
  */
 
-#include "executorimpl.h"
+#include "executorInt.h"
 #include "filter.h"
 #include "function.h"
 #include "functionMgt.h"
+#include "operator.h"
+#include "querytask.h"
 #include "tcommon.h"
 #include "tcompare.h"
 #include "tdatablock.h"
diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c
index c855a104b2..94041140d4 100644
--- a/source/libs/executor/src/exchangeoperator.c
+++ b/source/libs/executor/src/exchangeoperator.c
@@ -13,17 +13,19 @@
  * along with this program. If not, see .
  */
 
+#include "executorInt.h"
 #include "filter.h"
 #include "function.h"
+#include "index.h"
+#include "operator.h"
 #include "os.h"
+#include "query.h"
+#include "querytask.h"
+#include "tdatablock.h"
+#include "thash.h"
+#include "tmsg.h"
 #include "tname.h"
 #include "tref.h"
-#include "tdatablock.h"
-#include "tmsg.h"
-#include "executorimpl.h"
-#include "index.h"
-#include "query.h"
-#include "thash.h"
 
 typedef struct SFetchRspHandleWrapper {
   uint32_t exchangeId;
diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c
index f61fd1ae01..c8b16ad83b 100644
--- a/source/libs/executor/src/executil.c
+++ b/source/libs/executor/src/executil.c
@@ -24,7 +24,8 @@
 #include "ttime.h"
 
 #include "executil.h"
-#include "executorimpl.h"
+#include "executorInt.h"
+#include "querytask.h"
 #include "tcompression.h"
 
 typedef struct STableListIdInfo {
@@ -88,7 +89,6 @@ void resetResultRow(SResultRow* pResultRow, size_t entrySize) {
 
 // TODO refactor: use macro
 SResultRowEntryInfo* getResultEntryInfo(const SResultRow* pRow, int32_t index, const int32_t* offset) {
-  assert(index >= 0 && offset != NULL);
   return (SResultRowEntryInfo*)((char*)pRow->pEntryInfo + offset[index]);
 }
 
@@ -1484,14 +1484,23 @@ static int32_t setSelectValueColumnInfo(SqlFunctionCtx* pCtx, int32_t numOfOutpu
     return TSDB_CODE_OUT_OF_MEMORY;
   }
 
+  SHashObj *pSelectFuncs = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
   for (int32_t i = 0; i < numOfOutput; ++i) {
     const char* pName = pCtx[i].pExpr->pExpr->_function.functionName;
     if ((strcmp(pName, "_select_value") == 0) || (strcmp(pName, "_group_key") == 0)) {
       pValCtx[num++] = &pCtx[i];
     } else if (fmIsSelectFunc(pCtx[i].functionId)) {
-      p = &pCtx[i];
+      void* data = taosHashGet(pSelectFuncs, pName, strlen(pName));
+      if (taosHashGetSize(pSelectFuncs) != 0 && data == NULL) {
+        p = NULL;
+        break;
+      } else {
+        taosHashPut(pSelectFuncs, pName, strlen(pName), &num, sizeof(num));
+        p = &pCtx[i];
+      }
     }
   }
+  taosHashCleanup(pSelectFuncs);
 
   if (p != NULL) {
     p->subsidiaries.pCtx = pValCtx;
diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c
index 1732ec04a7..8bbbd3524d 100644
--- a/source/libs/executor/src/executor.c
+++ b/source/libs/executor/src/executor.c
@@ -14,9 +14,10 @@
  */
 
 #include "executor.h"
-#include 
-#include "executorimpl.h"
+#include "executorInt.h"
+#include "operator.h"
 #include "planner.h"
+#include "querytask.h"
 #include "tdatablock.h"
 #include "tref.h"
 #include "tudf.h"
@@ -138,7 +139,6 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu
       }
       pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
     } else if (type == STREAM_INPUT__DATA_SUBMIT) {
-      ASSERT(numOfBlocks == 1);
       taosArrayPush(pInfo->pBlockLists, input);
       pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
     } else if (type == STREAM_INPUT__DATA_BLOCK) {
@@ -249,7 +249,7 @@ int32_t qSetSMAInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks,
 qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* pReaderHandle, int32_t vgId, int32_t* numOfCols,
                                      uint64_t id) {
   if (msg == NULL) {  // create raw scan
-    SExecTaskInfo* pTaskInfo = doCreateExecTaskInfo(0, id, vgId, OPTR_EXEC_MODEL_QUEUE, "");
+    SExecTaskInfo* pTaskInfo = doCreateTask(0, id, vgId, OPTR_EXEC_MODEL_QUEUE);
     if (NULL == pTaskInfo) {
       terrno = TSDB_CODE_OUT_OF_MEMORY;
       return NULL;
@@ -312,7 +312,6 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, SReadHandle* readers, int32_t v
   qTaskInfo_t pTaskInfo = NULL;
   code = qCreateExecTask(readers, vgId, 0, pPlan, &pTaskInfo, NULL, NULL, OPTR_EXEC_MODEL_STREAM);
   if (code != TSDB_CODE_SUCCESS) {
-    nodesDestroyNode((SNode*)pPlan);
     qDestroyTask(pTaskInfo);
     terrno = code;
     return NULL;
@@ -717,8 +716,6 @@ void qRemoveTaskStopInfo(SExecTaskInfo* pTaskInfo, SExchangeOpStopInfo* pInfo) {
     taosArrayRemove(pTaskInfo->stopInfo.pStopInfo, idx);
   }
   taosWUnLockLatch(&pTaskInfo->stopInfo.lock);
-
-  return;
 }
 
 void qStopTaskOperators(SExecTaskInfo* pTaskInfo) {
@@ -802,7 +799,11 @@ void qDestroyTask(qTaskInfo_t qTaskHandle) {
     return;
   }
 
-  qDebug("%s execTask completed, numOfRows:%" PRId64, GET_TASKID(pTaskInfo), pTaskInfo->pRoot->resultInfo.totalRows);
+  if (pTaskInfo->pRoot != NULL) {
+    qDebug("%s execTask completed, numOfRows:%" PRId64, GET_TASKID(pTaskInfo), pTaskInfo->pRoot->resultInfo.totalRows);
+  } else {
+    qDebug("%s execTask completed", GET_TASKID(pTaskInfo));
+  }
 
   printTaskExecCostInLog(pTaskInfo);  // print the query cost summary
   doDestroyTask(pTaskInfo);
@@ -855,15 +856,6 @@ int32_t qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner) {
   }
 }
 
-#if 0
-int32_t qStreamInput(qTaskInfo_t tinfo, void* pItem) {
-  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
-  ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM);
-  taosWriteQitem(pTaskInfo->streamInfo.inputQueue->queue, pItem);
-  return 0;
-}
-#endif
-
 int32_t qStreamSourceRecoverStep1(qTaskInfo_t tinfo, int64_t ver) {
   SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
   ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM);
@@ -898,8 +890,7 @@ int32_t qStreamSetParamForRecover(qTaskInfo_t tinfo) {
       SStreamIntervalOperatorInfo* pInfo = pOperator->info;
       ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE ||
              pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE);
-      ASSERT(pInfo->twAggSup.calTriggerSaved == 0);
-      ASSERT(pInfo->twAggSup.deleteMarkSaved == 0);
+      ASSERT(pInfo->twAggSup.calTriggerSaved == 0 && pInfo->twAggSup.deleteMarkSaved == 0);
 
       qInfo("save stream param for interval: %d,  %" PRId64, pInfo->twAggSup.calTrigger, pInfo->twAggSup.deleteMark);
 
@@ -915,9 +906,8 @@ int32_t qStreamSetParamForRecover(qTaskInfo_t tinfo) {
       SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
       ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE ||
              pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE);
-      ASSERT(pInfo->twAggSup.calTriggerSaved == 0);
-      ASSERT(pInfo->twAggSup.deleteMarkSaved == 0);
 
+      ASSERT(pInfo->twAggSup.calTriggerSaved == 0 && pInfo->twAggSup.deleteMarkSaved == 0);
       qInfo("save stream param for session: %d,  %" PRId64, pInfo->twAggSup.calTrigger, pInfo->twAggSup.deleteMark);
 
       pInfo->twAggSup.calTriggerSaved = pInfo->twAggSup.calTrigger;
@@ -930,8 +920,7 @@ int32_t qStreamSetParamForRecover(qTaskInfo_t tinfo) {
       SStreamStateAggOperatorInfo* pInfo = pOperator->info;
       ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE ||
              pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE);
-      ASSERT(pInfo->twAggSup.calTriggerSaved == 0);
-      ASSERT(pInfo->twAggSup.deleteMarkSaved == 0);
+      ASSERT(pInfo->twAggSup.calTriggerSaved == 0 && pInfo->twAggSup.deleteMarkSaved == 0);
 
       qInfo("save stream param for state: %d,  %" PRId64, pInfo->twAggSup.calTrigger, pInfo->twAggSup.deleteMark);
 
@@ -992,7 +981,6 @@ int32_t qStreamRestoreParam(qTaskInfo_t tinfo) {
     if (pOperator->numOfDownstream != 1 || pOperator->pDownstream[0] == NULL) {
       if (pOperator->numOfDownstream > 1) {
         qError("unexpected stream, multiple downstream");
-        /*ASSERT(0);*/
         return -1;
       }
       return 0;
@@ -1064,25 +1052,20 @@ int32_t initQueryTableDataCondForTmq(SQueryTableDataCond* pCond, SSnapContext* s
   return TSDB_CODE_SUCCESS;
 }
 
-int32_t qStreamSetScanMemData(qTaskInfo_t tinfo, SPackedData submit) {
-  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
-  if ((pTaskInfo->execModel != OPTR_EXEC_MODEL_QUEUE) || (pTaskInfo->streamInfo.submit.msgStr != NULL)) {
-    qError("qStreamSetScanMemData err:%d,%p", pTaskInfo->execModel, pTaskInfo->streamInfo.submit.msgStr);
-    terrno = TSDB_CODE_PAR_INTERNAL_ERROR;
-    return -1;
-  }
-  qDebug("set the submit block for future scan");
-
-  pTaskInfo->streamInfo.submit = submit;
-  return 0;
-}
-
 void qStreamSetOpen(qTaskInfo_t tinfo) {
   SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
   SOperatorInfo* pOperator = pTaskInfo->pRoot;
   pOperator->status = OP_NOT_OPENED;
 }
 
+void verifyOffset(void *pWalReader, STqOffsetVal* pOffset){
+  // if offset version is small than first version , let's seek to first version
+  int64_t firstVer = walGetFirstVer(((SWalReader*)pWalReader)->pWal);
+  if (pOffset->version + 1 < firstVer){
+    pOffset->version = firstVer - 1;
+  }
+}
+
 int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subType) {
   SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
   SOperatorInfo* pOperator = pTaskInfo->pRoot;
@@ -1098,16 +1081,18 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
     if (pOperator == NULL) {
       return -1;
     }
+
     SStreamScanInfo* pInfo = pOperator->info;
     STableScanInfo*  pScanInfo = pInfo->pTableScanOp->info;
     STableScanBase*  pScanBaseInfo = &pScanInfo->base;
     STableListInfo*  pTableListInfo = pScanBaseInfo->pTableListInfo;
 
     if (pOffset->type == TMQ_OFFSET__LOG) {
+      // todo refactor: move away
       tsdbReaderClose(pScanBaseInfo->dataReader);
       pScanBaseInfo->dataReader = NULL;
 
-      // let's seek to the next version in wal file
+      verifyOffset(pInfo->tqReader->pWalReader, pOffset);
       if (tqSeekVer(pInfo->tqReader, pOffset->version + 1, id) < 0) {
         qError("tqSeekVer failed ver:%" PRId64 ", %s", pOffset->version + 1, id);
         return -1;
@@ -1228,7 +1213,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
 
       cleanupQueryTableDataCond(&pTaskInfo->streamInfo.tableCond);
       strcpy(pTaskInfo->streamInfo.tbName, mtInfo.tbName);
-      tDeleteSSchemaWrapper(pTaskInfo->streamInfo.schema);
+      tDeleteSchemaWrapper(pTaskInfo->streamInfo.schema);
       pTaskInfo->streamInfo.schema = mtInfo.schema;
 
       qDebug("tmqsnap qStreamPrepareScan snapshot data uid:%" PRId64 " ts %" PRId64 " %s", mtInfo.uid, pOffset->ts, id);
@@ -1298,3 +1283,25 @@ SArray* qGetQueriedTableListInfo(qTaskInfo_t tinfo) {
   taosArrayDestroy(plist);
   return pUidList;
 }
+
+static void extractTableList(SArray* pList, const SOperatorInfo* pOperator) {
+  if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
+    SStreamScanInfo* pScanInfo = pOperator->info;
+    STableScanInfo*  pTableScanInfo = pScanInfo->pTableScanOp->info;
+    taosArrayPush(pList, &pTableScanInfo->base.pTableListInfo);
+  } else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
+    STableScanInfo* pScanInfo = pOperator->info;
+    taosArrayPush(pList, &pScanInfo->base.pTableListInfo);
+  } else {
+    if (pOperator->pDownstream != NULL && pOperator->pDownstream[0] != NULL) {
+      extractTableList(pList, pOperator->pDownstream[0]);
+    }
+  }
+}
+
+SArray* getTableListInfo(const SExecTaskInfo* pTaskInfo) {
+  SArray*        pArray = taosArrayInit(0, POINTER_BYTES);
+  SOperatorInfo* pOperator = pTaskInfo->pRoot;
+  extractTableList(pArray, pOperator);
+  return pArray;
+}
\ No newline at end of file
diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorInt.c
similarity index 60%
rename from source/libs/executor/src/executorimpl.c
rename to source/libs/executor/src/executorInt.c
index 7594079cfb..62ab2d9df2 100644
--- a/source/libs/executor/src/executorimpl.c
+++ b/source/libs/executor/src/executorInt.c
@@ -22,13 +22,14 @@
 #include "tname.h"
 
 #include "tdatablock.h"
-#include "tglobal.h"
 #include "tmsg.h"
 #include "ttime.h"
 
-#include "executorimpl.h"
+#include "executorInt.h"
 #include "index.h"
+#include "operator.h"
 #include "query.h"
+#include "querytask.h"
 #include "tcompare.h"
 #include "thash.h"
 #include "ttypes.h"
@@ -71,12 +72,8 @@ static UNUSED_FUNC void* u_realloc(void* p, size_t __size) {
 #define realloc u_realloc
 #endif
 
-#define CLEAR_QUERY_STATUS(q, st) ((q)->status &= (~(st)))
-
 static void setBlockSMAInfo(SqlFunctionCtx* pCtx, SExprInfo* pExpr, SSDataBlock* pBlock);
 
-static void releaseQueryBuf(size_t numOfTables);
-
 static void initCtxOutputBuffer(SqlFunctionCtx* pCtx, int32_t size);
 static void doApplyScalarCalculation(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t order, int32_t scanFlag);
 
@@ -85,45 +82,7 @@ static void    extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SC
 static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int32_t order, int32_t scanFlag,
                                    bool createDummyCol);
 static int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
-                                  SGroupResInfo* pGroupResInfo);
-static SSchemaWrapper* extractQueriedColumnSchema(SScanPhysiNode* pScanNode);
-
-void setOperatorCompleted(SOperatorInfo* pOperator) {
-  pOperator->status = OP_EXEC_DONE;
-  pOperator->cost.totalCost = (taosGetTimestampUs() - pOperator->pTaskInfo->cost.start) / 1000.0;
-  setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED);
-}
-
-void setOperatorInfo(SOperatorInfo* pOperator, const char* name, int32_t type, bool blocking, int32_t status,
-                     void* pInfo, SExecTaskInfo* pTaskInfo) {
-  pOperator->name = (char*)name;
-  pOperator->operatorType = type;
-  pOperator->blocking = blocking;
-  pOperator->status = status;
-  pOperator->info = pInfo;
-  pOperator->pTaskInfo = pTaskInfo;
-}
-
-int32_t optrDummyOpenFn(SOperatorInfo* pOperator) {
-  OPTR_SET_OPENED(pOperator);
-  pOperator->cost.openCost = 0;
-  return TSDB_CODE_SUCCESS;
-}
-
-SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t cleanup,
-                                   __optr_close_fn_t closeFn, __optr_reqBuf_fn_t reqBufFn,
-                                   __optr_explain_fn_t explain) {
-  SOperatorFpSet fpSet = {
-      ._openFn = openFn,
-      .getNextFn = nextFn,
-      .cleanupFn = cleanup,
-      .closeFn = closeFn,
-      .reqBufFn = reqBufFn,
-      .getExplainFn = explain,
-  };
-
-  return fpSet;
-}
+                                  SGroupResInfo* pGroupResInfo, int32_t threshold);
 
 SResultRow* getNewResultRow(SDiskbasedBuf* pResultBuf, int32_t* currentPageId, int32_t interBufSize) {
   SFilePage* pData = NULL;
@@ -482,10 +441,6 @@ void setBlockSMAInfo(SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, SSDataBlock* pB
   }
 }
 
-bool isTaskKilled(SExecTaskInfo* pTaskInfo) { return (0 != pTaskInfo->code); }
-
-void setTaskKilled(SExecTaskInfo* pTaskInfo, int32_t rspCode) { pTaskInfo->code = rspCode; }
-
 /////////////////////////////////////////////////////////////////////////////////////////////
 STimeWindow getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key) {
   STimeWindow win = {0};
@@ -503,16 +458,6 @@ STimeWindow getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int
   return win;
 }
 
-void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status) {
-  if (status == TASK_NOT_COMPLETED) {
-    pTaskInfo->status = status;
-  } else {
-    // QUERY_NOT_COMPLETED is not compatible with any other status, so clear its position first
-    CLEAR_QUERY_STATUS(pTaskInfo, TASK_NOT_COMPLETED);
-    pTaskInfo->status |= status;
-  }
-}
-
 void setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowEntryInfoOffset) {
   bool init = false;
   for (int32_t i = 0; i < numOfOutput; ++i) {
@@ -831,7 +776,7 @@ int32_t finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPos
 }
 
 int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp* pSup, SDiskbasedBuf* pBuf,
-                           SGroupResInfo* pGroupResInfo) {
+                           SGroupResInfo* pGroupResInfo, int32_t threshold) {
   SExprInfo*      pExprInfo = pSup->pExprInfo;
   int32_t         numOfExprs = pSup->numOfExprs;
   int32_t*        rowEntryOffset = pSup->rowEntryInfoOffset;
@@ -880,6 +825,9 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprS
 
     releaseBufPage(pBuf, page);
     pBlock->info.rows += pRow->numOfRows;
+    if (pBlock->info.rows >= threshold) {
+      break;
+    }
   }
 
   qDebug("%s result generated, rows:%" PRId64 ", groupId:%" PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows,
@@ -905,7 +853,7 @@ void doBuildStreamResBlock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SGr
   // clear the existed group id
   pBlock->info.id.groupId = 0;
   ASSERT(!pbInfo->mergeResultBlock);
-  doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo);
+  doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold);
 
   void* tbname = NULL;
   if (streamStateGetParName(pTaskInfo->streamInfo.pState, pBlock->info.id.groupId, &tbname) < 0) {
@@ -932,10 +880,10 @@ void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SG
   // clear the existed group id
   pBlock->info.id.groupId = 0;
   if (!pbInfo->mergeResultBlock) {
-    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo);
+    doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold);
   } else {
     while (hasRemainResults(pGroupResInfo)) {
-      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo);
+      doCopyToSDataBlock(pTaskInfo, pBlock, &pOperator->exprSupp, pBuf, pGroupResInfo, pOperator->resultInfo.threshold);
       if (pBlock->info.rows >= pOperator->resultInfo.threshold) {
         break;
       }
@@ -949,72 +897,6 @@ void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SG
   }
 }
 
-int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t num) {
-  p->pDownstream = taosMemoryCalloc(1, num * POINTER_BYTES);
-  if (p->pDownstream == NULL) {
-    return TSDB_CODE_OUT_OF_MEMORY;
-  }
-
-  memcpy(p->pDownstream, pDownstream, num * POINTER_BYTES);
-  p->numOfDownstream = num;
-  return TSDB_CODE_SUCCESS;
-}
-
-int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t* order, int32_t* scanFlag, bool inheritUsOrder) {
-  // todo add more information about exchange operation
-  int32_t type = pOperator->operatorType;
-  if (type == QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN ||
-      type == QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN ||
-      type == QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN) {
-    *order = TSDB_ORDER_ASC;
-    *scanFlag = MAIN_SCAN;
-    return TSDB_CODE_SUCCESS;
-  } else if (type == QUERY_NODE_PHYSICAL_PLAN_EXCHANGE) {
-    if (!inheritUsOrder) {
-      *order = TSDB_ORDER_ASC;
-    }
-    *scanFlag = MAIN_SCAN;
-    return TSDB_CODE_SUCCESS;
-  } else if (type == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
-    STableScanInfo* pTableScanInfo = pOperator->info;
-    *order = pTableScanInfo->base.cond.order;
-    *scanFlag = pTableScanInfo->base.scanFlag;
-    return TSDB_CODE_SUCCESS;
-  } else if (type == QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN) {
-    STableMergeScanInfo* pTableScanInfo = pOperator->info;
-    *order = pTableScanInfo->base.cond.order;
-    *scanFlag = pTableScanInfo->base.scanFlag;
-    return TSDB_CODE_SUCCESS;
-  } else {
-    if (pOperator->pDownstream == NULL || pOperator->pDownstream[0] == NULL) {
-      return TSDB_CODE_INVALID_PARA;
-    } else {
-      return getTableScanInfo(pOperator->pDownstream[0], order, scanFlag, inheritUsOrder);
-    }
-  }
-}
-
-// QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN
-SOperatorInfo* extractOperatorInTree(SOperatorInfo* pOperator, int32_t type, const char* id) {
-  if (pOperator == NULL) {
-    qError("invalid operator, failed to find tableScanOperator %s", id);
-    terrno = TSDB_CODE_PAR_INTERNAL_ERROR;
-    return NULL;
-  }
-
-  if (pOperator->operatorType == type) {
-    return pOperator;
-  } else {
-    if (pOperator->pDownstream == NULL || pOperator->pDownstream[0] == NULL) {
-      qError("invalid operator, failed to find tableScanOperator %s", id);
-      terrno = TSDB_CODE_PAR_INTERNAL_ERROR;
-      return NULL;
-    }
-
-    return extractOperatorInTree(pOperator->pDownstream[0], type, id);
-  }
-}
-
 void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
   for (int32_t i = 0; i < numOfExprs; ++i) {
     SExprInfo* pExprInfo = &pExpr[i];
@@ -1031,37 +913,6 @@ void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
   }
 }
 
-void destroyOperatorInfo(SOperatorInfo* pOperator) {
-  if (pOperator == NULL) {
-    return;
-  }
-
-  if (pOperator->fpSet.closeFn != NULL) {
-    pOperator->fpSet.closeFn(pOperator->info);
-  }
-
-  if (pOperator->pDownstream != NULL) {
-    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
-      destroyOperatorInfo(pOperator->pDownstream[i]);
-    }
-
-    taosMemoryFreeClear(pOperator->pDownstream);
-    pOperator->numOfDownstream = 0;
-  }
-
-  cleanupExprSupp(&pOperator->exprSupp);
-  taosMemoryFreeClear(pOperator);
-}
-
-// each operator should be set their own function to return total cost buffer
-int32_t optrDefaultBufFn(SOperatorInfo* pOperator) {
-  if (pOperator->blocking) {
-    return -1;
-  } else {
-    return 0;
-  }
-}
-
 int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaultBufsz) {
   *defaultPgsz = 4096;
   while (*defaultPgsz < rowSize * 4) {
@@ -1151,136 +1002,6 @@ void cleanupExprSupp(SExprSupp* pSupp) {
 
 void cleanupBasicInfo(SOptrBasicInfo* pInfo) { pInfo->pRes = blockDataDestroy(pInfo->pRes); }
 
-void buildTaskId(uint64_t taskId, uint64_t queryId, char* dst) {
-  char* p = dst;
-
-  int32_t offset = 6;
-  memcpy(p, "TID:0x", offset);
-  offset += tintToHex(taskId, &p[offset]);
-
-  memcpy(&p[offset], " QID:0x", 7);
-  offset += 7;
-  offset += tintToHex(queryId, &p[offset]);
-
-  p[offset] = 0;
-}
-
-SExecTaskInfo* doCreateExecTaskInfo(uint64_t queryId, uint64_t taskId, int32_t vgId, EOPTR_EXEC_MODEL model,
-                                    char* dbFName) {
-  SExecTaskInfo* pTaskInfo = taosMemoryCalloc(1, sizeof(SExecTaskInfo));
-  if (pTaskInfo == NULL) {
-    terrno = TSDB_CODE_OUT_OF_MEMORY;
-    return NULL;
-  }
-
-  setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED);
-  pTaskInfo->cost.created = taosGetTimestampUs();
-
-  pTaskInfo->schemaInfo.dbname = taosStrdup(dbFName);
-  pTaskInfo->execModel = model;
-  pTaskInfo->stopInfo.pStopInfo = taosArrayInit(4, sizeof(SExchangeOpStopInfo));
-  pTaskInfo->pResultBlockList = taosArrayInit(128, POINTER_BYTES);
-
-  taosInitRWLatch(&pTaskInfo->lock);
-  pTaskInfo->id.vgId = vgId;
-  pTaskInfo->id.queryId = queryId;
-
-  pTaskInfo->id.str = taosMemoryMalloc(64);
-  buildTaskId(taskId, queryId, pTaskInfo->id.str);
-  return pTaskInfo;
-}
-
-int32_t extractTableSchemaInfo(SReadHandle* pHandle, SScanPhysiNode* pScanNode, SExecTaskInfo* pTaskInfo) {
-  SMetaReader mr = {0};
-  if (pHandle == NULL) {
-    terrno = TSDB_CODE_INVALID_PARA;
-    return terrno;
-  }
-
-  metaReaderInit(&mr, pHandle->meta, 0);
-  int32_t code = metaGetTableEntryByUidCache(&mr, pScanNode->uid);
-  if (code != TSDB_CODE_SUCCESS) {
-    qError("failed to get the table meta, uid:0x%" PRIx64 ", suid:0x%" PRIx64 ", %s", pScanNode->uid, pScanNode->suid,
-           GET_TASKID(pTaskInfo));
-
-    metaReaderClear(&mr);
-    return terrno;
-  }
-
-  SSchemaInfo* pSchemaInfo = &pTaskInfo->schemaInfo;
-  pSchemaInfo->tablename = taosStrdup(mr.me.name);
-
-  if (mr.me.type == TSDB_SUPER_TABLE) {
-    pSchemaInfo->sw = tCloneSSchemaWrapper(&mr.me.stbEntry.schemaRow);
-    pSchemaInfo->tversion = mr.me.stbEntry.schemaTag.version;
-  } else if (mr.me.type == TSDB_CHILD_TABLE) {
-    tDecoderClear(&mr.coder);
-
-    tb_uid_t suid = mr.me.ctbEntry.suid;
-    code = metaGetTableEntryByUidCache(&mr, suid);
-    if (code != TSDB_CODE_SUCCESS) {
-      metaReaderClear(&mr);
-      return terrno;
-    }
-
-    pSchemaInfo->sw = tCloneSSchemaWrapper(&mr.me.stbEntry.schemaRow);
-    pSchemaInfo->tversion = mr.me.stbEntry.schemaTag.version;
-  } else {
-    pSchemaInfo->sw = tCloneSSchemaWrapper(&mr.me.ntbEntry.schemaRow);
-  }
-
-  metaReaderClear(&mr);
-
-  pSchemaInfo->qsw = extractQueriedColumnSchema(pScanNode);
-  return TSDB_CODE_SUCCESS;
-}
-
-SSchemaWrapper* extractQueriedColumnSchema(SScanPhysiNode* pScanNode) {
-  int32_t numOfCols = LIST_LENGTH(pScanNode->pScanCols);
-  int32_t numOfTags = LIST_LENGTH(pScanNode->pScanPseudoCols);
-
-  SSchemaWrapper* pqSw = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
-  pqSw->pSchema = taosMemoryCalloc(numOfCols + numOfTags, sizeof(SSchema));
-
-  for (int32_t i = 0; i < numOfCols; ++i) {
-    STargetNode* pNode = (STargetNode*)nodesListGetNode(pScanNode->pScanCols, i);
-    SColumnNode* pColNode = (SColumnNode*)pNode->pExpr;
-
-    SSchema* pSchema = &pqSw->pSchema[pqSw->nCols++];
-    pSchema->colId = pColNode->colId;
-    pSchema->type = pColNode->node.resType.type;
-    pSchema->bytes = pColNode->node.resType.bytes;
-    tstrncpy(pSchema->name, pColNode->colName, tListLen(pSchema->name));
-  }
-
-  // this the tags and pseudo function columns, we only keep the tag columns
-  for (int32_t i = 0; i < numOfTags; ++i) {
-    STargetNode* pNode = (STargetNode*)nodesListGetNode(pScanNode->pScanPseudoCols, i);
-
-    int32_t type = nodeType(pNode->pExpr);
-    if (type == QUERY_NODE_COLUMN) {
-      SColumnNode* pColNode = (SColumnNode*)pNode->pExpr;
-
-      SSchema* pSchema = &pqSw->pSchema[pqSw->nCols++];
-      pSchema->colId = pColNode->colId;
-      pSchema->type = pColNode->node.resType.type;
-      pSchema->bytes = pColNode->node.resType.bytes;
-      tstrncpy(pSchema->name, pColNode->colName, tListLen(pSchema->name));
-    }
-  }
-
-  return pqSw;
-}
-
-static void cleanupTableSchemaInfo(SSchemaInfo* pSchemaInfo) {
-  taosMemoryFreeClear(pSchemaInfo->dbname);
-  taosMemoryFreeClear(pSchemaInfo->tablename);
-  tDeleteSSchemaWrapper(pSchemaInfo->sw);
-  tDeleteSSchemaWrapper(pSchemaInfo->qsw);
-}
-
-static void cleanupStreamInfo(SStreamTaskInfo* pStreamInfo) { tDeleteSSchemaWrapper(pStreamInfo->schema); }
-
 bool groupbyTbname(SNodeList* pGroupList) {
   bool bytbname = false;
   if (LIST_LENGTH(pGroupList) == 1) {
@@ -1294,306 +1015,6 @@ bool groupbyTbname(SNodeList* pGroupList) {
   return bytbname;
 }
 
-SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, SNode* pTagCond,
-                                  SNode* pTagIndexCond, const char* pUser) {
-  int32_t     type = nodeType(pPhyNode);
-  const char* idstr = GET_TASKID(pTaskInfo);
-
-  if (pPhyNode->pChildren == NULL || LIST_LENGTH(pPhyNode->pChildren) == 0) {
-    SOperatorInfo* pOperator = NULL;
-    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == type) {
-      STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
-
-      // NOTE: this is an patch to fix the physical plan
-      // TODO remove it later
-      if (pTableScanNode->scan.node.pLimit != NULL) {
-        pTableScanNode->groupSort = true;
-      }
-
-      STableListInfo* pTableListInfo = tableListCreate();
-      int32_t         code =
-          createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort, pHandle,
-                                  pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo);
-      if (code) {
-        pTaskInfo->code = code;
-        tableListDestroy(pTableListInfo);
-        qError("failed to createScanTableListInfo, code:%s, %s", tstrerror(code), idstr);
-        return NULL;
-      }
-
-      code = extractTableSchemaInfo(pHandle, &pTableScanNode->scan, pTaskInfo);
-      if (code) {
-        pTaskInfo->code = terrno;
-        tableListDestroy(pTableListInfo);
-        return NULL;
-      }
-
-      pOperator = createTableScanOperatorInfo(pTableScanNode, pHandle, pTableListInfo, pTaskInfo);
-      if (NULL == pOperator) {
-        pTaskInfo->code = terrno;
-        return NULL;
-      }
-
-      STableScanInfo* pScanInfo = pOperator->info;
-      pTaskInfo->cost.pRecoder = &pScanInfo->base.readRecorder;
-    } else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == type) {
-      STableMergeScanPhysiNode* pTableScanNode = (STableMergeScanPhysiNode*)pPhyNode;
-      STableListInfo*           pTableListInfo = tableListCreate();
-
-      int32_t code = createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, true, pHandle,
-                                             pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo);
-      if (code) {
-        pTaskInfo->code = code;
-        tableListDestroy(pTableListInfo);
-        qError("failed to createScanTableListInfo, code: %s", tstrerror(code));
-        return NULL;
-      }
-
-      code = extractTableSchemaInfo(pHandle, &pTableScanNode->scan, pTaskInfo);
-      if (code) {
-        pTaskInfo->code = terrno;
-        tableListDestroy(pTableListInfo);
-        return NULL;
-      }
-
-      pOperator = createTableMergeScanOperatorInfo(pTableScanNode, pHandle, pTableListInfo, pTaskInfo);
-      if (NULL == pOperator) {
-        pTaskInfo->code = terrno;
-        tableListDestroy(pTableListInfo);
-        return NULL;
-      }
-
-      STableScanInfo* pScanInfo = pOperator->info;
-      pTaskInfo->cost.pRecoder = &pScanInfo->base.readRecorder;
-    } else if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == type) {
-      pOperator = createExchangeOperatorInfo(pHandle ? pHandle->pMsgCb->clientRpc : NULL, (SExchangePhysiNode*)pPhyNode,
-                                             pTaskInfo);
-    } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN == type) {
-      STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
-      STableListInfo*      pTableListInfo = tableListCreate();
-
-      if (pHandle->vnode) {
-        int32_t code =
-            createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort,
-                                    pHandle, pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo);
-        if (code) {
-          pTaskInfo->code = code;
-          tableListDestroy(pTableListInfo);
-          qError("failed to createScanTableListInfo, code: %s", tstrerror(code));
-          return NULL;
-        }
-      }
-
-      pTaskInfo->schemaInfo.qsw = extractQueriedColumnSchema(&pTableScanNode->scan);
-      pOperator = createStreamScanOperatorInfo(pHandle, pTableScanNode, pTagCond, pTableListInfo, pTaskInfo);
-    } else if (QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN == type) {
-      SSystemTableScanPhysiNode* pSysScanPhyNode = (SSystemTableScanPhysiNode*)pPhyNode;
-      pOperator = createSysTableScanOperatorInfo(pHandle, pSysScanPhyNode, pUser, pTaskInfo);
-    } else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN == type) {
-      STableCountScanPhysiNode* pTblCountScanNode = (STableCountScanPhysiNode*)pPhyNode;
-      pOperator = createTableCountScanOperatorInfo(pHandle, pTblCountScanNode, pTaskInfo);
-    } else if (QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN == type) {
-      STagScanPhysiNode* pScanPhyNode = (STagScanPhysiNode*)pPhyNode;
-      STableListInfo*    pTableListInfo = tableListCreate();
-      int32_t            code = createScanTableListInfo(pScanPhyNode, NULL, false, pHandle, pTableListInfo, pTagCond,
-                                                        pTagIndexCond, pTaskInfo);
-      if (code != TSDB_CODE_SUCCESS) {
-        pTaskInfo->code = code;
-        qError("failed to getTableList, code: %s", tstrerror(code));
-        return NULL;
-      }
-
-      pOperator = createTagScanOperatorInfo(pHandle, pScanPhyNode, pTableListInfo, pTaskInfo);
-    } else if (QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN == type) {
-      SBlockDistScanPhysiNode* pBlockNode = (SBlockDistScanPhysiNode*)pPhyNode;
-      STableListInfo*          pTableListInfo = tableListCreate();
-
-      if (pBlockNode->tableType == TSDB_SUPER_TABLE) {
-        SArray* pList = taosArrayInit(4, sizeof(STableKeyInfo));
-        int32_t code = vnodeGetAllTableList(pHandle->vnode, pBlockNode->uid, pList);
-        if (code != TSDB_CODE_SUCCESS) {
-          pTaskInfo->code = terrno;
-          return NULL;
-        }
-
-        size_t num = taosArrayGetSize(pList);
-        for (int32_t i = 0; i < num; ++i) {
-          STableKeyInfo* p = taosArrayGet(pList, i);
-          tableListAddTableInfo(pTableListInfo, p->uid, 0);
-        }
-
-        taosArrayDestroy(pList);
-      } else {  // Create group with only one table
-        tableListAddTableInfo(pTableListInfo, pBlockNode->uid, 0);
-      }
-
-      pOperator = createDataBlockInfoScanOperator(pHandle, pBlockNode, pTableListInfo, pTaskInfo);
-    } else if (QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN == type) {
-      SLastRowScanPhysiNode* pScanNode = (SLastRowScanPhysiNode*)pPhyNode;
-      STableListInfo*        pTableListInfo = tableListCreate();
-
-      int32_t code = createScanTableListInfo(&pScanNode->scan, pScanNode->pGroupTags, true, pHandle, pTableListInfo,
-                                             pTagCond, pTagIndexCond, pTaskInfo);
-      if (code != TSDB_CODE_SUCCESS) {
-        pTaskInfo->code = code;
-        return NULL;
-      }
-
-      code = extractTableSchemaInfo(pHandle, &pScanNode->scan, pTaskInfo);
-      if (code != TSDB_CODE_SUCCESS) {
-        pTaskInfo->code = code;
-        return NULL;
-      }
-
-      pOperator = createCacherowsScanOperator(pScanNode, pHandle, pTableListInfo, pTaskInfo);
-    } else if (QUERY_NODE_PHYSICAL_PLAN_PROJECT == type) {
-      pOperator = createProjectOperatorInfo(NULL, (SProjectPhysiNode*)pPhyNode, pTaskInfo);
-    } else {
-      terrno = TSDB_CODE_INVALID_PARA;
-      return NULL;
-    }
-
-    if (pOperator != NULL) {  // todo moved away
-      pOperator->resultDataBlockId = pPhyNode->pOutputDataBlockDesc->dataBlockId;
-    }
-
-    return pOperator;
-  }
-
-  size_t          size = LIST_LENGTH(pPhyNode->pChildren);
-  SOperatorInfo** ops = taosMemoryCalloc(size, POINTER_BYTES);
-  if (ops == NULL) {
-    return NULL;
-  }
-
-  for (int32_t i = 0; i < size; ++i) {
-    SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, i);
-    ops[i] = createOperatorTree(pChildNode, pTaskInfo, pHandle, pTagCond, pTagIndexCond, pUser);
-    if (ops[i] == NULL) {
-      taosMemoryFree(ops);
-      return NULL;
-    }
-  }
-
-  SOperatorInfo* pOptr = NULL;
-  if (QUERY_NODE_PHYSICAL_PLAN_PROJECT == type) {
-    pOptr = createProjectOperatorInfo(ops[0], (SProjectPhysiNode*)pPhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_HASH_AGG == type) {
-    SAggPhysiNode* pAggNode = (SAggPhysiNode*)pPhyNode;
-    if (pAggNode->pGroupKeys != NULL) {
-      pOptr = createGroupOperatorInfo(ops[0], pAggNode, pTaskInfo);
-    } else {
-      pOptr = createAggregateOperatorInfo(ops[0], pAggNode, pTaskInfo);
-    }
-  } else if (QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL == type) {
-    SIntervalPhysiNode* pIntervalPhyNode = (SIntervalPhysiNode*)pPhyNode;
-    pOptr = createIntervalOperatorInfo(ops[0], pIntervalPhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL == type) {
-    pOptr = createStreamIntervalOperatorInfo(ops[0], pPhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL == type) {
-    SMergeAlignedIntervalPhysiNode* pIntervalPhyNode = (SMergeAlignedIntervalPhysiNode*)pPhyNode;
-    pOptr = createMergeAlignedIntervalOperatorInfo(ops[0], pIntervalPhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL == type) {
-    SMergeIntervalPhysiNode* pIntervalPhyNode = (SMergeIntervalPhysiNode*)pPhyNode;
-    pOptr = createMergeIntervalOperatorInfo(ops[0], pIntervalPhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL == type) {
-    int32_t children = 0;
-    pOptr = createStreamFinalIntervalOperatorInfo(ops[0], pPhyNode, pTaskInfo, children);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL == type) {
-    int32_t children = pHandle->numOfVgroups;
-    pOptr = createStreamFinalIntervalOperatorInfo(ops[0], pPhyNode, pTaskInfo, children);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_SORT == type) {
-    pOptr = createSortOperatorInfo(ops[0], (SSortPhysiNode*)pPhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT == type) {
-    pOptr = createGroupSortOperatorInfo(ops[0], (SGroupSortPhysiNode*)pPhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE == type) {
-    SMergePhysiNode* pMergePhyNode = (SMergePhysiNode*)pPhyNode;
-    pOptr = createMultiwayMergeOperatorInfo(ops, size, pMergePhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION == type) {
-    SSessionWinodwPhysiNode* pSessionNode = (SSessionWinodwPhysiNode*)pPhyNode;
-    pOptr = createSessionAggOperatorInfo(ops[0], pSessionNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION == type) {
-    pOptr = createStreamSessionAggOperatorInfo(ops[0], pPhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION == type) {
-    int32_t children = 0;
-    pOptr = createStreamFinalSessionAggOperatorInfo(ops[0], pPhyNode, pTaskInfo, children);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION == type) {
-    int32_t children = pHandle->numOfVgroups;
-    pOptr = createStreamFinalSessionAggOperatorInfo(ops[0], pPhyNode, pTaskInfo, children);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_PARTITION == type) {
-    pOptr = createPartitionOperatorInfo(ops[0], (SPartitionPhysiNode*)pPhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION == type) {
-    pOptr = createStreamPartitionOperatorInfo(ops[0], (SStreamPartitionPhysiNode*)pPhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE == type) {
-    SStateWinodwPhysiNode* pStateNode = (SStateWinodwPhysiNode*)pPhyNode;
-    pOptr = createStatewindowOperatorInfo(ops[0], pStateNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE == type) {
-    pOptr = createStreamStateAggOperatorInfo(ops[0], pPhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN == type) {
-    pOptr = createMergeJoinOperatorInfo(ops, size, (SSortMergeJoinPhysiNode*)pPhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_FILL == type) {
-    pOptr = createFillOperatorInfo(ops[0], (SFillPhysiNode*)pPhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_FILL == type) {
-    pOptr = createStreamFillOperatorInfo(ops[0], (SStreamFillPhysiNode*)pPhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC == type) {
-    pOptr = createIndefinitOutputOperatorInfo(ops[0], pPhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC == type) {
-    pOptr = createTimeSliceOperatorInfo(ops[0], pPhyNode, pTaskInfo);
-  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT == type) {
-    pOptr = createEventwindowOperatorInfo(ops[0], pPhyNode, pTaskInfo);
-  } else {
-    terrno = TSDB_CODE_INVALID_PARA;
-    taosMemoryFree(ops);
-    return NULL;
-  }
-
-  taosMemoryFree(ops);
-  if (pOptr) {
-    pOptr->resultDataBlockId = pPhyNode->pOutputDataBlockDesc->dataBlockId;
-  }
-
-  return pOptr;
-}
-
-static int32_t extractTbscanInStreamOpTree(SOperatorInfo* pOperator, STableScanInfo** ppInfo) {
-  if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
-    if (pOperator->numOfDownstream == 0) {
-      qError("failed to find stream scan operator");
-      return TSDB_CODE_APP_ERROR;
-    }
-
-    if (pOperator->numOfDownstream > 1) {
-      qError("join not supported for stream block scan");
-      return TSDB_CODE_APP_ERROR;
-    }
-    return extractTbscanInStreamOpTree(pOperator->pDownstream[0], ppInfo);
-  } else {
-    SStreamScanInfo* pInfo = pOperator->info;
-    *ppInfo = pInfo->pTableScanOp->info;
-    return 0;
-  }
-}
-
-int32_t extractTableScanNode(SPhysiNode* pNode, STableScanPhysiNode** ppNode) {
-  if (pNode->pChildren == NULL || LIST_LENGTH(pNode->pChildren) == 0) {
-    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == pNode->type) {
-      *ppNode = (STableScanPhysiNode*)pNode;
-      return 0;
-    } else {
-      terrno = TSDB_CODE_APP_ERROR;
-      return -1;
-    }
-  } else {
-    if (LIST_LENGTH(pNode->pChildren) != 1) {
-      terrno = TSDB_CODE_APP_ERROR;
-      return -1;
-    }
-    SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pNode->pChildren, 0);
-    return extractTableScanNode(pChildNode, ppNode);
-  }
-  return -1;
-}
-
 int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pTask, SReadHandle* readHandle) {
   switch (pNode->type) {
     case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: {
@@ -1641,131 +1062,6 @@ int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo*
   return TSDB_CODE_SUCCESS;
 }
 
-int32_t createExecTaskInfo(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId,
-                           int32_t vgId, char* sql, EOPTR_EXEC_MODEL model) {
-  *pTaskInfo = doCreateExecTaskInfo(pPlan->id.queryId, taskId, vgId, model, pPlan->dbFName);
-  if (*pTaskInfo == NULL) {
-    goto _complete;
-  }
-
-  if (pHandle) {
-    if (pHandle->pStateBackend) {
-      (*pTaskInfo)->streamInfo.pState = pHandle->pStateBackend;
-    }
-  }
-
-  (*pTaskInfo)->sql = sql;
-  sql = NULL;
-
-  (*pTaskInfo)->pSubplan = pPlan;
-  (*pTaskInfo)->pRoot =
-      createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, pPlan->pTagCond, pPlan->pTagIndexCond, pPlan->user);
-
-  if (NULL == (*pTaskInfo)->pRoot) {
-    terrno = (*pTaskInfo)->code;
-    goto _complete;
-  }
-
-  return TSDB_CODE_SUCCESS;
-
-_complete:
-  taosMemoryFree(sql);
-  doDestroyTask(*pTaskInfo);
-  return terrno;
-}
-
-static void freeBlock(void* pParam) {
-  SSDataBlock* pBlock = *(SSDataBlock**)pParam;
-  blockDataDestroy(pBlock);
-}
-
-void doDestroyTask(SExecTaskInfo* pTaskInfo) {
-  qDebug("%s execTask is freed", GET_TASKID(pTaskInfo));
-  destroyOperatorInfo(pTaskInfo->pRoot);
-  cleanupTableSchemaInfo(&pTaskInfo->schemaInfo);
-  cleanupStreamInfo(&pTaskInfo->streamInfo);
-
-  if (!pTaskInfo->localFetch.localExec) {
-    nodesDestroyNode((SNode*)pTaskInfo->pSubplan);
-  }
-
-  taosArrayDestroyEx(pTaskInfo->pResultBlockList, freeBlock);
-  taosArrayDestroy(pTaskInfo->stopInfo.pStopInfo);
-  taosMemoryFreeClear(pTaskInfo->sql);
-  taosMemoryFreeClear(pTaskInfo->id.str);
-  taosMemoryFreeClear(pTaskInfo);
-}
-
-static int64_t getQuerySupportBufSize(size_t numOfTables) {
-  size_t s1 = sizeof(STableQueryInfo);
-  //  size_t s3 = sizeof(STableCheckInfo);  buffer consumption in tsdb
-  return (int64_t)(s1 * 1.5 * numOfTables);
-}
-
-int32_t checkForQueryBuf(size_t numOfTables) {
-  int64_t t = getQuerySupportBufSize(numOfTables);
-  if (tsQueryBufferSizeBytes < 0) {
-    return TSDB_CODE_SUCCESS;
-  } else if (tsQueryBufferSizeBytes > 0) {
-    while (1) {
-      int64_t s = tsQueryBufferSizeBytes;
-      int64_t remain = s - t;
-      if (remain >= 0) {
-        if (atomic_val_compare_exchange_64(&tsQueryBufferSizeBytes, s, remain) == s) {
-          return TSDB_CODE_SUCCESS;
-        }
-      } else {
-        return TSDB_CODE_QRY_NOT_ENOUGH_BUFFER;
-      }
-    }
-  }
-
-  // disable query processing if the value of tsQueryBufferSize is zero.
-  return TSDB_CODE_QRY_NOT_ENOUGH_BUFFER;
-}
-
-void releaseQueryBuf(size_t numOfTables) {
-  if (tsQueryBufferSizeBytes < 0) {
-    return;
-  }
-
-  int64_t t = getQuerySupportBufSize(numOfTables);
-
-  // restore value is not enough buffer available
-  atomic_add_fetch_64(&tsQueryBufferSizeBytes, t);
-}
-
-int32_t getOperatorExplainExecInfo(SOperatorInfo* operatorInfo, SArray* pExecInfoList) {
-  SExplainExecInfo  execInfo = {0};
-  SExplainExecInfo* pExplainInfo = taosArrayPush(pExecInfoList, &execInfo);
-
-  pExplainInfo->numOfRows = operatorInfo->resultInfo.totalRows;
-  pExplainInfo->startupCost = operatorInfo->cost.openCost;
-  pExplainInfo->totalCost = operatorInfo->cost.totalCost;
-  pExplainInfo->verboseLen = 0;
-  pExplainInfo->verboseInfo = NULL;
-
-  if (operatorInfo->fpSet.getExplainFn) {
-    int32_t code =
-        operatorInfo->fpSet.getExplainFn(operatorInfo, &pExplainInfo->verboseInfo, &pExplainInfo->verboseLen);
-    if (code) {
-      qError("%s operator getExplainFn failed, code:%s", GET_TASKID(operatorInfo->pTaskInfo), tstrerror(code));
-      return code;
-    }
-  }
-
-  int32_t code = 0;
-  for (int32_t i = 0; i < operatorInfo->numOfDownstream; ++i) {
-    code = getOperatorExplainExecInfo(operatorInfo->pDownstream[i], pExecInfoList);
-    if (code != TSDB_CODE_SUCCESS) {
-      //      taosMemoryFreeClear(*pRes);
-      return TSDB_CODE_OUT_OF_MEMORY;
-    }
-  }
-
-  return TSDB_CODE_SUCCESS;
-}
-
 int32_t setOutputBuf(SStreamState* pState, STimeWindow* win, SResultRow** pResult, int64_t tableGroupId,
                      SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowEntryInfoOffset, SAggSupporter* pAggSup) {
   SWinKey key = {
@@ -2007,25 +1303,3 @@ void qStreamCloseTsdbReader(void* task) {
     }
   }
 }
-
-static void extractTableList(SArray* pList, const SOperatorInfo* pOperator) {
-  if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
-    SStreamScanInfo* pScanInfo = pOperator->info;
-    STableScanInfo*  pTableScanInfo = pScanInfo->pTableScanOp->info;
-    taosArrayPush(pList, &pTableScanInfo->base.pTableListInfo);
-  } else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
-    STableScanInfo* pScanInfo = pOperator->info;
-    taosArrayPush(pList, &pScanInfo->base.pTableListInfo);
-  } else {
-    if (pOperator->pDownstream != NULL && pOperator->pDownstream[0] != NULL) {
-      extractTableList(pList, pOperator->pDownstream[0]);
-    }
-  }
-}
-
-SArray* getTableListInfo(const SExecTaskInfo* pTaskInfo) {
-  SArray*        pArray = taosArrayInit(0, POINTER_BYTES);
-  SOperatorInfo* pOperator = pTaskInfo->pRoot;
-  extractTableList(pArray, pOperator);
-  return pArray;
-}
\ No newline at end of file
diff --git a/source/libs/executor/src/filloperator.c b/source/libs/executor/src/filloperator.c
index 234f1a666c..0ac9e6097f 100644
--- a/source/libs/executor/src/filloperator.c
+++ b/source/libs/executor/src/filloperator.c
@@ -20,16 +20,18 @@
 #include "tmsg.h"
 #include "ttypes.h"
 
-#include "executorimpl.h"
+#include "executorInt.h"
 #include "tcommon.h"
 #include "thash.h"
 #include "ttime.h"
 
-#include "executorInt.h"
 #include "function.h"
 #include "querynodes.h"
 #include "tdatablock.h"
 #include "tfill.h"
+#include "operator.h"
+#include "querytask.h"
+
 
 #define FILL_POS_INVALID 0
 #define FILL_POS_START   1
diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c
index 612ecb4684..2cc92d72e4 100644
--- a/source/libs/executor/src/groupoperator.c
+++ b/source/libs/executor/src/groupoperator.c
@@ -22,7 +22,8 @@
 #include "tmsg.h"
 
 #include "executorInt.h"
-#include "executorimpl.h"
+#include "operator.h"
+#include "querytask.h"
 #include "tcompare.h"
 #include "thash.h"
 #include "ttypes.h"
@@ -926,7 +927,6 @@ int32_t setGroupResultOutputBuf(SOperatorInfo* pOperator, SOptrBasicInfo* binfo,
 
   SResultRow* pResultRow =
       doSetResultOutBufByKey(pBuf, pResultRowInfo, (char*)pData, bytes, true, groupId, pTaskInfo, false, pAggSup, false);
-  assert(pResultRow != NULL);
 
   setResultRowInitCtx(pResultRow, pCtx, numOfCols, pOperator->exprSupp.rowEntryInfoOffset);
   return TSDB_CODE_SUCCESS;
diff --git a/source/libs/executor/src/joinoperator.c b/source/libs/executor/src/joinoperator.c
index 31ff11eec5..754b5f4737 100644
--- a/source/libs/executor/src/joinoperator.c
+++ b/source/libs/executor/src/joinoperator.c
@@ -13,11 +13,13 @@
  * along with this program. If not, see .
  */
 
+#include "executorInt.h"
 #include "filter.h"
-#include "executorimpl.h"
 #include "function.h"
+#include "operator.h"
 #include "os.h"
 #include "querynodes.h"
+#include "querytask.h"
 #include "tcompare.h"
 #include "tdatablock.h"
 #include "thash.h"
diff --git a/source/libs/executor/src/operator.c b/source/libs/executor/src/operator.c
new file mode 100644
index 0000000000..729178dc60
--- /dev/null
+++ b/source/libs/executor/src/operator.c
@@ -0,0 +1,578 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc. 
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#include "filter.h"
+#include "function.h"
+#include "os.h"
+#include "tname.h"
+
+#include "tglobal.h"
+
+#include "executorInt.h"
+#include "index.h"
+#include "operator.h"
+#include "query.h"
+#include "querytask.h"
+#include "vnode.h"
+
+SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t cleanup,
+                                   __optr_close_fn_t closeFn, __optr_reqBuf_fn_t reqBufFn,
+                                   __optr_explain_fn_t explain) {
+  SOperatorFpSet fpSet = {
+      ._openFn = openFn,
+      .getNextFn = nextFn,
+      .cleanupFn = cleanup,
+      .closeFn = closeFn,
+      .reqBufFn = reqBufFn,
+      .getExplainFn = explain,
+  };
+
+  return fpSet;
+}
+
+int32_t optrDummyOpenFn(SOperatorInfo* pOperator) {
+  OPTR_SET_OPENED(pOperator);
+  pOperator->cost.openCost = 0;
+  return TSDB_CODE_SUCCESS;
+}
+
+int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t num) {
+  p->pDownstream = taosMemoryCalloc(1, num * POINTER_BYTES);
+  if (p->pDownstream == NULL) {
+    return TSDB_CODE_OUT_OF_MEMORY;
+  }
+
+  memcpy(p->pDownstream, pDownstream, num * POINTER_BYTES);
+  p->numOfDownstream = num;
+  return TSDB_CODE_SUCCESS;
+}
+
+void setOperatorCompleted(SOperatorInfo* pOperator) {
+  pOperator->status = OP_EXEC_DONE;
+  pOperator->cost.totalCost = (taosGetTimestampUs() - pOperator->pTaskInfo->cost.start) / 1000.0;
+  setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED);
+}
+
+void setOperatorInfo(SOperatorInfo* pOperator, const char* name, int32_t type, bool blocking, int32_t status,
+                     void* pInfo, SExecTaskInfo* pTaskInfo) {
+  pOperator->name = (char*)name;
+  pOperator->operatorType = type;
+  pOperator->blocking = blocking;
+  pOperator->status = status;
+  pOperator->info = pInfo;
+  pOperator->pTaskInfo = pTaskInfo;
+}
+
+// each operator should be set their own function to return total cost buffer
+int32_t optrDefaultBufFn(SOperatorInfo* pOperator) {
+  if (pOperator->blocking) {
+    return -1;
+  } else {
+    return 0;
+  }
+}
+
+static int64_t getQuerySupportBufSize(size_t numOfTables) {
+  size_t s1 = sizeof(STableQueryInfo);
+  //  size_t s3 = sizeof(STableCheckInfo);  buffer consumption in tsdb
+  return (int64_t)(s1 * 1.5 * numOfTables);
+}
+
+int32_t checkForQueryBuf(size_t numOfTables) {
+  int64_t t = getQuerySupportBufSize(numOfTables);
+  if (tsQueryBufferSizeBytes < 0) {
+    return TSDB_CODE_SUCCESS;
+  } else if (tsQueryBufferSizeBytes > 0) {
+    while (1) {
+      int64_t s = tsQueryBufferSizeBytes;
+      int64_t remain = s - t;
+      if (remain >= 0) {
+        if (atomic_val_compare_exchange_64(&tsQueryBufferSizeBytes, s, remain) == s) {
+          return TSDB_CODE_SUCCESS;
+        }
+      } else {
+        return TSDB_CODE_QRY_NOT_ENOUGH_BUFFER;
+      }
+    }
+  }
+
+  // disable query processing if the value of tsQueryBufferSize is zero.
+  return TSDB_CODE_QRY_NOT_ENOUGH_BUFFER;
+}
+
+void releaseQueryBuf(size_t numOfTables) {
+  if (tsQueryBufferSizeBytes < 0) {
+    return;
+  }
+
+  int64_t t = getQuerySupportBufSize(numOfTables);
+
+  // restore value is not enough buffer available
+  atomic_add_fetch_64(&tsQueryBufferSizeBytes, t);
+}
+
+typedef enum {
+  OPTR_FN_RET_CONTINUE = 0x1,
+  OPTR_FN_RET_ABORT = 0x2,
+} ERetType;
+
+typedef struct STraverParam {
+  void*   pRet;
+  int32_t code;
+  void*   pParam;
+} STraverParam;
+
+// iterate the operator tree helper
+typedef ERetType (*optr_fn_t)(SOperatorInfo *pOperator, STraverParam *pParam, const char* pIdstr);
+
+void traverseOperatorTree(SOperatorInfo* pOperator, optr_fn_t fn, STraverParam* pParam, const char* id) {
+  if (pOperator == NULL) {
+    return;
+  }
+
+  ERetType ret = fn(pOperator, pParam, id);
+  if (ret == OPTR_FN_RET_ABORT || pParam->code != TSDB_CODE_SUCCESS) {
+    return;
+  }
+
+  for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
+    traverseOperatorTree(pOperator->pDownstream[i], fn, pParam, id);
+    if (pParam->code != 0) {
+      break;
+    }
+  }
+}
+
+ERetType extractOperatorInfo(SOperatorInfo* pOperator, STraverParam* pParam, const char* pIdStr) {
+  STraverParam* p = pParam;
+  if (pOperator->operatorType == *(int32_t*)p->pParam) {
+    p->pRet = pOperator;
+    return OPTR_FN_RET_ABORT;
+  } else {
+    return OPTR_FN_RET_CONTINUE;
+  }
+}
+
+// QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN
+SOperatorInfo* extractOperatorInTree(SOperatorInfo* pOperator, int32_t type, const char* id) {
+  if (pOperator == NULL) {
+    qError("invalid operator, failed to find tableScanOperator %s", id);
+    terrno = TSDB_CODE_PAR_INTERNAL_ERROR;
+    return NULL;
+  }
+
+  STraverParam p = {.pParam = &type, .pRet = NULL};
+  traverseOperatorTree(pOperator, extractOperatorInfo, &p, id);
+  if (p.code != 0) {
+    terrno = p.code;
+    return NULL;
+  } else {
+    return p.pRet;
+  }
+}
+
+typedef struct SExtScanInfo {
+  int32_t order;
+  int32_t scanFlag;
+  int32_t inheritUsOrder;
+} SExtScanInfo;
+
+static ERetType extractScanInfo(SOperatorInfo* pOperator, STraverParam* pParam, const char* pIdStr) {
+  int32_t type = pOperator->operatorType;
+  SExtScanInfo* pInfo = pParam->pParam;
+
+  if (type == QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN ||
+      type == QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN ||
+      type == QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN || type == QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN) {
+    pInfo->order = TSDB_ORDER_ASC;
+    pInfo->scanFlag= MAIN_SCAN;
+    return OPTR_FN_RET_ABORT;
+  } else if (type == QUERY_NODE_PHYSICAL_PLAN_EXCHANGE) {
+    if (!pInfo->inheritUsOrder) {
+      pInfo->order = TSDB_ORDER_ASC;
+    }
+    pInfo->scanFlag= MAIN_SCAN;
+    return OPTR_FN_RET_ABORT;
+  } else if (type == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
+    STableScanInfo* pTableScanInfo = pOperator->info;
+    pInfo->order = pTableScanInfo->base.cond.order;
+    pInfo->scanFlag= pTableScanInfo->base.scanFlag;
+    return OPTR_FN_RET_ABORT;
+  } else if (type == QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN) {
+    STableMergeScanInfo* pTableScanInfo = pOperator->info;
+    pInfo->order = pTableScanInfo->base.cond.order;
+    pInfo->scanFlag= pTableScanInfo->base.scanFlag;
+    return OPTR_FN_RET_ABORT;
+  } else {
+    return OPTR_FN_RET_CONTINUE;
+  }
+}
+
+int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t* order, int32_t* scanFlag, bool inheritUsOrder) {
+  SExtScanInfo info = {.inheritUsOrder = inheritUsOrder, .order = *order};
+  STraverParam p = {.pParam = &info};
+
+  traverseOperatorTree(pOperator, extractScanInfo, &p, NULL);
+  *order = info.order;
+  *scanFlag = info.scanFlag;
+
+  ASSERT(*order == TSDB_ORDER_ASC || *order == TSDB_ORDER_DESC);
+  return p.code;
+}
+
+static ERetType doStopDataReader(SOperatorInfo* pOperator, STraverParam* pParam, const char* pIdStr) {
+  if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
+    STableScanInfo* pInfo = pOperator->info;
+
+    if (pInfo->base.dataReader != NULL) {
+      tsdbReaderSetCloseFlag(pInfo->base.dataReader);
+    }
+    return OPTR_FN_RET_ABORT;
+  } else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
+    SStreamScanInfo* pInfo = pOperator->info;
+
+    if (pInfo->pTableScanOp != NULL) {
+      STableScanInfo* pTableScanInfo = pInfo->pTableScanOp->info;
+      if (pTableScanInfo != NULL && pTableScanInfo->base.dataReader != NULL) {
+        tsdbReaderSetCloseFlag(pTableScanInfo->base.dataReader);
+      }
+    }
+
+    return OPTR_FN_RET_ABORT;
+  }
+
+  return OPTR_FN_RET_CONTINUE;
+}
+
+int32_t stopTableScanOperator(SOperatorInfo* pOperator, const char* pIdStr) {
+  STraverParam p = {0};
+  traverseOperatorTree(pOperator, doStopDataReader, &p, pIdStr);
+  return p.code;
+}
+
+SOperatorInfo* createOperator(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, SNode* pTagCond,
+                              SNode* pTagIndexCond, const char* pUser, const char* dbname) {
+  int32_t     type = nodeType(pPhyNode);
+  const char* idstr = GET_TASKID(pTaskInfo);
+
+  if (pPhyNode->pChildren == NULL || LIST_LENGTH(pPhyNode->pChildren) == 0) {
+    SOperatorInfo* pOperator = NULL;
+    if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == type) {
+      STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
+
+      // NOTE: this is an patch to fix the physical plan
+      // TODO remove it later
+      if (pTableScanNode->scan.node.pLimit != NULL) {
+        pTableScanNode->groupSort = true;
+      }
+
+      STableListInfo* pTableListInfo = tableListCreate();
+      int32_t         code =
+          createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort, pHandle,
+                                  pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo);
+      if (code) {
+        pTaskInfo->code = code;
+        tableListDestroy(pTableListInfo);
+        qError("failed to createScanTableListInfo, code:%s, %s", tstrerror(code), idstr);
+        return NULL;
+      }
+
+      code = initQueriedTableSchemaInfo(pHandle, &pTableScanNode->scan, dbname, pTaskInfo);
+      if (code) {
+        pTaskInfo->code = code;
+        tableListDestroy(pTableListInfo);
+        return NULL;
+      }
+
+      pOperator = createTableScanOperatorInfo(pTableScanNode, pHandle, pTableListInfo, pTaskInfo);
+      if (NULL == pOperator) {
+        pTaskInfo->code = terrno;
+        tableListDestroy(pTableListInfo);
+        return NULL;
+      }
+
+      STableScanInfo* pScanInfo = pOperator->info;
+      pTaskInfo->cost.pRecoder = &pScanInfo->base.readRecorder;
+    } else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == type) {
+      STableMergeScanPhysiNode* pTableScanNode = (STableMergeScanPhysiNode*)pPhyNode;
+      STableListInfo*           pTableListInfo = tableListCreate();
+
+      int32_t code = createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, true, pHandle,
+                                             pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo);
+      if (code) {
+        pTaskInfo->code = code;
+        tableListDestroy(pTableListInfo);
+        qError("failed to createScanTableListInfo, code: %s", tstrerror(code));
+        return NULL;
+      }
+
+      code = initQueriedTableSchemaInfo(pHandle, &pTableScanNode->scan, dbname, pTaskInfo);
+      if (code) {
+        pTaskInfo->code = terrno;
+        tableListDestroy(pTableListInfo);
+        return NULL;
+      }
+
+      pOperator = createTableMergeScanOperatorInfo(pTableScanNode, pHandle, pTableListInfo, pTaskInfo);
+      if (NULL == pOperator) {
+        pTaskInfo->code = terrno;
+        tableListDestroy(pTableListInfo);
+        return NULL;
+      }
+
+      STableScanInfo* pScanInfo = pOperator->info;
+      pTaskInfo->cost.pRecoder = &pScanInfo->base.readRecorder;
+    } else if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == type) {
+      pOperator = createExchangeOperatorInfo(pHandle ? pHandle->pMsgCb->clientRpc : NULL, (SExchangePhysiNode*)pPhyNode,
+                                             pTaskInfo);
+    } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN == type) {
+      STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode;
+      STableListInfo*      pTableListInfo = tableListCreate();
+
+      if (pHandle->vnode) {
+        int32_t code =
+            createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort,
+                                    pHandle, pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo);
+        if (code) {
+          pTaskInfo->code = code;
+          tableListDestroy(pTableListInfo);
+          qError("failed to createScanTableListInfo, code: %s", tstrerror(code));
+          return NULL;
+        }
+      }
+
+      pTaskInfo->schemaInfo.qsw = extractQueriedColumnSchema(&pTableScanNode->scan);
+      pOperator = createStreamScanOperatorInfo(pHandle, pTableScanNode, pTagCond, pTableListInfo, pTaskInfo);
+    } else if (QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN == type) {
+      SSystemTableScanPhysiNode* pSysScanPhyNode = (SSystemTableScanPhysiNode*)pPhyNode;
+      pOperator = createSysTableScanOperatorInfo(pHandle, pSysScanPhyNode, pUser, pTaskInfo);
+    } else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN == type) {
+      STableCountScanPhysiNode* pTblCountScanNode = (STableCountScanPhysiNode*)pPhyNode;
+      pOperator = createTableCountScanOperatorInfo(pHandle, pTblCountScanNode, pTaskInfo);
+    } else if (QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN == type) {
+      STagScanPhysiNode* pScanPhyNode = (STagScanPhysiNode*)pPhyNode;
+      STableListInfo*    pTableListInfo = tableListCreate();
+      int32_t            code = createScanTableListInfo(pScanPhyNode, NULL, false, pHandle, pTableListInfo, pTagCond,
+                                                        pTagIndexCond, pTaskInfo);
+      if (code != TSDB_CODE_SUCCESS) {
+        pTaskInfo->code = code;
+        qError("failed to getTableList, code: %s", tstrerror(code));
+        return NULL;
+      }
+
+      pOperator = createTagScanOperatorInfo(pHandle, pScanPhyNode, pTableListInfo, pTaskInfo);
+    } else if (QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN == type) {
+      SBlockDistScanPhysiNode* pBlockNode = (SBlockDistScanPhysiNode*)pPhyNode;
+      STableListInfo*          pTableListInfo = tableListCreate();
+
+      if (pBlockNode->tableType == TSDB_SUPER_TABLE) {
+        SArray* pList = taosArrayInit(4, sizeof(STableKeyInfo));
+        int32_t code = vnodeGetAllTableList(pHandle->vnode, pBlockNode->uid, pList);
+        if (code != TSDB_CODE_SUCCESS) {
+          pTaskInfo->code = terrno;
+          return NULL;
+        }
+
+        size_t num = taosArrayGetSize(pList);
+        for (int32_t i = 0; i < num; ++i) {
+          STableKeyInfo* p = taosArrayGet(pList, i);
+          tableListAddTableInfo(pTableListInfo, p->uid, 0);
+        }
+
+        taosArrayDestroy(pList);
+      } else {  // Create group with only one table
+        tableListAddTableInfo(pTableListInfo, pBlockNode->uid, 0);
+      }
+
+      pOperator = createDataBlockInfoScanOperator(pHandle, pBlockNode, pTableListInfo, pTaskInfo);
+    } else if (QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN == type) {
+      SLastRowScanPhysiNode* pScanNode = (SLastRowScanPhysiNode*)pPhyNode;
+      STableListInfo*        pTableListInfo = tableListCreate();
+
+      int32_t code = createScanTableListInfo(&pScanNode->scan, pScanNode->pGroupTags, true, pHandle, pTableListInfo,
+                                             pTagCond, pTagIndexCond, pTaskInfo);
+      if (code != TSDB_CODE_SUCCESS) {
+        pTaskInfo->code = code;
+        return NULL;
+      }
+
+      code = initQueriedTableSchemaInfo(pHandle, &pScanNode->scan, dbname, pTaskInfo);
+      if (code != TSDB_CODE_SUCCESS) {
+        pTaskInfo->code = code;
+        return NULL;
+      }
+
+      pOperator = createCacherowsScanOperator(pScanNode, pHandle, pTableListInfo, pTaskInfo);
+    } else if (QUERY_NODE_PHYSICAL_PLAN_PROJECT == type) {
+      pOperator = createProjectOperatorInfo(NULL, (SProjectPhysiNode*)pPhyNode, pTaskInfo);
+    } else {
+      terrno = TSDB_CODE_INVALID_PARA;
+      return NULL;
+    }
+
+    if (pOperator != NULL) {  // todo moved away
+      pOperator->resultDataBlockId = pPhyNode->pOutputDataBlockDesc->dataBlockId;
+    }
+
+    return pOperator;
+  }
+
+  size_t          size = LIST_LENGTH(pPhyNode->pChildren);
+  SOperatorInfo** ops = taosMemoryCalloc(size, POINTER_BYTES);
+  if (ops == NULL) {
+    return NULL;
+  }
+
+  for (int32_t i = 0; i < size; ++i) {
+    SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, i);
+    ops[i] = createOperator(pChildNode, pTaskInfo, pHandle, pTagCond, pTagIndexCond, pUser, dbname);
+    if (ops[i] == NULL) {
+      taosMemoryFree(ops);
+      return NULL;
+    }
+  }
+
+  SOperatorInfo* pOptr = NULL;
+  if (QUERY_NODE_PHYSICAL_PLAN_PROJECT == type) {
+    pOptr = createProjectOperatorInfo(ops[0], (SProjectPhysiNode*)pPhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_HASH_AGG == type) {
+    SAggPhysiNode* pAggNode = (SAggPhysiNode*)pPhyNode;
+    if (pAggNode->pGroupKeys != NULL) {
+      pOptr = createGroupOperatorInfo(ops[0], pAggNode, pTaskInfo);
+    } else {
+      pOptr = createAggregateOperatorInfo(ops[0], pAggNode, pTaskInfo);
+    }
+  } else if (QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL == type) {
+    SIntervalPhysiNode* pIntervalPhyNode = (SIntervalPhysiNode*)pPhyNode;
+    pOptr = createIntervalOperatorInfo(ops[0], pIntervalPhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL == type) {
+    pOptr = createStreamIntervalOperatorInfo(ops[0], pPhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL == type) {
+    SMergeAlignedIntervalPhysiNode* pIntervalPhyNode = (SMergeAlignedIntervalPhysiNode*)pPhyNode;
+    pOptr = createMergeAlignedIntervalOperatorInfo(ops[0], pIntervalPhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL == type) {
+    SMergeIntervalPhysiNode* pIntervalPhyNode = (SMergeIntervalPhysiNode*)pPhyNode;
+    pOptr = createMergeIntervalOperatorInfo(ops[0], pIntervalPhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL == type) {
+    int32_t children = 0;
+    pOptr = createStreamFinalIntervalOperatorInfo(ops[0], pPhyNode, pTaskInfo, children);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL == type) {
+    int32_t children = pHandle->numOfVgroups;
+    pOptr = createStreamFinalIntervalOperatorInfo(ops[0], pPhyNode, pTaskInfo, children);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_SORT == type) {
+    pOptr = createSortOperatorInfo(ops[0], (SSortPhysiNode*)pPhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT == type) {
+    pOptr = createGroupSortOperatorInfo(ops[0], (SGroupSortPhysiNode*)pPhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE == type) {
+    SMergePhysiNode* pMergePhyNode = (SMergePhysiNode*)pPhyNode;
+    pOptr = createMultiwayMergeOperatorInfo(ops, size, pMergePhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION == type) {
+    SSessionWinodwPhysiNode* pSessionNode = (SSessionWinodwPhysiNode*)pPhyNode;
+    pOptr = createSessionAggOperatorInfo(ops[0], pSessionNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION == type) {
+    pOptr = createStreamSessionAggOperatorInfo(ops[0], pPhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION == type) {
+    int32_t children = 0;
+    pOptr = createStreamFinalSessionAggOperatorInfo(ops[0], pPhyNode, pTaskInfo, children);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION == type) {
+    int32_t children = pHandle->numOfVgroups;
+    pOptr = createStreamFinalSessionAggOperatorInfo(ops[0], pPhyNode, pTaskInfo, children);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_PARTITION == type) {
+    pOptr = createPartitionOperatorInfo(ops[0], (SPartitionPhysiNode*)pPhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION == type) {
+    pOptr = createStreamPartitionOperatorInfo(ops[0], (SStreamPartitionPhysiNode*)pPhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE == type) {
+    SStateWinodwPhysiNode* pStateNode = (SStateWinodwPhysiNode*)pPhyNode;
+    pOptr = createStatewindowOperatorInfo(ops[0], pStateNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE == type) {
+    pOptr = createStreamStateAggOperatorInfo(ops[0], pPhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN == type) {
+    pOptr = createMergeJoinOperatorInfo(ops, size, (SSortMergeJoinPhysiNode*)pPhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_FILL == type) {
+    pOptr = createFillOperatorInfo(ops[0], (SFillPhysiNode*)pPhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_FILL == type) {
+    pOptr = createStreamFillOperatorInfo(ops[0], (SStreamFillPhysiNode*)pPhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC == type) {
+    pOptr = createIndefinitOutputOperatorInfo(ops[0], pPhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC == type) {
+    pOptr = createTimeSliceOperatorInfo(ops[0], pPhyNode, pTaskInfo);
+  } else if (QUERY_NODE_PHYSICAL_PLAN_MERGE_EVENT == type) {
+    pOptr = createEventwindowOperatorInfo(ops[0], pPhyNode, pTaskInfo);
+  } else {
+    terrno = TSDB_CODE_INVALID_PARA;
+    taosMemoryFree(ops);
+    return NULL;
+  }
+
+  taosMemoryFree(ops);
+  if (pOptr) {
+    pOptr->resultDataBlockId = pPhyNode->pOutputDataBlockDesc->dataBlockId;
+  }
+
+  return pOptr;
+}
+
+void destroyOperator(SOperatorInfo* pOperator) {
+  if (pOperator == NULL) {
+    return;
+  }
+
+  if (pOperator->fpSet.closeFn != NULL) {
+    pOperator->fpSet.closeFn(pOperator->info);
+  }
+
+  if (pOperator->pDownstream != NULL) {
+    for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
+      destroyOperator(pOperator->pDownstream[i]);
+    }
+
+    taosMemoryFreeClear(pOperator->pDownstream);
+    pOperator->numOfDownstream = 0;
+  }
+
+  cleanupExprSupp(&pOperator->exprSupp);
+  taosMemoryFreeClear(pOperator);
+}
+
+int32_t getOperatorExplainExecInfo(SOperatorInfo* operatorInfo, SArray* pExecInfoList) {
+  SExplainExecInfo  execInfo = {0};
+  SExplainExecInfo* pExplainInfo = taosArrayPush(pExecInfoList, &execInfo);
+
+  pExplainInfo->numOfRows = operatorInfo->resultInfo.totalRows;
+  pExplainInfo->startupCost = operatorInfo->cost.openCost;
+  pExplainInfo->totalCost = operatorInfo->cost.totalCost;
+  pExplainInfo->verboseLen = 0;
+  pExplainInfo->verboseInfo = NULL;
+
+  if (operatorInfo->fpSet.getExplainFn) {
+    int32_t code =
+        operatorInfo->fpSet.getExplainFn(operatorInfo, &pExplainInfo->verboseInfo, &pExplainInfo->verboseLen);
+    if (code) {
+      qError("%s operator getExplainFn failed, code:%s", GET_TASKID(operatorInfo->pTaskInfo), tstrerror(code));
+      return code;
+    }
+  }
+
+  int32_t code = 0;
+  for (int32_t i = 0; i < operatorInfo->numOfDownstream; ++i) {
+    code = getOperatorExplainExecInfo(operatorInfo->pDownstream[i], pExecInfoList);
+    if (code != TSDB_CODE_SUCCESS) {
+      //      taosMemoryFreeClear(*pRes);
+      return TSDB_CODE_OUT_OF_MEMORY;
+    }
+  }
+
+  return TSDB_CODE_SUCCESS;
+}
diff --git a/source/libs/executor/src/projectoperator.c b/source/libs/executor/src/projectoperator.c
index 86c49e0fc8..02f504bef0 100644
--- a/source/libs/executor/src/projectoperator.c
+++ b/source/libs/executor/src/projectoperator.c
@@ -13,9 +13,11 @@
  * along with this program. If not, see .
  */
 
-#include "executorimpl.h"
+#include "executorInt.h"
 #include "filter.h"
 #include "functionMgt.h"
+#include "operator.h"
+#include "querytask.h"
 
 typedef struct SProjectOperatorInfo {
   SOptrBasicInfo binfo;
diff --git a/source/libs/executor/src/querytask.c b/source/libs/executor/src/querytask.c
new file mode 100644
index 0000000000..7716b5976b
--- /dev/null
+++ b/source/libs/executor/src/querytask.c
@@ -0,0 +1,239 @@
+/*
+ * Copyright (c) 2019 TAOS Data, Inc. 
+ *
+ * This program is free software: you can use, redistribute, and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3
+ * or later ("AGPL"), as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+#include "filter.h"
+#include "function.h"
+#include "functionMgt.h"
+#include "os.h"
+#include "querynodes.h"
+#include "tfill.h"
+#include "tname.h"
+
+#include "tdatablock.h"
+#include "tmsg.h"
+
+#include "executorInt.h"
+#include "index.h"
+#include "operator.h"
+#include "query.h"
+#include "querytask.h"
+#include "thash.h"
+#include "ttypes.h"
+#include "vnode.h"
+
+#define CLEAR_QUERY_STATUS(q, st) ((q)->status &= (~(st)))
+
+SExecTaskInfo* doCreateTask(uint64_t queryId, uint64_t taskId, int32_t vgId, EOPTR_EXEC_MODEL model) {
+  SExecTaskInfo* pTaskInfo = taosMemoryCalloc(1, sizeof(SExecTaskInfo));
+  if (pTaskInfo == NULL) {
+    terrno = TSDB_CODE_OUT_OF_MEMORY;
+    return NULL;
+  }
+
+  setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED);
+  pTaskInfo->cost.created = taosGetTimestampUs();
+
+  pTaskInfo->execModel = model;
+  pTaskInfo->stopInfo.pStopInfo = taosArrayInit(4, sizeof(SExchangeOpStopInfo));
+  pTaskInfo->pResultBlockList = taosArrayInit(128, POINTER_BYTES);
+
+  taosInitRWLatch(&pTaskInfo->lock);
+
+  pTaskInfo->id.vgId = vgId;
+  pTaskInfo->id.queryId = queryId;
+  pTaskInfo->id.str = taosMemoryMalloc(64);
+  buildTaskId(taskId, queryId, pTaskInfo->id.str);
+
+  return pTaskInfo;
+}
+
+bool isTaskKilled(SExecTaskInfo* pTaskInfo) { return (0 != pTaskInfo->code); }
+
+void setTaskKilled(SExecTaskInfo* pTaskInfo, int32_t rspCode) {
+  pTaskInfo->code = rspCode;
+  stopTableScanOperator(pTaskInfo->pRoot, pTaskInfo->id.str);
+}
+
+void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status) {
+  if (status == TASK_NOT_COMPLETED) {
+    pTaskInfo->status = status;
+  } else {
+    // QUERY_NOT_COMPLETED is not compatible with any other status, so clear its position first
+    CLEAR_QUERY_STATUS(pTaskInfo, TASK_NOT_COMPLETED);
+    pTaskInfo->status |= status;
+  }
+}
+
+int32_t createExecTaskInfo(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId,
+                           int32_t vgId, char* sql, EOPTR_EXEC_MODEL model) {
+  *pTaskInfo = doCreateTask(pPlan->id.queryId, taskId, vgId, model);
+  if (*pTaskInfo == NULL) {
+    taosMemoryFree(sql);
+    return terrno;
+  }
+
+  if (pHandle) {
+    if (pHandle->pStateBackend) {
+      (*pTaskInfo)->streamInfo.pState = pHandle->pStateBackend;
+    }
+  }
+
+  TSWAP((*pTaskInfo)->sql, sql);
+
+  (*pTaskInfo)->pSubplan = pPlan;
+  (*pTaskInfo)->pRoot = createOperator(pPlan->pNode, *pTaskInfo, pHandle, pPlan->pTagCond, pPlan->pTagIndexCond,
+                                       pPlan->user, pPlan->dbFName);
+
+  if (NULL == (*pTaskInfo)->pRoot) {
+    int32_t code = (*pTaskInfo)->code;
+    doDestroyTask(*pTaskInfo);
+    (*pTaskInfo) = NULL;
+    return code;
+  } else {
+    return TSDB_CODE_SUCCESS;
+  }
+}
+
+void cleanupQueriedTableScanInfo(SSchemaInfo* pSchemaInfo) {
+  taosMemoryFreeClear(pSchemaInfo->dbname);
+  taosMemoryFreeClear(pSchemaInfo->tablename);
+  tDeleteSchemaWrapper(pSchemaInfo->sw);
+  tDeleteSchemaWrapper(pSchemaInfo->qsw);
+}
+
+int32_t initQueriedTableSchemaInfo(SReadHandle* pHandle, SScanPhysiNode* pScanNode, const char* dbName, SExecTaskInfo* pTaskInfo) {
+  SMetaReader mr = {0};
+  if (pHandle == NULL) {
+    terrno = TSDB_CODE_INVALID_PARA;
+    return terrno;
+  }
+
+  metaReaderInit(&mr, pHandle->meta, 0);
+  int32_t code = metaGetTableEntryByUidCache(&mr, pScanNode->uid);
+  if (code != TSDB_CODE_SUCCESS) {
+    qError("failed to get the table meta, uid:0x%" PRIx64 ", suid:0x%" PRIx64 ", %s", pScanNode->uid, pScanNode->suid,
+           GET_TASKID(pTaskInfo));
+
+    metaReaderClear(&mr);
+    return terrno;
+  }
+
+  SSchemaInfo* pSchemaInfo = &pTaskInfo->schemaInfo;
+
+  pSchemaInfo->tablename = taosStrdup(mr.me.name);
+  pSchemaInfo->dbname = taosStrdup(dbName);
+
+  if (mr.me.type == TSDB_SUPER_TABLE) {
+    pSchemaInfo->sw = tCloneSSchemaWrapper(&mr.me.stbEntry.schemaRow);
+    pSchemaInfo->tversion = mr.me.stbEntry.schemaTag.version;
+  } else if (mr.me.type == TSDB_CHILD_TABLE) {
+    tDecoderClear(&mr.coder);
+
+    tb_uid_t suid = mr.me.ctbEntry.suid;
+    code = metaGetTableEntryByUidCache(&mr, suid);
+    if (code != TSDB_CODE_SUCCESS) {
+      metaReaderClear(&mr);
+      return terrno;
+    }
+
+    pSchemaInfo->sw = tCloneSSchemaWrapper(&mr.me.stbEntry.schemaRow);
+    pSchemaInfo->tversion = mr.me.stbEntry.schemaTag.version;
+  } else {
+    pSchemaInfo->sw = tCloneSSchemaWrapper(&mr.me.ntbEntry.schemaRow);
+  }
+
+  metaReaderClear(&mr);
+
+  pSchemaInfo->qsw = extractQueriedColumnSchema(pScanNode);
+  return TSDB_CODE_SUCCESS;
+}
+
+SSchemaWrapper* extractQueriedColumnSchema(SScanPhysiNode* pScanNode) {
+  int32_t numOfCols = LIST_LENGTH(pScanNode->pScanCols);
+  int32_t numOfTags = LIST_LENGTH(pScanNode->pScanPseudoCols);
+
+  SSchemaWrapper* pqSw = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
+  pqSw->pSchema = taosMemoryCalloc(numOfCols + numOfTags, sizeof(SSchema));
+
+  for (int32_t i = 0; i < numOfCols; ++i) {
+    STargetNode* pNode = (STargetNode*)nodesListGetNode(pScanNode->pScanCols, i);
+    SColumnNode* pColNode = (SColumnNode*)pNode->pExpr;
+
+    SSchema* pSchema = &pqSw->pSchema[pqSw->nCols++];
+    pSchema->colId = pColNode->colId;
+    pSchema->type = pColNode->node.resType.type;
+    pSchema->bytes = pColNode->node.resType.bytes;
+    tstrncpy(pSchema->name, pColNode->colName, tListLen(pSchema->name));
+  }
+
+  // this the tags and pseudo function columns, we only keep the tag columns
+  for (int32_t i = 0; i < numOfTags; ++i) {
+    STargetNode* pNode = (STargetNode*)nodesListGetNode(pScanNode->pScanPseudoCols, i);
+
+    int32_t type = nodeType(pNode->pExpr);
+    if (type == QUERY_NODE_COLUMN) {
+      SColumnNode* pColNode = (SColumnNode*)pNode->pExpr;
+
+      SSchema* pSchema = &pqSw->pSchema[pqSw->nCols++];
+      pSchema->colId = pColNode->colId;
+      pSchema->type = pColNode->node.resType.type;
+      pSchema->bytes = pColNode->node.resType.bytes;
+      tstrncpy(pSchema->name, pColNode->colName, tListLen(pSchema->name));
+    }
+  }
+
+  return pqSw;
+}
+
+static void cleanupStreamInfo(SStreamTaskInfo* pStreamInfo) { tDeleteSchemaWrapper(pStreamInfo->schema); }
+
+static void freeBlock(void* pParam) {
+  SSDataBlock* pBlock = *(SSDataBlock**)pParam;
+  blockDataDestroy(pBlock);
+}
+
+void doDestroyTask(SExecTaskInfo* pTaskInfo) {
+  qDebug("%s execTask is freed", GET_TASKID(pTaskInfo));
+  destroyOperator(pTaskInfo->pRoot);
+  pTaskInfo->pRoot = NULL;
+
+  cleanupQueriedTableScanInfo(&pTaskInfo->schemaInfo);
+  cleanupStreamInfo(&pTaskInfo->streamInfo);
+
+  if (!pTaskInfo->localFetch.localExec) {
+    nodesDestroyNode((SNode*)pTaskInfo->pSubplan);
+    pTaskInfo->pSubplan = NULL;
+  }
+
+  taosArrayDestroyEx(pTaskInfo->pResultBlockList, freeBlock);
+  taosArrayDestroy(pTaskInfo->stopInfo.pStopInfo);
+  taosMemoryFreeClear(pTaskInfo->sql);
+  taosMemoryFreeClear(pTaskInfo->id.str);
+  taosMemoryFreeClear(pTaskInfo);
+}
+
+void buildTaskId(uint64_t taskId, uint64_t queryId, char* dst) {
+  char* p = dst;
+
+  int32_t offset = 6;
+  memcpy(p, "TID:0x", offset);
+  offset += tintToHex(taskId, &p[offset]);
+
+  memcpy(&p[offset], " QID:0x", 7);
+  offset += 7;
+  offset += tintToHex(queryId, &p[offset]);
+
+  p[offset] = 0;
+}
diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c
index 6d62d55024..e853947a4f 100644
--- a/source/libs/executor/src/scanoperator.c
+++ b/source/libs/executor/src/scanoperator.c
@@ -13,7 +13,7 @@
  * along with this program. If not, see .
  */
 
-#include "executorimpl.h"
+#include "executorInt.h"
 #include "filter.h"
 #include "function.h"
 #include "functionMgt.h"
@@ -30,6 +30,8 @@
 #include "tcompare.h"
 #include "thash.h"
 #include "ttypes.h"
+#include "operator.h"
+#include "querytask.h"
 
 int32_t scanDebug = 0;
 
@@ -156,7 +158,7 @@ static bool overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBlockIn
         break;
       }
 
-      assert(w.skey < pBlockInfo->window.skey);
+      ASSERT(w.skey < pBlockInfo->window.skey);
       if (pBlockInfo->window.skey <= TMIN(w.ekey, pBlockInfo->window.ekey)) {
         return true;
       }
@@ -1621,7 +1623,7 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock
 
   pInfo->pRes->info.dataLoad = 1;
   blockDataUpdateTsWindow(pInfo->pRes, pInfo->primaryTsIndex);
-  blockDataFreeRes((SSDataBlock*)pBlock);
+//  blockDataFreeRes((SSDataBlock*)pBlock);
 
   calBlockTbName(pInfo, pInfo->pRes);
   return 0;
@@ -1634,8 +1636,9 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
 
   qDebug("start to exec queue scan, %s", id);
 
+#if 0
   if (pTaskInfo->streamInfo.submit.msgStr != NULL) {
-    if (pInfo->tqReader->msg2.msgStr == NULL) {
+    if (pInfo->tqReader->msg.msgStr == NULL) {
       SPackedData submit = pTaskInfo->streamInfo.submit;
       if (tqReaderSetSubmitMsg(pInfo->tqReader, submit.msgStr, submit.msgLen, submit.ver) < 0) {
         qError("submit msg messed up when initing stream submit block %p", submit.msgStr);
@@ -1646,25 +1649,24 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
     blockDataCleanup(pInfo->pRes);
     SDataBlockInfo* pBlockInfo = &pInfo->pRes->info;
 
-    while (tqNextDataBlock(pInfo->tqReader)) {
-      SSDataBlock block = {0};
-
-      int32_t code = tqRetrieveDataBlock2(&block, pInfo->tqReader, NULL);
-      if (code != TSDB_CODE_SUCCESS || block.info.rows == 0) {
+    while (tqNextBlockImpl(pInfo->tqReader)) {
+      int32_t code = tqRetrieveDataBlock(pInfo->tqReader, NULL);
+      if (code != TSDB_CODE_SUCCESS || pInfo->tqReader->pResBlock->info.rows == 0) {
         continue;
       }
 
-      setBlockIntoRes(pInfo, &block, true);
+      setBlockIntoRes(pInfo, pInfo->tqReader->pResBlock, true);
 
       if (pBlockInfo->rows > 0) {
         return pInfo->pRes;
       }
     }
 
-    pInfo->tqReader->msg2 = (SPackedData){0};
+    pInfo->tqReader->msg = (SPackedData){0};
     pTaskInfo->streamInfo.submit = (SPackedData){0};
     return NULL;
   }
+#endif
 
   if (pTaskInfo->streamInfo.currentOffset.type == TMQ_OFFSET__SNAPSHOT_DATA) {
     SSDataBlock* pResult = doTableScan(pInfo->pTableScanOp);
@@ -1682,28 +1684,28 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) {
     if (tqSeekVer(pInfo->tqReader, pTaskInfo->streamInfo.snapshotVer + 1, pTaskInfo->id.str) < 0) {
       return NULL;
     }
+
     tqOffsetResetToLog(&pTaskInfo->streamInfo.currentOffset, pTaskInfo->streamInfo.snapshotVer);
   }
 
   if (pTaskInfo->streamInfo.currentOffset.type == TMQ_OFFSET__LOG) {
-    while (1) {
-      SFetchRet ret = {0};
-      tqNextBlock(pInfo->tqReader, &ret);
-      tqOffsetResetToLog(
-          &pTaskInfo->streamInfo.currentOffset,
-          pInfo->tqReader->pWalReader->curVersion - 1);  // curVersion move to next, so currentOffset = curVersion - 1
 
-      if (ret.fetchType == FETCH_TYPE__DATA) {
-        qDebug("doQueueScan get data from log %" PRId64 " rows, version:%" PRId64, ret.data.info.rows,
+    while (1) {
+      int32_t type = tqNextBlockInWal(pInfo->tqReader);
+      SSDataBlock* pRes = pInfo->tqReader->pResBlock;
+
+      // curVersion move to next, so currentOffset = curVersion - 1
+      tqOffsetResetToLog(&pTaskInfo->streamInfo.currentOffset, pInfo->tqReader->pWalReader->curVersion - 1);
+
+      if (type == FETCH_TYPE__DATA) {
+        qDebug("doQueueScan get data from log %" PRId64 " rows, version:%" PRId64, pRes->info.rows,
                pTaskInfo->streamInfo.currentOffset.version);
         blockDataCleanup(pInfo->pRes);
-        setBlockIntoRes(pInfo, &ret.data, true);
+        setBlockIntoRes(pInfo, pRes, true);
         if (pInfo->pRes->info.rows > 0) {
-          qDebug("doQueueScan get data from log %" PRId64 " rows, return, version:%" PRId64, pInfo->pRes->info.rows,
-                 pTaskInfo->streamInfo.currentOffset.version);
           return pInfo->pRes;
         }
-      } else if (ret.fetchType == FETCH_TYPE__NONE) {
+      } else if (type == FETCH_TYPE__NONE) {
         qDebug("doQueueScan get none from log, return, version:%" PRId64, pTaskInfo->streamInfo.currentOffset.version);
         return NULL;
       }
@@ -1855,7 +1857,7 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) {
         SSDataBlock* pSDB = doRangeScan(pInfo, pInfo->pUpdateRes, pInfo->primaryTsIndex, &pInfo->updateResIndex);
         if (pSDB) {
           STableScanInfo* pTableScanInfo = pInfo->pTableScanOp->info;
-          uint64_t        version = getReaderMaxVersion(pTableScanInfo->base.dataReader);
+          uint64_t        version = tsdbGetReaderMaxVersion(pTableScanInfo->base.dataReader);
           updateInfoSetScanRange(pInfo->pUpdateInfo, &pTableScanInfo->base.cond.twindows, pInfo->groupId, version);
           pSDB->info.type = pInfo->scanMode == STREAM_SCAN_FROM_DATAREADER_RANGE ? STREAM_NORMAL : STREAM_PULL_DATA;
           checkUpdateData(pInfo, true, pSDB, false);
@@ -2021,7 +2023,7 @@ FETCH_NEXT_BLOCK:
         SSDataBlock* pSDB = doRangeScan(pInfo, pInfo->pUpdateRes, pInfo->primaryTsIndex, &pInfo->updateResIndex);
         if (pSDB) {
           STableScanInfo* pTableScanInfo = pInfo->pTableScanOp->info;
-          uint64_t        version = getReaderMaxVersion(pTableScanInfo->base.dataReader);
+          uint64_t        version = tsdbGetReaderMaxVersion(pTableScanInfo->base.dataReader);
           updateInfoSetScanRange(pInfo->pUpdateInfo, &pTableScanInfo->base.cond.twindows, pInfo->groupId, version);
           pSDB->info.type = pInfo->scanMode == STREAM_SCAN_FROM_DATAREADER_RANGE ? STREAM_NORMAL : STREAM_PULL_DATA;
           checkUpdateData(pInfo, true, pSDB, false);
@@ -2053,7 +2055,7 @@ FETCH_NEXT_BLOCK:
 
   NEXT_SUBMIT_BLK:
     while (1) {
-      if (pInfo->tqReader->msg2.msgStr == NULL) {
+      if (pInfo->tqReader->msg.msgStr == NULL) {
         if (pInfo->validBlockIndex >= totBlockNum) {
           updateInfoDestoryColseWinSBF(pInfo->pUpdateInfo);
           doClearBufferedBlocks(pInfo);
@@ -2072,16 +2074,13 @@ FETCH_NEXT_BLOCK:
 
       blockDataCleanup(pInfo->pRes);
 
-      while (tqNextDataBlock(pInfo->tqReader)) {
-        SSDataBlock block = {0};
-
-        int32_t code = tqRetrieveDataBlock2(&block, pInfo->tqReader, NULL);
-
-        if (code != TSDB_CODE_SUCCESS || block.info.rows == 0) {
+      while (tqNextBlockImpl(pInfo->tqReader)) {
+        int32_t code = tqRetrieveDataBlock(pInfo->tqReader, NULL);
+        if (code != TSDB_CODE_SUCCESS || pInfo->tqReader->pResBlock->info.rows == 0) {
           continue;
         }
 
-        setBlockIntoRes(pInfo, &block, false);
+        setBlockIntoRes(pInfo, pInfo->tqReader->pResBlock, false);
 
         if (updateInfoIgnore(pInfo->pUpdateInfo, &pInfo->pRes->info.window, pInfo->pRes->info.id.groupId,
                              pInfo->pRes->info.version)) {
@@ -2114,7 +2113,6 @@ FETCH_NEXT_BLOCK:
     // record the scan action.
     pInfo->numOfExec++;
     pOperator->resultInfo.totalRows += pBlockInfo->rows;
-    // printDataBlock(pInfo->pRes, "stream scan");
 
     qDebug("scan rows: %" PRId64, pBlockInfo->rows);
     if (pBlockInfo->rows > 0) {
@@ -2190,7 +2188,7 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
       qDebug("tmqsnap change get data uid:%" PRId64 "", mtInfo.uid);
     }
     qStreamPrepareScan(pTaskInfo, &offset, pInfo->sContext->subType);
-    tDeleteSSchemaWrapper(mtInfo.schema);
+    tDeleteSchemaWrapper(mtInfo.schema);
     return NULL;
   } else if (pTaskInfo->streamInfo.currentOffset.type == TMQ_OFFSET__SNAPSHOT_META) {
     SSnapContext* sContext = pInfo->sContext;
@@ -2305,7 +2303,7 @@ static void destroyStreamScanOperatorInfo(void* param) {
   SStreamScanInfo* pStreamScan = (SStreamScanInfo*)param;
 
   if (pStreamScan->pTableScanOp && pStreamScan->pTableScanOp->info) {
-    destroyOperatorInfo(pStreamScan->pTableScanOp);
+    destroyOperator(pStreamScan->pTableScanOp);
   }
 
   if (pStreamScan->tqReader) {
@@ -2427,7 +2425,7 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
 
     if (pHandle->initTqReader) {
       ASSERT(pHandle->tqReader == NULL);
-      pInfo->tqReader = tqOpenReader(pHandle->vnode);
+      pInfo->tqReader = tqReaderOpen(pHandle->vnode);
       ASSERT(pInfo->tqReader);
     } else {
       ASSERT(pHandle->tqReader);
diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c
index df62a7fa77..718bb596c5 100644
--- a/source/libs/executor/src/sortoperator.c
+++ b/source/libs/executor/src/sortoperator.c
@@ -13,8 +13,10 @@
  * along with this program. If not, see .
  */
 
+#include "executorInt.h"
 #include "filter.h"
-#include "executorimpl.h"
+#include "operator.h"
+#include "querytask.h"
 #include "tdatablock.h"
 
 typedef struct SSortOperatorInfo {
diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c
index 1abe678ac6..c75c49fe77 100644
--- a/source/libs/executor/src/sysscanoperator.c
+++ b/source/libs/executor/src/sysscanoperator.c
@@ -13,7 +13,7 @@
  * along with this program. If not, see .
  */
 
-#include "executorimpl.h"
+#include "executorInt.h"
 #include "filter.h"
 #include "function.h"
 #include "functionMgt.h"
@@ -31,6 +31,9 @@
 #include "thash.h"
 #include "ttypes.h"
 #include "vnode.h"
+#include "operator.h"
+#include "querytask.h"
+
 
 typedef int (*__optSysFilter)(void* a, void* b, int16_t dtype);
 typedef int32_t (*__sys_filte)(void* pMeta, SNode* cond, SArray* result);
@@ -1482,11 +1485,7 @@ static SSDataBlock* sysTableScanUserTables(SOperatorInfo* pOperator) {
           pInfo->pIdx->init = 1;
           SSDataBlock* blk = sysTableBuildUserTablesByUids(pOperator);
           return blk;
-        } else if (flt == -2) {
-          qDebug("%s failed to get sys table info by idx, empty result", GET_TASKID(pTaskInfo));
-          return NULL;
-        } else if (flt == -1) {
-          // not idx
+        } else if ((flt == -1) || (flt == -2)) {
           qDebug("%s failed to get sys table info by idx, scan sys table one by one", GET_TASKID(pTaskInfo));
         }
       } else if (pCondition != NULL && (pInfo->pIdx != NULL && pInfo->pIdx->init == 1)) {
diff --git a/source/libs/executor/src/tfill.c b/source/libs/executor/src/tfill.c
index e59ea253cc..fc4e82b57f 100644
--- a/source/libs/executor/src/tfill.c
+++ b/source/libs/executor/src/tfill.c
@@ -20,7 +20,7 @@
 #include "tmsg.h"
 #include "ttypes.h"
 
-#include "executorimpl.h"
+#include "executorInt.h"
 #include "tcommon.h"
 #include "thash.h"
 #include "ttime.h"
@@ -408,7 +408,7 @@ static int64_t appendFilledResult(SFillInfo* pFillInfo, SSDataBlock* pBlock, int
 
   pFillInfo->numOfTotal += pFillInfo->numOfCurrent;
 
-  assert(pFillInfo->numOfCurrent == resultCapacity);
+  ASSERT(pFillInfo->numOfCurrent == resultCapacity);
   return resultCapacity;
 }
 
@@ -558,7 +558,7 @@ int64_t getNumOfResultsAfterFillGap(SFillInfo* pFillInfo, TSKEY ekey, int32_t ma
     numOfRes = taosTimeCountInterval(lastKey, pFillInfo->currentKey, pFillInfo->interval.sliding,
                                      pFillInfo->interval.slidingUnit, pFillInfo->interval.precision);
     numOfRes += 1;
-    assert(numOfRes >= numOfRows);
+    ASSERT(numOfRes >= numOfRows);
   } else {  // reach the end of data
     if ((ekey1 < pFillInfo->currentKey && FILL_IS_ASC_FILL(pFillInfo)) ||
         (ekey1 >= pFillInfo->currentKey && !FILL_IS_ASC_FILL(pFillInfo))) {
@@ -593,14 +593,14 @@ int64_t taosFillResultDataBlock(SFillInfo* pFillInfo, SSDataBlock* p, int32_t ca
   int32_t remain = taosNumOfRemainRows(pFillInfo);
 
   int64_t numOfRes = getNumOfResultsAfterFillGap(pFillInfo, pFillInfo->end, capacity);
-  assert(numOfRes <= capacity);
+  ASSERT(numOfRes <= capacity);
 
   // no data existed for fill operation now, append result according to the fill strategy
   if (remain == 0) {
     appendFilledResult(pFillInfo, p, numOfRes);
   } else {
     fillResultImpl(pFillInfo, p, (int32_t)numOfRes);
-    assert(numOfRes == pFillInfo->numOfCurrent);
+    ASSERT(numOfRes == pFillInfo->numOfCurrent);
   }
 
   qDebug("fill:%p, generated fill result, src block:%d, index:%d, brange:%" PRId64 "-%" PRId64 ", currentKey:%" PRId64
diff --git a/source/libs/executor/src/timesliceoperator.c b/source/libs/executor/src/timesliceoperator.c
index b7f7a44080..d56595dae9 100644
--- a/source/libs/executor/src/timesliceoperator.c
+++ b/source/libs/executor/src/timesliceoperator.c
@@ -12,10 +12,12 @@
  * You should have received a copy of the GNU Affero General Public License
  * along with this program. If not, see .
  */
-#include "executorimpl.h"
+#include "executorInt.h"
 #include "filter.h"
 #include "function.h"
 #include "functionMgt.h"
+#include "operator.h"
+#include "querytask.h"
 #include "tcommon.h"
 #include "tcompare.h"
 #include "tdatablock.h"
diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c
index a9400e24ce..3ada593d60 100644
--- a/source/libs/executor/src/timewindowoperator.c
+++ b/source/libs/executor/src/timewindowoperator.c
@@ -12,10 +12,12 @@
  * You should have received a copy of the GNU Affero General Public License
  * along with this program. If not, see .
  */
-#include "executorimpl.h"
+#include "executorInt.h"
 #include "filter.h"
 #include "function.h"
 #include "functionMgt.h"
+#include "operator.h"
+#include "querytask.h"
 #include "tcommon.h"
 #include "tcompare.h"
 #include "tdatablock.h"
@@ -25,6 +27,12 @@
 #define IS_FINAL_OP(op)    ((op)->isFinal)
 #define DEAULT_DELETE_MARK (1000LL * 60LL * 60LL * 24LL * 365LL * 10LL);
 
+typedef struct SStateWindowInfo {
+  SResultWindowInfo winInfo;
+  SStateKeys*       pStateKey;
+} SStateWindowInfo;
+
+
 typedef struct SSessionAggOperatorInfo {
   SOptrBasicInfo     binfo;
   SAggSupporter      aggSup;
@@ -153,7 +161,7 @@ FORCE_INLINE int32_t getForwardStepsInBlock(int32_t numOfRows, __block_search_fn
     //    }
   }
 
-  assert(forwardRows >= 0);
+  ASSERT(forwardRows >= 0);
   return forwardRows;
 }
 
@@ -165,8 +173,6 @@ int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order) {
     return -1;
   }
 
-  assert(order == TSDB_ORDER_ASC || order == TSDB_ORDER_DESC);
-
   TSKEY*  keyList = (TSKEY*)pValue;
   int32_t firstPos = 0;
   int32_t lastPos = num - 1;
@@ -230,7 +236,7 @@ int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order) {
 
 int32_t getNumOfRowsInTimeWindow(SDataBlockInfo* pDataBlockInfo, TSKEY* pPrimaryColumn, int32_t startPos, TSKEY ekey,
                                  __block_search_fn_t searchFn, STableQueryInfo* item, int32_t order) {
-  assert(startPos >= 0 && startPos < pDataBlockInfo->rows);
+  ASSERT(startPos >= 0 && startPos < pDataBlockInfo->rows);
 
   int32_t num = -1;
   int32_t step = GET_FORWARD_DIRECTION_FACTOR(order);
@@ -261,7 +267,6 @@ int32_t getNumOfRowsInTimeWindow(SDataBlockInfo* pDataBlockInfo, TSKEY* pPrimary
     }
   }
 
-  assert(num >= 0);
   return num;
 }
 
@@ -433,7 +438,7 @@ static bool setTimeWindowInterpolationEndTs(SIntervalAggOperatorInfo* pInfo, SEx
   }
 
   int32_t nextRowIndex = endRowIndex + 1;
-  assert(nextRowIndex >= 0);
+  ASSERT(nextRowIndex >= 0);
 
   TSKEY nextKey = tsCols[nextRowIndex];
   doTimeWindowInterpolation(pInfo->pPrevValues, pDataBlock, actualEndKey, endRowIndex, nextKey, nextRowIndex, key,
@@ -494,9 +499,9 @@ static int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext,
    */
   if (primaryKeys == NULL) {
     if (ascQuery) {
-      assert(pDataBlockInfo->window.skey <= pNext->ekey);
+      ASSERT(pDataBlockInfo->window.skey <= pNext->ekey);
     } else {
-      assert(pDataBlockInfo->window.ekey >= pNext->skey);
+      ASSERT(pDataBlockInfo->window.ekey >= pNext->skey);
     }
   } else {
     if (ascQuery && primaryKeys[startPos] > pNext->ekey) {
@@ -533,7 +538,6 @@ static bool isResultRowInterpolated(SResultRow* pResult, SResultTsInterpType typ
 }
 
 static void setResultRowInterpo(SResultRow* pResult, SResultTsInterpType type) {
-  assert(pResult != NULL && (type == RESULT_ROW_START_INTERP || type == RESULT_ROW_END_INTERP));
   if (type == RESULT_ROW_START_INTERP) {
     pResult->startInterp = true;
   } else {
@@ -1610,7 +1614,7 @@ void destroyStreamFinalIntervalOperatorInfo(void* param) {
     int32_t size = taosArrayGetSize(pInfo->pChildren);
     for (int32_t i = 0; i < size; i++) {
       SOperatorInfo* pChildOp = taosArrayGetP(pInfo->pChildren, i);
-      destroyOperatorInfo(pChildOp);
+      destroyOperator(pChildOp);
     }
     taosArrayDestroy(pInfo->pChildren);
   }
@@ -2541,6 +2545,20 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
   }
 
   while (1) {
+    if (isTaskKilled(pTaskInfo)) {
+
+      if (pInfo->pUpdated != NULL) {
+        pInfo->pUpdated = taosArrayDestroy(pInfo->pUpdated);
+      }
+
+      if (pInfo->pUpdatedMap != NULL) {
+        tSimpleHashCleanup(pInfo->pUpdatedMap);
+        pInfo->pUpdatedMap = NULL;
+      }
+
+      T_LONG_JMP(pTaskInfo->env, pTaskInfo->code);
+    }
+
     SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
     if (pBlock == NULL) {
       pOperator->status = OP_RES_TO_RETURN;
@@ -2635,6 +2653,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) {
   while ((pIte = tSimpleHashIterate(pInfo->pUpdatedMap, pIte, &iter)) != NULL) {
     taosArrayPush(pInfo->pUpdated, pIte);
   }
+
   tSimpleHashCleanup(pInfo->pUpdatedMap);
   pInfo->pUpdatedMap = NULL;
   taosArraySort(pInfo->pUpdated, winKeyCmprImpl);
@@ -2824,7 +2843,7 @@ void destroyStreamSessionAggOperatorInfo(void* param) {
     int32_t size = taosArrayGetSize(pInfo->pChildren);
     for (int32_t i = 0; i < size; i++) {
       SOperatorInfo* pChild = taosArrayGetP(pInfo->pChildren, i);
-      destroyOperatorInfo(pChild);
+      destroyOperator(pChild);
     }
     taosArrayDestroy(pInfo->pChildren);
   }
@@ -3801,7 +3820,7 @@ void destroyStreamStateOperatorInfo(void* param) {
     int32_t size = taosArrayGetSize(pInfo->pChildren);
     for (int32_t i = 0; i < size; i++) {
       SOperatorInfo* pChild = taosArrayGetP(pInfo->pChildren, i);
-      destroyOperatorInfo(pChild);
+      destroyOperator(pChild);
     }
     taosArrayDestroy(pInfo->pChildren);
   }
diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c
index da5f65fdf2..211f78b981 100644
--- a/source/libs/executor/src/tsort.c
+++ b/source/libs/executor/src/tsort.c
@@ -155,7 +155,7 @@ void tsortDestroySortHandle(SSortHandle* pSortHandle) {
 
   int64_t fetchUs = 0, fetchNum = 0;
   tsortClearOrderdSource(pSortHandle->pOrderedSource, &fetchUs, &fetchNum);
-  qError("all source fetch time: %" PRId64 "us num:%" PRId64 " %s", fetchUs, fetchNum, pSortHandle->idStr);
+  qDebug("all source fetch time: %" PRId64 "us num:%" PRId64 " %s", fetchUs, fetchNum, pSortHandle->idStr);
   
   taosArrayDestroy(pSortHandle->pOrderedSource);
   taosMemoryFreeClear(pSortHandle);
@@ -229,7 +229,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) {
     taosArrayPush(pPageIdList, &pageId);
 
     int32_t size = blockDataGetSize(p) + sizeof(int32_t) + taosArrayGetSize(p->pDataBlock) * sizeof(int32_t);
-    assert(size <= getBufPageSize(pHandle->pBuf));
+    ASSERT(size <= getBufPageSize(pHandle->pBuf));
 
     blockDataToBuf(pPage, p);
 
@@ -315,7 +315,7 @@ static int32_t sortComparInit(SMsortComparParam* pParam, SArray* pSources, int32
     }
 
     int64_t et = taosGetTimestampUs();
-    qError("init for merge sort completed, elapsed time:%.2f ms, %s", (et - st) / 1000.0, pHandle->idStr);
+    qDebug("init for merge sort completed, elapsed time:%.2f ms, %s", (et - st) / 1000.0, pHandle->idStr);
   }
 
   return code;
@@ -591,7 +591,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) {
 
         int32_t size =
             blockDataGetSize(pDataBlock) + sizeof(int32_t) + taosArrayGetSize(pDataBlock->pDataBlock) * sizeof(int32_t);
-        assert(size <= getBufPageSize(pHandle->pBuf));
+        ASSERT(size <= getBufPageSize(pHandle->pBuf));
 
         blockDataToBuf(pPage, pDataBlock);
 
diff --git a/source/libs/executor/test/executorTests.cpp b/source/libs/executor/test/executorTests.cpp
index b9a696170a..cefe12990d 100644
--- a/source/libs/executor/test/executorTests.cpp
+++ b/source/libs/executor/test/executorTests.cpp
@@ -24,15 +24,12 @@
 #include "os.h"
 
 #include "executor.h"
-#include "executorimpl.h"
+#include "executorInt.h"
 #include "function.h"
+#include "operator.h"
 #include "taos.h"
 #include "tdatablock.h"
 #include "tdef.h"
-#include "tglobal.h"
-#include "tmsg.h"
-#include "tname.h"
-#include "trpc.h"
 #include "tvariant.h"
 
 namespace {
diff --git a/source/libs/executor/test/lhashTests.cpp b/source/libs/executor/test/lhashTests.cpp
index 24570ff788..92f7652d8d 100644
--- a/source/libs/executor/test/lhashTests.cpp
+++ b/source/libs/executor/test/lhashTests.cpp
@@ -15,7 +15,7 @@
 
 #include 
 #include 
-#include "executorimpl.h"
+#include "executorInt.h"
 #include "tlinearhash.h"
 
 #pragma GCC diagnostic push
diff --git a/source/libs/executor/test/sortTests.cpp b/source/libs/executor/test/sortTests.cpp
index f35d07804e..8122d7d6a9 100644
--- a/source/libs/executor/test/sortTests.cpp
+++ b/source/libs/executor/test/sortTests.cpp
@@ -26,7 +26,7 @@
 #include "os.h"
 
 #include "executor.h"
-#include "executorimpl.h"
+#include "executorInt.h"
 #include "taos.h"
 #include "tcompare.h"
 #include "tdatablock.h"
diff --git a/source/libs/function/CMakeLists.txt b/source/libs/function/CMakeLists.txt
index 9d11d7b376..f23b4d3e87 100644
--- a/source/libs/function/CMakeLists.txt
+++ b/source/libs/function/CMakeLists.txt
@@ -79,6 +79,26 @@ ENDIF ()
 target_link_libraries(
     udf1 PUBLIC os ${LINK_JEMALLOC})
 
+
+add_library(udf1_dup STATIC MODULE test/udf1_dup.c)
+target_include_directories(
+        udf1_dup
+        PUBLIC
+            "${TD_SOURCE_DIR}/include/libs/function"
+            "${TD_SOURCE_DIR}/include/util"
+            "${TD_SOURCE_DIR}/include/common"
+            "${TD_SOURCE_DIR}/include/client"
+            "${TD_SOURCE_DIR}/include/os"
+        PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
+)
+
+IF (TD_LINUX_64 AND JEMALLOC_ENABLED)
+    ADD_DEPENDENCIES(udf1_dup jemalloc)
+ENDIF ()
+
+target_link_libraries(
+    udf1_dup PUBLIC os ${LINK_JEMALLOC})
+
 add_library(udf2 STATIC MODULE test/udf2.c)
 target_include_directories(
         udf2
@@ -99,6 +119,26 @@ target_link_libraries(
     udf2 PUBLIC os ${LINK_JEMALLOC}
 )
 
+add_library(udf2_dup STATIC MODULE test/udf2_dup.c)
+target_include_directories(
+        udf2_dup
+        PUBLIC
+            "${TD_SOURCE_DIR}/include/libs/function"
+            "${TD_SOURCE_DIR}/include/util"
+            "${TD_SOURCE_DIR}/include/common"
+            "${TD_SOURCE_DIR}/include/client"
+            "${TD_SOURCE_DIR}/include/os"
+        PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
+)
+
+IF (TD_LINUX_64 AND JEMALLOC_ENABLED)
+    ADD_DEPENDENCIES(udf2_dup jemalloc)
+ENDIF ()
+
+target_link_libraries(
+    udf2_dup PUBLIC os ${LINK_JEMALLOC}
+)
+
 #SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/build/bin)
 add_executable(udfd src/udfd.c)
 target_include_directories(
diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c
index 2b917389f9..4ef3c124ed 100644
--- a/source/libs/function/src/builtinsimpl.c
+++ b/source/libs/function/src/builtinsimpl.c
@@ -5576,7 +5576,7 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
   }
 
   int32_t len = sprintf(st + VARSTR_HEADER_SIZE,
-                        "Total_Blocks=[%d] Total_Size=[%.2f Kb] Average_size=[%.2f Kb] Compression_Ratio=[%.2f %c]",
+                        "Total_Blocks=[%d] Total_Size=[%.2f KB] Average_size=[%.2f KB] Compression_Ratio=[%.2f %c]",
                         pData->numOfBlocks, pData->totalSize / 1024.0, averageSize / 1024.0, compRatio, '%');
 
   varDataSetLen(st, len);
diff --git a/source/libs/function/test/udf1_dup.c b/source/libs/function/test/udf1_dup.c
new file mode 100644
index 0000000000..c251192da3
--- /dev/null
+++ b/source/libs/function/test/udf1_dup.c
@@ -0,0 +1,42 @@
+#include 
+#include 
+#include 
+#ifdef LINUX
+#include 
+#endif
+#ifdef WINDOWS
+#include 
+#endif
+#include "taosudf.h"
+
+
+DLL_EXPORT int32_t udf1_dup_init() { return 0; }
+
+DLL_EXPORT int32_t udf1_dup_destroy() { return 0; }
+
+DLL_EXPORT int32_t udf1_dup(SUdfDataBlock *block, SUdfColumn *resultCol) {
+  SUdfColumnData *resultData = &resultCol->colData;
+  for (int32_t i = 0; i < block->numOfRows; ++i) {
+    int j = 0;
+    for (; j < block->numOfCols; ++j) {
+      if (udfColDataIsNull(block->udfCols[j], i)) {
+        udfColDataSetNull(resultCol, i);
+        break;
+      }
+    }
+    if (j == block->numOfCols) {
+      int32_t luckyNum = 2;
+      udfColDataSet(resultCol, i, (char *)&luckyNum, false);
+    }
+  }
+  // to simulate actual processing delay by udf
+#ifdef LINUX
+  usleep(1 * 1000);  // usleep takes sleep time in us (1 millionth of a second)
+#endif
+#ifdef WINDOWS
+  Sleep(1);
+#endif
+  resultData->numOfRows = block->numOfRows;
+  return 0;
+}
+
diff --git a/source/libs/function/test/udf2_dup.c b/source/libs/function/test/udf2_dup.c
new file mode 100644
index 0000000000..1a98190823
--- /dev/null
+++ b/source/libs/function/test/udf2_dup.c
@@ -0,0 +1,78 @@
+#include 
+#include 
+#include 
+#include 
+
+#include "taosudf.h"
+
+DLL_EXPORT int32_t udf2_dup_init() { return 0; }
+
+DLL_EXPORT int32_t udf2_dup_destroy() { return 0; }
+
+DLL_EXPORT int32_t udf2_dup_start(SUdfInterBuf* buf) {
+  *(int64_t*)(buf->buf) = 0;
+  buf->bufLen = sizeof(double);
+  buf->numOfResult = 1;
+  return 0;
+}
+
+DLL_EXPORT int32_t udf2_dup(SUdfDataBlock* block, SUdfInterBuf* interBuf, SUdfInterBuf* newInterBuf) {
+  double sumSquares = 0;
+  if (interBuf->numOfResult == 1) {
+    sumSquares = *(double*)interBuf->buf;
+  }
+  int8_t numNotNull = 0;
+  for (int32_t i = 0; i < block->numOfCols; ++i) {
+    SUdfColumn* col = block->udfCols[i];
+    if (!(col->colMeta.type == TSDB_DATA_TYPE_INT || col->colMeta.type == TSDB_DATA_TYPE_DOUBLE)) {
+      return TSDB_CODE_UDF_INVALID_INPUT;
+    }
+  }
+  for (int32_t i = 0; i < block->numOfCols; ++i) {
+    for (int32_t j = 0; j < block->numOfRows; ++j) {
+      SUdfColumn* col = block->udfCols[i];
+      if (udfColDataIsNull(col, j)) {
+        continue;
+      }
+      switch (col->colMeta.type) {
+        case TSDB_DATA_TYPE_INT: {
+          char*   cell = udfColDataGetData(col, j);
+          int32_t num = *(int32_t*)cell;
+          sumSquares += (double)num * num;
+          break;
+        }
+        case TSDB_DATA_TYPE_DOUBLE: {
+          char*  cell = udfColDataGetData(col, j);
+          double num = *(double*)cell;
+          sumSquares += num * num;
+          break;
+        }
+        default:
+          break;
+      }
+      ++numNotNull;
+    }
+  }
+
+  *(double*)(newInterBuf->buf) = sumSquares;
+  newInterBuf->bufLen = sizeof(double);
+
+  if (interBuf->numOfResult == 0 && numNotNull == 0) {
+    newInterBuf->numOfResult = 0;
+  } else {
+    newInterBuf->numOfResult = 1;
+  }
+  return 0;
+}
+
+DLL_EXPORT int32_t udf2_dup_finish(SUdfInterBuf* buf, SUdfInterBuf* resultData) {
+  if (buf->numOfResult == 0) {
+    resultData->numOfResult = 0;
+    return 0;
+  }
+  double sumSquares = *(double*)(buf->buf);
+  *(double*)(resultData->buf) = sqrt(sumSquares) + 100;
+  resultData->bufLen = sizeof(double);
+  resultData->numOfResult = 1;
+  return 0;
+}
diff --git a/source/libs/index/src/indexFilter.c b/source/libs/index/src/indexFilter.c
index ec5fc5ad2a..02ed0d2d05 100644
--- a/source/libs/index/src/indexFilter.c
+++ b/source/libs/index/src/indexFilter.c
@@ -221,6 +221,71 @@ static FORCE_INLINE int32_t sifInitJsonParam(SNode *node, SIFParam *param, SIFCt
   param->status = SFLT_COARSE_INDEX;
   return 0;
 }
+static int32_t sifNeedConvertCond(SNode *l, SNode *r) {
+  if (nodeType(l) != QUERY_NODE_COLUMN || nodeType(r) != QUERY_NODE_VALUE) {
+    return 0;
+  }
+  SColumnNode *c = (SColumnNode *)l;
+  SValueNode  *v = (SValueNode *)r;
+  int32_t      ctype = c->node.resType.type;
+  int32_t      vtype = v->node.resType.type;
+  if (!IS_VAR_DATA_TYPE(ctype) && IS_VAR_DATA_TYPE(vtype)) {
+    return 1;
+  }
+  return 0;
+}
+static int32_t sifInitParamValByCol(SNode *r, SNode *l, SIFParam *param, SIFCtx *ctx) {
+  param->status = SFLT_COARSE_INDEX;
+  SColumnNode *cn = (SColumnNode *)r;
+  SValueNode  *vn = (SValueNode *)l;
+  if (vn->typeData == TSDB_DATA_TYPE_NULL && (vn->literal == NULL || strlen(vn->literal) == 0)) {
+    param->status = SFLT_NOT_INDEX;
+    return 0;
+  }
+  SDataType *pType = &cn->node.resType;
+  int32_t    type = pType->type;
+
+  SDataType *pVType = &vn->node.resType;
+  int32_t    vtype = pVType->type;
+  char      *pData = nodesGetValueFromNode(vn);
+  int32_t    valLen = 0;
+  char     **value = ¶m->condValue;
+
+  if (IS_VAR_DATA_TYPE(type)) {
+    int32_t dataLen = varDataTLen(pData);
+    if (type == TSDB_DATA_TYPE_JSON) {
+      if (*pData == TSDB_DATA_TYPE_NULL) {
+        dataLen = 0;
+      } else if (*pData == TSDB_DATA_TYPE_NCHAR) {
+        dataLen = varDataTLen(pData);
+      } else if (*pData == TSDB_DATA_TYPE_DOUBLE) {
+        dataLen = LONG_BYTES;
+      } else if (*pData == TSDB_DATA_TYPE_BOOL) {
+        dataLen = CHAR_BYTES;
+      }
+      dataLen += CHAR_BYTES;
+    }
+    valLen = dataLen;
+  } else {
+    valLen = pType->bytes;
+  }
+  char *tv = taosMemoryCalloc(1, valLen + 1);
+  if (tv == NULL) {
+    return TSDB_CODE_OUT_OF_MEMORY;
+  }
+
+  memcpy(tv, pData, valLen);
+  *value = tv;
+
+  param->colId = -1;
+  param->colValType = (uint8_t)(vn->node.resType.type);
+  if (vn->literal != NULL && strlen(vn->literal) <= sizeof(param->colName)) {
+    memcpy(param->colName, vn->literal, strlen(vn->literal));
+  } else {
+    param->status = SFLT_NOT_INDEX;
+  }
+  return 0;
+}
 static int32_t sifInitParam(SNode *node, SIFParam *param, SIFCtx *ctx) {
   param->status = SFLT_COARSE_INDEX;
   switch (nodeType(node)) {
@@ -317,8 +382,13 @@ static int32_t sifInitOperParams(SIFParam **params, SOperatorNode *node, SIFCtx
     return TSDB_CODE_SUCCESS;
   } else {
     SIF_ERR_JRET(sifInitParam(node->pLeft, ¶mList[0], ctx));
+
     if (nParam > 1) {
+      // if (sifNeedConvertCond(node->pLeft, node->pRight)) {
+      // SIF_ERR_JRET(sifInitParamValByCol(node->pLeft, node->pRight, ¶mList[1], ctx));
+      // } else {
       SIF_ERR_JRET(sifInitParam(node->pRight, ¶mList[1], ctx));
+      // }
       // if (paramList[0].colValType == TSDB_DATA_TYPE_JSON &&
       //    ((SOperatorNode *)(node))->opType == OP_TYPE_JSON_CONTAINS) {
       //  return TSDB_CODE_OUT_OF_MEMORY;
@@ -404,60 +474,149 @@ static FORCE_INLINE FilterFunc sifGetFilterFunc(EIndexQueryType type, bool *reve
   }
   return NULL;
 }
+int32_t sifStr2Num(char *buf, int32_t len, int8_t type, void *val) {
+  // signed/unsigned/float
+  if (IS_SIGNED_NUMERIC_TYPE(type)) {
+    int64_t v = 0;
+    if (0 != toInteger(buf, len, 10, &v)) {
+      return -1;
+    }
+    if (type == TSDB_DATA_TYPE_BIGINT) {
+      *(int64_t *)val = v;
+    } else if (type == TSDB_DATA_TYPE_INT) {
+      *(int32_t *)val = v;
+    } else if (type == TSDB_DATA_TYPE_TINYINT) {
+      *(int8_t *)val = v;
+    } else if (type == TSDB_DATA_TYPE_SMALLINT) {
+      *(int16_t *)val = v;
+    }
+  } else if (IS_FLOAT_TYPE(type)) {
+    if (type == TSDB_DATA_TYPE_FLOAT) {
+      *(float *)val = taosStr2Float(buf, NULL);
+    } else {
+      *(double *)val = taosStr2Double(buf, NULL);
+    }
+  } else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
+    uint64_t v = 0;
+    if (0 != toUInteger(buf, len, 10, &v)) {
+      return -1;
+    }
+    if (type == TSDB_DATA_TYPE_UBIGINT) {
+      *(uint64_t *)val = v;
+    } else if (type == TSDB_DATA_TYPE_UINT) {
+      *(uint32_t *)val = v;
+    } else if (type == TSDB_DATA_TYPE_UTINYINT) {
+      *(uint8_t *)val = v;
+    } else if (type == TSDB_DATA_TYPE_USMALLINT) {
+      *(uint16_t *)val = v;
+    }
+  } else {
+    return -1;
+  }
+  return 0;
+}
 
-static void sifSetFltParam(SIFParam *left, SIFParam *right, SDataTypeBuf *typedata, SMetaFltParam *param) {
-  int8_t ltype = left->colValType, rtype = right->colValType;
+static int32_t sifSetFltParam(SIFParam *left, SIFParam *right, SDataTypeBuf *typedata, SMetaFltParam *param) {
+  int32_t code = 0;
+  int8_t  ltype = left->colValType, rtype = right->colValType;
+  if (!IS_NUMERIC_TYPE(ltype) || !((IS_NUMERIC_TYPE(rtype)) || rtype == TSDB_DATA_TYPE_VARCHAR)) {
+    return -1;
+  }
   if (ltype == TSDB_DATA_TYPE_FLOAT) {
     float f = 0;
-    SIF_DATA_CONVERT(rtype, right->condValue, f);
+    if (IS_NUMERIC_TYPE(rtype)) {
+      SIF_DATA_CONVERT(rtype, right->condValue, f);
+    } else {
+      SIF_ERR_RET(sifStr2Num(varDataVal(right->condValue), varDataLen(right->condValue), TSDB_DATA_TYPE_FLOAT, &f));
+    }
     typedata->f = f;
     param->val = &typedata->f;
   } else if (ltype == TSDB_DATA_TYPE_DOUBLE) {
     double d = 0;
-    SIF_DATA_CONVERT(rtype, right->condValue, d);
+    if (IS_NUMERIC_TYPE(rtype)) {
+      SIF_DATA_CONVERT(rtype, right->condValue, d);
+    } else {
+      SIF_ERR_RET(sifStr2Num(varDataVal(right->condValue), varDataLen(right->condValue), TSDB_DATA_TYPE_DOUBLE, &d));
+    }
     typedata->d = d;
     param->val = &typedata->d;
   } else if (ltype == TSDB_DATA_TYPE_BIGINT) {
     int64_t i64 = 0;
-    SIF_DATA_CONVERT(rtype, right->condValue, i64);
+    if (IS_NUMERIC_TYPE(rtype)) {
+      SIF_DATA_CONVERT(rtype, right->condValue, i64);
+    } else {
+      SIF_ERR_RET(sifStr2Num(varDataVal(right->condValue), varDataLen(right->condValue), TSDB_DATA_TYPE_BIGINT, &i64));
+    }
     typedata->i64 = i64;
     param->val = &typedata->i64;
   } else if (ltype == TSDB_DATA_TYPE_INT) {
     int32_t i32 = 0;
-    SIF_DATA_CONVERT(rtype, right->condValue, i32);
+    if (IS_NUMERIC_TYPE(rtype)) {
+      SIF_DATA_CONVERT(rtype, right->condValue, i32);
+    } else {
+      SIF_ERR_RET(sifStr2Num(varDataVal(right->condValue), varDataLen(right->condValue), TSDB_DATA_TYPE_INT, &i32));
+    }
     typedata->i32 = i32;
     param->val = &typedata->i32;
   } else if (ltype == TSDB_DATA_TYPE_SMALLINT) {
     int16_t i16 = 0;
-    SIF_DATA_CONVERT(rtype, right->condValue, i16);
+    if (IS_NUMERIC_TYPE(rtype)) {
+      SIF_DATA_CONVERT(rtype, right->condValue, i16);
+    } else {
+      SIF_ERR_RET(
+          sifStr2Num(varDataVal(right->condValue), varDataLen(right->condValue), TSDB_DATA_TYPE_SMALLINT, &i16));
+    }
+
     typedata->i16 = i16;
     param->val = &typedata->i16;
   } else if (ltype == TSDB_DATA_TYPE_TINYINT) {
     int8_t i8 = 0;
-    SIF_DATA_CONVERT(rtype, right->condValue, i8)
+    if (IS_NUMERIC_TYPE(rtype)) {
+      SIF_DATA_CONVERT(rtype, right->condValue, i8);
+    } else {
+      SIF_ERR_RET(sifStr2Num(varDataVal(right->condValue), varDataLen(right->condValue), TSDB_DATA_TYPE_TINYINT, &i8));
+    }
     typedata->i8 = i8;
     param->val = &typedata->i8;
   } else if (ltype == TSDB_DATA_TYPE_UBIGINT) {
     uint64_t u64 = 0;
-    SIF_DATA_CONVERT(rtype, right->condValue, u64);
+    if (IS_NUMERIC_TYPE(rtype)) {
+      SIF_DATA_CONVERT(rtype, right->condValue, u64);
+    } else {
+      SIF_ERR_RET(sifStr2Num(varDataVal(right->condValue), varDataLen(right->condValue), TSDB_DATA_TYPE_UBIGINT, &u64));
+    }
     typedata->u64 = u64;
     param->val = &typedata->u64;
   } else if (ltype == TSDB_DATA_TYPE_UINT) {
     uint32_t u32 = 0;
-    SIF_DATA_CONVERT(rtype, right->condValue, u32);
+    if (IS_NUMERIC_TYPE(rtype)) {
+      SIF_DATA_CONVERT(rtype, right->condValue, u32);
+    } else {
+      SIF_ERR_RET(sifStr2Num(varDataVal(right->condValue), varDataLen(right->condValue), TSDB_DATA_TYPE_UINT, &u32));
+    }
     typedata->u32 = u32;
     param->val = &typedata->u32;
   } else if (ltype == TSDB_DATA_TYPE_USMALLINT) {
     uint16_t u16 = 0;
-    SIF_DATA_CONVERT(rtype, right->condValue, u16);
+    if (IS_NUMERIC_TYPE(rtype)) {
+      SIF_DATA_CONVERT(rtype, right->condValue, u16);
+    } else {
+      SIF_ERR_RET(
+          sifStr2Num(varDataVal(right->condValue), varDataLen(right->condValue), TSDB_DATA_TYPE_USMALLINT, &u16));
+    }
     typedata->u16 = u16;
     param->val = &typedata->u16;
   } else if (ltype == TSDB_DATA_TYPE_UTINYINT) {
     uint8_t u8 = 0;
-    SIF_DATA_CONVERT(rtype, right->condValue, u8);
+    if (IS_NUMERIC_TYPE(rtype)) {
+      SIF_DATA_CONVERT(rtype, right->condValue, u8);
+    } else {
+      SIF_ERR_RET(sifStr2Num(varDataVal(right->condValue), varDataLen(right->condValue), TSDB_DATA_TYPE_UTINYINT, &u8));
+    }
     typedata->u8 = u8;
     param->val = &typedata->u8;
   }
+  return 0;
 }
 static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFParam *output) {
   int             ret = 0;
@@ -498,7 +657,7 @@ static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFP
         param.val = buf;
       }
     } else {
-      sifSetFltParam(left, right, &typedata, ¶m);
+      if (sifSetFltParam(left, right, &typedata, ¶m) != 0) return -1;
     }
     ret = metaFilterTableIds(arg->metaEx, ¶m, output->result);
   }
diff --git a/source/libs/index/src/indexFstDfa.c b/source/libs/index/src/indexFstDfa.c
index 4d348e76f2..a3e26d8518 100644
--- a/source/libs/index/src/indexFstDfa.c
+++ b/source/libs/index/src/indexFstDfa.c
@@ -188,7 +188,6 @@ void dfaAdd(FstDfa *dfa, FstSparseSet *set, uint32_t ip) {
     return;
   }
   bool succ = sparSetAdd(set, ip, NULL);
-  // assert(succ == true);
   Inst *inst = taosArrayGet(dfa->insts, ip);
   if (inst->ty == MATCH || inst->ty == RANGE) {
     // do nothing
diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c
index 5874093ea6..73e4968c9a 100644
--- a/source/libs/nodes/src/nodesUtilFuncs.c
+++ b/source/libs/nodes/src/nodesUtilFuncs.c
@@ -832,6 +832,8 @@ void nodesDestroyNode(SNode* pNode) {
       SVnodeModifyOpStmt* pStmt = (SVnodeModifyOpStmt*)pNode;
       destroyVgDataBlockArray(pStmt->pDataBlocks);
       taosMemoryFreeClear(pStmt->pTableMeta);
+      nodesDestroyNode(pStmt->pTagCond);
+      taosArrayDestroy(pStmt->pTableTag);
       taosHashCleanup(pStmt->pVgroupsHashObj);
       taosHashCleanup(pStmt->pSubTableHashObj);
       taosHashCleanup(pStmt->pTableNameHashObj);
@@ -958,8 +960,12 @@ void nodesDestroyNode(SNode* pNode) {
       break;
     case QUERY_NODE_SPLIT_VGROUP_STMT:  // no pointer field
     case QUERY_NODE_SYNCDB_STMT:        // no pointer field
-    case QUERY_NODE_GRANT_STMT:         // no pointer field
-    case QUERY_NODE_REVOKE_STMT:        // no pointer field
+      break;
+    case QUERY_NODE_GRANT_STMT:
+      nodesDestroyNode(((SGrantStmt*)pNode)->pTagCond);
+      break;
+    case QUERY_NODE_REVOKE_STMT:
+      nodesDestroyNode(((SRevokeStmt*)pNode)->pTagCond);
       break;
     case QUERY_NODE_SHOW_DNODES_STMT:
     case QUERY_NODE_SHOW_MNODES_STMT:
diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y
index d418415644..c57e738bfa 100755
--- a/source/libs/parser/inc/sql.y
+++ b/source/libs/parser/inc/sql.y
@@ -227,8 +227,8 @@ db_options(A) ::= db_options(B) WAL_RETENTION_SIZE NK_MINUS(D) NK_INTEGER(C).
 db_options(A) ::= db_options(B) WAL_ROLL_PERIOD NK_INTEGER(C).                    { A = setDatabaseOption(pCxt, B, DB_OPTION_WAL_ROLL_PERIOD, &C); }
 db_options(A) ::= db_options(B) WAL_SEGMENT_SIZE NK_INTEGER(C).                   { A = setDatabaseOption(pCxt, B, DB_OPTION_WAL_SEGMENT_SIZE, &C); }
 db_options(A) ::= db_options(B) STT_TRIGGER NK_INTEGER(C).                        { A = setDatabaseOption(pCxt, B, DB_OPTION_STT_TRIGGER, &C); }
-db_options(A) ::= db_options(B) TABLE_PREFIX NK_INTEGER(C).                       { A = setDatabaseOption(pCxt, B, DB_OPTION_TABLE_PREFIX, &C); }
-db_options(A) ::= db_options(B) TABLE_SUFFIX NK_INTEGER(C).                       { A = setDatabaseOption(pCxt, B, DB_OPTION_TABLE_SUFFIX, &C); }
+db_options(A) ::= db_options(B) TABLE_PREFIX signed(C).                           { A = setDatabaseOption(pCxt, B, DB_OPTION_TABLE_PREFIX, C); }
+db_options(A) ::= db_options(B) TABLE_SUFFIX signed(C).                           { A = setDatabaseOption(pCxt, B, DB_OPTION_TABLE_SUFFIX, C); }
 
 alter_db_options(A) ::= alter_db_option(B).                                       { A = createAlterDatabaseOptions(pCxt); A = setAlterDatabaseOption(pCxt, A, &B); }
 alter_db_options(A) ::= alter_db_options(B) alter_db_option(C).                   { A = setAlterDatabaseOption(pCxt, B, &C); }
diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c
index a0c17add27..c6833c5df1 100644
--- a/source/libs/parser/src/parAstCreater.c
+++ b/source/libs/parser/src/parAstCreater.c
@@ -1024,12 +1024,28 @@ static SNode* setDatabaseOptionImpl(SAstCreateContext* pCxt, SNode* pOptions, ED
     case DB_OPTION_STT_TRIGGER:
       pDbOptions->sstTrigger = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
       break;
-    case DB_OPTION_TABLE_PREFIX:
-      pDbOptions->tablePrefix = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
+    case DB_OPTION_TABLE_PREFIX: {
+      SValueNode *pNode = (SValueNode *)pVal;
+      if (TSDB_DATA_TYPE_BIGINT == pNode->node.resType.type || TSDB_DATA_TYPE_UBIGINT == pNode->node.resType.type) {
+        pDbOptions->tablePrefix = taosStr2Int32(pNode->literal, NULL, 10);
+      } else {
+        snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid table_prefix data type");
+        pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;        
+      }
+      nodesDestroyNode((SNode*)pNode);
       break;
-    case DB_OPTION_TABLE_SUFFIX:
-      pDbOptions->tableSuffix = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
+    }
+    case DB_OPTION_TABLE_SUFFIX:{
+      SValueNode *pNode = (SValueNode *)pVal;
+      if (TSDB_DATA_TYPE_BIGINT == pNode->node.resType.type || TSDB_DATA_TYPE_UBIGINT == pNode->node.resType.type) {
+        pDbOptions->tableSuffix = taosStr2Int32(pNode->literal, NULL, 10);
+      } else {
+        snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid table_suffix data type");
+        pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;        
+      }
+      nodesDestroyNode((SNode*)pNode);
       break;
+    }
     default:
       break;
   }
diff --git a/source/libs/parser/src/parAuthenticator.c b/source/libs/parser/src/parAuthenticator.c
index b06d48a690..1586d8128b 100644
--- a/source/libs/parser/src/parAuthenticator.c
+++ b/source/libs/parser/src/parAuthenticator.c
@@ -70,7 +70,7 @@ static EDealRes authSubquery(SAuthCxt* pCxt, SNode* pStmt) {
   return TSDB_CODE_SUCCESS == authQuery(pCxt, pStmt) ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
 }
 
-static int32_t mergeStableTagCond(SNode** pWhere, SNode** pTagCond) {
+static int32_t mergeStableTagCond(SNode** pWhere, SNode* pTagCond) {
   SLogicConditionNode* pLogicCond = (SLogicConditionNode*)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
   if (NULL == pLogicCond) {
     return TSDB_CODE_OUT_OF_MEMORY;
@@ -78,7 +78,7 @@ static int32_t mergeStableTagCond(SNode** pWhere, SNode** pTagCond) {
   pLogicCond->node.resType.type = TSDB_DATA_TYPE_BOOL;
   pLogicCond->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes;
   pLogicCond->condType = LOGIC_COND_TYPE_AND;
-  int32_t code = nodesListMakeStrictAppend(&pLogicCond->pParameterList, *pTagCond);
+  int32_t code = nodesListMakeStrictAppend(&pLogicCond->pParameterList, pTagCond);
   if (TSDB_CODE_SUCCESS == code) {
     code = nodesListMakeAppend(&pLogicCond->pParameterList, *pWhere);
   }
@@ -106,7 +106,7 @@ static int32_t appendStableTagCond(SNode** pWhere, SNode* pTagCond) {
     return nodesListStrictAppend(((SLogicConditionNode*)*pWhere)->pParameterList, pTagCondCopy);
   }
 
-  return mergeStableTagCond(pWhere, &pTagCondCopy);
+  return mergeStableTagCond(pWhere, pTagCondCopy);
 }
 
 static EDealRes authSelectImpl(SNode* pNode, void* pContext) {
diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c
index c25d0e7036..01b62a9051 100644
--- a/source/libs/parser/src/parCalcConst.c
+++ b/source/libs/parser/src/parCalcConst.c
@@ -388,6 +388,9 @@ static bool isSetUselessCol(SSetOperator* pSetOp, int32_t index, SExprNode* pPro
 }
 
 static int32_t calcConstSetOpProjections(SCalcConstContext* pCxt, SSetOperator* pSetOp, bool subquery) {
+  if (subquery && pSetOp->opType == SET_OP_TYPE_UNION) {
+    return TSDB_CODE_SUCCESS;
+  }
   int32_t index = 0;
   SNode*  pProj = NULL;
   WHERE_EACH(pProj, pSetOp->pProjectionList) {
diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c
index eb2efd573d..02de9f227d 100644
--- a/source/libs/parser/src/parInsertSql.c
+++ b/source/libs/parser/src/parInsertSql.c
@@ -53,6 +53,7 @@ typedef struct SInsertParseContext {
   bool           missCache;
   bool           usingDuplicateTable;
   bool           forceUpdate;
+  bool           needTableTagVal;
 } SInsertParseContext;
 
 typedef int32_t (*_row_append_fn_t)(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param);
@@ -577,28 +578,39 @@ static int32_t rewriteTagCondColumnImpl(STagVal* pVal, SNode** pNode) {
   if (NULL == pValue) {
     return TSDB_CODE_OUT_OF_MEMORY;
   }
-  pValue->node.resType.type = pVal->type;
+
+  pValue->node.resType = ((SColumnNode*)*pNode)->node.resType;
+  nodesDestroyNode(*pNode);
+  *pNode = (SNode*)pValue;
+
   switch (pVal->type) {
     case TSDB_DATA_TYPE_BOOL:
       pValue->datum.b = *(int8_t*)(&pVal->i64);
+      *(bool*)&pValue->typeData = pValue->datum.b;
       break;
     case TSDB_DATA_TYPE_TINYINT:
       pValue->datum.i = *(int8_t*)(&pVal->i64);
+      *(int8_t*)&pValue->typeData = pValue->datum.i;
       break;
     case TSDB_DATA_TYPE_SMALLINT:
       pValue->datum.i = *(int16_t*)(&pVal->i64);
+      *(int16_t*)&pValue->typeData = pValue->datum.i;
       break;
     case TSDB_DATA_TYPE_INT:
       pValue->datum.i = *(int32_t*)(&pVal->i64);
+      *(int32_t*)&pValue->typeData = pValue->datum.i;
       break;
     case TSDB_DATA_TYPE_BIGINT:
       pValue->datum.i = pVal->i64;
+      pValue->typeData = pValue->datum.i;
       break;
     case TSDB_DATA_TYPE_FLOAT:
       pValue->datum.d = *(float*)(&pVal->i64);
+      *(float*)&pValue->typeData = pValue->datum.d;
       break;
     case TSDB_DATA_TYPE_DOUBLE:
       pValue->datum.d = *(double*)(&pVal->i64);
+      *(double*)&pValue->typeData = pValue->datum.d;
       break;
     case TSDB_DATA_TYPE_VARCHAR:
     case TSDB_DATA_TYPE_NCHAR:
@@ -611,18 +623,23 @@ static int32_t rewriteTagCondColumnImpl(STagVal* pVal, SNode** pNode) {
       break;
     case TSDB_DATA_TYPE_TIMESTAMP:
       pValue->datum.i = pVal->i64;
+      pValue->typeData = pValue->datum.i;
       break;
     case TSDB_DATA_TYPE_UTINYINT:
       pValue->datum.i = *(uint8_t*)(&pVal->i64);
+      *(uint8_t*)&pValue->typeData = pValue->datum.i;
       break;
     case TSDB_DATA_TYPE_USMALLINT:
       pValue->datum.i = *(uint16_t*)(&pVal->i64);
+      *(uint16_t*)&pValue->typeData = pValue->datum.i;
       break;
     case TSDB_DATA_TYPE_UINT:
       pValue->datum.i = *(uint32_t*)(&pVal->i64);
+      *(uint32_t*)&pValue->typeData = pValue->datum.i;
       break;
     case TSDB_DATA_TYPE_UBIGINT:
       pValue->datum.i = *(uint64_t*)(&pVal->i64);
+      *(uint64_t*)&pValue->typeData = pValue->datum.i;
       break;
     case TSDB_DATA_TYPE_JSON:
     case TSDB_DATA_TYPE_VARBINARY:
@@ -667,16 +684,15 @@ static int32_t checkTagCondResult(SNode* pResult) {
                                                                                     : TSDB_CODE_PAR_PERMISSION_DENIED;
 }
 
-int32_t checkSubtablePrivilege(SArray* pTagVals, SArray* pTagName, SNode* pCond) {
-  int32_t code = setTagVal(pTagVals, pTagName, pCond);
-  SNode*  pNew = NULL;
+static int32_t checkSubtablePrivilege(SArray* pTagVals, SArray* pTagName, SNode** pCond) {
+  int32_t code = setTagVal(pTagVals, pTagName, *pCond);
   if (TSDB_CODE_SUCCESS == code) {
-    code = scalarCalculateConstants(pCond, &pNew);
+    code = scalarCalculateConstants(*pCond, pCond);
   }
   if (TSDB_CODE_SUCCESS == code) {
-    code = checkTagCondResult(pNew);
+    code = checkTagCondResult(*pCond);
   }
-  nodesDestroyNode(pNew);
+  NODES_DESTORY_NODE(*pCond);
   return code;
 }
 
@@ -716,6 +732,10 @@ static int32_t parseTagsClauseImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt
     }
   }
 
+  if (TSDB_CODE_SUCCESS == code && NULL != pStmt->pTagCond) {
+    code = checkSubtablePrivilege(pTagVals, pTagName, &pStmt->pTagCond);
+  }
+
   if (TSDB_CODE_SUCCESS == code && !isParseBindParam && !isJson) {
     code = tTagNew(pTagVals, 1, false, &pTag);
   }
@@ -843,7 +863,7 @@ static void setUserAuthInfo(SParseContext* pCxt, SName* pTbName, SUserAuthInfo*
   pInfo->type = AUTH_TYPE_WRITE;
 }
 
-static int32_t checkAuth(SParseContext* pCxt, SName* pTbName, bool* pMissCache) {
+static int32_t checkAuth(SParseContext* pCxt, SName* pTbName, bool* pMissCache, SNode** pTagCond) {
   int32_t       code = TSDB_CODE_SUCCESS;
   SUserAuthInfo authInfo = {0};
   setUserAuthInfo(pCxt, pTbName, &authInfo);
@@ -863,11 +883,28 @@ static int32_t checkAuth(SParseContext* pCxt, SName* pTbName, bool* pMissCache)
       *pMissCache = true;
     } else if (!authRes.pass) {
       code = TSDB_CODE_PAR_PERMISSION_DENIED;
+    } else if (NULL != authRes.pCond) {
+      *pTagCond = authRes.pCond;
     }
   }
   return code;
 }
 
+static int32_t checkAuthForTable(SParseContext* pCxt, SName* pTbName, bool* pMissCache, bool* pNeedTableTagVal) {
+  SNode*  pTagCond = NULL;
+  int32_t code = checkAuth(pCxt, pTbName, pMissCache, &pTagCond);
+  if (TSDB_CODE_SUCCESS == code) {
+    *pNeedTableTagVal = ((*pMissCache) || (NULL != pTagCond));
+    *pMissCache = (NULL != pTagCond);
+  }
+  nodesDestroyNode(pTagCond);
+  return code;
+}
+
+static int32_t checkAuthForStable(SParseContext* pCxt, SName* pTbName, bool* pMissCache, SNode** pTagCond) {
+  return checkAuth(pCxt, pTbName, pMissCache, pTagCond);
+}
+
 static int32_t getTableMeta(SInsertParseContext* pCxt, SName* pTbName, bool isStb, STableMeta** pTableMeta,
                             bool* pMissCache) {
   SParseContext* pComCxt = pCxt->pComCxt;
@@ -970,7 +1007,7 @@ static int32_t getTargetTableSchema(SInsertParseContext* pCxt, SVnodeModifyOpStm
     return TSDB_CODE_SUCCESS;
   }
 
-  int32_t code = checkAuth(pCxt->pComCxt, &pStmt->targetTableName, &pCxt->missCache);
+  int32_t code = checkAuthForTable(pCxt->pComCxt, &pStmt->targetTableName, &pCxt->missCache, &pCxt->needTableTagVal);
   if (TSDB_CODE_SUCCESS == code && !pCxt->missCache) {
     code = getTableMetaAndVgroup(pCxt, pStmt, &pCxt->missCache);
   }
@@ -993,7 +1030,7 @@ static int32_t getUsingTableSchema(SInsertParseContext* pCxt, SVnodeModifyOpStmt
     return TSDB_CODE_SUCCESS;
   }
 
-  int32_t code = checkAuth(pCxt->pComCxt, &pStmt->targetTableName, &pCxt->missCache);
+  int32_t code = checkAuthForStable(pCxt->pComCxt, &pStmt->usingTableName, &pCxt->missCache, &pStmt->pTagCond);
   if (TSDB_CODE_SUCCESS == code && !pCxt->missCache) {
     code = getTableMeta(pCxt, &pStmt->usingTableName, true, &pStmt->pTableMeta, &pCxt->missCache);
   }
@@ -1606,6 +1643,8 @@ static int32_t parseInsertTableClauseBottom(SInsertParseContext* pCxt, SVnodeMod
 static void resetEnvPreTable(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
   insDestroyBoundColInfo(&pCxt->tags);
   taosMemoryFreeClear(pStmt->pTableMeta);
+  nodesDestroyNode(pStmt->pTagCond);
+  taosArrayDestroy(pStmt->pTableTag);
   tdDestroySVCreateTbReq(pStmt->pCreateTblReq);
   taosMemoryFreeClear(pStmt->pCreateTblReq);
   pCxt->missCache = false;
@@ -1780,14 +1819,18 @@ static int32_t createInsertQuery(SInsertParseContext* pCxt, SQuery** pOutput) {
   return code;
 }
 
-static int32_t checkAuthFromMetaData(const SArray* pUsers) {
+static int32_t checkAuthFromMetaData(const SArray* pUsers, SNode** pTagCond) {
   if (1 != taosArrayGetSize(pUsers)) {
     return TSDB_CODE_FAILED;
   }
 
   SMetaRes* pRes = taosArrayGet(pUsers, 0);
   if (TSDB_CODE_SUCCESS == pRes->code) {
-    return (*(bool*)pRes->pRes) ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED;
+    SUserAuthRes* pAuth = pRes->pRes;
+    if (NULL != pAuth->pCond) {
+      *pTagCond = nodesCloneNode(pAuth->pCond);
+    }
+    return pAuth->pass ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED;
   }
   return pRes->code;
 }
@@ -1826,9 +1869,40 @@ static int32_t getTableVgroupFromMetaData(const SArray* pTables, SVnodeModifyOpS
                      sizeof(SVgroupInfo));
 }
 
+static int32_t buildTagNameFromMeta(STableMeta* pMeta, SArray** pTagName) {
+  *pTagName = taosArrayInit(pMeta->tableInfo.numOfTags, TSDB_COL_NAME_LEN);
+  if (NULL == *pTagName) {
+    return TSDB_CODE_OUT_OF_MEMORY;
+  }
+  SSchema* pSchema = getTableTagSchema(pMeta);
+  for (int32_t i = 0; i < pMeta->tableInfo.numOfTags; ++i) {
+    taosArrayPush(*pTagName, pSchema[i].name);
+  }
+  return TSDB_CODE_SUCCESS;
+}
+
+static int32_t checkSubtablePrivilegeForTable(const SArray* pTables, SVnodeModifyOpStmt* pStmt) {
+  if (1 != taosArrayGetSize(pTables)) {
+    return TSDB_CODE_FAILED;
+  }
+
+  SMetaRes* pRes = taosArrayGet(pTables, 0);
+  if (TSDB_CODE_SUCCESS != pRes->code) {
+    return pRes->code;
+  }
+
+  SArray* pTagName = NULL;
+  int32_t code = buildTagNameFromMeta(pStmt->pTableMeta, &pTagName);
+  if (TSDB_CODE_SUCCESS == code) {
+    code = checkSubtablePrivilege((SArray*)pRes->pRes, pTagName, &pStmt->pTagCond);
+  }
+  taosArrayDestroy(pTagName);
+  return code;
+}
+
 static int32_t getTableSchemaFromMetaData(SInsertParseContext* pCxt, const SMetaData* pMetaData,
                                           SVnodeModifyOpStmt* pStmt, bool isStb) {
-  int32_t code = checkAuthFromMetaData(pMetaData->pUser);
+  int32_t code = checkAuthFromMetaData(pMetaData->pUser, &pStmt->pTagCond);
   if (TSDB_CODE_SUCCESS == code) {
     code = getTableMetaFromMetaData(pMetaData->pTableMeta, &pStmt->pTableMeta);
   }
@@ -1841,6 +1915,9 @@ static int32_t getTableSchemaFromMetaData(SInsertParseContext* pCxt, const SMeta
   if (TSDB_CODE_SUCCESS == code) {
     code = getTableVgroupFromMetaData(pMetaData->pTableHash, pStmt, isStb);
   }
+  if (TSDB_CODE_SUCCESS == code && !isStb && NULL != pStmt->pTagCond) {
+    code = checkSubtablePrivilegeForTable(pMetaData->pTableTag, pStmt);
+  }
   return code;
 }
 
@@ -1860,6 +1937,8 @@ static void clearCatalogReq(SCatalogReq* pCatalogReq) {
   pCatalogReq->pTableHash = NULL;
   taosArrayDestroy(pCatalogReq->pUser);
   pCatalogReq->pUser = NULL;
+  taosArrayDestroy(pCatalogReq->pTableTag);
+  pCatalogReq->pTableTag = NULL;
 }
 
 static int32_t setVnodeModifOpStmt(SInsertParseContext* pCxt, SCatalogReq* pCatalogReq, const SMetaData* pMetaData,
@@ -2033,8 +2112,15 @@ static int32_t buildInsertUserAuthReq(const char* pUser, SName* pName, SArray**
   return TSDB_CODE_SUCCESS;
 }
 
+static int32_t buildInsertTableTagReq(SName* pName, SArray** pTables) { return buildInsertTableReq(pName, pTables); }
+
 static int32_t buildInsertCatalogReq(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, SCatalogReq* pCatalogReq) {
-  int32_t code = buildInsertUserAuthReq(pCxt->pComCxt->pUser, &pStmt->targetTableName, &pCatalogReq->pUser);
+  int32_t code = buildInsertUserAuthReq(
+      pCxt->pComCxt->pUser, (0 == pStmt->usingTableName.type ? &pStmt->targetTableName : &pStmt->usingTableName),
+      &pCatalogReq->pUser);
+  if (TSDB_CODE_SUCCESS == code && pCxt->needTableTagVal) {
+    code = buildInsertTableTagReq(&pStmt->targetTableName, &pCatalogReq->pTableTag);
+  }
   if (TSDB_CODE_SUCCESS == code) {
     if (0 == pStmt->usingTableName.type) {
       code = buildInsertDbReq(&pStmt->targetTableName, &pCatalogReq->pTableMeta);
diff --git a/source/libs/parser/src/parInsertUtil.c b/source/libs/parser/src/parInsertUtil.c
index ac504b9809..f921094752 100644
--- a/source/libs/parser/src/parInsertUtil.c
+++ b/source/libs/parser/src/parInsertUtil.c
@@ -313,7 +313,7 @@ void insDestroyTableDataCxt(STableDataCxt* pTableCxt) {
   insDestroyBoundColInfo(&pTableCxt->boundColsInfo);
   taosArrayDestroyEx(pTableCxt->pValues, destroyColVal);
   if (pTableCxt->pData) {
-    tDestroySSubmitTbData(pTableCxt->pData, TSDB_MSG_FLG_ENCODE);
+    tDestroySubmitTbData(pTableCxt->pData, TSDB_MSG_FLG_ENCODE);
     taosMemoryFree(pTableCxt->pData);
   }
   taosMemoryFree(pTableCxt);
@@ -324,7 +324,7 @@ void insDestroyVgroupDataCxt(SVgroupDataCxt* pVgCxt) {
     return;
   }
 
-  tDestroySSubmitReq2(pVgCxt->pData, TSDB_MSG_FLG_ENCODE);
+  tDestroySubmitReq(pVgCxt->pData, TSDB_MSG_FLG_ENCODE);
   taosMemoryFree(pVgCxt->pData);
   taosMemoryFree(pVgCxt);
 }
@@ -499,7 +499,7 @@ static int32_t buildSubmitReq(int32_t vgId, SSubmitReq2* pReq, void** pData, uin
   int32_t  code = TSDB_CODE_SUCCESS;
   uint32_t len = 0;
   void*    pBuf = NULL;
-  tEncodeSize(tEncodeSSubmitReq2, pReq, len, code);
+  tEncodeSize(tEncodeSubmitReq, pReq, len, code);
   if (TSDB_CODE_SUCCESS == code) {
     SEncoder encoder;
     len += sizeof(SSubmitReq2Msg);
@@ -511,7 +511,7 @@ static int32_t buildSubmitReq(int32_t vgId, SSubmitReq2* pReq, void** pData, uin
     ((SSubmitReq2Msg*)pBuf)->header.contLen = htonl(len);
     ((SSubmitReq2Msg*)pBuf)->version = htobe64(1);
     tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SSubmitReq2Msg)), len - sizeof(SSubmitReq2Msg));
-    code = tEncodeSSubmitReq2(&encoder, pReq);
+    code = tEncodeSubmitReq(&encoder, pReq);
     tEncoderClear(&encoder);
   }
 
diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c
index 57f77d42ad..3967314aa3 100644
--- a/source/libs/parser/src/parTokenizer.c
+++ b/source/libs/parser/src/parTokenizer.c
@@ -694,7 +694,7 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr, bool* pIgnoreC
     len = tGetToken(&str[*i + t0.n + 1], &type);
 
     // only id and string are valid
-    if ((TK_NK_STRING != t0.type) && (TK_NK_ID != t0.type)) {
+    if (((TK_NK_STRING != t0.type) && (TK_NK_ID != t0.type)) || ((TK_NK_STRING != type) && (TK_NK_ID != type))) {
       t0.type = TK_NK_ILLEGAL;
       t0.n = 0;
 
diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c
index 48fc8c6a9c..b1fe49c83a 100644
--- a/source/libs/parser/src/parTranslater.c
+++ b/source/libs/parser/src/parTranslater.c
@@ -30,6 +30,11 @@
 
 #define SYSTABLE_SHOW_TYPE_OFFSET QUERY_NODE_SHOW_DNODES_STMT
 
+typedef struct SRewriteTbNameContext {
+  int32_t          errCode;
+  char*            pTbName;
+} SRewriteTbNameContext;
+
 typedef struct STranslateContext {
   SParseContext*   pParseCxt;
   int32_t          errCode;
@@ -2558,6 +2563,64 @@ static int32_t setTableCacheLastMode(STranslateContext* pCxt, SSelectStmt* pSele
   return code;
 }
 
+static EDealRes doTranslateTbName(SNode** pNode, void* pContext) {
+  switch (nodeType(*pNode)) {
+    case QUERY_NODE_FUNCTION: {
+      SFunctionNode *pFunc = (SFunctionNode *)*pNode;
+      if (FUNCTION_TYPE_TBNAME == pFunc->funcType) {
+        SRewriteTbNameContext *pCxt = (SRewriteTbNameContext*)pContext;
+        SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
+        if (NULL == pVal) {
+          pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
+          return DEAL_RES_ERROR;
+        }
+
+        int32_t tbLen = strlen(pCxt->pTbName);
+        pVal->literal = taosStrdup(pCxt->pTbName);
+        if (NULL == pVal->literal) {
+          pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY;
+          return DEAL_RES_ERROR;
+        }
+        pVal->isDuration = false;
+        pVal->translate = true;
+        pVal->node.resType.type = TSDB_DATA_TYPE_BINARY;
+        pVal->node.resType.bytes = tbLen + VARSTR_HEADER_SIZE;
+        pVal->datum.p = taosMemoryCalloc(1, tbLen + VARSTR_HEADER_SIZE + 1);
+        varDataSetLen(pVal->datum.p, tbLen);
+        strncpy(varDataVal(pVal->datum.p), pVal->literal, tbLen);
+        strcpy(pVal->node.userAlias, pFunc->node.userAlias);
+        strcpy(pVal->node.aliasName, pFunc->node.aliasName);
+
+        nodesDestroyNode(*pNode);
+        *pNode = (SNode*)pVal;
+      }
+      break;
+    }
+    default:
+      break;
+  }
+  return DEAL_RES_CONTINUE;
+}
+
+static int32_t replaceTbName(STranslateContext* pCxt, SSelectStmt* pSelect) {
+  if (QUERY_NODE_REAL_TABLE != nodeType(pSelect->pFromTable)) {
+    return TSDB_CODE_SUCCESS;
+  }
+
+  SRealTableNode* pTable = (SRealTableNode*)pSelect->pFromTable;
+  if (TSDB_CHILD_TABLE != pTable->pMeta->tableType && TSDB_NORMAL_TABLE != pTable->pMeta->tableType && TSDB_SYSTEM_TABLE != pTable->pMeta->tableType) {
+    return TSDB_CODE_SUCCESS;
+  }
+
+  SNode** pNode = NULL;
+  SRewriteTbNameContext pRewriteCxt = {0};
+  pRewriteCxt.pTbName = pTable->table.tableName;
+  
+  nodesRewriteExprPostOrder(&pSelect->pWhere, doTranslateTbName, &pRewriteCxt);
+
+  return pRewriteCxt.errCode;
+}
+
 static int32_t checkJoinTable(STranslateContext* pCxt, SJoinTableNode* pJoinTable) {
   if ((QUERY_NODE_TEMP_TABLE == nodeType(pJoinTable->pLeft) &&
        !isTimeLineQuery(((STempTableNode*)pJoinTable->pLeft)->pSubquery)) ||
@@ -2595,8 +2658,13 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
         if (TSDB_SUPER_TABLE == pRealTable->pMeta->tableType) {
           pCxt->stableQuery = true;
         }
-        if (TSDB_SYSTEM_TABLE == pRealTable->pMeta->tableType && isSelectStmt(pCxt->pCurrStmt)) {
-          ((SSelectStmt*)pCxt->pCurrStmt)->isTimeLineResult = false;
+        if (TSDB_SYSTEM_TABLE == pRealTable->pMeta->tableType) {
+          if (isSelectStmt(pCxt->pCurrStmt)) {
+            ((SSelectStmt*)pCxt->pCurrStmt)->isTimeLineResult = false;
+          } else if (isDeleteStmt(pCxt->pCurrStmt)) {
+            code = TSDB_CODE_TSC_INVALID_OPERATION;
+            break;
+          }
         }
         code = addNamespace(pCxt, pRealTable);
       }
@@ -3667,6 +3735,10 @@ static int32_t translateSelectFrom(STranslateContext* pCxt, SSelectStmt* pSelect
   if (TSDB_CODE_SUCCESS == code) {
     code = setTableCacheLastMode(pCxt, pSelect);
   }
+  if (TSDB_CODE_SUCCESS == code) {
+    code = replaceTbName(pCxt, pSelect);
+  }
+  
   return code;
 }
 
@@ -4201,6 +4273,34 @@ static int32_t checkDbRetentionsOption(STranslateContext* pCxt, SNodeList* pRete
   return TSDB_CODE_SUCCESS;
 }
 
+
+static int32_t checkDbTbPrefixSuffixOptions(STranslateContext* pCxt, int32_t tbPrefix, int32_t tbSuffix) {
+  if (tbPrefix < TSDB_MIN_HASH_PREFIX || tbPrefix > TSDB_MAX_HASH_PREFIX) {
+    return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
+                                   "Invalid option table_prefix: %d valid range: [%d, %d]", tbPrefix,
+                                   TSDB_MIN_HASH_PREFIX, TSDB_MAX_HASH_PREFIX);
+  }
+
+  if (tbSuffix < TSDB_MIN_HASH_SUFFIX || tbSuffix > TSDB_MAX_HASH_SUFFIX) {
+    return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
+                                   "Invalid option table_suffix: %d valid range: [%d, %d]", tbSuffix,
+                                   TSDB_MIN_HASH_SUFFIX, TSDB_MAX_HASH_SUFFIX);
+  }
+
+  if ((tbPrefix * tbSuffix) < 0) {
+    return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
+                                   "Invalid option table_prefix & table_suffix: mixed usage not allowed");
+  }
+
+  if ((tbPrefix + tbSuffix) >= (TSDB_TABLE_NAME_LEN - 1)) {
+    return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
+                                   "Invalid option table_prefix & table_suffix: exceed max table name length");
+  }
+
+  return TSDB_CODE_SUCCESS;
+}
+
+
 static int32_t checkOptionsDependency(STranslateContext* pCxt, const char* pDbName, SDatabaseOptions* pOptions) {
   int32_t daysPerFile = pOptions->daysPerFile;
   int64_t daysToKeep0 = pOptions->keep[0];
@@ -4308,10 +4408,7 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName
     code = checkDbRangeOption(pCxt, "sstTrigger", pOptions->sstTrigger, TSDB_MIN_STT_TRIGGER, TSDB_MAX_STT_TRIGGER);
   }
   if (TSDB_CODE_SUCCESS == code) {
-    code = checkDbRangeOption(pCxt, "tablePrefix", pOptions->tablePrefix, TSDB_MIN_HASH_PREFIX, TSDB_MAX_HASH_PREFIX);
-  }
-  if (TSDB_CODE_SUCCESS == code) {
-    code = checkDbRangeOption(pCxt, "tableSuffix", pOptions->tableSuffix, TSDB_MIN_HASH_SUFFIX, TSDB_MAX_HASH_SUFFIX);
+    code = checkDbTbPrefixSuffixOptions(pCxt, pOptions->tablePrefix, pOptions->tableSuffix);
   }
   if (TSDB_CODE_SUCCESS == code) {
     code = checkOptionsDependency(pCxt, pDbName, pOptions);
@@ -5252,7 +5349,8 @@ static int32_t checkAlterSuperTableBySchema(STranslateContext* pCxt, SAlterTable
     }
 
     if (TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES == pStmt->alterType) {
-      if (calcTypeBytes(pStmt->dataType) > TSDB_MAX_FIELD_LEN) {
+      if ((TSDB_DATA_TYPE_VARCHAR == pStmt->dataType.type && calcTypeBytes(pStmt->dataType) > TSDB_MAX_BINARY_LEN) ||
+          (TSDB_DATA_TYPE_NCHAR == pStmt->dataType.type && calcTypeBytes(pStmt->dataType) > TSDB_MAX_NCHAR_LEN)) {
         return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN);
       }
 
@@ -5277,6 +5375,11 @@ static int32_t checkAlterSuperTableBySchema(STranslateContext* pCxt, SAlterTable
       return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TOO_MANY_COLUMNS);
     }
 
+    if ((TSDB_DATA_TYPE_VARCHAR == pStmt->dataType.type && calcTypeBytes(pStmt->dataType) > TSDB_MAX_BINARY_LEN) ||
+        (TSDB_DATA_TYPE_NCHAR == pStmt->dataType.type && calcTypeBytes(pStmt->dataType) > TSDB_MAX_NCHAR_LEN)) {
+      return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN);
+    }
+
     if (pTableMeta->tableInfo.rowSize + calcTypeBytes(pStmt->dataType) > TSDB_MAX_BYTES_PER_ROW) {
       return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ROW_LENGTH, TSDB_MAX_BYTES_PER_ROW);
     }
@@ -6075,17 +6178,50 @@ static bool isEventWindowQuery(SSelectStmt* pSelect) {
   return NULL != pSelect->pWindow && QUERY_NODE_EVENT_WINDOW == nodeType(pSelect->pWindow);
 }
 
+static bool hasJsonTypeProjection(SSelectStmt* pSelect) {
+  SNode* pProj = NULL;
+  FOREACH(pProj, pSelect->pProjectionList) {
+    if (TSDB_DATA_TYPE_JSON == ((SExprNode*)pProj)->resType.type) {
+      return true;
+    }
+  }
+  return false;
+}
+
+static EDealRes hasColumnOrPseudoColumn(SNode* pNode, void* pContext) {
+  if (QUERY_NODE_COLUMN == nodeType(pNode)) {
+    *(bool*)pContext = true;
+    return DEAL_RES_END;
+  }
+  if (QUERY_NODE_FUNCTION == nodeType(pNode) && fmIsPseudoColumnFunc(((SFunctionNode*)pNode)->funcId)) {
+    *(bool*)pContext = true;
+    return DEAL_RES_END;
+  }
+  return DEAL_RES_CONTINUE;
+}
+
+static int32_t subtableExprHasColumnOrPseudoColumn(SNode* pNode) {
+  bool hasColumn = false;
+  nodesWalkExprPostOrder(pNode, hasColumnOrPseudoColumn, &hasColumn);
+  return hasColumn;
+}
+
 static int32_t checkStreamQuery(STranslateContext* pCxt, SCreateStreamStmt* pStmt) {
   SSelectStmt* pSelect = (SSelectStmt*)pStmt->pQuery;
   if (TSDB_DATA_TYPE_TIMESTAMP != ((SExprNode*)nodesListGetNode(pSelect->pProjectionList, 0))->resType.type ||
       !pSelect->isTimeLineResult || crossTableWithoutAggOper(pSelect) || NULL != pSelect->pOrderByList ||
-      crossTableWithUdaf(pSelect) || isEventWindowQuery(pSelect)) {
+      crossTableWithUdaf(pSelect) || isEventWindowQuery(pSelect) || hasJsonTypeProjection(pSelect)) {
     return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, "Unsupported stream query");
   }
   if (NULL != pSelect->pSubtable && TSDB_DATA_TYPE_VARCHAR != ((SExprNode*)pSelect->pSubtable)->resType.type) {
     return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
                                    "SUBTABLE expression must be of VARCHAR type");
   }
+  if (NULL != pSelect->pSubtable && 0 == LIST_LENGTH(pSelect->pPartitionByList) && subtableExprHasColumnOrPseudoColumn(pSelect->pSubtable)) {
+    return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
+                                   "SUBTABLE expression must not has column when no partition by clause");
+  }
+
   if (NULL == pSelect->pWindow && STREAM_TRIGGER_AT_ONCE != pStmt->pOptions->triggerType) {
     return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
                                    "The trigger mode of non window query can only be AT_ONCE");
@@ -6623,22 +6759,40 @@ static int32_t createRealTableForGrantTable(SGrantStmt* pStmt, SRealTableNode**
 }
 
 static int32_t translateGrantTagCond(STranslateContext* pCxt, SGrantStmt* pStmt, SAlterUserReq* pReq) {
-  if (NULL == pStmt->pTagCond) {
-    return TSDB_CODE_SUCCESS;
-  }
+  SRealTableNode* pTable = NULL;
   if ('\0' == pStmt->tabName[0] || '*' == pStmt->tabName[0]) {
-    return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR,
-                                   "The With clause can only be used for table level privilege");
+    if (pStmt->pTagCond) {
+      return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR,
+                                     "The With clause can only be used for table level privilege");
+    } else {
+      return TSDB_CODE_SUCCESS;
+    }
   }
 
-  pCxt->pCurrStmt = (SNode*)pStmt;
-  SRealTableNode* pTable = NULL;
   int32_t         code = createRealTableForGrantTable(pStmt, &pTable);
   if (TSDB_CODE_SUCCESS == code) {
     SName name;
     code = getTableMetaImpl(pCxt, toName(pCxt->pParseCxt->acctId, pTable->table.dbName, pTable->table.tableName, &name),
                             &(pTable->pMeta));
+    if (code) {
+      nodesDestroyNode((SNode*)pTable);
+      return code;
+    }
+
+    if (TSDB_SUPER_TABLE != pTable->pMeta->tableType && TSDB_NORMAL_TABLE != pTable->pMeta->tableType) {
+      nodesDestroyNode((SNode*)pTable);
+      return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR,
+                                     "Only supertable and normal table can be granted");
+    }
   }
+
+  if (TSDB_CODE_SUCCESS == code && NULL == pStmt->pTagCond) {
+    nodesDestroyNode((SNode*)pTable);
+    return TSDB_CODE_SUCCESS;
+  }
+
+  pCxt->pCurrStmt = (SNode*)pStmt;
+
   if (TSDB_CODE_SUCCESS == code) {
     code = addNamespace(pCxt, pTable);
   }
@@ -6672,6 +6826,7 @@ static int32_t translateGrant(STranslateContext* pCxt, SGrantStmt* pStmt) {
   if (TSDB_CODE_SUCCESS == code) {
     code = buildCmdMsg(pCxt, TDMT_MND_ALTER_USER, (FSerializeFunc)tSerializeSAlterUserReq, &req);
   }
+  tFreeSAlterUserReq(&req);
   return code;
 }
 
@@ -8176,6 +8331,11 @@ static int32_t buildAddColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, S
     return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_DUPLICATED_COLUMN);
   }
 
+  if ((TSDB_DATA_TYPE_VARCHAR == pStmt->dataType.type && calcTypeBytes(pStmt->dataType) > TSDB_MAX_BINARY_LEN) ||
+      (TSDB_DATA_TYPE_NCHAR == pStmt->dataType.type && calcTypeBytes(pStmt->dataType) > TSDB_MAX_NCHAR_LEN)) {
+    return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN);
+  }
+
   if (TSDB_MAX_COLUMNS == pTableMeta->tableInfo.numOfColumns) {
     return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TOO_MANY_COLUMNS);
   }
@@ -8228,6 +8388,11 @@ static int32_t buildUpdateColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt
     return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_MODIFY_COL);
   }
 
+  if ((TSDB_DATA_TYPE_VARCHAR == pStmt->dataType.type && calcTypeBytes(pStmt->dataType) > TSDB_MAX_BINARY_LEN) ||
+      (TSDB_DATA_TYPE_NCHAR == pStmt->dataType.type && calcTypeBytes(pStmt->dataType) > TSDB_MAX_NCHAR_LEN)) {
+    return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN);
+  }
+
   if (pTableMeta->tableInfo.rowSize + pReq->colModBytes - pSchema->bytes > TSDB_MAX_BYTES_PER_ROW) {
     return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ROW_LENGTH, TSDB_MAX_BYTES_PER_ROW);
   }
diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c
index 592bad5dc2..9661659a1f 100644
--- a/source/libs/parser/src/sql.c
+++ b/source/libs/parser/src/sql.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 /************ Begin %include sections from the grammar ************************/
+#line 11 "sql.y"
 
 #include 
 #include 
@@ -41,6 +42,7 @@
 #include "parAst.h"
 
 #define YYSTACKDEPTH 0
+#line 46 "sql.c"
 /**************** End of %include directives **********************************/
 /* These constants specify the various numeric values for terminal symbols
 ** in a format understandable to "makeheaders".  This section is blank unless
@@ -218,648 +220,648 @@ typedef union {
 **  yy_default[]       Default action for each state.
 **
 *********** Begin parsing tables **********************************************/
-#define YY_ACTTAB_COUNT (3182)
+#define YY_ACTTAB_COUNT (3190)
 static const YYACTIONTYPE yy_action[] = {
- /*     0 */  2139, 1764, 2303,  514,  167, 2298,  515, 1777,   38,  296,
- /*    10 */   682, 1856,   48,   46, 1665,   47,   45,   44,   43,   42,
- /*    20 */   394, 2302, 1514,   41,   40, 2299, 2301,   47,   45,   44,
- /*    30 */    43,   42,  519, 1595, 1814, 1512, 2157,  439,  516,  397,
- /*    40 */  1669,  522,  643,  140,  515, 1777, 1539,  162, 2107, 2107,
- /*    50 */   684,  625,   41,   40,  373, 1917,   47,   45,   44,   43,
- /*    60 */    42, 1590, 1965, 2033, 1542,   41,   40,   19, 1539,   47,
- /*    70 */    45,   44,   43,   42, 1520,  385,  667, 2157, 2030,  655,
- /*    80 */   338, 2138,  153,  668, 1915, 2174,  566,  565,  332, 2140,
- /*    90 */   688, 2142, 2143,  683,  681,  678,  669, 2192,  168,  773,
- /*   100 */  1753,  133,   15,  750,  749,  748,  747,  404,  552,  746,
+ /*     0 */  2139,  435, 1967,  397, 2090,  434,  670, 1915, 2074,  374,
+ /*    10 */   684,  162,   48,   46, 1665,   38,  298, 1965,  375, 1917,
+ /*    20 */   394,  627, 1514,   41,   40,  133, 1965,   47,   45,   44,
+ /*    30 */    43,   42,  554, 1595, 1814, 1512,  168, 2157, 1753, 1207,
+ /*    40 */   211, 1206,  645,  140,  519, 1904, 1784,  608, 2157, 2107,
+ /*    50 */  2298,  686,   41,   40,  228,  246,   47,   45,   44,   43,
+ /*    60 */    42, 1590,  366,   66, 1542, 2304,  186,   19, 2033, 1539,
+ /*    70 */  2299,  634, 1208,  669, 1520,   47,   45,   44,   43,   42,
+ /*    80 */   387,  669, 2138, 2030,  657, 2174, 1961, 1962,  334, 2140,
+ /*    90 */   690, 2142, 2143,  685,  683,  680,  671, 2192,  441,  773,
+ /*   100 */   167,  626,   15,  750,  749,  748,  747,  406, 1856,  746,
  /*   110 */   745,  144,  740,  739,  738,  737,  736,  735,  734,  157,
- /*   120 */   730,  729,  728,  403,  402,  725,  724,  723,  722,  721,
- /*   130 */  2303,  624,  101, 2298,  668, 1915,  531, 1539, 1597, 1598,
- /*   140 */  1207,   56, 1206,  275, 2235,  642,  667,  134,  641, 2302,
- /*   150 */  2298,  180,  133, 2299, 2300,  226, 1908,  166,   51,  557,
- /*   160 */  1704, 1541,  316, 1954,   62,  630,  184, 1763, 1570, 1580,
- /*   170 */  2299,  632, 2303, 1208, 1596, 1599,  314,   73,   41,   40,
- /*   180 */    72, 1741,   47,   45,   44,   43,   42,  653, 1515, 1541,
- /*   190 */  1513,  339,   41,   40, 1571, 1734,   47,   45,   44,   43,
- /*   200 */    42,  207,  496,  494,  491,  132,  131,  130,  129,  128,
- /*   210 */   127,  126,  125,  124,  255, 2107,  621, 1518, 1519, 1817,
- /*   220 */  1569, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579,  680,
- /*   230 */   676, 1588, 1589, 1591, 1592, 1593, 1594,    2,   48,   46,
- /*   240 */  1514,   62, 1184,  342,  142, 1537,  394, 2198, 1514,  431,
- /*   250 */   626,  430,  470, 1512,  477,  484,  643,  140,  483, 1595,
- /*   260 */   123, 1512, 1967,  122,  121,  120,  119,  118,  117,  116,
- /*   270 */   115,  114, 1727, 1681,  453,  107,  485, 1966,  429,  109,
- /*   280 */   455, 1186, 1693, 1189, 1190, 1428, 1429, 1590,  570,  569,
- /*   290 */   568,  141, 1520,   19, 1733,  560,  137,  564, 1967, 1907,
- /*   300 */  1520,  563,  627,  622,  615,  372,  562,  567,  367,  366,
- /*   310 */   187,  277,  561, 1965,  200,  199,  187,  773,  720,   81,
- /*   320 */    80,  436, 1539,  196,  191,  773,  360, 2033,   15,  618,
- /*   330 */   617, 1691, 1692, 1694, 1695, 1696,  667,  476,  443,  277,
- /*   340 */  1961, 1962, 2031,  655,   66,  340,  744,  742,  422, 1540,
- /*   350 */  2125,  420,  416,  412,  409,  429,  645,  182, 2235, 2236,
- /*   360 */  2121,  138, 2240,   84, 1597, 1598,   83,  481,  278, 1538,
- /*   370 */   475,  474,  473,  472,  469,  468,  467,  466,  465,  461,
- /*   380 */   460,  459,  458,  341,  450,  449,  448,   87,  445,  444,
- /*   390 */   358, 1189, 1190,  187, 1570, 1580, 2117, 2123,  389, 1540,
- /*   400 */  1596, 1599,  631,  361,   62, 2298, 1515,  678, 1513,   62,
- /*   410 */  1539,   93, 1910,  242, 1515, 2128, 1513,  241,   51, 2242,
- /*   420 */   630,  184,  106,   41,   40, 2299,  632,   47,   45,   44,
- /*   430 */    43,   42,  103,   41,   40, 1518, 1519,   47,   45,   44,
- /*   440 */    43,   42,   62, 1518, 1519, 2239, 1569, 1572, 1573, 1574,
- /*   450 */  1575, 1576, 1577, 1578, 1579,  680,  676, 1588, 1589, 1591,
- /*   460 */  1592, 1593, 1594,    2,   12,   48,   46, 1373, 1374,   30,
- /*   470 */  2130,  654, 1997,  394, 1339, 1514,  399,   90,  346, 1960,
- /*   480 */  1962,  371,  351,  586, 1542, 1283, 1595,  177, 1512, 1330,
- /*   490 */   710,  709,  708, 1334,  707, 1336, 1337,  706,  703,   62,
- /*   500 */  1345,  700, 1347, 1348,  697,  694,  426,  359, 2016,  227,
- /*   510 */   668, 1915, 2139,  712, 1590, 1742, 1958, 1445, 1446,  654,
- /*   520 */    19,  529,  646, 2026, 1285,  172, 1624, 1520,  189,  177,
- /*   530 */   428,  424,  548,  544,  540,  536,  123,  224,  654,  122,
- /*   540 */   121,  120,  119,  118,  117,  116,  115,  114, 2157, 1906,
- /*   550 */  2017, 1605,  773, 1444, 1447,   15,  187, 1539, 1571, 2121,
- /*   560 */  2107,  187,  684,   52,  209,  570,  569,  568,  517,  652,
- /*   570 */  1784, 2026,  560,  137,  564,  211, 1762,   88,  563,  517,
- /*   580 */   222, 1784, 1625,  562,  567,  367,  366, 1892,  663,  561,
- /*   590 */  2026, 1597, 1598, 2138,  187, 2117, 2123, 2174,  668, 1915,
- /*   600 */   110, 2140,  688, 2142, 2143,  683,  678,  678, 1967,  386,
- /*   610 */   593, 1207,  181, 1206, 2227,  382,   57,  165,  388, 2223,
- /*   620 */  2242, 1570, 1580, 1965, 2107, 1917, 1739, 1596, 1599,  457,
- /*   630 */  1967,  186,  668, 1915,  193,  668, 1915,  357,  456, 2253,
- /*   640 */  1890, 1515,   12, 1513, 1208, 1965, 2238,  221,  215, 1761,
- /*   650 */   437,  187,  220,  438,  527, 2302,   37,  392, 1619, 1620,
- /*   660 */  1621, 1622, 1623, 1627, 1628, 1629, 1630,   44,   43,   42,
- /*   670 */  1518, 1519,  213, 1569, 1572, 1573, 1574, 1575, 1576, 1577,
- /*   680 */  1578, 1579,  680,  676, 1588, 1589, 1591, 1592, 1593, 1594,
- /*   690 */     2,   48,   46, 1600,  584, 1520,  407, 2107,  433,  394,
- /*   700 */   406, 1514,  432, 2126, 1760, 1571, 2139,  582,  631,  580,
- /*   710 */  1967, 2298, 1595, 2121, 1512,  187,  685,  387,  718,  155,
- /*   720 */   154,  715,  714,  713,  152, 1965,  630,  184, 1294,   41,
- /*   730 */    40, 2299,  632,   47,   45,   44,   43,   42, 1542,  397,
- /*   740 */  1590, 1293, 2157,  606, 1967,  606, 2298,  165, 2298, 2117,
- /*   750 */  2123,  398, 2107, 1520, 2107, 1917,  684, 1298, 1891, 1965,
- /*   760 */   678, 2304,  184, 2304,  184, 2012, 2299,  632, 2299,  632,
- /*   770 */  1297,  718,  155,  154,  715,  714,  713,  152,  773,  511,
- /*   780 */    12,   49,   10, 2139,  400,  649,  509, 2138,  711,  505,
- /*   790 */   501, 2174,  165,  685,  110, 2140,  688, 2142, 2143,  683,
- /*   800 */  1917,  678,  668, 1915,  143,  486,  150, 2198, 2227,  192,
- /*   810 */  1192,  153,  388, 2223,  243,   34, 1538, 1597, 1598, 2157,
- /*   820 */   447,   41,   40, 2242,  720,   47,   45,   44,   43,   42,
- /*   830 */    36, 2107,  606,  684,  488, 2298,   41,   40, 1759, 1758,
- /*   840 */    47,   45,   44,   43,   42,  643,  140, 1570, 1580, 2237,
- /*   850 */  2304,  184,  253, 1596, 1599, 2299,  632,   14,   13, 2090,
- /*   860 */   287,  288,  668, 1915, 2138,  286, 1662, 1515, 2174, 1513,
- /*   870 */  1482,  110, 2140,  688, 2142, 2143,  683,  670,  678, 2199,
- /*   880 */   462, 1487, 1488, 2202, 1757, 2227, 2107, 2107,  254,  388,
- /*   890 */  2223,  164, 2100, 1756,  732,   91, 1518, 1519, 1626, 1569,
- /*   900 */  1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579,  680,  676,
- /*   910 */  1588, 1589, 1591, 1592, 1593, 1594,    2,   48,   46,   87,
- /*   920 */   575,  165,  672, 2101, 2199,  394,  634, 1514, 1755, 1918,
- /*   930 */  2012, 2012, 2107, 2139, 1904,  585,  668, 1915, 1595,  606,
- /*   940 */  1512, 2107, 2298,  646, 1911,  591,  183, 2235, 2236,  240,
- /*   950 */   138, 2240, 1900,  716,  463, 1752, 1958, 2304,  184, 1638,
- /*   960 */  2247, 1658, 2299,  632, 1751,  578, 1590,  668, 1915, 2157,
- /*   970 */   606,  572,   35, 2298,  194,  198, 2107,  239,  364, 1520,
- /*   980 */  2074, 2107, 1631,  684, 1750,  530,  643,  140, 2304,  184,
- /*   990 */   668, 1915,  606, 2299,  632, 2298,  718,  155,  154,  715,
- /*  1000 */   714,  713,  152, 2107,  773, 1749,    9,   49, 1912, 2139,
- /*  1010 */  2304,  184, 2107, 1748, 2138, 2299,  632,   70, 2174,  685,
- /*  1020 */    69,  110, 2140,  688, 2142, 2143,  683,  244,  678,  668,
- /*  1030 */  1915,  635, 2107,  181, 1747, 2227,  668, 1915,  717,  388,
- /*  1040 */  2223, 1958,  638, 1597, 1598, 2157,  365,  245,  363,  362,
- /*  1050 */   733,  554, 1877, 2107,  602, 1746,   54, 2107,    3,  684,
- /*  1060 */  2254, 2107, 1745,  668, 1915, 2093,  668, 1915,  668, 1915,
- /*  1070 */   421, 1744,  556, 1570, 1580,  310,  555, 1893, 1944, 1596,
- /*  1080 */  1599,  647, 2107,  146,  651,  135,  291,  185, 2235, 2236,
- /*  1090 */  2138,  138, 2240, 1515, 2174, 1513,  675,  110, 2140,  688,
- /*  1100 */  2142, 2143,  683, 2107,  678,  440,  668, 1915,  556, 2200,
- /*  1110 */  2107, 2227,  555,   74,  414,  388, 2223, 1661,  441, 2107,
- /*  1120 */   153,  148, 1518, 1519,  665, 1569, 1572, 1573, 1574, 1575,
- /*  1130 */  1576, 1577, 1578, 1579,  680,  676, 1588, 1589, 1591, 1592,
- /*  1140 */  1593, 1594,    2,   48,   46,  668, 1915,  668, 1915, 1523,
- /*  1150 */    50,  394,  232, 1514,  234,  230,  558,  233,  668, 1915,
- /*  1160 */   559, 1801,   82,  401, 1595,  666, 1512, 2139,  236,  238,
- /*  1170 */    50,  235,  237, 1793, 1791,  252,  297,  685, 1281, 1485,
- /*  1180 */   259, 1902, 1279,  571,  588,  605,  587, 1736, 1737, 1522,
- /*  1190 */  2139, 1898, 1590, 1240,   50,  573,  576,   14,   13,  726,
- /*  1200 */   685,  727, 1786, 2157, 1857, 1520,  153,   50,  375, 1690,
- /*  1210 */  1919,  249,  679,  284,   71, 2107, 1754,  684, 1787, 2267,
- /*  1220 */  1658, 1259,  272, 1257,  619,  151, 2157,  153,   64, 1689,
- /*  1230 */   773,  225, 1241,   15,   50,  692,  266, 2158, 2107,  261,
- /*  1240 */   684, 2139,  151,  153,  405, 2021, 1616, 1778, 2138, 1955,
- /*  1250 */   136,  685, 2174, 1581,  151,  333, 2140,  688, 2142, 2143,
- /*  1260 */   683, 2257,  678,  636, 1783,  650, 1442,  644,  768, 1597,
- /*  1270 */  1598, 2138,  289,  660,  274, 2174,  639, 2157,  110, 2140,
- /*  1280 */   688, 2142, 2143,  683,  293,  678, 1324, 1632,  271, 2107,
- /*  1290 */  2318,  684, 2227,  309, 1351,    1,  388, 2223,    5, 1570,
- /*  1300 */  1580, 1355, 1362,  408, 1526, 1596, 1599,   55,  413, 1360,
- /*  1310 */   355, 1465,  304,  156,  197,  442, 1542, 2022,  446, 1515,
- /*  1320 */   479, 1513, 2138,  451, 1537,  464, 2174, 2014,  471,  169,
- /*  1330 */  2140,  688, 2142, 2143,  683,  478,  678,  480,  489,  487,
- /*  1340 */   490,  201,  492,  202, 1525,  493,  204,  495, 1518, 1519,
- /*  1350 */   497, 1569, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579,
- /*  1360 */   680,  676, 1588, 1589, 1591, 1592, 1593, 1594,    2, 2139,
- /*  1370 */  2265, 1543,  512,    4,  513,  520, 1545,  521,  212,  685,
- /*  1380 */   523, 2261, 1540,  214, 1544,  525,  524, 1546,  526,  217,
- /*  1390 */   528,  532,  219, 1210,  551,   85, 2139,   86,  553, 1905,
- /*  1400 */   549,  550,  223,  229,  345, 2157,  685, 2083, 2274,  590,
- /*  1410 */   112,  592,   89, 2080,  596,  305,  595, 2107,  149,  684,
- /*  1420 */   246,  597,  248,  250, 1901,  231,  158,  159, 1472, 1903,
- /*  1430 */  1899,  160, 2157,  601,  603,  161, 2273, 2272,  620,  658,
- /*  1440 */   629, 2249,    8, 2321, 2107,  611,  684,  173,  265,  267,
- /*  1450 */  2138, 2079,  610,  268, 2174,  640,  600,  110, 2140,  688,
- /*  1460 */  2142, 2143,  683,  616,  678, 2258,  609, 2268, 2139, 2318,
- /*  1470 */   377, 2227,  623,  257,  608,  388, 2223, 2138,  685,  260,
- /*  1480 */   613, 2174,  378, 2297,  110, 2140,  688, 2142, 2143,  683,
- /*  1490 */   637,  678,  273, 1658,  139, 1541, 2318,  270, 2227,  648,
- /*  1500 */  2139,  279,  388, 2223, 2157,  381, 2243,   96, 1547, 2027,
- /*  1510 */   685,  656, 2292,  306,  307,  657, 2107, 2041,  684,  661,
- /*  1520 */    61, 2040, 2039,  384,  662, 1916,   98,  308, 2139,  100,
- /*  1530 */   102, 2208,  769,  269,  335, 1959, 2157,  300,  685,  690,
- /*  1540 */  2246,  311,  772, 1878,  347,  770,   53,  348, 2107, 2138,
- /*  1550 */   684, 2099,  315, 2174,  320, 2098,  110, 2140,  688, 2142,
- /*  1560 */  2143,  683,  313,  678, 2157,  334,  324, 2097, 2318,   78,
- /*  1570 */  2227, 2094,  410, 1505,  388, 2223, 2107, 1506,  684,  411,
- /*  1580 */   190, 2138,  415, 2092,  417, 2174,  419,  418,  110, 2140,
- /*  1590 */   688, 2142, 2143,  683, 2091,  678,  356, 2089,  423, 2088,
- /*  1600 */  2318, 2087, 2227,  425,  391,  390,  388, 2223,  427, 2138,
- /*  1610 */    79, 1468, 1467, 2174, 1528, 2053,  110, 2140,  688, 2142,
- /*  1620 */  2143,  683,  594,  678, 2052, 1595, 2139, 1521, 2318, 2051,
- /*  1630 */  2227,  434,  435, 2050,  388, 2223,  685, 2049, 1419, 2005,
- /*  1640 */   776, 2004, 2002, 2001,  145, 2000, 2003, 1999, 1998, 1996,
- /*  1650 */  1995, 1994,  195, 1590,  303,  452, 1993,  454, 2007, 1992,
- /*  1660 */  1991, 1990, 2157,  482,  147, 1977, 1520, 1989, 1988, 1987,
- /*  1670 */   176, 1986, 1985, 1984, 2107, 1983,  684,  766,  762,  758,
- /*  1680 */   754, 1982,  301, 1981, 1980, 1979, 1978, 1976, 1975, 2006,
- /*  1690 */  1974,  674, 1421, 1972, 1971, 1970, 1969, 1968, 2139, 1973,
- /*  1700 */  1295,  343, 1299,  344, 1820,  203, 1819, 2138,  685, 1291,
- /*  1710 */  1818, 2174, 1816,  205,  110, 2140,  688, 2142, 2143,  683,
- /*  1720 */  1813,  678,  108,  206, 1812,  294,  671, 1805, 2227, 1795,
- /*  1730 */   500,  499,  388, 2223, 2157,  498,  502, 1773,  506, 1191,
- /*  1740 */  1772,  504,  510, 2070, 2060, 2048, 2107,  503,  684,  218,
- /*  1750 */   508,  208,   76, 2047,  507, 2127,   77,  664,  178,  210,
- /*  1760 */   216, 2025,  179,  518, 1894, 1815, 1811,  533, 1809,  535,
- /*  1770 */   537,  534,  538,  539, 1807,  543,  541,  542, 1804, 2138,
- /*  1780 */  1529,  545, 1524, 2174, 1790, 1789,  111, 2140,  688, 2142,
- /*  1790 */  2143,  683,  281,  678, 1233,  547, 2139,  280,  546, 1769,
- /*  1800 */  2227, 1366, 1367, 1895, 2226, 2223,  685, 1896, 1282, 1532,
- /*  1810 */  1534, 1280, 1278,  741,  743, 1277, 1276,  247, 1275, 1269,
- /*  1820 */  2139, 1274,  676, 1588, 1589, 1591, 1592, 1593, 1594,   63,
- /*  1830 */   685, 1271, 2157, 1270, 1802, 1268,  368, 1794,  369, 1792,
- /*  1840 */   228,  574,  370,  577, 2107, 1768,  684,  579, 1767, 1766,
- /*  1850 */   581,  583,  113, 1496, 1492, 2069, 2157, 1494, 1491,   29,
- /*  1860 */    67, 1478, 1474, 1476, 2059,  598, 2046,  163, 2107, 2044,
- /*  1870 */   684, 2303,   20,   31,   17, 1706,   23, 2138,    6,    7,
- /*  1880 */    21, 2174,  612,   65,  111, 2140,  688, 2142, 2143,  683,
- /*  1890 */   614,  678,  258,  256, 2139,   22, 1688,  171, 2227,  264,
- /*  1900 */   263,  686,  673, 2223,  685, 2174,  262,   32,  111, 2140,
- /*  1910 */   688, 2142, 2143,  683, 2139,  678,  604,   58,  599, 2128,
- /*  1920 */  1680,   24, 2227,  251,  685,  374,  350, 2223,   92, 1721,
- /*  1930 */  2157,   33, 1720,  379, 1725,   18, 1726,  276, 1727, 1724,
- /*  1940 */   380, 1655, 2107, 1654,  684,   60, 2045,  174, 2043, 2042,
- /*  1950 */  2157, 2024,   94,   95,  282,   25, 2023,  283,   97,  103,
- /*  1960 */  1686,  285, 2107,  290,  684,   68,   26,  659,  295,   99,
- /*  1970 */  1607, 1606,   11,  292,   13, 2138, 1530, 1617, 2177, 2174,
- /*  1980 */   175, 1585,  169, 2140,  688, 2142, 2143,  683,  677,  678,
- /*  1990 */    59, 1583, 1582,   39,   16, 2138, 1554,   27, 2139, 2174,
- /*  2000 */   188, 1562,  170, 2140,  688, 2142, 2143,  683,  685,  678,
- /*  2010 */    28,  691, 1352,  396,  693,  695,  689,  698,  701, 1349,
- /*  2020 */   696,  704,  607, 2264, 1361,  687, 1346, 2139,  699,  298,
- /*  2030 */  1340,  702, 1357, 1338, 2157, 1344,  705,  685,  104,  105,
- /*  2040 */    75, 1343, 1231, 1265, 1342, 1289, 2107, 1264,  684, 1341,
- /*  2050 */  1263,  719, 1262,  633, 2319, 1261, 1260, 1258, 1256, 1255,
- /*  2060 */  1254,  731,  299, 2157, 1252, 1251, 1250, 1249,  376, 1248,
- /*  2070 */  1247, 1246, 1286, 1284, 1243, 2107, 1242,  684, 1239, 2138,
- /*  2080 */  1237, 1238, 1236, 2174, 1810,  751,  111, 2140,  688, 2142,
- /*  2090 */  2143,  683,  753,  678, 1808,  755,  757,  752,  756, 1806,
- /*  2100 */  2227,  759,  761,  760, 1803, 2224,  763,  765, 2138, 1788,
- /*  2110 */   764,  767, 2174, 1181, 1765,  333, 2140,  688, 2142, 2143,
- /*  2120 */   683,  771,  678, 2139,  302, 1516, 1740,  312,  774, 1740,
- /*  2130 */   775, 1740, 1740,  685, 1740, 1740, 2139, 1740, 1740, 1740,
- /*  2140 */  1740, 1740, 1740, 1740, 1740, 1740,  685, 1740, 1740, 1740,
- /*  2150 */  1740, 1740, 1740, 2139, 1740, 1740, 1740, 1740, 1740, 2157,
- /*  2160 */  1740, 1740, 1740,  685, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  2170 */  1740, 2107, 2157,  684, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  2180 */  1740, 1740, 1740, 1740, 2107, 1740,  684, 1740, 1740, 2157,
- /*  2190 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  2200 */  1740, 2107, 1740,  684, 2138, 1740, 1740, 1740, 2174, 1740,
- /*  2210 */  1740,  326, 2140,  688, 2142, 2143,  683, 2138,  678, 1740,
- /*  2220 */  2139, 2174, 1740, 1740,  170, 2140,  688, 2142, 2143,  683,
- /*  2230 */   685,  678, 1740, 1740,  589, 1740, 1740, 2139, 2174, 1740,
- /*  2240 */  1740,  328, 2140,  688, 2142, 2143,  683,  682,  678, 1740,
- /*  2250 */  2139, 1740, 1740, 1740,  628, 1740, 2157, 1740, 1740, 1740,
- /*  2260 */   685,  383, 1740, 1740, 1740, 1740, 1740, 1740, 2107, 1740,
- /*  2270 */   684, 1740, 1740, 2157, 1740, 1740, 2320, 1740, 1740, 1740,
- /*  2280 */  1740, 1740, 1740, 1740, 1740, 2107, 2157,  684, 1740, 1740,
- /*  2290 */  1740,  393, 1740, 1740, 1740, 1740, 1740, 1740, 2107, 1740,
- /*  2300 */   684, 2138, 1740, 1740, 1740, 2174, 1740, 1740,  333, 2140,
- /*  2310 */   688, 2142, 2143,  683, 1740,  678, 1740, 1740, 2138, 1740,
- /*  2320 */  1740, 1740, 2174, 2139, 1740,  332, 2140,  688, 2142, 2143,
- /*  2330 */   683, 2138,  678,  685, 2193, 2174, 1740, 1740,  333, 2140,
- /*  2340 */   688, 2142, 2143,  683, 2139,  678, 1740, 1740, 1740, 1740,
- /*  2350 */  1740, 1740, 1740, 1740,  685, 1740, 1740, 1740, 1740, 2157,
- /*  2360 */  1740, 1740, 1740, 1740,  395, 1740, 1740, 1740, 1740, 1740,
- /*  2370 */  1740, 2107, 1740,  684, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  2380 */  2157, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  2390 */  2139, 1740, 2107, 1740,  684, 1740, 1740, 1740, 1740, 1740,
- /*  2400 */   685, 1740, 1740, 1740, 2138, 1740, 1740, 1740, 2174, 1740,
- /*  2410 */  1740,  333, 2140,  688, 2142, 2143,  683, 1740,  678, 1740,
- /*  2420 */  1740, 1740, 1740, 1740, 1740, 2138, 2157, 1740, 1740, 2174,
- /*  2430 */  1740, 1740,  317, 2140,  688, 2142, 2143,  683, 2107,  678,
- /*  2440 */   684, 2139, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  2450 */  1740,  685, 1740, 1740, 2139, 1740, 1740, 1740, 1740, 1740,
- /*  2460 */  1740, 1740, 1740, 1740,  685, 1740, 1740, 1740, 1740, 1740,
- /*  2470 */  1740, 2138, 1740, 1740, 1740, 2174, 1740, 2157,  318, 2140,
- /*  2480 */   688, 2142, 2143,  683, 1740,  678, 1740, 1740, 1740, 2107,
- /*  2490 */  2157,  684, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  2500 */  1740, 1740, 2107, 1740,  684, 1740, 1740, 1740, 1740, 1740,
- /*  2510 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  2520 */  1740, 1740, 2138, 1740, 1740, 1740, 2174, 1740, 1740,  319,
- /*  2530 */  2140,  688, 2142, 2143,  683, 2138,  678, 1740, 1740, 2174,
- /*  2540 */  2139, 1740,  325, 2140,  688, 2142, 2143,  683, 1740,  678,
- /*  2550 */   685, 1740, 1740, 2139, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  2560 */  1740, 1740, 1740,  685, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  2570 */  2139, 1740, 1740, 1740, 1740, 1740, 2157, 1740, 1740, 1740,
- /*  2580 */   685, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 2107, 2157,
- /*  2590 */   684, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  2600 */  1740, 2107, 1740,  684, 2139, 1740, 2157, 1740, 1740, 1740,
- /*  2610 */  1740, 1740, 1740, 1740,  685, 1740, 1740, 1740, 2107, 1740,
- /*  2620 */   684, 2138, 1740, 1740, 1740, 2174, 1740, 1740,  329, 2140,
- /*  2630 */   688, 2142, 2143,  683, 2138,  678, 1740, 1740, 2174, 1740,
- /*  2640 */  2157,  321, 2140,  688, 2142, 2143,  683, 1740,  678, 1740,
- /*  2650 */  1740, 2138, 2107, 1740,  684, 2174, 1740, 1740,  330, 2140,
- /*  2660 */   688, 2142, 2143,  683, 2139,  678, 1740, 1740, 1740, 1740,
- /*  2670 */  1740, 1740, 1740, 1740,  685, 1740, 1740, 2139, 1740, 1740,
- /*  2680 */  1740, 1740, 1740, 1740, 1740, 2138, 1740,  685, 1740, 2174,
- /*  2690 */  1740, 1740,  322, 2140,  688, 2142, 2143,  683, 1740,  678,
- /*  2700 */  2157, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  2710 */  1740, 1740, 2107, 2157,  684, 1740, 1740, 1740, 1740, 1740,
- /*  2720 */  1740, 1740, 1740, 1740, 1740, 2107, 1740,  684, 2139, 1740,
- /*  2730 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,  685, 1740,
- /*  2740 */  1740, 1740, 1740, 1740, 1740, 2138, 1740, 1740, 1740, 2174,
- /*  2750 */  2139, 1740,  331, 2140,  688, 2142, 2143,  683, 2138,  678,
- /*  2760 */   685, 1740, 2174, 1740, 2157,  323, 2140,  688, 2142, 2143,
- /*  2770 */   683, 1740,  678, 1740, 2139, 1740, 2107, 1740,  684, 1740,
- /*  2780 */  1740, 1740, 1740, 1740,  685, 1740, 2157, 1740, 1740, 1740,
- /*  2790 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 2107, 1740,
- /*  2800 */   684, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 2138,
- /*  2810 */  2157, 1740, 1740, 2174, 1740, 1740,  336, 2140,  688, 2142,
- /*  2820 */  2143,  683, 2107,  678,  684, 1740, 1740, 1740, 1740, 1740,
- /*  2830 */  1740, 2138, 1740, 1740, 1740, 2174, 1740, 1740,  337, 2140,
- /*  2840 */   688, 2142, 2143,  683, 1740,  678, 1740, 1740, 1740, 1740,
- /*  2850 */  1740, 1740, 1740, 1740, 1740, 2138, 1740, 1740, 2139, 2174,
- /*  2860 */  1740, 1740, 2151, 2140,  688, 2142, 2143,  683,  685,  678,
- /*  2870 */  1740, 2139, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  2880 */  1740,  685, 1740, 1740, 1740, 1740, 2139, 1740, 1740, 1740,
- /*  2890 */  1740, 1740, 1740, 1740, 2157, 1740,  685, 1740, 1740, 1740,
- /*  2900 */  1740, 1740, 1740, 1740, 1740, 1740, 2107, 2157,  684, 1740,
- /*  2910 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 2107,
- /*  2920 */  1740,  684, 2157, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  2930 */  1740, 1740, 1740, 1740, 2107, 1740,  684, 1740, 1740, 2138,
- /*  2940 */  1740, 1740, 1740, 2174, 1740, 1740, 2150, 2140,  688, 2142,
- /*  2950 */  2143,  683, 2138,  678, 1740, 1740, 2174, 1740, 1740, 2149,
- /*  2960 */  2140,  688, 2142, 2143,  683, 1740,  678, 2138, 1740, 1740,
- /*  2970 */  2139, 2174, 1740, 1740,  352, 2140,  688, 2142, 2143,  683,
- /*  2980 */   685,  678, 1740, 1740, 1740, 1740, 1740, 2139, 1740, 1740,
- /*  2990 */  1740, 1740, 1740, 1740, 1740, 1740, 1740,  685, 1740, 1740,
- /*  3000 */  2139, 1740, 1740, 1740, 1740, 1740, 2157, 1740, 1740, 1740,
- /*  3010 */   685, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 2107, 1740,
- /*  3020 */   684, 2139, 1740, 2157, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  3030 */  1740,  685, 1740, 1740, 1740, 2107, 2157,  684, 1740, 1740,
- /*  3040 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 2107, 1740,
- /*  3050 */   684, 2138, 1740, 1740, 1740, 2174, 1740, 2157,  353, 2140,
- /*  3060 */   688, 2142, 2143,  683, 1740,  678, 1740, 1740, 2138, 2107,
- /*  3070 */  1740,  684, 2174, 1740, 1740,  349, 2140,  688, 2142, 2143,
- /*  3080 */   683, 2138,  678, 1740, 1740, 2174, 2139, 1740,  354, 2140,
- /*  3090 */   688, 2142, 2143,  683, 1740,  678,  685, 1740, 1740, 1740,
- /*  3100 */  1740, 1740,  686, 1740, 1740, 1740, 2174, 1740, 1740,  328,
- /*  3110 */  2140,  688, 2142, 2143,  683, 1740,  678, 1740, 1740, 1740,
- /*  3120 */  1740, 1740, 2157, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  3130 */  1740, 1740, 1740, 1740, 2107, 1740,  684, 1740, 1740, 1740,
- /*  3140 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  3150 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
- /*  3160 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 2138, 1740, 1740,
- /*  3170 */  1740, 2174, 1740, 1740,  327, 2140,  688, 2142, 2143,  683,
- /*  3180 */  1740,  678,
+ /*   120 */   730,  729,  728,  405,  404,  725,  724,  723,  175,  174,
+ /*   130 */   367,  179,  365,  364, 1539,  556,  403,  402, 1597, 1598,
+ /*   140 */   521,   87,  340,  277, 2235,  644,  518,  134,  643, 1764,
+ /*   150 */  2298,  361, 2016,  670, 1915, 1184,  558,  166,  363, 1521,
+ /*   160 */   557,   62,  318,   51,   62,  632,  186, 1910, 1570, 1580,
+ /*   170 */  2299,  634,  133, 1540, 1596, 1599,  316,   73, 1967,  559,
+ /*   180 */    72, 1741, 1739, 2303,  672,  384, 2199,  182, 1515,  656,
+ /*   190 */  1513,  341, 1540, 1965, 1186, 1734, 1189, 1190, 2107, 1954,
+ /*   200 */  1541,  209,  498,  496,  493,  132,  131,  130,  129,  128,
+ /*   210 */   127,  126,  125,  124,  257,  423,   62, 1518, 1519, 1817,
+ /*   220 */  1569, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579,  682,
+ /*   230 */   678, 1588, 1589, 1591, 1592, 1593, 1594,    2,   48,   46,
+ /*   240 */   531,   62, 2026,  344,  533, 1537,  394, 2242, 1514,  433,
+ /*   250 */   213,  432,  472,  409,  519,  486, 1784,  408,  485, 1595,
+ /*   260 */   123, 1512,  586,  122,  121,  120,  119,  118,  117,  116,
+ /*   270 */   115,  114,   87, 2239,  455,  584,  487,  582,  431,  109,
+ /*   280 */   457,  516, 1693, 1727,  517, 1777,  655, 1590,  572,  571,
+ /*   290 */   570, 1373, 1374,   19, 1733,  562,  137,  566, 1911,  608,
+ /*   300 */  1520,  565, 2298,  645,  140,  669,  564,  569,  369,  368,
+ /*   310 */  1445, 1446,  563,  189, 1524,  189,  189, 2304,  186,   81,
+ /*   320 */    80,  438, 2299,  634,  193,  773,  362, 1283,   15,  620,
+ /*   330 */   619, 1691, 1692, 1694, 1695, 1696, 1294, 2303,  445,  633,
+ /*   340 */  2298,  640, 2298,  568,  567,  342, 1444, 1447,  424, 1293,
+ /*   350 */   279,  422,  418,  414,  411,  431, 2302,  632,  186,  628,
+ /*   360 */  2299, 2301, 2299,  634, 1597, 1598, 1285,  483,  189,  255,
+ /*   370 */   477,  476,  475,  474,  471,  470,  469,  468,  467,  463,
+ /*   380 */   462,  461,  460,  343,  452,  451,  450,   51,  447,  446,
+ /*   390 */   360,  670, 1915,  189, 1570, 1580, 2303,  623,  722, 2298,
+ /*   400 */  1596, 1599, 1539,  647,  184, 2235, 2236,  479,  138, 2240,
+ /*   410 */   191, 2117,   91,  488, 1515, 2302, 1513,  101,  524, 2299,
+ /*   420 */  2300,  517, 1777,   41,   40, 2125, 1192,   47,   45,   44,
+ /*   430 */    43,   42, 1538,   41,   40, 2121,  280,   47,   45,   44,
+ /*   440 */    43,   42, 1908, 1518, 1519,  428, 1569, 1572, 1573, 1574,
+ /*   450 */  1575, 1576, 1577, 1578, 1579,  682,  678, 1588, 1589, 1591,
+ /*   460 */  1592, 1593, 1594,    2,   12,   48,   46,  202,  201,  430,
+ /*   470 */   426, 2123,  391,  394, 1967, 1514, 2033,   62,  656,   93,
+ /*   480 */  1339,  680,  353,  629,  624,  617, 1595, 1541, 1512, 1966,
+ /*   490 */   478, 2031,  657,  670, 1915, 1330,  712,  711,  710, 1334,
+ /*   500 */   709, 1336, 1337,  708,  705, 2139, 1345,  702, 1347, 1348,
+ /*   510 */   699,  696,   57, 2012, 1590,  648,  179,   41,   40,  577,
+ /*   520 */    19,   47,   45,   44,   43,   42, 1624, 1520, 1704,  654,
+ /*   530 */  1207, 2026, 1206, 2242,  587,  595,  513, 2017, 1967,  403,
+ /*   540 */   402, 1538, 2157,  511,  107,  359,  507,  503,  242, 1528,
+ /*   550 */  1428, 1429,  773, 1965, 2107,   15,  686,  656,  194, 2238,
+ /*   560 */  1595,  141, 1521, 1208,  580,  572,  571,  570, 2012, 1907,
+ /*   570 */   574, 1892,  562,  137,  566,  641,  241,  399,  565,   62,
+ /*   580 */  1960, 1962, 1625,  564,  569,  369,  368, 2138, 1590,  563,
+ /*   590 */  2174, 1597, 1598,  110, 2140,  690, 2142, 2143,  685, 1967,
+ /*   600 */   680, 1520, 1967,  744,  742,  183,  389, 2227,  665,  398,
+ /*   610 */  2026,  390, 2223,  196, 1965,  633,   70, 1965, 2298,   69,
+ /*   620 */  1997, 1570, 1580, 1742,  188, 1669,  676, 1596, 1599,  189,
+ /*   630 */  1605, 1539, 2253,  632,  186,   12, 1539,  279, 2299,  634,
+ /*   640 */   674, 1515, 2199, 1513,  123, 1189, 1190,  122,  121,  120,
+ /*   650 */   119,  118,  117,  116,  115,  114,   37,  392, 1619, 1620,
+ /*   660 */  1621, 1622, 1623, 1627, 1628, 1629, 1630,  289,  290, 1763,
+ /*   670 */  1518, 1519,  288, 1569, 1572, 1573, 1574, 1575, 1576, 1577,
+ /*   680 */  1578, 1579,  682,  678, 1588, 1589, 1591, 1592, 1593, 1594,
+ /*   690 */     2,   48,   46, 1600,   44,   43,   42, 2012, 1514,  394,
+ /*   700 */  2139, 1514,  720,  155,  154,  717,  716,  715,  152,   52,
+ /*   710 */   687, 1512, 1595, 2242, 1512, 1529, 1520, 1524, 2107,   41,
+ /*   720 */    40,  713,  388,   47,   45,   44,   43,   42,   41,   40,
+ /*   730 */   165,  189,   47,   45,   44,   43,   42, 2157, 1917, 2237,
+ /*   740 */  1590,   12,  200,   10, 1532, 1534,  670, 1915,  397, 2107,
+ /*   750 */  1520,  686,   54, 1520,    3,   30,  165,  678, 1588, 1589,
+ /*   760 */  1591, 1592, 1593, 1594, 1917,  439,   41,   40,  670, 1915,
+ /*   770 */    47,   45,   44,   43,   42,  773, 1891,  459,  773, 1571,
+ /*   780 */   142,   49, 2138, 2198, 1571, 2174,  458,  440,  110, 2140,
+ /*   790 */   690, 2142, 2143,  685, 2139,  680,  670, 1915,  143,  637,
+ /*   800 */   150, 2198, 2227,  245,  687, 2117,  390, 2223,  720,  155,
+ /*   810 */   154,  717,  716,  715,  152,  449,  732, 1597, 1598, 1906,
+ /*   820 */   670, 1915,  165, 1681,  400,  670, 1915,  670, 1915, 2121,
+ /*   830 */  1918, 2157,  165,  670, 1915, 1542,  377,  670, 1915,  464,
+ /*   840 */  1917, 2139,  722, 2107,  465,  686,  532, 1570, 1580,  670,
+ /*   850 */  1915,  648, 1912, 1596, 1599, 1890,  247,  312, 2247, 1658,
+ /*   860 */  1944,  189,  670, 1915, 1515, 2123, 1513, 1515,  604, 1513,
+ /*   870 */  1487, 1488,  670, 1915,    9,  680, 2138, 2302, 2157, 2174,
+ /*   880 */  1900,  649,  335, 2140,  690, 2142, 2143,  685, 1626,  680,
+ /*   890 */  2107,  653,  686, 1518, 1519,  714, 1518, 1519, 1958, 1569,
+ /*   900 */  1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579,  682,  678,
+ /*   910 */  1588, 1589, 1591, 1592, 1593, 1594,    2,   48,   46, 1662,
+ /*   920 */    14,   13, 1298, 2138, 1539,  394, 2174, 1514,  164,  110,
+ /*   930 */  2140,  690, 2142, 2143,  685, 1297,  680, 1902, 1595,   34,
+ /*   940 */  1512,  183, 1542, 2227,  254,   41,   40,  390, 2223,   47,
+ /*   950 */    45,   44,   43,   42,  670, 1915,  651, 2139,  198,  670,
+ /*   960 */  1915,  106,   35,  146, 2100,  135, 1590,  687, 2254, 1786,
+ /*   970 */    36,  103, 1631,  401,  670, 1915,   41,   40,  299, 1520,
+ /*   980 */    47,   45,   44,   43,   42,  195,  720,  155,  154,  717,
+ /*   990 */   716,  715,  152,  293, 2157,  607,  670, 1915,   84,  490,
+ /*  1000 */  2117,   83,  608,  153,  773, 2298, 2107,   49,  686, 1762,
+ /*  1010 */   608,  670, 1915, 2298, 2126,  667, 1761, 2139, 1760,  244,
+ /*  1020 */  2304,  186, 1638,  243, 2121, 2299,  634,  687, 2304,  186,
+ /*  1030 */   668,  638, 1759, 2299,  634,  718, 1898,  719, 1958, 2138,
+ /*  1040 */  1958, 1758, 2174, 1597, 1598,  110, 2140,  690, 2142, 2143,
+ /*  1050 */   685, 2101,  680,  733, 2157, 2093, 1877, 2318, 2107, 2227,
+ /*  1060 */  2123,  677,   56,  390, 2223, 2107, 2107, 2107,  686, 1757,
+ /*  1070 */   680,  558, 1571, 1570, 1580,  557, 1523, 1919,  442, 1596,
+ /*  1080 */  1599, 2107,  251,   90,  348,  645,  140,  373, 1658,  588,
+ /*  1090 */  2107,  443,  256, 1515,  590, 1513,  589,  608, 1756, 2138,
+ /*  1100 */  2298, 1755, 2174, 1752,  416,  169, 2140,  690, 2142, 2143,
+ /*  1110 */   685,  593,  680, 1751, 1750, 2304,  186,   55, 2107,   74,
+ /*  1120 */  2299,  634, 1518, 1519,  681, 1569, 1572, 1573, 1574, 1575,
+ /*  1130 */  1576, 1577, 1578, 1579,  682,  678, 1588, 1589, 1591, 1592,
+ /*  1140 */  1593, 1594,    2,   48,   46,  609, 2264, 2107,  636, 1857,
+ /*  1150 */  2107,  394, 2107, 1514, 1749, 1748, 1893,  608, 1754, 1747,
+ /*  1160 */  2298, 1746, 2107, 2107, 1595, 1745, 1512, 1744,   82,  234,
+ /*  1170 */  1661,  236,  232,  229,  235, 2304,  186,  153, 2267,  238,
+ /*  1180 */  2299,  634,  237, 2139, 1240,  560,  185, 2235, 2236,  172,
+ /*  1190 */   138, 2240, 1590,  687,  274, 2261,  550,  546,  542,  538,
+ /*  1200 */   148,  226,  561, 2107, 2107, 1520,  240, 1281, 2107,  239,
+ /*  1210 */  2107, 1616, 1736, 1737, 2107, 1522, 2107, 1801, 1793,  621,
+ /*  1220 */  2157, 1791,  153, 1241, 1279,   50,  227,   50,  261,  268,
+ /*  1230 */   773, 1526, 2107,   15,  686,  153, 1482,  645,  140,  573,
+ /*  1240 */   575,   88, 2139,  578,  224,   50,   14,   13,  286,   71,
+ /*  1250 */  1855,  151,  687, 1787,  153,   64,   50, 2158, 1854,  407,
+ /*  1260 */  2021, 1778, 2128,   50, 1955, 2138,  694,  151, 2174, 1597,
+ /*  1270 */  1598,  110, 2140,  690, 2142, 2143,  685, 1783,  680, 2157,
+ /*  1280 */   726, 1485,  153, 2318, 1690, 2227, 1689,  263,  136,  390,
+ /*  1290 */  2223, 2107,  646,  686,  652, 2257,  276,  273,    1, 1570,
+ /*  1300 */  1580,  727, 1259,  768, 1442, 1596, 1599,  291,  662,    5,
+ /*  1310 */   295,  223,  217, 1324, 1632, 1581,  222, 2130,  529, 1515,
+ /*  1320 */   151, 1513,  311, 1257, 2138, 1351, 1355, 2174,  410,  415,
+ /*  1330 */   170, 2140,  690, 2142, 2143,  685,  215,  680,  187, 2235,
+ /*  1340 */  2236, 1362,  138, 2240,  357, 1465,  306, 1360, 1518, 1519,
+ /*  1350 */   199, 1569, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579,
+ /*  1360 */   682,  678, 1588, 1589, 1591, 1592, 1593, 1594,    2,  444,
+ /*  1370 */  1525, 1542,  448, 2022,  453, 2139,  481, 1537,  466,  156,
+ /*  1380 */  2014,  635, 2319,  473,  480,  687,  482, 2274,  492,  491,
+ /*  1390 */   489,  204,  203,  494,  206,  497,  495, 1543,  499,  514,
+ /*  1400 */     4,  515,  523,  522, 1545,  525, 1540,  526, 1544,  214,
+ /*  1410 */  2139,  216, 2157,  527, 1546,  528,  219,  530, 1210,  551,
+ /*  1420 */   687,  221,  615,  534, 2107,  553,  686, 2083,   85,   86,
+ /*  1430 */   225,  552,  347,  112,  592,  594, 2080,   89,  149,  307,
+ /*  1440 */   555,  248, 2139,  598, 1905,  597,  599, 2157,  250, 1472,
+ /*  1450 */   605,  622,  687,  231,  603, 1901,  233, 2138,  158, 2107,
+ /*  1460 */  2174,  686,  159,  110, 2140,  690, 2142, 2143,  685, 1903,
+ /*  1470 */   680, 1899,  252,  160, 2139, 2318,  161, 2227, 2079, 2157,
+ /*  1480 */  2273,  390, 2223, 2272,  687,    8, 2292, 2258,  602,  612,
+ /*  1490 */  2268, 2107, 2138,  686,  660, 2174,  618,  259,  110, 2140,
+ /*  1500 */   690, 2142, 2143,  685,  379,  680,  631,  262,  625, 2249,
+ /*  1510 */  2318, 2157, 2227,  613,  611,  610,  390, 2223,  267,  380,
+ /*  1520 */   642, 2321,  272, 2107, 2138,  686,  639, 2174, 1658, 1541,
+ /*  1530 */   111, 2140,  690, 2142, 2143,  685, 2243,  680,  173,  139,
+ /*  1540 */   650, 2139,  269,  270, 2227,  383, 1547,  271,  281, 2224,
+ /*  1550 */    96,  687, 2027, 2246,  658,  659, 2138,  308, 2041, 2174,
+ /*  1560 */  2040, 2039,  110, 2140,  690, 2142, 2143,  685,  309,  680,
+ /*  1570 */   386,  663,   61, 1916, 2318,  664, 2227,   98, 2157,  275,
+ /*  1580 */   390, 2223, 2297,  100,  310, 2208,  102, 1959, 1878,  692,
+ /*  1590 */  2107,  313,  686,  769,  770,  337,  302,  772,   53,  315,
+ /*  1600 */   322, 2139,  349,  336,  317, 2099, 2098,  326,  350, 2097,
+ /*  1610 */    78,  687, 2094,  412,  413, 1505, 1506,  192,  417, 2092,
+ /*  1620 */   419,  420,  421, 2138, 2091,  358, 2174, 2089,  425,  110,
+ /*  1630 */  2140,  690, 2142, 2143,  685, 2088,  680,  427, 2157, 2087,
+ /*  1640 */    79, 2318,  429, 2227, 1468, 1467, 2053,  390, 2223, 2052,
+ /*  1650 */  2107, 2051,  686,  436,  437, 2050, 2049, 1419, 2005, 2004,
+ /*  1660 */  2002, 2001,  145, 2000, 2003, 1999, 1998, 1996, 1995, 1994,
+ /*  1670 */   197,  454, 1993,  456, 2007, 1992, 1991, 1990, 1989, 1988,
+ /*  1680 */  1987, 1986, 1985, 2138, 1984, 2139, 2174, 1983, 1982,  110,
+ /*  1690 */  2140,  690, 2142, 2143,  685,  687,  680, 1981, 1980, 1979,
+ /*  1700 */  1978, 2202, 1977, 2227,  147, 1976, 1975,  390, 2223, 2006,
+ /*  1710 */  1974, 2139, 1973, 1421, 1972, 1971, 1970,  484, 1969, 1968,
+ /*  1720 */  1820,  687, 2157, 1295, 1291, 1299, 1819, 1818, 1816, 1813,
+ /*  1730 */   500,  345,  205,  346, 2107,  502,  686, 1812, 1805,  504,
+ /*  1740 */  1795, 1773,  501,  505, 1191, 1772, 2139,  207, 2157,  210,
+ /*  1750 */   506,  208,  508, 2070, 2060, 2048,  687,  180,  512, 2047,
+ /*  1760 */  2107, 2025,  686,  510,   76, 1894,  220, 2138, 2127, 1815,
+ /*  1770 */  2174,  509,   77,  110, 2140,  690, 2142, 2143,  685,  181,
+ /*  1780 */   680,  520,  212, 2157, 1811, 2200,  218, 2227,  537, 1809,
+ /*  1790 */   541,  390, 2223, 2138, 1807, 2107, 2174,  686,  535,  110,
+ /*  1800 */  2140,  690, 2142, 2143,  685,  536,  680, 1233,  539,  540,
+ /*  1810 */  2139,  673,  543, 2227,  545,  544, 1804,  390, 2223,  548,
+ /*  1820 */   687,  547,  549, 1790, 1789, 1769, 1896, 1366, 2138, 1895,
+ /*  1830 */  1367, 2174, 1282, 1280,  111, 2140,  690, 2142, 2143,  685,
+ /*  1840 */   741,  680,   63, 1278,  230, 1277, 1276, 2157, 2227, 1275,
+ /*  1850 */  1274,  743, 2226, 2223, 1271, 1270, 1269, 1268, 1802, 2107,
+ /*  1860 */  2139,  686,  370, 1794,  371, 1792,  372,  579,  576, 1768,
+ /*  1870 */   687,  581, 1767,  583, 1766,  585,  113, 2139, 1492, 1496,
+ /*  1880 */  1494, 1491,   29, 2069,   67, 1474, 1476,  687, 2059,  600,
+ /*  1890 */  2046, 2044, 2138,   20, 1706, 2174, 2303, 2157,  111, 2140,
+ /*  1900 */   690, 2142, 2143,  685,   31,  680,   58,    6,   17, 2107,
+ /*  1910 */     7,  686, 2227,  266, 2157,  258,  675, 2223,  601,   21,
+ /*  1920 */    22,  614,  253,  606,  265,  616, 2107,  376,  686, 2128,
+ /*  1930 */    33,  260,   65, 1688, 1680,  163, 1726,  171, 1478,  264,
+ /*  1940 */    24,   32, 2138,   92, 1721, 2174, 1720,  381,  169, 2140,
+ /*  1950 */   690, 2142, 2143,  685, 1727,  680, 1725, 1724,  382,  688,
+ /*  1960 */  1655,  278, 2174, 1654,   60,  111, 2140,  690, 2142, 2143,
+ /*  1970 */   685,  176,  680, 2045, 2043, 2042, 2024, 2139,   95, 2227,
+ /*  1980 */   284,   94,  661,  352, 2223, 2023,   25,  687,  285, 2265,
+ /*  1990 */  1686,  287,   97,  103,  292,  297,   68,   99,   26, 1607,
+ /*  2000 */  1606,   11,   13, 1530, 1617, 2177,  177, 1585,  679,   39,
+ /*  2010 */    23, 1583,  190, 1582, 2157,   16,   18,   27,  294,  378,
+ /*  2020 */  1554, 1562,  689,   59,  693,  396, 2107, 2139,  686,   28,
+ /*  2030 */   695,  691,  697, 1352, 1349, 1346,  698,  687,  700,  701,
+ /*  2040 */   703, 1340,  704, 2139, 1338,  706,  707,  104,  300, 1344,
+ /*  2050 */  1343,  105, 1361,  687,   75, 1357, 1231, 1263,  721, 2138,
+ /*  2060 */  1342, 1262, 2174, 1261, 2157,  335, 2140,  690, 2142, 2143,
+ /*  2070 */   685, 1341,  680, 1260, 1258, 1256, 2107, 1255,  686, 1254,
+ /*  2080 */  2157, 1289,  731, 1252, 1251,  301, 1250, 1249, 1248, 1247,
+ /*  2090 */  1246, 1284, 2107, 1286,  686, 1243, 1242, 1239, 1238, 1236,
+ /*  2100 */  1237, 1810,  751, 2139, 1808,  753,  752,  755,  756, 2138,
+ /*  2110 */   757, 1806, 2174,  687,  759,  328, 2140,  690, 2142, 2143,
+ /*  2120 */   685,  761,  680,  760, 1803, 2138,  763, 2139, 2174,  764,
+ /*  2130 */  1788,  170, 2140,  690, 2142, 2143,  685,  684,  680,  765,
+ /*  2140 */  2157,  767, 1181, 1765,  304,  385,  771, 1740, 1516,  314,
+ /*  2150 */   774,  775, 2107, 1740,  686, 1740, 1740, 1740,  630, 1740,
+ /*  2160 */  1740, 1740, 1740, 1740, 2157, 1740, 1740, 1740, 1740, 1740,
+ /*  2170 */  1740, 1740, 1740, 1740, 1740, 1740, 2107, 1740,  686, 1740,
+ /*  2180 */  1740, 1740, 1740, 2320, 1740, 2138, 1740, 1740, 2174, 2139,
+ /*  2190 */  1740,  335, 2140,  690, 2142, 2143,  685, 1740,  680,  687,
+ /*  2200 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 2138,
+ /*  2210 */  1740, 1740, 2174, 2139, 1740,  334, 2140,  690, 2142, 2143,
+ /*  2220 */   685, 1740,  680,  687, 2193, 1740, 2157, 1740, 1740, 1740,
+ /*  2230 */  1740,  393, 1740, 1740, 1740, 1740, 1740, 1740, 2107, 1740,
+ /*  2240 */   686, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
+ /*  2250 */  2157, 1740, 1740, 1740, 1740,  395, 1740, 1740, 1740, 1740,
+ /*  2260 */  1740, 1740, 2107, 1740,  686, 1740, 1740, 1740, 1740, 1740,
+ /*  2270 */  1740, 2138, 1740, 1740, 2174, 1740, 1740,  335, 2140,  690,
+ /*  2280 */  2142, 2143,  685, 1740,  680, 1740, 2139, 1740, 1740, 1740,
+ /*  2290 */  1740, 1740, 1740, 1740, 1740, 2138,  687,  596, 2174, 1740,
+ /*  2300 */  1740,  335, 2140,  690, 2142, 2143,  685, 1740,  680, 1740,
+ /*  2310 */  1740, 1740, 1740, 1740, 1740,  776, 1740, 1740, 1740, 1740,
+ /*  2320 */  1740, 1740, 1740, 2157, 1740, 1740, 1740, 1740, 1740,  305,
+ /*  2330 */  1740, 1740, 1740, 1740, 1740, 2107, 1740,  686, 1740, 1740,
+ /*  2340 */  1740, 1740, 1740, 1740, 1740,  178, 1740, 1740, 1740, 1740,
+ /*  2350 */  1740, 1740,  766,  762,  758,  754, 1740,  303, 1740, 1740,
+ /*  2360 */  1740, 1740, 2139, 1740, 1740, 1740, 1740, 1740,  591, 1740,
+ /*  2370 */  1740, 2174,  687, 1740,  330, 2140,  690, 2142, 2143,  685,
+ /*  2380 */  1740,  680, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
+ /*  2390 */  1740, 1740, 1740, 1740, 1740, 1740, 1740,  108, 1740, 2157,
+ /*  2400 */   296, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
+ /*  2410 */  1740, 2107, 2139,  686, 1740, 1740, 1740, 1740, 1740, 1740,
+ /*  2420 */  1740, 1740,  687, 1740, 1740, 1740, 1740, 1740, 2139, 1740,
+ /*  2430 */  1740, 1740,  666, 1740, 1740, 1740, 1740, 1740,  687, 1740,
+ /*  2440 */  1740, 1740, 1740, 1740, 2138, 1740, 1740, 2174, 1740, 2157,
+ /*  2450 */   319, 2140,  690, 2142, 2143,  685, 1740,  680, 1740, 1740,
+ /*  2460 */  1740, 2107, 1740,  686, 1740, 2157, 1740,  283, 1740, 1740,
+ /*  2470 */  1740, 1740,  282, 1740, 1740, 1740, 1740, 2107, 1740,  686,
+ /*  2480 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 2139, 1740,
+ /*  2490 */  1740, 1740,  249, 1740, 2138, 1740, 1740, 2174,  687, 1740,
+ /*  2500 */   320, 2140,  690, 2142, 2143,  685, 1740,  680, 1740, 1740,
+ /*  2510 */  2138, 1740, 2139, 2174, 1740, 1740,  321, 2140,  690, 2142,
+ /*  2520 */  2143,  685,  687,  680, 1740, 2157, 1740, 1740, 1740, 1740,
+ /*  2530 */  1740, 1740, 1740, 1740, 1740, 2139, 1740, 2107, 1740,  686,
+ /*  2540 */  1740, 1740, 1740, 1740, 1740,  687, 1740, 1740, 1740, 2157,
+ /*  2550 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 2139,
+ /*  2560 */  1740, 2107, 1740,  686, 1740, 1740, 1740, 1740, 1740,  687,
+ /*  2570 */  2138, 1740, 2157, 2174, 1740, 1740,  327, 2140,  690, 2142,
+ /*  2580 */  2143,  685, 1740,  680, 2107, 1740,  686, 1740, 1740, 1740,
+ /*  2590 */  1740, 1740, 1740, 1740, 2138, 1740, 2157, 2174, 1740, 1740,
+ /*  2600 */   331, 2140,  690, 2142, 2143,  685, 1740,  680, 2107, 1740,
+ /*  2610 */   686, 1740, 1740, 1740, 1740, 1740, 1740, 2138, 1740, 1740,
+ /*  2620 */  2174, 1740, 2139,  323, 2140,  690, 2142, 2143,  685, 1740,
+ /*  2630 */   680, 1740,  687, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
+ /*  2640 */  1740, 2138, 1740, 1740, 2174, 1740, 1740,  332, 2140,  690,
+ /*  2650 */  2142, 2143,  685, 1740,  680, 1740, 1740, 1740, 1740, 2157,
+ /*  2660 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
+ /*  2670 */  1740, 2107, 1740,  686, 1740, 1740, 1740, 1740, 1740, 1740,
+ /*  2680 */  1740, 2139, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
+ /*  2690 */  1740,  687, 1740, 1740, 1740, 1740, 1740, 1740, 2139, 1740,
+ /*  2700 */  1740, 1740, 1740, 1740, 2138, 1740, 1740, 2174,  687, 1740,
+ /*  2710 */   324, 2140,  690, 2142, 2143,  685, 1740,  680, 2157, 1740,
+ /*  2720 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
+ /*  2730 */  2107, 1740,  686, 1740, 1740, 2157, 1740, 1740, 1740, 1740,
+ /*  2740 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 2107, 2139,  686,
+ /*  2750 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,  687, 1740,
+ /*  2760 */  1740, 1740, 1740, 2138, 1740, 1740, 2174, 1740, 2139,  333,
+ /*  2770 */  2140,  690, 2142, 2143,  685, 1740,  680, 1740,  687, 1740,
+ /*  2780 */  2138, 1740, 1740, 2174, 1740, 2157,  325, 2140,  690, 2142,
+ /*  2790 */  2143,  685, 1740,  680, 1740, 1740, 1740, 2107, 1740,  686,
+ /*  2800 */  1740, 1740, 1740, 1740, 1740, 2157, 1740, 1740, 1740, 1740,
+ /*  2810 */  1740, 1740, 1740, 1740, 1740, 2139, 1740, 2107, 1740,  686,
+ /*  2820 */  1740, 1740, 1740, 1740, 1740,  687, 1740, 1740, 1740, 1740,
+ /*  2830 */  2138, 1740, 1740, 2174, 2139, 1740,  338, 2140,  690, 2142,
+ /*  2840 */  2143,  685, 1740,  680,  687, 1740, 1740, 1740, 1740, 1740,
+ /*  2850 */  2138, 1740, 2157, 2174, 1740, 1740,  339, 2140,  690, 2142,
+ /*  2860 */  2143,  685, 1740,  680, 2107, 1740,  686, 1740, 1740, 1740,
+ /*  2870 */  1740, 2157, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
+ /*  2880 */  1740, 2139, 1740, 2107, 1740,  686, 1740, 1740, 1740, 1740,
+ /*  2890 */  1740,  687, 1740, 1740, 1740, 1740, 1740, 2138, 1740, 2139,
+ /*  2900 */  2174, 1740, 1740, 2151, 2140,  690, 2142, 2143,  685,  687,
+ /*  2910 */   680, 1740, 1740, 1740, 1740, 1740, 2138, 1740, 2157, 2174,
+ /*  2920 */  1740, 1740, 2150, 2140,  690, 2142, 2143,  685, 1740,  680,
+ /*  2930 */  2107, 1740,  686, 1740, 1740, 1740, 2157, 1740, 1740, 1740,
+ /*  2940 */  1740, 1740, 1740, 1740, 1740, 1740, 2139, 1740, 2107, 1740,
+ /*  2950 */   686, 1740, 1740, 1740, 1740, 1740,  687, 1740, 1740, 1740,
+ /*  2960 */  1740, 1740, 1740, 2138, 1740, 1740, 2174, 1740, 2139, 2149,
+ /*  2970 */  2140,  690, 2142, 2143,  685, 1740,  680, 1740,  687, 1740,
+ /*  2980 */  1740, 2138, 1740, 2157, 2174, 1740, 1740,  354, 2140,  690,
+ /*  2990 */  2142, 2143,  685, 1740,  680, 2107, 1740,  686, 1740, 1740,
+ /*  3000 */  1740, 1740, 1740, 1740, 1740, 2157, 1740, 1740, 1740, 1740,
+ /*  3010 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 2107, 1740,  686,
+ /*  3020 */  1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 2138, 1740,
+ /*  3030 */  1740, 2174, 1740, 1740,  355, 2140,  690, 2142, 2143,  685,
+ /*  3040 */  1740,  680, 1740, 1740, 2139, 1740, 1740, 1740, 1740, 1740,
+ /*  3050 */  2138, 1740, 1740, 2174,  687, 1740,  351, 2140,  690, 2142,
+ /*  3060 */  2143,  685, 1740,  680, 1740, 1740, 2139, 1740, 1740, 1740,
+ /*  3070 */  1740, 1740, 1740, 1740, 1740, 1740,  687, 1740, 1740, 1740,
+ /*  3080 */  1740, 2157, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
+ /*  3090 */  1740, 1740, 1740, 2107, 2139,  686, 1740, 1740, 1740, 1740,
+ /*  3100 */  1740, 1740, 1740, 2157,  687, 1740, 1740, 1740, 1740, 1740,
+ /*  3110 */  1740, 1740, 1740, 1740, 1740, 2107, 1740,  686, 1740, 1740,
+ /*  3120 */  1740, 1740, 1740, 1740, 1740, 1740, 2138, 1740, 1740, 2174,
+ /*  3130 */  1740, 2157,  356, 2140,  690, 2142, 2143,  685, 1740,  680,
+ /*  3140 */  1740, 1740, 1740, 2107, 1740,  686, 1740, 1740,  688, 1740,
+ /*  3150 */  1740, 2174, 1740, 1740,  330, 2140,  690, 2142, 2143,  685,
+ /*  3160 */  1740,  680, 1740, 1740, 1740, 1740, 1740, 1740, 1740, 1740,
+ /*  3170 */  1740, 1740, 1740, 1740, 1740, 1740, 2138, 1740, 1740, 2174,
+ /*  3180 */  1740, 1740,  329, 2140,  690, 2142, 2143,  685, 1740,  680,
 };
 static const YYCODETYPE yy_lookahead[] = {
- /*     0 */   335,  335,  449,  339,  353,  452,  342,  343,  438,  439,
- /*    10 */   345,  360,   12,   13,   14,   12,   13,   14,   15,   16,
- /*    20 */    20,  468,   22,    8,    9,  472,  473,   12,   13,   14,
- /*    30 */    15,   16,   14,   33,    0,   35,  371,  344,   20,  363,
- /*    40 */    14,  339,  344,  345,  342,  343,   20,  371,  383,  383,
- /*    50 */   385,  345,    8,    9,  378,  379,   12,   13,   14,   15,
- /*    60 */    16,   61,  386,  385,   20,    8,    9,   67,   20,   12,
- /*    70 */    13,   14,   15,   16,   74,  397,   20,  371,  400,  401,
- /*    80 */   387,  416,   44,  344,  345,  420,  357,  358,  423,  424,
- /*    90 */   425,  426,  427,  428,  429,  430,  431,  432,  334,   99,
- /*   100 */   336,  362,  102,   69,   70,   71,   72,   73,  369,   75,
+ /*     0 */   335,  403,  372,  364,    0,  407,  344,  345,  368,  379,
+ /*    10 */   345,  372,   12,   13,   14,  438,  439,  387,  379,  380,
+ /*    20 */    20,  345,   22,    8,    9,  363,  387,   12,   13,   14,
+ /*    30 */    15,   16,  370,   33,    0,   35,  334,  372,  336,   20,
+ /*    40 */   340,   22,  344,  345,  344,  373,  346,  449,  372,  384,
+ /*    50 */   452,  386,    8,    9,   35,  415,   12,   13,   14,   15,
+ /*    60 */    16,   61,   37,    4,   20,  467,  468,   67,  386,   20,
+ /*    70 */   472,  473,   53,   20,   74,   12,   13,   14,   15,   16,
+ /*    80 */   398,   20,  417,  401,  402,  420,  385,  386,  423,  424,
+ /*    90 */   425,  426,  427,  428,  429,  430,  431,  432,  344,   99,
+ /*   100 */   353,  425,  102,   69,   70,   71,   72,   73,  361,   75,
  /*   110 */    76,   77,   78,   79,   80,   81,   82,   83,   84,   85,
  /*   120 */    86,   87,   88,   89,   90,   91,   92,   93,   94,   95,
- /*   130 */   449,  425,  350,  452,  344,  345,   66,   20,  138,  139,
- /*   140 */    20,  103,   22,  445,  446,  447,   20,  449,  450,  468,
- /*   150 */   452,  370,  362,  472,  473,   35,  374,   18,  102,  369,
- /*   160 */   103,   20,   23,  382,  102,  467,  468,  335,  168,  169,
- /*   170 */   472,  473,    3,   53,  174,  175,   37,   38,    8,    9,
- /*   180 */    41,    0,   12,   13,   14,   15,   16,   20,  188,   20,
- /*   190 */   190,   52,    8,    9,  168,  180,   12,   13,   14,   15,
- /*   200 */    16,   62,   63,   64,   65,   24,   25,   26,   27,   28,
- /*   210 */    29,   30,   31,   32,  170,  383,  173,  217,  218,    0,
+ /*   130 */   105,  372,  107,  108,   20,  110,   12,   13,  138,  139,
+ /*   140 */    14,  352,  388,  445,  446,  447,   20,  449,  450,  335,
+ /*   150 */   452,  392,  393,  344,  345,    4,  131,   18,  369,   35,
+ /*   160 */   135,  102,   23,  102,  102,  467,  468,  378,  168,  169,
+ /*   170 */   472,  473,  363,   20,  174,  175,   37,   38,  372,  370,
+ /*   180 */    41,    0,  332,    3,  434,  379,  436,  371,  188,  344,
+ /*   190 */   190,   52,   20,  387,   43,  180,   45,   46,  384,  383,
+ /*   200 */    20,   62,   63,   64,   65,   24,   25,   26,   27,   28,
+ /*   210 */    29,   30,   31,   32,  170,  211,  102,  217,  218,    0,
  /*   220 */   220,  221,  222,  223,  224,  225,  226,  227,  228,  229,
  /*   230 */   230,  231,  232,  233,  234,  235,  236,  237,   12,   13,
- /*   240 */    22,  102,    4,   18,  433,   20,   20,  436,   22,  187,
- /*   250 */    20,  189,   27,   35,   83,   30,  344,  345,   33,   33,
- /*   260 */    21,   35,  371,   24,   25,   26,   27,   28,   29,   30,
- /*   270 */    31,   32,  103,  103,   49,  350,   51,  386,  216,  140,
- /*   280 */    55,   43,  217,   45,   46,  168,  169,   61,   69,   70,
- /*   290 */    71,  366,   74,   67,  279,   76,   77,   78,  371,  374,
- /*   300 */    74,   82,  259,  260,  261,  378,   87,   88,   89,   90,
- /*   310 */   254,  170,   93,  386,  143,  144,  254,   99,   66,  180,
- /*   320 */   181,  182,   20,   61,  185,   99,  101,  385,  102,  264,
- /*   330 */   265,  266,  267,  268,  269,  270,   20,  166,  113,  170,
- /*   340 */   384,  385,  400,  401,    4,  206,  357,  358,  209,   20,
- /*   350 */   373,  212,  213,  214,  215,  216,  444,  445,  446,  447,
- /*   360 */   383,  449,  450,  101,  138,  139,  104,  142,   61,   20,
+ /*   240 */   395,  102,  397,   18,   66,   20,   20,  422,   22,  187,
+ /*   250 */   340,  189,   27,  403,  344,   30,  346,  407,   33,   33,
+ /*   260 */    21,   35,   21,   24,   25,   26,   27,   28,   29,   30,
+ /*   270 */    31,   32,  352,  448,   49,   34,   51,   36,  216,  140,
+ /*   280 */    55,  339,  217,  103,  342,  343,   20,   61,   69,   70,
+ /*   290 */    71,  138,  139,   67,  279,   76,   77,   78,  378,  449,
+ /*   300 */    74,   82,  452,  344,  345,   20,   87,   88,   89,   90,
+ /*   310 */   138,  139,   93,  254,  190,  254,  254,  467,  468,  180,
+ /*   320 */   181,  182,  472,  473,  185,   99,  101,   35,  102,  264,
+ /*   330 */   265,  266,  267,  268,  269,  270,   22,  449,  113,  449,
+ /*   340 */   452,   44,  452,  357,  358,  206,  174,  175,  209,   35,
+ /*   350 */   170,  212,  213,  214,  215,  216,  468,  467,  468,   20,
+ /*   360 */   472,  473,  472,  473,  138,  139,   74,  142,  254,   61,
  /*   370 */   145,  146,  147,  148,  149,  150,  151,  152,  153,  154,
- /*   380 */   155,  156,  157,  158,  159,  160,  161,  352,  163,  164,
- /*   390 */   165,   45,   46,  254,  168,  169,  419,  420,  421,   20,
- /*   400 */   174,  175,  449,  368,  102,  452,  188,  430,  190,  102,
- /*   410 */    20,  104,  377,  133,  188,   47,  190,  137,  102,  422,
- /*   420 */   467,  468,  102,    8,    9,  472,  473,   12,   13,   14,
- /*   430 */    15,   16,  112,    8,    9,  217,  218,   12,   13,   14,
- /*   440 */    15,   16,  102,  217,  218,  448,  220,  221,  222,  223,
+ /*   380 */   155,  156,  157,  158,  159,  160,  161,  102,  163,  164,
+ /*   390 */   165,  344,  345,  254,  168,  169,  449,  173,   66,  452,
+ /*   400 */   174,  175,   20,  444,  445,  446,  447,   83,  449,  450,
+ /*   410 */   363,  360,  104,   99,  188,  468,  190,  350,  339,  472,
+ /*   420 */   473,  342,  343,    8,    9,  374,   14,   12,   13,   14,
+ /*   430 */    15,   16,   20,    8,    9,  384,   61,   12,   13,   14,
+ /*   440 */    15,   16,  375,  217,  218,  183,  220,  221,  222,  223,
  /*   450 */   224,  225,  226,  227,  228,  229,  230,  231,  232,  233,
- /*   460 */   234,  235,  236,  237,  238,   12,   13,  138,  139,   44,
- /*   470 */   102,  344,    0,   20,   99,   22,  381,  197,  198,  384,
- /*   480 */   385,  201,   67,  203,   20,   35,   33,  371,   35,  114,
- /*   490 */   115,  116,  117,  118,  119,  120,  121,  122,  123,  102,
- /*   500 */   125,  126,  127,  128,  129,  130,  183,  391,  392,   33,
- /*   510 */   344,  345,  335,  380,   61,    0,  383,  138,  139,  344,
- /*   520 */    67,  394,  345,  396,   74,   49,  111,   74,  362,  371,
- /*   530 */   207,  208,   56,   57,   58,   59,   21,   61,  344,   24,
- /*   540 */    25,   26,   27,   28,   29,   30,   31,   32,  371,  373,
- /*   550 */   392,   14,   99,  174,  175,  102,  254,   20,  168,  383,
- /*   560 */   383,  254,  385,  102,  340,   69,   70,   71,  344,  394,
- /*   570 */   346,  396,   76,   77,   78,  340,  335,  101,   82,  344,
- /*   580 */   104,  346,  167,   87,   88,   89,   90,    0,  394,   93,
- /*   590 */   396,  138,  139,  416,  254,  419,  420,  420,  344,  345,
- /*   600 */   423,  424,  425,  426,  427,  428,  430,  430,  371,  363,
- /*   610 */   113,   20,  435,   22,  437,  378,  362,  371,  441,  442,
- /*   620 */   422,  168,  169,  386,  383,  379,  332,  174,  175,  157,
- /*   630 */   371,  454,  344,  345,  170,  344,  345,  378,  166,  462,
- /*   640 */     0,  188,  238,  190,   53,  386,  448,  171,  172,  335,
- /*   650 */   362,  254,  176,  362,  178,    3,  241,  242,  243,  244,
- /*   660 */   245,  246,  247,  248,  249,  250,  251,   14,   15,   16,
- /*   670 */   217,  218,  196,  220,  221,  222,  223,  224,  225,  226,
+ /*   460 */   234,  235,  236,  237,  238,   12,   13,  143,  144,  207,
+ /*   470 */   208,  420,  421,   20,  372,   22,  386,  102,  344,  104,
+ /*   480 */    99,  430,   67,  259,  260,  261,   33,   20,   35,  387,
+ /*   490 */   166,  401,  402,  344,  345,  114,  115,  116,  117,  118,
+ /*   500 */   119,  120,  121,  122,  123,  335,  125,  126,  127,  128,
+ /*   510 */   129,  130,  363,  345,   61,  345,  372,    8,    9,    4,
+ /*   520 */    67,   12,   13,   14,   15,   16,  111,   74,  103,  395,
+ /*   530 */    20,  397,   22,  422,   19,  113,   49,  393,  372,   12,
+ /*   540 */    13,   20,  372,   56,  350,  379,   59,   60,   33,   22,
+ /*   550 */   168,  169,   99,  387,  384,  102,  386,  344,  390,  448,
+ /*   560 */    33,  367,   35,   53,   49,   69,   70,   71,  345,  375,
+ /*   570 */    55,    0,   76,   77,   78,  278,   61,  382,   82,  102,
+ /*   580 */   385,  386,  167,   87,   88,   89,   90,  417,   61,   93,
+ /*   590 */   420,  138,  139,  423,  424,  425,  426,  427,  428,  372,
+ /*   600 */   430,   74,  372,  357,  358,  435,  379,  437,  395,  379,
+ /*   610 */   397,  441,  442,  390,  387,  449,  101,  387,  452,  104,
+ /*   620 */     0,  168,  169,    0,  454,   14,   99,  174,  175,  254,
+ /*   630 */    14,   20,  462,  467,  468,  238,   20,  170,  472,  473,
+ /*   640 */   434,  188,  436,  190,   21,   45,   46,   24,   25,   26,
+ /*   650 */    27,   28,   29,   30,   31,   32,  241,  242,  243,  244,
+ /*   660 */   245,  246,  247,  248,  249,  250,  251,  132,  133,  335,
+ /*   670 */   217,  218,  137,  220,  221,  222,  223,  224,  225,  226,
  /*   680 */   227,  228,  229,  230,  231,  232,  233,  234,  235,  236,
- /*   690 */   237,   12,   13,   14,   21,   74,  402,  383,  402,   20,
- /*   700 */   406,   22,  406,  373,  335,  168,  335,   34,  449,   36,
- /*   710 */   371,  452,   33,  383,   35,  254,  345,  378,  131,  132,
- /*   720 */   133,  134,  135,  136,  137,  386,  467,  468,   22,    8,
- /*   730 */     9,  472,  473,   12,   13,   14,   15,   16,   20,  363,
- /*   740 */    61,   35,  371,  449,  371,  449,  452,  371,  452,  419,
- /*   750 */   420,  378,  383,   74,  383,  379,  385,   22,    0,  386,
- /*   760 */   430,  467,  468,  467,  468,  345,  472,  473,  472,  473,
- /*   770 */    35,  131,  132,  133,  134,  135,  136,  137,   99,   49,
- /*   780 */   238,  102,  240,  335,  363,  402,   56,  416,  113,   59,
- /*   790 */    60,  420,  371,  345,  423,  424,  425,  426,  427,  428,
- /*   800 */   379,  430,  344,  345,  433,   99,  435,  436,  437,  389,
- /*   810 */    14,   44,  441,  442,  132,    2,   20,  138,  139,  371,
- /*   820 */   362,    8,    9,  422,   66,   12,   13,   14,   15,   16,
- /*   830 */     2,  383,  449,  385,   99,  452,    8,    9,  335,  335,
- /*   840 */    12,   13,   14,   15,   16,  344,  345,  168,  169,  448,
- /*   850 */   467,  468,   61,  174,  175,  472,  473,    1,    2,    0,
- /*   860 */   132,  133,  344,  345,  416,  137,    4,  188,  420,  190,
- /*   870 */   103,  423,  424,  425,  426,  427,  428,  434,  430,  436,
- /*   880 */   362,  199,  200,  435,  335,  437,  383,  383,  170,  441,
- /*   890 */   442,  170,  402,  335,   74,  104,  217,  218,  167,  220,
+ /*   690 */   237,   12,   13,   14,   14,   15,   16,  345,   22,   20,
+ /*   700 */   335,   22,  131,  132,  133,  134,  135,  136,  137,  102,
+ /*   710 */   345,   35,   33,  422,   35,  188,   74,  190,  384,    8,
+ /*   720 */     9,  113,  364,   12,   13,   14,   15,   16,    8,    9,
+ /*   730 */   372,  254,   12,   13,   14,   15,   16,  372,  380,  448,
+ /*   740 */    61,  238,  390,  240,  217,  218,  344,  345,  364,  384,
+ /*   750 */    74,  386,   42,   74,   44,   44,  372,  230,  231,  232,
+ /*   760 */   233,  234,  235,  236,  380,  363,    8,    9,  344,  345,
+ /*   770 */    12,   13,   14,   15,   16,   99,    0,  157,   99,  168,
+ /*   780 */   433,  102,  417,  436,  168,  420,  166,  363,  423,  424,
+ /*   790 */   425,  426,  427,  428,  335,  430,  344,  345,  433,   44,
+ /*   800 */   435,  436,  437,  132,  345,  360,  441,  442,  131,  132,
+ /*   810 */   133,  134,  135,  136,  137,  363,   74,  138,  139,  374,
+ /*   820 */   344,  345,  372,  103,  364,  344,  345,  344,  345,  384,
+ /*   830 */   380,  372,  372,  344,  345,   20,  377,  344,  345,  363,
+ /*   840 */   380,  335,   66,  384,  363,  386,  363,  168,  169,  344,
+ /*   850 */   345,  345,  363,  174,  175,    0,  363,  365,  252,  253,
+ /*   860 */   368,  254,  344,  345,  188,  420,  190,  188,  363,  190,
+ /*   870 */   199,  200,  344,  345,   39,  430,  417,    3,  372,  420,
+ /*   880 */   373,  363,  423,  424,  425,  426,  427,  428,  167,  430,
+ /*   890 */   384,  363,  386,  217,  218,  381,  217,  218,  384,  220,
  /*   900 */   221,  222,  223,  224,  225,  226,  227,  228,  229,  230,
- /*   910 */   231,  232,  233,  234,  235,  236,  237,   12,   13,  352,
- /*   920 */     4,  371,  434,  402,  436,   20,  274,   22,  335,  379,
- /*   930 */   345,  345,  383,  335,  372,   19,  344,  345,   33,  449,
- /*   940 */    35,  383,  452,  345,  377,  402,  445,  446,  447,   33,
- /*   950 */   449,  450,  372,  380,  362,  335,  383,  467,  468,  103,
- /*   960 */   252,  253,  472,  473,  335,   49,   61,  344,  345,  371,
- /*   970 */   449,   55,  241,  452,  389,  389,  383,   61,   37,   74,
- /*   980 */   367,  383,  251,  385,  335,  362,  344,  345,  467,  468,
- /*   990 */   344,  345,  449,  472,  473,  452,  131,  132,  133,  134,
- /*  1000 */   135,  136,  137,  383,   99,  335,   39,  102,  362,  335,
- /*  1010 */   467,  468,  383,  335,  416,  472,  473,  101,  420,  345,
- /*  1020 */   104,  423,  424,  425,  426,  427,  428,  414,  430,  344,
- /*  1030 */   345,   44,  383,  435,  335,  437,  344,  345,  380,  441,
- /*  1040 */   442,  383,   44,  138,  139,  371,  105,  362,  107,  108,
- /*  1050 */   359,  110,  361,  383,  362,  335,   42,  383,   44,  385,
- /*  1060 */   462,  383,  335,  344,  345,    0,  344,  345,  344,  345,
- /*  1070 */   211,  335,  131,  168,  169,  364,  135,    0,  367,  174,
- /*  1080 */   175,  362,  383,   42,  362,   44,  362,  445,  446,  447,
- /*  1090 */   416,  449,  450,  188,  420,  190,   67,  423,  424,  425,
- /*  1100 */   426,  427,  428,  383,  430,   22,  344,  345,  131,  435,
- /*  1110 */   383,  437,  135,  113,   49,  441,  442,  255,   35,  383,
- /*  1120 */    44,   44,  217,  218,  362,  220,  221,  222,  223,  224,
+ /*   910 */   231,  232,  233,  234,  235,  236,  237,   12,   13,    4,
+ /*   920 */     1,    2,   22,  417,   20,   20,  420,   22,  170,  423,
+ /*   930 */   424,  425,  426,  427,  428,   35,  430,  373,   33,    2,
+ /*   940 */    35,  435,   20,  437,  408,    8,    9,  441,  442,   12,
+ /*   950 */    13,   14,   15,   16,  344,  345,  403,  335,   61,  344,
+ /*   960 */   345,  102,  241,   42,  403,   44,   61,  345,  462,  347,
+ /*   970 */     2,  112,  251,  363,  344,  345,    8,    9,  363,   74,
+ /*   980 */    12,   13,   14,   15,   16,  170,  131,  132,  133,  134,
+ /*   990 */   135,  136,  137,  363,  372,   48,  344,  345,  101,   99,
+ /*  1000 */   360,  104,  449,   44,   99,  452,  384,  102,  386,  335,
+ /*  1010 */   449,  344,  345,  452,  374,  363,  335,  335,  335,  133,
+ /*  1020 */   467,  468,  103,  137,  384,  472,  473,  345,  467,  468,
+ /*  1030 */   363,  276,  335,  472,  473,  381,  373,  381,  384,  417,
+ /*  1040 */   384,  335,  420,  138,  139,  423,  424,  425,  426,  427,
+ /*  1050 */   428,  403,  430,  359,  372,    0,  362,  435,  384,  437,
+ /*  1060 */   420,   67,  103,  441,  442,  384,  384,  384,  386,  335,
+ /*  1070 */   430,  131,  168,  168,  169,  135,   35,  373,   22,  174,
+ /*  1080 */   175,  384,  373,  197,  198,  344,  345,  201,  253,  203,
+ /*  1090 */   384,   35,  170,  188,  202,  190,  204,  449,  335,  417,
+ /*  1100 */   452,  335,  420,  335,   49,  423,  424,  425,  426,  427,
+ /*  1110 */   428,  403,  430,  335,  335,  467,  468,  170,  384,  113,
+ /*  1120 */   472,  473,  217,  218,  373,  220,  221,  222,  223,  224,
  /*  1130 */   225,  226,  227,  228,  229,  230,  231,  232,  233,  234,
- /*  1140 */   235,  236,  237,   12,   13,  344,  345,  344,  345,   35,
- /*  1150 */    44,   20,  106,   22,  106,  109,   13,  109,  344,  345,
- /*  1160 */    13,    0,  162,  362,   33,  362,   35,  335,  106,  106,
- /*  1170 */    44,  109,  109,    0,    0,  407,  362,  345,   35,  103,
- /*  1180 */    44,  372,   35,   22,  202,   48,  204,  138,  139,   35,
- /*  1190 */   335,  372,   61,   35,   44,   22,   22,    1,    2,   13,
- /*  1200 */   345,   13,  347,  371,  360,   74,   44,   44,  376,  103,
- /*  1210 */   372,  372,  372,   44,   44,  383,  336,  385,    0,  393,
- /*  1220 */   253,   35,  476,   35,  465,   44,  371,   44,   44,  103,
- /*  1230 */    99,  348,   74,  102,   44,   44,  459,  371,  383,  103,
- /*  1240 */   385,  335,   44,   44,  348,  393,  217,  343,  416,  382,
- /*  1250 */    44,  345,  420,  103,   44,  423,  424,  425,  426,  427,
- /*  1260 */   428,  393,  430,  276,  345,  103,  103,  451,   50,  138,
- /*  1270 */   139,  416,  103,  103,  469,  420,  278,  371,  423,  424,
- /*  1280 */   425,  426,  427,  428,  103,  430,  103,  103,  443,  383,
- /*  1290 */   435,  385,  437,  103,  103,  453,  441,  442,  256,  168,
- /*  1300 */   169,  103,  103,  418,  190,  174,  175,  170,   49,  103,
- /*  1310 */   417,  186,  404,  103,   42,  390,   20,  393,  390,  188,
- /*  1320 */   167,  190,  416,  388,   20,  344,  420,  344,  390,  423,
- /*  1330 */   424,  425,  426,  427,  428,  388,  430,  388,  100,   98,
- /*  1340 */   356,  355,   97,  344,  190,  354,  344,  344,  217,  218,
- /*  1350 */   344,  220,  221,  222,  223,  224,  225,  226,  227,  228,
- /*  1360 */   229,  230,  231,  232,  233,  234,  235,  236,  237,  335,
- /*  1370 */   464,   20,  337,   48,  341,  337,   20,  341,  352,  345,
- /*  1380 */   411,  347,   20,  352,   20,  346,  385,   20,  403,  352,
- /*  1390 */   346,  344,  352,   54,  337,  352,  335,  352,  371,  371,
- /*  1400 */   349,  349,  352,  371,  337,  371,  345,  383,  347,  205,
- /*  1410 */   344,  415,  102,  383,  194,  411,  193,  383,  413,  385,
- /*  1420 */   350,  410,  409,  350,  371,  371,  371,  371,  192,  371,
- /*  1430 */   371,  371,  371,  408,  344,  371,  458,  458,  263,  262,
- /*  1440 */   179,  461,  271,  477,  383,  273,  385,  458,  460,  457,
- /*  1450 */   416,  383,  383,  456,  420,  277,  385,  423,  424,  425,
- /*  1460 */   426,  427,  428,  383,  430,  393,  272,  393,  335,  435,
- /*  1470 */   383,  437,  383,  398,  257,  441,  442,  416,  345,  398,
- /*  1480 */   347,  420,  280,  471,  423,  424,  425,  426,  427,  428,
- /*  1490 */   275,  430,  470,  253,  345,   20,  435,  418,  437,  344,
- /*  1500 */   335,  350,  441,  442,  371,  346,  422,  350,   20,  396,
- /*  1510 */   345,  383,  347,  398,  398,  383,  383,  383,  385,  172,
- /*  1520 */   102,  383,  383,  383,  395,  345,  350,  367,  335,  350,
- /*  1530 */   102,  440,   36,  455,  412,  383,  371,  350,  345,  375,
- /*  1540 */   347,  344,  337,  361,  399,  338,  405,  399,  383,  416,
- /*  1550 */   385,    0,  333,  420,  365,    0,  423,  424,  425,  426,
- /*  1560 */   427,  428,  351,  430,  371,  365,  365,    0,  435,   42,
- /*  1570 */   437,    0,   35,   35,  441,  442,  383,   35,  385,  210,
- /*  1580 */    35,  416,  210,    0,   35,  420,  210,   35,  423,  424,
- /*  1590 */   425,  426,  427,  428,    0,  430,  210,    0,   35,    0,
- /*  1600 */   435,    0,  437,   22,   12,   13,  441,  442,   35,  416,
- /*  1610 */   197,  190,  188,  420,   22,    0,  423,  424,  425,  426,
- /*  1620 */   427,  428,    1,  430,    0,   33,  335,   35,  435,    0,
- /*  1630 */   437,  184,  183,    0,  441,  442,  345,    0,   47,    0,
- /*  1640 */    19,    0,    0,    0,   42,    0,    0,    0,    0,    0,
- /*  1650 */     0,    0,  157,   61,   33,   35,    0,  157,    0,    0,
- /*  1660 */     0,    0,  371,  141,   42,    0,   74,    0,    0,    0,
- /*  1670 */    49,    0,    0,    0,  383,    0,  385,   56,   57,   58,
- /*  1680 */    59,    0,   61,    0,    0,    0,    0,    0,    0,    0,
- /*  1690 */     0,   99,   22,    0,    0,    0,    0,    0,  335,    0,
- /*  1700 */    22,   48,   22,   48,    0,   61,    0,  416,  345,   35,
- /*  1710 */     0,  420,    0,   61,  423,  424,  425,  426,  427,  428,
- /*  1720 */     0,  430,  101,   61,    0,  104,  435,    0,  437,    0,
- /*  1730 */    39,   49,  441,  442,  371,   35,   35,    0,   35,   14,
- /*  1740 */     0,   39,   35,    0,    0,    0,  383,   49,  385,  179,
- /*  1750 */    39,   42,   39,    0,   49,   47,   39,  136,   44,   40,
- /*  1760 */    39,    0,   47,   47,    0,    0,    0,   35,    0,   39,
- /*  1770 */    35,   49,   49,   39,    0,   39,   35,   49,    0,  416,
- /*  1780 */   188,   35,  190,  420,    0,    0,  423,  424,  425,  426,
- /*  1790 */   427,  428,  171,  430,   68,   39,  335,  176,   49,    0,
- /*  1800 */   437,   22,   35,    0,  441,  442,  345,    0,   35,  217,
- /*  1810 */   218,   35,   35,   44,   44,   35,   35,  196,   35,   22,
- /*  1820 */   335,   35,  230,  231,  232,  233,  234,  235,  236,  111,
- /*  1830 */   345,   35,  371,   35,    0,   35,   22,    0,   22,    0,
- /*  1840 */   109,   51,   22,   35,  383,    0,  385,   35,    0,    0,
- /*  1850 */    35,   22,   20,  103,   35,    0,  371,   35,   35,  102,
- /*  1860 */   102,  195,   35,   22,    0,   22,    0,  191,  383,    0,
- /*  1870 */   385,    3,   44,  102,  258,  103,  258,  416,   48,   48,
- /*  1880 */    44,  420,  100,    3,  423,  424,  425,  426,  427,  428,
- /*  1890 */    98,  430,  103,  102,  335,   44,  103,  102,  437,   47,
- /*  1900 */    44,  416,  441,  442,  345,  420,  102,  102,  423,  424,
- /*  1910 */   425,  426,  427,  428,  335,  430,  177,  170,  170,   47,
- /*  1920 */   103,   44,  437,  172,  345,  170,  441,  442,  102,   35,
- /*  1930 */   371,   44,   35,   35,   35,  258,  103,   47,  103,   35,
- /*  1940 */    35,  103,  383,  103,  385,   44,    0,   47,    0,    0,
- /*  1950 */   371,    0,  102,   39,   47,  102,    0,  103,   39,  112,
- /*  1960 */   103,  102,  383,  102,  385,  102,   44,  173,   47,  102,
- /*  1970 */   100,  100,  239,  171,    2,  416,   22,  217,  102,  420,
- /*  1980 */    47,  103,  423,  424,  425,  426,  427,  428,  102,  430,
- /*  1990 */   252,  103,  103,  102,  102,  416,  103,  102,  335,  420,
- /*  2000 */    47,   22,  423,  424,  425,  426,  427,  428,  345,  430,
- /*  2010 */   102,   35,  103,   35,  102,   35,  113,   35,   35,  103,
- /*  2020 */   102,   35,  463,  464,   35,  219,  103,  335,  102,   44,
- /*  2030 */   103,  102,   22,  103,  371,  124,  102,  345,  102,  102,
- /*  2040 */   102,  124,   68,   35,  124,   74,  383,   35,  385,  124,
- /*  2050 */    35,   67,   35,  474,  475,   35,   35,   35,   35,   35,
- /*  2060 */    35,   96,   44,  371,   35,   35,   35,   22,  376,   35,
- /*  2070 */    35,   35,   74,   35,   35,  383,   35,  385,   35,  416,
- /*  2080 */    22,   35,   35,  420,    0,   35,  423,  424,  425,  426,
- /*  2090 */   427,  428,   39,  430,    0,   35,   39,   49,   49,    0,
- /*  2100 */   437,   35,   39,   49,    0,  442,   35,   39,  416,    0,
- /*  2110 */    49,   35,  420,   35,    0,  423,  424,  425,  426,  427,
- /*  2120 */   428,   21,  430,  335,   22,   22,  478,   22,   21,  478,
- /*  2130 */    20,  478,  478,  345,  478,  478,  335,  478,  478,  478,
- /*  2140 */   478,  478,  478,  478,  478,  478,  345,  478,  478,  478,
- /*  2150 */   478,  478,  478,  335,  478,  478,  478,  478,  478,  371,
- /*  2160 */   478,  478,  478,  345,  478,  478,  478,  478,  478,  478,
- /*  2170 */   478,  383,  371,  385,  478,  478,  478,  478,  478,  478,
- /*  2180 */   478,  478,  478,  478,  383,  478,  385,  478,  478,  371,
- /*  2190 */   478,  478,  478,  478,  478,  478,  478,  478,  478,  478,
- /*  2200 */   478,  383,  478,  385,  416,  478,  478,  478,  420,  478,
- /*  2210 */   478,  423,  424,  425,  426,  427,  428,  416,  430,  478,
- /*  2220 */   335,  420,  478,  478,  423,  424,  425,  426,  427,  428,
- /*  2230 */   345,  430,  478,  478,  416,  478,  478,  335,  420,  478,
- /*  2240 */   478,  423,  424,  425,  426,  427,  428,  345,  430,  478,
- /*  2250 */   335,  478,  478,  478,  466,  478,  371,  478,  478,  478,
- /*  2260 */   345,  376,  478,  478,  478,  478,  478,  478,  383,  478,
- /*  2270 */   385,  478,  478,  371,  478,  478,  475,  478,  478,  478,
- /*  2280 */   478,  478,  478,  478,  478,  383,  371,  385,  478,  478,
- /*  2290 */   478,  376,  478,  478,  478,  478,  478,  478,  383,  478,
- /*  2300 */   385,  416,  478,  478,  478,  420,  478,  478,  423,  424,
- /*  2310 */   425,  426,  427,  428,  478,  430,  478,  478,  416,  478,
- /*  2320 */   478,  478,  420,  335,  478,  423,  424,  425,  426,  427,
- /*  2330 */   428,  416,  430,  345,  432,  420,  478,  478,  423,  424,
- /*  2340 */   425,  426,  427,  428,  335,  430,  478,  478,  478,  478,
- /*  2350 */   478,  478,  478,  478,  345,  478,  478,  478,  478,  371,
- /*  2360 */   478,  478,  478,  478,  376,  478,  478,  478,  478,  478,
- /*  2370 */   478,  383,  478,  385,  478,  478,  478,  478,  478,  478,
- /*  2380 */   371,  478,  478,  478,  478,  478,  478,  478,  478,  478,
- /*  2390 */   335,  478,  383,  478,  385,  478,  478,  478,  478,  478,
- /*  2400 */   345,  478,  478,  478,  416,  478,  478,  478,  420,  478,
- /*  2410 */   478,  423,  424,  425,  426,  427,  428,  478,  430,  478,
- /*  2420 */   478,  478,  478,  478,  478,  416,  371,  478,  478,  420,
- /*  2430 */   478,  478,  423,  424,  425,  426,  427,  428,  383,  430,
- /*  2440 */   385,  335,  478,  478,  478,  478,  478,  478,  478,  478,
- /*  2450 */   478,  345,  478,  478,  335,  478,  478,  478,  478,  478,
- /*  2460 */   478,  478,  478,  478,  345,  478,  478,  478,  478,  478,
- /*  2470 */   478,  416,  478,  478,  478,  420,  478,  371,  423,  424,
- /*  2480 */   425,  426,  427,  428,  478,  430,  478,  478,  478,  383,
- /*  2490 */   371,  385,  478,  478,  478,  478,  478,  478,  478,  478,
- /*  2500 */   478,  478,  383,  478,  385,  478,  478,  478,  478,  478,
- /*  2510 */   478,  478,  478,  478,  478,  478,  478,  478,  478,  478,
- /*  2520 */   478,  478,  416,  478,  478,  478,  420,  478,  478,  423,
- /*  2530 */   424,  425,  426,  427,  428,  416,  430,  478,  478,  420,
- /*  2540 */   335,  478,  423,  424,  425,  426,  427,  428,  478,  430,
- /*  2550 */   345,  478,  478,  335,  478,  478,  478,  478,  478,  478,
- /*  2560 */   478,  478,  478,  345,  478,  478,  478,  478,  478,  478,
- /*  2570 */   335,  478,  478,  478,  478,  478,  371,  478,  478,  478,
- /*  2580 */   345,  478,  478,  478,  478,  478,  478,  478,  383,  371,
- /*  2590 */   385,  478,  478,  478,  478,  478,  478,  478,  478,  478,
- /*  2600 */   478,  383,  478,  385,  335,  478,  371,  478,  478,  478,
- /*  2610 */   478,  478,  478,  478,  345,  478,  478,  478,  383,  478,
- /*  2620 */   385,  416,  478,  478,  478,  420,  478,  478,  423,  424,
- /*  2630 */   425,  426,  427,  428,  416,  430,  478,  478,  420,  478,
- /*  2640 */   371,  423,  424,  425,  426,  427,  428,  478,  430,  478,
- /*  2650 */   478,  416,  383,  478,  385,  420,  478,  478,  423,  424,
- /*  2660 */   425,  426,  427,  428,  335,  430,  478,  478,  478,  478,
- /*  2670 */   478,  478,  478,  478,  345,  478,  478,  335,  478,  478,
- /*  2680 */   478,  478,  478,  478,  478,  416,  478,  345,  478,  420,
- /*  2690 */   478,  478,  423,  424,  425,  426,  427,  428,  478,  430,
- /*  2700 */   371,  478,  478,  478,  478,  478,  478,  478,  478,  478,
- /*  2710 */   478,  478,  383,  371,  385,  478,  478,  478,  478,  478,
- /*  2720 */   478,  478,  478,  478,  478,  383,  478,  385,  335,  478,
- /*  2730 */   478,  478,  478,  478,  478,  478,  478,  478,  345,  478,
- /*  2740 */   478,  478,  478,  478,  478,  416,  478,  478,  478,  420,
- /*  2750 */   335,  478,  423,  424,  425,  426,  427,  428,  416,  430,
- /*  2760 */   345,  478,  420,  478,  371,  423,  424,  425,  426,  427,
- /*  2770 */   428,  478,  430,  478,  335,  478,  383,  478,  385,  478,
- /*  2780 */   478,  478,  478,  478,  345,  478,  371,  478,  478,  478,
- /*  2790 */   478,  478,  478,  478,  478,  478,  478,  478,  383,  478,
- /*  2800 */   385,  478,  478,  478,  478,  478,  478,  478,  478,  416,
- /*  2810 */   371,  478,  478,  420,  478,  478,  423,  424,  425,  426,
- /*  2820 */   427,  428,  383,  430,  385,  478,  478,  478,  478,  478,
- /*  2830 */   478,  416,  478,  478,  478,  420,  478,  478,  423,  424,
- /*  2840 */   425,  426,  427,  428,  478,  430,  478,  478,  478,  478,
- /*  2850 */   478,  478,  478,  478,  478,  416,  478,  478,  335,  420,
- /*  2860 */   478,  478,  423,  424,  425,  426,  427,  428,  345,  430,
- /*  2870 */   478,  335,  478,  478,  478,  478,  478,  478,  478,  478,
- /*  2880 */   478,  345,  478,  478,  478,  478,  335,  478,  478,  478,
- /*  2890 */   478,  478,  478,  478,  371,  478,  345,  478,  478,  478,
- /*  2900 */   478,  478,  478,  478,  478,  478,  383,  371,  385,  478,
- /*  2910 */   478,  478,  478,  478,  478,  478,  478,  478,  478,  383,
- /*  2920 */   478,  385,  371,  478,  478,  478,  478,  478,  478,  478,
- /*  2930 */   478,  478,  478,  478,  383,  478,  385,  478,  478,  416,
- /*  2940 */   478,  478,  478,  420,  478,  478,  423,  424,  425,  426,
- /*  2950 */   427,  428,  416,  430,  478,  478,  420,  478,  478,  423,
- /*  2960 */   424,  425,  426,  427,  428,  478,  430,  416,  478,  478,
- /*  2970 */   335,  420,  478,  478,  423,  424,  425,  426,  427,  428,
- /*  2980 */   345,  430,  478,  478,  478,  478,  478,  335,  478,  478,
- /*  2990 */   478,  478,  478,  478,  478,  478,  478,  345,  478,  478,
- /*  3000 */   335,  478,  478,  478,  478,  478,  371,  478,  478,  478,
- /*  3010 */   345,  478,  478,  478,  478,  478,  478,  478,  383,  478,
- /*  3020 */   385,  335,  478,  371,  478,  478,  478,  478,  478,  478,
- /*  3030 */   478,  345,  478,  478,  478,  383,  371,  385,  478,  478,
- /*  3040 */   478,  478,  478,  478,  478,  478,  478,  478,  383,  478,
- /*  3050 */   385,  416,  478,  478,  478,  420,  478,  371,  423,  424,
- /*  3060 */   425,  426,  427,  428,  478,  430,  478,  478,  416,  383,
- /*  3070 */   478,  385,  420,  478,  478,  423,  424,  425,  426,  427,
- /*  3080 */   428,  416,  430,  478,  478,  420,  335,  478,  423,  424,
- /*  3090 */   425,  426,  427,  428,  478,  430,  345,  478,  478,  478,
- /*  3100 */   478,  478,  416,  478,  478,  478,  420,  478,  478,  423,
- /*  3110 */   424,  425,  426,  427,  428,  478,  430,  478,  478,  478,
- /*  3120 */   478,  478,  371,  478,  478,  478,  478,  478,  478,  478,
- /*  3130 */   478,  478,  478,  478,  383,  478,  385,  478,  478,  478,
- /*  3140 */   478,  478,  478,  478,  478,  478,  478,  478,  478,  478,
- /*  3150 */   478,  478,  478,  478,  478,  478,  478,  478,  478,  478,
- /*  3160 */   478,  478,  478,  478,  478,  478,  478,  416,  478,  478,
- /*  3170 */   478,  420,  478,  478,  423,  424,  425,  426,  427,  428,
- /*  3180 */   478,  430,  332,  332,  332,  332,  332,  332,  332,  332,
+ /*  1140 */   235,  236,  237,   12,   13,  463,  464,  384,  274,  361,
+ /*  1150 */   384,   20,  384,   22,  335,  335,    0,  449,  336,  335,
+ /*  1160 */   452,  335,  384,  384,   33,  335,   35,  335,  162,  106,
+ /*  1170 */   255,  106,  109,   33,  109,  467,  468,   44,  394,  106,
+ /*  1180 */   472,  473,  109,  335,   35,   13,  445,  446,  447,   49,
+ /*  1190 */   449,  450,   61,  345,  476,  347,   56,   57,   58,   59,
+ /*  1200 */    44,   61,   13,  384,  384,   74,  106,   35,  384,  109,
+ /*  1210 */   384,  217,  138,  139,  384,   35,  384,    0,    0,  465,
+ /*  1220 */   372,    0,   44,   74,   35,   44,  348,   44,   44,  459,
+ /*  1230 */    99,  190,  384,  102,  386,   44,  103,  344,  345,   22,
+ /*  1240 */    22,  101,  335,   22,  104,   44,    1,    2,   44,   44,
+ /*  1250 */   360,   44,  345,    0,   44,   44,   44,  372,  360,  348,
+ /*  1260 */   394,  343,   47,   44,  383,  417,   44,   44,  420,  138,
+ /*  1270 */   139,  423,  424,  425,  426,  427,  428,  345,  430,  372,
+ /*  1280 */    13,  103,   44,  435,  103,  437,  103,  103,   44,  441,
+ /*  1290 */   442,  384,  451,  386,  103,  394,  469,  443,  453,  168,
+ /*  1300 */   169,   13,   35,   50,  103,  174,  175,  103,  103,  256,
+ /*  1310 */   103,  171,  172,  103,  103,  103,  176,  102,  178,  188,
+ /*  1320 */    44,  190,  103,   35,  417,  103,  103,  420,  419,   49,
+ /*  1330 */   423,  424,  425,  426,  427,  428,  196,  430,  445,  446,
+ /*  1340 */   447,  103,  449,  450,  418,  186,  405,  103,  217,  218,
+ /*  1350 */    42,  220,  221,  222,  223,  224,  225,  226,  227,  228,
+ /*  1360 */   229,  230,  231,  232,  233,  234,  235,  236,  237,  391,
+ /*  1370 */   190,   20,  391,  394,  389,  335,  167,   20,  344,  103,
+ /*  1380 */   344,  474,  475,  391,  389,  345,  389,  347,  356,  100,
+ /*  1390 */    98,  344,  355,   97,  344,  344,  354,   20,  344,  337,
+ /*  1400 */    48,  341,  341,  337,   20,  412,   20,  386,   20,  352,
+ /*  1410 */   335,  352,  372,  346,   20,  404,  352,  346,   54,  349,
+ /*  1420 */   345,  352,  347,  344,  384,  337,  386,  384,  352,  352,
+ /*  1430 */   352,  349,  337,  344,  205,  416,  384,  102,  414,  412,
+ /*  1440 */   372,  350,  335,  194,  372,  193,  411,  372,  410,  192,
+ /*  1450 */   344,  263,  345,  372,  409,  372,  372,  417,  372,  384,
+ /*  1460 */   420,  386,  372,  423,  424,  425,  426,  427,  428,  372,
+ /*  1470 */   430,  372,  350,  372,  335,  435,  372,  437,  384,  372,
+ /*  1480 */   458,  441,  442,  458,  345,  271,  347,  394,  386,  384,
+ /*  1490 */   394,  384,  417,  386,  262,  420,  384,  399,  423,  424,
+ /*  1500 */   425,  426,  427,  428,  384,  430,  179,  399,  384,  461,
+ /*  1510 */   435,  372,  437,  273,  272,  257,  441,  442,  460,  280,
+ /*  1520 */   277,  477,  419,  384,  417,  386,  275,  420,  253,   20,
+ /*  1530 */   423,  424,  425,  426,  427,  428,  422,  430,  458,  345,
+ /*  1540 */   344,  335,  457,  456,  437,  346,   20,  455,  350,  442,
+ /*  1550 */   350,  345,  397,  347,  384,  384,  417,  399,  384,  420,
+ /*  1560 */   384,  384,  423,  424,  425,  426,  427,  428,  399,  430,
+ /*  1570 */   384,  172,  102,  345,  435,  396,  437,  350,  372,  470,
+ /*  1580 */   441,  442,  471,  350,  368,  440,  102,  384,  362,  376,
+ /*  1590 */   384,  344,  386,   36,  338,  413,  350,  337,  406,  351,
+ /*  1600 */   366,  335,  400,  366,  333,    0,    0,  366,  400,    0,
+ /*  1610 */    42,  345,    0,   35,  210,   35,   35,   35,  210,    0,
+ /*  1620 */    35,   35,  210,  417,    0,  210,  420,    0,   35,  423,
+ /*  1630 */   424,  425,  426,  427,  428,    0,  430,   22,  372,    0,
+ /*  1640 */   197,  435,   35,  437,  190,  188,    0,  441,  442,    0,
+ /*  1650 */   384,    0,  386,  184,  183,    0,    0,   47,    0,    0,
+ /*  1660 */     0,    0,   42,    0,    0,    0,    0,    0,    0,    0,
+ /*  1670 */   157,   35,    0,  157,    0,    0,    0,    0,    0,    0,
+ /*  1680 */     0,    0,    0,  417,    0,  335,  420,    0,    0,  423,
+ /*  1690 */   424,  425,  426,  427,  428,  345,  430,    0,    0,    0,
+ /*  1700 */     0,  435,    0,  437,   42,    0,    0,  441,  442,    0,
+ /*  1710 */     0,  335,    0,   22,    0,    0,    0,  141,    0,    0,
+ /*  1720 */     0,  345,  372,   22,   35,   22,    0,    0,    0,    0,
+ /*  1730 */    35,   48,   61,   48,  384,   39,  386,    0,    0,   35,
+ /*  1740 */     0,    0,   49,   49,   14,    0,  335,   61,  372,   42,
+ /*  1750 */    39,   61,   35,    0,    0,    0,  345,   44,   35,    0,
+ /*  1760 */   384,    0,  386,   39,   39,    0,  179,  417,   47,    0,
+ /*  1770 */   420,   49,   39,  423,  424,  425,  426,  427,  428,   47,
+ /*  1780 */   430,   47,   40,  372,    0,  435,   39,  437,   39,    0,
+ /*  1790 */    39,  441,  442,  417,    0,  384,  420,  386,   35,  423,
+ /*  1800 */   424,  425,  426,  427,  428,   49,  430,   68,   35,   49,
+ /*  1810 */   335,  435,   35,  437,   39,   49,    0,  441,  442,   49,
+ /*  1820 */   345,   35,   39,    0,    0,    0,    0,   22,  417,    0,
+ /*  1830 */    35,  420,   35,   35,  423,  424,  425,  426,  427,  428,
+ /*  1840 */    44,  430,  111,   35,  109,   35,   35,  372,  437,   35,
+ /*  1850 */    35,   44,  441,  442,   35,   35,   22,   35,    0,  384,
+ /*  1860 */   335,  386,   22,    0,   22,    0,   22,   35,   51,    0,
+ /*  1870 */   345,   35,    0,   35,    0,   22,   20,  335,   35,  103,
+ /*  1880 */    35,   35,  102,    0,  102,   35,   22,  345,    0,   22,
+ /*  1890 */     0,    0,  417,   44,  103,  420,    3,  372,  423,  424,
+ /*  1900 */   425,  426,  427,  428,  102,  430,  170,   48,  258,  384,
+ /*  1910 */    48,  386,  437,   47,  372,  102,  441,  442,  170,   44,
+ /*  1920 */    44,  100,  172,  177,   44,   98,  384,  170,  386,   47,
+ /*  1930 */    44,  103,    3,  103,  103,  191,  103,  102,  195,  102,
+ /*  1940 */    44,  102,  417,  102,   35,  420,   35,   35,  423,  424,
+ /*  1950 */   425,  426,  427,  428,  103,  430,   35,   35,   35,  417,
+ /*  1960 */   103,   47,  420,  103,   44,  423,  424,  425,  426,  427,
+ /*  1970 */   428,   47,  430,    0,    0,    0,    0,  335,   39,  437,
+ /*  1980 */    47,  102,  173,  441,  442,    0,  102,  345,  103,  464,
+ /*  1990 */   103,  102,   39,  112,  102,   47,  102,  102,   44,  100,
+ /*  2000 */   100,  239,    2,   22,  217,  102,   47,  103,  102,  102,
+ /*  2010 */   258,  103,   47,  103,  372,  102,  258,  102,  171,  377,
+ /*  2020 */   103,   22,  219,  252,   35,   35,  384,  335,  386,  102,
+ /*  2030 */   102,  113,   35,  103,  103,  103,  102,  345,   35,  102,
+ /*  2040 */    35,  103,  102,  335,  103,   35,  102,  102,   44,  124,
+ /*  2050 */   124,  102,   35,  345,  102,   22,   68,   35,   67,  417,
+ /*  2060 */   124,   35,  420,   35,  372,  423,  424,  425,  426,  427,
+ /*  2070 */   428,  124,  430,   35,   35,   35,  384,   35,  386,   35,
+ /*  2080 */   372,   74,   96,   35,   35,   44,   35,   22,   35,   35,
+ /*  2090 */    35,   35,  384,   74,  386,   35,   35,   35,   35,   35,
+ /*  2100 */    22,    0,   35,  335,    0,   39,   49,   35,   49,  417,
+ /*  2110 */    39,    0,  420,  345,   35,  423,  424,  425,  426,  427,
+ /*  2120 */   428,   39,  430,   49,    0,  417,   35,  335,  420,   49,
+ /*  2130 */     0,  423,  424,  425,  426,  427,  428,  345,  430,   39,
+ /*  2140 */   372,   35,   35,    0,   22,  377,   21,  478,   22,   22,
+ /*  2150 */    21,   20,  384,  478,  386,  478,  478,  478,  466,  478,
+ /*  2160 */   478,  478,  478,  478,  372,  478,  478,  478,  478,  478,
+ /*  2170 */   478,  478,  478,  478,  478,  478,  384,  478,  386,  478,
+ /*  2180 */   478,  478,  478,  475,  478,  417,  478,  478,  420,  335,
+ /*  2190 */   478,  423,  424,  425,  426,  427,  428,  478,  430,  345,
+ /*  2200 */   478,  478,  478,  478,  478,  478,  478,  478,  478,  417,
+ /*  2210 */   478,  478,  420,  335,  478,  423,  424,  425,  426,  427,
+ /*  2220 */   428,  478,  430,  345,  432,  478,  372,  478,  478,  478,
+ /*  2230 */   478,  377,  478,  478,  478,  478,  478,  478,  384,  478,
+ /*  2240 */   386,  478,  478,  478,  478,  478,  478,  478,  478,  478,
+ /*  2250 */   372,  478,  478,  478,  478,  377,  478,  478,  478,  478,
+ /*  2260 */   478,  478,  384,  478,  386,  478,  478,  478,  478,  478,
+ /*  2270 */   478,  417,  478,  478,  420,  478,  478,  423,  424,  425,
+ /*  2280 */   426,  427,  428,  478,  430,  478,  335,  478,  478,  478,
+ /*  2290 */   478,  478,  478,  478,  478,  417,  345,    1,  420,  478,
+ /*  2300 */   478,  423,  424,  425,  426,  427,  428,  478,  430,  478,
+ /*  2310 */   478,  478,  478,  478,  478,   19,  478,  478,  478,  478,
+ /*  2320 */   478,  478,  478,  372,  478,  478,  478,  478,  478,   33,
+ /*  2330 */   478,  478,  478,  478,  478,  384,  478,  386,  478,  478,
+ /*  2340 */   478,  478,  478,  478,  478,   49,  478,  478,  478,  478,
+ /*  2350 */   478,  478,   56,   57,   58,   59,  478,   61,  478,  478,
+ /*  2360 */   478,  478,  335,  478,  478,  478,  478,  478,  417,  478,
+ /*  2370 */   478,  420,  345,  478,  423,  424,  425,  426,  427,  428,
+ /*  2380 */   478,  430,  478,  478,  478,  478,  478,  478,  478,  478,
+ /*  2390 */   478,  478,  478,  478,  478,  478,  478,  101,  478,  372,
+ /*  2400 */   104,  478,  478,  478,  478,  478,  478,  478,  478,  478,
+ /*  2410 */   478,  384,  335,  386,  478,  478,  478,  478,  478,  478,
+ /*  2420 */   478,  478,  345,  478,  478,  478,  478,  478,  335,  478,
+ /*  2430 */   478,  478,  136,  478,  478,  478,  478,  478,  345,  478,
+ /*  2440 */   478,  478,  478,  478,  417,  478,  478,  420,  478,  372,
+ /*  2450 */   423,  424,  425,  426,  427,  428,  478,  430,  478,  478,
+ /*  2460 */   478,  384,  478,  386,  478,  372,  478,  171,  478,  478,
+ /*  2470 */   478,  478,  176,  478,  478,  478,  478,  384,  478,  386,
+ /*  2480 */   478,  478,  478,  478,  478,  478,  478,  478,  335,  478,
+ /*  2490 */   478,  478,  196,  478,  417,  478,  478,  420,  345,  478,
+ /*  2500 */   423,  424,  425,  426,  427,  428,  478,  430,  478,  478,
+ /*  2510 */   417,  478,  335,  420,  478,  478,  423,  424,  425,  426,
+ /*  2520 */   427,  428,  345,  430,  478,  372,  478,  478,  478,  478,
+ /*  2530 */   478,  478,  478,  478,  478,  335,  478,  384,  478,  386,
+ /*  2540 */   478,  478,  478,  478,  478,  345,  478,  478,  478,  372,
+ /*  2550 */   478,  478,  478,  478,  478,  478,  478,  478,  478,  335,
+ /*  2560 */   478,  384,  478,  386,  478,  478,  478,  478,  478,  345,
+ /*  2570 */   417,  478,  372,  420,  478,  478,  423,  424,  425,  426,
+ /*  2580 */   427,  428,  478,  430,  384,  478,  386,  478,  478,  478,
+ /*  2590 */   478,  478,  478,  478,  417,  478,  372,  420,  478,  478,
+ /*  2600 */   423,  424,  425,  426,  427,  428,  478,  430,  384,  478,
+ /*  2610 */   386,  478,  478,  478,  478,  478,  478,  417,  478,  478,
+ /*  2620 */   420,  478,  335,  423,  424,  425,  426,  427,  428,  478,
+ /*  2630 */   430,  478,  345,  478,  478,  478,  478,  478,  478,  478,
+ /*  2640 */   478,  417,  478,  478,  420,  478,  478,  423,  424,  425,
+ /*  2650 */   426,  427,  428,  478,  430,  478,  478,  478,  478,  372,
+ /*  2660 */   478,  478,  478,  478,  478,  478,  478,  478,  478,  478,
+ /*  2670 */   478,  384,  478,  386,  478,  478,  478,  478,  478,  478,
+ /*  2680 */   478,  335,  478,  478,  478,  478,  478,  478,  478,  478,
+ /*  2690 */   478,  345,  478,  478,  478,  478,  478,  478,  335,  478,
+ /*  2700 */   478,  478,  478,  478,  417,  478,  478,  420,  345,  478,
+ /*  2710 */   423,  424,  425,  426,  427,  428,  478,  430,  372,  478,
+ /*  2720 */   478,  478,  478,  478,  478,  478,  478,  478,  478,  478,
+ /*  2730 */   384,  478,  386,  478,  478,  372,  478,  478,  478,  478,
+ /*  2740 */   478,  478,  478,  478,  478,  478,  478,  384,  335,  386,
+ /*  2750 */   478,  478,  478,  478,  478,  478,  478,  478,  345,  478,
+ /*  2760 */   478,  478,  478,  417,  478,  478,  420,  478,  335,  423,
+ /*  2770 */   424,  425,  426,  427,  428,  478,  430,  478,  345,  478,
+ /*  2780 */   417,  478,  478,  420,  478,  372,  423,  424,  425,  426,
+ /*  2790 */   427,  428,  478,  430,  478,  478,  478,  384,  478,  386,
+ /*  2800 */   478,  478,  478,  478,  478,  372,  478,  478,  478,  478,
+ /*  2810 */   478,  478,  478,  478,  478,  335,  478,  384,  478,  386,
+ /*  2820 */   478,  478,  478,  478,  478,  345,  478,  478,  478,  478,
+ /*  2830 */   417,  478,  478,  420,  335,  478,  423,  424,  425,  426,
+ /*  2840 */   427,  428,  478,  430,  345,  478,  478,  478,  478,  478,
+ /*  2850 */   417,  478,  372,  420,  478,  478,  423,  424,  425,  426,
+ /*  2860 */   427,  428,  478,  430,  384,  478,  386,  478,  478,  478,
+ /*  2870 */   478,  372,  478,  478,  478,  478,  478,  478,  478,  478,
+ /*  2880 */   478,  335,  478,  384,  478,  386,  478,  478,  478,  478,
+ /*  2890 */   478,  345,  478,  478,  478,  478,  478,  417,  478,  335,
+ /*  2900 */   420,  478,  478,  423,  424,  425,  426,  427,  428,  345,
+ /*  2910 */   430,  478,  478,  478,  478,  478,  417,  478,  372,  420,
+ /*  2920 */   478,  478,  423,  424,  425,  426,  427,  428,  478,  430,
+ /*  2930 */   384,  478,  386,  478,  478,  478,  372,  478,  478,  478,
+ /*  2940 */   478,  478,  478,  478,  478,  478,  335,  478,  384,  478,
+ /*  2950 */   386,  478,  478,  478,  478,  478,  345,  478,  478,  478,
+ /*  2960 */   478,  478,  478,  417,  478,  478,  420,  478,  335,  423,
+ /*  2970 */   424,  425,  426,  427,  428,  478,  430,  478,  345,  478,
+ /*  2980 */   478,  417,  478,  372,  420,  478,  478,  423,  424,  425,
+ /*  2990 */   426,  427,  428,  478,  430,  384,  478,  386,  478,  478,
+ /*  3000 */   478,  478,  478,  478,  478,  372,  478,  478,  478,  478,
+ /*  3010 */   478,  478,  478,  478,  478,  478,  478,  384,  478,  386,
+ /*  3020 */   478,  478,  478,  478,  478,  478,  478,  478,  417,  478,
+ /*  3030 */   478,  420,  478,  478,  423,  424,  425,  426,  427,  428,
+ /*  3040 */   478,  430,  478,  478,  335,  478,  478,  478,  478,  478,
+ /*  3050 */   417,  478,  478,  420,  345,  478,  423,  424,  425,  426,
+ /*  3060 */   427,  428,  478,  430,  478,  478,  335,  478,  478,  478,
+ /*  3070 */   478,  478,  478,  478,  478,  478,  345,  478,  478,  478,
+ /*  3080 */   478,  372,  478,  478,  478,  478,  478,  478,  478,  478,
+ /*  3090 */   478,  478,  478,  384,  335,  386,  478,  478,  478,  478,
+ /*  3100 */   478,  478,  478,  372,  345,  478,  478,  478,  478,  478,
+ /*  3110 */   478,  478,  478,  478,  478,  384,  478,  386,  478,  478,
+ /*  3120 */   478,  478,  478,  478,  478,  478,  417,  478,  478,  420,
+ /*  3130 */   478,  372,  423,  424,  425,  426,  427,  428,  478,  430,
+ /*  3140 */   478,  478,  478,  384,  478,  386,  478,  478,  417,  478,
+ /*  3150 */   478,  420,  478,  478,  423,  424,  425,  426,  427,  428,
+ /*  3160 */   478,  430,  478,  478,  478,  478,  478,  478,  478,  478,
+ /*  3170 */   478,  478,  478,  478,  478,  478,  417,  478,  478,  420,
+ /*  3180 */   478,  478,  423,  424,  425,  426,  427,  428,  478,  430,
  /*  3190 */   332,  332,  332,  332,  332,  332,  332,  332,  332,  332,
  /*  3200 */   332,  332,  332,  332,  332,  332,  332,  332,  332,  332,
  /*  3210 */   332,  332,  332,  332,  332,  332,  332,  332,  332,  332,
@@ -892,127 +894,128 @@ static const YYCODETYPE yy_lookahead[] = {
  /*  3480 */   332,  332,  332,  332,  332,  332,  332,  332,  332,  332,
  /*  3490 */   332,  332,  332,  332,  332,  332,  332,  332,  332,  332,
  /*  3500 */   332,  332,  332,  332,  332,  332,  332,  332,  332,  332,
- /*  3510 */   332,  332,  332,  332,
+ /*  3510 */   332,  332,  332,  332,  332,  332,  332,  332,  332,  332,
+ /*  3520 */   332,  332,
 };
 #define YY_SHIFT_COUNT    (776)
 #define YY_SHIFT_MIN      (0)
-#define YY_SHIFT_MAX      (2114)
+#define YY_SHIFT_MAX      (2296)
 static const unsigned short int yy_shift_ofst[] = {
  /*     0 */   139,    0,  226,    0,  453,  453,  453,  453,  453,  453,
  /*    10 */   453,  453,  453,  453,  453,  453,  679,  905,  905, 1131,
  /*    20 */   905,  905,  905,  905,  905,  905,  905,  905,  905,  905,
  /*    30 */   905,  905,  905,  905,  905,  905,  905,  905,  905,  905,
  /*    40 */   905,  905,  905,  905,  905,  905,  905,  905,  905,  905,
- /*    50 */   905,   56,  302,   62,  316,  307,  397,  461,  397,  316,
- /*    60 */   316, 1592,  397, 1592, 1592,  340,  397,   48,  379,  126,
- /*    70 */   126,  379,  238,  238,  117,  329,   18,   18,  126,  126,
- /*    80 */   126,  126,  126,  126,  126,  167,  126,  126,   70,   48,
- /*    90 */   126,  126,  230,  126,   48,  126,  167,  126,  167,   48,
- /*   100 */   126,  126,   48,  126,   48,   48,   48,  126,  252,  225,
- /*   110 */   415,  415,  496,  239,  218,  218,  218,  218,  218,  218,
- /*   120 */   218,  218,  218,  218,  218,  218,  218,  218,  218,  218,
- /*   130 */   218,  218,  218,  941,  169,  117,  329,  450,  141,  141,
- /*   140 */   141,  758,  542,  542,  450,  349,  349,  349,   70,  497,
- /*   150 */   404,   48,  621,   48,  621,  621,  675,  820,  375,  375,
- /*   160 */   375,  375,  375,  375,  375,  375, 1621,  219,  515,   44,
- /*   170 */    15,   65,  120,   43,   26,  537,  591,  464,  346,  796,
- /*   180 */   977,  718,  708,  967,  652,  708, 1014,  862,  390, 1042,
- /*   190 */  1259, 1125, 1272, 1296, 1272, 1153, 1304, 1304, 1272, 1153,
- /*   200 */  1153, 1238, 1241, 1304, 1245, 1304, 1304, 1304, 1351, 1325,
- /*   210 */  1351, 1325, 1356,   70, 1362,   70, 1364, 1367,   70, 1364,
- /*   220 */    70,   70,   70, 1304,   70, 1339, 1339, 1351,   48,   48,
- /*   230 */    48,   48,   48,   48,   48,   48,   48,   48,   48, 1304,
- /*   240 */  1351,  621,  621,  621, 1204, 1310, 1356,  252, 1220, 1223,
- /*   250 */  1362,  252, 1236, 1304, 1296, 1296,  621, 1175, 1177,  621,
- /*   260 */  1175, 1177,  621,  621,   48, 1171, 1261, 1175, 1172, 1194,
- /*   270 */  1217, 1042, 1202, 1178, 1215, 1240,  349, 1475, 1304, 1364,
- /*   280 */   252,  252, 1488, 1177,  621,  621,  621,  621,  621, 1177,
- /*   290 */   621, 1347,  252,  675,  252,  349, 1418, 1428,  621,  820,
- /*   300 */  1304,  252, 1496, 1351, 3182, 3182, 3182, 3182, 3182, 3182,
- /*   310 */  3182, 3182, 3182,   34,  476,  181,  916,   57,  425,  170,
- /*   320 */   587,  813,  828,  721,  640,  184,  184,  184,  184,  184,
- /*   330 */   184,  184,  184,  184,  865,  280,    3,    3,  171,  730,
- /*   340 */   323,  472,  262,  706,  735,  673,  682,  728,  728,  653,
- /*   350 */   856,  731,  653,  653,  653, 1065,  859,   38, 1083, 1041,
- /*   360 */  1000, 1077, 1046, 1048, 1062, 1063, 1143, 1147, 1161, 1173,
- /*   370 */  1174,  982,  767, 1076,  791, 1106, 1126, 1136, 1049,  987,
- /*   380 */   998, 1137, 1162, 1163, 1169, 1170, 1181, 1183, 1196, 1184,
- /*   390 */  1114, 1154, 1029, 1150,  368, 1190, 1191, 1198, 1199, 1206,
- /*   400 */  1210,  320, 1186, 1188, 1158, 1218, 1551, 1555, 1567, 1527,
- /*   410 */  1571, 1537, 1369, 1538, 1542, 1545, 1372, 1583, 1549, 1552,
- /*   420 */  1376, 1594, 1386, 1597, 1563, 1599, 1581, 1601, 1573, 1413,
- /*   430 */  1421, 1424, 1615, 1624, 1629, 1447, 1449, 1633, 1637, 1591,
- /*   440 */  1639, 1641, 1642, 1602, 1643, 1645, 1646, 1647, 1648, 1649,
- /*   450 */  1650, 1651, 1495, 1620, 1656, 1500, 1658, 1659, 1660, 1661,
- /*   460 */  1667, 1668, 1669, 1671, 1672, 1673, 1675, 1681, 1683, 1684,
- /*   470 */  1685, 1686, 1622, 1665, 1687, 1688, 1689, 1690, 1699, 1670,
- /*   480 */  1693, 1694, 1695, 1522, 1696, 1697, 1678, 1653, 1680, 1655,
- /*   490 */  1704, 1644, 1674, 1706, 1652, 1710, 1662, 1712, 1720, 1700,
- /*   500 */  1682, 1691, 1724, 1701, 1698, 1702, 1727, 1703, 1705, 1711,
- /*   510 */  1729, 1707, 1737, 1709, 1713, 1714, 1708, 1715, 1725, 1716,
- /*   520 */  1740, 1719, 1717, 1743, 1744, 1745, 1721, 1570, 1753, 1761,
- /*   530 */  1764, 1726, 1765, 1766, 1732, 1722, 1730, 1768, 1735, 1723,
- /*   540 */  1734, 1774, 1741, 1728, 1736, 1778, 1746, 1749, 1756, 1784,
- /*   550 */  1785, 1799, 1807, 1718, 1731, 1767, 1779, 1803, 1773, 1776,
- /*   560 */  1777, 1780, 1781, 1783, 1786, 1769, 1770, 1796, 1798, 1797,
- /*   570 */  1800, 1834, 1814, 1837, 1816, 1790, 1839, 1820, 1808, 1845,
- /*   580 */  1812, 1848, 1815, 1849, 1829, 1832, 1819, 1822, 1823, 1750,
- /*   590 */  1757, 1855, 1747, 1758, 1666, 1827, 1841, 1864, 1676, 1843,
- /*   600 */  1748, 1751, 1866, 1869, 1755, 1739, 1868, 1828, 1616, 1771,
- /*   610 */  1772, 1791, 1830, 1782, 1831, 1792, 1789, 1836, 1851, 1793,
- /*   620 */  1795, 1804, 1805, 1817, 1856, 1852, 1872, 1826, 1887, 1618,
- /*   630 */  1833, 1835, 1880, 1877, 1677, 1894, 1897, 1898, 1899, 1904,
- /*   640 */  1905, 1838, 1840, 1890, 1738, 1901, 1900, 1946, 1948, 1949,
- /*   650 */  1951, 1850, 1914, 1708, 1907, 1853, 1854, 1857, 1859, 1861,
- /*   660 */  1794, 1863, 1956, 1919, 1802, 1867, 1847, 1708, 1921, 1922,
- /*   670 */  1870, 1733, 1871, 1972, 1954, 1760, 1876, 1878, 1886, 1888,
- /*   680 */  1891, 1889, 1933, 1892, 1895, 1953, 1893, 1979, 1806, 1908,
- /*   690 */  1903, 1909, 1976, 1978, 1912, 1916, 1980, 1918, 1923, 1982,
- /*   700 */  1926, 1927, 1983, 1929, 1930, 1986, 1934, 1911, 1917, 1920,
- /*   710 */  1925, 1936, 1985, 1937, 1989, 1938, 1985, 1985, 2010, 1974,
- /*   720 */  1984, 2008, 2012, 2015, 2017, 2020, 2021, 2022, 2023, 2024,
- /*   730 */  2025, 1971, 1965, 2018, 2029, 2030, 2031, 2045, 2034, 2035,
- /*   740 */  2036, 1998, 1769, 2038, 1770, 2039, 2041, 2043, 2046, 2058,
- /*   750 */  2047, 2084, 2050, 2048, 2053, 2094, 2060, 2049, 2057, 2099,
- /*   760 */  2066, 2054, 2063, 2104, 2071, 2061, 2068, 2109, 2076, 2078,
- /*   770 */  2114, 2102, 2100, 2103, 2105, 2107, 2110,
+ /*    50 */   905,   61,  114,   62,  285,  375,  477,  607,  477,  285,
+ /*    60 */   285,  527,  477,  527,  527,   59,  477,   49,  172,   53,
+ /*    70 */    53,  172,  151,  151,  382,  153,  126,  126,   53,   53,
+ /*    80 */    53,   53,   53,   53,   53,  266,   53,   53,  178,   49,
+ /*    90 */    53,   53,  339,   53,   49,   53,  266,   53,  266,   49,
+ /*   100 */    53,   53,   49,   53,   49,   49,   49,   53,  332,  225,
+ /*   110 */   415,  415,  496,  239,  676,  676,  676,  676,  676,  676,
+ /*   120 */   676,  676,  676,  676,  676,  676,  676,  676,  676,  676,
+ /*   130 */   676,  676,  676,   25,  180,  382,  153,  292,  467,  467,
+ /*   140 */   467,  776,  503,  503,  292,  521,  521,  521,  178,  422,
+ /*   150 */   397,   49,  642,   49,  642,  642,  608,  742,  381,  381,
+ /*   160 */   381,  381,  381,  381,  381,  381, 2296,  219,  623,   44,
+ /*   170 */    15,   65,   19,  224,  124,  124,  611,  616,  510,  815,
+ /*   180 */   600,  412,  940,  922,  606,  835,  874,  606,  710,  915,
+ /*   190 */   904, 1053, 1280, 1159, 1308, 1351, 1308, 1209, 1357, 1357,
+ /*   200 */  1308, 1209, 1209, 1289, 1292, 1357, 1296, 1357, 1357, 1357,
+ /*   210 */  1377, 1352, 1377, 1352, 1384,  178, 1386,  178, 1388, 1394,
+ /*   220 */   178, 1388,  178,  178,  178, 1357,  178, 1364, 1364, 1377,
+ /*   230 */    49,   49,   49,   49,   49,   49,   49,   49,   49,   49,
+ /*   240 */    49, 1357, 1377,  642,  642,  642, 1229, 1335, 1384,  332,
+ /*   250 */  1249, 1252, 1386,  332, 1257, 1357, 1351, 1351,  642, 1188,
+ /*   260 */  1232,  642, 1188, 1232,  642,  642,   49, 1214, 1327, 1188,
+ /*   270 */  1240, 1242, 1258, 1053, 1239, 1243, 1251, 1275,  521, 1509,
+ /*   280 */  1357, 1388,  332,  332, 1526, 1232,  642,  642,  642,  642,
+ /*   290 */   642, 1232,  642, 1399,  332,  608,  332,  521, 1470, 1484,
+ /*   300 */   642,  742, 1357,  332, 1557, 1377, 3190, 3190, 3190, 3190,
+ /*   310 */  3190, 3190, 3190, 3190, 3190,   34, 1140,  181,  515,  425,
+ /*   320 */   711,  720,  571,  937,  968,  758,  855,  509,  509,  509,
+ /*   330 */   509,  509,  509,  509,  509,  509,  677,  886,   63,   63,
+ /*   340 */   324,  487,  262,  620,  897,  314,  900,  241,  671,  535,
+ /*   350 */   535,  680,  919,  721,  680,  680,  680, 1055,    4,  959,
+ /*   360 */  1056,  921, 1006, 1156, 1063, 1065, 1073, 1100, 1172, 1189,
+ /*   370 */  1217, 1218, 1221,  892, 1133, 1178,  308, 1181, 1183, 1184,
+ /*   380 */  1074,  755,  297,  947, 1191, 1201, 1204, 1205, 1207, 1210,
+ /*   390 */  1245, 1211,  994, 1212, 1215, 1219, 1222, 1223, 1238, 1244,
+ /*   400 */  1276,  859, 1041, 1180, 1267, 1288, 1149, 1253, 1605, 1606,
+ /*   410 */  1609, 1568, 1612, 1578, 1404, 1580, 1581, 1582, 1408, 1619,
+ /*   420 */  1585, 1586, 1412, 1624, 1415, 1627, 1593, 1635, 1615, 1639,
+ /*   430 */  1607, 1443, 1454, 1457, 1646, 1649, 1651, 1469, 1471, 1655,
+ /*   440 */  1656, 1610, 1658, 1659, 1660, 1620, 1661, 1663, 1664, 1665,
+ /*   450 */  1666, 1667, 1668, 1669, 1513, 1636, 1672, 1516, 1674, 1675,
+ /*   460 */  1676, 1677, 1678, 1679, 1680, 1681, 1682, 1684, 1687, 1688,
+ /*   470 */  1697, 1698, 1699, 1700, 1662, 1702, 1705, 1706, 1709, 1710,
+ /*   480 */  1712, 1691, 1714, 1715, 1716, 1576, 1718, 1719, 1701, 1683,
+ /*   490 */  1703, 1685, 1720, 1671, 1689, 1726, 1686, 1727, 1690, 1728,
+ /*   500 */  1729, 1695, 1693, 1696, 1737, 1704, 1694, 1711, 1738, 1717,
+ /*   510 */  1722, 1724, 1740, 1723, 1741, 1707, 1725, 1713, 1721, 1732,
+ /*   520 */  1730, 1734, 1745, 1742, 1733, 1753, 1754, 1755, 1747, 1587,
+ /*   530 */  1759, 1761, 1765, 1739, 1769, 1784, 1763, 1756, 1749, 1789,
+ /*   540 */  1773, 1760, 1751, 1794, 1777, 1766, 1775, 1816, 1786, 1770,
+ /*   550 */  1783, 1823, 1824, 1825, 1826, 1731, 1735, 1795, 1805, 1829,
+ /*   560 */  1797, 1798, 1808, 1810, 1811, 1814, 1815, 1796, 1807, 1819,
+ /*   570 */  1820, 1834, 1822, 1858, 1840, 1863, 1842, 1817, 1865, 1844,
+ /*   580 */  1832, 1869, 1836, 1872, 1838, 1874, 1853, 1856, 1843, 1845,
+ /*   590 */  1846, 1776, 1780, 1883, 1736, 1782, 1743, 1850, 1864, 1888,
+ /*   600 */  1744, 1867, 1748, 1750, 1890, 1891, 1757, 1746, 1893, 1849,
+ /*   610 */  1650, 1802, 1791, 1813, 1859, 1821, 1862, 1827, 1828, 1875,
+ /*   620 */  1876, 1830, 1835, 1837, 1839, 1831, 1880, 1866, 1882, 1841,
+ /*   630 */  1886, 1752, 1833, 1851, 1929, 1896, 1758, 1909, 1911, 1912,
+ /*   640 */  1921, 1922, 1923, 1857, 1860, 1914, 1771, 1920, 1924, 1973,
+ /*   650 */  1974, 1975, 1976, 1879, 1939, 1721, 1933, 1884, 1885, 1887,
+ /*   660 */  1889, 1892, 1809, 1894, 1985, 1953, 1847, 1895, 1881, 1721,
+ /*   670 */  1948, 1954, 1899, 1762, 1900, 2000, 1981, 1787, 1903, 1904,
+ /*   680 */  1906, 1908, 1907, 1910, 1959, 1913, 1915, 1965, 1917, 1999,
+ /*   690 */  1803, 1927, 1918, 1930, 1989, 1990, 1928, 1931, 1997, 1934,
+ /*   700 */  1932, 2003, 1937, 1938, 2005, 1940, 1941, 2010, 1944, 1925,
+ /*   710 */  1926, 1936, 1947, 1945, 2004, 1949, 2017, 1952, 2004, 2004,
+ /*   720 */  2033, 1988, 1991, 2022, 2026, 2028, 2038, 2039, 2040, 2042,
+ /*   730 */  2044, 2007, 1986, 2041, 2048, 2049, 2051, 2065, 2053, 2054,
+ /*   740 */  2055, 2019, 1796, 2056, 1807, 2060, 2061, 2062, 2063, 2078,
+ /*   750 */  2064, 2101, 2067, 2057, 2066, 2104, 2072, 2059, 2071, 2111,
+ /*   760 */  2079, 2074, 2082, 2124, 2091, 2080, 2100, 2130, 2106, 2107,
+ /*   770 */  2143, 2122, 2125, 2126, 2127, 2129, 2131,
 };
-#define YY_REDUCE_COUNT (312)
-#define YY_REDUCE_MIN   (-447)
-#define YY_REDUCE_MAX   (2751)
+#define YY_REDUCE_COUNT (314)
+#define YY_REDUCE_MIN   (-423)
+#define YY_REDUCE_MAX   (2759)
 static const short yy_reduce_ofst[] = {
- /*     0 */   294,  177,  371,  598,  855, 1034, 1061, 1133, 1165, 1193,
- /*    10 */   448,  674, 1291, 1363, 1461, 1485, -335, 1559, 1579, 1663,
- /*    20 */   906,  832, 1692, 1788, 1801, 1885, 1902, 1915, 1988, 1818,
- /*    30 */  2009, 2055, 2106, 2119, 2205, 2218, 2235, 2269, 2329, 2342,
- /*    40 */  2393, 2415, 2439, 2523, 2536, 2551, 2635, 2652, 2665, 2686,
- /*    50 */  2751, -302,  259,  296,  -88,  383,  490,  521,  543,  501,
- /*    60 */   642,  -23,  -47,  176,  330, -447, -319, -324, -322, -261,
- /*    70 */  -210,  -58, -336, -298,  116,   95,  224,  235,  166,  254,
- /*    80 */   288,  291,  458,  518,  592,  127,  623,  646,   35,  -73,
- /*    90 */   685,  692, -294,  719,  237,  722,  175,  724,  194,  246,
- /*   100 */   762,  803,  339,  814,  376,  373,  421,  801,  -75, -307,
- /*   110 */  -430, -430, -349, -236, -334, -168,  241,  314,  369,  503,
- /*   120 */   504,  549,  558,  593,  620,  629,  649,  670,  678,  699,
- /*   130 */   720,  727,  736, -219,   -3,  158,  -44, -271,   -3,  198,
- /*   140 */   401, -218,  443,  488,  -11,  420,  585,  586,  567,  613,
- /*   150 */  -189,  550,  133, -109,  573,  658,  711,  691,  562,  580,
- /*   160 */   809,  819,  838,  839,  840,  838,  768,  844,  880,  826,
- /*   170 */   746,  759,  883,  777,  866,  866,  896,  852,  904,  919,
- /*   180 */   867,  868,  816,  816,  805,  816,  845,  842,  866,  885,
- /*   190 */   893,  908,  925,  924,  928,  935,  981,  983,  938,  947,
- /*   200 */   949,  984,  986,  999,  991, 1002, 1003, 1006, 1035, 1033,
- /*   210 */  1038, 1036,  969, 1026, 1001, 1031, 1039,  985, 1037, 1044,
- /*   220 */  1040, 1043, 1045, 1047, 1050, 1051, 1052, 1057, 1027, 1028,
- /*   230 */  1032, 1053, 1054, 1055, 1056, 1058, 1059, 1060, 1064, 1066,
- /*   240 */  1067, 1024, 1030, 1068,  996, 1005, 1004, 1070, 1011, 1013,
- /*   250 */  1071, 1073, 1025, 1090, 1072, 1074, 1069,  978, 1075, 1080,
- /*   260 */   979, 1081, 1087, 1089,  866,  980,  988,  989,  992,  997,
- /*   270 */  1078, 1079,  966, 1012, 1022,  816, 1149, 1084, 1155, 1159,
- /*   280 */  1151, 1157, 1113, 1115, 1128, 1132, 1134, 1138, 1139, 1116,
- /*   290 */  1140, 1129, 1176, 1160, 1179, 1180, 1091, 1164, 1152, 1182,
- /*   300 */  1197, 1187, 1207, 1205, 1141, 1122, 1145, 1148, 1189, 1200,
- /*   310 */  1201, 1211, 1219,
+ /*     0 */  -150,  170,  365,  506,  622,  848, 1040, 1075, 1139, 1206,
+ /*    10 */  1266, 1350, 1376, 1411, 1475, 1542, -335,  682,  907, 1107,
+ /*    20 */  1525,  459, 1642, 1692, 1708, 1768, 1792, 1854, 1878, 1951,
+ /*    30 */  2027, 2077, 2093, 2153, 2177, 2200, 2224, 2287, 2346, 2363,
+ /*    40 */  2413, 2433, 2480, 2499, 2546, 2564, 2611, 2633, 2709, 2731,
+ /*    50 */  2759, -302,  166, -402,  -41,  553,  561,  648,  708,  741,
+ /*    60 */   893,   51, -110,  445,  640, -112,  -53, -361, -318, -338,
+ /*    70 */  -191,   90,  -58,   79, -241,  195, -300,  -90,   47,  149,
+ /*    80 */   402,  424,  452,  476,  481, -155,  483,  489, -211, -370,
+ /*    90 */   493,  505, -324,  518, -194,  528,  134,  630,  213,  358,
+ /*   100 */   652,  667,  227,  615,  384,  230,  460,  610,  194, -246,
+ /*   110 */  -423, -423, -253, -298, -186,  334,  674,  681,  683,  697,
+ /*   120 */   706,  734,  763,  766,  768,  778,  779,  819,  820,  824,
+ /*   130 */   826,  830,  832, -184, -175,  144, -299,  -14, -175,  111,
+ /*   140 */   291,   67, -250,  206,  246,  168,  223,  352,  -80, -360,
+ /*   150 */   347,  450,  514,  102,  654,  656,  492,  694, -328,  507,
+ /*   160 */   564,  663,  704,  709,  751,  704,  536,  788,  822,  784,
+ /*   170 */   718,  754,  878,  770,  890,  898,  885,  885,  911,  866,
+ /*   180 */   918,  932,  881,  901,  841,  841,  827,  841,  854,  845,
+ /*   190 */   885,  909,  926,  941,  978,  979,  981,  985, 1034, 1036,
+ /*   200 */   992,  995,  997, 1032, 1037, 1047, 1042, 1050, 1051, 1054,
+ /*   210 */  1062, 1060, 1066, 1061,  993, 1057, 1021, 1059, 1067, 1011,
+ /*   220 */  1064, 1071, 1069, 1076, 1077, 1079, 1078, 1070, 1082, 1088,
+ /*   230 */  1068, 1072, 1081, 1083, 1084, 1086, 1090, 1097, 1099, 1101,
+ /*   240 */  1104, 1089, 1095, 1043, 1052, 1094, 1019, 1024, 1027, 1091,
+ /*   250 */  1035, 1038, 1102, 1122, 1045, 1106, 1093, 1096, 1105, 1022,
+ /*   260 */  1098, 1112, 1025, 1108, 1120, 1124,  885, 1048, 1058, 1080,
+ /*   270 */  1085, 1087, 1092, 1103, 1044, 1111, 1109,  841, 1194, 1114,
+ /*   280 */  1196, 1199, 1198, 1200, 1155, 1158, 1170, 1171, 1174, 1176,
+ /*   290 */  1177, 1169, 1186, 1179, 1227, 1216, 1233, 1228, 1145, 1213,
+ /*   300 */  1203, 1226, 1247, 1246, 1256, 1260, 1192, 1182, 1202, 1208,
+ /*   310 */  1234, 1237, 1241, 1248, 1271,
 };
 static const YYACTIONTYPE yy_default[] = {
  /*     0 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
@@ -1032,29 +1035,29 @@ static const YYACTIONTYPE yy_default[] = {
  /*   140 */  2241, 1822, 2201, 2201, 1738, 1738, 1738, 1738, 1824, 2073,
  /*   150 */  1738, 1738, 1738, 1738, 1738, 1738, 1943, 1738, 1738, 1738,
  /*   160 */  1738, 1738, 1967, 1738, 1738, 1738, 2067, 1738, 1738, 2266,
- /*   170 */  2322, 1738, 1738, 2269, 1738, 1738, 1738, 2020, 1738, 1738,
- /*   180 */  1897, 2256, 2233, 2247, 2306, 2234, 2231, 2250, 1738, 2260,
- /*   190 */  1738, 2054, 2013, 1738, 2013, 2010, 1738, 1738, 2013, 2010,
- /*   200 */  2010, 1886, 1882, 1738, 1880, 1738, 1738, 1738, 1738, 1785,
- /*   210 */  1738, 1785, 1738, 1824, 1738, 1824, 1738, 1738, 1824, 1738,
- /*   220 */  1824, 1824, 1824, 1738, 1824, 1799, 1799, 1738, 1738, 1738,
+ /*   170 */  2322, 1738, 1738, 2269, 1738, 1738, 1738, 1738, 1738, 2020,
+ /*   180 */  1738, 1738, 1897, 2256, 2233, 2247, 2306, 2234, 2231, 2250,
+ /*   190 */  1738, 2260, 1738, 2054, 2013, 1738, 2013, 2010, 1738, 1738,
+ /*   200 */  2013, 2010, 2010, 1886, 1882, 1738, 1880, 1738, 1738, 1738,
+ /*   210 */  1738, 1785, 1738, 1785, 1738, 1824, 1738, 1824, 1738, 1738,
+ /*   220 */  1824, 1738, 1824, 1824, 1824, 1738, 1824, 1799, 1799, 1738,
  /*   230 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
- /*   240 */  1738, 1738, 1738, 1738, 2085, 2071, 1738, 1822, 2065, 2063,
- /*   250 */  1738, 1822, 2061, 1738, 1738, 1738, 1738, 2277, 2275, 1738,
- /*   260 */  2277, 2275, 1738, 1738, 1738, 2291, 2287, 2277, 2295, 2293,
- /*   270 */  2262, 2260, 2325, 2312, 2308, 2247, 1738, 1738, 1738, 1738,
- /*   280 */  1822, 1822, 1738, 2275, 1738, 1738, 1738, 1738, 1738, 2275,
- /*   290 */  1738, 1738, 1822, 1738, 1822, 1738, 1738, 1913, 1738, 1738,
- /*   300 */  1738, 1822, 1770, 1738, 2056, 2076, 2038, 2038, 1946, 1946,
- /*   310 */  1946, 1825, 1743, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
- /*   320 */  1738, 1738, 1738, 1738, 1738, 2290, 2289, 2156, 1738, 2205,
- /*   330 */  2204, 2203, 2194, 2155, 1909, 1738, 2154, 2153, 1738, 1738,
- /*   340 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 2029, 2028, 2147,
- /*   350 */  1738, 1738, 2148, 2146, 2145, 1738, 1738, 1738, 1738, 1738,
+ /*   240 */  1738, 1738, 1738, 1738, 1738, 1738, 2085, 2071, 1738, 1822,
+ /*   250 */  2065, 2063, 1738, 1822, 2061, 1738, 1738, 1738, 1738, 2277,
+ /*   260 */  2275, 1738, 2277, 2275, 1738, 1738, 1738, 2291, 2287, 2277,
+ /*   270 */  2295, 2293, 2262, 2260, 2325, 2312, 2308, 2247, 1738, 1738,
+ /*   280 */  1738, 1738, 1822, 1822, 1738, 2275, 1738, 1738, 1738, 1738,
+ /*   290 */  1738, 2275, 1738, 1738, 1822, 1738, 1822, 1738, 1738, 1913,
+ /*   300 */  1738, 1738, 1738, 1822, 1770, 1738, 2056, 2076, 2038, 2038,
+ /*   310 */  1946, 1946, 1946, 1825, 1743, 1738, 1738, 1738, 1738, 1738,
+ /*   320 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 2290, 2289, 2156,
+ /*   330 */  1738, 2205, 2204, 2203, 2194, 2155, 1909, 1738, 2154, 2153,
+ /*   340 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 2029,
+ /*   350 */  2028, 2147, 1738, 1738, 2148, 2146, 2145, 1738, 1738, 1738,
  /*   360 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
- /*   370 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 2309,
- /*   380 */  2313, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 2230, 1738,
- /*   390 */  1738, 1738, 1738, 1738, 2129, 1738, 1738, 1738, 1738, 1738,
+ /*   370 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
+ /*   380 */  1738, 2309, 2313, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
+ /*   390 */  2230, 1738, 1738, 1738, 2129, 1738, 1738, 1738, 1738, 1738,
  /*   400 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
  /*   410 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
  /*   420 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
@@ -1066,27 +1069,27 @@ static const YYACTIONTYPE yy_default[] = {
  /*   480 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
  /*   490 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
  /*   500 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
- /*   510 */  1738, 1738, 1738, 1738, 1738, 1775, 2134, 1738, 1738, 1738,
+ /*   510 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1775, 2134, 1738,
  /*   520 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
  /*   530 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
  /*   540 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
  /*   550 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
- /*   560 */  1738, 1738, 1738, 1738, 1738, 1863, 1862, 1738, 1738, 1738,
+ /*   560 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1863, 1862, 1738,
  /*   570 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
- /*   580 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 2138,
- /*   590 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
- /*   600 */  1738, 1738, 1738, 1738, 1738, 1738, 2305, 2263, 1738, 1738,
+ /*   580 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
+ /*   590 */  1738, 2138, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
+ /*   600 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 2305, 2263,
  /*   610 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
- /*   620 */  1738, 1738, 1738, 1738, 1738, 1738, 2129, 1738, 2288, 1738,
- /*   630 */  1738, 2303, 1738, 2307, 1738, 1738, 1738, 1738, 1738, 1738,
- /*   640 */  1738, 2240, 2236, 1738, 1738, 2232, 1738, 1738, 1738, 1738,
- /*   650 */  1738, 1738, 1738, 2137, 1738, 1738, 1738, 1738, 1738, 1738,
- /*   660 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 2128, 1738, 2191,
- /*   670 */  1738, 1738, 1738, 2225, 1738, 1738, 2176, 1738, 1738, 1738,
- /*   680 */  1738, 1738, 1738, 1738, 1738, 1738, 2138, 1738, 2141, 1738,
- /*   690 */  1738, 1738, 1738, 1738, 1940, 1738, 1738, 1738, 1738, 1738,
- /*   700 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1925, 1923, 1922,
- /*   710 */  1921, 1738, 1953, 1738, 1738, 1738, 1949, 1948, 1738, 1738,
+ /*   620 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 2129, 1738,
+ /*   630 */  2288, 1738, 1738, 2303, 1738, 2307, 1738, 1738, 1738, 1738,
+ /*   640 */  1738, 1738, 1738, 2240, 2236, 1738, 1738, 2232, 1738, 1738,
+ /*   650 */  1738, 1738, 1738, 1738, 1738, 2137, 1738, 1738, 1738, 1738,
+ /*   660 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 2128,
+ /*   670 */  1738, 2191, 1738, 1738, 1738, 2225, 1738, 1738, 2176, 1738,
+ /*   680 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 2138, 1738,
+ /*   690 */  2141, 1738, 1738, 1738, 1738, 1738, 1940, 1738, 1738, 1738,
+ /*   700 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1925,
+ /*   710 */  1923, 1922, 1921, 1738, 1953, 1738, 1738, 1738, 1949, 1948,
  /*   720 */  1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738, 1738,
  /*   730 */  1738, 1738, 1738, 1843, 1738, 1738, 1738, 1738, 1738, 1738,
  /*   740 */  1738, 1738, 1835, 1738, 1834, 1738, 1738, 1738, 1738, 1738,
@@ -1891,66 +1894,66 @@ static const char *const yyTokenName[] = {
   /*  357 */ "integer_list",
   /*  358 */ "variable_list",
   /*  359 */ "retention_list",
-  /*  360 */ "alter_db_option",
-  /*  361 */ "retention",
-  /*  362 */ "full_table_name",
-  /*  363 */ "column_def_list",
-  /*  364 */ "tags_def_opt",
-  /*  365 */ "table_options",
-  /*  366 */ "multi_create_clause",
-  /*  367 */ "tags_def",
-  /*  368 */ "multi_drop_clause",
-  /*  369 */ "alter_table_clause",
-  /*  370 */ "alter_table_options",
-  /*  371 */ "column_name",
-  /*  372 */ "type_name",
-  /*  373 */ "signed_literal",
-  /*  374 */ "create_subtable_clause",
-  /*  375 */ "specific_cols_opt",
-  /*  376 */ "expression_list",
-  /*  377 */ "drop_table_clause",
-  /*  378 */ "col_name_list",
-  /*  379 */ "column_def",
-  /*  380 */ "duration_list",
-  /*  381 */ "rollup_func_list",
-  /*  382 */ "alter_table_option",
-  /*  383 */ "duration_literal",
-  /*  384 */ "rollup_func_name",
-  /*  385 */ "function_name",
-  /*  386 */ "col_name",
-  /*  387 */ "db_name_cond_opt",
-  /*  388 */ "like_pattern_opt",
-  /*  389 */ "table_name_cond",
-  /*  390 */ "from_db_opt",
-  /*  391 */ "tag_list_opt",
-  /*  392 */ "tag_item",
-  /*  393 */ "column_alias",
-  /*  394 */ "full_index_name",
-  /*  395 */ "index_options",
-  /*  396 */ "index_name",
-  /*  397 */ "func_list",
-  /*  398 */ "sliding_opt",
-  /*  399 */ "sma_stream_opt",
-  /*  400 */ "func",
-  /*  401 */ "sma_func_name",
-  /*  402 */ "query_or_subquery",
-  /*  403 */ "cgroup_name",
-  /*  404 */ "analyze_opt",
-  /*  405 */ "explain_options",
-  /*  406 */ "insert_query",
-  /*  407 */ "or_replace_opt",
-  /*  408 */ "agg_func_opt",
-  /*  409 */ "bufsize_opt",
-  /*  410 */ "language_opt",
-  /*  411 */ "stream_name",
-  /*  412 */ "stream_options",
-  /*  413 */ "col_list_opt",
-  /*  414 */ "tag_def_or_ref_opt",
-  /*  415 */ "subtable_opt",
-  /*  416 */ "expression",
-  /*  417 */ "dnode_list",
-  /*  418 */ "where_clause_opt",
-  /*  419 */ "signed",
+  /*  360 */ "signed",
+  /*  361 */ "alter_db_option",
+  /*  362 */ "retention",
+  /*  363 */ "full_table_name",
+  /*  364 */ "column_def_list",
+  /*  365 */ "tags_def_opt",
+  /*  366 */ "table_options",
+  /*  367 */ "multi_create_clause",
+  /*  368 */ "tags_def",
+  /*  369 */ "multi_drop_clause",
+  /*  370 */ "alter_table_clause",
+  /*  371 */ "alter_table_options",
+  /*  372 */ "column_name",
+  /*  373 */ "type_name",
+  /*  374 */ "signed_literal",
+  /*  375 */ "create_subtable_clause",
+  /*  376 */ "specific_cols_opt",
+  /*  377 */ "expression_list",
+  /*  378 */ "drop_table_clause",
+  /*  379 */ "col_name_list",
+  /*  380 */ "column_def",
+  /*  381 */ "duration_list",
+  /*  382 */ "rollup_func_list",
+  /*  383 */ "alter_table_option",
+  /*  384 */ "duration_literal",
+  /*  385 */ "rollup_func_name",
+  /*  386 */ "function_name",
+  /*  387 */ "col_name",
+  /*  388 */ "db_name_cond_opt",
+  /*  389 */ "like_pattern_opt",
+  /*  390 */ "table_name_cond",
+  /*  391 */ "from_db_opt",
+  /*  392 */ "tag_list_opt",
+  /*  393 */ "tag_item",
+  /*  394 */ "column_alias",
+  /*  395 */ "full_index_name",
+  /*  396 */ "index_options",
+  /*  397 */ "index_name",
+  /*  398 */ "func_list",
+  /*  399 */ "sliding_opt",
+  /*  400 */ "sma_stream_opt",
+  /*  401 */ "func",
+  /*  402 */ "sma_func_name",
+  /*  403 */ "query_or_subquery",
+  /*  404 */ "cgroup_name",
+  /*  405 */ "analyze_opt",
+  /*  406 */ "explain_options",
+  /*  407 */ "insert_query",
+  /*  408 */ "or_replace_opt",
+  /*  409 */ "agg_func_opt",
+  /*  410 */ "bufsize_opt",
+  /*  411 */ "language_opt",
+  /*  412 */ "stream_name",
+  /*  413 */ "stream_options",
+  /*  414 */ "col_list_opt",
+  /*  415 */ "tag_def_or_ref_opt",
+  /*  416 */ "subtable_opt",
+  /*  417 */ "expression",
+  /*  418 */ "dnode_list",
+  /*  419 */ "where_clause_opt",
   /*  420 */ "literal_func",
   /*  421 */ "literal_list",
   /*  422 */ "table_alias",
@@ -2129,8 +2132,8 @@ static const char *const yyRuleName[] = {
  /* 110 */ "db_options ::= db_options WAL_ROLL_PERIOD NK_INTEGER",
  /* 111 */ "db_options ::= db_options WAL_SEGMENT_SIZE NK_INTEGER",
  /* 112 */ "db_options ::= db_options STT_TRIGGER NK_INTEGER",
- /* 113 */ "db_options ::= db_options TABLE_PREFIX NK_INTEGER",
- /* 114 */ "db_options ::= db_options TABLE_SUFFIX NK_INTEGER",
+ /* 113 */ "db_options ::= db_options TABLE_PREFIX signed",
+ /* 114 */ "db_options ::= db_options TABLE_SUFFIX signed",
  /* 115 */ "alter_db_options ::= alter_db_option",
  /* 116 */ "alter_db_options ::= alter_db_options alter_db_option",
  /* 117 */ "alter_db_option ::= BUFFER NK_INTEGER",
@@ -2737,36 +2740,36 @@ static void yy_destructor(
     case 353: /* alter_db_options */
     case 355: /* start_opt */
     case 356: /* end_opt */
-    case 361: /* retention */
-    case 362: /* full_table_name */
-    case 365: /* table_options */
-    case 369: /* alter_table_clause */
-    case 370: /* alter_table_options */
-    case 373: /* signed_literal */
-    case 374: /* create_subtable_clause */
-    case 377: /* drop_table_clause */
-    case 379: /* column_def */
-    case 383: /* duration_literal */
-    case 384: /* rollup_func_name */
-    case 386: /* col_name */
-    case 387: /* db_name_cond_opt */
-    case 388: /* like_pattern_opt */
-    case 389: /* table_name_cond */
-    case 390: /* from_db_opt */
-    case 392: /* tag_item */
-    case 394: /* full_index_name */
-    case 395: /* index_options */
-    case 398: /* sliding_opt */
-    case 399: /* sma_stream_opt */
-    case 400: /* func */
-    case 402: /* query_or_subquery */
-    case 405: /* explain_options */
-    case 406: /* insert_query */
-    case 412: /* stream_options */
-    case 415: /* subtable_opt */
-    case 416: /* expression */
-    case 418: /* where_clause_opt */
-    case 419: /* signed */
+    case 360: /* signed */
+    case 362: /* retention */
+    case 363: /* full_table_name */
+    case 366: /* table_options */
+    case 370: /* alter_table_clause */
+    case 371: /* alter_table_options */
+    case 374: /* signed_literal */
+    case 375: /* create_subtable_clause */
+    case 378: /* drop_table_clause */
+    case 380: /* column_def */
+    case 384: /* duration_literal */
+    case 385: /* rollup_func_name */
+    case 387: /* col_name */
+    case 388: /* db_name_cond_opt */
+    case 389: /* like_pattern_opt */
+    case 390: /* table_name_cond */
+    case 391: /* from_db_opt */
+    case 393: /* tag_item */
+    case 395: /* full_index_name */
+    case 396: /* index_options */
+    case 399: /* sliding_opt */
+    case 400: /* sma_stream_opt */
+    case 401: /* func */
+    case 403: /* query_or_subquery */
+    case 406: /* explain_options */
+    case 407: /* insert_query */
+    case 413: /* stream_options */
+    case 416: /* subtable_opt */
+    case 417: /* expression */
+    case 419: /* where_clause_opt */
     case 420: /* literal_func */
     case 423: /* expr_or_subquery */
     case 424: /* pseudo_column */
@@ -2804,16 +2807,20 @@ static void yy_destructor(
     case 473: /* query_simple_or_subquery */
     case 475: /* sort_specification */
 {
+#line 7 "sql.y"
  nodesDestroyNode((yypminor->yy184)); 
+#line 2813 "sql.c"
 }
       break;
     case 333: /* account_options */
     case 334: /* alter_account_options */
     case 336: /* alter_account_option */
     case 354: /* speed_opt */
-    case 409: /* bufsize_opt */
+    case 410: /* bufsize_opt */
 {
+#line 54 "sql.y"
  
+#line 2824 "sql.c"
 }
       break;
     case 337: /* user_name */
@@ -2821,68 +2828,78 @@ static void yy_destructor(
     case 345: /* table_name */
     case 346: /* topic_name */
     case 348: /* dnode_endpoint */
-    case 371: /* column_name */
-    case 385: /* function_name */
-    case 393: /* column_alias */
-    case 396: /* index_name */
-    case 401: /* sma_func_name */
-    case 403: /* cgroup_name */
-    case 410: /* language_opt */
-    case 411: /* stream_name */
+    case 372: /* column_name */
+    case 386: /* function_name */
+    case 394: /* column_alias */
+    case 397: /* index_name */
+    case 402: /* sma_func_name */
+    case 404: /* cgroup_name */
+    case 411: /* language_opt */
+    case 412: /* stream_name */
     case 422: /* table_alias */
     case 428: /* star_func */
     case 430: /* noarg_func */
     case 448: /* alias_opt */
 {
+#line 721 "sql.y"
  
+#line 2847 "sql.c"
 }
       break;
     case 338: /* sysinfo_opt */
 {
+#line 92 "sql.y"
  
+#line 2854 "sql.c"
 }
       break;
     case 339: /* privileges */
     case 342: /* priv_type_list */
     case 343: /* priv_type */
 {
+#line 101 "sql.y"
  
+#line 2863 "sql.c"
 }
       break;
     case 340: /* priv_level */
 {
+#line 117 "sql.y"
  
+#line 2870 "sql.c"
 }
       break;
     case 349: /* force_opt */
     case 350: /* not_exists_opt */
     case 352: /* exists_opt */
-    case 404: /* analyze_opt */
-    case 407: /* or_replace_opt */
-    case 408: /* agg_func_opt */
+    case 405: /* analyze_opt */
+    case 408: /* or_replace_opt */
+    case 409: /* agg_func_opt */
     case 453: /* set_quantifier_opt */
 {
+#line 144 "sql.y"
  
+#line 2883 "sql.c"
 }
       break;
     case 357: /* integer_list */
     case 358: /* variable_list */
     case 359: /* retention_list */
-    case 363: /* column_def_list */
-    case 364: /* tags_def_opt */
-    case 366: /* multi_create_clause */
-    case 367: /* tags_def */
-    case 368: /* multi_drop_clause */
-    case 375: /* specific_cols_opt */
-    case 376: /* expression_list */
-    case 378: /* col_name_list */
-    case 380: /* duration_list */
-    case 381: /* rollup_func_list */
-    case 391: /* tag_list_opt */
-    case 397: /* func_list */
-    case 413: /* col_list_opt */
-    case 414: /* tag_def_or_ref_opt */
-    case 417: /* dnode_list */
+    case 364: /* column_def_list */
+    case 365: /* tags_def_opt */
+    case 367: /* multi_create_clause */
+    case 368: /* tags_def */
+    case 369: /* multi_drop_clause */
+    case 376: /* specific_cols_opt */
+    case 377: /* expression_list */
+    case 379: /* col_name_list */
+    case 381: /* duration_list */
+    case 382: /* rollup_func_list */
+    case 392: /* tag_list_opt */
+    case 398: /* func_list */
+    case 414: /* col_list_opt */
+    case 415: /* tag_def_or_ref_opt */
+    case 418: /* dnode_list */
     case 421: /* literal_list */
     case 429: /* star_func_para_list */
     case 431: /* other_para_list */
@@ -2895,44 +2912,60 @@ static void yy_destructor(
     case 469: /* order_by_clause_opt */
     case 474: /* sort_specification_list */
 {
+#line 264 "sql.y"
  nodesDestroyList((yypminor->yy532)); 
+#line 2918 "sql.c"
 }
       break;
-    case 360: /* alter_db_option */
-    case 382: /* alter_table_option */
+    case 361: /* alter_db_option */
+    case 383: /* alter_table_option */
 {
+#line 237 "sql.y"
  
+#line 2926 "sql.c"
 }
       break;
-    case 372: /* type_name */
+    case 373: /* type_name */
 {
+#line 358 "sql.y"
  
+#line 2933 "sql.c"
 }
       break;
     case 438: /* compare_op */
     case 439: /* in_op */
 {
+#line 909 "sql.y"
  
+#line 2941 "sql.c"
 }
       break;
     case 451: /* join_type */
 {
+#line 985 "sql.y"
  
+#line 2948 "sql.c"
 }
       break;
     case 465: /* fill_mode */
 {
+#line 1060 "sql.y"
  
+#line 2955 "sql.c"
 }
       break;
     case 476: /* ordering_specification_opt */
 {
+#line 1143 "sql.y"
  
+#line 2962 "sql.c"
 }
       break;
     case 477: /* null_ordering_opt */
 {
+#line 1149 "sql.y"
  
+#line 2969 "sql.c"
 }
       break;
 /********* End destructor definitions *****************************************/
@@ -3334,32 +3367,32 @@ static const YYCODETYPE yyRuleInfoLhs[] = {
    351,  /* (110) db_options ::= db_options WAL_ROLL_PERIOD NK_INTEGER */
    351,  /* (111) db_options ::= db_options WAL_SEGMENT_SIZE NK_INTEGER */
    351,  /* (112) db_options ::= db_options STT_TRIGGER NK_INTEGER */
-   351,  /* (113) db_options ::= db_options TABLE_PREFIX NK_INTEGER */
-   351,  /* (114) db_options ::= db_options TABLE_SUFFIX NK_INTEGER */
+   351,  /* (113) db_options ::= db_options TABLE_PREFIX signed */
+   351,  /* (114) db_options ::= db_options TABLE_SUFFIX signed */
    353,  /* (115) alter_db_options ::= alter_db_option */
    353,  /* (116) alter_db_options ::= alter_db_options alter_db_option */
-   360,  /* (117) alter_db_option ::= BUFFER NK_INTEGER */
-   360,  /* (118) alter_db_option ::= CACHEMODEL NK_STRING */
-   360,  /* (119) alter_db_option ::= CACHESIZE NK_INTEGER */
-   360,  /* (120) alter_db_option ::= WAL_FSYNC_PERIOD NK_INTEGER */
-   360,  /* (121) alter_db_option ::= KEEP integer_list */
-   360,  /* (122) alter_db_option ::= KEEP variable_list */
-   360,  /* (123) alter_db_option ::= PAGES NK_INTEGER */
-   360,  /* (124) alter_db_option ::= REPLICA NK_INTEGER */
-   360,  /* (125) alter_db_option ::= WAL_LEVEL NK_INTEGER */
-   360,  /* (126) alter_db_option ::= STT_TRIGGER NK_INTEGER */
-   360,  /* (127) alter_db_option ::= MINROWS NK_INTEGER */
-   360,  /* (128) alter_db_option ::= WAL_RETENTION_PERIOD NK_INTEGER */
-   360,  /* (129) alter_db_option ::= WAL_RETENTION_PERIOD NK_MINUS NK_INTEGER */
-   360,  /* (130) alter_db_option ::= WAL_RETENTION_SIZE NK_INTEGER */
-   360,  /* (131) alter_db_option ::= WAL_RETENTION_SIZE NK_MINUS NK_INTEGER */
+   361,  /* (117) alter_db_option ::= BUFFER NK_INTEGER */
+   361,  /* (118) alter_db_option ::= CACHEMODEL NK_STRING */
+   361,  /* (119) alter_db_option ::= CACHESIZE NK_INTEGER */
+   361,  /* (120) alter_db_option ::= WAL_FSYNC_PERIOD NK_INTEGER */
+   361,  /* (121) alter_db_option ::= KEEP integer_list */
+   361,  /* (122) alter_db_option ::= KEEP variable_list */
+   361,  /* (123) alter_db_option ::= PAGES NK_INTEGER */
+   361,  /* (124) alter_db_option ::= REPLICA NK_INTEGER */
+   361,  /* (125) alter_db_option ::= WAL_LEVEL NK_INTEGER */
+   361,  /* (126) alter_db_option ::= STT_TRIGGER NK_INTEGER */
+   361,  /* (127) alter_db_option ::= MINROWS NK_INTEGER */
+   361,  /* (128) alter_db_option ::= WAL_RETENTION_PERIOD NK_INTEGER */
+   361,  /* (129) alter_db_option ::= WAL_RETENTION_PERIOD NK_MINUS NK_INTEGER */
+   361,  /* (130) alter_db_option ::= WAL_RETENTION_SIZE NK_INTEGER */
+   361,  /* (131) alter_db_option ::= WAL_RETENTION_SIZE NK_MINUS NK_INTEGER */
    357,  /* (132) integer_list ::= NK_INTEGER */
    357,  /* (133) integer_list ::= integer_list NK_COMMA NK_INTEGER */
    358,  /* (134) variable_list ::= NK_VARIABLE */
    358,  /* (135) variable_list ::= variable_list NK_COMMA NK_VARIABLE */
    359,  /* (136) retention_list ::= retention */
    359,  /* (137) retention_list ::= retention_list NK_COMMA retention */
-   361,  /* (138) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */
+   362,  /* (138) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */
    354,  /* (139) speed_opt ::= */
    354,  /* (140) speed_opt ::= MAX_SPEED NK_INTEGER */
    355,  /* (141) start_opt ::= */
@@ -3377,77 +3410,77 @@ static const YYCODETYPE yyRuleInfoLhs[] = {
    332,  /* (153) cmd ::= DROP STABLE exists_opt full_table_name */
    332,  /* (154) cmd ::= ALTER TABLE alter_table_clause */
    332,  /* (155) cmd ::= ALTER STABLE alter_table_clause */
-   369,  /* (156) alter_table_clause ::= full_table_name alter_table_options */
-   369,  /* (157) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */
-   369,  /* (158) alter_table_clause ::= full_table_name DROP COLUMN column_name */
-   369,  /* (159) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */
-   369,  /* (160) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */
-   369,  /* (161) alter_table_clause ::= full_table_name ADD TAG column_name type_name */
-   369,  /* (162) alter_table_clause ::= full_table_name DROP TAG column_name */
-   369,  /* (163) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */
-   369,  /* (164) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */
-   369,  /* (165) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */
-   366,  /* (166) multi_create_clause ::= create_subtable_clause */
-   366,  /* (167) multi_create_clause ::= multi_create_clause create_subtable_clause */
-   374,  /* (168) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */
-   368,  /* (169) multi_drop_clause ::= drop_table_clause */
-   368,  /* (170) multi_drop_clause ::= multi_drop_clause NK_COMMA drop_table_clause */
-   377,  /* (171) drop_table_clause ::= exists_opt full_table_name */
-   375,  /* (172) specific_cols_opt ::= */
-   375,  /* (173) specific_cols_opt ::= NK_LP col_name_list NK_RP */
-   362,  /* (174) full_table_name ::= table_name */
-   362,  /* (175) full_table_name ::= db_name NK_DOT table_name */
-   363,  /* (176) column_def_list ::= column_def */
-   363,  /* (177) column_def_list ::= column_def_list NK_COMMA column_def */
-   379,  /* (178) column_def ::= column_name type_name */
-   372,  /* (179) type_name ::= BOOL */
-   372,  /* (180) type_name ::= TINYINT */
-   372,  /* (181) type_name ::= SMALLINT */
-   372,  /* (182) type_name ::= INT */
-   372,  /* (183) type_name ::= INTEGER */
-   372,  /* (184) type_name ::= BIGINT */
-   372,  /* (185) type_name ::= FLOAT */
-   372,  /* (186) type_name ::= DOUBLE */
-   372,  /* (187) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */
-   372,  /* (188) type_name ::= TIMESTAMP */
-   372,  /* (189) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */
-   372,  /* (190) type_name ::= TINYINT UNSIGNED */
-   372,  /* (191) type_name ::= SMALLINT UNSIGNED */
-   372,  /* (192) type_name ::= INT UNSIGNED */
-   372,  /* (193) type_name ::= BIGINT UNSIGNED */
-   372,  /* (194) type_name ::= JSON */
-   372,  /* (195) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */
-   372,  /* (196) type_name ::= MEDIUMBLOB */
-   372,  /* (197) type_name ::= BLOB */
-   372,  /* (198) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */
-   372,  /* (199) type_name ::= DECIMAL */
-   372,  /* (200) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */
-   372,  /* (201) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */
-   364,  /* (202) tags_def_opt ::= */
-   364,  /* (203) tags_def_opt ::= tags_def */
-   367,  /* (204) tags_def ::= TAGS NK_LP column_def_list NK_RP */
-   365,  /* (205) table_options ::= */
-   365,  /* (206) table_options ::= table_options COMMENT NK_STRING */
-   365,  /* (207) table_options ::= table_options MAX_DELAY duration_list */
-   365,  /* (208) table_options ::= table_options WATERMARK duration_list */
-   365,  /* (209) table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */
-   365,  /* (210) table_options ::= table_options TTL NK_INTEGER */
-   365,  /* (211) table_options ::= table_options SMA NK_LP col_name_list NK_RP */
-   365,  /* (212) table_options ::= table_options DELETE_MARK duration_list */
-   370,  /* (213) alter_table_options ::= alter_table_option */
-   370,  /* (214) alter_table_options ::= alter_table_options alter_table_option */
-   382,  /* (215) alter_table_option ::= COMMENT NK_STRING */
-   382,  /* (216) alter_table_option ::= TTL NK_INTEGER */
-   380,  /* (217) duration_list ::= duration_literal */
-   380,  /* (218) duration_list ::= duration_list NK_COMMA duration_literal */
-   381,  /* (219) rollup_func_list ::= rollup_func_name */
-   381,  /* (220) rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */
-   384,  /* (221) rollup_func_name ::= function_name */
-   384,  /* (222) rollup_func_name ::= FIRST */
-   384,  /* (223) rollup_func_name ::= LAST */
-   378,  /* (224) col_name_list ::= col_name */
-   378,  /* (225) col_name_list ::= col_name_list NK_COMMA col_name */
-   386,  /* (226) col_name ::= column_name */
+   370,  /* (156) alter_table_clause ::= full_table_name alter_table_options */
+   370,  /* (157) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */
+   370,  /* (158) alter_table_clause ::= full_table_name DROP COLUMN column_name */
+   370,  /* (159) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */
+   370,  /* (160) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */
+   370,  /* (161) alter_table_clause ::= full_table_name ADD TAG column_name type_name */
+   370,  /* (162) alter_table_clause ::= full_table_name DROP TAG column_name */
+   370,  /* (163) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */
+   370,  /* (164) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */
+   370,  /* (165) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */
+   367,  /* (166) multi_create_clause ::= create_subtable_clause */
+   367,  /* (167) multi_create_clause ::= multi_create_clause create_subtable_clause */
+   375,  /* (168) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */
+   369,  /* (169) multi_drop_clause ::= drop_table_clause */
+   369,  /* (170) multi_drop_clause ::= multi_drop_clause NK_COMMA drop_table_clause */
+   378,  /* (171) drop_table_clause ::= exists_opt full_table_name */
+   376,  /* (172) specific_cols_opt ::= */
+   376,  /* (173) specific_cols_opt ::= NK_LP col_name_list NK_RP */
+   363,  /* (174) full_table_name ::= table_name */
+   363,  /* (175) full_table_name ::= db_name NK_DOT table_name */
+   364,  /* (176) column_def_list ::= column_def */
+   364,  /* (177) column_def_list ::= column_def_list NK_COMMA column_def */
+   380,  /* (178) column_def ::= column_name type_name */
+   373,  /* (179) type_name ::= BOOL */
+   373,  /* (180) type_name ::= TINYINT */
+   373,  /* (181) type_name ::= SMALLINT */
+   373,  /* (182) type_name ::= INT */
+   373,  /* (183) type_name ::= INTEGER */
+   373,  /* (184) type_name ::= BIGINT */
+   373,  /* (185) type_name ::= FLOAT */
+   373,  /* (186) type_name ::= DOUBLE */
+   373,  /* (187) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */
+   373,  /* (188) type_name ::= TIMESTAMP */
+   373,  /* (189) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */
+   373,  /* (190) type_name ::= TINYINT UNSIGNED */
+   373,  /* (191) type_name ::= SMALLINT UNSIGNED */
+   373,  /* (192) type_name ::= INT UNSIGNED */
+   373,  /* (193) type_name ::= BIGINT UNSIGNED */
+   373,  /* (194) type_name ::= JSON */
+   373,  /* (195) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */
+   373,  /* (196) type_name ::= MEDIUMBLOB */
+   373,  /* (197) type_name ::= BLOB */
+   373,  /* (198) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */
+   373,  /* (199) type_name ::= DECIMAL */
+   373,  /* (200) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */
+   373,  /* (201) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */
+   365,  /* (202) tags_def_opt ::= */
+   365,  /* (203) tags_def_opt ::= tags_def */
+   368,  /* (204) tags_def ::= TAGS NK_LP column_def_list NK_RP */
+   366,  /* (205) table_options ::= */
+   366,  /* (206) table_options ::= table_options COMMENT NK_STRING */
+   366,  /* (207) table_options ::= table_options MAX_DELAY duration_list */
+   366,  /* (208) table_options ::= table_options WATERMARK duration_list */
+   366,  /* (209) table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */
+   366,  /* (210) table_options ::= table_options TTL NK_INTEGER */
+   366,  /* (211) table_options ::= table_options SMA NK_LP col_name_list NK_RP */
+   366,  /* (212) table_options ::= table_options DELETE_MARK duration_list */
+   371,  /* (213) alter_table_options ::= alter_table_option */
+   371,  /* (214) alter_table_options ::= alter_table_options alter_table_option */
+   383,  /* (215) alter_table_option ::= COMMENT NK_STRING */
+   383,  /* (216) alter_table_option ::= TTL NK_INTEGER */
+   381,  /* (217) duration_list ::= duration_literal */
+   381,  /* (218) duration_list ::= duration_list NK_COMMA duration_literal */
+   382,  /* (219) rollup_func_list ::= rollup_func_name */
+   382,  /* (220) rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */
+   385,  /* (221) rollup_func_name ::= function_name */
+   385,  /* (222) rollup_func_name ::= FIRST */
+   385,  /* (223) rollup_func_name ::= LAST */
+   379,  /* (224) col_name_list ::= col_name */
+   379,  /* (225) col_name_list ::= col_name_list NK_COMMA col_name */
+   387,  /* (226) col_name ::= column_name */
    332,  /* (227) cmd ::= SHOW DNODES */
    332,  /* (228) cmd ::= SHOW USERS */
    332,  /* (229) cmd ::= SHOW USER PRIVILEGES */
@@ -3488,40 +3521,40 @@ static const YYCODETYPE yyRuleInfoLhs[] = {
    332,  /* (264) cmd ::= SHOW VNODES NK_STRING */
    332,  /* (265) cmd ::= SHOW db_name_cond_opt ALIVE */
    332,  /* (266) cmd ::= SHOW CLUSTER ALIVE */
-   387,  /* (267) db_name_cond_opt ::= */
-   387,  /* (268) db_name_cond_opt ::= db_name NK_DOT */
-   388,  /* (269) like_pattern_opt ::= */
-   388,  /* (270) like_pattern_opt ::= LIKE NK_STRING */
-   389,  /* (271) table_name_cond ::= table_name */
-   390,  /* (272) from_db_opt ::= */
-   390,  /* (273) from_db_opt ::= FROM db_name */
-   391,  /* (274) tag_list_opt ::= */
-   391,  /* (275) tag_list_opt ::= tag_item */
-   391,  /* (276) tag_list_opt ::= tag_list_opt NK_COMMA tag_item */
-   392,  /* (277) tag_item ::= TBNAME */
-   392,  /* (278) tag_item ::= QTAGS */
-   392,  /* (279) tag_item ::= column_name */
-   392,  /* (280) tag_item ::= column_name column_alias */
-   392,  /* (281) tag_item ::= column_name AS column_alias */
+   388,  /* (267) db_name_cond_opt ::= */
+   388,  /* (268) db_name_cond_opt ::= db_name NK_DOT */
+   389,  /* (269) like_pattern_opt ::= */
+   389,  /* (270) like_pattern_opt ::= LIKE NK_STRING */
+   390,  /* (271) table_name_cond ::= table_name */
+   391,  /* (272) from_db_opt ::= */
+   391,  /* (273) from_db_opt ::= FROM db_name */
+   392,  /* (274) tag_list_opt ::= */
+   392,  /* (275) tag_list_opt ::= tag_item */
+   392,  /* (276) tag_list_opt ::= tag_list_opt NK_COMMA tag_item */
+   393,  /* (277) tag_item ::= TBNAME */
+   393,  /* (278) tag_item ::= QTAGS */
+   393,  /* (279) tag_item ::= column_name */
+   393,  /* (280) tag_item ::= column_name column_alias */
+   393,  /* (281) tag_item ::= column_name AS column_alias */
    332,  /* (282) cmd ::= CREATE SMA INDEX not_exists_opt full_index_name ON full_table_name index_options */
    332,  /* (283) cmd ::= CREATE INDEX not_exists_opt full_index_name ON full_table_name NK_LP col_name_list NK_RP */
    332,  /* (284) cmd ::= DROP INDEX exists_opt full_index_name */
-   394,  /* (285) full_index_name ::= index_name */
-   394,  /* (286) full_index_name ::= db_name NK_DOT index_name */
-   395,  /* (287) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */
-   395,  /* (288) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */
-   397,  /* (289) func_list ::= func */
-   397,  /* (290) func_list ::= func_list NK_COMMA func */
-   400,  /* (291) func ::= sma_func_name NK_LP expression_list NK_RP */
-   401,  /* (292) sma_func_name ::= function_name */
-   401,  /* (293) sma_func_name ::= COUNT */
-   401,  /* (294) sma_func_name ::= FIRST */
-   401,  /* (295) sma_func_name ::= LAST */
-   401,  /* (296) sma_func_name ::= LAST_ROW */
-   399,  /* (297) sma_stream_opt ::= */
-   399,  /* (298) sma_stream_opt ::= sma_stream_opt WATERMARK duration_literal */
-   399,  /* (299) sma_stream_opt ::= sma_stream_opt MAX_DELAY duration_literal */
-   399,  /* (300) sma_stream_opt ::= sma_stream_opt DELETE_MARK duration_literal */
+   395,  /* (285) full_index_name ::= index_name */
+   395,  /* (286) full_index_name ::= db_name NK_DOT index_name */
+   396,  /* (287) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */
+   396,  /* (288) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */
+   398,  /* (289) func_list ::= func */
+   398,  /* (290) func_list ::= func_list NK_COMMA func */
+   401,  /* (291) func ::= sma_func_name NK_LP expression_list NK_RP */
+   402,  /* (292) sma_func_name ::= function_name */
+   402,  /* (293) sma_func_name ::= COUNT */
+   402,  /* (294) sma_func_name ::= FIRST */
+   402,  /* (295) sma_func_name ::= LAST */
+   402,  /* (296) sma_func_name ::= LAST_ROW */
+   400,  /* (297) sma_stream_opt ::= */
+   400,  /* (298) sma_stream_opt ::= sma_stream_opt WATERMARK duration_literal */
+   400,  /* (299) sma_stream_opt ::= sma_stream_opt MAX_DELAY duration_literal */
+   400,  /* (300) sma_stream_opt ::= sma_stream_opt DELETE_MARK duration_literal */
    332,  /* (301) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_or_subquery */
    332,  /* (302) cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */
    332,  /* (303) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */
@@ -3534,39 +3567,39 @@ static const YYCODETYPE yyRuleInfoLhs[] = {
    332,  /* (310) cmd ::= RESET QUERY CACHE */
    332,  /* (311) cmd ::= EXPLAIN analyze_opt explain_options query_or_subquery */
    332,  /* (312) cmd ::= EXPLAIN analyze_opt explain_options insert_query */
-   404,  /* (313) analyze_opt ::= */
-   404,  /* (314) analyze_opt ::= ANALYZE */
-   405,  /* (315) explain_options ::= */
-   405,  /* (316) explain_options ::= explain_options VERBOSE NK_BOOL */
-   405,  /* (317) explain_options ::= explain_options RATIO NK_FLOAT */
+   405,  /* (313) analyze_opt ::= */
+   405,  /* (314) analyze_opt ::= ANALYZE */
+   406,  /* (315) explain_options ::= */
+   406,  /* (316) explain_options ::= explain_options VERBOSE NK_BOOL */
+   406,  /* (317) explain_options ::= explain_options RATIO NK_FLOAT */
    332,  /* (318) cmd ::= CREATE or_replace_opt agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt language_opt */
    332,  /* (319) cmd ::= DROP FUNCTION exists_opt function_name */
-   408,  /* (320) agg_func_opt ::= */
-   408,  /* (321) agg_func_opt ::= AGGREGATE */
-   409,  /* (322) bufsize_opt ::= */
-   409,  /* (323) bufsize_opt ::= BUFSIZE NK_INTEGER */
-   410,  /* (324) language_opt ::= */
-   410,  /* (325) language_opt ::= LANGUAGE NK_STRING */
-   407,  /* (326) or_replace_opt ::= */
-   407,  /* (327) or_replace_opt ::= OR REPLACE */
+   409,  /* (320) agg_func_opt ::= */
+   409,  /* (321) agg_func_opt ::= AGGREGATE */
+   410,  /* (322) bufsize_opt ::= */
+   410,  /* (323) bufsize_opt ::= BUFSIZE NK_INTEGER */
+   411,  /* (324) language_opt ::= */
+   411,  /* (325) language_opt ::= LANGUAGE NK_STRING */
+   408,  /* (326) or_replace_opt ::= */
+   408,  /* (327) or_replace_opt ::= OR REPLACE */
    332,  /* (328) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options INTO full_table_name col_list_opt tag_def_or_ref_opt subtable_opt AS query_or_subquery */
    332,  /* (329) cmd ::= DROP STREAM exists_opt stream_name */
-   413,  /* (330) col_list_opt ::= */
-   413,  /* (331) col_list_opt ::= NK_LP col_name_list NK_RP */
-   414,  /* (332) tag_def_or_ref_opt ::= */
-   414,  /* (333) tag_def_or_ref_opt ::= tags_def */
-   414,  /* (334) tag_def_or_ref_opt ::= TAGS NK_LP col_name_list NK_RP */
-   412,  /* (335) stream_options ::= */
-   412,  /* (336) stream_options ::= stream_options TRIGGER AT_ONCE */
-   412,  /* (337) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */
-   412,  /* (338) stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */
-   412,  /* (339) stream_options ::= stream_options WATERMARK duration_literal */
-   412,  /* (340) stream_options ::= stream_options IGNORE EXPIRED NK_INTEGER */
-   412,  /* (341) stream_options ::= stream_options FILL_HISTORY NK_INTEGER */
-   412,  /* (342) stream_options ::= stream_options DELETE_MARK duration_literal */
-   412,  /* (343) stream_options ::= stream_options IGNORE UPDATE NK_INTEGER */
-   415,  /* (344) subtable_opt ::= */
-   415,  /* (345) subtable_opt ::= SUBTABLE NK_LP expression NK_RP */
+   414,  /* (330) col_list_opt ::= */
+   414,  /* (331) col_list_opt ::= NK_LP col_name_list NK_RP */
+   415,  /* (332) tag_def_or_ref_opt ::= */
+   415,  /* (333) tag_def_or_ref_opt ::= tags_def */
+   415,  /* (334) tag_def_or_ref_opt ::= TAGS NK_LP col_name_list NK_RP */
+   413,  /* (335) stream_options ::= */
+   413,  /* (336) stream_options ::= stream_options TRIGGER AT_ONCE */
+   413,  /* (337) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */
+   413,  /* (338) stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */
+   413,  /* (339) stream_options ::= stream_options WATERMARK duration_literal */
+   413,  /* (340) stream_options ::= stream_options IGNORE EXPIRED NK_INTEGER */
+   413,  /* (341) stream_options ::= stream_options FILL_HISTORY NK_INTEGER */
+   413,  /* (342) stream_options ::= stream_options DELETE_MARK duration_literal */
+   413,  /* (343) stream_options ::= stream_options IGNORE UPDATE NK_INTEGER */
+   416,  /* (344) subtable_opt ::= */
+   416,  /* (345) subtable_opt ::= SUBTABLE NK_LP expression NK_RP */
    332,  /* (346) cmd ::= KILL CONNECTION NK_INTEGER */
    332,  /* (347) cmd ::= KILL QUERY NK_STRING */
    332,  /* (348) cmd ::= KILL TRANSACTION NK_INTEGER */
@@ -3575,13 +3608,13 @@ static const YYCODETYPE yyRuleInfoLhs[] = {
    332,  /* (351) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */
    332,  /* (352) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */
    332,  /* (353) cmd ::= SPLIT VGROUP NK_INTEGER */
-   417,  /* (354) dnode_list ::= DNODE NK_INTEGER */
-   417,  /* (355) dnode_list ::= dnode_list DNODE NK_INTEGER */
+   418,  /* (354) dnode_list ::= DNODE NK_INTEGER */
+   418,  /* (355) dnode_list ::= dnode_list DNODE NK_INTEGER */
    332,  /* (356) cmd ::= DELETE FROM full_table_name where_clause_opt */
    332,  /* (357) cmd ::= query_or_subquery */
    332,  /* (358) cmd ::= insert_query */
-   406,  /* (359) insert_query ::= INSERT INTO full_table_name NK_LP col_name_list NK_RP query_or_subquery */
-   406,  /* (360) insert_query ::= INSERT INTO full_table_name query_or_subquery */
+   407,  /* (359) insert_query ::= INSERT INTO full_table_name NK_LP col_name_list NK_RP query_or_subquery */
+   407,  /* (360) insert_query ::= INSERT INTO full_table_name query_or_subquery */
    335,  /* (361) literal ::= NK_INTEGER */
    335,  /* (362) literal ::= NK_FLOAT */
    335,  /* (363) literal ::= NK_STRING */
@@ -3590,53 +3623,53 @@ static const YYCODETYPE yyRuleInfoLhs[] = {
    335,  /* (366) literal ::= duration_literal */
    335,  /* (367) literal ::= NULL */
    335,  /* (368) literal ::= NK_QUESTION */
-   383,  /* (369) duration_literal ::= NK_VARIABLE */
-   419,  /* (370) signed ::= NK_INTEGER */
-   419,  /* (371) signed ::= NK_PLUS NK_INTEGER */
-   419,  /* (372) signed ::= NK_MINUS NK_INTEGER */
-   419,  /* (373) signed ::= NK_FLOAT */
-   419,  /* (374) signed ::= NK_PLUS NK_FLOAT */
-   419,  /* (375) signed ::= NK_MINUS NK_FLOAT */
-   373,  /* (376) signed_literal ::= signed */
-   373,  /* (377) signed_literal ::= NK_STRING */
-   373,  /* (378) signed_literal ::= NK_BOOL */
-   373,  /* (379) signed_literal ::= TIMESTAMP NK_STRING */
-   373,  /* (380) signed_literal ::= duration_literal */
-   373,  /* (381) signed_literal ::= NULL */
-   373,  /* (382) signed_literal ::= literal_func */
-   373,  /* (383) signed_literal ::= NK_QUESTION */
+   384,  /* (369) duration_literal ::= NK_VARIABLE */
+   360,  /* (370) signed ::= NK_INTEGER */
+   360,  /* (371) signed ::= NK_PLUS NK_INTEGER */
+   360,  /* (372) signed ::= NK_MINUS NK_INTEGER */
+   360,  /* (373) signed ::= NK_FLOAT */
+   360,  /* (374) signed ::= NK_PLUS NK_FLOAT */
+   360,  /* (375) signed ::= NK_MINUS NK_FLOAT */
+   374,  /* (376) signed_literal ::= signed */
+   374,  /* (377) signed_literal ::= NK_STRING */
+   374,  /* (378) signed_literal ::= NK_BOOL */
+   374,  /* (379) signed_literal ::= TIMESTAMP NK_STRING */
+   374,  /* (380) signed_literal ::= duration_literal */
+   374,  /* (381) signed_literal ::= NULL */
+   374,  /* (382) signed_literal ::= literal_func */
+   374,  /* (383) signed_literal ::= NK_QUESTION */
    421,  /* (384) literal_list ::= signed_literal */
    421,  /* (385) literal_list ::= literal_list NK_COMMA signed_literal */
    344,  /* (386) db_name ::= NK_ID */
    345,  /* (387) table_name ::= NK_ID */
-   371,  /* (388) column_name ::= NK_ID */
-   385,  /* (389) function_name ::= NK_ID */
+   372,  /* (388) column_name ::= NK_ID */
+   386,  /* (389) function_name ::= NK_ID */
    422,  /* (390) table_alias ::= NK_ID */
-   393,  /* (391) column_alias ::= NK_ID */
+   394,  /* (391) column_alias ::= NK_ID */
    337,  /* (392) user_name ::= NK_ID */
    346,  /* (393) topic_name ::= NK_ID */
-   411,  /* (394) stream_name ::= NK_ID */
-   403,  /* (395) cgroup_name ::= NK_ID */
-   396,  /* (396) index_name ::= NK_ID */
+   412,  /* (394) stream_name ::= NK_ID */
+   404,  /* (395) cgroup_name ::= NK_ID */
+   397,  /* (396) index_name ::= NK_ID */
    423,  /* (397) expr_or_subquery ::= expression */
-   416,  /* (398) expression ::= literal */
-   416,  /* (399) expression ::= pseudo_column */
-   416,  /* (400) expression ::= column_reference */
-   416,  /* (401) expression ::= function_expression */
-   416,  /* (402) expression ::= case_when_expression */
-   416,  /* (403) expression ::= NK_LP expression NK_RP */
-   416,  /* (404) expression ::= NK_PLUS expr_or_subquery */
-   416,  /* (405) expression ::= NK_MINUS expr_or_subquery */
-   416,  /* (406) expression ::= expr_or_subquery NK_PLUS expr_or_subquery */
-   416,  /* (407) expression ::= expr_or_subquery NK_MINUS expr_or_subquery */
-   416,  /* (408) expression ::= expr_or_subquery NK_STAR expr_or_subquery */
-   416,  /* (409) expression ::= expr_or_subquery NK_SLASH expr_or_subquery */
-   416,  /* (410) expression ::= expr_or_subquery NK_REM expr_or_subquery */
-   416,  /* (411) expression ::= column_reference NK_ARROW NK_STRING */
-   416,  /* (412) expression ::= expr_or_subquery NK_BITAND expr_or_subquery */
-   416,  /* (413) expression ::= expr_or_subquery NK_BITOR expr_or_subquery */
-   376,  /* (414) expression_list ::= expr_or_subquery */
-   376,  /* (415) expression_list ::= expression_list NK_COMMA expr_or_subquery */
+   417,  /* (398) expression ::= literal */
+   417,  /* (399) expression ::= pseudo_column */
+   417,  /* (400) expression ::= column_reference */
+   417,  /* (401) expression ::= function_expression */
+   417,  /* (402) expression ::= case_when_expression */
+   417,  /* (403) expression ::= NK_LP expression NK_RP */
+   417,  /* (404) expression ::= NK_PLUS expr_or_subquery */
+   417,  /* (405) expression ::= NK_MINUS expr_or_subquery */
+   417,  /* (406) expression ::= expr_or_subquery NK_PLUS expr_or_subquery */
+   417,  /* (407) expression ::= expr_or_subquery NK_MINUS expr_or_subquery */
+   417,  /* (408) expression ::= expr_or_subquery NK_STAR expr_or_subquery */
+   417,  /* (409) expression ::= expr_or_subquery NK_SLASH expr_or_subquery */
+   417,  /* (410) expression ::= expr_or_subquery NK_REM expr_or_subquery */
+   417,  /* (411) expression ::= column_reference NK_ARROW NK_STRING */
+   417,  /* (412) expression ::= expr_or_subquery NK_BITAND expr_or_subquery */
+   417,  /* (413) expression ::= expr_or_subquery NK_BITOR expr_or_subquery */
+   377,  /* (414) expression_list ::= expr_or_subquery */
+   377,  /* (415) expression_list ::= expression_list NK_COMMA expr_or_subquery */
    425,  /* (416) column_reference ::= column_name */
    425,  /* (417) column_reference ::= table_name NK_DOT column_name */
    424,  /* (418) pseudo_column ::= ROWTS */
@@ -3740,8 +3773,8 @@ static const YYCODETYPE yyRuleInfoLhs[] = {
    462,  /* (516) select_item ::= common_expression column_alias */
    462,  /* (517) select_item ::= common_expression AS column_alias */
    462,  /* (518) select_item ::= table_name NK_DOT NK_STAR */
-   418,  /* (519) where_clause_opt ::= */
-   418,  /* (520) where_clause_opt ::= WHERE search_condition */
+   419,  /* (519) where_clause_opt ::= */
+   419,  /* (520) where_clause_opt ::= WHERE search_condition */
    455,  /* (521) partition_by_clause_opt ::= */
    455,  /* (522) partition_by_clause_opt ::= PARTITION BY partition_list */
    463,  /* (523) partition_list ::= partition_item */
@@ -3755,8 +3788,8 @@ static const YYCODETYPE yyRuleInfoLhs[] = {
    459,  /* (531) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */
    459,  /* (532) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */
    459,  /* (533) twindow_clause_opt ::= EVENT_WINDOW START WITH search_condition END WITH search_condition */
-   398,  /* (534) sliding_opt ::= */
-   398,  /* (535) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */
+   399,  /* (534) sliding_opt ::= */
+   399,  /* (535) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */
    458,  /* (536) fill_opt ::= */
    458,  /* (537) fill_opt ::= FILL NK_LP fill_mode NK_RP */
    458,  /* (538) fill_opt ::= FILL NK_LP VALUE NK_COMMA expression_list NK_RP */
@@ -3784,8 +3817,8 @@ static const YYCODETYPE yyRuleInfoLhs[] = {
    472,  /* (560) union_query_expression ::= query_simple_or_subquery UNION query_simple_or_subquery */
    473,  /* (561) query_simple_or_subquery ::= query_simple */
    473,  /* (562) query_simple_or_subquery ::= subquery */
-   402,  /* (563) query_or_subquery ::= query_expression */
-   402,  /* (564) query_or_subquery ::= subquery */
+   403,  /* (563) query_or_subquery ::= query_expression */
+   403,  /* (564) query_or_subquery ::= subquery */
    469,  /* (565) order_by_clause_opt ::= */
    469,  /* (566) order_by_clause_opt ::= ORDER BY sort_specification_list */
    470,  /* (567) slimit_clause_opt ::= */
@@ -3926,8 +3959,8 @@ static const signed char yyRuleInfoNRhs[] = {
    -3,  /* (110) db_options ::= db_options WAL_ROLL_PERIOD NK_INTEGER */
    -3,  /* (111) db_options ::= db_options WAL_SEGMENT_SIZE NK_INTEGER */
    -3,  /* (112) db_options ::= db_options STT_TRIGGER NK_INTEGER */
-   -3,  /* (113) db_options ::= db_options TABLE_PREFIX NK_INTEGER */
-   -3,  /* (114) db_options ::= db_options TABLE_SUFFIX NK_INTEGER */
+   -3,  /* (113) db_options ::= db_options TABLE_PREFIX signed */
+   -3,  /* (114) db_options ::= db_options TABLE_SUFFIX signed */
    -1,  /* (115) alter_db_options ::= alter_db_option */
    -2,  /* (116) alter_db_options ::= alter_db_options alter_db_option */
    -2,  /* (117) alter_db_option ::= BUFFER NK_INTEGER */
@@ -4490,15 +4523,21 @@ static YYACTIONTYPE yy_reduce(
 /********** Begin reduce actions **********************************************/
         YYMINORTYPE yylhsminor;
       case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */
+#line 50 "sql.y"
 { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
+#line 4529 "sql.c"
   yy_destructor(yypParser,333,&yymsp[0].minor);
         break;
       case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */
+#line 51 "sql.y"
 { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
+#line 4535 "sql.c"
   yy_destructor(yypParser,334,&yymsp[0].minor);
         break;
       case 2: /* account_options ::= */
+#line 55 "sql.y"
 { }
+#line 4541 "sql.c"
         break;
       case 3: /* account_options ::= account_options PPS literal */
       case 4: /* account_options ::= account_options TSERIES literal */ yytestcase(yyruleno==4);
@@ -4510,18 +4549,24 @@ static YYACTIONTYPE yy_reduce(
       case 10: /* account_options ::= account_options CONNS literal */ yytestcase(yyruleno==10);
       case 11: /* account_options ::= account_options STATE literal */ yytestcase(yyruleno==11);
 {  yy_destructor(yypParser,333,&yymsp[-2].minor);
+#line 56 "sql.y"
 { }
+#line 4555 "sql.c"
   yy_destructor(yypParser,335,&yymsp[0].minor);
 }
         break;
       case 12: /* alter_account_options ::= alter_account_option */
 {  yy_destructor(yypParser,336,&yymsp[0].minor);
+#line 68 "sql.y"
 { }
+#line 4563 "sql.c"
 }
         break;
       case 13: /* alter_account_options ::= alter_account_options alter_account_option */
 {  yy_destructor(yypParser,334,&yymsp[-1].minor);
+#line 69 "sql.y"
 { }
+#line 4570 "sql.c"
   yy_destructor(yypParser,336,&yymsp[0].minor);
 }
         break;
@@ -4535,71 +4580,111 @@ static YYACTIONTYPE yy_reduce(
       case 21: /* alter_account_option ::= USERS literal */ yytestcase(yyruleno==21);
       case 22: /* alter_account_option ::= CONNS literal */ yytestcase(yyruleno==22);
       case 23: /* alter_account_option ::= STATE literal */ yytestcase(yyruleno==23);
+#line 73 "sql.y"
 { }
+#line 4586 "sql.c"
   yy_destructor(yypParser,335,&yymsp[0].minor);
         break;
       case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING sysinfo_opt */
+#line 85 "sql.y"
 { pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-3].minor.yy649, &yymsp[-1].minor.yy0, yymsp[0].minor.yy231); }
+#line 4592 "sql.c"
         break;
       case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */
+#line 86 "sql.y"
 { pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy649, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); }
+#line 4597 "sql.c"
         break;
       case 26: /* cmd ::= ALTER USER user_name ENABLE NK_INTEGER */
+#line 87 "sql.y"
 { pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy649, TSDB_ALTER_USER_ENABLE, &yymsp[0].minor.yy0); }
+#line 4602 "sql.c"
         break;
       case 27: /* cmd ::= ALTER USER user_name SYSINFO NK_INTEGER */
+#line 88 "sql.y"
 { pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy649, TSDB_ALTER_USER_SYSINFO, &yymsp[0].minor.yy0); }
+#line 4607 "sql.c"
         break;
       case 28: /* cmd ::= DROP USER user_name */
+#line 89 "sql.y"
 { pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy649); }
+#line 4612 "sql.c"
         break;
       case 29: /* sysinfo_opt ::= */
+#line 93 "sql.y"
 { yymsp[1].minor.yy231 = 1; }
+#line 4617 "sql.c"
         break;
       case 30: /* sysinfo_opt ::= SYSINFO NK_INTEGER */
+#line 94 "sql.y"
 { yymsp[-1].minor.yy231 = taosStr2Int8(yymsp[0].minor.yy0.z, NULL, 10); }
+#line 4622 "sql.c"
         break;
       case 31: /* cmd ::= GRANT privileges ON priv_level with_opt TO user_name */
+#line 97 "sql.y"
 { pCxt->pRootNode = createGrantStmt(pCxt, yymsp[-5].minor.yy541, &yymsp[-3].minor.yy409, &yymsp[0].minor.yy649, yymsp[-2].minor.yy184); }
+#line 4627 "sql.c"
         break;
       case 32: /* cmd ::= REVOKE privileges ON priv_level with_opt FROM user_name */
+#line 98 "sql.y"
 { pCxt->pRootNode = createRevokeStmt(pCxt, yymsp[-5].minor.yy541, &yymsp[-3].minor.yy409, &yymsp[0].minor.yy649, yymsp[-2].minor.yy184); }
+#line 4632 "sql.c"
         break;
       case 33: /* privileges ::= ALL */
+#line 102 "sql.y"
 { yymsp[0].minor.yy541 = PRIVILEGE_TYPE_ALL; }
+#line 4637 "sql.c"
         break;
       case 34: /* privileges ::= priv_type_list */
       case 36: /* priv_type_list ::= priv_type */ yytestcase(yyruleno==36);
+#line 103 "sql.y"
 { yylhsminor.yy541 = yymsp[0].minor.yy541; }
+#line 4643 "sql.c"
   yymsp[0].minor.yy541 = yylhsminor.yy541;
         break;
       case 35: /* privileges ::= SUBSCRIBE */
+#line 104 "sql.y"
 { yymsp[0].minor.yy541 = PRIVILEGE_TYPE_SUBSCRIBE; }
+#line 4649 "sql.c"
         break;
       case 37: /* priv_type_list ::= priv_type_list NK_COMMA priv_type */
+#line 109 "sql.y"
 { yylhsminor.yy541 = yymsp[-2].minor.yy541 | yymsp[0].minor.yy541; }
+#line 4654 "sql.c"
   yymsp[-2].minor.yy541 = yylhsminor.yy541;
         break;
       case 38: /* priv_type ::= READ */
+#line 113 "sql.y"
 { yymsp[0].minor.yy541 = PRIVILEGE_TYPE_READ; }
+#line 4660 "sql.c"
         break;
       case 39: /* priv_type ::= WRITE */
+#line 114 "sql.y"
 { yymsp[0].minor.yy541 = PRIVILEGE_TYPE_WRITE; }
+#line 4665 "sql.c"
         break;
       case 40: /* priv_level ::= NK_STAR NK_DOT NK_STAR */
+#line 118 "sql.y"
 { yylhsminor.yy409.first = yymsp[-2].minor.yy0; yylhsminor.yy409.second = yymsp[0].minor.yy0; }
+#line 4670 "sql.c"
   yymsp[-2].minor.yy409 = yylhsminor.yy409;
         break;
       case 41: /* priv_level ::= db_name NK_DOT NK_STAR */
+#line 119 "sql.y"
 { yylhsminor.yy409.first = yymsp[-2].minor.yy649; yylhsminor.yy409.second = yymsp[0].minor.yy0; }
+#line 4676 "sql.c"
   yymsp[-2].minor.yy409 = yylhsminor.yy409;
         break;
       case 42: /* priv_level ::= db_name NK_DOT table_name */
+#line 120 "sql.y"
 { yylhsminor.yy409.first = yymsp[-2].minor.yy649; yylhsminor.yy409.second = yymsp[0].minor.yy649; }
+#line 4682 "sql.c"
   yymsp[-2].minor.yy409 = yylhsminor.yy409;
         break;
       case 43: /* priv_level ::= topic_name */
+#line 121 "sql.y"
 { yylhsminor.yy409.first = yymsp[0].minor.yy649; yylhsminor.yy409.second = nil_token; }
+#line 4688 "sql.c"
   yymsp[0].minor.yy409 = yylhsminor.yy409;
         break;
       case 44: /* with_opt ::= */
@@ -4618,40 +4703,62 @@ static YYACTIONTYPE yy_reduce(
       case 554: /* every_opt ::= */ yytestcase(yyruleno==554);
       case 567: /* slimit_clause_opt ::= */ yytestcase(yyruleno==567);
       case 571: /* limit_clause_opt ::= */ yytestcase(yyruleno==571);
+#line 123 "sql.y"
 { yymsp[1].minor.yy184 = NULL; }
+#line 4709 "sql.c"
         break;
       case 45: /* with_opt ::= WITH search_condition */
       case 491: /* from_clause_opt ::= FROM table_reference_list */ yytestcase(yyruleno==491);
       case 520: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==520);
       case 551: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==551);
+#line 124 "sql.y"
 { yymsp[-1].minor.yy184 = yymsp[0].minor.yy184; }
+#line 4717 "sql.c"
         break;
       case 46: /* cmd ::= CREATE DNODE dnode_endpoint */
+#line 127 "sql.y"
 { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy649, NULL); }
+#line 4722 "sql.c"
         break;
       case 47: /* cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */
+#line 128 "sql.y"
 { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy649, &yymsp[0].minor.yy0); }
+#line 4727 "sql.c"
         break;
       case 48: /* cmd ::= DROP DNODE NK_INTEGER force_opt */
+#line 129 "sql.y"
 { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy829); }
+#line 4732 "sql.c"
         break;
       case 49: /* cmd ::= DROP DNODE dnode_endpoint force_opt */
+#line 130 "sql.y"
 { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[-1].minor.yy649, yymsp[0].minor.yy829); }
+#line 4737 "sql.c"
         break;
       case 50: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */
+#line 131 "sql.y"
 { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); }
+#line 4742 "sql.c"
         break;
       case 51: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */
+#line 132 "sql.y"
 { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-2].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); }
+#line 4747 "sql.c"
         break;
       case 52: /* cmd ::= ALTER ALL DNODES NK_STRING */
+#line 133 "sql.y"
 { pCxt->pRootNode = createAlterDnodeStmt(pCxt, NULL, &yymsp[0].minor.yy0, NULL); }
+#line 4752 "sql.c"
         break;
       case 53: /* cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */
+#line 134 "sql.y"
 { pCxt->pRootNode = createAlterDnodeStmt(pCxt, NULL, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); }
+#line 4757 "sql.c"
         break;
       case 54: /* cmd ::= RESTORE DNODE NK_INTEGER */
+#line 135 "sql.y"
 { pCxt->pRootNode = createRestoreComponentNodeStmt(pCxt, QUERY_NODE_RESTORE_DNODE_STMT, &yymsp[0].minor.yy0); }
+#line 4762 "sql.c"
         break;
       case 55: /* dnode_endpoint ::= NK_STRING */
       case 56: /* dnode_endpoint ::= NK_ID */ yytestcase(yyruleno==56);
@@ -4684,7 +4791,9 @@ static YYACTIONTYPE yy_reduce(
       case 446: /* star_func ::= FIRST */ yytestcase(yyruleno==446);
       case 447: /* star_func ::= LAST */ yytestcase(yyruleno==447);
       case 448: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==448);
+#line 139 "sql.y"
 { yylhsminor.yy649 = yymsp[0].minor.yy0; }
+#line 4797 "sql.c"
   yymsp[0].minor.yy649 = yylhsminor.yy649;
         break;
       case 58: /* force_opt ::= */
@@ -4694,280 +4803,426 @@ static YYACTIONTYPE yy_reduce(
       case 320: /* agg_func_opt ::= */ yytestcase(yyruleno==320);
       case 326: /* or_replace_opt ::= */ yytestcase(yyruleno==326);
       case 509: /* set_quantifier_opt ::= */ yytestcase(yyruleno==509);
+#line 145 "sql.y"
 { yymsp[1].minor.yy829 = false; }
+#line 4809 "sql.c"
         break;
       case 59: /* force_opt ::= FORCE */
       case 314: /* analyze_opt ::= ANALYZE */ yytestcase(yyruleno==314);
       case 321: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==321);
       case 510: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==510);
+#line 146 "sql.y"
 { yymsp[0].minor.yy829 = true; }
+#line 4817 "sql.c"
         break;
       case 60: /* cmd ::= ALTER LOCAL NK_STRING */
+#line 149 "sql.y"
 { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); }
+#line 4822 "sql.c"
         break;
       case 61: /* cmd ::= ALTER LOCAL NK_STRING NK_STRING */
+#line 150 "sql.y"
 { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); }
+#line 4827 "sql.c"
         break;
       case 62: /* cmd ::= CREATE QNODE ON DNODE NK_INTEGER */
+#line 153 "sql.y"
 { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_QNODE_STMT, &yymsp[0].minor.yy0); }
+#line 4832 "sql.c"
         break;
       case 63: /* cmd ::= DROP QNODE ON DNODE NK_INTEGER */
+#line 154 "sql.y"
 { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_QNODE_STMT, &yymsp[0].minor.yy0); }
+#line 4837 "sql.c"
         break;
       case 64: /* cmd ::= RESTORE QNODE ON DNODE NK_INTEGER */
+#line 155 "sql.y"
 { pCxt->pRootNode = createRestoreComponentNodeStmt(pCxt, QUERY_NODE_RESTORE_QNODE_STMT, &yymsp[0].minor.yy0); }
+#line 4842 "sql.c"
         break;
       case 65: /* cmd ::= CREATE BNODE ON DNODE NK_INTEGER */
+#line 158 "sql.y"
 { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_BNODE_STMT, &yymsp[0].minor.yy0); }
+#line 4847 "sql.c"
         break;
       case 66: /* cmd ::= DROP BNODE ON DNODE NK_INTEGER */
+#line 159 "sql.y"
 { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_BNODE_STMT, &yymsp[0].minor.yy0); }
+#line 4852 "sql.c"
         break;
       case 67: /* cmd ::= CREATE SNODE ON DNODE NK_INTEGER */
+#line 162 "sql.y"
 { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_SNODE_STMT, &yymsp[0].minor.yy0); }
+#line 4857 "sql.c"
         break;
       case 68: /* cmd ::= DROP SNODE ON DNODE NK_INTEGER */
+#line 163 "sql.y"
 { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_SNODE_STMT, &yymsp[0].minor.yy0); }
+#line 4862 "sql.c"
         break;
       case 69: /* cmd ::= CREATE MNODE ON DNODE NK_INTEGER */
+#line 166 "sql.y"
 { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_MNODE_STMT, &yymsp[0].minor.yy0); }
+#line 4867 "sql.c"
         break;
       case 70: /* cmd ::= DROP MNODE ON DNODE NK_INTEGER */
+#line 167 "sql.y"
 { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_MNODE_STMT, &yymsp[0].minor.yy0); }
+#line 4872 "sql.c"
         break;
       case 71: /* cmd ::= RESTORE MNODE ON DNODE NK_INTEGER */
+#line 168 "sql.y"
 { pCxt->pRootNode = createRestoreComponentNodeStmt(pCxt, QUERY_NODE_RESTORE_MNODE_STMT, &yymsp[0].minor.yy0); }
+#line 4877 "sql.c"
         break;
       case 72: /* cmd ::= RESTORE VNODE ON DNODE NK_INTEGER */
+#line 171 "sql.y"
 { pCxt->pRootNode = createRestoreComponentNodeStmt(pCxt, QUERY_NODE_RESTORE_VNODE_STMT, &yymsp[0].minor.yy0); }
+#line 4882 "sql.c"
         break;
       case 73: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */
+#line 174 "sql.y"
 { pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy829, &yymsp[-1].minor.yy649, yymsp[0].minor.yy184); }
+#line 4887 "sql.c"
         break;
       case 74: /* cmd ::= DROP DATABASE exists_opt db_name */
+#line 175 "sql.y"
 { pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy829, &yymsp[0].minor.yy649); }
+#line 4892 "sql.c"
         break;
       case 75: /* cmd ::= USE db_name */
+#line 176 "sql.y"
 { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy649); }
+#line 4897 "sql.c"
         break;
       case 76: /* cmd ::= ALTER DATABASE db_name alter_db_options */
+#line 177 "sql.y"
 { pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy649, yymsp[0].minor.yy184); }
+#line 4902 "sql.c"
         break;
       case 77: /* cmd ::= FLUSH DATABASE db_name */
+#line 178 "sql.y"
 { pCxt->pRootNode = createFlushDatabaseStmt(pCxt, &yymsp[0].minor.yy649); }
+#line 4907 "sql.c"
         break;
       case 78: /* cmd ::= TRIM DATABASE db_name speed_opt */
+#line 179 "sql.y"
 { pCxt->pRootNode = createTrimDatabaseStmt(pCxt, &yymsp[-1].minor.yy649, yymsp[0].minor.yy480); }
+#line 4912 "sql.c"
         break;
       case 79: /* cmd ::= COMPACT DATABASE db_name start_opt end_opt */
+#line 180 "sql.y"
 { pCxt->pRootNode = createCompactStmt(pCxt, &yymsp[-2].minor.yy649, yymsp[-1].minor.yy184, yymsp[0].minor.yy184); }
+#line 4917 "sql.c"
         break;
       case 80: /* not_exists_opt ::= IF NOT EXISTS */
+#line 184 "sql.y"
 { yymsp[-2].minor.yy829 = true; }
+#line 4922 "sql.c"
         break;
       case 82: /* exists_opt ::= IF EXISTS */
       case 327: /* or_replace_opt ::= OR REPLACE */ yytestcase(yyruleno==327);
+#line 189 "sql.y"
 { yymsp[-1].minor.yy829 = true; }
+#line 4928 "sql.c"
         break;
       case 84: /* db_options ::= */
+#line 192 "sql.y"
 { yymsp[1].minor.yy184 = createDefaultDatabaseOptions(pCxt); }
+#line 4933 "sql.c"
         break;
       case 85: /* db_options ::= db_options BUFFER NK_INTEGER */
+#line 193 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_BUFFER, &yymsp[0].minor.yy0); }
+#line 4938 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 86: /* db_options ::= db_options CACHEMODEL NK_STRING */
+#line 194 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_CACHEMODEL, &yymsp[0].minor.yy0); }
+#line 4944 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 87: /* db_options ::= db_options CACHESIZE NK_INTEGER */
+#line 195 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_CACHESIZE, &yymsp[0].minor.yy0); }
+#line 4950 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 88: /* db_options ::= db_options COMP NK_INTEGER */
+#line 196 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_COMP, &yymsp[0].minor.yy0); }
+#line 4956 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 89: /* db_options ::= db_options DURATION NK_INTEGER */
       case 90: /* db_options ::= db_options DURATION NK_VARIABLE */ yytestcase(yyruleno==90);
+#line 197 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_DAYS, &yymsp[0].minor.yy0); }
+#line 4963 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 91: /* db_options ::= db_options MAXROWS NK_INTEGER */
+#line 199 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); }
+#line 4969 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 92: /* db_options ::= db_options MINROWS NK_INTEGER */
+#line 200 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); }
+#line 4975 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 93: /* db_options ::= db_options KEEP integer_list */
       case 94: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==94);
+#line 201 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_KEEP, yymsp[0].minor.yy532); }
+#line 4982 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 95: /* db_options ::= db_options PAGES NK_INTEGER */
+#line 203 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_PAGES, &yymsp[0].minor.yy0); }
+#line 4988 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 96: /* db_options ::= db_options PAGESIZE NK_INTEGER */
+#line 204 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_PAGESIZE, &yymsp[0].minor.yy0); }
+#line 4994 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 97: /* db_options ::= db_options TSDB_PAGESIZE NK_INTEGER */
+#line 205 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_TSDB_PAGESIZE, &yymsp[0].minor.yy0); }
+#line 5000 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 98: /* db_options ::= db_options PRECISION NK_STRING */
+#line 206 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); }
+#line 5006 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 99: /* db_options ::= db_options REPLICA NK_INTEGER */
+#line 207 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); }
+#line 5012 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 100: /* db_options ::= db_options VGROUPS NK_INTEGER */
+#line 209 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); }
+#line 5018 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 101: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */
+#line 210 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); }
+#line 5024 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 102: /* db_options ::= db_options RETENTIONS retention_list */
+#line 211 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_RETENTIONS, yymsp[0].minor.yy532); }
+#line 5030 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 103: /* db_options ::= db_options SCHEMALESS NK_INTEGER */
+#line 212 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_SCHEMALESS, &yymsp[0].minor.yy0); }
+#line 5036 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 104: /* db_options ::= db_options WAL_LEVEL NK_INTEGER */
+#line 213 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_WAL, &yymsp[0].minor.yy0); }
+#line 5042 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 105: /* db_options ::= db_options WAL_FSYNC_PERIOD NK_INTEGER */
+#line 214 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); }
+#line 5048 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 106: /* db_options ::= db_options WAL_RETENTION_PERIOD NK_INTEGER */
+#line 215 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_WAL_RETENTION_PERIOD, &yymsp[0].minor.yy0); }
+#line 5054 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 107: /* db_options ::= db_options WAL_RETENTION_PERIOD NK_MINUS NK_INTEGER */
+#line 216 "sql.y"
 { 
                                                                                     SToken t = yymsp[-1].minor.yy0;
                                                                                     t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z;
                                                                                     yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-3].minor.yy184, DB_OPTION_WAL_RETENTION_PERIOD, &t);
                                                                                   }
+#line 5064 "sql.c"
   yymsp[-3].minor.yy184 = yylhsminor.yy184;
         break;
       case 108: /* db_options ::= db_options WAL_RETENTION_SIZE NK_INTEGER */
+#line 221 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_WAL_RETENTION_SIZE, &yymsp[0].minor.yy0); }
+#line 5070 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 109: /* db_options ::= db_options WAL_RETENTION_SIZE NK_MINUS NK_INTEGER */
+#line 222 "sql.y"
 { 
                                                                                     SToken t = yymsp[-1].minor.yy0;
                                                                                     t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z;
                                                                                     yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-3].minor.yy184, DB_OPTION_WAL_RETENTION_SIZE, &t);
                                                                                   }
+#line 5080 "sql.c"
   yymsp[-3].minor.yy184 = yylhsminor.yy184;
         break;
       case 110: /* db_options ::= db_options WAL_ROLL_PERIOD NK_INTEGER */
+#line 227 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_WAL_ROLL_PERIOD, &yymsp[0].minor.yy0); }
+#line 5086 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 111: /* db_options ::= db_options WAL_SEGMENT_SIZE NK_INTEGER */
+#line 228 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_WAL_SEGMENT_SIZE, &yymsp[0].minor.yy0); }
+#line 5092 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 112: /* db_options ::= db_options STT_TRIGGER NK_INTEGER */
+#line 229 "sql.y"
 { yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_STT_TRIGGER, &yymsp[0].minor.yy0); }
+#line 5098 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
-      case 113: /* db_options ::= db_options TABLE_PREFIX NK_INTEGER */
-{ yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_TABLE_PREFIX, &yymsp[0].minor.yy0); }
+      case 113: /* db_options ::= db_options TABLE_PREFIX signed */
+#line 230 "sql.y"
+{ yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_TABLE_PREFIX, yymsp[0].minor.yy184); }
+#line 5104 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
-      case 114: /* db_options ::= db_options TABLE_SUFFIX NK_INTEGER */
-{ yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_TABLE_SUFFIX, &yymsp[0].minor.yy0); }
+      case 114: /* db_options ::= db_options TABLE_SUFFIX signed */
+#line 231 "sql.y"
+{ yylhsminor.yy184 = setDatabaseOption(pCxt, yymsp[-2].minor.yy184, DB_OPTION_TABLE_SUFFIX, yymsp[0].minor.yy184); }
+#line 5110 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 115: /* alter_db_options ::= alter_db_option */
+#line 233 "sql.y"
 { yylhsminor.yy184 = createAlterDatabaseOptions(pCxt); yylhsminor.yy184 = setAlterDatabaseOption(pCxt, yylhsminor.yy184, &yymsp[0].minor.yy361); }
+#line 5116 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 116: /* alter_db_options ::= alter_db_options alter_db_option */
+#line 234 "sql.y"
 { yylhsminor.yy184 = setAlterDatabaseOption(pCxt, yymsp[-1].minor.yy184, &yymsp[0].minor.yy361); }
+#line 5122 "sql.c"
   yymsp[-1].minor.yy184 = yylhsminor.yy184;
         break;
       case 117: /* alter_db_option ::= BUFFER NK_INTEGER */
+#line 238 "sql.y"
 { yymsp[-1].minor.yy361.type = DB_OPTION_BUFFER; yymsp[-1].minor.yy361.val = yymsp[0].minor.yy0; }
+#line 5128 "sql.c"
         break;
       case 118: /* alter_db_option ::= CACHEMODEL NK_STRING */
+#line 239 "sql.y"
 { yymsp[-1].minor.yy361.type = DB_OPTION_CACHEMODEL; yymsp[-1].minor.yy361.val = yymsp[0].minor.yy0; }
+#line 5133 "sql.c"
         break;
       case 119: /* alter_db_option ::= CACHESIZE NK_INTEGER */
+#line 240 "sql.y"
 { yymsp[-1].minor.yy361.type = DB_OPTION_CACHESIZE; yymsp[-1].minor.yy361.val = yymsp[0].minor.yy0; }
+#line 5138 "sql.c"
         break;
       case 120: /* alter_db_option ::= WAL_FSYNC_PERIOD NK_INTEGER */
+#line 241 "sql.y"
 { yymsp[-1].minor.yy361.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy361.val = yymsp[0].minor.yy0; }
+#line 5143 "sql.c"
         break;
       case 121: /* alter_db_option ::= KEEP integer_list */
       case 122: /* alter_db_option ::= KEEP variable_list */ yytestcase(yyruleno==122);
+#line 242 "sql.y"
 { yymsp[-1].minor.yy361.type = DB_OPTION_KEEP; yymsp[-1].minor.yy361.pList = yymsp[0].minor.yy532; }
+#line 5149 "sql.c"
         break;
       case 123: /* alter_db_option ::= PAGES NK_INTEGER */
+#line 244 "sql.y"
 { yymsp[-1].minor.yy361.type = DB_OPTION_PAGES; yymsp[-1].minor.yy361.val = yymsp[0].minor.yy0; }
+#line 5154 "sql.c"
         break;
       case 124: /* alter_db_option ::= REPLICA NK_INTEGER */
+#line 245 "sql.y"
 { yymsp[-1].minor.yy361.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy361.val = yymsp[0].minor.yy0; }
+#line 5159 "sql.c"
         break;
       case 125: /* alter_db_option ::= WAL_LEVEL NK_INTEGER */
+#line 247 "sql.y"
 { yymsp[-1].minor.yy361.type = DB_OPTION_WAL; yymsp[-1].minor.yy361.val = yymsp[0].minor.yy0; }
+#line 5164 "sql.c"
         break;
       case 126: /* alter_db_option ::= STT_TRIGGER NK_INTEGER */
+#line 248 "sql.y"
 { yymsp[-1].minor.yy361.type = DB_OPTION_STT_TRIGGER; yymsp[-1].minor.yy361.val = yymsp[0].minor.yy0; }
+#line 5169 "sql.c"
         break;
       case 127: /* alter_db_option ::= MINROWS NK_INTEGER */
+#line 249 "sql.y"
 { yymsp[-1].minor.yy361.type = DB_OPTION_MINROWS; yymsp[-1].minor.yy361.val = yymsp[0].minor.yy0; }
+#line 5174 "sql.c"
         break;
       case 128: /* alter_db_option ::= WAL_RETENTION_PERIOD NK_INTEGER */
+#line 250 "sql.y"
 { yymsp[-1].minor.yy361.type = DB_OPTION_WAL_RETENTION_PERIOD; yymsp[-1].minor.yy361.val = yymsp[0].minor.yy0; }
+#line 5179 "sql.c"
         break;
       case 129: /* alter_db_option ::= WAL_RETENTION_PERIOD NK_MINUS NK_INTEGER */
+#line 251 "sql.y"
 { 
                                                                                     SToken t = yymsp[-1].minor.yy0;
                                                                                     t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z;
                                                                                     yymsp[-2].minor.yy361.type = DB_OPTION_WAL_RETENTION_PERIOD; yymsp[-2].minor.yy361.val = t;
                                                                                   }
+#line 5188 "sql.c"
         break;
       case 130: /* alter_db_option ::= WAL_RETENTION_SIZE NK_INTEGER */
+#line 256 "sql.y"
 { yymsp[-1].minor.yy361.type = DB_OPTION_WAL_RETENTION_SIZE; yymsp[-1].minor.yy361.val = yymsp[0].minor.yy0; }
+#line 5193 "sql.c"
         break;
       case 131: /* alter_db_option ::= WAL_RETENTION_SIZE NK_MINUS NK_INTEGER */
+#line 257 "sql.y"
 { 
                                                                                     SToken t = yymsp[-1].minor.yy0;
                                                                                     t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z;
                                                                                     yymsp[-2].minor.yy361.type = DB_OPTION_WAL_RETENTION_SIZE; yymsp[-2].minor.yy361.val = t;
                                                                                   }
+#line 5202 "sql.c"
         break;
       case 132: /* integer_list ::= NK_INTEGER */
+#line 265 "sql.y"
 { yylhsminor.yy532 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); }
+#line 5207 "sql.c"
   yymsp[0].minor.yy532 = yylhsminor.yy532;
         break;
       case 133: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */
       case 355: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==355);
+#line 266 "sql.y"
 { yylhsminor.yy532 = addNodeToList(pCxt, yymsp[-2].minor.yy532, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); }
+#line 5214 "sql.c"
   yymsp[-2].minor.yy532 = yylhsminor.yy532;
         break;
       case 134: /* variable_list ::= NK_VARIABLE */
+#line 270 "sql.y"
 { yylhsminor.yy532 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); }
+#line 5220 "sql.c"
   yymsp[0].minor.yy532 = yylhsminor.yy532;
         break;
       case 135: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */
+#line 271 "sql.y"
 { yylhsminor.yy532 = addNodeToList(pCxt, yymsp[-2].minor.yy532, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); }
+#line 5226 "sql.c"
   yymsp[-2].minor.yy532 = yylhsminor.yy532;
         break;
       case 136: /* retention_list ::= retention */
@@ -4984,7 +5239,9 @@ static YYACTIONTYPE yy_reduce(
       case 512: /* select_list ::= select_item */ yytestcase(yyruleno==512);
       case 523: /* partition_list ::= partition_item */ yytestcase(yyruleno==523);
       case 578: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==578);
+#line 275 "sql.y"
 { yylhsminor.yy532 = createNodeList(pCxt, yymsp[0].minor.yy184); }
+#line 5245 "sql.c"
   yymsp[0].minor.yy532 = yylhsminor.yy532;
         break;
       case 137: /* retention_list ::= retention_list NK_COMMA retention */
@@ -4999,105 +5256,157 @@ static YYACTIONTYPE yy_reduce(
       case 513: /* select_list ::= select_list NK_COMMA select_item */ yytestcase(yyruleno==513);
       case 524: /* partition_list ::= partition_list NK_COMMA partition_item */ yytestcase(yyruleno==524);
       case 579: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==579);
+#line 276 "sql.y"
 { yylhsminor.yy532 = addNodeToList(pCxt, yymsp[-2].minor.yy532, yymsp[0].minor.yy184); }
+#line 5262 "sql.c"
   yymsp[-2].minor.yy532 = yylhsminor.yy532;
         break;
       case 138: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */
+#line 278 "sql.y"
 { yylhsminor.yy184 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); }
+#line 5268 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 139: /* speed_opt ::= */
       case 322: /* bufsize_opt ::= */ yytestcase(yyruleno==322);
+#line 282 "sql.y"
 { yymsp[1].minor.yy480 = 0; }
+#line 5275 "sql.c"
         break;
       case 140: /* speed_opt ::= MAX_SPEED NK_INTEGER */
       case 323: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ yytestcase(yyruleno==323);
+#line 283 "sql.y"
 { yymsp[-1].minor.yy480 = taosStr2Int32(yymsp[0].minor.yy0.z, NULL, 10); }
+#line 5281 "sql.c"
         break;
       case 142: /* start_opt ::= START WITH NK_INTEGER */
       case 146: /* end_opt ::= END WITH NK_INTEGER */ yytestcase(yyruleno==146);
+#line 286 "sql.y"
 { yymsp[-2].minor.yy184 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); }
+#line 5287 "sql.c"
         break;
       case 143: /* start_opt ::= START WITH NK_STRING */
       case 147: /* end_opt ::= END WITH NK_STRING */ yytestcase(yyruleno==147);
+#line 287 "sql.y"
 { yymsp[-2].minor.yy184 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); }
+#line 5293 "sql.c"
         break;
       case 144: /* start_opt ::= START WITH TIMESTAMP NK_STRING */
       case 148: /* end_opt ::= END WITH TIMESTAMP NK_STRING */ yytestcase(yyruleno==148);
+#line 288 "sql.y"
 { yymsp[-3].minor.yy184 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); }
+#line 5299 "sql.c"
         break;
       case 149: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */
       case 151: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==151);
+#line 297 "sql.y"
 { pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy829, yymsp[-5].minor.yy184, yymsp[-3].minor.yy532, yymsp[-1].minor.yy532, yymsp[0].minor.yy184); }
+#line 5305 "sql.c"
         break;
       case 150: /* cmd ::= CREATE TABLE multi_create_clause */
+#line 298 "sql.y"
 { pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy532); }
+#line 5310 "sql.c"
         break;
       case 152: /* cmd ::= DROP TABLE multi_drop_clause */
+#line 301 "sql.y"
 { pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy532); }
+#line 5315 "sql.c"
         break;
       case 153: /* cmd ::= DROP STABLE exists_opt full_table_name */
+#line 302 "sql.y"
 { pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy829, yymsp[0].minor.yy184); }
+#line 5320 "sql.c"
         break;
       case 154: /* cmd ::= ALTER TABLE alter_table_clause */
       case 357: /* cmd ::= query_or_subquery */ yytestcase(yyruleno==357);
       case 358: /* cmd ::= insert_query */ yytestcase(yyruleno==358);
+#line 304 "sql.y"
 { pCxt->pRootNode = yymsp[0].minor.yy184; }
+#line 5327 "sql.c"
         break;
       case 155: /* cmd ::= ALTER STABLE alter_table_clause */
+#line 305 "sql.y"
 { pCxt->pRootNode = setAlterSuperTableType(yymsp[0].minor.yy184); }
+#line 5332 "sql.c"
         break;
       case 156: /* alter_table_clause ::= full_table_name alter_table_options */
+#line 307 "sql.y"
 { yylhsminor.yy184 = createAlterTableModifyOptions(pCxt, yymsp[-1].minor.yy184, yymsp[0].minor.yy184); }
+#line 5337 "sql.c"
   yymsp[-1].minor.yy184 = yylhsminor.yy184;
         break;
       case 157: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */
+#line 309 "sql.y"
 { yylhsminor.yy184 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy184, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy649, yymsp[0].minor.yy388); }
+#line 5343 "sql.c"
   yymsp[-4].minor.yy184 = yylhsminor.yy184;
         break;
       case 158: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */
+#line 310 "sql.y"
 { yylhsminor.yy184 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy184, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy649); }
+#line 5349 "sql.c"
   yymsp[-3].minor.yy184 = yylhsminor.yy184;
         break;
       case 159: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */
+#line 312 "sql.y"
 { yylhsminor.yy184 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy184, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy649, yymsp[0].minor.yy388); }
+#line 5355 "sql.c"
   yymsp[-4].minor.yy184 = yylhsminor.yy184;
         break;
       case 160: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */
+#line 314 "sql.y"
 { yylhsminor.yy184 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy184, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy649, &yymsp[0].minor.yy649); }
+#line 5361 "sql.c"
   yymsp[-4].minor.yy184 = yylhsminor.yy184;
         break;
       case 161: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */
+#line 316 "sql.y"
 { yylhsminor.yy184 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy184, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy649, yymsp[0].minor.yy388); }
+#line 5367 "sql.c"
   yymsp[-4].minor.yy184 = yylhsminor.yy184;
         break;
       case 162: /* alter_table_clause ::= full_table_name DROP TAG column_name */
+#line 317 "sql.y"
 { yylhsminor.yy184 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy184, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy649); }
+#line 5373 "sql.c"
   yymsp[-3].minor.yy184 = yylhsminor.yy184;
         break;
       case 163: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */
+#line 319 "sql.y"
 { yylhsminor.yy184 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy184, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy649, yymsp[0].minor.yy388); }
+#line 5379 "sql.c"
   yymsp[-4].minor.yy184 = yylhsminor.yy184;
         break;
       case 164: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */
+#line 321 "sql.y"
 { yylhsminor.yy184 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy184, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy649, &yymsp[0].minor.yy649); }
+#line 5385 "sql.c"
   yymsp[-4].minor.yy184 = yylhsminor.yy184;
         break;
       case 165: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */
+#line 323 "sql.y"
 { yylhsminor.yy184 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy184, &yymsp[-2].minor.yy649, yymsp[0].minor.yy184); }
+#line 5391 "sql.c"
   yymsp[-5].minor.yy184 = yylhsminor.yy184;
         break;
       case 167: /* multi_create_clause ::= multi_create_clause create_subtable_clause */
       case 458: /* when_then_list ::= when_then_list when_then_expr */ yytestcase(yyruleno==458);
+#line 328 "sql.y"
 { yylhsminor.yy532 = addNodeToList(pCxt, yymsp[-1].minor.yy532, yymsp[0].minor.yy184); }
+#line 5398 "sql.c"
   yymsp[-1].minor.yy532 = yylhsminor.yy532;
         break;
       case 168: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */
+#line 332 "sql.y"
 { yylhsminor.yy184 = createCreateSubTableClause(pCxt, yymsp[-9].minor.yy829, yymsp[-8].minor.yy184, yymsp[-6].minor.yy184, yymsp[-5].minor.yy532, yymsp[-2].minor.yy532, yymsp[0].minor.yy184); }
+#line 5404 "sql.c"
   yymsp[-9].minor.yy184 = yylhsminor.yy184;
         break;
       case 171: /* drop_table_clause ::= exists_opt full_table_name */
+#line 339 "sql.y"
 { yylhsminor.yy184 = createDropTableClause(pCxt, yymsp[-1].minor.yy829, yymsp[0].minor.yy184); }
+#line 5410 "sql.c"
   yymsp[-1].minor.yy184 = yylhsminor.yy184;
         break;
       case 172: /* specific_cols_opt ::= */
@@ -5108,514 +5417,812 @@ static YYACTIONTYPE yy_reduce(
       case 521: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==521);
       case 546: /* group_by_clause_opt ::= */ yytestcase(yyruleno==546);
       case 565: /* order_by_clause_opt ::= */ yytestcase(yyruleno==565);
+#line 343 "sql.y"
 { yymsp[1].minor.yy532 = NULL; }
+#line 5423 "sql.c"
         break;
       case 173: /* specific_cols_opt ::= NK_LP col_name_list NK_RP */
       case 331: /* col_list_opt ::= NK_LP col_name_list NK_RP */ yytestcase(yyruleno==331);
+#line 344 "sql.y"
 { yymsp[-2].minor.yy532 = yymsp[-1].minor.yy532; }
+#line 5429 "sql.c"
         break;
       case 174: /* full_table_name ::= table_name */
+#line 346 "sql.y"
 { yylhsminor.yy184 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy649, NULL); }
+#line 5434 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 175: /* full_table_name ::= db_name NK_DOT table_name */
+#line 347 "sql.y"
 { yylhsminor.yy184 = createRealTableNode(pCxt, &yymsp[-2].minor.yy649, &yymsp[0].minor.yy649, NULL); }
+#line 5440 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 178: /* column_def ::= column_name type_name */
+#line 354 "sql.y"
 { yylhsminor.yy184 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy649, yymsp[0].minor.yy388, NULL); }
+#line 5446 "sql.c"
   yymsp[-1].minor.yy184 = yylhsminor.yy184;
         break;
       case 179: /* type_name ::= BOOL */
+#line 359 "sql.y"
 { yymsp[0].minor.yy388 = createDataType(TSDB_DATA_TYPE_BOOL); }
+#line 5452 "sql.c"
         break;
       case 180: /* type_name ::= TINYINT */
+#line 360 "sql.y"
 { yymsp[0].minor.yy388 = createDataType(TSDB_DATA_TYPE_TINYINT); }
+#line 5457 "sql.c"
         break;
       case 181: /* type_name ::= SMALLINT */
+#line 361 "sql.y"
 { yymsp[0].minor.yy388 = createDataType(TSDB_DATA_TYPE_SMALLINT); }
+#line 5462 "sql.c"
         break;
       case 182: /* type_name ::= INT */
       case 183: /* type_name ::= INTEGER */ yytestcase(yyruleno==183);
+#line 362 "sql.y"
 { yymsp[0].minor.yy388 = createDataType(TSDB_DATA_TYPE_INT); }
+#line 5468 "sql.c"
         break;
       case 184: /* type_name ::= BIGINT */
+#line 364 "sql.y"
 { yymsp[0].minor.yy388 = createDataType(TSDB_DATA_TYPE_BIGINT); }
+#line 5473 "sql.c"
         break;
       case 185: /* type_name ::= FLOAT */
+#line 365 "sql.y"
 { yymsp[0].minor.yy388 = createDataType(TSDB_DATA_TYPE_FLOAT); }
+#line 5478 "sql.c"
         break;
       case 186: /* type_name ::= DOUBLE */
+#line 366 "sql.y"
 { yymsp[0].minor.yy388 = createDataType(TSDB_DATA_TYPE_DOUBLE); }
+#line 5483 "sql.c"
         break;
       case 187: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */
+#line 367 "sql.y"
 { yymsp[-3].minor.yy388 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); }
+#line 5488 "sql.c"
         break;
       case 188: /* type_name ::= TIMESTAMP */
+#line 368 "sql.y"
 { yymsp[0].minor.yy388 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); }
+#line 5493 "sql.c"
         break;
       case 189: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */
+#line 369 "sql.y"
 { yymsp[-3].minor.yy388 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); }
+#line 5498 "sql.c"
         break;
       case 190: /* type_name ::= TINYINT UNSIGNED */
+#line 370 "sql.y"
 { yymsp[-1].minor.yy388 = createDataType(TSDB_DATA_TYPE_UTINYINT); }
+#line 5503 "sql.c"
         break;
       case 191: /* type_name ::= SMALLINT UNSIGNED */
+#line 371 "sql.y"
 { yymsp[-1].minor.yy388 = createDataType(TSDB_DATA_TYPE_USMALLINT); }
+#line 5508 "sql.c"
         break;
       case 192: /* type_name ::= INT UNSIGNED */
+#line 372 "sql.y"
 { yymsp[-1].minor.yy388 = createDataType(TSDB_DATA_TYPE_UINT); }
+#line 5513 "sql.c"
         break;
       case 193: /* type_name ::= BIGINT UNSIGNED */
+#line 373 "sql.y"
 { yymsp[-1].minor.yy388 = createDataType(TSDB_DATA_TYPE_UBIGINT); }
+#line 5518 "sql.c"
         break;
       case 194: /* type_name ::= JSON */
+#line 374 "sql.y"
 { yymsp[0].minor.yy388 = createDataType(TSDB_DATA_TYPE_JSON); }
+#line 5523 "sql.c"
         break;
       case 195: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */
+#line 375 "sql.y"
 { yymsp[-3].minor.yy388 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); }
+#line 5528 "sql.c"
         break;
       case 196: /* type_name ::= MEDIUMBLOB */
+#line 376 "sql.y"
 { yymsp[0].minor.yy388 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); }
+#line 5533 "sql.c"
         break;
       case 197: /* type_name ::= BLOB */
+#line 377 "sql.y"
 { yymsp[0].minor.yy388 = createDataType(TSDB_DATA_TYPE_BLOB); }
+#line 5538 "sql.c"
         break;
       case 198: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */
+#line 378 "sql.y"
 { yymsp[-3].minor.yy388 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); }
+#line 5543 "sql.c"
         break;
       case 199: /* type_name ::= DECIMAL */
+#line 379 "sql.y"
 { yymsp[0].minor.yy388 = createDataType(TSDB_DATA_TYPE_DECIMAL); }
+#line 5548 "sql.c"
         break;
       case 200: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */
+#line 380 "sql.y"
 { yymsp[-3].minor.yy388 = createDataType(TSDB_DATA_TYPE_DECIMAL); }
+#line 5553 "sql.c"
         break;
       case 201: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */
+#line 381 "sql.y"
 { yymsp[-5].minor.yy388 = createDataType(TSDB_DATA_TYPE_DECIMAL); }
+#line 5558 "sql.c"
         break;
       case 203: /* tags_def_opt ::= tags_def */
       case 333: /* tag_def_or_ref_opt ::= tags_def */ yytestcase(yyruleno==333);
       case 450: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==450);
+#line 386 "sql.y"
 { yylhsminor.yy532 = yymsp[0].minor.yy532; }
+#line 5565 "sql.c"
   yymsp[0].minor.yy532 = yylhsminor.yy532;
         break;
       case 204: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */
       case 334: /* tag_def_or_ref_opt ::= TAGS NK_LP col_name_list NK_RP */ yytestcase(yyruleno==334);
+#line 390 "sql.y"
 { yymsp[-3].minor.yy532 = yymsp[-1].minor.yy532; }
+#line 5572 "sql.c"
         break;
       case 205: /* table_options ::= */
+#line 392 "sql.y"
 { yymsp[1].minor.yy184 = createDefaultTableOptions(pCxt); }
+#line 5577 "sql.c"
         break;
       case 206: /* table_options ::= table_options COMMENT NK_STRING */
+#line 393 "sql.y"
 { yylhsminor.yy184 = setTableOption(pCxt, yymsp[-2].minor.yy184, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); }
+#line 5582 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 207: /* table_options ::= table_options MAX_DELAY duration_list */
+#line 394 "sql.y"
 { yylhsminor.yy184 = setTableOption(pCxt, yymsp[-2].minor.yy184, TABLE_OPTION_MAXDELAY, yymsp[0].minor.yy532); }
+#line 5588 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 208: /* table_options ::= table_options WATERMARK duration_list */
+#line 395 "sql.y"
 { yylhsminor.yy184 = setTableOption(pCxt, yymsp[-2].minor.yy184, TABLE_OPTION_WATERMARK, yymsp[0].minor.yy532); }
+#line 5594 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 209: /* table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */
+#line 396 "sql.y"
 { yylhsminor.yy184 = setTableOption(pCxt, yymsp[-4].minor.yy184, TABLE_OPTION_ROLLUP, yymsp[-1].minor.yy532); }
+#line 5600 "sql.c"
   yymsp[-4].minor.yy184 = yylhsminor.yy184;
         break;
       case 210: /* table_options ::= table_options TTL NK_INTEGER */
+#line 397 "sql.y"
 { yylhsminor.yy184 = setTableOption(pCxt, yymsp[-2].minor.yy184, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); }
+#line 5606 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 211: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */
+#line 398 "sql.y"
 { yylhsminor.yy184 = setTableOption(pCxt, yymsp[-4].minor.yy184, TABLE_OPTION_SMA, yymsp[-1].minor.yy532); }
+#line 5612 "sql.c"
   yymsp[-4].minor.yy184 = yylhsminor.yy184;
         break;
       case 212: /* table_options ::= table_options DELETE_MARK duration_list */
+#line 399 "sql.y"
 { yylhsminor.yy184 = setTableOption(pCxt, yymsp[-2].minor.yy184, TABLE_OPTION_DELETE_MARK, yymsp[0].minor.yy532); }
+#line 5618 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 213: /* alter_table_options ::= alter_table_option */
+#line 401 "sql.y"
 { yylhsminor.yy184 = createAlterTableOptions(pCxt); yylhsminor.yy184 = setTableOption(pCxt, yylhsminor.yy184, yymsp[0].minor.yy361.type, &yymsp[0].minor.yy361.val); }
+#line 5624 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 214: /* alter_table_options ::= alter_table_options alter_table_option */
+#line 402 "sql.y"
 { yylhsminor.yy184 = setTableOption(pCxt, yymsp[-1].minor.yy184, yymsp[0].minor.yy361.type, &yymsp[0].minor.yy361.val); }
+#line 5630 "sql.c"
   yymsp[-1].minor.yy184 = yylhsminor.yy184;
         break;
       case 215: /* alter_table_option ::= COMMENT NK_STRING */
+#line 406 "sql.y"
 { yymsp[-1].minor.yy361.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy361.val = yymsp[0].minor.yy0; }
+#line 5636 "sql.c"
         break;
       case 216: /* alter_table_option ::= TTL NK_INTEGER */
+#line 407 "sql.y"
 { yymsp[-1].minor.yy361.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy361.val = yymsp[0].minor.yy0; }
+#line 5641 "sql.c"
         break;
       case 217: /* duration_list ::= duration_literal */
       case 414: /* expression_list ::= expr_or_subquery */ yytestcase(yyruleno==414);
+#line 411 "sql.y"
 { yylhsminor.yy532 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy184)); }
+#line 5647 "sql.c"
   yymsp[0].minor.yy532 = yylhsminor.yy532;
         break;
       case 218: /* duration_list ::= duration_list NK_COMMA duration_literal */
       case 415: /* expression_list ::= expression_list NK_COMMA expr_or_subquery */ yytestcase(yyruleno==415);
+#line 412 "sql.y"
 { yylhsminor.yy532 = addNodeToList(pCxt, yymsp[-2].minor.yy532, releaseRawExprNode(pCxt, yymsp[0].minor.yy184)); }
+#line 5654 "sql.c"
   yymsp[-2].minor.yy532 = yylhsminor.yy532;
         break;
       case 221: /* rollup_func_name ::= function_name */
+#line 419 "sql.y"
 { yylhsminor.yy184 = createFunctionNode(pCxt, &yymsp[0].minor.yy649, NULL); }
+#line 5660 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 222: /* rollup_func_name ::= FIRST */
       case 223: /* rollup_func_name ::= LAST */ yytestcase(yyruleno==223);
       case 278: /* tag_item ::= QTAGS */ yytestcase(yyruleno==278);
+#line 420 "sql.y"
 { yylhsminor.yy184 = createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL); }
+#line 5668 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 226: /* col_name ::= column_name */
       case 279: /* tag_item ::= column_name */ yytestcase(yyruleno==279);
+#line 428 "sql.y"
 { yylhsminor.yy184 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy649); }
+#line 5675 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 227: /* cmd ::= SHOW DNODES */
+#line 431 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT); }
+#line 5681 "sql.c"
         break;
       case 228: /* cmd ::= SHOW USERS */
+#line 432 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT); }
+#line 5686 "sql.c"
         break;
       case 229: /* cmd ::= SHOW USER PRIVILEGES */
+#line 433 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USER_PRIVILEGES_STMT); }
+#line 5691 "sql.c"
         break;
       case 230: /* cmd ::= SHOW DATABASES */
+#line 434 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT); }
+#line 5696 "sql.c"
         break;
       case 231: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */
+#line 435 "sql.y"
 { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy184, yymsp[0].minor.yy184, OP_TYPE_LIKE); }
+#line 5701 "sql.c"
         break;
       case 232: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */
+#line 436 "sql.y"
 { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy184, yymsp[0].minor.yy184, OP_TYPE_LIKE); }
+#line 5706 "sql.c"
         break;
       case 233: /* cmd ::= SHOW db_name_cond_opt VGROUPS */
+#line 437 "sql.y"
 { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy184, NULL, OP_TYPE_LIKE); }
+#line 5711 "sql.c"
         break;
       case 234: /* cmd ::= SHOW MNODES */
+#line 438 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT); }
+#line 5716 "sql.c"
         break;
       case 235: /* cmd ::= SHOW QNODES */
+#line 440 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT); }
+#line 5721 "sql.c"
         break;
       case 236: /* cmd ::= SHOW FUNCTIONS */
+#line 441 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT); }
+#line 5726 "sql.c"
         break;
       case 237: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */
+#line 442 "sql.y"
 { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[0].minor.yy184, yymsp[-1].minor.yy184, OP_TYPE_EQUAL); }
+#line 5731 "sql.c"
         break;
       case 238: /* cmd ::= SHOW STREAMS */
+#line 443 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT); }
+#line 5736 "sql.c"
         break;
       case 239: /* cmd ::= SHOW ACCOUNTS */
+#line 444 "sql.y"
 { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
+#line 5741 "sql.c"
         break;
       case 240: /* cmd ::= SHOW APPS */
+#line 445 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT); }
+#line 5746 "sql.c"
         break;
       case 241: /* cmd ::= SHOW CONNECTIONS */
+#line 446 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT); }
+#line 5751 "sql.c"
         break;
       case 242: /* cmd ::= SHOW LICENCES */
       case 243: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==243);
+#line 447 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCES_STMT); }
+#line 5757 "sql.c"
         break;
       case 244: /* cmd ::= SHOW CREATE DATABASE db_name */
+#line 449 "sql.y"
 { pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy649); }
+#line 5762 "sql.c"
         break;
       case 245: /* cmd ::= SHOW CREATE TABLE full_table_name */
+#line 450 "sql.y"
 { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy184); }
+#line 5767 "sql.c"
         break;
       case 246: /* cmd ::= SHOW CREATE STABLE full_table_name */
+#line 451 "sql.y"
 { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy184); }
+#line 5772 "sql.c"
         break;
       case 247: /* cmd ::= SHOW QUERIES */
+#line 452 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT); }
+#line 5777 "sql.c"
         break;
       case 248: /* cmd ::= SHOW SCORES */
+#line 453 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT); }
+#line 5782 "sql.c"
         break;
       case 249: /* cmd ::= SHOW TOPICS */
+#line 454 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT); }
+#line 5787 "sql.c"
         break;
       case 250: /* cmd ::= SHOW VARIABLES */
       case 251: /* cmd ::= SHOW CLUSTER VARIABLES */ yytestcase(yyruleno==251);
+#line 455 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT); }
+#line 5793 "sql.c"
         break;
       case 252: /* cmd ::= SHOW LOCAL VARIABLES */
+#line 457 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT); }
+#line 5798 "sql.c"
         break;
       case 253: /* cmd ::= SHOW DNODE NK_INTEGER VARIABLES like_pattern_opt */
+#line 458 "sql.y"
 { pCxt->pRootNode = createShowDnodeVariablesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[-2].minor.yy0), yymsp[0].minor.yy184); }
+#line 5803 "sql.c"
         break;
       case 254: /* cmd ::= SHOW BNODES */
+#line 459 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT); }
+#line 5808 "sql.c"
         break;
       case 255: /* cmd ::= SHOW SNODES */
+#line 460 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); }
+#line 5813 "sql.c"
         break;
       case 256: /* cmd ::= SHOW CLUSTER */
+#line 461 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT); }
+#line 5818 "sql.c"
         break;
       case 257: /* cmd ::= SHOW TRANSACTIONS */
+#line 462 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT); }
+#line 5823 "sql.c"
         break;
       case 258: /* cmd ::= SHOW TABLE DISTRIBUTED full_table_name */
+#line 463 "sql.y"
 { pCxt->pRootNode = createShowTableDistributedStmt(pCxt, yymsp[0].minor.yy184); }
+#line 5828 "sql.c"
         break;
       case 259: /* cmd ::= SHOW CONSUMERS */
+#line 464 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONSUMERS_STMT); }
+#line 5833 "sql.c"
         break;
       case 260: /* cmd ::= SHOW SUBSCRIPTIONS */
+#line 465 "sql.y"
 { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT); }
+#line 5838 "sql.c"
         break;
       case 261: /* cmd ::= SHOW TAGS FROM table_name_cond from_db_opt */
+#line 466 "sql.y"
 { pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TAGS_STMT, yymsp[0].minor.yy184, yymsp[-1].minor.yy184, OP_TYPE_EQUAL); }
+#line 5843 "sql.c"
         break;
       case 262: /* cmd ::= SHOW TABLE TAGS tag_list_opt FROM table_name_cond from_db_opt */
+#line 467 "sql.y"
 { pCxt->pRootNode = createShowTableTagsStmt(pCxt, yymsp[-1].minor.yy184, yymsp[0].minor.yy184, yymsp[-3].minor.yy532); }
+#line 5848 "sql.c"
         break;
       case 263: /* cmd ::= SHOW VNODES NK_INTEGER */
+#line 468 "sql.y"
 { pCxt->pRootNode = createShowVnodesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0), NULL); }
+#line 5853 "sql.c"
         break;
       case 264: /* cmd ::= SHOW VNODES NK_STRING */
+#line 469 "sql.y"
 { pCxt->pRootNode = createShowVnodesStmt(pCxt, NULL, createValueNode(pCxt, TSDB_DATA_TYPE_VARCHAR, &yymsp[0].minor.yy0)); }
+#line 5858 "sql.c"
         break;
       case 265: /* cmd ::= SHOW db_name_cond_opt ALIVE */
+#line 471 "sql.y"
 { pCxt->pRootNode = createShowAliveStmt(pCxt, yymsp[-1].minor.yy184,    QUERY_NODE_SHOW_DB_ALIVE_STMT); }
+#line 5863 "sql.c"
         break;
       case 266: /* cmd ::= SHOW CLUSTER ALIVE */
+#line 472 "sql.y"
 { pCxt->pRootNode = createShowAliveStmt(pCxt, NULL, QUERY_NODE_SHOW_CLUSTER_ALIVE_STMT); }
+#line 5868 "sql.c"
         break;
       case 267: /* db_name_cond_opt ::= */
       case 272: /* from_db_opt ::= */ yytestcase(yyruleno==272);
+#line 474 "sql.y"
 { yymsp[1].minor.yy184 = createDefaultDatabaseCondValue(pCxt); }
+#line 5874 "sql.c"
         break;
       case 268: /* db_name_cond_opt ::= db_name NK_DOT */
+#line 475 "sql.y"
 { yylhsminor.yy184 = createIdentifierValueNode(pCxt, &yymsp[-1].minor.yy649); }
+#line 5879 "sql.c"
   yymsp[-1].minor.yy184 = yylhsminor.yy184;
         break;
       case 270: /* like_pattern_opt ::= LIKE NK_STRING */
+#line 478 "sql.y"
 { yymsp[-1].minor.yy184 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); }
+#line 5885 "sql.c"
         break;
       case 271: /* table_name_cond ::= table_name */
+#line 480 "sql.y"
 { yylhsminor.yy184 = createIdentifierValueNode(pCxt, &yymsp[0].minor.yy649); }
+#line 5890 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 273: /* from_db_opt ::= FROM db_name */
+#line 483 "sql.y"
 { yymsp[-1].minor.yy184 = createIdentifierValueNode(pCxt, &yymsp[0].minor.yy649); }
+#line 5896 "sql.c"
         break;
       case 277: /* tag_item ::= TBNAME */
+#line 491 "sql.y"
 { yylhsminor.yy184 = setProjectionAlias(pCxt, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL), &yymsp[0].minor.yy0); }
+#line 5901 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 280: /* tag_item ::= column_name column_alias */
+#line 494 "sql.y"
 { yylhsminor.yy184 = setProjectionAlias(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy649), &yymsp[0].minor.yy649); }
+#line 5907 "sql.c"
   yymsp[-1].minor.yy184 = yylhsminor.yy184;
         break;
       case 281: /* tag_item ::= column_name AS column_alias */
+#line 495 "sql.y"
 { yylhsminor.yy184 = setProjectionAlias(pCxt, createColumnNode(pCxt, NULL, &yymsp[-2].minor.yy649), &yymsp[0].minor.yy649); }
+#line 5913 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 282: /* cmd ::= CREATE SMA INDEX not_exists_opt full_index_name ON full_table_name index_options */
+#line 499 "sql.y"
 { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy829, yymsp[-3].minor.yy184, yymsp[-1].minor.yy184, NULL, yymsp[0].minor.yy184); }
+#line 5919 "sql.c"
         break;
       case 283: /* cmd ::= CREATE INDEX not_exists_opt full_index_name ON full_table_name NK_LP col_name_list NK_RP */
+#line 501 "sql.y"
 { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_NORMAL, yymsp[-6].minor.yy829, yymsp[-5].minor.yy184, yymsp[-3].minor.yy184, yymsp[-1].minor.yy532, NULL); }
+#line 5924 "sql.c"
         break;
       case 284: /* cmd ::= DROP INDEX exists_opt full_index_name */
+#line 502 "sql.y"
 { pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-1].minor.yy829, yymsp[0].minor.yy184); }
+#line 5929 "sql.c"
         break;
       case 285: /* full_index_name ::= index_name */
+#line 504 "sql.y"
 { yylhsminor.yy184 = createRealTableNodeForIndexName(pCxt, NULL, &yymsp[0].minor.yy649); }
+#line 5934 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 286: /* full_index_name ::= db_name NK_DOT index_name */
+#line 505 "sql.y"
 { yylhsminor.yy184 = createRealTableNodeForIndexName(pCxt, &yymsp[-2].minor.yy649, &yymsp[0].minor.yy649); }
+#line 5940 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 287: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */
+#line 508 "sql.y"
 { yymsp[-9].minor.yy184 = createIndexOption(pCxt, yymsp[-7].minor.yy532, releaseRawExprNode(pCxt, yymsp[-3].minor.yy184), NULL, yymsp[-1].minor.yy184, yymsp[0].minor.yy184); }
+#line 5946 "sql.c"
         break;
       case 288: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */
+#line 511 "sql.y"
 { yymsp[-11].minor.yy184 = createIndexOption(pCxt, yymsp[-9].minor.yy532, releaseRawExprNode(pCxt, yymsp[-5].minor.yy184), releaseRawExprNode(pCxt, yymsp[-3].minor.yy184), yymsp[-1].minor.yy184, yymsp[0].minor.yy184); }
+#line 5951 "sql.c"
         break;
       case 291: /* func ::= sma_func_name NK_LP expression_list NK_RP */
+#line 518 "sql.y"
 { yylhsminor.yy184 = createFunctionNode(pCxt, &yymsp[-3].minor.yy649, yymsp[-1].minor.yy532); }
+#line 5956 "sql.c"
   yymsp[-3].minor.yy184 = yylhsminor.yy184;
         break;
       case 292: /* sma_func_name ::= function_name */
       case 501: /* alias_opt ::= table_alias */ yytestcase(yyruleno==501);
+#line 522 "sql.y"
 { yylhsminor.yy649 = yymsp[0].minor.yy649; }
+#line 5963 "sql.c"
   yymsp[0].minor.yy649 = yylhsminor.yy649;
         break;
       case 297: /* sma_stream_opt ::= */
       case 335: /* stream_options ::= */ yytestcase(yyruleno==335);
+#line 528 "sql.y"
 { yymsp[1].minor.yy184 = createStreamOptions(pCxt); }
+#line 5970 "sql.c"
         break;
       case 298: /* sma_stream_opt ::= sma_stream_opt WATERMARK duration_literal */
+#line 529 "sql.y"
 { ((SStreamOptions*)yymsp[-2].minor.yy184)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy184); yylhsminor.yy184 = yymsp[-2].minor.yy184; }
+#line 5975 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 299: /* sma_stream_opt ::= sma_stream_opt MAX_DELAY duration_literal */
+#line 530 "sql.y"
 { ((SStreamOptions*)yymsp[-2].minor.yy184)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy184); yylhsminor.yy184 = yymsp[-2].minor.yy184; }
+#line 5981 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 300: /* sma_stream_opt ::= sma_stream_opt DELETE_MARK duration_literal */
+#line 531 "sql.y"
 { ((SStreamOptions*)yymsp[-2].minor.yy184)->pDeleteMark = releaseRawExprNode(pCxt, yymsp[0].minor.yy184); yylhsminor.yy184 = yymsp[-2].minor.yy184; }
+#line 5987 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 301: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_or_subquery */
+#line 534 "sql.y"
 { pCxt->pRootNode = createCreateTopicStmtUseQuery(pCxt, yymsp[-3].minor.yy829, &yymsp[-2].minor.yy649, yymsp[0].minor.yy184); }
+#line 5993 "sql.c"
         break;
       case 302: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */
+#line 535 "sql.y"
 { pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-4].minor.yy829, &yymsp[-3].minor.yy649, &yymsp[0].minor.yy649, false); }
+#line 5998 "sql.c"
         break;
       case 303: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */
+#line 537 "sql.y"
 { pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-6].minor.yy829, &yymsp[-5].minor.yy649, &yymsp[0].minor.yy649, true); }
+#line 6003 "sql.c"
         break;
       case 304: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */
+#line 539 "sql.y"
 { pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-4].minor.yy829, &yymsp[-3].minor.yy649, yymsp[0].minor.yy184, false); }
+#line 6008 "sql.c"
         break;
       case 305: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */
+#line 541 "sql.y"
 { pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-6].minor.yy829, &yymsp[-5].minor.yy649, yymsp[0].minor.yy184, true); }
+#line 6013 "sql.c"
         break;
       case 306: /* cmd ::= DROP TOPIC exists_opt topic_name */
+#line 542 "sql.y"
 { pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy829, &yymsp[0].minor.yy649); }
+#line 6018 "sql.c"
         break;
       case 307: /* cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */
+#line 543 "sql.y"
 { pCxt->pRootNode = createDropCGroupStmt(pCxt, yymsp[-3].minor.yy829, &yymsp[-2].minor.yy649, &yymsp[0].minor.yy649); }
+#line 6023 "sql.c"
         break;
       case 308: /* cmd ::= DESC full_table_name */
       case 309: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==309);
+#line 546 "sql.y"
 { pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy184); }
+#line 6029 "sql.c"
         break;
       case 310: /* cmd ::= RESET QUERY CACHE */
+#line 550 "sql.y"
 { pCxt->pRootNode = createResetQueryCacheStmt(pCxt); }
+#line 6034 "sql.c"
         break;
       case 311: /* cmd ::= EXPLAIN analyze_opt explain_options query_or_subquery */
       case 312: /* cmd ::= EXPLAIN analyze_opt explain_options insert_query */ yytestcase(yyruleno==312);
+#line 553 "sql.y"
 { pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy829, yymsp[-1].minor.yy184, yymsp[0].minor.yy184); }
+#line 6040 "sql.c"
         break;
       case 315: /* explain_options ::= */
+#line 561 "sql.y"
 { yymsp[1].minor.yy184 = createDefaultExplainOptions(pCxt); }
+#line 6045 "sql.c"
         break;
       case 316: /* explain_options ::= explain_options VERBOSE NK_BOOL */
+#line 562 "sql.y"
 { yylhsminor.yy184 = setExplainVerbose(pCxt, yymsp[-2].minor.yy184, &yymsp[0].minor.yy0); }
+#line 6050 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 317: /* explain_options ::= explain_options RATIO NK_FLOAT */
+#line 563 "sql.y"
 { yylhsminor.yy184 = setExplainRatio(pCxt, yymsp[-2].minor.yy184, &yymsp[0].minor.yy0); }
+#line 6056 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 318: /* cmd ::= CREATE or_replace_opt agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt language_opt */
+#line 568 "sql.y"
 { pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-7].minor.yy829, yymsp[-9].minor.yy829, &yymsp[-6].minor.yy649, &yymsp[-4].minor.yy0, yymsp[-2].minor.yy388, yymsp[-1].minor.yy480, &yymsp[0].minor.yy649, yymsp[-10].minor.yy829); }
+#line 6062 "sql.c"
         break;
       case 319: /* cmd ::= DROP FUNCTION exists_opt function_name */
+#line 569 "sql.y"
 { pCxt->pRootNode = createDropFunctionStmt(pCxt, yymsp[-1].minor.yy829, &yymsp[0].minor.yy649); }
+#line 6067 "sql.c"
         break;
       case 324: /* language_opt ::= */
+#line 583 "sql.y"
 { yymsp[1].minor.yy649 = nil_token; }
+#line 6072 "sql.c"
         break;
       case 325: /* language_opt ::= LANGUAGE NK_STRING */
+#line 584 "sql.y"
 { yymsp[-1].minor.yy649 = yymsp[0].minor.yy0; }
+#line 6077 "sql.c"
         break;
       case 328: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options INTO full_table_name col_list_opt tag_def_or_ref_opt subtable_opt AS query_or_subquery */
+#line 594 "sql.y"
 { pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-9].minor.yy829, &yymsp[-8].minor.yy649, yymsp[-5].minor.yy184, yymsp[-7].minor.yy184, yymsp[-3].minor.yy532, yymsp[-2].minor.yy184, yymsp[0].minor.yy184, yymsp[-4].minor.yy532); }
+#line 6082 "sql.c"
         break;
       case 329: /* cmd ::= DROP STREAM exists_opt stream_name */
+#line 595 "sql.y"
 { pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy829, &yymsp[0].minor.yy649); }
+#line 6087 "sql.c"
         break;
       case 336: /* stream_options ::= stream_options TRIGGER AT_ONCE */
       case 337: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ yytestcase(yyruleno==337);
+#line 609 "sql.y"
 { yylhsminor.yy184 = setStreamOptions(pCxt, yymsp[-2].minor.yy184, SOPT_TRIGGER_TYPE_SET, &yymsp[0].minor.yy0, NULL); }
+#line 6093 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 338: /* stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */
+#line 611 "sql.y"
 { yylhsminor.yy184 = setStreamOptions(pCxt, yymsp[-3].minor.yy184, SOPT_TRIGGER_TYPE_SET, &yymsp[-1].minor.yy0, releaseRawExprNode(pCxt, yymsp[0].minor.yy184)); }
+#line 6099 "sql.c"
   yymsp[-3].minor.yy184 = yylhsminor.yy184;
         break;
       case 339: /* stream_options ::= stream_options WATERMARK duration_literal */
+#line 612 "sql.y"
 { yylhsminor.yy184 = setStreamOptions(pCxt, yymsp[-2].minor.yy184, SOPT_WATERMARK_SET, NULL, releaseRawExprNode(pCxt, yymsp[0].minor.yy184)); }
+#line 6105 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 340: /* stream_options ::= stream_options IGNORE EXPIRED NK_INTEGER */
+#line 613 "sql.y"
 { yylhsminor.yy184 = setStreamOptions(pCxt, yymsp[-3].minor.yy184, SOPT_IGNORE_EXPIRED_SET, &yymsp[0].minor.yy0, NULL); }
+#line 6111 "sql.c"
   yymsp[-3].minor.yy184 = yylhsminor.yy184;
         break;
       case 341: /* stream_options ::= stream_options FILL_HISTORY NK_INTEGER */
+#line 614 "sql.y"
 { yylhsminor.yy184 = setStreamOptions(pCxt, yymsp[-2].minor.yy184, SOPT_FILL_HISTORY_SET, &yymsp[0].minor.yy0, NULL); }
+#line 6117 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 342: /* stream_options ::= stream_options DELETE_MARK duration_literal */
+#line 615 "sql.y"
 { yylhsminor.yy184 = setStreamOptions(pCxt, yymsp[-2].minor.yy184, SOPT_DELETE_MARK_SET, NULL, releaseRawExprNode(pCxt, yymsp[0].minor.yy184)); }
+#line 6123 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 343: /* stream_options ::= stream_options IGNORE UPDATE NK_INTEGER */
+#line 616 "sql.y"
 { yylhsminor.yy184 = setStreamOptions(pCxt, yymsp[-3].minor.yy184, SOPT_IGNORE_UPDATE_SET, &yymsp[0].minor.yy0, NULL); }
+#line 6129 "sql.c"
   yymsp[-3].minor.yy184 = yylhsminor.yy184;
         break;
       case 345: /* subtable_opt ::= SUBTABLE NK_LP expression NK_RP */
       case 535: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ yytestcase(yyruleno==535);
       case 555: /* every_opt ::= EVERY NK_LP duration_literal NK_RP */ yytestcase(yyruleno==555);
+#line 619 "sql.y"
 { yymsp[-3].minor.yy184 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy184); }
+#line 6137 "sql.c"
         break;
       case 346: /* cmd ::= KILL CONNECTION NK_INTEGER */
+#line 622 "sql.y"
 { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &yymsp[0].minor.yy0); }
+#line 6142 "sql.c"
         break;
       case 347: /* cmd ::= KILL QUERY NK_STRING */
+#line 623 "sql.y"
 { pCxt->pRootNode = createKillQueryStmt(pCxt, &yymsp[0].minor.yy0); }
+#line 6147 "sql.c"
         break;
       case 348: /* cmd ::= KILL TRANSACTION NK_INTEGER */
+#line 624 "sql.y"
 { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_TRANSACTION_STMT, &yymsp[0].minor.yy0); }
+#line 6152 "sql.c"
         break;
       case 349: /* cmd ::= BALANCE VGROUP */
+#line 627 "sql.y"
 { pCxt->pRootNode = createBalanceVgroupStmt(pCxt); }
+#line 6157 "sql.c"
         break;
       case 350: /* cmd ::= BALANCE VGROUP LEADER */
+#line 628 "sql.y"
 { pCxt->pRootNode = createBalanceVgroupLeaderStmt(pCxt); }
+#line 6162 "sql.c"
         break;
       case 351: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */
+#line 629 "sql.y"
 { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); }
+#line 6167 "sql.c"
         break;
       case 352: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */
+#line 630 "sql.y"
 { pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy532); }
+#line 6172 "sql.c"
         break;
       case 353: /* cmd ::= SPLIT VGROUP NK_INTEGER */
+#line 631 "sql.y"
 { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &yymsp[0].minor.yy0); }
+#line 6177 "sql.c"
         break;
       case 354: /* dnode_list ::= DNODE NK_INTEGER */
+#line 635 "sql.y"
 { yymsp[-1].minor.yy532 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); }
+#line 6182 "sql.c"
         break;
       case 356: /* cmd ::= DELETE FROM full_table_name where_clause_opt */
+#line 642 "sql.y"
 { pCxt->pRootNode = createDeleteStmt(pCxt, yymsp[-1].minor.yy184, yymsp[0].minor.yy184); }
+#line 6187 "sql.c"
         break;
       case 359: /* insert_query ::= INSERT INTO full_table_name NK_LP col_name_list NK_RP query_or_subquery */
+#line 651 "sql.y"
 { yymsp[-6].minor.yy184 = createInsertStmt(pCxt, yymsp[-4].minor.yy184, yymsp[-2].minor.yy532, yymsp[0].minor.yy184); }
+#line 6192 "sql.c"
         break;
       case 360: /* insert_query ::= INSERT INTO full_table_name query_or_subquery */
+#line 652 "sql.y"
 { yymsp[-3].minor.yy184 = createInsertStmt(pCxt, yymsp[-1].minor.yy184, NULL, yymsp[0].minor.yy184); }
+#line 6197 "sql.c"
         break;
       case 361: /* literal ::= NK_INTEGER */
+#line 655 "sql.y"
 { yylhsminor.yy184 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &yymsp[0].minor.yy0)); }
+#line 6202 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 362: /* literal ::= NK_FLOAT */
+#line 656 "sql.y"
 { yylhsminor.yy184 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); }
+#line 6208 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 363: /* literal ::= NK_STRING */
+#line 657 "sql.y"
 { yylhsminor.yy184 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); }
+#line 6214 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 364: /* literal ::= NK_BOOL */
+#line 658 "sql.y"
 { yylhsminor.yy184 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); }
+#line 6220 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 365: /* literal ::= TIMESTAMP NK_STRING */
+#line 659 "sql.y"
 { yylhsminor.yy184 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); }
+#line 6226 "sql.c"
   yymsp[-1].minor.yy184 = yylhsminor.yy184;
         break;
       case 366: /* literal ::= duration_literal */
@@ -5639,61 +6246,87 @@ static YYACTIONTYPE yy_reduce(
       case 558: /* query_simple ::= union_query_expression */ yytestcase(yyruleno==558);
       case 561: /* query_simple_or_subquery ::= query_simple */ yytestcase(yyruleno==561);
       case 563: /* query_or_subquery ::= query_expression */ yytestcase(yyruleno==563);
+#line 660 "sql.y"
 { yylhsminor.yy184 = yymsp[0].minor.yy184; }
+#line 6252 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 367: /* literal ::= NULL */
+#line 661 "sql.y"
 { yylhsminor.yy184 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); }
+#line 6258 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 368: /* literal ::= NK_QUESTION */
+#line 662 "sql.y"
 { yylhsminor.yy184 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); }
+#line 6264 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 369: /* duration_literal ::= NK_VARIABLE */
+#line 664 "sql.y"
 { yylhsminor.yy184 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); }
+#line 6270 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 370: /* signed ::= NK_INTEGER */
+#line 666 "sql.y"
 { yylhsminor.yy184 = createValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &yymsp[0].minor.yy0); }
+#line 6276 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 371: /* signed ::= NK_PLUS NK_INTEGER */
+#line 667 "sql.y"
 { yymsp[-1].minor.yy184 = createValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &yymsp[0].minor.yy0); }
+#line 6282 "sql.c"
         break;
       case 372: /* signed ::= NK_MINUS NK_INTEGER */
+#line 668 "sql.y"
 { 
                                                                                     SToken t = yymsp[-1].minor.yy0;
                                                                                     t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z;
                                                                                     yylhsminor.yy184 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t);
                                                                                   }
+#line 6291 "sql.c"
   yymsp[-1].minor.yy184 = yylhsminor.yy184;
         break;
       case 373: /* signed ::= NK_FLOAT */
+#line 673 "sql.y"
 { yylhsminor.yy184 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); }
+#line 6297 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 374: /* signed ::= NK_PLUS NK_FLOAT */
+#line 674 "sql.y"
 { yymsp[-1].minor.yy184 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); }
+#line 6303 "sql.c"
         break;
       case 375: /* signed ::= NK_MINUS NK_FLOAT */
+#line 675 "sql.y"
 { 
                                                                                     SToken t = yymsp[-1].minor.yy0;
                                                                                     t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z;
                                                                                     yylhsminor.yy184 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t);
                                                                                   }
+#line 6312 "sql.c"
   yymsp[-1].minor.yy184 = yylhsminor.yy184;
         break;
       case 377: /* signed_literal ::= NK_STRING */
+#line 682 "sql.y"
 { yylhsminor.yy184 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); }
+#line 6318 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 378: /* signed_literal ::= NK_BOOL */
+#line 683 "sql.y"
 { yylhsminor.yy184 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); }
+#line 6324 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 379: /* signed_literal ::= TIMESTAMP NK_STRING */
+#line 684 "sql.y"
 { yymsp[-1].minor.yy184 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); }
+#line 6330 "sql.c"
         break;
       case 380: /* signed_literal ::= duration_literal */
       case 382: /* signed_literal ::= literal_func */ yytestcase(yyruleno==382);
@@ -5703,106 +6336,138 @@ static YYACTIONTYPE yy_reduce(
       case 562: /* query_simple_or_subquery ::= subquery */ yytestcase(yyruleno==562);
       case 564: /* query_or_subquery ::= subquery */ yytestcase(yyruleno==564);
       case 577: /* search_condition ::= common_expression */ yytestcase(yyruleno==577);
+#line 685 "sql.y"
 { yylhsminor.yy184 = releaseRawExprNode(pCxt, yymsp[0].minor.yy184); }
+#line 6342 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 381: /* signed_literal ::= NULL */
+#line 686 "sql.y"
 { yylhsminor.yy184 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0); }
+#line 6348 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 383: /* signed_literal ::= NK_QUESTION */
+#line 688 "sql.y"
 { yylhsminor.yy184 = createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0); }
+#line 6354 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 403: /* expression ::= NK_LP expression NK_RP */
       case 487: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==487);
       case 576: /* subquery ::= NK_LP subquery NK_RP */ yytestcase(yyruleno==576);
+#line 749 "sql.y"
 { yylhsminor.yy184 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy184)); }
+#line 6362 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 404: /* expression ::= NK_PLUS expr_or_subquery */
+#line 750 "sql.y"
 {
                                                                                     SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy184));
                                                                                   }
+#line 6371 "sql.c"
   yymsp[-1].minor.yy184 = yylhsminor.yy184;
         break;
       case 405: /* expression ::= NK_MINUS expr_or_subquery */
+#line 754 "sql.y"
 {
                                                                                     SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy184), NULL));
                                                                                   }
+#line 6380 "sql.c"
   yymsp[-1].minor.yy184 = yylhsminor.yy184;
         break;
       case 406: /* expression ::= expr_or_subquery NK_PLUS expr_or_subquery */
+#line 758 "sql.y"
 {
                                                                                     SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy184);
                                                                                     SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), releaseRawExprNode(pCxt, yymsp[0].minor.yy184))); 
                                                                                   }
+#line 6390 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 407: /* expression ::= expr_or_subquery NK_MINUS expr_or_subquery */
+#line 763 "sql.y"
 {
                                                                                     SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy184);
                                                                                     SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), releaseRawExprNode(pCxt, yymsp[0].minor.yy184))); 
                                                                                   }
+#line 6400 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 408: /* expression ::= expr_or_subquery NK_STAR expr_or_subquery */
+#line 768 "sql.y"
 {
                                                                                     SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy184);
                                                                                     SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), releaseRawExprNode(pCxt, yymsp[0].minor.yy184))); 
                                                                                   }
+#line 6410 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 409: /* expression ::= expr_or_subquery NK_SLASH expr_or_subquery */
+#line 773 "sql.y"
 {
                                                                                     SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy184);
                                                                                     SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), releaseRawExprNode(pCxt, yymsp[0].minor.yy184))); 
                                                                                   }
+#line 6420 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 410: /* expression ::= expr_or_subquery NK_REM expr_or_subquery */
+#line 778 "sql.y"
 {
                                                                                     SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy184);
                                                                                     SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_REM, releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), releaseRawExprNode(pCxt, yymsp[0].minor.yy184)));
                                                                                   }
+#line 6430 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 411: /* expression ::= column_reference NK_ARROW NK_STRING */
+#line 783 "sql.y"
 {
                                                                                     SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); 
                                                                                   }
+#line 6439 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 412: /* expression ::= expr_or_subquery NK_BITAND expr_or_subquery */
+#line 787 "sql.y"
 {
                                                                                     SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy184);
                                                                                     SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), releaseRawExprNode(pCxt, yymsp[0].minor.yy184)));
                                                                                   }
+#line 6449 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 413: /* expression ::= expr_or_subquery NK_BITOR expr_or_subquery */
+#line 792 "sql.y"
 {
                                                                                     SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy184);
                                                                                     SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), releaseRawExprNode(pCxt, yymsp[0].minor.yy184)));
                                                                                   }
+#line 6459 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 416: /* column_reference ::= column_name */
+#line 803 "sql.y"
 { yylhsminor.yy184 = createRawExprNode(pCxt, &yymsp[0].minor.yy649, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy649)); }
+#line 6465 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 417: /* column_reference ::= table_name NK_DOT column_name */
+#line 804 "sql.y"
 { yylhsminor.yy184 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy649, &yymsp[0].minor.yy649, createColumnNode(pCxt, &yymsp[-2].minor.yy649, &yymsp[0].minor.yy649)); }
+#line 6471 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 418: /* pseudo_column ::= ROWTS */
@@ -5817,191 +6482,278 @@ static YYACTIONTYPE yy_reduce(
       case 428: /* pseudo_column ::= ISFILLED */ yytestcase(yyruleno==428);
       case 429: /* pseudo_column ::= QTAGS */ yytestcase(yyruleno==429);
       case 435: /* literal_func ::= NOW */ yytestcase(yyruleno==435);
+#line 806 "sql.y"
 { yylhsminor.yy184 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); }
+#line 6488 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 420: /* pseudo_column ::= table_name NK_DOT TBNAME */
+#line 808 "sql.y"
 { yylhsminor.yy184 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy649, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-2].minor.yy649)))); }
+#line 6494 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 430: /* function_expression ::= function_name NK_LP expression_list NK_RP */
       case 431: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==431);
+#line 819 "sql.y"
 { yylhsminor.yy184 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy649, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy649, yymsp[-1].minor.yy532)); }
+#line 6501 "sql.c"
   yymsp[-3].minor.yy184 = yylhsminor.yy184;
         break;
       case 432: /* function_expression ::= CAST NK_LP expr_or_subquery AS type_name NK_RP */
+#line 822 "sql.y"
 { yylhsminor.yy184 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy184), yymsp[-1].minor.yy388)); }
+#line 6507 "sql.c"
   yymsp[-5].minor.yy184 = yylhsminor.yy184;
         break;
       case 434: /* literal_func ::= noarg_func NK_LP NK_RP */
+#line 825 "sql.y"
 { yylhsminor.yy184 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy649, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-2].minor.yy649, NULL)); }
+#line 6513 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 449: /* star_func_para_list ::= NK_STAR */
+#line 849 "sql.y"
 { yylhsminor.yy532 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); }
+#line 6519 "sql.c"
   yymsp[0].minor.yy532 = yylhsminor.yy532;
         break;
       case 454: /* star_func_para ::= table_name NK_DOT NK_STAR */
       case 518: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==518);
+#line 858 "sql.y"
 { yylhsminor.yy184 = createColumnNode(pCxt, &yymsp[-2].minor.yy649, &yymsp[0].minor.yy0); }
+#line 6526 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 455: /* case_when_expression ::= CASE when_then_list case_when_else_opt END */
+#line 861 "sql.y"
 { yylhsminor.yy184 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, createCaseWhenNode(pCxt, NULL, yymsp[-2].minor.yy532, yymsp[-1].minor.yy184)); }
+#line 6532 "sql.c"
   yymsp[-3].minor.yy184 = yylhsminor.yy184;
         break;
       case 456: /* case_when_expression ::= CASE common_expression when_then_list case_when_else_opt END */
+#line 863 "sql.y"
 { yylhsminor.yy184 = createRawExprNodeExt(pCxt, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0, createCaseWhenNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy184), yymsp[-2].minor.yy532, yymsp[-1].minor.yy184)); }
+#line 6538 "sql.c"
   yymsp[-4].minor.yy184 = yylhsminor.yy184;
         break;
       case 459: /* when_then_expr ::= WHEN common_expression THEN common_expression */
+#line 870 "sql.y"
 { yymsp[-3].minor.yy184 = createWhenThenNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), releaseRawExprNode(pCxt, yymsp[0].minor.yy184)); }
+#line 6544 "sql.c"
         break;
       case 461: /* case_when_else_opt ::= ELSE common_expression */
+#line 873 "sql.y"
 { yymsp[-1].minor.yy184 = releaseRawExprNode(pCxt, yymsp[0].minor.yy184); }
+#line 6549 "sql.c"
         break;
       case 462: /* predicate ::= expr_or_subquery compare_op expr_or_subquery */
       case 467: /* predicate ::= expr_or_subquery in_op in_predicate_value */ yytestcase(yyruleno==467);
+#line 876 "sql.y"
 {
                                                                                     SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy184);
                                                                                     SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy424, releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), releaseRawExprNode(pCxt, yymsp[0].minor.yy184)));
                                                                                   }
+#line 6559 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 463: /* predicate ::= expr_or_subquery BETWEEN expr_or_subquery AND expr_or_subquery */
+#line 883 "sql.y"
 {
                                                                                     SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy184);
                                                                                     SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy184), releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), releaseRawExprNode(pCxt, yymsp[0].minor.yy184)));
                                                                                   }
+#line 6569 "sql.c"
   yymsp[-4].minor.yy184 = yylhsminor.yy184;
         break;
       case 464: /* predicate ::= expr_or_subquery NOT BETWEEN expr_or_subquery AND expr_or_subquery */
+#line 889 "sql.y"
 {
                                                                                     SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy184);
                                                                                     SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy184), releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), releaseRawExprNode(pCxt, yymsp[0].minor.yy184)));
                                                                                   }
+#line 6579 "sql.c"
   yymsp[-5].minor.yy184 = yylhsminor.yy184;
         break;
       case 465: /* predicate ::= expr_or_subquery IS NULL */
+#line 894 "sql.y"
 {
                                                                                     SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), NULL));
                                                                                   }
+#line 6588 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 466: /* predicate ::= expr_or_subquery IS NOT NULL */
+#line 898 "sql.y"
 {
                                                                                     SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy184), NULL));
                                                                                   }
+#line 6597 "sql.c"
   yymsp[-3].minor.yy184 = yylhsminor.yy184;
         break;
       case 468: /* compare_op ::= NK_LT */
+#line 910 "sql.y"
 { yymsp[0].minor.yy424 = OP_TYPE_LOWER_THAN; }
+#line 6603 "sql.c"
         break;
       case 469: /* compare_op ::= NK_GT */
+#line 911 "sql.y"
 { yymsp[0].minor.yy424 = OP_TYPE_GREATER_THAN; }
+#line 6608 "sql.c"
         break;
       case 470: /* compare_op ::= NK_LE */
+#line 912 "sql.y"
 { yymsp[0].minor.yy424 = OP_TYPE_LOWER_EQUAL; }
+#line 6613 "sql.c"
         break;
       case 471: /* compare_op ::= NK_GE */
+#line 913 "sql.y"
 { yymsp[0].minor.yy424 = OP_TYPE_GREATER_EQUAL; }
+#line 6618 "sql.c"
         break;
       case 472: /* compare_op ::= NK_NE */
+#line 914 "sql.y"
 { yymsp[0].minor.yy424 = OP_TYPE_NOT_EQUAL; }
+#line 6623 "sql.c"
         break;
       case 473: /* compare_op ::= NK_EQ */
+#line 915 "sql.y"
 { yymsp[0].minor.yy424 = OP_TYPE_EQUAL; }
+#line 6628 "sql.c"
         break;
       case 474: /* compare_op ::= LIKE */
+#line 916 "sql.y"
 { yymsp[0].minor.yy424 = OP_TYPE_LIKE; }
+#line 6633 "sql.c"
         break;
       case 475: /* compare_op ::= NOT LIKE */
+#line 917 "sql.y"
 { yymsp[-1].minor.yy424 = OP_TYPE_NOT_LIKE; }
+#line 6638 "sql.c"
         break;
       case 476: /* compare_op ::= MATCH */
+#line 918 "sql.y"
 { yymsp[0].minor.yy424 = OP_TYPE_MATCH; }
+#line 6643 "sql.c"
         break;
       case 477: /* compare_op ::= NMATCH */
+#line 919 "sql.y"
 { yymsp[0].minor.yy424 = OP_TYPE_NMATCH; }
+#line 6648 "sql.c"
         break;
       case 478: /* compare_op ::= CONTAINS */
+#line 920 "sql.y"
 { yymsp[0].minor.yy424 = OP_TYPE_JSON_CONTAINS; }
+#line 6653 "sql.c"
         break;
       case 479: /* in_op ::= IN */
+#line 924 "sql.y"
 { yymsp[0].minor.yy424 = OP_TYPE_IN; }
+#line 6658 "sql.c"
         break;
       case 480: /* in_op ::= NOT IN */
+#line 925 "sql.y"
 { yymsp[-1].minor.yy424 = OP_TYPE_NOT_IN; }
+#line 6663 "sql.c"
         break;
       case 481: /* in_predicate_value ::= NK_LP literal_list NK_RP */
+#line 927 "sql.y"
 { yylhsminor.yy184 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy532)); }
+#line 6668 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 483: /* boolean_value_expression ::= NOT boolean_primary */
+#line 931 "sql.y"
 {
                                                                                     SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy184), NULL));
                                                                                   }
+#line 6677 "sql.c"
   yymsp[-1].minor.yy184 = yylhsminor.yy184;
         break;
       case 484: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */
+#line 936 "sql.y"
 {
                                                                                     SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy184);
                                                                                     SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), releaseRawExprNode(pCxt, yymsp[0].minor.yy184)));
                                                                                   }
+#line 6687 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 485: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */
+#line 942 "sql.y"
 {
                                                                                     SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy184);
                                                                                     SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy184);
                                                                                     yylhsminor.yy184 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), releaseRawExprNode(pCxt, yymsp[0].minor.yy184)));
                                                                                   }
+#line 6697 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 493: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */
+#line 960 "sql.y"
 { yylhsminor.yy184 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy184, yymsp[0].minor.yy184, NULL); }
+#line 6703 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 496: /* table_primary ::= table_name alias_opt */
+#line 966 "sql.y"
 { yylhsminor.yy184 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy649, &yymsp[0].minor.yy649); }
+#line 6709 "sql.c"
   yymsp[-1].minor.yy184 = yylhsminor.yy184;
         break;
       case 497: /* table_primary ::= db_name NK_DOT table_name alias_opt */
+#line 967 "sql.y"
 { yylhsminor.yy184 = createRealTableNode(pCxt, &yymsp[-3].minor.yy649, &yymsp[-1].minor.yy649, &yymsp[0].minor.yy649); }
+#line 6715 "sql.c"
   yymsp[-3].minor.yy184 = yylhsminor.yy184;
         break;
       case 498: /* table_primary ::= subquery alias_opt */
+#line 968 "sql.y"
 { yylhsminor.yy184 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy184), &yymsp[0].minor.yy649); }
+#line 6721 "sql.c"
   yymsp[-1].minor.yy184 = yylhsminor.yy184;
         break;
       case 500: /* alias_opt ::= */
+#line 973 "sql.y"
 { yymsp[1].minor.yy649 = nil_token;  }
+#line 6727 "sql.c"
         break;
       case 502: /* alias_opt ::= AS table_alias */
+#line 975 "sql.y"
 { yymsp[-1].minor.yy649 = yymsp[0].minor.yy649; }
+#line 6732 "sql.c"
         break;
       case 503: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */
       case 504: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==504);
+#line 977 "sql.y"
 { yymsp[-2].minor.yy184 = yymsp[-1].minor.yy184; }
+#line 6738 "sql.c"
         break;
       case 505: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */
+#line 982 "sql.y"
 { yylhsminor.yy184 = createJoinTableNode(pCxt, yymsp[-4].minor.yy416, yymsp[-5].minor.yy184, yymsp[-2].minor.yy184, yymsp[0].minor.yy184); }
+#line 6743 "sql.c"
   yymsp[-5].minor.yy184 = yylhsminor.yy184;
         break;
       case 506: /* join_type ::= */
+#line 986 "sql.y"
 { yymsp[1].minor.yy416 = JOIN_TYPE_INNER; }
+#line 6749 "sql.c"
         break;
       case 507: /* join_type ::= INNER */
+#line 987 "sql.y"
 { yymsp[0].minor.yy416 = JOIN_TYPE_INNER; }
+#line 6754 "sql.c"
         break;
       case 508: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */
+#line 993 "sql.y"
 { 
                                                                                     yymsp[-11].minor.yy184 = createSelectStmt(pCxt, yymsp[-10].minor.yy829, yymsp[-9].minor.yy532, yymsp[-8].minor.yy184);
                                                                                     yymsp[-11].minor.yy184 = addWhereClause(pCxt, yymsp[-11].minor.yy184, yymsp[-7].minor.yy184);
@@ -6013,135 +6765,208 @@ static YYACTIONTYPE yy_reduce(
                                                                                     yymsp[-11].minor.yy184 = addEveryClause(pCxt, yymsp[-11].minor.yy184, yymsp[-4].minor.yy184);
                                                                                     yymsp[-11].minor.yy184 = addFillClause(pCxt, yymsp[-11].minor.yy184, yymsp[-3].minor.yy184);
                                                                                   }
+#line 6769 "sql.c"
         break;
       case 511: /* set_quantifier_opt ::= ALL */
+#line 1009 "sql.y"
 { yymsp[0].minor.yy829 = false; }
+#line 6774 "sql.c"
         break;
       case 514: /* select_item ::= NK_STAR */
+#line 1016 "sql.y"
 { yylhsminor.yy184 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0); }
+#line 6779 "sql.c"
   yymsp[0].minor.yy184 = yylhsminor.yy184;
         break;
       case 516: /* select_item ::= common_expression column_alias */
       case 526: /* partition_item ::= expr_or_subquery column_alias */ yytestcase(yyruleno==526);
+#line 1018 "sql.y"
 { yylhsminor.yy184 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy184), &yymsp[0].minor.yy649); }
+#line 6786 "sql.c"
   yymsp[-1].minor.yy184 = yylhsminor.yy184;
         break;
       case 517: /* select_item ::= common_expression AS column_alias */
       case 527: /* partition_item ::= expr_or_subquery AS column_alias */ yytestcase(yyruleno==527);
+#line 1019 "sql.y"
 { yylhsminor.yy184 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), &yymsp[0].minor.yy649); }
+#line 6793 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 522: /* partition_by_clause_opt ::= PARTITION BY partition_list */
       case 547: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==547);
       case 566: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==566);
+#line 1028 "sql.y"
 { yymsp[-2].minor.yy532 = yymsp[0].minor.yy532; }
+#line 6801 "sql.c"
         break;
       case 529: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */
+#line 1041 "sql.y"
 { yymsp[-5].minor.yy184 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy184), releaseRawExprNode(pCxt, yymsp[-1].minor.yy184)); }
+#line 6806 "sql.c"
         break;
       case 530: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expr_or_subquery NK_RP */
+#line 1042 "sql.y"
 { yymsp[-3].minor.yy184 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy184)); }
+#line 6811 "sql.c"
         break;
       case 531: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */
+#line 1044 "sql.y"
 { yymsp[-5].minor.yy184 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy184), NULL, yymsp[-1].minor.yy184, yymsp[0].minor.yy184); }
+#line 6816 "sql.c"
         break;
       case 532: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */
+#line 1047 "sql.y"
 { yymsp[-7].minor.yy184 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy184), releaseRawExprNode(pCxt, yymsp[-3].minor.yy184), yymsp[-1].minor.yy184, yymsp[0].minor.yy184); }
+#line 6821 "sql.c"
         break;
       case 533: /* twindow_clause_opt ::= EVENT_WINDOW START WITH search_condition END WITH search_condition */
+#line 1049 "sql.y"
 { yymsp[-6].minor.yy184 = createEventWindowNode(pCxt, yymsp[-3].minor.yy184, yymsp[0].minor.yy184); }
+#line 6826 "sql.c"
         break;
       case 537: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */
+#line 1055 "sql.y"
 { yymsp[-3].minor.yy184 = createFillNode(pCxt, yymsp[-1].minor.yy362, NULL); }
+#line 6831 "sql.c"
         break;
       case 538: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA expression_list NK_RP */
+#line 1056 "sql.y"
 { yymsp[-5].minor.yy184 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy532)); }
+#line 6836 "sql.c"
         break;
       case 539: /* fill_opt ::= FILL NK_LP VALUE_F NK_COMMA expression_list NK_RP */
+#line 1057 "sql.y"
 { yymsp[-5].minor.yy184 = createFillNode(pCxt, FILL_MODE_VALUE_F, createNodeListNode(pCxt, yymsp[-1].minor.yy532)); }
+#line 6841 "sql.c"
         break;
       case 540: /* fill_mode ::= NONE */
+#line 1061 "sql.y"
 { yymsp[0].minor.yy362 = FILL_MODE_NONE; }
+#line 6846 "sql.c"
         break;
       case 541: /* fill_mode ::= PREV */
+#line 1062 "sql.y"
 { yymsp[0].minor.yy362 = FILL_MODE_PREV; }
+#line 6851 "sql.c"
         break;
       case 542: /* fill_mode ::= NULL */
+#line 1063 "sql.y"
 { yymsp[0].minor.yy362 = FILL_MODE_NULL; }
+#line 6856 "sql.c"
         break;
       case 543: /* fill_mode ::= NULL_F */
+#line 1064 "sql.y"
 { yymsp[0].minor.yy362 = FILL_MODE_NULL_F; }
+#line 6861 "sql.c"
         break;
       case 544: /* fill_mode ::= LINEAR */
+#line 1065 "sql.y"
 { yymsp[0].minor.yy362 = FILL_MODE_LINEAR; }
+#line 6866 "sql.c"
         break;
       case 545: /* fill_mode ::= NEXT */
+#line 1066 "sql.y"
 { yymsp[0].minor.yy362 = FILL_MODE_NEXT; }
+#line 6871 "sql.c"
         break;
       case 548: /* group_by_list ::= expr_or_subquery */
+#line 1075 "sql.y"
 { yylhsminor.yy532 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy184))); }
+#line 6876 "sql.c"
   yymsp[0].minor.yy532 = yylhsminor.yy532;
         break;
       case 549: /* group_by_list ::= group_by_list NK_COMMA expr_or_subquery */
+#line 1076 "sql.y"
 { yylhsminor.yy532 = addNodeToList(pCxt, yymsp[-2].minor.yy532, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy184))); }
+#line 6882 "sql.c"
   yymsp[-2].minor.yy532 = yylhsminor.yy532;
         break;
       case 553: /* range_opt ::= RANGE NK_LP expr_or_subquery NK_COMMA expr_or_subquery NK_RP */
+#line 1083 "sql.y"
 { yymsp[-5].minor.yy184 = createInterpTimeRange(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy184), releaseRawExprNode(pCxt, yymsp[-1].minor.yy184)); }
+#line 6888 "sql.c"
         break;
       case 556: /* query_expression ::= query_simple order_by_clause_opt slimit_clause_opt limit_clause_opt */
+#line 1090 "sql.y"
 {
                                                                                     yylhsminor.yy184 = addOrderByClause(pCxt, yymsp[-3].minor.yy184, yymsp[-2].minor.yy532);
                                                                                     yylhsminor.yy184 = addSlimitClause(pCxt, yylhsminor.yy184, yymsp[-1].minor.yy184);
                                                                                     yylhsminor.yy184 = addLimitClause(pCxt, yylhsminor.yy184, yymsp[0].minor.yy184);
                                                                                   }
+#line 6897 "sql.c"
   yymsp[-3].minor.yy184 = yylhsminor.yy184;
         break;
       case 559: /* union_query_expression ::= query_simple_or_subquery UNION ALL query_simple_or_subquery */
+#line 1100 "sql.y"
 { yylhsminor.yy184 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy184, yymsp[0].minor.yy184); }
+#line 6903 "sql.c"
   yymsp[-3].minor.yy184 = yylhsminor.yy184;
         break;
       case 560: /* union_query_expression ::= query_simple_or_subquery UNION query_simple_or_subquery */
+#line 1102 "sql.y"
 { yylhsminor.yy184 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy184, yymsp[0].minor.yy184); }
+#line 6909 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 568: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */
       case 572: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==572);
+#line 1116 "sql.y"
 { yymsp[-1].minor.yy184 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); }
+#line 6916 "sql.c"
         break;
       case 569: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */
       case 573: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==573);
+#line 1117 "sql.y"
 { yymsp[-3].minor.yy184 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); }
+#line 6922 "sql.c"
         break;
       case 570: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */
       case 574: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==574);
+#line 1118 "sql.y"
 { yymsp[-3].minor.yy184 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); }
+#line 6928 "sql.c"
         break;
       case 575: /* subquery ::= NK_LP query_expression NK_RP */
+#line 1126 "sql.y"
 { yylhsminor.yy184 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy184); }
+#line 6933 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 580: /* sort_specification ::= expr_or_subquery ordering_specification_opt null_ordering_opt */
+#line 1140 "sql.y"
 { yylhsminor.yy184 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy184), yymsp[-1].minor.yy706, yymsp[0].minor.yy617); }
+#line 6939 "sql.c"
   yymsp[-2].minor.yy184 = yylhsminor.yy184;
         break;
       case 581: /* ordering_specification_opt ::= */
+#line 1144 "sql.y"
 { yymsp[1].minor.yy706 = ORDER_ASC; }
+#line 6945 "sql.c"
         break;
       case 582: /* ordering_specification_opt ::= ASC */
+#line 1145 "sql.y"
 { yymsp[0].minor.yy706 = ORDER_ASC; }
+#line 6950 "sql.c"
         break;
       case 583: /* ordering_specification_opt ::= DESC */
+#line 1146 "sql.y"
 { yymsp[0].minor.yy706 = ORDER_DESC; }
+#line 6955 "sql.c"
         break;
       case 584: /* null_ordering_opt ::= */
+#line 1150 "sql.y"
 { yymsp[1].minor.yy617 = NULL_ORDER_DEFAULT; }
+#line 6960 "sql.c"
         break;
       case 585: /* null_ordering_opt ::= NULLS FIRST */
+#line 1151 "sql.y"
 { yymsp[-1].minor.yy617 = NULL_ORDER_FIRST; }
+#line 6965 "sql.c"
         break;
       case 586: /* null_ordering_opt ::= NULLS LAST */
+#line 1152 "sql.y"
 { yymsp[-1].minor.yy617 = NULL_ORDER_LAST; }
+#line 6970 "sql.c"
         break;
       default:
         break;
@@ -6203,6 +7028,7 @@ static void yy_syntax_error(
   ParseCTX_FETCH
 #define TOKEN yyminor
 /************ Begin %syntax_error code ****************************************/
+#line 29 "sql.y"
 
   if (TSDB_CODE_SUCCESS == pCxt->errCode) {
     if(TOKEN.z) {
@@ -6213,6 +7039,7 @@ static void yy_syntax_error(
   } else if (TSDB_CODE_PAR_DB_NOT_SPECIFIED == pCxt->errCode && TK_NK_FLOAT == TOKEN.type) {
     pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z);
   }
+#line 7043 "sql.c"
 /************ End %syntax_error code ******************************************/
   ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
   ParseCTX_STORE
diff --git a/source/libs/parser/test/parInitialCTest.cpp b/source/libs/parser/test/parInitialCTest.cpp
index b7ca944ebb..6a08193a39 100644
--- a/source/libs/parser/test/parInitialCTest.cpp
+++ b/source/libs/parser/test/parInitialCTest.cpp
@@ -920,6 +920,10 @@ TEST_F(ParserInitialCTest, createStreamSemanticCheck) {
 
   run("CREATE STREAM s1 INTO st1 AS SELECT PERCENTILE(c1, 30) FROM t1 INTERVAL(10S)",
       TSDB_CODE_PAR_STREAM_NOT_ALLOWED_FUNC);
+  run("CREATE STREAM s2 INTO st1 AS SELECT ts, to_json('{c1:1}') FROM st1 PARTITION BY TBNAME",
+      TSDB_CODE_PAR_INVALID_STREAM_QUERY);
+  run("CREATE STREAM s3 INTO st3 TAGS(tname VARCHAR(10), id INT) SUBTABLE(CONCAT('new-', tbname)) "
+      "AS SELECT _WSTART wstart, COUNT(*) cnt FROM st1 INTERVAL(10S)", TSDB_CODE_PAR_INVALID_STREAM_QUERY);
 }
 
 /*
diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c
index 6544898be9..66b478004f 100644
--- a/source/libs/planner/src/planLogicCreater.c
+++ b/source/libs/planner/src/planLogicCreater.c
@@ -1458,7 +1458,7 @@ static int32_t createDeleteRootLogicNode(SLogicPlanContext* pCxt, SDeleteStmt* p
 
 static int32_t createDeleteScanLogicNode(SLogicPlanContext* pCxt, SDeleteStmt* pDelete, SLogicNode** pLogicNode) {
   SScanLogicNode* pScan = NULL;
-  int32_t         code = makeScanLogicNode(pCxt, (SRealTableNode*)pDelete->pFromTable, false, (SLogicNode**)&pScan);
+  int32_t          code = makeScanLogicNode(pCxt, (SRealTableNode*)pDelete->pFromTable, false, (SLogicNode**)&pScan);
 
   // set columns to scan
   if (TSDB_CODE_SUCCESS == code) {
diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c
index 4f8b57de5f..ea6ffed1f6 100644
--- a/source/libs/planner/src/planOptimizer.c
+++ b/source/libs/planner/src/planOptimizer.c
@@ -2560,7 +2560,7 @@ static bool tbCntScanOptIsEligibleAggFuncs(SNodeList* pAggFuncs) {
       return false;
     }
   }
-  return true;
+  return LIST_LENGTH(pAggFuncs) > 0;
 }
 
 static bool tbCntScanOptIsEligibleAgg(SAggLogicNode* pAgg) {
diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c
index c6a4a97f6e..58b8e53478 100644
--- a/source/libs/planner/src/planner.c
+++ b/source/libs/planner/src/planner.c
@@ -19,6 +19,14 @@
 #include "scalar.h"
 #include "tglobal.h"
 
+static void debugPrintNode(SNode* pNode) {
+  char* pStr = NULL;
+  nodesNodeToString(pNode, false, &pStr, NULL);
+  printf("%s\n", pStr);
+  taosMemoryFree(pStr);
+  return;
+}
+
 static void dumpQueryPlan(SQueryPlan* pPlan) {
   if (!tsQueryPlannerTrace) {
     return;
diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c
index b62a3e4932..01b136d5e0 100644
--- a/source/libs/qcom/src/querymsg.c
+++ b/source/libs/qcom/src/querymsg.c
@@ -407,7 +407,7 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta *
     pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
   }
 
-  qDebug("table %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s stb %s suid %" PRIx64 " sver %d tver %d" PRIx64
+  qDebug("table %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s stb %s suid %" PRIx64 " sver %d tver %d"
          " tagNum %d colNum %d precision %d rowSize %d",
          msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName,
          pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags,
diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c
index 0521076d23..d9295656e8 100644
--- a/source/libs/scalar/src/scalar.c
+++ b/source/libs/scalar/src/scalar.c
@@ -53,6 +53,7 @@ int32_t sclCreateColumnInfoData(SDataType *pType, int32_t numOfRows, SScalarPara
   int32_t code = colInfoDataEnsureCapacity(pColumnData, numOfRows, true);
   if (code != TSDB_CODE_SUCCESS) {
     terrno = TSDB_CODE_OUT_OF_MEMORY;
+    colDataDestroy(pColumnData);
     taosMemoryFree(pColumnData);
     return terrno;
   }
@@ -1061,17 +1062,20 @@ int32_t sclConvertOpValueNodeTs(SOperatorNode *node, SScalarCtx *ctx) {
 
   if (node->pLeft && SCL_IS_VAR_VALUE_NODE(node->pLeft)) {
     if (node->pRight && (TSDB_DATA_TYPE_TIMESTAMP == ((SExprNode *)node->pRight)->resType.type)) {
-      SCL_ERR_JRET(sclConvertToTsValueNode(sclGetOpValueNodeTsPrecision(node->pLeft, node->pRight), (SValueNode*)node->pLeft));
+      SCL_ERR_JRET(
+          sclConvertToTsValueNode(sclGetOpValueNodeTsPrecision(node->pLeft, node->pRight), (SValueNode *)node->pLeft));
     }
   } else if (node->pRight && SCL_IS_NOTNULL_CONST_NODE(node->pRight)) {
     if (node->pLeft && (TSDB_DATA_TYPE_TIMESTAMP == ((SExprNode *)node->pLeft)->resType.type)) {
       if (SCL_IS_VAR_VALUE_NODE(node->pRight)) {
-        SCL_ERR_JRET(sclConvertToTsValueNode(sclGetOpValueNodeTsPrecision(node->pLeft, node->pRight), (SValueNode*)node->pRight));
+        SCL_ERR_JRET(sclConvertToTsValueNode(sclGetOpValueNodeTsPrecision(node->pLeft, node->pRight),
+                                             (SValueNode *)node->pRight));
       } else if (QUERY_NODE_NODE_LIST == node->pRight->type) {
-        SNode* pNode;
-        FOREACH(pNode, ((SNodeListNode*)node->pRight)->pNodeList) {
+        SNode *pNode;
+        FOREACH(pNode, ((SNodeListNode *)node->pRight)->pNodeList) {
           if (SCL_IS_VAR_VALUE_NODE(pNode)) {
-            SCL_ERR_JRET(sclConvertToTsValueNode(sclGetOpValueNodeTsPrecision(node->pLeft, pNode), (SValueNode*)pNode));
+            SCL_ERR_JRET(
+                sclConvertToTsValueNode(sclGetOpValueNodeTsPrecision(node->pLeft, pNode), (SValueNode *)pNode));
           }
         }
       }
@@ -1086,8 +1090,6 @@ _return:
   return DEAL_RES_ERROR;
 }
 
-
-
 int32_t sclConvertCaseWhenValueNodeTs(SCaseWhenNode *node, SScalarCtx *ctx) {
   int32_t code = 0;
 
@@ -1096,19 +1098,20 @@ int32_t sclConvertCaseWhenValueNodeTs(SCaseWhenNode *node, SScalarCtx *ctx) {
   }
 
   if (SCL_IS_VAR_VALUE_NODE(node->pCase)) {
-    SNode* pNode;
+    SNode *pNode;
     FOREACH(pNode, node->pWhenThenList) {
       SExprNode *pExpr = (SExprNode *)((SWhenThenNode *)pNode)->pWhen;
       if (TSDB_DATA_TYPE_TIMESTAMP == pExpr->resType.type) {
-        SCL_ERR_JRET(sclConvertToTsValueNode(pExpr->resType.precision, (SValueNode*)node->pCase));
+        SCL_ERR_JRET(sclConvertToTsValueNode(pExpr->resType.precision, (SValueNode *)node->pCase));
         break;
       }
     }
   } else if (TSDB_DATA_TYPE_TIMESTAMP == ((SExprNode *)node->pCase)->resType.type) {
-    SNode* pNode;
+    SNode *pNode;
     FOREACH(pNode, node->pWhenThenList) {
       if (SCL_IS_VAR_VALUE_NODE(((SWhenThenNode *)pNode)->pWhen)) {
-        SCL_ERR_JRET(sclConvertToTsValueNode(((SExprNode *)node->pCase)->resType.precision, (SValueNode*)((SWhenThenNode *)pNode)->pWhen));
+        SCL_ERR_JRET(sclConvertToTsValueNode(((SExprNode *)node->pCase)->resType.precision,
+                                             (SValueNode *)((SWhenThenNode *)pNode)->pWhen));
       }
     }
   }
@@ -1271,7 +1274,6 @@ EDealRes sclRewriteLogic(SNode **pNode, SScalarCtx *ctx) {
   return DEAL_RES_CONTINUE;
 }
 
-
 EDealRes sclRewriteOperator(SNode **pNode, SScalarCtx *ctx) {
   SOperatorNode *node = (SOperatorNode *)*pNode;
 
diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c
index 563e7d76ab..1afcf44958 100644
--- a/source/libs/scalar/src/sclfunc.c
+++ b/source/libs/scalar/src/sclfunc.c
@@ -1663,73 +1663,6 @@ int32_t charLengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam
   return doLengthFunction(pInput, inputNum, pOutput, tcharlength);
 }
 
-#if 0
-static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOfRows) {
-  switch(type) {
-    case TSDB_DATA_TYPE_TINYINT:
-    case TSDB_DATA_TYPE_UTINYINT:{
-      int8_t* p = (int8_t*) dest;
-      int8_t* pSrc = (int8_t*) src;
-
-      for(int32_t i = 0; i < numOfRows; ++i) {
-        p[i] = pSrc[numOfRows - i - 1];
-      }
-      return;
-    }
-
-    case TSDB_DATA_TYPE_SMALLINT:
-    case TSDB_DATA_TYPE_USMALLINT:{
-      int16_t* p = (int16_t*) dest;
-      int16_t* pSrc = (int16_t*) src;
-
-      for(int32_t i = 0; i < numOfRows; ++i) {
-        p[i] = pSrc[numOfRows - i - 1];
-      }
-      return;
-    }
-    case TSDB_DATA_TYPE_INT:
-    case TSDB_DATA_TYPE_UINT: {
-      int32_t* p = (int32_t*) dest;
-      int32_t* pSrc = (int32_t*) src;
-
-      for(int32_t i = 0; i < numOfRows; ++i) {
-        p[i] = pSrc[numOfRows - i - 1];
-      }
-      return;
-    }
-    case TSDB_DATA_TYPE_BIGINT:
-    case TSDB_DATA_TYPE_UBIGINT: {
-      int64_t* p = (int64_t*) dest;
-      int64_t* pSrc = (int64_t*) src;
-
-      for(int32_t i = 0; i < numOfRows; ++i) {
-        p[i] = pSrc[numOfRows - i - 1];
-      }
-      return;
-    }
-    case TSDB_DATA_TYPE_FLOAT: {
-      float* p = (float*) dest;
-      float* pSrc = (float*) src;
-
-      for(int32_t i = 0; i < numOfRows; ++i) {
-        p[i] = pSrc[numOfRows - i - 1];
-      }
-      return;
-    }
-    case TSDB_DATA_TYPE_DOUBLE: {
-      double* p = (double*) dest;
-      double* pSrc = (double*) src;
-
-      for(int32_t i = 0; i < numOfRows; ++i) {
-        p[i] = pSrc[numOfRows - i - 1];
-      }
-      return;
-    }
-    default: assert(0);
-  }
-}
-#endif
-
 bool getTimePseudoFuncEnv(SFunctionNode *UNUSED_PARAM(pFunc), SFuncExecEnv *pEnv) {
   pEnv->calcMemSize = sizeof(int64_t);
   return true;
diff --git a/source/libs/scalar/test/CMakeLists.txt b/source/libs/scalar/test/CMakeLists.txt
index 32f5e098c5..caaf86264c 100644
--- a/source/libs/scalar/test/CMakeLists.txt
+++ b/source/libs/scalar/test/CMakeLists.txt
@@ -1,4 +1,4 @@
 enable_testing()
 
-#add_subdirectory(filter)
+add_subdirectory(filter)
 add_subdirectory(scalar)
diff --git a/source/libs/scalar/test/filter/filterTests.cpp b/source/libs/scalar/test/filter/filterTests.cpp
index b59e89fe0d..51ee9b6570 100644
--- a/source/libs/scalar/test/filter/filterTests.cpp
+++ b/source/libs/scalar/test/filter/filterTests.cpp
@@ -33,6 +33,7 @@
 #include "os.h"
 
 #include "filter.h"
+#include "filterInt.h"
 #include "nodes.h"
 #include "scalar.h"
 #include "stub.h"
@@ -344,6 +345,7 @@ TEST(timerangeTest, greater_and_lower_not_strict) {
   nodesDestroyNode(logicNode1);
 }
 
+#if 0
 TEST(columnTest, smallint_column_greater_double_value) {
   SNode       *pLeft = NULL, *pRight = NULL, *opNode = NULL;
   int16_t      leftv[5] = {1, 2, 3, 4, 5};
@@ -1337,6 +1339,127 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
   nodesDestroyNode(logicNode1);
   blockDataDestroy(src);
 }
+#endif
+
+template 
+int32_t compareSignedWithUnsigned(SignedT l, UnsignedT r) {
+  if (l < 0) return -1;
+  auto l_uint64 = static_cast(l);
+  auto r_uint64 = static_cast(r);
+  if (l_uint64 < r_uint64) return -1;
+  if (l_uint64 > r_uint64) return 1;
+  return 0;
+}
+
+template 
+int32_t compareUnsignedWithSigned(UnsignedT l, SignedT r) {
+  if (r < 0) return 1;
+  auto l_uint64 = static_cast(l);
+  auto r_uint64 = static_cast(r);
+  if (l_uint64 < r_uint64) return -1;
+  if (l_uint64 > r_uint64) return 1;
+  return 0;
+}
+
+template 
+void doCompareWithValueRange_SignedWithUnsigned(__compar_fn_t fp) {
+  int32_t signedMin = -10, signedMax = 10;
+  int32_t unsignedMin = 0, unsignedMax = 10;
+  for (SignedT l = signedMin; l <= signedMax; ++l) {
+    for (UnsignedT r = unsignedMin; r <= unsignedMax; ++r) {
+      ASSERT_EQ(fp(&l, &r), compareSignedWithUnsigned(l, r));
+    }
+  }
+}
+
+template 
+void doCompareWithValueRange_UnsignedWithSigned(__compar_fn_t fp) {
+  int32_t signedMin = -10, signedMax = 10;
+  int32_t unsignedMin = 0, unsignedMax = 10;
+  for (UnsignedT l = unsignedMin; l <= unsignedMax; ++l) {
+    for (SignedT r = signedMin; r <= signedMax; ++r) {
+      ASSERT_EQ(fp(&l, &r), compareUnsignedWithSigned(l, r));
+    }
+  }
+}
+
+template 
+void doCompareWithValueRange_OnlyLeftType(__compar_fn_t fp, int32_t rType) {
+  switch (rType) {
+    case TSDB_DATA_TYPE_UTINYINT:
+      doCompareWithValueRange_SignedWithUnsigned(fp);
+      break;
+    case TSDB_DATA_TYPE_USMALLINT:
+      doCompareWithValueRange_SignedWithUnsigned(fp);
+      break;
+    case TSDB_DATA_TYPE_UINT:
+      doCompareWithValueRange_SignedWithUnsigned(fp);
+      break;
+    case TSDB_DATA_TYPE_UBIGINT:
+      doCompareWithValueRange_SignedWithUnsigned(fp);
+      break;
+    case TSDB_DATA_TYPE_TINYINT:
+      doCompareWithValueRange_UnsignedWithSigned(fp);
+      break;
+    case TSDB_DATA_TYPE_SMALLINT:
+      doCompareWithValueRange_UnsignedWithSigned(fp);
+      break;
+    case TSDB_DATA_TYPE_INT:
+      doCompareWithValueRange_UnsignedWithSigned(fp);
+      break;
+    case TSDB_DATA_TYPE_BIGINT:
+      doCompareWithValueRange_UnsignedWithSigned(fp);
+      break;
+    default:
+      FAIL();
+  }
+}
+
+void doCompare(const std::vector &lTypes, const std::vector &rTypes, int32_t oper) {
+  for (int i = 0; i < lTypes.size(); ++i) {
+    for (int j = 0; j < rTypes.size(); ++j) {
+      auto fp = filterGetCompFuncEx(lTypes[i], rTypes[j], oper);
+      switch (lTypes[i]) {
+        case TSDB_DATA_TYPE_TINYINT:
+          doCompareWithValueRange_OnlyLeftType(fp, rTypes[j]);
+          break;
+        case TSDB_DATA_TYPE_SMALLINT:
+          doCompareWithValueRange_OnlyLeftType(fp, rTypes[j]);
+          break;
+        case TSDB_DATA_TYPE_INT:
+          doCompareWithValueRange_OnlyLeftType(fp, rTypes[j]);
+          break;
+        case TSDB_DATA_TYPE_BIGINT:
+          doCompareWithValueRange_OnlyLeftType(fp, rTypes[j]);
+          break;
+        case TSDB_DATA_TYPE_UTINYINT:
+          doCompareWithValueRange_OnlyLeftType(fp, rTypes[j]);
+          break;
+        case TSDB_DATA_TYPE_USMALLINT:
+          doCompareWithValueRange_OnlyLeftType(fp, rTypes[j]);
+          break;
+        case TSDB_DATA_TYPE_UINT:
+          doCompareWithValueRange_OnlyLeftType(fp, rTypes[j]);
+          break;
+        case TSDB_DATA_TYPE_UBIGINT:
+          doCompareWithValueRange_OnlyLeftType(fp, rTypes[j]);
+          break;
+        default:
+          FAIL();
+      }
+    }
+  }
+}
+
+TEST(dataCompareTest, signed_and_unsigned_int) {
+  std::vector lType = {TSDB_DATA_TYPE_TINYINT, TSDB_DATA_TYPE_SMALLINT, TSDB_DATA_TYPE_INT,
+                                TSDB_DATA_TYPE_BIGINT};
+  std::vector rType = {TSDB_DATA_TYPE_UTINYINT, TSDB_DATA_TYPE_USMALLINT, TSDB_DATA_TYPE_UINT,
+                                TSDB_DATA_TYPE_UBIGINT};
+
+  doCompare(lType, rType, OP_TYPE_GREATER_THAN);
+  doCompare(rType, lType, OP_TYPE_GREATER_THAN);
+}
 
 int main(int argc, char **argv) {
   taosSeedRand(taosGetTimestampSec());
diff --git a/source/libs/stream/inc/streamInc.h b/source/libs/stream/inc/streamInc.h
index 876b80697a..b17afeec98 100644
--- a/source/libs/stream/inc/streamInc.h
+++ b/source/libs/stream/inc/streamInc.h
@@ -39,7 +39,7 @@ int32_t streamBroadcastToChildren(SStreamTask* pTask, const SSDataBlock* pBlock)
 
 int32_t tEncodeStreamRetrieveReq(SEncoder* pEncoder, const SStreamRetrieveReq* pReq);
 
-int32_t streamDispatchOneCheckReq(SStreamTask* pTask, const SStreamTaskCheckReq* pReq, int32_t nodeId, SEpSet* pEpSet);
+int32_t streamDispatchCheckMsg(SStreamTask* pTask, const SStreamTaskCheckReq* pReq, int32_t nodeId, SEpSet* pEpSet);
 
 int32_t streamDispatchOneRecoverFinishReq(SStreamTask* pTask, const SStreamRecoverFinishReq* pReq, int32_t vgId,
                                           SEpSet* pEpSet);
diff --git a/source/libs/stream/src/stream.c b/source/libs/stream/src/stream.c
index 0f000f1f50..9ed297bd6b 100644
--- a/source/libs/stream/src/stream.c
+++ b/source/libs/stream/src/stream.c
@@ -16,7 +16,7 @@
 #include "streamInc.h"
 #include "ttimer.h"
 
-#define STREAM_TASK_INPUT_QUEUEU_CAPACITY 100000
+#define STREAM_TASK_INPUT_QUEUEU_CAPACITY 3000
 
 int32_t streamInit() {
   int8_t old;
@@ -52,7 +52,7 @@ void streamCleanUp() {
 void streamSchedByTimer(void* param, void* tmrId) {
   SStreamTask* pTask = (void*)param;
 
-  if (atomic_load_8(&pTask->status.taskStatus) == TASK_STATUS__DROPPING) {
+  if (streamTaskShouldStop(&pTask->status)) {
     streamMetaReleaseTask(NULL, pTask);
     return;
   }
@@ -212,9 +212,10 @@ int32_t streamTaskOutput(SStreamTask* pTask, SStreamDataBlock* pBlock) {
 }
 
 int32_t streamProcessDispatchReq(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pRsp, bool exec) {
-  qDebug("vgId:%d s-task:%s receive dispatch req from taskId:%d", pReq->upstreamNodeId, pTask->id.idStr,
-         pReq->upstreamTaskId);
+  qDebug("s-task:%s receive dispatch req from taskId:%d(vgId:%d)", pTask->id.idStr, pReq->upstreamTaskId,
+         pReq->upstreamNodeId);
 
+  // todo add the input queue buffer limitation
   streamTaskEnqueueBlocks(pTask, pReq, pRsp);
   tDeleteStreamDispatchReq(pReq);
 
@@ -222,10 +223,6 @@ int32_t streamProcessDispatchReq(SStreamTask* pTask, SStreamDispatchReq* pReq, S
     if (streamTryExec(pTask) < 0) {
       return -1;
     }
-
-    /*if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH || pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) {*/
-    /*streamDispatch(pTask);*/
-    /*}*/
   } else {
     streamSchedExec(pTask);
   }
diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c
index 549374ed94..d12eca7ce3 100644
--- a/source/libs/stream/src/streamDispatch.c
+++ b/source/libs/stream/src/streamDispatch.c
@@ -208,7 +208,7 @@ static int32_t streamAddBlockToDispatchMsg(const SSDataBlock* pBlock, SStreamDis
   return 0;
 }
 
-int32_t streamDispatchOneCheckReq(SStreamTask* pTask, const SStreamTaskCheckReq* pReq, int32_t nodeId, SEpSet* pEpSet) {
+int32_t streamDispatchCheckMsg(SStreamTask* pTask, const SStreamTaskCheckReq* pReq, int32_t nodeId, SEpSet* pEpSet) {
   void*   buf = NULL;
   int32_t code = -1;
   SRpcMsg msg = {0};
@@ -240,7 +240,7 @@ int32_t streamDispatchOneCheckReq(SStreamTask* pTask, const SStreamTaskCheckReq*
   msg.pCont = buf;
   msg.msgType = TDMT_STREAM_TASK_CHECK;
 
-  qDebug("dispatch from s-task:%s to downstream s-task:%" PRIx64 ":%d node %d: check msg", pTask->id.idStr,
+  qDebug("s-task:%s dispatch check msg to downstream s-task:%" PRIx64 ":%d node %d: check msg", pTask->id.idStr,
          pReq->streamId, pReq->downstreamTaskId, nodeId);
 
   tmsgSendReq(pEpSet, &msg);
diff --git a/source/libs/stream/src/streamExec.c b/source/libs/stream/src/streamExec.c
index 9a6ff302ef..e10562f5cb 100644
--- a/source/libs/stream/src/streamExec.c
+++ b/source/libs/stream/src/streamExec.c
@@ -17,13 +17,18 @@
 
 #define STREAM_EXEC_MAX_BATCH_NUM 100
 
+bool streamTaskShouldStop(const SStreamStatus* pStatus) {
+  int32_t status = atomic_load_8((int8_t*) &pStatus->taskStatus);
+  return (status == TASK_STATUS__STOP) || (status == TASK_STATUS__DROPPING);
+}
+
 static int32_t streamTaskExecImpl(SStreamTask* pTask, const void* data, SArray* pRes) {
   int32_t code = TSDB_CODE_SUCCESS;
   void*   pExecutor = pTask->exec.pExecutor;
 
   while (pTask->taskLevel == TASK_LEVEL__SOURCE) {
     int8_t status = atomic_load_8(&pTask->status.taskStatus);
-    if (status != TASK_STATUS__NORMAL && status != TASK_STATUS__RESTORE) {
+    if (status != TASK_STATUS__NORMAL) {
       qError("stream task wait for the end of fill history, s-task:%s, status:%d", pTask->id.idStr,
              atomic_load_8(&pTask->status.taskStatus));
       taosMsleep(2);
@@ -66,7 +71,7 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, const void* data, SArray*
 
   // pExecutor
   while (1) {
-    if (pTask->status.taskStatus == TASK_STATUS__DROPPING) {
+    if (streamTaskShouldStop(&pTask->status)) {
       return 0;
     }
 
@@ -106,7 +111,7 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, const void* data, SArray*
       continue;
     }
 
-    qDebug("task %d(child %d) executed and get block", pTask->id.taskId, pTask->selfChildId);
+    qDebug("s-task:%s (child %d) executed and get block", pTask->id.idStr, pTask->selfChildId);
 
     SSDataBlock block = {0};
     assignOneDataBlock(&block, output);
@@ -134,7 +139,7 @@ int32_t streamScanExec(SStreamTask* pTask, int32_t batchSz) {
 
     int32_t batchCnt = 0;
     while (1) {
-      if (atomic_load_8(&pTask->status.taskStatus) == TASK_STATUS__DROPPING) {
+      if (streamTaskShouldStop(&pTask->status)) {
         taosArrayDestroy(pRes);
         return 0;
       }
@@ -160,20 +165,24 @@ int32_t streamScanExec(SStreamTask* pTask, int32_t batchSz) {
 
       batchCnt++;
 
-      qDebug("task %d scan exec block num %d, block limit %d", pTask->id.taskId, batchCnt, batchSz);
+      qDebug("s-task:%s scan exec block num %d, block limit %d", pTask->id.idStr, batchCnt, batchSz);
 
-      if (batchCnt >= batchSz) break;
+      if (batchCnt >= batchSz) {
+        break;
+      }
     }
+
     if (taosArrayGetSize(pRes) == 0) {
       if (finished) {
         taosArrayDestroy(pRes);
-        qDebug("task %d finish recover exec task ", pTask->id.taskId);
+        qDebug("s-task:%s finish recover exec task ", pTask->id.idStr);
         break;
       } else {
-        qDebug("task %d continue recover exec task ", pTask->id.taskId);
+        qDebug("s-task:%s continue recover exec task ", pTask->id.idStr);
         continue;
       }
     }
+
     SStreamDataBlock* qRes = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, 0);
     if (qRes == NULL) {
       taosArrayDestroyEx(pRes, (FDelete)blockDataFreeRes);
@@ -241,10 +250,11 @@ int32_t streamExecForAll(SStreamTask* pTask) {
     void*   pInput = NULL;
 
     // merge multiple input data if possible in the input queue.
+    qDebug("s-task:%s start to extract data block from inputQ", pTask->id.idStr);
+
     while (1) {
       SStreamQueueItem* qItem = streamQueueNextItem(pTask->inputQueue);
       if (qItem == NULL) {
-//        qDebug("s-task:%s extract data from input queue, queue is empty, abort", pTask->id.idStr);
         break;
       }
 
@@ -270,7 +280,7 @@ int32_t streamExecForAll(SStreamTask* pTask) {
       }
     }
 
-    if (pTask->status.taskStatus == TASK_STATUS__DROPPING) {
+    if (streamTaskShouldStop(&pTask->status)) {
       if (pInput) {
         streamFreeQitem(pInput);
       }
@@ -289,7 +299,7 @@ int32_t streamExecForAll(SStreamTask* pTask) {
     }
 
     SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock));
-    qDebug("s-task:%s exec begin, numOfBlocks:%d", pTask->id.idStr, batchSize);
+    qDebug("s-task:%s start to execute, numOfBlocks:%d", pTask->id.idStr, batchSize);
 
     streamTaskExecImpl(pTask, pInput, pRes);
 
@@ -301,9 +311,10 @@ int32_t streamExecForAll(SStreamTask* pTask) {
              ", checkPoint id:%" PRId64 " -> %" PRId64,
              pTask->id.idStr, pTask->chkInfo.version, dataVer, pTask->chkInfo.id, ckId);
 
-      pTask->chkInfo = (SCheckpointInfo) {.version = dataVer, .id = ckId};
+      pTask->chkInfo = (SCheckpointInfo) {.version = dataVer, .id = ckId, .currentVer = pTask->chkInfo.currentVer};
 
       taosWLockLatch(&pTask->pMeta->lock);
+
       streamMetaSaveTask(pTask->pMeta, pTask);
       if (streamMetaCommit(pTask->pMeta) < 0) {
         taosWUnLockLatch(&pTask->pMeta->lock);
@@ -368,7 +379,7 @@ int32_t streamTryExec(SStreamTask* pTask) {
     atomic_store_8(&pTask->status.schedStatus, TASK_SCHED_STATUS__INACTIVE);
     qDebug("s-task:%s exec completed", pTask->id.idStr);
 
-    if (!taosQueueEmpty(pTask->inputQueue->queue)) {
+    if (!taosQueueEmpty(pTask->inputQueue->queue) && (!streamTaskShouldStop(&pTask->status))) {
       streamSchedExec(pTask);
     }
   }
diff --git a/source/libs/stream/src/streamMeta.c b/source/libs/stream/src/streamMeta.c
index 860514bb44..af54904c43 100644
--- a/source/libs/stream/src/streamMeta.c
+++ b/source/libs/stream/src/streamMeta.c
@@ -57,6 +57,13 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF
     goto _err;
   }
 
+  // task list
+  pMeta->pTaskList = taosArrayInit(4, sizeof(int32_t));
+  if (pMeta->pTaskList == NULL) {
+    terrno = TSDB_CODE_OUT_OF_MEMORY;
+    goto _err;
+  }
+
   if (streamMetaBegin(pMeta) < 0) {
     goto _err;
   }
@@ -70,6 +77,7 @@ SStreamMeta* streamMetaOpen(const char* path, void* ahandle, FTaskExpand expandF
 _err:
   taosMemoryFree(pMeta->path);
   if (pMeta->pTasks) taosHashCleanup(pMeta->pTasks);
+  if (pMeta->pTaskList) taosArrayDestroy(pMeta->pTaskList);
   if (pMeta->pTaskDb) tdbTbClose(pMeta->pTaskDb);
   if (pMeta->pCheckpointDb) tdbTbClose(pMeta->pCheckpointDb);
   if (pMeta->db) tdbClose(pMeta->db);
@@ -84,11 +92,6 @@ void streamMetaClose(SStreamMeta* pMeta) {
   tdbClose(pMeta->db);
 
   void* pIter = NULL;
-//  while(pMeta->walScan) {
-//    qDebug("wait stream daemon quit");
-//    taosMsleep(100);
-//  }
-
   while (1) {
     pIter = taosHashIterate(pMeta->pTasks, pIter);
     if (pIter == NULL) {
@@ -102,10 +105,10 @@ void streamMetaClose(SStreamMeta* pMeta) {
     }
 
     tFreeStreamTask(pTask);
-    /*streamMetaReleaseTask(pMeta, pTask);*/
   }
 
   taosHashCleanup(pMeta->pTasks);
+  pMeta->pTaskList = taosArrayDestroy(pMeta->pTaskList);
   taosMemoryFree(pMeta->path);
   taosMemoryFree(pMeta);
 }
@@ -176,29 +179,42 @@ int32_t streamMetaSaveTask(SStreamMeta* pMeta, SStreamTask* pTask) {
 // add to the ready tasks hash map, not the restored tasks hash map
 int32_t streamMetaAddDeployedTask(SStreamMeta* pMeta, int64_t ver, SStreamTask* pTask) {
   if (pMeta->expandFunc(pMeta->ahandle, pTask, ver) < 0) {
+    tFreeStreamTask(pTask);
     return -1;
   }
 
   if (streamMetaSaveTask(pMeta, pTask) < 0) {
+    tFreeStreamTask(pTask);
+    return -1;
+  }
+
+  if (streamMetaCommit(pMeta) < 0) {
+    tFreeStreamTask(pTask);
     return -1;
   }
 
   taosHashPut(pMeta->pTasks, &pTask->id.taskId, sizeof(int32_t), &pTask, POINTER_BYTES);
+  taosArrayPush(pMeta->pTaskList, &pTask->id.taskId);
   return 0;
 }
 
 int32_t streamMetaGetNumOfTasks(const SStreamMeta* pMeta) {
-  return (int32_t) taosHashGetSize(pMeta->pTasks);
+  size_t size = taosHashGetSize(pMeta->pTasks);
+  ASSERT(taosArrayGetSize(pMeta->pTaskList) == taosHashGetSize(pMeta->pTasks));
+
+  return (int32_t) size;
 }
 
 SStreamTask* streamMetaAcquireTask(SStreamMeta* pMeta, int32_t taskId) {
   taosRLockLatch(&pMeta->lock);
 
   SStreamTask** ppTask = (SStreamTask**)taosHashGet(pMeta->pTasks, &taskId, sizeof(int32_t));
-  if (ppTask != NULL && (atomic_load_8(&((*ppTask)->status.taskStatus)) != TASK_STATUS__DROPPING)) {
-    atomic_add_fetch_32(&(*ppTask)->refCnt, 1);
-    taosRUnLockLatch(&pMeta->lock);
-    return *ppTask;
+  if (ppTask != NULL) {
+    if (!streamTaskShouldStop(&(*ppTask)->status)) {
+      atomic_add_fetch_32(&(*ppTask)->refCnt, 1);
+      taosRUnLockLatch(&pMeta->lock);
+      return *ppTask;
+    }
   }
 
   taosRUnLockLatch(&pMeta->lock);
@@ -209,7 +225,7 @@ void streamMetaReleaseTask(SStreamMeta* pMeta, SStreamTask* pTask) {
   int32_t left = atomic_sub_fetch_32(&pTask->refCnt, 1);
   ASSERT(left >= 0);
   if (left == 0) {
-    ASSERT(atomic_load_8(&pTask->status.taskStatus) == TASK_STATUS__DROPPING);
+    ASSERT(streamTaskShouldStop(&pTask->status));
     tFreeStreamTask(pTask);
   }
 }
@@ -218,15 +234,23 @@ void streamMetaRemoveTask(SStreamMeta* pMeta, int32_t taskId) {
   SStreamTask** ppTask = (SStreamTask**)taosHashGet(pMeta->pTasks, &taskId, sizeof(int32_t));
   if (ppTask) {
     SStreamTask* pTask = *ppTask;
-    taosHashRemove(pMeta->pTasks, &taskId, sizeof(int32_t));
-    tdbTbDelete(pMeta->pTaskDb, &taskId, sizeof(int32_t), pMeta->txn);
-    /*if (pTask->timer) {
-     * taosTmrStop(pTask->timer);*/
-    /*pTask->timer = NULL;*/
-    /*}*/
-    atomic_store_8(&pTask->status.taskStatus, TASK_STATUS__DROPPING);
 
     taosWLockLatch(&pMeta->lock);
+
+    taosHashRemove(pMeta->pTasks, &taskId, sizeof(int32_t));
+    tdbTbDelete(pMeta->pTaskDb, &taskId, sizeof(int32_t), pMeta->txn);
+
+    atomic_store_8(&pTask->status.taskStatus, TASK_STATUS__STOP);
+
+    int32_t num = taosArrayGetSize(pMeta->pTaskList);
+    for(int32_t i = 0; i < num; ++i) {
+      int32_t* pTaskId = taosArrayGet(pMeta->pTaskList, i);
+      if (*pTaskId == taskId) {
+        taosArrayRemove(pMeta->pTaskList, i);
+        break;
+      }
+    }
+
     streamMetaReleaseTask(pMeta, pTask);
     taosWUnLockLatch(&pMeta->lock);
   }
@@ -292,6 +316,7 @@ int32_t streamLoadTasks(SStreamMeta* pMeta, int64_t ver) {
       tdbTbcClose(pCur);
       return -1;
     }
+
     tDecoderInit(&decoder, (uint8_t*)pVal, vLen);
     tDecodeStreamTask(&decoder, pTask);
     tDecoderClear(&decoder);
@@ -310,7 +335,8 @@ int32_t streamLoadTasks(SStreamMeta* pMeta, int64_t ver) {
       return -1;
     }
 
-    /*pTask->status.taskStatus = TASK_STATUS__NORMAL;*/
+    taosArrayPush(pMeta->pTaskList, &pTask->id.taskId);
+
     if (pTask->fillHistory) {
       pTask->status.taskStatus = TASK_STATUS__WAIT_DOWNSTREAM;
       streamTaskCheckDownstream(pTask, ver);
diff --git a/source/libs/stream/src/streamRecover.c b/source/libs/stream/src/streamRecover.c
index 55c745e417..0324580885 100644
--- a/source/libs/stream/src/streamRecover.c
+++ b/source/libs/stream/src/streamRecover.c
@@ -20,6 +20,8 @@ int32_t streamTaskLaunchRecover(SStreamTask* pTask, int64_t version) {
 
   if (pTask->taskLevel == TASK_LEVEL__SOURCE) {
     atomic_store_8(&pTask->status.taskStatus, TASK_STATUS__RECOVER_PREPARE);
+    qDebug("s-task:%s set task status:%d and start recover", pTask->id.idStr, pTask->status.taskStatus);
+
     streamSetParamForRecover(pTask);
     streamSourceRecoverPrepareStep1(pTask, version);
 
@@ -52,6 +54,8 @@ int32_t streamTaskLaunchRecover(SStreamTask* pTask, int64_t version) {
 
 // checkstatus
 int32_t streamTaskCheckDownstream(SStreamTask* pTask, int64_t version) {
+  qDebug("s-taks:%s in fill history stage, ver:%"PRId64, pTask->id.idStr, version);
+
   SStreamTaskCheckReq req = {
       .streamId = pTask->id.streamId,
       .upstreamTaskId = pTask->id.taskId,
@@ -61,16 +65,18 @@ int32_t streamTaskCheckDownstream(SStreamTask* pTask, int64_t version) {
 
   // serialize
   if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH) {
+
     req.reqId = tGenIdPI64();
     req.downstreamNodeId = pTask->fixedEpDispatcher.nodeId;
     req.downstreamTaskId = pTask->fixedEpDispatcher.taskId;
     pTask->checkReqId = req.reqId;
 
-    qDebug("task %d at node %d check downstream task %d at node %d", pTask->id.taskId, pTask->nodeId, req.downstreamTaskId,
+    qDebug("s-task:%s at node %d check downstream task %d at node %d", pTask->id.idStr, pTask->nodeId, req.downstreamTaskId,
            req.downstreamNodeId);
-    streamDispatchOneCheckReq(pTask, &req, pTask->fixedEpDispatcher.nodeId, &pTask->fixedEpDispatcher.epSet);
+    streamDispatchCheckMsg(pTask, &req, pTask->fixedEpDispatcher.nodeId, &pTask->fixedEpDispatcher.epSet);
   } else if (pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) {
     SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos;
+
     int32_t vgSz = taosArrayGetSize(vgInfo);
     pTask->recoverTryingDownstream = vgSz;
     pTask->checkReqIds = taosArrayInit(vgSz, sizeof(int64_t));
@@ -81,14 +87,15 @@ int32_t streamTaskCheckDownstream(SStreamTask* pTask, int64_t version) {
       taosArrayPush(pTask->checkReqIds, &req.reqId);
       req.downstreamNodeId = pVgInfo->vgId;
       req.downstreamTaskId = pVgInfo->taskId;
-      qDebug("task %d at node %d check downstream task %d at node %d (shuffle)", pTask->id.taskId, pTask->nodeId,
+      qDebug("s-task:%s at node %d check downstream task %d at node %d (shuffle)", pTask->id.idStr, pTask->nodeId,
              req.downstreamTaskId, req.downstreamNodeId);
-      streamDispatchOneCheckReq(pTask, &req, pVgInfo->vgId, &pVgInfo->epSet);
+      streamDispatchCheckMsg(pTask, &req, pVgInfo->vgId, &pVgInfo->epSet);
     }
   } else {
-    qDebug("task %d at node %d direct launch recover since no downstream", pTask->id.taskId, pTask->nodeId);
+    qDebug("s-task:%s at node %d direct launch recover since no downstream", pTask->id.idStr, pTask->nodeId);
     streamTaskLaunchRecover(pTask, version);
   }
+
   return 0;
 }
 
@@ -107,14 +114,14 @@ int32_t streamRecheckOneDownstream(SStreamTask* pTask, const SStreamTaskCheckRsp
          req.downstreamTaskId, req.downstreamNodeId);
 
   if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH) {
-    streamDispatchOneCheckReq(pTask, &req, pRsp->downstreamNodeId, &pTask->fixedEpDispatcher.epSet);
+    streamDispatchCheckMsg(pTask, &req, pRsp->downstreamNodeId, &pTask->fixedEpDispatcher.epSet);
   } else if (pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) {
     SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos;
     int32_t vgSz = taosArrayGetSize(vgInfo);
     for (int32_t i = 0; i < vgSz; i++) {
       SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i);
       if (pVgInfo->taskId == req.downstreamTaskId) {
-        streamDispatchOneCheckReq(pTask, &req, pRsp->downstreamNodeId, &pVgInfo->epSet);
+        streamDispatchCheckMsg(pTask, &req, pRsp->downstreamNodeId, &pVgInfo->epSet);
       }
     }
   }
@@ -122,8 +129,8 @@ int32_t streamRecheckOneDownstream(SStreamTask* pTask, const SStreamTaskCheckRsp
   return 0;
 }
 
-int32_t streamProcessTaskCheckReq(SStreamTask* pTask, const SStreamTaskCheckReq* pReq) {
-  return atomic_load_8(&pTask->status.taskStatus) == TASK_STATUS__NORMAL;
+int32_t streamTaskCheckStatus(SStreamTask* pTask) {
+  return atomic_load_8(&pTask->status.taskStatus) == TASK_STATUS__NORMAL? 1:0;
 }
 
 int32_t streamProcessTaskCheckRsp(SStreamTask* pTask, const SStreamTaskCheckRsp* pRsp, int64_t version) {
@@ -133,7 +140,9 @@ int32_t streamProcessTaskCheckRsp(SStreamTask* pTask, const SStreamTaskCheckRsp*
   if (pRsp->status == 1) {
     if (pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) {
       bool found = false;
-      for (int32_t i = 0; i < taosArrayGetSize(pTask->checkReqIds); i++) {
+
+      int32_t numOfReqs = taosArrayGetSize(pTask->checkReqIds);
+      for (int32_t i = 0; i < numOfReqs; i++) {
         int64_t reqId = *(int64_t*)taosArrayGet(pTask->checkReqIds, i);
         if (reqId == pRsp->reqId) {
           found = true;
@@ -147,9 +156,12 @@ int32_t streamProcessTaskCheckRsp(SStreamTask* pTask, const SStreamTaskCheckRsp*
 
       int32_t left = atomic_sub_fetch_32(&pTask->recoverTryingDownstream, 1);
       ASSERT(left >= 0);
+
       if (left == 0) {
         taosArrayDestroy(pTask->checkReqIds);
         pTask->checkReqIds = NULL;
+
+        qDebug("s-task:%s all downstream tasks:%d are ready, now enter into recover stage", pTask->id.idStr, numOfReqs);
         streamTaskLaunchRecover(pTask, version);
       }
     } else if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH) {
@@ -161,7 +173,10 @@ int32_t streamProcessTaskCheckRsp(SStreamTask* pTask, const SStreamTaskCheckRsp*
     } else {
       ASSERT(0);
     }
-  } else { // not ready, it should wait for at least 100ms and then retry
+  } else { // not ready, wait for 100ms and retry
+    qDebug("s-task:%s downstream taskId:%d (vgId:%d) not ready, wait for 100ms and retry", pTask->id.idStr,
+        pRsp->downstreamTaskId, pRsp->downstreamNodeId);
+    taosMsleep(100);
     streamRecheckOneDownstream(pTask, pRsp);
   }
 
@@ -197,7 +212,6 @@ int32_t streamBuildSourceRecover1Req(SStreamTask* pTask, SStreamRecoverStep1Req*
 }
 
 int32_t streamSourceRecoverScanStep1(SStreamTask* pTask) {
-  //
   return streamScanExec(pTask, 100);
 }
 
@@ -210,8 +224,11 @@ int32_t streamBuildSourceRecover2Req(SStreamTask* pTask, SStreamRecoverStep2Req*
 
 int32_t streamSourceRecoverScanStep2(SStreamTask* pTask, int64_t ver) {
   void* exec = pTask->exec.pExecutor;
+
+  qDebug("s-task:%s recover step2(blocking stage) started", pTask->id.idStr);
   if (qStreamSourceRecoverStep2(exec, ver) < 0) {
   }
+
   return streamScanExec(pTask, 100);
 }
 
diff --git a/source/libs/stream/src/streamTask.c b/source/libs/stream/src/streamTask.c
index 67c60008fd..f301d9d517 100644
--- a/source/libs/stream/src/streamTask.c
+++ b/source/libs/stream/src/streamTask.c
@@ -193,7 +193,7 @@ void tFreeStreamTask(SStreamTask* pTask) {
 
   taosArrayDestroyP(pTask->childEpInfo, taosMemoryFree);
   if (pTask->outputType == TASK_OUTPUT__TABLE) {
-    tDeleteSSchemaWrapper(pTask->tbSink.pSchemaWrapper);
+    tDeleteSchemaWrapper(pTask->tbSink.pSchemaWrapper);
     taosMemoryFree(pTask->tbSink.pTSchema);
   }
 
diff --git a/source/libs/sync/inc/syncCommit.h b/source/libs/sync/inc/syncCommit.h
index 7d638a7336..07b4702b1b 100644
--- a/source/libs/sync/inc/syncCommit.h
+++ b/source/libs/sync/inc/syncCommit.h
@@ -48,8 +48,6 @@ extern "C" {
 void syncOneReplicaAdvance(SSyncNode* pSyncNode);
 void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode);
 
-bool syncAgreeIndex(SSyncNode* pSyncNode, SRaftId* pRaftId, SyncIndex index);
-bool syncAgree(SSyncNode* pSyncNode, SyncIndex index);
 bool syncNodeAgreedUpon(SSyncNode* pNode, SyncIndex index);
 
 int64_t syncNodeUpdateCommitIndex(SSyncNode* ths, SyncIndex commitIndex);
diff --git a/source/libs/sync/inc/syncReplication.h b/source/libs/sync/inc/syncReplication.h
index a55fd7ead3..04456b2454 100644
--- a/source/libs/sync/inc/syncReplication.h
+++ b/source/libs/sync/inc/syncReplication.h
@@ -55,7 +55,6 @@ int32_t syncNodeReplicateReset(SSyncNode* pSyncNode, SRaftId* pDestId);
 int32_t syncNodeReplicateWithoutLock(SSyncNode* pNode);
 
 int32_t syncNodeSendAppendEntries(SSyncNode* pNode, const SRaftId* destRaftId, SRpcMsg* pRpcMsg);
-int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pNode, const SRaftId* destRaftId, SRpcMsg* pRpcMsg);
 
 #ifdef __cplusplus
 }
diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c
index b488455dba..6f065f56e8 100644
--- a/source/libs/sync/src/syncAppendEntries.c
+++ b/source/libs/sync/src/syncAppendEntries.c
@@ -89,17 +89,6 @@
 //       /\ UNCHANGED <>
 //
 
-SSyncRaftEntry* syncBuildRaftEntryFromAppendEntries(const SyncAppendEntries* pMsg) {
-  SSyncRaftEntry* pEntry = taosMemoryMalloc(pMsg->dataLen);
-  if (pEntry == NULL) {
-    terrno = TSDB_CODE_OUT_OF_MEMORY;
-    return NULL;
-  }
-  (void)memcpy(pEntry, pMsg->data, pMsg->dataLen);
-  ASSERT(pEntry->bytes == pMsg->dataLen);
-  return pEntry;
-}
-
 int32_t syncNodeOnAppendEntries(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
   SyncAppendEntries* pMsg = pRpcMsg->pCont;
   SRpcMsg            rpcRsp = {0};
@@ -148,7 +137,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
     goto _IGNORE;
   }
 
-  pEntry = syncBuildRaftEntryFromAppendEntries(pMsg);
+  pEntry = syncEntryBuildFromAppendEntries(pMsg);
   if (pEntry == NULL) {
     sError("vgId:%d, failed to get raft entry from append entries since %s", ths->vgId, terrstr());
     goto _IGNORE;
diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c
index d3397f8e88..47e4049c73 100644
--- a/source/libs/sync/src/syncCommit.c
+++ b/source/libs/sync/src/syncCommit.c
@@ -44,22 +44,6 @@
 //     /\ UNCHANGED <>
 //
 
-bool syncAgreeIndex(SSyncNode* pSyncNode, SRaftId* pRaftId, SyncIndex index) {
-  // I am leader, I agree
-  if (syncUtilSameId(pRaftId, &(pSyncNode->myRaftId)) && pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
-    return true;
-  }
-
-  // follower agree
-  SyncIndex matchIndex = syncIndexMgrGetIndex(pSyncNode->pMatchIndex, pRaftId);
-  if (matchIndex >= index) {
-    return true;
-  }
-
-  // not agree
-  return false;
-}
-
 static inline int64_t syncNodeAbs64(int64_t a, int64_t b) {
   ASSERT(a >= 0);
   ASSERT(b >= 0);
@@ -87,19 +71,6 @@ bool syncNodeAgreedUpon(SSyncNode* pNode, SyncIndex index) {
   return count >= pNode->quorum;
 }
 
-bool syncAgree(SSyncNode* pNode, SyncIndex index) {
-  int agreeCount = 0;
-  for (int i = 0; i < pNode->replicaNum; ++i) {
-    if (syncAgreeIndex(pNode, &(pNode->replicasId[i]), index)) {
-      ++agreeCount;
-    }
-    if (agreeCount >= pNode->quorum) {
-      return true;
-    }
-  }
-  return false;
-}
-
 int64_t syncNodeUpdateCommitIndex(SSyncNode* ths, SyncIndex commitIndex) {
   SyncIndex lastVer = ths->pLogStore->syncLogLastIndex(ths->pLogStore);
   commitIndex = TMAX(commitIndex, ths->commitIndex);
diff --git a/source/libs/sync/src/syncRaftEntry.c b/source/libs/sync/src/syncRaftEntry.c
index 3e63e2fb8e..8f42780eb9 100644
--- a/source/libs/sync/src/syncRaftEntry.c
+++ b/source/libs/sync/src/syncRaftEntry.c
@@ -64,10 +64,13 @@ SSyncRaftEntry* syncEntryBuildFromRpcMsg(const SRpcMsg* pMsg, SyncTerm term, Syn
 }
 
 SSyncRaftEntry* syncEntryBuildFromAppendEntries(const SyncAppendEntries* pMsg) {
-  SSyncRaftEntry* pEntry = syncEntryBuild((int32_t)(pMsg->dataLen));
-  if (pEntry == NULL) return NULL;
-
+  SSyncRaftEntry* pEntry = taosMemoryMalloc(pMsg->dataLen);
+  if (pEntry == NULL) {
+    terrno = TSDB_CODE_OUT_OF_MEMORY;
+    return NULL;
+  }
   memcpy(pEntry, pMsg->data, pMsg->dataLen);
+  ASSERT(pEntry->bytes == pMsg->dataLen);
   return pEntry;
 }
 
diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c
index 77e73402fa..5a3a3bbb70 100644
--- a/source/libs/sync/src/syncReplication.c
+++ b/source/libs/sync/src/syncReplication.c
@@ -46,8 +46,6 @@
 //                mdest          |-> j])
 //    /\ UNCHANGED <>
 
-int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, SRpcMsg* pRpcMsg);
-
 int32_t syncNodeReplicateReset(SSyncNode* pNode, SRaftId* pDestId) {
   SSyncLogBuffer* pBuf = pNode->pLogBuf;
   taosThreadMutexLock(&pBuf->mutex);
@@ -86,20 +84,6 @@ int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftI
   return 0;
 }
 
-int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, SRpcMsg* pRpcMsg) {
-  int32_t            ret = 0;
-  SyncAppendEntries* pMsg = pRpcMsg->pCont;
-
-  if (syncNodeNeedSendAppendEntries(pSyncNode, destRaftId, pMsg)) {
-    ret = syncNodeSendAppendEntries(pSyncNode, destRaftId, pRpcMsg);
-  } else {
-    sNTrace(pSyncNode, "do not repcate to dnode:%d for index:%" PRId64, DID(destRaftId), pMsg->prevLogIndex + 1);
-    rpcFreeCont(pRpcMsg->pCont);
-  }
-
-  return ret;
-}
-
 int32_t syncNodeSendHeartbeat(SSyncNode* pSyncNode, const SRaftId* destId, SRpcMsg* pMsg) {
   return syncNodeSendMsgById(destId, pSyncNode, pMsg);
 }
diff --git a/source/libs/sync/src/syncRespMgr.c b/source/libs/sync/src/syncRespMgr.c
index f9f14c2e00..3506d477d3 100644
--- a/source/libs/sync/src/syncRespMgr.c
+++ b/source/libs/sync/src/syncRespMgr.c
@@ -171,6 +171,8 @@ static void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) {
 }
 
 void syncRespCleanRsp(SSyncRespMgr *pObj) {
+  if (pObj == NULL) return;
+
   SSyncNode *pNode = pObj->data;
   sTrace("vgId:%d, clean all resp", pNode->vgId);
 
diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c
index c23d6d0a1f..ea35f1cfe5 100644
--- a/source/libs/transport/src/transCli.c
+++ b/source/libs/transport/src/transCli.c
@@ -587,12 +587,12 @@ void* destroyConnPool(SCliThrd* pThrd) {
 
 static SCliConn* getConnFromPool(SCliThrd* pThrd, char* key, bool* exceed) {
   void*      pool = pThrd->pool;
-  SConnList* plist = taosHashGet((SHashObj*)pool, key, strlen(key));
+  SConnList* plist = taosHashGet((SHashObj*)pool, key, strlen(key) + 1);
   STrans*    pTranInst = pThrd->pTransInst;
   if (plist == NULL) {
     SConnList list = {0};
-    taosHashPut((SHashObj*)pool, key, strlen(key), (void*)&list, sizeof(list));
-    plist = taosHashGet(pool, key, strlen(key));
+    taosHashPut((SHashObj*)pool, key, strlen(key) + 1, (void*)&list, sizeof(list));
+    plist = taosHashGet(pool, key, strlen(key) + 1);
 
     SMsgList* nList = taosMemoryCalloc(1, sizeof(SMsgList));
     QUEUE_INIT(&nList->msgQ);
@@ -627,11 +627,11 @@ static SCliConn* getConnFromPool(SCliThrd* pThrd, char* key, bool* exceed) {
 static SCliConn* getConnFromPool2(SCliThrd* pThrd, char* key, SCliMsg** pMsg) {
   void*      pool = pThrd->pool;
   STrans*    pTransInst = pThrd->pTransInst;
-  SConnList* plist = taosHashGet((SHashObj*)pool, key, strlen(key));
+  SConnList* plist = taosHashGet((SHashObj*)pool, key, strlen(key) + 1);
   if (plist == NULL) {
     SConnList list = {0};
-    taosHashPut((SHashObj*)pool, key, strlen(key), (void*)&list, sizeof(list));
-    plist = taosHashGet(pool, key, strlen(key));
+    taosHashPut((SHashObj*)pool, key, strlen(key) + 1, (void*)&list, sizeof(list));
+    plist = taosHashGet(pool, key, strlen(key) + 1);
 
     SMsgList* nList = taosMemoryCalloc(1, sizeof(SMsgList));
     QUEUE_INIT(&nList->msgQ);
@@ -717,7 +717,7 @@ static void addConnToPool(void* pool, SCliConn* conn) {
   cliDestroyConnMsgs(conn, false);
 
   if (conn->list == NULL) {
-    conn->list = taosHashGet((SHashObj*)pool, conn->ip, strlen(conn->ip));
+    conn->list = taosHashGet((SHashObj*)pool, conn->ip, strlen(conn->ip) + 1);
   }
 
   SConnList* pList = conn->list;
@@ -822,7 +822,8 @@ static void cliRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
     return;
   }
   if (nread < 0) {
-    tWarn("%s conn %p read error:%s, ref:%d", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread), T_REF_VAL_GET(conn));
+    tDebug("%s conn %p read error:%s, ref:%d", CONN_GET_INST_LABEL(conn), conn, uv_err_name(nread),
+           T_REF_VAL_GET(conn));
     conn->broken = true;
     cliHandleExcept(conn);
   }
@@ -875,8 +876,8 @@ static void cliDestroyConn(SCliConn* conn, bool clear) {
     connList->list->numOfConn--;
     connList->size--;
   } else {
-    SConnList* connList = taosHashGet((SHashObj*)pThrd->pool, conn->ip, strlen(conn->ip));
-    connList->list->numOfConn--;
+    SConnList* connList = taosHashGet((SHashObj*)pThrd->pool, conn->ip, strlen(conn->ip) + 1);
+    if (connList != NULL) connList->list->numOfConn--;
   }
   conn->list = NULL;
   pThrd->newConnCount--;
@@ -1269,7 +1270,7 @@ static void cliHandleFastFail(SCliConn* pConn, int status) {
 
     if (pMsg != NULL && REQUEST_NO_RESP(&pMsg->msg) &&
         (pTransInst->failFastFp != NULL && pTransInst->failFastFp(pMsg->msg.msgType))) {
-      SFailFastItem* item = taosHashGet(pThrd->failFastCache, pConn->ip, strlen(pConn->ip));
+      SFailFastItem* item = taosHashGet(pThrd->failFastCache, pConn->ip, strlen(pConn->ip) + 1);
       int64_t        cTimestamp = taosGetTimestampMs();
       if (item != NULL) {
         int32_t elapse = cTimestamp - item->timestamp;
@@ -1281,7 +1282,7 @@ static void cliHandleFastFail(SCliConn* pConn, int status) {
         }
       } else {
         SFailFastItem item = {.count = 1, .timestamp = cTimestamp};
-        taosHashPut(pThrd->failFastCache, pConn->ip, strlen(pConn->ip), &item, sizeof(SFailFastItem));
+        taosHashPut(pThrd->failFastCache, pConn->ip, strlen(pConn->ip) + 1, &item, sizeof(SFailFastItem));
       }
     }
   } else {
@@ -1459,7 +1460,7 @@ FORCE_INLINE int32_t cliBuildExceptResp(SCliMsg* pMsg, STransMsg* pResp) {
 }
 static FORCE_INLINE uint32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn) {
   uint32_t  addr = 0;
-  uint32_t* v = taosHashGet(cache, fqdn, strlen(fqdn));
+  uint32_t* v = taosHashGet(cache, fqdn, strlen(fqdn) + 1);
   if (v == NULL) {
     addr = taosGetIpv4FromFqdn(fqdn);
     if (addr == 0xffffffff) {
@@ -1468,7 +1469,7 @@ static FORCE_INLINE uint32_t cliGetIpFromFqdnCache(SHashObj* cache, char* fqdn)
       return addr;
     }
 
-    taosHashPut(cache, fqdn, strlen(fqdn), &addr, sizeof(addr));
+    taosHashPut(cache, fqdn, strlen(fqdn) + 1, &addr, sizeof(addr));
   } else {
     addr = *v;
   }
diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c
index 28fb474972..269c7ecf9b 100644
--- a/source/libs/transport/src/transSvr.c
+++ b/source/libs/transport/src/transSvr.c
@@ -314,7 +314,7 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) {
     return;
   }
 
-  tWarn("%s conn %p read error:%s", transLabel(pTransInst), conn, uv_err_name(nread));
+  tDebug("%s conn %p read error:%s", transLabel(pTransInst), conn, uv_err_name(nread));
   if (nread < 0) {
     conn->broken = true;
     if (conn->status == ConnAcquire) {
diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c
index cda7e35b0f..a12f8051ba 100644
--- a/source/libs/wal/src/walMeta.c
+++ b/source/libs/wal/src/walMeta.c
@@ -295,6 +295,36 @@ void walAlignVersions(SWal* pWal) {
   wInfo("vgId:%d, reset commitVer to %" PRId64, pWal->cfg.vgId, pWal->vers.commitVer);
 }
 
+int walRepairLogFileTs(SWal* pWal, bool* updateMeta) {
+  int32_t sz = taosArrayGetSize(pWal->fileInfoSet);
+  int32_t fileIdx = -1;
+  int32_t lastCloseTs = 0;
+  char    fnameStr[WAL_FILE_LEN] = {0};
+
+  while (++fileIdx < sz - 1) {
+    SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, fileIdx);
+    if (pFileInfo->closeTs != -1) {
+      lastCloseTs = pFileInfo->closeTs;
+      continue;
+    }
+
+    walBuildLogName(pWal, pFileInfo->firstVer, fnameStr);
+    int32_t mtime = 0;
+    if (taosStatFile(fnameStr, NULL, &mtime) < 0) {
+      terrno = TAOS_SYSTEM_ERROR(errno);
+      wError("vgId:%d, failed to stat file due to %s, file:%s", pWal->cfg.vgId, strerror(errno), fnameStr);
+      return -1;
+    }
+
+    if (updateMeta != NULL) *updateMeta = true;
+    if (pFileInfo->createTs == -1) pFileInfo->createTs = lastCloseTs;
+    pFileInfo->closeTs = mtime;
+    lastCloseTs = pFileInfo->closeTs;
+  }
+
+  return 0;
+}
+
 bool walLogEntriesComplete(const SWal* pWal) {
   int32_t sz = taosArrayGetSize(pWal->fileInfoSet);
   bool    complete = true;
@@ -433,15 +463,8 @@ int walCheckAndRepairMeta(SWal* pWal) {
         wError("failed to scan wal last ver since %s", terrstr());
         return -1;
       }
-      // remove the empty wal log, and its idx
-      wInfo("vgId:%d, wal remove empty file %s", pWal->cfg.vgId, fnameStr);
-      taosRemoveFile(fnameStr);
-      walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr);
-      wInfo("vgId:%d, wal remove empty file %s", pWal->cfg.vgId, fnameStr);
-      taosRemoveFile(fnameStr);
-      // remove its meta entry
-      taosArrayRemove(pWal->fileInfoSet, fileIdx);
-      continue;
+      // empty log file
+      lastVer = pFileInfo->firstVer - 1;
     }
 
     // update lastVer
@@ -460,6 +483,11 @@ int walCheckAndRepairMeta(SWal* pWal) {
   }
   (void)walAlignVersions(pWal);
 
+  // repair ts of files
+  if (walRepairLogFileTs(pWal, &updateMeta) < 0) {
+    return -1;
+  }
+
   // update meta file
   if (updateMeta) {
     (void)walSaveMeta(pWal);
diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c
index 19694a6126..aa5ebb221e 100644
--- a/source/libs/wal/src/walRead.c
+++ b/source/libs/wal/src/walRead.c
@@ -37,7 +37,7 @@ SWalReader *walOpenReader(SWal *pWal, SWalFilterCond *cond) {
   if (cond) {
     pReader->cond = *cond;
   } else {
-    pReader->cond.scanUncommited = 0;
+//    pReader->cond.scanUncommited = 0;
     pReader->cond.scanNotApplied = 0;
     pReader->cond.scanMeta = 0;
     pReader->cond.enableRef = 0;
@@ -74,11 +74,15 @@ int32_t walNextValidMsg(SWalReader *pReader) {
   int64_t lastVer = walGetLastVer(pReader->pWal);
   int64_t committedVer = walGetCommittedVer(pReader->pWal);
   int64_t appliedVer = walGetAppliedVer(pReader->pWal);
-  int64_t endVer = pReader->cond.scanUncommited ? lastVer : committedVer;
-  endVer = TMIN(appliedVer, endVer);
+  if(appliedVer < committedVer){   // wait apply ver equal to commit ver, otherwise may lost data when consume data [TD-24010]
+    wDebug("vgId:%d, wal apply ver:%"PRId64" smaller than commit ver:%"PRId64, pReader->pWal->cfg.vgId, appliedVer, committedVer);
+//    taosMsleep(10);
+  }
+//  int64_t endVer = pReader->cond.scanUncommited ? lastVer : committedVer;
+  int64_t endVer = TMIN(appliedVer, committedVer);
 
   wDebug("vgId:%d, wal start to fetch, index:%" PRId64 ", last index:%" PRId64 " commit index:%" PRId64
-         ", applied index:%" PRId64 ", end index:%" PRId64,
+         ", applied index:%" PRId64", end index:%" PRId64,
          pReader->pWal->cfg.vgId, fetchVer, lastVer, committedVer, appliedVer, endVer);
   while (fetchVer <= endVer) {
     if (walFetchHeadNew(pReader, fetchVer) < 0) {
@@ -244,6 +248,7 @@ static int32_t walFetchHeadNew(SWalReader *pRead, int64_t fetchVer) {
     }
     seeked = true;
   }
+
   while (1) {
     contLen = taosReadFile(pRead->pLogFile, pRead->pHead, sizeof(SWalCkHead));
     if (contLen == sizeof(SWalCkHead)) {
@@ -269,7 +274,7 @@ static int32_t walFetchBodyNew(SWalReader *pReader) {
   SWalCont *pReadHead = &pReader->pHead->head;
   int64_t   ver = pReadHead->version;
 
-  wDebug("vgId:%d, wal starts to fetch body, ver:%" PRId64 " ,len:%d", pReader->pWal->cfg.vgId, ver,
+  wDebug("vgId:%d, wal starts to fetch body, ver:%" PRId64 " ,len:%d, total", pReader->pWal->cfg.vgId, ver,
          pReadHead->bodyLen);
 
   if (pReader->capacity < pReadHead->bodyLen) {
diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c
index 848de4f36d..9b7b3dfd50 100644
--- a/source/libs/wal/src/walWrite.c
+++ b/source/libs/wal/src/walWrite.c
@@ -284,15 +284,15 @@ int32_t walEndSnapshot(SWal *pWal) {
   if (ver == -1) {
     code = -1;
     goto END;
-  };
+  }
 
   pWal->vers.snapshotVer = ver;
   int ts = taosGetTimestampSec();
-
   ver = TMAX(ver - pWal->vers.logRetention, pWal->vers.firstVer - 1);
 
+  // compatible mode for refVer
   bool hasTopic = false;
-  int64_t refVer = ver;
+  int64_t refVer = INT64_MAX;
   void *pIter = NULL;
   while (1) {
     pIter = taosHashIterate(pWal->pRefHash, pIter);
@@ -300,54 +300,40 @@ int32_t walEndSnapshot(SWal *pWal) {
     SWalRef *pRef = *(SWalRef **)pIter;
     if (pRef->refVer == -1) continue;
     refVer = TMIN(refVer, pRef->refVer - 1);
-    wDebug("vgId:%d, wal found ref %" PRId64 ", refId %" PRId64, pWal->cfg.vgId, pRef->refVer, pRef->refId);
     hasTopic = true;
   }
-  // compatible mode
   if (pWal->cfg.retentionPeriod == 0 && hasTopic) {
+    wInfo("vgId:%d, wal found refVer:%" PRId64 " in compatible mode, ver:%" PRId64, pWal->cfg.vgId, refVer, ver);
     ver = TMIN(ver, refVer);
   }
 
+  // find files safe to delete
   int          deleteCnt = 0;
   int64_t      newTotSize = pWal->totSize;
-  SWalFileInfo tmp;
+  SWalFileInfo tmp = {0};
   tmp.firstVer = ver;
-  // find files safe to delete
   SWalFileInfo *pInfo = taosArraySearch(pWal->fileInfoSet, &tmp, compareWalFileInfo, TD_LE);
+
   if (pInfo) {
-    SWalFileInfo *pLastFileInfo = taosArrayGetLast(pWal->fileInfoSet);
-    wDebug("vgId:%d, wal search found file info: first:%" PRId64 " last:%" PRId64, pWal->cfg.vgId, pInfo->firstVer,
-           pInfo->lastVer);
-    if (ver >= pInfo->lastVer) {
+    wDebug("vgId:%d, wal search found file info. ver:%" PRId64 ", first:%" PRId64 " last:%" PRId64, pWal->cfg.vgId, ver,
+           pInfo->firstVer, pInfo->lastVer);
+    ASSERT(ver <= pInfo->lastVer);
+    if (ver == pInfo->lastVer) {
       pInfo++;
-      wDebug("vgId:%d, wal remove advance one file: first:%" PRId64 " last:%" PRId64, pWal->cfg.vgId, pInfo->firstVer,
-             pInfo->lastVer);
-    }
-    if (pInfo <= pLastFileInfo) {
-      wDebug("vgId:%d, wal end remove for first:%" PRId64 " last:%" PRId64, pWal->cfg.vgId, pInfo->firstVer,
-             pInfo->lastVer);
-    } else {
-      wDebug("vgId:%d, wal no remove", pWal->cfg.vgId);
     }
 
     // iterate files, until the searched result
+    // delete according to file size or close time
     for (SWalFileInfo *iter = pWal->fileInfoSet->pData; iter < pInfo; iter++) {
-      wDebug("vgId:%d, wal check remove file %" PRId64 "(file size %" PRId64 " close ts %" PRId64
-             "), new tot size %" PRId64,
-             pWal->cfg.vgId, iter->firstVer, iter->fileSize, iter->closeTs, newTotSize);
-      if ((pWal->cfg.retentionSize != -1 && pWal->cfg.retentionSize != 0 && newTotSize > pWal->cfg.retentionSize) ||
-          ((pWal->cfg.retentionPeriod == 0) || (pWal->cfg.retentionPeriod != -1 && iter->closeTs != -1 &&
-                                                iter->closeTs + pWal->cfg.retentionPeriod < ts))) {
-        // delete according to file size or close time
-        wDebug("vgId:%d, check pass", pWal->cfg.vgId);
+      if ((pWal->cfg.retentionSize > 0 && newTotSize > pWal->cfg.retentionSize) ||
+          (pWal->cfg.retentionPeriod == 0 ||
+           pWal->cfg.retentionPeriod > 0 && iter->closeTs >= 0 && iter->closeTs + pWal->cfg.retentionPeriod < ts)) {
         deleteCnt++;
         newTotSize -= iter->fileSize;
         taosArrayPush(pWal->toDeleteFiles, iter);
       }
-      wDebug("vgId:%d, check not pass", pWal->cfg.vgId);
     }
 
-  UPDATE_META:
     // make new array, remove files
     taosArrayPopFrontBatch(pWal->fileInfoSet, deleteCnt);
     if (taosArrayGetSize(pWal->fileInfoSet) == 0) {
@@ -357,11 +343,12 @@ int32_t walEndSnapshot(SWal *pWal) {
       pWal->vers.firstVer = ((SWalFileInfo *)taosArrayGet(pWal->fileInfoSet, 0))->firstVer;
     }
   }
+
+  // update meta
   pWal->writeCur = taosArrayGetSize(pWal->fileInfoSet) - 1;
   pWal->totSize = newTotSize;
   pWal->vers.verInSnapshotting = -1;
 
-  // save snapshot ver, commit ver
   code = walSaveMeta(pWal);
   if (code < 0) {
     goto END;
@@ -369,23 +356,27 @@ int32_t walEndSnapshot(SWal *pWal) {
 
   // delete files
   deleteCnt = taosArrayGetSize(pWal->toDeleteFiles);
-  wDebug("vgId:%d, wal should delete %d files", pWal->cfg.vgId, deleteCnt);
-  char fnameStr[WAL_FILE_LEN];
+  char fnameStr[WAL_FILE_LEN] = {0};
+  pInfo = NULL;
+
   for (int i = 0; i < deleteCnt; i++) {
     pInfo = taosArrayGet(pWal->toDeleteFiles, i);
+
     walBuildLogName(pWal, pInfo->firstVer, fnameStr);
-    wDebug("vgId:%d, wal remove file %s", pWal->cfg.vgId, fnameStr);
     if (taosRemoveFile(fnameStr) < 0 && errno != ENOENT) {
       wError("vgId:%d, failed to remove log file %s due to %s", pWal->cfg.vgId, fnameStr, strerror(errno));
       goto END;
     }
     walBuildIdxName(pWal, pInfo->firstVer, fnameStr);
-    wDebug("vgId:%d, wal remove file %s", pWal->cfg.vgId, fnameStr);
     if (taosRemoveFile(fnameStr) < 0 && errno != ENOENT) {
       wError("vgId:%d, failed to remove idx file %s due to %s", pWal->cfg.vgId, fnameStr, strerror(errno));
       goto END;
     }
   }
+  if (pInfo != NULL) {
+    wInfo("vgId:%d, wal log files recycled. count:%d, until ver:%" PRId64 ", closeTs:%" PRId64, pWal->cfg.vgId,
+          deleteCnt, pInfo->lastVer, pInfo->closeTs);
+  }
   taosArrayClear(pWal->toDeleteFiles);
 
 END:
diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c
index aab547223f..dd670595f0 100644
--- a/source/os/src/osFile.c
+++ b/source/os/src/osFile.c
@@ -538,10 +538,11 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
     return -1;
   }
 
-  struct stat fileStat;
 #ifdef WINDOWS
-  int32_t code = _fstat(pFile->fd, &fileStat);
+  struct __stat64 fileStat;
+  int32_t code = _fstat64(pFile->fd, &fileStat);
 #else
+  struct stat fileStat;
   int32_t code = fstat(pFile->fd, &fileStat);
 #endif
   if (code < 0) {
diff --git a/source/os/src/osLocale.c b/source/os/src/osLocale.c
index 7008c38576..136b8cf022 100644
--- a/source/os/src/osLocale.c
+++ b/source/os/src/osLocale.c
@@ -171,7 +171,7 @@ void taosGetSystemLocale(char *outLocale, char *outCharset) {
     strcpy(outLocale, "en_US.UTF-8");
   } else {
     tstrncpy(outLocale, locale, TD_LOCALE_LEN);
-    // printf("locale not configured, set to system default:%s", outLocale);
+    //printf("locale not configured, set to system default:%s\n", outLocale);
   }
 
   // if user does not specify the charset, extract it from locale
diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c
index 7d2c8aa4e5..2b2a0daf7b 100644
--- a/source/os/src/osSocket.c
+++ b/source/os/src/osSocket.c
@@ -1008,7 +1008,7 @@ int32_t taosGetFqdn(char *fqdn) {
   // hints.ai_family = AF_INET;
   strcpy(fqdn, hostname);
   strcpy(fqdn + strlen(hostname), ".local");
-#else   // __APPLE__
+#else   // linux
   struct addrinfo  hints = {0};
   struct addrinfo *result = NULL;
   hints.ai_flags = AI_CANONNAME;
@@ -1020,7 +1020,7 @@ int32_t taosGetFqdn(char *fqdn) {
   }
   strcpy(fqdn, result->ai_canonname);
   freeaddrinfo(result);
-#endif  // __APPLE__
+#endif  // linux
 
   return 0;
 }
diff --git a/source/util/src/tarray.c b/source/util/src/tarray.c
index b15bb519e7..f8ce680531 100644
--- a/source/util/src/tarray.c
+++ b/source/util/src/tarray.c
@@ -69,8 +69,6 @@ SArray* taosArrayInit_s(size_t elemSize, size_t initialSize) {
 }
 
 static int32_t taosArrayResize(SArray* pArray) {
-  assert(pArray->size >= pArray->capacity);
-
   size_t size = pArray->capacity;
   size = (size << 1u);
 
@@ -252,12 +250,15 @@ void* taosArrayInsert(SArray* pArray, size_t index, void* pData) {
 }
 
 void taosArraySet(SArray* pArray, size_t index, void* pData) {
-  assert(index < pArray->size);
+  ASSERT(index < pArray->size);
   memcpy(TARRAY_GET_ELEM(pArray, index), pData, pArray->elemSize);
 }
 
 void taosArrayPopFrontBatch(SArray* pArray, size_t cnt) {
-  assert(cnt <= pArray->size);
+  if (cnt > pArray->size) {
+    cnt = pArray->size;
+  }
+
   pArray->size = pArray->size - cnt;
   if (pArray->size == 0 || cnt == 0) {
     return;
@@ -266,12 +267,15 @@ void taosArrayPopFrontBatch(SArray* pArray, size_t cnt) {
 }
 
 void taosArrayPopTailBatch(SArray* pArray, size_t cnt) {
-  assert(cnt <= pArray->size);
+  if (cnt >= pArray->size) {
+    cnt = pArray->size;
+  }
+
   pArray->size = pArray->size - cnt;
 }
 
 void taosArrayRemove(SArray* pArray, size_t index) {
-  assert(index < pArray->size);
+  ASSERT(index < pArray->size);
 
   if (index == pArray->size - 1) {
     taosArrayPop(pArray);
@@ -483,7 +487,8 @@ void* taosDecodeArray(const void* buf, SArray** pArray, FDecode decode, int32_t
 // todo remove it
 // order array
 void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* param) {
-  taosArrayGetSize(pArray) > 8 ? taosArrayQuickSort(pArray, fn, param) : taosArrayInsertSort(pArray, fn, param);
+  taosqsort(pArray->pData, pArray->size, pArray->elemSize, param, fn);
+//  taosArrayGetSize(pArray) > 8 ? taosArrayQuickSort(pArray, fn, param) : taosArrayInsertSort(pArray, fn, param);
 }
 
 void taosArraySwap(SArray* a, SArray* b) {
diff --git a/source/util/src/tcache.c b/source/util/src/tcache.c
index 1d480e7beb..28d9b412a0 100644
--- a/source/util/src/tcache.c
+++ b/source/util/src/tcache.c
@@ -243,11 +243,6 @@ static FORCE_INLINE STrashElem *doRemoveElemInTrashcan(SCacheObj *pCacheObj, STr
   if (next) {
     next->prev = pElem->prev;
   }
-
-  if (pCacheObj->numOfElemsInTrash == 0) {
-    assert(pCacheObj->pTrash == NULL);
-  }
-
   return next;
 }
 
@@ -261,8 +256,6 @@ static FORCE_INLINE void doDestroyTrashcanElem(SCacheObj *pCacheObj, STrashElem
 }
 
 static void pushfrontNodeInEntryList(SCacheEntry *pEntry, SCacheNode *pNode) {
-  assert(pNode != NULL && pEntry != NULL);
-
   pNode->pNext = pEntry->next;
   pEntry->next = pNode;
   pEntry->num += 1;
@@ -271,7 +264,6 @@ static void pushfrontNodeInEntryList(SCacheEntry *pEntry, SCacheNode *pNode) {
 
 static void removeNodeInEntryList(SCacheEntry *pe, SCacheNode *prev, SCacheNode *pNode) {
   if (prev == NULL) {
-    ASSERT(pe->next == pNode);
     pe->next = pNode->pNext;
   } else {
     prev->pNext = pNode->pNext;
@@ -471,7 +463,6 @@ void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen
   SCacheNode *pNode = doSearchInEntryList(pe, key, keyLen, &prev);
   if (pNode != NULL) {
     int32_t ref = T_REF_INC(pNode);
-    ASSERT(ref > 0);
   }
 
   taosRUnLockLatch(&pe->latch);
@@ -503,7 +494,7 @@ void *taosCacheAcquireByData(SCacheObj *pCacheObj, void *data) {
   uDebug("cache:%s, data: %p acquired by data in cache, refcnt:%d", pCacheObj->name, ptNode->data, ref);
 
   // the data if referenced by at least one object, so the reference count must be greater than the value of 2.
-  assert(ref >= 2);
+  ASSERT(ref >= 2);
   return data;
 }
 
@@ -516,7 +507,6 @@ void *taosCacheTransferData(SCacheObj *pCacheObj, void **data) {
     return NULL;
   }
 
-  assert(T_REF_VAL_GET(ptNode) >= 1);
   char *d = *data;
 
   // clear its reference to old area
@@ -575,19 +565,19 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
       if (ref == 1) {
         // If it is the last ref, remove it from trashcan linked-list first, and then destroy it.Otherwise, it may be
         // destroyed by refresh worker if decrease ref count before removing it from linked-list.
-        assert(pNode->pTNodeHeader->pData == pNode);
+        ASSERT(pNode->pTNodeHeader->pData == pNode);
 
         __trashcan_wr_lock(pCacheObj);
         doRemoveElemInTrashcan(pCacheObj, pNode->pTNodeHeader);
         __trashcan_unlock(pCacheObj);
 
         ref = T_REF_DEC(pNode);
-        assert(ref == 0);
+        ASSERT(ref == 0);
 
         doDestroyTrashcanElem(pCacheObj, pNode->pTNodeHeader);
       } else {
         ref = T_REF_DEC(pNode);
-        assert(ref >= 0);
+        ASSERT(ref >= 0);
       }
     } else {
       // NOTE: remove it from hash in the first place, otherwise, the pNode may have been released by other thread
@@ -609,13 +599,12 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
               "others already, prev must in trashcan",
               pCacheObj->name, pNode->key, p->data, T_REF_VAL_GET(p), pNode->data, T_REF_VAL_GET(pNode));
 
-          assert(p->pTNodeHeader == NULL && pNode->pTNodeHeader != NULL);
+          ASSERT(p->pTNodeHeader == NULL && pNode->pTNodeHeader != NULL);
         } else {
           removeNodeInEntryList(pe, prev, p);
           uDebug("cache:%s, key:%p, %p successfully removed from hash table, refcnt:%d", pCacheObj->name, pNode->key,
                  pNode->data, ref);
           if (ref > 0) {
-            assert(pNode->pTNodeHeader == NULL);
             taosAddToTrashcan(pCacheObj, pNode);
           } else {  // ref == 0
             atomic_sub_fetch_64(&pCacheObj->sizeInBytes, pNode->size);
@@ -736,7 +725,7 @@ SCacheNode *taosCreateCacheNode(const char *key, size_t keyLen, const char *pDat
 
 void taosAddToTrashcan(SCacheObj *pCacheObj, SCacheNode *pNode) {
   if (pNode->inTrashcan) { /* node is already in trash */
-    assert(pNode->pTNodeHeader != NULL && pNode->pTNodeHeader->pData == pNode);
+    ASSERT(pNode->pTNodeHeader != NULL && pNode->pTNodeHeader->pData == pNode);
     return;
   }
 
@@ -782,7 +771,7 @@ void taosTrashcanEmpty(SCacheObj *pCacheObj, bool force) {
   STrashElem *pElem = pCacheObj->pTrash;
   while (pElem) {
     T_REF_VAL_CHECK(pElem->pData);
-    assert(pElem->next != pElem && pElem->prev != pElem);
+    ASSERT(pElem->next != pElem && pElem->prev != pElem);
 
     if (force || (T_REF_VAL_GET(pElem->pData) == 0)) {
       uDebug("cache:%s, key:%p, %p removed from trashcan. numOfElem in trashcan:%d", pCacheObj->name, pElem->pData->key,
@@ -814,8 +803,6 @@ void doCleanupDataCache(SCacheObj *pCacheObj) {
 }
 
 static void doCacheRefresh(SCacheObj *pCacheObj, int64_t time, __cache_trav_fn_t fp, void *param1) {
-  assert(pCacheObj != NULL);
-
   SCacheObjTravSup sup = {.pCacheObj = pCacheObj, .fp = fp, .time = time, .param1 = param1};
   doTraverseElems(pCacheObj, doRemoveExpiredFn, &sup);
 }
@@ -827,9 +814,7 @@ void taosCacheRefreshWorkerUnexpectedStopped(void) {
 }
 
 void *taosCacheTimedRefresh(void *handle) {
-  assert(pCacheArrayList != NULL);
   uDebug("cache refresh thread starts");
-
   setThreadName("cacheRefresh");
 
   const int32_t SLEEP_DURATION = 500;  // 500 ms
@@ -928,7 +913,6 @@ void taosStopCacheRefreshWorker(void) {
 size_t taosCacheGetNumOfObj(const SCacheObj *pCacheObj) { return pCacheObj->numOfElems + pCacheObj->numOfElemsInTrash; }
 
 SCacheIter *taosCacheCreateIter(const SCacheObj *pCacheObj) {
-  ASSERT(pCacheObj != NULL);
   SCacheIter *pIter = taosMemoryCalloc(1, sizeof(SCacheIter));
   pIter->pCacheObj = (SCacheObj *)pCacheObj;
   pIter->entryIndex = -1;
@@ -978,12 +962,8 @@ bool taosCacheIterNext(SCacheIter *pIter) {
 
       SCacheNode *pNode = pEntry->next;
       for (int32_t i = 0; i < pEntry->num; ++i) {
-        ASSERT(pNode != NULL);
-
         pIter->pCurrent[i] = pNode;
         int32_t ref = T_REF_INC(pIter->pCurrent[i]);
-        ASSERT(ref >= 1);
-
         pNode = pNode->pNext;
       }
 
diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c
index be2ad730f7..d6f0e898ef 100644
--- a/source/util/src/tcompare.c
+++ b/source/util/src/tcompare.c
@@ -308,17 +308,19 @@ int32_t compareInt8Uint16(const void *pLeft, const void *pRight) {
 
 int32_t compareInt8Uint32(const void *pLeft, const void *pRight) {
   int8_t   left = GET_INT8_VAL(pLeft);
+  if (left < 0) return -1;
   uint32_t right = GET_UINT32_VAL(pRight);
-  if (left > right) return 1;
-  if (left < right) return -1;
+  if ((uint32_t)left > right) return 1;
+  if ((uint32_t)left < right) return -1;
   return 0;
 }
 
 int32_t compareInt8Uint64(const void *pLeft, const void *pRight) {
   int8_t   left = GET_INT8_VAL(pLeft);
+  if (left < 0) return -1;
   uint64_t right = GET_UINT64_VAL(pRight);
-  if (left > right) return 1;
-  if (left < right) return -1;
+  if ((uint64_t)left > right) return 1;
+  if ((uint64_t)left < right) return -1;
   return 0;
 }
 
@@ -380,17 +382,19 @@ int32_t compareInt16Uint16(const void *pLeft, const void *pRight) {
 
 int32_t compareInt16Uint32(const void *pLeft, const void *pRight) {
   int16_t  left = GET_INT16_VAL(pLeft);
+  if (left < 0) return -1;
   uint32_t right = GET_UINT32_VAL(pRight);
-  if (left > right) return 1;
-  if (left < right) return -1;
+  if ((uint32_t)left > right) return 1;
+  if ((uint32_t)left < right) return -1;
   return 0;
 }
 
 int32_t compareInt16Uint64(const void *pLeft, const void *pRight) {
   int16_t  left = GET_INT16_VAL(pLeft);
+  if (left < 0) return -1;
   uint64_t right = GET_UINT64_VAL(pRight);
-  if (left > right) return 1;
-  if (left < right) return -1;
+  if ((uint64_t)left > right) return 1;
+  if ((uint64_t)left < right) return -1;
   return 0;
 }
 
@@ -452,17 +456,19 @@ int32_t compareInt32Uint16(const void *pLeft, const void *pRight) {
 
 int32_t compareInt32Uint32(const void *pLeft, const void *pRight) {
   int32_t  left = GET_INT32_VAL(pLeft);
+  if (left < 0) return -1;
   uint32_t right = GET_UINT32_VAL(pRight);
-  if (left > right) return 1;
-  if (left < right) return -1;
+  if ((uint32_t)left > right) return 1;
+  if ((uint32_t)left < right) return -1;
   return 0;
 }
 
 int32_t compareInt32Uint64(const void *pLeft, const void *pRight) {
   int32_t  left = GET_INT32_VAL(pLeft);
+  if (left < 0) return -1;
   uint64_t right = GET_UINT64_VAL(pRight);
-  if (left > right) return 1;
-  if (left < right) return -1;
+  if ((uint64_t)left > right) return 1;
+  if ((uint64_t)left < right) return -1;
   return 0;
 }
 
@@ -532,9 +538,10 @@ int32_t compareInt64Uint32(const void *pLeft, const void *pRight) {
 
 int32_t compareInt64Uint64(const void *pLeft, const void *pRight) {
   int64_t  left = GET_INT64_VAL(pLeft);
+  if (left < 0) return -1;
   uint64_t right = GET_UINT64_VAL(pRight);
-  if (left > right) return 1;
-  if (left < right) return -1;
+  if ((uint64_t)left > right) return 1;
+  if ((uint64_t)left < right) return -1;
   return 0;
 }
 
@@ -857,24 +864,27 @@ int32_t compareUint16Uint64(const void *pLeft, const void *pRight) {
 int32_t compareUint32Int8(const void *pLeft, const void *pRight) {
   uint32_t left = GET_UINT32_VAL(pLeft);
   int8_t   right = GET_INT8_VAL(pRight);
-  if (left > right) return 1;
-  if (left < right) return -1;
+  if (right < 0) return 1;
+  if (left > (uint32_t)right) return 1;
+  if (left < (uint32_t)right) return -1;
   return 0;
 }
 
 int32_t compareUint32Int16(const void *pLeft, const void *pRight) {
   uint32_t left = GET_UINT32_VAL(pLeft);
   int16_t  right = GET_INT16_VAL(pRight);
-  if (left > right) return 1;
-  if (left < right) return -1;
+  if (right < 0) return 1;
+  if (left > (uint32_t)right) return 1;
+  if (left < (uint32_t)right) return -1;
   return 0;
 }
 
 int32_t compareUint32Int32(const void *pLeft, const void *pRight) {
   uint32_t left = GET_UINT32_VAL(pLeft);
   int32_t  right = GET_INT32_VAL(pRight);
-  if (left > right) return 1;
-  if (left < right) return -1;
+  if (right < 0) return 1;
+  if (left > (uint32_t)right) return 1;
+  if (left < (uint32_t)right) return -1;
   return 0;
 }
 
@@ -929,32 +939,36 @@ int32_t compareUint32Uint64(const void *pLeft, const void *pRight) {
 int32_t compareUint64Int8(const void *pLeft, const void *pRight) {
   uint64_t left = GET_UINT64_VAL(pLeft);
   int8_t   right = GET_INT8_VAL(pRight);
-  if (left > right) return 1;
-  if (left < right) return -1;
+  if (right < 0) return 1;
+  if (left > (uint64_t)right) return 1;
+  if (left < (uint64_t)right) return -1;
   return 0;
 }
 
 int32_t compareUint64Int16(const void *pLeft, const void *pRight) {
   uint64_t left = GET_UINT64_VAL(pLeft);
   int16_t  right = GET_INT16_VAL(pRight);
-  if (left > right) return 1;
-  if (left < right) return -1;
+  if (right < 0) return 1;
+  if (left > (uint64_t)right) return 1;
+  if (left < (uint64_t)right) return -1;
   return 0;
 }
 
 int32_t compareUint64Int32(const void *pLeft, const void *pRight) {
   uint64_t left = GET_UINT64_VAL(pLeft);
   int32_t  right = GET_INT32_VAL(pRight);
-  if (left > right) return 1;
-  if (left < right) return -1;
+  if (right < 0) return 1;
+  if (left > (uint64_t)right) return 1;
+  if (left < (uint64_t)right) return -1;
   return 0;
 }
 
 int32_t compareUint64Int64(const void *pLeft, const void *pRight) {
   uint64_t left = GET_UINT64_VAL(pLeft);
   int64_t  right = GET_INT64_VAL(pRight);
-  if (left > right) return 1;
-  if (left < right) return -1;
+  if (right < 0) return 1;
+  if (left > (uint64_t)right) return 1;
+  if (left < (uint64_t)right) return -1;
   return 0;
 }
 
diff --git a/source/util/src/terror.c b/source/util/src/terror.c
index 2b54c41c3d..e12e451f9e 100644
--- a/source/util/src/terror.c
+++ b/source/util/src/terror.c
@@ -123,7 +123,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NO_WRITE_AUTH,            "No write permission")
 TAOS_DEFINE_ERROR(TSDB_CODE_TSC_CONN_KILLED,              "Connection killed")
 TAOS_DEFINE_ERROR(TSDB_CODE_TSC_SQL_SYNTAX_ERROR,         "Syntax error in SQL")
 TAOS_DEFINE_ERROR(TSDB_CODE_TSC_DB_NOT_SELECTED,          "Database not specified or available")
-TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_TABLE_NAME,       "Table does not exist")
+//TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_TABLE_NAME,       "Table does not exist")
 TAOS_DEFINE_ERROR(TSDB_CODE_TSC_EXCEED_SQL_LIMIT,         "SQL statement too long")
 TAOS_DEFINE_ERROR(TSDB_CODE_TSC_FILE_EMPTY,               "File is empty")
 TAOS_DEFINE_ERROR(TSDB_CODE_TSC_LINE_SYNTAX_ERROR,        "Syntax error in Line")
@@ -204,6 +204,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_COLUMN_ALREADY_EXIST,     "Column already exists
 TAOS_DEFINE_ERROR(TSDB_CODE_MND_COLUMN_NOT_EXIST,         "Column does not exist")
 TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_STB_OPTION,       "Invalid stable options")
 TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ROW_BYTES,        "Invalid row bytes")
+TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_VALUE_OVERFLOW,          "out of range and overflow")
 
 // mnode-func
 TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_FUNC_NAME,        "Invalid func name")
diff --git a/source/util/src/thash.c b/source/util/src/thash.c
index 926dc304a4..cf4f17bfbc 100644
--- a/source/util/src/thash.c
+++ b/source/util/src/thash.c
@@ -150,7 +150,6 @@ static FORCE_INLINE SHashNode *doSearchInEntryList(SHashObj *pHashObj, SHashEntr
     //atomic_add_fetch_64(&pHashObj->compTimes, 1);
     if ((pNode->keyLen == keyLen) && ((*(pHashObj->equalFp))(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0) &&
         pNode->removed == 0) {
-      assert(pNode->hashVal == hashVal);
       break;
     }
 
@@ -189,8 +188,6 @@ static SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *p
  */
 static FORCE_INLINE void doUpdateHashNode(SHashObj *pHashObj, SHashEntry *pe, SHashNode *prev, SHashNode *pNode,
                                           SHashNode *pNewNode) {
-  assert(pNode->keyLen == pNewNode->keyLen);
-
   atomic_sub_fetch_16(&pNode->refCount, 1);
   if (prev != NULL) {
     prev->next = pNewNode;
@@ -236,7 +233,7 @@ static FORCE_INLINE bool taosHashTableEmpty(const SHashObj *pHashObj) { return t
 
 SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool update, SHashLockTypeE type) {
   if (fn == NULL) {
-    assert(0);
+    terrno = TSDB_CODE_INVALID_PARA;
     return NULL;
   }
 
@@ -262,8 +259,6 @@ SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool update, SHashLockTyp
   pHashObj->freeFp = NULL;
   pHashObj->callbackFp = NULL;
 
-  ASSERT((pHashObj->capacity & (pHashObj->capacity - 1)) == 0);
-
   pHashObj->hashList = (SHashEntry **)taosMemoryMalloc(pHashObj->capacity * sizeof(void *));
   if (pHashObj->hashList == NULL) {
     taosMemoryFree(pHashObj);
@@ -342,19 +337,10 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, const vo
   taosHashEntryWLock(pHashObj, pe);
 
   SHashNode *pNode = pe->next;
-#if 0
-  if (pe->num > 0) {
-    assert(pNode != NULL);
-  } else {
-    assert(pNode == NULL);
-  }
-#endif
-
   SHashNode *prev = NULL;
   while (pNode) {
     if ((pNode->keyLen == keyLen) && (*(pHashObj->equalFp))(GET_HASH_NODE_KEY(pNode), key, keyLen) == 0 &&
         pNode->removed == 0) {
-      assert(pNode->hashVal == hashVal);
       break;
     }
 
@@ -370,8 +356,6 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, const vo
     }
 
     pushfrontNodeInEntryList(pe, pNewNode);
-    assert(pe->next != NULL);
-
     taosHashEntryWUnlock(pHashObj, pe);
 
     // enable resize
@@ -446,14 +430,6 @@ void *taosHashGetImpl(SHashObj *pHashObj, const void *key, size_t keyLen, void *
   char *data = NULL;
   taosHashEntryRLock(pHashObj, pe);
 
-#if 0
-  if (pe->num > 0) {
-    assert(pe->next != NULL);
-  } else {
-    assert(pe->next == NULL);
-  }
-#endif
-
   SHashNode *pNode = doSearchInEntryList(pHashObj, pe, key, keyLen, hashVal);
   if (pNode != NULL) {
     if (pHashObj->callbackFp != NULL) {
@@ -514,8 +490,6 @@ int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen) {
 
   // double check after locked
   if (pe->num == 0) {
-    assert(pe->next == NULL);
-
     taosHashEntryWUnlock(pHashObj, pe);
     taosHashRUnlock(pHashObj);
     return -1;
@@ -568,13 +542,10 @@ void taosHashClear(SHashObj *pHashObj) {
   for (int32_t i = 0; i < pHashObj->capacity; ++i) {
     SHashEntry *pEntry = pHashObj->hashList[i];
     if (pEntry->num == 0) {
-      assert(pEntry->next == NULL);
       continue;
     }
 
     pNode = pEntry->next;
-    assert(pNode != NULL);
-
     while (pNode) {
       pNext = pNode->next;
       FREE_HASH_NODE(pHashObj->freeFp, pNode);
@@ -671,14 +642,11 @@ void taosHashTableResize(SHashObj *pHashObj) {
     SHashNode  *pPrev = NULL;
 
     if (pe->num == 0) {
-      assert(pe->next == NULL);
       continue;
     }
 
     pNode = pe->next;
 
-    assert(pNode != NULL);
-
     while (pNode != NULL) {
       int32_t newIdx = HASH_INDEX(pNode->hashVal, pHashObj->capacity);
       pNext = pNode->next;
@@ -728,12 +696,8 @@ SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *pData, s
 }
 
 void pushfrontNodeInEntryList(SHashEntry *pEntry, SHashNode *pNode) {
-  assert(pNode != NULL && pEntry != NULL);
-
   pNode->next = pEntry->next;
   pEntry->next = pNode;
-
-  ASSERT(pNode->next != pNode);
   pEntry->num += 1;
 }
 
@@ -847,19 +811,7 @@ void *taosHashIterate(SHashObj *pHashObj, void *p) {
 
     /*uint16_t prevRef = atomic_load_16(&pNode->refCount);*/
     uint16_t afterRef = atomic_add_fetch_16(&pNode->refCount, 1);
-#if 0
-    ASSERT(prevRef < afterRef);
 
-    // the reference count value is overflow, which will cause the delete node operation immediately.
-    if (prevRef > afterRef) {
-      uError("hash entry ref count overflow, prev ref:%d, current ref:%d", prevRef, afterRef);
-      // restore the value
-      atomic_sub_fetch_16(&pNode->refCount, 1);
-      data = NULL;
-    } else {
-      data = GET_HASH_NODE_DATA(pNode);
-    }
-#endif
     data = GET_HASH_NODE_DATA(pNode);
 
     if (afterRef >= MAX_WARNING_REF_COUNT) {
diff --git a/source/util/src/tlist.c b/source/util/src/tlist.c
index 1b12ea0cdd..5d729d27d6 100644
--- a/source/util/src/tlist.c
+++ b/source/util/src/tlist.c
@@ -104,7 +104,6 @@ SListNode *tdListPopNode(SList *list, SListNode *node) {
 
 // Move all node elements from src to dst, the dst is assumed as an empty list
 void tdListMove(SList *src, SList *dst) {
-  // assert(dst->eleSize == src->eleSize);
   SListNode *node = NULL;
   while ((node = tdListPopHead(src)) != NULL) {
     tdListAppendNode(dst, node);
diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c
index baf6a9f319..c8ac15786f 100644
--- a/source/util/src/tlog.c
+++ b/source/util/src/tlog.c
@@ -17,7 +17,6 @@
 #include "tlog.h"
 #include "os.h"
 #include "tconfig.h"
-#include "tutil.h"
 #include "tjson.h"
 #include "tglobal.h"
 
@@ -391,7 +390,6 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
 
   char    name[LOG_FILE_NAME_LEN + 50] = "\0";
   int32_t logstat0_mtime, logstat1_mtime;
-  int32_t size;
 
   tsLogObj.maxLines = maxLines;
   tsLogObj.fileNum = maxFileNum;
@@ -439,8 +437,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
     printf("\nfailed to fstat log file:%s, reason:%s\n", fileName, strerror(errno));
     return -1;
   }
-  size = (int32_t)filesize;
-  tsLogObj.lines = size / 60;
+  tsLogObj.lines = (int32_t)(filesize / 60);
 
   taosLSeekFile(tsLogObj.logHandle->pFile, 0, SEEK_END);
 
@@ -845,65 +842,6 @@ bool taosAssertDebug(bool condition, const char *file, int32_t line, const char
   return true;
 }
 
-int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t startTime) {
-  SJson* pJson = tjsonCreateObject();
-  if (pJson == NULL) return -1;
-  char tmp[4096] = {0};
-
-  tjsonAddDoubleToObject(pJson, "reportVersion", 1);
-
-  tjsonAddIntegerToObject(pJson, "clusterId", clusterId);
-  tjsonAddIntegerToObject(pJson, "startTime", startTime);
-
-  taosGetFqdn(tmp);  
-  tjsonAddStringToObject(pJson, "fqdn", tmp);
-  
-  tjsonAddIntegerToObject(pJson, "pid", taosGetPId());
-
-  taosGetAppName(tmp, NULL);
-  tjsonAddStringToObject(pJson, "appName", tmp);  
-
-  if (taosGetOsReleaseName(tmp, sizeof(tmp)) == 0) {
-    tjsonAddStringToObject(pJson, "os", tmp);
-  }
-
-  float numOfCores = 0;
-  if (taosGetCpuInfo(tmp, sizeof(tmp), &numOfCores) == 0) {
-    tjsonAddStringToObject(pJson, "cpuModel", tmp);
-    tjsonAddDoubleToObject(pJson, "numOfCpu", numOfCores);
-  } else {
-    tjsonAddDoubleToObject(pJson, "numOfCpu", tsNumOfCores);
-  }
-
-  snprintf(tmp, sizeof(tmp), "%" PRId64 " kB", tsTotalMemoryKB);
-  tjsonAddStringToObject(pJson, "memory", tmp);
-
-  tjsonAddStringToObject(pJson, "version", version);
-  tjsonAddStringToObject(pJson, "buildInfo", buildinfo);
-  tjsonAddStringToObject(pJson, "gitInfo", gitinfo);
-
-  tjsonAddIntegerToObject(pJson, "crashSig", signum);
-  tjsonAddIntegerToObject(pJson, "crashTs", taosGetTimestampUs());
-
-#ifdef _TD_DARWIN_64
-  taosLogTraceToBuf(tmp, sizeof(tmp), 4);
-#elif !defined(WINDOWS)
-  taosLogTraceToBuf(tmp, sizeof(tmp), 3);
-#else
-  taosLogTraceToBuf(tmp, sizeof(tmp), 8);
-#endif
-
-  tjsonAddStringToObject(pJson, "stackInfo", tmp);
-  
-  char* pCont = tjsonToString(pJson);
-  tjsonDelete(pJson);
-
-  *pMsg = pCont;
-
-  return TSDB_CODE_SUCCESS;
-}
-
-
 void taosLogCrashInfo(char* nodeType, char* pMsg, int64_t msgLen, int signum, void *sigInfo) {
   const char *flags = "UTL FATAL ";
   ELogLevel   level = DEBUG_FATAL;
diff --git a/source/util/src/tlosertree.c b/source/util/src/tlosertree.c
index bf99212b78..c476baa790 100644
--- a/source/util/src/tlosertree.c
+++ b/source/util/src/tlosertree.c
@@ -115,8 +115,6 @@ void tMergeTreeAdjust(SMultiwayMergeTreeInfo* pTree, int32_t idx) {
 }
 
 void tMergeTreeRebuild(SMultiwayMergeTreeInfo* pTree) {
-  ASSERT((pTree->totalSources & 0x1) == 0);
-
   tMergeTreeInit(pTree);
   for (int32_t i = pTree->totalSources - 1; i >= pTree->numOfSources; i--) {
     tMergeTreeAdjust(pTree, i);
diff --git a/source/util/src/tlrucache.c b/source/util/src/tlrucache.c
index f4172fbb44..e182800d9c 100644
--- a/source/util/src/tlrucache.c
+++ b/source/util/src/tlrucache.c
@@ -85,13 +85,13 @@ struct SLRUEntry {
 #define TAOS_LRU_ENTRY_REF(h)      (++(h)->refs)
 
 static bool taosLRUEntryUnref(SLRUEntry *entry) {
-  assert(entry->refs > 0);
+  ASSERT(entry->refs > 0);
   --entry->refs;
   return entry->refs == 0;
 }
 
 static void taosLRUEntryFree(SLRUEntry *entry) {
-  assert(entry->refs == 0);
+  ASSERT(entry->refs == 0);
 
   if (entry->deleter) {
     (*entry->deleter)(entry->keyData, entry->keyLength, entry->value);
@@ -127,7 +127,7 @@ static void taosLRUEntryTableApply(SLRUEntryTable *table, _taos_lru_table_func_t
     SLRUEntry *h = table->list[i];
     while (h) {
       SLRUEntry *n = h->nextHash;
-      assert(TAOS_LRU_ENTRY_IN_CACHE(h));
+      ASSERT(TAOS_LRU_ENTRY_IN_CACHE(h));
       func(h);
       h = n;
     }
@@ -184,7 +184,7 @@ static void taosLRUEntryTableResize(SLRUEntryTable *table) {
       ++count;
     }
   }
-  assert(table->elems == count);
+  ASSERT(table->elems == count);
 
   taosMemoryFree(table->list);
   table->list = newList;
@@ -240,17 +240,16 @@ struct SLRUCacheShard {
 static void taosLRUCacheShardMaintainPoolSize(SLRUCacheShard *shard) {
   while (shard->highPriPoolUsage > shard->highPriPoolCapacity) {
     shard->lruLowPri = shard->lruLowPri->next;
-    assert(shard->lruLowPri != &shard->lru);
+    ASSERT(shard->lruLowPri != &shard->lru);
     TAOS_LRU_ENTRY_SET_IN_HIGH_POOL(shard->lruLowPri, false);
 
-    assert(shard->highPriPoolUsage >= shard->lruLowPri->totalCharge);
+    ASSERT(shard->highPriPoolUsage >= shard->lruLowPri->totalCharge);
     shard->highPriPoolUsage -= shard->lruLowPri->totalCharge;
   }
 }
 
 static void taosLRUCacheShardLRUInsert(SLRUCacheShard *shard, SLRUEntry *e) {
-  assert(e->next == NULL);
-  assert(e->prev == NULL);
+  ASSERT(e->next == NULL && e->prev == NULL);
 
   if (shard->highPriPoolRatio > 0 && (TAOS_LRU_ENTRY_IS_HIGH_PRI(e) || TAOS_LRU_ENTRY_HAS_HIT(e))) {
     e->next = &shard->lru;
@@ -277,8 +276,7 @@ static void taosLRUCacheShardLRUInsert(SLRUCacheShard *shard, SLRUEntry *e) {
 }
 
 static void taosLRUCacheShardLRURemove(SLRUCacheShard *shard, SLRUEntry *e) {
-  assert(e->next);
-  assert(e->prev);
+  ASSERT(e->next && e->prev);
 
   if (shard->lruLowPri == e) {
     shard->lruLowPri = e->prev;
@@ -287,10 +285,10 @@ static void taosLRUCacheShardLRURemove(SLRUCacheShard *shard, SLRUEntry *e) {
   e->prev->next = e->next;
   e->prev = e->next = NULL;
 
-  assert(shard->lruUsage >= e->totalCharge);
+  ASSERT(shard->lruUsage >= e->totalCharge);
   shard->lruUsage -= e->totalCharge;
   if (TAOS_LRU_ENTRY_IN_HIGH_POOL(e)) {
-    assert(shard->highPriPoolUsage >= e->totalCharge);
+    ASSERT(shard->highPriPoolUsage >= e->totalCharge);
     shard->highPriPoolUsage -= e->totalCharge;
   }
 }
@@ -298,13 +296,13 @@ static void taosLRUCacheShardLRURemove(SLRUCacheShard *shard, SLRUEntry *e) {
 static void taosLRUCacheShardEvictLRU(SLRUCacheShard *shard, size_t charge, SArray *deleted) {
   while (shard->usage + charge > shard->capacity && shard->lru.next != &shard->lru) {
     SLRUEntry *old = shard->lru.next;
-    assert(TAOS_LRU_ENTRY_IN_CACHE(old) && !TAOS_LRU_ENTRY_HAS_REFS(old));
+    ASSERT(TAOS_LRU_ENTRY_IN_CACHE(old) && !TAOS_LRU_ENTRY_HAS_REFS(old));
 
     taosLRUCacheShardLRURemove(shard, old);
     taosLRUEntryTableRemove(&shard->table, old->keyData, old->keyLength, old->hash);
 
     TAOS_LRU_ENTRY_SET_IN_CACHE(old, false);
-    assert(shard->usage >= old->totalCharge);
+    ASSERT(shard->usage >= old->totalCharge);
     shard->usage -= old->totalCharge;
 
     taosArrayPush(deleted, &old);
@@ -391,11 +389,11 @@ static LRUStatus taosLRUCacheShardInsertEntry(SLRUCacheShard *shard, SLRUEntry *
     if (old != NULL) {
       status = TAOS_LRU_STATUS_OK_OVERWRITTEN;
 
-      assert(TAOS_LRU_ENTRY_IN_CACHE(old));
+      ASSERT(TAOS_LRU_ENTRY_IN_CACHE(old));
       TAOS_LRU_ENTRY_SET_IN_CACHE(old, false);
       if (!TAOS_LRU_ENTRY_HAS_REFS(old)) {
         taosLRUCacheShardLRURemove(shard, old);
-        assert(shard->usage >= old->totalCharge);
+        ASSERT(shard->usage >= old->totalCharge);
         shard->usage -= old->totalCharge;
 
         taosArrayPush(lastReferenceList, &old);
@@ -455,7 +453,7 @@ static LRUHandle *taosLRUCacheShardLookup(SLRUCacheShard *shard, const void *key
   taosThreadMutexLock(&shard->mutex);
   e = taosLRUEntryTableLookup(&shard->table, key, keyLen, hash);
   if (e != NULL) {
-    assert(TAOS_LRU_ENTRY_IN_CACHE(e));
+    ASSERT(TAOS_LRU_ENTRY_IN_CACHE(e));
     if (!TAOS_LRU_ENTRY_HAS_REFS(e)) {
       taosLRUCacheShardLRURemove(shard, e);
     }
@@ -474,12 +472,12 @@ static void taosLRUCacheShardErase(SLRUCacheShard *shard, const void *key, size_
 
   SLRUEntry *e = taosLRUEntryTableRemove(&shard->table, key, keyLen, hash);
   if (e != NULL) {
-    assert(TAOS_LRU_ENTRY_IN_CACHE(e));
+    ASSERT(TAOS_LRU_ENTRY_IN_CACHE(e));
     TAOS_LRU_ENTRY_SET_IN_CACHE(e, false);
     if (!TAOS_LRU_ENTRY_HAS_REFS(e)) {
       taosLRUCacheShardLRURemove(shard, e);
 
-      assert(shard->usage >= e->totalCharge);
+      ASSERT(shard->usage >= e->totalCharge);
       shard->usage -= e->totalCharge;
       lastReference = true;
     }
@@ -499,11 +497,11 @@ static void taosLRUCacheShardEraseUnrefEntries(SLRUCacheShard *shard) {
 
   while (shard->lru.next != &shard->lru) {
     SLRUEntry *old = shard->lru.next;
-    assert(TAOS_LRU_ENTRY_IN_CACHE(old) && !TAOS_LRU_ENTRY_HAS_REFS(old));
+    ASSERT(TAOS_LRU_ENTRY_IN_CACHE(old) && !TAOS_LRU_ENTRY_HAS_REFS(old));
     taosLRUCacheShardLRURemove(shard, old);
     taosLRUEntryTableRemove(&shard->table, old->keyData, old->keyLength, old->hash);
     TAOS_LRU_ENTRY_SET_IN_CACHE(old, false);
-    assert(shard->usage >= old->totalCharge);
+    ASSERT(shard->usage >= old->totalCharge);
     shard->usage -= old->totalCharge;
 
     taosArrayPush(lastReferenceList, &old);
@@ -524,7 +522,7 @@ static bool taosLRUCacheShardRef(SLRUCacheShard *shard, LRUHandle *handle) {
   SLRUEntry *e = (SLRUEntry *)handle;
   taosThreadMutexLock(&shard->mutex);
 
-  assert(TAOS_LRU_ENTRY_HAS_REFS(e));
+  ASSERT(TAOS_LRU_ENTRY_HAS_REFS(e));
   TAOS_LRU_ENTRY_REF(e);
 
   taosThreadMutexUnlock(&shard->mutex);
@@ -545,7 +543,7 @@ static bool taosLRUCacheShardRelease(SLRUCacheShard *shard, LRUHandle *handle, b
   lastReference = taosLRUEntryUnref(e);
   if (lastReference && TAOS_LRU_ENTRY_IN_CACHE(e)) {
     if (shard->usage > shard->capacity || eraseIfLastRef) {
-      assert(shard->lru.next == &shard->lru || eraseIfLastRef);
+      ASSERT(shard->lru.next == &shard->lru || eraseIfLastRef);
 
       taosLRUEntryTableRemove(&shard->table, e->keyData, e->keyLength, e->hash);
       TAOS_LRU_ENTRY_SET_IN_CACHE(e, false);
@@ -557,7 +555,7 @@ static bool taosLRUCacheShardRelease(SLRUCacheShard *shard, LRUHandle *handle, b
   }
 
   if (lastReference && e->value) {
-    assert(shard->usage >= e->totalCharge);
+    ASSERT(shard->usage >= e->totalCharge);
     shard->usage -= e->totalCharge;
   }
 
@@ -595,7 +593,7 @@ static size_t taosLRUCacheShardGetPinnedUsage(SLRUCacheShard *shard) {
 
   taosThreadMutexLock(&shard->mutex);
 
-  assert(shard->usage >= shard->lruUsage);
+  ASSERT(shard->usage >= shard->lruUsage);
   usage = shard->usage - shard->lruUsage;
 
   taosThreadMutexUnlock(&shard->mutex);
@@ -687,7 +685,7 @@ void taosLRUCacheCleanup(SLRUCache *cache) {
   if (cache) {
     if (cache->shards) {
       int numShards = cache->numShards;
-      assert(numShards > 0);
+      ASSERT(numShards > 0);
       for (int i = 0; i < numShards; ++i) {
         taosLRUCacheShardCleanup(&cache->shards[i]);
       }
diff --git a/source/util/src/tsched.c b/source/util/src/tsched.c
index 467f26b362..5c1706e405 100644
--- a/source/util/src/tsched.c
+++ b/source/util/src/tsched.c
@@ -137,7 +137,6 @@ void *taosProcessSchedQueue(void *scheduler) {
   while (1) {
     if ((ret = tsem_wait(&pSched->fullSem)) != 0) {
       uFatal("wait %s fullSem failed(%s)", pSched->label, strerror(errno));
-      ASSERT(0);
     }
     if (atomic_load_8(&pSched->stop)) {
       break;
@@ -145,7 +144,6 @@ void *taosProcessSchedQueue(void *scheduler) {
 
     if ((ret = taosThreadMutexLock(&pSched->queueMutex)) != 0) {
       uFatal("lock %s queueMutex failed(%s)", pSched->label, strerror(errno));
-      ASSERT(0);
     }
 
     msg = pSched->queue[pSched->fullSlot];
@@ -154,12 +152,10 @@ void *taosProcessSchedQueue(void *scheduler) {
 
     if ((ret = taosThreadMutexUnlock(&pSched->queueMutex)) != 0) {
       uFatal("unlock %s queueMutex failed(%s)", pSched->label, strerror(errno));
-      ASSERT(0);
     }
 
     if ((ret = tsem_post(&pSched->emptySem)) != 0) {
       uFatal("post %s emptySem failed(%s)", pSched->label, strerror(errno));
-      ASSERT(0);
     }
 
     if (msg.fp)
@@ -187,12 +183,10 @@ int taosScheduleTask(void *queueScheduler, SSchedMsg *pMsg) {
 
   if ((ret = tsem_wait(&pSched->emptySem)) != 0) {
     uFatal("wait %s emptySem failed(%s)", pSched->label, strerror(errno));
-    ASSERT(0);
   }
 
   if ((ret = taosThreadMutexLock(&pSched->queueMutex)) != 0) {
     uFatal("lock %s queueMutex failed(%s)", pSched->label, strerror(errno));
-    ASSERT(0);
   }
 
   pSched->queue[pSched->emptySlot] = *pMsg;
@@ -200,12 +194,10 @@ int taosScheduleTask(void *queueScheduler, SSchedMsg *pMsg) {
 
   if ((ret = taosThreadMutexUnlock(&pSched->queueMutex)) != 0) {
     uFatal("unlock %s queueMutex failed(%s)", pSched->label, strerror(errno));
-    ASSERT(0);
   }
 
   if ((ret = tsem_post(&pSched->fullSem)) != 0) {
     uFatal("post %s fullSem failed(%s)", pSched->label, strerror(errno));
-    ASSERT(0);
   }
   return ret;
 }
diff --git a/source/util/src/tsimplehash.c b/source/util/src/tsimplehash.c
index ec1991923f..4c7983a983 100644
--- a/source/util/src/tsimplehash.c
+++ b/source/util/src/tsimplehash.c
@@ -361,10 +361,6 @@ int32_t tSimpleHashIterateRemove(SSHashObj *pHashObj, const void *key, size_t ke
   return TSDB_CODE_SUCCESS;
 }
 
-static void destroyItems(void* pItem) {
-  taosMemoryFree(*(void**)pItem);
-}
-
 void tSimpleHashClear(SSHashObj *pHashObj) {
   if (!pHashObj || taosHashTableEmpty(pHashObj)) {
     return;
diff --git a/source/util/src/tskiplist.c b/source/util/src/tskiplist.c
index c72c5c70ae..222e0e8a51 100644
--- a/source/util/src/tskiplist.c
+++ b/source/util/src/tskiplist.c
@@ -268,8 +268,9 @@ SSkipListIterator *tSkipListCreateIter(SSkipList *pSkipList) {
 }
 
 SSkipListIterator *tSkipListCreateIterFromVal(SSkipList *pSkipList, const char *val, int32_t type, int32_t order) {
-  ASSERT(order == TSDB_ORDER_ASC || order == TSDB_ORDER_DESC);
-  ASSERT(pSkipList != NULL);
+  if (order != TSDB_ORDER_ASC && order != TSDB_ORDER_DESC) {
+    return NULL;
+  }
 
   SSkipListIterator *iter = doCreateSkipListIterator(pSkipList, order);
   if (val == NULL) {
@@ -585,7 +586,6 @@ static FORCE_INLINE int32_t getSkipListRandLevel(SSkipList *pSkipList) {
     }
   }
 
-  ASSERT(level <= pSkipList->maxLevel);
   return level;
 }
 
diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task
index 16b699fc44..cd87285839 100644
--- a/tests/parallel_test/cases.task
+++ b/tests/parallel_test/cases.task
@@ -51,6 +51,16 @@
 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/nestedQuery_math.py -Q 3
 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/nestedQuery_time.py -Q 3
 ,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/nestedQuery_26.py -Q 3
+,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/select_null.py
+,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/select_null.py -R
+,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/select_null.py -Q 2
+,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/select_null.py -Q 3
+,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/select_null.py -Q 4
+,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/slimit.py
+,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/slimit.py -R
+,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/slimit.py -Q 2
+,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/slimit.py -Q 3
+,,y,system-test,./pytest.sh python3 ./test.py -f 2-query/slimit.py -Q 4
 
 ,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/create_wrong_topic.py
 ,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/dropDbR3ConflictTransaction.py -N 3
@@ -126,12 +136,15 @@
 ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/sysinfo.py
 ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/user_control.py
 ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/user_manage.py
+,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/user_privilege.py
 ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/fsync.py
+,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/multilevel.py
 ,,n,system-test,python3 ./test.py -f 0-others/compatibility.py
 ,,n,system-test,python3 ./test.py -f 0-others/tag_index_basic.py
 ,,n,system-test,python3 ./test.py -f 0-others/udfpy_main.py
 ,,n,system-test,python3 ./test.py -N 3 -f 0-others/walRetention.py
 ,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/alter_database.py
+,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/alter_replica.py -N 3
 ,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/influxdb_line_taosc_insert.py
 ,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/opentsdb_telnet_line_taosc_insert.py
 #,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/opentsdb_json_taosc_insert.py
@@ -337,6 +350,7 @@
 ,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/tb_100w_data_order.py
 ,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/delete_childtable.py
 ,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/delete_normaltable.py
+,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/delete_systable.py
 ,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/keep_expired.py
 ,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/stmt_error.py
 ,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/drop.py
@@ -724,6 +738,7 @@
 ,,y,script,./test.sh -f tsim/user/privilege_db.sim
 ,,y,script,./test.sh -f tsim/user/privilege_sysinfo.sim
 ,,y,script,./test.sh -f tsim/user/privilege_topic.sim
+,,y,script,./test.sh -f tsim/user/privilege_table.sim
 ,,y,script,./test.sh -f tsim/db/alter_option.sim
 ,,y,script,./test.sh -f tsim/db/alter_replica_31.sim
 ,,y,script,./test.sh -f tsim/db/basic1.sim
@@ -748,6 +763,7 @@
 ,,y,script,./test.sh -f tsim/db/show_create_table.sim
 ,,y,script,./test.sh -f tsim/db/tables.sim
 ,,y,script,./test.sh -f tsim/db/taosdlog.sim
+,,y,script,./test.sh -f tsim/db/table_prefix_suffix.sim
 ,,y,script,./test.sh -f tsim/dnode/balance_replica1.sim
 ,,y,script,./test.sh -f tsim/dnode/balance_replica3.sim
 ,,y,script,./test.sh -f tsim/dnode/balance1.sim
diff --git a/tests/parallel_test/run.sh b/tests/parallel_test/run.sh
index de343752c6..f05e0dfc83 100755
--- a/tests/parallel_test/run.sh
+++ b/tests/parallel_test/run.sh
@@ -303,7 +303,7 @@ function run_thread() {
             if [ ! -z "$corefile" ]; then
                 echo -e "\e[34m corefiles: $corefile \e[0m"
                 local build_dir=$log_dir/build_${hosts[index]}
-                local remote_build_dir="${workdirs[index]}/{DEBUGPATH}/build"
+                local remote_build_dir="${workdirs[index]}/${DEBUGPATH}/build"
                 # if [ $ent -ne 0 ]; then
                 #     remote_build_dir="${workdirs[index]}/{DEBUGPATH}/build"
                 # fi
diff --git a/tests/parallel_test/run_case.sh b/tests/parallel_test/run_case.sh
index ffc23ba6d2..2d736e1414 100755
--- a/tests/parallel_test/run_case.sh
+++ b/tests/parallel_test/run_case.sh
@@ -79,7 +79,7 @@ md5sum /home/TDinternal/debug/build/lib/libtaos.so
 #define taospy 2.7.6
 pip3 list|grep taospy
 pip3 uninstall taospy -y
-pip3 install taospy==2.7.6
+pip3 install  --default-timeout=120 taospy==2.7.6 
 
 $TIMEOUT_CMD $cmd
 RET=$?
diff --git a/tests/pytest/auto_crash_gen.py b/tests/pytest/auto_crash_gen.py
index 56629ede13..00e1786399 100755
--- a/tests/pytest/auto_crash_gen.py
+++ b/tests/pytest/auto_crash_gen.py
@@ -1,3 +1,4 @@
+import datetime
 import os
 import socket
 import requests
@@ -238,17 +239,7 @@ def start_taosd():
     start_cmd = 'cd %s && python3 test.py >>/dev/null '%(start_path)
     os.system(start_cmd)
 
-def get_cmds(args_list):
-    # build_path = get_path()
-    # if repo == "community":
-    #     crash_gen_path = build_path[:-5]+"community/tests/pytest/"
-    # elif repo == "TDengine":
-    #     crash_gen_path = build_path[:-5]+"/tests/pytest/"
-    # else:
-    #     pass
-
-    # crash_gen_cmd = 'cd %s && ./crash_gen.sh --valgrind -p -t 10 -s 1000 -g 0x32c,0x32d,0x3d3,0x18,0x2501,0x369,0x388,0x061a,0x2550  '%(crash_gen_path)
-
+def get_cmds(args_list):    
     crash_gen_cmd = get_auto_mix_cmds(args_list,valgrind=valgrind_mode)
     return crash_gen_cmd
 
@@ -295,7 +286,7 @@ def check_status():
     elif "Crash_Gen is now exiting with status code: 0" in run_code:
         return 0
     else:
-        return 2 
+        return 2
 
 
 def main():
@@ -310,7 +301,7 @@ def main():
 
 
     build_path = get_path()
-    os.system("pip install git+https://github.com/taosdata/taos-connector-python.git")
+        
     if repo =="community":
         crash_gen_path = build_path[:-5]+"community/tests/pytest/"
     elif repo =="TDengine":
@@ -334,7 +325,9 @@ def main():
     if not os.path.exists(run_dir):
         os.mkdir(run_dir)
     print(crash_cmds)
+    starttime = datetime.datetime.now()
     run_crash_gen(crash_cmds)
+    endtime = datetime.datetime.now()
     status = check_status()
     
     print("exit status : ", status)
@@ -349,7 +342,29 @@ def main():
         print('======== crash_gen run sucess and exit as expected ========')
 
     try:
-        text = f"crash_gen instance exit status of docker [ {hostname} ] is : {msg_dict[status]}\n  " + f" and git commit :  {git_commit}"
+        cmd = crash_cmds.split('&')[2]
+        if status == 0:
+            log_dir = "none"            
+        else:
+            log_dir= "/root/pxiao/crash_gen_logs" 
+        
+        if status == 3:
+            core_dir = "/root/pxiao/crash_gen_logs"
+        else:
+            core_dir = "none"
+            
+        text = f'''
+        exit status: {msg_dict[status]}
+        test scope: crash_gen
+        owner: pxiao
+        hostname: {hostname}
+        start time: {starttime}
+        end time: {endtime}
+        git commit :  {git_commit}
+        log dir: {log_dir}
+        core dir: {core_dir}
+        cmd: {cmd}'''
+                
         send_msg(get_msg(text))  
     except Exception as e:
         print("exception:", e)
diff --git a/tests/pytest/auto_crash_gen_valgrind.py b/tests/pytest/auto_crash_gen_valgrind.py
index 22fc5a480f..e37cda0a27 100755
--- a/tests/pytest/auto_crash_gen_valgrind.py
+++ b/tests/pytest/auto_crash_gen_valgrind.py
@@ -1,6 +1,7 @@
 #!/usr/bin/python3
 
 
+import datetime
 import os
 import socket
 import requests
@@ -241,15 +242,6 @@ def start_taosd():
     os.system(start_cmd +">>/dev/null")
 
 def get_cmds(args_list):
-    # build_path = get_path()
-    # if repo == "community":
-    #     crash_gen_path = build_path[:-5]+"community/tests/pytest/"
-    # elif repo == "TDengine":
-    #     crash_gen_path = build_path[:-5]+"/tests/pytest/"
-    # else:
-    #     pass
-
-    # crash_gen_cmd = 'cd %s && ./crash_gen.sh --valgrind -p -t 10 -s 1000 -g 0x32c,0x32d,0x3d3,0x18,0x2501,0x369,0x388,0x061a,0x2550  '%(crash_gen_path)
 
     crash_gen_cmd = get_auto_mix_cmds(args_list,valgrind=valgrind_mode)
     return crash_gen_cmd
@@ -343,7 +335,6 @@ def main():
     args = limits(args)
 
     build_path = get_path()
-    os.system("pip install git+https://github.com/taosdata/taos-connector-python.git >>/dev/null")
     if repo =="community":
         crash_gen_path = build_path[:-5]+"community/tests/pytest/"
     elif repo =="TDengine":
@@ -368,7 +359,9 @@ def main():
     if not os.path.exists(run_dir):
         os.mkdir(run_dir)
     print(crash_cmds)
+    starttime = datetime.datetime.now()
     run_crash_gen(crash_cmds)
+    endtime = datetime.datetime.now()
     status = check_status()
     # back_path = os.path.join(core_path,"valgrind_report")
     
@@ -384,8 +377,30 @@ def main():
         print('======== crash_gen run sucess and exit as expected ========')
 
     try:
-        text = f"crash_gen instance exit status of docker [ {hostname} ] is : {msg_dict[status]}\n  " + f" and git commit : {git_commit}"
-        send_msg(get_msg(text))  
+        cmd = crash_cmds.split('&')[2]
+        if status == 0:
+            log_dir = "none"            
+        else:
+            log_dir= "/root/pxiao/crash_gen_logs" 
+        
+        if status == 3:
+            core_dir = "/root/pxiao/crash_gen_logs"
+        else:
+            core_dir = "none"
+            
+        text = f'''
+        exit status: {msg_dict[status]}
+        test scope: crash_gen
+        owner: pxiao
+        hostname: {hostname}
+        start time: {starttime}
+        end time: {endtime}
+        git commit :  {git_commit}
+        log dir: {log_dir}
+        core dir: {core_dir}
+        cmd: {cmd}'''
+        
+        send_msg(get_msg(text))
     except Exception as e:
         print("exception:", e)
     exit(status)
diff --git a/tests/pytest/auto_crash_gen_valgrind_cluster.py b/tests/pytest/auto_crash_gen_valgrind_cluster.py
index 547de9af47..af19836a83 100755
--- a/tests/pytest/auto_crash_gen_valgrind_cluster.py
+++ b/tests/pytest/auto_crash_gen_valgrind_cluster.py
@@ -1,6 +1,7 @@
 #!/usr/bin/python3
 
 
+import datetime
 import os
 import socket
 import requests
@@ -241,16 +242,7 @@ def start_taosd():
     os.system(start_cmd +">>/dev/null")
 
 def get_cmds(args_list):
-    # build_path = get_path()
-    # if repo == "community":
-    #     crash_gen_path = build_path[:-5]+"community/tests/pytest/"
-    # elif repo == "TDengine":
-    #     crash_gen_path = build_path[:-5]+"/tests/pytest/"
-    # else:
-    #     pass
-
-    # crash_gen_cmd = 'cd %s && ./crash_gen.sh --valgrind -p -t 10 -s 1000 -g 0x32c,0x32d,0x3d3,0x18,0x2501,0x369,0x388,0x061a,0x2550  '%(crash_gen_path)
-
+    
     crash_gen_cmd = get_auto_mix_cmds(args_list,valgrind=valgrind_mode)
     return crash_gen_cmd
 
@@ -342,8 +334,7 @@ def main():
     args = random_args(args_list)
     args = limits(args)
 
-    build_path = get_path()
-    os.system("pip install git+https://github.com/taosdata/taos-connector-python.git >>/dev/null")
+    build_path = get_path()    
     if repo =="community":
         crash_gen_path = build_path[:-5]+"community/tests/pytest/"
     elif repo =="TDengine":
@@ -368,7 +359,9 @@ def main():
     if not os.path.exists(run_dir):
         os.mkdir(run_dir)
     print(crash_cmds)
+    starttime = datetime.datetime.now()
     run_crash_gen(crash_cmds)
+    endtime = datetime.datetime.now()
     status = check_status()
     # back_path = os.path.join(core_path,"valgrind_report")
     
@@ -384,7 +377,29 @@ def main():
         print('======== crash_gen run sucess and exit as expected ========')
 
     try:
-        text = f"crash_gen instance exit status of docker [ {hostname} ] is : {msg_dict[status]}\n  " + f" and git commit : {git_commit}"
+        cmd = crash_cmds.split('&')[2]
+        if status == 0:
+            log_dir = "none"            
+        else:
+            log_dir= "/root/pxiao/crash_gen_logs" 
+        
+        if status == 3:
+            core_dir = "/root/pxiao/crash_gen_logs"
+        else:
+            core_dir = "none"
+            
+        text = f'''
+        exit status: {msg_dict[status]}
+        test scope: crash_gen
+        owner: pxiao
+        hostname: {hostname}
+        start time: {starttime}
+        end time: {endtime}
+        git commit :  {git_commit}
+        log dir: {log_dir}
+        core dir: {core_dir}
+        cmd: {cmd}'''
+                
         send_msg(get_msg(text))  
     except Exception as e:
         print("exception:", e)
diff --git a/tests/script/tsim/alter/table.sim b/tests/script/tsim/alter/table.sim
index dccfc7f5d6..db2a22205f 100644
--- a/tests/script/tsim/alter/table.sim
+++ b/tests/script/tsim/alter/table.sim
@@ -657,6 +657,37 @@ if $data20 != null then
   return -1
 endi
 
+#print =============== error for normal table
+#sql create table tb2023(ts timestamp, f int);
+#sql_error alter table tb2023 add column v varchar(65535);
+#sql_error alter table tb2023 add column v varchar(65535);
+#sql_error alter table tb2023 add column v varchar(65530);
+#sql alter table tb2023 add column v varchar(16374);
+#sql_error alter table tb2023 modify column v varchar(65536);
+#sql desc tb2023
+#sql alter table tb2023 drop column v
+#sql_error alter table tb2023 add column v nchar(16384);
+#sql alter table tb2023 add column v nchar(4093);
+#sql_error alter table tb2023 modify column v nchar(16384);
+#sql_error alter table tb2023 add column v nchar(16384);
+#sql alter table tb2023 drop column v
+#sql alter table tb2023 add column v nchar(16374);
+#sql desc tb2023
+#
+#print =============== error for super table
+#sql create table stb2023(ts timestamp, f int) tags(t1 int);
+#sql_error alter table stb2023 add column v varchar(65535);
+#sql_error alter table stb2023 add column v varchar(65536);
+#sql_error alter table stb2023 add column v varchar(33100);
+#sql alter table stb2023 add column v varchar(16374);
+#sql_error alter table stb2023 modify column v varchar(16375);
+#sql desc stb2023
+#sql alter table stb2023 drop column v
+#sql_error alter table stb2023 add column v nchar(4094);
+#sql alter table stb2023 add column v nchar(4093);
+#sql_error alter table stb2023 modify column v nchar(4094);
+#sql desc stb2023
+
 print ======= over
 sql drop database d1
 sql select * from information_schema.ins_databases
diff --git a/tests/script/tsim/db/error1.sim b/tests/script/tsim/db/error1.sim
index 32dbe826cc..64b17125aa 100644
--- a/tests/script/tsim/db/error1.sim
+++ b/tests/script/tsim/db/error1.sim
@@ -58,16 +58,16 @@ if $data23 != 0 then
   return -1
 endi
 
-print ========== stop dnode2
-system sh/exec.sh -n dnode2 -s stop -x SIGKILL
+#print ========== stop dnode2
+#system sh/exec.sh -n dnode2 -s stop -x SIGKILL
 
-sleep 1000
-print =============== drop database
-sql_error drop database d1
+#sleep 1000
+#print =============== drop database
+sql drop database d1
 
-print ========== start dnode2
-system sh/exec.sh -n dnode2 -s start
-sleep 1000
+#print ========== start dnode2
+#system sh/exec.sh -n dnode2 -s start
+#sleep 1000
 
 print =============== re-create database
 $x = 0
diff --git a/tests/script/tsim/db/table_prefix_suffix.sim b/tests/script/tsim/db/table_prefix_suffix.sim
new file mode 100644
index 0000000000..1b483d7df7
--- /dev/null
+++ b/tests/script/tsim/db/table_prefix_suffix.sim
@@ -0,0 +1,182 @@
+system sh/stop_dnodes.sh
+system sh/deploy.sh -n dnode1 -i 1
+system sh/exec.sh -n dnode1 -s start
+sql connect
+
+sql drop database if exists db1;
+sql create database db1 vgroups 5 TABLE_PREFIX 1 TABLE_SUFFIX 2;
+sql use db1;
+sql create table atb1aa (ts timestamp, f1 int);
+sql create table btb1bb (ts timestamp, f1 int);
+sql create table ctb1cc (ts timestamp, f1 int);
+sql create table dtb1dd (ts timestamp, f1 int);
+sql create table atb2aa (ts timestamp, f1 int);
+sql create table btb2bb (ts timestamp, f1 int);
+sql create table ctb2cc (ts timestamp, f1 int);
+sql create table dtb2dd (ts timestamp, f1 int);
+sql create table etb2ee (ts timestamp, f1 int);
+sql show create database db1;
+sql select count(*) a from information_schema.ins_tables where db_name='db1' group by vgroup_id having(count(*) > 0) order by a;
+if $rows != 2 then
+  return -1
+endi
+if $data00 != 4 then
+  return -1
+endi
+if $data10 != 5 then
+  return -1
+endi
+sql drop database if exists db1;
+ 
+sql drop database if exists db2;
+sql create database db2 vgroups 5 TABLE_PREFIX -1 TABLE_SUFFIX -2;
+sql use db2;
+sql create table taaa11 (ts timestamp, f1 int);
+sql create table tbbb11 (ts timestamp, f1 int);
+sql create table tccc11 (ts timestamp, f1 int);
+sql create table tddd11 (ts timestamp, f1 int);
+sql create table taaa22 (ts timestamp, f1 int);
+sql create table tbbb22 (ts timestamp, f1 int);
+sql create table tccc22 (ts timestamp, f1 int);
+sql create table tddd22 (ts timestamp, f1 int);
+sql create table teee22 (ts timestamp, f1 int);
+sql show create database db2;
+sql select count(*) a from information_schema.ins_tables where db_name='db2' group by vgroup_id having(count(*) > 0) order by a;
+if $rows != 2 then
+  return -1
+endi
+if $data00 != 4 then
+  return -1
+endi
+if $data10 != 5 then
+  return -1
+endi
+sql drop database if exists db2;
+ 
+sql drop database if exists db3;
+sql create database db3 vgroups 5 TABLE_PREFIX -1;
+sql use db3;
+sql create table taaa11 (ts timestamp, f1 int);
+sql create table tbbb11 (ts timestamp, f1 int);
+sql create table tccc11 (ts timestamp, f1 int);
+sql create table tddd11 (ts timestamp, f1 int);
+sql create table zaaa22 (ts timestamp, f1 int);
+sql create table zbbb22 (ts timestamp, f1 int);
+sql create table zccc22 (ts timestamp, f1 int);
+sql create table zddd22 (ts timestamp, f1 int);
+sql create table zeee22 (ts timestamp, f1 int);
+sql show create database db3;
+sql select count(*) a from information_schema.ins_tables where db_name='db3' group by vgroup_id having(count(*) > 0) order by a;
+if $rows != 2 then
+  return -1
+endi
+if $data00 != 4 then
+  return -1
+endi
+if $data10 != 5 then
+  return -1
+endi
+sql drop database if exists db3;
+ 
+sql drop database if exists db4;
+sql create database db4 vgroups 5 TABLE_SUFFIX -2;
+sql use db4;
+sql create table taaa11 (ts timestamp, f1 int);
+sql create table tbbb11 (ts timestamp, f1 int);
+sql create table tccc11 (ts timestamp, f1 int);
+sql create table tddd11 (ts timestamp, f1 int);
+sql create table zaaa22 (ts timestamp, f1 int);
+sql create table zbbb22 (ts timestamp, f1 int);
+sql create table zccc22 (ts timestamp, f1 int);
+sql create table zddd22 (ts timestamp, f1 int);
+sql create table zeee22 (ts timestamp, f1 int);
+sql show create database db4;
+sql select count(*) a from information_schema.ins_tables where db_name='db4' group by vgroup_id having(count(*) > 0) order by a;
+if $rows != 2 then
+  return -1
+endi
+if $data00 != 4 then
+  return -1
+endi
+if $data10 != 5 then
+  return -1
+endi
+sql drop database if exists db4;
+ 
+sql drop database if exists db5;
+sql create database db5 vgroups 5 TABLE_PREFIX 1;
+sql use db5;
+sql create table taaa11 (ts timestamp, f1 int);
+sql create table baaa11 (ts timestamp, f1 int);
+sql create table caaa11 (ts timestamp, f1 int);
+sql create table daaa11 (ts timestamp, f1 int);
+sql create table faaa11 (ts timestamp, f1 int);
+sql create table gbbb11 (ts timestamp, f1 int);
+sql create table hbbb11 (ts timestamp, f1 int);
+sql create table ibbb11 (ts timestamp, f1 int);
+sql create table jbbb11 (ts timestamp, f1 int);
+sql show create database db5;
+sql select count(*) a from information_schema.ins_tables where db_name='db5' group by vgroup_id having(count(*) > 0) order by a;
+if $rows != 2 then
+  return -1
+endi
+if $data00 != 4 then
+  return -1
+endi
+if $data10 != 5 then
+  return -1
+endi
+sql drop database if exists db5;
+ 
+sql drop database if exists db6;
+sql create database db6 vgroups 5 TABLE_SUFFIX 2;
+sql use db6;
+sql create table taaa11 (ts timestamp, f1 int);
+sql create table taaa12 (ts timestamp, f1 int);
+sql create table taaa13 (ts timestamp, f1 int);
+sql create table taaa14 (ts timestamp, f1 int);
+sql create table tbbb23 (ts timestamp, f1 int);
+sql create table tbbb24 (ts timestamp, f1 int);
+sql create table tbbb31 (ts timestamp, f1 int);
+sql create table tbbb32 (ts timestamp, f1 int);
+sql create table tbbb33 (ts timestamp, f1 int);
+sql show create database db6;
+sql select count(*) a from information_schema.ins_tables where db_name='db6' group by vgroup_id having(count(*) > 0) order by a;
+if $rows != 2 then
+  return -1
+endi
+if $data00 != 4 then
+  return -1
+endi
+if $data10 != 5 then
+  return -1
+endi
+sql drop database if exists db6;
+ 
+sql drop database if exists db7;
+sql create database db7 vgroups 5 TABLE_PREFIX -100 TABLE_SUFFIX -92;
+sql use db7;
+sql create table taaa11 (ts timestamp, f1 int);
+sql create table taaa12 (ts timestamp, f1 int);
+sql create table taaa13 (ts timestamp, f1 int);
+sql create table tbbb21 (ts timestamp, f1 int);
+sql create table tbbb22 (ts timestamp, f1 int);
+sql create table tbbb23 (ts timestamp, f1 int);
+sql create table tbbb24 (ts timestamp, f1 int);
+sql create table tccc31 (ts timestamp, f1 int);
+sql create table tccc32 (ts timestamp, f1 int);
+sql create table tccc33 (ts timestamp, f1 int);
+sql create table tddd24 (ts timestamp, f1 int);
+sql create table tddd31 (ts timestamp, f1 int);
+sql create table tddd32 (ts timestamp, f1 int);
+sql create table tddd33 (ts timestamp, f1 int);
+sql show create database db7;
+sql select count(*) a from information_schema.ins_tables where db_name='db7' group by vgroup_id having(count(*) > 0) order by a;
+sql drop database if exists db7;
+
+sql_error create database db8 vgroups 5 TABLE_PREFIX -1 TABLE_SUFFIX 2;
+sql_error create database db8 vgroups 5 TABLE_PREFIX 191 TABLE_SUFFIX 192;
+sql_error create database db8 vgroups 5 TABLE_PREFIX -192 TABLE_SUFFIX -191;
+sql_error create database db8 vgroups 5 TABLE_PREFIX 100 TABLE_SUFFIX 92;
+
+system sh/exec.sh -n dnode1 -s stop -x SIGINT
diff --git a/tests/script/tsim/parser/alter_column.sim b/tests/script/tsim/parser/alter_column.sim
index c70a604c73..f892115735 100644
--- a/tests/script/tsim/parser/alter_column.sim
+++ b/tests/script/tsim/parser/alter_column.sim
@@ -48,7 +48,7 @@ sql_error alter table tb modify column c2 binary(10);
 sql_error alter table tb modify column c2 binary(9);
 sql_error alter table tb modify column c2 binary(-9);
 sql_error alter table tb modify column c2 binary(0);
-sql alter table tb modify column c2 binary(17000);
+sql_error alter table tb modify column c2 binary(65600);
 sql_error alter table tb modify column c2 nchar(30);
 sql_error alter table tb modify column c3 double;
 sql_error alter table tb modify column c3 nchar(10);
diff --git a/tests/script/tsim/query/sys_tbname.sim b/tests/script/tsim/query/sys_tbname.sim
index c676f2b1e0..849aeb2ac5 100644
--- a/tests/script/tsim/query/sys_tbname.sim
+++ b/tests/script/tsim/query/sys_tbname.sim
@@ -109,5 +109,26 @@ if $rows != 5000 then
         return -1
 endi
 
+sql create database d1;
+sql create stable d1.st1 (ts timestamp, f int) tags(t int);
+sql create stable d1.st2 (ts timestamp, f int) tags(t int);
+sql create table d1.ct1 using d1.st1 tags(1);
+sql create table d1.ct2 using d1.st2 tags(2);
 
+sql create database d2;
+sql create stable d2.st1(ts timestamp, f int) tags(t int);
+sql create stable d2.st2(ts timestamp, f int) tags(t int);
+sql create table d2.ct1 using d2.st1 tags(1);
+sql create table d2.ct2 using d2.st2 tags(2);
+
+sql create database d3;
+sql create stable d3.st1(ts timestamp, f int) tags(t int);
+sql create stable d3.st2(ts timestamp, f int) tags(t int);
+sql create table d3.ct1 using d3.st1 tags(1);
+sql create table d3.ct2 using d3.st2 tags(2);
+sql select count(*), stable_name, db_name from information_schema.ins_tables where db_name != 'd2' group by stable_name,db_name
+print $rows
+if $rows != 9 then
+  return -1
+endi
 #system sh/exec.sh -n dnode1 -s stop -x SIGINT
diff --git a/tests/script/tsim/query/tableCount.sim b/tests/script/tsim/query/tableCount.sim
index d8d9bb9b03..ac5e23273a 100644
--- a/tests/script/tsim/query/tableCount.sim
+++ b/tests/script/tsim/query/tableCount.sim
@@ -104,4 +104,9 @@ if $data62 != 5 then
   return -1
 endi
 
+sql select distinct db_name from information_schema.ins_tables;
+print $rows
+if $rows != 4 then
+  return -1
+endi
 system sh/exec.sh -n dnode1 -s stop -x SIGINT
diff --git a/tests/script/tsim/query/unionall_as_table.sim b/tests/script/tsim/query/unionall_as_table.sim
index dc3d2cbec4..4d8f990718 100644
--- a/tests/script/tsim/query/unionall_as_table.sim
+++ b/tests/script/tsim/query/unionall_as_table.sim
@@ -25,4 +25,21 @@ if $data05 != @0021001@ then
   return -1
 endi
 
+sql create table st (ts timestamp, f int) tags (t int);
+sql insert into ct1 using st tags(1) values(now, 1)(now+1s, 2)
+sql insert into ct2 using st tags(2) values(now+2s, 3)(now+3s, 4)
+sql select count(*) from (select * from ct1 union all select * from ct2)
+if $rows != 1 then
+  return -1
+endi
+if $data00 != 4 then
+  return -1
+endi
+sql select count(*) from (select * from ct1 union select * from ct2)
+if $rows != 1 then
+  return -1
+endi
+if $data00 != 4 then
+  return -1
+endi
 system sh/exec.sh -n dnode1 -s stop -x SIGINT
diff --git a/tests/script/tsim/stream/basic1.sim b/tests/script/tsim/stream/basic1.sim
index 15ca6bf7c9..65032817b3 100644
--- a/tests/script/tsim/stream/basic1.sim
+++ b/tests/script/tsim/stream/basic1.sim
@@ -37,7 +37,7 @@ if $loop_count == 20 then
 endi
 
 if $rows != 4 then
-  print =====rows=$rows, expect 4
+  print =====rows=$rows  expect 4
   goto loop0
 endi
 
diff --git a/tests/script/tsim/tag/bigint.sim b/tests/script/tsim/tag/bigint.sim
index 26a5addf6a..34fcc09411 100644
--- a/tests/script/tsim/tag/bigint.sim
+++ b/tests/script/tsim/tag/bigint.sim
@@ -123,6 +123,17 @@ sql select * from $mt where tgcol = 1
 if $rows != 100 then
   return -1
 endi
+
+sql select * from $mt where tgcol = '1'
+if $rows != 100 then
+  return -1
+endi
+
+sql select * from $mt where tgcol = "1"
+if $rows != 100 then
+  return -1
+endi
+
 sql select * from $mt where tgcol <> 1
 if $rows != 100 then
   return -1
diff --git a/tests/script/tsim/tag/double.sim b/tests/script/tsim/tag/double.sim
index fbdf973337..acc026c13d 100644
--- a/tests/script/tsim/tag/double.sim
+++ b/tests/script/tsim/tag/double.sim
@@ -123,6 +123,15 @@ sql select * from $mt where tgcol = 1
 if $rows != 100 then
   return -1
 endi
+
+sql select * from $mt where tgcol = '1';
+if $rows != 100 then
+  return -1
+endi
+sql select * from $mt where tgcol = "1.0"
+if $rows != 100 then
+  return -1
+endi
 sql select * from $mt where tgcol <> 1
 if $rows != 100 then
   return -1
diff --git a/tests/script/tsim/tag/float.sim b/tests/script/tsim/tag/float.sim
index 10fac93d5d..f62feba057 100644
--- a/tests/script/tsim/tag/float.sim
+++ b/tests/script/tsim/tag/float.sim
@@ -123,6 +123,16 @@ sql select * from $mt where tgcol = 1
 if $rows != 100 then
   return -1
 endi
+
+sql select * from $mt where tgcol = "1.0"
+if $rows != 100 then
+  return -1
+endi
+
+sql select * from $mt where tgcol = "1"
+if $rows != 100 then
+  return -1
+endi
 sql select * from $mt where tgcol <> 1
 if $rows != 100 then
   return -1
diff --git a/tests/script/tsim/tag/int.sim b/tests/script/tsim/tag/int.sim
index ac8d31db3b..084b7e74d7 100644
--- a/tests/script/tsim/tag/int.sim
+++ b/tests/script/tsim/tag/int.sim
@@ -123,6 +123,16 @@ sql select * from $mt where tgcol = 1
 if $rows != 100 then
   return -1
 endi
+
+sql select * from $mt where tgcol = '1'
+if $rows != 100 then
+  return -1
+endi
+
+sql select * from $mt where tgcol = "1";
+if $rows != 100 then
+  return -1
+endi
 sql select * from $mt where tgcol <> 1
 if $rows != 100 then
   return -1
diff --git a/tests/script/tsim/tag/int_float.sim b/tests/script/tsim/tag/int_float.sim
index 009629aac9..3034f8b64e 100644
--- a/tests/script/tsim/tag/int_float.sim
+++ b/tests/script/tsim/tag/int_float.sim
@@ -85,10 +85,22 @@ sql select * from $mt where tgcol <> 1
 if $rows != 100 then
   return -1
 endi
+
 sql select * from $mt where tgcol = 1
 if $rows != 100 then
   return -1
 endi
+
+sql select * from $mt where tgcol = '1'
+if $rows != 100 then
+  return -1
+endi
+
+sql select * from $mt where tgcol = "1"
+if $rows != 100 then
+  return -1
+endi
+
 sql select * from $mt where tgcol <> 1
 if $rows != 100 then
   return -1
diff --git a/tests/script/tsim/tag/tinyint.sim b/tests/script/tsim/tag/tinyint.sim
index 8560def34c..89b0134bb3 100644
--- a/tests/script/tsim/tag/tinyint.sim
+++ b/tests/script/tsim/tag/tinyint.sim
@@ -115,14 +115,36 @@ sql select * from $mt where tgcol = 0
 if $rows != 100 then
   return -1
 endi
+
+sql select * from $mt where tgcol = '0'
+if $rows != 100 then
+  return -1
+endi
+
+sql select * from $mt where tgcol = "0"
+if $rows != 100 then
+  return -1
+endi
 sql select * from $mt where tgcol <> 0
 if $rows != 100 then
   return -1
 endi
+
 sql select * from $mt where tgcol = 1
 if $rows != 100 then
   return -1
 endi
+sql select * from $mt where tgcol = "1"
+if $rows != 100 then
+  return -1
+endi
+
+sql select * from $mt where tgcol = '1'
+if $rows != 100 then
+  return -1
+endi
+
+
 sql select * from $mt where tgcol <> 1
 if $rows != 100 then
   return -1
diff --git a/tests/script/tsim/user/privilege_table.sim b/tests/script/tsim/user/privilege_table.sim
new file mode 100644
index 0000000000..05f91ff5b0
--- /dev/null
+++ b/tests/script/tsim/user/privilege_table.sim
@@ -0,0 +1,302 @@
+system sh/stop_dnodes.sh
+system sh/deploy.sh -n dnode1 -i 1
+system sh/exec.sh -n dnode1 -s start
+sql connect
+
+print =============== init env
+sql drop database if exists test;
+sql create database test vgroups 1;
+sql use test;
+sql create stable st1(ts timestamp, i int) tags(id int, loc varchar(20));
+sql create table st1s1 using st1 tags(1, 'beijing');
+sql create table st1s2 using st1 tags(2, 'shanghai');
+sql insert into st1s1 values(now, 1) st1s2 values(now, 2);
+sql create stable st2(ts timestamp, i int) tags(id int, loc varchar(20));
+sql create table st2s1 using st2 tags(1, 'beijing');
+sql create table st2s2 using st2 tags(2, 'shanghai');
+sql insert into st2s1 values(now, 1) st2s2 values(now, 2);
+sql create user wxy pass 'taosdata';
+
+print =============== case 1: database unauthorized and table unauthorized
+sql close
+sql connect wxy
+
+sql reset query cache;
+sql_error select * from test.st1;
+sql_error insert into test.st1s1 values(now, 10) test.st1s2 values(now, 20);
+sql_error select * from test.st2; 
+sql_error insert into test.st2s1 values(now, 10) test.st2s2 values(now, 20);
+
+
+print =============== case 2: database unauthorized and table read privilege
+sql close
+sql connect
+
+sql grant read on test.st1 to wxy;
+
+sql close
+sql connect wxy
+
+sql reset query cache;
+sql select * from test.st1;
+if $rows != 2 then 
+  return -1
+endi
+sql_error insert into test.st1s1 values(now, 10) test.st1s2 values(now, 20);
+sql_error select * from test.st2; 
+sql_error insert into test.st2s1 values(now, 10) test.st2s2 values(now, 20);
+
+print =============== case 3: database unauthorized and table read privilege with condition
+sql close
+sql connect
+
+sql revoke read on test.st1 from wxy;
+sql grant read on test.st1 with id = 1 to wxy;
+
+sql close
+sql connect wxy
+
+sql reset query cache;
+sql select * from test.st1; 
+if $rows != 1 then 
+  return -1
+endi
+sql_error insert into test.st1s1 values(now, 10);
+sql_error insert into test.st1s2 values(now, 20);
+sql_error select * from test.st2; 
+sql_error insert into test.st2s1 values(now, 10) test.st2s2 values(now, 20);
+
+print =============== case 4: database unauthorized and table write privilege
+sql close
+sql connect
+
+sql revoke read on test.st1 with id = 1 from wxy;
+sql grant write on test.st1 to wxy;
+
+sql close
+sql connect wxy
+
+sql reset query cache;
+sql_error select tbname, * from test.st1; 
+sql insert into test.st1s1 values(now, 10);
+sql insert into test.st1s2 values(now, 20);
+sql_error select * from test.st2; 
+sql_error insert into test.st2s1 values(now, 10) test.st2s2 values(now, 20);
+
+print =============== case 5: database unauthorized and table write privilege with condition
+sql close
+sql connect
+
+sql revoke write on test.st1 from wxy;
+sql grant write on test.st1 with id = 1 to wxy;
+
+sql close
+sql connect wxy
+
+sql reset query cache;
+sql_error select tbname, * from test.st1; 
+sql insert into test.st1s1 values(now, 10);
+sql insert into test.st1s3 using test.st1 tags(1, 'dachang') values(now, 100);
+sql_error insert into test.st1s2 values(now, 20);
+sql_error insert into test.st1s4 using test.st1 tags(3, 'dachang') values(now, 300);
+sql_error select * from test.st2; 
+sql_error insert into test.st2s1 values(now, 10) test.st2s2 values(now, 20);
+
+print =============== case 6: database read privilege and table unauthorized
+sql close
+sql connect
+
+sql revoke write on test.st1 with id = 1 from wxy;
+sql grant read on test.* to wxy;
+
+sql close
+sql connect wxy
+
+sql reset query cache;
+sql select * from test.st1;
+if $rows != 6 then 
+  return -1
+endi
+sql_error insert into test.st1s1 values(now, 10) test.st1s2 values(now, 20);
+sql select * from test.st2; 
+if $rows != 2 then 
+  return -1
+endi
+sql_error insert into test.st2s1 values(now, 10) test.st2s2 values(now, 20);
+
+print =============== case 7: database read privilege and table read privilege
+sql close
+sql connect
+
+sql grant read on test.st1 to wxy;
+
+sql close
+sql connect wxy
+
+sql reset query cache;
+sql select * from test.st1; 
+if $rows != 6 then 
+  return -1
+endi
+sql_error insert into test.st1s1 values(now, 10) test.st1s2 values(now, 20);
+sql select * from test.st2; 
+if $rows != 2 then 
+  return -1
+endi
+sql_error insert into test.st2s1 values(now, 10) test.st2s2 values(now, 20);
+
+print =============== case 8: database read privilege and table read privilege with condition
+sql close
+sql connect
+
+sql revoke read on test.st1 from wxy;
+sql grant read on test.st1 with id = 1 to wxy;
+
+sql close
+sql connect wxy
+
+sql reset query cache;
+sql select * from test.st1; 
+if $rows != 4 then 
+  return -1
+endi
+sql_error insert into test.st1s1 values(now, 10) test.st1s2 values(now, 20);
+sql select * from test.st2; 
+if $rows != 2 then 
+  return -1
+endi
+sql_error insert into test.st2s1 values(now, 10) test.st2s2 values(now, 20);
+
+print =============== case 9: database read privilege and table write privilege
+sql close
+sql connect
+
+sql revoke read on test.st1 with id = 1 from wxy;
+sql grant write on test.st1 to wxy;
+
+sql close
+sql connect wxy
+
+sql reset query cache;
+sql select * from test.st1;
+if $rows != 6 then 
+  return -1
+endi
+sql insert into test.st1s1 values(now, 10) test.st1s2 values(now, 20);
+sql select * from test.st2;
+if $rows != 2 then 
+  return -1
+endi
+sql_error insert into test.st2s1 values(now, 10) test.st2s2 values(now, 20);
+
+print =============== case 10: database read privilege and table write privilege with condition
+sql close
+sql connect
+
+sql revoke write on test.st1 from wxy;
+sql grant write on test.st1 with id = 1 to wxy;
+
+sql close
+sql connect wxy
+
+sql reset query cache;
+sql select * from test.st1;
+if $rows != 8 then 
+  return -1
+endi
+sql insert into test.st1s1 values(now, 10);
+sql_error insert into test.st1s2 values(now, 20);
+sql select * from test.st2;
+if $rows != 2 then 
+  return -1
+endi
+sql_error insert into test.st2s1 values(now, 10) test.st2s2 values(now, 20);
+
+print =============== case 11: database write privilege and table unauthorized
+sql close
+sql connect
+
+sql revoke read on test.* from wxy;
+sql revoke write on test.st1 with id = 1 from wxy;
+sql grant write on test.* to wxy;
+
+sql close
+sql connect wxy
+
+sql reset query cache;
+sql_error select * from test.st1; 
+sql insert into test.st1s1 values(now, 10) test.st1s2 values(now, 20);
+sql_error select * from test.st2; 
+sql insert into test.st2s1 values(now, 10) test.st2s2 values(now, 20);
+
+print =============== case 12: database write privilege and table read privilege
+sql close
+sql connect
+
+sql grant read on test.st1 to wxy;
+
+sql close
+sql connect wxy
+
+sql reset query cache;
+sql select * from test.st1; 
+if $rows != 11 then 
+  return -1
+endi
+sql insert into test.st1s1 values(now, 10) test.st1s2 values(now, 20);
+sql_error select * from test.st2; 
+sql insert into test.st2s1 values(now, 10) test.st2s2 values(now, 20);
+
+print =============== case 13: database write privilege and table read privilege with condition
+sql close
+sql connect
+
+sql revoke read on test.st1 from wxy;
+sql grant read on test.st1 with id = 1 to wxy;
+
+sql close
+sql connect wxy
+
+sql reset query cache;
+sql select * from test.st1; 
+if $rows != 8 then 
+  return -1
+endi
+sql insert into test.st1s1 values(now, 10) test.st1s2 values(now, 20);
+sql_error select * from test.st2; 
+sql insert into test.st2s1 values(now, 10) test.st2s2 values(now, 20);
+
+print =============== case 14: database write privilege and table write privilege
+sql close
+sql connect
+
+sql revoke read on test.st1 with id = 1 from wxy;
+sql grant write on test.st1 to wxy;
+
+sql close
+sql connect wxy
+
+sql reset query cache;
+sql_error select * from test.st1; 
+sql insert into test.st1s1 values(now, 10) test.st1s2 values(now, 20);
+sql_error select * from test.st2; 
+sql insert into test.st2s1 values(now, 10) test.st2s2 values(now, 20);
+
+print =============== case 15: database write privilege and table write privilege with condition
+sql close
+sql connect
+
+sql revoke write on test.st1 from wxy;
+sql grant write on test.st1 with id = 1 to wxy;
+
+sql close
+sql connect wxy
+
+sql reset query cache;
+sql_error select * from test.st1; 
+sql insert into test.st1s1 values(now, 10);
+sql_error insert into test.st1s2 values(now, 20);
+sql_error select * from test.st2; 
+sql insert into test.st2s1 values(now, 10) test.st2s2 values(now, 20);
+
+system sh/exec.sh -n dnode1 -s stop -x SIGINT
diff --git a/tests/script/win-test-file b/tests/script/win-test-file
index 2d5a1b3108..3b358993fa 100644
--- a/tests/script/win-test-file
+++ b/tests/script/win-test-file
@@ -3,6 +3,7 @@
 ./test.sh -f tsim/user/privilege_db.sim
 ./test.sh -f tsim/user/privilege_sysinfo.sim
 ./test.sh -f tsim/user/privilege_topic.sim
+./test.sh -f tsim/user/privilege_table.sim
 ./test.sh -f tsim/db/alter_option.sim
 rem ./test.sh -f tsim/db/alter_replica_13.sim
 ./test.sh -f tsim/db/alter_replica_31.sim
diff --git a/tests/system-test/0-others/TS-3131.tsql b/tests/system-test/0-others/TS-3131.tsql
new file mode 100644
index 0000000000..6d4b4c53f4
--- /dev/null
+++ b/tests/system-test/0-others/TS-3131.tsql
@@ -0,0 +1,71 @@
+drop database if exists d0;
+create database d0 replica 1 keep 365 minRows 100 maxRows 4096 comp 2 vgroups 2 precision 'ms';
+use d0;
+create table if not exists almlog (starttime timestamp,endtime timestamp,durationtime int, alarmno int, alarmtext nchar(256),isactive nchar(64)) tags (mcid nchar(16));
+create table if not exists mplog (starttime timestamp,mpid int, paravalue nchar(256),mptype nchar(32)) tags (mcid nchar(16));
+create table if not exists mdlog (starttime timestamp,endtime timestamp,durationtime int, statuscode int, npcgmname nchar(256),attr int) tags (mcid nchar(16));
+create table if not exists nrglog (updatetime timestamp,energyvalue double,enerygyincrease double) tags (mcid nchar(16),enerygytype nchar(16));
+
+create table almlog_m201 using almlog tags("m201");
+create table almlog_m0103 using almlog tags("m0103");
+create table almlog_m0103_20031 using almlog tags("m0103");
+create table almlog_m0103_20032 using almlog tags("m0103");
+create table almlog_m0103_3003 using almlog tags("m0103");
+create table almlog_m0103_20033 using almlog tags("m0103");
+create table almlog_m0103_30031 using almlog tags("m0103");
+create table almlog_m0201 using almlog tags("m0201");
+create table almlog_m0102 using almlog tags("m0102");
+create table almlog_m0101 using almlog tags("m0101");
+create table almlog_m1002 using almlog tags("m1002");
+
+create table mplog_m0204_4 using mplog tags("m0204");
+create table mplog_m0204_5 using mplog tags("m0204");
+create table mplog_m0204_6 using mplog tags("m0204");
+create table mplog_m0204_12 using mplog tags("m0204");
+create table mplog_m0204 using mplog tags("m0204");
+create table mplog_m201 using mplog tags("m201");
+create table mplog_m0102 using mplog tags("m0102");
+create table mplog_m1101 using mplog tags("m1101");
+
+create table mdlog_m0102 using mplog tags("m0102");
+create table mdlog_m0504 using mplog tags("m0504");
+create table mdlog_m0505 using mplog tags("m0505");
+create table mdlog_m0507 using mplog tags("m0507");
+create table mdlog_m1002 using mplog tags("m1002");
+create table mdlog_m3201 using mplog tags("m3201");
+create table mdlog_m0201 using mplog tags("m0201");
+create table mdlog_m1102 using mplog tags("m1102");
+create table mdlog_m201 using mplog tags("m201");
+
+create table nrglog_m201_electricvalue1 using nrglog tags("m201","electricValue1");
+create table nrglog_m201_oilvalue1 using nrglog tags("m201","oilValue1");
+create table nrglog_m201_gasvalue1 using nrglog tags("m201","gasValue1");
+create table nrglog_m201_watervalue1 using nrglog tags("m201","waterValue1");
+create table nrglog_m0101_oilvalue1 using nrglog tags("m0101","oilValue1");
+create table nrglog_m0101_watervalue1 using nrglog tags("m0101","waterValue1");
+create table nrglog_m0102_gasvalue1 using nrglog tags("m0102","gasValue1");
+create table nrglog_m1903 using nrglog tags("m1903",NULL);
+create table nrglog_m2802 using nrglog tags("m2802",NULL);
+create table nrglog_m2101 using nrglog tags("m2101",NULL);
+create table nrglog_m0102 using nrglog tags("m0102",NULL);
+create table nrglog_m0101_electricvalue1 using nrglog tags("m0101","electricValue1");
+create table nrglog_m0101_gasvalue1 using nrglog tags("m0101","gasValue1");
+create table nrglog_m0102_electricvalue1 using nrglog tags("m0102","electricValue1");
+create table nrglog_m0102_oilvalue1 using nrglog tags("m0102","oilValue1");
+create table nrglog_m0102_watervalue1 using nrglog tags("m0102","waterValue1");
+
+
+insert into almlog_m0103 values(now,now+1s,10,0,'','dismissed');
+insert into almlog_m0103_20031 values(now,now+1s,10,20031,'','dismissed');
+insert into almlog_m0103_20032 values(now,now+1s,10,20032,'','dismissed');
+insert into almlog_m0103_3003 values(now,now+1s,10,3003,'','dismissed');
+insert into almlog_m0103_20033 values(now,now+1s,10,20033,'','dismissed');
+insert into almlog_m0103_30031 values(now,now+1s,10,30031,'','dismissed');
+
+flush database d0;
+
+show table tags from almlog;
+
+select *,tbname from d0.almlog where mcid='m0103';
+
+select table_name from information_schema.ins_tables where db_name='d0';
diff --git a/tests/system-test/0-others/compa4096.json b/tests/system-test/0-others/compa4096.json
index 5cc5d2084d..5e203ded45 100644
--- a/tests/system-test/0-others/compa4096.json
+++ b/tests/system-test/0-others/compa4096.json
@@ -53,18 +53,8 @@
           "sample_format": "csv",
           "sample_file": "./sample.csv",
           "tags_file": "",
-          "columns": [
-            {
-              "type": "INT",
-              "count": 4094
-            }
-          ],
-          "tags": [
-            {
-              "type": "TINYINT",
-              "count": 1
-            }
-                     ]
+          "columns": [{ "type": "INT","count": 4093}],
+          "tags": [{"type": "TINYINT", "count": 1},{"type": "NCHAR","count": 1}]
         }
       ]
     }
diff --git a/tests/system-test/0-others/compatibility.py b/tests/system-test/0-others/compatibility.py
index 1922ebfb2f..22e319fdaf 100644
--- a/tests/system-test/0-others/compatibility.py
+++ b/tests/system-test/0-others/compatibility.py
@@ -17,12 +17,12 @@ from util.dnodes import TDDnode
 from util.cluster import *
 import subprocess
 
-BASEVERSION = "3.0.1.8"
+BASEVERSION = "3.0.2.3"
 class TDTestCase:
     def caseDescription(self):
-        '''
+        f'''
         3.0 data compatibility test 
-        case1: basedata version is 3.0.1.8
+        case1: basedata version is {BASEVERSION}
         '''
         return
 
@@ -98,9 +98,12 @@ class TDTestCase:
 
     def buildTaosd(self,bPath):
         # os.system(f"mv {bPath}/build_bak  {bPath}/build ")
-        os.system(f" cd {bPath}  ")
-
+        os.system(f" cd {bPath} ")
 
+    def is_list_same_as_ordered_list(self,unordered_list, ordered_list):
+        sorted_list = sorted(unordered_list)
+        return sorted_list == ordered_list
+        
     def run(self):
         scriptsPath = os.path.dirname(os.path.realpath(__file__))
         distro_id = distro.id()
@@ -146,6 +149,8 @@ class TDTestCase:
         tdLog.info(" LD_LIBRARY_PATH=/usr/lib  taosBenchmark -f 0-others/compa4096.json -y  ")
         os.system("LD_LIBRARY_PATH=/usr/lib  taosBenchmark -f 0-others/compa4096.json -y")
         os.system("LD_LIBRARY_PATH=/usr/lib  taos -s 'flush database db4096 '")
+        os.system("LD_LIBRARY_PATH=/usr/lib  taos -f 0-others/TS-3131.tsql")
+
         cmd = f" LD_LIBRARY_PATH={bPath}/build/lib  {bPath}/build/bin/taos -h localhost ;"
         if os.system(cmd) == 0:
             raise Exception("failed to execute system command. cmd: %s" % cmd)
@@ -220,6 +225,17 @@ class TDTestCase:
                 tdLog.exit("%s(%d) failed" % args)
         tdsql.query("show streams;")
         tdsql.checkRows(2)
+        tdsql.query("select *,tbname from d0.almlog where mcid='m0103';")
+        tdsql.checkRows(6)
+        expectList = [0,3003,20031,20032,20033,30031]
+        resultList = []
+        for i in range(6):
+            resultList.append(tdsql.queryResult[i][3])
+        print(resultList)
+        if self.is_list_same_as_ordered_list(resultList,expectList):
+            print("The unordered list is the same as the ordered list.")
+        else:
+            tdlog.error("The unordered list is not the same as the ordered list.")
         tdsql.execute("insert into test.d80 values (now+1s, 11, 103, 0.21);")
         tdsql.execute("insert into test.d9 values (now+5s, 4.3, 104, 0.4);")
 
diff --git a/tests/system-test/0-others/multilevel.py b/tests/system-test/0-others/multilevel.py
new file mode 100644
index 0000000000..7ad4eba645
--- /dev/null
+++ b/tests/system-test/0-others/multilevel.py
@@ -0,0 +1,263 @@
+###################################################################
+#           Copyright (c) 2016 by TAOS Technologies, Inc.
+#                     All rights reserved.
+#
+#  This file is proprietary and confidential to TAOS Technologies.
+#  No part of this file may be reproduced, stored, transmitted,
+#  disclosed or used in any form or by any means other than as
+#  expressly provided by the written permission from Jianhui Tao
+#
+###################################################################
+
+# -*- coding: utf-8 -*-
+
+
+from util.log import *
+from util.cases import *
+from util.sql import *
+from util.common import *
+from util.sqlset import *
+
+class TDTestCase:
+    def init(self, conn, logSql, replicaVar=1):
+
+        self.replicaVar = int(replicaVar)
+        tdLog.debug("start to execute %s" % __file__)
+        tdSql.init(conn.cursor())
+        self.setsql = TDSetSql()
+
+    def basic(self):
+        tdLog.info("============== basic test ===============")
+        cfg={
+            '/mnt/data1' : 'dataDir',
+            '/mnt/data2 0 0' : 'dataDir'
+        }
+        tdSql.createDir('/mnt/data1')
+        tdSql.createDir('/mnt/data2')
+
+        tdLog.info("================= step1")
+        tdDnodes.stop(1)
+        tdDnodes.deploy(1,cfg)
+        tdDnodes.start(1)
+        
+        tdLog.info("================= step2")
+        tdSql.haveFile('/mnt/data1/',1)
+        tdSql.haveFile('/mnt/data2/',0)
+        tdDnodes.stop(1)
+    def dir_not_exist(self):
+        tdLog.info("============== dir_not_exist test ===============")
+        cfg={
+            '/mnt/data1 0 0' : 'dataDir',
+            '/mnt/data2 0 0' : 'dataDir'
+        }
+        tdSql.createDir('/mnt/data1')
+        os.system('rm -rf /mnt/data2')
+        
+
+        tdLog.info("================= step1")
+        tdDnodes.deploy(1,cfg)
+        tdDnodes.startWithoutSleep(1)
+        
+        tdLog.info("================= step2")
+        tdSql.taosdStatus(0)
+
+    def dir_permission_denied(self):
+        tdDnodes.stop(1)
+        tdLog.info("============== dir_permission_denied test ===============")
+        cfg={
+            '/mnt/data1 0 0' : 'dataDir',
+            '/mnt/data2 0 0' : 'dataDir'
+        }
+        tdSql.createDir('/mnt/data1')
+        tdSql.createDir('/mnt/data2')
+        os.system('chmod 111 /mnt/data2')
+
+        tdLog.info("================= step1")
+        tdDnodes.deploy(1,cfg)
+        tdDnodes.startWithoutSleep(1)
+        
+        tdLog.info("================= step2")
+        tdSql.taosdStatus(0)
+    
+    def file_distribution_same_level(self):
+        tdLog.info("============== file_distribution_same_level test ===============")
+        dataDir = ['data00','data01','data02','data03','data04']
+        dataDict = {'data00':0,'data01':0,'data02':0,'data03':0,'data04':0}
+        tdDnodes.stop(1)
+        self.ntables = 1000             
+        self.ts = 1520000010000
+        tdLog.info("================= step1")
+        cfg={
+            '/mnt/data00 0 1' : 'dataDir',
+            '/mnt/data01 0 0' : 'dataDir',
+            '/mnt/data02 0 0' : 'dataDir',
+            '/mnt/data03 0 0' : 'dataDir',
+            '/mnt/data04 0 0' : 'dataDir'
+        }
+        dir_list = ['/mnt/data00','/mnt/data01','/mnt/data02','/mnt/data03','/mnt/data04']
+        for i in dir_list:
+            tdSql.createDir(i)
+        tdDnodes.deploy(1,cfg)
+        tdDnodes.start(1)
+
+        tdSql.execute("create database test duration 1")
+        tdSql.execute("use test")
+
+        tdSql.execute("create table stb(ts timestamp, c int) tags(t int)")
+
+        for i in range(self.ntables):
+            tdSql.execute("create table tb%d using stb tags(%d)" %(i, i))            
+            tdSql.execute("insert into tb%d values(%d, 1)" % (i,self.ts + int (i / 100) * 86400000))
+
+        tdLog.info("================= step2")
+        tdDnodes.stop(1)
+        tdDnodes.start(1)
+        tdSql.query("select * from test.stb")
+        tdSql.checkRows(1000)
+        tdLog.info("================= step3")
+        tdSql.execute('drop database test')
+        for i in range(50):
+            tdSql.execute("create database test%d duration 1" %(i))
+            tdSql.execute("use test%d" %(i))
+            tdSql.execute("create table tb (ts timestamp,i int)") 
+            for j in range(10):           
+                tdSql.execute("insert into tb values(%d, 1)" % (self.ts + int (i / 100) * 86400000))
+        tdDnodes.stop(1)
+        tdDnodes.start(1)
+        flag = True
+        for i in range(4):
+            if dataDict[dataDir[i]] == dataDict[dataDir[i+1]]:
+                flag = flag & True
+            else:
+                flag = flag & False
+                break
+        if not flag : tdLog.exit("%s failed, expect  not occured" % (sys.argv[0]))
+    
+    def three_level_basic(self):
+        tdLog.info("============== three_level_basic test ===============")
+        tdDnodes.stop(1)
+        # Test1 1 dataDir
+        cfg={
+            '/mnt/data000 0 1' : 'dataDir',
+            '/mnt/data001 0 0' : 'dataDir',
+            '/mnt/data002 0 0' : 'dataDir',
+            '/mnt/data010 1 0' : 'dataDir',
+            '/mnt/data011 1 0' : 'dataDir',
+            '/mnt/data012 1 0' : 'dataDir',
+            '/mnt/data020 2 0' : 'dataDir',
+            '/mnt/data021 2 0' : 'dataDir',
+            '/mnt/data022 2 0' : 'dataDir'          
+        }
+        dir_list = ['/mnt/data000','/mnt/data001','/mnt/data002','/mnt/data010','/mnt/data011','/mnt/data012','/mnt/data020','/mnt/data021''/mnt/data022']
+        for i in dir_list:
+            tdSql.createDir(i)
+        
+        tdDnodes.deploy(1,cfg)
+        tdDnodes.start(1)
+        for i in dir_list:
+            if i == '/mnt/data000':
+                tdSql.haveFile(i,1)
+            else:
+                tdSql.haveFile(i,0)
+    
+    def more_than_16_disks(self):
+        tdLog.info("============== more_than_16_disks test ===============")
+        cfg={}
+        for i in range(17):
+            if i == 0 :
+                datadir = '/mnt/data%d 0 1' % (i+1)
+            else:
+                datadir = '/mnt/data%d 0 0' % (i+1)
+            cfg.update({ datadir : 'dataDir' })
+            tdSql.createDir('/mnt/data%d' % (i+1))
+        
+        tdLog.info("================= step1")
+        tdDnodes.stop(1)
+        tdDnodes.deploy(1,cfg)
+        tdDnodes.startWithoutSleep(1)
+        
+        tdLog.info("================= step2")
+        tdSql.taosdStatus(0)
+    
+    def missing_middle_level(self):
+        tdLog.info("============== missing_middle_level test ===============")
+        tdDnodes.stop(1)
+        # Test1 1 dataDir
+        cfg={
+            '/mnt/data1 1 0' : 'dataDir'           
+        }
+        tdSql.createDir('/mnt/data1')
+        
+        tdDnodes.deploy(1,cfg)
+        tdDnodes.startWithoutSleep(1)
+        
+        tdSql.taosdStatus(0)
+        tdDnodes.stop(1)
+        # Test2 2 dataDir
+        cfg = {
+            '/mnt/data1 0 1' : 'dataDir',
+            '/mnt/data1 2 0' : 'dataDir'
+        }
+        tdSql.createDir('/mnt/data1')
+        
+        tdDnodes.deploy(1,cfg)
+        tdDnodes.startWithoutSleep(1)
+        
+        tdSql.taosdStatus(0)
+
+    def trim_database(self):
+        tdLog.info("============== trim_database test ===============")
+        tdDnodes.stop(1)
+        cfg = {
+            '/mnt/data1 0 1' : 'dataDir'
+            
+        }
+        tdSql.createDir('/mnt/data1')
+        tdDnodes.deploy(1,cfg)
+        tdDnodes.start(1)
+
+        tdSql.execute('create database dbtest')
+        tdSql.execute('use dbtest')
+        tdSql.execute('create table stb (ts timestamp,c0 int) tags(t0 int)')
+        tdSql.execute('create table tb1 using stb tags(1)')
+        for i in range(10,30):
+            tdSql.execute(f'insert into tb1 values(now-{i}d,10)')
+        tdSql.execute('flush database dbtest')
+        tdSql.haveFile('/mnt/data1/',1)
+        tdDnodes.stop(1)
+        cfg={
+            '/mnt/data1 0 1' : 'dataDir',
+            '/mnt/data2 1 0' : 'dataDir',
+            '/mnt/data3 2 0' : 'dataDir',        
+        }
+        tdSql.createDir('/mnt/data2')
+        tdSql.createDir('/mnt/data3')
+        tdDnodes.deploy(1,cfg)
+        tdDnodes.start(1)
+        tdSql.haveFile('/mnt/data1/',1)
+        tdSql.haveFile('/mnt/data2/',0)
+        tdSql.haveFile('/mnt/data3/',0)
+        tdSql.execute('alter database dbtest keep 10d,365d,3650d')
+        tdSql.execute('trim database dbtest')
+        time.sleep(3)
+        tdSql.haveFile('/mnt/data1/',1)
+        tdSql.haveFile('/mnt/data2/',1)
+
+    def run(self):
+        self.basic()
+        self.dir_not_exist()
+        self.dir_permission_denied()
+        self.file_distribution_same_level()
+        self.three_level_basic()
+        self.more_than_16_disks()
+        self.trim_database()
+        self.missing_middle_level()
+        
+
+
+    def stop(self):
+        tdSql.close()
+        tdLog.success("%s successfully executed" % __file__)
+
+tdCases.addWindows(__file__, TDTestCase())
+tdCases.addLinux(__file__, TDTestCase())
diff --git a/tests/system-test/0-others/udf_create.py b/tests/system-test/0-others/udf_create.py
index f467e802ac..ee1a0ef5b3 100644
--- a/tests/system-test/0-others/udf_create.py
+++ b/tests/system-test/0-others/udf_create.py
@@ -47,17 +47,27 @@ class TDTestCase:
 
         if platform.system().lower() == 'windows':
             self.libudf1 = subprocess.Popen('(for /r %s %%i in ("udf1.d*") do @echo %%i)|grep lib|head -n1'%projPath , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8")
+            self.libudf1_dup = subprocess.Popen('(for /r %s %%i in ("udf1_dup.d*") do @echo %%i)|grep lib|head -n1'%projPath , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8")
             self.libudf2 = subprocess.Popen('(for /r %s %%i in ("udf2.d*") do @echo %%i)|grep lib|head -n1'%projPath , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8")
+            self.libudf2_dup = subprocess.Popen('(for /r %s %%i in ("udf2_dup.d*") do @echo %%i)|grep lib|head -n1'%projPath , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8")
             if (not tdDnodes.dnodes[0].remoteIP == ""):
                 tdDnodes.dnodes[0].remote_conn.get(tdDnodes.dnodes[0].config["path"]+'/debug/build/lib/libudf1.so',projPath+"\\debug\\build\\lib\\")
+                tdDnodes.dnodes[0].remote_conn.get(tdDnodes.dnodes[0].config["path"]+'/debug/build/lib/libudf1_dup.so',projPath+"\\debug\\build\\lib\\")
                 tdDnodes.dnodes[0].remote_conn.get(tdDnodes.dnodes[0].config["path"]+'/debug/build/lib/libudf2.so',projPath+"\\debug\\build\\lib\\")
+                tdDnodes.dnodes[0].remote_conn.get(tdDnodes.dnodes[0].config["path"]+'/debug/build/lib/libudf2_dup.so',projPath+"\\debug\\build\\lib\\")
                 self.libudf1 = self.libudf1.replace('udf1.dll','libudf1.so')
+                self.libudf1_dup = self.libudf1_dup.replace('udf1_dup.dll','libudf1_dup.so')
                 self.libudf2 = self.libudf2.replace('udf2.dll','libudf2.so')
+                self.libudf2_dup = self.libudf2_dup.replace('udf2_dup.dll','libudf2_dup.so')
         else:
             self.libudf1 = subprocess.Popen('find %s -name "libudf1.so"|grep lib|head -n1'%projPath , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8")
+            self.libudf1_dup = subprocess.Popen('find %s -name "libudf1_dup.so"|grep lib|head -n1'%projPath , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8")
             self.libudf2 = subprocess.Popen('find %s -name "libudf2.so"|grep lib|head -n1'%projPath , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8")
+            self.libudf2_dup = subprocess.Popen('find %s -name "libudf2_dup.so"|grep lib|head -n1'%projPath , shell=True, stdout=subprocess.PIPE,stderr=subprocess.STDOUT).stdout.read().decode("utf-8")
         self.libudf1 = self.libudf1.replace('\r','').replace('\n','')
+        self.libudf1_dup = self.libudf1_dup.replace('\r','').replace('\n','')
         self.libudf2 = self.libudf2.replace('\r','').replace('\n','')
+        self.libudf2_dup = self.libudf2_dup.replace('\r','').replace('\n','')
 
 
     def prepare_data(self):
@@ -174,10 +184,12 @@ class TDTestCase:
 
         # create  scalar functions
         tdSql.execute("create function udf1 as '%s' outputtype int;"%self.libudf1)
+        tdSql.execute("create function udf1_dup as '%s' outputtype int;"%self.libudf1_dup)
 
         # create aggregate functions
 
         tdSql.execute("create aggregate function udf2 as '%s' outputtype double bufSize 8;"%self.libudf2)
+        tdSql.execute("create aggregate function udf2_dup as '%s' outputtype double bufSize 8;"%self.libudf2_dup)
 
         functions = tdSql.getResult("show functions")
         function_nums = len(functions)
@@ -188,6 +200,13 @@ class TDTestCase:
 
         # scalar functions
 
+        # udf1_dup
+        tdSql.query("select udf1(num1) ,udf1_dup(num1) from tb")
+        tdSql.checkData(1,0,1)
+        tdSql.checkData(1,1,2)
+        tdSql.checkData(2,0,1)
+        tdSql.checkData(2,1,2)
+
         tdSql.execute("use db ")
         tdSql.query("select num1 , udf1(num1) ,num2 ,udf1(num2),num3 ,udf1(num3),num4 ,udf1(num4) from tb")
         tdSql.checkData(0,0,None)
@@ -238,6 +257,10 @@ class TDTestCase:
 
 
         # aggregate functions
+        tdSql.query("select udf2(num1) ,udf2_dup(num1) from tb")
+        val = tdSql.queryResult[0][0] + 100
+        tdSql.checkData(0,1,val)
+        
         tdSql.query("select udf2(num1) ,udf2(num2), udf2(num3) from tb")
         tdSql.checkData(0,0,15.362291496)
         tdSql.checkData(0,1,10000949.553189287)
diff --git a/tests/system-test/0-others/user_privilege.py b/tests/system-test/0-others/user_privilege.py
new file mode 100644
index 0000000000..d1b93f6942
--- /dev/null
+++ b/tests/system-test/0-others/user_privilege.py
@@ -0,0 +1,144 @@
+###################################################################
+#           Copyright (c) 2016 by TAOS Technologies, Inc.
+#                     All rights reserved.
+#
+#  This file is proprietary and confidential to TAOS Technologies.
+#  No part of this file may be reproduced, stored, transmitted,
+#  disclosed or used in any form or by any means other than as
+#  expressly provided by the written permission from Jianhui Tao
+#
+###################################################################
+
+# -*- coding: utf-8 -*-
+
+import taos
+from taos.tmq import *
+from util.cases import *
+from util.common import *
+from util.log import *
+from util.sql import *
+from util.sqlset import *
+
+
+class TDTestCase:
+    def init(self, conn, logSql, replicaVar=1):
+        self.replicaVar = int(replicaVar)
+        tdLog.debug("start to execute %s" % __file__)
+        tdSql.init(conn.cursor())
+        self.setsql = TDSetSql()
+        self.stbname = 'stb'
+        self.binary_length = 20  # the length of binary for column_dict
+        self.nchar_length = 20  # the length of nchar for column_dict
+        self.dbnames = ['db1', 'db2']
+        self.column_dict = {
+            'ts': 'timestamp',
+            'col1': 'float',
+            'col2': 'int',
+            'col3': 'float',
+        }
+        
+        self.tag_dict = {
+            't1': 'int',
+            't2': f'binary({self.binary_length})'
+        }
+        
+        self.tag_list = [
+            f'1, "Beijing"',
+            f'2, "Shanghai"',
+            f'3, "Guangzhou"',
+            f'4, "Shenzhen"'
+        ]
+        
+        self.values_list = [
+            f'now, 9.1, 200, 0.3'            
+        ]
+        
+        self.tbnum = 4
+
+    def create_user(self):
+        user_name = 'test'        
+        tdSql.execute(f'create user {user_name} pass "test"')
+        tdSql.execute(f'grant read on {self.dbnames[0]}.{self.stbname} with t2 = "Beijing" to {user_name}')
+        tdSql.execute(f'grant write on {self.dbnames[1]}.{self.stbname} with t1 = 2 to {user_name}')
+                
+    def prepare_data(self):
+        for db in self.dbnames:
+            tdSql.execute(f"create database {db}")
+            tdSql.execute(f"use {db}")
+            tdSql.execute(self.setsql.set_create_stable_sql(self.stbname, self.column_dict, self.tag_dict))
+            for i in range(self.tbnum):
+                tdSql.execute(f'create table {self.stbname}_{i} using {self.stbname} tags({self.tag_list[i]})')
+                for j in self.values_list:
+                    tdSql.execute(f'insert into {self.stbname}_{i} values({j})')
+    
+    def user_read_privilege_check(self, dbname):
+        testconn = taos.connect(user='test', password='test')        
+        expectErrNotOccured = False
+        
+        try:
+            sql = f"select count(*) from {dbname}.stb where t2 = 'Beijing'"
+            res = testconn.query(sql)
+            data = res.fetch_all()
+            count = data[0][0]            
+        except BaseException:
+            expectErrNotOccured = True
+        
+        if expectErrNotOccured:
+            caller = inspect.getframeinfo(inspect.stack()[1][0])
+            tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{sql}, expect error not occured")
+        elif count != 1:
+            tdLog.exit(f"{sql}, expect result doesn't match")
+        pass
+    
+    def user_write_privilege_check(self, dbname):
+        testconn = taos.connect(user='test', password='test')        
+        expectErrNotOccured = False
+        
+        try:            
+            sql = f"insert into {dbname}.stb_1 values(now, 1.1, 200, 0.3)"
+            testconn.execute(sql)            
+        except BaseException:
+            expectErrNotOccured = True
+        
+        if expectErrNotOccured:
+            caller = inspect.getframeinfo(inspect.stack()[1][0])
+            tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{sql}, expect error not occured")
+        else:
+            pass
+    
+    def user_privilege_error_check(self):
+        testconn = taos.connect(user='test', password='test')        
+        expectErrNotOccured = False
+        
+        sql_list = [f"alter talbe {self.dbnames[0]}.stb_1 set t2 = 'Wuhan'", 
+                    f"insert into {self.dbnames[0]}.stb_1 values(now, 1.1, 200, 0.3)", 
+                    f"drop table {self.dbnames[0]}.stb_1", 
+                    f"select count(*) from {self.dbnames[1]}.stb"]
+        
+        for sql in sql_list:
+            try:
+                res = testconn.execute(sql)                        
+            except BaseException:
+                expectErrNotOccured = True
+            
+            if expectErrNotOccured:
+                pass
+            else:
+                caller = inspect.getframeinfo(inspect.stack()[1][0])
+                tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{sql}, expect error not occured")
+        pass
+
+    def run(self):           
+        self.prepare_data()
+        self.create_user()
+        self.user_read_privilege_check(self.dbnames[0])
+        self.user_write_privilege_check(self.dbnames[1])
+        self.user_privilege_error_check()
+                
+    def stop(self):
+        tdSql.close()
+        tdLog.success("%s successfully executed" % __file__)
+
+
+tdCases.addWindows(__file__, TDTestCase())
+tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
diff --git a/tests/system-test/1-insert/alter_replica.py b/tests/system-test/1-insert/alter_replica.py
new file mode 100644
index 0000000000..900b64d943
--- /dev/null
+++ b/tests/system-test/1-insert/alter_replica.py
@@ -0,0 +1,114 @@
+import taos
+import sys
+import time
+import socket
+import os
+import threading
+import datetime
+
+from util.log import *
+from util.sql import *
+from util.cases import *
+from util.dnodes import *
+
+
+class TDTestCase:
+    def init(self, conn, logSql, replicaVar=1):
+        self.replicaVar = int(replicaVar)
+        tdLog.debug("start to execute %s" % __file__)
+        tdSql.init(conn.cursor(), logSql)        
+        
+    def checkVgroups(self, dbName, vgNum):
+        sleepNum = vgNum * 60
+        flag = 0
+        while (sleepNum > 0):
+            sql = f'show {dbName}.vgroups'
+            tdSql.query(sql)
+            flag = 0
+            for vgid in range (vgNum) :
+                v1_status = tdSql.queryResult[vgid][4]
+                v2_status = tdSql.queryResult[vgid][6]
+                v3_status = tdSql.queryResult[vgid][8]
+                if ((v1_status == 'leader') and (v2_status == 'follower') and (v3_status == 'follower')) \
+                or ((v2_status == 'leader') and (v1_status == 'follower') and (v3_status == 'follower')) \
+                or ((v3_status == 'leader') and (v2_status == 'follower') and (v1_status == 'follower')):
+                    continue
+                else: 
+                    sleepNum = sleepNum - 1
+                    time.sleep(1)
+                    flag = 1
+                    break
+            if (0 == flag):
+                return 0
+        tdLog.debug("vgroup[%d] status: %s, %s, %s" %(vgid,v1_status,v2_status,v3_status))
+        return -1
+        
+    def alter_replica(self):        
+        # create db and alter replica
+        tdLog.debug("====alter db repica 1====")
+        vgNum = 3
+        dbName = 'db1'
+        sql = f'create database {dbName} vgroups {vgNum}'
+        tdSql.execute(sql)
+        sql = f'alter database {dbName} replica 3'
+        tdSql.execute(sql)
+        tdLog.debug("start check time: %s"%(str(datetime.datetime.now())))
+        res = self.checkVgroups(dbName, vgNum)       
+        tdLog.debug("end   check time: %s"%(str(datetime.datetime.now())))
+        if (0 != res):
+            tdLog.exit(f'fail: alter database {dbName} replica 3') 
+        
+        # create db, stable, child tables, and insert data, then alter replica
+        tdLog.debug("====alter db repica 2====")
+        dbName = 'db2'
+        sql = f'create database {dbName} vgroups {vgNum}'
+        tdSql.execute(sql)        
+        sql = f'use {dbName}'
+        tdSql.execute(sql)
+        sql = f'create stable stb (ts timestamp, c int) tags (t int)'
+        tdSql.execute(sql)
+        sql = f'create table ctb using stb tags (1)'
+        tdSql.execute(sql)
+        sql = f'insert into ctb values (now, 1) (now+1s, 2) (now+2s, 3)'
+        tdSql.execute(sql)
+        sql = f'alter database {dbName} replica 3'
+        tdSql.execute(sql)
+        tdLog.debug("start check time: %s"%(str(datetime.datetime.now())))
+        res = self.checkVgroups(dbName, vgNum)
+        tdLog.debug("end   check time: %s"%(str(datetime.datetime.now())))
+        if (0 != res):
+            tdLog.exit(f'fail: alter database {dbName} replica 3')        
+        
+        # firstly create db, stable, child tables, and insert data, then drop stable, and then alter replica
+        tdLog.debug("====alter db repica 3====")
+        dbName = 'db3'
+        sql = f'create database {dbName} vgroups {vgNum}'
+        tdSql.execute(sql)
+        sql = f'use {dbName}'
+        tdSql.execute(sql)
+        sql = f'create stable stb (ts timestamp, c int) tags (t int)'
+        tdSql.execute(sql)
+        sql = f'create table ctb using stb tags (1)'
+        tdSql.execute(sql)
+        sql = f'insert into ctb values (now, 1) (now+1s, 2) (now+2s, 3)'
+        tdSql.execute(sql)      
+        sql = f'drop table stb'
+        tdSql.execute(sql)        
+        sql = f'alter database {dbName} replica 3'
+        tdSql.execute(sql)
+        tdLog.debug("start check time: %s"%(str(datetime.datetime.now())))
+        res = self.checkVgroups(dbName, vgNum)
+        tdLog.debug("end   check time: %s"%(str(datetime.datetime.now())))
+        if (0 != res):
+            tdLog.exit(f'fail: alter database {dbName} replica 3')
+
+    def run(self):
+        self.alter_replica()
+
+    def stop(self):
+        tdSql.close()
+        tdLog.success(f"{__file__} successfully executed")
+
+
+tdCases.addLinux(__file__, TDTestCase())
+tdCases.addWindows(__file__, TDTestCase())
diff --git a/tests/system-test/1-insert/database_pre_suf.py b/tests/system-test/1-insert/database_pre_suf.py
index a6ff95ab3f..2e993b9a40 100755
--- a/tests/system-test/1-insert/database_pre_suf.py
+++ b/tests/system-test/1-insert/database_pre_suf.py
@@ -24,9 +24,7 @@ from util.dnodes import tdDnodes
 from util.dnodes import *
 
 class TDTestCase:
-    updatecfgDict = {'maxSQLLength':1048576,'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , 
-    "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143,
-    "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"fnDebugFlag":143}
+    updatecfgDict = {'maxSQLLength':1048576,'debugFlag': 135}
     
     def init(self, conn, logSql, replicaVar=1):
         self.replicaVar = int(replicaVar)
@@ -39,7 +37,9 @@ class TDTestCase:
         
         self.db = "pre_suf"
 
-    def dropandcreateDB_random(self,database,n,vgroups,table_prefix,table_suffix,check_result):
+    def dropandcreateDB_random(self,database,n,vgroups,table_prefix,table_suffix,check_result_positive,check_result_negative):
+        #check_result_positive 检查前缀后缀是正数的,check_result_negative 检查前缀后缀是负数的(TS-3249)
+        tdLog.info(f"create start:n:{n},vgroups:{vgroups},table_prefix:{table_prefix},table_suffix:{table_suffix},check_result_positive:{check_result_positive},check_result_negative:{check_result_negative}") 
         ts = 1630000000000
         num_random = 100
         fake = Faker('zh_CN')
@@ -56,6 +56,7 @@ class TDTestCase:
                 q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \
                 tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);''')
         
+        #positive
         for i in range(10*n):
             tdSql.execute('''create table bj_%d (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp ) ;'''%i)
             tdSql.execute('''create table sh_%d (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp ) ;'''%i)
@@ -106,11 +107,60 @@ class TDTestCase:
                         fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , 
                         fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1)))
 
-        
+        #negative
+        for i in range(10*n):
+            tdSql.execute('''create table bj_table_%d_r_negative (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp ) ;'''%i)
+            tdSql.execute('''create table sh_table_%d_r_negative (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp ) ;'''%i)
+            tdSql.execute('''create table hn_table_%d_r_negative \
+                    (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \
+                    q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\
+                    q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\
+                    q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;'''%i)
+            
+            tdSql.execute('''create table bj_stable_1_%d_negative using stable_1 tags('bj_stable_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' 
+                      %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), 
+                        fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , 
+                        fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) 
+            tdSql.execute('''create table sh_table_%d_a_negative using stable_1 tags('sh_a_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' 
+                      %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), 
+                        fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , 
+                        fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) 
+            tdSql.execute('''create table sh_table_%d_b_negative using stable_1 tags('sh_b_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' 
+                      %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), 
+                        fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , 
+                        fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1)))
+            tdSql.execute('''create table sh_table_%d_c_negative using stable_1 tags('sh_c_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' 
+                      %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), 
+                        fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , 
+                        fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1)))
+            
+            tdSql.execute('''create table bj_table_%d_a_negative using stable_1 tags('bj_a_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' 
+                      %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), 
+                        fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , 
+                        fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) 
+            tdSql.execute('''create table bj_table_%d_b_negative using stable_1 tags('bj_b_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' 
+                      %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), 
+                        fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , 
+                        fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1)))
+            tdSql.execute('''create table bj_table_%d_c_negative using stable_1 tags('bj_c_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' 
+                      %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), 
+                        fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , 
+                        fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1)))
+
+            
+            tdSql.execute('''create table tj_table_%d_a_negative using stable_2 tags('tj_a_table_2_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' 
+                      %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), 
+                        fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , 
+                        fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) 
+            tdSql.execute('''create table tj_table_%d_b_negative using stable_2 tags('tj_b_table_2_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' 
+                      %(i,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), 
+                        fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , 
+                        fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1)))
+            
         # create stream
         tdSql.execute('''create stream current_stream trigger at_once IGNORE EXPIRED 0 into stream_max_stable_1 as select _wstart as startts, _wend as wend, max(q_int) as max_int, min(q_bigint) as min_int from stable_1 where ts is not null interval (5s);''')
         
-        # insert data
+        # insert data positive
         for i in range(num_random*n):        
             tdSql.execute('''insert into bj_stable_1_1  (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double , q_bool , q_binary , q_nchar, q_ts,\
                         q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \
@@ -180,8 +230,60 @@ class TDTestCase:
                         fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , 
                         fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr()))
 
+        # insert data negative
+        for i in range(num_random*n):        
+            tdSql.execute('''insert into bj_stable_1_1_negative  (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double , q_bool , q_binary , q_nchar, q_ts,\
+                        q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \
+                        values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \
+                        'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' 
+                        % (ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1), 
+                        fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), 
+                        fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , 
+                        fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , 
+                        fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr()))
+
+            tdSql.execute('''insert into bj_stable_1_2_negative (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\
+                        q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8)\
+                        values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \
+                        'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' 
+                        % (ts + i*1000, fake.random_int(min=0, max=2147483647, step=1), 
+                        fake.random_int(min=0, max=9223372036854775807, step=1), 
+                        fake.random_int(min=0, max=32767, step=1) , fake.random_int(min=0, max=127, step=1) , 
+                        fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , 
+                        fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr()))
+
+            tdSql.execute('''insert into bj_stable_1_3_negative (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\
+                        q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \
+                        values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \
+                        'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' 
+                        % (ts + i*1000, fake.random_int(min=-0, max=2147483647, step=1), 
+                        fake.random_int(min=-0, max=9223372036854775807, step=1), 
+                        fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , 
+                        fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , 
+                        fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr()))
+
+            tdSql.execute('''insert into bj_stable_1_4_negative (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\
+                        q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \
+                        values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \
+                        'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' 
+                        % (ts + i*1000 +1, fake.random_int(min=-0, max=2147483647, step=1), 
+                        fake.random_int(min=-0, max=9223372036854775807, step=1), 
+                        fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , 
+                        fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , 
+                        fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr()))
+
+            tdSql.execute('''insert into bj_stable_1_5_negative (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\
+                        q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \
+                        values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \
+                        'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' 
+                        % (ts + i*1000 +10, fake.random_int(min=-0, max=2147483647, step=1), 
+                        fake.random_int(min=-0, max=9223372036854775807, step=1), 
+                        fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , 
+                        fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , 
+                        fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr()))
+            
         tdSql.query("select count(*) from stable_1;")
-        tdSql.checkData(0,0,5*num_random*n)
+        tdSql.checkData(0,0,10*num_random*n)
         tdSql.query("select count(*) from hn_table_1_r;")
         tdSql.checkData(0,0,num_random*n)
         
@@ -220,39 +322,28 @@ class TDTestCase:
         
         
         tdSql.query(" select * from information_schema.ins_databases where name = '%s';" %database)
-        print(tdSql.queryResult)
+        tdLog.info(tdSql.queryResult)
         
-        # tdSql.query(" select table_prefix,table_suffix from information_schema.ins_databases where name = '%s';" %database)
-        # print(tdSql.queryResult)
-        #TD-19082
-        
-        #tdSql.query(" select * from information_schema.ins_tables where db_name = '%s';" %database)
-        #print(tdSql.queryResult)
-        
-        tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s';" %database)  
+        tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' limit 3;" %database)  
         queryRows = len(tdSql.queryResult)    
         for i in range(queryRows):
-            print("row=%d,  vgroup_id=%s,  tbname=%s " %(i,tdSql.queryResult[i][1],tdSql.queryResult[i][0]))
+            tdLog.info("row=%d,  vgroup_id=%s,  tbname=%s " %(i,tdSql.queryResult[i][1],tdSql.queryResult[i][0]))
         
         tdLog.info("\n=============flush database ====================\n")
         
         tdSql.execute(" flush database %s;" %database)
         
         tdSql.query(" select * from information_schema.ins_databases where name = '%s';" %database)
-        print(tdSql.queryResult)
-        
-        # tdSql.query(" select table_prefix,table_suffix from information_schema.ins_databases where name = '%s';" %database)
-        # print(tdSql.queryResult)
-        #TD-19082
-        
-        tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s';" %database)
+        tdLog.info(tdSql.queryResult)
+               
+        tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' limit 3;" %database)
         queryRows = len(tdSql.queryResult)    
         for i in range(queryRows):
-            print("row=%d,  vgroup_id=%s,  tbname=%s " %(i,tdSql.queryResult[i][1],tdSql.queryResult[i][0]))
+            tdLog.info("row=%d,  vgroup_id=%s,  tbname=%s " %(i,tdSql.queryResult[i][1],tdSql.queryResult[i][0]))
 
 
         # check in one vgroup
-        if check_result == 'Y':
+        if check_result_positive == 'Y':
             #base table : sh_table_0_a
             tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='sh_table_0_a';" %(database))
             base_value_table_name = tdSql.queryResult[0][0]
@@ -324,8 +415,100 @@ class TDTestCase:
                 tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='tj_table_%d_b';" %(database,i))
                 self.value_check(base_value_table_name,base_value_table_vgroup)
                          
+        elif check_result_negative == 'Y':
+            #base table : sh_table_0_a
+            tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='sh_table_0_a_negative';" %(database))
+            base_value_table_name = tdSql.queryResult[0][0]
+            base_value_table_vgroup = tdSql.queryResult[0][1]
+            
+            #check table :sh_table_i_a
+            check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'sh_table_%%_a_negative';" %(database))
+            for i in range(check_rows):
+                tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='sh_table_%d_a_negative';" %(database,i))
+                self.value_check(base_value_table_name,base_value_table_vgroup)
+                        
+            #check table :sh_table_i_b
+            check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'sh_table_%%_b_negative';" %(database))
+            for i in range(check_rows):
+                tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='sh_table_%d_b_negative';" %(database,i))
+                self.value_check(base_value_table_name,base_value_table_vgroup) 
+                       
+            #check table :sh_table_i_c
+            check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'sh_table_%%_c_negative';" %(database))
+            for i in range(check_rows):
+                tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='sh_table_%d_c_negative';" %(database,i))
+                self.value_check(base_value_table_name,base_value_table_vgroup)
+                    
+            #check table :sh_table_i_r
+            check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'sh_table_%%_r_negative';" %(database))
+            for i in range(check_rows):
+                tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='sh_table_%d_r_negative';" %(database,i))
+                self.value_check(base_value_table_name,base_value_table_vgroup)
+                
+            #base table : bj_table_0_a
+            tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='bj_table_0_a_negative';" %(database))
+            base_value_table_name = tdSql.queryResult[0][0]
+            base_value_table_vgroup = tdSql.queryResult[0][1]
+                
+            #check table :bj_table_i_a
+            check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'bj_table_%%_a_negative';" %(database))
+            for i in range(check_rows):
+                tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='bj_table_%d_a_negative';" %(database,i))
+                self.value_check(base_value_table_name,base_value_table_vgroup)
+                
+            #check table :bj_table_i_b
+            check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'bj_table_%%_b_negative';" %(database))
+            for i in range(check_rows):
+                tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='bj_table_%d_b_negative';" %(database,i))
+                self.value_check(base_value_table_name,base_value_table_vgroup)
+                
+            #check table :bj_table_i_c
+            check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'bj_table_%%_c_negative';" %(database))
+            for i in range(check_rows):
+                tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='bj_table_%d_c_negative';" %(database,i))
+                self.value_check(base_value_table_name,base_value_table_vgroup)
+                
+            #check table :bj_table_i_r
+            check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'bj_table_%%_r_negative';" %(database))
+            for i in range(check_rows):
+                tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='bj_table_%d_r_negative';" %(database,i))
+                self.value_check(base_value_table_name,base_value_table_vgroup)
+                
+            #base table : hn_table_0_r
+            tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='hn_table_0_r_negative';" %(database))
+            base_value_table_name = tdSql.queryResult[0][0]
+            base_value_table_vgroup = tdSql.queryResult[0][1]
+            
+            #check table :hn_table_i_r
+            check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'hn_table_%%_r_negative';" %(database))
+            for i in range(check_rows):
+                tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='hn_table_%d_r_negative';" %(database,i))
+                self.value_check(base_value_table_name,base_value_table_vgroup)
+                
+                
+            #base table : tj_table_0_r
+            tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='tj_table_0_a_negative';" %(database))
+            base_value_table_name = tdSql.queryResult[0][0]
+            base_value_table_vgroup = tdSql.queryResult[0][1]
+            
+            #check table :tj_table_i_a
+            check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'tj_table_%%_a_negative';" %(database))
+            for i in range(check_rows):
+                tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='tj_table_%d_a_negative';" %(database,i))
+                self.value_check(base_value_table_name,base_value_table_vgroup)
+                
+            #check table :tj_table_i_b
+            check_rows = tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name like 'tj_table_%%_b_negative';" %(database))
+            for i in range(check_rows):
+                tdSql.query(" select table_name,vgroup_id from information_schema.ins_tables where db_name = '%s' and table_name='tj_table_%d_b_negative';" %(database,i))
+                self.value_check(base_value_table_name,base_value_table_vgroup)
+                
+                
         else:
             pass
+        
+        tdLog.info(f"create end:n:{n},vgroups:{vgroups},table_prefix:{table_prefix},table_suffix:{table_suffix},check_result_positive:{check_result_positive},check_result_negative:{check_result_negative}") 
+        
     
     def value_check(self,base_value_table_name,base_value_table_vgroup):
         check_value_table_name = tdSql.queryResult[0][0]
@@ -348,17 +531,28 @@ class TDTestCase:
                   
         os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) 
         
-        #(self,database,n,vgroups,table_prefix,table_suffix)
-        self.dropandcreateDB_random("%s" %self.db, 1,2,0,0,'N')
-        self.dropandcreateDB_random("%s" %self.db, 1,2,0,2,'N')
-        self.dropandcreateDB_random("%s" %self.db, 1,2,2,0,'N')
-        self.dropandcreateDB_random("%s" %self.db, 1,2,3,3,'Y')  
-        self.dropandcreateDB_random("%s" %self.db, 1,3,3,3,'Y')  
-        self.dropandcreateDB_random("%s" %self.db, 1,4,4,4,'Y')
-        self.dropandcreateDB_random("%s" %self.db, 1,5,5,5,'Y')
+        #(self,database,n,vgroups,table_prefix,table_suffix,check_result_positive,check_result_negative):
+        #check_result_positive 检查前缀后缀是正数的,check_result_negative 检查前缀后缀是负数的(TS-3249)
+        # self.dropandcreateDB_random("%s" %self.db, 1,2,0,0,'N','N')
+        # self.dropandcreateDB_random("%s" %self.db, 1,2,0,2,'N','N')
+        # self.dropandcreateDB_random("%s" %self.db, 1,2,2,0,'N','N')        
+        
+        self.dropandcreateDB_random("%s" %self.db, 1,random.randint(1,5),random.randint(0,3),random.randint(0,3),'N','N')
+        self.dropandcreateDB_random("%s" %self.db, 1,random.randint(1,5),random.randint(-10,0),random.randint(-10,0),'N','N')
+        self.dropandcreateDB_random("%s" %self.db, 1,random.randint(1,5),random.randint(-191,0),random.randint(-191,0),'N','N')
+        self.dropandcreateDB_random("%s" %self.db, 1,random.randint(1,5),random.randint(0,100),random.randint(0,91),'N','N')
+        
+        # self.dropandcreateDB_random("%s" %self.db, 1,2,3,3,'Y','N')  
+        # self.dropandcreateDB_random("%s" %self.db, 1,3,3,3,'Y','N')  
+        # self.dropandcreateDB_random("%s" %self.db, 1,4,4,4,'Y','N')
+        # self.dropandcreateDB_random("%s" %self.db, 1,5,5,5,'Y','N')       
+        self.dropandcreateDB_random("%s" %self.db, 1,random.randint(1,5),random.randint(3,5),random.randint(3,5),'Y','N')
+                
+        self.dropandcreateDB_random("%s" %self.db, 1,random.randint(1,5),random.randint(-5,-1),0,'N','Y')        
+        self.dropandcreateDB_random("%s" %self.db, 1,random.randint(1,5),random.randint(-5,-1),random.randint(-9,-0),'N','Y')
         
         
-        #taos -f sql
+        # #taos -f sql
         print("taos -f sql start!")
         taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename)
         _ = subprocess.check_output(taos_cmd1, shell=True)
diff --git a/tests/system-test/1-insert/delete_stable.py b/tests/system-test/1-insert/delete_stable.py
index 313b6ce731..8ebe7b6692 100644
--- a/tests/system-test/1-insert/delete_stable.py
+++ b/tests/system-test/1-insert/delete_stable.py
@@ -29,6 +29,9 @@ class TDTestCase:
         tdLog.debug("start to execute %s" % __file__)
         tdSql.init(conn.cursor())
         self.dbname = 'db_test'
+        self.ns_dbname = 'ns_test'
+        self.us_dbname = 'us_test'
+        self.ms_dbname = 'ms_test'
         self.setsql = TDSetSql()
         self.stbname = 'stb'
         self.ntbname = 'ntb'
@@ -220,11 +223,45 @@ class TDTestCase:
                 tdSql.query(f'select {func}(*) from {self.stbname}')
             tdSql.execute(f'drop table {self.stbname}')
         tdSql.execute(f'drop database {self.dbname}')
+
+    def precision_now_check(self):
+        for dbname in [self.ms_dbname, self.us_dbname, self.ns_dbname]:
+            self.ts = 1537146000000
+            if dbname == self.us_dbname:
+                self.ts = int(self.ts*1000)
+                precision = "us"
+            elif dbname == self.ns_dbname:
+                precision = "ns"
+                self.ts = int(self.ts*1000000)
+            else:
+                precision = "ms"
+                self.ts = int(self.ts)
+            tdSql.execute(f'drop database if exists {dbname}')
+            tdSql.execute(f'create database if not exists {dbname} precision "{precision}"')
+            tdSql.execute(f'use {dbname}')
+            self.base_data = {
+                'tinyint':self.tinyint_val
+                        }
+            self.column_dict = {
+                'col1': 'tinyint'
+            }
+            for col_name,col_type in self.column_dict.items():
+                tdSql.execute(f'create table if not exists {self.stbname} (ts timestamp,{col_name} {col_type}) tags(t1 int)')
+                for i in range(self.tbnum):
+                    tdSql.execute(f'create table if not exists {self.stbname}_{i} using {self.stbname} tags(1)')
+                    self.insert_base_data(col_type,f'{self.stbname}_{i}',self.rowNum,self.base_data)
+                tdSql.query(f'select * from {self.stbname}')
+                tdSql.checkEqual(tdSql.queryRows, self.tbnum*self.rowNum)
+                tdSql.execute(f'delete from {self.stbname} where ts < now()')
+                tdSql.query(f'select * from {self.stbname}')
+                tdSql.checkEqual(tdSql.queryRows, 0)
+
     def run(self):
         self.delete_data_stb()
         tdDnodes.stoptaosd(1)
         tdDnodes.starttaosd(1)
         self.delete_data_stb()
+        self.precision_now_check()
     def stop(self):
         tdSql.close()
         tdLog.success("%s successfully executed" % __file__)
diff --git a/tests/system-test/1-insert/delete_systable.py b/tests/system-test/1-insert/delete_systable.py
new file mode 100644
index 0000000000..40422a7515
--- /dev/null
+++ b/tests/system-test/1-insert/delete_systable.py
@@ -0,0 +1,111 @@
+
+###################################################################
+#           Copyright (c) 2016 by TAOS Technologies, Inc.
+#                     All rights reserved.
+#
+#  This file is proprietary and confidential to TAOS Technologies.
+#  No part of this file may be reproduced, stored, transmitted,
+#  disclosed or used in any form or by any means other than as
+#  expressly provided by the written permission from Jianhui Tao
+#
+###################################################################
+
+# -*- coding: utf-8 -*-
+
+import random
+import string
+
+from numpy import logspace
+from util import constant
+from util.log import *
+from util.cases import *
+from util.sql import *
+from util.common import *
+from util.sqlset import TDSetSql
+
+info_schema_db = "information_schema"
+perf_schema_db = "performance_schema"
+
+info_schema_tables = [
+    "ins_dnodes",
+    "ins_mnodes",
+    "ins_modules",
+    "ins_qnodes",
+    "ins_snodes",
+    "ins_cluster",
+    "ins_databases",
+    "ins_functions",
+    "ins_indexes",
+    "ins_stables",
+    "ins_tables",
+    "ins_tags",
+    "ins_columns",
+    "ins_users",
+    "ins_grants",
+    "ins_vgroups",
+    "ins_configs",
+    "ins_dnode_variables",
+    "ins_topics",
+    "ins_subscriptions",
+    "ins_streams",
+    "ins_streams_tasks",
+    "ins_vnodes",
+    "ins_user_privileges"
+]
+
+perf_schema_tables = [
+    "perf_connections",
+    "perf_queries",
+    "perf_consumers",
+    "perf_trans",
+    "perf_apps"
+]
+
+class TDTestCase:
+    def init(self, conn, logSql, replicaVar=1):
+        self.replicaVar = int(replicaVar)
+        tdLog.debug("start to execute %s" % __file__)
+        tdSql.init(conn.cursor())
+
+    def delete_systb(self):
+        tdSql.execute(f'use {info_schema_db}')
+        for i in info_schema_tables:
+            tdSql.error(f'delete from {i}')
+            tdSql.error(f'delete from {info_schema_db}.{i}')
+            tdSql.error(f'delete from {i} where ts >= 0')
+            tdSql.error(f'delete from {info_schema_db}.{i} where ts >= 0')
+
+        tdSql.execute(f'use {perf_schema_db}')
+        for i in perf_schema_tables:
+            tdSql.error(f'delete from {i}')
+            tdSql.error(f'delete from {perf_schema_db}.{i}')
+            tdSql.error(f'delete from {i} where ts >= 0')
+            tdSql.error(f'delete from {perf_schema_db}.{i} where ts >= 0')
+
+    def drop_systb(self):
+        tdSql.execute(f'use {info_schema_db}')
+        for i in info_schema_tables:
+            tdSql.error(f'drop table {i}')
+            tdSql.error(f'drop {info_schema_db}.{i}')
+        tdSql.error(f'drop database {info_schema_db}')
+
+        tdSql.execute(f'use {perf_schema_db}')
+        for i in perf_schema_tables:
+            tdSql.error(f'drop table {i}')
+            tdSql.error(f'drop table {perf_schema_db}.{i}')
+        tdSql.error(f'drop database {perf_schema_db}')
+
+    def delete_from_systb(self):
+        self.delete_systb()
+        self.drop_systb()
+    def run(self):
+        self.delete_from_systb()
+        tdDnodes.stoptaosd(1)
+        tdDnodes.starttaosd(1)
+        self.delete_from_systb()
+    def stop(self):
+        tdSql.close()
+        tdLog.success("%s successfully executed" % __file__)
+
+tdCases.addWindows(__file__, TDTestCase())
+tdCases.addLinux(__file__, TDTestCase())
diff --git a/tests/system-test/2-query/select_null.py b/tests/system-test/2-query/select_null.py
new file mode 100755
index 0000000000..68eea8bc67
--- /dev/null
+++ b/tests/system-test/2-query/select_null.py
@@ -0,0 +1,446 @@
+###################################################################
+#           Copyright (c) 2016 by TAOS Technologies, Inc.
+#                     All rights reserved.
+#
+#  This file is proprietary and confidential to TAOS Technologies.
+#  No part of this file may be reproduced, stored, transmitted,
+#  disclosed or used in any form or by any means other than as
+#  expressly provided by the written permission from Jianhui Tao
+#
+###################################################################
+
+# -*- coding: utf-8 -*-
+
+import random
+import os
+import time
+import taos
+import subprocess
+from faker import Faker
+from util.log import tdLog
+from util.cases import tdCases
+from util.sql import tdSql
+from util.dnodes import tdDnodes
+from util.dnodes import *
+
+class TDTestCase:
+    
+    def init(self, conn, logSql, replicaVar):
+        tdLog.debug("start to execute %s" % __file__)
+        tdSql.init(conn.cursor(), logSql)
+
+        self.testcasePath = os.path.split(__file__)[0]
+        self.testcaseFilename = os.path.split(__file__)[-1]
+        os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename))
+        
+        self.db = "sel_null"
+
+    def insert_data(self,database,vgroups):
+        num_random = 10
+        tdSql.execute('''drop database if exists %s ;''' %database)
+        tdSql.execute('''create database %s keep 36500 vgroups %d PRECISION 'us';'''%(database,vgroups))
+        tdSql.execute('''use %s;'''%database)
+
+        tdSql.execute('''create stable %s.stb0 (ts timestamp , c0 int , c1 double , c0null int , c1null double ) tags( t0 tinyint , t1 varchar(16) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint , t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);'''%database)
+
+        for i in range(5):
+            tdSql.execute('''create table %s.stb0_%d using %s.stb0 tags(%d,'varchar%d',%d,%d, %d, %d,%d,'binary%d','nchar%d',%d,%d,%d ) ;'''%(database,i,database,i,i,i,i,i,i,i,i,i,i,i,i))
+            
+        # insert data
+        for i in range(num_random):   
+            for j in range(50):     
+                tdSql.execute('''insert into %s.stb0_0  (ts , c1 , c0) values(now, %d, %d) ;''' % (database,j,j))
+                tdSql.execute('''insert into %s.stb0_1  (ts , c1 , c0) values(now, %d, %d) ;''' % (database,j,j))
+                tdSql.execute('''insert into %s.stb0_2  (ts , c1 , c0) values(now, %d, %d) ;''' % (database,j,j))
+                tdSql.execute('''insert into %s.stb0_3  (ts , c1 , c0) values(now, %d, %d) ;''' % (database,j,j))
+                tdSql.execute('''insert into %s.stb0_4  (ts , c1 , c0) values(now, %d, %d) ;''' % (database,j,j))
+
+        tdSql.query("select count(*) from %s.stb0;" %database)
+        tdSql.checkData(0,0,5*num_random*50)
+        tdSql.query("select count(*) from %s.stb0_0;"%database)
+        tdSql.checkData(0,0,num_random*50)
+        
+    def ts_3085(self,database):  
+        sql = "select count(c0null) from(select * from %s.stb0 limit 20,4) "%(database)
+        tdSql.query(sql) 
+        tdSql.checkData(0,0,0)
+        
+        offset =  random.randint(10,100)
+        for i in range(offset):
+            sql = "select count(c0null) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i)
+            tdSql.query(sql) 
+            tdSql.checkData(0,0,0)
+            sql = "select count(c1null) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i)
+            tdSql.query(sql) 
+            tdSql.checkData(0,0,0)
+            sql = "select count(c0) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i)
+            tdSql.query(sql) 
+            tdSql.checkData(0,0,i)
+            sql = "select count(c1) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i)
+            tdSql.query(sql) 
+            tdSql.checkData(0,0,i)
+            sql = "select count(t0) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i)
+            tdSql.query(sql) 
+            tdSql.checkData(0,0,i)
+            sql = "select count(t1) from(select * from %s.stb0 limit %d,%d) "%(database,offset,i)
+            tdSql.query(sql) 
+            tdSql.checkData(0,0,i)
+
+
+    def ts_2974_max(self,database):  
+        sql = "select max(c0) from %s.stb0 where ts= 1 or rows <= 4):
+            tdLog.info("sql checkrows success")
+        else:
+            tdLog.exit(f"checkEqual error, sql_rows=={rows}")
+            
+            
+        self.sql_query_time_cost(nest_sql)
+        rows = tdSql.queryRows
+        if (rows >= 1 or rows <= 4):
+            tdLog.info("sql checkrows success")
+        else:
+            tdLog.exit(f"checkEqual error, sql_rows=={rows}")         
+        
+        sql_0 = re.sub(r'\d+',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkRows(0)
+        
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql) # \d是匹配数字字符[0-9],+匹配一个或多个
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkRows(0)
+        
+        sql = sql.replace('limit','slimit')
+        tdSql.error(sql)
+        nest_sql = nest_sql.replace('limit','slimit')
+        tdSql.error(nest_sql)
+        
+        sql_0 = re.sub(r'\d+',"0",sql)
+        tdSql.error(sql_0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        tdSql.error(nest_sql_0)
+        
+    def sql_limit_retun_tables_slimit_return_error(self,sql,num,tables,per_table_num,base_fun,replace_fun): 
+        #sql limit n =n;sql limit 0 = 0 ;sql slmit n = error;sql slimit 0  = error  
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+          
+        nest_sql =" select * from (%s) " %sql         
+        self.sql_query_time_cost(sql)
+        tdSql.checkRows(tables)     
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkRows(tables)  
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkRows(0)
+        
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql) # \d是匹配数字字符[0-9],+匹配一个或多个
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkRows(0)
+        
+        sql = sql.replace('limit','slimit')
+        tdSql.error(sql)
+        nest_sql = nest_sql.replace('limit','slimit')
+        tdSql.error(nest_sql)
+        
+        sql_0 = re.sub(r'\d+',"0",sql)
+        tdSql.error(sql_0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        tdSql.error(nest_sql_0)
+
+    def sql_limit_retun_tables_slimit_return_n(self,sql,num,tables,per_table_num,base_fun,replace_fun): 
+        #sql limit n =tables;sql limit 0 = 0 ;sql slmit n = n;sql slimit 0  = 0   
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+         
+        nest_sql =" select * from (%s) " %sql           
+        self.sql_query_time_cost(sql)
+        tdSql.checkRows(tables)  
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkRows(tables)  
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkRows(0)
+        
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql) # \d是匹配数字字符[0-9],+匹配一个或多个
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkRows(0)
+        
+        sql = sql.replace('limit','slimit')
+        self.sql_query_time_cost(sql)
+        tdSql.checkRows(num)
+        nest_sql = nest_sql.replace('limit','slimit')
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkRows(num)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkRows(0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkRows(0)
+
+    def sql_data_limit_retun_tables_slimit_return_n(self,sql,num,tables,per_table_num,base_fun,replace_fun): 
+        #sql limit n =tables;sql limit 0 = 0 ;sql slmit n = n;sql slimit 0  = 0   
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+         
+        nest_sql =" select * from (%s) " %sql           
+        self.sql_query_time_cost(sql)
+        tdSql.checkData(0,0,tables)  
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkData(0,0,tables)  
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkData(0,0,0)
+        
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql) # \d是匹配数字字符[0-9],+匹配一个或多个
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkData(0,0,0)
+        
+        sql = sql.replace('limit','slimit')
+        self.sql_query_time_cost(sql)
+        tdSql.checkData(0,0,num)
+        nest_sql = nest_sql.replace('limit','slimit')
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkData(0,0,num)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkData(0,0,0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkData(0,0,0)
+
+    def sql_limit_retun_n_slimit_return_tables(self,sql,num,tables,per_table_num,base_fun,replace_fun): 
+        #sql limit n =n;sql limit 0 = 0 ;sql slmit n = 100;sql slimit 0  = 0    
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+         
+        nest_sql =" select * from (%s) " %sql            
+        self.sql_query_time_cost(sql)
+        tdSql.checkRows(num)
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkRows(num) 
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkRows(0)
+        
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql) # \d是匹配数字字符[0-9],+匹配一个或多个
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkRows(0)
+        
+        sql = sql.replace('limit','slimit')
+        self.sql_query_time_cost(sql)
+        tdSql.checkRows(tables)
+        nest_sql = nest_sql.replace('limit','slimit')
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkRows(tables)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkRows(0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkRows(0)
+
+    def sql_data_limit_retun_n_slimit_return_tables(self,sql,num,tables,per_table_num,base_fun,replace_fun): 
+        #sql limit n =n;sql limit 0 = 0 ;sql slmit n = 100;sql slimit 0  = 0  
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+           
+        nest_sql =" select * from (%s) " %sql            
+        self.sql_query_time_cost(sql)
+        tdSql.checkData(0,0,num)
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkData(0,0,num) 
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkData(0,0,0)
+        
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql) # \d是匹配数字字符[0-9],+匹配一个或多个
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkData(0,0,0)
+        
+        sql = sql.replace('limit','slimit')
+        self.sql_query_time_cost(sql)
+        tdSql.checkData(0,0,tables)
+        nest_sql = nest_sql.replace('limit','slimit')
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkData(0,0,tables)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkData(0,0,0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkData(0,0,0)
+
+    def sql_limit_retun_tables_times_n_slimit_return_error(self,sql,num,tables,per_table_num,base_fun,replace_fun): 
+        #sql limit n =n*tables;sql limit 0 = 0 ;sql slmit n = tables*n;sql slimit 0  = 0   
+        #interval     
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+         
+        nest_sql =" select * from (%s) " %sql   
+        self.sql_query_time_cost(sql)
+        tdSql.checkRows(num*tables)
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkRows(num*tables) 
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkRows(0)
+        
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql) # \d是匹配数字字符[0-9],+匹配一个或多个
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkRows(0)
+        
+        sql = sql.replace('limit','slimit')
+        tdSql.error(sql)
+        nest_sql = nest_sql.replace('limit','slimit')
+        tdSql.error(nest_sql)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        tdSql.error(sql_0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        tdSql.error(nest_sql_0)
+
+    def sql_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(self,sql,num,tables,per_table_num,base_fun,replace_fun): 
+        #sql limit n =n*tables;sql limit 0 = 0 ;sql slmit n = per_table_num*n;sql slimit 0  = 0   
+        #interval   
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+         
+        nest_sql =" select * from (%s) " %sql     
+        self.sql_query_time_cost(sql)
+        tdSql.checkRows(num*tables)
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkRows(num*tables) 
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkRows(0)
+        
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql) # \d是匹配数字字符[0-9],+匹配一个或多个
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkRows(0)
+        
+        sql = sql.replace('limit','slimit')
+        self.sql_query_time_cost(sql)
+        tdSql.checkRows(num*per_table_num)
+        nest_sql = nest_sql.replace('limit','slimit')
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkRows(num*per_table_num)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkRows(0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkRows(0)
+
+    def sql_data_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(self,sql,num,tables,per_table_num,base_fun,replace_fun): 
+        #sql limit n =n*tables;sql limit 0 = 0 ;sql slmit n = per_table_num*n;sql slimit 0  = 0   
+        #interval   
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+         
+        nest_sql =" select * from (%s) " %sql     
+        self.sql_query_time_cost(sql)
+        tdSql.checkData(0,0,num*tables)
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkData(0,0,num*tables) 
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkData(0,0,0)
+        
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql) # \d是匹配数字字符[0-9],+匹配一个或多个
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkData(0,0,0)
+        
+        sql = sql.replace('limit','slimit')
+        self.sql_query_time_cost(sql)
+        tdSql.checkData(0,0,num*per_table_num)
+        nest_sql = nest_sql.replace('limit','slimit')
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkData(0,0,num*per_table_num)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkData(0,0,0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkData(0,0,0)
+
+    def sql_limit_retun_n_slimit_return_per_table_num_times_tables(self,sql,num,tables,per_table_num,base_fun,replace_fun): 
+        #sql limit n =n*tables;sql limit 0 = 0 ;sql slmit n = per_table_num*n;sql slimit 0  = 0   
+        #interval  
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+         
+        nest_sql =" select * from (%s) " %sql     
+        self.sql_query_time_cost(sql)
+        tdSql.checkRows(num)
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkRows(num) 
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkRows(0)
+        
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql) # \d是匹配数字字符[0-9],+匹配一个或多个
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkRows(0)
+        
+        sql = sql.replace('limit','slimit')
+        self.sql_query_time_cost(sql)
+        tdSql.checkRows(tables*per_table_num)
+        nest_sql = nest_sql.replace('limit','slimit')
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkRows(tables*per_table_num)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkRows(0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkRows(0)
+
+    def sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(self,sql,num,tables,per_table_num,base_fun,replace_fun): 
+        #sql limit n =n*tables;sql limit 0 = 0 ;sql slmit n = per_table_num*n;sql slimit 0  = 0   
+        #interval  
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+         
+        nest_sql =" select * from (%s) " %sql     
+        self.sql_query_time_cost(sql)
+        tdSql.checkData(0,0,num)
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkData(0,0,num) 
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkData(0,0,0)
+        
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql) # \d是匹配数字字符[0-9],+匹配一个或多个
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkData(0,0,0)
+        
+        sql = sql.replace('limit','slimit')
+        self.sql_query_time_cost(sql)
+        tdSql.checkData(0,0,tables*per_table_num)
+        nest_sql = nest_sql.replace('limit','slimit')
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkData(0,0,tables*per_table_num)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkData(0,0,0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkData(0,0,0)
+
+    def sql_limit_not_test_slimitkeep_return_per_table_num_times_n(self,sql,num,tables,per_table_num,base_fun,replace_fun): 
+        #sql sql slmit n = per_table_num*n;sql slimit 0  = 0 
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+         
+        nest_sql =" select * from (%s) " %sql                
+        sql = sql.replace('limit','limit')
+        self.sql_query_time_cost(sql)
+        tdSql.checkRows(num*per_table_num)
+        
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkRows(num*per_table_num)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkRows(0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkRows(0)
+
+    def sql_data_limit_not_test_slimitkeep_return_per_table_num_times_n(self,sql,num,tables,per_table_num,base_fun,replace_fun): 
+        #sql sql slmit n = per_table_num*n;sql slimit 0  = 0 
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+         
+        nest_sql =" select * from (%s) " %sql                
+        sql = sql.replace('limit','limit')
+        self.sql_query_time_cost(sql)
+        tdSql.checkData(0,0,num*per_table_num)
+        
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkData(0,0,num*per_table_num)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkData(0,0,0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkData(0,0,0)
+
+    def sql_limit_not_test_slimitkeep_return_per_table_num_times_tables(self,sql,num,tables,per_table_num,base_fun,replace_fun): 
+        #sql sql slmit n = per_table_num*tables;sql slimit 0  = 0   
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+         
+        nest_sql =" select * from (%s) " %sql         
+        self.sql_query_time_cost(sql)
+        tdSql.checkRows(tables*per_table_num)
+        
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkRows(tables*per_table_num)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkRows(0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkRows(0)
+
+    def sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(self,sql,num,tables,per_table_num,base_fun,replace_fun): 
+        #sql sql slmit n = per_table_num*tables;sql slimit 0  = 0   
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+         
+        nest_sql =" select * from (%s) " %sql         
+        self.sql_query_time_cost(sql)
+        tdSql.checkData(0,0,tables*per_table_num)
+        
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkData(0,0,tables*per_table_num)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkData(0,0,0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkData(0,0,0)
+        
+    def sql_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(self,sql,num,num2,tables,per_table_num,base_fun,replace_fun): 
+        #sql limit n =n*num2;sql limit 0 = 0 ;sql slmit n = num2*n;sql slimit 0  = 0 
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+         
+        nest_sql =" select * from (%s) " %sql            
+        self.sql_query_time_cost(sql)
+        tdSql.checkRows(num*num2)        
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkRows(num*num2)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkRows(0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkRows(0)
+        
+        sql = sql.replace('limit','limit')
+        self.sql_query_time_cost(sql)
+        tdSql.checkRows(num*num2)   
+        nest_sql = nest_sql.replace('limit','limit')  
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkRows(num*num2)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkRows(0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkRows(0)
+        
+    def sql_data_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(self,sql,num,num2,tables,per_table_num,base_fun,replace_fun): 
+        #sql limit n =n*num2;sql limit 0 = 0 ;sql slmit n = num2*n;sql slimit 0  = 0 
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+         
+        nest_sql =" select * from (%s) " %sql            
+        self.sql_query_time_cost(sql)
+        tdSql.checkData(0,0,num*num2)        
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkData(0,0,num*num2)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkData(0,0,0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkData(0,0,0)
+        
+        sql = sql.replace('limit','limit')
+        self.sql_query_time_cost(sql)
+        tdSql.checkData(0,0,num*num2)   
+        nest_sql = nest_sql.replace('limit','limit')  
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkData(0,0,num*num2)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkData(0,0,0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkData(0,0,0)
+        
+    def sql_limit_times_slimitkeep_return_n2(self,sql,num,num2,tables,per_table_num,base_fun,replace_fun): 
+        #sql limit n =n*num2;sql limit 0 = 0 ;sql slmit n = num2*n;sql slimit 0  = 0   
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+         
+        nest_sql =" select * from (%s) " %sql     
+        self.sql_query_time_cost(sql)
+        tdSql.checkRows(num2)      
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkRows(num2)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkRows(0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkRows(0)
+        
+    def sql_data_limit_times_slimitkeep_return_n2(self,sql,num,num2,tables,per_table_num,base_fun,replace_fun): 
+        #sql limit n =n*num2;sql limit 0 = 0 ;sql slmit n = num2*n;sql slimit 0  = 0   
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+         
+        nest_sql =" select * from (%s) " %sql     
+        self.sql_query_time_cost(sql)
+        tdSql.checkData(0,0,num2)      
+        self.sql_query_time_cost(nest_sql)
+        tdSql.checkData(0,0,num2)
+        
+        sql_0 = re.sub(r'\d\d',"0",sql)
+        self.sql_query_time_cost(sql_0)
+        tdSql.checkData(0,0,0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        self.sql_query_time_cost(nest_sql_0)
+        tdSql.checkData(0,0,0)
+
+    def sql_retun_error(self,sql,base_fun,replace_fun): 
+        #sql limit n = error;sql limit 0 = error ;sql slmit n = error ;sql slimit 0 = error 
+        sql = sql.replace('%s'%base_fun,'%s'%replace_fun)
+          
+        nest_sql =" select * from (%s) " %sql            
+        tdSql.error(sql)
+        tdSql.error(nest_sql)
+        
+        sql_0 = re.sub(r'\d+',"0",sql)
+        tdSql.error(sql)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        tdSql.error(nest_sql_0)
+        
+        sql = sql.replace('limit','slimit')
+        tdSql.error(sql)
+        nest_sql = nest_sql.replace('limit','slimit')
+        tdSql.error(nest_sql)
+        
+        sql_0 = re.sub(r'\d+',"0",sql)
+        tdSql.error(sql_0)
+        nest_sql_0 = re.sub(r'\d\d',"0",nest_sql)
+        tdSql.error(nest_sql_0)
+
+    def fun_base(self,dbname,num,num2,tables,per_table_num,dbnamejoin,base_fun,replace_fun):
+        
+        tdLog.info("base query ---------1----------")
+        sql = "select * from %s.meters limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)        
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)  
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.* from %s.meters a,%s.meters b where a.ts = b.ts limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)  
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("base query ---------2----------")
+        sql = "select * from %s.meters where ts is not null limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.* from %s.meters a,%s.meters b where a.ts is not null and  a.ts = b.ts limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("base query ---------3----------")
+        sql = "select * from %s.meters where ts is not null order by ts limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.* from %s.meters a,%s.meters b where a.ts is not null  and  a.ts = b.ts order by b.ts limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        tdLog.info("base query ---------4----------")
+        sql = "select * from %s.meters where ts is not null order by ts desc limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+               
+        sql_join = "select a.* from %s.meters a,%s.meters b where b.ts is not null and  a.ts = b.ts order by a.ts desc limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+    
+    def fun_count(self,dbname,num,num2,tables,per_table_num,dbnamejoin,base_fun,replace_fun):
+        
+        tdLog.info("count query ---------1----------")       
+        sql = "select count(*) from %s.meters limit %d" %(dbname,num)
+        self.sql_limit_retun_1_slimit_return_error(sql,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_1_slimit_return_error(sql,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_1_slimit_return_error(sql_union,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_1_slimit_return_error(sql_union_all,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select count(a.*) from %s.meters a,%s.meters b where a.ts = b.ts limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_1_slimit_return_error(sql_join,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_1_slimit_return_error(sql_join,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_1_slimit_return_error(sql_union,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_1_slimit_return_error(sql_union_all,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        
+        
+        tdLog.info("count query ---------2----------")
+        sql = "select count(*) from %s.meters where ts is not null limit %d" %(dbname,num)
+        self.sql_limit_retun_1_slimit_return_error(sql,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_1_slimit_return_error(sql,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_1_slimit_return_error(sql_union,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_1_slimit_return_error(sql_union_all,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select count(a.*) from %s.meters a,%s.meters b where a.ts is not null and  a.ts = b.ts limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_1_slimit_return_error(sql_join,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_1_slimit_return_error(sql_join,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_1_slimit_return_error(sql_union,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_1_slimit_return_error(sql_union_all,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("count query ---------3----------")
+        sql = "select count(*) from %s.meters where ts is not null order by ts limit %d" %(dbname,num)
+        self.sql_retun_error(sql,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_retun_error(sql,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_retun_error(sql_union,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_retun_error(sql_union_all,base_fun,replace_fun)
+        
+        sql_join = "select count(a.*) from %s.meters a,%s.meters b where a.ts is not null and  a.ts = b.ts order by b.ts limit %d" %(dbname,dbnamejoin,num)
+        self.sql_retun_error(sql_join,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_retun_error(sql_join,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_retun_error(sql_union,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_retun_error(sql_union_all,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("count query ---------4----------")
+        sql = "select count(*) from %s.meters where ts is not null order by ts desc limit %d" %(dbname,num)        
+        self.sql_retun_error(sql,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_retun_error(sql,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_retun_error(sql_union,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_retun_error(sql_union_all,base_fun,replace_fun)
+        
+        sql_join = "select count(a.*) from %s.meters a,%s.meters b where b.ts is not null and  a.ts = b.ts order by a.ts desc limit %d" %(dbname,dbnamejoin,num)        
+        self.sql_retun_error(sql_join,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_retun_error(sql_join,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_retun_error(sql_union,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_retun_error(sql_union_all,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("count query ---------5----------")
+        sql = "select count(*) from %s.meters where ts is not null group by tbname limit %d" %(dbname,num)
+        self.sql_limit_retun_tables_slimit_return_n(sql,num,tables,per_table_num,base_fun,replace_fun)        
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_tables_slimit_return_n(sql,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        sql_join = "select count(*) from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts group by b.tbname limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_tables_slimit_return_n(sql_join,num,tables,per_table_num,base_fun,replace_fun)        
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_join,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        
+        
+        
+        tdLog.info("count query ---------6----------")
+        sql = "select count(*) from %s.meters where ts is not null partition by tbname limit %d" %(dbname,num)
+        self.sql_limit_retun_tables_slimit_return_n(sql,num,tables,per_table_num,base_fun,replace_fun) 
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_tables_slimit_return_n(sql,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        sql_join = "select count(*) from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by b.tbname limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_tables_slimit_return_n(sql_join,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_join,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        
+        
+        tdLog.info("count query ---------7----------")
+        sql = "select count(*) cc from %s.meters where ts is not null group by tbname order by cc limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_tables(sql,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        sql_join  = "select count(*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts group by b.tbname order by cc limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        
+        
+        tdLog.info("count query ---------8----------")
+        sql = "select count(*) cc from %s.meters where ts is not null partition by tbname order by cc limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_tables(sql,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        sql_join = "select count(*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by b.tbname order by cc limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        
+        
+        tdLog.info("count query ---------9----------")
+        sql = "select count(*) cc from %s.meters where ts is not null interval(1a) limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        sql_join  = "select count(*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts interval(1a) limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        
+        
+        tdLog.info("count query ---------10----------")
+        sql = "select count(*) cc from %s.meters where ts is not null interval(1a) order by cc asc limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        sql_join = "select count(*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts interval(1a) order by cc asc limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        
+        
+        tdLog.info("count query ---------11----------")
+        sql = "select count(*) cc from %s.meters where ts is not null interval(1a) order by cc desc limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        sql_join = "select count(*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts interval(1a) order by cc desc limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        
+        
+        tdLog.info("count query ---------12----------")
+        sql = "select tbname,count(*) cc from %s.meters where ts is not null interval(1a) group by tbname limit %d" %(dbname,num)
+        self.sql_retun_error(sql,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_retun_error(sql,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_retun_error(sql_union,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_retun_error(sql_union_all,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,count(*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts interval(1a) group by b.tbname limit %d" %(dbname,dbnamejoin,num)
+        self.sql_retun_error(sql_join,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_retun_error(sql_join,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_retun_error(sql_union,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_retun_error(sql_union_all,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("count query ---------13----------")
+        sql = "select tbname,count(*) cc from %s.meters where ts is not null interval(1a) partition by tbname limit %d" %(dbname,num)
+        self.sql_retun_error(sql,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_retun_error(sql,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_retun_error(sql_union,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_retun_error(sql_union_all,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,count(*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts interval(1a) partition by b.tbname limit %d" %(dbname,dbnamejoin,num)
+        self.sql_retun_error(sql_join,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_retun_error(sql_join,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_retun_error(sql_union,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_retun_error(sql_union_all,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("count query ---------14----------")
+        sql = "select tbname,count(*) cc from %s.meters where ts is not null partition by tbname interval(1a) limit %d" %(dbname,num)
+        self.sql_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,count(*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("count query ---------15----------")
+        sql = "select tbname,count(*) cc from %s.meters where ts is not null partition by tbname interval(1a) order by cc asc limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_per_table_num_times_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,count(*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) order by cc asc limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_per_table_num_times_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("count query ---------16----------")
+        sql = "select tbname,count(*) cc from %s.meters where ts is not null partition by tbname interval(1a) order by cc desc limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_per_table_num_times_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,count(*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) order by cc desc limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_per_table_num_times_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("count query ---------17----------")
+        sql = "select tbname,count(*) cc from %s.meters where ts is not null partition by tbname interval(1a) slimit %d" %(dbname,num)
+        self.sql_limit_not_test_slimitkeep_return_per_table_num_times_n(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_n(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_n(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_n(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,count(*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) slimit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_not_test_slimitkeep_return_per_table_num_times_n(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_n(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_n(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_n(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("count query ---------18----------")
+        sql = "select tbname,count(*) cc from %s.meters where ts is not null partition by tbname interval(1a) order by cc asc slimit %d" %(dbname,num)
+        self.sql_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,count(*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) order by cc asc slimit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        tdLog.info("count query ---------19----------")
+        sql = "select tbname,count(*) cc from %s.meters where ts is not null partition by tbname interval(1a) order by cc desc slimit %d" %(dbname,num)
+        self.sql_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,count(*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) order by cc desc slimit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("count query ---------20----------")
+        sql = "select tbname,count(*) cc from %s.meters where ts is not null partition by tbname interval(1a) slimit %d limit %d" %(dbname,num,num2)
+        self.sql_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(sql,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(sql,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(sql_union,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(sql_union_all,num,num2,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,count(*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) slimit %d limit %d" %(dbname,dbnamejoin,num,num2)
+        self.sql_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(sql_join,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(sql_join,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(sql_union,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(sql_union_all,num,num2,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        tdLog.info("count query ---------21----------")
+        sql = "select tbname,count(*) cc from %s.meters where ts is not null partition by tbname interval(1a) order by cc asc slimit %d limit %d" %(dbname,num,num2)
+        self.sql_limit_times_slimitkeep_return_n2(sql,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_times_slimitkeep_return_n2(sql,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_union,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_union_all,num,num2,tables,per_table_num,base_fun,replace_fun)       
+        
+        sql_join = "select a.tbname,count(*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) order by cc asc slimit %d limit %d" %(dbname,dbnamejoin,num,num2)
+        self.sql_limit_times_slimitkeep_return_n2(sql_join,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_join,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_union,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_union_all,num,num2,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        tdLog.info("count query ---------22----------")
+        sql = "select tbname,count(*) cc from %s.meters where ts is not null partition by tbname interval(1a) order by cc desc slimit %d limit %d" %(dbname,num,num2)
+        self.sql_limit_times_slimitkeep_return_n2(sql,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_times_slimitkeep_return_n2(sql,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_union,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_union_all,num,num2,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,count(*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) order by cc desc slimit %d limit %d" %(dbname,dbnamejoin,num,num2)
+        self.sql_limit_times_slimitkeep_return_n2(sql_join,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_join,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_union,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_union_all,num,num2,tables,per_table_num,base_fun,replace_fun)
+        
+         
+    def fun_last(self,dbname,num,num2,tables,per_table_num,dbnamejoin,base_fun,replace_fun):
+        
+        tdLog.info("last query ---------1----------")       
+        sql = "select last(*) from %s.meters limit %d" %(dbname,num)
+        self.sql_limit_retun_1_slimit_return_error(sql,tables,per_table_num,base_fun,replace_fun)
+        sql = "select last(*) from (%s)" %sql
+        self.sql_limit_retun_1_slimit_return_error(sql,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_last_limit_retun_1_slimit_return_error(sql_union,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_last_limit_retun_1_slimit_return_error(sql_union_all,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select last(a.*) from %s.meters a,%s.meters b where a.ts = b.ts limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_1_slimit_return_error(sql_join,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select last(*) from (%s)" %sql_join
+        self.sql_limit_retun_1_slimit_return_error(sql_join,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_last_limit_retun_1_slimit_return_error(sql_union,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_last_limit_retun_1_slimit_return_error(sql_union_all,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        
+        
+        tdLog.info("last query ---------2----------")
+        sql = "select last(*) from %s.meters where ts is not null limit %d" %(dbname,num)
+        self.sql_limit_retun_1_slimit_return_error(sql,tables,per_table_num,base_fun,replace_fun)
+        sql = "select last(*) from (%s)" %sql
+        self.sql_limit_retun_1_slimit_return_error(sql,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_last_limit_retun_1_slimit_return_error(sql_union,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_last_limit_retun_1_slimit_return_error(sql_union_all,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select last(a.*) from %s.meters a,%s.meters b where a.ts is not null and  a.ts = b.ts limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_1_slimit_return_error(sql_join,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select last(*) from (%s)" %sql_join
+        self.sql_limit_retun_1_slimit_return_error(sql_join,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_last_limit_retun_1_slimit_return_error(sql_union,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_last_limit_retun_1_slimit_return_error(sql_union_all,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("last query ---------3----------")
+        sql = "select last(*) from %s.meters where ts is not null order by ts limit %d" %(dbname,num)
+        self.sql_retun_error(sql,base_fun,replace_fun)
+        sql = "select last(*) from (%s)" %sql
+        self.sql_retun_error(sql,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_retun_error(sql_union,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_retun_error(sql_union_all,base_fun,replace_fun)
+        
+        sql_join = "select last(a.*) from %s.meters a,%s.meters b where a.ts is not null and  a.ts = b.ts order by b.ts limit %d" %(dbname,dbnamejoin,num)
+        self.sql_retun_error(sql_join,base_fun,replace_fun)
+        sql_join = "select last(*) from (%s)" %sql_join
+        self.sql_retun_error(sql_join,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_retun_error(sql_union,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_retun_error(sql_union_all,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("last query ---------4----------")
+        sql = "select last(*) from %s.meters where ts is not null order by ts desc limit %d" %(dbname,num)        
+        self.sql_retun_error(sql,base_fun,replace_fun)
+        sql = "select last(*) from (%s)" %sql
+        self.sql_retun_error(sql,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_retun_error(sql_union,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_retun_error(sql_union_all,base_fun,replace_fun)
+        
+        sql_join = "select last(a.*) from %s.meters a,%s.meters b where b.ts is not null and  a.ts = b.ts order by a.ts desc limit %d" %(dbname,dbnamejoin,num)        
+        self.sql_retun_error(sql_join,base_fun,replace_fun)
+        sql_join = "select last(*) from (%s)" %sql_join
+        self.sql_retun_error(sql_join,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_retun_error(sql_union,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_retun_error(sql_union_all,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("last query ---------5----------")
+        sql = "select last(*) from %s.meters where ts is not null group by tbname limit %d" %(dbname,num)
+        self.sql_limit_retun_tables_slimit_return_n(sql,num,tables,per_table_num,base_fun,replace_fun)        
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_tables_slimit_return_n(sql,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        sql_join = "select last(a.*) from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts group by b.tbname limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_tables_slimit_return_n(sql_join,num,tables,per_table_num,base_fun,replace_fun)        
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_join,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        
+        
+        
+        tdLog.info("last query ---------6----------")
+        sql = "select last(*) from %s.meters where ts is not null partition by tbname limit %d" %(dbname,num)
+        self.sql_limit_retun_tables_slimit_return_n(sql,num,tables,per_table_num,base_fun,replace_fun) 
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_tables_slimit_return_n(sql,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        sql_join = "select last(a.*) from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by b.tbname limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_tables_slimit_return_n(sql_join,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_join,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_tables_slimit_return_n(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        
+        
+        tdLog.info("last query ---------7----------")
+        sql = "select last(ts) cc from %s.meters where ts is not null group by tbname order by cc limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_tables(sql,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        sql_join  = "select last(a.ts) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts group by b.tbname order by cc limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        
+        
+        tdLog.info("last query ---------8----------")
+        sql = "select last(ts) cc from %s.meters where ts is not null partition by tbname order by cc limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_tables(sql,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        sql_join = "select last(a.ts) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by b.tbname order by cc limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        
+        
+        tdLog.info("last query ---------9----------")
+        sql = "select last(*) from %s.meters where ts is not null interval(1a) limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        sql_join  = "select last(a.ts) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts interval(1a) limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        
+        
+        tdLog.info("last query ---------10----------")
+        sql = "select last(ts) cc from %s.meters where ts is not null interval(1a) order by cc asc limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        sql_join = "select last(a.ts) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts interval(1a) order by cc asc limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        
+        
+        tdLog.info("last query ---------11----------")
+        sql = "select last(ts) cc from %s.meters where ts is not null interval(1a) order by cc desc limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_error(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        sql_join = "select last(a.ts) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts interval(1a) order by cc desc limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_error(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union,num,tables,per_table_num,base_fun,replace_fun) 
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_error(sql_union_all,num,tables,per_table_num,base_fun,replace_fun) 
+        
+        
+        
+        tdLog.info("last query ---------12----------")
+        sql = "select tbname,last(ts) cc from %s.meters where ts is not null interval(1a) group by tbname limit %d" %(dbname,num)
+        self.sql_retun_error(sql,base_fun,replace_fun)
+        sql = "select last(*) from (%s)" %sql
+        self.sql_retun_error(sql,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_retun_error(sql_union,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_retun_error(sql_union_all,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,last(a.ts) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts interval(1a) group by b.tbname limit %d" %(dbname,dbnamejoin,num)
+        self.sql_retun_error(sql_join,base_fun,replace_fun)
+        sql_join = "select last(*) from (%s)" %sql_join
+        self.sql_retun_error(sql_join,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_retun_error(sql_union,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_retun_error(sql_union_all,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("last query ---------13----------")
+        sql = "select tbname,last(ts) cc from %s.meters where ts is not null interval(1a) partition by tbname limit %d" %(dbname,num)
+        self.sql_retun_error(sql,base_fun,replace_fun)
+        sql = "select last(*) from (%s)" %sql
+        self.sql_retun_error(sql,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_retun_error(sql_union,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_retun_error(sql_union_all,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,last(a.ts) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts interval(1a) partition by b.tbname limit %d" %(dbname,dbnamejoin,num)
+        self.sql_retun_error(sql_join,base_fun,replace_fun)
+        sql_join = "select last(*) from (%s)" %sql_join
+        self.sql_retun_error(sql_join,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_retun_error(sql_union,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_retun_error(sql_union_all,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("last query ---------14----------") 
+        sql = "select tbname,last(*) cc from %s.meters where ts is not null partition by tbname interval(1a) limit %d" %(dbname,num)
+        self.sql_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,last(a.ts) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_tables_times_n_slimit_return_per_table_num_times_n(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("last query ---------15----------")
+        sql = "select tbname,last(ts) cc from %s.meters where ts is not null partition by tbname interval(1a) order by cc asc limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_per_table_num_times_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,last(a.ts) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) order by cc asc limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_per_table_num_times_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("last query ---------16----------")
+        sql = "select tbname,last(ts) cc from %s.meters where ts is not null partition by tbname interval(1a) order by cc desc limit %d" %(dbname,num)
+        self.sql_limit_retun_n_slimit_return_per_table_num_times_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,last(a.ts) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) order by cc desc limit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_retun_n_slimit_return_per_table_num_times_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_slimit_return_per_table_num_times_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("last query ---------17----------")
+        sql = "select tbname,last(*) cc from %s.meters where ts is not null partition by tbname interval(1a) slimit %d" %(dbname,num)
+        self.sql_limit_not_test_slimitkeep_return_per_table_num_times_n(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_n(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_n(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_n(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,last(a.ts) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) slimit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_not_test_slimitkeep_return_per_table_num_times_n(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_n(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_n(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_n(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("last query ---------18----------")
+        sql = "select tbname,last(ts) cc from %s.meters where ts is not null partition by tbname interval(1a) order by cc asc slimit %d" %(dbname,num)
+        self.sql_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,last(a.ts) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) order by cc asc slimit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        tdLog.info("last query ---------19----------")
+        sql = "select tbname,last(ts) cc from %s.meters where ts is not null partition by tbname interval(1a) order by cc desc slimit %d" %(dbname,num)
+        self.sql_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,last(a.ts) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) order by cc desc slimit %d" %(dbname,dbnamejoin,num)
+        self.sql_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_join,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_union,num,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_not_test_slimitkeep_return_per_table_num_times_tables(sql_union_all,num,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        
+        tdLog.info("last query ---------20----------") 
+        sql = "select tbname,last(*) cc from %s.meters where ts is not null partition by tbname interval(1a) slimit %d limit %d" %(dbname,num,num2)
+        self.sql_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(sql,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(sql,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(sql_union,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(sql_union_all,num,num2,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,last(a.*) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) slimit %d limit %d" %(dbname,dbnamejoin,num,num2)
+        self.sql_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(sql_join,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(sql_join,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(sql_union,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_retun_n_times_n2_slimitkeep_return_n_times_n2(sql_union_all,num,num2,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        tdLog.info("last query ---------21----------")
+        sql = "select tbname,last(ts) cc from %s.meters where ts is not null partition by tbname interval(1a) order by cc asc slimit %d limit %d" %(dbname,num,num2)
+        self.sql_limit_times_slimitkeep_return_n2(sql,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_times_slimitkeep_return_n2(sql,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_union,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_union_all,num,num2,tables,per_table_num,base_fun,replace_fun)       
+        
+        sql_join = "select a.tbname,last(a.ts) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) order by cc asc slimit %d limit %d" %(dbname,dbnamejoin,num,num2)
+        self.sql_limit_times_slimitkeep_return_n2(sql_join,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_join,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_union,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_union_all,num,num2,tables,per_table_num,base_fun,replace_fun)
+        
+        
+        tdLog.info("last query ---------22----------")
+        sql = "select tbname,last(ts) cc from %s.meters where ts is not null partition by tbname interval(1a) order by cc desc slimit %d limit %d" %(dbname,num,num2)
+        self.sql_limit_times_slimitkeep_return_n2(sql,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql = "select count(*) from (%s)" %sql
+        self.sql_data_limit_times_slimitkeep_return_n2(sql,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql,sql)
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_union,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql,sql_union)
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_union_all,num,num2,tables,per_table_num,base_fun,replace_fun)
+        
+        sql_join = "select a.tbname,last(a.ts) cc from %s.meters a,%s.meters b where a.ts is not null and a.ts = b.ts partition by a.tbname interval(1a) order by cc desc slimit %d limit %d" %(dbname,dbnamejoin,num,num2)
+        self.sql_limit_times_slimitkeep_return_n2(sql_join,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_join = "select count(*) from (%s)" %sql_join
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_join,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union = "(%s) union (%s)" %(sql_join,sql_join)
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_union,num,num2,tables,per_table_num,base_fun,replace_fun)
+        sql_union_all = "(%s) union all (%s)" %(sql_join,sql_union)
+        self.sql_data_limit_times_slimitkeep_return_n2(sql_union_all,num,num2,tables,per_table_num,base_fun,replace_fun)
+        
+        
+            
+   
+
+    def sql_base_check(self,sql1,sql2):
+        tdSql.query(sql1)
+        sql1_result = tdSql.getData(0,0)
+        tdLog.info("sql:%s , result: %s" %(sql1,sql1_result))
+
+        tdSql.query(sql2)
+        sql2_result = tdSql.getData(0,0)
+        tdLog.info("sql:%s , result: %s" %(sql2,sql2_result))
+
+        if sql1_result==sql2_result:
+            tdLog.info(f"checkEqual success, sql1_result={sql1_result},sql2_result={sql2_result}")
+        else :
+            tdLog.exit(f"checkEqual error, sql1_result=={sql1_result},sql2_result={sql2_result}")
+
+    def run_limit_slimit_sql(self,dbname,tables,per_table_num,dbnamejoin):
+        
+        num,num2 = random.randint(10,100),random.randint(10,100)
+        self.sql_base(dbname,num,num2,tables,per_table_num,dbnamejoin)
+
+        tdSql.execute(" flush database %s;" %dbname)
+
+        self.sql_base(dbname,num,num2,tables,per_table_num,dbnamejoin)
+
+    def check_sub(self,dbname):
+
+        sql = "select count(*) from (select distinct(tbname) from %s.meters)" %dbname
+        self.sql_query_time_cost(sql)
+        num = tdSql.getData(0,0)
+
+        for i in range(0,num):
+            sql1 = "select count(*) from %s.d%d" %(dbname,i)
+            self.sql_query_time_cost(sql1)
+            sql1_result = tdSql.getData(0,0)
+            tdLog.info("sql:%s , result: %s" %(sql1,sql1_result))
+    
+                
+    def sql_base(self,dbname,num,num2,tables,per_table_num,dbnamejoin):
+        
+        sql = "select count(*) from %s.meters" %dbname
+        self.sql_query_time_cost(sql)
+        tdSql.checkData(0,0,tables*per_table_num)
+        sql = "select count(*) from %s.meters" %dbnamejoin
+        self.sql_query_time_cost(sql)
+        
+        self.fun_base(dbname,num,num2,tables,per_table_num,dbnamejoin,'*','*')
+        # self.fun_count(dbname,num,num2,tables,per_table_num,dbnamejoin,'count','count')
+        # self.fun_last(dbname,num,num2,tables,per_table_num,dbnamejoin,'last','last')
+        # #self.fun_last(dbname,num,num2,tables,per_table_num,dbnamejoin,'last','last_row')
+        # self.fun_last(dbname,num,num2,tables,per_table_num,dbnamejoin,'last','first')
+            
+    def test(self,dbname,tables,per_table_num,vgroups,replica,dbnamejoin):
+        self.run_benchmark(dbname,tables,per_table_num,vgroups,replica)
+        self.run_benchmark(dbnamejoin,tables,per_table_num,vgroups,replica)
+        self.run_limit_slimit_sql(dbname,tables,per_table_num,dbnamejoin)
+
+    def run(self):
+        startTime = time.time()
+
+        dbname = 'test'
+        dbnamejoin = 'testjoin'
+        vgroups = random.randint(1,8)
+        tables = random.randint(100,300)
+        per_table_num = random.randint(100,500)
+        replica = 1
+        #self.test('test',tables,per_table_num,vgroup,1) 
+        #self.test('test',10000,150,vgroup,1)     
+        
+        self.test('test',100,150,vgroups,1,'testjoin')    #方便调试,调试时不执行下面3个 
+        
+        # self.run_benchmark(dbname,tables,per_table_num,vgroups,replica)
+        # self.run_benchmark(dbnamejoin,tables*vgroups,per_table_num*vgroups,vgroups*2,replica) #方便测试不同数据量
+        # self.run_limit_slimit_sql(dbname,tables,per_table_num,dbnamejoin)  
+
+        endTime = time.time()
+        print("total time %ds" % (endTime - startTime))
+
+
+    def stop(self):
+        tdSql.close()
+        tdLog.success("%s successfully executed" % __file__)
+
+
+tdCases.addWindows(__file__, TDTestCase())
+tdCases.addLinux(__file__, TDTestCase())
diff --git a/tests/system-test/2-query/sml.py b/tests/system-test/2-query/sml.py
index f96ed8a3ff..2f97118fbf 100644
--- a/tests/system-test/2-query/sml.py
+++ b/tests/system-test/2-query/sml.py
@@ -34,6 +34,9 @@ class TDTestCase:
         if ret != 0:
             tdLog.info("sml_test ret != 0")
 
+        tdSql.query(f"select * from ts3303.stb2")
+        tdSql.query(f"select * from ts3303.meters")
+
         # tdSql.execute('use sml_db')
         tdSql.query(f"select * from {dbname}.t_b7d815c9222ca64cdf2614c61de8f211")
         tdSql.checkRows(1)
diff --git a/tests/system-test/6-cluster/clusterCommonCheck.py b/tests/system-test/6-cluster/clusterCommonCheck.py
index 7abc45bf73..7aa2ba06b9 100644
--- a/tests/system-test/6-cluster/clusterCommonCheck.py
+++ b/tests/system-test/6-cluster/clusterCommonCheck.py
@@ -251,7 +251,7 @@ class ClusterComCheck:
                 count+=1
             elif self.db_replica == 3 :
                 vgroup_status_first=[tdSql.queryResult[0][4],tdSql.queryResult[0][6],tdSql.queryResult[0][8]]
-                
+
                 vgroup_status_last=[tdSql.queryResult[last_number][4],tdSql.queryResult[last_number][6],tdSql.queryResult[last_number][8]]
                 if  vgroup_status_first.count('leader') == 1 and vgroup_status_first.count('follower') == 2:
                     if vgroup_status_last.count('leader') == 1 and vgroup_status_last.count('follower') == 2:
diff --git a/tests/system-test/6-cluster/clusterCommonCreate.py b/tests/system-test/6-cluster/clusterCommonCreate.py
index 6e699e2396..a06c1233d8 100644
--- a/tests/system-test/6-cluster/clusterCommonCreate.py
+++ b/tests/system-test/6-cluster/clusterCommonCreate.py
@@ -94,26 +94,26 @@ class ClusterComCreate:
         tdLog.info(shellCmd)
         os.system(shellCmd)
 
-    def getStartConsumeNotifyFromTmqsim(self,cdbName='cdb'):
-        while 1:
-            tdSql.query("select * from %s.notifyinfo"%cdbName)
-            #tdLog.info("row: %d, %l64d, %l64d"%(tdSql.getData(0, 1),tdSql.getData(0, 2),tdSql.getData(0, 3))
-            if (tdSql.getRows() == 1) and (tdSql.getData(0, 1) == 0):
-                break
-            else:
-                time.sleep(0.1)
-        return
-
-    def getStartCommitNotifyFromTmqsim(self,cdbName='cdb'):
-        while 1:
-            tdSql.query("select * from %s.notifyinfo"%cdbName)
-            #tdLog.info("row: %d, %l64d, %l64d"%(tdSql.getData(0, 1),tdSql.getData(0, 2),tdSql.getData(0, 3))
-            if tdSql.getRows() == 2 :
-                print(tdSql.getData(0, 1), tdSql.getData(1, 1))
-                if tdSql.getData(1, 1) == 1:
-                    break
-            time.sleep(0.1)
-        return
+    # def getStartConsumeNotifyFromTmqsim(self,cdbName='cdb'):
+    #     while 1:
+    #         tdSql.query("select * from %s.notifyinfo"%cdbName)
+    #         #tdLog.info("row: %d, %l64d, %l64d"%(tdSql.getData(0, 1),tdSql.getData(0, 2),tdSql.getData(0, 3))
+    #         if (tdSql.getRows() == 1) and (tdSql.getData(0, 1) == 0):
+    #             break
+    #         else:
+    #             time.sleep(0.1)
+    #     return
+    #
+    # def getStartCommitNotifyFromTmqsim(self,cdbName='cdb'):
+    #     while 1:
+    #         tdSql.query("select * from %s.notifyinfo"%cdbName)
+    #         #tdLog.info("row: %d, %l64d, %l64d"%(tdSql.getData(0, 1),tdSql.getData(0, 2),tdSql.getData(0, 3))
+    #         if tdSql.getRows() == 2 :
+    #             print(tdSql.getData(0, 1), tdSql.getData(1, 1))
+    #             if tdSql.getData(1, 1) == 1:
+    #                 break
+    #         time.sleep(0.1)
+    #     return
 
     def create_database(self,tsql, dbName,dropFlag=1,vgroups=4,replica=1):
         if dropFlag == 1:
diff --git a/tests/system-test/6-cluster/manually-test/6dnode3mnodeInsertDatarRebootAlterRep1-3.py b/tests/system-test/6-cluster/manually-test/6dnode3mnodeInsertDatarRebootAlterRep1-3.py
new file mode 100644
index 0000000000..aa3ed8e3fd
--- /dev/null
+++ b/tests/system-test/6-cluster/manually-test/6dnode3mnodeInsertDatarRebootAlterRep1-3.py
@@ -0,0 +1,222 @@
+import taos
+import sys
+import time
+import os
+
+from util.log import *
+from util.sql import *
+from util.cases import *
+from util.dnodes import TDDnodes
+from util.dnodes import TDDnode
+from util.cluster import *
+sys.path.append("./6-cluster")
+from clusterCommonCreate import *
+from clusterCommonCheck import clusterComCheck
+
+import time
+import socket
+import subprocess
+from multiprocessing import Process
+import threading
+import time
+import inspect
+import ctypes
+
+class TDTestCase:
+
+    def init(self, conn, logSql, replicaVar=1):
+        tdLog.debug(f"start to excute {__file__}")
+        self.TDDnodes = None
+        tdSql.init(conn.cursor())
+        self.host = socket.gethostname()
+
+
+    def getBuildPath(self):
+        selfPath = os.path.dirname(os.path.realpath(__file__))
+
+        if ("community" in selfPath):
+            projPath = selfPath[:selfPath.find("community")]
+        else:
+            projPath = selfPath[:selfPath.find("tests")]
+
+        for root, dirs, files in os.walk(projPath):
+            if ("taosd" in files):
+                rootRealPath = os.path.dirname(os.path.realpath(root))
+                if ("packaging" not in rootRealPath):
+                    buildPath = root[:len(root) - len("/build/bin")]
+                    break
+        return buildPath
+
+    def _async_raise(self, tid, exctype):
+        """raises the exception, performs cleanup if needed"""
+        if not inspect.isclass(exctype):
+            exctype = type(exctype)
+        res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
+        if res == 0:
+            raise ValueError("invalid thread id")
+        elif res != 1:
+            # """if it returns a number greater than one, you're in trouble,
+            # and you should call it again with exc=NULL to revert the effect"""
+            ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None)
+            raise SystemError("PyThreadState_SetAsyncExc failed")
+
+    def stopThread(self,thread):
+        self._async_raise(thread.ident, SystemExit)
+
+
+    def insertData(self,countstart,countstop):
+        # fisrt add data : db\stable\childtable\general table
+
+        for couti in range(countstart,countstop):
+            tdLog.debug("drop database if exists db%d" %couti)
+            tdSql.execute("drop database if exists db%d" %couti)
+            print("create database if not exists db%d replica 1 duration 300" %couti)
+            tdSql.execute("create database if not exists db%d replica 1 duration 300" %couti)
+            tdSql.execute("use db%d" %couti)
+            tdSql.execute(
+            '''create table stb1
+            (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp)
+            tags (t1 int)
+            '''
+            )
+            tdSql.execute(
+                '''
+                create table t1
+                (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp)
+                '''
+            )
+            for i in range(4):
+                tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )')
+
+
+    def fiveDnodeThreeMnode(self,dnodeNumbers,mnodeNums,restartNumbers,stopRole):
+        tdLog.printNoPrefix("======== test case 1: ")
+        paraDict = {'dbName':     'db0_0',
+                    'dropFlag':   1,
+                    'event':      '',
+                    'vgroups':    4,
+                    'replica':    1,
+                    'stbName':    'stb',
+                    'stbNumbers': 2,
+                    'colPrefix':  'c',
+                    'tagPrefix':  't',
+                    'colSchema':   [{'type': 'INT', 'count':1}, {'type': 'binary', 'len':20, 'count':1}],
+                    'tagSchema':   [{'type': 'INT', 'count':1}, {'type': 'binary', 'len':20, 'count':1}],
+                    'ctbPrefix':  'ctb',
+                    'ctbNum':     1000,
+                    'startTs':    1640966400000,  # 2022-01-01 00:00:00.000
+                    "rowsPerTbl": 100,
+                    "batchNum": 5000
+                    }
+
+        dnodeNumbers = int(dnodeNumbers)
+        mnodeNums = int(mnodeNums)
+        vnodeNumbers = int(dnodeNumbers-mnodeNums)
+        allctbNumbers = (paraDict['stbNumbers']*paraDict["ctbNum"])
+        rowsPerStb = paraDict["ctbNum"]*paraDict["rowsPerTbl"]
+        rowsall = rowsPerStb*paraDict['stbNumbers']
+        dbNumbers = 1
+        replica3 = 3
+        tdLog.info("first check dnode and mnode")
+        tdSql.query("select * from information_schema.ins_dnodes;")
+        tdSql.checkData(0,1,'%s:6030'%self.host)
+        tdSql.checkData(4,1,'%s:6430'%self.host)
+        clusterComCheck.checkDnodes(dnodeNumbers)
+        
+        #check mnode status
+        tdLog.info("check mnode status")
+        clusterComCheck.checkMnodeStatus(mnodeNums)
+
+        # add some error operations and
+        tdLog.info("Confirm the status of the dnode again")
+        tdSql.error("create mnode on dnode 2")
+        tdSql.query("select * from information_schema.ins_dnodes;")
+        print(tdSql.queryResult)
+        clusterComCheck.checkDnodes(dnodeNumbers)
+
+        # create database and stable
+        clusterComCreate.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], paraDict["vgroups"],paraDict['replica'])
+        tdLog.info("Take turns stopping Mnodes ")
+
+        tdDnodes=cluster.dnodes
+        stopcount =0
+        threads=[]
+
+        # create stable:stb_0
+        stableName= paraDict['stbName']
+        newTdSql=tdCom.newTdSql()
+        clusterComCreate.create_stables(newTdSql, paraDict["dbName"],stableName,paraDict['stbNumbers'])
+        #create child table:ctb_0
+        for i in range(paraDict['stbNumbers']):
+            stableName= '%s_%d'%(paraDict['stbName'],i)
+            newTdSql=tdCom.newTdSql()
+            clusterComCreate.create_ctable(newTdSql, paraDict["dbName"],stableName,stableName, paraDict['ctbNum'])
+        #insert date
+        for i in range(paraDict['stbNumbers']):
+            stableName= '%s_%d'%(paraDict['stbName'],i)
+            newTdSql=tdCom.newTdSql()
+            threads.append(threading.Thread(target=clusterComCreate.insert_data, args=(newTdSql, paraDict["dbName"],stableName,paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"],paraDict["startTs"])))
+        for tr in threads:
+            tr.start()
+        TdSqlEx=tdCom.newTdSql()
+        tdLog.info("alter database db0_0 replica 3")
+        TdSqlEx.execute('alter database db0_0 replica 3')
+        while stopcount < restartNumbers:
+            tdLog.info(" restart loop: %d"%stopcount )
+            if stopRole == "mnode":
+                for i in range(mnodeNums):
+                    tdDnodes[i].stoptaosd()
+                    # sleep(10)
+                    tdDnodes[i].starttaosd()
+                    # sleep(10)
+            elif stopRole == "vnode":
+                for i in range(vnodeNumbers):
+                    tdDnodes[i+mnodeNums].stoptaosd()
+                    # sleep(10)
+                    tdDnodes[i+mnodeNums].starttaosd()
+                    # sleep(10)
+            elif stopRole == "dnode":
+                for i in range(dnodeNumbers):
+                    tdDnodes[i].stoptaosd()
+                    # tdLog.info('select  cast(c2 as nchar(10)) from db0_0.stb_1;')
+                    # TdSqlEx.execute('select  cast(c2 as nchar(10)) from db0_0.stb_1;')
+                    # tdLog.info('select  avg(c1)  from db0_0.stb_0 interval(10s);')
+                    # TdSqlEx.execute('select  avg(c1)  from db0_0.stb_0 interval(10s);')
+                    # sleep(10)
+                    tdDnodes[i].starttaosd()
+                    # sleep(10)
+            # dnodeNumbers don't include database of schema
+            if clusterComCheck.checkDnodes(dnodeNumbers):
+                tdLog.info("123")
+            else:
+                print("456")
+
+                self.stopThread(threads)
+                tdLog.exit("one or more of dnodes failed to start ")
+                # self.check3mnode()
+            stopcount+=1
+
+        for tr in threads:
+            tr.join()
+        clusterComCheck.checkDnodes(dnodeNumbers)
+        clusterComCheck.checkDbRows(dbNumbers)
+        # clusterComCheck.checkDb(dbNumbers,1,paraDict["dbName"])
+
+        # tdSql.execute("use %s" %(paraDict["dbName"]))
+        tdSql.query("show %s.stables"%(paraDict["dbName"]))
+        tdSql.checkRows(paraDict["stbNumbers"])
+        # for i in range(paraDict['stbNumbers']):
+        #     stableName= '%s.%s_%d'%(paraDict["dbName"],paraDict['stbName'],i)
+        #     tdSql.query("select count(*) from %s"%stableName)
+        #     tdSql.checkData(0,0,rowsPerStb)
+        clusterComCheck.check_vgroups_status(vgroup_numbers=paraDict["vgroups"],db_replica=replica3,db_name=paraDict["dbName"],count_number=240)        
+    def run(self):
+        # print(self.master_dnode.cfgDict)
+        self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=4,stopRole='dnode')
+
+    def stop(self):
+        tdSql.close()
+        tdLog.success(f"{__file__} successfully executed")
+
+tdCases.addLinux(__file__, TDTestCase())
+tdCases.addWindows(__file__, TDTestCase())
diff --git a/tests/system-test/7-tmq/stbTagFilter-1ctb.py b/tests/system-test/7-tmq/stbTagFilter-1ctb.py
index 7ee5fce5a8..1867dc54cb 100644
--- a/tests/system-test/7-tmq/stbTagFilter-1ctb.py
+++ b/tests/system-test/7-tmq/stbTagFilter-1ctb.py
@@ -111,7 +111,7 @@ class TDTestCase:
         topicFromStb1 = 'topic_UpperCase_stb1'
         # queryString = "select ts, c1, c2 from %s.%s where t4 == 'shanghai' or t4 == 'changsha'"%(paraDict['dbName'], paraDict['stbName'])
         queryString = "select ts, c1, c2, t4 from %s.%s where t4 == 'shanghai' or t4 == 'changsha'"%(paraDict['dbName'], paraDict['stbName'])
-        sqlString = "create topic %s as %s" %(topicFromStb1, queryString)
+        sqlString = "create topic `%s` as %s" %(topicFromStb1, queryString)
         tdLog.info("create topic sql: %s"%sqlString)
         tdSql.execute(sqlString)
 
@@ -148,7 +148,7 @@ class TDTestCase:
 
         tmqCom.checkFileContent(consumerId, queryString)
 
-        tdSql.query("drop topic %s"%topicFromStb1)
+        tdSql.query("drop topic `%s`"%topicFromStb1)
         tdLog.printNoPrefix("======== test case 1 end ...... ")
 
     def tmqCase2(self):
@@ -196,7 +196,7 @@ class TDTestCase:
         topicFromStb1 = 'topic_UpperCase_stb1'
         queryString = "select ts, c1, c2 from %s.%s where t4 == 'shanghai' or t4 == 'changsha'"%(paraDict['dbName'], paraDict['stbName'])
         # queryString = "select ts, c1, c2, t4 from %s.%s where t4 == 'shanghai' or t4 == 'changsha'"%(paraDict['dbName'], paraDict['stbName'])
-        sqlString = "create topic %s as %s" %(topicFromStb1, queryString)
+        sqlString = "create topic `%s` as %s" %(topicFromStb1, queryString)
         tdLog.info("create topic sql: %s"%sqlString)
         tdSql.execute(sqlString)
 
@@ -242,7 +242,7 @@ class TDTestCase:
 
         # tmqCom.checkFileContent(consumerId, queryString)
 
-        tdSql.query("drop topic %s"%topicFromStb1)
+        tdSql.query("drop topic `%s`"%topicFromStb1)
 
         tdLog.printNoPrefix("======== test case 2 end ...... ")
 
diff --git a/tests/system-test/7-tmq/stbTagFilter-multiCtb.py b/tests/system-test/7-tmq/stbTagFilter-multiCtb.py
index 71b7fdef5d..67cc60d196 100644
--- a/tests/system-test/7-tmq/stbTagFilter-multiCtb.py
+++ b/tests/system-test/7-tmq/stbTagFilter-multiCtb.py
@@ -111,7 +111,7 @@ class TDTestCase:
         topicFromStb1 = 'topic_UpperCase_stb1'
         queryString = "select ts, c1, c2 from %s.%s where t4 == 'beijing' or t4 == 'changsha'"%(paraDict['dbName'], paraDict['stbName'])
         # queryString = "select ts, c1, c2, t4 from %s.%s where t4 == 'beijing' or t4 == 'changsha'"%(paraDict['dbName'], paraDict['stbName'])
-        sqlString = "create topic %s as %s" %(topicFromStb1, queryString)
+        sqlString = "create topic `%s` as %s" %(topicFromStb1, queryString)
         tdLog.info("create topic sql: %s"%sqlString)
         tdSql.execute(sqlString)
 
@@ -148,7 +148,7 @@ class TDTestCase:
 
         # tmqCom.checkFileContent(consumerId, queryString)
 
-        tdSql.query("drop topic %s"%topicFromStb1)
+        tdSql.query("drop topic `%s`"%topicFromStb1)
         tdLog.printNoPrefix("======== test case 1 end ...... ")
 
     def tmqCase2(self):
@@ -196,7 +196,7 @@ class TDTestCase:
         topicFromStb1 = 'topic_UpperCase_stb1'
         # queryString = "select ts, c1, c2 from %s.%s where t4 == 'beijing' or t4 == 'changsha'"%(paraDict['dbName'], paraDict['stbName'])
         queryString = "select ts, c1, c2, t4 from %s.%s where t4 == 'beijing' or t4 == 'changsha'"%(paraDict['dbName'], paraDict['stbName'])
-        sqlString = "create topic %s as %s" %(topicFromStb1, queryString)
+        sqlString = "create topic `%s` as %s" %(topicFromStb1, queryString)
         tdLog.info("create topic sql: %s"%sqlString)
         tdSql.execute(sqlString)
 
@@ -244,7 +244,7 @@ class TDTestCase:
 
         # tmqCom.checkFileContent(consumerId, queryString)
 
-        tdSql.query("drop topic %s"%topicFromStb1)
+        tdSql.query("drop topic `%s`"%topicFromStb1)
 
         tdLog.printNoPrefix("======== test case 2 end ...... ")
 
diff --git a/tests/system-test/7-tmq/subscribeDb3.py b/tests/system-test/7-tmq/subscribeDb3.py
index f82f89f1b9..b66334a6a6 100644
--- a/tests/system-test/7-tmq/subscribeDb3.py
+++ b/tests/system-test/7-tmq/subscribeDb3.py
@@ -10,6 +10,8 @@ from util.log import *
 from util.sql import *
 from util.cases import *
 from util.dnodes import *
+sys.path.append("./7-tmq")
+from tmqCommon import *
 
 class TDTestCase:
     hostname = socket.gethostname()
@@ -67,26 +69,26 @@ class TDTestCase:
         tdLog.info("consume info sql: %s"%sql)
         tdSql.query(sql)
 
-    def getStartConsumeNotifyFromTmqsim(self,cdbName='cdb'):
-        while 1:
-            tdSql.query("select * from %s.notifyinfo"%cdbName)
-            #tdLog.info("row: %d, %l64d, %l64d"%(tdSql.getData(0, 1),tdSql.getData(0, 2),tdSql.getData(0, 3))
-            if (tdSql.getRows() == 1) and (tdSql.getData(0, 1) == 0):
-                break
-            else:
-                time.sleep(0.1)
-        return
-
-    def getStartCommitNotifyFromTmqsim(self,cdbName='cdb'):
-        while 1:
-            tdSql.query("select * from %s.notifyinfo"%cdbName)
-            #tdLog.info("row: %d, %l64d, %l64d"%(tdSql.getData(0, 1),tdSql.getData(0, 2),tdSql.getData(0, 3))
-            if tdSql.getRows() == 2 :
-                print(tdSql.getData(0, 1), tdSql.getData(1, 1))
-                if tdSql.getData(1, 1) == 1:
-                    break
-            time.sleep(0.1)
-        return
+    # def getStartConsumeNotifyFromTmqsim(self,cdbName='cdb'):
+    #     while 1:
+    #         tdSql.query("select * from %s.notifyinfo"%cdbName)
+    #         #tdLog.info("row: %d, %l64d, %l64d"%(tdSql.getData(0, 1),tdSql.getData(0, 2),tdSql.getData(0, 3))
+    #         if (tdSql.getRows() == 1) and (tdSql.getData(0, 1) == 0):
+    #             break
+    #         else:
+    #             time.sleep(0.1)
+    #     return
+    #
+    # def getStartCommitNotifyFromTmqsim(self,cdbName='cdb'):
+    #     while 1:
+    #         tdSql.query("select * from %s.notifyinfo"%cdbName)
+    #         #tdLog.info("row: %d, %l64d, %l64d"%(tdSql.getData(0, 1),tdSql.getData(0, 2),tdSql.getData(0, 3))
+    #         if tdSql.getRows() == 2 :
+    #             tdLog.info("row[0][1]: %d, row[1][1]: %d"%(tdSql.getData(0, 1), tdSql.getData(1, 1)))
+    #             if tdSql.getData(1, 1) == 1:
+    #                 break
+    #         time.sleep(0.1)
+    #     return
 
     def selectConsumeResult(self,expectRows,cdbName='cdb'):
         resultList=[]
@@ -122,6 +124,7 @@ class TDTestCase:
         os.system(shellCmd)
 
     def create_tables(self,tsql, dbName,vgroups,stbName,ctbNum,rowsPerTbl):
+        tdLog.info("start create tables......")
         tsql.execute("create database if not exists %s vgroups %d wal_retention_period 3600"%(dbName, vgroups))
         tsql.execute("use %s" %dbName)
         tsql.execute("create table  if not exists %s (ts timestamp, c1 bigint, c2 binary(16)) tags(t1 int)"%stbName)
@@ -137,11 +140,11 @@ class TDTestCase:
             tsql.execute(sql)
 
         event.set()
-        tdLog.debug("complete to create database[%s], stable[%s] and %d child tables" %(dbName, stbName, ctbNum))
+        tdLog.info("complete to create database[%s], stable[%s] and %d child tables" %(dbName, stbName, ctbNum))
         return
 
     def insert_data(self,tsql,dbName,stbName,ctbNum,rowsPerTbl,batchNum,startTs):
-        tdLog.debug("start to insert data ............")
+        tdLog.info("start to insert data ............")
         tsql.execute("use %s" %dbName)
         pre_insert = "insert into "
         sql = pre_insert
@@ -163,7 +166,7 @@ class TDTestCase:
         if sql != pre_insert:
             #print("insert sql:%s"%sql)
             tsql.execute(sql)
-        tdLog.debug("insert data ............ [OK]")
+        tdLog.info("insert data ............ [OK]")
         return
 
     def prepareEnv(self, **parameterDict):
@@ -226,13 +229,13 @@ class TDTestCase:
         event.wait()
 
         tdLog.info("start consume processor")
-        pollDelay = 100
+        pollDelay = 20
         showMsg   = 1
         showRow   = 1
         self.startTmqSimProcess(buildPath,cfgPath,pollDelay,parameterDict["dbName"],showMsg, showRow)
 
         tdLog.info("wait the notify info of start consume")
-        self.getStartConsumeNotifyFromTmqsim()
+        tmqCom.getStartConsumeNotifyFromTmqsim()
 
         tdLog.info("pkill consume processor")
         if (platform.system().lower() == 'windows'):
@@ -286,7 +289,7 @@ class TDTestCase:
         prepareEnvThread.start()
 
         tdLog.info("create topics from db")
-        topicName1 = 'topic_db1'
+        topicName1 = 'topic_db11'
 
         tdSql.execute("create topic %s as database %s" %(topicName1, parameterDict['dbName']))
         consumerId   = 0
@@ -310,7 +313,7 @@ class TDTestCase:
 
         # time.sleep(6)
         tdLog.info("start to wait commit notify")
-        self.getStartCommitNotifyFromTmqsim()
+        tmqCom.getStartCommitNotifyFromTmqsim()
 
         tdLog.info("pkill consume processor")
         if (platform.system().lower() == 'windows'):
@@ -333,7 +336,7 @@ class TDTestCase:
         for i in range(expectRows):
             totalConsumeRows += resultList[i]
 
-        if totalConsumeRows >= expectrowcnt or totalConsumeRows <= 0:
+        if totalConsumeRows > expectrowcnt or totalConsumeRows <= 0:
             tdLog.info("act consume rows: %d, expect consume rows between %d and 0"%(totalConsumeRows, expectrowcnt))
             tdLog.exit("tmq consume rows error!")
 
diff --git a/tests/system-test/7-tmq/subscribeStb.py b/tests/system-test/7-tmq/subscribeStb.py
index 9dcbf5b351..53f1a34d58 100644
--- a/tests/system-test/7-tmq/subscribeStb.py
+++ b/tests/system-test/7-tmq/subscribeStb.py
@@ -226,12 +226,11 @@ class TDTestCase:
         self.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit)
 
         tdLog.info("start consume processor")
-        pollDelay = 5
+        pollDelay = 10
         showMsg   = 1
         showRow   = 1
         self.startTmqSimProcess(buildPath,cfgPath,pollDelay,parameterDict["dbName"],showMsg, showRow)
 
-        time.sleep(5)
         self.create_ctables(tdSql, parameterDict["dbName"], parameterDict["stbName"], parameterDict["ctbNum"])
         self.insert_data(tdSql,\
                          parameterDict["dbName"],\
@@ -307,7 +306,7 @@ class TDTestCase:
         self.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit)
 
         tdLog.info("start consume processor")
-        pollDelay = 5
+        pollDelay = 10
         showMsg   = 1
         showRow   = 1
         self.startTmqSimProcess(buildPath,cfgPath,pollDelay,parameterDict["dbName"],showMsg, showRow)
diff --git a/tests/system-test/7-tmq/tmqCommon.py b/tests/system-test/7-tmq/tmqCommon.py
index f63c70a4c6..44eef8bf24 100644
--- a/tests/system-test/7-tmq/tmqCommon.py
+++ b/tests/system-test/7-tmq/tmqCommon.py
@@ -145,31 +145,29 @@ class TMQCom:
             processID = subprocess.check_output(psCmd, shell=True).decode("utf-8")
         tdLog.debug("%s is stopped by kill -INT" % (processorName))
 
-    def getStartConsumeNotifyFromTmqsim(self,cdbName='cdb',rows=1):
+    def getStartConsumeNotifyFromTmqsim(self,cdbName='cdb'):
         loopFlag = 1
         while loopFlag:
             tdSql.query("select * from %s.notifyinfo"%cdbName)
             #tdLog.info("row: %d, %l64d, %l64d"%(tdSql.getData(0, 1),tdSql.getData(0, 2),tdSql.getData(0, 3))
             actRows = tdSql.getRows()
-            if (actRows >= rows):
-                for i in range(actRows):
-                    if tdSql.getData(i, 1) == 0:
-                        loopFlag = 0
-                        break
+            for i in range(actRows):
+                if tdSql.getData(i, 1) == 0:
+                    loopFlag = 0
+                    break
             time.sleep(0.02)
         return
 
-    def getStartCommitNotifyFromTmqsim(self,cdbName='cdb',rows=2):
+    def getStartCommitNotifyFromTmqsim(self,cdbName='cdb'):
         loopFlag = 1
         while loopFlag:
             tdSql.query("select * from %s.notifyinfo"%cdbName)
             #tdLog.info("row: %d, %l64d, %l64d"%(tdSql.getData(0, 1),tdSql.getData(0, 2),tdSql.getData(0, 3))
             actRows = tdSql.getRows()
-            if (actRows >= rows):
-                for i in range(actRows):
-                    if tdSql.getData(i, 1) == 1:
-                        loopFlag = 0
-                        break
+            for i in range(actRows):
+                if tdSql.getData(i, 1) == 1:
+                    loopFlag = 0
+                    break
             time.sleep(0.02)
         return
 
diff --git a/tests/system-test/7-tmq/tmqConsumerGroup.py b/tests/system-test/7-tmq/tmqConsumerGroup.py
index d146dca449..ae9671bcf4 100644
--- a/tests/system-test/7-tmq/tmqConsumerGroup.py
+++ b/tests/system-test/7-tmq/tmqConsumerGroup.py
@@ -42,7 +42,7 @@ class TDTestCase:
                     'showRow':    1}
 
         topicNameList = ['topic1', 'topic2']
-        expectRowsList = []
+        queryRowsList = []
         tmqCom.initConsumerTable()
         tdCom.create_database(tdSql, paraDict["dbName"],paraDict["dropFlag"], vgroups=4,replica=1)
         tdSql.execute("alter database %s wal_retention_period 3600" % (paraDict['dbName']))
@@ -60,7 +60,7 @@ class TDTestCase:
         tdLog.info("create topic sql: %s"%sqlString)
         tdSql.execute(sqlString)
         tdSql.query(queryString)
-        expectRowsList.append(tdSql.getRows())
+        queryRowsList.append(tdSql.getRows())
 
         # create one stb2
         paraDict["stbName"] = 'stb2'
@@ -77,7 +77,7 @@ class TDTestCase:
         tdLog.info("create topic sql: %s"%sqlString)
         tdSql.execute(sqlString)
         # tdSql.query(queryString)
-        # expectRowsList.append(tdSql.getRows())
+        # queryRowsList.append(tdSql.getRows())
 
         # init consume info, and start tmq_sim, then check consume result
         tdLog.info("insert consume info to consume processor")
@@ -99,7 +99,8 @@ class TDTestCase:
         pThread = tmqCom.asyncInsertData(paraDict)
 
         tdLog.info("wait consumer commit notify")
-        tmqCom.getStartCommitNotifyFromTmqsim(rows=4)
+        # tmqCom.getStartCommitNotifyFromTmqsim(rows=4)
+        tmqCom.getStartConsumeNotifyFromTmqsim()
 
         tdLog.info("pkill one consume processor")
         tmqCom.stopTmqSimProcess('tmq_sim_new')
@@ -109,19 +110,21 @@ class TDTestCase:
         tdLog.info("wait the consume result")
         expectRows = 2
         resultList = tmqCom.selectConsumeResult(expectRows)
-        actTotalRows = 0
+        actConsumTotalRows = 0
         for i in range(len(resultList)):
-            actTotalRows += resultList[i]
+            actConsumTotalRows += resultList[i]
+            
+        tdLog.info("act consumer1 rows: %d, consumer2 rows: %d"%(resultList[0], resultList[1]))
 
         tdSql.query(queryString)
-        expectRowsList.append(tdSql.getRows())
-        expectTotalRows = 0
-        for i in range(len(expectRowsList)):
-            expectTotalRows += expectRowsList[i]
+        queryRowsList.append(tdSql.getRows())
+        queryTotalRows = 0
+        for i in range(len(queryRowsList)):
+            queryTotalRows += queryRowsList[i]
 
-        tdLog.info("act consume rows: %d, expect consume rows: %d"%(actTotalRows, expectTotalRows))
-        if expectTotalRows <= resultList[0]:
-            tdLog.info("act consume rows: %d should >= expect consume rows: %d"%(actTotalRows, expectTotalRows))
+        tdLog.info("act consume rows: %d, query consume rows: %d"%(actConsumTotalRows, queryTotalRows))
+        if actConsumTotalRows < queryTotalRows:
+            tdLog.info("act consume rows: %d should >= query consume rows: %d"%(actConsumTotalRows, queryTotalRows))
             tdLog.exit("0 tmq consume rows error!")
 
         # time.sleep(10)
@@ -130,9 +133,95 @@ class TDTestCase:
 
         tdLog.printNoPrefix("======== test case 1 end ...... ")
 
+
+    def tmqCase2(self):
+        tdLog.printNoPrefix("======== test case 2: ")
+        paraDict = {'dbName':     'db1',
+                    'dropFlag':   1,
+                    'event':      '',
+                    'vgroups':    4,
+                    'stbName':    'stb',
+                    'colPrefix':  'c',
+                    'tagPrefix':  't',
+                    'colSchema':   [{'type': 'INT', 'count':2}, {'type': 'binary', 'len':20, 'count':1},{'type': 'TIMESTAMP', 'count':1}],
+                    'tagSchema':   [{'type': 'INT', 'count':1}, {'type': 'binary', 'len':20, 'count':1}],
+                    'ctbPrefix':  'ctb',
+                    'ctbNum':     10,
+                    'rowsPerTbl': 1000,
+                    'batchNum':   10,
+                    'startTs':    1640966400000,  # 2022-01-01 00:00:00.000
+                    'pollDelay':  20,
+                    'showMsg':    1,
+                    'showRow':    1}
+
+        topicNameList = ['topic3', 'topic4']
+        queryRowsList = []
+        tmqCom.initConsumerTable()       
+
+        tdLog.info("create topics from stb with filter")
+        # queryString = "select ts, log(c1), ceil(pow(c1,3)) from %s.%s where c1 %% 7 == 0" %(paraDict['dbName'], paraDict['stbName'])
+        queryString = "select ts, log(c1), ceil(pow(c1,3)) from %s.%s" %(paraDict['dbName'], paraDict['stbName'])
+        sqlString = "create topic %s as %s" %(topicNameList[0], queryString)
+        tdLog.info("create topic sql: %s"%sqlString)
+        tdSql.execute(sqlString)
+        tdSql.query(queryString)
+        queryRowsList.append(tdSql.getRows())
+
+        # create one stb2
+        paraDict["stbName"] = 'stb2'
+        # queryString = "select ts, sin(c1), abs(pow(c1,3)) from %s.%s where c1 %% 7 == 0" %(paraDict['dbName'], paraDict['stbName'])
+        queryString = "select ts, sin(c1), abs(pow(c1,3)) from %s.%s" %(paraDict['dbName'], paraDict['stbName'])
+        sqlString = "create topic %s as %s" %(topicNameList[1], queryString)
+        tdLog.info("create topic sql: %s"%sqlString)
+        tdSql.execute(sqlString)
+        tdSql.query(queryString)
+        queryRowsList.append(tdSql.getRows())
+
+        # init consume info, and start tmq_sim, then check consume result
+        tdLog.info("insert consume info to consume processor")
+        consumerId   = 0
+        paraDict["rowsPerTbl"] = 5000
+        expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] * 2
+        topicList    = "%s,%s"%(topicNameList[0],topicNameList[1])
+        ifcheckdata  = 1
+        ifManualCommit = 1
+        keyList      = 'group.id:cgrp1, enable.auto.commit:true, auto.commit.interval.ms:3000, auto.offset.reset:earliest'
+        tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit)
+
+        tdLog.info("start consume processor 1")
+        tmqCom.startTmqSimProcess(paraDict['pollDelay'],paraDict["dbName"],paraDict['showMsg'], paraDict['showRow'])
+
+        tdLog.info("start consume processor 2")
+        tmqCom.startTmqSimProcess(paraDict['pollDelay'],paraDict["dbName"],paraDict['showMsg'], paraDict['showRow'],'cdb',0,1)
+
+        tdLog.info("wait the consume result")
+        expectRows = 2
+        resultList = tmqCom.selectConsumeResult(expectRows)
+        actConsumTotalRows = 0
+        for i in range(len(resultList)):
+            actConsumTotalRows += resultList[i]
+            
+        tdLog.info("act consumer1 rows: %d, consumer2 rows: %d"%(resultList[0], resultList[1]))
+
+        queryTotalRows = 0
+        for i in range(len(queryRowsList)):
+            queryTotalRows += queryRowsList[i]
+
+        tdLog.info("act consume rows: %d, query consume rows: %d"%(actConsumTotalRows, queryTotalRows))
+        if actConsumTotalRows < queryTotalRows:
+            tdLog.info("act consume rows: %d should >= query consume rows: %d"%(actConsumTotalRows, queryTotalRows))
+            tdLog.exit("0 tmq consume rows error!")
+
+        # time.sleep(10)
+        # for i in range(len(topicNameList)):
+        #     tdSql.query("drop topic %s"%topicNameList[i])
+
+        tdLog.printNoPrefix("======== test case 2 end ...... ")
+
     def run(self):
         tdSql.prepare()
         self.tmqCase1()
+        self.tmqCase2()
 
     def stop(self):
         tdSql.close()
diff --git a/tests/system-test/7-tmq/tmqDnodeRestart1.py b/tests/system-test/7-tmq/tmqDnodeRestart1.py
index cff55a1239..2bde32800b 100644
--- a/tests/system-test/7-tmq/tmqDnodeRestart1.py
+++ b/tests/system-test/7-tmq/tmqDnodeRestart1.py
@@ -121,7 +121,7 @@ class TDTestCase:
         tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot'])
 
         # time.sleep(3)
-        tmqCom.getStartCommitNotifyFromTmqsim('cdb',1)
+        tmqCom.getStartCommitNotifyFromTmqsim()
 
         tdLog.info("create some new child table and insert data for latest mode")
         paraDict["batchNum"] = 100
@@ -205,7 +205,7 @@ class TDTestCase:
         tdLog.info("start consume processor")
         tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot'])
 
-        tmqCom.getStartCommitNotifyFromTmqsim('cdb',1)
+        tmqCom.getStartCommitNotifyFromTmqsim()
 
         tdLog.info("create some new child table and insert data for latest mode")
         paraDict["batchNum"] = 10
diff --git a/tests/system-test/7-tmq/tmqDropStb.py b/tests/system-test/7-tmq/tmqDropStb.py
index a94747e574..0b252a7334 100644
--- a/tests/system-test/7-tmq/tmqDropStb.py
+++ b/tests/system-test/7-tmq/tmqDropStb.py
@@ -82,7 +82,7 @@ class TDTestCase:
 
         tdLog.info("create topics from db")
         topicName1 = 'UpperCasetopic_%s'%(self.paraDict['dbName'])
-        tdSql.execute("create topic %s as database %s" %(topicName1, self.paraDict['dbName']))
+        tdSql.execute("create topic `%s` as database %s" %(topicName1, self.paraDict['dbName']))
 
         topicList = topicName1 + ',' +topicName1
         keyList = '%s,%s,%s,%s'%(self.groupId,self.autoCommit,self.autoCommitInterval,self.autoOffset)
@@ -113,7 +113,7 @@ class TDTestCase:
             tdLog.exit("tmq consume rows error!")
 
         time.sleep(10)
-        tdSql.query("drop topic %s"%topicName1)
+        tdSql.query("drop topic `%s`"%topicName1)
 
         tdLog.printNoPrefix("======== test case 1 end ...... ")
 
diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c
index 0123472e3a..e2752f7899 100644
--- a/tools/shell/src/shellEngine.c
+++ b/tools/shell/src/shellEngine.c
@@ -58,7 +58,6 @@ int32_t shellRunSingleCommand(char *command) {
   }
 
   if (shellRegexMatch(command, "^[ \t]*(quit|q|exit)[ \t;]*$", REG_EXTENDED | REG_ICASE)) {
-    shellWriteHistory();
     return -1;
   }
 
@@ -555,7 +554,12 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t
       if (tsEnableScience) {
         printf("%*e", width, GET_FLOAT_VAL(val));
       } else {
-        printf("%*.5f", width, GET_FLOAT_VAL(val));
+        n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.5f", width, GET_FLOAT_VAL(val));
+        if (n > TMAX(20, width)) {
+            printf("%*e", width, GET_FLOAT_VAL(val));
+        } else {
+            printf("%s", buf);
+        }
       }
       break;
     case TSDB_DATA_TYPE_DOUBLE:
@@ -887,7 +891,6 @@ void shellWriteHistory() {
     }
     i = (i + 1) % SHELL_MAX_HISTORY_SIZE;
   }
-  taosFsyncFile(pFile);
   taosCloseFile(&pFile);
 }
 
diff --git a/tools/shell/src/shellMain.c b/tools/shell/src/shellMain.c
index bc5809ffe8..795621dfdd 100644
--- a/tools/shell/src/shellMain.c
+++ b/tools/shell/src/shellMain.c
@@ -83,6 +83,9 @@ int main(int argc, char *argv[]) {
 #endif
   taos_init();
 
+  // kill heart-beat thread when quit
+  taos_set_hb_quit(1);
+
   if (shell.args.is_dump_config) {
     shellDumpConfig();
     taos_cleanup();
diff --git a/utils/test/c/sml_test.c b/utils/test/c/sml_test.c
index 755ab55625..ac5aff4727 100644
--- a/utils/test/c/sml_test.c
+++ b/utils/test/c/sml_test.c
@@ -895,6 +895,63 @@ int smlProcess_18784_Test() {
   return code;
 }
 
+int sml_escape_Test() {
+  TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
+
+  TAOS_RES *pRes = taos_query(taos, "create database if not exists db_escape");
+  taos_free_result(pRes);
+
+  pRes = taos_query(taos, "use db_escape");
+  taos_free_result(pRes);
+
+  const char *sql[] = {
+      "d\\,i=\\ s\\k\",dev\"i\\,\\=\\ ce=s\"i\\,\\=\\ dc inode\"i\\,\\=\\ s_used=176059i,total=1076048383523889174i 1661943960000000000",
+      "d\\,i=\\ s\\k\",dev\"i\\,\\=\\ ce=s\"i\\,\\=\\ dc inode\"i\\,\\=\\ s_f\\\\ree=\"\\\"id,= ei\\\\\\f\" 1661943960000000000",
+  };
+  pRes = taos_schemaless_insert(taos, (char **)sql, sizeof(sql) / sizeof(sql[0]), TSDB_SML_LINE_PROTOCOL, 0);
+  printf("%s result:%s, rows:%d\n", __FUNCTION__, taos_errstr(pRes), taos_affected_rows(pRes));
+  int code = taos_errno(pRes);
+  ASSERT(!code);
+  ASSERT(taos_affected_rows(pRes) == 1);
+  taos_free_result(pRes);
+
+  pRes = taos_query(taos, "select * from `d,i= s\\k\"`");     //check stable name
+  ASSERT(pRes);
+  int fieldNum = taos_field_count(pRes);
+  ASSERT(fieldNum == 5);
+  printf("fieldNum:%d\n", fieldNum);
+
+  int         numFields = taos_num_fields(pRes);
+  TAOS_FIELD *fields = taos_fetch_fields(pRes);
+  ASSERT(numFields == 5);
+  ASSERT(strncmp(fields[1].name, "inode\"i,= s_used", sizeof("inode\"i,= s_used") - 1) == 0);
+  ASSERT(strncmp(fields[2].name, "total", sizeof("total") - 1) == 0);
+  ASSERT(strncmp(fields[3].name, "inode\"i,= s_f\\\\ree", sizeof("inode\"i,= s_f\\\\ree") - 1) == 0);
+  ASSERT(strncmp(fields[4].name, "dev\"i,= ce", sizeof("dev\"i,= ce") - 1) == 0);
+
+  TAOS_ROW row = NULL;
+  int32_t  rowIndex = 0;
+  while ((row = taos_fetch_row(pRes)) != NULL) {
+    int64_t ts = *(int64_t *)row[0];
+    int64_t used = *(int64_t *)row[1];
+    int64_t total = *(int64_t *)row[2];
+
+    if (rowIndex == 0) {
+      ASSERT(ts == 1661943960000);
+      ASSERT(used == 176059);
+      ASSERT(total == 1076048383523889174);
+      ASSERT(strncmp(row[3], "\"id,= ei\\\\f", sizeof("\"id,= ei\\\\f") - 1) == 0);
+      ASSERT(strncmp(row[4], "s\"i,= dc", sizeof("s\"i,= dc") - 1) == 0);
+
+    }
+    rowIndex++;
+  }
+  taos_free_result(pRes);
+  taos_close(taos);
+
+  return code;
+}
+
 int sml_19221_Test() {
   TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
 
@@ -932,7 +989,7 @@ int sml_ts2164_Test() {
   TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
 
   TAOS_RES *pRes =
-      taos_query(taos, "CREATE DATABASE IF NOT EXISTS line_test  BUFFER 384  MINROWS 1000  PAGES 256 PRECISION 'ns'");
+      taos_query(taos, "CREATE DATABASE IF NOT EXISTS line_test MINROWS 1000 PRECISION 'ns'");
   taos_free_result(pRes);
 
   const char *sql[] = {
@@ -961,6 +1018,55 @@ int sml_ts2164_Test() {
   return code;
 }
 
+
+int sml_ts3116_Test() {
+  TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
+
+  TAOS_RES *pRes =
+      taos_query(taos, "DROP DATABASE IF EXISTS ts3116");
+  taos_free_result(pRes);
+
+  pRes = taos_query(taos, "CREATE DATABASE IF NOT EXISTS ts3116  BUFFER 384  MINROWS 1000  PAGES 256 PRECISION 'ns'");
+  taos_free_result(pRes);
+
+  char *sql = {
+      "meters,location=la,groupid=ca current=11.8,voltage=221",
+  };
+
+  pRes = taos_query(taos, "use ts3116");
+  taos_free_result(pRes);
+  int32_t totalRows = 0;
+  char *tmp = (char *)taosMemoryCalloc(1024, 1);
+  memcpy(tmp, sql, strlen(sql));
+  totalRows = 0;
+  pRes = taos_schemaless_insert_raw(taos, tmp, strlen(tmp), &totalRows, TSDB_SML_LINE_PROTOCOL,
+                                    TSDB_SML_TIMESTAMP_MILLI_SECONDS);
+  taosMemoryFree(tmp);
+  printf("%s result:%s\n", __FUNCTION__, taos_errstr(pRes));
+  int code = taos_errno(pRes);
+  taos_free_result(pRes);
+
+  char *sql1 = {
+      "meters,location=la,groupid=ca\\=3 current=11.8,voltage=221\nmeters,location=la,groupid=ca current=11.8,voltage=221,phase=0.27",
+  };
+
+  pRes = taos_query(taos, "use ts3116");
+  taos_free_result(pRes);
+
+  tmp = (char *)taosMemoryCalloc(1024, 1);
+  memcpy(tmp, sql1, strlen(sql1));
+  totalRows = 0;
+  pRes = taos_schemaless_insert_raw(taos, tmp, strlen(tmp), &totalRows, TSDB_SML_LINE_PROTOCOL,
+                                TSDB_SML_TIMESTAMP_MILLI_SECONDS);
+  taosMemoryFree(tmp);
+  printf("%s result:%s\n", __FUNCTION__, taos_errstr(pRes));
+  code = taos_errno(pRes);
+  taos_free_result(pRes);
+  taos_close(taos);
+
+  return code;
+}
+
 int sml_td22898_Test() {
   TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
 
@@ -1026,6 +1132,84 @@ int sml_td22900_Test() {
   return code;
 }
 
+int sml_td23881_Test() {
+  TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
+
+  TAOS_RES *pRes =
+      taos_query(taos, "CREATE DATABASE IF NOT EXISTS line_23881 PRECISION 'ns'");
+  taos_free_result(pRes);
+
+  char tmp[26375] = {0};
+  memset(tmp, 'a', 26374);
+  char sql[102400] = {0};
+  sprintf(sql,"lujixfvqor,t0=t c0=f,c1=\"%s\",c2=\"%s\",c3=\"%s\",c4=\"wthvqxcsrlps\" 1626006833639000000", tmp, tmp, tmp);
+
+  pRes = taos_query(taos, "use line_23881");
+  taos_free_result(pRes);
+
+  int totalRows = 0;
+  pRes = taos_schemaless_insert_raw(taos, sql, strlen(sql), &totalRows, TSDB_SML_LINE_PROTOCOL,
+                                    TSDB_SML_TIMESTAMP_NANO_SECONDS);
+
+  printf("%s result:%s\n", __FUNCTION__, taos_errstr(pRes));
+  int code = taos_errno(pRes);
+  taos_free_result(pRes);
+  taos_close(taos);
+
+  return code;
+}
+
+int sml_ts3303_Test() {
+  TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
+
+  TAOS_RES *pRes = taos_query(taos, "drop database if exists ts3303");
+  taos_free_result(pRes);
+
+  pRes = taos_query(taos, "create database if not exists ts3303");
+  taos_free_result(pRes);
+
+  const char *sql[] = {
+      "stb2,t1=1,dataModelName=t0 f1=283i32 1632299372000",
+      "stb2,t1=1,dataModelName=t0 f1=106i32 1632299378000",
+      "stb2,t1=4,dataModelName=t0 f1=144i32 1629716944000",
+      "stb2,t1=4,dataModelName=t0 f1=125i32 1629717012000",
+      "stb2,t1=4,dataModelName=t0 f1=144i32 1629717012000",
+      "stb2,t1=4,dataModelName=t0 f1=107i32 1629717013000",
+      "stb2,t1=6,dataModelName=t0 f1=154i32 1629717140000",
+      "stb2,t1=6,dataModelName=t0 f1=93i32 1629717140000",
+      "stb2,t1=6,dataModelName=t0 f1=134i32 1629717140000",
+      "stb2,t1=4,dataModelName=t0 f1=73i32 1629717140000",
+      "stb2,t1=4,dataModelName=t0 f1=83i32 1629717140000",
+      "stb2,t1=4,dataModelName=t0 f1=72i32 1629717140000",
+  };
+
+  const char *sql1[] = {
+      "meters,location=California.LosAngeles,groupid=2 current=11.8,voltage=221,phase=\"2022-02-0210:22:22\" 1626006833339000000",
+      "meters,groupid=2,location=California.LosAngeles current=11.8,voltage=221,phase=\"2022-02-0210:22:22\" 1626006833339000000",
+  };
+
+  pRes = taos_query(taos, "use ts3303");
+  taos_free_result(pRes);
+
+  pRes = taos_schemaless_insert_ttl(taos, (char **)sql, sizeof(sql) / sizeof(sql[0]), TSDB_SML_LINE_PROTOCOL,
+                                    TSDB_SML_TIMESTAMP_MILLI_SECONDS, 20);
+
+  int code = taos_errno(pRes);
+  printf("%s result0:%s\n", __FUNCTION__, taos_errstr(pRes));
+  taos_free_result(pRes);
+  ASSERT(code == 0);
+
+  pRes = taos_schemaless_insert_ttl(taos, (char **)sql1, sizeof(sql1) / sizeof(sql1[0]), TSDB_SML_LINE_PROTOCOL,
+                                    TSDB_SML_TIMESTAMP_NANO_SECONDS, 20);
+
+  printf("%s result1:%s\n", __FUNCTION__, taos_errstr(pRes));
+  taos_free_result(pRes);
+
+  taos_close(taos);
+
+  return code;
+}
+
 int sml_ttl_Test() {
   TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0);
 
@@ -1195,8 +1379,17 @@ int main(int argc, char *argv[]) {
   }
 
   int ret = 0;
-  ret = sml_ts2385_Test();    // this test case need config sml table name using ./sml_test config_file
+  ret = sml_td23881_Test();
+  ASSERT(ret);
+  ret = sml_escape_Test();
   ASSERT(!ret);
+  ret = sml_ts3116_Test();
+  ASSERT(!ret);
+//  ret = sml_ts2385_Test();    // this test case need config sml table name using ./sml_test config_file
+//  ASSERT(!ret);
+  ret = sml_ts3303_Test();    // this test case need config sml table name using ./sml_test config_file
+  ASSERT(!ret);
+
   //  for(int i = 0; i < sizeof(str)/sizeof(str[0]); i++){
   //    printf("str:%s \t %d\n", str[i], smlCalTypeSum(str[i], strlen(str[i])));
   //  }
diff --git a/utils/test/c/tmqSim.c b/utils/test/c/tmqSim.c
index f2de219f4e..d98a45f0d3 100644
--- a/utils/test/c/tmqSim.c
+++ b/utils/test/c/tmqSim.c
@@ -232,7 +232,7 @@ void saveConfigToLogFile() {
       taosFprintfFile(g_fp, "%s:%s, ", g_stConfInfo.stThreads[i].key[k], g_stConfInfo.stThreads[i].value[k]);
     }
     taosFprintfFile(g_fp, "\n");
-    taosFprintfFile(g_fp, "  expect rows: %" PRIx64 "\n", g_stConfInfo.stThreads[i].expectMsgCnt);
+    taosFprintfFile(g_fp, "  expect rows: %" PRId64 "\n", g_stConfInfo.stThreads[i].expectMsgCnt);
   }
 
   char tmpString[128];