Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
73 changes: 26 additions & 47 deletions go/libraries/doltcore/doltdb/system_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,50 +137,6 @@ func GetNonSystemTableNames(ctx context.Context, root RootValue) ([]string, erro
return tn, nil
}

// GetSystemTableNames gets system table names
func GetSystemTableNames(ctx context.Context, root RootValue) ([]string, error) {
p, err := GetPersistedSystemTables(ctx, root)
if err != nil {
return nil, err
}

g, err := GetGeneratedSystemTables(ctx, root)
if err != nil {

}

s := append(p, g...)
sort.Strings(s)

return s, nil
}

// GetPersistedSystemTables returns table names of all persisted system tables.
func GetPersistedSystemTables(ctx context.Context, root RootValue) ([]string, error) {
tn, err := root.GetTableNames(ctx, DefaultSchemaName)
if err != nil {
return nil, err
}
sort.Strings(tn)
return funcitr.FilterStrings(tn, HasDoltPrefix), nil
}

// GetGeneratedSystemTables returns table names of all generated system tables.
func GetGeneratedSystemTables(ctx context.Context, root RootValue) ([]string, error) {
s := set.NewStrSet(getGeneratedSystemTables())

tn, err := root.GetTableNames(ctx, DefaultSchemaName)
if err != nil {
return nil, err
}

for _, pre := range generatedSystemTablePrefixes {
s.Add(funcitr.MapStrings(tn, func(s string) string { return pre + s })...)
}

return s.AsSlice(), nil
}

// The set of reserved dolt_ tables that should be considered part of user space, like any other user-created table,
// for the purposes of the dolt command line. These tables cannot be created or altered explicitly, but can be updated
// like normal SQL tables.
Expand All @@ -206,9 +162,9 @@ var getWriteableSystemTables = func() []string {
}
}

// getGeneratedSystemTables is a function which returns the names of all generated system tables. This is not
// GeneratedSystemTableNames returns the names of all generated system tables. This is not
// simply a list of constants because doltgres swaps out the functions used to generate different names.
var getGeneratedSystemTables = func() []string {
func GeneratedSystemTableNames() []string {
return []string{
GetBranchesTableName(),
GetRemoteBranchesTableName(),
Expand All @@ -224,7 +180,9 @@ var getGeneratedSystemTables = func() []string {
}
}

var generatedSystemTablePrefixes = []string{
// GeneratedSystemTablePrefixes returns the prefixes of all generated system tables, the ones that exist for every
// user table.
var GeneratedSystemTablePrefixes = []string{
DoltDiffTablePrefix,
DoltCommitDiffTablePrefix,
DoltHistoryTablePrefix,
Expand Down Expand Up @@ -446,6 +404,27 @@ const (
StatisticsTableName = "dolt_statistics"
)

// DoltGeneratedTableNames is a list of all the generated dolt system tables that are not specific to a user table.
// It does not include tables in the dolt_ prefix namespace that are user-populated, such as dolt_ignore or dolt_docs.
// These tables are addressable by these names in both Dolt and Doltgres. In doltgres they are additionally addressable
// in the `dolt.` schema, e.g. `dolt.branches`
var DoltGeneratedTableNames = []string{
LogTableName,
DiffTableName,
ColumnDiffTableName,
TableOfTablesInConflictName,
TableOfTablesWithViolationsName,
SchemaConflictsTableName,
BranchesTableName,
RemoteBranchesTableName,
RemotesTableName,
CommitsTableName,
CommitAncestorsTableName,
StatusTableName,
MergeStatusTableName,
TagsTableName,
}

const (
// WorkflowsTableName is the dolt CI workflows system table name
WorkflowsTableName = "dolt_ci_workflows"
Expand Down
4 changes: 2 additions & 2 deletions go/libraries/doltcore/sqle/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -1171,11 +1171,11 @@ func (db Database) getAllTableNames(ctx *sql.Context, root doltdb.RootValue, sho
}

if showSystemTables {
systemTables, err := doltdb.GetGeneratedSystemTables(ctx, root)
systemTables, err := resolve.GetGeneratedSystemTables(ctx, root)
if err != nil {
return nil, err
}
result = append(result, systemTables...)
result = append(result, doltdb.FlattenTableNames(systemTables)...)
}

return result, nil
Expand Down
77 changes: 77 additions & 0 deletions go/libraries/doltcore/sqle/resolve/system_tables.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2025 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package resolve

import (
"context"

"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
)

// GetGeneratedSystemTables returns table names of all generated system tables.
func GetGeneratedSystemTables(ctx context.Context, root doltdb.RootValue) ([]doltdb.TableName, error) {
s := doltdb.NewTableNameSet(nil)

// Depending on whether the search path is used, the generated system tables will either be in the dolt namespace
// or the empty (default) namespace
if !UseSearchPath {
for _, t := range doltdb.GeneratedSystemTableNames() {
s.Add(doltdb.TableName{Name: t})
}
} else {
for _, t := range doltdb.GeneratedSystemTableNames() {
s.Add(doltdb.TableName{Name: t, Schema: doltdb.DoltNamespace})
}
}

schemas, err := root.GetDatabaseSchemas(ctx)
if err != nil {
return nil, err
}

// For dolt there are no stored schemas, search the default (empty string) schema
if len(schemas) == 0 {
schemas = append(schemas, schema.DatabaseSchema{Name: doltdb.DefaultSchemaName})
}

for _, schema := range schemas {
tableNames, err := root.GetTableNames(ctx, schema.Name)
if err != nil {
return nil, err
}

for _, pre := range doltdb.GeneratedSystemTablePrefixes {
for _, tableName := range tableNames {
s.Add(doltdb.TableName{
Name: pre + tableName,
Schema: schema.Name,
})
}
}

// For doltgres, we also support the legacy dolt_ table names, addressable in any user schema
if UseSearchPath && schema.Name != "pg_catalog" && schema.Name != doltdb.DoltNamespace {
for _, name := range doltdb.DoltGeneratedTableNames {
s.Add(doltdb.TableName{
Name: name,
Schema: schema.Name,
})
}
}
}

return s.AsSlice(), nil
}
1 change: 0 additions & 1 deletion go/libraries/doltcore/sqle/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func init() {
}
}

var _ dtables.VersionableTable = (*DoltTable)(nil)
var _ dtables.VersionableTable = (*DoltTable)(nil)

// DoltTable implements the sql.Table interface and gives access to dolt table rows and schema.
Expand Down
Loading