Merge pull request #12865 from taosdata/enh/index_filter
enh: index filter interface
This commit is contained in:
commit
cbc6a43015
|
@ -16,9 +16,11 @@
|
||||||
#ifndef _TD_INDEX_H_
|
#ifndef _TD_INDEX_H_
|
||||||
#define _TD_INDEX_H_
|
#define _TD_INDEX_H_
|
||||||
|
|
||||||
|
#include "nodes.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "tarray.h"
|
#include "tarray.h"
|
||||||
|
#include "tglobal.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -189,6 +191,12 @@ void indexTermDestroy(SIndexTerm* p);
|
||||||
*/
|
*/
|
||||||
void indexInit();
|
void indexInit();
|
||||||
|
|
||||||
|
/* index filter */
|
||||||
|
typedef enum { SFLT_NOT_INDEX, SFLT_COARSE_INDEX, SFLT_ACCURATE_INDEX } SIdxFltStatus;
|
||||||
|
|
||||||
|
SIdxFltStatus idxGetFltStatus(SNode* pFilterNode);
|
||||||
|
|
||||||
|
int32_t doFilterTag(const SNode* pFilterNode, SArray* result);
|
||||||
/*
|
/*
|
||||||
* destory index env
|
* destory index env
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,35 +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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _INDEX_OPERATOR_H
|
|
||||||
#define _INDEX_OPERATOR_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
#include "nodes.h"
|
|
||||||
#include "tglobal.h"
|
|
||||||
|
|
||||||
typedef enum { SFLT_NOT_INDEX, SFLT_COARSE_INDEX, SFLT_ACCURATE_INDEX } SIdxFltStatus;
|
|
||||||
|
|
||||||
SIdxFltStatus idxGetFltStatus(SNode *pFilterNode);
|
|
||||||
// construct tag filter operator later
|
|
||||||
int32_t doFilterTag(const SNode *pFilterNode, SArray *result);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*INDEX_OPERATOR_*/
|
|
|
@ -12,6 +12,9 @@ target_link_libraries(
|
||||||
PUBLIC os
|
PUBLIC os
|
||||||
PUBLIC util
|
PUBLIC util
|
||||||
PUBLIC common
|
PUBLIC common
|
||||||
|
PUBLIC nodes
|
||||||
|
PUBLIC scalar
|
||||||
|
PUBLIC function
|
||||||
)
|
)
|
||||||
|
|
||||||
if (${BUILD_WITH_LUCENE})
|
if (${BUILD_WITH_LUCENE})
|
||||||
|
|
|
@ -13,10 +13,11 @@
|
||||||
* 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 "indexoperator.h"
|
|
||||||
#include "executorimpl.h"
|
|
||||||
#include "index.h"
|
#include "index.h"
|
||||||
|
#include "indexInt.h"
|
||||||
#include "nodes.h"
|
#include "nodes.h"
|
||||||
|
#include "querynodes.h"
|
||||||
|
#include "scalar.h"
|
||||||
#include "tdatablock.h"
|
#include "tdatablock.h"
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
@ -69,9 +70,9 @@ typedef int32_t (*sif_func_t)(SIFParam *left, SIFParam *rigth, SIFParam *output)
|
||||||
static sif_func_t sifNullFunc = NULL;
|
static sif_func_t sifNullFunc = NULL;
|
||||||
// typedef struct SIFWalkParm
|
// typedef struct SIFWalkParm
|
||||||
// construct tag filter operator later
|
// construct tag filter operator later
|
||||||
static void destroyTagFilterOperatorInfo(void *param) {
|
// static void destroyTagFilterOperatorInfo(void *param) {
|
||||||
STagFilterOperatorInfo *pInfo = (STagFilterOperatorInfo *)param;
|
// STagFilterOperatorInfo *pInfo = (STagFilterOperatorInfo *)param;
|
||||||
}
|
//}
|
||||||
|
|
||||||
static void sifFreeParam(SIFParam *param) {
|
static void sifFreeParam(SIFParam *param) {
|
||||||
if (param == NULL) return;
|
if (param == NULL) return;
|
||||||
|
@ -178,13 +179,13 @@ static int32_t sifInitParam(SNode *node, SIFParam *param, SIFCtx *ctx) {
|
||||||
case QUERY_NODE_NODE_LIST: {
|
case QUERY_NODE_NODE_LIST: {
|
||||||
SNodeListNode *nl = (SNodeListNode *)node;
|
SNodeListNode *nl = (SNodeListNode *)node;
|
||||||
if (LIST_LENGTH(nl->pNodeList) <= 0) {
|
if (LIST_LENGTH(nl->pNodeList) <= 0) {
|
||||||
qError("invalid length for node:%p, length: %d", node, LIST_LENGTH(nl->pNodeList));
|
indexError("invalid length for node:%p, length: %d", node, LIST_LENGTH(nl->pNodeList));
|
||||||
SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||||
}
|
}
|
||||||
SIF_ERR_RET(scalarGenerateSetFromList((void **)¶m->pFilter, node, nl->dataType.type));
|
SIF_ERR_RET(scalarGenerateSetFromList((void **)¶m->pFilter, node, nl->dataType.type));
|
||||||
if (taosHashPut(ctx->pRes, &node, POINTER_BYTES, param, sizeof(*param))) {
|
if (taosHashPut(ctx->pRes, &node, POINTER_BYTES, param, sizeof(*param))) {
|
||||||
taosHashCleanup(param->pFilter);
|
taosHashCleanup(param->pFilter);
|
||||||
qError("taosHashPut nodeList failed, size:%d", (int32_t)sizeof(*param));
|
indexError("taosHashPut nodeList failed, size:%d", (int32_t)sizeof(*param));
|
||||||
SIF_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
SIF_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -194,7 +195,7 @@ static int32_t sifInitParam(SNode *node, SIFParam *param, SIFCtx *ctx) {
|
||||||
case QUERY_NODE_LOGIC_CONDITION: {
|
case QUERY_NODE_LOGIC_CONDITION: {
|
||||||
SIFParam *res = (SIFParam *)taosHashGet(ctx->pRes, &node, POINTER_BYTES);
|
SIFParam *res = (SIFParam *)taosHashGet(ctx->pRes, &node, POINTER_BYTES);
|
||||||
if (NULL == res) {
|
if (NULL == res) {
|
||||||
qError("no result for node, type:%d, node:%p", nodeType(node), node);
|
indexError("no result for node, type:%d, node:%p", nodeType(node), node);
|
||||||
SIF_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
SIF_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||||
}
|
}
|
||||||
*param = *res;
|
*param = *res;
|
||||||
|
@ -210,7 +211,7 @@ static int32_t sifInitOperParams(SIFParam **params, SOperatorNode *node, SIFCtx
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t nParam = sifGetOperParamNum(node->opType);
|
int32_t nParam = sifGetOperParamNum(node->opType);
|
||||||
if (NULL == node->pLeft || (nParam == 2 && NULL == node->pRight)) {
|
if (NULL == node->pLeft || (nParam == 2 && NULL == node->pRight)) {
|
||||||
qError("invalid operation node, left: %p, rigth: %p", node->pLeft, node->pRight);
|
indexError("invalid operation node, left: %p, rigth: %p", node->pLeft, node->pRight);
|
||||||
SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||||
}
|
}
|
||||||
SIFParam *paramList = taosMemoryCalloc(nParam, sizeof(SIFParam));
|
SIFParam *paramList = taosMemoryCalloc(nParam, sizeof(SIFParam));
|
||||||
|
@ -232,7 +233,7 @@ static int32_t sifInitParamList(SIFParam **params, SNodeList *nodeList, SIFCtx *
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SIFParam *tParams = taosMemoryCalloc(nodeList->length, sizeof(SIFParam));
|
SIFParam *tParams = taosMemoryCalloc(nodeList->length, sizeof(SIFParam));
|
||||||
if (tParams == NULL) {
|
if (tParams == NULL) {
|
||||||
qError("failed to calloc, nodeList: %p", nodeList);
|
indexError("failed to calloc, nodeList: %p", nodeList);
|
||||||
SIF_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
SIF_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +253,7 @@ _return:
|
||||||
SIF_RET(code);
|
SIF_RET(code);
|
||||||
}
|
}
|
||||||
static int32_t sifExecFunction(SFunctionNode *node, SIFCtx *ctx, SIFParam *output) {
|
static int32_t sifExecFunction(SFunctionNode *node, SIFCtx *ctx, SIFParam *output) {
|
||||||
qError("index-filter not support buildin function");
|
indexError("index-filter not support buildin function");
|
||||||
return TSDB_CODE_QRY_INVALID_INPUT;
|
return TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
}
|
}
|
||||||
static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFParam *output) {
|
static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFParam *output) {
|
||||||
|
@ -390,7 +391,7 @@ _return:
|
||||||
|
|
||||||
static int32_t sifExecLogic(SLogicConditionNode *node, SIFCtx *ctx, SIFParam *output) {
|
static int32_t sifExecLogic(SLogicConditionNode *node, SIFCtx *ctx, SIFParam *output) {
|
||||||
if (NULL == node->pParameterList || node->pParameterList->length <= 0) {
|
if (NULL == node->pParameterList || node->pParameterList->length <= 0) {
|
||||||
qError("invalid logic parameter list, list:%p, paramNum:%d", node->pParameterList,
|
indexError("invalid logic parameter list, list:%p, paramNum:%d", node->pParameterList,
|
||||||
node->pParameterList ? node->pParameterList->length : 0);
|
node->pParameterList ? node->pParameterList->length : 0);
|
||||||
return TSDB_CODE_QRY_INVALID_INPUT;
|
return TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
}
|
}
|
||||||
|
@ -485,7 +486,7 @@ EDealRes sifCalcWalker(SNode *node, void *context) {
|
||||||
return sifWalkOper(node, ctx);
|
return sifWalkOper(node, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
qError("invalid node type for index filter calculating, type:%d", nodeType(node));
|
indexError("invalid node type for index filter calculating, type:%d", nodeType(node));
|
||||||
ctx->code = TSDB_CODE_QRY_INVALID_INPUT;
|
ctx->code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
return DEAL_RES_ERROR;
|
return DEAL_RES_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -509,7 +510,7 @@ static int32_t sifCalculate(SNode *pNode, SIFParam *pDst) {
|
||||||
SIFCtx ctx = {.code = 0, .noExec = false};
|
SIFCtx ctx = {.code = 0, .noExec = false};
|
||||||
ctx.pRes = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
ctx.pRes = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
||||||
if (NULL == ctx.pRes) {
|
if (NULL == ctx.pRes) {
|
||||||
qError("index-filter failed to taosHashInit");
|
indexError("index-filter failed to taosHashInit");
|
||||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,7 +520,7 @@ static int32_t sifCalculate(SNode *pNode, SIFParam *pDst) {
|
||||||
if (pDst) {
|
if (pDst) {
|
||||||
SIFParam *res = (SIFParam *)taosHashGet(ctx.pRes, (void *)&pNode, POINTER_BYTES);
|
SIFParam *res = (SIFParam *)taosHashGet(ctx.pRes, (void *)&pNode, POINTER_BYTES);
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
qError("no valid res in hash, node:(%p), type(%d)", (void *)&pNode, nodeType(pNode));
|
indexError("no valid res in hash, node:(%p), type(%d)", (void *)&pNode, nodeType(pNode));
|
||||||
SIF_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
SIF_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||||
}
|
}
|
||||||
taosArrayAddAll(pDst->result, res->result);
|
taosArrayAddAll(pDst->result, res->result);
|
||||||
|
@ -539,7 +540,7 @@ static int32_t sifGetFltHint(SNode *pNode, SIdxFltStatus *status) {
|
||||||
SIFCtx ctx = {.code = 0, .noExec = true};
|
SIFCtx ctx = {.code = 0, .noExec = true};
|
||||||
ctx.pRes = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
ctx.pRes = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
||||||
if (NULL == ctx.pRes) {
|
if (NULL == ctx.pRes) {
|
||||||
qError("index-filter failed to taosHashInit");
|
indexError("index-filter failed to taosHashInit");
|
||||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -549,7 +550,7 @@ static int32_t sifGetFltHint(SNode *pNode, SIdxFltStatus *status) {
|
||||||
|
|
||||||
SIFParam *res = (SIFParam *)taosHashGet(ctx.pRes, (void *)&pNode, POINTER_BYTES);
|
SIFParam *res = (SIFParam *)taosHashGet(ctx.pRes, (void *)&pNode, POINTER_BYTES);
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
qError("no valid res in hash, node:(%p), type(%d)", (void *)&pNode, nodeType(pNode));
|
indexError("no valid res in hash, node:(%p), type(%d)", (void *)&pNode, nodeType(pNode));
|
||||||
SIF_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
SIF_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||||
}
|
}
|
||||||
*status = res->status;
|
*status = res->status;
|
Loading…
Reference in New Issue