-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
crosscluster/logical: handle user-defined types in SQL mode #133280
Conversation
84b7479
to
9b8ac45
Compare
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.
Amazing! this fix is much lower impact than what we originally proposed.
@@ -211,16 +210,9 @@ func createLogicalReplicationStreamPlanHook( | |||
|
|||
sourceTypes := make([]*descpb.TypeDescriptor, len(spec.TypeDescriptors)) | |||
for i, desc := range spec.TypeDescriptors { | |||
// Until https://github.com/cockroachdb/cockroach/issues/132164 is resolved, | |||
// we cannot allow user-defined types on the SQL ingestion path. |
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.
i think this little block of code should be in the previous commit.
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.
done
@@ -92,6 +92,9 @@ func (q *queryBuilder) AddRow(row cdcevent.Row) error { | |||
} | |||
if err := it.Datum(func(d tree.Datum, col cdcevent.ResultColumn) error { | |||
if dEnum, ok := d.(*tree.DEnum); ok { | |||
// Override the type to Unknown to avoid a mismatched type OID error | |||
// during execution. Note that Unknown is the type used by default |
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.
the diff in this file should be in the previous commit.
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.
done
Previously, using a user-defined type in SQL mode would fail because of a low level check in the execution engine that verifies that the input datum has the same type OID as the destination column. This does not work for LDR, since the input datums come directly from a source table in a different cluster, so user-defined types have different OIDs. This fixes it by setting the datum type to "unknown" before executing the insert query. The "unknown" type is what is normally used when any SQL statement is sent to CRDB without explicit type annotations/hints. When the execution engine sees this type, it will perform an automatic (and cheap) immutable assignment cast to change the datum to the appropriate type. Release note (ops change): Logical replication streams that reference tables with user-defined types can now be created with the `mode = immediate` option.
Since we're using this type resolver for more than just IMPORT, it makes more sense to put it in a more fitting package. Release note: None
9b8ac45
to
579ecef
Compare
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.
tftr!
bors r+
This PR also includes a cleanup refactor:
importer,crosscluster: move type resolver to a different package
Since we're using this type resolver for more than just IMPORT, it makes
more sense to put it in a more fitting package.
crosscluster/logical: handle user-defined types in SQL mode
Previously, using a user-defined type in SQL mode would fail because of
a low level check in the execution engine that verifies that the input
datum has the same type OID as the destination column.
This does not work for LDR, since the input datums come directly from a
source table in a different cluster, so user-defined types have
different OIDs.
This fixes it by setting the datum type to "unknown" before executing
the insert query. The "unknown" type is what is normally used when any
SQL statement is sent to CRDB without explicit type annotations/hints.
When the execution engine sees this type, it will perform an automatic
(and cheap) immutable assignment cast to change the datum to the
appropriate type.
fixes #132164
Release note (ops change): Logical replication streams that reference
tables with user-defined types can now be created with the
mode = immediate
option.