Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4dcdb549
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
4dcdb549
编写于
8月 17, 2023
作者:
W
wangjiaming0909
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: get systable cols error
上级
df6c93fd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
123 addition
and
93 deletion
+123
-93
source/dnode/mnode/impl/src/mndStb.c
source/dnode/mnode/impl/src/mndStb.c
+116
-92
tests/system-test/0-others/information_schema.py
tests/system-test/0-others/information_schema.py
+7
-1
未找到文件。
source/dnode/mnode/impl/src/mndStb.c
浏览文件 @
4dcdb549
...
...
@@ -3159,137 +3159,161 @@ static int32_t buildDbColsInfoBlock(const SSDataBlock *p, const SSysTableMeta *p
return
numOfRows
;
}
#define BUILD_COL_FOR_INFO_DB 1
#define BUILD_COL_FOR_PERF_DB 1 << 1
#define BUILD_COL_FOR_USER_DB 1 << 2
#define BUILD_COL_FOR_ALL_DB (BUILD_COL_FOR_INFO_DB | BUILD_COL_FOR_PERF_DB | BUILD_COL_FOR_USER_DB)
static
int32_t
buildSysDbColsInfo
(
SSDataBlock
*
p
,
char
*
db
,
char
*
tb
)
{
static
int32_t
buildSysDbColsInfo
(
SSDataBlock
*
p
,
int8_t
buildWhichDBs
,
char
*
tb
)
{
size_t
size
=
0
;
const
SSysTableMeta
*
pSysDbTableMeta
=
NULL
;
if
(
db
[
0
]
&&
strncmp
(
db
,
TSDB_INFORMATION_SCHEMA_DB
,
TSDB_DB_FNAME_LEN
)
!=
0
&&
strncmp
(
db
,
TSDB_PERFORMANCE_SCHEMA_DB
,
TSDB_DB_FNAME_LEN
)
!=
0
)
{
return
p
->
info
.
rows
;
if
(
buildWhichDBs
&
BUILD_COL_FOR_INFO_DB
)
{
getInfosDbMeta
(
&
pSysDbTableMeta
,
&
size
);
p
->
info
.
rows
=
buildDbColsInfoBlock
(
p
,
pSysDbTableMeta
,
size
,
TSDB_INFORMATION_SCHEMA_DB
,
tb
)
;
}
getInfosDbMeta
(
&
pSysDbTableMeta
,
&
size
);
p
->
info
.
rows
=
buildDbColsInfoBlock
(
p
,
pSysDbTableMeta
,
size
,
TSDB_INFORMATION_SCHEMA_DB
,
tb
);
getPerfDbMeta
(
&
pSysDbTableMeta
,
&
size
);
p
->
info
.
rows
=
buildDbColsInfoBlock
(
p
,
pSysDbTableMeta
,
size
,
TSDB_PERFORMANCE_SCHEMA_DB
,
tb
);
if
(
buildWhichDBs
&
BUILD_COL_FOR_PERF_DB
)
{
getPerfDbMeta
(
&
pSysDbTableMeta
,
&
size
);
p
->
info
.
rows
=
buildDbColsInfoBlock
(
p
,
pSysDbTableMeta
,
size
,
TSDB_PERFORMANCE_SCHEMA_DB
,
tb
);
}
return
p
->
info
.
rows
;
}
static
int8_t
determineBuildColForWhichDBs
(
const
char
*
db
)
{
int8_t
buildWhichDBs
;
if
(
!
db
[
0
])
buildWhichDBs
=
BUILD_COL_FOR_ALL_DB
;
else
{
char
*
p
=
strchr
(
db
,
'.'
);
if
(
p
&&
strcmp
(
p
+
1
,
TSDB_INFORMATION_SCHEMA_DB
)
==
0
)
{
buildWhichDBs
=
BUILD_COL_FOR_INFO_DB
;
}
else
if
(
p
&&
strcmp
(
p
+
1
,
TSDB_PERFORMANCE_SCHEMA_DB
)
==
0
)
{
buildWhichDBs
=
BUILD_COL_FOR_PERF_DB
;
}
else
{
buildWhichDBs
=
BUILD_COL_FOR_USER_DB
;
}
}
return
buildWhichDBs
;
}
static
int32_t
mndRetrieveStbCol
(
SRpcMsg
*
pReq
,
SShowObj
*
pShow
,
SSDataBlock
*
pBlock
,
int32_t
rows
)
{
uint8_t
buildWhichDBs
;
SMnode
*
pMnode
=
pReq
->
info
.
node
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
SStbObj
*
pStb
=
NULL
;
int32_t
numOfRows
=
0
;
buildWhichDBs
=
determineBuildColForWhichDBs
(
pShow
->
db
);
int32_t
numOfRows
=
0
;
if
(
!
pShow
->
sysDbRsp
)
{
numOfRows
=
buildSysDbColsInfo
(
pBlock
,
pShow
->
db
,
pShow
->
filterTb
);
numOfRows
=
buildSysDbColsInfo
(
pBlock
,
buildWhichDBs
,
pShow
->
filterTb
);
mDebug
(
"mndRetrieveStbCol get system table cols, rows:%d, db:%s"
,
numOfRows
,
pShow
->
db
);
pShow
->
sysDbRsp
=
true
;
}
SDbObj
*
pDb
=
NULL
;
if
(
strlen
(
pShow
->
db
)
>
0
)
{
pDb
=
mndAcquireDb
(
pMnode
,
pShow
->
db
);
if
(
pDb
==
NULL
)
return
terrno
;
}
char
typeName
[
TSDB_TABLE_FNAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
STR_TO_VARSTR
(
typeName
,
"SUPER_TABLE"
);
bool
fetch
=
pShow
->
restore
?
false
:
true
;
pShow
->
restore
=
false
;
while
(
numOfRows
<
rows
)
{
if
(
fetch
)
{
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_STB
,
pShow
->
pIter
,
(
void
**
)
&
pStb
);
if
(
pShow
->
pIter
==
NULL
)
break
;
}
else
{
fetch
=
true
;
void
*
pKey
=
taosHashGetKey
(
pShow
->
pIter
,
NULL
);
pStb
=
sdbAcquire
(
pSdb
,
SDB_STB
,
pKey
);
if
(
!
pStb
)
continue
;
if
(
buildWhichDBs
&
BUILD_COL_FOR_USER_DB
)
{
SDbObj
*
pDb
=
NULL
;
if
(
strlen
(
pShow
->
db
)
>
0
)
{
pDb
=
mndAcquireDb
(
pMnode
,
pShow
->
db
);
if
(
pDb
==
NULL
&&
TSDB_CODE_MND_DB_NOT_EXIST
!=
terrno
&&
pBlock
->
info
.
rows
==
0
)
return
terrno
;
}
if
(
pDb
!=
NULL
&&
pStb
->
dbUid
!=
pDb
->
uid
)
{
sdbRelease
(
pSdb
,
pStb
);
continue
;
}
char
typeName
[
TSDB_TABLE_FNAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
STR_TO_VARSTR
(
typeName
,
"SUPER_TABLE"
);
bool
fetch
=
pShow
->
restore
?
false
:
true
;
pShow
->
restore
=
false
;
while
(
numOfRows
<
rows
)
{
if
(
fetch
)
{
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_STB
,
pShow
->
pIter
,
(
void
**
)
&
pStb
);
if
(
pShow
->
pIter
==
NULL
)
break
;
}
else
{
fetch
=
true
;
void
*
pKey
=
taosHashGetKey
(
pShow
->
pIter
,
NULL
);
pStb
=
sdbAcquire
(
pSdb
,
SDB_STB
,
pKey
);
if
(
!
pStb
)
continue
;
}
SName
name
=
{
0
};
char
stbName
[
TSDB_TABLE_NAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
mndExtractTbNameFromStbFullName
(
pStb
->
name
,
&
stbName
[
VARSTR_HEADER_SIZE
],
TSDB_TABLE_NAME_LEN
);
if
(
pShow
->
filterTb
[
0
]
&&
strncmp
(
pShow
->
filterTb
,
&
stbName
[
VARSTR_HEADER_SIZE
],
TSDB_TABLE_NAME_LEN
)
!=
0
)
{
sdbRelease
(
pSdb
,
pStb
);
continue
;
}
if
(
pDb
!=
NULL
&&
pStb
->
dbUid
!=
pDb
->
uid
)
{
sdbRelease
(
pSdb
,
pStb
);
continue
;
}
if
((
numOfRows
+
pStb
->
numOfColumns
)
>
rows
)
{
pShow
->
restore
=
true
;
if
(
numOfRows
==
0
)
{
mError
(
"mndRetrieveStbCol failed to get stable cols since buf:%d less than result:%d, stable name:%s, db:%s"
,
rows
,
pStb
->
numOfColumns
,
pStb
->
name
,
pStb
->
db
);
SName
name
=
{
0
};
char
stbName
[
TSDB_TABLE_NAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
mndExtractTbNameFromStbFullName
(
pStb
->
name
,
&
stbName
[
VARSTR_HEADER_SIZE
],
TSDB_TABLE_NAME_LEN
);
if
(
pShow
->
filterTb
[
0
]
&&
strncmp
(
pShow
->
filterTb
,
&
stbName
[
VARSTR_HEADER_SIZE
],
TSDB_TABLE_NAME_LEN
)
!=
0
)
{
sdbRelease
(
pSdb
,
pStb
);
continue
;
}
sdbRelease
(
pSdb
,
pStb
);
break
;
}
varDataSetLen
(
stbName
,
strlen
(
&
stbName
[
VARSTR_HEADER_SIZE
]));
if
((
numOfRows
+
pStb
->
numOfColumns
)
>
rows
)
{
pShow
->
restore
=
true
;
if
(
numOfRows
==
0
)
{
mError
(
"mndRetrieveStbCol failed to get stable cols since buf:%d less than result:%d, stable name:%s, db:%s"
,
rows
,
pStb
->
numOfColumns
,
pStb
->
name
,
pStb
->
db
);
}
sdbRelease
(
pSdb
,
pStb
);
break
;
}
mDebug
(
"mndRetrieveStbCol get stable cols, stable name:%s, db:%s"
,
pStb
->
name
,
pStb
->
db
);
varDataSetLen
(
stbName
,
strlen
(
&
stbName
[
VARSTR_HEADER_SIZE
])
);
char
db
[
TSDB_DB_NAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
tNameFromString
(
&
name
,
pStb
->
db
,
T_NAME_ACCT
|
T_NAME_DB
);
tNameGetDbName
(
&
name
,
varDataVal
(
db
));
varDataSetLen
(
db
,
strlen
(
varDataVal
(
db
)));
mDebug
(
"mndRetrieveStbCol get stable cols, stable name:%s, db:%s"
,
pStb
->
name
,
pStb
->
db
);
for
(
int
i
=
0
;
i
<
pStb
->
numOfColumns
;
i
++
)
{
int32_t
cols
=
0
;
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataSetVal
(
pColInfo
,
numOfRows
,
(
const
char
*
)
stbName
,
false
);
char
db
[
TSDB_DB_NAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
tNameFromString
(
&
name
,
pStb
->
db
,
T_NAME_ACCT
|
T_NAME_DB
)
;
tNameGetDbName
(
&
name
,
varDataVal
(
db
)
);
varDataSetLen
(
db
,
strlen
(
varDataVal
(
db
))
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataSetVal
(
pColInfo
,
numOfRows
,
(
const
char
*
)
db
,
false
);
for
(
int
i
=
0
;
i
<
pStb
->
numOfColumns
;
i
++
)
{
int32_t
cols
=
0
;
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataSetVal
(
pColInfo
,
numOfRows
,
(
const
char
*
)
stbName
,
false
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataSetVal
(
pColInfo
,
numOfRows
,
typeName
,
false
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataSetVal
(
pColInfo
,
numOfRows
,
(
const
char
*
)
db
,
false
);
// col name
char
colName
[
TSDB_COL_NAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
STR_TO_VARSTR
(
colName
,
pStb
->
pColumns
[
i
].
name
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataSetVal
(
pColInfo
,
numOfRows
,
colName
,
false
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataSetVal
(
pColInfo
,
numOfRows
,
typeName
,
false
);
// col type
int8_t
colType
=
pStb
->
pColumns
[
i
].
type
;
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
char
colTypeStr
[
VARSTR_HEADER_SIZE
+
32
];
int
colTypeLen
=
sprintf
(
varDataVal
(
colTypeStr
),
"%s"
,
tDataTypes
[
colType
].
name
);
if
(
colType
==
TSDB_DATA_TYPE_VARCHAR
)
{
colTypeLen
+=
sprintf
(
varDataVal
(
colTypeStr
)
+
colTypeLen
,
"(%d)"
,
(
int32_t
)(
pStb
->
pColumns
[
i
].
bytes
-
VARSTR_HEADER_SIZE
));
}
else
if
(
colType
==
TSDB_DATA_TYPE_NCHAR
)
{
colTypeLen
+=
sprintf
(
varDataVal
(
colTypeStr
)
+
colTypeLen
,
"(%d)"
,
(
int32_t
)((
pStb
->
pColumns
[
i
].
bytes
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
));
}
varDataSetLen
(
colTypeStr
,
colTypeLen
);
colDataSetVal
(
pColInfo
,
numOfRows
,
(
char
*
)
colTypeStr
,
false
);
// col name
char
colName
[
TSDB_COL_NAME_LEN
+
VARSTR_HEADER_SIZE
]
=
{
0
};
STR_TO_VARSTR
(
colName
,
pStb
->
pColumns
[
i
].
name
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataSetVal
(
pColInfo
,
numOfRows
,
colName
,
false
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataSetVal
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pStb
->
pColumns
[
i
].
bytes
,
false
);
while
(
cols
<
pShow
->
numOfColumns
)
{
// col type
int8_t
colType
=
pStb
->
pColumns
[
i
].
type
;
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataSetNULL
(
pColInfo
,
numOfRows
);
char
colTypeStr
[
VARSTR_HEADER_SIZE
+
32
];
int
colTypeLen
=
sprintf
(
varDataVal
(
colTypeStr
),
"%s"
,
tDataTypes
[
colType
].
name
);
if
(
colType
==
TSDB_DATA_TYPE_VARCHAR
)
{
colTypeLen
+=
sprintf
(
varDataVal
(
colTypeStr
)
+
colTypeLen
,
"(%d)"
,
(
int32_t
)(
pStb
->
pColumns
[
i
].
bytes
-
VARSTR_HEADER_SIZE
));
}
else
if
(
colType
==
TSDB_DATA_TYPE_NCHAR
)
{
colTypeLen
+=
sprintf
(
varDataVal
(
colTypeStr
)
+
colTypeLen
,
"(%d)"
,
(
int32_t
)((
pStb
->
pColumns
[
i
].
bytes
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
));
}
varDataSetLen
(
colTypeStr
,
colTypeLen
);
colDataSetVal
(
pColInfo
,
numOfRows
,
(
char
*
)
colTypeStr
,
false
);
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataSetVal
(
pColInfo
,
numOfRows
,
(
const
char
*
)
&
pStb
->
pColumns
[
i
].
bytes
,
false
);
while
(
cols
<
pShow
->
numOfColumns
)
{
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
cols
++
);
colDataSetNULL
(
pColInfo
,
numOfRows
);
}
numOfRows
++
;
}
numOfRows
++
;
}
sdbRelease
(
pSdb
,
pStb
);
}
sdbRelease
(
pSdb
,
pStb
);
}
if
(
pDb
!=
NULL
)
{
mndReleaseDb
(
pMnode
,
pDb
);
if
(
pDb
!=
NULL
)
{
mndReleaseDb
(
pMnode
,
pDb
);
}
}
pShow
->
numOfRows
+=
numOfRows
;
...
...
tests/system-test/0-others/information_schema.py
浏览文件 @
4dcdb549
...
...
@@ -215,7 +215,13 @@ class TDTestCase:
for
t
in
range
(
2
):
tdSql
.
query
(
f
'select * from information_schema.ins_columns where db_name="db2" and table_type=="NORMAL_TABLE"'
)
tdSql
.
checkEqual
(
20470
,
len
(
tdSql
.
queryResult
))
tdSql
.
query
(
"select * from information_schema.ins_columns where db_name ='information_schema'"
)
tdSql
.
checkEqual
(
195
,
len
(
tdSql
.
queryResult
))
tdSql
.
query
(
"select * from information_schema.ins_columns where db_name ='performance_schema'"
)
tdSql
.
checkEqual
(
54
,
len
(
tdSql
.
queryResult
))
def
ins_dnodes_check
(
self
):
tdSql
.
execute
(
'drop database if exists db2'
)
tdSql
.
execute
(
'create database if not exists db2 vgroups 1 replica 1'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录