diff --git a/pkg/ccl/importccl/import_stmt.go b/pkg/ccl/importccl/import_stmt.go index a112b931badd..0dd4096f8e9e 100644 --- a/pkg/ccl/importccl/import_stmt.go +++ b/pkg/ccl/importccl/import_stmt.go @@ -877,8 +877,12 @@ func importPlanHook( "IMPORT to REGIONAL BY ROW table not supported", ) } + // IMPORT TABLE do not support user defined types, and so we nil out the + // type resolver to protect against unexpected behavior on UDT + // resolution. + semaCtxPtr := makeSemaCtxWithoutTypeResolver(p.SemaCtx()) tbl, err := MakeSimpleTableDescriptor( - ctx, p.SemaCtx(), p.ExecCfg().Settings, create, db, sc, defaultCSVTableID, NoFKs, walltime) + ctx, semaCtxPtr, p.ExecCfg().Settings, create, db, sc, defaultCSVTableID, NoFKs, walltime) if err != nil { return err } diff --git a/pkg/ccl/importccl/import_stmt_test.go b/pkg/ccl/importccl/import_stmt_test.go index 5c9e46b26251..9aee63e6a4a9 100644 --- a/pkg/ccl/importccl/import_stmt_test.go +++ b/pkg/ccl/importccl/import_stmt_test.go @@ -1075,6 +1075,30 @@ CREATE INDEX i ON t USING btree (a) WHERE (b > 10); `, err: "cannot import a table with partial indexes", }, + { + name: "user defined type", + typ: "PGDUMP", + data: ` +CREATE TYPE duration AS ENUM ( + 'YESTERDAY', + 'LAST_7_DAYS', + 'LAST_28_DAYS', + 'LAST_90_DAYS', + 'LAST_365_DAYS', + 'LIFE_TIME' +); +CREATE TABLE t (a duration); + `, + err: "IMPORT PGDUMP does not support user defined types", + }, + { + name: "user defined type without create", + typ: "PGDUMP", + data: ` +CREATE TABLE t (a duration); + `, + err: "type \"duration\" does not exist", + }, // Error { diff --git a/pkg/ccl/importccl/import_table_creation.go b/pkg/ccl/importccl/import_table_creation.go index 55bb2459396c..febef288f877 100644 --- a/pkg/ccl/importccl/import_table_creation.go +++ b/pkg/ccl/importccl/import_table_creation.go @@ -122,6 +122,12 @@ func MakeTestingSimpleTableDescriptor( return MakeSimpleTableDescriptor(ctx, semaCtx, st, create, db, sc, tableID, fks, walltime) } +func makeSemaCtxWithoutTypeResolver(semaCtx *tree.SemaContext) *tree.SemaContext { + semaCtxCopy := *semaCtx + semaCtxCopy.TypeResolver = nil + return &semaCtxCopy +} + // MakeSimpleTableDescriptor creates a tabledesc.Mutable from a CreateTable // parse node without the full machinery. Many parts of the syntax are // unsupported (see the implementation and TestMakeSimpleTableDescriptorErrors diff --git a/pkg/ccl/importccl/read_import_mysql.go b/pkg/ccl/importccl/read_import_mysql.go index 67bd812be95d..ce571bfe943b 100644 --- a/pkg/ccl/importccl/read_import_mysql.go +++ b/pkg/ccl/importccl/read_import_mysql.go @@ -508,6 +508,10 @@ func mysqlTableToCockroach( if p != nil { semaCtxPtr = p.SemaCtx() } + + // Bundle imports do not support user defined types, and so we nil out the + // type resolver to protect against unexpected behavior on UDT resolution. + semaCtxPtr = makeSemaCtxWithoutTypeResolver(semaCtxPtr) desc, err := MakeSimpleTableDescriptor( ctx, semaCtxPtr, evalCtx.Settings, stmt, parentDB, schemadesc.GetPublicSchema(), id, fks, time.WallTime, diff --git a/pkg/ccl/importccl/read_import_pgdump.go b/pkg/ccl/importccl/read_import_pgdump.go index 2fafb8a3ed88..2c6c86c987a4 100644 --- a/pkg/ccl/importccl/read_import_pgdump.go +++ b/pkg/ccl/importccl/read_import_pgdump.go @@ -370,7 +370,10 @@ func createPostgresTables( return nil, err } removeDefaultRegclass(create) - desc, err := MakeSimpleTableDescriptor(evalCtx.Ctx(), p.SemaCtx(), p.ExecCfg().Settings, + // Bundle imports do not support user defined types, and so we nil out the + // type resolver to protect against unexpected behavior on UDT resolution. + semaCtxPtr := makeSemaCtxWithoutTypeResolver(p.SemaCtx()) + desc, err := MakeSimpleTableDescriptor(evalCtx.Ctx(), semaCtxPtr, p.ExecCfg().Settings, create, parentDB, schema, getNextPlaceholderDescID(), fks, walltime) if err != nil { return nil, err @@ -858,6 +861,9 @@ func readPostgresStmt( return unsupportedStmtLogger.log(fmt.Sprintf("%s", stmt), false /* isParseError */) } return wrapErrorWithUnsupportedHint(errors.Errorf("unsupported %T statement: %s", stmt, stmt)) + case *tree.CreateType: + return errors.New("IMPORT PGDUMP does not support user defined types; please" + + " remove all CREATE TYPE statements and their usages from the dump file") case error: if !errors.Is(stmt, errCopyDone) { return stmt