diff --git a/pkg/ccl/changefeedccl/changefeed_stmt.go b/pkg/ccl/changefeedccl/changefeed_stmt.go index 78af0847d70a..17d01352a5d3 100644 --- a/pkg/ccl/changefeedccl/changefeed_stmt.go +++ b/pkg/ccl/changefeedccl/changefeed_stmt.go @@ -563,10 +563,11 @@ func getTargetsAndTables( } } } + seen := make(map[jobspb.ChangefeedTargetSpecification]tree.ChangefeedTarget) for i, ct := range rawTargets { desc, ok := targetDescs[ct.TableName] if !ok { - return nil, nil, errors.Newf("could not match %v to a fetched descriptor. fetched were %v", ct.TableName, targetDescs) + return nil, nil, errors.Newf("could not match %v to a fetched descriptor. Fetched were %v", ct.TableName, targetDescs) } td, ok := desc.(catalog.TableDescriptor) if !ok { @@ -586,6 +587,13 @@ func getTargetsAndTables( FamilyName: string(ct.FamilyName), StatementTimeName: tables[td.GetID()].StatementTimeName, } + if dup, isDup := seen[targets[i]]; isDup { + return nil, nil, errors.Errorf( + "CHANGEFEED targets %s and %s are duplicates", + tree.AsString(&dup), tree.AsString(&ct), + ) + } + seen[targets[i]] = ct } return targets, tables, nil } diff --git a/pkg/ccl/changefeedccl/changefeed_test.go b/pkg/ccl/changefeedccl/changefeed_test.go index 6a12bc207b92..3fe1dd8ff373 100644 --- a/pkg/ccl/changefeedccl/changefeed_test.go +++ b/pkg/ccl/changefeedccl/changefeed_test.go @@ -3516,6 +3516,21 @@ func TestChangefeedErrors(t *testing.T) { `EXPERIMENTAL CHANGEFEED FOR vw`, ) + sqlDB.ExpectErr( + t, `CHANGEFEED targets TABLE foo and TABLE foo are duplicates`, + `EXPERIMENTAL CHANGEFEED FOR foo, foo`, + ) + sqlDB.ExpectErr( + t, `CHANGEFEED targets TABLE foo and TABLE defaultdb.foo are duplicates`, + `EXPERIMENTAL CHANGEFEED FOR foo, defaultdb.foo`, + ) + sqlDB.Exec(t, + `CREATE TABLE threefams (a int, b int, c int, family f_a(a), family f_b(b), family f_c(c))`) + sqlDB.ExpectErr( + t, `CHANGEFEED targets TABLE foo FAMILY f_a and TABLE foo FAMILY f_a are duplicates`, + `EXPERIMENTAL CHANGEFEED FOR foo family f_a, foo FAMILY f_b, foo FAMILY f_a`, + ) + // Backup has the same bad error message #28170. sqlDB.ExpectErr( t, `"information_schema.tables" does not exist`,