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= diff --git a/go/libraries/doltcore/sqle/database.go b/go/libraries/doltcore/sqle/database.go index 2cc69d82ae9..ee024ee2e2f 100644 --- a/go/libraries/doltcore/sqle/database.go +++ b/go/libraries/doltcore/sqle/database.go @@ -923,14 +923,32 @@ 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 } - 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 the search_path + if resolve.UseSearchPath && db.schemaName == "" { + 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) + if err != nil { + return nil, err + } + } + result = append(result, systemTables...) - return result, err + return result, nil } func filterDoltInternalTables(tblNames []string) []string { diff --git a/go/libraries/doltcore/sqle/resolve/resolve_tables.go b/go/libraries/doltcore/sqle/resolve/resolve_tables.go index f7365b8bc55..77f8d9ea2db 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,