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

Bug fix: IndexedDoltTable didn't fully implement DoltTable's interface #7490

Merged
merged 2 commits into from
Feb 14, 2024
Merged
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
2 changes: 1 addition & 1 deletion go/cmd/dolt/commands/engine/sqlengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func NewSqlEngine(
return nil, err
}

all := append(dbs)
all := dbs[:]

clusterDB := config.ClusterController.ClusterDatabase()
if clusterDB != nil {
Expand Down
45 changes: 45 additions & 0 deletions go/libraries/doltcore/sqle/enginetest/dolt_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,51 @@ var DoltScripts = []queries.ScriptTest{
},
},
},
{
Name: "test AS OF indexed queries (https://github.com/dolthub/dolt/issues/7488)",
SetUpScript: []string{
"create table indexedTable (pk int primary key, c0 int, c1 varchar(255), key c1_idx(c1));",
"insert into indexedTable (pk, c1) values (1, 'one');",
"call dolt_commit('-Am', 'adding table t with index');",
"SET @commit1 = hashof('HEAD');",

"update indexedTable set c1='two';",
"call dolt_commit('-am', 'updating one to two');",
"SET @commit2 = hashof('HEAD');",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT c1 from indexedTable;",
Expected: []sql.Row{{"two"}},
ExpectedIndexes: []string{},
},
{
Query: "SELECT c1 from indexedTable where c1 > 'o';",
Expected: []sql.Row{{"two"}},
ExpectedIndexes: []string{"c1_idx"},
},
{
Query: "SELECT c1 from indexedTable as of @commit2;",
Expected: []sql.Row{{"two"}},
ExpectedIndexes: []string{},
},
{
Query: "SELECT c1 from indexedTable as of @commit2 where c1 > 'o';",
Expected: []sql.Row{{"two"}},
ExpectedIndexes: []string{"c1_idx"},
},
{
Query: "SELECT c1 from indexedTable as of @commit1;",
Expected: []sql.Row{{"one"}},
ExpectedIndexes: []string{},
},
{
Query: "SELECT c1 from indexedTable as of @commit1 where c1 > 'o';",
Expected: []sql.Row{{"one"}},
ExpectedIndexes: []string{"c1_idx"},
},
},
},
{
Name: "test as of indexed join (https://github.com/dolthub/dolt/issues/2189)",
SetUpScript: []string{
Expand Down
42 changes: 7 additions & 35 deletions go/libraries/doltcore/sqle/indexed_dolt_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
// DoltTable, but its RowIter function returns values that match a sql.Range, instead of all
// rows. It's returned by the DoltTable.IndexedAccess function.
type IndexedDoltTable struct {
table *DoltTable
*DoltTable
idx index.DoltIndex
lb index.LookupBuilder
isDoltFormat bool
Expand All @@ -36,7 +36,7 @@ type IndexedDoltTable struct {

func NewIndexedDoltTable(t *DoltTable, idx index.DoltIndex) *IndexedDoltTable {
return &IndexedDoltTable{
table: t,
DoltTable: t,
idx: idx,
isDoltFormat: types.IsFormat_DOLT(t.Format()),
mu: &sync.Mutex{},
Expand All @@ -46,32 +46,8 @@ func NewIndexedDoltTable(t *DoltTable, idx index.DoltIndex) *IndexedDoltTable {
var _ sql.IndexedTable = (*IndexedDoltTable)(nil)
var _ sql.CommentedTable = (*IndexedDoltTable)(nil)

func (idt *IndexedDoltTable) GetIndexes(ctx *sql.Context) ([]sql.Index, error) {
return idt.table.GetIndexes(ctx)
}

func (idt *IndexedDoltTable) Name() string {
return idt.table.Name()
}

func (idt *IndexedDoltTable) String() string {
return idt.table.String()
}

func (idt *IndexedDoltTable) Schema() sql.Schema {
return idt.table.Schema()
}

func (idt *IndexedDoltTable) Collation() sql.CollationID {
return sql.CollationID(idt.table.sch.GetCollation())
}

func (idt *IndexedDoltTable) Comment() string {
return idt.table.Comment()
}

func (idt *IndexedDoltTable) LookupPartitions(ctx *sql.Context, lookup sql.IndexLookup) (sql.PartitionIter, error) {
return index.NewRangePartitionIter(ctx, idt.table, lookup, idt.isDoltFormat)
return index.NewRangePartitionIter(ctx, idt.DoltTable, lookup, idt.isDoltFormat)
}

func (idt *IndexedDoltTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
Expand All @@ -81,13 +57,13 @@ func (idt *IndexedDoltTable) Partitions(ctx *sql.Context) (sql.PartitionIter, er
func (idt *IndexedDoltTable) PartitionRows(ctx *sql.Context, part sql.Partition) (sql.RowIter, error) {
idt.mu.Lock()
defer idt.mu.Unlock()
key, canCache, err := idt.table.DataCacheKey(ctx)
key, canCache, err := idt.DoltTable.DataCacheKey(ctx)
if err != nil {
return nil, err
}

if idt.lb == nil || !canCache || idt.lb.Key() != key {
idt.lb, err = index.NewLookupBuilder(ctx, idt.table, idt.idx, key, idt.table.projectedCols, idt.table.sqlSch, idt.isDoltFormat)
idt.lb, err = index.NewLookupBuilder(ctx, idt.DoltTable, idt.idx, key, idt.DoltTable.projectedCols, idt.DoltTable.sqlSch, idt.isDoltFormat)
if err != nil {
return nil, err
}
Expand All @@ -99,12 +75,12 @@ func (idt *IndexedDoltTable) PartitionRows(ctx *sql.Context, part sql.Partition)
func (idt *IndexedDoltTable) PartitionRows2(ctx *sql.Context, part sql.Partition) (sql.RowIter, error) {
idt.mu.Lock()
defer idt.mu.Unlock()
key, canCache, err := idt.table.DataCacheKey(ctx)
key, canCache, err := idt.DoltTable.DataCacheKey(ctx)
if err != nil {
return nil, err
}
if idt.lb == nil || !canCache || idt.lb.Key() != key {
idt.lb, err = index.NewLookupBuilder(ctx, idt.table, idt.idx, key, idt.table.projectedCols, idt.table.sqlSch, idt.isDoltFormat)
idt.lb, err = index.NewLookupBuilder(ctx, idt.DoltTable, idt.idx, key, idt.DoltTable.projectedCols, idt.DoltTable.sqlSch, idt.isDoltFormat)
if err != nil {
return nil, err
}
Expand All @@ -113,10 +89,6 @@ func (idt *IndexedDoltTable) PartitionRows2(ctx *sql.Context, part sql.Partition
return idt.lb.NewRowIter(ctx, part)
}

func (idt *IndexedDoltTable) IsTemporary() bool {
return idt.table.IsTemporary()
}

var _ sql.IndexedTable = (*WritableIndexedDoltTable)(nil)
var _ sql.UpdatableTable = (*WritableIndexedDoltTable)(nil)
var _ sql.DeletableTable = (*WritableIndexedDoltTable)(nil)
Expand Down
Loading