From 5b3d301df2aeb2f04a1f78d124bec946f1d2b0e7 Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Tue, 8 Oct 2024 17:31:14 -0700 Subject: [PATCH 1/5] Change the behavior of AllTables when no schema is set --- go/libraries/doltcore/sqle/database.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/go/libraries/doltcore/sqle/database.go b/go/libraries/doltcore/sqle/database.go index 2cc69d82ae9..9079de38e51 100644 --- a/go/libraries/doltcore/sqle/database.go +++ b/go/libraries/doltcore/sqle/database.go @@ -928,9 +928,26 @@ func (db Database) getAllTableNames(ctx context.Context, root doltdb.RootValue) if err != nil { return nil, err } - result, err := root.GetTableNames(ctx, db.schemaName) + + var result []string + // If we are in a schema-enabled session and the schema name is not set, we need to union all table names in all + // schemas in this DB + // TODO: is this the right behavior choice? Should we use the first schema in the search path instead? + if resolve.UseSearchPath && db.schemaName == "" { + names, err := doltdb.UnionTableNames(ctx, root) + if err != nil { + return nil, err + } + result = doltdb.FlattenTableNames(names) + } else { + result, err = root.GetTableNames(ctx, db.schemaName) + if err != nil { + return nil, err + } + } + result = append(result, systemTables...) - return result, err + return result, nil } func filterDoltInternalTables(tblNames []string) []string { From f1d4c085b1ccb8c3cf921515df9fbf3393c07718 Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Wed, 9 Oct 2024 09:53:06 -0700 Subject: [PATCH 2/5] New gms and vitess --- go/go.mod | 4 ++-- go/go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go/go.mod b/go/go.mod index f2aa5ce363e..c22ef4eabfc 100644 --- a/go/go.mod +++ b/go/go.mod @@ -15,7 +15,7 @@ require ( github.com/dolthub/fslock v0.0.3 github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 - github.com/dolthub/vitess v0.0.0-20241002230050-2c2ea65cf324 + github.com/dolthub/vitess v0.0.0-20241009160728-54c0746cbff7 github.com/dustin/go-humanize v1.0.1 github.com/fatih/color v1.13.0 github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 @@ -57,7 +57,7 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 github.com/creasty/defaults v1.6.0 github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 - github.com/dolthub/go-mysql-server v0.18.2-0.20241008192944-eb9722c25843 + github.com/dolthub/go-mysql-server v0.18.2-0.20241009163215-487cf93b802a github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 github.com/dolthub/swiss v0.1.0 github.com/goccy/go-json v0.10.2 diff --git a/go/go.sum b/go/go.sum index 6462f6edcd6..077b25a9e39 100644 --- a/go/go.sum +++ b/go/go.sum @@ -183,8 +183,8 @@ github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U= github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0= github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662 h1:aC17hZD6iwzBwwfO5M+3oBT5E5gGRiQPdn+vzpDXqIA= github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168= -github.com/dolthub/go-mysql-server v0.18.2-0.20241008192944-eb9722c25843 h1:M7nttswAk2hCl6WfsXK6Pwe5KE9iwUIjUQg+GDwDNkI= -github.com/dolthub/go-mysql-server v0.18.2-0.20241008192944-eb9722c25843/go.mod h1:kXkvkPV9LdB2oCk1wC6mX+GpOayqwlmWJMjPnrGRgAk= +github.com/dolthub/go-mysql-server v0.18.2-0.20241009163215-487cf93b802a h1:TJJs3c2cxQmEuKINZb2RrRT5ZxwgJi2YizfqFMgk5Yc= +github.com/dolthub/go-mysql-server v0.18.2-0.20241009163215-487cf93b802a/go.mod h1:stBunNQzfqjxBXKb/v5bhluW5mXPGFFkHPlUZxD/0xE= github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI= github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q= github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE= @@ -197,8 +197,8 @@ github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9X github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY= github.com/dolthub/swiss v0.1.0 h1:EaGQct3AqeP/MjASHLiH6i4TAmgbG/c4rA6a1bzCOPc= github.com/dolthub/swiss v0.1.0/go.mod h1:BeucyB08Vb1G9tumVN3Vp/pyY4AMUnr9p7Rz7wJ7kAQ= -github.com/dolthub/vitess v0.0.0-20241002230050-2c2ea65cf324 h1:OO1XBXmBM3HBJfbwEwsj8h0m/bwYKIgFgGN8d+S+vrw= -github.com/dolthub/vitess v0.0.0-20241002230050-2c2ea65cf324/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM= +github.com/dolthub/vitess v0.0.0-20241009160728-54c0746cbff7 h1:mepdzTqvr0ZAbyOEsdgLg/nJ2qQzLJIwHD7xityHzz4= +github.com/dolthub/vitess v0.0.0-20241009160728-54c0746cbff7/go.mod h1:uBvlRluuL+SbEWTCZ68o0xvsdYZER3CEG/35INdzfJM= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= From d391fd0f3cbab765a84aed3a79d108d57e2ce79c Mon Sep 17 00:00:00 2001 From: zachmu Date: Wed, 9 Oct 2024 17:02:48 +0000 Subject: [PATCH 3/5] [ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/update.sh --- go/libraries/doltcore/sqle/database.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go/libraries/doltcore/sqle/database.go b/go/libraries/doltcore/sqle/database.go index 9079de38e51..fc19a4bf3dc 100644 --- a/go/libraries/doltcore/sqle/database.go +++ b/go/libraries/doltcore/sqle/database.go @@ -930,7 +930,7 @@ func (db Database) getAllTableNames(ctx context.Context, root doltdb.RootValue) } var result []string - // If we are in a schema-enabled session and the schema name is not set, we need to union all table names in all + // If we are in a schema-enabled session and the schema name is not set, we need to union all table names in all // schemas in this DB // TODO: is this the right behavior choice? Should we use the first schema in the search path instead? if resolve.UseSearchPath && db.schemaName == "" { @@ -945,7 +945,7 @@ func (db Database) getAllTableNames(ctx context.Context, root doltdb.RootValue) return nil, err } } - + result = append(result, systemTables...) return result, nil } From 2f36fe51bba723c757fb97cc2b849bdf9acf7066 Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Wed, 9 Oct 2024 14:54:56 -0700 Subject: [PATCH 4/5] Changed getAllTables behavior to restrict to search path --- go/libraries/doltcore/sqle/database.go | 9 +++++---- .../doltcore/sqle/resolve/resolve_tables.go | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/go/libraries/doltcore/sqle/database.go b/go/libraries/doltcore/sqle/database.go index 9079de38e51..0909b1fdbdf 100644 --- a/go/libraries/doltcore/sqle/database.go +++ b/go/libraries/doltcore/sqle/database.go @@ -923,7 +923,7 @@ func (db Database) GetAllTableNames(ctx *sql.Context) ([]string, error) { return db.getAllTableNames(ctx, root) } -func (db Database) getAllTableNames(ctx context.Context, root doltdb.RootValue) ([]string, error) { +func (db Database) getAllTableNames(ctx *sql.Context, root doltdb.RootValue) ([]string, error) { systemTables, err := doltdb.GetGeneratedSystemTables(ctx, root) if err != nil { return nil, err @@ -931,13 +931,14 @@ func (db Database) getAllTableNames(ctx context.Context, root doltdb.RootValue) var result []string // If we are in a schema-enabled session and the schema name is not set, we need to union all table names in all - // schemas in this DB - // TODO: is this the right behavior choice? Should we use the first schema in the search path instead? + // schemas in the search_path if resolve.UseSearchPath && db.schemaName == "" { - names, err := doltdb.UnionTableNames(ctx, root) + names, err := resolve.TablesOnSearchPath(ctx, root) if err != nil { return nil, err } + // TODO: this method should probably return TableNames, but need to iron out the effective schema for system + // tables first result = doltdb.FlattenTableNames(names) } else { result, err = root.GetTableNames(ctx, db.schemaName) diff --git a/go/libraries/doltcore/sqle/resolve/resolve_tables.go b/go/libraries/doltcore/sqle/resolve/resolve_tables.go index f7365b8bc55..6944dc51899 100755 --- a/go/libraries/doltcore/sqle/resolve/resolve_tables.go +++ b/go/libraries/doltcore/sqle/resolve/resolve_tables.go @@ -37,6 +37,25 @@ func Table( return tName, tbl, tblExists, err } +// TablesOnSearchPath returns all the tables in the root value given that are in a schema in the search path +func TablesOnSearchPath( ctx *sql.Context, root doltdb.RootValue) ([]doltdb.TableName, error) { + schemasToSearch, err := SearchPath(ctx) + if err != nil { + return nil, err + } + + var tableNames []doltdb.TableName + for _, schemaName := range schemasToSearch { + names, err := root.GetTableNames(ctx, schemaName) + if err != nil { + return nil, err + } + tableNames = append(tableNames, doltdb.ToTableNames(names, schemaName)...) + } + + return tableNames, nil +} + // TableWithSearchPath resolves a table name to a table in the root value, searching through the schemas in the func TableWithSearchPath( ctx *sql.Context, From 23432f4f807142fc735f00da0d939ec04d752eea Mon Sep 17 00:00:00 2001 From: zachmu Date: Wed, 9 Oct 2024 22:03:58 +0000 Subject: [PATCH 5/5] [ga-format-pr] Run go/utils/repofmt/format_repo.sh and go/Godeps/update.sh --- go/libraries/doltcore/sqle/database.go | 2 +- go/libraries/doltcore/sqle/resolve/resolve_tables.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go/libraries/doltcore/sqle/database.go b/go/libraries/doltcore/sqle/database.go index 44c3621f9e1..ee024ee2e2f 100644 --- a/go/libraries/doltcore/sqle/database.go +++ b/go/libraries/doltcore/sqle/database.go @@ -937,7 +937,7 @@ func (db Database) getAllTableNames(ctx *sql.Context, root doltdb.RootValue) ([] if err != nil { return nil, err } - // TODO: this method should probably return TableNames, but need to iron out the effective schema for system + // TODO: this method should probably return TableNames, but need to iron out the effective schema for system // tables first result = doltdb.FlattenTableNames(names) } else { diff --git a/go/libraries/doltcore/sqle/resolve/resolve_tables.go b/go/libraries/doltcore/sqle/resolve/resolve_tables.go index 6944dc51899..77f8d9ea2db 100755 --- a/go/libraries/doltcore/sqle/resolve/resolve_tables.go +++ b/go/libraries/doltcore/sqle/resolve/resolve_tables.go @@ -37,8 +37,8 @@ func Table( return tName, tbl, tblExists, err } -// TablesOnSearchPath returns all the tables in the root value given that are in a schema in the search path -func TablesOnSearchPath( ctx *sql.Context, root doltdb.RootValue) ([]doltdb.TableName, error) { +// TablesOnSearchPath returns all the tables in the root value given that are in a schema in the search path +func TablesOnSearchPath(ctx *sql.Context, root doltdb.RootValue) ([]doltdb.TableName, error) { schemasToSearch, err := SearchPath(ctx) if err != nil { return nil, err @@ -52,7 +52,7 @@ func TablesOnSearchPath( ctx *sql.Context, root doltdb.RootValue) ([]doltdb.Tabl } tableNames = append(tableNames, doltdb.ToTableNames(names, schemaName)...) } - + return tableNames, nil }