mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-24 03:16:12 -05:00
Track database in system tables.
This commit is contained in:
@@ -375,7 +375,7 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
|
||||
}
|
||||
}
|
||||
|
||||
dt, found = dtables.NewLogTable(ctx, db.ddb, head), true
|
||||
dt, found = dtables.NewLogTable(ctx, db.RevisionQualifiedName(), db.ddb, head), true
|
||||
case doltdb.DiffTableName:
|
||||
if head == nil {
|
||||
var err error
|
||||
@@ -409,9 +409,9 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
|
||||
case doltdb.RemotesTableName:
|
||||
dt, found = dtables.NewRemotesTable(ctx, db.ddb), true
|
||||
case doltdb.CommitsTableName:
|
||||
dt, found = dtables.NewCommitsTable(ctx, db.ddb), true
|
||||
dt, found = dtables.NewCommitsTable(ctx, db.RevisionQualifiedName(), db.ddb), true
|
||||
case doltdb.CommitAncestorsTableName:
|
||||
dt, found = dtables.NewCommitAncestorsTable(ctx, db.ddb), true
|
||||
dt, found = dtables.NewCommitAncestorsTable(ctx, db.RevisionQualifiedName(), db.ddb), true
|
||||
case doltdb.StatusTableName:
|
||||
sess := dsess.DSessFromSess(ctx.Session)
|
||||
adapter := dsess.NewSessionStateAdapter(
|
||||
|
||||
@@ -215,7 +215,7 @@ func (p *PatchTableFunction) IndexedAccess(lookup sql.IndexLookup) sql.IndexedTa
|
||||
|
||||
func (p *PatchTableFunction) GetIndexes(ctx *sql.Context) ([]sql.Index, error) {
|
||||
return []sql.Index{
|
||||
index.MockIndex(diffTypeColumnName, p.Name(), types.StringKind, false),
|
||||
index.MockIndex(p.database.Name(), p.Name(), diffTypeColumnName, types.StringKind, false),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@ const commitAncestorsDefaultRowCount = 100
|
||||
// CommitAncestorsTable is a sql.Table that implements a system table which
|
||||
// shows (commit, parent_commit) relationships for all commits in the repo.
|
||||
type CommitAncestorsTable struct {
|
||||
ddb *doltdb.DoltDB
|
||||
dbName string
|
||||
ddb *doltdb.DoltDB
|
||||
}
|
||||
|
||||
var _ sql.Table = (*CommitAncestorsTable)(nil)
|
||||
@@ -38,8 +39,8 @@ var _ sql.IndexAddressable = (*CommitAncestorsTable)(nil)
|
||||
var _ sql.StatisticsTable = (*CommitAncestorsTable)(nil)
|
||||
|
||||
// NewCommitAncestorsTable creates a CommitAncestorsTable
|
||||
func NewCommitAncestorsTable(_ *sql.Context, ddb *doltdb.DoltDB) sql.Table {
|
||||
return &CommitAncestorsTable{ddb: ddb}
|
||||
func NewCommitAncestorsTable(_ *sql.Context, dbName string, ddb *doltdb.DoltDB) sql.Table {
|
||||
return &CommitAncestorsTable{dbName: dbName, ddb: ddb}
|
||||
}
|
||||
|
||||
func (dt *CommitAncestorsTable) DataLength(ctx *sql.Context) (uint64, error) {
|
||||
@@ -100,7 +101,7 @@ func (dt *CommitAncestorsTable) PartitionRows(ctx *sql.Context, p sql.Partition)
|
||||
|
||||
// GetIndexes implements sql.IndexAddressable
|
||||
func (dt *CommitAncestorsTable) GetIndexes(ctx *sql.Context) ([]sql.Index, error) {
|
||||
return index.DoltCommitIndexes(dt.Name(), dt.ddb, true)
|
||||
return index.DoltCommitIndexes(dt.dbName, dt.Name(), dt.ddb, true)
|
||||
}
|
||||
|
||||
// IndexedAccess implements sql.IndexAddressable
|
||||
|
||||
@@ -41,8 +41,8 @@ var _ sql.IndexAddressable = (*CommitsTable)(nil)
|
||||
var _ sql.StatisticsTable = (*CommitsTable)(nil)
|
||||
|
||||
// NewCommitsTable creates a CommitsTable
|
||||
func NewCommitsTable(_ *sql.Context, ddb *doltdb.DoltDB) sql.Table {
|
||||
return &CommitsTable{ddb: ddb}
|
||||
func NewCommitsTable(_ *sql.Context, dbName string, ddb *doltdb.DoltDB) sql.Table {
|
||||
return &CommitsTable{dbName: dbName, ddb: ddb}
|
||||
}
|
||||
|
||||
func (dt *CommitsTable) DataLength(ctx *sql.Context) (uint64, error) {
|
||||
@@ -102,7 +102,7 @@ func (dt *CommitsTable) PartitionRows(ctx *sql.Context, p sql.Partition) (sql.Ro
|
||||
|
||||
// GetIndexes implements sql.IndexAddressable
|
||||
func (dt *CommitsTable) GetIndexes(ctx *sql.Context) ([]sql.Index, error) {
|
||||
return index.DoltCommitIndexes(dt.Name(), dt.ddb, true)
|
||||
return index.DoltCommitIndexes(dt.dbName, dt.Name(), dt.ddb, true)
|
||||
}
|
||||
|
||||
// IndexedAccess implements sql.IndexAddressable
|
||||
|
||||
@@ -33,6 +33,7 @@ const logsDefaultRowCount = 100
|
||||
|
||||
// LogTable is a sql.Table implementation that implements a system table which shows the dolt commit log
|
||||
type LogTable struct {
|
||||
dbName string
|
||||
ddb *doltdb.DoltDB
|
||||
head *doltdb.Commit
|
||||
headHash hash.Hash
|
||||
@@ -44,8 +45,8 @@ var _ sql.StatisticsTable = (*LogTable)(nil)
|
||||
var _ sql.IndexAddressable = (*LogTable)(nil)
|
||||
|
||||
// NewLogTable creates a LogTable
|
||||
func NewLogTable(_ *sql.Context, ddb *doltdb.DoltDB, head *doltdb.Commit) sql.Table {
|
||||
return &LogTable{ddb: ddb, head: head}
|
||||
func NewLogTable(_ *sql.Context, dbName string, ddb *doltdb.DoltDB, head *doltdb.Commit) sql.Table {
|
||||
return &LogTable{dbName: dbName, ddb: ddb, head: head}
|
||||
}
|
||||
|
||||
// DataLength implements sql.StatisticsTable
|
||||
@@ -116,7 +117,7 @@ func (dt *LogTable) PartitionRows(ctx *sql.Context, p sql.Partition) (sql.RowIte
|
||||
}
|
||||
|
||||
func (dt *LogTable) GetIndexes(ctx *sql.Context) ([]sql.Index, error) {
|
||||
return index.DoltCommitIndexes(dt.Name(), dt.ddb, true)
|
||||
return index.DoltCommitIndexes(dt.dbName, dt.Name(), dt.ddb, true)
|
||||
}
|
||||
|
||||
// IndexedAccess implements sql.IndexAddressable
|
||||
|
||||
@@ -141,7 +141,7 @@ func (dt *UnscopedDiffTable) PartitionRows(ctx *sql.Context, partition sql.Parti
|
||||
|
||||
// GetIndexes implements sql.IndexAddressable
|
||||
func (dt *UnscopedDiffTable) GetIndexes(ctx *sql.Context) ([]sql.Index, error) {
|
||||
return index.DoltCommitIndexes(dt.Name(), dt.ddb, true)
|
||||
return index.DoltCommitIndexes(dt.dbName, dt.Name(), dt.ddb, true)
|
||||
}
|
||||
|
||||
// IndexedAccess implements sql.IndexAddressable
|
||||
|
||||
@@ -202,11 +202,11 @@ func DoltToFromCommitIndex(tbl string) sql.Index {
|
||||
|
||||
// MockIndex returns a sql.Index that is not backed by an actual datastore. It's useful for system tables and
|
||||
// system table functions provide indexes but produce their rows at execution time based on the provided `IndexLookup`
|
||||
func MockIndex(columnName, tableName string, columnType types.NomsKind, unique bool) (index *doltIndex) {
|
||||
func MockIndex(dbName, tableName, columnName string, columnType types.NomsKind, unique bool) (index *doltIndex) {
|
||||
return &doltIndex{
|
||||
id: columnName,
|
||||
tblName: tableName,
|
||||
dbName: "",
|
||||
dbName: dbName,
|
||||
columns: []schema.Column{
|
||||
schema.NewColumn(columnName, 0, columnType, false),
|
||||
},
|
||||
@@ -221,13 +221,13 @@ func MockIndex(columnName, tableName string, columnType types.NomsKind, unique b
|
||||
}
|
||||
}
|
||||
|
||||
func DoltCommitIndexes(tab string, db *doltdb.DoltDB, unique bool) (indexes []sql.Index, err error) {
|
||||
func DoltCommitIndexes(dbName, tab string, db *doltdb.DoltDB, unique bool) (indexes []sql.Index, err error) {
|
||||
if !types.IsFormat_DOLT(db.Format()) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return []sql.Index{
|
||||
NewCommitIndex(MockIndex(CommitHashIndexId, tab, types.StringKind, unique)),
|
||||
NewCommitIndex(MockIndex(dbName, tab, CommitHashIndexId, types.StringKind, unique)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ func DoltHistoryIndexesFromTable(ctx context.Context, db, tbl string, t *doltdb.
|
||||
unorderedIndexes[i] = di
|
||||
}
|
||||
|
||||
cmIdx, err := DoltCommitIndexes(tbl, ddb, false)
|
||||
cmIdx, err := DoltCommitIndexes(db, tbl, ddb, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user