commit
2986d41fda
|
@ -296,5 +296,6 @@ ENDIF ()
|
||||||
|
|
||||||
ADD_SUBDIRECTORY(deps)
|
ADD_SUBDIRECTORY(deps)
|
||||||
ADD_SUBDIRECTORY(src)
|
ADD_SUBDIRECTORY(src)
|
||||||
|
ADD_SUBDIRECTORY(tests)
|
||||||
|
|
||||||
INCLUDE(CPack)
|
INCLUDE(CPack)
|
||||||
|
|
|
@ -6,6 +6,7 @@ INCLUDE_DIRECTORIES(jni)
|
||||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
|
||||||
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||||
INCLUDE_DIRECTORIES(${TD_ENTERPRISE_DIR}/src/inc)
|
INCLUDE_DIRECTORIES(${TD_ENTERPRISE_DIR}/src/inc)
|
||||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||||
AUX_SOURCE_DIRECTORY(src SRC)
|
AUX_SOURCE_DIRECTORY(src SRC)
|
||||||
|
|
|
@ -32,6 +32,12 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code);
|
||||||
SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, int32_t index);
|
SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, int32_t index);
|
||||||
void tscDestroyJoinSupporter(SJoinSubquerySupporter* pSupporter);
|
void tscDestroyJoinSupporter(SJoinSubquerySupporter* pSupporter);
|
||||||
|
|
||||||
|
int32_t tscHandleMasterJoinQuery(SSqlObj* pSql);
|
||||||
|
|
||||||
|
int32_t tscHandleMasterSTableQuery(SSqlObj *pSql);
|
||||||
|
|
||||||
|
int32_t tscHandleMultivnodeInsert(SSqlObj *pSql);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -29,11 +29,11 @@ extern "C" {
|
||||||
#include "tscSecondaryMerge.h"
|
#include "tscSecondaryMerge.h"
|
||||||
#include "tsclient.h"
|
#include "tsclient.h"
|
||||||
|
|
||||||
#define UTIL_METER_IS_SUPERTABLE(metaInfo) \
|
#define UTIL_TABLE_IS_SUPERTABLE(metaInfo) \
|
||||||
(((metaInfo)->pMeterMeta != NULL) && ((metaInfo)->pMeterMeta->tableType == TSDB_SUPER_TABLE))
|
(((metaInfo)->pTableMeta != NULL) && ((metaInfo)->pTableMeta->tableType == TSDB_SUPER_TABLE))
|
||||||
#define UTIL_METER_IS_NOMRAL_METER(metaInfo) (!(UTIL_METER_IS_SUPERTABLE(metaInfo)))
|
#define UTIL_TABLE_IS_NOMRAL_TABLE(metaInfo) (!(UTIL_TABLE_IS_SUPERTABLE(metaInfo)))
|
||||||
#define UTIL_METER_IS_CREATE_FROM_METRIC(metaInfo) \
|
#define UTIL_TABLE_CREATE_FROM_STABLE(metaInfo) \
|
||||||
(((metaInfo)->pMeterMeta != NULL) && ((metaInfo)->pMeterMeta->tableType == TSDB_CHILD_TABLE))
|
(((metaInfo)->pTableMeta != NULL) && ((metaInfo)->pTableMeta->tableType == TSDB_CHILD_TABLE))
|
||||||
|
|
||||||
#define TSDB_COL_IS_TAG(f) (((f)&TSDB_COL_TAG) != 0)
|
#define TSDB_COL_IS_TAG(f) (((f)&TSDB_COL_TAG) != 0)
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ typedef struct SJoinSubquerySupporter {
|
||||||
} SJoinSubquerySupporter;
|
} SJoinSubquerySupporter;
|
||||||
|
|
||||||
int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, const char* name,
|
int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, const char* name,
|
||||||
STableMeta* pMeterMeta, STableDataBlocks** dataBlocks);
|
STableMeta* pTableMeta, STableDataBlocks** dataBlocks);
|
||||||
void tscAppendDataBlock(SDataBlockList* pList, STableDataBlocks* pBlocks);
|
void tscAppendDataBlock(SDataBlockList* pList, STableDataBlocks* pBlocks);
|
||||||
void tscDestroyDataBlock(STableDataBlocks* pDataBlock);
|
void tscDestroyDataBlock(STableDataBlocks* pDataBlock);
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock);
|
||||||
void tscFreeUnusedDataBlocks(SDataBlockList* pList);
|
void tscFreeUnusedDataBlocks(SDataBlockList* pList);
|
||||||
int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pDataList);
|
int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pDataList);
|
||||||
int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList, int64_t id, int32_t size,
|
int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList, int64_t id, int32_t size,
|
||||||
int32_t startOffset, int32_t rowSize, const char* tableId, STableMeta* pMeterMeta,
|
int32_t startOffset, int32_t rowSize, const char* tableId, STableMeta* pTableMeta,
|
||||||
STableDataBlocks** dataBlocks);
|
STableDataBlocks** dataBlocks);
|
||||||
|
|
||||||
SVnodeSidList* tscGetVnodeSidList(SSuperTableMeta* pMetricmeta, int32_t vnodeIdx);
|
SVnodeSidList* tscGetVnodeSidList(SSuperTableMeta* pMetricmeta, int32_t vnodeIdx);
|
||||||
|
@ -104,7 +104,7 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex);
|
||||||
|
|
||||||
bool tscProjectionQueryOnTable(SQueryInfo* pQueryInfo);
|
bool tscProjectionQueryOnTable(SQueryInfo* pQueryInfo);
|
||||||
|
|
||||||
bool tscIsTwoStageMergeMetricQuery(SQueryInfo* pQueryInfo, int32_t tableIndex);
|
bool tscIsTwoStageSTableQuery(SQueryInfo* pQueryInfo, int32_t tableIndex);
|
||||||
bool tscQueryOnMetric(SSqlCmd* pCmd);
|
bool tscQueryOnMetric(SSqlCmd* pCmd);
|
||||||
bool tscQueryMetricTags(SQueryInfo* pQueryInfo);
|
bool tscQueryMetricTags(SQueryInfo* pQueryInfo);
|
||||||
bool tscIsSelectivityWithTagQuery(SSqlCmd* pCmd);
|
bool tscIsSelectivityWithTagQuery(SSqlCmd* pCmd);
|
||||||
|
@ -114,7 +114,7 @@ void tscAddSpecialColumnForSelect(SQueryInfo* pQueryInfo, int32_t outputColIndex
|
||||||
|
|
||||||
void addRequiredTagColumn(SQueryInfo* pQueryInfo, int32_t tagColIndex, int32_t tableIndex);
|
void addRequiredTagColumn(SQueryInfo* pQueryInfo, int32_t tagColIndex, int32_t tableIndex);
|
||||||
|
|
||||||
int32_t setMeterID(SMeterMetaInfo* pMeterMetaInfo, SSQLToken* pzTableName, SSqlObj* pSql);
|
int32_t setMeterID(STableMetaInfo* pTableMetaInfo, SSQLToken* pzTableName, SSqlObj* pSql);
|
||||||
void tscClearInterpInfo(SQueryInfo* pQueryInfo);
|
void tscClearInterpInfo(SQueryInfo* pQueryInfo);
|
||||||
|
|
||||||
bool tscIsInsertOrImportData(char* sqlstr);
|
bool tscIsInsertOrImportData(char* sqlstr);
|
||||||
|
@ -173,7 +173,7 @@ int32_t tscValidateName(SSQLToken* pToken);
|
||||||
|
|
||||||
void tscIncStreamExecutionCount(void* pStream);
|
void tscIncStreamExecutionCount(void* pStream);
|
||||||
|
|
||||||
bool tscValidateColumnId(SMeterMetaInfo* pMeterMetaInfo, int32_t colId);
|
bool tscValidateColumnId(STableMetaInfo* pTableMetaInfo, int32_t colId);
|
||||||
|
|
||||||
// get starter position of metric query condition (query on tags) in SSqlCmd.payload
|
// get starter position of metric query condition (query on tags) in SSqlCmd.payload
|
||||||
SCond* tsGetMetricQueryCondPos(STagCond* pCond, uint64_t tableIndex);
|
SCond* tsGetMetricQueryCondPos(STagCond* pCond, uint64_t tableIndex);
|
||||||
|
@ -190,26 +190,26 @@ void tscCleanSqlCmd(SSqlCmd* pCmd);
|
||||||
bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql);
|
bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql);
|
||||||
|
|
||||||
void tscRemoveAllMeterMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool removeFromCache);
|
void tscRemoveAllMeterMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool removeFromCache);
|
||||||
SMeterMetaInfo* tscGetMeterMetaInfo(SSqlCmd *pCmd, int32_t subClauseIndex, int32_t tableIndex);
|
STableMetaInfo* tscGetTableMetaInfoFromCmd(SSqlCmd *pCmd, int32_t subClauseIndex, int32_t tableIndex);
|
||||||
SMeterMetaInfo* tscGetMeterMetaInfoFromQueryInfo(SQueryInfo *pQueryInfo, int32_t tableIndex);
|
STableMetaInfo* tscGetMetaInfo(SQueryInfo *pQueryInfo, int32_t tableIndex);
|
||||||
|
|
||||||
SQueryInfo *tscGetQueryInfoDetail(SSqlCmd* pCmd, int32_t subClauseIndex);
|
SQueryInfo *tscGetQueryInfoDetail(SSqlCmd* pCmd, int32_t subClauseIndex);
|
||||||
int32_t tscGetQueryInfoDetailSafely(SSqlCmd *pCmd, int32_t subClauseIndex, SQueryInfo** pQueryInfo);
|
int32_t tscGetQueryInfoDetailSafely(SSqlCmd *pCmd, int32_t subClauseIndex, SQueryInfo** pQueryInfo);
|
||||||
|
|
||||||
SMeterMetaInfo* tscGetMeterMetaInfoByUid(SQueryInfo* pQueryInfo, uint64_t uid, int32_t* index);
|
STableMetaInfo* tscGetMeterMetaInfoByUid(SQueryInfo* pQueryInfo, uint64_t uid, int32_t* index);
|
||||||
void tscClearMeterMetaInfo(SMeterMetaInfo* pMeterMetaInfo, bool removeFromCache);
|
void tscClearMeterMetaInfo(STableMetaInfo* pTableMetaInfo, bool removeFromCache);
|
||||||
|
|
||||||
SMeterMetaInfo* tscAddMeterMetaInfo(SQueryInfo* pQueryInfo, const char* name, STableMeta* pMeterMeta, SSuperTableMeta* pMetricMeta,
|
STableMetaInfo* tscAddMeterMetaInfo(SQueryInfo* pQueryInfo, const char* name, STableMeta* pTableMeta, SSuperTableMeta* pMetricMeta,
|
||||||
int16_t numOfTags, int16_t* tags);
|
int16_t numOfTags, int16_t* tags);
|
||||||
SMeterMetaInfo* tscAddEmptyMeterMetaInfo(SQueryInfo *pQueryInfo);
|
STableMetaInfo* tscAddEmptyMetaInfo(SQueryInfo *pQueryInfo);
|
||||||
int32_t tscAddSubqueryInfo(SSqlCmd *pCmd);
|
int32_t tscAddSubqueryInfo(SSqlCmd *pCmd);
|
||||||
void tscFreeSubqueryInfo(SSqlCmd* pCmd);
|
void tscFreeSubqueryInfo(SSqlCmd* pCmd);
|
||||||
void tscClearSubqueryInfo(SSqlCmd* pCmd);
|
void tscClearSubqueryInfo(SSqlCmd* pCmd);
|
||||||
|
|
||||||
void tscGetMetricMetaCacheKey(SQueryInfo* pQueryInfo, char* keyStr, uint64_t uid);
|
void tscGetMetricMetaCacheKey(SQueryInfo* pQueryInfo, char* keyStr, uint64_t uid);
|
||||||
int tscGetMetricMeta(SSqlObj* pSql, int32_t clauseIndex);
|
int tscGetMetricMeta(SSqlObj* pSql, int32_t clauseIndex);
|
||||||
int tscGetMeterMeta(SSqlObj* pSql, SMeterMetaInfo* pMeterMetaInfo);
|
int tscGetTableMeta(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo);
|
||||||
int tscGetMeterMetaEx(SSqlObj* pSql, SMeterMetaInfo* pMeterMetaInfo, bool createIfNotExists);
|
int tscGetMeterMetaEx(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, bool createIfNotExists);
|
||||||
|
|
||||||
void tscResetForNextRetrieve(SSqlRes* pRes);
|
void tscResetForNextRetrieve(SSqlRes* pRes);
|
||||||
|
|
||||||
|
@ -252,8 +252,6 @@ void tscTryQueryNextVnode(SSqlObj *pSql, __async_cb_func_t fp);
|
||||||
void tscAsyncQuerySingleRowForNextVnode(void *param, TAOS_RES *tres, int numOfRows);
|
void tscAsyncQuerySingleRowForNextVnode(void *param, TAOS_RES *tres, int numOfRows);
|
||||||
void tscTryQueryNextClause(SSqlObj* pSql, void (*queryFp)());
|
void tscTryQueryNextClause(SSqlObj* pSql, void (*queryFp)());
|
||||||
|
|
||||||
int32_t launchMultivnodeInsert(SSqlObj *pSql);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,13 +20,56 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "tstoken.h"
|
#include "tstoken.h"
|
||||||
|
#include "tsclient.h"
|
||||||
|
|
||||||
#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS)
|
#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS)
|
||||||
|
|
||||||
struct SSchema;
|
//struct SSchema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the number of tags of this table
|
||||||
|
* @param pTableMeta
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int32_t tscGetNumOfTags(const STableMeta* pTableMeta);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the number of columns of this table
|
||||||
|
* @param pTableMeta
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int32_t tscGetNumOfColumns(const STableMeta* pTableMeta);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the basic info of this table
|
||||||
|
* @param pTableMeta
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
STableComInfo tscGetTableInfo(const STableMeta* pTableMeta);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the schema
|
||||||
|
* @param pTableMeta
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SSchema* tscGetTableSchema(const STableMeta* pTableMeta);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the tag schema
|
||||||
|
* @param pMeta
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SSchema *tscGetTableTagSchema(const STableMeta *pMeta);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param pMeta
|
||||||
|
* @param startCol
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SSchema *tscGetTableColumnSchema(const STableMeta *pMeta, int32_t startCol);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the schema is valid or not, including following aspects:
|
* check if the schema is valid or not, including following aspects:
|
||||||
|
@ -42,21 +85,23 @@ struct SSchema;
|
||||||
*/
|
*/
|
||||||
bool isValidSchema(struct SSchema *pSchema, int32_t numOfCols);
|
bool isValidSchema(struct SSchema *pSchema, int32_t numOfCols);
|
||||||
|
|
||||||
struct SSchema *tsGetSchema(STableMeta *pMeta);
|
/**
|
||||||
|
* get the schema for the "tbname" column. it is a built column
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SSchema tscGetTbnameColumnSchema();
|
||||||
|
|
||||||
struct SSchema *tsGetTagSchema(STableMeta *pMeta);
|
/**
|
||||||
|
* create the table meta from the msg
|
||||||
struct SSchema *tsGetColumnSchema(STableMeta *pMeta, int32_t startCol);
|
* @param pTableMetaMsg
|
||||||
struct SSchema tsGetTbnameColumnSchema();
|
* @param size size of the table meta
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
STableMeta* tscCreateTableMetaFromMsg(STableMetaMsg* pTableMetaMsg, size_t* size);
|
||||||
|
|
||||||
|
//todo tags value as well as the table id structure needs refactor
|
||||||
char *tsGetTagsValue(STableMeta *pMeta);
|
char *tsGetTagsValue(STableMeta *pMeta);
|
||||||
|
|
||||||
bool tsMeterMetaIdentical(STableMeta *p1, STableMeta *p2);
|
|
||||||
|
|
||||||
void extractTableName(char *tableId, char *name);
|
|
||||||
|
|
||||||
SSQLToken extractDBName(char *tableId, char *name);
|
|
||||||
|
|
||||||
void extractTableNameFromToken(SSQLToken *pToken, SSQLToken* pTable);
|
void extractTableNameFromToken(SSQLToken *pToken, SSQLToken* pTable);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
|
@ -21,17 +21,19 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
|
#include "qsqlparser.h"
|
||||||
|
#include "qsqltype.h"
|
||||||
|
#include "qtsbuf.h"
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
|
#include "taosdef.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "tglobalcfg.h"
|
#include "tglobalcfg.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "taosdef.h"
|
#include "trpc.h"
|
||||||
#include "tsqlfunction.h"
|
#include "tsqlfunction.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
#include "trpc.h"
|
#include "tarray.h"
|
||||||
#include "qsqltype.h"
|
|
||||||
#include "qsqlparser.h"
|
|
||||||
#include "qtsbuf.h"
|
|
||||||
|
|
||||||
#define TSC_GET_RESPTR_BASE(res, _queryinfo, col) (res->data + ((_queryinfo)->fieldsInfo.pSqlExpr[col]->offset) * res->numOfRows)
|
#define TSC_GET_RESPTR_BASE(res, _queryinfo, col) (res->data + ((_queryinfo)->fieldsInfo.pSqlExpr[col]->offset) * res->numOfRows)
|
||||||
|
|
||||||
|
@ -46,8 +48,28 @@ typedef struct SSqlGroupbyExpr {
|
||||||
int16_t orderType; // order by type: asc/desc
|
int16_t orderType; // order by type: asc/desc
|
||||||
} SSqlGroupbyExpr;
|
} SSqlGroupbyExpr;
|
||||||
|
|
||||||
typedef struct SMeterMetaInfo {
|
typedef struct STableComInfo {
|
||||||
STableMeta * pMeterMeta; // metermeta
|
uint8_t numOfTags;
|
||||||
|
uint8_t precision;
|
||||||
|
int16_t numOfColumns;
|
||||||
|
int16_t rowSize;
|
||||||
|
} STableComInfo;
|
||||||
|
|
||||||
|
typedef struct STableMeta {
|
||||||
|
//super table if it is created according to super table, otherwise, tableInfo is used
|
||||||
|
union { struct STableMeta* pSTable; STableComInfo tableInfo; };
|
||||||
|
uint8_t tableType;
|
||||||
|
int8_t numOfVpeers;
|
||||||
|
int16_t sversion;
|
||||||
|
SVnodeDesc vpeerDesc[TSDB_VNODES_SUPPORT];
|
||||||
|
int32_t vgid; // virtual group id, which current table belongs to
|
||||||
|
int32_t sid; // the index of one table in a virtual node
|
||||||
|
uint64_t uid; // unique id of a table
|
||||||
|
SSchema schema[]; // if the table is TSDB_CHILD_TABLE, schema is acquired by super table meta info
|
||||||
|
} STableMeta;
|
||||||
|
|
||||||
|
typedef struct STableMetaInfo {
|
||||||
|
STableMeta * pTableMeta; // table meta, cached in client side and acquried by name
|
||||||
SSuperTableMeta *pMetricMeta; // metricmeta
|
SSuperTableMeta *pMetricMeta; // metricmeta
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -55,14 +77,14 @@ typedef struct SMeterMetaInfo {
|
||||||
* 2. keep the vnode index for multi-vnode insertion
|
* 2. keep the vnode index for multi-vnode insertion
|
||||||
*/
|
*/
|
||||||
int32_t vnodeIndex;
|
int32_t vnodeIndex;
|
||||||
char name[TSDB_TABLE_ID_LEN + 1]; // table(super table) name
|
char name[TSDB_TABLE_ID_LEN]; // (super) table name
|
||||||
int16_t numOfTags; // total required tags in query, including groupby tags
|
int16_t numOfTags; // total required tags in query, including groupby tags
|
||||||
int16_t tagColumnIndex[TSDB_MAX_TAGS]; // clause + tag projection
|
int16_t tagColumnIndex[TSDB_MAX_TAGS]; // clause + tag projection
|
||||||
} SMeterMetaInfo;
|
} STableMetaInfo;
|
||||||
|
|
||||||
/* the structure for sql function in select clause */
|
/* the structure for sql function in select clause */
|
||||||
typedef struct SSqlExpr {
|
typedef struct SSqlExpr {
|
||||||
char aliasName[TSDB_COL_NAME_LEN + 1]; // as aliasName
|
char aliasName[TSDB_COL_NAME_LEN]; // as aliasName
|
||||||
SColIndexEx colInfo;
|
SColIndexEx colInfo;
|
||||||
int64_t uid; // refactor use the pointer
|
int64_t uid; // refactor use the pointer
|
||||||
int16_t functionId; // function id in aAgg array
|
int16_t functionId; // function id in aAgg array
|
||||||
|
@ -83,7 +105,6 @@ typedef struct SFieldInfo {
|
||||||
int16_t numOfOutputCols; // number of column in result
|
int16_t numOfOutputCols; // number of column in result
|
||||||
int16_t numOfAlloc; // allocated size
|
int16_t numOfAlloc; // allocated size
|
||||||
TAOS_FIELD *pFields;
|
TAOS_FIELD *pFields;
|
||||||
// short * pOffset;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* define if this column is belong to the queried result, it may be add by parser to faciliate
|
* define if this column is belong to the queried result, it may be add by parser to faciliate
|
||||||
|
@ -174,7 +195,7 @@ typedef struct STableDataBlocks {
|
||||||
* the metermeta for current table, the metermeta will be used during submit stage, keep a ref
|
* the metermeta for current table, the metermeta will be used during submit stage, keep a ref
|
||||||
* to avoid it to be removed from cache
|
* to avoid it to be removed from cache
|
||||||
*/
|
*/
|
||||||
STableMeta *pMeterMeta;
|
STableMeta *pTableMeta;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
char *filename;
|
char *filename;
|
||||||
|
@ -199,7 +220,7 @@ typedef struct SDataBlockList {
|
||||||
typedef struct SQueryInfo {
|
typedef struct SQueryInfo {
|
||||||
int16_t command; // the command may be different for each subclause, so keep it seperately.
|
int16_t command; // the command may be different for each subclause, so keep it seperately.
|
||||||
uint16_t type; // query/insert/import type
|
uint16_t type; // query/insert/import type
|
||||||
char intervalTimeUnit;
|
char slidingTimeUnit;
|
||||||
|
|
||||||
int64_t etime, stime;
|
int64_t etime, stime;
|
||||||
int64_t intervalTime; // aggregation time interval
|
int64_t intervalTime; // aggregation time interval
|
||||||
|
@ -215,7 +236,7 @@ typedef struct SQueryInfo {
|
||||||
SOrderVal order;
|
SOrderVal order;
|
||||||
int16_t interpoType; // interpolate type
|
int16_t interpoType; // interpolate type
|
||||||
int16_t numOfTables;
|
int16_t numOfTables;
|
||||||
SMeterMetaInfo **pMeterInfo;
|
STableMetaInfo **pTableMetaInfo;
|
||||||
struct STSBuf * tsBuf;
|
struct STSBuf * tsBuf;
|
||||||
int64_t * defaultVal; // default value for interpolation
|
int64_t * defaultVal; // default value for interpolation
|
||||||
char * msg; // pointer to the pCmd->payload to keep error message temporarily
|
char * msg; // pointer to the pCmd->payload to keep error message temporarily
|
||||||
|
@ -238,7 +259,7 @@ typedef struct {
|
||||||
union {
|
union {
|
||||||
bool existsCheck; // check if the table exists or not
|
bool existsCheck; // check if the table exists or not
|
||||||
bool inStream; // denote if current sql is executed in stream or not
|
bool inStream; // denote if current sql is executed in stream or not
|
||||||
bool createOnDemand; // if the table is missing, on-the-fly create it. during getmeterMeta
|
bool autoCreated; // if the table is missing, on-the-fly create it. during getmeterMeta
|
||||||
int8_t dataSourceType; // load data from file or not
|
int8_t dataSourceType; // load data from file or not
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -296,7 +317,7 @@ typedef struct {
|
||||||
struct SLocalReducer *pLocalReducer;
|
struct SLocalReducer *pLocalReducer;
|
||||||
} SSqlRes;
|
} SSqlRes;
|
||||||
|
|
||||||
typedef struct _tsc_obj {
|
typedef struct STscObj {
|
||||||
void * signature;
|
void * signature;
|
||||||
void * pTimer;
|
void * pTimer;
|
||||||
char mgmtIp[TSDB_USER_LEN];
|
char mgmtIp[TSDB_USER_LEN];
|
||||||
|
@ -311,7 +332,7 @@ typedef struct _tsc_obj {
|
||||||
struct SSqlObj *pSql;
|
struct SSqlObj *pSql;
|
||||||
struct SSqlObj *pHb;
|
struct SSqlObj *pHb;
|
||||||
struct SSqlObj *sqlList;
|
struct SSqlObj *sqlList;
|
||||||
struct _sstream *streamList;
|
struct SSqlStream *streamList;
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
} STscObj;
|
} STscObj;
|
||||||
|
|
||||||
|
@ -344,7 +365,7 @@ typedef struct SSqlObj {
|
||||||
struct SSqlObj * prev, *next;
|
struct SSqlObj * prev, *next;
|
||||||
} SSqlObj;
|
} SSqlObj;
|
||||||
|
|
||||||
typedef struct _sstream {
|
typedef struct SSqlStream {
|
||||||
SSqlObj *pSql;
|
SSqlObj *pSql;
|
||||||
uint32_t streamId;
|
uint32_t streamId;
|
||||||
char listed;
|
char listed;
|
||||||
|
@ -369,7 +390,7 @@ typedef struct _sstream {
|
||||||
void *param;
|
void *param;
|
||||||
|
|
||||||
void (*callback)(void *); // Callback function when stream is stopped from client level
|
void (*callback)(void *); // Callback function when stream is stopped from client level
|
||||||
struct _sstream *prev, *next;
|
struct SSqlStream *prev, *next;
|
||||||
} SSqlStream;
|
} SSqlStream;
|
||||||
|
|
||||||
int32_t tscInitRpc(const char *user, const char *secret);
|
int32_t tscInitRpc(const char *user, const char *secret);
|
||||||
|
@ -377,14 +398,12 @@ int32_t tscInitRpc(const char *user, const char *secret);
|
||||||
// tscSql API
|
// tscSql API
|
||||||
int tsParseSql(SSqlObj *pSql, bool multiVnodeInsertion);
|
int tsParseSql(SSqlObj *pSql, bool multiVnodeInsertion);
|
||||||
|
|
||||||
void tscInitMsgs();
|
void tscInitMsgsFp();
|
||||||
extern int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo);
|
extern int (*tscBuildMsg[TSDB_SQL_MAX])(SSqlObj *pSql, SSqlInfo *pInfo);
|
||||||
|
|
||||||
void tscProcessMsgFromServer(SRpcMsg *rpcMsg);
|
void tscProcessMsgFromServer(SRpcMsg *rpcMsg);
|
||||||
int tscProcessSql(SSqlObj *pSql);
|
int tscProcessSql(SSqlObj *pSql);
|
||||||
|
|
||||||
void tscAsyncInsertMultiVnodesProxy(void *param, TAOS_RES *tres, int numOfRows);
|
|
||||||
|
|
||||||
int tscRenewMeterMeta(SSqlObj *pSql, char *tableId);
|
int tscRenewMeterMeta(SSqlObj *pSql, char *tableId);
|
||||||
void tscQueueAsyncRes(SSqlObj *pSql);
|
void tscQueueAsyncRes(SSqlObj *pSql);
|
||||||
|
|
||||||
|
|
|
@ -13,13 +13,13 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
#include "com_taosdata_jdbc_TSDBJNIConnector.h"
|
#include "com_taosdata_jdbc_TSDBJNIConnector.h"
|
||||||
|
#include "os.h"
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "tscJoinProcess.h"
|
#include "tscSubquery.h"
|
||||||
#include "tsclient.h"
|
|
||||||
#include "tscUtil.h"
|
#include "tscUtil.h"
|
||||||
|
#include "tsclient.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
|
|
||||||
int __init = 0;
|
int __init = 0;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
#include "tnote.h"
|
#include "tnote.h"
|
||||||
#include "tsched.h"
|
#include "tsched.h"
|
||||||
|
#include "tschemautil.h"
|
||||||
|
|
||||||
static void tscProcessFetchRow(SSchedMsg *pMsg);
|
static void tscProcessFetchRow(SSchedMsg *pMsg);
|
||||||
static void tscAsyncQueryRowsForNextVnode(void *param, TAOS_RES *tres, int numOfRows);
|
static void tscAsyncQueryRowsForNextVnode(void *param, TAOS_RES *tres, int numOfRows);
|
||||||
|
@ -83,7 +84,7 @@ void doAsyncQuery(STscObj* pObj, SSqlObj* pSql, void (*fp)(), void* param, const
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO return the correct error code to client in tscQueueAsyncError
|
// TODO return the correct error code to client in tscQueueAsyncError
|
||||||
void taos_query_a(TAOS *taos, const char *sqlstr, void (*fp)(void *, TAOS_RES *, int), void *param) {
|
void taos_query_a(TAOS *taos, const char *sqlstr, __async_cb_func_t fp, void *param) {
|
||||||
STscObj *pObj = (STscObj *)taos;
|
STscObj *pObj = (STscObj *)taos;
|
||||||
if (pObj == NULL || pObj->signature != pObj) {
|
if (pObj == NULL || pObj->signature != pObj) {
|
||||||
tscError("bug!!! pObj:%p", pObj);
|
tscError("bug!!! pObj:%p", pObj);
|
||||||
|
@ -396,51 +397,9 @@ void tscQueueAsyncFreeResult(SSqlObj *pSql) {
|
||||||
taosScheduleTask(tscQhandle, &schedMsg);
|
taosScheduleTask(tscQhandle, &schedMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscAsyncInsertMultiVnodesProxy(void *param, TAOS_RES *tres, int numOfRows) {
|
|
||||||
SSqlObj *pSql = (SSqlObj *)param;
|
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
|
||||||
|
|
||||||
assert(pCmd->dataSourceType != 0 && pSql->signature == pSql);
|
|
||||||
|
|
||||||
int32_t index = 0;
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, index);
|
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
|
||||||
assert(pQueryInfo->numOfTables == 1 || pQueryInfo->numOfTables == 2);
|
|
||||||
|
|
||||||
SDataBlockList *pDataBlocks = pCmd->pDataBlocks;
|
|
||||||
if (pDataBlocks == NULL || pMeterMetaInfo->vnodeIndex >= pDataBlocks->nSize) {
|
|
||||||
// restore user defined fp
|
|
||||||
pSql->fp = pSql->fetchFp;
|
|
||||||
tscTrace("%p Async insertion completed, destroy data block list", pSql);
|
|
||||||
|
|
||||||
// release data block data
|
|
||||||
pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
|
|
||||||
|
|
||||||
// all data has been sent to vnode, call user function
|
|
||||||
(*pSql->fp)(pSql->param, tres, numOfRows);
|
|
||||||
} else {
|
|
||||||
do {
|
|
||||||
code = tscCopyDataBlockToPayload(pSql, pDataBlocks->pData[pMeterMetaInfo->vnodeIndex++]);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
|
||||||
tscTrace("%p prepare submit data block failed in async insertion, vnodeIdx:%d, total:%d, code:%d",
|
|
||||||
pSql, pMeterMetaInfo->vnodeIndex - 1, pDataBlocks->nSize, code);
|
|
||||||
}
|
|
||||||
|
|
||||||
} while (code != TSDB_CODE_SUCCESS && pMeterMetaInfo->vnodeIndex < pDataBlocks->nSize);
|
|
||||||
|
|
||||||
// build submit msg may fail
|
|
||||||
if (code == TSDB_CODE_SUCCESS) {
|
|
||||||
tscTrace("%p async insertion, vnodeIdx:%d, total:%d", pSql, pMeterMetaInfo->vnodeIndex - 1, pDataBlocks->nSize);
|
|
||||||
tscProcessSql(pSql);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int tscSendMsgToServer(SSqlObj *pSql);
|
int tscSendMsgToServer(SSqlObj *pSql);
|
||||||
|
|
||||||
void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
|
void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
|
||||||
SSqlObj *pSql = (SSqlObj *)param;
|
SSqlObj *pSql = (SSqlObj *)param;
|
||||||
if (pSql == NULL || pSql->signature != pSql) return;
|
if (pSql == NULL || pSql->signature != pSql) return;
|
||||||
|
|
||||||
|
@ -464,10 +423,10 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
|
||||||
tscTrace("%p renew tableMeta successfully, command:%d, code:%d, retry:%d",
|
tscTrace("%p renew tableMeta successfully, command:%d, code:%d, retry:%d",
|
||||||
pSql, pSql->cmd.command, pSql->res.code, pSql->retry);
|
pSql, pSql->cmd.command, pSql->res.code, pSql->retry);
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0);
|
||||||
assert(pMeterMetaInfo->pMeterMeta == NULL);
|
assert(pTableMetaInfo->pTableMeta == NULL);
|
||||||
|
|
||||||
tscGetMeterMeta(pSql, pMeterMetaInfo);
|
tscGetTableMeta(pSql, pTableMetaInfo);
|
||||||
code = tscSendMsgToServer(pSql);
|
code = tscSendMsgToServer(pSql);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
pRes->code = code;
|
pRes->code = code;
|
||||||
|
@ -489,18 +448,18 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||||
|
|
||||||
if ((pQueryInfo->type & TSDB_QUERY_TYPE_STABLE_SUBQUERY) == TSDB_QUERY_TYPE_STABLE_SUBQUERY) {
|
if ((pQueryInfo->type & TSDB_QUERY_TYPE_STABLE_SUBQUERY) == TSDB_QUERY_TYPE_STABLE_SUBQUERY) {
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
assert(pMeterMetaInfo->pMeterMeta->numOfTags != 0 && pMeterMetaInfo->vnodeIndex >= 0 && pSql->param != NULL);
|
assert((tscGetNumOfTags(pTableMetaInfo->pTableMeta) != 0) && pTableMetaInfo->vnodeIndex >= 0 && pSql->param != NULL);
|
||||||
|
|
||||||
SRetrieveSupport *trs = (SRetrieveSupport *)pSql->param;
|
SRetrieveSupport *trs = (SRetrieveSupport *)pSql->param;
|
||||||
SSqlObj * pParObj = trs->pParentSqlObj;
|
SSqlObj * pParObj = trs->pParentSqlObj;
|
||||||
|
|
||||||
assert(pParObj->signature == pParObj && trs->subqueryIndex == pMeterMetaInfo->vnodeIndex &&
|
assert(pParObj->signature == pParObj && trs->subqueryIndex == pTableMetaInfo->vnodeIndex &&
|
||||||
pMeterMetaInfo->pMeterMeta->numOfTags != 0);
|
tscGetNumOfTags(pTableMetaInfo->pTableMeta) != 0);
|
||||||
|
|
||||||
tscTrace("%p get metricMeta during super table query successfully", pSql);
|
tscTrace("%p get metricMeta during super table query successfully", pSql);
|
||||||
|
|
||||||
code = tscGetMeterMeta(pSql, pMeterMetaInfo);
|
code = tscGetTableMeta(pSql, pTableMetaInfo);
|
||||||
pRes->code = code;
|
pRes->code = code;
|
||||||
|
|
||||||
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
|
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
|
||||||
|
@ -513,11 +472,11 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
|
||||||
if (pCmd->isParseFinish) {
|
if (pCmd->isParseFinish) {
|
||||||
tscTrace("%p resend data to vnode in metermeta callback since sql has been parsed completed", pSql);
|
tscTrace("%p resend data to vnode in metermeta callback since sql has been parsed completed", pSql);
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
code = tscGetMeterMeta(pSql, pMeterMetaInfo);
|
code = tscGetTableMeta(pSql, pTableMetaInfo);
|
||||||
assert(code == TSDB_CODE_SUCCESS);
|
assert(code == TSDB_CODE_SUCCESS);
|
||||||
|
|
||||||
if (pMeterMetaInfo->pMeterMeta) {
|
if (pTableMetaInfo->pTableMeta) {
|
||||||
code = tscSendMsgToServer(pSql);
|
code = tscSendMsgToServer(pSql);
|
||||||
if (code == TSDB_CODE_SUCCESS) return;
|
if (code == TSDB_CODE_SUCCESS) return;
|
||||||
}
|
}
|
||||||
|
@ -528,13 +487,13 @@ void tscMeterMetaCallBack(void *param, TAOS_RES *res, int code) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { // stream computing
|
} else { // stream computing
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
code = tscGetMeterMeta(pSql, pMeterMetaInfo);
|
code = tscGetTableMeta(pSql, pTableMetaInfo);
|
||||||
pRes->code = code;
|
pRes->code = code;
|
||||||
|
|
||||||
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
|
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
|
||||||
|
|
||||||
if (code == TSDB_CODE_SUCCESS && UTIL_METER_IS_SUPERTABLE(pMeterMetaInfo)) {
|
if (code == TSDB_CODE_SUCCESS && UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) {
|
||||||
code = tscGetMetricMeta(pSql, pCmd->clauseIndex);
|
code = tscGetMetricMeta(pSql, pCmd->clauseIndex);
|
||||||
pRes->code = code;
|
pRes->code = code;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "tscJoinProcess.h"
|
#include "tscSubquery.h"
|
||||||
#include "tscompression.h"
|
#include "tscompression.h"
|
||||||
#include "tsqlfunction.h"
|
#include "tsqlfunction.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
|
@ -388,6 +388,10 @@ static void function_finalizer(SQLFunctionCtx *pCtx) {
|
||||||
doFinalizer(pCtx);
|
doFinalizer(pCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool usePreVal(SQLFunctionCtx *pCtx) {
|
||||||
|
return pCtx->preAggVals.isSet && pCtx->size == pCtx->preAggVals.size;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* count function does need the finalize, if data is missing, the default value, which is 0, is used
|
* count function does need the finalize, if data is missing, the default value, which is 0, is used
|
||||||
* count function does not use the pCtx->interResBuf to keep the intermediate buffer
|
* count function does not use the pCtx->interResBuf to keep the intermediate buffer
|
||||||
|
@ -395,13 +399,14 @@ static void function_finalizer(SQLFunctionCtx *pCtx) {
|
||||||
static void count_function(SQLFunctionCtx *pCtx) {
|
static void count_function(SQLFunctionCtx *pCtx) {
|
||||||
int32_t numOfElem = 0;
|
int32_t numOfElem = 0;
|
||||||
|
|
||||||
if (IS_DATA_BLOCK_LOADED(pCtx->blockStatus)) {
|
|
||||||
/*
|
/*
|
||||||
* In following cases, the data block is loaded:
|
* 1. column data missing (schema modified) causes pCtx->hasNull == true. pCtx->preAggVals.isSet == true;
|
||||||
* 1. A first/last file block for a query
|
* 2. for general non-primary key columns, pCtx->hasNull may be true or false, pCtx->preAggVals.isSet == true;
|
||||||
* 2. Required to handle other queries, such as apercentile/twa/stddev etc.
|
* 3. for primary key column, pCtx->hasNull always be false, pCtx->preAggVals.isSet == false;
|
||||||
* 3. A cache block
|
|
||||||
*/
|
*/
|
||||||
|
if (usePreVal(pCtx)) {
|
||||||
|
numOfElem = pCtx->size - pCtx->preAggVals.statis.numOfNull;
|
||||||
|
} else {
|
||||||
if (pCtx->hasNull) {
|
if (pCtx->hasNull) {
|
||||||
for (int32_t i = 0; i < pCtx->size; ++i) {
|
for (int32_t i = 0; i < pCtx->size; ++i) {
|
||||||
char *val = GET_INPUT_CHAR_INDEX(pCtx, i);
|
char *val = GET_INPUT_CHAR_INDEX(pCtx, i);
|
||||||
|
@ -414,18 +419,6 @@ static void count_function(SQLFunctionCtx *pCtx) {
|
||||||
} else {
|
} else {
|
||||||
numOfElem = pCtx->size;
|
numOfElem = pCtx->size;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* 1. column data missing (schema modified) causes pCtx->hasNull == true. pCtx->preAggVals.isSet == true;
|
|
||||||
* 2. for general non-primary key columns, pCtx->hasNull may be true or false, pCtx->preAggVals.isSet == true;
|
|
||||||
* 3. for primary key column, pCtx->hasNull always be false, pCtx->preAggVals.isSet == false;
|
|
||||||
*/
|
|
||||||
if (pCtx->preAggVals.isSet) {
|
|
||||||
numOfElem = pCtx->size - pCtx->preAggVals.numOfNull;
|
|
||||||
} else {
|
|
||||||
assert(pCtx->hasNull == false);
|
|
||||||
numOfElem = pCtx->size;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numOfElem > 0) {
|
if (numOfElem > 0) {
|
||||||
|
@ -469,7 +462,7 @@ static void count_func_merge(SQLFunctionCtx *pCtx) {
|
||||||
* @param filterCols
|
* @param filterCols
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t count_load_data_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId, int32_t blockStatus) {
|
int32_t count_load_data_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) {
|
||||||
if (colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
|
if (colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
|
||||||
return BLK_DATA_NO_NEEDED;
|
return BLK_DATA_NO_NEEDED;
|
||||||
} else {
|
} else {
|
||||||
|
@ -477,7 +470,7 @@ int32_t count_load_data_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t no_data_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId, int32_t blockStatus) {
|
int32_t no_data_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) {
|
||||||
return BLK_DATA_NO_NEEDED;
|
return BLK_DATA_NO_NEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,16 +525,16 @@ static void do_sum(SQLFunctionCtx *pCtx) {
|
||||||
int32_t notNullElems = 0;
|
int32_t notNullElems = 0;
|
||||||
|
|
||||||
// Only the pre-computing information loaded and actual data does not loaded
|
// Only the pre-computing information loaded and actual data does not loaded
|
||||||
if (!IS_DATA_BLOCK_LOADED(pCtx->blockStatus) && pCtx->preAggVals.isSet) {
|
if (pCtx->preAggVals.isSet && pCtx->preAggVals.size == pCtx->size) {
|
||||||
notNullElems = pCtx->size - pCtx->preAggVals.numOfNull;
|
notNullElems = pCtx->size - pCtx->preAggVals.statis.numOfNull;
|
||||||
assert(pCtx->size >= pCtx->preAggVals.numOfNull);
|
assert(pCtx->size >= pCtx->preAggVals.statis.numOfNull);
|
||||||
|
|
||||||
if (pCtx->inputType >= TSDB_DATA_TYPE_TINYINT && pCtx->inputType <= TSDB_DATA_TYPE_BIGINT) {
|
if (pCtx->inputType >= TSDB_DATA_TYPE_TINYINT && pCtx->inputType <= TSDB_DATA_TYPE_BIGINT) {
|
||||||
int64_t *retVal = (int64_t*) pCtx->aOutputBuf;
|
int64_t *retVal = (int64_t*) pCtx->aOutputBuf;
|
||||||
*retVal += pCtx->preAggVals.sum;
|
*retVal += pCtx->preAggVals.statis.sum;
|
||||||
} else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE || pCtx->inputType == TSDB_DATA_TYPE_FLOAT) {
|
} else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE || pCtx->inputType == TSDB_DATA_TYPE_FLOAT) {
|
||||||
double *retVal = (double*) pCtx->aOutputBuf;
|
double *retVal = (double*) pCtx->aOutputBuf;
|
||||||
*retVal += GET_DOUBLE_VAL(&(pCtx->preAggVals.sum));
|
*retVal += GET_DOUBLE_VAL(&(pCtx->preAggVals.statis.sum));
|
||||||
}
|
}
|
||||||
} else { // computing based on the true data block
|
} else { // computing based on the true data block
|
||||||
void *pData = GET_INPUT_CHAR(pCtx);
|
void *pData = GET_INPUT_CHAR(pCtx);
|
||||||
|
@ -684,16 +677,16 @@ static void sum_func_second_merge(SQLFunctionCtx *pCtx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t precal_req_load_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId, int32_t blockStatus) {
|
static int32_t precal_req_load_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) {
|
||||||
return BLK_DATA_FILEDS_NEEDED;
|
return BLK_DATA_FILEDS_NEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t data_req_load_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId, int32_t blockStatus) {
|
static int32_t data_req_load_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) {
|
||||||
return BLK_DATA_ALL_NEEDED;
|
return BLK_DATA_ALL_NEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: if column in current data block are null, opt for this case
|
// todo: if column in current data block are null, opt for this case
|
||||||
static int32_t first_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId, int32_t blockStatus) {
|
static int32_t first_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) {
|
||||||
if (pCtx->order == TSQL_SO_DESC) {
|
if (pCtx->order == TSQL_SO_DESC) {
|
||||||
return BLK_DATA_NO_NEEDED;
|
return BLK_DATA_NO_NEEDED;
|
||||||
}
|
}
|
||||||
|
@ -706,7 +699,7 @@ static int32_t first_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t last_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId, int32_t blockStatus) {
|
static int32_t last_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) {
|
||||||
if (pCtx->order == TSQL_SO_ASC) {
|
if (pCtx->order == TSQL_SO_ASC) {
|
||||||
return BLK_DATA_NO_NEEDED;
|
return BLK_DATA_NO_NEEDED;
|
||||||
}
|
}
|
||||||
|
@ -718,8 +711,7 @@ static int32_t last_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t first_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId,
|
static int32_t first_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) {
|
||||||
int32_t blockStatus) {
|
|
||||||
if (pCtx->order == TSQL_SO_DESC) {
|
if (pCtx->order == TSQL_SO_DESC) {
|
||||||
return BLK_DATA_NO_NEEDED;
|
return BLK_DATA_NO_NEEDED;
|
||||||
}
|
}
|
||||||
|
@ -735,8 +727,7 @@ static int32_t first_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t last_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId,
|
static int32_t last_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY end, int32_t colId) {
|
||||||
int32_t blockStatus) {
|
|
||||||
if (pCtx->order == TSQL_SO_ASC) {
|
if (pCtx->order == TSQL_SO_ASC) {
|
||||||
return BLK_DATA_NO_NEEDED;
|
return BLK_DATA_NO_NEEDED;
|
||||||
}
|
}
|
||||||
|
@ -765,15 +756,15 @@ static void avg_function(SQLFunctionCtx *pCtx) {
|
||||||
SAvgInfo *pAvgInfo = (SAvgInfo *)pResInfo->interResultBuf;
|
SAvgInfo *pAvgInfo = (SAvgInfo *)pResInfo->interResultBuf;
|
||||||
double * pVal = &pAvgInfo->sum;
|
double * pVal = &pAvgInfo->sum;
|
||||||
|
|
||||||
if (!IS_DATA_BLOCK_LOADED(pCtx->blockStatus) && pCtx->preAggVals.isSet) {
|
if (usePreVal(pCtx)) {
|
||||||
// Pre-aggregation
|
// Pre-aggregation
|
||||||
notNullElems = pCtx->size - pCtx->preAggVals.numOfNull;
|
notNullElems = pCtx->size - pCtx->preAggVals.statis.numOfNull;
|
||||||
assert(notNullElems >= 0);
|
assert(notNullElems >= 0);
|
||||||
|
|
||||||
if (pCtx->inputType >= TSDB_DATA_TYPE_TINYINT && pCtx->inputType <= TSDB_DATA_TYPE_BIGINT) {
|
if (pCtx->inputType >= TSDB_DATA_TYPE_TINYINT && pCtx->inputType <= TSDB_DATA_TYPE_BIGINT) {
|
||||||
*pVal += pCtx->preAggVals.sum;
|
*pVal += pCtx->preAggVals.statis.sum;
|
||||||
} else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE || pCtx->inputType == TSDB_DATA_TYPE_FLOAT) {
|
} else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE || pCtx->inputType == TSDB_DATA_TYPE_FLOAT) {
|
||||||
*pVal += GET_DOUBLE_VAL(&(pCtx->preAggVals.sum));
|
*pVal += GET_DOUBLE_VAL(&(pCtx->preAggVals.statis.sum));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
void *pData = GET_INPUT_CHAR(pCtx);
|
void *pData = GET_INPUT_CHAR(pCtx);
|
||||||
|
@ -928,20 +919,20 @@ static void avg_finalizer(SQLFunctionCtx *pCtx) {
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static void minMax_function(SQLFunctionCtx *pCtx, char *pOutput, int32_t isMin, int32_t *notNullElems) {
|
static void minMax_function(SQLFunctionCtx *pCtx, char *pOutput, int32_t isMin, int32_t *notNullElems) {
|
||||||
if (!IS_DATA_BLOCK_LOADED(pCtx->blockStatus) && pCtx->preAggVals.isSet) {
|
|
||||||
// data in current data block are qualified to the query
|
// data in current data block are qualified to the query
|
||||||
*notNullElems = pCtx->size - pCtx->preAggVals.numOfNull;
|
if (usePreVal(pCtx)) {
|
||||||
|
*notNullElems = pCtx->size - pCtx->preAggVals.statis.numOfNull;
|
||||||
assert(*notNullElems >= 0);
|
assert(*notNullElems >= 0);
|
||||||
|
|
||||||
void * tval = NULL;
|
void * tval = NULL;
|
||||||
int16_t index = 0;
|
int16_t index = 0;
|
||||||
|
|
||||||
if (isMin) {
|
if (isMin) {
|
||||||
tval = &pCtx->preAggVals.min;
|
tval = &pCtx->preAggVals.statis.min;
|
||||||
index = pCtx->preAggVals.minIndex;
|
index = pCtx->preAggVals.statis.minIndex;
|
||||||
} else {
|
} else {
|
||||||
tval = &pCtx->preAggVals.max;
|
tval = &pCtx->preAggVals.statis.max;
|
||||||
index = pCtx->preAggVals.maxIndex;
|
index = pCtx->preAggVals.statis.maxIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1488,7 +1479,7 @@ static bool first_last_function_setup(SQLFunctionCtx *pCtx) {
|
||||||
|
|
||||||
// todo opt for null block
|
// todo opt for null block
|
||||||
static void first_function(SQLFunctionCtx *pCtx) {
|
static void first_function(SQLFunctionCtx *pCtx) {
|
||||||
if (!IS_DATA_BLOCK_LOADED(pCtx->blockStatus) || pCtx->order == TSQL_SO_DESC) {
|
if (pCtx->order == TSQL_SO_DESC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1566,7 +1557,7 @@ static void first_dist_function(SQLFunctionCtx *pCtx) {
|
||||||
* 1. data block that are not loaded
|
* 1. data block that are not loaded
|
||||||
* 2. scan data files in desc order
|
* 2. scan data files in desc order
|
||||||
*/
|
*/
|
||||||
if (!IS_DATA_BLOCK_LOADED(pCtx->blockStatus) || pCtx->order == TSQL_SO_DESC) {
|
if (pCtx->order == TSQL_SO_DESC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1659,7 +1650,7 @@ static void first_dist_func_second_merge(SQLFunctionCtx *pCtx) {
|
||||||
* least one data in this block that is not null.(TODO opt for this case)
|
* least one data in this block that is not null.(TODO opt for this case)
|
||||||
*/
|
*/
|
||||||
static void last_function(SQLFunctionCtx *pCtx) {
|
static void last_function(SQLFunctionCtx *pCtx) {
|
||||||
if (!IS_DATA_BLOCK_LOADED(pCtx->blockStatus) || pCtx->order == TSQL_SO_ASC) {
|
if (pCtx->order == TSQL_SO_ASC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1735,7 +1726,7 @@ static void last_dist_function(SQLFunctionCtx *pCtx) {
|
||||||
* 1. for scan data in asc order, no need to check data
|
* 1. for scan data in asc order, no need to check data
|
||||||
* 2. for data blocks that are not loaded, no need to check data
|
* 2. for data blocks that are not loaded, no need to check data
|
||||||
*/
|
*/
|
||||||
if (!IS_DATA_BLOCK_LOADED(pCtx->blockStatus) || pCtx->order == TSQL_SO_ASC) {
|
if (pCtx->order == TSQL_SO_ASC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3305,9 +3296,9 @@ char *arithmetic_callback_function(void *param, char *name, int32_t colId) {
|
||||||
SSqlFunctionExpr *pExpr = pSupport->pExpr;
|
SSqlFunctionExpr *pExpr = pSupport->pExpr;
|
||||||
int32_t colIndexInBuf = -1;
|
int32_t colIndexInBuf = -1;
|
||||||
|
|
||||||
for (int32_t i = 0; i < pExpr->pBinExprInfo.numOfCols; ++i) {
|
for (int32_t i = 0; i < pExpr->binExprInfo.numOfCols; ++i) {
|
||||||
if (colId == pExpr->pBinExprInfo.pReqColumns[i].colId) {
|
if (colId == pExpr->binExprInfo.pReqColumns[i].colId) {
|
||||||
colIndexInBuf = pExpr->pBinExprInfo.pReqColumns[i].colIdxInBuf;
|
colIndexInBuf = pExpr->binExprInfo.pReqColumns[i].colIdxInBuf;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3320,7 +3311,7 @@ static void arithmetic_function(SQLFunctionCtx *pCtx) {
|
||||||
GET_RES_INFO(pCtx)->numOfRes += pCtx->size;
|
GET_RES_INFO(pCtx)->numOfRes += pCtx->size;
|
||||||
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[1].pz;
|
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[1].pz;
|
||||||
|
|
||||||
tSQLBinaryExprCalcTraverse(sas->pExpr->pBinExprInfo.pBinExpr, pCtx->size, pCtx->aOutputBuf, sas, pCtx->order,
|
tSQLBinaryExprCalcTraverse(sas->pExpr->binExprInfo.pBinExpr, pCtx->size, pCtx->aOutputBuf, sas, pCtx->order,
|
||||||
arithmetic_callback_function);
|
arithmetic_callback_function);
|
||||||
|
|
||||||
pCtx->aOutputBuf += pCtx->outputBytes * pCtx->size;
|
pCtx->aOutputBuf += pCtx->outputBytes * pCtx->size;
|
||||||
|
@ -3332,7 +3323,7 @@ static void arithmetic_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
||||||
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[1].pz;
|
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[1].pz;
|
||||||
|
|
||||||
sas->offset = index;
|
sas->offset = index;
|
||||||
tSQLBinaryExprCalcTraverse(sas->pExpr->pBinExprInfo.pBinExpr, 1, pCtx->aOutputBuf, sas, pCtx->order,
|
tSQLBinaryExprCalcTraverse(sas->pExpr->binExprInfo.pBinExpr, 1, pCtx->aOutputBuf, sas, pCtx->order,
|
||||||
arithmetic_callback_function);
|
arithmetic_callback_function);
|
||||||
|
|
||||||
pCtx->aOutputBuf += pCtx->outputBytes/* * GET_FORWARD_DIRECTION_FACTOR(pCtx->order)*/;
|
pCtx->aOutputBuf += pCtx->outputBytes/* * GET_FORWARD_DIRECTION_FACTOR(pCtx->order)*/;
|
||||||
|
@ -3382,9 +3373,8 @@ static void spread_function(SQLFunctionCtx *pCtx) {
|
||||||
int32_t numOfElems = pCtx->size;
|
int32_t numOfElems = pCtx->size;
|
||||||
|
|
||||||
// column missing cause the hasNull to be true
|
// column missing cause the hasNull to be true
|
||||||
if (!IS_DATA_BLOCK_LOADED(pCtx->blockStatus)) {
|
if (usePreVal(pCtx)) {
|
||||||
if (pCtx->preAggVals.isSet) {
|
numOfElems = pCtx->size - pCtx->preAggVals.statis.numOfNull;
|
||||||
numOfElems = pCtx->size - pCtx->preAggVals.numOfNull;
|
|
||||||
|
|
||||||
// all data are null in current data block, ignore current data block
|
// all data are null in current data block, ignore current data block
|
||||||
if (numOfElems == 0) {
|
if (numOfElems == 0) {
|
||||||
|
@ -3393,20 +3383,20 @@ static void spread_function(SQLFunctionCtx *pCtx) {
|
||||||
|
|
||||||
if ((pCtx->inputType >= TSDB_DATA_TYPE_TINYINT && pCtx->inputType <= TSDB_DATA_TYPE_BIGINT) ||
|
if ((pCtx->inputType >= TSDB_DATA_TYPE_TINYINT && pCtx->inputType <= TSDB_DATA_TYPE_BIGINT) ||
|
||||||
(pCtx->inputType == TSDB_DATA_TYPE_TIMESTAMP)) {
|
(pCtx->inputType == TSDB_DATA_TYPE_TIMESTAMP)) {
|
||||||
if (pInfo->min > pCtx->preAggVals.min) {
|
if (pInfo->min > pCtx->preAggVals.statis.min) {
|
||||||
pInfo->min = pCtx->preAggVals.min;
|
pInfo->min = pCtx->preAggVals.statis.min;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInfo->max < pCtx->preAggVals.max) {
|
if (pInfo->max < pCtx->preAggVals.statis.max) {
|
||||||
pInfo->max = pCtx->preAggVals.max;
|
pInfo->max = pCtx->preAggVals.statis.max;
|
||||||
}
|
}
|
||||||
} else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE || pCtx->inputType == TSDB_DATA_TYPE_FLOAT) {
|
} else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE || pCtx->inputType == TSDB_DATA_TYPE_FLOAT) {
|
||||||
if (pInfo->min > GET_DOUBLE_VAL(&(pCtx->preAggVals.min))) {
|
if (pInfo->min > GET_DOUBLE_VAL(&(pCtx->preAggVals.statis.min))) {
|
||||||
pInfo->min = GET_DOUBLE_VAL(&(pCtx->preAggVals.min));
|
pInfo->min = GET_DOUBLE_VAL(&(pCtx->preAggVals.statis.min));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInfo->max < GET_DOUBLE_VAL(&(pCtx->preAggVals.max))) {
|
if (pInfo->max < GET_DOUBLE_VAL(&(pCtx->preAggVals.statis.max))) {
|
||||||
pInfo->max = GET_DOUBLE_VAL(&(pCtx->preAggVals.max));
|
pInfo->max = GET_DOUBLE_VAL(&(pCtx->preAggVals.statis.max));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -3419,9 +3409,6 @@ static void spread_function(SQLFunctionCtx *pCtx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
goto _spread_over;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *pData = GET_INPUT_CHAR(pCtx);
|
void *pData = GET_INPUT_CHAR(pCtx);
|
||||||
numOfElems = 0;
|
numOfElems = 0;
|
||||||
|
|
||||||
|
@ -3443,7 +3430,7 @@ static void spread_function(SQLFunctionCtx *pCtx) {
|
||||||
assert(pCtx->size == numOfElems);
|
assert(pCtx->size == numOfElems);
|
||||||
}
|
}
|
||||||
|
|
||||||
_spread_over:
|
_spread_over:
|
||||||
SET_VAL(pCtx, numOfElems, 1);
|
SET_VAL(pCtx, numOfElems, 1);
|
||||||
|
|
||||||
if (numOfElems > 0) {
|
if (numOfElems > 0) {
|
||||||
|
@ -4044,8 +4031,6 @@ static void twa_function(SQLFunctionCtx *pCtx) {
|
||||||
void * data = GET_INPUT_CHAR(pCtx);
|
void * data = GET_INPUT_CHAR(pCtx);
|
||||||
TSKEY *primaryKey = pCtx->ptsList;
|
TSKEY *primaryKey = pCtx->ptsList;
|
||||||
|
|
||||||
assert(IS_DATA_BLOCK_LOADED(pCtx->blockStatus));
|
|
||||||
|
|
||||||
int32_t notNullElems = 0;
|
int32_t notNullElems = 0;
|
||||||
|
|
||||||
SResultInfo *pResInfo = GET_RES_INFO(pCtx);
|
SResultInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||||
|
@ -4440,8 +4425,6 @@ static bool rate_function_setup(SQLFunctionCtx *pCtx) {
|
||||||
|
|
||||||
static void rate_function(SQLFunctionCtx *pCtx) {
|
static void rate_function(SQLFunctionCtx *pCtx) {
|
||||||
|
|
||||||
assert(IS_DATA_BLOCK_LOADED(pCtx->blockStatus));
|
|
||||||
|
|
||||||
int32_t notNullElems = 0;
|
int32_t notNullElems = 0;
|
||||||
SResultInfo *pResInfo = GET_RES_INFO(pCtx);
|
SResultInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||||
SRateInfo *pRateInfo = (SRateInfo *)pResInfo->interResultBuf;
|
SRateInfo *pRateInfo = (SRateInfo *)pResInfo->interResultBuf;
|
||||||
|
@ -4647,8 +4630,6 @@ static void rate_finalizer(SQLFunctionCtx *pCtx) {
|
||||||
|
|
||||||
static void irate_function(SQLFunctionCtx *pCtx) {
|
static void irate_function(SQLFunctionCtx *pCtx) {
|
||||||
|
|
||||||
assert(IS_DATA_BLOCK_LOADED(pCtx->blockStatus));
|
|
||||||
|
|
||||||
int32_t notNullElems = 0;
|
int32_t notNullElems = 0;
|
||||||
SResultInfo *pResInfo = GET_RES_INFO(pCtx);
|
SResultInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||||
SRateInfo *pRateInfo = (SRateInfo *)pResInfo->interResultBuf;
|
SRateInfo *pRateInfo = (SRateInfo *)pResInfo->interResultBuf;
|
||||||
|
|
|
@ -1,812 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
#include "tscJoinProcess.h"
|
|
||||||
#include "tsclient.h"
|
|
||||||
#include "qtsbuf.h"
|
|
||||||
|
|
||||||
static void freeSubqueryObj(SSqlObj* pSql);
|
|
||||||
|
|
||||||
static bool doCompare(int32_t order, int64_t left, int64_t right) {
|
|
||||||
if (order == TSQL_SO_ASC) {
|
|
||||||
return left < right;
|
|
||||||
} else {
|
|
||||||
return left > right;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSupporter1,
|
|
||||||
SJoinSubquerySupporter* pSupporter2, TSKEY* st, TSKEY* et) {
|
|
||||||
STSBuf* output1 = tsBufCreate(true);
|
|
||||||
STSBuf* output2 = tsBufCreate(true);
|
|
||||||
|
|
||||||
*st = INT64_MAX;
|
|
||||||
*et = INT64_MIN;
|
|
||||||
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
|
||||||
|
|
||||||
SLimitVal* pLimit = &pQueryInfo->limit;
|
|
||||||
int32_t order = pQueryInfo->order.order;
|
|
||||||
|
|
||||||
SQueryInfo* pSubQueryInfo1 = tscGetQueryInfoDetail(&pSql->pSubs[0]->cmd, 0);
|
|
||||||
SQueryInfo* pSubQueryInfo2 = tscGetQueryInfoDetail(&pSql->pSubs[1]->cmd, 0);
|
|
||||||
|
|
||||||
pSubQueryInfo1->tsBuf = output1;
|
|
||||||
pSubQueryInfo2->tsBuf = output2;
|
|
||||||
|
|
||||||
tsBufResetPos(pSupporter1->pTSBuf);
|
|
||||||
tsBufResetPos(pSupporter2->pTSBuf);
|
|
||||||
|
|
||||||
// TODO add more details information
|
|
||||||
if (!tsBufNextPos(pSupporter1->pTSBuf)) {
|
|
||||||
tsBufFlush(output1);
|
|
||||||
tsBufFlush(output2);
|
|
||||||
|
|
||||||
tscTrace("%p input1 is empty, 0 for secondary query after ts blocks intersecting", pSql);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tsBufNextPos(pSupporter2->pTSBuf)) {
|
|
||||||
tsBufFlush(output1);
|
|
||||||
tsBufFlush(output2);
|
|
||||||
|
|
||||||
tscTrace("%p input2 is empty, 0 for secondary query after ts blocks intersecting", pSql);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t numOfInput1 = 1;
|
|
||||||
int64_t numOfInput2 = 1;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
STSElem elem1 = tsBufGetElem(pSupporter1->pTSBuf);
|
|
||||||
STSElem elem2 = tsBufGetElem(pSupporter2->pTSBuf);
|
|
||||||
|
|
||||||
#ifdef _DEBUG_VIEW
|
|
||||||
// for debug purpose
|
|
||||||
tscPrint("%" PRId64 ", tags:%d \t %" PRId64 ", tags:%d", elem1.ts, elem1.tag, elem2.ts, elem2.tag);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (elem1.tag < elem2.tag || (elem1.tag == elem2.tag && doCompare(order, elem1.ts, elem2.ts))) {
|
|
||||||
if (!tsBufNextPos(pSupporter1->pTSBuf)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
numOfInput1++;
|
|
||||||
} else if (elem1.tag > elem2.tag || (elem1.tag == elem2.tag && doCompare(order, elem2.ts, elem1.ts))) {
|
|
||||||
if (!tsBufNextPos(pSupporter2->pTSBuf)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
numOfInput2++;
|
|
||||||
} else {
|
|
||||||
/*
|
|
||||||
* in case of stable query, limit/offset is not applied here. the limit/offset is applied to the
|
|
||||||
* final results which is acquired after the secondry merge of in the client.
|
|
||||||
*/
|
|
||||||
if (pLimit->offset == 0 || pQueryInfo->intervalTime > 0 || QUERY_IS_STABLE_QUERY(pQueryInfo->type)) {
|
|
||||||
if (*st > elem1.ts) {
|
|
||||||
*st = elem1.ts;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*et < elem1.ts) {
|
|
||||||
*et = elem1.ts;
|
|
||||||
}
|
|
||||||
|
|
||||||
tsBufAppend(output1, elem1.vnode, elem1.tag, (const char*)&elem1.ts, sizeof(elem1.ts));
|
|
||||||
tsBufAppend(output2, elem2.vnode, elem2.tag, (const char*)&elem2.ts, sizeof(elem2.ts));
|
|
||||||
} else {
|
|
||||||
pLimit->offset -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tsBufNextPos(pSupporter1->pTSBuf)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
numOfInput1++;
|
|
||||||
|
|
||||||
if (!tsBufNextPos(pSupporter2->pTSBuf)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
numOfInput2++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* failed to set the correct ts order yet in two cases:
|
|
||||||
* 1. only one element
|
|
||||||
* 2. only one element for each tag.
|
|
||||||
*/
|
|
||||||
if (output1->tsOrder == -1) {
|
|
||||||
output1->tsOrder = TSQL_SO_ASC;
|
|
||||||
output2->tsOrder = TSQL_SO_ASC;
|
|
||||||
}
|
|
||||||
|
|
||||||
tsBufFlush(output1);
|
|
||||||
tsBufFlush(output2);
|
|
||||||
|
|
||||||
tsBufDestory(pSupporter1->pTSBuf);
|
|
||||||
tsBufDestory(pSupporter2->pTSBuf);
|
|
||||||
|
|
||||||
tscTrace("%p input1:%" PRId64 ", input2:%" PRId64 ", final:%" PRId64 " for secondary query after ts blocks "
|
|
||||||
"intersecting, skey:%" PRId64 ", ekey:%" PRId64, pSql,
|
|
||||||
numOfInput1, numOfInput2, output1->numOfTotal, *st, *et);
|
|
||||||
|
|
||||||
return output1->numOfTotal;
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo handle failed to create sub query
|
|
||||||
SJoinSubquerySupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, int32_t index) {
|
|
||||||
SJoinSubquerySupporter* pSupporter = calloc(1, sizeof(SJoinSubquerySupporter));
|
|
||||||
if (pSupporter == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pSupporter->pObj = pSql;
|
|
||||||
pSupporter->pState = pState;
|
|
||||||
|
|
||||||
pSupporter->subqueryIndex = index;
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
|
||||||
|
|
||||||
pSupporter->interval = pQueryInfo->intervalTime;
|
|
||||||
pSupporter->limit = pQueryInfo->limit;
|
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, pSql->cmd.clauseIndex, index);
|
|
||||||
pSupporter->uid = pMeterMetaInfo->pMeterMeta->uid;
|
|
||||||
|
|
||||||
assert (pSupporter->uid != 0);
|
|
||||||
|
|
||||||
getTmpfilePath("join-", pSupporter->path);
|
|
||||||
pSupporter->f = fopen(pSupporter->path, "w");
|
|
||||||
|
|
||||||
if (pSupporter->f == NULL) {
|
|
||||||
tscError("%p failed to create tmp file:%s, reason:%s", pSql, pSupporter->path, strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
return pSupporter;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tscDestroyJoinSupporter(SJoinSubquerySupporter* pSupporter) {
|
|
||||||
if (pSupporter == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tscSqlExprInfoDestroy(&pSupporter->exprsInfo);
|
|
||||||
tscColumnBaseInfoDestroy(&pSupporter->colList);
|
|
||||||
|
|
||||||
tscClearFieldInfo(&pSupporter->fieldsInfo);
|
|
||||||
|
|
||||||
if (pSupporter->f != NULL) {
|
|
||||||
fclose(pSupporter->f);
|
|
||||||
unlink(pSupporter->path);
|
|
||||||
}
|
|
||||||
|
|
||||||
tscTagCondRelease(&pSupporter->tagCond);
|
|
||||||
free(pSupporter);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* need the secondary query process
|
|
||||||
* In case of count(ts)/count(*)/spread(ts) query, that are only applied to
|
|
||||||
* primary timestamp column , the secondary query is not necessary
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
bool needSecondaryQuery(SQueryInfo* pQueryInfo) {
|
|
||||||
for (int32_t i = 0; i < pQueryInfo->colList.numOfCols; ++i) {
|
|
||||||
SColumnBase* pBase = tscColumnBaseInfoGet(&pQueryInfo->colList, i);
|
|
||||||
if (pBase->colIndex.columnIndex != PRIMARYKEY_TIMESTAMP_COL_INDEX) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* launch secondary stage query to fetch the result that contains timestamp in set
|
|
||||||
*/
|
|
||||||
int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
|
|
||||||
int32_t numOfSub = 0;
|
|
||||||
SJoinSubquerySupporter* pSupporter = NULL;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If the columns are not involved in the final select clause, the secondary query will not be launched
|
|
||||||
* for the subquery.
|
|
||||||
*/
|
|
||||||
SSubqueryState* pState = NULL;
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
|
|
||||||
pSupporter = pSql->pSubs[i]->param;
|
|
||||||
if (pSupporter->exprsInfo.numOfExprs > 0) {
|
|
||||||
++numOfSub;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(numOfSub > 0);
|
|
||||||
|
|
||||||
// scan all subquery, if one sub query has only ts, ignore it
|
|
||||||
tscTrace("%p start to launch secondary subqueries, total:%d, only:%d needs to query, others are not retrieve in "
|
|
||||||
"select clause", pSql, pSql->numOfSubs, numOfSub);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* the subqueries that do not actually launch the secondary query to virtual node is set as completed.
|
|
||||||
*/
|
|
||||||
pState = pSupporter->pState;
|
|
||||||
pState->numOfTotal = pSql->numOfSubs;
|
|
||||||
pState->numOfCompleted = (pSql->numOfSubs - numOfSub);
|
|
||||||
|
|
||||||
bool success = true;
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
|
|
||||||
SSqlObj *pPrevSub = pSql->pSubs[i];
|
|
||||||
pSql->pSubs[i] = NULL;
|
|
||||||
|
|
||||||
pSupporter = pPrevSub->param;
|
|
||||||
|
|
||||||
if (pSupporter->exprsInfo.numOfExprs == 0) {
|
|
||||||
tscTrace("%p subIndex: %d, not need to launch query, ignore it", pSql, i);
|
|
||||||
|
|
||||||
tscDestroyJoinSupporter(pSupporter);
|
|
||||||
tscFreeSqlObj(pPrevSub);
|
|
||||||
|
|
||||||
pSql->pSubs[i] = NULL;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
SQueryInfo *pSubQueryInfo = tscGetQueryInfoDetail(&pPrevSub->cmd, 0);
|
|
||||||
STSBuf *pTSBuf = pSubQueryInfo->tsBuf;
|
|
||||||
pSubQueryInfo->tsBuf = NULL;
|
|
||||||
|
|
||||||
// free result for async object will also free sqlObj
|
|
||||||
assert(pSubQueryInfo->exprsInfo.numOfExprs == 1); // ts_comp query only requires one resutl columns
|
|
||||||
taos_free_result(pPrevSub);
|
|
||||||
|
|
||||||
SSqlObj *pNew = createSubqueryObj(pSql, (int16_t) i, tscJoinQueryCallback, pSupporter, NULL);
|
|
||||||
if (pNew == NULL) {
|
|
||||||
tscDestroyJoinSupporter(pSupporter);
|
|
||||||
success = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
tscClearSubqueryInfo(&pNew->cmd);
|
|
||||||
pSql->pSubs[i] = pNew;
|
|
||||||
|
|
||||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0);
|
|
||||||
pQueryInfo->tsBuf = pTSBuf; // transfer the ownership of timestamp comp-z data to the new created object
|
|
||||||
|
|
||||||
// set the second stage sub query for join process
|
|
||||||
pQueryInfo->type |= TSDB_QUERY_TYPE_JOIN_SEC_STAGE;
|
|
||||||
|
|
||||||
pQueryInfo->intervalTime = pSupporter->interval;
|
|
||||||
pQueryInfo->groupbyExpr = pSupporter->groupbyExpr;
|
|
||||||
|
|
||||||
tscColumnBaseInfoCopy(&pQueryInfo->colList, &pSupporter->colList, 0);
|
|
||||||
tscTagCondCopy(&pQueryInfo->tagCond, &pSupporter->tagCond);
|
|
||||||
|
|
||||||
tscSqlExprCopy(&pQueryInfo->exprsInfo, &pSupporter->exprsInfo, pSupporter->uid, false);
|
|
||||||
tscFieldInfoCopyAll(&pQueryInfo->fieldsInfo, &pSupporter->fieldsInfo);
|
|
||||||
|
|
||||||
pSupporter->exprsInfo.numOfExprs = 0;
|
|
||||||
pSupporter->fieldsInfo.numOfOutputCols = 0;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if the first column of the secondary query is not ts function, add this function.
|
|
||||||
* Because this column is required to filter with timestamp after intersecting.
|
|
||||||
*/
|
|
||||||
if (pSupporter->exprsInfo.pExprs[0]->functionId != TSDB_FUNC_TS) {
|
|
||||||
tscAddTimestampColumn(pQueryInfo, TSDB_FUNC_TS, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
SQueryInfo *pNewQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0);
|
|
||||||
assert(pNew->numOfSubs == 0 && pNew->cmd.numOfClause == 1 && pNewQueryInfo->numOfTables == 1);
|
|
||||||
|
|
||||||
tscFieldInfoCalOffset(pNewQueryInfo);
|
|
||||||
|
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pNewQueryInfo, 0);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* When handling the projection query, the offset value will be modified for table-table join, which is changed
|
|
||||||
* during the timestamp intersection.
|
|
||||||
*/
|
|
||||||
pSupporter->limit = pQueryInfo->limit;
|
|
||||||
pNewQueryInfo->limit = pSupporter->limit;
|
|
||||||
|
|
||||||
// fetch the join tag column
|
|
||||||
if (UTIL_METER_IS_SUPERTABLE(pMeterMetaInfo)) {
|
|
||||||
SSqlExpr *pExpr = tscSqlExprGet(pNewQueryInfo, 0);
|
|
||||||
assert(pQueryInfo->tagCond.joinInfo.hasJoin);
|
|
||||||
|
|
||||||
int16_t tagColIndex = tscGetJoinTagColIndexByUid(&pQueryInfo->tagCond, pMeterMetaInfo->pMeterMeta->uid);
|
|
||||||
pExpr->param[0].i64Key = tagColIndex;
|
|
||||||
pExpr->numOfParams = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
tscPrintSelectClause(pNew, 0);
|
|
||||||
|
|
||||||
tscTrace("%p subquery:%p tableIndex:%d, vnodeIdx:%d, type:%d, exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s",
|
|
||||||
pSql, pNew, 0, pMeterMetaInfo->vnodeIndex, pNewQueryInfo->type,
|
|
||||||
pNewQueryInfo->exprsInfo.numOfExprs, pNewQueryInfo->colList.numOfCols,
|
|
||||||
pNewQueryInfo->fieldsInfo.numOfOutputCols, pNewQueryInfo->pMeterInfo[0]->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
//prepare the subqueries object failed, abort
|
|
||||||
if (!success) {
|
|
||||||
pSql->res.code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
|
||||||
tscError("%p failed to prepare subqueries objs for secondary phase query, numOfSub:%d, code:%d", pSql,
|
|
||||||
pSql->numOfSubs, pSql->res.code);
|
|
||||||
freeSubqueryObj(pSql);
|
|
||||||
|
|
||||||
return pSql->res.code;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int32_t i = 0; i < pSql->numOfSubs; ++i) {
|
|
||||||
SSqlObj* pSub = pSql->pSubs[i];
|
|
||||||
if (pSub == NULL) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
tscProcessSql(pSub);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void freeSubqueryObj(SSqlObj* pSql) {
|
|
||||||
SSubqueryState* pState = NULL;
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
|
|
||||||
if (pSql->pSubs[i] != NULL) {
|
|
||||||
SJoinSubquerySupporter* p = pSql->pSubs[i]->param;
|
|
||||||
pState = p->pState;
|
|
||||||
|
|
||||||
tscDestroyJoinSupporter(p);
|
|
||||||
|
|
||||||
if (pSql->pSubs[i]->res.code == TSDB_CODE_SUCCESS) {
|
|
||||||
taos_free_result(pSql->pSubs[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tfree(pState);
|
|
||||||
pSql->numOfSubs = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void doQuitSubquery(SSqlObj* pParentSql) {
|
|
||||||
freeSubqueryObj(pParentSql);
|
|
||||||
|
|
||||||
tsem_wait(&pParentSql->emptyRspSem);
|
|
||||||
tsem_wait(&pParentSql->emptyRspSem);
|
|
||||||
|
|
||||||
tsem_post(&pParentSql->rspSem);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSubquerySupporter* pSupporter) {
|
|
||||||
int32_t numOfTotal = pSupporter->pState->numOfTotal;
|
|
||||||
int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1);
|
|
||||||
|
|
||||||
if (finished >= numOfTotal) {
|
|
||||||
pSqlObj->res.code = abs(pSupporter->pState->code);
|
|
||||||
tscError("%p all subquery return and query failed, global code:%d", pSqlObj, pSqlObj->res.code);
|
|
||||||
|
|
||||||
doQuitSubquery(pSqlObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// update the query time range according to the join results on timestamp
|
|
||||||
static void updateQueryTimeRange(SQueryInfo* pQueryInfo, int64_t st, int64_t et) {
|
|
||||||
assert(pQueryInfo->stime <= st && pQueryInfo->etime >= et);
|
|
||||||
|
|
||||||
pQueryInfo->stime = st;
|
|
||||||
pQueryInfo->etime = et;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
|
|
||||||
SJoinSubquerySupporter* pSupporter = (SJoinSubquerySupporter*)param;
|
|
||||||
SSqlObj* pParentSql = pSupporter->pObj;
|
|
||||||
|
|
||||||
SSqlObj* pSql = (SSqlObj*)tres;
|
|
||||||
SSqlCmd* pCmd = &pSql->cmd;
|
|
||||||
SSqlRes* pRes = &pSql->res;
|
|
||||||
|
|
||||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
|
||||||
|
|
||||||
if ((pQueryInfo->type & TSDB_QUERY_TYPE_JOIN_SEC_STAGE) == 0) {
|
|
||||||
if (pSupporter->pState->code != TSDB_CODE_SUCCESS) {
|
|
||||||
tscError("%p abort query due to other subquery failure. code:%d, global code:%d", pSql, numOfRows,
|
|
||||||
pSupporter->pState->code);
|
|
||||||
|
|
||||||
quitAllSubquery(pParentSql, pSupporter);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (numOfRows > 0) { // write the data into disk
|
|
||||||
fwrite(pSql->res.data, pSql->res.numOfRows, 1, pSupporter->f);
|
|
||||||
fclose(pSupporter->f);
|
|
||||||
|
|
||||||
STSBuf* pBuf = tsBufCreateFromFile(pSupporter->path, true);
|
|
||||||
if (pBuf == NULL) {
|
|
||||||
tscError("%p invalid ts comp file from vnode, abort sub query, file size:%d", pSql, numOfRows);
|
|
||||||
|
|
||||||
pSupporter->pState->code = TSDB_CODE_APP_ERROR; // todo set the informative code
|
|
||||||
quitAllSubquery(pParentSql, pSupporter);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pSupporter->pTSBuf == NULL) {
|
|
||||||
tscTrace("%p create tmp file for ts block:%s", pSql, pBuf->path);
|
|
||||||
pSupporter->pTSBuf = pBuf;
|
|
||||||
} else {
|
|
||||||
assert(pQueryInfo->numOfTables == 1); // for subquery, only one metermetaInfo
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
|
||||||
|
|
||||||
tsBufMerge(pSupporter->pTSBuf, pBuf, pMeterMetaInfo->vnodeIndex);
|
|
||||||
tsBufDestory(pBuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
// open new file to save the result
|
|
||||||
getTmpfilePath("ts-join", pSupporter->path);
|
|
||||||
pSupporter->f = fopen(pSupporter->path, "w");
|
|
||||||
pSql->res.row = pSql->res.numOfRows;
|
|
||||||
|
|
||||||
taos_fetch_rows_a(tres, joinRetrieveCallback, param);
|
|
||||||
} else if (numOfRows == 0) { // no data from this vnode anymore
|
|
||||||
SQueryInfo* pParentQueryInfo = tscGetQueryInfoDetail(&pParentSql->cmd, pParentSql->cmd.clauseIndex);
|
|
||||||
|
|
||||||
//todo refactor
|
|
||||||
if (tscNonOrderedProjectionQueryOnSTable(pParentQueryInfo, 0)) {
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
|
||||||
assert(pQueryInfo->numOfTables == 1);
|
|
||||||
|
|
||||||
// for projection query, need to try next vnode
|
|
||||||
int32_t totalVnode = pMeterMetaInfo->pMetricMeta->numOfVnodes;
|
|
||||||
if ((++pMeterMetaInfo->vnodeIndex) < totalVnode) {
|
|
||||||
tscTrace("%p current vnode:%d exhausted, try next:%d. total vnode:%d. current numOfRes:%d", pSql,
|
|
||||||
pMeterMetaInfo->vnodeIndex - 1, pMeterMetaInfo->vnodeIndex, totalVnode, pRes->numOfTotal);
|
|
||||||
|
|
||||||
pSql->cmd.command = TSDB_SQL_SELECT;
|
|
||||||
pSql->fp = tscJoinQueryCallback;
|
|
||||||
tscProcessSql(pSql);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t numOfTotal = pSupporter->pState->numOfTotal;
|
|
||||||
int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1);
|
|
||||||
|
|
||||||
if (finished >= numOfTotal) {
|
|
||||||
assert(finished == numOfTotal);
|
|
||||||
|
|
||||||
if (pSupporter->pState->code != TSDB_CODE_SUCCESS) {
|
|
||||||
tscTrace("%p sub:%p, numOfSub:%d, quit from further procedure due to other queries failure", pParentSql, tres,
|
|
||||||
pSupporter->subqueryIndex);
|
|
||||||
doQuitSubquery(pParentSql);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tscTrace("%p all subqueries retrieve ts complete, do ts block intersect", pParentSql);
|
|
||||||
|
|
||||||
SJoinSubquerySupporter* p1 = pParentSql->pSubs[0]->param;
|
|
||||||
SJoinSubquerySupporter* p2 = pParentSql->pSubs[1]->param;
|
|
||||||
|
|
||||||
TSKEY st, et;
|
|
||||||
|
|
||||||
int64_t num = doTSBlockIntersect(pParentSql, p1, p2, &st, &et);
|
|
||||||
if (num <= 0) { // no result during ts intersect
|
|
||||||
tscTrace("%p free all sub SqlObj and quit", pParentSql);
|
|
||||||
doQuitSubquery(pParentSql);
|
|
||||||
} else {
|
|
||||||
updateQueryTimeRange(pParentQueryInfo, st, et);
|
|
||||||
tscLaunchSecondPhaseSubqueries(pParentSql);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else { // failure of sub query
|
|
||||||
tscError("%p sub query failed, code:%d, index:%d", pSql, numOfRows, pSupporter->subqueryIndex);
|
|
||||||
pSupporter->pState->code = numOfRows;
|
|
||||||
|
|
||||||
quitAllSubquery(pParentSql, pSupporter);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else { // secondary stage retrieve, driven by taos_fetch_row or other functions
|
|
||||||
if (numOfRows < 0) {
|
|
||||||
pSupporter->pState->code = numOfRows;
|
|
||||||
tscError("%p retrieve failed, code:%d, index:%d", pSql, numOfRows, pSupporter->subqueryIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (numOfRows >= 0) {
|
|
||||||
pSql->res.numOfTotal += pSql->res.numOfRows;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) && numOfRows == 0) {
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
|
||||||
assert(pQueryInfo->numOfTables == 1);
|
|
||||||
|
|
||||||
// for projection query, need to try next vnode if current vnode is exhausted
|
|
||||||
if ((++pMeterMetaInfo->vnodeIndex) < pMeterMetaInfo->pMetricMeta->numOfVnodes) {
|
|
||||||
pSupporter->pState->numOfCompleted = 0;
|
|
||||||
pSupporter->pState->numOfTotal = 1;
|
|
||||||
|
|
||||||
pSql->cmd.command = TSDB_SQL_SELECT;
|
|
||||||
pSql->fp = tscJoinQueryCallback;
|
|
||||||
tscProcessSql(pSql);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t numOfTotal = pSupporter->pState->numOfTotal;
|
|
||||||
int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1);
|
|
||||||
|
|
||||||
if (finished >= numOfTotal) {
|
|
||||||
assert(finished == numOfTotal);
|
|
||||||
tscTrace("%p all %d secondary subquery retrieves completed, global code:%d", tres, numOfTotal,
|
|
||||||
pParentSql->res.code);
|
|
||||||
|
|
||||||
if (pSupporter->pState->code != TSDB_CODE_SUCCESS) {
|
|
||||||
pParentSql->res.code = abs(pSupporter->pState->code);
|
|
||||||
freeSubqueryObj(pParentSql);
|
|
||||||
}
|
|
||||||
|
|
||||||
tsem_post(&pParentSql->rspSem);
|
|
||||||
} else {
|
|
||||||
tscTrace("%p sub:%p completed, completed:%d, total:%d", pParentSql, tres, finished, numOfTotal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static SJoinSubquerySupporter* tscUpdateSubqueryStatus(SSqlObj* pSql, int32_t numOfFetch) {
|
|
||||||
int32_t notInvolved = 0;
|
|
||||||
SJoinSubquerySupporter* pSupporter = NULL;
|
|
||||||
SSubqueryState* pState = NULL;
|
|
||||||
|
|
||||||
for(int32_t i = 0; i < pSql->numOfSubs; ++i) {
|
|
||||||
if (pSql->pSubs[i] == NULL) {
|
|
||||||
notInvolved++;
|
|
||||||
} else {
|
|
||||||
pSupporter = (SJoinSubquerySupporter*)pSql->pSubs[i]->param;
|
|
||||||
pState = pSupporter->pState;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pState->numOfTotal = pSql->numOfSubs;
|
|
||||||
pState->numOfCompleted = pSql->numOfSubs - numOfFetch;
|
|
||||||
|
|
||||||
return pSupporter;
|
|
||||||
}
|
|
||||||
|
|
||||||
void tscFetchDatablockFromSubquery(SSqlObj* pSql) {
|
|
||||||
int32_t numOfFetch = 0;
|
|
||||||
assert(pSql->numOfSubs >= 1);
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
|
|
||||||
if (pSql->pSubs[i] == NULL) { // this subquery does not need to involve in secondary query
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSqlRes *pRes = &pSql->pSubs[i]->res;
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->pSubs[i]->cmd, 0);
|
|
||||||
|
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
|
||||||
|
|
||||||
if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0)) {
|
|
||||||
if (pRes->row >= pRes->numOfRows && pMeterMetaInfo->vnodeIndex < pMeterMetaInfo->pMetricMeta->numOfVnodes &&
|
|
||||||
(!tscHasReachLimitation(pQueryInfo, pRes))) {
|
|
||||||
numOfFetch++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (pRes->row >= pRes->numOfRows && (!tscHasReachLimitation(pQueryInfo, pRes))) {
|
|
||||||
numOfFetch++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (numOfFetch <= 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO multi-vnode retrieve for projection query with limitation has bugs, since the global limiation is not handled
|
|
||||||
tscTrace("%p retrieve data from %d subqueries", pSql, numOfFetch);
|
|
||||||
|
|
||||||
SJoinSubquerySupporter* pSupporter = tscUpdateSubqueryStatus(pSql, numOfFetch);
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
|
|
||||||
SSqlObj* pSql1 = pSql->pSubs[i];
|
|
||||||
if (pSql1 == NULL) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSqlRes* pRes1 = &pSql1->res;
|
|
||||||
SSqlCmd* pCmd1 = &pSql1->cmd;
|
|
||||||
|
|
||||||
pSupporter = (SJoinSubquerySupporter*)pSql1->param;
|
|
||||||
|
|
||||||
// wait for all subqueries completed
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd1, 0);
|
|
||||||
assert(pRes1->numOfRows >= 0 && pQueryInfo->numOfTables == 1);
|
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
|
||||||
|
|
||||||
if (pRes1->row >= pRes1->numOfRows) {
|
|
||||||
tscTrace("%p subquery:%p retrieve data from vnode, subquery:%d, vnodeIndex:%d", pSql, pSql1,
|
|
||||||
pSupporter->subqueryIndex, pMeterMetaInfo->vnodeIndex);
|
|
||||||
|
|
||||||
tscResetForNextRetrieve(pRes1);
|
|
||||||
pSql1->fp = joinRetrieveCallback;
|
|
||||||
|
|
||||||
if (pCmd1->command < TSDB_SQL_LOCAL) {
|
|
||||||
pCmd1->command = (pCmd1->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
|
|
||||||
}
|
|
||||||
|
|
||||||
tscProcessSql(pSql1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// wait for all subquery completed
|
|
||||||
tsem_wait(&pSql->rspSem);
|
|
||||||
|
|
||||||
// update the records for each subquery
|
|
||||||
for(int32_t i = 0; i < pSql->numOfSubs; ++i) {
|
|
||||||
if (pSql->pSubs[i] == NULL) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSqlRes* pRes1 = &pSql->pSubs[i]->res;
|
|
||||||
pRes1->numOfTotalInCurrentClause += pRes1->numOfRows;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// all subqueries return, set the result output index
|
|
||||||
void tscSetupOutputColumnIndex(SSqlObj* pSql) {
|
|
||||||
SSqlCmd* pCmd = &pSql->cmd;
|
|
||||||
SSqlRes* pRes = &pSql->res;
|
|
||||||
|
|
||||||
tscTrace("%p all subquery response, retrieve data", pSql);
|
|
||||||
|
|
||||||
if (pRes->pColumnIndex != NULL) {
|
|
||||||
return; // the column transfer support struct has been built
|
|
||||||
}
|
|
||||||
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
|
||||||
pRes->pColumnIndex = calloc(1, sizeof(SColumnIndex) * pQueryInfo->fieldsInfo.numOfOutputCols);
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutputCols; ++i) {
|
|
||||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
|
||||||
|
|
||||||
int32_t tableIndexOfSub = -1;
|
|
||||||
for (int32_t j = 0; j < pQueryInfo->numOfTables; ++j) {
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, j);
|
|
||||||
if (pMeterMetaInfo->pMeterMeta->uid == pExpr->uid) {
|
|
||||||
tableIndexOfSub = j;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(tableIndexOfSub >= 0 && tableIndexOfSub < pQueryInfo->numOfTables);
|
|
||||||
|
|
||||||
SSqlCmd* pSubCmd = &pSql->pSubs[tableIndexOfSub]->cmd;
|
|
||||||
SQueryInfo* pSubQueryInfo = tscGetQueryInfoDetail(pSubCmd, 0);
|
|
||||||
|
|
||||||
for (int32_t k = 0; k < pSubQueryInfo->exprsInfo.numOfExprs; ++k) {
|
|
||||||
SSqlExpr* pSubExpr = tscSqlExprGet(pSubQueryInfo, k);
|
|
||||||
if (pExpr->functionId == pSubExpr->functionId && pExpr->colInfo.colId == pSubExpr->colInfo.colId) {
|
|
||||||
pRes->pColumnIndex[i] = (SColumnIndex){.tableIndex = tableIndexOfSub, .columnIndex = k};
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
|
|
||||||
SSqlObj* pSql = (SSqlObj*)tres;
|
|
||||||
// SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0, 0);
|
|
||||||
|
|
||||||
// int32_t idx = pSql->cmd.vnodeIdx;
|
|
||||||
|
|
||||||
// SVnodeSidList *vnodeInfo = NULL;
|
|
||||||
// if (pMeterMetaInfo->pMetricMeta != NULL) {
|
|
||||||
// vnodeInfo = tscGetVnodeSidList(pMeterMetaInfo->pMetricMeta, idx - 1);
|
|
||||||
// }
|
|
||||||
|
|
||||||
SJoinSubquerySupporter* pSupporter = (SJoinSubquerySupporter*)param;
|
|
||||||
|
|
||||||
// if (atomic_add_fetch_32(pSupporter->numOfComplete, 1) >=
|
|
||||||
// pSupporter->numOfTotal) {
|
|
||||||
// SSqlObj *pParentObj = pSupporter->pObj;
|
|
||||||
//
|
|
||||||
// if ((pSql->cmd.type & TSDB_QUERY_TYPE_JOIN_SEC_STAGE) != 1) {
|
|
||||||
// int32_t num = 0;
|
|
||||||
// tscFetchDatablockFromSubquery(pParentObj);
|
|
||||||
// TSKEY* ts = tscGetQualifiedTSList(pParentObj, &num);
|
|
||||||
//
|
|
||||||
// if (num <= 0) {
|
|
||||||
// // no qualified result
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// tscLaunchSecondPhaseSubqueries(pSql, ts, num);
|
|
||||||
// } else {
|
|
||||||
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
|
||||||
if ((pQueryInfo->type & TSDB_QUERY_TYPE_JOIN_SEC_STAGE) != TSDB_QUERY_TYPE_JOIN_SEC_STAGE) {
|
|
||||||
if (code != TSDB_CODE_SUCCESS) { // direct call joinRetrieveCallback and set the error code
|
|
||||||
joinRetrieveCallback(param, pSql, code);
|
|
||||||
} else { // first stage query, continue to retrieve data
|
|
||||||
pSql->fp = joinRetrieveCallback;
|
|
||||||
pSql->cmd.command = TSDB_SQL_FETCH;
|
|
||||||
tscProcessSql(pSql);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else { // second stage join subquery
|
|
||||||
SSqlObj* pParentSql = pSupporter->pObj;
|
|
||||||
|
|
||||||
if (pSupporter->pState->code != TSDB_CODE_SUCCESS) {
|
|
||||||
tscError("%p abort query due to other subquery failure. code:%d, global code:%d", pSql, code,
|
|
||||||
pSupporter->pState->code);
|
|
||||||
quitAllSubquery(pParentSql, pSupporter);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
|
||||||
tscError("%p sub query failed, code:%d, set global code:%d, index:%d", pSql, code, code,
|
|
||||||
pSupporter->subqueryIndex);
|
|
||||||
pSupporter->pState->code = code; // todo set the informative code
|
|
||||||
|
|
||||||
quitAllSubquery(pParentSql, pSupporter);
|
|
||||||
} else {
|
|
||||||
int32_t numOfTotal = pSupporter->pState->numOfTotal;
|
|
||||||
int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1);
|
|
||||||
|
|
||||||
if (finished >= numOfTotal) {
|
|
||||||
assert(finished == numOfTotal);
|
|
||||||
|
|
||||||
tscSetupOutputColumnIndex(pParentSql);
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* if the query is a continue query (vnodeIndex > 0 for projection query) for next vnode, do the retrieval of
|
|
||||||
* data instead of returning to its invoker
|
|
||||||
*/
|
|
||||||
if (pMeterMetaInfo->vnodeIndex > 0 && tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0)) {
|
|
||||||
assert(pMeterMetaInfo->vnodeIndex < pMeterMetaInfo->pMetricMeta->numOfVnodes);
|
|
||||||
pSupporter->pState->numOfCompleted = 0; // reset the record value
|
|
||||||
|
|
||||||
pSql->fp = joinRetrieveCallback; // continue retrieve data
|
|
||||||
pSql->cmd.command = TSDB_SQL_FETCH;
|
|
||||||
tscProcessSql(pSql);
|
|
||||||
} else { // first retrieve from vnode during the secondary stage sub-query
|
|
||||||
if (pParentSql->fp == NULL) {
|
|
||||||
tsem_wait(&pParentSql->emptyRspSem);
|
|
||||||
tsem_wait(&pParentSql->emptyRspSem);
|
|
||||||
|
|
||||||
tsem_post(&pParentSql->rspSem);
|
|
||||||
} else {
|
|
||||||
// set the command flag must be after the semaphore been correctly set.
|
|
||||||
// pPObj->cmd.command = TSDB_SQL_RETRIEVE_METRIC;
|
|
||||||
// if (pPObj->res.code == TSDB_CODE_SUCCESS) {
|
|
||||||
// (*pPObj->fp)(pPObj->param, pPObj, 0);
|
|
||||||
// } else {
|
|
||||||
// tscQueueAsyncRes(pPObj);
|
|
||||||
// }
|
|
||||||
assert(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "qextbuffer.h"
|
#include "qextbuffer.h"
|
||||||
#include "tscSecondaryMerge.h"
|
#include "tscSecondaryMerge.h"
|
||||||
#include "tschemautil.h"
|
#include "tschemautil.h"
|
||||||
#include "tsocket.h"
|
#include "name.h"
|
||||||
|
|
||||||
static void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, size_t valueLength);
|
static void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, size_t valueLength);
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type
|
||||||
* length((uint64_t) 123456789011) > 12, greater than sizsof(uint64_t)
|
* length((uint64_t) 123456789011) > 12, greater than sizsof(uint64_t)
|
||||||
*/
|
*/
|
||||||
static int32_t tscMaxLengthOfTagsFields(SSqlObj *pSql) {
|
static int32_t tscMaxLengthOfTagsFields(SSqlObj *pSql) {
|
||||||
STableMeta *pMeta = tscGetMeterMetaInfo(&pSql->cmd, 0, 0)->pMeterMeta;
|
STableMeta *pMeta = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0)->pTableMeta;
|
||||||
|
|
||||||
if (pMeta->tableType == TSDB_SUPER_TABLE || pMeta->tableType == TSDB_NORMAL_TABLE ||
|
if (pMeta->tableType == TSDB_SUPER_TABLE || pMeta->tableType == TSDB_NORMAL_TABLE ||
|
||||||
pMeta->tableType == TSDB_STREAM_TABLE) {
|
pMeta->tableType == TSDB_STREAM_TABLE) {
|
||||||
|
@ -85,12 +85,14 @@ static int32_t tscMaxLengthOfTagsFields(SSqlObj *pSql) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char * pTagValue = tsGetTagsValue(pMeta);
|
char * pTagValue = tsGetTagsValue(pMeta);
|
||||||
SSchema *pTagsSchema = tsGetTagSchema(pMeta);
|
SSchema *pTagsSchema = tscGetTableTagSchema(pMeta);
|
||||||
|
|
||||||
int32_t len = getToStringLength(pTagValue, pTagsSchema[0].bytes, pTagsSchema[0].type);
|
int32_t len = getToStringLength(pTagValue, pTagsSchema[0].bytes, pTagsSchema[0].type);
|
||||||
|
|
||||||
pTagValue += pTagsSchema[0].bytes;
|
pTagValue += pTagsSchema[0].bytes;
|
||||||
for (int32_t i = 1; i < pMeta->numOfTags; ++i) {
|
int32_t numOfTags = tscGetNumOfTags(pMeta);
|
||||||
|
|
||||||
|
for (int32_t i = 1; i < numOfTags; ++i) {
|
||||||
int32_t tLen = getToStringLength(pTagValue, pTagsSchema[i].bytes, pTagsSchema[i].type);
|
int32_t tLen = getToStringLength(pTagValue, pTagsSchema[i].bytes, pTagsSchema[i].type);
|
||||||
if (len < tLen) {
|
if (len < tLen) {
|
||||||
len = tLen;
|
len = tLen;
|
||||||
|
@ -108,8 +110,8 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
||||||
// one column for each row
|
// one column for each row
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
STableMeta * pMeta = pMeterMetaInfo->pMeterMeta;
|
STableMeta * pMeta = pTableMetaInfo->pTableMeta;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* tagValueCnt is to denote the number of tags columns for meter, not metric. and is to show the column data.
|
* tagValueCnt is to denote the number of tags columns for meter, not metric. and is to show the column data.
|
||||||
|
@ -117,15 +119,15 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
||||||
* for metric, the value of tagValueCnt must be 0, but the numOfTags is not 0
|
* for metric, the value of tagValueCnt must be 0, but the numOfTags is not 0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int32_t numOfRows = pMeta->numOfColumns;
|
int32_t numOfRows = tscGetNumOfColumns(pMeta);
|
||||||
int32_t totalNumOfRows = numOfRows + pMeta->numOfTags;
|
int32_t totalNumOfRows = numOfRows + tscGetNumOfTags(pMeta);
|
||||||
|
|
||||||
if (UTIL_METER_IS_SUPERTABLE(pMeterMetaInfo)) {
|
if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) {
|
||||||
numOfRows = pMeta->numOfColumns + pMeta->numOfTags;
|
numOfRows = numOfRows + tscGetNumOfTags(pMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
tscInitResObjForLocalQuery(pSql, totalNumOfRows, rowLen);
|
tscInitResObjForLocalQuery(pSql, totalNumOfRows, rowLen);
|
||||||
SSchema *pSchema = tsGetSchema(pMeta);
|
SSchema *pSchema = tscGetTableSchema(pMeta);
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfRows; ++i) {
|
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||||
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, 0);
|
TAOS_FIELD *pField = tscFieldInfoGetField(pQueryInfo, 0);
|
||||||
|
@ -146,13 +148,13 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
|
||||||
*(int32_t *)(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 2) * totalNumOfRows + pField->bytes * i) = bytes;
|
*(int32_t *)(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 2) * totalNumOfRows + pField->bytes * i) = bytes;
|
||||||
|
|
||||||
pField = tscFieldInfoGetField(pQueryInfo, 3);
|
pField = tscFieldInfoGetField(pQueryInfo, 3);
|
||||||
if (i >= pMeta->numOfColumns && pMeta->numOfTags != 0) {
|
if (i >= tscGetNumOfColumns(pMeta) && tscGetNumOfTags(pMeta) != 0) {
|
||||||
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 3) * totalNumOfRows + pField->bytes * i, "tag",
|
strncpy(pRes->data + tscFieldInfoGetOffset(pQueryInfo, 3) * totalNumOfRows + pField->bytes * i, "tag",
|
||||||
strlen("tag") + 1);
|
strlen("tag") + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UTIL_METER_IS_SUPERTABLE(pMeterMetaInfo)) {
|
if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +267,7 @@ static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
|
||||||
static int32_t tscProcessDescribeTable(SSqlObj *pSql) {
|
static int32_t tscProcessDescribeTable(SSqlObj *pSql) {
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
|
||||||
assert(tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0)->pMeterMeta != NULL);
|
assert(tscGetMetaInfo(pQueryInfo, 0)->pTableMeta != NULL);
|
||||||
|
|
||||||
const int32_t NUM_OF_DESCRIBE_TABLE_COLUMNS = 4;
|
const int32_t NUM_OF_DESCRIBE_TABLE_COLUMNS = 4;
|
||||||
const int32_t TYPE_COLUMN_LENGTH = 16;
|
const int32_t TYPE_COLUMN_LENGTH = 16;
|
||||||
|
@ -290,15 +292,15 @@ static int tscBuildMetricTagProjectionResult(SSqlObj *pSql) {
|
||||||
SSqlRes * pRes = &pSql->res;
|
SSqlRes * pRes = &pSql->res;
|
||||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||||
|
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
|
||||||
SSuperTableMeta *pMetricMeta = pMeterMetaInfo->pMetricMeta;
|
SSuperTableMeta *pMetricMeta = pTableMetaInfo->pMetricMeta;
|
||||||
SSchema * pSchema = tsGetTagSchema(pMeterMetaInfo->pMeterMeta);
|
SSchema * pSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta);
|
||||||
|
|
||||||
int32_t vOffset[TSDB_MAX_COLUMNS] = {0};
|
int32_t vOffset[TSDB_MAX_COLUMNS] = {0};
|
||||||
|
|
||||||
for (int32_t f = 1; f < pMeterMetaInfo->numOfTags; ++f) {
|
for (int32_t f = 1; f < pTableMetaInfo->numOfTags; ++f) {
|
||||||
int16_t tagColumnIndex = pMeterMetaInfo->tagColumnIndex[f - 1];
|
int16_t tagColumnIndex = pTableMetaInfo->tagColumnIndex[f - 1];
|
||||||
if (tagColumnIndex == -1) {
|
if (tagColumnIndex == -1) {
|
||||||
vOffset[f] = vOffset[f - 1] + TSDB_TABLE_NAME_LEN;
|
vOffset[f] = vOffset[f - 1] + TSDB_TABLE_NAME_LEN;
|
||||||
} else {
|
} else {
|
||||||
|
@ -343,7 +345,7 @@ static int tscBuildMetricTagSqlFunctionResult(SSqlObj *pSql) {
|
||||||
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||||
|
|
||||||
SSuperTableMeta *pMetricMeta = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0)->pMetricMeta;
|
SSuperTableMeta *pMetricMeta = tscGetMetaInfo(pQueryInfo, 0)->pMetricMeta;
|
||||||
int32_t totalNumOfResults = 1; // count function only produce one result
|
int32_t totalNumOfResults = 1; // count function only produce one result
|
||||||
int32_t rowLen = tscGetResRowLength(pQueryInfo);
|
int32_t rowLen = tscGetResRowLength(pQueryInfo);
|
||||||
|
|
||||||
|
@ -375,8 +377,8 @@ static int tscProcessQueryTags(SSqlObj *pSql) {
|
||||||
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||||
|
|
||||||
STableMeta *pMeterMeta = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0)->pMeterMeta;
|
STableMeta *pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta;
|
||||||
if (pMeterMeta == NULL || pMeterMeta->numOfTags == 0 || pMeterMeta->numOfColumns == 0) {
|
if (pTableMeta == NULL || tscGetNumOfTags(pTableMeta) == 0 || tscGetNumOfColumns(pTableMeta) == 0) {
|
||||||
strcpy(pCmd->payload, "invalid table");
|
strcpy(pCmd->payload, "invalid table");
|
||||||
pSql->res.code = TSDB_CODE_INVALID_TABLE;
|
pSql->res.code = TSDB_CODE_INVALID_TABLE;
|
||||||
return pSql->res.code;
|
return pSql->res.code;
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
|
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
|
#include "tscSubquery.h"
|
||||||
#include "tstoken.h"
|
#include "tstoken.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
|
|
||||||
|
@ -496,15 +497,17 @@ static int32_t rowDataCompar(const void *lhs, const void *rhs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsParseValues(char **str, STableDataBlocks *pDataBlock, STableMeta *pMeterMeta, int maxRows,
|
int tsParseValues(char **str, STableDataBlocks *pDataBlock, STableMeta *pTableMeta, int maxRows,
|
||||||
SParsedDataColInfo *spd, char *error, int32_t *code, char *tmpTokenBuf) {
|
SParsedDataColInfo *spd, char *error, int32_t *code, char *tmpTokenBuf) {
|
||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
SSQLToken sToken;
|
SSQLToken sToken;
|
||||||
|
|
||||||
int16_t numOfRows = 0;
|
int16_t numOfRows = 0;
|
||||||
|
|
||||||
SSchema *pSchema = tsGetSchema(pMeterMeta);
|
SSchema *pSchema = tscGetTableSchema(pTableMeta);
|
||||||
int32_t precision = pMeterMeta->precision;
|
STableComInfo tinfo = tscGetTableInfo(pTableMeta);
|
||||||
|
|
||||||
|
int32_t precision = tinfo.precision;
|
||||||
|
|
||||||
if (spd->hasVal[0] == false) {
|
if (spd->hasVal[0] == false) {
|
||||||
strcpy(error, "primary timestamp column can not be null");
|
strcpy(error, "primary timestamp column can not be null");
|
||||||
|
@ -518,9 +521,9 @@ int tsParseValues(char **str, STableDataBlocks *pDataBlock, STableMeta *pMeterMe
|
||||||
if (sToken.n == 0 || sToken.type != TK_LP) break;
|
if (sToken.n == 0 || sToken.type != TK_LP) break;
|
||||||
|
|
||||||
*str += index;
|
*str += index;
|
||||||
if (numOfRows >= maxRows || pDataBlock->size + pMeterMeta->rowSize >= pDataBlock->nAllocSize) {
|
if (numOfRows >= maxRows || pDataBlock->size + tinfo.rowSize >= pDataBlock->nAllocSize) {
|
||||||
int32_t tSize;
|
int32_t tSize;
|
||||||
int32_t retcode = tscAllocateMemIfNeed(pDataBlock, pMeterMeta->rowSize, &tSize);
|
int32_t retcode = tscAllocateMemIfNeed(pDataBlock, tinfo.rowSize, &tSize);
|
||||||
if (retcode != TSDB_CODE_SUCCESS) { //TODO pass the correct error code to client
|
if (retcode != TSDB_CODE_SUCCESS) { //TODO pass the correct error code to client
|
||||||
strcpy(error, "client out of memory");
|
strcpy(error, "client out of memory");
|
||||||
*code = retcode;
|
*code = retcode;
|
||||||
|
@ -601,10 +604,10 @@ int32_t tscAllocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int3
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tsSetBlockInfo(SShellSubmitBlock *pBlocks, const STableMeta *pMeterMeta, int32_t numOfRows) {
|
static void tsSetBlockInfo(SShellSubmitBlock *pBlocks, const STableMeta *pTableMeta, int32_t numOfRows) {
|
||||||
pBlocks->sid = pMeterMeta->sid;
|
pBlocks->sid = pTableMeta->sid;
|
||||||
pBlocks->uid = pMeterMeta->uid;
|
pBlocks->uid = pTableMeta->uid;
|
||||||
pBlocks->sversion = pMeterMeta->sversion;
|
pBlocks->sversion = pTableMeta->sversion;
|
||||||
pBlocks->numOfRows += numOfRows;
|
pBlocks->numOfRows += numOfRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -654,19 +657,20 @@ void sortRemoveDuplicates(STableDataBlocks *dataBuf) {
|
||||||
static int32_t doParseInsertStatement(SSqlObj *pSql, void *pTableHashList, char **str, SParsedDataColInfo *spd,
|
static int32_t doParseInsertStatement(SSqlObj *pSql, void *pTableHashList, char **str, SParsedDataColInfo *spd,
|
||||||
int32_t *totalNum) {
|
int32_t *totalNum) {
|
||||||
SSqlCmd * pCmd = &pSql->cmd;
|
SSqlCmd * pCmd = &pSql->cmd;
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
STableMeta * pMeterMeta = pMeterMetaInfo->pMeterMeta;
|
STableMeta * pTableMeta = pTableMetaInfo->pTableMeta;
|
||||||
|
STableComInfo tinfo = tscGetTableInfo(pTableMeta);
|
||||||
|
|
||||||
STableDataBlocks *dataBuf = NULL;
|
STableDataBlocks *dataBuf = NULL;
|
||||||
int32_t ret = tscGetDataBlockFromList(pTableHashList, pCmd->pDataBlocks, pMeterMeta->uid, TSDB_DEFAULT_PAYLOAD_SIZE,
|
int32_t ret = tscGetDataBlockFromList(pTableHashList, pCmd->pDataBlocks, pTableMeta->uid, TSDB_DEFAULT_PAYLOAD_SIZE,
|
||||||
sizeof(SShellSubmitBlock), pMeterMeta->rowSize, pMeterMetaInfo->name,
|
sizeof(SShellSubmitBlock), tinfo.rowSize, pTableMetaInfo->name,
|
||||||
pMeterMeta, &dataBuf);
|
pTableMeta, &dataBuf);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t maxNumOfRows;
|
int32_t maxNumOfRows;
|
||||||
ret = tscAllocateMemIfNeed(dataBuf, pMeterMeta->rowSize, &maxNumOfRows);
|
ret = tscAllocateMemIfNeed(dataBuf, tinfo.rowSize, &maxNumOfRows);
|
||||||
if (TSDB_CODE_SUCCESS != ret) {
|
if (TSDB_CODE_SUCCESS != ret) {
|
||||||
return TSDB_CODE_CLI_OUT_OF_MEMORY;
|
return TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -677,7 +681,7 @@ static int32_t doParseInsertStatement(SSqlObj *pSql, void *pTableHashList, char
|
||||||
return TSDB_CODE_CLI_OUT_OF_MEMORY;
|
return TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t numOfRows = tsParseValues(str, dataBuf, pMeterMeta, maxNumOfRows, spd, pCmd->payload, &code, tmpTokenBuf);
|
int32_t numOfRows = tsParseValues(str, dataBuf, pTableMeta, maxNumOfRows, spd, pCmd->payload, &code, tmpTokenBuf);
|
||||||
free(tmpTokenBuf);
|
free(tmpTokenBuf);
|
||||||
if (numOfRows <= 0) {
|
if (numOfRows <= 0) {
|
||||||
return code;
|
return code;
|
||||||
|
@ -692,9 +696,9 @@ static int32_t doParseInsertStatement(SSqlObj *pSql, void *pTableHashList, char
|
||||||
}
|
}
|
||||||
|
|
||||||
SShellSubmitBlock *pBlocks = (SShellSubmitBlock *)(dataBuf->pData);
|
SShellSubmitBlock *pBlocks = (SShellSubmitBlock *)(dataBuf->pData);
|
||||||
tsSetBlockInfo(pBlocks, pMeterMeta, numOfRows);
|
tsSetBlockInfo(pBlocks, pTableMeta, numOfRows);
|
||||||
|
|
||||||
dataBuf->vgid = pMeterMeta->vgid;
|
dataBuf->vgid = pTableMeta->vgid;
|
||||||
dataBuf->numOfTables = 1;
|
dataBuf->numOfTables = 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -756,7 +760,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
||||||
return TSDB_CODE_INVALID_SQL;
|
return TSDB_CODE_INVALID_SQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, TABLE_INDEX);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, TABLE_INDEX);
|
||||||
|
|
||||||
if (sToken.type == TK_USING) { // create table if not exists according to the super table
|
if (sToken.type == TK_USING) { // create table if not exists according to the super table
|
||||||
index = 0;
|
index = 0;
|
||||||
|
@ -767,26 +771,27 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
||||||
memset(pTag, 0, sizeof(STagData));
|
memset(pTag, 0, sizeof(STagData));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the source super table is moved to the secondary position of the pMeterMetaInfo list
|
* the source super table is moved to the secondary position of the pTableMetaInfo list
|
||||||
*/
|
*/
|
||||||
if (pQueryInfo->numOfTables < 2) {
|
if (pQueryInfo->numOfTables < 2) {
|
||||||
tscAddEmptyMeterMetaInfo(pQueryInfo);
|
tscAddEmptyMetaInfo(pQueryInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
SMeterMetaInfo *pSTableMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, STABLE_INDEX);
|
STableMetaInfo *pSTableMeterMetaInfo = tscGetMetaInfo(pQueryInfo, STABLE_INDEX);
|
||||||
setMeterID(pSTableMeterMetaInfo, &sToken, pSql);
|
setMeterID(pSTableMeterMetaInfo, &sToken, pSql);
|
||||||
|
|
||||||
strncpy(pTag->name, pSTableMeterMetaInfo->name, TSDB_TABLE_ID_LEN);
|
strncpy(pTag->name, pSTableMeterMetaInfo->name, TSDB_TABLE_ID_LEN);
|
||||||
code = tscGetMeterMeta(pSql, pSTableMeterMetaInfo);
|
code = tscGetTableMeta(pSql, pSTableMeterMetaInfo);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!UTIL_METER_IS_SUPERTABLE(pSTableMeterMetaInfo)) {
|
if (!UTIL_TABLE_IS_SUPERTABLE(pSTableMeterMetaInfo)) {
|
||||||
return tscInvalidSQLErrMsg(pCmd->payload, "create table only from super table is allowed", sToken.z);
|
return tscInvalidSQLErrMsg(pCmd->payload, "create table only from super table is allowed", sToken.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
SSchema *pTagSchema = tsGetTagSchema(pSTableMeterMetaInfo->pMeterMeta);
|
SSchema *pTagSchema = tscGetTableTagSchema(pSTableMeterMetaInfo->pTableMeta);
|
||||||
|
STableComInfo tinfo = tscGetTableInfo(pSTableMeterMetaInfo->pTableMeta);
|
||||||
|
|
||||||
index = 0;
|
index = 0;
|
||||||
sToken = tStrGetToken(sql, &index, false, 0, NULL);
|
sToken = tStrGetToken(sql, &index, false, 0, NULL);
|
||||||
|
@ -794,7 +799,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
||||||
|
|
||||||
SParsedDataColInfo spd = {0};
|
SParsedDataColInfo spd = {0};
|
||||||
|
|
||||||
uint8_t numOfTags = pSTableMeterMetaInfo->pMeterMeta->numOfTags;
|
uint8_t numOfTags = tscGetNumOfTags(pSTableMeterMetaInfo->pTableMeta);
|
||||||
spd.numOfCols = numOfTags;
|
spd.numOfCols = numOfTags;
|
||||||
|
|
||||||
// if specify some tags column
|
// if specify some tags column
|
||||||
|
@ -881,8 +886,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
||||||
sToken.n -= 2;
|
sToken.n -= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = tsParseOneColumnData(&pTagSchema[colIndex], &sToken, tagVal, pCmd->payload, &sql, false,
|
code = tsParseOneColumnData(&pTagSchema[colIndex], &sToken, tagVal, pCmd->payload, &sql, false, tinfo.precision);
|
||||||
pSTableMeterMetaInfo->pMeterMeta->precision);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -917,13 +921,13 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
||||||
return tscInvalidSQLErrMsg(pCmd->payload, "invalid table name", *sqlstr);
|
return tscInvalidSQLErrMsg(pCmd->payload, "invalid table name", *sqlstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ret = setMeterID(pMeterMetaInfo, &tableToken, pSql);
|
int32_t ret = setMeterID(pTableMetaInfo, &tableToken, pSql);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
createTable = true;
|
createTable = true;
|
||||||
code = tscGetMeterMetaEx(pSql, pMeterMetaInfo, true);
|
code = tscGetMeterMetaEx(pSql, pTableMetaInfo, true);
|
||||||
if (TSDB_CODE_ACTION_IN_PROGRESS == code) {
|
if (TSDB_CODE_ACTION_IN_PROGRESS == code) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -934,7 +938,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
||||||
} else {
|
} else {
|
||||||
sql = sToken.z;
|
sql = sToken.z;
|
||||||
}
|
}
|
||||||
code = tscGetMeterMeta(pSql, pMeterMetaInfo);
|
code = tscGetTableMeta(pSql, pTableMetaInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t len = cend - cstart + 1;
|
int32_t len = cend - cstart + 1;
|
||||||
|
@ -983,15 +987,15 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
|
||||||
int32_t totalNum = 0;
|
int32_t totalNum = 0;
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
SMeterMetaInfo *pMeterMetaInfo = NULL;
|
STableMetaInfo *pTableMetaInfo = NULL;
|
||||||
|
|
||||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||||
assert(pQueryInfo != NULL);
|
assert(pQueryInfo != NULL);
|
||||||
|
|
||||||
if (pQueryInfo->numOfTables == 0) {
|
if (pQueryInfo->numOfTables == 0) {
|
||||||
pMeterMetaInfo = tscAddEmptyMeterMetaInfo(pQueryInfo);
|
pTableMetaInfo = tscAddEmptyMetaInfo(pQueryInfo);
|
||||||
} else {
|
} else {
|
||||||
pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((code = tscAllocPayload(pCmd, TSDB_PAYLOAD_SIZE)) != TSDB_CODE_SUCCESS) {
|
if ((code = tscAllocPayload(pCmd, TSDB_PAYLOAD_SIZE)) != TSDB_CODE_SUCCESS) {
|
||||||
|
@ -1050,7 +1054,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
|
||||||
goto _error_clean;
|
goto _error_clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((code = setMeterID(pMeterMetaInfo, &sToken, pSql)) != TSDB_CODE_SUCCESS) {
|
if ((code = setMeterID(pTableMetaInfo, &sToken, pSql)) != TSDB_CODE_SUCCESS) {
|
||||||
goto _error_clean;
|
goto _error_clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1078,7 +1082,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
|
||||||
goto _error_clean; // TODO: should _clean or _error_clean to async flow ????
|
goto _error_clean; // TODO: should _clean or _error_clean to async flow ????
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UTIL_METER_IS_SUPERTABLE(pMeterMetaInfo)) {
|
if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) {
|
||||||
code = tscInvalidSQLErrMsg(pCmd->payload, "insert data into super table is not supported", NULL);
|
code = tscInvalidSQLErrMsg(pCmd->payload, "insert data into super table is not supported", NULL);
|
||||||
goto _error_clean;
|
goto _error_clean;
|
||||||
}
|
}
|
||||||
|
@ -1092,11 +1096,15 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
|
||||||
goto _error_clean;
|
goto _error_clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sToken.type == TK_VALUES) {
|
int32_t numOfCols = tscGetNumOfTags(pTableMetaInfo->pTableMeta);
|
||||||
SParsedDataColInfo spd = {.numOfCols = pMeterMetaInfo->pMeterMeta->numOfColumns};
|
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||||
SSchema * pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta);
|
|
||||||
|
|
||||||
tscSetAssignedColumnInfo(&spd, pSchema, pMeterMetaInfo->pMeterMeta->numOfColumns);
|
if (sToken.type == TK_VALUES) {
|
||||||
|
SParsedDataColInfo spd = {.numOfCols = numOfCols};
|
||||||
|
|
||||||
|
SSchema *pSchema = tscGetTableSchema(pTableMetaInfo->pTableMeta);
|
||||||
|
|
||||||
|
tscSetAssignedColumnInfo(&spd, pSchema, numOfCols);
|
||||||
|
|
||||||
if (validateDataSource(pCmd, DATA_FROM_SQL_STRING, sToken.z) != TSDB_CODE_SUCCESS) {
|
if (validateDataSource(pCmd, DATA_FROM_SQL_STRING, sToken.z) != TSDB_CODE_SUCCESS) {
|
||||||
goto _error_clean;
|
goto _error_clean;
|
||||||
|
@ -1136,10 +1144,10 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
|
||||||
wordfree(&full_path);
|
wordfree(&full_path);
|
||||||
|
|
||||||
STableDataBlocks *pDataBlock = NULL;
|
STableDataBlocks *pDataBlock = NULL;
|
||||||
STableMeta* pMeterMeta = pMeterMetaInfo->pMeterMeta;
|
STableMeta* pTableMeta = pTableMetaInfo->pTableMeta;
|
||||||
|
|
||||||
int32_t ret = tscCreateDataBlock(PATH_MAX, pMeterMeta->rowSize, sizeof(SShellSubmitBlock), pMeterMetaInfo->name,
|
int32_t ret = tscCreateDataBlock(PATH_MAX, tinfo.rowSize, sizeof(SShellSubmitBlock), pTableMetaInfo->name,
|
||||||
pMeterMeta, &pDataBlock);
|
pTableMeta, &pDataBlock);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
goto _error_clean;
|
goto _error_clean;
|
||||||
}
|
}
|
||||||
|
@ -1148,18 +1156,18 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
|
||||||
strcpy(pDataBlock->filename, fname);
|
strcpy(pDataBlock->filename, fname);
|
||||||
} else if (sToken.type == TK_LP) {
|
} else if (sToken.type == TK_LP) {
|
||||||
/* insert into tablename(col1, col2,..., coln) values(v1, v2,... vn); */
|
/* insert into tablename(col1, col2,..., coln) values(v1, v2,... vn); */
|
||||||
STableMeta *pMeterMeta = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0)->pMeterMeta;
|
STableMeta *pTableMeta = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0)->pTableMeta;
|
||||||
SSchema * pSchema = tsGetSchema(pMeterMeta);
|
SSchema * pSchema = tscGetTableSchema(pTableMeta);
|
||||||
|
|
||||||
if (validateDataSource(pCmd, DATA_FROM_SQL_STRING, sToken.z) != TSDB_CODE_SUCCESS) {
|
if (validateDataSource(pCmd, DATA_FROM_SQL_STRING, sToken.z) != TSDB_CODE_SUCCESS) {
|
||||||
goto _error_clean;
|
goto _error_clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
SParsedDataColInfo spd = {0};
|
SParsedDataColInfo spd = {0};
|
||||||
spd.numOfCols = pMeterMeta->numOfColumns;
|
spd.numOfCols = tinfo.numOfColumns;
|
||||||
|
|
||||||
int16_t offset[TSDB_MAX_COLUMNS] = {0};
|
int16_t offset[TSDB_MAX_COLUMNS] = {0};
|
||||||
for (int32_t t = 1; t < pMeterMeta->numOfColumns; ++t) {
|
for (int32_t t = 1; t < tinfo.numOfColumns; ++t) {
|
||||||
offset[t] = offset[t - 1] + pSchema[t - 1].bytes;
|
offset[t] = offset[t - 1] + pSchema[t - 1].bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1181,7 +1189,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
|
||||||
bool findColumnIndex = false;
|
bool findColumnIndex = false;
|
||||||
|
|
||||||
// todo speedup by using hash list
|
// todo speedup by using hash list
|
||||||
for (int32_t t = 0; t < pMeterMeta->numOfColumns; ++t) {
|
for (int32_t t = 0; t < tinfo.numOfColumns; ++t) {
|
||||||
if (strncmp(sToken.z, pSchema[t].name, sToken.n) == 0 && strlen(pSchema[t].name) == sToken.n) {
|
if (strncmp(sToken.z, pSchema[t].name, sToken.n) == 0 && strlen(pSchema[t].name) == sToken.n) {
|
||||||
SParsedColElem *pElem = &spd.elems[spd.numOfAssignedCols++];
|
SParsedColElem *pElem = &spd.elems[spd.numOfAssignedCols++];
|
||||||
pElem->offset = offset[t];
|
pElem->offset = offset[t];
|
||||||
|
@ -1204,7 +1212,7 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spd.numOfAssignedCols == 0 || spd.numOfAssignedCols > pMeterMeta->numOfColumns) {
|
if (spd.numOfAssignedCols == 0 || spd.numOfAssignedCols > tinfo.numOfColumns) {
|
||||||
code = tscInvalidSQLErrMsg(pCmd->payload, "column name expected", sToken.z);
|
code = tscInvalidSQLErrMsg(pCmd->payload, "column name expected", sToken.z);
|
||||||
goto _error_clean;
|
goto _error_clean;
|
||||||
}
|
}
|
||||||
|
@ -1245,10 +1253,10 @@ int doParseInsertSql(SSqlObj *pSql, char *str) {
|
||||||
goto _error_clean;
|
goto _error_clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0, 0);
|
pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0);
|
||||||
|
|
||||||
// set the next sent data vnode index in data block arraylist
|
// set the next sent data vnode index in data block arraylist
|
||||||
pMeterMetaInfo->vnodeIndex = 1;
|
pTableMetaInfo->vnodeIndex = 1;
|
||||||
} else {
|
} else {
|
||||||
pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
|
pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
|
||||||
}
|
}
|
||||||
|
@ -1317,7 +1325,7 @@ int tsParseSql(SSqlObj *pSql, bool multiVnodeInsertion) {
|
||||||
pSql->fetchFp = pSql->fp;
|
pSql->fetchFp = pSql->fp;
|
||||||
|
|
||||||
// replace user defined callback function with multi-insert proxy function
|
// replace user defined callback function with multi-insert proxy function
|
||||||
pSql->fp = (void(*)())launchMultivnodeInsert;
|
pSql->fp = (void(*)())tscHandleMultivnodeInsert;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = tsParseInsertSql(pSql);
|
ret = tsParseInsertSql(pSql);
|
||||||
|
@ -1333,7 +1341,7 @@ int tsParseSql(SSqlObj *pSql, bool multiVnodeInsertion) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the pRes->code may be modified or even released by another thread in tscMeterMetaCallBack
|
* the pRes->code may be modified or even released by another thread in tscTableMetaCallBack
|
||||||
* function, so do NOT use pRes->code to determine if the getMeterMeta/getMetricMeta function
|
* function, so do NOT use pRes->code to determine if the getMeterMeta/getMetricMeta function
|
||||||
* invokes new threads to get data from mnode or simply retrieves data from cache.
|
* invokes new threads to get data from mnode or simply retrieves data from cache.
|
||||||
*
|
*
|
||||||
|
@ -1348,10 +1356,10 @@ static int doPackSendDataBlock(SSqlObj *pSql, int32_t numOfRows, STableDataBlock
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
|
|
||||||
assert(pCmd->numOfClause == 1);
|
assert(pCmd->numOfClause == 1);
|
||||||
STableMeta *pMeterMeta = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0)->pMeterMeta;
|
STableMeta *pTableMeta = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0)->pTableMeta;
|
||||||
|
|
||||||
SShellSubmitBlock *pBlocks = (SShellSubmitBlock *)(pTableDataBlocks->pData);
|
SShellSubmitBlock *pBlocks = (SShellSubmitBlock *)(pTableDataBlocks->pData);
|
||||||
tsSetBlockInfo(pBlocks, pMeterMeta, numOfRows);
|
tsSetBlockInfo(pBlocks, pTableMeta, numOfRows);
|
||||||
|
|
||||||
if ((code = tscMergeTableDataBlocks(pSql, pCmd->pDataBlocks)) != TSDB_CODE_SUCCESS) {
|
if ((code = tscMergeTableDataBlocks(pSql, pCmd->pDataBlocks)) != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
|
@ -1381,16 +1389,18 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int nrows = 0;
|
int nrows = 0;
|
||||||
|
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
STableMeta * pMeterMeta = pMeterMetaInfo->pMeterMeta;
|
STableMeta * pTableMeta = pTableMetaInfo->pTableMeta;
|
||||||
|
STableComInfo tinfo = tscGetTableInfo(pTableMeta);
|
||||||
|
|
||||||
assert(pCmd->numOfClause == 1);
|
assert(pCmd->numOfClause == 1);
|
||||||
|
|
||||||
int32_t rowSize = pMeterMeta->rowSize;
|
int32_t rowSize = tinfo.rowSize;
|
||||||
|
|
||||||
pCmd->pDataBlocks = tscCreateBlockArrayList();
|
pCmd->pDataBlocks = tscCreateBlockArrayList();
|
||||||
STableDataBlocks *pTableDataBlock = NULL;
|
STableDataBlocks *pTableDataBlock = NULL;
|
||||||
int32_t ret = tscCreateDataBlock(TSDB_PAYLOAD_SIZE, rowSize, sizeof(SShellSubmitBlock),
|
int32_t ret = tscCreateDataBlock(TSDB_PAYLOAD_SIZE, rowSize, sizeof(SShellSubmitBlock),
|
||||||
pMeterMetaInfo->name, pMeterMeta, &pTableDataBlock);
|
pTableMetaInfo->name, pTableMeta, &pTableDataBlock);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1401,10 +1411,10 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) {
|
||||||
if (TSDB_CODE_SUCCESS != code) return -1;
|
if (TSDB_CODE_SUCCESS != code) return -1;
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
SParsedDataColInfo spd = {.numOfCols = pMeterMeta->numOfColumns};
|
SParsedDataColInfo spd = {.numOfCols = tinfo.numOfColumns};
|
||||||
SSchema * pSchema = tsGetSchema(pMeterMeta);
|
SSchema * pSchema = tscGetTableSchema(pTableMeta);
|
||||||
|
|
||||||
tscSetAssignedColumnInfo(&spd, pSchema, pMeterMeta->numOfColumns);
|
tscSetAssignedColumnInfo(&spd, pSchema, tinfo.numOfColumns);
|
||||||
|
|
||||||
while ((readLen = getline(&line, &n, fp)) != -1) {
|
while ((readLen = getline(&line, &n, fp)) != -1) {
|
||||||
// line[--readLen] = '\0';
|
// line[--readLen] = '\0';
|
||||||
|
@ -1414,7 +1424,7 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) {
|
||||||
char *lineptr = line;
|
char *lineptr = line;
|
||||||
strtolower(line, line);
|
strtolower(line, line);
|
||||||
|
|
||||||
len = tsParseOneRowData(&lineptr, pTableDataBlock, pSchema, &spd, pCmd->payload, pMeterMeta->precision, &code, tmpTokenBuf);
|
len = tsParseOneRowData(&lineptr, pTableDataBlock, pSchema, &spd, pCmd->payload, tinfo.precision, &code, tmpTokenBuf);
|
||||||
if (len <= 0 || pTableDataBlock->numOfParams > 0) {
|
if (len <= 0 || pTableDataBlock->numOfParams > 0) {
|
||||||
pSql->res.code = code;
|
pSql->res.code = code;
|
||||||
return (-code);
|
return (-code);
|
||||||
|
@ -1431,7 +1441,7 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) {
|
||||||
|
|
||||||
pTableDataBlock = pCmd->pDataBlocks->pData[0];
|
pTableDataBlock = pCmd->pDataBlocks->pData[0];
|
||||||
pTableDataBlock->size = sizeof(SShellSubmitBlock);
|
pTableDataBlock->size = sizeof(SShellSubmitBlock);
|
||||||
pTableDataBlock->rowSize = pMeterMeta->rowSize;
|
pTableDataBlock->rowSize = tinfo.rowSize;
|
||||||
|
|
||||||
numOfRows += pSql->res.numOfRows;
|
numOfRows += pSql->res.numOfRows;
|
||||||
pSql->res.numOfRows = 0;
|
pSql->res.numOfRows = 0;
|
||||||
|
@ -1473,25 +1483,25 @@ void tscProcessMultiVnodesInsert(SSqlObj *pSql) {
|
||||||
}
|
}
|
||||||
|
|
||||||
STableDataBlocks *pDataBlock = NULL;
|
STableDataBlocks *pDataBlock = NULL;
|
||||||
SMeterMetaInfo * pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo * pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
assert(pCmd->numOfClause == 1);
|
assert(pCmd->numOfClause == 1);
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
/* the first block has been sent to server in processSQL function */
|
/* the first block has been sent to server in processSQL function */
|
||||||
assert(pMeterMetaInfo->vnodeIndex >= 1 && pCmd->pDataBlocks != NULL);
|
assert(pTableMetaInfo->vnodeIndex >= 1 && pCmd->pDataBlocks != NULL);
|
||||||
|
|
||||||
if (pMeterMetaInfo->vnodeIndex < pCmd->pDataBlocks->nSize) {
|
if (pTableMetaInfo->vnodeIndex < pCmd->pDataBlocks->nSize) {
|
||||||
SDataBlockList *pDataBlocks = pCmd->pDataBlocks;
|
SDataBlockList *pDataBlocks = pCmd->pDataBlocks;
|
||||||
|
|
||||||
for (int32_t i = pMeterMetaInfo->vnodeIndex; i < pDataBlocks->nSize; ++i) {
|
for (int32_t i = pTableMetaInfo->vnodeIndex; i < pDataBlocks->nSize; ++i) {
|
||||||
pDataBlock = pDataBlocks->pData[i];
|
pDataBlock = pDataBlocks->pData[i];
|
||||||
if (pDataBlock == NULL) {
|
if (pDataBlock == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((code = tscCopyDataBlockToPayload(pSql, pDataBlock)) != TSDB_CODE_SUCCESS) {
|
if ((code = tscCopyDataBlockToPayload(pSql, pDataBlock)) != TSDB_CODE_SUCCESS) {
|
||||||
tscTrace("%p build submit data block failed, vnodeIdx:%d, total:%d", pSql, pMeterMetaInfo->vnodeIndex,
|
tscTrace("%p build submit data block failed, vnodeIdx:%d, total:%d", pSql, pTableMetaInfo->vnodeIndex,
|
||||||
pDataBlocks->nSize);
|
pDataBlocks->nSize);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1512,7 +1522,7 @@ void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
|
||||||
STableDataBlocks *pDataBlock = NULL;
|
STableDataBlocks *pDataBlock = NULL;
|
||||||
int32_t affected_rows = 0;
|
int32_t affected_rows = 0;
|
||||||
|
@ -1543,10 +1553,10 @@ void tscProcessMultiVnodesInsertFromFile(SSqlObj *pSql) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(pMeterMetaInfo->name, pDataBlock->tableId, TSDB_TABLE_ID_LEN);
|
strncpy(pTableMetaInfo->name, pDataBlock->tableId, TSDB_TABLE_ID_LEN);
|
||||||
memset(pDataBlock->pData, 0, pDataBlock->nAllocSize);
|
memset(pDataBlock->pData, 0, pDataBlock->nAllocSize);
|
||||||
|
|
||||||
int32_t ret = tscGetMeterMeta(pSql, pMeterMetaInfo);
|
int32_t ret = tscGetTableMeta(pSql, pTableMetaInfo);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
tscError("%p get meter meta failed, abort", pSql);
|
tscError("%p get meter meta failed, abort", pSql);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -407,8 +407,8 @@ static int insertStmtReset(STscStmt* pStmt) {
|
||||||
}
|
}
|
||||||
pCmd->batchSize = 0;
|
pCmd->batchSize = 0;
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
pMeterMetaInfo->vnodeIndex = 0;
|
pTableMetaInfo->vnodeIndex = 0;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,7 +421,7 @@ static int insertStmtExecute(STscStmt* stmt) {
|
||||||
++pCmd->batchSize;
|
++pCmd->batchSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
assert(pCmd->numOfClause == 1);
|
assert(pCmd->numOfClause == 1);
|
||||||
|
|
||||||
if (pCmd->pDataBlocks->nSize > 0) {
|
if (pCmd->pDataBlocks->nSize > 0) {
|
||||||
|
@ -438,7 +438,7 @@ static int insertStmtExecute(STscStmt* stmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the next sent data vnode index in data block arraylist
|
// set the next sent data vnode index in data block arraylist
|
||||||
pMeterMetaInfo->vnodeIndex = 1;
|
pTableMetaInfo->vnodeIndex = 1;
|
||||||
} else {
|
} else {
|
||||||
pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
|
pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks);
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -19,6 +19,68 @@
|
||||||
#include "ttokendef.h"
|
#include "ttokendef.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
#include "tsclient.h"
|
||||||
|
|
||||||
|
int32_t tscGetNumOfTags(const STableMeta* pTableMeta) {
|
||||||
|
assert(pTableMeta != NULL);
|
||||||
|
|
||||||
|
STableComInfo tinfo = tscGetTableInfo(pTableMeta);
|
||||||
|
|
||||||
|
if (pTableMeta->tableType == TSDB_NORMAL_TABLE) {
|
||||||
|
assert(tinfo.numOfTags == 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_CHILD_TABLE) {
|
||||||
|
assert(tinfo.numOfTags > 0);
|
||||||
|
return tinfo.numOfTags;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(tinfo.numOfTags == 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tscGetNumOfColumns(const STableMeta* pTableMeta) {
|
||||||
|
assert(pTableMeta != NULL);
|
||||||
|
|
||||||
|
// table created according to super table, use data from super table
|
||||||
|
STableComInfo tinfo = tscGetTableInfo(pTableMeta);
|
||||||
|
return tinfo.numOfColumns;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSchema *tscGetTableSchema(const STableMeta *pTableMeta) {
|
||||||
|
assert(pTableMeta != NULL);
|
||||||
|
|
||||||
|
if (pTableMeta->tableType == TSDB_CHILD_TABLE) {
|
||||||
|
STableMeta* pSTableMeta = pTableMeta->pSTable;
|
||||||
|
assert (pSTableMeta != NULL);
|
||||||
|
|
||||||
|
return pSTableMeta->schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pTableMeta->schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSchema* tscGetTableTagSchema(const STableMeta* pTableMeta) {
|
||||||
|
assert(pTableMeta != NULL && (pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_CHILD_TABLE));
|
||||||
|
|
||||||
|
STableComInfo tinfo = tscGetTableInfo(pTableMeta);
|
||||||
|
assert(tinfo.numOfTags > 0);
|
||||||
|
|
||||||
|
return tscGetTableColumnSchema(pTableMeta, tinfo.numOfColumns);
|
||||||
|
}
|
||||||
|
|
||||||
|
STableComInfo tscGetTableInfo(const STableMeta* pTableMeta) {
|
||||||
|
assert(pTableMeta != NULL);
|
||||||
|
|
||||||
|
if (pTableMeta->tableType == TSDB_CHILD_TABLE) {
|
||||||
|
assert (pTableMeta->pSTable != NULL);
|
||||||
|
return pTableMeta->pSTable->tableInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pTableMeta->tableInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool isValidSchema(struct SSchema* pSchema, int32_t numOfCols) {
|
bool isValidSchema(struct SSchema* pSchema, int32_t numOfCols) {
|
||||||
if (!VALIDNUMOFCOLS(numOfCols)) {
|
if (!VALIDNUMOFCOLS(numOfCols)) {
|
||||||
|
@ -64,34 +126,66 @@ bool isValidSchema(struct SSchema* pSchema, int32_t numOfCols) {
|
||||||
return (rowLen <= TSDB_MAX_BYTES_PER_ROW);
|
return (rowLen <= TSDB_MAX_BYTES_PER_ROW);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SSchema* tsGetSchema(STableMeta* pMeta) {
|
SSchema* tscGetTableColumnSchema(const STableMeta* pTableMeta, int32_t startCol) {
|
||||||
if (pMeta == NULL) {
|
assert(pTableMeta != NULL);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return tsGetColumnSchema(pMeta, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SSchema* tsGetTagSchema(STableMeta* pMeta) {
|
SSchema* pSchema = pTableMeta->schema;
|
||||||
if (pMeta == NULL || pMeta->numOfTags == 0) {
|
|
||||||
return NULL;
|
if (pTableMeta->tableType == TSDB_CHILD_TABLE) {
|
||||||
|
assert (pTableMeta->pSTable != NULL);
|
||||||
|
pSchema = pTableMeta->pSTable->schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tsGetColumnSchema(pMeta, pMeta->numOfColumns);
|
return &pSchema[startCol];
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SSchema* tsGetColumnSchema(STableMeta* pMeta, int32_t startCol) {
|
struct SSchema tscGetTbnameColumnSchema() {
|
||||||
return (SSchema*)(((char*)pMeta + sizeof(STableMeta)) + startCol * sizeof(SSchema));
|
struct SSchema s = {
|
||||||
}
|
.colId = TSDB_TBNAME_COLUMN_INDEX,
|
||||||
|
.type = TSDB_DATA_TYPE_BINARY,
|
||||||
|
.bytes = TSDB_TABLE_NAME_LEN
|
||||||
|
};
|
||||||
|
|
||||||
struct SSchema tsGetTbnameColumnSchema() {
|
|
||||||
struct SSchema s = {.colId = TSDB_TBNAME_COLUMN_INDEX, .type = TSDB_DATA_TYPE_BINARY, .bytes = TSDB_TABLE_NAME_LEN};
|
|
||||||
strcpy(s.name, TSQL_TBNAME_L);
|
strcpy(s.name, TSQL_TBNAME_L);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STableMeta* tscCreateTableMetaFromMsg(STableMetaMsg* pTableMetaMsg, size_t* size) {
|
||||||
|
assert(pTableMetaMsg != NULL);
|
||||||
|
|
||||||
|
int32_t schemaSize = (pTableMetaMsg->numOfColumns + pTableMetaMsg->numOfTags) * sizeof(SSchema);
|
||||||
|
STableMeta* pTableMeta = calloc(1, sizeof(STableMeta) + schemaSize);
|
||||||
|
pTableMeta->tableType = pTableMetaMsg->tableType;
|
||||||
|
|
||||||
|
pTableMeta->tableInfo = (STableComInfo) {
|
||||||
|
.numOfTags = pTableMetaMsg->numOfTags,
|
||||||
|
.numOfColumns = pTableMetaMsg->numOfColumns,
|
||||||
|
.precision = pTableMetaMsg->precision
|
||||||
|
};
|
||||||
|
|
||||||
|
pTableMeta->sid = pTableMetaMsg->sid;
|
||||||
|
pTableMeta->uid = pTableMetaMsg->uid;
|
||||||
|
pTableMeta->vgid = pTableMetaMsg->vgid;
|
||||||
|
|
||||||
|
pTableMeta->numOfVpeers = pTableMetaMsg->numOfVpeers;
|
||||||
|
memcpy(pTableMeta->vpeerDesc, pTableMetaMsg->vpeerDesc, sizeof(SVnodeDesc) * pTableMeta->numOfVpeers);
|
||||||
|
memcpy(pTableMeta->schema, pTableMetaMsg->schema, schemaSize);
|
||||||
|
|
||||||
|
int32_t numOfTotalCols = pTableMeta->tableInfo.numOfColumns + pTableMeta->tableInfo.numOfTags;
|
||||||
|
for(int32_t i = 0; i < numOfTotalCols; ++i) {
|
||||||
|
pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size != NULL) {
|
||||||
|
*size = sizeof(STableMeta) + schemaSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pTableMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the MeterMeta data format in memory is as follows:
|
* the TableMeta data format in memory is as follows:
|
||||||
*
|
*
|
||||||
* +--------------------+
|
* +--------------------+
|
||||||
* |STableMeta Body data| sizeof(STableMeta)
|
* |STableMeta Body data| sizeof(STableMeta)
|
||||||
|
@ -101,33 +195,15 @@ struct SSchema tsGetTbnameColumnSchema() {
|
||||||
* |Tags data | tag_col_1.bytes + tag_col_2.bytes + ....
|
* |Tags data | tag_col_1.bytes + tag_col_2.bytes + ....
|
||||||
* +--------------------+
|
* +--------------------+
|
||||||
*
|
*
|
||||||
* @param pMeta
|
* @param pTableMeta
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
char* tsGetTagsValue(STableMeta* pMeta) {
|
char* tsGetTagsValue(STableMeta* pTableMeta) {
|
||||||
int32_t numOfTotalCols = pMeta->numOfColumns + pMeta->numOfTags;
|
int32_t offset = 0;
|
||||||
uint32_t offset = sizeof(STableMeta) + numOfTotalCols * sizeof(SSchema);
|
// int32_t numOfTotalCols = pTableMeta->numOfColumns + pTableMeta->numOfTags;
|
||||||
|
// uint32_t offset = sizeof(STableMeta) + numOfTotalCols * sizeof(SSchema);
|
||||||
|
|
||||||
return ((char*)pMeta + offset);
|
return ((char*)pTableMeta + offset);
|
||||||
}
|
|
||||||
|
|
||||||
bool tsMeterMetaIdentical(STableMeta* p1, STableMeta* p2) {
|
|
||||||
if (p1 == NULL || p2 == NULL || p1->uid != p2->uid || p1->sversion != p2->sversion) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p1 == p2) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t size = sizeof(STableMeta) + p1->numOfColumns * sizeof(SSchema);
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < p1->numOfTags; ++i) {
|
|
||||||
SSchema* pColSchema = tsGetColumnSchema(p1, i + p1->numOfColumns);
|
|
||||||
size += pColSchema->bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
return memcmp(p1, p2, size) == 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo refactor
|
// todo refactor
|
||||||
|
@ -149,24 +225,6 @@ static FORCE_INLINE size_t copy(char* dst, const char* src, char delimiter) {
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* extract table name from meterid, which the format of userid.dbname.metername
|
|
||||||
* @param tableId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
void extractTableName(char* tableId, char* name) {
|
|
||||||
char* r = skipSegments(tableId, TS_PATH_DELIMITER[0], 2);
|
|
||||||
copy(name, r, TS_PATH_DELIMITER[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
SSQLToken extractDBName(char* tableId, char* name) {
|
|
||||||
char* r = skipSegments(tableId, TS_PATH_DELIMITER[0], 1);
|
|
||||||
size_t len = copy(name, r, TS_PATH_DELIMITER[0]);
|
|
||||||
|
|
||||||
SSQLToken token = {.z = name, .n = len, .type = TK_STRING};
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* tablePrefix.columnName
|
* tablePrefix.columnName
|
||||||
* extract table name and save it in pTable, with only column name in pToken
|
* extract table name and save it in pTable, with only column name in pToken
|
||||||
|
|
|
@ -319,12 +319,13 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
|
||||||
pRes->pLocalReducer = pReducer;
|
pRes->pLocalReducer = pReducer;
|
||||||
pRes->numOfGroups = 0;
|
pRes->numOfGroups = 0;
|
||||||
|
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
int16_t prec = pMeterMetaInfo->pMeterMeta->precision;
|
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||||
|
|
||||||
|
int16_t prec = tinfo.precision;
|
||||||
int64_t stime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->stime : pQueryInfo->etime;
|
int64_t stime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->stime : pQueryInfo->etime;
|
||||||
int64_t revisedSTime =
|
int64_t revisedSTime =
|
||||||
taosGetIntervalStartTimestamp(stime, pQueryInfo->intervalTime, pQueryInfo->intervalTimeUnit, prec);
|
taosGetIntervalStartTimestamp(stime, pQueryInfo->intervalTime, pQueryInfo->slidingTimeUnit, prec);
|
||||||
|
|
||||||
SInterpolationInfo *pInterpoInfo = &pReducer->interpolationInfo;
|
SInterpolationInfo *pInterpoInfo = &pReducer->interpolationInfo;
|
||||||
taosInitInterpoInfo(pInterpoInfo, pQueryInfo->order.order, revisedSTime, pQueryInfo->groupbyExpr.numOfGroupCols,
|
taosInitInterpoInfo(pInterpoInfo, pQueryInfo->order.order, revisedSTime, pQueryInfo->groupbyExpr.numOfGroupCols,
|
||||||
|
@ -602,9 +603,9 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
||||||
*pFinalModel = NULL;
|
*pFinalModel = NULL;
|
||||||
|
|
||||||
SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
|
||||||
(*pMemBuffer) = (tExtMemBuffer **)malloc(POINTER_BYTES * pMeterMetaInfo->pMetricMeta->numOfVnodes);
|
(*pMemBuffer) = (tExtMemBuffer **)malloc(POINTER_BYTES * pTableMetaInfo->pMetricMeta->numOfVnodes);
|
||||||
if (*pMemBuffer == NULL) {
|
if (*pMemBuffer == NULL) {
|
||||||
tscError("%p failed to allocate memory", pSql);
|
tscError("%p failed to allocate memory", pSql);
|
||||||
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||||
|
@ -635,7 +636,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
||||||
|
|
||||||
pModel = createColumnModel(pSchema, pQueryInfo->exprsInfo.numOfExprs, capacity);
|
pModel = createColumnModel(pSchema, pQueryInfo->exprsInfo.numOfExprs, capacity);
|
||||||
|
|
||||||
for (int32_t i = 0; i < pMeterMetaInfo->pMetricMeta->numOfVnodes; ++i) {
|
for (int32_t i = 0; i < pTableMetaInfo->pMetricMeta->numOfVnodes; ++i) {
|
||||||
(*pMemBuffer)[i] = createExtMemBuffer(nBufferSizes, rlen, pModel);
|
(*pMemBuffer)[i] = createExtMemBuffer(nBufferSizes, rlen, pModel);
|
||||||
(*pMemBuffer)[i]->flushModel = MULTIPLE_APPEND_MODEL;
|
(*pMemBuffer)[i]->flushModel = MULTIPLE_APPEND_MODEL;
|
||||||
}
|
}
|
||||||
|
@ -650,7 +651,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
|
||||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||||
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||||
|
|
||||||
SSchema *p1 = tsGetColumnSchema(pMeterMetaInfo->pMeterMeta, pExpr->colInfo.colIdx);
|
SSchema *p1 = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, pExpr->colInfo.colIdx);
|
||||||
|
|
||||||
int16_t inter = 0;
|
int16_t inter = 0;
|
||||||
int16_t type = -1;
|
int16_t type = -1;
|
||||||
|
@ -774,12 +775,14 @@ void adjustLoserTreeFromNewData(SLocalReducer *pLocalReducer, SLocalDataSource *
|
||||||
void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SQueryInfo *pQueryInfo,
|
void savePrevRecordAndSetupInterpoInfo(SLocalReducer *pLocalReducer, SQueryInfo *pQueryInfo,
|
||||||
SInterpolationInfo *pInterpoInfo) {
|
SInterpolationInfo *pInterpoInfo) {
|
||||||
// discard following dataset in the same group and reset the interpolation information
|
// discard following dataset in the same group and reset the interpolation information
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
int16_t prec = pMeterMetaInfo->pMeterMeta->precision;
|
|
||||||
|
|
||||||
|
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||||
|
|
||||||
|
int16_t prec = tinfo.precision;
|
||||||
int64_t stime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->stime : pQueryInfo->etime;
|
int64_t stime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->stime : pQueryInfo->etime;
|
||||||
int64_t revisedSTime =
|
int64_t revisedSTime =
|
||||||
taosGetIntervalStartTimestamp(stime, pQueryInfo->intervalTime, pQueryInfo->intervalTimeUnit, prec);
|
taosGetIntervalStartTimestamp(stime, pQueryInfo->intervalTime, pQueryInfo->slidingTimeUnit, prec);
|
||||||
|
|
||||||
taosInitInterpoInfo(pInterpoInfo, pQueryInfo->order.order, revisedSTime, pQueryInfo->groupbyExpr.numOfGroupCols,
|
taosInitInterpoInfo(pInterpoInfo, pQueryInfo->order.order, revisedSTime, pQueryInfo->groupbyExpr.numOfGroupCols,
|
||||||
pLocalReducer->rowSize);
|
pLocalReducer->rowSize);
|
||||||
|
@ -917,13 +920,15 @@ static void doInterpolateResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, boo
|
||||||
functions[i] = tscSqlExprGet(pQueryInfo, i)->functionId;
|
functions[i] = tscSqlExprGet(pQueryInfo, i)->functionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
int8_t precision = pMeterMetaInfo->pMeterMeta->precision;
|
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||||
|
|
||||||
|
int8_t precision = tinfo.precision;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int32_t remains = taosNumOfRemainPoints(pInterpoInfo);
|
int32_t remains = taosNumOfRemainPoints(pInterpoInfo);
|
||||||
TSKEY etime = taosGetRevisedEndKey(actualETime, pQueryInfo->order.order, pQueryInfo->intervalTime,
|
TSKEY etime = taosGetRevisedEndKey(actualETime, pQueryInfo->order.order, pQueryInfo->intervalTime,
|
||||||
pQueryInfo->intervalTimeUnit, precision);
|
pQueryInfo->slidingTimeUnit, precision);
|
||||||
int32_t nrows = taosGetNumOfResultWithInterpo(pInterpoInfo, pPrimaryKeys, remains, pQueryInfo->intervalTime, etime,
|
int32_t nrows = taosGetNumOfResultWithInterpo(pInterpoInfo, pPrimaryKeys, remains, pQueryInfo->intervalTime, etime,
|
||||||
pLocalReducer->resColModel->capacity);
|
pLocalReducer->resColModel->capacity);
|
||||||
|
|
||||||
|
@ -1268,14 +1273,16 @@ static void resetEnvForNewResultset(SSqlRes *pRes, SSqlCmd *pCmd, SLocalReducer
|
||||||
|
|
||||||
pQueryInfo->limit.offset = pLocalReducer->offset;
|
pQueryInfo->limit.offset = pLocalReducer->offset;
|
||||||
|
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
int16_t precision = pMeterMetaInfo->pMeterMeta->precision;
|
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||||
|
|
||||||
|
int8_t precision = tinfo.precision;
|
||||||
|
|
||||||
// for group result interpolation, do not return if not data is generated
|
// for group result interpolation, do not return if not data is generated
|
||||||
if (pQueryInfo->interpoType != TSDB_INTERPO_NONE) {
|
if (pQueryInfo->interpoType != TSDB_INTERPO_NONE) {
|
||||||
int64_t stime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->stime : pQueryInfo->etime;
|
int64_t stime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->stime : pQueryInfo->etime;
|
||||||
int64_t newTime =
|
int64_t newTime =
|
||||||
taosGetIntervalStartTimestamp(stime, pQueryInfo->intervalTime, pQueryInfo->intervalTimeUnit, precision);
|
taosGetIntervalStartTimestamp(stime, pQueryInfo->intervalTime, pQueryInfo->slidingTimeUnit, precision);
|
||||||
|
|
||||||
taosInitInterpoInfo(&pLocalReducer->interpolationInfo, pQueryInfo->order.order, newTime,
|
taosInitInterpoInfo(&pLocalReducer->interpolationInfo, pQueryInfo->order.order, newTime,
|
||||||
pQueryInfo->groupbyExpr.numOfGroupCols, pLocalReducer->rowSize);
|
pQueryInfo->groupbyExpr.numOfGroupCols, pLocalReducer->rowSize);
|
||||||
|
@ -1294,8 +1301,10 @@ static bool doInterpolationForCurrentGroup(SSqlObj *pSql) {
|
||||||
SLocalReducer * pLocalReducer = pRes->pLocalReducer;
|
SLocalReducer * pLocalReducer = pRes->pLocalReducer;
|
||||||
SInterpolationInfo *pInterpoInfo = &pLocalReducer->interpolationInfo;
|
SInterpolationInfo *pInterpoInfo = &pLocalReducer->interpolationInfo;
|
||||||
|
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
int8_t p = pMeterMetaInfo->pMeterMeta->precision;
|
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||||
|
|
||||||
|
int8_t p = tinfo.precision;
|
||||||
|
|
||||||
if (taosHasRemainsDataForInterpolation(pInterpoInfo)) {
|
if (taosHasRemainsDataForInterpolation(pInterpoInfo)) {
|
||||||
assert(pQueryInfo->interpoType != TSDB_INTERPO_NONE);
|
assert(pQueryInfo->interpoType != TSDB_INTERPO_NONE);
|
||||||
|
@ -1305,7 +1314,7 @@ static bool doInterpolationForCurrentGroup(SSqlObj *pSql) {
|
||||||
|
|
||||||
int32_t remain = taosNumOfRemainPoints(pInterpoInfo);
|
int32_t remain = taosNumOfRemainPoints(pInterpoInfo);
|
||||||
TSKEY ekey =
|
TSKEY ekey =
|
||||||
taosGetRevisedEndKey(etime, pQueryInfo->order.order, pQueryInfo->intervalTime, pQueryInfo->intervalTimeUnit, p);
|
taosGetRevisedEndKey(etime, pQueryInfo->order.order, pQueryInfo->intervalTime, pQueryInfo->slidingTimeUnit, p);
|
||||||
int32_t rows = taosGetNumOfResultWithInterpo(pInterpoInfo, (TSKEY *)pLocalReducer->pBufForInterpo, remain,
|
int32_t rows = taosGetNumOfResultWithInterpo(pInterpoInfo, (TSKEY *)pLocalReducer->pBufForInterpo, remain,
|
||||||
pQueryInfo->intervalTime, ekey, pLocalReducer->resColModel->capacity);
|
pQueryInfo->intervalTime, ekey, pLocalReducer->resColModel->capacity);
|
||||||
if (rows > 0) { // do interpo
|
if (rows > 0) { // do interpo
|
||||||
|
@ -1328,8 +1337,10 @@ static bool doHandleLastRemainData(SSqlObj *pSql) {
|
||||||
bool prevGroupCompleted = (!pLocalReducer->discard) && pLocalReducer->hasUnprocessedRow;
|
bool prevGroupCompleted = (!pLocalReducer->discard) && pLocalReducer->hasUnprocessedRow;
|
||||||
|
|
||||||
SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
SQueryInfo * pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
int8_t precision = pMeterMetaInfo->pMeterMeta->precision;
|
|
||||||
|
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||||
|
int8_t precision = tinfo.precision;
|
||||||
|
|
||||||
if ((isAllSourcesCompleted(pLocalReducer) && !pLocalReducer->hasPrevRow) || pLocalReducer->pLocalDataSrc[0] == NULL ||
|
if ((isAllSourcesCompleted(pLocalReducer) && !pLocalReducer->hasPrevRow) || pLocalReducer->pLocalDataSrc[0] == NULL ||
|
||||||
prevGroupCompleted) {
|
prevGroupCompleted) {
|
||||||
|
@ -1338,7 +1349,7 @@ static bool doHandleLastRemainData(SSqlObj *pSql) {
|
||||||
int64_t etime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->etime : pQueryInfo->stime;
|
int64_t etime = (pQueryInfo->stime < pQueryInfo->etime) ? pQueryInfo->etime : pQueryInfo->stime;
|
||||||
|
|
||||||
etime = taosGetRevisedEndKey(etime, pQueryInfo->order.order, pQueryInfo->intervalTime,
|
etime = taosGetRevisedEndKey(etime, pQueryInfo->order.order, pQueryInfo->intervalTime,
|
||||||
pQueryInfo->intervalTimeUnit, precision);
|
pQueryInfo->slidingTimeUnit, precision);
|
||||||
int32_t rows = taosGetNumOfResultWithInterpo(pInterpoInfo, NULL, 0, pQueryInfo->intervalTime, etime,
|
int32_t rows = taosGetNumOfResultWithInterpo(pInterpoInfo, NULL, 0, pQueryInfo->intervalTime, etime,
|
||||||
pLocalReducer->resColModel->capacity);
|
pLocalReducer->resColModel->capacity);
|
||||||
if (rows > 0) { // do interpo
|
if (rows > 0) { // do interpo
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -15,49 +15,55 @@
|
||||||
|
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#include "qast.h"
|
||||||
#include "tcache.h"
|
#include "tcache.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "tnote.h"
|
#include "tnote.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
#include "tscJoinProcess.h"
|
|
||||||
#include "tscProfile.h"
|
#include "tscProfile.h"
|
||||||
#include "tscSecondaryMerge.h"
|
#include "tscSecondaryMerge.h"
|
||||||
|
#include "tscSubquery.h"
|
||||||
#include "tscUtil.h"
|
#include "tscUtil.h"
|
||||||
#include "tsclient.h"
|
#include "tsclient.h"
|
||||||
#include "tscompression.h"
|
#include "tscompression.h"
|
||||||
#include "tsocket.h"
|
#include "tsocket.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
#include "tutil.h"
|
|
||||||
#include "ttokendef.h"
|
#include "ttokendef.h"
|
||||||
#include "qast.h"
|
#include "tutil.h"
|
||||||
|
|
||||||
TAOS *taos_connect_imp(const char *ip, const char *user, const char *pass, const char *db, uint16_t port,
|
static bool validImpl(const char* str, size_t maxsize) {
|
||||||
|
if (str == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t len = strlen(str);
|
||||||
|
if (len <= 0 || len > maxsize) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool validUserName(const char* user) {
|
||||||
|
return validImpl(user, TSDB_USER_LEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool validPassword(const char* passwd) {
|
||||||
|
return validImpl(passwd, TSDB_PASSWORD_LEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
STscObj *taosConnectImpl(const char *ip, const char *user, const char *pass, const char *db, uint16_t port,
|
||||||
void (*fp)(void *, TAOS_RES *, int), void *param, void **taos) {
|
void (*fp)(void *, TAOS_RES *, int), void *param, void **taos) {
|
||||||
STscObj *pObj;
|
|
||||||
|
|
||||||
|
|
||||||
taos_init();
|
taos_init();
|
||||||
|
|
||||||
if (user == NULL) {
|
if (!validUserName(user)) {
|
||||||
globalCode = TSDB_CODE_INVALID_ACCT;
|
globalCode = TSDB_CODE_INVALID_ACCT;
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
|
||||||
size_t len = strlen(user);
|
|
||||||
if (len <= 0 || len > TSDB_USER_LEN) {
|
|
||||||
globalCode = TSDB_CODE_INVALID_ACCT;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pass == NULL) {
|
if (!validPassword(pass)) {
|
||||||
globalCode = TSDB_CODE_INVALID_PASS;
|
globalCode = TSDB_CODE_INVALID_PASS;
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
|
||||||
size_t len = strlen(pass);
|
|
||||||
if (len <= 0 || len > TSDB_KEY_LEN) {
|
|
||||||
globalCode = TSDB_CODE_INVALID_PASS;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tscInitRpc(user, pass) != 0) {
|
if (tscInitRpc(user, pass) != 0) {
|
||||||
|
@ -84,13 +90,12 @@ TAOS *taos_connect_imp(const char *ip, const char *user, const char *pass, const
|
||||||
|
|
||||||
tscMgmtIpList.port = port ? port : tsMnodeShellPort;
|
tscMgmtIpList.port = port ? port : tsMnodeShellPort;
|
||||||
|
|
||||||
pObj = (STscObj *)malloc(sizeof(STscObj));
|
STscObj *pObj = (STscObj *)calloc(1, sizeof(STscObj));
|
||||||
if (NULL == pObj) {
|
if (NULL == pObj) {
|
||||||
globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(pObj, 0, sizeof(STscObj));
|
|
||||||
pObj->signature = pObj;
|
pObj->signature = pObj;
|
||||||
|
|
||||||
strncpy(pObj->user, user, TSDB_USER_LEN);
|
strncpy(pObj->user, user, TSDB_USER_LEN);
|
||||||
|
@ -115,18 +120,17 @@ TAOS *taos_connect_imp(const char *ip, const char *user, const char *pass, const
|
||||||
|
|
||||||
pthread_mutex_init(&pObj->mutex, NULL);
|
pthread_mutex_init(&pObj->mutex, NULL);
|
||||||
|
|
||||||
SSqlObj *pSql = (SSqlObj *)malloc(sizeof(SSqlObj));
|
SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj));
|
||||||
if (NULL == pSql) {
|
if (NULL == pSql) {
|
||||||
globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
globalCode = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||||
free(pObj);
|
free(pObj);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(pSql, 0, sizeof(SSqlObj));
|
|
||||||
pSql->pTscObj = pObj;
|
pSql->pTscObj = pObj;
|
||||||
pSql->signature = pSql;
|
pSql->signature = pSql;
|
||||||
tsem_init(&pSql->rspSem, 0, 0);
|
tsem_init(&pSql->rspSem, 0, 0);
|
||||||
tsem_init(&pSql->emptyRspSem, 0, 1);
|
// tsem_init(&pSql->emptyRspSem, 0, 1);
|
||||||
pObj->pSql = pSql;
|
pObj->pSql = pSql;
|
||||||
pSql->fp = fp;
|
pSql->fp = fp;
|
||||||
pSql->param = param;
|
pSql->param = param;
|
||||||
|
@ -142,46 +146,69 @@ TAOS *taos_connect_imp(const char *ip, const char *user, const char *pass, const
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pSql->res.code = tscProcessSql(pSql);
|
|
||||||
if (fp != NULL) {
|
|
||||||
tscTrace("%p DB async connection is opening", pObj);
|
|
||||||
return pObj;
|
return pObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSql->res.code) {
|
static void syncConnCallback(void *param, TAOS_RES *tres, int code) {
|
||||||
taos_close(pObj);
|
STscObj *pObj = (STscObj *)param;
|
||||||
return NULL;
|
assert(pObj != NULL && pObj->pSql != NULL);
|
||||||
}
|
|
||||||
|
|
||||||
tscTrace("%p DB connection is opened", pObj);
|
sem_post(&pObj->pSql->rspSem);
|
||||||
return pObj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) {
|
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) {
|
||||||
if (ip == NULL || (ip != NULL && (strcmp("127.0.0.1", ip) == 0 || strcasecmp("localhost", ip) == 0))) {
|
if (ip == NULL || (ip != NULL && (strcmp("127.0.0.1", ip) == 0 || strcasecmp("localhost", ip) == 0))) {
|
||||||
ip = tsMasterIp;
|
ip = tsMasterIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
tscTrace("try to create a connection to %s", ip);
|
tscTrace("try to create a connection to %s", ip);
|
||||||
|
|
||||||
void *taos = taos_connect_imp(ip, user, pass, db, port, NULL, NULL, NULL);
|
STscObj *pObj = taosConnectImpl(ip, user, pass, db, port, NULL, NULL, NULL);
|
||||||
if (taos != NULL) {
|
if (pObj != NULL) {
|
||||||
STscObj *pObj = (STscObj *)taos;
|
SSqlObj* pSql = pObj->pSql;
|
||||||
|
assert(pSql != NULL);
|
||||||
|
|
||||||
// version compare only requires the first 3 segments of the version string
|
pSql->fp = syncConnCallback;
|
||||||
int code = taosCheckVersion(version, taos_get_server_info(taos), 3);
|
pSql->param = pObj;
|
||||||
if (code != 0) {
|
|
||||||
pObj->pSql->res.code = code;
|
tscProcessSql(pSql);
|
||||||
taos_close(taos);
|
sem_wait(&pSql->rspSem);
|
||||||
|
|
||||||
|
if (pSql->res.code != TSDB_CODE_SUCCESS) {
|
||||||
|
taos_close(pObj);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tscTrace("%p DB connection is opening", pObj);
|
||||||
|
|
||||||
|
// version compare only requires the first 3 segments of the version string
|
||||||
|
int code = taosCheckVersion(version, taos_get_server_info(pObj), 3);
|
||||||
|
if (code != 0) {
|
||||||
|
pSql->res.code = code;
|
||||||
|
|
||||||
|
taos_close(pObj);
|
||||||
|
return NULL;
|
||||||
|
} else {
|
||||||
|
return pObj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return taos;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int),
|
TAOS *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int),
|
||||||
void *param, void **taos) {
|
void *param, void **taos) {
|
||||||
return taos_connect_imp(ip, user, pass, db, port, fp, param, taos);
|
STscObj* pObj = taosConnectImpl(ip, user, pass, db, port, fp, param, taos);
|
||||||
|
if (pObj == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSqlObj* pSql = pObj->pSql;
|
||||||
|
|
||||||
|
pSql->res.code = tscProcessSql(pSql);
|
||||||
|
tscTrace("%p DB async connection is opening", pObj);
|
||||||
|
|
||||||
|
return pObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
void taos_close(TAOS *taos) {
|
void taos_close(TAOS *taos) {
|
||||||
|
@ -408,14 +435,14 @@ static char *getArithemicInputSrc(void *param, char *name, int32_t colId) {
|
||||||
SSqlFunctionExpr * pExpr = pSupport->pExpr;
|
SSqlFunctionExpr * pExpr = pSupport->pExpr;
|
||||||
|
|
||||||
int32_t index = -1;
|
int32_t index = -1;
|
||||||
for (int32_t i = 0; i < pExpr->pBinExprInfo.numOfCols; ++i) {
|
for (int32_t i = 0; i < pExpr->binExprInfo.numOfCols; ++i) {
|
||||||
if (strcmp(name, pExpr->pBinExprInfo.pReqColumns[i].name) == 0) {
|
if (strcmp(name, pExpr->binExprInfo.pReqColumns[i].name) == 0) {
|
||||||
index = i;
|
index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(index >= 0 && index < pExpr->pBinExprInfo.numOfCols);
|
assert(index >= 0 && index < pExpr->binExprInfo.numOfCols);
|
||||||
return pSupport->data[index] + pSupport->offset * pSupport->elemSize[index];
|
return pSupport->data[index] + pSupport->offset * pSupport->elemSize[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,21 +492,21 @@ static void **doSetResultRowData(SSqlObj *pSql) {
|
||||||
sas->offset = 0;
|
sas->offset = 0;
|
||||||
sas->pExpr = pQueryInfo->fieldsInfo.pExpr[i];
|
sas->pExpr = pQueryInfo->fieldsInfo.pExpr[i];
|
||||||
|
|
||||||
sas->numOfCols = sas->pExpr->pBinExprInfo.numOfCols;
|
sas->numOfCols = sas->pExpr->binExprInfo.numOfCols;
|
||||||
|
|
||||||
if (pRes->buffer[i] == NULL) {
|
if (pRes->buffer[i] == NULL) {
|
||||||
pRes->buffer[i] = malloc(tscFieldInfoGetField(pQueryInfo, i)->bytes);
|
pRes->buffer[i] = malloc(tscFieldInfoGetField(pQueryInfo, i)->bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int32_t k = 0; k < sas->numOfCols; ++k) {
|
for(int32_t k = 0; k < sas->numOfCols; ++k) {
|
||||||
int32_t columnIndex = sas->pExpr->pBinExprInfo.pReqColumns[k].colIdxInBuf;
|
int32_t columnIndex = sas->pExpr->binExprInfo.pReqColumns[k].colIdxInBuf;
|
||||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, columnIndex);
|
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, columnIndex);
|
||||||
|
|
||||||
sas->elemSize[k] = pExpr->resBytes;
|
sas->elemSize[k] = pExpr->resBytes;
|
||||||
sas->data[k] = (pRes->data + pRes->numOfRows* pExpr->offset) + pRes->row*pExpr->resBytes;
|
sas->data[k] = (pRes->data + pRes->numOfRows* pExpr->offset) + pRes->row*pExpr->resBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
tSQLBinaryExprCalcTraverse(sas->pExpr->pBinExprInfo.pBinExpr, 1, pRes->buffer[i], sas, TSQL_SO_ASC, getArithemicInputSrc);
|
tSQLBinaryExprCalcTraverse(sas->pExpr->binExprInfo.pBinExpr, 1, pRes->buffer[i], sas, TSQL_SO_ASC, getArithemicInputSrc);
|
||||||
pRes->tsrow[i] = pRes->buffer[i];
|
pRes->tsrow[i] = pRes->buffer[i];
|
||||||
|
|
||||||
free(sas); //todo optimization
|
free(sas); //todo optimization
|
||||||
|
@ -509,7 +536,7 @@ static bool tscHashRemainDataInSubqueryResultSet(SSqlObj *pSql) {
|
||||||
SSqlCmd *pCmd1 = &pSql->pSubs[i]->cmd;
|
SSqlCmd *pCmd1 = &pSql->pSubs[i]->cmd;
|
||||||
|
|
||||||
SQueryInfo * pQueryInfo1 = tscGetQueryInfoDetail(pCmd1, pCmd1->clauseIndex);
|
SQueryInfo * pQueryInfo1 = tscGetQueryInfoDetail(pCmd1, pCmd1->clauseIndex);
|
||||||
SMeterMetaInfo *pMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo1, 0);
|
STableMetaInfo *pMetaInfo = tscGetMetaInfo(pQueryInfo1, 0);
|
||||||
|
|
||||||
assert(pQueryInfo1->numOfTables == 1);
|
assert(pQueryInfo1->numOfTables == 1);
|
||||||
|
|
||||||
|
@ -810,7 +837,7 @@ void taos_free_result_imp(TAOS_RES *res, int keepCmd) {
|
||||||
|
|
||||||
pQueryInfo->type = TSDB_QUERY_TYPE_FREE_RESOURCE;
|
pQueryInfo->type = TSDB_QUERY_TYPE_FREE_RESOURCE;
|
||||||
|
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* case 1. Partial data have been retrieved from vnodes, but not all data has been retrieved yet.
|
* case 1. Partial data have been retrieved from vnodes, but not all data has been retrieved yet.
|
||||||
|
@ -825,7 +852,7 @@ void taos_free_result_imp(TAOS_RES *res, int keepCmd) {
|
||||||
if (pRes->code != TSDB_CODE_QUERY_CANCELLED &&
|
if (pRes->code != TSDB_CODE_QUERY_CANCELLED &&
|
||||||
((pRes->numOfRows > 0 && pCmd->command < TSDB_SQL_LOCAL) ||
|
((pRes->numOfRows > 0 && pCmd->command < TSDB_SQL_LOCAL) ||
|
||||||
(pRes->code == TSDB_CODE_SUCCESS && pRes->numOfRows == 0 && pCmd->command == TSDB_SQL_SELECT &&
|
(pRes->code == TSDB_CODE_SUCCESS && pRes->numOfRows == 0 && pCmd->command == TSDB_SQL_SELECT &&
|
||||||
pSql->pStream == NULL && pMeterMetaInfo->pMeterMeta != NULL))) {
|
pSql->pStream == NULL && pTableMetaInfo->pTableMeta != NULL))) {
|
||||||
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
|
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
|
||||||
|
|
||||||
tscTrace("%p code:%d, numOfRows:%d, command:%d", pSql, pRes->code, pRes->numOfRows, pCmd->command);
|
tscTrace("%p code:%d, numOfRows:%d, command:%d", pSql, pRes->code, pRes->numOfRows, pCmd->command);
|
||||||
|
@ -967,7 +994,7 @@ void taos_stop_query(TAOS_RES *res) {
|
||||||
pSql->res.code = TSDB_CODE_QUERY_CANCELLED;
|
pSql->res.code = TSDB_CODE_QUERY_CANCELLED;
|
||||||
|
|
||||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||||
if (tscIsTwoStageMergeMetricQuery(pQueryInfo, 0)) {
|
if (tscIsTwoStageSTableQuery(pQueryInfo, 0)) {
|
||||||
tscKillMetricQuery(pSql);
|
tscKillMetricQuery(pSql);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1109,7 +1136,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
|
||||||
SQueryInfo *pQueryInfo = NULL;
|
SQueryInfo *pQueryInfo = NULL;
|
||||||
tscGetQueryInfoDetailSafely(pCmd, pCmd->clauseIndex, &pQueryInfo);
|
tscGetQueryInfoDetailSafely(pCmd, pCmd->clauseIndex, &pQueryInfo);
|
||||||
|
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscAddEmptyMeterMetaInfo(pQueryInfo);
|
STableMetaInfo *pTableMetaInfo = tscAddEmptyMetaInfo(pQueryInfo);
|
||||||
|
|
||||||
if ((code = tscAllocPayload(pCmd, tblListLen + 16)) != TSDB_CODE_SUCCESS) {
|
if ((code = tscAllocPayload(pCmd, tblListLen + 16)) != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
|
@ -1144,7 +1171,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((code = setMeterID(pMeterMetaInfo, &sToken, pSql)) != TSDB_CODE_SUCCESS) {
|
if ((code = setMeterID(pTableMetaInfo, &sToken, pSql)) != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1154,7 +1181,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (payloadLen + strlen(pMeterMetaInfo->name) + 128 >= pCmd->allocSize) {
|
if (payloadLen + strlen(pTableMetaInfo->name) + 128 >= pCmd->allocSize) {
|
||||||
char *pNewMem = realloc(pCmd->payload, pCmd->allocSize + tblListLen);
|
char *pNewMem = realloc(pCmd->payload, pCmd->allocSize + tblListLen);
|
||||||
if (pNewMem == NULL) {
|
if (pNewMem == NULL) {
|
||||||
code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||||
|
@ -1167,7 +1194,7 @@ static int tscParseTblNameList(SSqlObj *pSql, const char *tblNameList, int32_t t
|
||||||
pMsg = pCmd->payload;
|
pMsg = pCmd->payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadLen += sprintf(pMsg + payloadLen, "%s,", pMeterMetaInfo->name);
|
payloadLen += sprintf(pMsg + payloadLen, "%s,", pTableMetaInfo->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
*(pMsg + payloadLen) = '\0';
|
*(pMsg + payloadLen) = '\0';
|
||||||
|
|
|
@ -13,15 +13,16 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <tschemautil.h>
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#include "taosmsg.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
|
#include "tscUtil.h"
|
||||||
|
#include "tsched.h"
|
||||||
|
#include "tsclient.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
#include "tsched.h"
|
|
||||||
#include "taosmsg.h"
|
|
||||||
#include "tscUtil.h"
|
|
||||||
#include "tsclient.h"
|
|
||||||
|
|
||||||
#include "tscProfile.h"
|
#include "tscProfile.h"
|
||||||
|
|
||||||
|
@ -71,14 +72,14 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) {
|
||||||
pSql->param = pStream;
|
pSql->param = pStream;
|
||||||
|
|
||||||
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
|
||||||
int code = tscGetMeterMeta(pSql, pMeterMetaInfo);
|
int code = tscGetTableMeta(pSql, pTableMetaInfo);
|
||||||
pSql->res.code = code;
|
pSql->res.code = code;
|
||||||
|
|
||||||
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
|
if (code == TSDB_CODE_ACTION_IN_PROGRESS) return;
|
||||||
|
|
||||||
if (code == 0 && UTIL_METER_IS_SUPERTABLE(pMeterMetaInfo)) {
|
if (code == 0 && UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) {
|
||||||
code = tscGetMetricMeta(pSql, 0);
|
code = tscGetMetricMeta(pSql, 0);
|
||||||
pSql->res.code = code;
|
pSql->res.code = code;
|
||||||
|
|
||||||
|
@ -96,7 +97,7 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tscTrace("%p stream:%p start stream query on:%s", pSql, pStream, pMeterMetaInfo->name);
|
tscTrace("%p stream:%p start stream query on:%s", pSql, pStream, pTableMetaInfo->name);
|
||||||
tscProcessSql(pStream->pSql);
|
tscProcessSql(pStream->pSql);
|
||||||
|
|
||||||
tscIncStreamExecutionCount(pStream);
|
tscIncStreamExecutionCount(pStream);
|
||||||
|
@ -145,8 +146,8 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
|
||||||
tscError("%p stream:%p, query data failed, code:%d, retry in %" PRId64 "ms", pStream->pSql, pStream, numOfRows,
|
tscError("%p stream:%p, query data failed, code:%d, retry in %" PRId64 "ms", pStream->pSql, pStream, numOfRows,
|
||||||
retryDelay);
|
retryDelay);
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pStream->pSql->cmd, 0, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pStream->pSql->cmd, 0, 0);
|
||||||
tscClearMeterMetaInfo(pMeterMetaInfo, true);
|
tscClearMeterMetaInfo(pTableMetaInfo, true);
|
||||||
|
|
||||||
tscSetRetryTimer(pStream, pStream->pSql, retryDelay);
|
tscSetRetryTimer(pStream, pStream->pSql, retryDelay);
|
||||||
return;
|
return;
|
||||||
|
@ -171,12 +172,12 @@ static void tscSetTimestampForRes(SSqlStream *pStream, SSqlObj *pSql) {
|
||||||
static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOfRows) {
|
static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOfRows) {
|
||||||
SSqlStream * pStream = (SSqlStream *)param;
|
SSqlStream * pStream = (SSqlStream *)param;
|
||||||
SSqlObj * pSql = (SSqlObj *)res;
|
SSqlObj * pSql = (SSqlObj *)res;
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, 0, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0);
|
||||||
|
|
||||||
if (pSql == NULL || numOfRows < 0) {
|
if (pSql == NULL || numOfRows < 0) {
|
||||||
int64_t retryDelayTime = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision);
|
int64_t retryDelayTime = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision);
|
||||||
tscError("%p stream:%p, retrieve data failed, code:%d, retry in %" PRId64 "ms", pSql, pStream, numOfRows, retryDelayTime);
|
tscError("%p stream:%p, retrieve data failed, code:%d, retry in %" PRId64 "ms", pSql, pStream, numOfRows, retryDelayTime);
|
||||||
tscClearMeterMetaInfo(pMeterMetaInfo, true);
|
tscClearMeterMetaInfo(pTableMetaInfo, true);
|
||||||
|
|
||||||
tscSetRetryTimer(pStream, pStream->pSql, retryDelayTime);
|
tscSetRetryTimer(pStream, pStream->pSql, retryDelayTime);
|
||||||
return;
|
return;
|
||||||
|
@ -254,11 +255,11 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tscTrace("%p stream:%p, query on:%s, fetch result completed, fetched rows:%d", pSql, pStream, pMeterMetaInfo->name,
|
tscTrace("%p stream:%p, query on:%s, fetch result completed, fetched rows:%d", pSql, pStream, pTableMetaInfo->name,
|
||||||
pStream->numOfRes);
|
pStream->numOfRes);
|
||||||
|
|
||||||
// release the metric/meter meta information reference, so data in cache can be updated
|
// release the metric/meter meta information reference, so data in cache can be updated
|
||||||
tscClearMeterMetaInfo(pMeterMetaInfo, false);
|
tscClearMeterMetaInfo(pTableMetaInfo, false);
|
||||||
tscSetNextLaunchTimer(pStream, pSql);
|
tscSetNextLaunchTimer(pStream, pSql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -539,13 +540,14 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
|
||||||
}
|
}
|
||||||
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, 0);
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||||
|
|
||||||
pStream->fp = fp;
|
pStream->fp = fp;
|
||||||
pStream->callback = callback;
|
pStream->callback = callback;
|
||||||
pStream->param = param;
|
pStream->param = param;
|
||||||
pStream->pSql = pSql;
|
pStream->pSql = pSql;
|
||||||
pStream->precision = pMeterMetaInfo->pMeterMeta->precision;
|
pStream->precision = tinfo.precision;
|
||||||
|
|
||||||
pStream->ctime = taosGetTimestamp(pStream->precision);
|
pStream->ctime = taosGetTimestamp(pStream->precision);
|
||||||
pStream->etime = pQueryInfo->etime;
|
pStream->etime = pQueryInfo->etime;
|
||||||
|
@ -560,7 +562,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
|
||||||
taosTmrReset(tscProcessStreamTimer, starttime, pStream, tscTmr, &pStream->pTimer);
|
taosTmrReset(tscProcessStreamTimer, starttime, pStream, tscTmr, &pStream->pTimer);
|
||||||
|
|
||||||
tscTrace("%p stream:%p is opened, query on:%s, interval:%" PRId64 ", sliding:%" PRId64 ", first launched in:%" PRId64 ", sql:%s", pSql,
|
tscTrace("%p stream:%p is opened, query on:%s, interval:%" PRId64 ", sliding:%" PRId64 ", first launched in:%" PRId64 ", sql:%s", pSql,
|
||||||
pStream, pMeterMetaInfo->name, pStream->interval, pStream->slidingTime, starttime, sqlstr);
|
pStream, pTableMetaInfo->name, pStream->interval, pStream->slidingTime, starttime, sqlstr);
|
||||||
|
|
||||||
return pStream;
|
return pStream;
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,10 +175,10 @@ int tscUpdateSubscription(STscObj* pObj, SSub* pSub) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0, 0);
|
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0, 0);
|
||||||
int numOfTables = 0;
|
int numOfTables = 0;
|
||||||
if (!UTIL_METER_IS_NOMRAL_METER(pMeterMetaInfo)) {
|
if (!UTIL_TABLE_IS_NOMRAL_TABLE(pTableMetaInfo)) {
|
||||||
SSuperTableMeta* pMetricMeta = pMeterMetaInfo->pMetricMeta;
|
SSuperTableMeta* pMetricMeta = pTableMetaInfo->pMetricMeta;
|
||||||
for (int32_t i = 0; i < pMetricMeta->numOfVnodes; i++) {
|
for (int32_t i = 0; i < pMetricMeta->numOfVnodes; i++) {
|
||||||
SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, i);
|
SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, i);
|
||||||
numOfTables += pVnodeSidList->numOfSids;
|
numOfTables += pVnodeSidList->numOfSids;
|
||||||
|
@ -191,19 +191,19 @@ int tscUpdateSubscription(STscObj* pObj, SSub* pSub) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UTIL_METER_IS_NOMRAL_METER(pMeterMetaInfo)) {
|
if (UTIL_TABLE_IS_NOMRAL_TABLE(pTableMetaInfo)) {
|
||||||
numOfTables = 1;
|
numOfTables = 1;
|
||||||
int64_t uid = pMeterMetaInfo->pMeterMeta->uid;
|
int64_t uid = pTableMetaInfo->pTableMeta->uid;
|
||||||
progress[0].uid = uid;
|
progress[0].uid = uid;
|
||||||
progress[0].key = tscGetSubscriptionProgress(pSub, uid);
|
progress[0].key = tscGetSubscriptionProgress(pSub, uid);
|
||||||
} else {
|
} else {
|
||||||
SSuperTableMeta* pMetricMeta = pMeterMetaInfo->pMetricMeta;
|
SSuperTableMeta* pMetricMeta = pTableMetaInfo->pMetricMeta;
|
||||||
numOfTables = 0;
|
numOfTables = 0;
|
||||||
for (int32_t i = 0; i < pMetricMeta->numOfVnodes; i++) {
|
for (int32_t i = 0; i < pMetricMeta->numOfVnodes; i++) {
|
||||||
SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, i);
|
SVnodeSidList *pVnodeSidList = tscGetVnodeSidList(pMetricMeta, i);
|
||||||
for (int32_t j = 0; j < pVnodeSidList->numOfSids; j++) {
|
for (int32_t j = 0; j < pVnodeSidList->numOfSids; j++) {
|
||||||
STableSidExtInfo *pMeterInfo = tscGetMeterSidInfo(pVnodeSidList, j);
|
STableSidExtInfo *pTableMetaInfo = tscGetMeterSidInfo(pVnodeSidList, j);
|
||||||
int64_t uid = pMeterInfo->uid;
|
int64_t uid = pTableMetaInfo->uid;
|
||||||
progress[numOfTables].uid = uid;
|
progress[numOfTables].uid = uid;
|
||||||
progress[numOfTables++].key = tscGetSubscriptionProgress(pSub, uid);
|
progress[numOfTables++].key = tscGetSubscriptionProgress(pSub, uid);
|
||||||
}
|
}
|
||||||
|
@ -385,7 +385,7 @@ TAOS_RES *taos_consume(TAOS_SUB *tsub) {
|
||||||
pSql->cmd.command = TSDB_SQL_SELECT;
|
pSql->cmd.command = TSDB_SQL_SELECT;
|
||||||
pQueryInfo->type = type;
|
pQueryInfo->type = type;
|
||||||
|
|
||||||
tscGetMeterMetaInfo(&pSql->cmd, 0, 0)->vnodeIndex = 0;
|
tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0)->vnodeIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
tscDoQuery(pSql);
|
tscDoQuery(pSql);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -159,7 +159,7 @@ void taos_init_imp() {
|
||||||
tscMgmtIpList.ip[1] = inet_addr(tsSecondIp);
|
tscMgmtIpList.ip[1] = inet_addr(tsSecondIp);
|
||||||
}
|
}
|
||||||
|
|
||||||
tscInitMsgs();
|
tscInitMsgsFp();
|
||||||
slaveIndex = rand();
|
slaveIndex = rand();
|
||||||
int queueSize = tsMaxVnodeConnections + tsMaxMeterConnections + tsMaxMgmtConnections + tsMaxMgmtConnections;
|
int queueSize = tsMaxVnodeConnections + tsMaxMeterConnections + tsMaxMgmtConnections + tsMaxMgmtConnections;
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,9 @@
|
||||||
#include "tcache.h"
|
#include "tcache.h"
|
||||||
#include "tkey.h"
|
#include "tkey.h"
|
||||||
#include "tmd5.h"
|
#include "tmd5.h"
|
||||||
#include "tscJoinProcess.h"
|
|
||||||
#include "tscProfile.h"
|
#include "tscProfile.h"
|
||||||
#include "tscSecondaryMerge.h"
|
#include "tscSecondaryMerge.h"
|
||||||
|
#include "tscSubquery.h"
|
||||||
#include "tschemautil.h"
|
#include "tschemautil.h"
|
||||||
#include "tsclient.h"
|
#include "tsclient.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
|
@ -40,12 +40,12 @@
|
||||||
*/
|
*/
|
||||||
void tscGetMetricMetaCacheKey(SQueryInfo* pQueryInfo, char* str, uint64_t uid) {
|
void tscGetMetricMetaCacheKey(SQueryInfo* pQueryInfo, char* str, uint64_t uid) {
|
||||||
int32_t index = -1;
|
int32_t index = -1;
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoByUid(pQueryInfo, uid, &index);
|
STableMetaInfo* pTableMetaInfo = tscGetMeterMetaInfoByUid(pQueryInfo, uid, &index);
|
||||||
|
|
||||||
int32_t len = 0;
|
int32_t len = 0;
|
||||||
char tagIdBuf[128] = {0};
|
char tagIdBuf[128] = {0};
|
||||||
for (int32_t i = 0; i < pMeterMetaInfo->numOfTags; ++i) {
|
for (int32_t i = 0; i < pTableMetaInfo->numOfTags; ++i) {
|
||||||
len += sprintf(&tagIdBuf[len], "%d,", pMeterMetaInfo->tagColumnIndex[i]);
|
len += sprintf(&tagIdBuf[len], "%d,", pTableMetaInfo->tagColumnIndex[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
STagCond* pTagCond = &pQueryInfo->tagCond;
|
STagCond* pTagCond = &pQueryInfo->tagCond;
|
||||||
|
@ -64,7 +64,7 @@ void tscGetMetricMetaCacheKey(SQueryInfo* pQueryInfo, char* str, uint64_t uid) {
|
||||||
size_t tbnameCondLen = pTagCond->tbnameCond.cond != NULL ? strlen(pTagCond->tbnameCond.cond) : 0;
|
size_t tbnameCondLen = pTagCond->tbnameCond.cond != NULL ? strlen(pTagCond->tbnameCond.cond) : 0;
|
||||||
size_t redundantLen = 20;
|
size_t redundantLen = 20;
|
||||||
|
|
||||||
size_t bufSize = strlen(pMeterMetaInfo->name) + tbnameCondLen + strlen(join) + strlen(tagIdBuf);
|
size_t bufSize = strlen(pTableMetaInfo->name) + tbnameCondLen + strlen(join) + strlen(tagIdBuf);
|
||||||
if (cond != NULL && cond->cond != NULL) {
|
if (cond != NULL && cond->cond != NULL) {
|
||||||
bufSize += strlen(cond->cond);
|
bufSize += strlen(cond->cond);
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ void tscGetMetricMetaCacheKey(SQueryInfo* pQueryInfo, char* str, uint64_t uid) {
|
||||||
bufSize = (size_t)((bufSize + redundantLen) * 1.5);
|
bufSize = (size_t)((bufSize + redundantLen) * 1.5);
|
||||||
char* tmp = calloc(1, bufSize);
|
char* tmp = calloc(1, bufSize);
|
||||||
|
|
||||||
int32_t keyLen = snprintf(tmp, bufSize, "%s,%s,%s,%d,%s,[%s],%d", pMeterMetaInfo->name,
|
int32_t keyLen = snprintf(tmp, bufSize, "%s,%s,%s,%d,%s,[%s],%d", pTableMetaInfo->name,
|
||||||
((cond != NULL && cond->cond != NULL) ? cond->cond : NULL), (tbnameCondLen > 0 ? pTagCond->tbnameCond.cond : NULL),
|
((cond != NULL && cond->cond != NULL) ? cond->cond : NULL), (tbnameCondLen > 0 ? pTagCond->tbnameCond.cond : NULL),
|
||||||
pTagCond->relType, join, tagIdBuf, pQueryInfo->groupbyExpr.orderType);
|
pTagCond->relType, join, tagIdBuf, pQueryInfo->groupbyExpr.orderType);
|
||||||
|
|
||||||
|
@ -209,22 +209,22 @@ STableSidExtInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx) {
|
||||||
return (STableSidExtInfo*)(pSidList->pSidExtInfoList[idx] + (char*)pSidList);
|
return (STableSidExtInfo*)(pSidList->pSidExtInfoList[idx] + (char*)pSidList);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tscIsTwoStageMergeMetricQuery(SQueryInfo* pQueryInfo, int32_t tableIndex) {
|
bool tscIsTwoStageSTableQuery(SQueryInfo* pQueryInfo, int32_t tableIndex) {
|
||||||
if (pQueryInfo == NULL) {
|
if (pQueryInfo == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, tableIndex);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, tableIndex);
|
||||||
if (pMeterMetaInfo == NULL) {
|
if (pTableMetaInfo == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for select query super table, the metricmeta can not be null in any cases.
|
// for select query super table, the metricmeta can not be null in any cases.
|
||||||
if (pQueryInfo->command == TSDB_SQL_SELECT && UTIL_METER_IS_SUPERTABLE(pMeterMetaInfo)) {
|
if (pQueryInfo->command == TSDB_SQL_SELECT && UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) {
|
||||||
assert(pMeterMetaInfo->pMetricMeta != NULL);
|
assert(pTableMetaInfo->pMetricMeta != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMeterMetaInfo->pMetricMeta == NULL) {
|
if (pTableMetaInfo->pMetricMeta == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,21 +239,21 @@ bool tscIsTwoStageMergeMetricQuery(SQueryInfo* pQueryInfo, int32_t tableIndex) {
|
||||||
|
|
||||||
if (((pQueryInfo->type & TSDB_QUERY_TYPE_STABLE_SUBQUERY) != TSDB_QUERY_TYPE_STABLE_SUBQUERY) &&
|
if (((pQueryInfo->type & TSDB_QUERY_TYPE_STABLE_SUBQUERY) != TSDB_QUERY_TYPE_STABLE_SUBQUERY) &&
|
||||||
pQueryInfo->command == TSDB_SQL_SELECT) {
|
pQueryInfo->command == TSDB_SQL_SELECT) {
|
||||||
return UTIL_METER_IS_SUPERTABLE(pMeterMetaInfo);
|
return UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) {
|
bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) {
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, tableIndex);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, tableIndex);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* In following cases, return false for non ordered project query on super table
|
* In following cases, return false for non ordered project query on super table
|
||||||
* 1. failed to get metermeta from server; 2. not a super table; 3. limitation is 0;
|
* 1. failed to get metermeta from server; 2. not a super table; 3. limitation is 0;
|
||||||
* 4. show queries, instead of a select query
|
* 4. show queries, instead of a select query
|
||||||
*/
|
*/
|
||||||
if (pMeterMetaInfo == NULL || !UTIL_METER_IS_SUPERTABLE(pMeterMetaInfo) ||
|
if (pTableMetaInfo == NULL || !UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo) ||
|
||||||
pQueryInfo->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pQueryInfo->exprsInfo.numOfExprs == 0) {
|
pQueryInfo->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pQueryInfo->exprsInfo.numOfExprs == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -505,7 +505,7 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock) {
|
||||||
tfree(pDataBlock->params);
|
tfree(pDataBlock->params);
|
||||||
|
|
||||||
// free the refcount for metermeta
|
// free the refcount for metermeta
|
||||||
taosCacheRelease(tscCacheHandle, (void**)&(pDataBlock->pMeterMeta), false);
|
taosCacheRelease(tscCacheHandle, (void**)&(pDataBlock->pTableMeta), false);
|
||||||
tfree(pDataBlock);
|
tfree(pDataBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,21 +579,21 @@ void* tscDestroyBlockArrayList(SDataBlockList* pList) {
|
||||||
|
|
||||||
int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
|
int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
|
||||||
SSqlCmd* pCmd = &pSql->cmd;
|
SSqlCmd* pCmd = &pSql->cmd;
|
||||||
assert(pDataBlock->pMeterMeta != NULL);
|
assert(pDataBlock->pTableMeta != NULL);
|
||||||
|
|
||||||
pCmd->numOfTablesInSubmit = pDataBlock->numOfTables;
|
pCmd->numOfTablesInSubmit = pDataBlock->numOfTables;
|
||||||
|
|
||||||
assert(pCmd->numOfClause == 1);
|
assert(pCmd->numOfClause == 1);
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
|
||||||
|
|
||||||
// set the correct metermeta object, the metermeta has been locked in pDataBlocks, so it must be in the cache
|
// set the correct metermeta object, the metermeta has been locked in pDataBlocks, so it must be in the cache
|
||||||
if (pMeterMetaInfo->pMeterMeta != pDataBlock->pMeterMeta) {
|
if (pTableMetaInfo->pTableMeta != pDataBlock->pTableMeta) {
|
||||||
strcpy(pMeterMetaInfo->name, pDataBlock->tableId);
|
strcpy(pTableMetaInfo->name, pDataBlock->tableId);
|
||||||
taosCacheRelease(tscCacheHandle, (void**)&(pMeterMetaInfo->pMeterMeta), false);
|
taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pTableMeta), false);
|
||||||
|
|
||||||
pMeterMetaInfo->pMeterMeta = taosCacheTransfer(tscCacheHandle, (void**)&pDataBlock->pMeterMeta);
|
pTableMetaInfo->pTableMeta = taosCacheTransfer(tscCacheHandle, (void**)&pDataBlock->pTableMeta);
|
||||||
} else {
|
} else {
|
||||||
assert(strncmp(pMeterMetaInfo->name, pDataBlock->tableId, tListLen(pDataBlock->tableId)) == 0);
|
assert(strncmp(pTableMetaInfo->name, pDataBlock->tableId, tListLen(pDataBlock->tableId)) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -637,7 +637,7 @@ void tscFreeUnusedDataBlocks(SDataBlockList* pList) {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, const char* name,
|
int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, const char* name,
|
||||||
STableMeta* pMeterMeta, STableDataBlocks** dataBlocks) {
|
STableMeta* pTableMeta, STableDataBlocks** dataBlocks) {
|
||||||
STableDataBlocks* dataBuf = (STableDataBlocks*)calloc(1, sizeof(STableDataBlocks));
|
STableDataBlocks* dataBuf = (STableDataBlocks*)calloc(1, sizeof(STableDataBlocks));
|
||||||
if (dataBuf == NULL) {
|
if (dataBuf == NULL) {
|
||||||
tscError("failed to allocated memory, reason:%s", strerror(errno));
|
tscError("failed to allocated memory, reason:%s", strerror(errno));
|
||||||
|
@ -665,15 +665,15 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff
|
||||||
* due to operation such as drop database. So here we add the reference count directly instead of invoke
|
* due to operation such as drop database. So here we add the reference count directly instead of invoke
|
||||||
* taosGetDataFromCache, which may return NULL value.
|
* taosGetDataFromCache, which may return NULL value.
|
||||||
*/
|
*/
|
||||||
dataBuf->pMeterMeta = taosCacheAcquireByData(tscCacheHandle, pMeterMeta);
|
dataBuf->pTableMeta = taosCacheAcquireByData(tscCacheHandle, pTableMeta);
|
||||||
assert(initialSize > 0 && pMeterMeta != NULL && dataBuf->pMeterMeta != NULL);
|
assert(initialSize > 0 && pTableMeta != NULL && dataBuf->pTableMeta != NULL);
|
||||||
|
|
||||||
*dataBlocks = dataBuf;
|
*dataBlocks = dataBuf;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList, int64_t id, int32_t size,
|
int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList, int64_t id, int32_t size,
|
||||||
int32_t startOffset, int32_t rowSize, const char* tableId, STableMeta* pMeterMeta,
|
int32_t startOffset, int32_t rowSize, const char* tableId, STableMeta* pTableMeta,
|
||||||
STableDataBlocks** dataBlocks) {
|
STableDataBlocks** dataBlocks) {
|
||||||
*dataBlocks = NULL;
|
*dataBlocks = NULL;
|
||||||
|
|
||||||
|
@ -683,7 +683,7 @@ int32_t tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*dataBlocks == NULL) {
|
if (*dataBlocks == NULL) {
|
||||||
int32_t ret = tscCreateDataBlock((size_t)size, rowSize, startOffset, tableId, pMeterMeta, dataBlocks);
|
int32_t ret = tscCreateDataBlock((size_t)size, rowSize, startOffset, tableId, pTableMeta, dataBlocks);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -707,7 +707,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pTableDataBlockLi
|
||||||
STableDataBlocks* dataBuf = NULL;
|
STableDataBlocks* dataBuf = NULL;
|
||||||
int32_t ret =
|
int32_t ret =
|
||||||
tscGetDataBlockFromList(pVnodeDataBlockHashList, pVnodeDataBlockList, pOneTableBlock->vgid, TSDB_PAYLOAD_SIZE,
|
tscGetDataBlockFromList(pVnodeDataBlockHashList, pVnodeDataBlockList, pOneTableBlock->vgid, TSDB_PAYLOAD_SIZE,
|
||||||
tsInsertHeadSize, 0, pOneTableBlock->tableId, pOneTableBlock->pMeterMeta, &dataBuf);
|
tsInsertHeadSize, 0, pOneTableBlock->tableId, pOneTableBlock->pTableMeta, &dataBuf);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
tscError("%p failed to prepare the data block buffer for merging table data, code:%d", pSql, ret);
|
tscError("%p failed to prepare the data block buffer for merging table data, code:%d", pSql, ret);
|
||||||
taosHashCleanup(pVnodeDataBlockHashList);
|
taosHashCleanup(pVnodeDataBlockHashList);
|
||||||
|
@ -1061,8 +1061,8 @@ void tscClearFieldInfo(SFieldInfo* pFieldInfo) {
|
||||||
|
|
||||||
for(int32_t i = 0; i < pFieldInfo->numOfOutputCols; ++i) {
|
for(int32_t i = 0; i < pFieldInfo->numOfOutputCols; ++i) {
|
||||||
if (pFieldInfo->pExpr[i] != NULL) {
|
if (pFieldInfo->pExpr[i] != NULL) {
|
||||||
tSQLBinaryExprDestroy(&pFieldInfo->pExpr[i]->pBinExprInfo.pBinExpr, NULL);
|
tSQLBinaryExprDestroy(&pFieldInfo->pExpr[i]->binExprInfo.pBinExpr, NULL);
|
||||||
tfree(pFieldInfo->pExpr[i]->pBinExprInfo.pReqColumns);
|
tfree(pFieldInfo->pExpr[i]->binExprInfo.pReqColumns);
|
||||||
tfree(pFieldInfo->pExpr[i]);
|
tfree(pFieldInfo->pExpr[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1116,7 +1116,7 @@ SSqlExpr* tscSqlExprInsertEmpty(SQueryInfo* pQueryInfo, int32_t index, int16_t f
|
||||||
|
|
||||||
SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, SColumnIndex* pColIndex,
|
SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, SColumnIndex* pColIndex,
|
||||||
int16_t type, int16_t size, int16_t interSize) {
|
int16_t type, int16_t size, int16_t interSize) {
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, pColIndex->tableIndex);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pColIndex->tableIndex);
|
||||||
|
|
||||||
SSqlExprInfo* pExprInfo = &pQueryInfo->exprsInfo;
|
SSqlExprInfo* pExprInfo = &pQueryInfo->exprsInfo;
|
||||||
|
|
||||||
|
@ -1127,13 +1127,13 @@ SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
|
||||||
pExprInfo->pExprs[index] = pExpr;
|
pExprInfo->pExprs[index] = pExpr;
|
||||||
|
|
||||||
pExpr->functionId = functionId;
|
pExpr->functionId = functionId;
|
||||||
int16_t numOfCols = pMeterMetaInfo->pMeterMeta->numOfColumns;
|
int16_t numOfCols = tscGetNumOfColumns(pTableMetaInfo->pTableMeta);
|
||||||
|
|
||||||
// set the correct column index
|
// set the correct column index
|
||||||
if (pColIndex->columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
if (pColIndex->columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||||
pExpr->colInfo.colId = TSDB_TBNAME_COLUMN_INDEX;
|
pExpr->colInfo.colId = TSDB_TBNAME_COLUMN_INDEX;
|
||||||
} else {
|
} else {
|
||||||
SSchema* pSchema = tsGetColumnSchema(pMeterMetaInfo->pMeterMeta, pColIndex->columnIndex);
|
SSchema* pSchema = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, pColIndex->columnIndex);
|
||||||
pExpr->colInfo.colId = pSchema->colId;
|
pExpr->colInfo.colId = pSchema->colId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1153,7 +1153,7 @@ SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
|
||||||
pExpr->resType = type;
|
pExpr->resType = type;
|
||||||
pExpr->resBytes = size;
|
pExpr->resBytes = size;
|
||||||
pExpr->interResBytes = interSize;
|
pExpr->interResBytes = interSize;
|
||||||
pExpr->uid = pMeterMetaInfo->pMeterMeta->uid;
|
pExpr->uid = pTableMetaInfo->pTableMeta->uid;
|
||||||
|
|
||||||
pExprInfo->numOfExprs++;
|
pExprInfo->numOfExprs++;
|
||||||
return pExpr;
|
return pExpr;
|
||||||
|
@ -1161,7 +1161,7 @@ SSqlExpr* tscSqlExprInsert(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
|
||||||
|
|
||||||
SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, int16_t srcColumnIndex,
|
SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functionId, int16_t srcColumnIndex,
|
||||||
int16_t type, int16_t size) {
|
int16_t type, int16_t size) {
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
SSqlExprInfo* pExprInfo = &pQueryInfo->exprsInfo;
|
SSqlExprInfo* pExprInfo = &pQueryInfo->exprsInfo;
|
||||||
if (index > pExprInfo->numOfExprs) {
|
if (index > pExprInfo->numOfExprs) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1172,7 +1172,7 @@ SSqlExpr* tscSqlExprUpdate(SQueryInfo* pQueryInfo, int32_t index, int16_t functi
|
||||||
pExpr->functionId = functionId;
|
pExpr->functionId = functionId;
|
||||||
|
|
||||||
pExpr->colInfo.colIdx = srcColumnIndex;
|
pExpr->colInfo.colIdx = srcColumnIndex;
|
||||||
pExpr->colInfo.colId = tsGetColumnSchema(pMeterMetaInfo->pMeterMeta, srcColumnIndex)->colId;
|
pExpr->colInfo.colId = tscGetTableColumnSchema(pTableMetaInfo->pTableMeta, srcColumnIndex)->colId;
|
||||||
|
|
||||||
pExpr->resType = type;
|
pExpr->resType = type;
|
||||||
pExpr->resBytes = size;
|
pExpr->resBytes = size;
|
||||||
|
@ -1573,17 +1573,19 @@ void tscIncStreamExecutionCount(void* pStream) {
|
||||||
ps->num += 1;
|
ps->num += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tscValidateColumnId(SMeterMetaInfo* pMeterMetaInfo, int32_t colId) {
|
bool tscValidateColumnId(STableMetaInfo* pTableMetaInfo, int32_t colId) {
|
||||||
if (pMeterMetaInfo->pMeterMeta == NULL) {
|
if (pTableMetaInfo->pTableMeta == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colId == -1 && UTIL_METER_IS_SUPERTABLE(pMeterMetaInfo)) {
|
if (colId == -1 && UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSchema* pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta);
|
SSchema* pSchema = tscGetTableSchema(pTableMetaInfo->pTableMeta);
|
||||||
int32_t numOfTotal = pMeterMetaInfo->pMeterMeta->numOfTags + pMeterMetaInfo->pMeterMeta->numOfColumns;
|
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
|
||||||
|
|
||||||
|
int32_t numOfTotal = tinfo.numOfTags + tinfo.numOfColumns;
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfTotal; ++i) {
|
for (int32_t i = 0; i < numOfTotal; ++i) {
|
||||||
if (pSchema[i].colId == colId) {
|
if (pSchema[i].colId == colId) {
|
||||||
|
@ -1627,16 +1629,16 @@ void tscTagCondRelease(STagCond* pCond) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SQueryInfo* pQueryInfo) {
|
void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SQueryInfo* pQueryInfo) {
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
SSchema* pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta);
|
SSchema* pSchema = tscGetTableSchema(pTableMetaInfo->pTableMeta);
|
||||||
|
|
||||||
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->exprsInfo.numOfExprs; ++i) {
|
||||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||||
pColInfo[i].functionId = pExpr->functionId;
|
pColInfo[i].functionId = pExpr->functionId;
|
||||||
|
|
||||||
if (TSDB_COL_IS_TAG(pExpr->colInfo.flag)) {
|
if (TSDB_COL_IS_TAG(pExpr->colInfo.flag)) {
|
||||||
SSchema* pTagSchema = tsGetTagSchema(pMeterMetaInfo->pMeterMeta);
|
SSchema* pTagSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta);
|
||||||
int16_t actualTagIndex = pMeterMetaInfo->tagColumnIndex[pExpr->colInfo.colIdx];
|
int16_t actualTagIndex = pTableMetaInfo->tagColumnIndex[pExpr->colInfo.colIdx];
|
||||||
|
|
||||||
pColInfo[i].type = (actualTagIndex != -1) ? pTagSchema[actualTagIndex].type : TSDB_DATA_TYPE_BINARY;
|
pColInfo[i].type = (actualTagIndex != -1) ? pTagSchema[actualTagIndex].type : TSDB_DATA_TYPE_BINARY;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1723,10 +1725,10 @@ bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql) {
|
||||||
SDataBlockList* pDataBlocks = pCmd->pDataBlocks;
|
SDataBlockList* pDataBlocks = pCmd->pDataBlocks;
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
assert(pQueryInfo->numOfTables == 1 || pQueryInfo->numOfTables == 2);
|
assert(pQueryInfo->numOfTables == 1 || pQueryInfo->numOfTables == 2);
|
||||||
|
|
||||||
if (pDataBlocks == NULL || pMeterMetaInfo->vnodeIndex >= pDataBlocks->nSize) {
|
if (pDataBlocks == NULL || pTableMetaInfo->vnodeIndex >= pDataBlocks->nSize) {
|
||||||
tscTrace("%p object should be release since all data blocks have been submit", pSql);
|
tscTrace("%p object should be release since all data blocks have been submit", pSql);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1745,7 +1747,7 @@ bool tscShouldFreeAsyncSqlObj(SSqlObj* pSql) {
|
||||||
* @param tableIndex denote the table index for join query, where more than one table exists
|
* @param tableIndex denote the table index for join query, where more than one table exists
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
SMeterMetaInfo* tscGetMeterMetaInfo(SSqlCmd* pCmd, int32_t clauseIndex, int32_t tableIndex) {
|
STableMetaInfo* tscGetTableMetaInfoFromCmd(SSqlCmd* pCmd, int32_t clauseIndex, int32_t tableIndex) {
|
||||||
if (pCmd == NULL || pCmd->numOfClause == 0) {
|
if (pCmd == NULL || pCmd->numOfClause == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1753,20 +1755,20 @@ SMeterMetaInfo* tscGetMeterMetaInfo(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
|
||||||
assert(clauseIndex >= 0 && clauseIndex < pCmd->numOfClause);
|
assert(clauseIndex >= 0 && clauseIndex < pCmd->numOfClause);
|
||||||
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, clauseIndex);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, clauseIndex);
|
||||||
return tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, tableIndex);
|
return tscGetMetaInfo(pQueryInfo, tableIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
SMeterMetaInfo* tscGetMeterMetaInfoFromQueryInfo(SQueryInfo* pQueryInfo, int32_t tableIndex) {
|
STableMetaInfo* tscGetMetaInfo(SQueryInfo* pQueryInfo, int32_t tableIndex) {
|
||||||
assert(pQueryInfo != NULL);
|
assert(pQueryInfo != NULL);
|
||||||
|
|
||||||
if (pQueryInfo->pMeterInfo == NULL) {
|
if (pQueryInfo->pTableMetaInfo == NULL) {
|
||||||
assert(pQueryInfo->numOfTables == 0);
|
assert(pQueryInfo->numOfTables == 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(tableIndex >= 0 && tableIndex <= pQueryInfo->numOfTables && pQueryInfo->pMeterInfo != NULL);
|
assert(tableIndex >= 0 && tableIndex <= pQueryInfo->numOfTables && pQueryInfo->pTableMetaInfo != NULL);
|
||||||
|
|
||||||
return pQueryInfo->pMeterInfo[tableIndex];
|
return pQueryInfo->pTableMetaInfo[tableIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
SQueryInfo* tscGetQueryInfoDetail(SSqlCmd* pCmd, int32_t subClauseIndex) {
|
SQueryInfo* tscGetQueryInfoDetail(SSqlCmd* pCmd, int32_t subClauseIndex) {
|
||||||
|
@ -1795,11 +1797,11 @@ int32_t tscGetQueryInfoDetailSafely(SSqlCmd* pCmd, int32_t subClauseIndex, SQuer
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMeterMetaInfo* tscGetMeterMetaInfoByUid(SQueryInfo* pQueryInfo, uint64_t uid, int32_t* index) {
|
STableMetaInfo* tscGetMeterMetaInfoByUid(SQueryInfo* pQueryInfo, uint64_t uid, int32_t* index) {
|
||||||
int32_t k = -1;
|
int32_t k = -1;
|
||||||
|
|
||||||
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
|
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
|
||||||
if (pQueryInfo->pMeterInfo[i]->pMeterMeta->uid == uid) {
|
if (pQueryInfo->pTableMetaInfo[i]->pTableMeta->uid == uid) {
|
||||||
k = i;
|
k = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1810,7 +1812,7 @@ SMeterMetaInfo* tscGetMeterMetaInfoByUid(SQueryInfo* pQueryInfo, uint64_t uid, i
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(k != -1);
|
assert(k != -1);
|
||||||
return tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, k);
|
return tscGetMetaInfo(pQueryInfo, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) {
|
int32_t tscAddSubqueryInfo(SSqlCmd* pCmd) {
|
||||||
|
@ -1872,37 +1874,37 @@ void tscFreeSubqueryInfo(SSqlCmd* pCmd) {
|
||||||
tfree(pCmd->pQueryInfo);
|
tfree(pCmd->pQueryInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
SMeterMetaInfo* tscAddMeterMetaInfo(SQueryInfo* pQueryInfo, const char* name, STableMeta* pMeterMeta,
|
STableMetaInfo* tscAddMeterMetaInfo(SQueryInfo* pQueryInfo, const char* name, STableMeta* pTableMeta,
|
||||||
SSuperTableMeta* pMetricMeta, int16_t numOfTags, int16_t* tags) {
|
SSuperTableMeta* pMetricMeta, int16_t numOfTags, int16_t* tags) {
|
||||||
void* pAlloc = realloc(pQueryInfo->pMeterInfo, (pQueryInfo->numOfTables + 1) * POINTER_BYTES);
|
void* pAlloc = realloc(pQueryInfo->pTableMetaInfo, (pQueryInfo->numOfTables + 1) * POINTER_BYTES);
|
||||||
if (pAlloc == NULL) {
|
if (pAlloc == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pQueryInfo->pMeterInfo = pAlloc;
|
pQueryInfo->pTableMetaInfo = pAlloc;
|
||||||
pQueryInfo->pMeterInfo[pQueryInfo->numOfTables] = calloc(1, sizeof(SMeterMetaInfo));
|
pQueryInfo->pTableMetaInfo[pQueryInfo->numOfTables] = calloc(1, sizeof(STableMetaInfo));
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = pQueryInfo->pMeterInfo[pQueryInfo->numOfTables];
|
STableMetaInfo* pTableMetaInfo = pQueryInfo->pTableMetaInfo[pQueryInfo->numOfTables];
|
||||||
assert(pMeterMetaInfo != NULL);
|
assert(pTableMetaInfo != NULL);
|
||||||
|
|
||||||
if (name != NULL) {
|
if (name != NULL) {
|
||||||
assert(strlen(name) <= TSDB_TABLE_ID_LEN);
|
assert(strlen(name) <= TSDB_TABLE_ID_LEN);
|
||||||
strcpy(pMeterMetaInfo->name, name);
|
strcpy(pTableMetaInfo->name, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
pMeterMetaInfo->pMeterMeta = pMeterMeta;
|
pTableMetaInfo->pTableMeta = pTableMeta;
|
||||||
pMeterMetaInfo->pMetricMeta = pMetricMeta;
|
pTableMetaInfo->pMetricMeta = pMetricMeta;
|
||||||
pMeterMetaInfo->numOfTags = numOfTags;
|
pTableMetaInfo->numOfTags = numOfTags;
|
||||||
|
|
||||||
if (tags != NULL) {
|
if (tags != NULL) {
|
||||||
memcpy(pMeterMetaInfo->tagColumnIndex, tags, sizeof(pMeterMetaInfo->tagColumnIndex[0]) * numOfTags);
|
memcpy(pTableMetaInfo->tagColumnIndex, tags, sizeof(pTableMetaInfo->tagColumnIndex[0]) * numOfTags);
|
||||||
}
|
}
|
||||||
|
|
||||||
pQueryInfo->numOfTables += 1;
|
pQueryInfo->numOfTables += 1;
|
||||||
return pMeterMetaInfo;
|
return pTableMetaInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMeterMetaInfo* tscAddEmptyMeterMetaInfo(SQueryInfo* pQueryInfo) {
|
STableMetaInfo* tscAddEmptyMetaInfo(SQueryInfo* pQueryInfo) {
|
||||||
return tscAddMeterMetaInfo(pQueryInfo, NULL, NULL, NULL, 0, NULL);
|
return tscAddMeterMetaInfo(pQueryInfo, NULL, NULL, NULL, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1911,14 +1913,14 @@ void doRemoveMeterMetaInfo(SQueryInfo* pQueryInfo, int32_t index, bool removeFro
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, index);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index);
|
||||||
|
|
||||||
tscClearMeterMetaInfo(pMeterMetaInfo, removeFromCache);
|
tscClearMeterMetaInfo(pTableMetaInfo, removeFromCache);
|
||||||
free(pMeterMetaInfo);
|
free(pTableMetaInfo);
|
||||||
|
|
||||||
int32_t after = pQueryInfo->numOfTables - index - 1;
|
int32_t after = pQueryInfo->numOfTables - index - 1;
|
||||||
if (after > 0) {
|
if (after > 0) {
|
||||||
memmove(&pQueryInfo->pMeterInfo[index], &pQueryInfo->pMeterInfo[index + 1], after * POINTER_BYTES);
|
memmove(&pQueryInfo->pTableMetaInfo[index], &pQueryInfo->pTableMetaInfo[index + 1], after * POINTER_BYTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
pQueryInfo->numOfTables -= 1;
|
pQueryInfo->numOfTables -= 1;
|
||||||
|
@ -1932,16 +1934,16 @@ void tscRemoveAllMeterMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool
|
||||||
doRemoveMeterMetaInfo(pQueryInfo, --index, removeFromCache);
|
doRemoveMeterMetaInfo(pQueryInfo, --index, removeFromCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
tfree(pQueryInfo->pMeterInfo);
|
tfree(pQueryInfo->pTableMetaInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscClearMeterMetaInfo(SMeterMetaInfo* pMeterMetaInfo, bool removeFromCache) {
|
void tscClearMeterMetaInfo(STableMetaInfo* pTableMetaInfo, bool removeFromCache) {
|
||||||
if (pMeterMetaInfo == NULL) {
|
if (pTableMetaInfo == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCacheRelease(tscCacheHandle, (void**)&(pMeterMetaInfo->pMeterMeta), removeFromCache);
|
taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pTableMeta), removeFromCache);
|
||||||
taosCacheRelease(tscCacheHandle, (void**)&(pMeterMetaInfo->pMetricMeta), removeFromCache);
|
taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pMetricMeta), removeFromCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscResetForNextRetrieve(SSqlRes* pRes) {
|
void tscResetForNextRetrieve(SSqlRes* pRes) {
|
||||||
|
@ -1955,11 +1957,11 @@ void tscResetForNextRetrieve(SSqlRes* pRes) {
|
||||||
|
|
||||||
SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void* param, SSqlObj* pPrevSql) {
|
SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void* param, SSqlObj* pPrevSql) {
|
||||||
SSqlCmd* pCmd = &pSql->cmd;
|
SSqlCmd* pCmd = &pSql->cmd;
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, pCmd->clauseIndex, tableIndex);
|
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, tableIndex);
|
||||||
|
|
||||||
SSqlObj* pNew = (SSqlObj*)calloc(1, sizeof(SSqlObj));
|
SSqlObj* pNew = (SSqlObj*)calloc(1, sizeof(SSqlObj));
|
||||||
if (pNew == NULL) {
|
if (pNew == NULL) {
|
||||||
tscError("%p new subquery failed, tableIndex:%d, vnodeIndex:%d", pSql, tableIndex, pMeterMetaInfo->vnodeIndex);
|
tscError("%p new subquery failed, tableIndex:%d, vnodeIndex:%d", pSql, tableIndex, pTableMetaInfo->vnodeIndex);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1968,7 +1970,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
|
||||||
|
|
||||||
pNew->sqlstr = strdup(pSql->sqlstr);
|
pNew->sqlstr = strdup(pSql->sqlstr);
|
||||||
if (pNew->sqlstr == NULL) {
|
if (pNew->sqlstr == NULL) {
|
||||||
tscError("%p new subquery failed, tableIndex:%d, vnodeIndex:%d", pSql, tableIndex, pMeterMetaInfo->vnodeIndex);
|
tscError("%p new subquery failed, tableIndex:%d, vnodeIndex:%d", pSql, tableIndex, pTableMetaInfo->vnodeIndex);
|
||||||
|
|
||||||
free(pNew);
|
free(pNew);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1997,7 +1999,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
|
||||||
memset(&pNewQueryInfo->colList, 0, sizeof(pNewQueryInfo->colList));
|
memset(&pNewQueryInfo->colList, 0, sizeof(pNewQueryInfo->colList));
|
||||||
memset(&pNewQueryInfo->fieldsInfo, 0, sizeof(SFieldInfo));
|
memset(&pNewQueryInfo->fieldsInfo, 0, sizeof(SFieldInfo));
|
||||||
|
|
||||||
pNewQueryInfo->pMeterInfo = NULL;
|
pNewQueryInfo->pTableMetaInfo = NULL;
|
||||||
pNewQueryInfo->defaultVal = NULL;
|
pNewQueryInfo->defaultVal = NULL;
|
||||||
pNewQueryInfo->numOfTables = 0;
|
pNewQueryInfo->numOfTables = 0;
|
||||||
pNewQueryInfo->tsBuf = NULL;
|
pNewQueryInfo->tsBuf = NULL;
|
||||||
|
@ -2010,7 +2012,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tscAllocPayload(&pNew->cmd, TSDB_DEFAULT_PAYLOAD_SIZE) != TSDB_CODE_SUCCESS) {
|
if (tscAllocPayload(&pNew->cmd, TSDB_DEFAULT_PAYLOAD_SIZE) != TSDB_CODE_SUCCESS) {
|
||||||
tscError("%p new subquery failed, tableIndex:%d, vnodeIndex:%d", pSql, tableIndex, pMeterMetaInfo->vnodeIndex);
|
tscError("%p new subquery failed, tableIndex:%d, vnodeIndex:%d", pSql, tableIndex, pTableMetaInfo->vnodeIndex);
|
||||||
tscFreeSqlObj(pNew);
|
tscFreeSqlObj(pNew);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2025,7 +2027,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
|
||||||
pNewQueryInfo->type |= TSDB_QUERY_TYPE_SUBQUERY; // it must be the subquery
|
pNewQueryInfo->type |= TSDB_QUERY_TYPE_SUBQUERY; // it must be the subquery
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t uid = pMeterMetaInfo->pMeterMeta->uid;
|
uint64_t uid = pTableMetaInfo->pTableMeta->uid;
|
||||||
tscSqlExprCopy(&pNewQueryInfo->exprsInfo, &pQueryInfo->exprsInfo, uid, true);
|
tscSqlExprCopy(&pNewQueryInfo->exprsInfo, &pQueryInfo->exprsInfo, uid, true);
|
||||||
|
|
||||||
int32_t numOfOutputCols = pNewQueryInfo->exprsInfo.numOfExprs;
|
int32_t numOfOutputCols = pNewQueryInfo->exprsInfo.numOfExprs;
|
||||||
|
@ -2067,34 +2069,34 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
|
||||||
printf("the metricmeta key is:%s\n", key);
|
printf("the metricmeta key is:%s\n", key);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char* name = pMeterMetaInfo->name;
|
char* name = pTableMetaInfo->name;
|
||||||
SMeterMetaInfo* pFinalInfo = NULL;
|
STableMetaInfo* pFinalInfo = NULL;
|
||||||
|
|
||||||
if (pPrevSql == NULL) {
|
if (pPrevSql == NULL) {
|
||||||
STableMeta* pMeterMeta = taosCacheAcquireByName(tscCacheHandle, name);
|
STableMeta* pTableMeta = taosCacheAcquireByName(tscCacheHandle, name);
|
||||||
SSuperTableMeta* pMetricMeta = taosCacheAcquireByName(tscCacheHandle, key);
|
SSuperTableMeta* pMetricMeta = taosCacheAcquireByName(tscCacheHandle, key);
|
||||||
|
|
||||||
pFinalInfo = tscAddMeterMetaInfo(pNewQueryInfo, name, pMeterMeta, pMetricMeta, pMeterMetaInfo->numOfTags,
|
pFinalInfo = tscAddMeterMetaInfo(pNewQueryInfo, name, pTableMeta, pMetricMeta, pTableMetaInfo->numOfTags,
|
||||||
pMeterMetaInfo->tagColumnIndex);
|
pTableMetaInfo->tagColumnIndex);
|
||||||
} else { // transfer the ownership of pMeterMeta/pMetricMeta to the newly create sql object.
|
} else { // transfer the ownership of pTableMeta/pMetricMeta to the newly create sql object.
|
||||||
SMeterMetaInfo* pPrevInfo = tscGetMeterMetaInfo(&pPrevSql->cmd, pPrevSql->cmd.clauseIndex, 0);
|
STableMetaInfo* pPrevInfo = tscGetTableMetaInfoFromCmd(&pPrevSql->cmd, pPrevSql->cmd.clauseIndex, 0);
|
||||||
|
|
||||||
STableMeta* pPrevMeterMeta = taosCacheTransfer(tscCacheHandle, (void**)&pPrevInfo->pMeterMeta);
|
STableMeta* pPrevMeterMeta = taosCacheTransfer(tscCacheHandle, (void**)&pPrevInfo->pTableMeta);
|
||||||
SSuperTableMeta* pPrevMetricMeta = taosCacheTransfer(tscCacheHandle, (void**)&pPrevInfo->pMetricMeta);
|
SSuperTableMeta* pPrevMetricMeta = taosCacheTransfer(tscCacheHandle, (void**)&pPrevInfo->pMetricMeta);
|
||||||
|
|
||||||
pFinalInfo = tscAddMeterMetaInfo(pNewQueryInfo, name, pPrevMeterMeta, pPrevMetricMeta, pMeterMetaInfo->numOfTags,
|
pFinalInfo = tscAddMeterMetaInfo(pNewQueryInfo, name, pPrevMeterMeta, pPrevMetricMeta, pTableMetaInfo->numOfTags,
|
||||||
pMeterMetaInfo->tagColumnIndex);
|
pTableMetaInfo->tagColumnIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(pFinalInfo->pMeterMeta != NULL && pNewQueryInfo->numOfTables == 1);
|
assert(pFinalInfo->pTableMeta != NULL && pNewQueryInfo->numOfTables == 1);
|
||||||
if (UTIL_METER_IS_SUPERTABLE(pMeterMetaInfo)) {
|
if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) {
|
||||||
assert(pFinalInfo->pMetricMeta != NULL);
|
assert(pFinalInfo->pMetricMeta != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
tscTrace(
|
tscTrace(
|
||||||
"%p new subquery: %p, tableIndex:%d, vnodeIdx:%d, type:%d, exprInfo:%d, colList:%d,"
|
"%p new subquery: %p, tableIndex:%d, vnodeIdx:%d, type:%d, exprInfo:%d, colList:%d,"
|
||||||
"fieldInfo:%d, name:%s, qrang:%" PRId64 " - %" PRId64 " order:%d, limit:%" PRId64,
|
"fieldInfo:%d, name:%s, qrang:%" PRId64 " - %" PRId64 " order:%d, limit:%" PRId64,
|
||||||
pSql, pNew, tableIndex, pMeterMetaInfo->vnodeIndex, pNewQueryInfo->type, pNewQueryInfo->exprsInfo.numOfExprs,
|
pSql, pNew, tableIndex, pTableMetaInfo->vnodeIndex, pNewQueryInfo->type, pNewQueryInfo->exprsInfo.numOfExprs,
|
||||||
pNewQueryInfo->colList.numOfCols, pNewQueryInfo->fieldsInfo.numOfOutputCols, pFinalInfo->name, pNewQueryInfo->stime,
|
pNewQueryInfo->colList.numOfCols, pNewQueryInfo->fieldsInfo.numOfOutputCols, pFinalInfo->name, pNewQueryInfo->stime,
|
||||||
pNewQueryInfo->etime, pNewQueryInfo->order.order, pNewQueryInfo->limit.limit);
|
pNewQueryInfo->etime, pNewQueryInfo->order.order, pNewQueryInfo->limit.limit);
|
||||||
|
|
||||||
|
@ -2187,14 +2189,14 @@ bool hasMoreVnodesToTry(SSqlObj* pSql) {
|
||||||
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
if (!UTIL_METER_IS_SUPERTABLE(pMeterMetaInfo) || (pMeterMetaInfo->pMetricMeta == NULL)) {
|
if (!UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo) || (pTableMetaInfo->pMetricMeta == NULL)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t totalVnode = pMeterMetaInfo->pMetricMeta->numOfVnodes;
|
int32_t totalVnode = pTableMetaInfo->pMetricMeta->numOfVnodes;
|
||||||
return pRes->numOfRows == 0 && tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) &&
|
return pRes->numOfRows == 0 && tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) &&
|
||||||
(!tscHasReachLimitation(pQueryInfo, pRes)) && (pMeterMetaInfo->vnodeIndex < totalVnode - 1);
|
(!tscHasReachLimitation(pQueryInfo, pRes)) && (pTableMetaInfo->vnodeIndex < totalVnode - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tscTryQueryNextVnode(SSqlObj* pSql, __async_cb_func_t fp) {
|
void tscTryQueryNextVnode(SSqlObj* pSql, __async_cb_func_t fp) {
|
||||||
|
@ -2209,12 +2211,12 @@ void tscTryQueryNextVnode(SSqlObj* pSql, __async_cb_func_t fp) {
|
||||||
*/
|
*/
|
||||||
assert(pRes->numOfRows == 0 && tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) && !tscHasReachLimitation(pQueryInfo, pRes));
|
assert(pRes->numOfRows == 0 && tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) && !tscHasReachLimitation(pQueryInfo, pRes));
|
||||||
|
|
||||||
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfoFromQueryInfo(pQueryInfo, 0);
|
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
int32_t totalVnode = pMeterMetaInfo->pMetricMeta->numOfVnodes;
|
int32_t totalVnode = pTableMetaInfo->pMetricMeta->numOfVnodes;
|
||||||
|
|
||||||
while (++pMeterMetaInfo->vnodeIndex < totalVnode) {
|
while (++pTableMetaInfo->vnodeIndex < totalVnode) {
|
||||||
tscTrace("%p current vnode:%d exhausted, try next:%d. total vnode:%d. current numOfRes:%d", pSql,
|
tscTrace("%p current vnode:%d exhausted, try next:%d. total vnode:%d. current numOfRes:%d", pSql,
|
||||||
pMeterMetaInfo->vnodeIndex - 1, pMeterMetaInfo->vnodeIndex, totalVnode, pRes->numOfTotalInCurrentClause);
|
pTableMetaInfo->vnodeIndex - 1, pTableMetaInfo->vnodeIndex, totalVnode, pRes->numOfTotalInCurrentClause);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* update the limit and offset value for the query on the next vnode,
|
* update the limit and offset value for the query on the next vnode,
|
||||||
|
@ -2233,7 +2235,7 @@ void tscTryQueryNextVnode(SSqlObj* pSql, __async_cb_func_t fp) {
|
||||||
|
|
||||||
assert((pRes->offset >= 0 && pRes->numOfRows == 0) || (pRes->offset == 0 && pRes->numOfRows >= 0));
|
assert((pRes->offset >= 0 && pRes->numOfRows == 0) || (pRes->offset == 0 && pRes->numOfRows >= 0));
|
||||||
tscTrace("%p new query to next vnode, vnode index:%d, limit:%" PRId64 ", offset:%" PRId64 ", glimit:%" PRId64, pSql,
|
tscTrace("%p new query to next vnode, vnode index:%d, limit:%" PRId64 ", offset:%" PRId64 ", glimit:%" PRId64, pSql,
|
||||||
pMeterMetaInfo->vnodeIndex, pQueryInfo->limit.limit, pQueryInfo->limit.offset, pQueryInfo->clauseLimit);
|
pTableMetaInfo->vnodeIndex, pQueryInfo->limit.limit, pQueryInfo->limit.offset, pQueryInfo->clauseLimit);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For project query with super table join, the numOfSub is equalled to the number of all subqueries.
|
* For project query with super table join, the numOfSub is equalled to the number of all subqueries.
|
||||||
|
@ -2319,94 +2321,3 @@ void tscTryQueryNextClause(SSqlObj* pSql, void (*queryFp)()) {
|
||||||
tscProcessSql(pSql);
|
tscProcessSql(pSql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct SinsertSupporter {
|
|
||||||
SSubqueryState* pState;
|
|
||||||
SSqlObj* pSql;
|
|
||||||
} SinsertSupporter;
|
|
||||||
|
|
||||||
void multiVnodeInsertMerge(void* param, TAOS_RES* tres, int numOfRows) {
|
|
||||||
SinsertSupporter *pSupporter = (SinsertSupporter *)param;
|
|
||||||
SSqlObj* pParentObj = pSupporter->pSql;
|
|
||||||
SSqlCmd* pParentCmd = &pParentObj->cmd;
|
|
||||||
|
|
||||||
SSubqueryState* pState = pSupporter->pState;
|
|
||||||
int32_t total = pState->numOfTotal;
|
|
||||||
|
|
||||||
// increase the total inserted rows
|
|
||||||
if (numOfRows > 0) {
|
|
||||||
pParentObj->res.numOfRows += numOfRows;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t completed = atomic_add_fetch_32(&pState->numOfCompleted, 1);
|
|
||||||
if (completed < total) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tscTrace("%p Async insertion completed, total inserted:%d", pParentObj, pParentObj->res.numOfRows);
|
|
||||||
|
|
||||||
// release data block data
|
|
||||||
pParentCmd->pDataBlocks = tscDestroyBlockArrayList(pParentCmd->pDataBlocks);
|
|
||||||
|
|
||||||
// restore user defined fp
|
|
||||||
pParentObj->fp = pParentObj->fetchFp;
|
|
||||||
|
|
||||||
// all data has been sent to vnode, call user function
|
|
||||||
(*pParentObj->fp)(pParentObj->param, tres, numOfRows);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t launchMultivnodeInsert(SSqlObj *pSql) {
|
|
||||||
SSqlRes *pRes = &pSql->res;
|
|
||||||
SSqlCmd *pCmd = &pSql->cmd;
|
|
||||||
|
|
||||||
pRes->qhandle = 1; // hack the qhandle check
|
|
||||||
SDataBlockList *pDataBlocks = pCmd->pDataBlocks;
|
|
||||||
|
|
||||||
pSql->pSubs = calloc(pDataBlocks->nSize, POINTER_BYTES);
|
|
||||||
pSql->numOfSubs = pDataBlocks->nSize;
|
|
||||||
assert(pDataBlocks->nSize > 0);
|
|
||||||
|
|
||||||
tscTrace("%p submit data to %d vnode(s)", pSql, pDataBlocks->nSize);
|
|
||||||
SSubqueryState *pState = calloc(1, sizeof(SSubqueryState));
|
|
||||||
pState->numOfTotal = pSql->numOfSubs;
|
|
||||||
|
|
||||||
pRes->code = TSDB_CODE_SUCCESS;
|
|
||||||
|
|
||||||
int32_t i = 0;
|
|
||||||
for (; i < pSql->numOfSubs; ++i) {
|
|
||||||
SinsertSupporter* pSupporter = calloc(1, sizeof(SinsertSupporter));
|
|
||||||
pSupporter->pSql = pSql;
|
|
||||||
pSupporter->pState = pState;
|
|
||||||
|
|
||||||
SSqlObj *pNew = createSubqueryObj(pSql, 0, multiVnodeInsertMerge, pSupporter, NULL);
|
|
||||||
if (pNew == NULL) {
|
|
||||||
tscError("%p failed to malloc buffer for subObj, orderOfSub:%d, reason:%s", pSql, i, strerror(errno));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
pSql->pSubs[i] = pNew;
|
|
||||||
tscTrace("%p sub:%p create subObj success. orderOfSub:%d", pSql, pNew, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i < pSql->numOfSubs) {
|
|
||||||
tscError("%p failed to prepare subObj structure and launch sub-insertion", pSql);
|
|
||||||
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
|
||||||
return pRes->code; // free all allocated resource
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int32_t j = 0; j < pSql->numOfSubs; ++j) {
|
|
||||||
SSqlObj *pSub = pSql->pSubs[j];
|
|
||||||
pSub->cmd.command = TSDB_SQL_INSERT;
|
|
||||||
int32_t code = tscCopyDataBlockToPayload(pSub, pDataBlocks->pData[j]);
|
|
||||||
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
|
||||||
tscTrace("%p prepare submit data block failed in async insertion, vnodeIdx:%d, total:%d, code:%d", pSql, j,
|
|
||||||
pDataBlocks->nSize, code);
|
|
||||||
}
|
|
||||||
|
|
||||||
tscTrace("%p sub:%p launch sub insert, orderOfSub:%d", pSql, pSub, j);
|
|
||||||
tscProcessSql(pSub);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef TDENGINE_NAME_H
|
||||||
|
#define TDENGINE_NAME_H
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
#include "taosmsg.h"
|
||||||
|
|
||||||
|
typedef struct SDataStatis {
|
||||||
|
int16_t colId;
|
||||||
|
int64_t sum;
|
||||||
|
int64_t max;
|
||||||
|
int64_t min;
|
||||||
|
int16_t maxIndex;
|
||||||
|
int16_t minIndex;
|
||||||
|
int16_t numOfNull;
|
||||||
|
} SDataStatis;
|
||||||
|
|
||||||
|
typedef struct SColumnInfoEx {
|
||||||
|
SColumnInfo info;
|
||||||
|
void* pData; // the corresponding block data in memory
|
||||||
|
} SColumnInfoEx;
|
||||||
|
|
||||||
|
int32_t extractTableName(const char *tableId, char *name);
|
||||||
|
|
||||||
|
char* extractDBName(const char *tableId, char *name);
|
||||||
|
|
||||||
|
#endif // TDENGINE_NAME_H
|
|
@ -0,0 +1,42 @@
|
||||||
|
#include "os.h"
|
||||||
|
#include "tutil.h"
|
||||||
|
|
||||||
|
#include "name.h"
|
||||||
|
#include "tstoken.h"
|
||||||
|
#include "ttokendef.h"
|
||||||
|
|
||||||
|
// todo refactor
|
||||||
|
static FORCE_INLINE const char* skipSegments(const char* input, char delim, int32_t num) {
|
||||||
|
for (int32_t i = 0; i < num; ++i) {
|
||||||
|
while (*input != 0 && *input++ != delim) {
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCE_INLINE size_t copy(char* dst, const char* src, char delimiter) {
|
||||||
|
size_t len = 0;
|
||||||
|
while (*src != delimiter && *src != 0) {
|
||||||
|
*dst++ = *src++;
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t extractTableName(const char* tableId, char* name) {
|
||||||
|
size_t offset = strcspn(tableId, &TS_PATH_DELIMITER[0]);
|
||||||
|
offset = strcspn(&tableId[offset], &TS_PATH_DELIMITER[0]);
|
||||||
|
|
||||||
|
return strncpy(name, &tableId[offset], TSDB_TABLE_NAME_LEN);
|
||||||
|
|
||||||
|
// char* r = skipSegments(tableId, TS_PATH_DELIMITER[0], 2);
|
||||||
|
// return copy(name, r, TS_PATH_DELIMITER[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* extractDBName(const char* tableId, char* name) {
|
||||||
|
size_t offset1 = strcspn(tableId, &TS_PATH_DELIMITER[0]);
|
||||||
|
size_t len = strcspn(&tableId[offset1 + 1], &TS_PATH_DELIMITER[0]);
|
||||||
|
|
||||||
|
return strncpy(name, &tableId[offset1 + 1], len);
|
||||||
|
}
|
|
@ -99,7 +99,7 @@ typedef struct {
|
||||||
} SVnodeGid;
|
} SVnodeGid;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
char tableId[TSDB_TABLE_ID_LEN];
|
||||||
int8_t type;
|
int8_t type;
|
||||||
int8_t dirty;
|
int8_t dirty;
|
||||||
uint64_t uid;
|
uint64_t uid;
|
||||||
|
@ -143,7 +143,7 @@ typedef struct {
|
||||||
} SChildTableObj;
|
} SChildTableObj;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
char tableId[TSDB_TABLE_ID_LEN];
|
||||||
int8_t type;
|
int8_t type;
|
||||||
int8_t dirty;
|
int8_t dirty;
|
||||||
uint64_t uid;
|
uint64_t uid;
|
||||||
|
|
|
@ -177,7 +177,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
|
||||||
#define TSDB_MIN_COLUMNS 2 //PRIMARY COLUMN(timestamp) + other columns
|
#define TSDB_MIN_COLUMNS 2 //PRIMARY COLUMN(timestamp) + other columns
|
||||||
|
|
||||||
#define TSDB_DNODE_NAME_LEN 63
|
#define TSDB_DNODE_NAME_LEN 63
|
||||||
#define TSDB_TABLE_NAME_LEN 64
|
#define TSDB_TABLE_NAME_LEN 192
|
||||||
#define TSDB_DB_NAME_LEN 32
|
#define TSDB_DB_NAME_LEN 32
|
||||||
#define TSDB_COL_NAME_LEN 64
|
#define TSDB_COL_NAME_LEN 64
|
||||||
#define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 16
|
#define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 16
|
||||||
|
|
|
@ -180,9 +180,9 @@ enum _mgmt_table {
|
||||||
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
|
#define TSDB_VN_WRITE_ACCCESS ((char)0x2)
|
||||||
#define TSDB_VN_ALL_ACCCESS (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
|
#define TSDB_VN_ALL_ACCCESS (TSDB_VN_READ_ACCCESS | TSDB_VN_WRITE_ACCCESS)
|
||||||
|
|
||||||
#define TSDB_COL_NORMAL 0x0U
|
#define TSDB_COL_NORMAL 0x0u
|
||||||
#define TSDB_COL_TAG 0x1U
|
#define TSDB_COL_TAG 0x1u
|
||||||
#define TSDB_COL_JOIN 0x2U
|
#define TSDB_COL_JOIN 0x2u
|
||||||
|
|
||||||
extern char *taosMsg[];
|
extern char *taosMsg[];
|
||||||
|
|
||||||
|
@ -222,13 +222,12 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct SSchema {
|
typedef struct SSchema {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
char name[TSDB_COL_NAME_LEN + 1];
|
char name[TSDB_COL_NAME_LEN];
|
||||||
int16_t colId;
|
int16_t colId;
|
||||||
int16_t bytes;
|
int16_t bytes;
|
||||||
} SSchema;
|
} SSchema;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t vgId;
|
|
||||||
int32_t vnode; //the index of vnode
|
int32_t vnode; //the index of vnode
|
||||||
uint32_t ip;
|
uint32_t ip;
|
||||||
} SVnodeDesc;
|
} SVnodeDesc;
|
||||||
|
@ -255,14 +254,14 @@ typedef struct {
|
||||||
uint64_t uid;
|
uint64_t uid;
|
||||||
uint64_t superTableUid;
|
uint64_t superTableUid;
|
||||||
uint64_t createdTime;
|
uint64_t createdTime;
|
||||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
char tableId[TSDB_TABLE_ID_LEN];
|
||||||
char superTableId[TSDB_TABLE_ID_LEN + 1];
|
char superTableId[TSDB_TABLE_ID_LEN];
|
||||||
char data[];
|
char data[];
|
||||||
} SMDCreateTableMsg;
|
} SMDCreateTableMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
char tableId[TSDB_TABLE_ID_LEN];
|
||||||
char db[TSDB_DB_NAME_LEN + 1];
|
char db[TSDB_DB_NAME_LEN];
|
||||||
int8_t igExists;
|
int8_t igExists;
|
||||||
int16_t numOfTags;
|
int16_t numOfTags;
|
||||||
int16_t numOfColumns;
|
int16_t numOfColumns;
|
||||||
|
@ -273,13 +272,13 @@ typedef struct {
|
||||||
} SCMCreateTableMsg;
|
} SCMCreateTableMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
char tableId[TSDB_TABLE_ID_LEN];
|
||||||
int8_t igNotExists;
|
int8_t igNotExists;
|
||||||
} SCMDropTableMsg;
|
} SCMDropTableMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
char tableId[TSDB_TABLE_ID_LEN];
|
||||||
char db[TSDB_DB_NAME_LEN + 1];
|
char db[TSDB_DB_NAME_LEN];
|
||||||
int16_t type; /* operation type */
|
int16_t type; /* operation type */
|
||||||
char tagVal[TSDB_MAX_BYTES_PER_ROW];
|
char tagVal[TSDB_MAX_BYTES_PER_ROW];
|
||||||
int8_t numOfCols; /* number of schema */
|
int8_t numOfCols; /* number of schema */
|
||||||
|
@ -396,7 +395,7 @@ typedef struct SSqlBinaryExprInfo {
|
||||||
|
|
||||||
typedef struct SSqlFunctionExpr {
|
typedef struct SSqlFunctionExpr {
|
||||||
SSqlFuncExprMsg pBase;
|
SSqlFuncExprMsg pBase;
|
||||||
SSqlBinaryExprInfo pBinExprInfo;
|
SSqlBinaryExprInfo binExprInfo;
|
||||||
int16_t resBytes;
|
int16_t resBytes;
|
||||||
int16_t resType;
|
int16_t resType;
|
||||||
int16_t interResBytes;
|
int16_t interResBytes;
|
||||||
|
@ -445,6 +444,11 @@ typedef struct STableSidExtInfo {
|
||||||
char tags[];
|
char tags[];
|
||||||
} STableSidExtInfo;
|
} STableSidExtInfo;
|
||||||
|
|
||||||
|
typedef struct STimeWindow {
|
||||||
|
TSKEY skey;
|
||||||
|
TSKEY ekey;
|
||||||
|
} STimeWindow;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the outputCols is equalled to or larger than numOfCols
|
* the outputCols is equalled to or larger than numOfCols
|
||||||
* e.g., select min(colName), max(colName), avg(colName) from table
|
* e.g., select min(colName), max(colName), avg(colName) from table
|
||||||
|
@ -452,18 +456,17 @@ typedef struct STableSidExtInfo {
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int16_t vnode;
|
int16_t vnode;
|
||||||
int32_t numOfSids;
|
int32_t numOfTables;
|
||||||
uint64_t pSidExtInfo; // table id & tag info ptr, in windows pointer may
|
uint64_t pSidExtInfo; // table id & tag info ptr, in windows pointer may
|
||||||
|
|
||||||
uint64_t uid;
|
uint64_t uid;
|
||||||
TSKEY skey;
|
STimeWindow window;
|
||||||
TSKEY ekey;
|
|
||||||
|
|
||||||
int16_t order;
|
int16_t order;
|
||||||
int16_t orderColId;
|
int16_t orderColId;
|
||||||
|
|
||||||
int16_t numOfCols; // the number of columns will be load from vnode
|
int16_t numOfCols; // the number of columns will be load from vnode
|
||||||
char intervalTimeUnit; // time interval type, for revisement of interval(1d)
|
char slidingTimeUnit; // time interval type, for revisement of interval(1d)
|
||||||
|
|
||||||
int64_t intervalTime; // time interval for aggregation, in million second
|
int64_t intervalTime; // time interval for aggregation, in million second
|
||||||
int64_t slidingTime; // value for sliding window
|
int64_t slidingTime; // value for sliding window
|
||||||
|
@ -677,28 +680,27 @@ typedef struct {
|
||||||
int32_t list[]; /* offset of SVnodeSidList, compared to the SSuperTableMeta struct */
|
int32_t list[]; /* offset of SVnodeSidList, compared to the SSuperTableMeta struct */
|
||||||
} SSuperTableMeta;
|
} SSuperTableMeta;
|
||||||
|
|
||||||
typedef struct STableMeta {
|
typedef struct STableMetaMsg {
|
||||||
char tableId[TSDB_TABLE_ID_LEN + 1]; // note: This field must be at the front
|
char tableId[TSDB_TABLE_ID_LEN]; // note: This field must be at the front
|
||||||
int32_t contLen;
|
int32_t contLen;
|
||||||
uint8_t numOfTags : 6;
|
uint8_t numOfTags;
|
||||||
uint8_t precision : 2;
|
uint8_t precision;
|
||||||
uint8_t tableType : 4;
|
uint8_t tableType;
|
||||||
uint8_t index : 4; // used locally
|
|
||||||
int16_t numOfColumns;
|
int16_t numOfColumns;
|
||||||
int16_t rowSize; // used locally, calculated in client
|
|
||||||
int16_t sversion;
|
int16_t sversion;
|
||||||
|
|
||||||
int8_t numOfVpeers;
|
int8_t numOfVpeers;
|
||||||
SVnodeDesc vpeerDesc[TSDB_VNODES_SUPPORT];
|
SVnodeDesc vpeerDesc[TSDB_VNODES_SUPPORT];
|
||||||
int32_t sid;
|
int32_t sid;
|
||||||
int32_t vgid;
|
int32_t vgid;
|
||||||
uint64_t uid;
|
uint64_t uid;
|
||||||
SSchema schema[];
|
SSchema schema[];
|
||||||
} STableMeta;
|
} STableMetaMsg;
|
||||||
|
|
||||||
typedef struct SMultiTableMeta {
|
typedef struct SMultiTableMeta {
|
||||||
int32_t numOfTables;
|
int32_t numOfTables;
|
||||||
int32_t contLen;
|
int32_t contLen;
|
||||||
STableMeta metas[];
|
STableMetaMsg metas[];
|
||||||
} SMultiTableMeta;
|
} SMultiTableMeta;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -718,9 +720,9 @@ typedef struct {
|
||||||
char payload[];
|
char payload[];
|
||||||
} SCMShowMsg;
|
} SCMShowMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct SCMShowRsp {
|
||||||
uint64_t qhandle;
|
uint64_t qhandle;
|
||||||
STableMeta tableMeta;
|
STableMetaMsg tableMeta;
|
||||||
} SCMShowRsp;
|
} SCMShowRsp;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -36,7 +36,7 @@ void *mgmtBuildCreateChildTableMsg(SCMCreateTableMsg *pCreate, SChildTableObj *p
|
||||||
int32_t mgmtDropChildTable(SQueuedMsg *newMsg, SChildTableObj *pTable);
|
int32_t mgmtDropChildTable(SQueuedMsg *newMsg, SChildTableObj *pTable);
|
||||||
int32_t mgmtModifyChildTableTagValueByName(SChildTableObj *pTable, char *tagName, char *nContent);
|
int32_t mgmtModifyChildTableTagValueByName(SChildTableObj *pTable, char *tagName, char *nContent);
|
||||||
|
|
||||||
int32_t mgmtGetChildTableMeta(SDbObj *pDb, SChildTableObj *pTable, STableMeta *pMeta, bool usePublicIp);
|
int32_t mgmtGetChildTableMeta(SDbObj *pDb, SChildTableObj *pTable, STableMetaMsg *pMeta, bool usePublicIp);
|
||||||
|
|
||||||
void mgmtDropAllChildTables(SDbObj *pDropDb);
|
void mgmtDropAllChildTables(SDbObj *pDropDb);
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ int32_t mgmtDropNormalTable(SQueuedMsg *newMsg, SNormalTableObj *pTable);
|
||||||
int32_t mgmtAddNormalTableColumn(SNormalTableObj *pTable, SSchema schema[], int32_t ncols);
|
int32_t mgmtAddNormalTableColumn(SNormalTableObj *pTable, SSchema schema[], int32_t ncols);
|
||||||
int32_t mgmtDropNormalTableColumnByName(SNormalTableObj *pTable, char *colName);
|
int32_t mgmtDropNormalTableColumnByName(SNormalTableObj *pTable, char *colName);
|
||||||
|
|
||||||
int32_t mgmtGetNormalTableMeta(SDbObj *pDb, SNormalTableObj *pTable, STableMeta *pMeta, bool usePublicIp);
|
int32_t mgmtGetNormalTableMeta(SDbObj *pDb, SNormalTableObj *pTable, STableMetaMsg *pMeta, bool usePublicIp);
|
||||||
|
|
||||||
void mgmtDropAllNormalTables(SDbObj *pDropDb);
|
void mgmtDropAllNormalTables(SDbObj *pDropDb);
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ int32_t mgmtInitShell();
|
||||||
void mgmtCleanUpShell();
|
void mgmtCleanUpShell();
|
||||||
void mgmtAddShellMsgHandle(uint8_t msgType, void (*fp)(SQueuedMsg *queuedMsg));
|
void mgmtAddShellMsgHandle(uint8_t msgType, void (*fp)(SQueuedMsg *queuedMsg));
|
||||||
|
|
||||||
typedef int32_t (*SShowMetaFp)(STableMeta *pMeta, SShowObj *pShow, void *pConn);
|
typedef int32_t (*SShowMetaFp)(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||||
typedef int32_t (*SShowRetrieveFp)(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
typedef int32_t (*SShowRetrieveFp)(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||||
void mgmtAddShellShowMetaHandle(uint8_t showType, SShowMetaFp fp);
|
void mgmtAddShellShowMetaHandle(uint8_t showType, SShowMetaFp fp);
|
||||||
void mgmtAddShellShowRetrieveHandle(uint8_t showType, SShowRetrieveFp fp);
|
void mgmtAddShellShowRetrieveHandle(uint8_t showType, SShowRetrieveFp fp);
|
||||||
|
|
|
@ -39,7 +39,7 @@ int32_t mgmtModifySuperTableTagNameByName(SSuperTableObj *pTable, char *oldTagNa
|
||||||
int32_t mgmtAddSuperTableColumn(SSuperTableObj *pTable, SSchema schema[], int32_t ncols);
|
int32_t mgmtAddSuperTableColumn(SSuperTableObj *pTable, SSchema schema[], int32_t ncols);
|
||||||
int32_t mgmtDropSuperTableColumnByName(SSuperTableObj *pTable, char *colName);
|
int32_t mgmtDropSuperTableColumnByName(SSuperTableObj *pTable, char *colName);
|
||||||
|
|
||||||
int32_t mgmtGetSuperTableMeta(SDbObj *pDb, SSuperTableObj *pTable, STableMeta *pMeta, bool usePublicIp);
|
int32_t mgmtGetSuperTableMeta(SDbObj *pDb, SSuperTableObj *pTable, STableMetaMsg *pMeta, bool usePublicIp);
|
||||||
void * mgmtGetSuperTableVgroup(SSuperTableObj *pStable);
|
void * mgmtGetSuperTableVgroup(SSuperTableObj *pStable);
|
||||||
|
|
||||||
int32_t mgmtFindSuperTableTagIndex(SSuperTableObj *pTable, const char *tagName);
|
int32_t mgmtFindSuperTableTagIndex(SSuperTableObj *pTable, const char *tagName);
|
||||||
|
|
|
@ -30,7 +30,7 @@ void mgmtCleanUpTables();
|
||||||
STableInfo* mgmtGetTable(char *tableId);
|
STableInfo* mgmtGetTable(char *tableId);
|
||||||
|
|
||||||
STableInfo* mgmtGetTableByPos(uint32_t dnodeIp, int32_t vnode, int32_t sid);
|
STableInfo* mgmtGetTableByPos(uint32_t dnodeIp, int32_t vnode, int32_t sid);
|
||||||
int32_t mgmtGetTableMeta(SDbObj *pDb, STableInfo *pTable, STableMeta *pMeta, bool usePublicIp);
|
int32_t mgmtGetTableMeta(SDbObj *pDb, STableInfo *pTable, STableMetaMsg *pMeta, bool usePublicIp);
|
||||||
|
|
||||||
void mgmtAddTableIntoSuperTable(SSuperTableObj *pStable);
|
void mgmtAddTableIntoSuperTable(SSuperTableObj *pStable);
|
||||||
void mgmtRemoveTableFromSuperTable(SSuperTableObj *pStable);
|
void mgmtRemoveTableFromSuperTable(SSuperTableObj *pStable);
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "tschemautil.h"
|
|
||||||
#include "tscompression.h"
|
#include "tscompression.h"
|
||||||
#include "tskiplist.h"
|
#include "tskiplist.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
|
@ -443,7 +442,7 @@ int32_t mgmtModifyChildTableTagValueByName(SChildTableObj *pTable, char *tagName
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mgmtGetChildTableMeta(SDbObj *pDb, SChildTableObj *pTable, STableMeta *pMeta, bool usePublicIp) {
|
int32_t mgmtGetChildTableMeta(SDbObj *pDb, SChildTableObj *pTable, STableMetaMsg *pMeta, bool usePublicIp) {
|
||||||
pMeta->uid = htobe64(pTable->uid);
|
pMeta->uid = htobe64(pTable->uid);
|
||||||
pMeta->sid = htonl(pTable->sid);
|
pMeta->sid = htonl(pTable->sid);
|
||||||
pMeta->vgid = htonl(pTable->vgId);
|
pMeta->vgid = htonl(pTable->vgId);
|
||||||
|
@ -452,8 +451,8 @@ int32_t mgmtGetChildTableMeta(SDbObj *pDb, SChildTableObj *pTable, STableMeta *p
|
||||||
pMeta->numOfTags = pTable->superTable->numOfTags;
|
pMeta->numOfTags = pTable->superTable->numOfTags;
|
||||||
pMeta->numOfColumns = htons(pTable->superTable->numOfColumns);
|
pMeta->numOfColumns = htons(pTable->superTable->numOfColumns);
|
||||||
pMeta->tableType = pTable->type;
|
pMeta->tableType = pTable->type;
|
||||||
pMeta->contLen = sizeof(STableMeta) + mgmtSetSchemaFromSuperTable(pMeta->schema, pTable->superTable);
|
pMeta->contLen = sizeof(STableMetaMsg) + mgmtSetSchemaFromSuperTable(pMeta->schema, pTable->superTable);
|
||||||
strcpy(pMeta->tableId, pTable->tableId);
|
strncpy(pMeta->tableId, pTable->tableId, tListLen(pTable->tableId));
|
||||||
|
|
||||||
SVgObj *pVgroup = mgmtGetVgroup(pTable->vgId);
|
SVgObj *pVgroup = mgmtGetVgroup(pTable->vgId);
|
||||||
if (pVgroup == NULL) {
|
if (pVgroup == NULL) {
|
||||||
|
@ -466,7 +465,6 @@ int32_t mgmtGetChildTableMeta(SDbObj *pDb, SChildTableObj *pTable, STableMeta *p
|
||||||
pMeta->vpeerDesc[i].ip = pVgroup->vnodeGid[i].privateIp;
|
pMeta->vpeerDesc[i].ip = pVgroup->vnodeGid[i].privateIp;
|
||||||
}
|
}
|
||||||
pMeta->vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode);
|
pMeta->vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode);
|
||||||
pMeta->vpeerDesc[i].vgId = htonl(pVgroup->vgId);
|
|
||||||
}
|
}
|
||||||
pMeta->numOfVpeers = pVgroup->numOfVnodes;
|
pMeta->numOfVpeers = pVgroup->numOfVnodes;
|
||||||
|
|
||||||
|
|
|
@ -15,24 +15,26 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taoserror.h"
|
|
||||||
#include "tschemautil.h"
|
#include "mgmtDb.h"
|
||||||
#include "tstatus.h"
|
|
||||||
#include "tutil.h"
|
|
||||||
#include "mnode.h"
|
|
||||||
#include "mgmtAcct.h"
|
#include "mgmtAcct.h"
|
||||||
#include "mgmtBalance.h"
|
#include "mgmtBalance.h"
|
||||||
#include "mgmtDb.h"
|
|
||||||
#include "mgmtDnode.h"
|
|
||||||
#include "mgmtMnode.h"
|
|
||||||
#include "mgmtGrant.h"
|
|
||||||
#include "mgmtShell.h"
|
|
||||||
#include "mgmtNormalTable.h"
|
|
||||||
#include "mgmtChildTable.h"
|
#include "mgmtChildTable.h"
|
||||||
|
#include "mgmtDnode.h"
|
||||||
|
#include "mgmtGrant.h"
|
||||||
|
#include "mgmtMnode.h"
|
||||||
|
#include "mgmtNormalTable.h"
|
||||||
|
#include "mgmtShell.h"
|
||||||
#include "mgmtSuperTable.h"
|
#include "mgmtSuperTable.h"
|
||||||
#include "mgmtTable.h"
|
#include "mgmtTable.h"
|
||||||
#include "mgmtUser.h"
|
#include "mgmtUser.h"
|
||||||
#include "mgmtVgroup.h"
|
#include "mgmtVgroup.h"
|
||||||
|
#include "mnode.h"
|
||||||
|
|
||||||
|
#include "taoserror.h"
|
||||||
|
#include "tstatus.h"
|
||||||
|
#include "tutil.h"
|
||||||
|
#include "name.h"
|
||||||
|
|
||||||
static void *tsDbSdb = NULL;
|
static void *tsDbSdb = NULL;
|
||||||
static int32_t tsDbUpdateSize;
|
static int32_t tsDbUpdateSize;
|
||||||
|
@ -41,7 +43,7 @@ static int32_t mgmtCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate);
|
||||||
static void mgmtDropDb(void *handle, void *tmrId);
|
static void mgmtDropDb(void *handle, void *tmrId);
|
||||||
static void mgmtSetDbDirty(SDbObj *pDb);
|
static void mgmtSetDbDirty(SDbObj *pDb);
|
||||||
|
|
||||||
static int32_t mgmtGetDbMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn);
|
static int32_t mgmtGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||||
static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||||
static void mgmtProcessCreateDbMsg(SQueuedMsg *pMsg);
|
static void mgmtProcessCreateDbMsg(SQueuedMsg *pMsg);
|
||||||
static void mgmtProcessAlterDbMsg(SQueuedMsg *pMsg);
|
static void mgmtProcessAlterDbMsg(SQueuedMsg *pMsg);
|
||||||
|
@ -421,10 +423,10 @@ void mgmtCleanUpDbs() {
|
||||||
sdbCloseTable(tsDbSdb);
|
sdbCloseTable(tsDbSdb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mgmtGetDbMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn) {
|
static int32_t mgmtGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
|
|
||||||
SSchema *pSchema = tsGetSchema(pMeta);
|
SSchema *pSchema = pMeta->schema;
|
||||||
SUserObj *pUser = mgmtGetUserFromConn(pConn);
|
SUserObj *pUser = mgmtGetUserFromConn(pConn);
|
||||||
if (pUser == NULL) return 0;
|
if (pUser == NULL) return 0;
|
||||||
|
|
||||||
|
@ -436,7 +438,7 @@ static int32_t mgmtGetDbMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
|
|
||||||
pShow->bytes[cols] = 8;
|
pShow->bytes[cols] = 8;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
strcpy(pSchema[cols].name, "created time");
|
strcpy(pSchema[cols].name, "created_time");
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tmodule.h"
|
#include "tmodule.h"
|
||||||
#include "tschemautil.h"
|
|
||||||
#include "tstatus.h"
|
#include "tstatus.h"
|
||||||
#include "mgmtBalance.h"
|
#include "mgmtBalance.h"
|
||||||
#include "mgmtDnode.h"
|
#include "mgmtDnode.h"
|
||||||
|
@ -39,11 +38,11 @@ void (*mgmtSetDnodeUnRemoveFp)(SDnodeObj *pDnode) = NULL;
|
||||||
static SDnodeObj tsDnodeObj = {0};
|
static SDnodeObj tsDnodeObj = {0};
|
||||||
static void * mgmtGetNextDnode(SShowObj *pShow, SDnodeObj **pDnode);
|
static void * mgmtGetNextDnode(SShowObj *pShow, SDnodeObj **pDnode);
|
||||||
static bool mgmtCheckConfigShow(SGlobalConfig *cfg);
|
static bool mgmtCheckConfigShow(SGlobalConfig *cfg);
|
||||||
static int32_t mgmtGetModuleMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn);
|
static int32_t mgmtGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||||
static int32_t mgmtRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
static int32_t mgmtRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||||
static int32_t mgmtGetConfigMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn);
|
static int32_t mgmtGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||||
static int32_t mgmtRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
static int32_t mgmtRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||||
static int32_t mgmtGetVnodeMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn);
|
static int32_t mgmtGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||||
static int32_t mgmtRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
static int32_t mgmtRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||||
static void mgmtProcessCfgDnodeMsg(SQueuedMsg *pMsg);
|
static void mgmtProcessCfgDnodeMsg(SQueuedMsg *pMsg);
|
||||||
static void mgmtProcessCfgDnodeMsgRsp(SRpcMsg *rpcMsg) ;
|
static void mgmtProcessCfgDnodeMsgRsp(SRpcMsg *rpcMsg) ;
|
||||||
|
@ -74,7 +73,7 @@ bool mgmtCheckModuleInDnode(SDnodeObj *pDnode, int32_t moduleType) {
|
||||||
return status > 0;
|
return status > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mgmtGetModuleMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn) {
|
int32_t mgmtGetModuleMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
|
|
||||||
SUserObj *pUser = mgmtGetUserFromConn(pConn);
|
SUserObj *pUser = mgmtGetUserFromConn(pConn);
|
||||||
|
@ -82,7 +81,7 @@ int32_t mgmtGetModuleMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
|
|
||||||
if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS;
|
if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS;
|
||||||
|
|
||||||
SSchema *pSchema = tsGetSchema(pMeta);
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
pShow->bytes[cols] = 16;
|
pShow->bytes[cols] = 16;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
@ -167,7 +166,7 @@ int32_t mgmtRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pCo
|
||||||
return numOfRows;
|
return numOfRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mgmtGetConfigMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn) {
|
static int32_t mgmtGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
|
|
||||||
SUserObj *pUser = mgmtGetUserFromConn(pConn);
|
SUserObj *pUser = mgmtGetUserFromConn(pConn);
|
||||||
|
@ -175,7 +174,7 @@ static int32_t mgmtGetConfigMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn
|
||||||
|
|
||||||
if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS;
|
if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS;
|
||||||
|
|
||||||
SSchema *pSchema = tsGetSchema(pMeta);
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
pShow->bytes[cols] = TSDB_CFG_OPTION_LEN;
|
pShow->bytes[cols] = TSDB_CFG_OPTION_LEN;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
@ -255,13 +254,13 @@ static int32_t mgmtRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, vo
|
||||||
return numOfRows;
|
return numOfRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mgmtGetVnodeMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn) {
|
static int32_t mgmtGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
SUserObj *pUser = mgmtGetUserFromConn(pConn);
|
SUserObj *pUser = mgmtGetUserFromConn(pConn);
|
||||||
if (pUser == NULL) return 0;
|
if (pUser == NULL) return 0;
|
||||||
if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS;
|
if (strcmp(pUser->user, "root") != 0) return TSDB_CODE_NO_RIGHTS;
|
||||||
|
|
||||||
SSchema *pSchema = tsGetSchema(pMeta);
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
pShow->bytes[cols] = 4;
|
pShow->bytes[cols] = 4;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||||
|
@ -277,7 +276,7 @@ static int32_t mgmtGetVnodeMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn)
|
||||||
|
|
||||||
pShow->bytes[cols] = 12;
|
pShow->bytes[cols] = 12;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
strcpy(pSchema[cols].name, "sync status");
|
strcpy(pSchema[cols].name, "sync_status");
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
|
|
|
@ -521,7 +521,7 @@ static int32_t mgmtSetSchemaFromNormalTable(SSchema *pSchema, SNormalTableObj *p
|
||||||
return numOfCols * sizeof(SSchema);
|
return numOfCols * sizeof(SSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mgmtGetNormalTableMeta(SDbObj *pDb, SNormalTableObj *pTable, STableMeta *pMeta, bool usePublicIp) {
|
int32_t mgmtGetNormalTableMeta(SDbObj *pDb, SNormalTableObj *pTable, STableMetaMsg *pMeta, bool usePublicIp) {
|
||||||
pMeta->uid = htobe64(pTable->uid);
|
pMeta->uid = htobe64(pTable->uid);
|
||||||
pMeta->sid = htonl(pTable->sid);
|
pMeta->sid = htonl(pTable->sid);
|
||||||
pMeta->vgid = htonl(pTable->vgId);
|
pMeta->vgid = htonl(pTable->vgId);
|
||||||
|
@ -530,7 +530,9 @@ int32_t mgmtGetNormalTableMeta(SDbObj *pDb, SNormalTableObj *pTable, STableMeta
|
||||||
pMeta->numOfTags = 0;
|
pMeta->numOfTags = 0;
|
||||||
pMeta->numOfColumns = htons(pTable->numOfColumns);
|
pMeta->numOfColumns = htons(pTable->numOfColumns);
|
||||||
pMeta->tableType = pTable->type;
|
pMeta->tableType = pTable->type;
|
||||||
pMeta->contLen = sizeof(STableMeta) + mgmtSetSchemaFromNormalTable(pMeta->schema, pTable);
|
pMeta->contLen = sizeof(STableMetaMsg) + mgmtSetSchemaFromNormalTable(pMeta->schema, pTable);
|
||||||
|
|
||||||
|
strncpy(pMeta->tableId, pTable->tableId, tListLen(pTable->tableId));
|
||||||
|
|
||||||
SVgObj *pVgroup = mgmtGetVgroup(pTable->vgId);
|
SVgObj *pVgroup = mgmtGetVgroup(pTable->vgId);
|
||||||
if (pVgroup == NULL) {
|
if (pVgroup == NULL) {
|
||||||
|
@ -542,8 +544,8 @@ int32_t mgmtGetNormalTableMeta(SDbObj *pDb, SNormalTableObj *pTable, STableMeta
|
||||||
} else {
|
} else {
|
||||||
pMeta->vpeerDesc[i].ip = pVgroup->vnodeGid[i].privateIp;
|
pMeta->vpeerDesc[i].ip = pVgroup->vnodeGid[i].privateIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
pMeta->vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode);
|
pMeta->vpeerDesc[i].vnode = htonl(pVgroup->vnodeGid[i].vnode);
|
||||||
pMeta->vpeerDesc[i].vgId = htonl(pVgroup->vgId);
|
|
||||||
}
|
}
|
||||||
pMeta->numOfVpeers = pVgroup->numOfVnodes;
|
pMeta->numOfVpeers = pVgroup->numOfVnodes;
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "tschemautil.h"
|
|
||||||
#include "mgmtMnode.h"
|
#include "mgmtMnode.h"
|
||||||
#include "mgmtProfile.h"
|
#include "mgmtProfile.h"
|
||||||
#include "mgmtShell.h"
|
#include "mgmtShell.h"
|
||||||
|
@ -137,10 +136,10 @@ int32_t mgmtGetQueries(SShowObj *pShow, void *pConn) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mgmtGetQueryMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn) {
|
int32_t mgmtGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
|
|
||||||
SSchema *pSchema = tsGetSchema(pMeta);
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
pShow->bytes[cols] = TSDB_USER_LEN;
|
pShow->bytes[cols] = TSDB_USER_LEN;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
@ -336,9 +335,9 @@ int32_t mgmtGetStreams(SShowObj *pShow, void *pConn) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mgmtGetStreamMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn) {
|
int32_t mgmtGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
SSchema *pSchema = tsGetSchema(pMeta);
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
pShow->bytes[cols] = TSDB_USER_LEN;
|
pShow->bytes[cols] = TSDB_USER_LEN;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
@ -600,11 +599,11 @@ int mgmtGetConns(SShowObj *pShow, void *pConn) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mgmtGetConnsMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn) {
|
int32_t mgmtGetConnsMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
|
|
||||||
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN;
|
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN;
|
||||||
SSchema *pSchema = tsGetSchema(pMeta);
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
strcpy(pSchema[cols].name, "user");
|
strcpy(pSchema[cols].name, "user");
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
#include "mgmtUser.h"
|
#include "mgmtUser.h"
|
||||||
#include "mgmtVgroup.h"
|
#include "mgmtVgroup.h"
|
||||||
|
|
||||||
typedef int32_t (*SShowMetaFp)(STableMeta *pMeta, SShowObj *pShow, void *pConn);
|
typedef int32_t (*SShowMetaFp)(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||||
typedef int32_t (*SShowRetrieveFp)(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
typedef int32_t (*SShowRetrieveFp)(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||||
|
|
||||||
static int mgmtShellRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey);
|
static int mgmtShellRetriveAuth(char *user, char *spi, char *encrypt, char *secret, char *ckey);
|
||||||
|
|
|
@ -15,15 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taosmsg.h"
|
|
||||||
#include "tschemautil.h"
|
|
||||||
#include "tscompression.h"
|
|
||||||
#include "tskiplist.h"
|
|
||||||
#include "tsqlfunction.h"
|
|
||||||
#include "ttime.h"
|
|
||||||
#include "tstatus.h"
|
|
||||||
#include "tutil.h"
|
|
||||||
#include "mnode.h"
|
|
||||||
#include "mgmtAcct.h"
|
#include "mgmtAcct.h"
|
||||||
#include "mgmtChildTable.h"
|
#include "mgmtChildTable.h"
|
||||||
#include "mgmtDb.h"
|
#include "mgmtDb.h"
|
||||||
|
@ -34,6 +26,10 @@
|
||||||
#include "mgmtTable.h"
|
#include "mgmtTable.h"
|
||||||
#include "mgmtUser.h"
|
#include "mgmtUser.h"
|
||||||
#include "mgmtVgroup.h"
|
#include "mgmtVgroup.h"
|
||||||
|
#include "mnode.h"
|
||||||
|
|
||||||
|
#include "name.h"
|
||||||
|
#include "tsqlfunction.h"
|
||||||
|
|
||||||
static void *tsSuperTableSdb;
|
static void *tsSuperTableSdb;
|
||||||
static int32_t tsSuperTableUpdateSize;
|
static int32_t tsSuperTableUpdateSize;
|
||||||
|
@ -47,7 +43,7 @@ static void *mgmtSuperTableActionDecode(void *row, char *str, int32_t size, int3
|
||||||
static void *mgmtSuperTableActionReset(void *row, char *str, int32_t size, int32_t *ssize);
|
static void *mgmtSuperTableActionReset(void *row, char *str, int32_t size, int32_t *ssize);
|
||||||
static void *mgmtSuperTableActionDestroy(void *row, char *str, int32_t size, int32_t *ssize);
|
static void *mgmtSuperTableActionDestroy(void *row, char *str, int32_t size, int32_t *ssize);
|
||||||
static int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
static int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||||
static int32_t mgmtGetShowSuperTableMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn);
|
static int32_t mgmtGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||||
|
|
||||||
static void mgmtDestroySuperTable(SSuperTableObj *pTable) {
|
static void mgmtDestroySuperTable(SSuperTableObj *pTable) {
|
||||||
free(pTable->schema);
|
free(pTable->schema);
|
||||||
|
@ -490,14 +486,14 @@ int32_t mgmtDropSuperTableColumnByName(SSuperTableObj *pStable, char *colName) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mgmtGetShowSuperTableMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn) {
|
static int32_t mgmtGetShowSuperTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
SDbObj *pDb = mgmtGetDb(pShow->db);
|
SDbObj *pDb = mgmtGetDb(pShow->db);
|
||||||
if (pDb == NULL) {
|
if (pDb == NULL) {
|
||||||
return TSDB_CODE_DB_NOT_SELECTED;
|
return TSDB_CODE_DB_NOT_SELECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
SSchema *pSchema = tsGetSchema(pMeta);
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN;
|
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
@ -507,7 +503,7 @@ static int32_t mgmtGetShowSuperTableMeta(STableMeta *pMeta, SShowObj *pShow, voi
|
||||||
|
|
||||||
pShow->bytes[cols] = 8;
|
pShow->bytes[cols] = 8;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
strcpy(pSchema[cols].name, "create time");
|
strcpy(pSchema[cols].name, "create_time");
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
|
@ -655,7 +651,7 @@ int32_t mgmtSetSchemaFromSuperTable(SSchema *pSchema, SSuperTableObj *pTable) {
|
||||||
return (pTable->numOfColumns + pTable->numOfTags) * sizeof(SSchema);
|
return (pTable->numOfColumns + pTable->numOfTags) * sizeof(SSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mgmtGetSuperTableMeta(SDbObj *pDb, SSuperTableObj *pTable, STableMeta *pMeta, bool usePublicIp) {
|
int32_t mgmtGetSuperTableMeta(SDbObj *pDb, SSuperTableObj *pTable, STableMetaMsg *pMeta, bool usePublicIp) {
|
||||||
pMeta->uid = htobe64(pTable->uid);
|
pMeta->uid = htobe64(pTable->uid);
|
||||||
pMeta->sid = htonl(pTable->sid);
|
pMeta->sid = htonl(pTable->sid);
|
||||||
pMeta->vgid = htonl(pTable->vgId);
|
pMeta->vgid = htonl(pTable->vgId);
|
||||||
|
@ -664,7 +660,7 @@ int32_t mgmtGetSuperTableMeta(SDbObj *pDb, SSuperTableObj *pTable, STableMeta *p
|
||||||
pMeta->numOfTags = pTable->numOfTags;
|
pMeta->numOfTags = pTable->numOfTags;
|
||||||
pMeta->numOfColumns = htons(pTable->numOfColumns);
|
pMeta->numOfColumns = htons(pTable->numOfColumns);
|
||||||
pMeta->tableType = pTable->type;
|
pMeta->tableType = pTable->type;
|
||||||
pMeta->contLen = sizeof(STableMeta) + mgmtSetSchemaFromSuperTable(pMeta->schema, pTable);
|
pMeta->contLen = sizeof(STableMetaMsg) + mgmtSetSchemaFromSuperTable(pMeta->schema, pTable);
|
||||||
strcpy(pMeta->tableId, pTable->tableId);
|
strcpy(pMeta->tableId, pTable->tableId);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#include "mgmtTable.h"
|
#include "mgmtTable.h"
|
||||||
#include "mgmtAcct.h"
|
#include "mgmtAcct.h"
|
||||||
#include "mgmtChildTable.h"
|
#include "mgmtChildTable.h"
|
||||||
|
@ -29,17 +31,17 @@
|
||||||
#include "mgmtUser.h"
|
#include "mgmtUser.h"
|
||||||
#include "mgmtVgroup.h"
|
#include "mgmtVgroup.h"
|
||||||
#include "mnode.h"
|
#include "mnode.h"
|
||||||
#include "os.h"
|
|
||||||
#include "qast.h"
|
#include "qast.h"
|
||||||
#include "qextbuffer.h"
|
#include "qextbuffer.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "tschemautil.h"
|
|
||||||
#include "tscompression.h"
|
#include "tscompression.h"
|
||||||
#include "tskiplist.h"
|
#include "tskiplist.h"
|
||||||
#include "tsqlfunction.h"
|
#include "tsqlfunction.h"
|
||||||
#include "tstatus.h"
|
#include "tstatus.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
|
#include "name.h"
|
||||||
|
|
||||||
extern void *tsNormalTableSdb;
|
extern void *tsNormalTableSdb;
|
||||||
extern void *tsChildTableSdb;
|
extern void *tsChildTableSdb;
|
||||||
|
@ -52,9 +54,10 @@ static void mgmtProcessMultiTableMetaMsg(SQueuedMsg *queueMsg);
|
||||||
static void mgmtProcessSuperTableMetaMsg(SQueuedMsg *queueMsg);
|
static void mgmtProcessSuperTableMetaMsg(SQueuedMsg *queueMsg);
|
||||||
static void mgmtProcessCreateTableRsp(SRpcMsg *rpcMsg);
|
static void mgmtProcessCreateTableRsp(SRpcMsg *rpcMsg);
|
||||||
static void mgmtProcessDropTableRsp(SRpcMsg *rpcMsg);
|
static void mgmtProcessDropTableRsp(SRpcMsg *rpcMsg);
|
||||||
|
static int32_t mgmtGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||||
static void mgmtProcessAlterTableRsp(SRpcMsg *rpcMsg);
|
static void mgmtProcessAlterTableRsp(SRpcMsg *rpcMsg);
|
||||||
static void mgmtProcessDropStableRsp(SRpcMsg *rpcMsg);
|
static void mgmtProcessDropStableRsp(SRpcMsg *rpcMsg);
|
||||||
static int32_t mgmtGetShowTableMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn);
|
static int32_t mgmtGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||||
static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||||
static void mgmtProcessGetTableMeta(STableInfo *pTable, void *thandle);
|
static void mgmtProcessGetTableMeta(STableInfo *pTable, void *thandle);
|
||||||
|
|
||||||
|
@ -122,7 +125,7 @@ STableInfo* mgmtGetTableByPos(uint32_t dnodeId, int32_t vnode, int32_t sid) {
|
||||||
return pVgroup->tableList[sid];
|
return pVgroup->tableList[sid];
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mgmtGetTableMeta(SDbObj *pDb, STableInfo *pTable, STableMeta *pMeta, bool usePublicIp) {
|
int32_t mgmtGetTableMeta(SDbObj *pDb, STableInfo *pTable, STableMetaMsg *pMeta, bool usePublicIp) {
|
||||||
if (pTable->type == TSDB_CHILD_TABLE) {
|
if (pTable->type == TSDB_CHILD_TABLE) {
|
||||||
mgmtGetChildTableMeta(pDb, (SChildTableObj *) pTable, pMeta, usePublicIp);
|
mgmtGetChildTableMeta(pDb, (SChildTableObj *) pTable, pMeta, usePublicIp);
|
||||||
} else if (pTable->type == TSDB_NORMAL_TABLE) {
|
} else if (pTable->type == TSDB_NORMAL_TABLE) {
|
||||||
|
@ -187,24 +190,24 @@ void mgmtCleanUpTables() {
|
||||||
mgmtCleanUpSuperTables();
|
mgmtCleanUpSuperTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mgmtGetShowTableMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn) {
|
int32_t mgmtGetShowTableMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
SDbObj *pDb = mgmtGetDb(pShow->db);
|
SDbObj *pDb = mgmtGetDb(pShow->db);
|
||||||
if (pDb == NULL) {
|
if (pDb == NULL) {
|
||||||
return TSDB_CODE_DB_NOT_SELECTED;
|
return TSDB_CODE_DB_NOT_SELECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
SSchema *pSchema = tsGetSchema(pMeta);
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN;
|
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
strcpy(pSchema[cols].name, "table name");
|
strcpy(pSchema[cols].name, "table_name");
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
pShow->bytes[cols] = 8;
|
pShow->bytes[cols] = 8;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
strcpy(pSchema[cols].name, "create time");
|
strcpy(pSchema[cols].name, "created_time");
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
|
@ -216,7 +219,7 @@ int32_t mgmtGetShowTableMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
|
|
||||||
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN;
|
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
strcpy(pSchema[cols].name, "super table name");
|
strcpy(pSchema[cols].name, "stable_name");
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
|
@ -602,15 +605,16 @@ void mgmtProcessGetTableMeta(STableInfo *pTable, void *thandle) {
|
||||||
|
|
||||||
bool usePublicIp = (connInfo.serverIp == tsPublicIpInt);
|
bool usePublicIp = (connInfo.serverIp == tsPublicIpInt);
|
||||||
|
|
||||||
STableMeta *pMeta = rpcMallocCont(sizeof(STableMeta) + sizeof(SSchema) * TSDB_MAX_COLUMNS);
|
STableMetaMsg *pMeta = rpcMallocCont(sizeof(STableMetaMsg) + sizeof(SSchema) * TSDB_MAX_COLUMNS);
|
||||||
rpcRsp.code = mgmtGetTableMeta(pDb, pTable, pMeta, usePublicIp);
|
rpcRsp.code = mgmtGetTableMeta(pDb, pTable, pMeta, usePublicIp);
|
||||||
|
|
||||||
if (rpcRsp.code != TSDB_CODE_SUCCESS) {
|
if (rpcRsp.code != TSDB_CODE_SUCCESS) {
|
||||||
rpcFreeCont(pMeta);
|
rpcFreeCont(pMeta);
|
||||||
} else {
|
} else {
|
||||||
pMeta->contLen = htons(pMeta->contLen);
|
|
||||||
rpcRsp.pCont = pMeta;
|
rpcRsp.pCont = pMeta;
|
||||||
rpcRsp.contLen = pMeta->contLen;
|
rpcRsp.contLen = pMeta->contLen;
|
||||||
|
|
||||||
|
pMeta->contLen = htons(pMeta->contLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
rpcSendResponse(&rpcRsp);
|
rpcSendResponse(&rpcRsp);
|
||||||
|
@ -695,7 +699,7 @@ void mgmtProcessMultiTableMetaMsg(SQueuedMsg *pMsg) {
|
||||||
if (pDb == NULL) continue;
|
if (pDb == NULL) continue;
|
||||||
|
|
||||||
int availLen = totalMallocLen - pMultiMeta->contLen;
|
int availLen = totalMallocLen - pMultiMeta->contLen;
|
||||||
if (availLen <= sizeof(STableMeta) + sizeof(SSchema) * TSDB_MAX_COLUMNS) {
|
if (availLen <= sizeof(STableMetaMsg) + sizeof(SSchema) * TSDB_MAX_COLUMNS) {
|
||||||
//TODO realloc
|
//TODO realloc
|
||||||
//totalMallocLen *= 2;
|
//totalMallocLen *= 2;
|
||||||
//pMultiMeta = rpcReMalloc(pMultiMeta, totalMallocLen);
|
//pMultiMeta = rpcReMalloc(pMultiMeta, totalMallocLen);
|
||||||
|
@ -708,7 +712,7 @@ void mgmtProcessMultiTableMetaMsg(SQueuedMsg *pMsg) {
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
STableMeta *pMeta = (STableMeta *)(pMultiMeta->metas + pMultiMeta->contLen);
|
STableMetaMsg *pMeta = (STableMetaMsg *)(pMultiMeta->metas + pMultiMeta->contLen);
|
||||||
int32_t code = mgmtGetTableMeta(pDb, pTable, pMeta, usePublicIp);
|
int32_t code = mgmtGetTableMeta(pDb, pTable, pMeta, usePublicIp);
|
||||||
if (code == TSDB_CODE_SUCCESS) {
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
pMultiMeta->numOfTables ++;
|
pMultiMeta->numOfTables ++;
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
#include "tschemautil.h"
|
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
#include "mgmtAcct.h"
|
#include "mgmtAcct.h"
|
||||||
#include "mgmtGrant.h"
|
#include "mgmtGrant.h"
|
||||||
|
@ -30,7 +29,7 @@ static int32_t tsUserUpdateSize = 0;
|
||||||
static int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass);
|
static int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass);
|
||||||
static int32_t mgmtDropUser(SAcctObj *pAcct, char *name);
|
static int32_t mgmtDropUser(SAcctObj *pAcct, char *name);
|
||||||
static int32_t mgmtUpdateUser(SUserObj *pUser);
|
static int32_t mgmtUpdateUser(SUserObj *pUser);
|
||||||
static int32_t mgmtGetUserMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn);
|
static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||||
static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||||
|
|
||||||
static void mgmtProcessCreateUserMsg(SQueuedMsg *pMsg);
|
static void mgmtProcessCreateUserMsg(SQueuedMsg *pMsg);
|
||||||
|
@ -171,14 +170,14 @@ static int32_t mgmtDropUser(SAcctObj *pAcct, char *name) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mgmtGetUserMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn) {
|
static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
SUserObj *pUser = mgmtGetUserFromConn(pConn);
|
SUserObj *pUser = mgmtGetUserFromConn(pConn);
|
||||||
if (pUser == NULL) {
|
if (pUser == NULL) {
|
||||||
return TSDB_CODE_INVALID_USER;
|
return TSDB_CODE_INVALID_USER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
SSchema *pSchema = tsGetSchema(pMeta);
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
pShow->bytes[cols] = TSDB_USER_LEN;
|
pShow->bytes[cols] = TSDB_USER_LEN;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
@ -194,7 +193,7 @@ static int32_t mgmtGetUserMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn)
|
||||||
|
|
||||||
pShow->bytes[cols] = 8;
|
pShow->bytes[cols] = 8;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||||
strcpy(pSchema[cols].name, "created time");
|
strcpy(pSchema[cols].name, "created_time");
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "tschemautil.h"
|
|
||||||
#include "tstatus.h"
|
#include "tstatus.h"
|
||||||
#include "mnode.h"
|
#include "mnode.h"
|
||||||
#include "mgmtBalance.h"
|
#include "mgmtBalance.h"
|
||||||
|
@ -41,7 +40,7 @@ static void *mgmtVgroupActionDecode(void *row, char *str, int32_t size, int32_t
|
||||||
static void *mgmtVgroupActionReset(void *row, char *str, int32_t size, int32_t *ssize);
|
static void *mgmtVgroupActionReset(void *row, char *str, int32_t size, int32_t *ssize);
|
||||||
static void *mgmtVgroupActionDestroy(void *row, char *str, int32_t size, int32_t *ssize);
|
static void *mgmtVgroupActionDestroy(void *row, char *str, int32_t size, int32_t *ssize);
|
||||||
|
|
||||||
static int32_t mgmtGetVgroupMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn);
|
static int32_t mgmtGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn);
|
||||||
static int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
static int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pConn);
|
||||||
static void mgmtProcessCreateVnodeRsp(SRpcMsg *rpcMsg);
|
static void mgmtProcessCreateVnodeRsp(SRpcMsg *rpcMsg);
|
||||||
static void mgmtProcessDropVnodeRsp(SRpcMsg *rpcMsg);
|
static void mgmtProcessDropVnodeRsp(SRpcMsg *rpcMsg);
|
||||||
|
@ -208,14 +207,14 @@ void mgmtCleanUpVgroups() {
|
||||||
sdbCloseTable(tsVgroupSdb);
|
sdbCloseTable(tsVgroupSdb);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mgmtGetVgroupMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn) {
|
int32_t mgmtGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
SDbObj *pDb = mgmtGetDb(pShow->db);
|
SDbObj *pDb = mgmtGetDb(pShow->db);
|
||||||
if (pDb == NULL) {
|
if (pDb == NULL) {
|
||||||
return TSDB_CODE_DB_NOT_SELECTED;
|
return TSDB_CODE_DB_NOT_SELECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
SSchema *pSchema = tsGetSchema(pMeta);
|
SSchema *pSchema = pMeta->schema;
|
||||||
|
|
||||||
pShow->bytes[cols] = 4;
|
pShow->bytes[cols] = 4;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||||
|
@ -231,7 +230,7 @@ int32_t mgmtGetVgroupMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
|
|
||||||
pShow->bytes[cols] = 9;
|
pShow->bytes[cols] = 9;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
strcpy(pSchema[cols].name, "vgroup status");
|
strcpy(pSchema[cols].name, "vgroup_status");
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
|
@ -271,13 +270,13 @@ int32_t mgmtGetVgroupMeta(STableMeta *pMeta, SShowObj *pShow, void *pConn) {
|
||||||
|
|
||||||
pShow->bytes[cols] = 9;
|
pShow->bytes[cols] = 9;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
strcpy(pSchema[cols].name, "vnode status");
|
strcpy(pSchema[cols].name, "vnode_status");
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
pShow->bytes[cols] = 16;
|
pShow->bytes[cols] = 16;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
strcpy(pSchema[cols].name, "public ip");
|
strcpy(pSchema[cols].name, "public_ip");
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
}
|
}
|
||||||
|
@ -515,7 +514,6 @@ SMDCreateVnodeMsg *mgmtBuildCreateVnodeMsg(SVgObj *pVgroup) {
|
||||||
|
|
||||||
SVnodeDesc *vpeerDesc = pVnode->vpeerDesc;
|
SVnodeDesc *vpeerDesc = pVnode->vpeerDesc;
|
||||||
for (int32_t j = 0; j < pVgroup->numOfVnodes; ++j) {
|
for (int32_t j = 0; j < pVgroup->numOfVnodes; ++j) {
|
||||||
vpeerDesc[j].vgId = htonl(pVgroup->vgId);
|
|
||||||
vpeerDesc[j].ip = htonl(pVgroup->vnodeGid[j].privateIp);
|
vpeerDesc[j].ip = htonl(pVgroup->vnodeGid[j].privateIp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,12 @@ PROJECT(TDengine)
|
||||||
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc)
|
||||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc)
|
||||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc)
|
||||||
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc)
|
||||||
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/vnode/tsdb/inc)
|
||||||
INCLUDE_DIRECTORIES(inc)
|
INCLUDE_DIRECTORIES(inc)
|
||||||
|
|
||||||
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
|
||||||
AUX_SOURCE_DIRECTORY(src SRC)
|
AUX_SOURCE_DIRECTORY(src SRC)
|
||||||
ADD_LIBRARY(query ${SRC})
|
ADD_LIBRARY(query ${SRC})
|
||||||
TARGET_LINK_LIBRARIES(query util m rt)
|
TARGET_LINK_LIBRARIES(query tutil m rt)
|
||||||
ENDIF ()
|
ENDIF ()
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TDENGINE_TPERCENTILE_H
|
#ifndef TDENGINE_QPERCENTILE_H
|
||||||
#define TDENGINE_TPERCENTILE_H
|
#define TDENGINE_QPERCENTILE_H
|
||||||
|
|
||||||
#include "qextbuffer.h"
|
#include "qextbuffer.h"
|
||||||
|
|
||||||
|
@ -74,4 +74,4 @@ void tBucketIntHash(tMemBucket *pBucket, void *value, int16_t *segIdx, int16_t *
|
||||||
|
|
||||||
void tBucketDoubleHash(tMemBucket *pBucket, void *value, int16_t *segIdx, int16_t *slotIdx);
|
void tBucketDoubleHash(tMemBucket *pBucket, void *value, int16_t *segIdx, int16_t *slotIdx);
|
||||||
|
|
||||||
#endif // TDENGINE_TPERCENTILE_H
|
#endif // TDENGINE_QPERCENTILE_H
|
|
@ -29,7 +29,7 @@ typedef struct SIDList {
|
||||||
int32_t* pData;
|
int32_t* pData;
|
||||||
} SIDList;
|
} SIDList;
|
||||||
|
|
||||||
typedef struct SQueryDiskbasedResultBuf {
|
typedef struct SDiskbasedResultBuf {
|
||||||
int32_t numOfRowsPerPage;
|
int32_t numOfRowsPerPage;
|
||||||
int32_t numOfPages;
|
int32_t numOfPages;
|
||||||
int64_t totalBufSize;
|
int64_t totalBufSize;
|
||||||
|
@ -42,7 +42,7 @@ typedef struct SQueryDiskbasedResultBuf {
|
||||||
uint32_t numOfAllocGroupIds; // number of allocated id list
|
uint32_t numOfAllocGroupIds; // number of allocated id list
|
||||||
void* idsTable; // id hash table
|
void* idsTable; // id hash table
|
||||||
SIDList* list; // for each id, there is a page id list
|
SIDList* list; // for each id, there is a page id list
|
||||||
} SQueryDiskbasedResultBuf;
|
} SDiskbasedResultBuf;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create disk-based result buffer
|
* create disk-based result buffer
|
||||||
|
@ -51,7 +51,7 @@ typedef struct SQueryDiskbasedResultBuf {
|
||||||
* @param rowSize
|
* @param rowSize
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t createDiskbasedResultBuffer(SQueryDiskbasedResultBuf** pResultBuf, int32_t size, int32_t rowSize);
|
int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t size, int32_t rowSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -60,14 +60,14 @@ int32_t createDiskbasedResultBuffer(SQueryDiskbasedResultBuf** pResultBuf, int32
|
||||||
* @param pageId
|
* @param pageId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
tFilePage* getNewDataBuf(SQueryDiskbasedResultBuf* pResultBuf, int32_t groupId, int32_t* pageId);
|
tFilePage* getNewDataBuf(SDiskbasedResultBuf* pResultBuf, int32_t groupId, int32_t* pageId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param pResultBuf
|
* @param pResultBuf
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t getNumOfRowsPerPage(SQueryDiskbasedResultBuf* pResultBuf);
|
int32_t getNumOfRowsPerPage(SDiskbasedResultBuf* pResultBuf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -75,7 +75,7 @@ int32_t getNumOfRowsPerPage(SQueryDiskbasedResultBuf* pResultBuf);
|
||||||
* @param groupId
|
* @param groupId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
SIDList getDataBufPagesIdList(SQueryDiskbasedResultBuf* pResultBuf, int32_t groupId);
|
SIDList getDataBufPagesIdList(SDiskbasedResultBuf* pResultBuf, int32_t groupId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the specified buffer page by id
|
* get the specified buffer page by id
|
||||||
|
@ -83,27 +83,27 @@ SIDList getDataBufPagesIdList(SQueryDiskbasedResultBuf* pResultBuf, int32_t grou
|
||||||
* @param id
|
* @param id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
tFilePage* getResultBufferPageById(SQueryDiskbasedResultBuf* pResultBuf, int32_t id);
|
tFilePage* getResultBufferPageById(SDiskbasedResultBuf* pResultBuf, int32_t id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the total buffer size in the format of disk file
|
* get the total buffer size in the format of disk file
|
||||||
* @param pResultBuf
|
* @param pResultBuf
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t getResBufSize(SQueryDiskbasedResultBuf* pResultBuf);
|
int32_t getResBufSize(SDiskbasedResultBuf* pResultBuf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the number of groups in the result buffer
|
* get the number of groups in the result buffer
|
||||||
* @param pResultBuf
|
* @param pResultBuf
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t getNumOfResultBufGroupId(SQueryDiskbasedResultBuf* pResultBuf);
|
int32_t getNumOfResultBufGroupId(SDiskbasedResultBuf* pResultBuf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* destroy result buffer
|
* destroy result buffer
|
||||||
* @param pResultBuf
|
* @param pResultBuf
|
||||||
*/
|
*/
|
||||||
void destroyResultBuf(SQueryDiskbasedResultBuf* pResultBuf);
|
void destroyResultBuf(SDiskbasedResultBuf* pResultBuf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,221 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#ifndef TDENGINE_QUERYEXECUTOR_H
|
||||||
|
#define TDENGINE_QUERYEXECUTOR_H
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
|
#include "hash.h"
|
||||||
|
#include "qinterpolation.h"
|
||||||
|
#include "qresultBuf.h"
|
||||||
|
#include "qsqlparser.h"
|
||||||
|
#include "qtsbuf.h"
|
||||||
|
#include "taosdef.h"
|
||||||
|
#include "tref.h"
|
||||||
|
#include "tsqlfunction.h"
|
||||||
|
|
||||||
|
typedef struct SData {
|
||||||
|
int32_t num;
|
||||||
|
char data[];
|
||||||
|
} SData;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
ST_QUERY_KILLED = 0, // query killed
|
||||||
|
ST_QUERY_PAUSED = 1, // query paused, due to full of the response buffer
|
||||||
|
ST_QUERY_COMPLETED = 2, // query completed
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SColumnFilterElem;
|
||||||
|
typedef bool (*__filter_func_t)(struct SColumnFilterElem* pFilter, char* val1, char* val2);
|
||||||
|
typedef int (*__block_search_fn_t)(char* data, int num, int64_t key, int order);
|
||||||
|
|
||||||
|
typedef struct SSqlGroupbyExpr {
|
||||||
|
int16_t tableIndex;
|
||||||
|
int16_t numOfGroupCols;
|
||||||
|
SColIndexEx columnInfo[TSDB_MAX_TAGS]; // group by columns information
|
||||||
|
int16_t orderIndex; // order by column index
|
||||||
|
int16_t orderType; // order by type: asc/desc
|
||||||
|
} SSqlGroupbyExpr;
|
||||||
|
|
||||||
|
typedef struct SPosInfo {
|
||||||
|
int16_t pageId;
|
||||||
|
int16_t rowId;
|
||||||
|
} SPosInfo;
|
||||||
|
|
||||||
|
typedef struct SWindowStatus {
|
||||||
|
bool closed;
|
||||||
|
} SWindowStatus;
|
||||||
|
|
||||||
|
typedef struct SWindowResult {
|
||||||
|
uint16_t numOfRows;
|
||||||
|
SPosInfo pos; // Position of current result in disk-based output buffer
|
||||||
|
SResultInfo* resultInfo; // For each result column, there is a resultInfo
|
||||||
|
STimeWindow window; // The time window that current result covers.
|
||||||
|
SWindowStatus status;
|
||||||
|
} SWindowResult;
|
||||||
|
|
||||||
|
typedef struct SResultRec {
|
||||||
|
int64_t pointsTotal;
|
||||||
|
int64_t pointsRead;
|
||||||
|
} SResultRec;
|
||||||
|
|
||||||
|
typedef struct SWindowResInfo {
|
||||||
|
SWindowResult* pResult; // result list
|
||||||
|
void* hashList; // hash list for quick access
|
||||||
|
int16_t type; // data type for hash key
|
||||||
|
int32_t capacity; // max capacity
|
||||||
|
int32_t curIndex; // current start active index
|
||||||
|
int32_t size; // number of result set
|
||||||
|
int64_t startTime; // start time of the first time window for sliding query
|
||||||
|
int64_t prevSKey; // previous (not completed) sliding window start key
|
||||||
|
int64_t threshold; // threshold to pausing query and return closed results.
|
||||||
|
} SWindowResInfo;
|
||||||
|
|
||||||
|
typedef struct SColumnFilterElem {
|
||||||
|
int16_t bytes; // column length
|
||||||
|
__filter_func_t fp;
|
||||||
|
SColumnFilterInfo filterInfo;
|
||||||
|
} SColumnFilterElem;
|
||||||
|
|
||||||
|
typedef struct SSingleColumnFilterInfo {
|
||||||
|
SColumnInfoEx info;
|
||||||
|
int32_t numOfFilters;
|
||||||
|
SColumnFilterElem* pFilters;
|
||||||
|
void* pData;
|
||||||
|
} SSingleColumnFilterInfo;
|
||||||
|
|
||||||
|
/* intermediate pos during multimeter query involves interval */
|
||||||
|
typedef struct STableQueryInfo {
|
||||||
|
int64_t lastKey;
|
||||||
|
STimeWindow win;
|
||||||
|
int32_t numOfRes;
|
||||||
|
int16_t queryRangeSet; // denote if the query range is set, only available for interval query
|
||||||
|
int64_t tag;
|
||||||
|
STSCursor cur;
|
||||||
|
int32_t sid; // for retrieve the page id list
|
||||||
|
|
||||||
|
SWindowResInfo windowResInfo;
|
||||||
|
} STableQueryInfo;
|
||||||
|
|
||||||
|
typedef struct STableDataInfo {
|
||||||
|
int32_t numOfBlocks;
|
||||||
|
int32_t start; // start block index
|
||||||
|
int32_t tableIndex;
|
||||||
|
void* pMeterObj;
|
||||||
|
int32_t groupIdx; // group id in table list
|
||||||
|
STableQueryInfo* pTableQInfo;
|
||||||
|
} STableDataInfo;
|
||||||
|
|
||||||
|
typedef struct SQuery {
|
||||||
|
int16_t numOfCols;
|
||||||
|
SOrderVal order;
|
||||||
|
STimeWindow window;
|
||||||
|
int64_t intervalTime;
|
||||||
|
int64_t slidingTime; // sliding time for sliding window query
|
||||||
|
char slidingTimeUnit; // interval data type, used for daytime revise
|
||||||
|
int8_t precision;
|
||||||
|
int16_t numOfOutputCols;
|
||||||
|
int16_t interpoType;
|
||||||
|
int16_t checkBufferInLoop; // check if the buffer is full during scan each block
|
||||||
|
SLimitVal limit;
|
||||||
|
int32_t rowSize;
|
||||||
|
SSqlGroupbyExpr* pGroupbyExpr;
|
||||||
|
SSqlFunctionExpr* pSelectExpr;
|
||||||
|
SColumnInfoEx* colList;
|
||||||
|
int32_t numOfFilterCols;
|
||||||
|
int64_t* defaultVal;
|
||||||
|
TSKEY lastKey;
|
||||||
|
uint32_t status; // query status
|
||||||
|
SResultRec rec;
|
||||||
|
int32_t pos;
|
||||||
|
int64_t pointsOffset; // the number of points offset to save read data
|
||||||
|
SData** sdata;
|
||||||
|
|
||||||
|
SSingleColumnFilterInfo* pFilterInfo;
|
||||||
|
} SQuery;
|
||||||
|
|
||||||
|
typedef struct SQueryCostSummary {
|
||||||
|
} SQueryCostSummary;
|
||||||
|
|
||||||
|
typedef struct SQueryRuntimeEnv {
|
||||||
|
SResultInfo* resultInfo; // todo refactor to merge with SWindowResInfo
|
||||||
|
SQuery* pQuery;
|
||||||
|
void* pTabObj;
|
||||||
|
SData** pInterpoBuf;
|
||||||
|
SQLFunctionCtx* pCtx;
|
||||||
|
int16_t numOfRowsPerPage;
|
||||||
|
int16_t offset[TSDB_MAX_COLUMNS];
|
||||||
|
uint16_t scanFlag; // denotes reversed scan of data or not
|
||||||
|
SInterpolationInfo interpoInfo;
|
||||||
|
SWindowResInfo windowResInfo;
|
||||||
|
STSBuf* pTSBuf;
|
||||||
|
STSCursor cur;
|
||||||
|
SQueryCostSummary summary;
|
||||||
|
bool stableQuery; // super table query or not
|
||||||
|
void* pQueryHandle;
|
||||||
|
|
||||||
|
SDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
||||||
|
} SQueryRuntimeEnv;
|
||||||
|
|
||||||
|
typedef struct SQInfo {
|
||||||
|
uint64_t signature;
|
||||||
|
TSKEY startTime;
|
||||||
|
int64_t elapsedTime;
|
||||||
|
SResultRec rec;
|
||||||
|
int pointsReturned;
|
||||||
|
int pointsInterpo;
|
||||||
|
int code; // error code to returned to client
|
||||||
|
sem_t dataReady;
|
||||||
|
SHashObj* pTableList; // table list
|
||||||
|
SQueryRuntimeEnv runtimeEnv;
|
||||||
|
int32_t subgroupIdx;
|
||||||
|
int32_t offset; /* offset in group result set of subgroup */
|
||||||
|
tSidSet* pSidSet;
|
||||||
|
|
||||||
|
T_REF_DECLARE()
|
||||||
|
/*
|
||||||
|
* the query is executed position on which meter of the whole list.
|
||||||
|
* when the index reaches the last one of the list, it means the query is completed.
|
||||||
|
* We later may refactor to remove this attribution by using another flag to denote
|
||||||
|
* whether a multimeter query is completed or not.
|
||||||
|
*/
|
||||||
|
int32_t tableIndex;
|
||||||
|
int32_t numOfGroupResultPages;
|
||||||
|
STableDataInfo* pTableDataInfo;
|
||||||
|
TSKEY* tsList;
|
||||||
|
} SQInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create the qinfo object before adding the query task to each tsdb query worker
|
||||||
|
*
|
||||||
|
* @param pReadMsg
|
||||||
|
* @param pQInfo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int32_t qCreateQueryInfo(void* pReadMsg, SQInfo** pQInfo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* query on single table
|
||||||
|
* @param pReadMsg
|
||||||
|
*/
|
||||||
|
void qTableQuery(void* pReadMsg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* query on super table
|
||||||
|
* @param pReadMsg
|
||||||
|
*/
|
||||||
|
void qSuperTableQuery(void* pReadMsg);
|
||||||
|
|
||||||
|
#endif // TDENGINE_QUERYEXECUTOR_H
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#ifndef TDENGINE_QUERYUTIL_H
|
||||||
|
#define TDENGINE_QUERYUTIL_H
|
||||||
|
|
||||||
|
void clearTimeWindowResBuf(SQueryRuntimeEnv* pRuntimeEnv, SWindowResult* pOneOutputRes);
|
||||||
|
void copyTimeWindowResBuf(SQueryRuntimeEnv* pRuntimeEnv, SWindowResult* dst, const SWindowResult* src);
|
||||||
|
|
||||||
|
int32_t initWindowResInfo(SWindowResInfo* pWindowResInfo, SQueryRuntimeEnv* pRuntimeEnv, int32_t size,
|
||||||
|
int32_t threshold, int16_t type);
|
||||||
|
|
||||||
|
void cleanupTimeWindowInfo(SWindowResInfo* pWindowResInfo, int32_t numOfCols);
|
||||||
|
void resetTimeWindowInfo(SQueryRuntimeEnv* pRuntimeEnv, SWindowResInfo* pWindowResInfo);
|
||||||
|
void clearFirstNTimeWindow(SQueryRuntimeEnv *pRuntimeEnv, int32_t num);
|
||||||
|
|
||||||
|
void clearClosedTimeWindow(SQueryRuntimeEnv* pRuntimeEnv);
|
||||||
|
int32_t numOfClosedTimeWindow(SWindowResInfo* pWindowResInfo);
|
||||||
|
void closeTimeWindow(SWindowResInfo* pWindowResInfo, int32_t slot);
|
||||||
|
void closeAllTimeWindow(SWindowResInfo* pWindowResInfo);
|
||||||
|
void removeRedundantWindow(SWindowResInfo *pWindowResInfo, TSKEY lastKey, int32_t order);
|
||||||
|
SWindowResult *getWindowResult(SWindowResInfo *pWindowResInfo, int32_t slot);
|
||||||
|
int32_t curTimeWindow(SWindowResInfo *pWindowResInfo);
|
||||||
|
bool isWindowResClosed(SWindowResInfo *pWindowResInfo, int32_t slot);
|
||||||
|
|
||||||
|
void createQueryResultInfo(SQuery *pQuery, SWindowResult *pResultRow, bool isSTableQuery, SPosInfo *posInfo);
|
||||||
|
|
||||||
|
#endif // TDENGINE_QUERYUTIL_H
|
|
@ -20,11 +20,11 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include "os.h"
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "trpc.h"
|
#include "../../common/inc/name.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
|
#include "trpc.h"
|
||||||
#include "tvariant.h"
|
#include "tvariant.h"
|
||||||
|
|
||||||
#define TSDB_FUNC_INVALID_ID -1
|
#define TSDB_FUNC_INVALID_ID -1
|
||||||
|
@ -130,12 +130,8 @@ typedef struct SArithmeticSupport {
|
||||||
|
|
||||||
typedef struct SQLPreAggVal {
|
typedef struct SQLPreAggVal {
|
||||||
bool isSet;
|
bool isSet;
|
||||||
int32_t numOfNull;
|
int32_t size;
|
||||||
int64_t sum;
|
SDataStatis statis;
|
||||||
int64_t max;
|
|
||||||
int64_t min;
|
|
||||||
int16_t maxIndex;
|
|
||||||
int16_t minIndex;
|
|
||||||
} SQLPreAggVal;
|
} SQLPreAggVal;
|
||||||
|
|
||||||
typedef struct SInterpInfoDetail {
|
typedef struct SInterpInfoDetail {
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "tschemautil.h"
|
|
||||||
#include "tsqlfunction.h"
|
#include "tsqlfunction.h"
|
||||||
#include "tstoken.h"
|
#include "tstoken.h"
|
||||||
#include "ttokendef.h"
|
#include "ttokendef.h"
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
|
|
||||||
#define DEFAULT_INTERN_BUF_SIZE 16384L
|
#define DEFAULT_INTERN_BUF_SIZE 16384L
|
||||||
|
|
||||||
int32_t createDiskbasedResultBuffer(SQueryDiskbasedResultBuf** pResultBuf, int32_t size, int32_t rowSize) {
|
int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t size, int32_t rowSize) {
|
||||||
SQueryDiskbasedResultBuf* pResBuf = calloc(1, sizeof(SQueryDiskbasedResultBuf));
|
SDiskbasedResultBuf* pResBuf = calloc(1, sizeof(SDiskbasedResultBuf));
|
||||||
pResBuf->numOfRowsPerPage = (DEFAULT_INTERN_BUF_SIZE - sizeof(tFilePage)) / rowSize;
|
pResBuf->numOfRowsPerPage = (DEFAULT_INTERN_BUF_SIZE - sizeof(tFilePage)) / rowSize;
|
||||||
pResBuf->numOfPages = size;
|
pResBuf->numOfPages = size;
|
||||||
|
|
||||||
|
@ -50,17 +50,17 @@ int32_t createDiskbasedResultBuffer(SQueryDiskbasedResultBuf** pResultBuf, int32
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
tFilePage* getResultBufferPageById(SQueryDiskbasedResultBuf* pResultBuf, int32_t id) {
|
tFilePage* getResultBufferPageById(SDiskbasedResultBuf* pResultBuf, int32_t id) {
|
||||||
assert(id < pResultBuf->numOfPages && id >= 0);
|
assert(id < pResultBuf->numOfPages && id >= 0);
|
||||||
|
|
||||||
return (tFilePage*)(pResultBuf->pBuf + DEFAULT_INTERN_BUF_SIZE * id);
|
return (tFilePage*)(pResultBuf->pBuf + DEFAULT_INTERN_BUF_SIZE * id);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getNumOfResultBufGroupId(SQueryDiskbasedResultBuf* pResultBuf) { return taosHashGetSize(pResultBuf->idsTable); }
|
int32_t getNumOfResultBufGroupId(SDiskbasedResultBuf* pResultBuf) { return taosHashGetSize(pResultBuf->idsTable); }
|
||||||
|
|
||||||
int32_t getResBufSize(SQueryDiskbasedResultBuf* pResultBuf) { return pResultBuf->totalBufSize; }
|
int32_t getResBufSize(SDiskbasedResultBuf* pResultBuf) { return pResultBuf->totalBufSize; }
|
||||||
|
|
||||||
static int32_t extendDiskFileSize(SQueryDiskbasedResultBuf* pResultBuf, int32_t numOfPages) {
|
static int32_t extendDiskFileSize(SDiskbasedResultBuf* pResultBuf, int32_t numOfPages) {
|
||||||
assert(pResultBuf->numOfPages * DEFAULT_INTERN_BUF_SIZE == pResultBuf->totalBufSize);
|
assert(pResultBuf->numOfPages * DEFAULT_INTERN_BUF_SIZE == pResultBuf->totalBufSize);
|
||||||
|
|
||||||
int32_t ret = munmap(pResultBuf->pBuf, pResultBuf->totalBufSize);
|
int32_t ret = munmap(pResultBuf->pBuf, pResultBuf->totalBufSize);
|
||||||
|
@ -88,11 +88,11 @@ static int32_t extendDiskFileSize(SQueryDiskbasedResultBuf* pResultBuf, int32_t
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool noMoreAvailablePages(SQueryDiskbasedResultBuf* pResultBuf) {
|
static bool noMoreAvailablePages(SDiskbasedResultBuf* pResultBuf) {
|
||||||
return (pResultBuf->allocateId == pResultBuf->numOfPages - 1);
|
return (pResultBuf->allocateId == pResultBuf->numOfPages - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t getGroupIndex(SQueryDiskbasedResultBuf* pResultBuf, int32_t groupId) {
|
static int32_t getGroupIndex(SDiskbasedResultBuf* pResultBuf, int32_t groupId) {
|
||||||
assert(pResultBuf != NULL);
|
assert(pResultBuf != NULL);
|
||||||
|
|
||||||
char* p = taosHashGet(pResultBuf->idsTable, (const char*)&groupId, sizeof(int32_t));
|
char* p = taosHashGet(pResultBuf->idsTable, (const char*)&groupId, sizeof(int32_t));
|
||||||
|
@ -106,7 +106,7 @@ static int32_t getGroupIndex(SQueryDiskbasedResultBuf* pResultBuf, int32_t group
|
||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t addNewGroupId(SQueryDiskbasedResultBuf* pResultBuf, int32_t groupId) {
|
static int32_t addNewGroupId(SDiskbasedResultBuf* pResultBuf, int32_t groupId) {
|
||||||
int32_t num = getNumOfResultBufGroupId(pResultBuf); // the num is the newest allocated group id slot
|
int32_t num = getNumOfResultBufGroupId(pResultBuf); // the num is the newest allocated group id slot
|
||||||
|
|
||||||
if (pResultBuf->numOfAllocGroupIds <= num) {
|
if (pResultBuf->numOfAllocGroupIds <= num) {
|
||||||
|
@ -148,7 +148,7 @@ static int32_t doRegisterId(SIDList* pList, int32_t id) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void registerPageId(SQueryDiskbasedResultBuf* pResultBuf, int32_t groupId, int32_t pageId) {
|
static void registerPageId(SDiskbasedResultBuf* pResultBuf, int32_t groupId, int32_t pageId) {
|
||||||
int32_t slot = getGroupIndex(pResultBuf, groupId);
|
int32_t slot = getGroupIndex(pResultBuf, groupId);
|
||||||
if (slot < 0) {
|
if (slot < 0) {
|
||||||
slot = addNewGroupId(pResultBuf, groupId);
|
slot = addNewGroupId(pResultBuf, groupId);
|
||||||
|
@ -158,7 +158,7 @@ static void registerPageId(SQueryDiskbasedResultBuf* pResultBuf, int32_t groupId
|
||||||
doRegisterId(pList, pageId);
|
doRegisterId(pList, pageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
tFilePage* getNewDataBuf(SQueryDiskbasedResultBuf* pResultBuf, int32_t groupId, int32_t* pageId) {
|
tFilePage* getNewDataBuf(SDiskbasedResultBuf* pResultBuf, int32_t groupId, int32_t* pageId) {
|
||||||
if (noMoreAvailablePages(pResultBuf)) {
|
if (noMoreAvailablePages(pResultBuf)) {
|
||||||
if (extendDiskFileSize(pResultBuf, pResultBuf->incStep) != TSDB_CODE_SUCCESS) {
|
if (extendDiskFileSize(pResultBuf, pResultBuf->incStep) != TSDB_CODE_SUCCESS) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -177,9 +177,9 @@ tFilePage* getNewDataBuf(SQueryDiskbasedResultBuf* pResultBuf, int32_t groupId,
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getNumOfRowsPerPage(SQueryDiskbasedResultBuf* pResultBuf) { return pResultBuf->numOfRowsPerPage; }
|
int32_t getNumOfRowsPerPage(SDiskbasedResultBuf* pResultBuf) { return pResultBuf->numOfRowsPerPage; }
|
||||||
|
|
||||||
SIDList getDataBufPagesIdList(SQueryDiskbasedResultBuf* pResultBuf, int32_t groupId) {
|
SIDList getDataBufPagesIdList(SDiskbasedResultBuf* pResultBuf, int32_t groupId) {
|
||||||
SIDList list = {0};
|
SIDList list = {0};
|
||||||
int32_t slot = getGroupIndex(pResultBuf, groupId);
|
int32_t slot = getGroupIndex(pResultBuf, groupId);
|
||||||
if (slot < 0) {
|
if (slot < 0) {
|
||||||
|
@ -189,7 +189,7 @@ SIDList getDataBufPagesIdList(SQueryDiskbasedResultBuf* pResultBuf, int32_t grou
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroyResultBuf(SQueryDiskbasedResultBuf* pResultBuf) {
|
void destroyResultBuf(SDiskbasedResultBuf* pResultBuf) {
|
||||||
if (pResultBuf == NULL) {
|
if (pResultBuf == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,269 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
|
#include "hash.h"
|
||||||
|
#include "taosmsg.h"
|
||||||
|
#include "qextbuffer.h"
|
||||||
|
#include "ttime.h"
|
||||||
|
|
||||||
|
#include "qinterpolation.h"
|
||||||
|
//#include "tscJoinProcess.h"
|
||||||
|
#include "ttime.h"
|
||||||
|
|
||||||
|
#include "queryExecutor.h"
|
||||||
|
|
||||||
|
int32_t initWindowResInfo(SWindowResInfo *pWindowResInfo, SQueryRuntimeEnv *pRuntimeEnv, int32_t size,
|
||||||
|
int32_t threshold, int16_t type) {
|
||||||
|
pWindowResInfo->capacity = size;
|
||||||
|
pWindowResInfo->threshold = threshold;
|
||||||
|
|
||||||
|
pWindowResInfo->type = type;
|
||||||
|
|
||||||
|
_hash_fn_t fn = taosGetDefaultHashFunction(type);
|
||||||
|
pWindowResInfo->hashList = taosHashInit(threshold, fn, false);
|
||||||
|
|
||||||
|
pWindowResInfo->curIndex = -1;
|
||||||
|
pWindowResInfo->size = 0;
|
||||||
|
|
||||||
|
// use the pointer arraylist
|
||||||
|
pWindowResInfo->pResult = calloc(threshold, sizeof(SWindowResult));
|
||||||
|
for (int32_t i = 0; i < pWindowResInfo->capacity; ++i) {
|
||||||
|
SPosInfo posInfo = {-1, -1};
|
||||||
|
createQueryResultInfo(pRuntimeEnv->pQuery, &pWindowResInfo->pResult[i], pRuntimeEnv->stableQuery, &posInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroyTimeWindowRes(SWindowResult *pWindowRes, int32_t nOutputCols) {
|
||||||
|
if (pWindowRes == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < nOutputCols; ++i) {
|
||||||
|
free(pWindowRes->resultInfo[i].interResultBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(pWindowRes->resultInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void cleanupTimeWindowInfo(SWindowResInfo *pWindowResInfo, int32_t numOfCols) {
|
||||||
|
if (pWindowResInfo == NULL || pWindowResInfo->capacity == 0) {
|
||||||
|
assert(pWindowResInfo->hashList == NULL && pWindowResInfo->pResult == NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < pWindowResInfo->capacity; ++i) {
|
||||||
|
SWindowResult *pResult = &pWindowResInfo->pResult[i];
|
||||||
|
destroyTimeWindowRes(pResult, numOfCols);
|
||||||
|
}
|
||||||
|
|
||||||
|
taosHashCleanup(pWindowResInfo->hashList);
|
||||||
|
tfree(pWindowResInfo->pResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetTimeWindowInfo(SQueryRuntimeEnv *pRuntimeEnv, SWindowResInfo *pWindowResInfo) {
|
||||||
|
if (pWindowResInfo == NULL || pWindowResInfo->capacity == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < pWindowResInfo->size; ++i) {
|
||||||
|
SWindowResult *pWindowRes = &pWindowResInfo->pResult[i];
|
||||||
|
clearTimeWindowResBuf(pRuntimeEnv, pWindowRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
pWindowResInfo->curIndex = -1;
|
||||||
|
taosHashCleanup(pWindowResInfo->hashList);
|
||||||
|
pWindowResInfo->size = 0;
|
||||||
|
|
||||||
|
_hash_fn_t fn = taosGetDefaultHashFunction(pWindowResInfo->type);
|
||||||
|
pWindowResInfo->hashList = taosHashInit(pWindowResInfo->capacity, fn, false);
|
||||||
|
|
||||||
|
pWindowResInfo->startTime = 0;
|
||||||
|
pWindowResInfo->prevSKey = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearFirstNTimeWindow(SQueryRuntimeEnv *pRuntimeEnv, int32_t num) {
|
||||||
|
SWindowResInfo *pWindowResInfo = &pRuntimeEnv->windowResInfo;
|
||||||
|
if (pWindowResInfo == NULL || pWindowResInfo->capacity == 0 || pWindowResInfo->size == 0 || num == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t numOfClosed = numOfClosedTimeWindow(pWindowResInfo);
|
||||||
|
assert(num >= 0 && num <= numOfClosed);
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < num; ++i) {
|
||||||
|
SWindowResult *pResult = &pWindowResInfo->pResult[i];
|
||||||
|
if (pResult->status.closed) { // remove the window slot from hash table
|
||||||
|
taosHashRemove(pWindowResInfo->hashList, (const char *)&pResult->window.skey, TSDB_KEYSIZE);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t remain = pWindowResInfo->size - num;
|
||||||
|
|
||||||
|
// clear all the closed windows from the window list
|
||||||
|
for (int32_t k = 0; k < remain; ++k) {
|
||||||
|
copyTimeWindowResBuf(pRuntimeEnv, &pWindowResInfo->pResult[k], &pWindowResInfo->pResult[num + k]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// move the unclosed window in the front of the window list
|
||||||
|
for (int32_t k = remain; k < pWindowResInfo->size; ++k) {
|
||||||
|
SWindowResult *pWindowRes = &pWindowResInfo->pResult[k];
|
||||||
|
clearTimeWindowResBuf(pRuntimeEnv, pWindowRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
pWindowResInfo->size = remain;
|
||||||
|
|
||||||
|
for (int32_t k = 0; k < pWindowResInfo->size; ++k) {
|
||||||
|
SWindowResult *pResult = &pWindowResInfo->pResult[k];
|
||||||
|
int32_t *p = (int32_t *)taosHashGet(pWindowResInfo->hashList, (const char *)&pResult->window.skey, TSDB_KEYSIZE);
|
||||||
|
int32_t v = (*p - num);
|
||||||
|
assert(v >= 0 && v <= pWindowResInfo->size);
|
||||||
|
|
||||||
|
taosHashPut(pWindowResInfo->hashList, (const char *)&pResult->window.skey, TSDB_KEYSIZE, (char *)&v,
|
||||||
|
sizeof(int32_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
pWindowResInfo->curIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearClosedTimeWindow(SQueryRuntimeEnv *pRuntimeEnv) {
|
||||||
|
SWindowResInfo *pWindowResInfo = &pRuntimeEnv->windowResInfo;
|
||||||
|
if (pWindowResInfo == NULL || pWindowResInfo->capacity == 0 || pWindowResInfo->size == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t numOfClosed = numOfClosedTimeWindow(pWindowResInfo);
|
||||||
|
clearFirstNTimeWindow(pRuntimeEnv, numOfClosed);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t numOfClosedTimeWindow(SWindowResInfo *pWindowResInfo) {
|
||||||
|
int32_t i = 0;
|
||||||
|
while (i < pWindowResInfo->size && pWindowResInfo->pResult[i].status.closed) {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
void closeAllTimeWindow(SWindowResInfo *pWindowResInfo) {
|
||||||
|
assert(pWindowResInfo->size >= 0 && pWindowResInfo->capacity >= pWindowResInfo->size);
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < pWindowResInfo->size; ++i) {
|
||||||
|
if (pWindowResInfo->pResult[i].status.closed) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
pWindowResInfo->pResult[i].status.closed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* remove the results that are not the FIRST time window that spreads beyond the
|
||||||
|
* the last qualified time stamp in case of sliding query, which the sliding time is not equalled to the interval time
|
||||||
|
*/
|
||||||
|
void removeRedundantWindow(SWindowResInfo *pWindowResInfo, TSKEY lastKey, int32_t order) {
|
||||||
|
assert(pWindowResInfo->size >= 0 && pWindowResInfo->capacity >= pWindowResInfo->size);
|
||||||
|
|
||||||
|
int32_t i = 0;
|
||||||
|
while (i < pWindowResInfo->size &&
|
||||||
|
((pWindowResInfo->pResult[i].window.ekey < lastKey && order == QUERY_ASC_FORWARD_STEP) ||
|
||||||
|
(pWindowResInfo->pResult[i].window.skey > lastKey && order == QUERY_DESC_FORWARD_STEP))) {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// assert(i < pWindowResInfo->size);
|
||||||
|
if (i < pWindowResInfo->size) {
|
||||||
|
pWindowResInfo->size = (i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SWindowResult *getWindowResult(SWindowResInfo *pWindowResInfo, int32_t slot) {
|
||||||
|
assert(pWindowResInfo != NULL && slot >= 0 && slot < pWindowResInfo->size);
|
||||||
|
return &pWindowResInfo->pResult[slot];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isWindowResClosed(SWindowResInfo *pWindowResInfo, int32_t slot) {
|
||||||
|
return (getWindowResult(pWindowResInfo, slot)->status.closed == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t curTimeWindow(SWindowResInfo *pWindowResInfo) {
|
||||||
|
assert(pWindowResInfo->curIndex >= 0 && pWindowResInfo->curIndex < pWindowResInfo->size);
|
||||||
|
return pWindowResInfo->curIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
void closeTimeWindow(SWindowResInfo *pWindowResInfo, int32_t slot) {
|
||||||
|
getWindowResult(pWindowResInfo, slot)->status.closed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pWindowRes) {
|
||||||
|
if (pWindowRes == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < pRuntimeEnv->pQuery->numOfOutputCols; ++i) {
|
||||||
|
SResultInfo *pResultInfo = &pWindowRes->resultInfo[i];
|
||||||
|
|
||||||
|
char * s = getPosInResultPage(pRuntimeEnv, i, pWindowRes);
|
||||||
|
size_t size = pRuntimeEnv->pQuery->pSelectExpr[i].resBytes;
|
||||||
|
memset(s, 0, size);
|
||||||
|
|
||||||
|
resetResultInfo(pResultInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
pWindowRes->numOfRows = 0;
|
||||||
|
// pWindowRes->nAlloc = 0;
|
||||||
|
pWindowRes->pos = (SPosInfo){-1, -1};
|
||||||
|
pWindowRes->status.closed = false;
|
||||||
|
pWindowRes->window = (STimeWindow){0, 0};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The source window result pos attribution of the source window result does not assign to the destination,
|
||||||
|
* since the attribute of "Pos" is bound to each window result when the window result is created in the
|
||||||
|
* disk-based result buffer.
|
||||||
|
*/
|
||||||
|
void copyTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *dst, const SWindowResult *src) {
|
||||||
|
dst->numOfRows = src->numOfRows;
|
||||||
|
// dst->nAlloc = src->nAlloc;
|
||||||
|
dst->window = src->window;
|
||||||
|
dst->status = src->status;
|
||||||
|
|
||||||
|
int32_t nOutputCols = pRuntimeEnv->pQuery->numOfOutputCols;
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < nOutputCols; ++i) {
|
||||||
|
SResultInfo *pDst = &dst->resultInfo[i];
|
||||||
|
SResultInfo *pSrc = &src->resultInfo[i];
|
||||||
|
|
||||||
|
char *buf = pDst->interResultBuf;
|
||||||
|
memcpy(pDst, pSrc, sizeof(SResultInfo));
|
||||||
|
pDst->interResultBuf = buf; // restore the allocated buffer
|
||||||
|
|
||||||
|
// copy the result info struct
|
||||||
|
memcpy(pDst->interResultBuf, pSrc->interResultBuf, pDst->bufLen);
|
||||||
|
|
||||||
|
// copy the output buffer data from src to dst, the position info keep unchanged
|
||||||
|
char * dstBuf = getPosInResultPage(pRuntimeEnv, i, dst);
|
||||||
|
char * srcBuf = getPosInResultPage(pRuntimeEnv, i, (SWindowResult *)src);
|
||||||
|
size_t s = pRuntimeEnv->pQuery->pSelectExpr[i].resBytes;
|
||||||
|
|
||||||
|
memcpy(dstBuf, srcBuf, s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -98,15 +98,15 @@ SCacheObj *taosCacheInit(void *tmrCtrl, int64_t refreshTimeInSeconds);
|
||||||
* @param keepTime survival time in second
|
* @param keepTime survival time in second
|
||||||
* @return cached element
|
* @return cached element
|
||||||
*/
|
*/
|
||||||
void *taosCachePut(void *handle, char *key, char *pData, int dataSize, int keepTimeInSeconds);
|
void *taosCachePut(SCacheObj *pCacheObj, char *key, void *pData, size_t dataSize, int keepTimeInSeconds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get data from cache
|
* get data from cache
|
||||||
* @param handle cache object
|
* @param pCacheObj cache object
|
||||||
* @param key key
|
* @param key key
|
||||||
* @return cached data or NULL
|
* @return cached data or NULL
|
||||||
*/
|
*/
|
||||||
void *taosCacheAcquireByName(void *handle, char *key);
|
void *taosCacheAcquireByName(SCacheObj *pCacheObj, const char *key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add one reference count for the exist data, and assign this data for a new owner.
|
* Add one reference count for the exist data, and assign this data for a new owner.
|
||||||
|
@ -118,7 +118,7 @@ void *taosCacheAcquireByName(void *handle, char *key);
|
||||||
* @param data
|
* @param data
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void *taosCacheAcquireByData(void *handle, void *data);
|
void *taosCacheAcquireByData(SCacheObj *pCacheObj, void *data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* transfer the ownership of data in cache to another object without increasing reference count.
|
* transfer the ownership of data in cache to another object without increasing reference count.
|
||||||
|
@ -126,7 +126,7 @@ void *taosCacheAcquireByData(void *handle, void *data);
|
||||||
* @param data
|
* @param data
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
void *taosCacheTransfer(void *handle, void **data);
|
void *taosCacheTransfer(SCacheObj *pCacheObj, void **data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove data in cache, the data will not be removed immediately.
|
* remove data in cache, the data will not be removed immediately.
|
||||||
|
@ -136,7 +136,7 @@ void *taosCacheTransfer(void *handle, void **data);
|
||||||
* @param _remove force model, reduce the ref count and move the data into
|
* @param _remove force model, reduce the ref count and move the data into
|
||||||
* pTrash
|
* pTrash
|
||||||
*/
|
*/
|
||||||
void taosCacheRelease(void *handle, void **data, bool _remove);
|
void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* move all data node into trash, clear node in trash can if it is not referenced by any clients
|
* move all data node into trash, clear node in trash can if it is not referenced by any clients
|
||||||
|
|
|
@ -22,43 +22,43 @@
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
|
||||||
static FORCE_INLINE void __cache_wr_lock(SCacheObj *pObj) {
|
static FORCE_INLINE void __cache_wr_lock(SCacheObj *pCacheObj) {
|
||||||
#if defined(LINUX)
|
#if defined(LINUX)
|
||||||
pthread_rwlock_wrlock(&pObj->lock);
|
pthread_rwlock_wrlock(&pCacheObj->lock);
|
||||||
#else
|
#else
|
||||||
pthread_mutex_lock(&pObj->lock);
|
pthread_mutex_lock(&pCacheObj->lock);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void __cache_rd_lock(SCacheObj *pObj) {
|
static FORCE_INLINE void __cache_rd_lock(SCacheObj *pCacheObj) {
|
||||||
#if defined(LINUX)
|
#if defined(LINUX)
|
||||||
pthread_rwlock_rdlock(&pObj->lock);
|
pthread_rwlock_rdlock(&pCacheObj->lock);
|
||||||
#else
|
#else
|
||||||
pthread_mutex_lock(&pObj->lock);
|
pthread_mutex_lock(&pCacheObj->lock);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void __cache_unlock(SCacheObj *pObj) {
|
static FORCE_INLINE void __cache_unlock(SCacheObj *pCacheObj) {
|
||||||
#if defined(LINUX)
|
#if defined(LINUX)
|
||||||
pthread_rwlock_unlock(&pObj->lock);
|
pthread_rwlock_unlock(&pCacheObj->lock);
|
||||||
#else
|
#else
|
||||||
pthread_mutex_unlock(&pObj->lock);
|
pthread_mutex_unlock(&pCacheObj->lock);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t __cache_lock_init(SCacheObj *pObj) {
|
static FORCE_INLINE int32_t __cache_lock_init(SCacheObj *pCacheObj) {
|
||||||
#if defined(LINUX)
|
#if defined(LINUX)
|
||||||
return pthread_rwlock_init(&pObj->lock, NULL);
|
return pthread_rwlock_init(&pCacheObj->lock, NULL);
|
||||||
#else
|
#else
|
||||||
return pthread_mutex_init(&pObj->lock, NULL);
|
return pthread_mutex_init(&pCacheObj->lock, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void __cache_lock_destroy(SCacheObj *pObj) {
|
static FORCE_INLINE void __cache_lock_destroy(SCacheObj *pCacheObj) {
|
||||||
#if defined(LINUX)
|
#if defined(LINUX)
|
||||||
pthread_rwlock_destroy(&pObj->lock);
|
pthread_rwlock_destroy(&pCacheObj->lock);
|
||||||
#else
|
#else
|
||||||
pthread_mutex_destroy(&pObj->lock);
|
pthread_mutex_destroy(&pCacheObj->lock);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,10 +105,10 @@ static SCacheDataNode *taosCreateHashNode(const char *key, size_t keyLen, const
|
||||||
/**
|
/**
|
||||||
* addedTime object node into trash, and this object is closed for referencing if it is addedTime to trash
|
* addedTime object node into trash, and this object is closed for referencing if it is addedTime to trash
|
||||||
* It will be removed until the pNode->refCount == 0
|
* It will be removed until the pNode->refCount == 0
|
||||||
* @param pObj Cache object
|
* @param pCacheObj Cache object
|
||||||
* @param pNode Cache slot object
|
* @param pNode Cache slot object
|
||||||
*/
|
*/
|
||||||
static void taosAddToTrash(SCacheObj *pObj, SCacheDataNode *pNode) {
|
static void taosAddToTrash(SCacheObj *pCacheObj, SCacheDataNode *pNode) {
|
||||||
if (pNode->inTrash) { /* node is already in trash */
|
if (pNode->inTrash) { /* node is already in trash */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -116,31 +116,31 @@ static void taosAddToTrash(SCacheObj *pObj, SCacheDataNode *pNode) {
|
||||||
STrashElem *pElem = calloc(1, sizeof(STrashElem));
|
STrashElem *pElem = calloc(1, sizeof(STrashElem));
|
||||||
pElem->pData = pNode;
|
pElem->pData = pNode;
|
||||||
|
|
||||||
pElem->next = pObj->pTrash;
|
pElem->next = pCacheObj->pTrash;
|
||||||
if (pObj->pTrash) {
|
if (pCacheObj->pTrash) {
|
||||||
pObj->pTrash->prev = pElem;
|
pCacheObj->pTrash->prev = pElem;
|
||||||
}
|
}
|
||||||
|
|
||||||
pElem->prev = NULL;
|
pElem->prev = NULL;
|
||||||
pObj->pTrash = pElem;
|
pCacheObj->pTrash = pElem;
|
||||||
|
|
||||||
pNode->inTrash = true;
|
pNode->inTrash = true;
|
||||||
pObj->numOfElemsInTrash++;
|
pCacheObj->numOfElemsInTrash++;
|
||||||
|
|
||||||
pTrace("key:%s %p move to trash, numOfElem in trash:%d", pNode->key, pNode, pObj->numOfElemsInTrash);
|
pTrace("key:%s %p move to trash, numOfElem in trash:%d", pNode->key, pNode, pCacheObj->numOfElemsInTrash);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taosRemoveFromTrash(SCacheObj *pObj, STrashElem *pElem) {
|
static void taosRemoveFromTrash(SCacheObj *pCacheObj, STrashElem *pElem) {
|
||||||
if (pElem->pData->signature != (uint64_t)pElem->pData) {
|
if (pElem->pData->signature != (uint64_t)pElem->pData) {
|
||||||
pError("key:sig:%d %p data has been released, ignore", pElem->pData->signature, pElem->pData);
|
pError("key:sig:%d %p data has been released, ignore", pElem->pData->signature, pElem->pData);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pObj->numOfElemsInTrash--;
|
pCacheObj->numOfElemsInTrash--;
|
||||||
if (pElem->prev) {
|
if (pElem->prev) {
|
||||||
pElem->prev->next = pElem->next;
|
pElem->prev->next = pElem->next;
|
||||||
} else { /* pnode is the header, update header */
|
} else { /* pnode is the header, update header */
|
||||||
pObj->pTrash = pElem->next;
|
pCacheObj->pTrash = pElem->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pElem->next) {
|
if (pElem->next) {
|
||||||
|
@ -154,24 +154,24 @@ static void taosRemoveFromTrash(SCacheObj *pObj, STrashElem *pElem) {
|
||||||
/**
|
/**
|
||||||
* remove nodes in trash with refCount == 0 in cache
|
* remove nodes in trash with refCount == 0 in cache
|
||||||
* @param pNode
|
* @param pNode
|
||||||
* @param pObj
|
* @param pCacheObj
|
||||||
* @param force force model, if true, remove data in trash without check refcount.
|
* @param force force model, if true, remove data in trash without check refcount.
|
||||||
* may cause corruption. So, forece model only applys before cache is closed
|
* may cause corruption. So, forece model only applys before cache is closed
|
||||||
*/
|
*/
|
||||||
static void taosTrashEmpty(SCacheObj *pObj, bool force) {
|
static void taosTrashEmpty(SCacheObj *pCacheObj, bool force) {
|
||||||
__cache_wr_lock(pObj);
|
__cache_wr_lock(pCacheObj);
|
||||||
|
|
||||||
if (pObj->numOfElemsInTrash == 0) {
|
if (pCacheObj->numOfElemsInTrash == 0) {
|
||||||
if (pObj->pTrash != NULL) {
|
if (pCacheObj->pTrash != NULL) {
|
||||||
pError("key:inconsistency data in cache, numOfElem in trash:%d", pObj->numOfElemsInTrash);
|
pError("key:inconsistency data in cache, numOfElem in trash:%d", pCacheObj->numOfElemsInTrash);
|
||||||
}
|
}
|
||||||
pObj->pTrash = NULL;
|
pCacheObj->pTrash = NULL;
|
||||||
|
|
||||||
__cache_unlock(pObj);
|
__cache_unlock(pCacheObj);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
STrashElem *pElem = pObj->pTrash;
|
STrashElem *pElem = pCacheObj->pTrash;
|
||||||
|
|
||||||
while (pElem) {
|
while (pElem) {
|
||||||
T_REF_VAL_CHECK(pElem->pData);
|
T_REF_VAL_CHECK(pElem->pData);
|
||||||
|
@ -181,50 +181,51 @@ static void taosTrashEmpty(SCacheObj *pObj, bool force) {
|
||||||
|
|
||||||
if (force || (T_REF_VAL_GET(pElem->pData) == 0)) {
|
if (force || (T_REF_VAL_GET(pElem->pData) == 0)) {
|
||||||
pTrace("key:%s %p removed from trash. numOfElem in trash:%d", pElem->pData->key, pElem->pData,
|
pTrace("key:%s %p removed from trash. numOfElem in trash:%d", pElem->pData->key, pElem->pData,
|
||||||
pObj->numOfElemsInTrash - 1);
|
pCacheObj->numOfElemsInTrash - 1);
|
||||||
STrashElem *p = pElem;
|
STrashElem *p = pElem;
|
||||||
|
|
||||||
pElem = pElem->next;
|
pElem = pElem->next;
|
||||||
taosRemoveFromTrash(pObj, p);
|
taosRemoveFromTrash(pCacheObj, p);
|
||||||
} else {
|
} else {
|
||||||
pElem = pElem->next;
|
pElem = pElem->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(pObj->numOfElemsInTrash >= 0);
|
assert(pCacheObj->numOfElemsInTrash >= 0);
|
||||||
__cache_unlock(pObj);
|
__cache_unlock(pCacheObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* release node
|
* release node
|
||||||
* @param pObj cache object
|
* @param pCacheObj cache object
|
||||||
* @param pNode data node
|
* @param pNode data node
|
||||||
*/
|
*/
|
||||||
static FORCE_INLINE void taosCacheReleaseNode(SCacheObj *pObj, SCacheDataNode *pNode) {
|
static FORCE_INLINE void taosCacheReleaseNode(SCacheObj *pCacheObj, SCacheDataNode *pNode) {
|
||||||
if (pNode->signature != (uint64_t)pNode) {
|
if (pNode->signature != (uint64_t)pNode) {
|
||||||
pError("key:%s, %p data is invalid, or has been released", pNode->key, pNode);
|
pError("key:%s, %p data is invalid, or has been released", pNode->key, pNode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosHashRemove(pObj->pHashTable, pNode->key, pNode->keySize);
|
int32_t size = pNode->size;
|
||||||
pTrace("key:%s is removed from cache,total:%d,size:%ldbytes", pNode->key, pObj->totalSize, pObj->totalSize);
|
taosHashRemove(pCacheObj->pHashTable, pNode->key, pNode->keySize);
|
||||||
|
|
||||||
|
pTrace("key:%s is removed from cache,total:%d,size:%ldbytes", pNode->key, pCacheObj->totalSize, size);
|
||||||
free(pNode);
|
free(pNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* move the old node into trash
|
* move the old node into trash
|
||||||
* @param pObj
|
* @param pCacheObj
|
||||||
* @param pNode
|
* @param pNode
|
||||||
*/
|
*/
|
||||||
static FORCE_INLINE void taosCacheMoveToTrash(SCacheObj *pObj, SCacheDataNode *pNode) {
|
static FORCE_INLINE void taosCacheMoveToTrash(SCacheObj *pCacheObj, SCacheDataNode *pNode) {
|
||||||
taosHashRemove(pObj->pHashTable, pNode->key, pNode->keySize);
|
taosHashRemove(pCacheObj->pHashTable, pNode->key, pNode->keySize);
|
||||||
taosAddToTrash(pObj, pNode);
|
taosAddToTrash(pCacheObj, pNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update data in cache
|
* update data in cache
|
||||||
* @param pObj
|
* @param pCacheObj
|
||||||
* @param pNode
|
* @param pNode
|
||||||
* @param key
|
* @param key
|
||||||
* @param keyLen
|
* @param keyLen
|
||||||
|
@ -232,7 +233,7 @@ static FORCE_INLINE void taosCacheMoveToTrash(SCacheObj *pObj, SCacheDataNode *p
|
||||||
* @param dataSize
|
* @param dataSize
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pObj, SCacheDataNode *pNode, char *key, int32_t keyLen,
|
static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pCacheObj, SCacheDataNode *pNode, char *key, int32_t keyLen,
|
||||||
void *pData, uint32_t dataSize, uint64_t duration) {
|
void *pData, uint32_t dataSize, uint64_t duration) {
|
||||||
SCacheDataNode *pNewNode = NULL;
|
SCacheDataNode *pNewNode = NULL;
|
||||||
|
|
||||||
|
@ -259,9 +260,9 @@ static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pObj, SCacheDataNode *pNod
|
||||||
T_REF_INC(pNewNode);
|
T_REF_INC(pNewNode);
|
||||||
|
|
||||||
// the address of this node may be changed, so the prev and next element should update the corresponding pointer
|
// the address of this node may be changed, so the prev and next element should update the corresponding pointer
|
||||||
taosHashPut(pObj->pHashTable, key, keyLen, &pNewNode, sizeof(void *));
|
taosHashPut(pCacheObj->pHashTable, key, keyLen, &pNewNode, sizeof(void *));
|
||||||
} else {
|
} else {
|
||||||
taosCacheMoveToTrash(pObj, pNode);
|
taosCacheMoveToTrash(pCacheObj, pNode);
|
||||||
|
|
||||||
pNewNode = taosCreateHashNode(key, keyLen, pData, dataSize, duration);
|
pNewNode = taosCreateHashNode(key, keyLen, pData, dataSize, duration);
|
||||||
if (pNewNode == NULL) {
|
if (pNewNode == NULL) {
|
||||||
|
@ -271,7 +272,7 @@ static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pObj, SCacheDataNode *pNod
|
||||||
T_REF_INC(pNewNode);
|
T_REF_INC(pNewNode);
|
||||||
|
|
||||||
// addedTime new element to hashtable
|
// addedTime new element to hashtable
|
||||||
taosHashPut(pObj->pHashTable, key, keyLen, &pNewNode, sizeof(void *));
|
taosHashPut(pCacheObj->pHashTable, key, keyLen, &pNewNode, sizeof(void *));
|
||||||
}
|
}
|
||||||
|
|
||||||
return pNewNode;
|
return pNewNode;
|
||||||
|
@ -282,12 +283,12 @@ static SCacheDataNode *taosUpdateCacheImpl(SCacheObj *pObj, SCacheDataNode *pNod
|
||||||
* @param key
|
* @param key
|
||||||
* @param pData
|
* @param pData
|
||||||
* @param size
|
* @param size
|
||||||
* @param pObj
|
* @param pCacheObj
|
||||||
* @param keyLen
|
* @param keyLen
|
||||||
* @param pNode
|
* @param pNode
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static FORCE_INLINE SCacheDataNode *taosAddToCacheImpl(SCacheObj *pObj, char *key, size_t keyLen, const void *pData,
|
static FORCE_INLINE SCacheDataNode *taosAddToCacheImpl(SCacheObj *pCacheObj, char *key, size_t keyLen, const void *pData,
|
||||||
size_t dataSize, uint64_t duration) {
|
size_t dataSize, uint64_t duration) {
|
||||||
SCacheDataNode *pNode = taosCreateHashNode(key, keyLen, pData, dataSize, duration);
|
SCacheDataNode *pNode = taosCreateHashNode(key, keyLen, pData, dataSize, duration);
|
||||||
if (pNode == NULL) {
|
if (pNode == NULL) {
|
||||||
|
@ -295,70 +296,70 @@ static FORCE_INLINE SCacheDataNode *taosAddToCacheImpl(SCacheObj *pObj, char *ke
|
||||||
}
|
}
|
||||||
|
|
||||||
T_REF_INC(pNode);
|
T_REF_INC(pNode);
|
||||||
taosHashPut(pObj->pHashTable, key, keyLen, &pNode, sizeof(void *));
|
taosHashPut(pCacheObj->pHashTable, key, keyLen, &pNode, sizeof(void *));
|
||||||
return pNode;
|
return pNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doCleanupDataCache(SCacheObj *pObj) {
|
static void doCleanupDataCache(SCacheObj *pCacheObj) {
|
||||||
__cache_wr_lock(pObj);
|
__cache_wr_lock(pCacheObj);
|
||||||
|
|
||||||
if (taosHashGetSize(pObj->pHashTable) > 0) {
|
if (taosHashGetSize(pCacheObj->pHashTable) > 0) {
|
||||||
taosHashCleanup(pObj->pHashTable);
|
taosHashCleanup(pCacheObj->pHashTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
__cache_unlock(pObj);
|
__cache_unlock(pCacheObj);
|
||||||
|
|
||||||
taosTrashEmpty(pObj, true);
|
taosTrashEmpty(pCacheObj, true);
|
||||||
__cache_lock_destroy(pObj);
|
__cache_lock_destroy(pCacheObj);
|
||||||
|
|
||||||
memset(pObj, 0, sizeof(SCacheObj));
|
memset(pCacheObj, 0, sizeof(SCacheObj));
|
||||||
free(pObj);
|
free(pCacheObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* refresh cache to remove data in both hash list and trash, if any nodes' refcount == 0, every pObj->refreshTime
|
* refresh cache to remove data in both hash list and trash, if any nodes' refcount == 0, every pCacheObj->refreshTime
|
||||||
* @param handle Cache object handle
|
* @param handle Cache object handle
|
||||||
*/
|
*/
|
||||||
static void taosCacheRefresh(void *handle, void *tmrId) {
|
static void taosCacheRefresh(void *handle, void *tmrId) {
|
||||||
SCacheObj *pObj = (SCacheObj *)handle;
|
SCacheObj *pCacheObj = (SCacheObj *)handle;
|
||||||
|
|
||||||
if (pObj == NULL || taosHashGetSize(pObj->pHashTable) == 0) {
|
if (pCacheObj == NULL || taosHashGetSize(pCacheObj->pHashTable) == 0) {
|
||||||
pTrace("object is destroyed. no refresh retry");
|
pTrace("object is destroyed. no refresh retry");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pObj->deleting == 1) {
|
if (pCacheObj->deleting == 1) {
|
||||||
doCleanupDataCache(pObj);
|
doCleanupDataCache(pCacheObj);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t expiredTime = taosGetTimestampMs();
|
uint64_t expiredTime = taosGetTimestampMs();
|
||||||
pObj->statistics.refreshCount++;
|
pCacheObj->statistics.refreshCount++;
|
||||||
|
|
||||||
SHashMutableIterator *pIter = taosHashCreateIter(pObj->pHashTable);
|
SHashMutableIterator *pIter = taosHashCreateIter(pCacheObj->pHashTable);
|
||||||
|
|
||||||
__cache_wr_lock(pObj);
|
__cache_wr_lock(pCacheObj);
|
||||||
while (taosHashIterNext(pIter)) {
|
while (taosHashIterNext(pIter)) {
|
||||||
if (pObj->deleting == 1) {
|
if (pCacheObj->deleting == 1) {
|
||||||
taosHashDestroyIter(pIter);
|
taosHashDestroyIter(pIter);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCacheDataNode *pNode = *(SCacheDataNode **)taosHashIterGet(pIter);
|
SCacheDataNode *pNode = *(SCacheDataNode **)taosHashIterGet(pIter);
|
||||||
if (pNode->expiredTime <= expiredTime && T_REF_VAL_GET(pNode) <= 0) {
|
if (pNode->expiredTime <= expiredTime && T_REF_VAL_GET(pNode) <= 0) {
|
||||||
taosCacheReleaseNode(pObj, pNode);
|
taosCacheReleaseNode(pCacheObj, pNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__cache_unlock(pObj);
|
__cache_unlock(pCacheObj);
|
||||||
|
|
||||||
taosHashDestroyIter(pIter);
|
taosHashDestroyIter(pIter);
|
||||||
|
|
||||||
if (pObj->deleting == 1) { // clean up resources and abort
|
if (pCacheObj->deleting == 1) { // clean up resources and abort
|
||||||
doCleanupDataCache(pObj);
|
doCleanupDataCache(pCacheObj);
|
||||||
} else {
|
} else {
|
||||||
taosTrashEmpty(pObj, false);
|
taosTrashEmpty(pCacheObj, false);
|
||||||
taosTmrReset(taosCacheRefresh, pObj->refreshTime, pObj, pObj->tmrCtrl, &pObj->pTimer);
|
taosTmrReset(taosCacheRefresh, pCacheObj->refreshTime, pCacheObj, pCacheObj->tmrCtrl, &pCacheObj->pTimer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,104 +368,100 @@ SCacheObj *taosCacheInit(void *tmrCtrl, int64_t refreshTime) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCacheObj *pObj = (SCacheObj *)calloc(1, sizeof(SCacheObj));
|
SCacheObj *pCacheObj = (SCacheObj *)calloc(1, sizeof(SCacheObj));
|
||||||
if (pObj == NULL) {
|
if (pCacheObj == NULL) {
|
||||||
pError("failed to allocate memory, reason:%s", strerror(errno));
|
pError("failed to allocate memory, reason:%s", strerror(errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pObj->pHashTable = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false);
|
pCacheObj->pHashTable = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false);
|
||||||
if (pObj->pHashTable == NULL) {
|
if (pCacheObj->pHashTable == NULL) {
|
||||||
free(pObj);
|
free(pCacheObj);
|
||||||
pError("failed to allocate memory, reason:%s", strerror(errno));
|
pError("failed to allocate memory, reason:%s", strerror(errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set free cache node callback function for hash table
|
// set free cache node callback function for hash table
|
||||||
taosHashSetFreecb(pObj->pHashTable, taosFreeNode);
|
taosHashSetFreecb(pCacheObj->pHashTable, taosFreeNode);
|
||||||
|
|
||||||
pObj->refreshTime = refreshTime * 1000;
|
pCacheObj->refreshTime = refreshTime * 1000;
|
||||||
pObj->tmrCtrl = tmrCtrl;
|
pCacheObj->tmrCtrl = tmrCtrl;
|
||||||
|
|
||||||
taosTmrReset(taosCacheRefresh, pObj->refreshTime, pObj, pObj->tmrCtrl, &pObj->pTimer);
|
taosTmrReset(taosCacheRefresh, pCacheObj->refreshTime, pCacheObj, pCacheObj->tmrCtrl, &pCacheObj->pTimer);
|
||||||
|
|
||||||
if (__cache_lock_init(pObj) != 0) {
|
if (__cache_lock_init(pCacheObj) != 0) {
|
||||||
taosTmrStopA(&pObj->pTimer);
|
taosTmrStopA(&pCacheObj->pTimer);
|
||||||
taosHashCleanup(pObj->pHashTable);
|
taosHashCleanup(pCacheObj->pHashTable);
|
||||||
free(pObj);
|
free(pCacheObj);
|
||||||
|
|
||||||
pError("failed to init lock, reason:%s", strerror(errno));
|
pError("failed to init lock, reason:%s", strerror(errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pObj;
|
return pCacheObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *taosCachePut(void *handle, char *key, char *pData, int dataSize, int duration) {
|
void *taosCachePut(SCacheObj *pCacheObj, char *key, void *pData, size_t dataSize, int duration) {
|
||||||
SCacheDataNode *pNode;
|
SCacheDataNode *pNode;
|
||||||
SCacheObj * pObj;
|
|
||||||
|
|
||||||
pObj = (SCacheObj *)handle;
|
if (pCacheObj == NULL || pCacheObj->pHashTable == NULL) {
|
||||||
if (pObj == NULL || pObj->pHashTable == NULL) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t keyLen = strlen(key);
|
size_t keyLen = strlen(key);
|
||||||
|
|
||||||
__cache_wr_lock(pObj);
|
__cache_wr_lock(pCacheObj);
|
||||||
SCacheDataNode **pt = (SCacheDataNode **)taosHashGet(pObj->pHashTable, key, keyLen);
|
SCacheDataNode **pt = (SCacheDataNode **)taosHashGet(pCacheObj->pHashTable, key, keyLen);
|
||||||
SCacheDataNode * pOld = (pt != NULL) ? (*pt) : NULL;
|
SCacheDataNode * pOld = (pt != NULL) ? (*pt) : NULL;
|
||||||
|
|
||||||
if (pOld == NULL) { // do addedTime to cache
|
if (pOld == NULL) { // do addedTime to cache
|
||||||
pNode = taosAddToCacheImpl(pObj, key, keyLen, pData, dataSize, duration * 1000L);
|
pNode = taosAddToCacheImpl(pCacheObj, key, keyLen, pData, dataSize, duration * 1000L);
|
||||||
if (NULL != pNode) {
|
if (NULL != pNode) {
|
||||||
pTrace("key:%s %p added into cache, addedTime:%" PRIu64 ", expireTime:%" PRIu64 ", cache total:%d, size:%" PRId64
|
pCacheObj->totalSize += pNode->size;
|
||||||
" bytes, collision:%d",
|
|
||||||
key, pNode, pNode->addedTime, pNode->expiredTime, dataSize, pObj->totalSize,
|
pTrace("key:%s %p added into cache, added:%" PRIu64 ", expire:%" PRIu64 ", total:%d, size:%" PRId64 " bytes",
|
||||||
pObj->statistics.numOfCollision);
|
key, pNode, pNode->addedTime, pNode->expiredTime, pCacheObj->totalSize, dataSize);
|
||||||
}
|
}
|
||||||
} else { // old data exists, update the node
|
} else { // old data exists, update the node
|
||||||
pNode = taosUpdateCacheImpl(pObj, pOld, key, keyLen, pData, dataSize, duration * 1000L);
|
pNode = taosUpdateCacheImpl(pCacheObj, pOld, key, keyLen, pData, dataSize, duration * 1000L);
|
||||||
pTrace("key:%s %p exist in cache, updated", key, pNode);
|
pTrace("key:%s %p exist in cache, updated", key, pNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
__cache_unlock(pObj);
|
__cache_unlock(pCacheObj);
|
||||||
|
|
||||||
return (pNode != NULL) ? pNode->data : NULL;
|
return (pNode != NULL) ? pNode->data : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *taosCacheAcquireByName(void *handle, char *key) {
|
void *taosCacheAcquireByName(SCacheObj *pCacheObj, const char *key) {
|
||||||
SCacheObj *pObj = (SCacheObj *)handle;
|
if (pCacheObj == NULL || taosHashGetSize(pCacheObj->pHashTable) == 0) {
|
||||||
if (pObj == NULL || taosHashGetSize(pObj->pHashTable) == 0) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t keyLen = (uint32_t)strlen(key);
|
uint32_t keyLen = (uint32_t)strlen(key);
|
||||||
|
|
||||||
__cache_rd_lock(pObj);
|
__cache_rd_lock(pCacheObj);
|
||||||
|
|
||||||
SCacheDataNode **ptNode = (SCacheDataNode **)taosHashGet(pObj->pHashTable, key, keyLen);
|
SCacheDataNode **ptNode = (SCacheDataNode **)taosHashGet(pCacheObj->pHashTable, key, keyLen);
|
||||||
if (ptNode != NULL) {
|
if (ptNode != NULL) {
|
||||||
T_REF_INC(*ptNode);
|
T_REF_INC(*ptNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
__cache_unlock(pObj);
|
__cache_unlock(pCacheObj);
|
||||||
|
|
||||||
if (ptNode != NULL) {
|
if (ptNode != NULL) {
|
||||||
atomic_add_fetch_32(&pObj->statistics.hitCount, 1);
|
atomic_add_fetch_32(&pCacheObj->statistics.hitCount, 1);
|
||||||
pTrace("key:%s is retrieved from cache,refcnt:%d", key, T_REF_VAL_GET(*ptNode));
|
pTrace("key:%s is retrieved from cache,refcnt:%d", key, T_REF_VAL_GET(*ptNode));
|
||||||
} else {
|
} else {
|
||||||
atomic_add_fetch_32(&pObj->statistics.missCount, 1);
|
atomic_add_fetch_32(&pCacheObj->statistics.missCount, 1);
|
||||||
pTrace("key:%s not in cache,retrieved failed", key);
|
pTrace("key:%s not in cache,retrieved failed", key);
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic_add_fetch_32(&pObj->statistics.totalAccess, 1);
|
atomic_add_fetch_32(&pCacheObj->statistics.totalAccess, 1);
|
||||||
return (ptNode != NULL) ? (*ptNode)->data : NULL;
|
return (ptNode != NULL) ? (*ptNode)->data : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *taosCacheAcquireByData(void *handle, void *data) {
|
void *taosCacheAcquireByData(SCacheObj *pCacheObj, void *data) {
|
||||||
SCacheObj *pObj = (SCacheObj *)handle;
|
if (pCacheObj == NULL || data == NULL) return NULL;
|
||||||
if (pObj == NULL || data == NULL) return NULL;
|
|
||||||
|
|
||||||
size_t offset = offsetof(SCacheDataNode, data);
|
size_t offset = offsetof(SCacheDataNode, data);
|
||||||
SCacheDataNode *ptNode = (SCacheDataNode *)((char *)data - offset);
|
SCacheDataNode *ptNode = (SCacheDataNode *)((char *)data - offset);
|
||||||
|
@ -482,9 +479,8 @@ void *taosCacheAcquireByData(void *handle, void *data) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *taosCacheTransfer(void *handle, void **data) {
|
void *taosCacheTransfer(SCacheObj *pCacheObj, void **data) {
|
||||||
SCacheObj *pObj = (SCacheObj *)handle;
|
if (pCacheObj == NULL || data == NULL) return NULL;
|
||||||
if (pObj == NULL || data == NULL) return NULL;
|
|
||||||
|
|
||||||
size_t offset = offsetof(SCacheDataNode, data);
|
size_t offset = offsetof(SCacheDataNode, data);
|
||||||
SCacheDataNode *ptNode = (SCacheDataNode *)((char *)(*data) - offset);
|
SCacheDataNode *ptNode = (SCacheDataNode *)((char *)(*data) - offset);
|
||||||
|
@ -504,9 +500,8 @@ void *taosCacheTransfer(void *handle, void **data) {
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosCacheRelease(void *handle, void **data, bool _remove) {
|
void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) {
|
||||||
SCacheObj *pObj = (SCacheObj *)handle;
|
if (pCacheObj == NULL || (*data) == NULL || (taosHashGetSize(pCacheObj->pHashTable) + pCacheObj->numOfElemsInTrash == 0)) {
|
||||||
if (pObj == NULL || (*data) == NULL || (taosHashGetSize(pObj->pHashTable) + pObj->numOfElemsInTrash == 0)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -522,13 +517,13 @@ void taosCacheRelease(void *handle, void **data, bool _remove) {
|
||||||
*data = NULL;
|
*data = NULL;
|
||||||
|
|
||||||
if (_remove) {
|
if (_remove) {
|
||||||
__cache_wr_lock(pObj);
|
__cache_wr_lock(pCacheObj);
|
||||||
// pNode may be released immediately by other thread after the reference count of pNode is set to 0,
|
// pNode may be released immediately by other thread after the reference count of pNode is set to 0,
|
||||||
// So we need to lock it in the first place.
|
// So we need to lock it in the first place.
|
||||||
T_REF_DEC(pNode);
|
T_REF_DEC(pNode);
|
||||||
taosCacheMoveToTrash(pObj, pNode);
|
taosCacheMoveToTrash(pCacheObj, pNode);
|
||||||
|
|
||||||
__cache_unlock(pObj);
|
__cache_unlock(pCacheObj);
|
||||||
} else {
|
} else {
|
||||||
T_REF_DEC(pNode);
|
T_REF_DEC(pNode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,7 +170,7 @@ typedef struct SQueryRuntimeEnv {
|
||||||
STSCursor cur;
|
STSCursor cur;
|
||||||
SQueryCostSummary summary;
|
SQueryCostSummary summary;
|
||||||
bool stableQuery; // is super table query or not
|
bool stableQuery; // is super table query or not
|
||||||
SQueryDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
SDiskbasedResultBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Temporarily hold the in-memory cache block info during scan cache blocks
|
* Temporarily hold the in-memory cache block info during scan cache blocks
|
||||||
|
|
|
@ -1532,7 +1532,7 @@ static STimeWindow getActiveTimeWindow(SWindowResInfo *pWindowResInfo, int64_t t
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t addNewWindowResultBuf(SWindowResult *pWindowRes, SQueryDiskbasedResultBuf *pResultBuf, int32_t sid,
|
static int32_t addNewWindowResultBuf(SWindowResult *pWindowRes, SDiskbasedResultBuf *pResultBuf, int32_t sid,
|
||||||
int32_t numOfRowsPerPage) {
|
int32_t numOfRowsPerPage) {
|
||||||
if (pWindowRes->pos.pageId != -1) {
|
if (pWindowRes->pos.pageId != -1) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1574,7 +1574,7 @@ static int32_t addNewWindowResultBuf(SWindowResult *pWindowRes, SQueryDiskbasedR
|
||||||
static int32_t setWindowOutputBufByKey(SQueryRuntimeEnv *pRuntimeEnv, SWindowResInfo *pWindowResInfo, int32_t sid,
|
static int32_t setWindowOutputBufByKey(SQueryRuntimeEnv *pRuntimeEnv, SWindowResInfo *pWindowResInfo, int32_t sid,
|
||||||
STimeWindow *win) {
|
STimeWindow *win) {
|
||||||
assert(win->skey <= win->ekey);
|
assert(win->skey <= win->ekey);
|
||||||
SQueryDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf;
|
SDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf;
|
||||||
|
|
||||||
SWindowResult *pWindowRes = doSetTimeWindowFromKey(pRuntimeEnv, pWindowResInfo, (char *)&win->skey, TSDB_KEYSIZE);
|
SWindowResult *pWindowRes = doSetTimeWindowFromKey(pRuntimeEnv, pWindowResInfo, (char *)&win->skey, TSDB_KEYSIZE);
|
||||||
if (pWindowRes == NULL) {
|
if (pWindowRes == NULL) {
|
||||||
|
@ -2156,7 +2156,7 @@ static int32_t setGroupResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, char *pDat
|
||||||
|
|
||||||
int32_t GROUPRESULTID = 1;
|
int32_t GROUPRESULTID = 1;
|
||||||
|
|
||||||
SQueryDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf;
|
SDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf;
|
||||||
|
|
||||||
SWindowResult *pWindowRes = doSetTimeWindowFromKey(pRuntimeEnv, &pRuntimeEnv->windowResInfo, pData, bytes);
|
SWindowResult *pWindowRes = doSetTimeWindowFromKey(pRuntimeEnv, &pRuntimeEnv->windowResInfo, pData, bytes);
|
||||||
if (pWindowRes == NULL) {
|
if (pWindowRes == NULL) {
|
||||||
|
@ -5594,7 +5594,7 @@ void UNUSED_FUNC displayInterResult(SData **pdata, SQuery *pQuery, int32_t numOf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// static tFilePage *getMeterDataPage(SQueryDiskbasedResultBuf *pResultBuf, SMeterQueryInfo *pMeterQueryInfo,
|
// static tFilePage *getMeterDataPage(SDiskbasedResultBuf *pResultBuf, SMeterQueryInfo *pMeterQueryInfo,
|
||||||
// int32_t index) {
|
// int32_t index) {
|
||||||
// SIDList pList = getDataBufPagesIdList(pResultBuf, pMeterQueryInfo->sid);
|
// SIDList pList = getDataBufPagesIdList(pResultBuf, pMeterQueryInfo->sid);
|
||||||
// return getResultBufferPageById(pResultBuf, pList.pData[index]);
|
// return getResultBufferPageById(pResultBuf, pList.pData[index]);
|
||||||
|
@ -5700,7 +5700,7 @@ void copyResToQueryResultBuf(STableQuerySupportObj *pSupporter, SQuery *pQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
|
SQueryRuntimeEnv * pRuntimeEnv = &pSupporter->runtimeEnv;
|
||||||
SQueryDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf;
|
SDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf;
|
||||||
|
|
||||||
int32_t id = getGroupResultId(pSupporter->subgroupIdx - 1);
|
int32_t id = getGroupResultId(pSupporter->subgroupIdx - 1);
|
||||||
SIDList list = getDataBufPagesIdList(pResultBuf, pSupporter->offset + id);
|
SIDList list = getDataBufPagesIdList(pResultBuf, pSupporter->offset + id);
|
||||||
|
@ -5883,7 +5883,7 @@ int32_t doMergeMetersResultsToGroupRes(STableQuerySupportObj *pSupporter, SQuery
|
||||||
|
|
||||||
int32_t flushFromResultBuf(STableQuerySupportObj *pSupporter, const SQuery *pQuery,
|
int32_t flushFromResultBuf(STableQuerySupportObj *pSupporter, const SQuery *pQuery,
|
||||||
const SQueryRuntimeEnv *pRuntimeEnv) {
|
const SQueryRuntimeEnv *pRuntimeEnv) {
|
||||||
SQueryDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf;
|
SDiskbasedResultBuf *pResultBuf = pRuntimeEnv->pResultBuf;
|
||||||
int32_t capacity = (DEFAULT_INTERN_BUF_SIZE - sizeof(tFilePage)) / pQuery->rowSize;
|
int32_t capacity = (DEFAULT_INTERN_BUF_SIZE - sizeof(tFilePage)) / pQuery->rowSize;
|
||||||
|
|
||||||
// the base value for group result, since the maximum number of table for each vnode will not exceed 100,000.
|
// the base value for group result, since the maximum number of table for each vnode will not exceed 100,000.
|
||||||
|
|
|
@ -19,9 +19,11 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "dataformat.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "dataformat.h"
|
#include "tarray.h"
|
||||||
|
#include "name.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -181,23 +183,17 @@ int32_t tsdbInsertData(tsdb_repo_t *pRepo, SSubmitMsg *pMsg);
|
||||||
|
|
||||||
// -- FOR QUERY TIME SERIES DATA
|
// -- FOR QUERY TIME SERIES DATA
|
||||||
|
|
||||||
typedef void tsdb_query_handle_t; // Use void to hide implementation details
|
typedef void* tsdb_query_handle_t; // Use void to hide implementation details
|
||||||
|
|
||||||
// time window
|
|
||||||
typedef struct STimeWindow {
|
|
||||||
int64_t skey;
|
|
||||||
int64_t ekey;
|
|
||||||
} STimeWindow;
|
|
||||||
|
|
||||||
// typedef struct {
|
// typedef struct {
|
||||||
// } SColumnFilterInfo;
|
// } SColumnFilterInfo;
|
||||||
|
|
||||||
// query condition to build vnode iterator
|
// query condition to build vnode iterator
|
||||||
typedef struct STSDBQueryCond {
|
typedef struct STsdbQueryCond {
|
||||||
STimeWindow twindow;
|
STimeWindow twindow;
|
||||||
int32_t order; // desc/asc order to iterate the data block
|
int32_t order; // desc/asc order to iterate the data block
|
||||||
SColumnFilterInfo colFilterInfo;
|
SColumnInfoEx colList;
|
||||||
} STSDBQueryCond;
|
} STsdbQueryCond;
|
||||||
|
|
||||||
typedef struct SBlockInfo {
|
typedef struct SBlockInfo {
|
||||||
STimeWindow window;
|
STimeWindow window;
|
||||||
|
@ -209,15 +205,18 @@ typedef struct SBlockInfo {
|
||||||
} SBlockInfo;
|
} SBlockInfo;
|
||||||
|
|
||||||
// TODO: move this data struct out of the module
|
// TODO: move this data struct out of the module
|
||||||
typedef struct SData {
|
//typedef struct SData {
|
||||||
int32_t num;
|
// int32_t num;
|
||||||
char * data;
|
// char * data;
|
||||||
} SData;
|
//} SData;
|
||||||
|
|
||||||
typedef struct SDataBlock {
|
typedef struct SDataBlockInfo {
|
||||||
|
STimeWindow window;
|
||||||
|
int32_t size;
|
||||||
int32_t numOfCols;
|
int32_t numOfCols;
|
||||||
SData **pData;
|
int64_t uid;
|
||||||
} SDataBlock;
|
int32_t sid;
|
||||||
|
} SDataBlockInfo;
|
||||||
|
|
||||||
typedef struct STableIDList {
|
typedef struct STableIDList {
|
||||||
STableId *tableIds;
|
STableId *tableIds;
|
||||||
|
@ -227,60 +226,40 @@ typedef struct STableIDList {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
} SFields;
|
} SFields;
|
||||||
|
|
||||||
|
#define TSDB_TS_GREATER_EQUAL 1
|
||||||
|
#define TSDB_TS_LESS_EQUAL 2
|
||||||
|
|
||||||
|
typedef struct SQueryRowCond {
|
||||||
|
int32_t rel;
|
||||||
|
TSKEY ts;
|
||||||
|
} SQueryRowCond;
|
||||||
|
|
||||||
|
typedef void *tsdbpos_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the data block iterator, starting from position according to the query condition
|
* Get the data block iterator, starting from position according to the query condition
|
||||||
* @param pRepo the TSDB repository to query on
|
|
||||||
* @param pCond query condition, only includes the filter on primary time stamp
|
* @param pCond query condition, only includes the filter on primary time stamp
|
||||||
* @param pTableList table sid list
|
* @param pTableList table sid list
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
tsdb_query_handle_t *tsdbQueryFromTableID(tsdb_repo_t *pRepo, STSDBQueryCond *pCond, const STableIDList *pTableList);
|
tsdb_query_handle_t *tsdbQueryByTableId(STsdbQueryCond *pCond, SArray *idList, SArray *pColumnInfo);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get iterator for super tables, of which tags values satisfy the tag filter info
|
|
||||||
*
|
|
||||||
* NOTE: the tagFilterStr is an bin-expression for tag filter, such as ((tag_col = 5) and (tag_col2 > 7))
|
|
||||||
* The filter string is sent from client directly.
|
|
||||||
* The build of the tags filter expression from string is done in the iterator generating function.
|
|
||||||
*
|
|
||||||
* @param pRepo the repository to query on
|
|
||||||
* @param pCond query condition
|
|
||||||
* @param pTagFilterStr tag filter info
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
tsdb_query_handle_t *tsdbQueryFromTagConds(tsdb_repo_t *pRepo, STSDBQueryCond *pCond, int16_t stableId,
|
|
||||||
const char *pTagFilterStr);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reset to the start(end) position of current query, from which the iterator starts.
|
|
||||||
*
|
|
||||||
* @param pQueryHandle
|
|
||||||
* @param position set the iterator traverses position. (TSDB_POS_START|TSDB_POS_END)
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
int32_t tsdbResetQuery(tsdb_query_handle_t *pQueryHandle, int16_t position);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* move to next block
|
* move to next block
|
||||||
* @param pQueryHandle
|
* @param pQueryHandle
|
||||||
* @param pCond
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
bool tsdbIterNext(tsdb_query_handle_t *pQueryHandle);
|
bool tsdbNextDataBlock(tsdb_query_handle_t *pQueryHandle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前数据块的信息,调用next函数后,只会获得block的信息,包括:行数、列数、skey/ekey信息。注意该信息并不是现在的SCompBlockInfo信息。
|
|
||||||
* 因为SCompBlockInfo是完整的数据块信息,但是迭代器返回并不是。
|
|
||||||
* 查询处理引擎会自己决定需要blockInfo, 还是预计算数据,亦或是完整的数据。
|
|
||||||
* Get current data block information
|
* Get current data block information
|
||||||
*
|
*
|
||||||
* @param pQueryHandle
|
* @param pQueryHandle
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
SBlockInfo tsdbRetrieveDataBlockInfo(tsdb_query_handle_t *pQueryHandle);
|
SDataBlockInfo tsdbRetrieveDataBlockInfo(tsdb_query_handle_t *pQueryHandle);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前数据块的预计算信息,如果块不完整,无预计算信息,如果是cache块,无预计算信息。
|
|
||||||
*
|
*
|
||||||
* Get the pre-calculated information w.r.t. current data block.
|
* Get the pre-calculated information w.r.t. current data block.
|
||||||
*
|
*
|
||||||
|
@ -290,12 +269,9 @@ SBlockInfo tsdbRetrieveDataBlockInfo(tsdb_query_handle_t *pQueryHandle);
|
||||||
* @pBlockStatis the pre-calculated value for current data blocks. if the block is a cache block, always return 0
|
* @pBlockStatis the pre-calculated value for current data blocks. if the block is a cache block, always return 0
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int32_t tsdbRetrieveDataBlockStatisInfo(tsdb_query_handle_t *pQueryHandle, SFields *pBlockStatis);
|
int32_t tsdbRetrieveDataBlockStatisInfo(tsdb_query_handle_t *pQueryHandle, SDataStatis **pBlockStatis);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回加载到缓存中的数据,可能是磁盘数据也可能是内存数据,对客户透明。即使是磁盘数据,返回的结果也是磁盘块中,满足查询时间范围要求的数据行,并不是一个完整的磁盘数
|
|
||||||
* 据块。
|
|
||||||
*
|
|
||||||
* The query condition with primary timestamp is passed to iterator during its constructor function,
|
* The query condition with primary timestamp is passed to iterator during its constructor function,
|
||||||
* the returned data block must be satisfied with the time window condition in any cases,
|
* the returned data block must be satisfied with the time window condition in any cases,
|
||||||
* which means the SData data block is not actually the completed disk data blocks.
|
* which means the SData data block is not actually the completed disk data blocks.
|
||||||
|
@ -303,7 +279,54 @@ int32_t tsdbRetrieveDataBlockStatisInfo(tsdb_query_handle_t *pQueryHandle, SFiel
|
||||||
* @param pQueryHandle
|
* @param pQueryHandle
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
SDataBlock *tsdbRetrieveDataBlock(tsdb_query_handle_t *pQueryHandle);
|
SArray *tsdbRetrieveDataBlock(tsdb_query_handle_t *pQueryHandle, SArray *pIdList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* todo remove the parameter of position, and order type
|
||||||
|
*
|
||||||
|
* Reset to the start(end) position of current query, from which the iterator starts.
|
||||||
|
*
|
||||||
|
* @param pQueryHandle
|
||||||
|
* @param position set the iterator traverses position
|
||||||
|
* @param order ascending order or descending order
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int32_t tsdbResetQuery(tsdb_query_handle_t *pQueryHandle, STimeWindow* window, tsdbpos_t position, int16_t order);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return the access position of current query handle
|
||||||
|
* @param pQueryHandle
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int32_t tsdbDataBlockSeek(tsdb_query_handle_t *pQueryHandle, tsdbpos_t pos);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* todo remove this function later
|
||||||
|
* @param pQueryHandle
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
tsdbpos_t tsdbDataBlockTell(tsdb_query_handle_t *pQueryHandle);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* todo remove this function later
|
||||||
|
* @param pQueryHandle
|
||||||
|
* @param pIdList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SArray *tsdbRetrieveDataRow(tsdb_query_handle_t *pQueryHandle, SArray *pIdList, SQueryRowCond *pCond);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get iterator for super tables, of which tags values satisfy the tag filter info
|
||||||
|
*
|
||||||
|
* NOTE: the tagFilterStr is an bin-expression for tag filter, such as ((tag_col = 5) and (tag_col2 > 7))
|
||||||
|
* The filter string is sent from client directly.
|
||||||
|
* The build of the tags filter expression from string is done in the iterator generating function.
|
||||||
|
*
|
||||||
|
* @param pCond query condition
|
||||||
|
* @param pTagFilterStr tag filter info
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
tsdb_query_handle_t *tsdbQueryFromTagConds(STsdbQueryCond *pCond, int16_t stableId, const char *pTagFilterStr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the qualified tables for (super) table query.
|
* Get the qualified tables for (super) table query.
|
||||||
|
|
|
@ -12,8 +12,7 @@
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include <stdlib.h>
|
#include "os.h"
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
#include "tsdb.h"
|
||||||
|
|
|
@ -35,6 +35,7 @@ int main(int argc, char *argv[]) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
taos_options(TSDB_OPTION_CONFIGDIR, "~/first/cfg");
|
||||||
// init TAOS
|
// init TAOS
|
||||||
taos_init();
|
taos_init();
|
||||||
|
|
||||||
|
@ -45,6 +46,25 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
printf("success to connect to server\n");
|
printf("success to connect to server\n");
|
||||||
|
|
||||||
|
int32_t code = taos_query(taos, "select * from test.t1");
|
||||||
|
if (code != 0) {
|
||||||
|
printf("failed to execute query, reason:%s\n", taos_errstr(taos));
|
||||||
|
}
|
||||||
|
|
||||||
|
TAOS_RES* res = taos_use_result(taos);
|
||||||
|
TAOS_ROW row = NULL;
|
||||||
|
char buf[512] = {0};
|
||||||
|
|
||||||
|
int32_t numOfFields = taos_num_fields(res);
|
||||||
|
TAOS_FIELD* pFields = taos_fetch_fields(res);
|
||||||
|
|
||||||
|
while((row = taos_fetch_row(res)) != NULL) {
|
||||||
|
taos_print_row(buf, row, pFields, numOfFields);
|
||||||
|
printf("%s\n", buf);
|
||||||
|
memset(buf, 0, 512);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
taos_query(taos, "drop database demo");
|
taos_query(taos, "drop database demo");
|
||||||
if (taos_query(taos, "create database demo") != 0) {
|
if (taos_query(taos, "create database demo") != 0) {
|
||||||
|
@ -90,7 +110,7 @@ int main(int argc, char *argv[]) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TAOS_ROW row;
|
// TAOS_ROW row;
|
||||||
int rows = 0;
|
int rows = 0;
|
||||||
int num_fields = taos_field_count(taos);
|
int num_fields = taos_field_count(taos);
|
||||||
TAOS_FIELD *fields = taos_fetch_fields(result);
|
TAOS_FIELD *fields = taos_fetch_fields(result);
|
||||||
|
|
Loading…
Reference in New Issue