Skip to content

Commit

Permalink
sql: turn some catalog.TableDescriptor methods into functions
Browse files Browse the repository at this point in the history
The catalog.TableDescriptor has ForEach*Index and Find*Index methods
which can just as well be expressed as functions, thereby lightening
that interface definition somewhat.

This patch also adds iterutils.StopIteration() support for the above
ForEach*Index functions, and otherwise also adds comments to many
catalog.Index methods.

Release note: None
  • Loading branch information
Marius Posta committed Jan 7, 2021
1 parent 02a8b3d commit e6448f4
Show file tree
Hide file tree
Showing 20 changed files with 346 additions and 221 deletions.
2 changes: 1 addition & 1 deletion pkg/ccl/backupccl/backup_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func getLogicallyMergedTableSpans(
checkForKVInBounds func(start, end roachpb.Key, endTime hlc.Timestamp) (bool, error),
) ([]roachpb.Span, error) {
var nonDropIndexIDs []descpb.IndexID
if err := table.ForEachNonDropIndex(func(idx catalog.Index) error {
if err := catalog.ForEachNonDropIndex(table, func(idx catalog.Index) error {
key := tableAndIndex{tableID: table.GetID(), indexID: idx.GetID()}
if added[key] {
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/backupccl/restore_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ func RewriteTableDescs(
return err
}

if err := table.ForEachNonDropIndex(func(indexI catalog.Index) error {
if err := catalog.ForEachNonDropIndex(table, func(indexI catalog.Index) error {
index := indexI.IndexDesc()
// Verify that for any interleaved index being restored, the interleave
// parent is also being restored. Otherwise, the interleave entries in the
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/backupccl/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ func ensureInterleavesIncluded(tables []catalog.TableDescriptor) error {
}

for _, table := range tables {
if err := table.ForEachIndex(catalog.IndexOpts{
if err := catalog.ForEachIndex(table, catalog.IndexOpts{
AddMutations: true,
}, func(index catalog.Index) error {
for i := 0; i < index.NumInterleaveAncestors(); i++ {
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/importccl/import_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func makeInputConverter(
}

if singleTable != nil {
if idx := singleTable.FindDeletableNonPrimaryIndex(func(idx catalog.Index) bool {
if idx := catalog.FindDeletableNonPrimaryIndex(singleTable, func(idx catalog.Index) bool {
return idx.IsPartial()
}); idx != nil {
return nil, unimplemented.NewWithIssue(50225, "cannot import into table with partial indexes")
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/partitionccl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func selectPartitionExprs(

a := &rowenc.DatumAlloc{}
var prefixDatums []tree.Datum
if err := tableDesc.ForEachIndex(catalog.IndexOpts{
if err := catalog.ForEachIndex(tableDesc, catalog.IndexOpts{
AddMutations: true,
}, func(idx catalog.Index) error {
return selectPartitionExprsByName(
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ func (n *alterTableNode) startExec(params runParams) error {
// new name exists. This is what postgres does.
switch details.Kind {
case descpb.ConstraintTypeUnique, descpb.ConstraintTypePK:
if n.tableDesc.FindNonDropIndex(func(idx catalog.Index) bool {
if catalog.FindNonDropIndex(n.tableDesc, func(idx catalog.Index) bool {
return idx.GetName() == string(t.NewName)
}) != nil {
return pgerror.Newf(pgcode.DuplicateRelation,
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/catalog/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ go_library(
"//pkg/sql/types",
"//pkg/util",
"//pkg/util/hlc",
"//pkg/util/iterutil",
"@com_github_cockroachdb_errors//:errors",
"@com_github_cockroachdb_redact//:redact",
],
Expand Down
Loading

0 comments on commit e6448f4

Please sign in to comment.