feat: Support incompatible type conversions via DROP/ADD approach#231
Open
bheemreddy181 wants to merge 1 commit intostripe:mainfrom
Open
feat: Support incompatible type conversions via DROP/ADD approach#231bheemreddy181 wants to merge 1 commit intostripe:mainfrom
bheemreddy181 wants to merge 1 commit intostripe:mainfrom
Conversation
Resolves stripe#179 by implementing intelligent type coercion analysis that automatically switches to DROP COLUMN + ADD COLUMN for incompatible type conversions instead of failing with cast errors. Key Changes: - Added comprehensive type coercion analysis system with GetTypeCoercionInfo() - Categorizes type conversions as binary coercible, coercible, or incompatible - Modified column alteration logic to use DROP/ADD for incompatible types - Enhanced hazard reporting to distinguish between conversion approaches - Added appropriate data loss warnings for destructive operations Technical Details: - Binary coercible types (e.g., smallint→integer) use ALTER with minimal locking - Coercible types (e.g., text→integer) use ALTER with table rewrite warnings - Incompatible types (e.g., integer→timestamptz) use DROP/ADD with data loss warnings - Maintains backward compatibility for all existing functionality - Addresses related issue stripe#52 for better hazard reporting on binary coercible types Test Coverage: - Added comprehensive unit tests for type coercion logic - Added integration tests for issue stripe#179 scenarios - All existing tests continue to pass Before: ALTER COLUMN integer to timestamptz would fail with cast error After: Generates DROP COLUMN + ADD COLUMN with appropriate hazard warnings
Author
|
@bplunkett-stripe thoughts ? |
Author
|
@Navbryce can I get a code review when ever you can ? |
Author
|
@Navbryce @bplunkett-stripe can you take a look at this and share some feedback ? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #179 by implementing intelligent type coercion analysis that automatically switches to
DROP COLUMN + ADD COLUMNfor incompatible type conversions instead of failing with cast errors.Description
This PR introduces a comprehensive type coercion analysis system that intelligently handles column type changes by categorizing conversions and choosing the appropriate alteration strategy:
smallint→integer): UseALTER COLUMNwith minimal lockingtext→integer): UseALTER COLUMNwith table rewrite warningsinteger→timestamptz): UseDROP COLUMN + ADD COLUMNwith data loss warningsKey Changes
GetTypeCoercionInfo()function for comprehensive type conversion analysisMotivation
Problem: Previously, attempting to alter incompatible column types (like
integertotimestamptz) would fail with cast errors, requiring manual intervention.Solution: This change automatically detects incompatible conversions and uses the appropriate
DROP/ADDstrategy while providing clear warnings about potential data loss.Related Issues:
ACQUIRES_ACCESS_EXCLUSIVElock migration hazard if switching between binary-coercible types #52 for improved hazard reporting on binary coercible typesTechnical Details
The implementation categorizes type conversions into three levels:
Testing
New Test Coverage
Regression Testing
Before/After
Before:
After: