github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/views.go (about) 1 // Copyright 2015 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package sql 12 13 import ( 14 "bytes" 15 "fmt" 16 17 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 18 "github.com/cockroachdb/cockroach/pkg/sql/sqlbase" 19 ) 20 21 // planDependencyInfo collects the dependencies related to a single 22 // table -- which index and columns are being depended upon. 23 type planDependencyInfo struct { 24 // desc is a reference to the descriptor for the table being 25 // depended on. 26 desc *sqlbase.ImmutableTableDescriptor 27 // deps is the list of ways in which the current plan depends on 28 // that table. There can be more than one entries when the same 29 // table is used in different places. The entries can also be 30 // different because some may reference an index and others may 31 // reference only a subset of the table's columns. 32 // Note: the "ID" field of TableDescriptor_Reference is not 33 // (and cannot be) filled during plan construction / dependency 34 // analysis because the descriptor that is using this dependency 35 // has not been constructed yet. 36 deps []sqlbase.TableDescriptor_Reference 37 } 38 39 // planDependencies maps the ID of a table depended upon to a list of 40 // detailed dependencies on that table. 41 type planDependencies map[sqlbase.ID]planDependencyInfo 42 43 // String implements the fmt.Stringer interface. 44 func (d planDependencies) String() string { 45 var buf bytes.Buffer 46 for id, deps := range d { 47 fmt.Fprintf(&buf, "%d (%q):", id, tree.ErrNameStringP(&deps.desc.Name)) 48 for _, dep := range deps.deps { 49 buf.WriteString(" [") 50 if dep.IndexID != 0 { 51 fmt.Fprintf(&buf, "idx: %d ", dep.IndexID) 52 } 53 fmt.Fprintf(&buf, "cols: %v]", dep.ColumnIDs) 54 } 55 buf.WriteByte('\n') 56 } 57 return buf.String() 58 }