Skip to content

Commit ab573a9

Browse files
systayshanth96
authored andcommitted
handle system databases other that information_schema correctly (vitessio#12175)
Signed-off-by: Andres Taylor <[email protected]> Signed-off-by: Andres Taylor <[email protected]>
1 parent 280605c commit ab573a9

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

go/test/endtoend/vtgate/gen4/system_schema_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,15 @@ func TestMultipleSchemaPredicates(t *testing.T) {
214214
require.Error(t, err)
215215
require.Contains(t, err.Error(), "specifying two different database in the query is not supported")
216216
}
217+
218+
func TestQuerySystemTables(t *testing.T) {
219+
defer cluster.PanicHandler(t)
220+
ctx := context.Background()
221+
conn, err := mysql.Connect(ctx, &vtParams)
222+
require.NoError(t, err)
223+
defer conn.Close()
224+
225+
utils.Exec(t, conn, `select * from sys.sys_config`)
226+
utils.Exec(t, conn, "select * from mysql.`db`")
227+
utils.Exec(t, conn, "select * from performance_schema.error_log")
228+
}

go/vt/vtgate/planbuilder/testdata/systemtables_cases80.json

+57
Original file line numberDiff line numberDiff line change
@@ -1866,5 +1866,62 @@
18661866
"information_schema.key_column_usage"
18671867
]
18681868
}
1869+
},
1870+
{
1871+
"comment": "select variable, value from sys.sys_config",
1872+
"query": "select variable, value from sys.sys_config",
1873+
"plan": {
1874+
"QueryType": "SELECT",
1875+
"Original": "select variable, value from sys.sys_config",
1876+
"Instructions": {
1877+
"OperatorType": "Route",
1878+
"Variant": "DBA",
1879+
"Keyspace": {
1880+
"Name": "main",
1881+
"Sharded": false
1882+
},
1883+
"FieldQuery": "select variable, value from sys.sys_config where 1 != 1",
1884+
"Query": "select variable, value from sys.sys_config",
1885+
"Table": "sys.sys_config"
1886+
}
1887+
}
1888+
},
1889+
{
1890+
"comment": "select host, db from mysql.`db`",
1891+
"query": "select host, db from mysql.`db`",
1892+
"plan": {
1893+
"QueryType": "SELECT",
1894+
"Original": "select host, db from mysql.`db`",
1895+
"Instructions": {
1896+
"OperatorType": "Route",
1897+
"Variant": "DBA",
1898+
"Keyspace": {
1899+
"Name": "main",
1900+
"Sharded": false
1901+
},
1902+
"FieldQuery": "select host, db from mysql.db where 1 != 1",
1903+
"Query": "select host, db from mysql.db",
1904+
"Table": "mysql.db"
1905+
}
1906+
}
1907+
},
1908+
{
1909+
"comment": "select logged, prio from performance_schema.error_log",
1910+
"query": "select logged, prio from performance_schema.error_log",
1911+
"plan": {
1912+
"QueryType": "SELECT",
1913+
"Original": "select logged, prio from performance_schema.error_log",
1914+
"Instructions": {
1915+
"OperatorType": "Route",
1916+
"Variant": "DBA",
1917+
"Keyspace": {
1918+
"Name": "main",
1919+
"Sharded": false
1920+
},
1921+
"FieldQuery": "select logged, prio from performance_schema.error_log where 1 != 1",
1922+
"Query": "select logged, prio from performance_schema.error_log",
1923+
"Table": "performance_schema.error_log"
1924+
}
1925+
}
18691926
}
18701927
]

go/vt/vtgate/semantics/table_collector.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ func (tc *tableCollector) up(cursor *sqlparser.Cursor) error {
8787
isInfSchema := sqlparser.SystemSchema(t.Qualifier.String())
8888
var err error
8989
tbl, vindex, _, _, _, err = tc.si.FindTableOrVindex(t)
90-
if err != nil {
90+
if err != nil && !isInfSchema {
91+
// if we are dealing with a system table, it might not be available in the vschema, but that is OK
9192
return err
9293
}
9394
if tbl == nil && vindex != nil {

0 commit comments

Comments
 (0)