Merge pull request #26292 from taosdata/fix/TD-30620
Add index filtering based on column value type
This commit is contained in:
commit
10237869d9
|
@ -624,6 +624,23 @@ static int32_t sifSetFltParam(SIFParam *left, SIFParam *right, SDataTypeBuf *typ
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int8_t sifShouldUseIndexBasedOnType(SIFParam *left, SIFParam *right) {
|
||||||
|
// not compress
|
||||||
|
if (left->colValType == TSDB_DATA_TYPE_FLOAT) return 0;
|
||||||
|
|
||||||
|
if (left->colValType == TSDB_DATA_TYPE_GEOMETRY || right->colValType == TSDB_DATA_TYPE_GEOMETRY ||
|
||||||
|
left->colValType == TSDB_DATA_TYPE_JSON || right->colValType == TSDB_DATA_TYPE_JSON) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IS_VAR_DATA_TYPE(left->colValType)) {
|
||||||
|
if (!IS_VAR_DATA_TYPE(right->colValType)) return 0;
|
||||||
|
} else if (IS_NUMERIC_TYPE(left->colValType)) {
|
||||||
|
if (left->colValType != right->colValType) return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
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) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
SIndexMetaArg *arg = &output->arg;
|
SIndexMetaArg *arg = &output->arg;
|
||||||
|
@ -641,8 +658,10 @@ static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFP
|
||||||
ret = indexJsonSearch(arg->ivtIdx, mtm, output->result);
|
ret = indexJsonSearch(arg->ivtIdx, mtm, output->result);
|
||||||
indexMultiTermQueryDestroy(mtm);
|
indexMultiTermQueryDestroy(mtm);
|
||||||
} else {
|
} else {
|
||||||
if (left->colValType == TSDB_DATA_TYPE_GEOMETRY || right->colValType == TSDB_DATA_TYPE_GEOMETRY) {
|
int8_t useIndex = sifShouldUseIndexBasedOnType(left, right);
|
||||||
return TSDB_CODE_QRY_GEO_NOT_SUPPORT_ERROR;
|
if (!useIndex) {
|
||||||
|
output->status = SFLT_NOT_INDEX;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool reverse = false, equal = false;
|
bool reverse = false, equal = false;
|
||||||
|
@ -660,15 +679,12 @@ static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFP
|
||||||
|
|
||||||
SDataTypeBuf typedata;
|
SDataTypeBuf typedata;
|
||||||
memset(&typedata, 0, sizeof(typedata));
|
memset(&typedata, 0, sizeof(typedata));
|
||||||
if (IS_VAR_DATA_TYPE(left->colValType)) {
|
|
||||||
if (!IS_VAR_DATA_TYPE(right->colValType)) {
|
if (sifSetFltParam(left, right, &typedata, ¶m) != 0) {
|
||||||
NUM_TO_STRING(right->colValType, right->condValue, sizeof(buf) - 2, buf + VARSTR_HEADER_SIZE);
|
output->status = SFLT_NOT_INDEX;
|
||||||
varDataSetLen(buf, strlen(buf + VARSTR_HEADER_SIZE));
|
return -1;
|
||||||
param.val = buf;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (sifSetFltParam(left, right, &typedata, ¶m) != 0) return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = left->api.metaFilterTableIds(arg->metaEx, ¶m, output->result);
|
ret = left->api.metaFilterTableIds(arg->metaEx, ¶m, output->result);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
taosArraySort(output->result, uidCompare);
|
taosArraySort(output->result, uidCompare);
|
||||||
|
|
|
@ -1488,12 +1488,14 @@
|
||||||
,,y,script,./test.sh -f tmp/monitor.sim
|
,,y,script,./test.sh -f tmp/monitor.sim
|
||||||
,,y,script,./test.sh -f tsim/tagindex/add_index.sim
|
,,y,script,./test.sh -f tsim/tagindex/add_index.sim
|
||||||
,,n,script,./test.sh -f tsim/tagindex/sma_and_tag_index.sim
|
,,n,script,./test.sh -f tsim/tagindex/sma_and_tag_index.sim
|
||||||
|
,,y,script,./test.sh -f tsim/tagindex/indexOverflow.sim
|
||||||
,,y,script,./test.sh -f tsim/view/view.sim
|
,,y,script,./test.sh -f tsim/view/view.sim
|
||||||
,,y,script,./test.sh -f tsim/query/cache_last.sim
|
,,y,script,./test.sh -f tsim/query/cache_last.sim
|
||||||
,,y,script,./test.sh -f tsim/query/const.sim
|
,,y,script,./test.sh -f tsim/query/const.sim
|
||||||
,,y,script,./test.sh -f tsim/query/nestedJoinView.sim
|
,,y,script,./test.sh -f tsim/query/nestedJoinView.sim
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#develop test
|
#develop test
|
||||||
,,n,develop-test,python3 ./test.py -f 2-query/table_count_scan.py
|
,,n,develop-test,python3 ./test.py -f 2-query/table_count_scan.py
|
||||||
,,n,develop-test,python3 ./test.py -f 2-query/pseudo_column.py
|
,,n,develop-test,python3 ./test.py -f 2-query/pseudo_column.py
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
|
||||||
|
system sh/stop_dnodes.sh
|
||||||
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
sql connect
|
||||||
|
|
||||||
|
print ======== step0
|
||||||
|
$dbPrefix = ta_3_db
|
||||||
|
$tbPrefix = ta_3_tb
|
||||||
|
$mtPrefix = ta_3_mt
|
||||||
|
$lastRowNum = 0
|
||||||
|
$tbNum = 100000
|
||||||
|
$rowNum = 20
|
||||||
|
$totalNum = 200
|
||||||
|
|
||||||
|
print =============== create database
|
||||||
|
sql create database $dbPrefix
|
||||||
|
sql use $dbPrefix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sql create table if not exists $mtPrefix (ts timestamp, c1 int) tags (t1 tinyint, t1c tinyint)
|
||||||
|
$i = 0
|
||||||
|
$tinyLimit = 127
|
||||||
|
$tinyTable = tinyTable
|
||||||
|
while $i < $tinyLimit
|
||||||
|
$tb = $tinyTable . $i
|
||||||
|
sql insert into $tb using $mtPrefix tags( $i , $i ) values( now , $i )
|
||||||
|
$i = $i + 1
|
||||||
|
endw
|
||||||
|
|
||||||
|
$i = 0
|
||||||
|
$maxTinyLimit = 200
|
||||||
|
|
||||||
|
# 1. compress index and no-index to verify resultset
|
||||||
|
# 2. compress resultset of index filter and scalar filter
|
||||||
|
while $i < $maxTinyLimit
|
||||||
|
sql select * from $mtPrefix where t1 <= $i
|
||||||
|
$lastRowNum = $rows
|
||||||
|
|
||||||
|
sql select * from $mtPrefix where t1c <= $i
|
||||||
|
if $lastRowNum != $rows then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
$i = $i + 1
|
||||||
|
endw
|
||||||
|
|
||||||
|
|
||||||
|
$tbPrefix = ta_3_tb_c
|
||||||
|
$mtPrefix = ta_3_mt_c
|
||||||
|
$colPrefix = 'col'
|
||||||
|
sql create table if not exists $mtPrefix (ts timestamp, c1 int) tags (t1 nchar(18), t1c nchar(18))
|
||||||
|
$i = 0
|
||||||
|
$tinyLimit = 127
|
||||||
|
while $i < $tinyLimit
|
||||||
|
$tb = $tbPrefix . $i
|
||||||
|
sql insert into $tb using $mtPrefix tags( $colPrefix , $colPrefix ) values( now , $i )
|
||||||
|
$i = $i + 1
|
||||||
|
endw
|
||||||
|
|
||||||
|
$i = 0
|
||||||
|
$maxTinyLimit = 200
|
||||||
|
|
||||||
|
# 1. compress index and no-index to verify resultset
|
||||||
|
# 2. compress resultset of index filter and scalar filter
|
||||||
|
while $i < $maxTinyLimit
|
||||||
|
sql select * from $mtPrefix where t1 <= $i
|
||||||
|
$lastRowNum = $rows
|
||||||
|
|
||||||
|
sql select * from $mtPrefix where t1c <= $i
|
||||||
|
if $lastRowNum != $rows then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
$i = $i + 1
|
||||||
|
endw
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -401,6 +401,7 @@
|
||||||
./test.sh -f tsim/tag/tbNameIn.sim
|
./test.sh -f tsim/tag/tbNameIn.sim
|
||||||
./test.sh -f tmp/monitor.sim
|
./test.sh -f tmp/monitor.sim
|
||||||
./test.sh -f tsim/tagindex/add_index.sim
|
./test.sh -f tsim/tagindex/add_index.sim
|
||||||
|
./test.sh -f tsim/tagindex/indexOverflow.sim
|
||||||
./test.sh -f tsim/tagindex/sma_and_tag_index.sim
|
./test.sh -f tsim/tagindex/sma_and_tag_index.sim
|
||||||
./test.sh -f tsim/view/view.sim
|
./test.sh -f tsim/view/view.sim
|
||||||
./test.sh -f tsim/query/cache_last.sim
|
./test.sh -f tsim/query/cache_last.sim
|
||||||
|
|
Loading…
Reference in New Issue