Skip to content

Comments

Fix duplicate columns in initialize-table-information#140

Merged
tamurashingo merged 1 commit intodevelopfrom
fix/duplicate-columns-in-initialize-table-information
Jan 28, 2026
Merged

Fix duplicate columns in initialize-table-information#140
tamurashingo merged 1 commit intodevelopfrom
fix/duplicate-columns-in-initialize-table-information

Conversation

@tamurashingo
Copy link
Owner

Summary

Fixed the issue where initialize-table-information function retrieves duplicate column information when fetching table metadata.

Problem

When querying information_schema.columns with only table_name condition, it searches for tables with the same name across all databases (development, te
st, etc.) on the same MySQL instance, resulting in duplicate column information.

Observed Symptoms

  • 27 rows of column information returned for a table with 11 columns
  • Each column appears twice (retrieved from both dev and test databases)
  • Unrelated columns from performance_schema are also included

Changes

MySQL (src/model/impl/mysql.lisp)

Added table_schema = database() condition to SQL queries in fetch-columns-and-types-impl and fetch-columns-and-types-plist-impl methods.

Before:

select column_name, data_type from information_schema.columns
where table_name = ?
order by ordinal_position

After:

select column_name, data_type from information_schema.columns
where table_schema = database() and table_name = ?
order by ordinal_position

PostgreSQL (src/model/impl/postgresql.lisp)

Added table_schema = current_schema() condition to SQL queries in fetch-columns-and-types-impl and fetch-columns-and-types-plist-impl methods.

Before:

select COLUMN_NAME, DATA_TYPE from information_schema.columns
where table_name = ?
order by ordinal_position

After:

select COLUMN_NAME, DATA_TYPE from information_schema.columns
where table_schema = current_schema() and table_name = ?
order by ordinal_position

Impact Scope

  • Model initialization process for all MySQL-based models
  • Model initialization process for all PostgreSQL-based models

Testing

  • Confirmed existing tests pass
  • Verified column information is not duplicated in environments with multiple databases

Related Issue

fix #139

Add table_schema condition to information_schema.columns queries to prevent
fetching duplicate columns from multiple databases/schemas.

- MySQL: Add 'table_schema = database()' condition
- PostgreSQL: Add 'table_schema = current_schema()' condition

This ensures only columns from the currently connected database/schema are retrieved.

Fixes issue where columns were duplicated when multiple databases (e.g., dev and test)
exist on the same database instance.
@tamurashingo tamurashingo merged commit 8ceed37 into develop Jan 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue: Duplicate Columns Retrieved by initialize-table-information

1 participant