From b368470ab11192916ed2300cba037109ea91051a Mon Sep 17 00:00:00 2001 From: Jason Fulghum Date: Tue, 13 Feb 2024 16:16:39 -0800 Subject: [PATCH 1/2] Fixing issue with IndexedDoltTable not fully implementing the interface of DoltTable (inconsistent with WritableIndexedDoltTable) --- .../doltcore/sqle/enginetest/dolt_queries.go | 45 +++++++++++++++++++ .../doltcore/sqle/indexed_dolt_table.go | 42 +++-------------- 2 files changed, 52 insertions(+), 35 deletions(-) diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_queries.go b/go/libraries/doltcore/sqle/enginetest/dolt_queries.go index 512f2234a2f..2fad458b7f7 100644 --- a/go/libraries/doltcore/sqle/enginetest/dolt_queries.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_queries.go @@ -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{ diff --git a/go/libraries/doltcore/sqle/indexed_dolt_table.go b/go/libraries/doltcore/sqle/indexed_dolt_table.go index 941450ff273..910fa3da540 100644 --- a/go/libraries/doltcore/sqle/indexed_dolt_table.go +++ b/go/libraries/doltcore/sqle/indexed_dolt_table.go @@ -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 @@ -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{}, @@ -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) { @@ -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 } @@ -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 } @@ -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) From fd8fcd5a0b85f0f53075960a3b86fd3bf7c6f68e Mon Sep 17 00:00:00 2001 From: Neil Macneale IV Date: Tue, 13 Feb 2024 12:34:33 -0800 Subject: [PATCH 2/2] Formatter complaining about no-op append use for reasons unknown --- go/cmd/dolt/commands/engine/sqlengine.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/cmd/dolt/commands/engine/sqlengine.go b/go/cmd/dolt/commands/engine/sqlengine.go index 5e72e052665..103f082fc69 100644 --- a/go/cmd/dolt/commands/engine/sqlengine.go +++ b/go/cmd/dolt/commands/engine/sqlengine.go @@ -115,7 +115,7 @@ func NewSqlEngine( return nil, err } - all := append(dbs) + all := dbs[:] clusterDB := config.ClusterController.ClusterDatabase() if clusterDB != nil {