Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support views in BaseShowTablesWithSizes for MySQL 8.0 #13394

Merged
merged 4 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions go/mysql/flavor_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ GROUP BY t.table_name, t.table_type, t.create_time, t.table_comment`
// - We utilize `INFORMATION_SCHEMA`.`TABLES`.`CREATE_OPTIONS` column to do early pruning before the JOIN.
// - `TABLES`.`TABLE_NAME` has `utf8mb4_0900_ai_ci` collation. `INNODB_TABLESPACES`.`NAME` has `utf8mb3_general_ci`.
// We normalize the collation to get better query performance (we force the casting at the time of our choosing)
// - `create_options` is NULL for views, and therefore we need an additional UNION ALL to include views
const TablesWithSize80 = `SELECT t.table_name,
t.table_type,
UNIX_TIMESTAMP(t.create_time),
Expand All @@ -378,6 +379,16 @@ UNION ALL
t.table_schema = database() AND t.create_options = 'partitioned'
GROUP BY
t.table_schema, t.table_name, t.table_type, t.create_time, t.table_comment
UNION ALL
SELECT t.table_name,
t.table_type,
UNIX_TIMESTAMP(t.create_time),
t.table_comment,
NULL,
NULL
FROM information_schema.tables t
WHERE
t.table_schema = database() AND t.table_type='VIEW'
`

// baseShowTablesWithSizes is part of the Flavor interface.
Expand Down
44 changes: 44 additions & 0 deletions go/vt/vttablet/endtoend/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"io"
"math"
"net/http"
"reflect"
"strings"
Expand Down Expand Up @@ -944,3 +945,46 @@ func TestHexAndBitBindVar(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, `[[INT64(10) UINT64(10) INT64(2480) UINT64(2480)]]`, fmt.Sprintf("%v", qr.Rows))
}

// Test will validate drop view ddls.
func TestShowTablesWithSizes(t *testing.T) {
ctx := context.Background()
conn, err := mysql.Connect(ctx, &connParams)
if err != nil {
t.Error(err)
return
}
defer conn.Close()

setupQueries := []string{
`drop view if exists v1`,
`drop table if exists t1`,
`drop table if exists employees`,
`create table t1 (id int primary key)`,
`create view v1 as select * from t1`,
`CREATE TABLE employees (id INT NOT NULL, store_id INT) PARTITION BY HASH(store_id) PARTITIONS 4`,
}
for _, query := range setupQueries {
_, err := conn.ExecuteFetch(query, 1, false)
require.NoError(t, err)
}
expectTables := map[string]([]string){ // TABLE_TYPE, TABLE_COMMENT
"t1": []string{"BASE TABLE", ""},
"v1": []string{"VIEW", "VIEW"},
"employees": []string{"BASE TABLE", ""},
}

rs, err := conn.ExecuteFetch(conn.BaseShowTablesWithSizes(), math.MaxInt, false)
require.NoError(t, err)
require.NotEmpty(t, rs.Rows)

assert.Equal(t, len(expectTables), len(rs.Rows))
foundTables := map[string]([]string){}
for _, row := range rs.Rows {
tableName := row[0].ToString()
_, ok := expectTables[tableName]
assert.True(t, ok)
foundTables[tableName] = []string{row[1].ToString(), row[3].ToString()} // TABLE_TYPE, TABLE_COMMENT
}
assert.Equal(t, expectTables, foundTables)
}