github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/catalog/catalog.go (about)

     1  // Copyright 2018 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 catalog
    12  
    13  import (
    14  	"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
    15  	"github.com/cockroachdb/cockroach/pkg/sql/sqlbase"
    16  )
    17  
    18  // Descriptor provides table information for results from a name lookup.
    19  type Descriptor interface {
    20  	tree.NameResolutionResult
    21  
    22  	// DatabaseDesc returns the underlying database descriptor, or nil if the
    23  	// descriptor is not a table backed object.
    24  	DatabaseDesc() *sqlbase.DatabaseDescriptor
    25  
    26  	// SchemaDesc returns the underlying schema descriptor, or nil if the
    27  	// descriptor is not a table backed object.
    28  	SchemaDesc() *sqlbase.SchemaDescriptor
    29  
    30  	// TableDesc returns the underlying table descriptor, or nil if the
    31  	// descriptor is not a table backed object.
    32  	TableDesc() *sqlbase.TableDescriptor
    33  
    34  	// TypeDesc returns the underlying type descriptor, or nil if the
    35  	// descriptor is not a type backed object.
    36  	TypeDesc() *sqlbase.TypeDescriptor
    37  }
    38  
    39  // VirtualSchemas is a collection of VirtualSchemas.
    40  type VirtualSchemas interface {
    41  	GetVirtualSchema(schemaName string) (VirtualSchema, bool)
    42  }
    43  
    44  // VirtualSchema represents a collection of VirtualObjects.
    45  type VirtualSchema interface {
    46  	Desc() Descriptor
    47  	NumTables() int
    48  	VisitTables(func(object VirtualObject))
    49  	GetObjectByName(name string, flags tree.ObjectLookupFlags) (VirtualObject, error)
    50  }
    51  
    52  // VirtualObject is a virtual schema object.
    53  type VirtualObject interface {
    54  	Desc() Descriptor
    55  }
    56  
    57  // TableEntry is the value type of FkTableMetadata: An optional table
    58  // descriptor, populated when the table is public/leasable, and an IsAdding
    59  // flag.
    60  //
    61  // This also includes an optional CheckHelper for the table (for CHECK
    62  // constraints). This is needed for FK work because CASCADE actions
    63  // can modify rows, and CHECK constraints must be applied to rows
    64  // modified by CASCADE.
    65  type TableEntry struct {
    66  	// Desc is the descriptor of the table. This can be nil if eg.
    67  	// the table is not public.
    68  	Desc *sqlbase.ImmutableTableDescriptor
    69  
    70  	// IsAdding indicates the descriptor is being created.
    71  	IsAdding bool
    72  
    73  	// CheckHelper is the utility responsible for CHECK constraint
    74  	// checks. The lookup function (see TableLookupFunction below) needs
    75  	// not populate this field; this is populated by the lookup queue
    76  	// below.
    77  	CheckHelper *sqlbase.CheckHelper
    78  }