Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
079a8f75
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
079a8f75
编写于
5月 02, 2020
作者:
H
hjxilinx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-168]
上级
9e280acb
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
85 addition
and
46 deletion
+85
-46
src/client/src/tscLocal.c
src/client/src/tscLocal.c
+22
-17
src/common/inc/tdataformat.h
src/common/inc/tdataformat.h
+11
-0
src/mnode/src/mgmtDb.c
src/mnode/src/mgmtDb.c
+5
-1
src/mnode/src/mgmtTable.c
src/mnode/src/mgmtTable.c
+12
-2
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+29
-22
tests/examples/c/demo.c
tests/examples/c/demo.c
+6
-4
未找到文件。
src/client/src/tscLocal.c
浏览文件 @
079a8f75
...
...
@@ -131,17 +131,23 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
&
pQueryInfo
->
fieldsInfo
,
0
);
strncpy
(
pRes
->
data
+
tscFieldInfoGetOffset
(
pQueryInfo
,
0
)
*
totalNumOfRows
+
pField
->
bytes
*
i
,
pSchema
[
i
].
name
,
TSDB_COL_NAME_LEN
);
char
*
dst
=
pRes
->
data
+
tscFieldInfoGetOffset
(
pQueryInfo
,
0
)
*
totalNumOfRows
+
pField
->
bytes
*
i
;
STR_TO_VARSTR
(
dst
,
pSchema
[
i
].
name
);
char
*
type
=
tDataTypeDesc
[
pSchema
[
i
].
type
].
aName
;
pField
=
tscFieldInfoGetField
(
&
pQueryInfo
->
fieldsInfo
,
1
);
strncpy
(
pRes
->
data
+
tscFieldInfoGetOffset
(
pQueryInfo
,
1
)
*
totalNumOfRows
+
pField
->
bytes
*
i
,
type
,
pField
->
bytes
);
dst
=
pRes
->
data
+
tscFieldInfoGetOffset
(
pQueryInfo
,
1
)
*
totalNumOfRows
+
pField
->
bytes
*
i
;
STR_TO_VARSTR
(
dst
,
type
);
int32_t
bytes
=
pSchema
[
i
].
bytes
;
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
bytes
=
bytes
/
TSDB_NCHAR_SIZE
;
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_BINARY
||
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
bytes
-=
VARSTR_HEADER_SIZE
;
if
(
pSchema
[
i
].
type
==
TSDB_DATA_TYPE_NCHAR
)
{
bytes
=
bytes
/
TSDB_NCHAR_SIZE
;
}
}
pField
=
tscFieldInfoGetField
(
&
pQueryInfo
->
fieldsInfo
,
2
);
...
...
@@ -233,7 +239,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
return
0
;
}
static
int32_t
tscBuild
Meter
SchemaResultFields
(
SSqlObj
*
pSql
,
int32_t
numOfCols
,
int32_t
typeColLength
,
static
int32_t
tscBuild
Table
SchemaResultFields
(
SSqlObj
*
pSql
,
int32_t
numOfCols
,
int32_t
typeColLength
,
int32_t
noteColLength
)
{
int32_t
rowLen
=
0
;
SColumnIndex
index
=
{
0
};
...
...
@@ -243,14 +249,14 @@ static int32_t tscBuildMeterSchemaResultFields(SSqlObj *pSql, int32_t numOfCols,
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
pQueryInfo
->
order
.
order
=
TSDB_ORDER_ASC
;
TAOS_FIELD
f
=
{.
type
=
TSDB_DATA_TYPE_BINARY
,
.
bytes
=
TSDB_COL_NAME_LEN
};
TAOS_FIELD
f
=
{.
type
=
TSDB_DATA_TYPE_BINARY
,
.
bytes
=
TSDB_COL_NAME_LEN
+
VARSTR_HEADER_SIZE
};
strncpy
(
f
.
name
,
"Field"
,
TSDB_COL_NAME_LEN
);
SFieldSupInfo
*
pInfo
=
tscFieldInfoAppend
(
&
pQueryInfo
->
fieldsInfo
,
&
f
);
pInfo
->
pSqlExpr
=
tscSqlExprAppend
(
pQueryInfo
,
TSDB_FUNC_TS_DUMMY
,
&
index
,
TSDB_DATA_TYPE_BINARY
,
TSDB_COL_NAME_LEN
,
TSDB_COL_NAME_LEN
,
false
);
pInfo
->
pSqlExpr
=
tscSqlExprAppend
(
pQueryInfo
,
TSDB_FUNC_TS_DUMMY
,
&
index
,
TSDB_DATA_TYPE_BINARY
,
TSDB_COL_NAME_LEN
+
VARSTR_HEADER_SIZE
,
TSDB_COL_NAME_LEN
,
false
);
rowLen
+=
TSDB_COL_NAME_LEN
;
rowLen
+=
(
TSDB_COL_NAME_LEN
+
VARSTR_HEADER_SIZE
)
;
f
.
bytes
=
typeColLength
;
f
.
type
=
TSDB_DATA_TYPE_BINARY
;
...
...
@@ -289,17 +295,16 @@ static int32_t tscProcessDescribeTable(SSqlObj *pSql) {
assert
(
tscGetMetaInfo
(
pQueryInfo
,
0
)
->
pTableMeta
!=
NULL
);
const
int32_t
NUM_OF_DESC
RIBE
_TABLE_COLUMNS
=
4
;
const
int32_t
NUM_OF_DESC_TABLE_COLUMNS
=
4
;
const
int32_t
TYPE_COLUMN_LENGTH
=
16
;
const
int32_t
NOTE_COLUMN_MIN_LENGTH
=
8
;
int32_t
note
_field_length
=
tscMaxLengthOfTagsFields
(
pSql
);
if
(
note
_field_length
==
0
)
{
note
_field_length
=
NOTE_COLUMN_MIN_LENGTH
;
int32_t
note
FieldLen
=
tscMaxLengthOfTagsFields
(
pSql
);
if
(
note
FieldLen
==
0
)
{
note
FieldLen
=
NOTE_COLUMN_MIN_LENGTH
;
}
int32_t
rowLen
=
tscBuildMeterSchemaResultFields
(
pSql
,
NUM_OF_DESCRIBE_TABLE_COLUMNS
,
TYPE_COLUMN_LENGTH
,
note_field_length
);
int32_t
rowLen
=
tscBuildTableSchemaResultFields
(
pSql
,
NUM_OF_DESC_TABLE_COLUMNS
,
TYPE_COLUMN_LENGTH
,
noteFieldLen
);
tscFieldInfoUpdateOffset
(
pQueryInfo
);
return
tscSetValueToResObj
(
pSql
,
rowLen
);
}
...
...
src/common/inc/tdataformat.h
浏览文件 @
079a8f75
...
...
@@ -26,6 +26,17 @@
extern
"C"
{
#endif
#define VARSTR_HEADER_SIZE sizeof(int16_t)
#define STR_TO_VARSTR(x, str) do {int16_t __len = strlen(str); \
*(int16_t*)(x) = __len; \
strncpy((char*)(x) + VARSTR_HEADER_SIZE, (str), __len);} while(0);
#define STR_TO_VARSTR_WITH_SIZE(x, str, _size) do {\
int16_t __len = strnlen((str), (_size)); \
*(int16_t*)(x) = __len; \
strncpy((char*)(x) + VARSTR_HEADER_SIZE, (str), __len);\
} while(0);
// ----------------- TSDB COLUMN DEFINITION
typedef
struct
{
int8_t
type
;
// Column type
...
...
src/mnode/src/mgmtDb.c
浏览文件 @
079a8f75
...
...
@@ -579,7 +579,11 @@ static int32_t mgmtRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strcpy
(
pWrite
,
mgmtGetDbStr
(
pDb
->
name
));
char
*
name
=
mgmtGetDbStr
(
pDb
->
name
);
*
(
int16_t
*
)
pWrite
=
strnlen
(
name
,
TSDB_DB_NAME_LEN
);
pWrite
+=
sizeof
(
int16_t
);
// todo refactor
strncpy
(
pWrite
,
mgmtGetDbStr
(
pDb
->
name
),
TSDB_DB_NAME_LEN
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
...
...
src/mnode/src/mgmtTable.c
浏览文件 @
079a8f75
...
...
@@ -1119,7 +1119,12 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strncpy
(
pWrite
,
stableName
,
TSDB_TABLE_NAME_LEN
);
int16_t
len
=
strnlen
(
stableName
,
TSDB_DB_NAME_LEN
);
*
(
int16_t
*
)
pWrite
=
len
;
pWrite
+=
sizeof
(
int16_t
);
// todo refactor
strncpy
(
pWrite
,
stableName
,
len
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
...
...
@@ -2075,7 +2080,12 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows,
int32_t
cols
=
0
;
char
*
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
strncpy
(
pWrite
,
tableName
,
TSDB_TABLE_NAME_LEN
);
int16_t
len
=
strnlen
(
tableName
,
TSDB_DB_NAME_LEN
);
*
(
int16_t
*
)
pWrite
=
len
;
pWrite
+=
sizeof
(
int16_t
);
// todo refactor
strncpy
(
pWrite
,
tableName
,
len
);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
079a8f75
...
...
@@ -415,16 +415,11 @@ static bool doLoadFileDataBlock(STsdbQueryHandle* pQueryHandle, SCompBlock* pBlo
SArray
*
sa
=
getDefaultLoadColumns
(
pQueryHandle
,
true
);
if
(
pCheckInfo
->
pDataCols
==
NULL
)
{
pCheckInfo
->
pDataCols
=
tdNewDataCols
(
1000
,
2
,
4096
);
pCheckInfo
->
pDataCols
=
tdNewDataCols
(
1000
,
100
,
4096
);
//todo fix me
}
tdInitDataCols
(
pCheckInfo
->
pDataCols
,
tsdbGetTableSchema
(
tsdbGetMeta
(
pQueryHandle
->
pTsdb
),
pCheckInfo
->
pTableObj
));
// SFile* pFile = &pQueryHandle->pFileGroup->files[TSDB_FILE_TYPE_DATA];
// if (pFile->fd == FD_INITIALIZER) {
// pFile->fd = open(pFile->fname, O_RDONLY);
// }
if
(
tsdbLoadBlockData
(
&
(
pQueryHandle
->
rhelper
),
pBlock
,
NULL
)
==
0
)
{
SDataBlockLoadInfo
*
pBlockLoadInfo
=
&
pQueryHandle
->
dataBlockLoadInfo
;
...
...
@@ -601,27 +596,27 @@ static void filterDataInDataBlock(STsdbQueryHandle* pQueryHandle, STableCheckInf
// }
// move the data block in the front to data block if needed
int32_t
numOfCols
=
QH_GET_NUM_OF_COLS
(
pQueryHandle
);
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
sa
);
++
i
)
{
int16_t
colId
=
*
(
int16_t
*
)
taosArrayGet
(
sa
,
i
);
int32_t
numOfCols
=
pQueryHandle
->
rhelper
.
pDataCols
[
0
]
->
numOfCols
;
int32_t
reqCols
=
taosArrayGetSize
(
pQueryHandle
->
pColumns
);
for
(
int32_t
i
=
0
;
i
<
reqCols
;
++
i
)
{
// int16_t colId = *(int16_t*)taosArrayGet(sa, i);
SColumnInfoData
*
pCol
=
taosArrayGet
(
pQueryHandle
->
pColumns
,
i
);
int32_t
bytes
=
pCol
->
info
.
bytes
;
for
(
int32_t
j
=
0
;
j
<
numOfCols
;
++
j
)
{
SColumnInfoData
*
pCol
=
taosArrayGet
(
pQueryHandle
->
pColumns
,
j
);
int32_t
bytes
=
pCol
->
info
.
bytes
;
SDataCol
*
src
=
&
pQueryHandle
->
rhelper
.
pDataCols
[
0
]
->
cols
[
j
];
if
(
pCol
->
info
.
colId
==
colId
)
{
if
(
pCol
->
info
.
colId
==
src
->
colId
)
{
if
(
pCol
->
info
.
type
!=
TSDB_DATA_TYPE_BINARY
&&
pCol
->
info
.
type
!=
TSDB_DATA_TYPE_NCHAR
)
{
memmove
(
pCol
->
pData
,
pQueryHandle
->
rhelper
.
pDataCols
[
0
]
->
cols
[
i
].
pData
+
bytes
*
start
,
bytes
*
pQueryHandle
->
realNumOfRows
);
}
else
{
SDataCol
*
src
=
&
pQueryHandle
->
rhelper
.
pDataCols
[
0
]
->
cols
[
i
];
memmove
(
pCol
->
pData
,
src
->
pData
+
bytes
*
start
,
bytes
*
pQueryHandle
->
realNumOfRows
);
}
else
{
// handle the var-string
for
(
int32_t
k
=
start
;
k
<
pQueryHandle
->
realNumOfRows
+
start
;
++
k
)
{
char
*
p
=
tdGetColDataOfRow
(
src
,
k
);
memcpy
(
pCol
->
pData
+
k
*
bytes
,
p
,
*
(
int16_t
*
)
p
+
sizeof
(
int16_t
));
// todo refactor
memcpy
(
pCol
->
pData
+
k
*
bytes
,
p
,
varDataTLen
(
p
));
// todo refactor
}
}
break
;
}
}
...
...
@@ -1010,7 +1005,7 @@ void changeQueryHandleForQuery(TsdbQueryHandleT pqHandle) {
pQueryHandle
->
window
=
(
STimeWindow
)
{
key
,
key
};
}
static
int
tsdbReadRowsFromCache
(
SSkipListIterator
*
pIter
,
TSKEY
maxKey
,
int
maxRowsToRead
,
TSKEY
*
skey
,
TSKEY
*
ekey
,
static
int
tsdbReadRowsFromCache
(
SSkipListIterator
*
pIter
,
STable
*
pTable
,
TSKEY
maxKey
,
int
maxRowsToRead
,
TSKEY
*
skey
,
TSKEY
*
ekey
,
STsdbQueryHandle
*
pQueryHandle
)
{
int
numOfRows
=
0
;
int32_t
numOfCols
=
taosArrayGetSize
(
pQueryHandle
->
pColumns
);
...
...
@@ -1040,8 +1035,11 @@ static int tsdbReadRowsFromCache(SSkipListIterator* pIter, TSKEY maxKey, int max
*
ekey
=
dataRowKey
(
row
);
int32_t
offset
=
0
;
int32_t
offset
=
-
1
;
char
*
pData
=
NULL
;
STSchema
*
pSchema
=
tsdbGetTableSchema
(
tsdbGetMeta
(
pQueryHandle
->
pTsdb
),
pTable
);
int32_t
numOfTableCols
=
schemaNCols
(
pSchema
);
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pQueryHandle
->
pColumns
,
i
);
...
...
@@ -1052,6 +1050,15 @@ static int tsdbReadRowsFromCache(SSkipListIterator* pIter, TSKEY maxKey, int max
pData
=
pColInfo
->
pData
+
(
maxRowsToRead
-
numOfRows
-
1
)
*
pColInfo
->
info
.
bytes
;
}
for
(
int32_t
j
=
0
;
j
<
numOfTableCols
;
++
j
)
{
if
(
pColInfo
->
info
.
colId
==
pSchema
->
columns
[
j
].
colId
)
{
offset
=
pSchema
->
columns
[
j
].
offset
;
break
;
}
}
assert
(
offset
!=
-
1
);
// todo handle error
if
(
pColInfo
->
info
.
type
==
TSDB_DATA_TYPE_BINARY
||
pColInfo
->
info
.
type
==
TSDB_DATA_TYPE_NCHAR
)
{
void
*
value
=
tdGetRowDataOfCol
(
row
,
pColInfo
->
info
.
type
,
TD_DATA_ROW_HEAD_SIZE
+
offset
);
memcpy
(
pData
,
value
,
varDataTLen
(
value
));
...
...
@@ -1127,7 +1134,7 @@ SDataBlockInfo tsdbRetrieveDataBlockInfo(TsdbQueryHandleT* pQueryHandle) {
if
(
pTable
->
mem
!=
NULL
)
{
// create mem table iterator if it is not created yet
assert
(
pCheckInfo
->
iter
!=
NULL
);
rows
=
tsdbReadRowsFromCache
(
pCheckInfo
->
iter
,
pHandle
->
window
.
ekey
,
4000
,
&
skey
,
&
ekey
,
pHandle
);
rows
=
tsdbReadRowsFromCache
(
pCheckInfo
->
iter
,
p
CheckInfo
->
pTableObj
,
p
Handle
->
window
.
ekey
,
4000
,
&
skey
,
&
ekey
,
pHandle
);
// update the last key value
pCheckInfo
->
lastKey
=
ekey
+
step
;
...
...
tests/examples/c/demo.c
浏览文件 @
079a8f75
...
...
@@ -75,11 +75,13 @@ int main(int argc, char *argv[]) {
doQuery
(
taos
,
"create database if not exists test"
);
doQuery
(
taos
,
"use test"
);
doQuery
(
taos
,
"select * from t1 order by ts desc"
);
// doQuery(taos, "create table t1(ts timestamp, k binary(12), f nchar(2))");
for
(
int32_t
i
=
0
;
i
<
100000
;
++
i
)
{
doQuery
(
taos
,
"select m1.ts,m1.a from m1, m2 where m1.ts=m2.ts and m1.a=m2.b;"
);
usleep
(
500000
);
}
//
for(int32_t i = 0; i< 100000; ++i) {
//
doQuery(taos, "select m1.ts,m1.a from m1, m2 where m1.ts=m2.ts and m1.a=m2.b;");
//
usleep(500000);
//
}
// doQuery(taos, "insert into tm0 values('2020-1-1 1:1:1', 'abc')");
// doQuery(taos, "create table if not exists tm0 (ts timestamp, k int);");
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录