Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
46527878
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1193
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
46527878
编写于
5月 28, 2022
作者:
dengyihao
提交者:
GitHub
5月 28, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #13159 from taosdata/enh/tagFlt
Enh/tag flt
上级
c4782752
ddab6752
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
442 addition
and
345 deletion
+442
-345
include/libs/index/index.h
include/libs/index/index.h
+6
-1
source/common/src/tdatablock.c
source/common/src/tdatablock.c
+3
-1
source/common/src/tglobal.c
source/common/src/tglobal.c
+1
-1
source/dnode/vnode/inc/vnode.h
source/dnode/vnode/inc/vnode.h
+11
-9
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+1
-0
source/dnode/vnode/src/meta/metaTable.c
source/dnode/vnode/src/meta/metaTable.c
+27
-19
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+92
-83
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+25
-17
source/libs/index/inc/indexCache.h
source/libs/index/inc/indexCache.h
+1
-1
source/libs/index/inc/indexTfile.h
source/libs/index/inc/indexTfile.h
+2
-2
source/libs/index/inc/indexUtil.h
source/libs/index/inc/indexUtil.h
+14
-9
source/libs/index/src/index.c
source/libs/index/src/index.c
+17
-15
source/libs/index/src/indexCache.c
source/libs/index/src/indexCache.c
+56
-57
source/libs/index/src/indexFilter.c
source/libs/index/src/indexFilter.c
+29
-12
source/libs/index/src/indexTfile.c
source/libs/index/src/indexTfile.c
+48
-48
source/libs/index/src/indexUtil.c
source/libs/index/src/indexUtil.c
+41
-38
source/libs/index/test/CMakeLists.txt
source/libs/index/test/CMakeLists.txt
+24
-24
source/libs/index/test/indexTests.cc
source/libs/index/test/indexTests.cc
+6
-6
source/libs/index/test/utilUT.cc
source/libs/index/test/utilUT.cc
+38
-2
未找到文件。
include/libs/index/index.h
浏览文件 @
46527878
...
...
@@ -192,11 +192,16 @@ void indexTermDestroy(SIndexTerm* p);
void
indexInit
();
/* index filter */
typedef
struct
SIndexMetaArg
{
void
*
metaHandle
;
uint64_t
suid
;
}
SIndexMetaArg
;
typedef
enum
{
SFLT_NOT_INDEX
,
SFLT_COARSE_INDEX
,
SFLT_ACCURATE_INDEX
}
SIdxFltStatus
;
SIdxFltStatus
idxGetFltStatus
(
SNode
*
pFilterNode
);
int32_t
doFilterTag
(
const
SNode
*
pFilterNode
,
SArray
*
result
);
int32_t
doFilterTag
(
const
SNode
*
pFilterNode
,
S
IndexMetaArg
*
metaArg
,
S
Array
*
result
);
/*
* destory index env
*
...
...
source/common/src/tdatablock.c
浏览文件 @
46527878
...
...
@@ -1153,7 +1153,9 @@ void colInfoDataCleanup(SColumnInfoData* pColumn, uint32_t numOfRows) {
if
(
IS_VAR_DATA_TYPE
(
pColumn
->
info
.
type
))
{
pColumn
->
varmeta
.
length
=
0
;
}
else
{
memset
(
pColumn
->
nullbitmap
,
0
,
BitmapLen
(
numOfRows
));
if
(
pColumn
->
nullbitmap
!=
NULL
)
{
memset
(
pColumn
->
nullbitmap
,
0
,
BitmapLen
(
numOfRows
));
}
}
}
...
...
source/common/src/tglobal.c
浏览文件 @
46527878
...
...
@@ -293,7 +293,7 @@ int32_t taosAddClientLogCfg(SConfig *pCfg) {
if
(
cfgAddInt32
(
pCfg
,
"jniDebugFlag"
,
jniDebugFlag
,
0
,
255
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"simDebugFlag"
,
143
,
0
,
255
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"debugFlag"
,
0
,
0
,
255
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"idxDebugFlag"
,
0
,
0
,
255
,
1
)
!=
0
)
return
-
1
;
if
(
cfgAddInt32
(
pCfg
,
"idxDebugFlag"
,
idxDebugFlag
,
0
,
255
,
1
)
!=
0
)
return
-
1
;
return
0
;
}
...
...
source/dnode/vnode/inc/vnode.h
浏览文件 @
46527878
...
...
@@ -105,10 +105,12 @@ tsdbReaderT tsdbQueryCacheLast(SVnode *pVnode, SQueryTableDataCond *pCond, STab
void
*
pMemRef
);
int32_t
tsdbGetFileBlocksDistInfo
(
tsdbReaderT
*
pReader
,
STableBlockDistInfo
*
pTableBlockInfo
);
bool
isTsdbCacheLastRow
(
tsdbReaderT
*
pReader
);
int32_t
tsdbGetAllTableList
(
SMeta
*
pMeta
,
uint64_t
uid
,
SArray
*
list
);
int32_t
tsdbGetAllTableList
(
SMeta
*
pMeta
,
uint64_t
uid
,
SArray
*
list
);
void
*
tsdbGetIdx
(
SMeta
*
pMeta
);
int64_t
tsdbGetNumOfRowsInMemTable
(
tsdbReaderT
*
pHandle
);
bool
tsdbNextDataBlock
(
tsdbReaderT
pTsdbReadHandle
);
void
tsdbRetrieveDataBlockInfo
(
tsdbReaderT
*
pTsdbReadHandle
,
SDataBlockInfo
*
pBlockInfo
);
bool
tsdbNextDataBlock
(
tsdbReaderT
pTsdbReadHandle
);
void
tsdbRetrieveDataBlockInfo
(
tsdbReaderT
*
pTsdbReadHandle
,
SDataBlockInfo
*
pBlockInfo
);
int32_t
tsdbRetrieveDataBlockStatisInfo
(
tsdbReaderT
*
pTsdbReadHandle
,
SColumnDataAgg
***
pBlockStatis
,
bool
*
allHave
);
SArray
*
tsdbRetrieveDataBlock
(
tsdbReaderT
*
pTsdbReadHandle
,
SArray
*
pColumnIdList
);
void
tsdbResetReadHandle
(
tsdbReaderT
queryHandle
,
SQueryTableDataCond
*
pCond
,
int32_t
tWinIdx
);
...
...
@@ -174,7 +176,7 @@ struct SMetaEntry {
int64_t
version
;
int8_t
type
;
tb_uid_t
uid
;
char
*
name
;
char
*
name
;
union
{
struct
{
SSchemaWrapper
schemaRow
;
...
...
@@ -202,17 +204,17 @@ struct SMetaEntry {
struct
SMetaReader
{
int32_t
flags
;
SMeta
*
pMeta
;
SMeta
*
pMeta
;
SDecoder
coder
;
SMetaEntry
me
;
void
*
pBuf
;
void
*
pBuf
;
int32_t
szBuf
;
};
struct
SMTbCursor
{
TBC
*
pDbc
;
void
*
pKey
;
void
*
pVal
;
TBC
*
pDbc
;
void
*
pKey
;
void
*
pVal
;
int32_t
kLen
;
int32_t
vLen
;
SMetaReader
mr
;
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
46527878
...
...
@@ -103,6 +103,7 @@ SArray* metaGetSmaTbUids(SMeta* pMeta);
int32_t
metaSnapshotReaderOpen
(
SMeta
*
pMeta
,
SMetaSnapshotReader
**
ppReader
,
int64_t
sver
,
int64_t
ever
);
int32_t
metaSnapshotReaderClose
(
SMetaSnapshotReader
*
pReader
);
int32_t
metaSnapshotRead
(
SMetaSnapshotReader
*
pReader
,
void
**
ppData
,
uint32_t
*
nData
);
void
*
metaGetIdx
(
SMeta
*
pMeta
);
int32_t
metaCreateTSma
(
SMeta
*
pMeta
,
int64_t
version
,
SSmaCfg
*
pCfg
);
int32_t
metaDropTSma
(
SMeta
*
pMeta
,
int64_t
indexUid
);
...
...
source/dnode/vnode/src/meta/metaTable.c
浏览文件 @
46527878
...
...
@@ -31,9 +31,9 @@ int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
int
vLen
=
0
;
const
void
*
pKey
=
NULL
;
const
void
*
pVal
=
NULL
;
void
*
pBuf
=
NULL
;
void
*
pBuf
=
NULL
;
int32_t
szBuf
=
0
;
void
*
p
=
NULL
;
void
*
p
=
NULL
;
SMetaReader
mr
=
{
0
};
// validate req
...
...
@@ -87,7 +87,7 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq) {
}
// drop all child tables
TBC
*
pCtbIdxc
=
NULL
;
TBC
*
pCtbIdxc
=
NULL
;
SArray
*
pArray
=
taosArrayInit
(
8
,
sizeof
(
tb_uid_t
));
tdbTbcOpen
(
pMeta
->
pCtbIdx
,
&
pCtbIdxc
,
&
pMeta
->
txn
);
...
...
@@ -142,8 +142,8 @@ _exit:
int
metaAlterSTable
(
SMeta
*
pMeta
,
int64_t
version
,
SVCreateStbReq
*
pReq
)
{
SMetaEntry
oStbEntry
=
{
0
};
SMetaEntry
nStbEntry
=
{
0
};
TBC
*
pUidIdxc
=
NULL
;
TBC
*
pTbDbc
=
NULL
;
TBC
*
pUidIdxc
=
NULL
;
TBC
*
pTbDbc
=
NULL
;
const
void
*
pData
;
int
nData
;
int64_t
oversion
;
...
...
@@ -262,7 +262,7 @@ _err:
}
int
metaDropTable
(
SMeta
*
pMeta
,
int64_t
version
,
SVDropTbReq
*
pReq
,
SArray
*
tbUids
)
{
void
*
pData
=
NULL
;
void
*
pData
=
NULL
;
int
nData
=
0
;
int
rc
=
0
;
tb_uid_t
uid
;
...
...
@@ -288,7 +288,7 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi
}
static
int
metaDropTableByUid
(
SMeta
*
pMeta
,
tb_uid_t
uid
,
int
*
type
)
{
void
*
pData
=
NULL
;
void
*
pData
=
NULL
;
int
nData
=
0
;
int
rc
=
0
;
int64_t
version
;
...
...
@@ -324,14 +324,14 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
}
static
int
metaAlterTableColumn
(
SMeta
*
pMeta
,
int64_t
version
,
SVAlterTbReq
*
pAlterTbReq
)
{
void
*
pVal
=
NULL
;
void
*
pVal
=
NULL
;
int
nVal
=
0
;
const
void
*
pData
=
NULL
;
const
void
*
pData
=
NULL
;
int
nData
=
0
;
int
ret
=
0
;
tb_uid_t
uid
;
int64_t
oversion
;
SSchema
*
pColumn
=
NULL
;
SSchema
*
pColumn
=
NULL
;
SMetaEntry
entry
=
{
0
};
SSchemaWrapper
*
pSchema
;
int
c
;
...
...
@@ -479,7 +479,7 @@ _err:
static
int
metaUpdateTableTagVal
(
SMeta
*
pMeta
,
int64_t
version
,
SVAlterTbReq
*
pAlterTbReq
)
{
SMetaEntry
ctbEntry
=
{
0
};
SMetaEntry
stbEntry
=
{
0
};
void
*
pVal
=
NULL
;
void
*
pVal
=
NULL
;
int
nVal
=
0
;
int
ret
;
int
c
;
...
...
@@ -510,7 +510,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
oversion
=
*
(
int64_t
*
)
pData
;
// search table.db
TBC
*
pTbDbc
=
NULL
;
TBC
*
pTbDbc
=
NULL
;
SDecoder
dc1
=
{
0
};
SDecoder
dc2
=
{
0
};
...
...
@@ -534,7 +534,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
metaDecodeEntry
(
&
dc2
,
&
stbEntry
);
SSchemaWrapper
*
pTagSchema
=
&
stbEntry
.
stbEntry
.
schemaTag
;
SSchema
*
pColumn
=
NULL
;
SSchema
*
pColumn
=
NULL
;
int32_t
iCol
=
0
;
for
(;;)
{
pColumn
=
NULL
;
...
...
@@ -639,8 +639,8 @@ int metaAlterTable(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq) {
static
int
metaSaveToTbDb
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
STbDbKey
tbDbKey
;
void
*
pKey
=
NULL
;
void
*
pVal
=
NULL
;
void
*
pKey
=
NULL
;
void
*
pVal
=
NULL
;
int
kLen
=
0
;
int
vLen
=
0
;
SEncoder
coder
=
{
0
};
...
...
@@ -755,14 +755,14 @@ static void metaDestroyTagIdxKey(STagIdxKey *pTagIdxKey) {
}
static
int
metaUpdateTagIdx
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pCtbEntry
)
{
void
*
pData
=
NULL
;
void
*
pData
=
NULL
;
int
nData
=
0
;
STbDbKey
tbDbKey
=
{
0
};
SMetaEntry
stbEntry
=
{
0
};
STagIdxKey
*
pTagIdxKey
=
NULL
;
STagIdxKey
*
pTagIdxKey
=
NULL
;
int32_t
nTagIdxKey
;
const
SSchema
*
pTagColumn
;
// = &stbEntry.stbEntry.schema.pSchema[0];
const
void
*
pTagData
=
NULL
;
//
const
void
*
pTagData
=
NULL
;
//
SDecoder
dc
=
{
0
};
// get super table
...
...
@@ -804,7 +804,7 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) {
static
int
metaSaveToSkmDb
(
SMeta
*
pMeta
,
const
SMetaEntry
*
pME
)
{
SEncoder
coder
=
{
0
};
void
*
pVal
=
NULL
;
void
*
pVal
=
NULL
;
int
vLen
=
0
;
int
rcode
=
0
;
SSkmDbKey
skmDbKey
=
{
0
};
...
...
@@ -880,3 +880,11 @@ _err:
metaULock
(
pMeta
);
return
-
1
;
}
// refactor later
void
*
metaGetIdx
(
SMeta
*
pMeta
)
{
#ifdef USE_INVERTED_INDEX
return
pMeta
->
pTagIvtIdx
;
#else
return
pMeta
->
pTagIdx
;
#endif
}
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
46527878
...
...
@@ -248,8 +248,8 @@ static SArray* createCheckInfoFromTableGroup(STsdbReadHandle* pTsdbReadHandle, S
}
taosArrayPush
(
pTableCheckInfo
,
&
info
);
tsdbDebug
(
"%p check table uid:%"
PRId64
" from lastKey:%"
PRId64
" %s"
,
pTsdbReadHandle
,
info
.
tableId
,
info
.
lastKey
,
pTsdbReadHandle
->
idStr
);
tsdbDebug
(
"%p check table uid:%"
PRId64
" from lastKey:%"
PRId64
" %s"
,
pTsdbReadHandle
,
info
.
tableId
,
info
.
lastKey
,
pTsdbReadHandle
->
idStr
);
}
// TODO group table according to the tag value.
...
...
@@ -352,13 +352,16 @@ static STsdb* getTsdbByRetentions(SVnode* pVnode, STsdbReadHandle* pReadHandle,
}
if
(
level
==
TSDB_RETENTION_L0
)
{
tsdbDebug
(
"vgId:%d read handle %p rsma level %d is selected to query"
,
TD_VID
(
pVnode
),
pReadHandle
,
TSDB_RETENTION_L0
);
tsdbDebug
(
"vgId:%d read handle %p rsma level %d is selected to query"
,
TD_VID
(
pVnode
),
pReadHandle
,
TSDB_RETENTION_L0
);
return
VND_RSMA0
(
pVnode
);
}
else
if
(
level
==
TSDB_RETENTION_L1
)
{
tsdbDebug
(
"vgId:%d read handle %p rsma level %d is selected to query"
,
TD_VID
(
pVnode
),
pReadHandle
,
TSDB_RETENTION_L1
);
tsdbDebug
(
"vgId:%d read handle %p rsma level %d is selected to query"
,
TD_VID
(
pVnode
),
pReadHandle
,
TSDB_RETENTION_L1
);
return
VND_RSMA1
(
pVnode
);
}
else
{
tsdbDebug
(
"vgId:%d read handle %p rsma level %d is selected to query"
,
TD_VID
(
pVnode
),
pReadHandle
,
TSDB_RETENTION_L2
);
tsdbDebug
(
"vgId:%d read handle %p rsma level %d is selected to query"
,
TD_VID
(
pVnode
),
pReadHandle
,
TSDB_RETENTION_L2
);
return
VND_RSMA2
(
pVnode
);
}
}
...
...
@@ -401,7 +404,7 @@ static STsdbReadHandle* tsdbQueryTablesImpl(SVnode* pVnode, SQueryTableDataCond*
if
(
pCond
->
numOfCols
>
0
)
{
int32_t
rowLen
=
0
;
for
(
int32_t
i
=
0
;
i
<
pCond
->
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pCond
->
numOfCols
;
++
i
)
{
rowLen
+=
pCond
->
colList
[
i
].
bytes
;
}
...
...
@@ -685,7 +688,7 @@ SArray* tsdbGetQueriedTableList(tsdbReaderT* pHandle) {
}
// leave only one table for each group
//static STableGroupInfo* trimTableGroup(STimeWindow* window, STableGroupInfo* pGroupList) {
//
static STableGroupInfo* trimTableGroup(STimeWindow* window, STableGroupInfo* pGroupList) {
// assert(pGroupList);
// size_t numOfGroup = taosArrayGetSize(pGroupList->pGroupList);
//
...
...
@@ -717,7 +720,7 @@ SArray* tsdbGetQueriedTableList(tsdbReaderT* pHandle) {
// return pNew;
//}
//tsdbReaderT tsdbQueryRowsInExternalWindow(SVnode* pVnode, SQueryTableDataCond* pCond, STableGroupInfo* groupList,
//
tsdbReaderT tsdbQueryRowsInExternalWindow(SVnode* pVnode, SQueryTableDataCond* pCond, STableGroupInfo* groupList,
// uint64_t qId, uint64_t taskId) {
// STableGroupInfo* pNew = trimTableGroup(&pCond->twindow, groupList);
//
...
...
@@ -1324,7 +1327,6 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock*
if
((
ascScan
&&
(
key
!=
TSKEY_INITIAL_VAL
&&
key
<=
binfo
.
window
.
ekey
))
||
(
!
ascScan
&&
(
key
!=
TSKEY_INITIAL_VAL
&&
key
>=
binfo
.
window
.
skey
)))
{
bool
cacheDataInFileBlockHole
=
(
ascScan
&&
(
key
!=
TSKEY_INITIAL_VAL
&&
key
<
binfo
.
window
.
skey
))
||
(
!
ascScan
&&
(
key
!=
TSKEY_INITIAL_VAL
&&
key
>
binfo
.
window
.
ekey
));
if
(
cacheDataInFileBlockHole
)
{
...
...
@@ -1367,7 +1369,7 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock*
pTsdbReadHandle
->
realNumOfRows
=
binfo
.
rows
;
cur
->
rows
=
binfo
.
rows
;
cur
->
win
=
binfo
.
window
;
cur
->
win
=
binfo
.
window
;
cur
->
mixBlock
=
false
;
cur
->
blockCompleted
=
true
;
...
...
@@ -1378,9 +1380,9 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock*
cur
->
lastKey
=
binfo
.
window
.
skey
-
1
;
cur
->
pos
=
-
1
;
}
}
else
{
// partially copy to dest buffer
}
else
{
// partially copy to dest buffer
// make sure to only load once
bool
firstTimeExtract
=
((
cur
->
pos
==
0
&&
ascScan
)
||
(
cur
->
pos
==
binfo
.
rows
-
1
&&
(
!
ascScan
)));
bool
firstTimeExtract
=
((
cur
->
pos
==
0
&&
ascScan
)
||
(
cur
->
pos
==
binfo
.
rows
-
1
&&
(
!
ascScan
)));
if
(
pTsdbReadHandle
->
outputCapacity
<
binfo
.
rows
&&
firstTimeExtract
)
{
code
=
doLoadFileDataBlock
(
pTsdbReadHandle
,
pBlock
,
pCheckInfo
,
cur
->
slot
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -1889,7 +1891,7 @@ static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STa
bool
ascScan
=
ASCENDING_TRAVERSE
(
pTsdbReadHandle
->
order
);
int32_t
step
=
ascScan
?
1
:
-
1
;
int32_t
step
=
ascScan
?
1
:
-
1
;
int32_t
start
=
cur
->
pos
;
int32_t
end
=
endPos
;
...
...
@@ -1904,8 +1906,8 @@ static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STa
// the time window should always be ascending order: skey <= ekey
cur
->
win
=
(
STimeWindow
){.
skey
=
tsArray
[
start
],
.
ekey
=
tsArray
[
end
]};
cur
->
mixBlock
=
(
numOfRows
!=
pBlockInfo
->
rows
);
cur
->
lastKey
=
tsArray
[
endPos
]
+
step
;
cur
->
blockCompleted
=
(
ascScan
?
(
endPos
==
pBlockInfo
->
rows
-
1
)
:
(
endPos
==
0
));
cur
->
lastKey
=
tsArray
[
endPos
]
+
step
;
cur
->
blockCompleted
=
(
ascScan
?
(
endPos
==
pBlockInfo
->
rows
-
1
)
:
(
endPos
==
0
));
// The value of pos may be -1 or pBlockInfo->rows, and it is invalid in both cases.
int32_t
pos
=
endPos
+
step
;
...
...
@@ -1921,7 +1923,7 @@ int32_t getEndPosInDataBlock(STsdbReadHandle* pTsdbReadHandle, SDataBlockInfo* p
// NOTE: reverse the order to find the end position in data block
int32_t
endPos
=
-
1
;
bool
ascScan
=
ASCENDING_TRAVERSE
(
pTsdbReadHandle
->
order
);
int32_t
order
=
ascScan
?
TSDB_ORDER_DESC
:
TSDB_ORDER_ASC
;
int32_t
order
=
ascScan
?
TSDB_ORDER_DESC
:
TSDB_ORDER_ASC
;
SQueryFilePos
*
cur
=
&
pTsdbReadHandle
->
cur
;
SDataCols
*
pCols
=
pTsdbReadHandle
->
rhelper
.
pDCols
[
0
];
...
...
@@ -1981,7 +1983,7 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
assert
(
pCols
->
numOfRows
==
pBlock
->
numOfRows
&&
tsArray
[
0
]
==
pBlock
->
keyFirst
&&
tsArray
[
pBlock
->
numOfRows
-
1
]
==
pBlock
->
keyLast
);
bool
ascScan
=
ASCENDING_TRAVERSE
(
pTsdbReadHandle
->
order
);
bool
ascScan
=
ASCENDING_TRAVERSE
(
pTsdbReadHandle
->
order
);
int32_t
step
=
ascScan
?
1
:
-
1
;
// for search the endPos, so the order needs to reverse
...
...
@@ -1992,8 +1994,9 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
STimeWindow
*
pWin
=
&
blockInfo
.
window
;
tsdbDebug
(
"%p uid:%"
PRIu64
" start merge data block, file block range:%"
PRIu64
"-%"
PRIu64
" rows:%d, start:%d, end:%d, %s"
,
pTsdbReadHandle
,
pCheckInfo
->
tableId
,
pWin
->
skey
,
pWin
->
ekey
,
blockInfo
.
rows
,
cur
->
pos
,
endPos
,
pTsdbReadHandle
->
idStr
);
" rows:%d, start:%d, end:%d, %s"
,
pTsdbReadHandle
,
pCheckInfo
->
tableId
,
pWin
->
skey
,
pWin
->
ekey
,
blockInfo
.
rows
,
cur
->
pos
,
endPos
,
pTsdbReadHandle
->
idStr
);
// compared with the data from in-memory buffer, to generate the correct timestamp array list
int32_t
numOfRows
=
0
;
...
...
@@ -2112,8 +2115,9 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
}
// still assign data into current row
numOfRows
+=
mergeTwoRowFromMem
(
pTsdbReadHandle
,
pTsdbReadHandle
->
outputCapacity
,
&
curRow
,
row1
,
row2
,
numOfCols
,
pCheckInfo
->
tableId
,
pSchema1
,
pSchema2
,
pCfg
->
update
,
&
lastKeyAppend
);
numOfRows
+=
mergeTwoRowFromMem
(
pTsdbReadHandle
,
pTsdbReadHandle
->
outputCapacity
,
&
curRow
,
row1
,
row2
,
numOfCols
,
pCheckInfo
->
tableId
,
pSchema1
,
pSchema2
,
pCfg
->
update
,
&
lastKeyAppend
);
if
(
cur
->
win
.
skey
==
TSKEY_INITIAL_VAL
)
{
cur
->
win
.
skey
=
key
;
...
...
@@ -2178,8 +2182,7 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
* if cache is empty, load remain file block data. In contrast, if there are remain data in cache, do NOT
* copy them all to result buffer, since it may be overlapped with file data block.
*/
if
(
node
==
NULL
||
((
TD_ROW_KEY
((
STSRow
*
)
SL_GET_NODE_DATA
(
node
))
>
pTsdbReadHandle
->
window
.
ekey
)
&&
ascScan
)
||
if
(
node
==
NULL
||
((
TD_ROW_KEY
((
STSRow
*
)
SL_GET_NODE_DATA
(
node
))
>
pTsdbReadHandle
->
window
.
ekey
)
&&
ascScan
)
||
((
TD_ROW_KEY
((
STSRow
*
)
SL_GET_NODE_DATA
(
node
))
<
pTsdbReadHandle
->
window
.
ekey
)
&&
!
ascScan
))
{
// no data in cache or data in cache is greater than the ekey of time window, load data from file block
if
(
cur
->
win
.
skey
==
TSKEY_INITIAL_VAL
)
{
...
...
@@ -2200,7 +2203,7 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
}
cur
->
blockCompleted
=
(((
pos
>
endPos
||
cur
->
lastKey
>
pTsdbReadHandle
->
window
.
ekey
)
&&
ascScan
)
||
((
pos
<
endPos
||
cur
->
lastKey
<
pTsdbReadHandle
->
window
.
ekey
)
&&
!
ascScan
));
((
pos
<
endPos
||
cur
->
lastKey
<
pTsdbReadHandle
->
window
.
ekey
)
&&
!
ascScan
));
if
(
!
ascScan
)
{
TSWAP
(
cur
->
win
.
skey
,
cur
->
win
.
ekey
);
...
...
@@ -2819,6 +2822,12 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
return
numOfRows
;
}
void
*
tsdbGetIdx
(
SMeta
*
pMeta
)
{
if
(
pMeta
==
NULL
)
{
return
NULL
;
}
return
metaGetIdx
(
pMeta
);
}
int32_t
tsdbGetAllTableList
(
SMeta
*
pMeta
,
uint64_t
uid
,
SArray
*
list
)
{
SMCtbCursor
*
pCur
=
metaOpenCtbCursor
(
pMeta
,
uid
);
...
...
@@ -3407,65 +3416,65 @@ int32_t checkForCachedLast(STsdbReadHandle* pTsdbReadHandle) {
STimeWindow
updateLastrowForEachGroup
(
STableListInfo
*
pList
)
{
STimeWindow
window
=
{
INT64_MAX
,
INT64_MIN
};
// int32_t totalNumOfTable = 0;
// SArray* emptyGroup = taosArrayInit(16, sizeof(int32_t));
//
// // NOTE: starts from the buffer in case of descending timestamp order check data blocks
// size_t numOfGroups = taosArrayGetSize(groupList->pGroupList);
// for (int32_t j = 0; j < numOfGroups; ++j) {
// SArray* pGroup = taosArrayGetP(groupList->pGroupList, j);
// TSKEY key = TSKEY_INITIAL_VAL;
//
// STableKeyInfo keyInfo = {0};
//
// size_t numOfTables = taosArrayGetSize(pGroup);
// for (int32_t i = 0; i < numOfTables; ++i) {
// STableKeyInfo* pInfo = (STableKeyInfo*)taosArrayGet(pGroup, i);
//
// // if the lastKey equals to INT64_MIN, there is no data in this table
// TSKEY lastKey = 0; //((STable*)(pInfo->pTable))->lastKey;
// if (key < lastKey) {
// key = lastKey;
//
// // keyInfo.pTable = pInfo->pTable;
// keyInfo.lastKey = key;
// pInfo->lastKey = key;
//
// if (key < window.skey) {
// window.skey = key;
// }
//
// if (key > window.ekey) {
// window.ekey = key;
// }
// }
// }
//
// // more than one table in each group, only one table left for each group
// // if (keyInfo.pTable != NULL) {
// // totalNumOfTable++;
// // if (taosArrayGetSize(pGroup) == 1) {
// // // do nothing
// // } else {
// // taosArrayClear(pGroup);
// // taosArrayPush(pGroup, &keyInfo);
// // }
// // } else { // mark all the empty groups, and remove it later
// // taosArrayDestroy(pGroup);
// // taosArrayPush(emptyGroup, &j);
// // }
// }
//
// // window does not being updated, so set the original
// if (window.skey == INT64_MAX && window.ekey == INT64_MIN) {
// window = TSWINDOW_INITIALIZER;
// assert(totalNumOfTable == 0 && taosArrayGetSize(groupList->pGroupList) == numOfGroups);
// }
//
// taosArrayRemoveBatch(groupList->pGroupList, TARRAY_GET_START(emptyGroup), (int32_t)taosArrayGetSize(emptyGroup));
// taosArrayDestroy(emptyGroup);
//
// groupList->numOfTables = totalNumOfTable;
// int32_t totalNumOfTable = 0;
// SArray* emptyGroup = taosArrayInit(16, sizeof(int32_t));
//
// // NOTE: starts from the buffer in case of descending timestamp order check data blocks
// size_t numOfGroups = taosArrayGetSize(groupList->pGroupList);
// for (int32_t j = 0; j < numOfGroups; ++j) {
// SArray* pGroup = taosArrayGetP(groupList->pGroupList, j);
// TSKEY key = TSKEY_INITIAL_VAL;
//
// STableKeyInfo keyInfo = {0};
//
// size_t numOfTables = taosArrayGetSize(pGroup);
// for (int32_t i = 0; i < numOfTables; ++i) {
// STableKeyInfo* pInfo = (STableKeyInfo*)taosArrayGet(pGroup, i);
//
// // if the lastKey equals to INT64_MIN, there is no data in this table
// TSKEY lastKey = 0; //((STable*)(pInfo->pTable))->lastKey;
// if (key < lastKey) {
// key = lastKey;
//
// // keyInfo.pTable = pInfo->pTable;
// keyInfo.lastKey = key;
// pInfo->lastKey = key;
//
// if (key < window.skey) {
// window.skey = key;
// }
//
// if (key > window.ekey) {
// window.ekey = key;
// }
// }
// }
//
// // more than one table in each group, only one table left for each group
// // if (keyInfo.pTable != NULL) {
// // totalNumOfTable++;
// // if (taosArrayGetSize(pGroup) == 1) {
// // // do nothing
// // } else {
// // taosArrayClear(pGroup);
// // taosArrayPush(pGroup, &keyInfo);
// // }
// // } else { // mark all the empty groups, and remove it later
// // taosArrayDestroy(pGroup);
// // taosArrayPush(emptyGroup, &j);
// // }
// }
//
// // window does not being updated, so set the original
// if (window.skey == INT64_MAX && window.ekey == INT64_MIN) {
// window = TSWINDOW_INITIALIZER;
// assert(totalNumOfTable == 0 && taosArrayGetSize(groupList->pGroupList) == numOfGroups);
// }
//
// taosArrayRemoveBatch(groupList->pGroupList, TARRAY_GET_START(emptyGroup), (int32_t)taosArrayGetSize(emptyGroup));
// taosArrayDestroy(emptyGroup);
//
// groupList->numOfTables = totalNumOfTable;
return
window
;
}
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
46527878
...
...
@@ -28,13 +28,13 @@
#include "ttime.h"
#include "executorimpl.h"
#include "index.h"
#include "query.h"
#include "tcompare.h"
#include "tcompression.h"
#include "thash.h"
#include "ttypes.h"
#include "vnode.h"
#include "index.h"
#define IS_MAIN_SCAN(runtime) ((runtime)->scanFlag == MAIN_SCAN)
#define IS_REVERSE_SCAN(runtime) ((runtime)->scanFlag == REVERSE_SCAN)
...
...
@@ -87,7 +87,7 @@ static UNUSED_FUNC void* u_realloc(void* p, size_t __size) {
#define realloc u_realloc
#endif
#define CLEAR_QUERY_STATUS(q, st)
((q)->status &= (~(st)))
#define CLEAR_QUERY_STATUS(q, st) ((q)->status &= (~(st)))
//#define GET_NUM_OF_TABLEGROUP(q) taosArrayGetSize((q)->tableqinfoGroupInfo.pGroupList)
#define QUERY_IS_INTERVAL_QUERY(_q) ((_q)->interval.interval > 0)
...
...
@@ -3960,11 +3960,11 @@ int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t n
return
TSDB_CODE_OUT_OF_MEMORY
;
}
uint32_t
defaultPgsz
=
0
;
uint32_t
defaultPgsz
=
0
;
uint32_t
defaultBufsz
=
0
;
getBufferPgSize
(
pAggSup
->
resultRowSize
,
&
defaultPgsz
,
&
defaultBufsz
);
int32_t
code
=
createDiskbasedBuf
(
&
pAggSup
->
pResultBuf
,
defaultPgsz
,
defaultBufsz
,
pKey
,
TD_TMP_DIR_PATH
);
int32_t
code
=
createDiskbasedBuf
(
&
pAggSup
->
pResultBuf
,
defaultPgsz
,
defaultBufsz
,
pKey
,
TD_TMP_DIR_PATH
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -4001,7 +4001,7 @@ void initResultSizeInfo(SOperatorInfo* pOperator, int32_t numOfRows) {
}
}
//static STableQueryInfo* initTableQueryInfo(const STableListInfo* pTableListInfo) {
//
static STableQueryInfo* initTableQueryInfo(const STableListInfo* pTableListInfo) {
// int32_t size = taosArrayGetSize(pTableListInfo->pTableList);
// if (size == 0) {
// return NULL;
...
...
@@ -4434,9 +4434,11 @@ static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId, EOPT
}
static
tsdbReaderT
doCreateDataReader
(
STableScanPhysiNode
*
pTableScanNode
,
SReadHandle
*
pHandle
,
STableListInfo
*
pTableGroupInfo
,
uint64_t
queryId
,
uint64_t
taskId
,
SNode
*
pTagCond
);
STableListInfo
*
pTableGroupInfo
,
uint64_t
queryId
,
uint64_t
taskId
,
SNode
*
pTagCond
);
static
int32_t
getTableList
(
void
*
metaHandle
,
int32_t
tableType
,
uint64_t
tableUid
,
STableListInfo
*
pListInfo
,
SNode
*
pTagCond
);
static
int32_t
getTableList
(
void
*
metaHandle
,
int32_t
tableType
,
uint64_t
tableUid
,
STableListInfo
*
pListInfo
,
SNode
*
pTagCond
);
static
SArray
*
extractTableIdList
(
const
STableListInfo
*
pTableGroupInfo
);
static
SArray
*
extractColumnInfo
(
SNodeList
*
pNodeList
);
...
...
@@ -4473,7 +4475,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
if
(
QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN
==
type
)
{
STableScanPhysiNode
*
pTableScanNode
=
(
STableScanPhysiNode
*
)
pPhyNode
;
tsdbReaderT
pDataReader
=
doCreateDataReader
(
pTableScanNode
,
pHandle
,
pTableListInfo
,
(
uint64_t
)
queryId
,
taskId
,
pTagCond
);
tsdbReaderT
pDataReader
=
doCreateDataReader
(
pTableScanNode
,
pHandle
,
pTableListInfo
,
(
uint64_t
)
queryId
,
taskId
,
pTagCond
);
if
(
pDataReader
==
NULL
&&
terrno
!=
0
)
{
return
NULL
;
}
...
...
@@ -4593,8 +4596,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
pOptr
=
createGroupOperatorInfo
(
ops
[
0
],
pExprInfo
,
num
,
pResBlock
,
pColList
,
pAggNode
->
node
.
pConditions
,
pScalarExprInfo
,
numOfScalarExpr
,
pTaskInfo
);
}
else
{
pOptr
=
createAggregateOperatorInfo
(
ops
[
0
],
pExprInfo
,
num
,
pResBlock
,
pScalarExprInfo
,
numOfScalarExpr
,
pTaskInfo
);
pOptr
=
createAggregateOperatorInfo
(
ops
[
0
],
pExprInfo
,
num
,
pResBlock
,
pScalarExprInfo
,
numOfScalarExpr
,
pTaskInfo
);
}
}
else
if
(
QUERY_NODE_PHYSICAL_PLAN_INTERVAL
==
type
||
QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL
==
type
)
{
SIntervalPhysiNode
*
pIntervalPhyNode
=
(
SIntervalPhysiNode
*
)
pPhyNode
;
...
...
@@ -4912,21 +4915,25 @@ int32_t getTableList(void* metaHandle, int32_t tableType, uint64_t tableUid, STa
pListInfo
->
pTableList
=
taosArrayInit
(
8
,
sizeof
(
STableKeyInfo
));
if
(
tableType
==
TSDB_SUPER_TABLE
)
{
if
(
pTagCond
){
if
(
pTagCond
)
{
SIndexMetaArg
metaArg
=
{.
metaHandle
=
tsdbGetIdx
(
metaHandle
),
.
suid
=
tableUid
};
SArray
*
res
=
taosArrayInit
(
8
,
sizeof
(
uint64_t
));
code
=
doFilterTag
(
pTagCond
,
res
);
code
=
doFilterTag
(
pTagCond
,
&
metaArg
,
res
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
qError
(
"doFilterTag error:%d"
,
code
);
taosArrayDestroy
(
res
);
terrno
=
code
;
return
code
;
}
else
{
qDebug
(
"doFilterTag error:%d, suid: %"
PRIu64
""
,
code
,
tableUid
);
}
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
res
);
i
++
)
{
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
res
);
i
++
)
{
STableKeyInfo
info
=
{.
lastKey
=
TSKEY_INITIAL_VAL
,
.
uid
=
*
(
uint64_t
*
)
taosArrayGet
(
res
,
i
)};
taosArrayPush
(
pListInfo
->
pTableList
,
&
info
);
}
taosArrayDestroy
(
res
);
}
else
{
}
else
{
code
=
tsdbGetAllTableList
(
metaHandle
,
tableUid
,
pListInfo
->
pTableList
);
}
}
else
{
// Create one table group.
...
...
@@ -4951,7 +4958,8 @@ SArray* extractTableIdList(const STableListInfo* pTableGroupInfo) {
tsdbReaderT
doCreateDataReader
(
STableScanPhysiNode
*
pTableScanNode
,
SReadHandle
*
pHandle
,
STableListInfo
*
pTableListInfo
,
uint64_t
queryId
,
uint64_t
taskId
,
SNode
*
pTagCond
)
{
int32_t
code
=
getTableList
(
pHandle
->
meta
,
pTableScanNode
->
scan
.
tableType
,
pTableScanNode
->
scan
.
uid
,
pTableListInfo
,
pTagCond
);
int32_t
code
=
getTableList
(
pHandle
->
meta
,
pTableScanNode
->
scan
.
tableType
,
pTableScanNode
->
scan
.
uid
,
pTableListInfo
,
pTagCond
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
...
...
@@ -4986,8 +4994,8 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead
goto
_complete
;
}
(
*
pTaskInfo
)
->
pRoot
=
createOperatorTree
(
pPlan
->
pNode
,
*
pTaskInfo
,
pHandle
,
queryId
,
taskId
,
&
(
*
pTaskInfo
)
->
tableqinfoList
,
pPlan
->
pTagCond
);
(
*
pTaskInfo
)
->
pRoot
=
createOperatorTree
(
pPlan
->
pNode
,
*
pTaskInfo
,
pHandle
,
queryId
,
taskId
,
&
(
*
pTaskInfo
)
->
tableqinfoList
,
pPlan
->
pTagCond
);
if
(
NULL
==
(
*
pTaskInfo
)
->
pRoot
)
{
code
=
terrno
;
goto
_complete
;
...
...
source/libs/index/inc/indexCache.h
浏览文件 @
46527878
...
...
@@ -74,7 +74,7 @@ void indexCacheIteratorDestroy(Iterate* iiter);
int
indexCachePut
(
void
*
cache
,
SIndexTerm
*
term
,
uint64_t
uid
);
// int indexCacheGet(void *cache, uint64_t *rst);
int
indexCacheSearch
(
void
*
cache
,
SIndexTermQuery
*
query
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
);
int
indexCacheSearch
(
void
*
cache
,
SIndexTermQuery
*
query
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
);
void
indexCacheRef
(
IndexCache
*
cache
);
void
indexCacheUnRef
(
IndexCache
*
cache
);
...
...
source/libs/index/inc/indexTfile.h
浏览文件 @
46527878
...
...
@@ -105,7 +105,7 @@ TFileReader* tfileGetReaderByCol(IndexTFile* tf, uint64_t suid, char* colName);
TFileReader
*
tfileReaderOpen
(
char
*
path
,
uint64_t
suid
,
int64_t
version
,
const
char
*
colName
);
TFileReader
*
tfileReaderCreate
(
WriterCtx
*
ctx
);
void
tfileReaderDestroy
(
TFileReader
*
reader
);
int
tfileReaderSearch
(
TFileReader
*
reader
,
SIndexTermQuery
*
query
,
SIdxT
empResu
lt
*
tr
);
int
tfileReaderSearch
(
TFileReader
*
reader
,
SIndexTermQuery
*
query
,
SIdxT
Rs
lt
*
tr
);
void
tfileReaderRef
(
TFileReader
*
reader
);
void
tfileReaderUnRef
(
TFileReader
*
reader
);
...
...
@@ -120,7 +120,7 @@ int tfileWriterFinish(TFileWriter* tw);
IndexTFile
*
indexTFileCreate
(
const
char
*
path
);
void
indexTFileDestroy
(
IndexTFile
*
tfile
);
int
indexTFilePut
(
void
*
tfile
,
SIndexTerm
*
term
,
uint64_t
uid
);
int
indexTFileSearch
(
void
*
tfile
,
SIndexTermQuery
*
query
,
SIdxT
empResu
lt
*
tr
);
int
indexTFileSearch
(
void
*
tfile
,
SIndexTermQuery
*
query
,
SIdxT
Rs
lt
*
tr
);
Iterate
*
tfileIteratorCreate
(
TFileReader
*
reader
);
void
tfileIteratorDestroy
(
Iterate
*
iterator
);
...
...
source/libs/index/inc/indexUtil.h
浏览文件 @
46527878
...
...
@@ -66,7 +66,7 @@ extern "C" {
* [1, 4, 5]
* output:[4, 5]
*/
void
iIntersection
(
SArray
*
in
terResults
,
SArray
*
finalResul
t
);
void
iIntersection
(
SArray
*
in
,
SArray
*
ou
t
);
/* multi sorted result union
* input: [1, 2, 4, 5]
...
...
@@ -74,7 +74,7 @@ void iIntersection(SArray *interResults, SArray *finalResult);
* [1, 4, 5]
* output:[1, 2, 3, 4, 5]
*/
void
iUnion
(
SArray
*
in
terResults
,
SArray
*
finalResul
t
);
void
iUnion
(
SArray
*
in
,
SArray
*
ou
t
);
/* see example
* total: [1, 2, 4, 5, 7, 8]
...
...
@@ -92,19 +92,24 @@ typedef struct {
uint64_t
data
;
}
SIdxVerdata
;
/*
* index temp result
*
*/
typedef
struct
{
SArray
*
total
;
SArray
*
added
;
SArray
*
deled
;
}
SIdxTempResult
;
SArray
*
add
;
SArray
*
del
;
}
SIdxTRslt
;
SIdxTRslt
*
idxTRsltCreate
();
SIdxTempResult
*
sIdxTempResultCreate
(
);
void
idxTRsltClear
(
SIdxTRslt
*
tr
);
void
sIdxTempResultClear
(
SIdxTempResu
lt
*
tr
);
void
idxTRsltDestroy
(
SIdxTRs
lt
*
tr
);
void
sIdxTempResultDestroy
(
SIdxTempResult
*
tr
);
void
idxTRsltMergeTo
(
SIdxTRslt
*
tr
,
SArray
*
out
);
void
sIdxTempResultMergeTo
(
SArray
*
result
,
SIdxTempResult
*
tr
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/index/src/index.c
浏览文件 @
46527878
...
...
@@ -29,7 +29,7 @@
#include "lucene++/Lucene_c.h"
#endif
#define INDEX_NUM_OF_THREADS
1
#define INDEX_NUM_OF_THREADS
5
#define INDEX_QUEUE_SIZE 200
#define INDEX_DATA_BOOL_NULL 0x02
...
...
@@ -85,7 +85,7 @@ static int indexMergeFinalResults(SArray* interResults, EIndexOperatorType oTyp
static
int
indexGenTFile
(
SIndex
*
index
,
IndexCache
*
cache
,
SArray
*
batch
);
// merge cache and tfile by opera type
static
void
indexMergeCacheAndTFile
(
SArray
*
result
,
IterateValue
*
icache
,
IterateValue
*
iTfv
,
SIdxT
empResu
lt
*
helper
);
static
void
indexMergeCacheAndTFile
(
SArray
*
result
,
IterateValue
*
icache
,
IterateValue
*
iTfv
,
SIdxT
Rs
lt
*
helper
);
// static int32_t indexSerialTermKey(SIndexTerm* itm, char* buf);
// int32_t indexSerialKey(ICacheKey* key, char* buf);
...
...
@@ -201,6 +201,7 @@ int indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) {
char
buf
[
128
]
=
{
0
};
ICacheKey
key
=
{.
suid
=
p
->
suid
,
.
colName
=
p
->
colName
,
.
nColName
=
strlen
(
p
->
colName
),
.
colType
=
p
->
colType
};
int32_t
sz
=
indexSerialCacheKey
(
&
key
,
buf
);
indexDebug
(
"suid: %"
PRIu64
", colName: %s, colType: %d"
,
key
.
suid
,
key
.
colName
,
key
.
colType
);
IndexCache
**
cache
=
taosHashGet
(
index
->
colObj
,
buf
,
sz
);
assert
(
*
cache
!=
NULL
);
...
...
@@ -328,6 +329,7 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result
char
buf
[
128
]
=
{
0
};
ICacheKey
key
=
{
.
suid
=
term
->
suid
,
.
colName
=
term
->
colName
,
.
nColName
=
strlen
(
term
->
colName
),
.
colType
=
term
->
colType
};
indexDebug
(
"suid: %"
PRIu64
", colName: %s, colType: %d"
,
key
.
suid
,
key
.
colName
,
key
.
colType
);
int32_t
sz
=
indexSerialCacheKey
(
&
key
,
buf
);
taosThreadMutexLock
(
&
sIdx
->
mtx
);
...
...
@@ -341,7 +343,7 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result
int64_t
st
=
taosGetTimestampUs
();
SIdxT
empResult
*
tr
=
sIdxTempResu
ltCreate
();
SIdxT
Rslt
*
tr
=
idxTRs
ltCreate
();
if
(
0
==
indexCacheSearch
(
cache
,
query
,
tr
,
&
s
))
{
if
(
s
==
kTypeDeletion
)
{
indexInfo
(
"col: %s already drop by"
,
term
->
colName
);
...
...
@@ -363,12 +365,12 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result
int64_t
cost
=
taosGetTimestampUs
()
-
st
;
indexInfo
(
"search cost: %"
PRIu64
"us"
,
cost
);
sIdxTempResultMergeTo
(
*
result
,
tr
);
idxTRsltMergeTo
(
tr
,
*
result
);
sIdxTempResu
ltDestroy
(
tr
);
idxTRs
ltDestroy
(
tr
);
return
0
;
END:
sIdxTempResu
ltDestroy
(
tr
);
idxTRs
ltDestroy
(
tr
);
return
-
1
;
}
static
void
indexInterResultsDestroy
(
SArray
*
results
)
{
...
...
@@ -404,18 +406,18 @@ static int indexMergeFinalResults(SArray* interResults, EIndexOperatorType oType
return
0
;
}
static
void
indexMayMergeTempToFinalResult
(
SArray
*
result
,
TFileValue
*
tfv
,
SIdxT
empResu
lt
*
tr
)
{
static
void
indexMayMergeTempToFinalResult
(
SArray
*
result
,
TFileValue
*
tfv
,
SIdxT
Rs
lt
*
tr
)
{
int32_t
sz
=
taosArrayGetSize
(
result
);
if
(
sz
>
0
)
{
TFileValue
*
lv
=
taosArrayGetP
(
result
,
sz
-
1
);
if
(
tfv
!=
NULL
&&
strcmp
(
lv
->
colVal
,
tfv
->
colVal
)
!=
0
)
{
sIdxTempResultMergeTo
(
lv
->
tableId
,
tr
);
sIdxTempResu
ltClear
(
tr
);
idxTRsltMergeTo
(
tr
,
lv
->
tableId
);
idxTRs
ltClear
(
tr
);
taosArrayPush
(
result
,
&
tfv
);
}
else
if
(
tfv
==
NULL
)
{
// handle last iterator
sIdxTempResultMergeTo
(
lv
->
tableId
,
tr
);
idxTRsltMergeTo
(
tr
,
lv
->
tableId
);
}
else
{
// temp result saved in help
tfileValueDestroy
(
tfv
);
...
...
@@ -424,7 +426,7 @@ static void indexMayMergeTempToFinalResult(SArray* result, TFileValue* tfv, SIdx
taosArrayPush
(
result
,
&
tfv
);
}
}
static
void
indexMergeCacheAndTFile
(
SArray
*
result
,
IterateValue
*
cv
,
IterateValue
*
tv
,
SIdxT
empResu
lt
*
tr
)
{
static
void
indexMergeCacheAndTFile
(
SArray
*
result
,
IterateValue
*
cv
,
IterateValue
*
tv
,
SIdxT
Rs
lt
*
tr
)
{
char
*
colVal
=
(
cv
!=
NULL
)
?
cv
->
colVal
:
tv
->
colVal
;
TFileValue
*
tfv
=
tfileValueCreate
(
colVal
);
...
...
@@ -434,9 +436,9 @@ static void indexMergeCacheAndTFile(SArray* result, IterateValue* cv, IterateVal
uint64_t
id
=
*
(
uint64_t
*
)
taosArrayGet
(
cv
->
val
,
0
);
uint32_t
ver
=
cv
->
ver
;
if
(
cv
->
type
==
ADD_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
del
ed
,
tr
->
adde
d
,
id
)
INDEX_MERGE_ADD_DEL
(
tr
->
del
,
tr
->
ad
d
,
id
)
}
else
if
(
cv
->
type
==
DEL_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
add
ed
,
tr
->
deled
,
id
)
INDEX_MERGE_ADD_DEL
(
tr
->
add
,
tr
->
del
,
id
)
}
}
if
(
tv
!=
NULL
)
{
...
...
@@ -489,7 +491,7 @@ int indexFlushCacheToTFile(SIndex* sIdx, void* cache) {
bool
cn
=
cacheIter
?
cacheIter
->
next
(
cacheIter
)
:
false
;
bool
tn
=
tfileIter
?
tfileIter
->
next
(
tfileIter
)
:
false
;
SIdxT
empResult
*
tr
=
sIdxTempResu
ltCreate
();
SIdxT
Rslt
*
tr
=
idxTRs
ltCreate
();
while
(
cn
==
true
||
tn
==
true
)
{
IterateValue
*
cv
=
(
cn
==
true
)
?
cacheIter
->
getValue
(
cacheIter
)
:
NULL
;
IterateValue
*
tv
=
(
tn
==
true
)
?
tfileIter
->
getValue
(
tfileIter
)
:
NULL
;
...
...
@@ -515,7 +517,7 @@ int indexFlushCacheToTFile(SIndex* sIdx, void* cache) {
}
}
indexMayMergeTempToFinalResult
(
result
,
NULL
,
tr
);
sIdxTempResu
ltDestroy
(
tr
);
idxTRs
ltDestroy
(
tr
);
int
ret
=
indexGenTFile
(
sIdx
,
pCache
,
result
);
indexDestroyFinalResult
(
result
);
...
...
source/libs/index/src/indexCache.c
浏览文件 @
46527878
...
...
@@ -36,32 +36,31 @@ static char* indexCacheTermGet(const void* pData);
static
MemTable
*
indexInternalCacheCreate
(
int8_t
type
);
static
int32_t
cacheSearchTerm
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchPrefix
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchSuffix
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchRegex
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchLessThan
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchLessEqual
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchGreaterThan
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchGreaterEqual
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchRange
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchTerm
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchPrefix
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchSuffix
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchRegex
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchLessThan
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchLessEqual
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchGreaterThan
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchGreaterEqual
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchRange
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
);
/*comm func of compare, used in (LE/LT/GE/GT compare)*/
static
int32_t
cacheSearchCompareFunc
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTempResult
*
tr
,
STermValueType
*
s
,
RangeType
type
);
static
int32_t
cacheSearchTerm_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTempResult
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchPrefix_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTempResult
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchSuffix_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTempResult
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchRegex_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTempResult
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchLessThan_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTempResult
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchLessEqual_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTempResult
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchGreaterThan_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTempResult
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchGreaterEqual_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTempResult
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchRange_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTempResult
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchCompareFunc_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxTempResult
*
tr
,
STermValueType
*
s
,
static
int32_t
cacheSearchCompareFunc
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTRslt
*
tr
,
STermValueType
*
s
,
RangeType
type
);
static
int32_t
cacheSearchTerm_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTRslt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchPrefix_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTRslt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchSuffix_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTRslt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchRegex_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTRslt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchLessThan_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTRslt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchLessEqual_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTRslt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchGreaterThan_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTRslt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchGreaterEqual_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTRslt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchRange_JSON
(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxTRslt
*
tr
,
STermValueType
*
s
);
static
int32_t
cacheSearchCompareFunc_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxTRslt
*
tr
,
STermValueType
*
s
,
RangeType
type
);
static
int32_t
(
*
cacheSearch
[][
QUERY_MAX
])(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
=
{
static
int32_t
(
*
cacheSearch
[][
QUERY_MAX
])(
void
*
cache
,
SIndexTerm
*
ct
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
=
{
{
cacheSearchTerm
,
cacheSearchPrefix
,
cacheSearchSuffix
,
cacheSearchRegex
,
cacheSearchLessThan
,
cacheSearchLessEqual
,
cacheSearchGreaterThan
,
cacheSearchGreaterEqual
,
cacheSearchRange
},
{
cacheSearchTerm_JSON
,
cacheSearchPrefix_JSON
,
cacheSearchSuffix_JSON
,
cacheSearchRegex_JSON
,
...
...
@@ -71,7 +70,7 @@ static int32_t (*cacheSearch[][QUERY_MAX])(void* cache, SIndexTerm* ct, SIdxTemp
static
void
doMergeWork
(
SSchedMsg
*
msg
);
static
bool
indexCacheIteratorNext
(
Iterate
*
itera
);
static
int32_t
cacheSearchTerm
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchTerm
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
if
(
cache
==
NULL
)
{
return
0
;
}
...
...
@@ -93,11 +92,11 @@ static int32_t cacheSearchTerm(void* cache, SIndexTerm* term, SIdxTempResult* tr
CacheTerm
*
c
=
(
CacheTerm
*
)
SL_GET_NODE_DATA
(
node
);
if
(
0
==
strcmp
(
c
->
colVal
,
pCt
->
colVal
))
{
if
(
c
->
operaType
==
ADD_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
del
ed
,
tr
->
adde
d
,
c
->
uid
)
INDEX_MERGE_ADD_DEL
(
tr
->
del
,
tr
->
ad
d
,
c
->
uid
)
// taosArrayPush(result, &c->uid);
*
s
=
kTypeValue
;
}
else
if
(
c
->
operaType
==
DEL_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
add
ed
,
tr
->
deled
,
c
->
uid
)
INDEX_MERGE_ADD_DEL
(
tr
->
add
,
tr
->
del
,
c
->
uid
)
}
}
else
{
break
;
...
...
@@ -108,20 +107,19 @@ static int32_t cacheSearchTerm(void* cache, SIndexTerm* term, SIdxTempResult* tr
tSkipListDestroyIter
(
iter
);
return
0
;
}
static
int32_t
cacheSearchPrefix
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchPrefix
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
// impl later
return
0
;
}
static
int32_t
cacheSearchSuffix
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchSuffix
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
// impl later
return
0
;
}
static
int32_t
cacheSearchRegex
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchRegex
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
// impl later
return
0
;
}
static
int32_t
cacheSearchCompareFunc
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxTempResult
*
tr
,
STermValueType
*
s
,
RangeType
type
)
{
static
int32_t
cacheSearchCompareFunc
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxTRslt
*
tr
,
STermValueType
*
s
,
RangeType
type
)
{
if
(
cache
==
NULL
)
{
return
0
;
}
...
...
@@ -133,6 +131,7 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTempRes
CacheTerm
*
pCt
=
taosMemoryCalloc
(
1
,
sizeof
(
CacheTerm
));
pCt
->
colVal
=
term
->
colVal
;
pCt
->
colType
=
term
->
colType
;
pCt
->
version
=
atomic_load_64
(
&
pCache
->
version
);
char
*
key
=
indexCacheTermGet
(
pCt
);
...
...
@@ -147,11 +146,11 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTempRes
TExeCond
cond
=
cmpFn
(
c
->
colVal
,
pCt
->
colVal
,
pCt
->
colType
);
if
(
cond
==
MATCH
)
{
if
(
c
->
operaType
==
ADD_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
del
ed
,
tr
->
adde
d
,
c
->
uid
)
INDEX_MERGE_ADD_DEL
(
tr
->
del
,
tr
->
ad
d
,
c
->
uid
)
// taosArrayPush(result, &c->uid);
*
s
=
kTypeValue
;
}
else
if
(
c
->
operaType
==
DEL_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
add
ed
,
tr
->
deled
,
c
->
uid
)
INDEX_MERGE_ADD_DEL
(
tr
->
add
,
tr
->
del
,
c
->
uid
)
}
}
else
if
(
cond
==
CONTINUE
)
{
continue
;
...
...
@@ -163,20 +162,20 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTempRes
tSkipListDestroyIter
(
iter
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cacheSearchLessThan
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchLessThan
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
return
cacheSearchCompareFunc
(
cache
,
term
,
tr
,
s
,
LT
);
}
static
int32_t
cacheSearchLessEqual
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchLessEqual
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
return
cacheSearchCompareFunc
(
cache
,
term
,
tr
,
s
,
LE
);
}
static
int32_t
cacheSearchGreaterThan
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchGreaterThan
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
return
cacheSearchCompareFunc
(
cache
,
term
,
tr
,
s
,
GT
);
}
static
int32_t
cacheSearchGreaterEqual
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchGreaterEqual
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
return
cacheSearchCompareFunc
(
cache
,
term
,
tr
,
s
,
GE
);
}
static
int32_t
cacheSearchTerm_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchTerm_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
if
(
cache
==
NULL
)
{
return
0
;
}
...
...
@@ -204,11 +203,11 @@ static int32_t cacheSearchTerm_JSON(void* cache, SIndexTerm* term, SIdxTempResul
if
(
0
==
strcmp
(
c
->
colVal
,
pCt
->
colVal
))
{
if
(
c
->
operaType
==
ADD_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
del
ed
,
tr
->
adde
d
,
c
->
uid
)
INDEX_MERGE_ADD_DEL
(
tr
->
del
,
tr
->
ad
d
,
c
->
uid
)
// taosArrayPush(result, &c->uid);
*
s
=
kTypeValue
;
}
else
if
(
c
->
operaType
==
DEL_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
add
ed
,
tr
->
deled
,
c
->
uid
)
INDEX_MERGE_ADD_DEL
(
tr
->
add
,
tr
->
del
,
c
->
uid
)
}
}
else
{
break
;
...
...
@@ -222,32 +221,32 @@ static int32_t cacheSearchTerm_JSON(void* cache, SIndexTerm* term, SIdxTempResul
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cacheSearchPrefix_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchPrefix_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cacheSearchSuffix_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchSuffix_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cacheSearchRegex_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchRegex_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cacheSearchLessThan_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchLessThan_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
return
cacheSearchCompareFunc_JSON
(
cache
,
term
,
tr
,
s
,
LT
);
}
static
int32_t
cacheSearchLessEqual_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchLessEqual_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
return
cacheSearchCompareFunc_JSON
(
cache
,
term
,
tr
,
s
,
LE
);
}
static
int32_t
cacheSearchGreaterThan_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchGreaterThan_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
return
cacheSearchCompareFunc_JSON
(
cache
,
term
,
tr
,
s
,
GT
);
}
static
int32_t
cacheSearchGreaterEqual_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchGreaterEqual_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
return
cacheSearchCompareFunc_JSON
(
cache
,
term
,
tr
,
s
,
GE
);
}
static
int32_t
cacheSearchRange_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchRange_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cacheSearchCompareFunc_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
,
static
int32_t
cacheSearchCompareFunc_JSON
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
,
RangeType
type
)
{
if
(
cache
==
NULL
)
{
return
0
;
...
...
@@ -289,11 +288,11 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTe
TExeCond
cond
=
cmpFn
(
p
+
skip
,
term
->
colVal
,
dType
);
if
(
cond
==
MATCH
)
{
if
(
c
->
operaType
==
ADD_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
del
ed
,
tr
->
adde
d
,
c
->
uid
)
INDEX_MERGE_ADD_DEL
(
tr
->
del
,
tr
->
ad
d
,
c
->
uid
)
// taosArrayPush(result, &c->uid);
*
s
=
kTypeValue
;
}
else
if
(
c
->
operaType
==
DEL_VALUE
)
{
INDEX_MERGE_ADD_DEL
(
tr
->
add
ed
,
tr
->
deled
,
c
->
uid
)
INDEX_MERGE_ADD_DEL
(
tr
->
add
,
tr
->
del
,
c
->
uid
)
}
}
else
if
(
cond
==
CONTINUE
)
{
continue
;
...
...
@@ -309,7 +308,7 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTe
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cacheSearchRange
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
cacheSearchRange
(
void
*
cache
,
SIndexTerm
*
term
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
// impl later
return
0
;
}
...
...
@@ -568,7 +567,7 @@ int indexCacheDel(void* cache, const char* fieldValue, int32_t fvlen, uint64_t u
return
0
;
}
static
int32_t
indexQueryMem
(
MemTable
*
mem
,
SIndexTermQuery
*
query
,
SIdxT
empResu
lt
*
tr
,
STermValueType
*
s
)
{
static
int32_t
indexQueryMem
(
MemTable
*
mem
,
SIndexTermQuery
*
query
,
SIdxT
Rs
lt
*
tr
,
STermValueType
*
s
)
{
if
(
mem
==
NULL
)
{
return
0
;
}
...
...
@@ -582,7 +581,7 @@ static int32_t indexQueryMem(MemTable* mem, SIndexTermQuery* query, SIdxTempResu
return
cacheSearch
[
0
][
qtype
](
mem
,
term
,
tr
,
s
);
}
}
int
indexCacheSearch
(
void
*
cache
,
SIndexTermQuery
*
query
,
SIdxT
empResu
lt
*
result
,
STermValueType
*
s
)
{
int
indexCacheSearch
(
void
*
cache
,
SIndexTermQuery
*
query
,
SIdxT
Rs
lt
*
result
,
STermValueType
*
s
)
{
int64_t
st
=
taosGetTimestampUs
();
if
(
cache
==
NULL
)
{
return
0
;
...
...
@@ -597,10 +596,10 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SIdxTempResult* result
indexMemRef
(
imm
);
taosThreadMutexUnlock
(
&
pCache
->
mtx
);
int
ret
=
indexQueryMem
(
mem
,
query
,
result
,
s
)
;
int
ret
=
(
mem
&&
mem
->
mem
)
?
indexQueryMem
(
mem
,
query
,
result
,
s
)
:
0
;
if
(
ret
==
0
&&
*
s
!=
kTypeDeletion
)
{
// continue search in imm
ret
=
indexQueryMem
(
imm
,
query
,
result
,
s
)
;
ret
=
(
imm
&&
imm
->
mem
)
?
indexQueryMem
(
imm
,
query
,
result
,
s
)
:
0
;
}
indexMemUnRef
(
mem
);
...
...
@@ -709,7 +708,7 @@ static int32_t indexCacheJsonTermCompare(const void* l, const void* r) {
return
cmp
;
}
static
MemTable
*
indexInternalCacheCreate
(
int8_t
type
)
{
int
ttype
=
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
type
,
TSDB_DATA_TYPE_JSON
)
?
TSDB_DATA_TYPE_BINARY
:
type
;
int
ttype
=
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
type
,
TSDB_DATA_TYPE_JSON
)
?
TSDB_DATA_TYPE_BINARY
:
TSDB_DATA_TYPE_BINARY
;
int32_t
(
*
cmpFn
)(
const
void
*
l
,
const
void
*
r
)
=
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
type
,
TSDB_DATA_TYPE_JSON
)
?
indexCacheJsonTermCompare
:
indexCacheTermCompare
;
...
...
source/libs/index/src/indexFilter.c
浏览文件 @
46527878
...
...
@@ -37,12 +37,15 @@ typedef struct SIFParam {
int64_t
suid
;
// add later
char
dbName
[
TSDB_DB_NAME_LEN
];
char
colName
[
TSDB_COL_NAME_LEN
];
SIndexMetaArg
arg
;
}
SIFParam
;
typedef
struct
SIFCtx
{
int32_t
code
;
SHashObj
*
pRes
;
/* element is SIFParam */
bool
noExec
;
// true: just iterate condition tree, and add hint to executor plan
int32_t
code
;
SHashObj
*
pRes
;
/* element is SIFParam */
bool
noExec
;
// true: just iterate condition tree, and add hint to executor plan
SIndexMetaArg
arg
;
// SIdxFltStatus st;
}
SIFCtx
;
...
...
@@ -257,7 +260,9 @@ static int32_t sifExecFunction(SFunctionNode *node, SIFCtx *ctx, SIFParam *outpu
return
TSDB_CODE_QRY_INVALID_INPUT
;
}
static
int32_t
sifDoIndex
(
SIFParam
*
left
,
SIFParam
*
right
,
int8_t
operType
,
SIFParam
*
output
)
{
SIndexTerm
*
tm
=
indexTermCreate
(
left
->
suid
,
DEFAULT
,
left
->
colValType
,
left
->
colName
,
strlen
(
left
->
colName
),
#ifdef USE_INVERTED_INDEX
SIndexMetaArg
*
arg
=
&
output
->
arg
;
SIndexTerm
*
tm
=
indexTermCreate
(
arg
->
suid
,
DEFAULT
,
left
->
colValType
,
left
->
colName
,
strlen
(
left
->
colName
),
right
->
condValue
,
strlen
(
right
->
condValue
));
if
(
tm
==
NULL
)
{
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
...
...
@@ -268,9 +273,13 @@ static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFP
SIndexMultiTermQuery
*
mtm
=
indexMultiTermQueryCreate
(
MUST
);
indexMultiTermQueryAdd
(
mtm
,
tm
,
qtype
);
int
ret
=
indexSearch
(
NULL
,
mtm
,
output
->
result
);
int
ret
=
indexSearch
(
arg
->
metaHandle
,
mtm
,
output
->
result
);
indexDebug
(
"index filter data size: %d"
,
(
int
)
taosArrayGetSize
(
output
->
result
));
indexMultiTermQueryDestroy
(
mtm
);
return
ret
;
#else
return
0
;
#endif
}
static
int32_t
sifLessThanFunc
(
SIFParam
*
left
,
SIFParam
*
right
,
SIFParam
*
output
)
{
...
...
@@ -372,6 +381,8 @@ static int32_t sifExecOper(SOperatorNode *node, SIFCtx *ctx, SIFParam *output) {
SIFParam
*
params
=
NULL
;
SIF_ERR_RET
(
sifInitOperParams
(
&
params
,
node
,
ctx
));
// ugly code, refactor later
output
->
arg
=
ctx
->
arg
;
sif_func_t
operFn
=
sifGetOperFn
(
node
->
opType
);
if
(
ctx
->
noExec
&&
operFn
==
NULL
)
{
output
->
status
=
SFLT_NOT_INDEX
;
...
...
@@ -423,7 +434,7 @@ _return:
static
EDealRes
sifWalkFunction
(
SNode
*
pNode
,
void
*
context
)
{
SFunctionNode
*
node
=
(
SFunctionNode
*
)
pNode
;
SIFParam
output
=
{
0
};
SIFParam
output
=
{
.
result
=
taosArrayInit
(
8
,
sizeof
(
uint64_t
))
};
SIFCtx
*
ctx
=
context
;
ctx
->
code
=
sifExecFunction
(
node
,
ctx
,
&
output
);
...
...
@@ -439,7 +450,8 @@ static EDealRes sifWalkFunction(SNode *pNode, void *context) {
}
static
EDealRes
sifWalkLogic
(
SNode
*
pNode
,
void
*
context
)
{
SLogicConditionNode
*
node
=
(
SLogicConditionNode
*
)
pNode
;
SIFParam
output
=
{
0
};
SIFParam
output
=
{.
result
=
taosArrayInit
(
8
,
sizeof
(
uint64_t
))};
SIFCtx
*
ctx
=
context
;
ctx
->
code
=
sifExecLogic
(
node
,
ctx
,
&
output
);
...
...
@@ -455,7 +467,7 @@ static EDealRes sifWalkLogic(SNode *pNode, void *context) {
}
static
EDealRes
sifWalkOper
(
SNode
*
pNode
,
void
*
context
)
{
SOperatorNode
*
node
=
(
SOperatorNode
*
)
pNode
;
SIFParam
output
=
{
0
};
SIFParam
output
=
{
.
result
=
taosArrayInit
(
8
,
sizeof
(
uint64_t
))
};
SIFCtx
*
ctx
=
context
;
ctx
->
code
=
sifExecOper
(
node
,
ctx
,
&
output
);
...
...
@@ -507,8 +519,9 @@ static int32_t sifCalculate(SNode *pNode, SIFParam *pDst) {
return
TSDB_CODE_QRY_INVALID_INPUT
;
}
int32_t
code
=
0
;
SIFCtx
ctx
=
{.
code
=
0
,
.
noExec
=
false
};
SIFCtx
ctx
=
{.
code
=
0
,
.
noExec
=
false
,
.
arg
=
pDst
->
arg
};
ctx
.
pRes
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
,
HASH_NO_LOCK
);
if
(
NULL
==
ctx
.
pRes
)
{
indexError
(
"index-filter failed to taosHashInit"
);
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
...
...
@@ -523,7 +536,9 @@ static int32_t sifCalculate(SNode *pNode, SIFParam *pDst) {
indexError
(
"no valid res in hash, node:(%p), type(%d)"
,
(
void
*
)
&
pNode
,
nodeType
(
pNode
));
SIF_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
taosArrayAddAll
(
pDst
->
result
,
res
->
result
);
if
(
res
->
result
!=
NULL
)
{
taosArrayAddAll
(
pDst
->
result
,
res
->
result
);
}
sifFreeParam
(
res
);
taosHashRemove
(
ctx
.
pRes
,
(
void
*
)
&
pNode
,
POINTER_BYTES
);
...
...
@@ -561,7 +576,7 @@ static int32_t sifGetFltHint(SNode *pNode, SIdxFltStatus *status) {
SIF_RET
(
code
);
}
int32_t
doFilterTag
(
const
SNode
*
pFilterNode
,
SArray
*
result
)
{
int32_t
doFilterTag
(
const
SNode
*
pFilterNode
,
S
IndexMetaArg
*
metaArg
,
S
Array
*
result
)
{
if
(
pFilterNode
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -570,10 +585,12 @@ int32_t doFilterTag(const SNode *pFilterNode, SArray *result) {
// todo move to the initialization function
// SIF_ERR_RET(filterInitFromNode((SNode *)pFilterNode, &filter, 0));
SIFParam
param
=
{
0
};
SArray
*
output
=
taosArrayInit
(
8
,
sizeof
(
uint64_t
));
SIFParam
param
=
{.
arg
=
*
metaArg
,
.
result
=
output
};
SIF_ERR_RET
(
sifCalculate
((
SNode
*
)
pFilterNode
,
&
param
));
taosArrayAddAll
(
result
,
param
.
result
);
// taosArrayAddAll(result, param.result);
sifFreeParam
(
&
param
);
SIF_RET
(
TSDB_CODE_SUCCESS
);
}
...
...
source/libs/index/src/indexTfile.c
浏览文件 @
46527878
...
...
@@ -60,31 +60,31 @@ static void tfileGenFileFullName(char* fullname, const char* path, uint64_t s
/*
* search from tfile
*/
static
int32_t
tfSearchTerm
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchPrefix
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchSuffix
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchRegex
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchLessThan
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchLessEqual
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchGreaterThan
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchGreaterEqual
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchRange
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchCompareFunc
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
,
RangeType
ctype
);
static
int32_t
tfSearchTerm_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchPrefix_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchSuffix_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchRegex_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchLessThan_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchLessEqual_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchGreaterThan_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchGreaterEqual_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchRange_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
);
static
int32_t
tfSearchCompareFunc_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
,
RangeType
ctype
);
static
int32_t
(
*
tfSearch
[][
QUERY_MAX
])(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
=
{
static
int32_t
tfSearchTerm
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchPrefix
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchSuffix
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchRegex
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchLessThan
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchLessEqual
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchGreaterThan
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchGreaterEqual
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchRange
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchCompareFunc
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
,
RangeType
ctype
);
static
int32_t
tfSearchTerm_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchPrefix_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchSuffix_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchRegex_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchLessThan_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchLessEqual_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchGreaterThan_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchGreaterEqual_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchRange_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
);
static
int32_t
tfSearchCompareFunc_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
,
RangeType
ctype
);
static
int32_t
(
*
tfSearch
[][
QUERY_MAX
])(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
=
{
{
tfSearchTerm
,
tfSearchPrefix
,
tfSearchSuffix
,
tfSearchRegex
,
tfSearchLessThan
,
tfSearchLessEqual
,
tfSearchGreaterThan
,
tfSearchGreaterEqual
,
tfSearchRange
},
{
tfSearchTerm_JSON
,
tfSearchPrefix_JSON
,
tfSearchSuffix_JSON
,
tfSearchRegex_JSON
,
tfSearchLessThan_JSON
,
...
...
@@ -211,16 +211,16 @@ void tfileReaderDestroy(TFileReader* reader) {
}
// T_REF_INC(reader);
fstDestroy
(
reader
->
fst
);
writerCtxDestroy
(
reader
->
ctx
,
reader
->
remove
);
if
(
reader
->
remove
)
{
indexInfo
(
"%s is removed"
,
reader
->
ctx
->
file
.
buf
);
}
else
{
indexInfo
(
"%s is not removed"
,
reader
->
ctx
->
file
.
buf
);
}
writerCtxDestroy
(
reader
->
ctx
,
reader
->
remove
);
taosMemoryFree
(
reader
);
}
static
int32_t
tfSearchTerm
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchTerm
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
int
ret
=
0
;
char
*
p
=
tem
->
colVal
;
uint64_t
sz
=
tem
->
nColVal
;
...
...
@@ -243,7 +243,7 @@ static int32_t tfSearchTerm(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
return
0
;
}
static
int32_t
tfSearchPrefix
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchPrefix
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
bool
hasJson
=
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
tem
->
colType
,
TSDB_DATA_TYPE_JSON
);
char
*
p
=
tem
->
colVal
;
uint64_t
sz
=
tem
->
nColVal
;
...
...
@@ -279,7 +279,7 @@ static int32_t tfSearchPrefix(void* reader, SIndexTerm* tem, SIdxTempResult* tr)
}
return
0
;
}
static
int32_t
tfSearchSuffix
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchSuffix
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
bool
hasJson
=
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
tem
->
colType
,
TSDB_DATA_TYPE_JSON
);
int
ret
=
0
;
...
...
@@ -298,7 +298,7 @@ static int32_t tfSearchSuffix(void* reader, SIndexTerm* tem, SIdxTempResult* tr)
fstSliceDestroy
(
&
key
);
return
0
;
}
static
int32_t
tfSearchRegex
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchRegex
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
bool
hasJson
=
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
tem
->
colType
,
TSDB_DATA_TYPE_JSON
);
int
ret
=
0
;
...
...
@@ -319,7 +319,7 @@ static int32_t tfSearchRegex(void* reader, SIndexTerm* tem, SIdxTempResult* tr)
return
0
;
}
static
int32_t
tfSearchCompareFunc
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
,
RangeType
type
)
{
static
int32_t
tfSearchCompareFunc
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
,
RangeType
type
)
{
int
ret
=
0
;
char
*
p
=
tem
->
colVal
;
int
skip
=
0
;
...
...
@@ -358,19 +358,19 @@ static int32_t tfSearchCompareFunc(void* reader, SIndexTerm* tem, SIdxTempResult
fstStreamBuilderDestroy
(
sb
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
tfSearchLessThan
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchLessThan
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
return
tfSearchCompareFunc
(
reader
,
tem
,
tr
,
LT
);
}
static
int32_t
tfSearchLessEqual
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchLessEqual
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
return
tfSearchCompareFunc
(
reader
,
tem
,
tr
,
LE
);
}
static
int32_t
tfSearchGreaterThan
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchGreaterThan
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
return
tfSearchCompareFunc
(
reader
,
tem
,
tr
,
GT
);
}
static
int32_t
tfSearchGreaterEqual
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchGreaterEqual
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
return
tfSearchCompareFunc
(
reader
,
tem
,
tr
,
GE
);
}
static
int32_t
tfSearchRange
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchRange
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
bool
hasJson
=
INDEX_TYPE_CONTAIN_EXTERN_TYPE
(
tem
->
colType
,
TSDB_DATA_TYPE_JSON
);
int
ret
=
0
;
char
*
p
=
tem
->
colVal
;
...
...
@@ -399,7 +399,7 @@ static int32_t tfSearchRange(void* reader, SIndexTerm* tem, SIdxTempResult* tr)
fstSliceDestroy
(
&
key
);
return
0
;
}
static
int32_t
tfSearchTerm_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchTerm_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
int
ret
=
0
;
char
*
p
=
indexPackJsonData
(
tem
);
int
sz
=
strlen
(
p
);
...
...
@@ -424,36 +424,36 @@ static int32_t tfSearchTerm_JSON(void* reader, SIndexTerm* tem, SIdxTempResult*
// deprecate api
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
tfSearchPrefix_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchPrefix_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
// impl later
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
tfSearchSuffix_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchSuffix_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
// impl later
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
tfSearchRegex_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchRegex_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
// impl later
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
tfSearchLessThan_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchLessThan_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
return
tfSearchCompareFunc_JSON
(
reader
,
tem
,
tr
,
LT
);
}
static
int32_t
tfSearchLessEqual_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchLessEqual_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
return
tfSearchCompareFunc_JSON
(
reader
,
tem
,
tr
,
LE
);
}
static
int32_t
tfSearchGreaterThan_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchGreaterThan_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
return
tfSearchCompareFunc_JSON
(
reader
,
tem
,
tr
,
GT
);
}
static
int32_t
tfSearchGreaterEqual_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchGreaterEqual_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
return
tfSearchCompareFunc_JSON
(
reader
,
tem
,
tr
,
GE
);
}
static
int32_t
tfSearchRange_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
)
{
static
int32_t
tfSearchRange_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
)
{
// impl later
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
tfSearchCompareFunc_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
empResu
lt
*
tr
,
RangeType
ctype
)
{
static
int32_t
tfSearchCompareFunc_JSON
(
void
*
reader
,
SIndexTerm
*
tem
,
SIdxT
Rs
lt
*
tr
,
RangeType
ctype
)
{
int
ret
=
0
;
int
skip
=
0
;
...
...
@@ -501,7 +501,7 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTempR
fstStreamBuilderDestroy
(
sb
);
return
TSDB_CODE_SUCCESS
;
}
int
tfileReaderSearch
(
TFileReader
*
reader
,
SIndexTermQuery
*
query
,
SIdxT
empResu
lt
*
tr
)
{
int
tfileReaderSearch
(
TFileReader
*
reader
,
SIndexTermQuery
*
query
,
SIdxT
Rs
lt
*
tr
)
{
SIndexTerm
*
term
=
query
->
term
;
EIndexQueryType
qtype
=
query
->
qType
;
int
ret
=
0
;
...
...
@@ -673,7 +673,7 @@ void indexTFileDestroy(IndexTFile* tfile) {
taosMemoryFree
(
tfile
);
}
int
indexTFileSearch
(
void
*
tfile
,
SIndexTermQuery
*
query
,
SIdxT
empResu
lt
*
result
)
{
int
indexTFileSearch
(
void
*
tfile
,
SIndexTermQuery
*
query
,
SIdxT
Rs
lt
*
result
)
{
int
ret
=
-
1
;
if
(
tfile
==
NULL
)
{
return
ret
;
...
...
source/libs/index/src/indexUtil.c
浏览文件 @
46527878
...
...
@@ -36,24 +36,24 @@ static int iBinarySearch(SArray *arr, int s, int e, uint64_t k) {
return
s
;
}
void
iIntersection
(
SArray
*
in
ters
,
SArray
*
final
)
{
int32_t
sz
=
(
int32_t
)
taosArrayGetSize
(
in
ters
);
void
iIntersection
(
SArray
*
in
,
SArray
*
out
)
{
int32_t
sz
=
(
int32_t
)
taosArrayGetSize
(
in
);
if
(
sz
<=
0
)
{
return
;
}
MergeIndex
*
mi
=
taosMemoryCalloc
(
sz
,
sizeof
(
MergeIndex
));
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
SArray
*
t
=
taosArrayGetP
(
in
ters
,
i
);
SArray
*
t
=
taosArrayGetP
(
in
,
i
);
mi
[
i
].
len
=
(
int32_t
)
taosArrayGetSize
(
t
);
mi
[
i
].
idx
=
0
;
}
SArray
*
base
=
taosArrayGetP
(
in
ters
,
0
);
SArray
*
base
=
taosArrayGetP
(
in
,
0
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
base
);
i
++
)
{
uint64_t
tgt
=
*
(
uint64_t
*
)
taosArrayGet
(
base
,
i
);
bool
has
=
true
;
for
(
int
j
=
1
;
j
<
taosArrayGetSize
(
in
ters
);
j
++
)
{
SArray
*
oth
=
taosArrayGetP
(
in
ters
,
j
);
for
(
int
j
=
1
;
j
<
taosArrayGetSize
(
in
);
j
++
)
{
SArray
*
oth
=
taosArrayGetP
(
in
,
j
);
int
mid
=
iBinarySearch
(
oth
,
mi
[
j
].
idx
,
mi
[
j
].
len
-
1
,
tgt
);
if
(
mid
>=
0
&&
mid
<
mi
[
j
].
len
)
{
uint64_t
val
=
*
(
uint64_t
*
)
taosArrayGet
(
oth
,
mid
);
...
...
@@ -64,33 +64,33 @@ void iIntersection(SArray *inters, SArray *final) {
}
}
if
(
has
==
true
)
{
taosArrayPush
(
final
,
&
tgt
);
taosArrayPush
(
out
,
&
tgt
);
}
}
taosMemoryFreeClear
(
mi
);
}
void
iUnion
(
SArray
*
in
ters
,
SArray
*
final
)
{
int32_t
sz
=
(
int32_t
)
taosArrayGetSize
(
in
ters
);
void
iUnion
(
SArray
*
in
,
SArray
*
out
)
{
int32_t
sz
=
(
int32_t
)
taosArrayGetSize
(
in
);
if
(
sz
<=
0
)
{
return
;
}
if
(
sz
==
1
)
{
taosArrayAddAll
(
final
,
taosArrayGetP
(
inters
,
0
));
taosArrayAddAll
(
out
,
taosArrayGetP
(
in
,
0
));
return
;
}
MergeIndex
*
mi
=
taosMemoryCalloc
(
sz
,
sizeof
(
MergeIndex
));
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
SArray
*
t
=
taosArrayGetP
(
in
ters
,
i
);
SArray
*
t
=
taosArrayGetP
(
in
,
i
);
mi
[
i
].
len
=
(
int32_t
)
taosArrayGetSize
(
t
);
mi
[
i
].
idx
=
0
;
}
while
(
1
)
{
uint64_t
mVal
=
UINT_MAX
;
uint64_t
mVal
=
UINT
64
_MAX
;
int
mIdx
=
-
1
;
for
(
int
j
=
0
;
j
<
sz
;
j
++
)
{
SArray
*
t
=
taosArrayGetP
(
in
ters
,
j
);
SArray
*
t
=
taosArrayGetP
(
in
,
j
);
if
(
mi
[
j
].
idx
>=
mi
[
j
].
len
)
{
continue
;
}
...
...
@@ -102,13 +102,13 @@ void iUnion(SArray *inters, SArray *final) {
}
if
(
mIdx
!=
-
1
)
{
mi
[
mIdx
].
idx
++
;
if
(
taosArrayGetSize
(
final
)
>
0
)
{
uint64_t
lVal
=
*
(
uint64_t
*
)
taosArrayGetLast
(
final
);
if
(
taosArrayGetSize
(
out
)
>
0
)
{
uint64_t
lVal
=
*
(
uint64_t
*
)
taosArrayGetLast
(
out
);
if
(
lVal
==
mVal
)
{
continue
;
}
}
taosArrayPush
(
final
,
&
mVal
);
taosArrayPush
(
out
,
&
mVal
);
}
else
{
break
;
}
...
...
@@ -158,41 +158,44 @@ int verdataCompare(const void *a, const void *b) {
return
cmp
;
}
SIdxT
empResult
*
sIdxTempResu
ltCreate
()
{
SIdxT
empResult
*
tr
=
taosMemoryCalloc
(
1
,
sizeof
(
SIdxTempResu
lt
));
SIdxT
Rslt
*
idxTRs
ltCreate
()
{
SIdxT
Rslt
*
tr
=
taosMemoryCalloc
(
1
,
sizeof
(
SIdxTRs
lt
));
tr
->
total
=
taosArrayInit
(
4
,
sizeof
(
uint64_t
));
tr
->
add
ed
=
taosArrayInit
(
4
,
sizeof
(
uint64_t
));
tr
->
del
ed
=
taosArrayInit
(
4
,
sizeof
(
uint64_t
));
tr
->
add
=
taosArrayInit
(
4
,
sizeof
(
uint64_t
));
tr
->
del
=
taosArrayInit
(
4
,
sizeof
(
uint64_t
));
return
tr
;
}
void
sIdxTempResultClear
(
SIdxTempResu
lt
*
tr
)
{
void
idxTRsltClear
(
SIdxTRs
lt
*
tr
)
{
if
(
tr
==
NULL
)
{
return
;
}
taosArrayClear
(
tr
->
total
);
taosArrayClear
(
tr
->
add
ed
);
taosArrayClear
(
tr
->
del
ed
);
taosArrayClear
(
tr
->
add
);
taosArrayClear
(
tr
->
del
);
}
void
sIdxTempResultDestroy
(
SIdxTempResu
lt
*
tr
)
{
void
idxTRsltDestroy
(
SIdxTRs
lt
*
tr
)
{
if
(
tr
==
NULL
)
{
return
;
}
taosArrayDestroy
(
tr
->
total
);
taosArrayDestroy
(
tr
->
add
ed
);
taosArrayDestroy
(
tr
->
del
ed
);
taosArrayDestroy
(
tr
->
add
);
taosArrayDestroy
(
tr
->
del
);
}
void
sIdxTempResultMergeTo
(
SArray
*
result
,
SIdxTempResult
*
tr
)
{
void
idxTRsltMergeTo
(
SIdxTRslt
*
tr
,
SArray
*
result
)
{
taosArraySort
(
tr
->
total
,
uidCompare
);
taosArraySort
(
tr
->
added
,
uidCompare
);
taosArraySort
(
tr
->
deled
,
uidCompare
);
SArray
*
arrs
=
taosArrayInit
(
2
,
sizeof
(
void
*
));
taosArrayPush
(
arrs
,
&
tr
->
total
);
taosArrayPush
(
arrs
,
&
tr
->
added
);
iUnion
(
arrs
,
result
);
taosArrayDestroy
(
arrs
);
iExcept
(
result
,
tr
->
deled
);
taosArraySort
(
tr
->
add
,
uidCompare
);
taosArraySort
(
tr
->
del
,
uidCompare
);
if
(
taosArrayGetSize
(
tr
->
total
)
==
0
||
taosArrayGetSize
(
tr
->
add
)
==
0
)
{
SArray
*
t
=
taosArrayGetSize
(
tr
->
total
)
==
0
?
tr
->
add
:
tr
->
total
;
taosArrayAddAll
(
result
,
t
);
}
else
{
SArray
*
arrs
=
taosArrayInit
(
2
,
sizeof
(
void
*
));
taosArrayPush
(
arrs
,
&
tr
->
total
);
taosArrayPush
(
arrs
,
&
tr
->
add
);
iUnion
(
arrs
,
result
);
taosArrayDestroy
(
arrs
);
}
iExcept
(
result
,
tr
->
del
);
}
source/libs/index/test/CMakeLists.txt
浏览文件 @
46527878
add_executable
(
i
nde
xTest
""
)
add_executable
(
f
stTest
""
)
add_executable
(
f
stUT
""
)
add_executable
(
UtilUT
""
)
add_executable
(
j
sonUT
""
)
add_executable
(
i
d
xTest
""
)
add_executable
(
idxF
stTest
""
)
add_executable
(
idxF
stUT
""
)
add_executable
(
idx
UtilUT
""
)
add_executable
(
idxJ
sonUT
""
)
target_sources
(
i
nde
xTest
target_sources
(
i
d
xTest
PRIVATE
"indexTests.cc"
)
target_sources
(
f
stTest
target_sources
(
idxF
stTest
PRIVATE
"fstTest.cc"
)
target_sources
(
f
stUT
target_sources
(
idxF
stUT
PRIVATE
"fstUT.cc"
)
target_sources
(
UtilUT
target_sources
(
idx
UtilUT
PRIVATE
"utilUT.cc"
)
target_sources
(
j
sonUT
target_sources
(
idxJ
sonUT
PRIVATE
"jsonUT.cc"
)
target_include_directories
(
inde
xTest
target_include_directories
(
id
xTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/index"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
f
stTest
target_include_directories
(
idxF
stTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/index"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
f
stUT
target_include_directories
(
idxF
stUT
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/index"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
UtilUT
target_include_directories
(
idx
UtilUT
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/index"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
j
sonUT
target_include_directories
(
idxJ
sonUT
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/index"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_link_libraries
(
i
nde
xTest
target_link_libraries
(
i
d
xTest
os
util
common
gtest_main
index
)
target_link_libraries
(
f
stTest
target_link_libraries
(
idxF
stTest
os
util
common
gtest_main
index
)
target_link_libraries
(
f
stUT
target_link_libraries
(
idxF
stUT
os
util
common
...
...
@@ -76,7 +76,7 @@ target_link_libraries (fstUT
index
)
target_link_libraries
(
UtilUT
target_link_libraries
(
idx
UtilUT
os
util
common
...
...
@@ -84,7 +84,7 @@ target_link_libraries (UtilUT
index
)
target_link_libraries
(
j
sonUT
target_link_libraries
(
idxJ
sonUT
os
util
common
...
...
@@ -94,17 +94,17 @@ target_link_libraries (jsonUT
add_test
(
NAME idxtest
COMMAND i
nde
xTest
COMMAND i
d
xTest
)
add_test
(
NAME idxJsonUT
COMMAND
j
sonUT
COMMAND
idxJ
sonUT
)
add_test
(
NAME idxUtilUT
COMMAND UtilUT
COMMAND
idx
UtilUT
)
add_test
(
NAME idxFstUT
COMMAND
f
stUT
COMMAND
idxF
stUT
)
source/libs/index/test/indexTests.cc
浏览文件 @
46527878
...
...
@@ -411,12 +411,12 @@ class TFileObj {
//
//
}
SIdxT
empResult
*
tr
=
sIdxTempResu
ltCreate
();
SIdxT
Rslt
*
tr
=
idxTRs
ltCreate
();
int
ret
=
tfileReaderSearch
(
reader_
,
query
,
tr
);
sIdxTempResultMergeTo
(
result
,
tr
);
sIdxTempResu
ltDestroy
(
tr
);
idxTRsltMergeTo
(
tr
,
result
);
idxTRs
ltDestroy
(
tr
);
return
ret
;
}
~
TFileObj
()
{
...
...
@@ -531,11 +531,11 @@ class CacheObj {
indexCacheDebug
(
cache
);
}
int
Get
(
SIndexTermQuery
*
query
,
int16_t
colId
,
int32_t
version
,
SArray
*
result
,
STermValueType
*
s
)
{
SIdxT
empResult
*
tr
=
sIdxTempResu
ltCreate
();
SIdxT
Rslt
*
tr
=
idxTRs
ltCreate
();
int
ret
=
indexCacheSearch
(
cache
,
query
,
tr
,
s
);
sIdxTempResultMergeTo
(
result
,
tr
);
sIdxTempResu
ltDestroy
(
tr
);
idxTRsltMergeTo
(
tr
,
result
);
idxTRs
ltDestroy
(
tr
);
if
(
ret
!=
0
)
{
std
::
cout
<<
"failed to get from cache:"
<<
ret
<<
std
::
endl
;
...
...
source/libs/index/test/utilUT.cc
浏览文件 @
46527878
...
...
@@ -226,6 +226,22 @@ TEST_F(UtilEnv, 04union) {
iUnion
(
src
,
rslt
);
assert
(
taosArrayGetSize
(
rslt
)
==
12
);
}
TEST_F
(
UtilEnv
,
05u
nionExcept
)
{
clearSourceArray
(
src
);
clearFinalArray
(
rslt
);
uint64_t
arr2
[]
=
{
7
};
SArray
*
f
=
(
SArray
*
)
taosArrayGetP
(
src
,
1
);
for
(
int
i
=
0
;
i
<
sizeof
(
arr2
)
/
sizeof
(
arr2
[
0
]);
i
++
)
{
taosArrayPush
(
f
,
&
arr2
[
i
]);
}
iUnion
(
src
,
rslt
);
SArray
*
ept
=
taosArrayInit
(
0
,
sizeof
(
uint64_t
));
iExcept
(
rslt
,
ept
);
EXPECT_EQ
(
taosArrayGetSize
(
rslt
),
1
);
}
TEST_F
(
UtilEnv
,
01
Except
)
{
SArray
*
total
=
taosArrayInit
(
4
,
sizeof
(
uint64_t
));
{
...
...
@@ -308,16 +324,36 @@ TEST_F(UtilEnv, 01Except) {
ASSERT_EQ
(
*
(
uint64_t
*
)
taosArrayGet
(
total
,
1
),
100
);
}
TEST_F
(
UtilEnv
,
testFill
)
{
for
(
int
i
=
0
;
i
<
1000000
0
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000000
;
i
++
)
{
int64_t
val
=
i
;
char
buf
[
65
]
=
{
0
};
indexInt2str
(
val
,
buf
,
1
);
EXPECT_EQ
(
val
,
taosStr2int64
(
buf
));
}
for
(
int
i
=
0
;
i
<
1000000
0
;
i
++
)
{
for
(
int
i
=
0
;
i
<
1000000
;
i
++
)
{
int64_t
val
=
0
-
i
;
char
buf
[
65
]
=
{
0
};
indexInt2str
(
val
,
buf
,
-
1
);
EXPECT_EQ
(
val
,
taosStr2int64
(
buf
));
}
}
TEST_F
(
UtilEnv
,
TempResult
)
{
SIdxTRslt
*
relt
=
idxTRsltCreate
();
SArray
*
f
=
taosArrayInit
(
0
,
sizeof
(
uint64_t
));
uint64_t
val
=
UINT64_MAX
-
1
;
taosArrayPush
(
relt
->
add
,
&
val
);
idxTRsltMergeTo
(
relt
,
f
);
EXPECT_EQ
(
taosArrayGetSize
(
f
),
1
);
}
TEST_F
(
UtilEnv
,
TempResultExcept
)
{
SIdxTRslt
*
relt
=
idxTRsltCreate
();
SArray
*
f
=
taosArrayInit
(
0
,
sizeof
(
uint64_t
));
uint64_t
val
=
UINT64_MAX
;
taosArrayPush
(
relt
->
add
,
&
val
);
idxTRsltMergeTo
(
relt
,
f
);
EXPECT_EQ
(
taosArrayGetSize
(
f
),
1
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录