已开启
[Bug] dolphin MySQL 协议查询元数据返回 Opengauss类型名,导致 MySQL ORM(Diesel)print-schema 报 Unsupported type #1625
Rourou2285创建于  18 天前
Rourou2285
Rourou2285
18 天前 创建

问题描述

通过 MySQL 协议(dolphin 3306)连接 openGauss B 兼容库后,执行结构内省(DESCRIBE/SHOW COLUMNS、查询 information_schema.columnsdata_type/column_type)时,返回的是 PostgreSQL 原生类型名,而非 MySQL 类型名:

入口 实际返回 期望(MySQL)
SHOW COLUMNS 的 Type character varying(50)double precisiontimestamp without time zone varchar(50)doubledatetime
information_schema.columns.data_type character varyingdouble precisionbooleanrealnumber varchardoubletinyint/tinyint(1)floatdecimal
information_schema.columns.column_type 同上 同上

这导致依赖 information_schema/SHOW COLUMNS 做自动内省的 MySQL ORM(如 Rust Diesel 2.3)无法识别类型名并中止:

$ diesel print-schema --only-tables t8_mig
Unsupported type: `character varying`

复现步骤

  1. 启动 dolphin(enable_dolphin_proto=ondolphin_server_port=3306),连接 B 兼容库。
  2. 建表:
    CREATE TABLE t8_mig (id INT AUTO_INCREMENT PRIMARY KEY, v VARCHAR(50), d DOUBLE, ts TIMESTAMP, dt DATETIME);
    
  3. MySQL 协议下查询内省:
    SELECT column_name, data_type, column_type
    FROM information_schema.columns
    WHERE table_schema = DATABASE() AND table_name = 't8_mig'
    ORDER BY ordinal_position;
    
    返回 character varying / double precision / timestamp with time zone / timestamp without time zone
  4. 运行 diesel print-schema --only-tables t8_mig,报 Unsupported type: \character varying``。

环境

  • openGauss master(build 56d37672)
  • Plugin(dolphin)master(1ea8c72b3)
  • Diesel 2.3.12(mysql backend,mysqlclient-sys 0.5.2)

根因

dolphin 的 MySQL 协议边界两条内省出口直接输出了 PG 侧 format_type() 文本:

  • plugin_parser/parse_describe.cpp::makeTypeColumn()DESCRIBE/SHOW COLUMNS 的 Type 列调用 format_type(atttypid, atttypmod)
  • information_schema.columns(共享视图):data_type/column_type 同样来自 format_type(...)

而协议层 b_type_items[] 只提供结果集字段的类型码/字符集,没有“MySQL 可读类型名”字段,因此两条路径长期缺少 PG→MySQL 名称映射。

影响

  • 普通 DML/查询不受影响(结果集列元数据走 DOLPHIN_TYPE_* 类型码)。
  • 所有依赖 information_schema.columns/SHOW COLUMNS 做自动内省的 ORM/工具(Diesel、不少 MySQL 驱动/迁移工具)会因无法识别类型名而中止或生成错误模型。
  • 业务若按 data_type 分派(区分文本/数值/日期),会因拿到 PG 名而走错分支。

期望行为

MySQL 协议内省返回 MySQL 类型名,并保留长度/精度:
character varying→varcharcharacter→charboolean→tinyint(1)real→floatdouble precision→doublenumeric/number→decimaltimestamp without time zone→datetimetimestamp with time zone→timestamptime without time zone→timebit varying→bitinteger→intbytea→blob

建议修复

  • TypeItem 增加 mysql_typname,以 b_type_items[] 作为 PG→MySQL 类型名映射(单一真源)。
  • 新增 mysql_type_name(oid, typmod)mysql_type_name(text) 两个 SQL 函数,统一转换。
  • DESCRIBE/SHOW COLUMNS 的 Type 列改用 mysql_type_name
  • 通过 transformStmt 包装,仅对 MySQL 协议连接改写 information_schema.columns.column_type/data_type;PG 协议与共享视图不受影响。

验证

  • clean(未修复)dolphin:diesel print-schemaUnsupported type: \character varying`information_schema.columns` 返回 PG 名。
  • 修复后:内省返回 varchar/double/datetime 等 MySQL 名,print-schema 正常生成 Diesel 核心类型(Varchar/Double/Datetime/Timestamp)。
likedislike
opengauss_bot
opengauss_bot成员
18 天前 评论:

This issue requires an assignee. Since you haven't specified one, we've assigned TestManager as the default assignee for this issue.

likedislike
opengauss_botopengauss_bot成员
18 天前 将 TestManager 设为负责人
opengauss_botopengauss_bot成员
18 天前 添加了label:sig/Plugin
opengauss_bot
opengauss_bot成员
18 天前 评论:

Welcome To openGauss Community

Hey @Rourou2285 , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.

Contact Guide

If you have any questions, please contact the SIG: Plugin ,
and any of the maintainers: @CarrotGo, @chendong76, @chenxiaobin19, @congzhou2603, @dodders, @hwworkholic, @jemappellehc, @libiao2024, @muyulinzhong, @quemingjian, @shenzheng4, @shirley_zhengx, @superlchf, @totaj, @wlff234, @wofanzheng, @ywzq1161327784 ,
and any of the committers: @dreamalloc, @huyinghao, @libiao2024, @wangfeihuo, @wmy_ld, @wuyuechuan, @xiong_xjun, @zhangxubo, @zhaojunv3z810 .

likedislike
Rourou2285Rourou2285
18 天前 关联了pull request:[dolphin] Map PG type names to MySQL names on protocol introspection
Rourou2285Rourou2285
18 天前 修改了issue 的描述
superlchf成员
17 天前 评论:

推荐逻辑
在 Datum format_type() 中:修改
1.判断当前会话是否是 Dolphin/MySQL 协议;
2.如果是 MySQL 协议,再执行 PostgreSQL 类型名到 MySQL 类型名的转换;
3.如果是 PostgreSQL 协议,保持原输出完全不变。

likedislike
sungang14sungang14成员
12 天前 issue优先级由 无优先级 改变为 次要
sungang14sungang14成员
12 天前 关联了看板:openGauss 7.0.0-LTS
ywzq1161327784ywzq1161327784成员
11 天前 移除了负责人 TestManager
opengauss_bot
opengauss_bot成员
11 天前 评论:

This issue requires an assignee. Since you haven't specified one, we've assigned TestManager as the default assignee for this issue.

likedislike
opengauss_botopengauss_bot成员
11 天前 将 TestManager 设为负责人
此处折叠了11条事件消息 查看更多
Ssuperlchf成员
3 天前 issue状态由 待办的 改变为 进行中
Rourou2285
Rourou2285
3 天前 评论:

验证结果:通过(PASS)

测例:Diesel metadata 模块(examples 测例链接 https://atomgit.com/opengauss/examples/merge_requests/108

用例 覆盖 结果
T-Meta-Setup 创建元数据探针表(16 种类型) PASS
T-Meta-1 information_schema.columns 返回 MySQL 类型名 PASS
T-Meta-2 类型名无 openGauss 原生名泄漏(负向断言) PASS
T-Meta-3 diesel print-schema 生成 Diesel 核心类型 PASS
T-Meta-4a SHOW COLUMNSType 返回 MySQL 类型名 PASS
T-Meta-4b SHOW COLUMNS 无 openGauss 原生名泄漏 PASS
T-Meta-5 nvarchar2 列类型名映射为 varchar PASS
T-Meta-6 DESCRIBESHOW COLUMNS 类型名一致 PASS
T-Meta-7 format_type() 会话感知返回 MySQL 名 PASS

Diesel 全量矩阵:85 例 = 85 PASS / 0 FAIL。

likedislike
ywzq1161327784ywzq1161327784成员
2 天前 issue类型由 任务 改变为 缺陷
ywzq1161327784ywzq1161327784成员
2 天前 issue状态由 待办的 改变为 已完成
ywzq1161327784ywzq1161327784成员
2 天前 issue状态由 已完成 改变为 待回归