add SchemaName to DatabaseSchema interface (#8062)

This commit is contained in:
jennifersp
2024-06-25 15:35:14 -07:00
committed by GitHub
parent 04c25bc550
commit 4c704c3dae
15 changed files with 33 additions and 65 deletions

View File

@@ -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

View File

@@ -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=

View File

@@ -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())
}

View File

@@ -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) {

View File

@@ -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)
@@ -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

View File

@@ -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,
@@ -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",
@@ -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"}},
},
},
}

View File

@@ -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))

View File

@@ -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~`;",
@@ -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
@@ -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;",
@@ -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;",
@@ -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"}},
},
},
},
@@ -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
@@ -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();",
@@ -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
@@ -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`;",
@@ -4654,7 +4654,7 @@ 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;",
@@ -4662,7 +4662,7 @@ var DoltUndropTestScripts = []queries.ScriptTest{
},
{
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');",
@@ -4670,7 +4670,7 @@ var DoltUndropTestScripts = []queries.ScriptTest{
},
{
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;",
@@ -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;",

View File

@@ -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');",
@@ -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();",
@@ -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');",
@@ -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

View File

@@ -73,7 +73,6 @@ func TestDbRevision(t *testing.T) {
rows: []sql.Row{
{"dolt"},
{"information_schema"},
{"performance_schema"},
},
},
{

View File

@@ -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

View File

@@ -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
@@ -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" {

View File

@@ -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:
@@ -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"
@@ -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:
@@ -1752,7 +1749,6 @@ tests:
- ["dolt_cluster"]
- ["information_schema"]
- ["mysql"]
- ["performance_schema"]
- ["repo1"]
- exec: 'use repo1'
- query: "select d from vals"
@@ -1811,7 +1807,6 @@ tests:
- ["dolt_cluster"]
- ["information_schema"]
- ["mysql"]
- ["performance_schema"]
- exec: "call dolt_cluster_transition_to_standby('2', '1')"
- on: server2
queries:

View File

@@ -228,7 +228,6 @@ tests:
rows:
- ["information_schema"]
- ["mysql"]
- ["performance_schema"]
- ["repo1"]
- name: LOAD DATA LOCAL INFILE works
repos:

View File

@@ -23,7 +23,6 @@ export const databaseTests = [
{ Database: `${dbName}/main` },
{ Database: "information_schema" },
{ Database: "mysql" },
{ Database: "performance_schema" },
],
},
{
@@ -47,7 +46,6 @@ export const databaseTests = [
{ Database: "information_schema" },
{ Database: "mysql" },
{ Database: "new_db" },
{ Database: "performance_schema" },
],
},
{