Skip to content

4 Byte PK support#4010

Draft
sm745052 wants to merge 7 commits into
mainfrom
4b_support
Draft

4 Byte PK support#4010
sm745052 wants to merge 7 commits into
mainfrom
4b_support

Conversation

@sm745052

Copy link
Copy Markdown
Contributor

No description provided.

@sm745052 sm745052 requested a review from a team as a code owner July 10, 2026 05:55
@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 introduces support for 4-byte character sets (such as emojis) in primary keys during source database to Spanner migrations. The changes involve refining the collation order logic for both MySQL and PostgreSQL to ensure these characters are correctly processed and validated, alongside new integration tests to validate the end-to-end migration flow.

Highlights

  • 4-Byte Character Support: Updated SQL collation queries for MySQL and PostgreSQL to correctly handle 4-byte UTF-8 characters (like emojis) in primary keys.
  • Integration Testing: Added new integration tests for both MySQL and PostgreSQL to verify the migration of tables containing 4-byte string primary keys.
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.

@sm745052 sm745052 marked this pull request as draft July 10, 2026 05:55

@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 collation order queries for MySQL and PostgreSQL to support 4-byte UTF-8 characters and adds corresponding integration tests. Feedback highlights a significant performance concern in the MySQL query due to the massive increase in rows (to over 1.1 million) processed during 4-byte codepoint generation, which could cause high CPU/IO load and disk sorting. Additionally, the new integration tests should be refactored to use instance fields instead of static fields for resource managers and to declare the Dataflow job info as a local variable.

'WHERE t1.h BETWEEN ''00'' AND ''7f'''
);

SET @all_utf8_hex = CONCAT(@four_byte_codepoints, ' UNION ALL ', @three_byte_codepoints, ' UNION ALL ', @two_byte_codepoints, ' UNION ALL ', @one_byte_codepoints);

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.

high

Performance Concern: Scale of 4-Byte Codepoints

Including 4-byte codepoints increases the number of rows processed by this query from ~65,000 (for 1, 2, and 3-byte characters) to over 1.1 million (a ~17x increase).

Since the query performs 6 FIRST_VALUE and 2 DENSE_RANK window functions, MySQL will have to perform multiple large-scale sorts. With 1.1 million rows, this is highly likely to exceed the default MySQL sort_buffer_size (typically 256KB) and tmp_table_size, forcing MySQL to write large temporary files to disk.

This can cause:

  1. Significant CPU and I/O load on the source database during pipeline initialization.
  2. Query execution time to increase from < 60 seconds to several minutes, potentially causing timeouts.

Recommendations:

  • Benchmark this query on a standard MySQL instance with default configuration to measure the performance impact.
  • Consider if we can optimize the 4-byte range or if we can increase the session-level sort_buffer_size and join_buffer_size before running this query (e.g., SET SESSION sort_buffer_size = ...).

Comment on lines +30 to +33
import org.apache.beam.it.gcp.spanner.SpannerResourceManager;
import org.apache.beam.it.gcp.spanner.matchers.SpannerAsserts;
import org.apache.beam.it.jdbc.JDBCResourceManager;
import org.apache.beam.it.jdbc.MySQLResourceManager;

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.

medium

The jobInfo field is only used within the testMySqlToSpanner method and does not need to be a class field. Additionally, the resource managers do not need to be static since they are initialized in the non-static @Before method. Making them instance fields prevents potential issues if tests are run in parallel or if multiple test methods are added in the future.

Suggested change
import org.apache.beam.it.gcp.spanner.SpannerResourceManager;
import org.apache.beam.it.gcp.spanner.matchers.SpannerAsserts;
import org.apache.beam.it.jdbc.JDBCResourceManager;
import org.apache.beam.it.jdbc.MySQLResourceManager;
private MySQLResourceManager mySQLResourceManager;
private SpannerResourceManager spannerResourceManager;

Comment on lines +87 to +88
spannerResourceManager = setUpSpannerResourceManager();
}

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.

medium

Declare jobInfo as a local variable since it is only used within this test method.

Suggested change
spannerResourceManager = setUpSpannerResourceManager();
}
PipelineLauncher.LaunchInfo jobInfo =
launchDataflowJob(

Comment on lines +30 to +33
import org.apache.beam.it.gcp.spanner.SpannerResourceManager;
import org.apache.beam.it.gcp.spanner.matchers.SpannerAsserts;
import org.apache.beam.it.jdbc.JDBCResourceManager;
import org.apache.beam.it.jdbc.PostgresResourceManager;

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.

medium

The jobInfo field is only used within the testPostgreSQLToSpanner method and does not need to be a class field. Additionally, the resource managers do not need to be static since they are initialized in the non-static @Before method. Making them instance fields prevents potential issues if tests are run in parallel or if multiple test methods are added in the future.

Suggested change
import org.apache.beam.it.gcp.spanner.SpannerResourceManager;
import org.apache.beam.it.gcp.spanner.matchers.SpannerAsserts;
import org.apache.beam.it.jdbc.JDBCResourceManager;
import org.apache.beam.it.jdbc.PostgresResourceManager;
private PostgresResourceManager postgreSQLResourceManager;
private SpannerResourceManager spannerResourceManager;

Comment on lines +87 to +88
spannerResourceManager = setUpSpannerResourceManager();
}

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.

medium

Declare jobInfo as a local variable since it is only used within this test method.

Suggested change
spannerResourceManager = setUpSpannerResourceManager();
}
PipelineLauncher.LaunchInfo jobInfo =
launchDataflowJob(

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.48%. Comparing base (3f0e4bb) to head (0fcc113).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4010      +/-   ##
============================================
+ Coverage     55.69%   63.48%   +7.78%     
+ Complexity     6772     2498    -4274     
============================================
  Files          1125      536     -589     
  Lines         68437    30710   -37727     
  Branches       7719     3418    -4301     
============================================
- Hits          38118    19497   -18621     
+ Misses        27843    10200   -17643     
+ Partials       2476     1013    -1463     
Components Coverage Δ
spanner-templates 88.08% <ø> (+0.40%) ⬆️
spanner-import-export ∅ <ø> (∅)
spanner-live-forward-migration 89.19% <ø> (-0.10%) ⬇️
spanner-live-reverse-replication 83.39% <ø> (-0.08%) ⬇️
spanner-bulk-migration 92.44% <ø> (-0.06%) ⬇️
gcs-spanner-dv 89.96% <ø> (+1.41%) ⬆️
see 613 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.

@sm745052 sm745052 force-pushed the 4b_support branch 8 times, most recently from 88454e5 to 5c85c66 Compare July 10, 2026 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant