From 748db5b373472d14371ab305782eb4be16e99cb7 Mon Sep 17 00:00:00 2001 From: angelamayxie Date: Thu, 28 May 2026 13:53:38 -0700 Subject: [PATCH 1/2] do not make diff table indexes on nil schemas --- go/libraries/doltcore/sqle/index/dolt_index.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/go/libraries/doltcore/sqle/index/dolt_index.go b/go/libraries/doltcore/sqle/index/dolt_index.go index 218d3403e6a..57c3e6e7e68 100644 --- a/go/libraries/doltcore/sqle/index/dolt_index.go +++ b/go/libraries/doltcore/sqle/index/dolt_index.go @@ -240,10 +240,14 @@ func MakeDiffTableIndex(tableName string, prefix string, sch schema.Schema, incl } func MakeDiffTableIndexes(tbl string, toSchema, fromSchema schema.Schema, includeCommits bool) (indexes []sql.Index) { - return []sql.Index{ - MakeDiffTableIndex(tbl, "to", toSchema, includeCommits), - MakeDiffTableIndex(tbl, "from", fromSchema, includeCommits), + indexes = make([]sql.Index, 0) + if toSchema != nil { + indexes = append(indexes, MakeDiffTableIndex(tbl, "to", toSchema, includeCommits)) + } + if fromSchema != nil { + indexes = append(indexes, MakeDiffTableIndex(tbl, "from", fromSchema, includeCommits)) } + return indexes } // MockIndex returns a sql.Index that is not backed by an actual datastore. It's useful for system tables and From 430f1d65dedc407ddb4af0c48a144effa1540d40 Mon Sep 17 00:00:00 2001 From: angelamayxie Date: Thu, 28 May 2026 14:58:48 -0700 Subject: [PATCH 2/2] add tests --- .../sqle/enginetest/dolt_queries_diff.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_queries_diff.go b/go/libraries/doltcore/sqle/enginetest/dolt_queries_diff.go index a35dfcbdd67..5902a182911 100644 --- a/go/libraries/doltcore/sqle/enginetest/dolt_queries_diff.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_queries_diff.go @@ -6857,6 +6857,25 @@ left join dolt_commit_diff_xy cd }, }, }, + { + name: "indexes work when table doesn't exist on one branch", + setup: []string{ + "call dolt_checkout('-b', 'mod')", + "create table newTable(id int)", + "call dolt_add('newTable')", + "call dolt_commit('-am', 'added new table')", + }, + queries: []systabQuery{ + { + query: "select count(*) from dolt_diff('main', 'mod', 'newTable') where to_commit='def'", + exp: []sql.Row{{0}}, + }, + { + query: "select count(*) from dolt_diff('mod', 'main', 'newTable') where to_commit='def'", + exp: []sql.Row{{0}}, + }, + }, + }, } var QueryDiffTableScriptTests = []queries.ScriptTest{