diff --git a/pkg/sql/row/writer.go b/pkg/sql/row/writer.go index 0b48284faa61..6e90b7bcb440 100644 --- a/pkg/sql/row/writer.go +++ b/pkg/sql/row/writer.go @@ -139,7 +139,13 @@ func prepareInsertOrUpdateBatch( if !ok { continue } - + // Skip any values with a default ID not stored in the primary index, + // which can happen if we are adding new columns. + if skip, err := helper.skipColumnNotInPrimaryIndexValue(family.DefaultColumnID, values[idx]); err != nil { + return nil, err + } else if skip { + continue + } typ := fetchedCols[idx].GetType() marshaled, err := valueside.MarshalLegacy(typ, values[idx]) if err != nil { diff --git a/pkg/sql/rowenc/index_encoding.go b/pkg/sql/rowenc/index_encoding.go index 680490ec2539..70b6a9446570 100644 --- a/pkg/sql/rowenc/index_encoding.go +++ b/pkg/sql/rowenc/index_encoding.go @@ -1074,6 +1074,14 @@ func EncodePrimaryIndex( // The decoders expect that column family 0 is encoded with a TUPLE value tag, so we // don't want to use the untagged value encoding. if len(family.ColumnIDs) == 1 && family.ColumnIDs[0] == family.DefaultColumnID && family.ID != 0 { + // Single column value families which are not stored can be skipped, these + // may exist temporarily while adding a column. + if !storedColumns.Contains(family.DefaultColumnID) { + if cdatum, ok := values[colMap.GetDefault(family.DefaultColumnID)].(tree.CompositeDatum); !ok || + !cdatum.IsComposite() { + return nil + } + } datum := findColumnValue(family.DefaultColumnID, colMap, values) // We want to include this column if its value is non-null or // we were requested to include all of the columns. diff --git a/pkg/sql/schema_changer_test.go b/pkg/sql/schema_changer_test.go index ec67a05ffb15..8264ea988bba 100644 --- a/pkg/sql/schema_changer_test.go +++ b/pkg/sql/schema_changer_test.go @@ -3144,9 +3144,6 @@ CREATE TABLE t.test ( // backfill. This should have the same number of Puts // as there are CPuts above. fmt.Sprintf("Put /Table/%d/3/2/0 -> /BYTES/0x0a030a1302", tableID), - // TODO (rohany): this k/v is spurious and should be removed - // when #45343 is fixed. - fmt.Sprintf("Put /Table/%d/3/2/1/1 -> /BYTES/0x0a020104", tableID), fmt.Sprintf("Put /Table/%d/3/2/2/1 -> /BYTES/0x0a030a3306", tableID), fmt.Sprintf("Put /Table/%d/3/2/4/1 -> /BYTES/0x0a02010c", tableID), @@ -3185,7 +3182,6 @@ CREATE TABLE t.test ( // The temporary indexes are delete-preserving -- they // should see the delete and issue Puts. fmt.Sprintf("Put (delete) /Table/%d/3/2/0", tableID), - fmt.Sprintf("Put (delete) /Table/%d/3/2/1/1", tableID), fmt.Sprintf("Put (delete) /Table/%d/3/2/2/1", tableID), fmt.Sprintf("Put (delete) /Table/%d/3/2/3/1", tableID), fmt.Sprintf("Put (delete) /Table/%d/3/2/4/1", tableID), @@ -3213,7 +3209,6 @@ CREATE TABLE t.test ( // The temporary index for the newly added index sees // a Put in all families. fmt.Sprintf("Put /Table/%d/3/3/0 -> /BYTES/0x0a030a1302", tableID), - fmt.Sprintf("Put /Table/%d/3/3/1/1 -> /BYTES/0x0a020106", tableID), fmt.Sprintf("Put /Table/%d/3/3/2/1 -> /BYTES/0x0a030a3306", tableID), fmt.Sprintf("Put /Table/%d/3/3/4/1 -> /BYTES/0x0a02010c", tableID), // TODO(ssd): double-check that this trace makes @@ -3243,7 +3238,6 @@ CREATE TABLE t.test ( // The temporary index sees a Put in all families even though // only some are changing. This is expected. fmt.Sprintf("Put /Table/%d/3/3/0 -> /BYTES/0x0a030a1302", tableID), - fmt.Sprintf("Put /Table/%d/3/3/1/1 -> /BYTES/0x0a020106", tableID), fmt.Sprintf("Put /Table/%d/3/3/3/1 -> /BYTES/0x0a02010a", tableID), } require.Equal(t, expected, scanToArray(rows))