Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: make pg_catalog OIDs stable and refer to the descriptor IDs directly #33420

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions pkg/keys/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,6 @@ const (
// clusters (default databases).
MinNonPredefinedUserDescID = MinUserDescID + 2

// VirtualDescriptorID is the ID used by all virtual descriptors.
VirtualDescriptorID = math.MaxUint32

// RootNamespaceID is the ID of the root namespace.
RootNamespaceID = 0

Expand Down
78 changes: 36 additions & 42 deletions pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,40 +52,40 @@ const crdbInternalName = "crdb_internal"

var crdbInternal = virtualSchema{
name: crdbInternalName,
tableDefs: []virtualSchemaDef{
crdbInternalBackwardDependenciesTable,
crdbInternalBuildInfoTable,
crdbInternalBuiltinFunctionsTable,
crdbInternalClusterQueriesTable,
crdbInternalClusterSessionsTable,
crdbInternalClusterSettingsTable,
crdbInternalCreateStmtsTable,
crdbInternalFeatureUsage,
crdbInternalForwardDependenciesTable,
crdbInternalGossipNodesTable,
crdbInternalGossipAlertsTable,
crdbInternalGossipLivenessTable,
crdbInternalGossipNetworkTable,
crdbInternalIndexColumnsTable,
crdbInternalJobsTable,
crdbInternalKVNodeStatusTable,
crdbInternalKVStoreStatusTable,
crdbInternalLeasesTable,
crdbInternalLocalQueriesTable,
crdbInternalLocalSessionsTable,
crdbInternalLocalMetricsTable,
crdbInternalPartitionsTable,
crdbInternalRangesNoLeasesTable,
crdbInternalRangesView,
crdbInternalRuntimeInfoTable,
crdbInternalSchemaChangesTable,
crdbInternalSessionTraceTable,
crdbInternalSessionVariablesTable,
crdbInternalStmtStatsTable,
crdbInternalTableColumnsTable,
crdbInternalTableIndexesTable,
crdbInternalTablesTable,
crdbInternalZonesTable,
tableDefs: map[sqlbase.ID]virtualSchemaDef{
sqlbase.CrdbInternalBackwardDependenciesTableID: crdbInternalBackwardDependenciesTable,
sqlbase.CrdbInternalBuildInfoTableID: crdbInternalBuildInfoTable,
sqlbase.CrdbInternalBuiltinFunctionsTableID: crdbInternalBuiltinFunctionsTable,
sqlbase.CrdbInternalClusterQueriesTableID: crdbInternalClusterQueriesTable,
sqlbase.CrdbInternalClusterSessionsTableID: crdbInternalClusterSessionsTable,
sqlbase.CrdbInternalClusterSettingsTableID: crdbInternalClusterSettingsTable,
sqlbase.CrdbInternalCreateStmtsTableID: crdbInternalCreateStmtsTable,
sqlbase.CrdbInternalFeatureUsageID: crdbInternalFeatureUsage,
sqlbase.CrdbInternalForwardDependenciesTableID: crdbInternalForwardDependenciesTable,
sqlbase.CrdbInternalGossipNodesTableID: crdbInternalGossipNodesTable,
sqlbase.CrdbInternalGossipAlertsTableID: crdbInternalGossipAlertsTable,
sqlbase.CrdbInternalGossipLivenessTableID: crdbInternalGossipLivenessTable,
sqlbase.CrdbInternalGossipNetworkTableID: crdbInternalGossipNetworkTable,
sqlbase.CrdbInternalIndexColumnsTableID: crdbInternalIndexColumnsTable,
sqlbase.CrdbInternalJobsTableID: crdbInternalJobsTable,
sqlbase.CrdbInternalKVNodeStatusTableID: crdbInternalKVNodeStatusTable,
sqlbase.CrdbInternalKVStoreStatusTableID: crdbInternalKVStoreStatusTable,
sqlbase.CrdbInternalLeasesTableID: crdbInternalLeasesTable,
sqlbase.CrdbInternalLocalQueriesTableID: crdbInternalLocalQueriesTable,
sqlbase.CrdbInternalLocalSessionsTableID: crdbInternalLocalSessionsTable,
sqlbase.CrdbInternalLocalMetricsTableID: crdbInternalLocalMetricsTable,
sqlbase.CrdbInternalPartitionsTableID: crdbInternalPartitionsTable,
sqlbase.CrdbInternalRangesNoLeasesTableID: crdbInternalRangesNoLeasesTable,
sqlbase.CrdbInternalRangesViewID: crdbInternalRangesView,
sqlbase.CrdbInternalRuntimeInfoTableID: crdbInternalRuntimeInfoTable,
sqlbase.CrdbInternalSchemaChangesTableID: crdbInternalSchemaChangesTable,
sqlbase.CrdbInternalSessionTraceTableID: crdbInternalSessionTraceTable,
sqlbase.CrdbInternalSessionVariablesTableID: crdbInternalSessionVariablesTable,
sqlbase.CrdbInternalStmtStatsTableID: crdbInternalStmtStatsTable,
sqlbase.CrdbInternalTableColumnsTableID: crdbInternalTableColumnsTable,
sqlbase.CrdbInternalTableIndexesTableID: crdbInternalTableIndexesTable,
sqlbase.CrdbInternalTablesTableID: crdbInternalTablesTable,
sqlbase.CrdbInternalZonesTableID: crdbInternalZonesTable,
},
validWithNoDatabaseContext: true,
}
Expand Down Expand Up @@ -1109,14 +1109,8 @@ CREATE TABLE crdb_internal.create_statements (
return err
}

descID := tree.DNull
if table.ID != keys.VirtualDescriptorID {
descID = tree.NewDInt(tree.DInt(table.ID))
}
dbDescID := tree.DNull
if table.GetParentID() != keys.VirtualDescriptorID {
dbDescID = tree.NewDInt(tree.DInt(table.GetParentID()))
}
descID := tree.NewDInt(tree.DInt(table.ID))
dbDescID := tree.NewDInt(tree.DInt(table.GetParentID()))
if createNofk == "" {
createNofk = stmt
}
Expand Down
44 changes: 22 additions & 22 deletions pkg/sql/information_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,27 @@ var informationSchema = virtualSchema{
"view_table_usage",
"views",
),
tableDefs: []virtualSchemaDef{
informationSchemaAdministrableRoleAuthorizations,
informationSchemaApplicableRoles,
informationSchemaColumnPrivileges,
informationSchemaColumnsTable,
informationSchemaConstraintColumnUsageTable,
informationSchemaEnabledRoles,
informationSchemaKeyColumnUsageTable,
informationSchemaParametersTable,
informationSchemaReferentialConstraintsTable,
informationSchemaRoleTableGrants,
informationSchemaRoutineTable,
informationSchemaSchemataTable,
informationSchemaSchemataTablePrivileges,
informationSchemaSequences,
informationSchemaStatisticsTable,
informationSchemaTableConstraintTable,
informationSchemaTablePrivileges,
informationSchemaTablesTable,
informationSchemaViewsTable,
informationSchemaUserPrivileges,
tableDefs: map[sqlbase.ID]virtualSchemaDef{
sqlbase.InformationSchemaAdministrableRoleAuthorizationsID: informationSchemaAdministrableRoleAuthorizations,
sqlbase.InformationSchemaApplicableRolesID: informationSchemaApplicableRoles,
sqlbase.InformationSchemaColumnPrivilegesID: informationSchemaColumnPrivileges,
sqlbase.InformationSchemaColumnsTableID: informationSchemaColumnsTable,
sqlbase.InformationSchemaConstraintColumnUsageTableID: informationSchemaConstraintColumnUsageTable,
sqlbase.InformationSchemaEnabledRolesID: informationSchemaEnabledRoles,
sqlbase.InformationSchemaKeyColumnUsageTableID: informationSchemaKeyColumnUsageTable,
sqlbase.InformationSchemaParametersTableID: informationSchemaParametersTable,
sqlbase.InformationSchemaReferentialConstraintsTableID: informationSchemaReferentialConstraintsTable,
sqlbase.InformationSchemaRoleTableGrantsID: informationSchemaRoleTableGrants,
sqlbase.InformationSchemaRoutineTableID: informationSchemaRoutineTable,
sqlbase.InformationSchemaSchemataTableID: informationSchemaSchemataTable,
sqlbase.InformationSchemaSchemataTablePrivilegesID: informationSchemaSchemataTablePrivileges,
sqlbase.InformationSchemaSequencesID: informationSchemaSequences,
sqlbase.InformationSchemaStatisticsTableID: informationSchemaStatisticsTable,
sqlbase.InformationSchemaTableConstraintTableID: informationSchemaTableConstraintTable,
sqlbase.InformationSchemaTablePrivilegesID: informationSchemaTablePrivileges,
sqlbase.InformationSchemaTablesTableID: informationSchemaTablesTable,
sqlbase.InformationSchemaViewsTableID: informationSchemaViewsTable,
sqlbase.InformationSchemaUserPrivilegesID: informationSchemaUserPrivileges,
},
tableValidator: validateInformationSchemaTable,
validWithNoDatabaseContext: true,
Expand Down Expand Up @@ -1115,7 +1115,7 @@ var informationSchemaTablesTable = virtualSchemaTable{
}
tableType := tableTypeBaseTable
insertable := yesString
if isVirtualDescriptor(table) {
if table.IsVirtualTable() {
tableType = tableTypeSystemView
insertable = noString
} else if table.IsView() {
Expand Down
Loading