-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(contrib/drivers): resolve field duplication issue when same table/column names exist across different MySQL/MariaDB databases #4577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
当不同数据库存在相同表名和相同字段名, 并且该字段存在约束时, 例如字段类型是JSON, 会出现字段叠加. 导致访问数据库时, 出现数组越界.
|
希望能举个具体的例子,方便写个单元测试验证 |
同一个mysql 或者 mariadb 实例中, 先后创建数据库 db_a和db_b, 在db_a和db_b创建同名表 t, db_a.t 有8个字段, db_b.t有10个字段. 最后一个字段的字段名同名. 并且该字段存在约束(比如是一个JSON类型字段), 当使用从db_a.t 或者db_b.t 读取数据的时候可能会触发越界的panic. <大概是这个case, 时间有点久了> 具体原因:
我看现在版本mariadb_table_fields.go 也会有此问题, 也应该按照该方法修正 |
好的,我后续加个单元测试验证后合并 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug where querying table fields in MySQL/MariaDB drivers returns incorrect field indexes when multiple database schemas contain tables with the same name and JSON fields. The issue stems from the LEFT JOIN with CHECK_CONSTRAINTS table lacking a schema filter, causing rows from different schemas to be incorrectly joined and producing duplicate field entries.
Key Changes:
- Added schema filtering (
TABLE_SCHEMA = CONSTRAINT_SCHEMA) to the CHECK_CONSTRAINTS JOIN in both MySQL and MariaDB drivers - Added regression tests for multi-schema scenarios with identical table names
- Included development tooling (Makefile docker target and docker-services.sh script) for easier local testing
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| contrib/drivers/mysql/mysql_table_fields.go | Added TABLE_SCHEMA filter to CHECK_CONSTRAINTS JOIN to prevent cross-schema constraint matching |
| contrib/drivers/mariadb/mariadb_table_fields.go | Added TABLE_SCHEMA filter to CHECK_CONSTRAINTS JOIN to prevent cross-schema constraint matching |
| contrib/drivers/mysql/mysql_z_unit_issue_test.go | Added test verifying field indexes remain valid when identical tables exist in multiple schemas |
| contrib/drivers/mariadb/mariadb_unit_model_test.go | Added comprehensive test with JSON fields demonstrating the bug fix for multi-schema scenarios |
| contrib/drivers/mariadb/mariadb_unit_init_test.go | Initialized db2 variable for multi-schema testing |
| contrib/drivers/mariadb/mariadb.go | Added New method implementation for driver instantiation |
| Makefile | Added docker target for managing test services |
| .github/workflows/scripts/docker-services.sh | Added comprehensive script for managing Docker-based test dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@smzgl LGTM,请解决Copilot的问题后可以合并。 |
当不同数据库存在相同表名和相同字段名, 并且该字段存在约束时, 例如字段类型是JSON, 会出现字段叠加. 导致访问数据库时, 出现数组越界.