Skip to content

Commit

Permalink
add SchemaName to DatabaseSchema interface (#8062)
Browse files Browse the repository at this point in the history
  • Loading branch information
jennifersp authored Jun 25, 2024
1 parent 04c25bc commit 4c704c3
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 65 deletions.
2 changes: 1 addition & 1 deletion go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ require (
github.com/cespare/xxhash v1.1.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.20240625021513-e92a4b8477ad
github.com/dolthub/go-mysql-server v0.18.2-0.20240625212035-80f4e402d726
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63
github.com/dolthub/swiss v0.1.0
github.com/goccy/go-json v0.10.2
Expand Down
4 changes: 2 additions & 2 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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-20230524105445-af7e7991c97e h1:kPsT4a47cw1+y/N5SSCkma7FhAPw7KeGmD6c9PBZW9Y=
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168=
github.com/dolthub/go-mysql-server v0.18.2-0.20240625021513-e92a4b8477ad h1:fzobsRknxihSlaz8x9JmwUkxFSAfvPzEeA9MNg/te9c=
github.com/dolthub/go-mysql-server v0.18.2-0.20240625021513-e92a4b8477ad/go.mod h1:XdiHsd2TX3OOhjwY6tPcw1ztT2BdBiP6Wp0m/7OYHn4=
github.com/dolthub/go-mysql-server v0.18.2-0.20240625212035-80f4e402d726 h1:zVMMW0gpT/Cq+xEUPulbt5y7dWz0K1A5BtNRDarW+i0=
github.com/dolthub/go-mysql-server v0.18.2-0.20240625212035-80f4e402d726/go.mod h1:XdiHsd2TX3OOhjwY6tPcw1ztT2BdBiP6Wp0m/7OYHn4=
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-20221214210346-d7db0b066488 h1:0HHu0GWJH0N6a6keStrHhUAK5/o9LVfkh44pvsV4514=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ func getAllUserDatabaseNames(ctx *sql.Context, engine *gms.Engine) []string {
userDatabaseNames := make([]string, 0, len(allDatabases))
for _, database := range allDatabases {
switch database.Name() {
case "information_schema", "mysql", "performance_schema":
case "information_schema", "mysql":
default:
userDatabaseNames = append(userDatabaseNames, database.Name())
}
Expand Down
4 changes: 4 additions & 0 deletions go/libraries/doltcore/sqle/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,10 @@ func (db Database) GetTableNames(ctx *sql.Context) ([]string, error) {
}
}

func (db Database) SchemaName() string {
return db.schemaName
}

// GetAllTableNames returns all user-space tables, including system tables in user space
// (e.g. dolt_docs, dolt_query_catalog).
func (db Database) GetAllTableNames(ctx *sql.Context) ([]string, error) {
Expand Down
27 changes: 0 additions & 27 deletions go/libraries/doltcore/sqle/database_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ type DoltDatabaseProvider struct {
}

var _ sql.DatabaseProvider = (*DoltDatabaseProvider)(nil)
var _ sql.SchemaDatabaseProvider = (*DoltDatabaseProvider)(nil)
var _ sql.FunctionProvider = (*DoltDatabaseProvider)(nil)
var _ sql.MutableDatabaseProvider = (*DoltDatabaseProvider)(nil)
var _ sql.CollatedDatabaseProvider = (*DoltDatabaseProvider)(nil)
Expand Down Expand Up @@ -256,32 +255,6 @@ func (p *DoltDatabaseProvider) Database(ctx *sql.Context, name string) (sql.Data
return database, nil
}

// SchemaDatabase is called to resolve a table when it's qualified with a single qualifer, e.g. `myDb.myTable`. We
// resolve this differently depending on whether we are emulating the MySQL or the Postgres dialect. In MySQL, the
// qualifier refers to a database name. In Postgres, it refers to a schema name.
// TODO: this should live only on a Doltgres implementation of this provider, this is a shim to get something working.
func (p *DoltDatabaseProvider) SchemaDatabase(ctx *sql.Context, dbName, schemaName string) (sql.DatabaseSchema, bool, error) {
// If search path isn't enabled, this becomes a simple DB lookup on the schema name, which is the qualifier specified
// in the query
if !resolve.UseSearchPath {
database, err := p.Database(ctx, schemaName)
return database, err == nil, err
}

db, err := p.Database(ctx, dbName)
if err != nil {
return nil, false, err
}

// We do have some database implementations that don't implement the SchemaDatabase interface, so we need to check
sdb, ok := db.(sql.SchemaDatabase)
if !ok {
return nil, false, nil
}

return sdb.GetSchema(ctx, schemaName)
}

func wrapForStandby(db dsess.SqlDatabase, standby bool) dsess.SqlDatabase {
if !standby {
return db
Expand Down
6 changes: 3 additions & 3 deletions go/libraries/doltcore/sqle/enginetest/dolt_engine_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ func RunDoltRevisionDbScriptsTest(t *testing.T, h DoltEnginetestHarness) {
Assertions: []queries.ScriptTestAssertion{
{
Query: "show databases;",
Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}, {"performance_schema"}},
Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}},
},
{
Query: "use mydb/" + commithash,
Expand All @@ -725,7 +725,7 @@ func RunDoltRevisionDbScriptsTest(t *testing.T, h DoltEnginetestHarness) {
},
{
Query: "show databases;",
Expected: []sql.Row{{"mydb"}, {"mydb/" + commithash}, {"information_schema"}, {"mysql"}, {"performance_schema"}},
Expected: []sql.Row{{"mydb"}, {"mydb/" + commithash}, {"information_schema"}, {"mysql"}},
},
{
Query: "select * from t01",
Expand Down Expand Up @@ -757,7 +757,7 @@ func RunDoltRevisionDbScriptsTest(t *testing.T, h DoltEnginetestHarness) {
},
{
Query: "show databases;",
Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}, {"performance_schema"}},
Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}},
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion go/libraries/doltcore/sqle/enginetest/dolt_harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (d *DoltHarness) SkipSetupCommit() {
// included.
func (d *DoltHarness) resetScripts() []setup.SetupScript {
ctx := enginetest.NewContext(d)
_, res := enginetest.MustQuery(ctx, d.engine, "select schema_name from information_schema.schemata where schema_name not in ('information_schema', 'performance_schema');")
_, res := enginetest.MustQuery(ctx, d.engine, "select schema_name from information_schema.schemata where schema_name not in ('information_schema');")
var dbs []string
for i := range res {
dbs = append(dbs, res[i][0].(string))
Expand Down
26 changes: 13 additions & 13 deletions go/libraries/doltcore/sqle/enginetest/dolt_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ var DoltRevisionDbScripts = []queries.ScriptTest{
Assertions: []queries.ScriptTestAssertion{
{
Query: "show databases;",
Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}, {"performance_schema"}},
Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}},
},
{
Query: "use `mydb/tag1~`;",
Expand All @@ -406,7 +406,7 @@ var DoltRevisionDbScripts = []queries.ScriptTest{
},
{
Query: "show databases;",
Expected: []sql.Row{{"mydb"}, {"mydb/tag1~"}, {"information_schema"}, {"mysql"}, {"performance_schema"}},
Expected: []sql.Row{{"mydb"}, {"mydb/tag1~"}, {"information_schema"}, {"mysql"}},
},
{
// The branch is nil in the case of a non-branch revision DB
Expand Down Expand Up @@ -475,7 +475,7 @@ var DoltRevisionDbScripts = []queries.ScriptTest{
Assertions: []queries.ScriptTestAssertion{
{
Query: "show databases;",
Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}, {"performance_schema"}},
Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}},
},
{
Query: "use mydb/tag1;",
Expand All @@ -493,7 +493,7 @@ var DoltRevisionDbScripts = []queries.ScriptTest{
},
{
Query: "show databases;",
Expected: []sql.Row{{"mydb"}, {"mydb/tag1"}, {"information_schema"}, {"mysql"}, {"performance_schema"}},
Expected: []sql.Row{{"mydb"}, {"mydb/tag1"}, {"information_schema"}, {"mysql"}},
},
{
Query: "select * from t01;",
Expand Down Expand Up @@ -525,7 +525,7 @@ var DoltRevisionDbScripts = []queries.ScriptTest{
},
{
Query: "show databases;",
Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}, {"performance_schema"}},
Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}},
},
},
},
Expand All @@ -548,7 +548,7 @@ var DoltRevisionDbScripts = []queries.ScriptTest{
},
{
Query: "show databases;",
Expected: []sql.Row{{"mydb"}, {"mydb/branch1"}, {"information_schema"}, {"mysql"}, {"performance_schema"}},
Expected: []sql.Row{{"mydb"}, {"mydb/branch1"}, {"information_schema"}, {"mysql"}},
},
{
// The database name is always the requested name
Expand All @@ -572,7 +572,7 @@ var DoltRevisionDbScripts = []queries.ScriptTest{
// base database name. But we should also consider the connection string: if you connect to a revision
// database, that database should always be visible.
Query: "show databases;",
Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}, {"performance_schema"}},
Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}},
},
{
Query: "select database();",
Expand All @@ -592,7 +592,7 @@ var DoltRevisionDbScripts = []queries.ScriptTest{
},
{
Query: "show databases;",
Expected: []sql.Row{{"mydb"}, {"mydb/branch1"}, {"information_schema"}, {"mysql"}, {"performance_schema"}},
Expected: []sql.Row{{"mydb"}, {"mydb/branch1"}, {"information_schema"}, {"mysql"}},
},
{
// Create a table in the working set to verify the main db
Expand Down Expand Up @@ -679,7 +679,7 @@ var DoltRevisionDbScripts = []queries.ScriptTest{
Assertions: []queries.ScriptTestAssertion{
{
Query: "show databases;",
Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}, {"performance_schema"}},
Expected: []sql.Row{{"mydb"}, {"information_schema"}, {"mysql"}},
},
{
Query: "use `mydb/main`;",
Expand Down Expand Up @@ -4654,23 +4654,23 @@ var DoltUndropTestScripts = []queries.ScriptTest{
Assertions: []queries.ScriptTestAssertion{
{
Query: "show databases;",
Expected: []sql.Row{{"information_schema"}, {"mydb"}, {"mysql"}, {"one"}, {"performance_schema"}, {"two"}},
Expected: []sql.Row{{"information_schema"}, {"mydb"}, {"mysql"}, {"one"}, {"two"}},
},
{
Query: "drop database one;",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "show databases;",
Expected: []sql.Row{{"information_schema"}, {"mydb"}, {"mysql"}, {"performance_schema"}, {"two"}},
Expected: []sql.Row{{"information_schema"}, {"mydb"}, {"mysql"}, {"two"}},
},
{
Query: "call dolt_undrop('one');",
Expected: []sql.Row{{0}},
},
{
Query: "show databases;",
Expected: []sql.Row{{"information_schema"}, {"mydb"}, {"mysql"}, {"one"}, {"performance_schema"}, {"two"}},
Expected: []sql.Row{{"information_schema"}, {"mydb"}, {"mysql"}, {"one"}, {"two"}},
},
{
Query: "use one;",
Expand Down Expand Up @@ -4698,7 +4698,7 @@ var DoltUndropTestScripts = []queries.ScriptTest{
},
{
Query: "show databases;",
Expected: []sql.Row{{"information_schema"}, {"mydb"}, {"mysql"}, {"two"}, {"performance_schema"}},
Expected: []sql.Row{{"information_schema"}, {"mydb"}, {"mysql"}, {"two"}},
},
{
Query: "call dolt_undrop;",
Expand Down
8 changes: 4 additions & 4 deletions go/libraries/doltcore/sqle/enginetest/dolt_server_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ var DoltBranchMultiSessionScriptTests = []queries.ScriptTest{
},
{
Query: "/* client a */ SHOW DATABASES;",
Expected: []sql.Row{{"dolt"}, {"dolt/branch1"}, {"information_schema"}, {"mysql"}, {"performance_schema"}},
Expected: []sql.Row{{"dolt"}, {"dolt/branch1"}, {"information_schema"}, {"mysql"}},
},
{
Query: "/* client a */ CALL DOLT_BRANCH('-d', 'branch2');",
Expand All @@ -146,7 +146,7 @@ var DoltBranchMultiSessionScriptTests = []queries.ScriptTest{
},
{
Query: "/* client a */ SHOW DATABASES;",
Expected: []sql.Row{{"dolt"}, {"dolt/branch1"}, {"information_schema"}, {"mysql"}, {"performance_schema"}},
Expected: []sql.Row{{"dolt"}, {"dolt/branch1"}, {"information_schema"}, {"mysql"}},
},
{
Query: "/* client a */ SELECT DATABASE(), ACTIVE_BRANCH();",
Expand Down Expand Up @@ -185,7 +185,7 @@ var DoltBranchMultiSessionScriptTests = []queries.ScriptTest{
},
{
Query: "/* client a */ SHOW DATABASES;",
Expected: []sql.Row{{"dolt"}, {"dolt/branch1"}, {"information_schema"}, {"mysql"}, {"performance_schema"}},
Expected: []sql.Row{{"dolt"}, {"dolt/branch1"}, {"information_schema"}, {"mysql"}},
},
{
Query: "/* client a */ CALL DOLT_BRANCH('-m', 'branch2', 'newName');",
Expand All @@ -197,7 +197,7 @@ var DoltBranchMultiSessionScriptTests = []queries.ScriptTest{
},
{
Query: "/* client a */ SHOW DATABASES;",
Expected: []sql.Row{{"dolt"}, {"dolt/branch1"}, {"information_schema"}, {"mysql"}, {"performance_schema"}},
Expected: []sql.Row{{"dolt"}, {"dolt/branch1"}, {"information_schema"}, {"mysql"}},
},
{
// Call a stored procedure since this searches across all databases and will
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func TestDbRevision(t *testing.T) {
rows: []sql.Row{
{"dolt"},
{"information_schema"},
{"performance_schema"},
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/bats/sql-multi-db.bats
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ seed_repos_with_tables_with_use_statements() {
}

@test "sql-multi-db: sql multi-db test show databases" {
EXPECTED=$(echo -e "Database\ninformation_schema\nmysql\nperformance_schema\nrepo1\nrepo2")
EXPECTED=$(echo -e "Database\ninformation_schema\nmysql\nrepo1\nrepo2")
run dolt --data-dir ./ sql -r csv -q "SHOW DATABASES"
[ "$status" -eq 0 ]
[[ "$output" =~ "$EXPECTED" ]] || false
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/bats/sql.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ SQL

run dolt sql -r csv -q "set dolt_show_branch_databases = 1; show databases"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 12 ] # 2 base dbs, 3 branch dbs each, 3 mysql dbs, 1 header line
[ "${#lines[@]}" -eq 11 ] # 2 base dbs, 3 branch dbs each, 2 mysql dbs, 1 header line
[[ "$output" =~ "db1/b1" ]] || false
[[ "$output" =~ "db1/b2" ]] || false
[[ "$output" =~ "db1/main" ]] || false
Expand All @@ -1476,13 +1476,13 @@ SQL
dolt sql -q "set @@persist.dolt_show_branch_databases = 1"
run dolt sql -r csv -q "show databases"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 12 ]
[ "${#lines[@]}" -eq 11 ]

# make sure we aren't double-counting revision dbs
run dolt sql -r csv -q 'use `db1/main`; show databases'
[ "$status" -eq 0 ]
[[ "$output" =~ "Database changed" ]] || false
[ "${#lines[@]}" -eq 13 ] # one line for above output, 12 dbs
[ "${#lines[@]}" -eq 12 ] # one line for above output, 11 dbs
}

@test "sql: run outside a dolt directory" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,6 @@ tests:
- ["dolt_cluster"]
- ["information_schema"]
- ["mysql"]
- ["performance_schema"]
- ["repo1"]
- query: "select `database`, standby_remote, role, epoch, replication_lag_millis is not null as `replication_lag_millis`, current_error from dolt_cluster.dolt_cluster_status"
result:
Expand All @@ -1583,7 +1582,6 @@ tests:
- ["dolt_cluster"]
- ["information_schema"]
- ["mysql"]
- ["performance_schema"]
- ["repo1"]
retry_attempts: 100
- query: "select `database`, standby_remote, role, epoch from dolt_cluster.dolt_cluster_status"
Expand Down Expand Up @@ -1732,7 +1730,6 @@ tests:
- ["dolt_cluster"]
- ["information_schema"]
- ["mysql"]
- ["performance_schema"]
retry_attempts: 100
- query: "select `database`, standby_remote, role, epoch from dolt_cluster.dolt_cluster_status"
result:
Expand All @@ -1752,7 +1749,6 @@ tests:
- ["dolt_cluster"]
- ["information_schema"]
- ["mysql"]
- ["performance_schema"]
- ["repo1"]
- exec: 'use repo1'
- query: "select d from vals"
Expand Down Expand Up @@ -1811,7 +1807,6 @@ tests:
- ["dolt_cluster"]
- ["information_schema"]
- ["mysql"]
- ["performance_schema"]
- exec: "call dolt_cluster_transition_to_standby('2', '1')"
- on: server2
queries:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ tests:
rows:
- ["information_schema"]
- ["mysql"]
- ["performance_schema"]
- ["repo1"]
- name: LOAD DATA LOCAL INFILE works
repos:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const databaseTests = [
{ Database: `${dbName}/main` },
{ Database: "information_schema" },
{ Database: "mysql" },
{ Database: "performance_schema" },
],
},
{
Expand All @@ -47,7 +46,6 @@ export const databaseTests = [
{ Database: "information_schema" },
{ Database: "mysql" },
{ Database: "new_db" },
{ Database: "performance_schema" },
],
},
{
Expand Down

0 comments on commit 4c704c3

Please sign in to comment.