Skip to content

Commit

Permalink
handle system databases other that information_schema correctly (vite…
Browse files Browse the repository at this point in the history
…ssio#12175)

Signed-off-by: Andres Taylor <[email protected]>

Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay authored and shanth96 committed Feb 28, 2024
1 parent 280605c commit ab573a9
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
12 changes: 12 additions & 0 deletions go/test/endtoend/vtgate/gen4/system_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,15 @@ func TestMultipleSchemaPredicates(t *testing.T) {
require.Error(t, err)
require.Contains(t, err.Error(), "specifying two different database in the query is not supported")
}

func TestQuerySystemTables(t *testing.T) {
defer cluster.PanicHandler(t)
ctx := context.Background()
conn, err := mysql.Connect(ctx, &vtParams)
require.NoError(t, err)
defer conn.Close()

utils.Exec(t, conn, `select * from sys.sys_config`)
utils.Exec(t, conn, "select * from mysql.`db`")
utils.Exec(t, conn, "select * from performance_schema.error_log")
}
57 changes: 57 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/systemtables_cases80.json
Original file line number Diff line number Diff line change
Expand Up @@ -1866,5 +1866,62 @@
"information_schema.key_column_usage"
]
}
},
{
"comment": "select variable, value from sys.sys_config",
"query": "select variable, value from sys.sys_config",
"plan": {
"QueryType": "SELECT",
"Original": "select variable, value from sys.sys_config",
"Instructions": {
"OperatorType": "Route",
"Variant": "DBA",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"FieldQuery": "select variable, value from sys.sys_config where 1 != 1",
"Query": "select variable, value from sys.sys_config",
"Table": "sys.sys_config"
}
}
},
{
"comment": "select host, db from mysql.`db`",
"query": "select host, db from mysql.`db`",
"plan": {
"QueryType": "SELECT",
"Original": "select host, db from mysql.`db`",
"Instructions": {
"OperatorType": "Route",
"Variant": "DBA",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"FieldQuery": "select host, db from mysql.db where 1 != 1",
"Query": "select host, db from mysql.db",
"Table": "mysql.db"
}
}
},
{
"comment": "select logged, prio from performance_schema.error_log",
"query": "select logged, prio from performance_schema.error_log",
"plan": {
"QueryType": "SELECT",
"Original": "select logged, prio from performance_schema.error_log",
"Instructions": {
"OperatorType": "Route",
"Variant": "DBA",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"FieldQuery": "select logged, prio from performance_schema.error_log where 1 != 1",
"Query": "select logged, prio from performance_schema.error_log",
"Table": "performance_schema.error_log"
}
}
}
]
3 changes: 2 additions & 1 deletion go/vt/vtgate/semantics/table_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func (tc *tableCollector) up(cursor *sqlparser.Cursor) error {
isInfSchema := sqlparser.SystemSchema(t.Qualifier.String())
var err error
tbl, vindex, _, _, _, err = tc.si.FindTableOrVindex(t)
if err != nil {
if err != nil && !isInfSchema {
// if we are dealing with a system table, it might not be available in the vschema, but that is OK
return err
}
if tbl == nil && vindex != nil {
Expand Down

0 comments on commit ab573a9

Please sign in to comment.