diff --git a/pkg/sql/conn_executor_prepare.go b/pkg/sql/conn_executor_prepare.go index 53491d0cb6d9..5afc1ae38659 100644 --- a/pkg/sql/conn_executor_prepare.go +++ b/pkg/sql/conn_executor_prepare.go @@ -203,6 +203,7 @@ func (ex *connExecutor) prepare( prepared.PrepareMetadata = querycache.PrepareMetadata{ PlaceholderTypesInfo: tree.PlaceholderTypesInfo{ TypeHints: placeholderHints, + Types: placeholderHints, }, } prepared.Statement = stmt.Statement @@ -225,13 +226,13 @@ func (ex *connExecutor) prepare( if txn := ex.state.mu.txn; txn != nil && txn.IsOpen() { // Use the existing transaction. - if err := prepare(ctx, txn); err != nil { + if err := prepare(ctx, txn); err != nil && origin != PreparedStatementOriginSessionMigration { return nil, err } } else { // Use a new transaction. This will handle retriable errors here rather // than bubbling them up to the connExecutor state machine. - if err := ex.server.cfg.DB.Txn(ctx, prepare); err != nil { + if err := ex.server.cfg.DB.Txn(ctx, prepare); err != nil && origin != PreparedStatementOriginSessionMigration { return nil, err } // Prepare with an implicit transaction will end up creating diff --git a/pkg/sql/testdata/session_migration/prepared_statements b/pkg/sql/testdata/session_migration/prepared_statements index c2f87e699a92..1163f9b3acef 100644 --- a/pkg/sql/testdata/session_migration/prepared_statements +++ b/pkg/sql/testdata/session_migration/prepared_statements @@ -17,6 +17,34 @@ wire_prepare s2 INSERT INTO t VALUES($1, $2, $3) ---- +exec +ALTER TABLE t RENAME TO t2 +---- + +wire_prepare s3 +INSERT INTO t2 VALUES($1, $2, $3) +---- + +exec +ALTER TABLE t2 DROP COLUMN c +---- + +wire_prepare s4 +INSERT INTO t2 VALUES($1, $2) +---- + +wire_exec s2 1 cat 2022-02-10 +---- +ERROR: relation "t" does not exist (SQLSTATE 42P01) + +wire_exec s3 1 cat 2022-02-10 +---- +ERROR: INSERT has more expressions than target columns, 3 expressions for 2 targets (SQLSTATE 42601) + +query +SELECT * FROM t2 +---- + let $x SELECT encode(crdb_internal.serialize_session(), 'hex') ---- @@ -46,13 +74,23 @@ EXECUTE s1 ---- 1 +# The s2 and s3 statements should experience the same errors that they did +# before the session migration. wire_exec s2 1 cat 2022-02-10 ---- +ERROR: relation "t" does not exist (SQLSTATE 42P01) + +wire_exec s3 1 cat 2022-02-10 +---- +ERROR: INSERT has more expressions than target columns, 3 expressions for 2 targets (SQLSTATE 42601) + +wire_exec s4 1 cat +---- query -SELECT * FROM t +SELECT * FROM t2 ---- -1 cat 2022-02-10 00:00:00 +0000 UTC +1 cat reset ----