Skip to content

Postgres prevent index name collisions across schemas during non-publ… - #4412

Open
SaurabhSingh2115 wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
SaurabhSingh2115:pg-non-public-index-fix
Open

SaurabhSingh2115 wants to merge 2 commits into
GoogleCloudPlatform:mainfrom
SaurabhSingh2115:pg-non-public-index-fix

Conversation

@SaurabhSingh2115

@SaurabhSingh2115 SaurabhSingh2115 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

When migrating only the 'public' schema while ignoring tables in other schemas (such as
sales or archive), PostgreSQL default primary key indices (e.g., orders_pkey) share identical
names across schemas.

Previously, PostgreSQLDialectAdapter queried table indices by index name alone without verifying
its schema namespace. Consequently, when a public table shared its name and index name with a
non-public table, Dataflow erroneously pulled primary key columns from the non-public schema table,
resulting in pipeline failures (e.g., column "order_no" does not exist).

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a bug in the PostgreSQL dialect adapter where index discovery could incorrectly match indexes from non-target schemas due to name collisions. By enforcing a namespace check during the join process, the system now correctly identifies indexes associated with the intended schema, preventing data inconsistencies during migration.

Highlights

  • Index Discovery Logic: Updated the PostgreSQL index discovery query to include a join on pg_namespace, ensuring that index lookups are scoped to the correct schema.
  • Collision Prevention: Prevented index name collisions across different schemas by validating the index namespace against the schema namespace.
  • Regression Testing: Added a new unit test case to verify that the generated SQL query correctly incorporates the schema-aware join logic.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the PostgreSQL dialect adapter to join pg_catalog.pg_class with pg_catalog.pg_namespace when discovering table indexes. This ensures that index names are correctly matched within their respective schemas, preventing collisions when identical index names exist across different schemas. A corresponding unit test has been added to verify this SQL query structure. There are no review comments, and we have no feedback to provide.

@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.85%. Comparing base (bf02f9c) to head (7fe8fdb).
⚠️ Report is 27 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4412      +/-   ##
============================================
+ Coverage     57.00%   63.85%   +6.85%     
+ Complexity     8029     3079    -4950     
============================================
  Files          1156      577     -579     
  Lines         73694    34066   -39628     
  Branches       8691     3885    -4806     
============================================
- Hits          42007    21752   -20255     
+ Misses        28891    11215   -17676     
+ Partials       2796     1099    -1697     
Components Coverage Δ
spanner-templates 84.56% <ø> (+0.04%) ⬆️
spanner-import-export ∅ <ø> (∅)
spanner-live-forward-migration 88.99% <ø> (+<0.01%) ⬆️
spanner-live-reverse-replication 80.91% <ø> (-0.04%) ⬇️
spanner-bulk-migration 89.00% <ø> (+0.02%) ⬆️
gcs-spanner-dv 88.04% <ø> (-0.06%) ⬇️
Files with missing lines Coverage Δ
...ctadapter/postgresql/PostgreSQLDialectAdapter.java 89.67% <ø> (ø)

... and 610 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bharadwaj-aditya bharadwaj-aditya left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if it is feasible to add an integration test here. (preferably add to an existing integration test)

adapter.discoverTableIndexes(mockDataSource, sourceSchemaReference, ImmutableList.of("orders"));

// Index names are unique only within a schema, e.g. public.orders_pkey and tenant.orders_pkey.
verify(mockConnection)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UT is fine, but it would be good to have an integration test for this to ensure this works on PG ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants