Skip to content

Commit

Permalink
Do not load table stats when booting vttablet.
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schreiber <arthurschreiber@github.com>
  • Loading branch information
arthurschreiber committed Jun 10, 2024
1 parent 6fb0f0e commit f1f2596
Show file tree
Hide file tree
Showing 10 changed files with 232 additions and 107 deletions.
11 changes: 10 additions & 1 deletion go/mysql/flavor_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,18 @@ func (mysqlFlavor) readBinlogEvent(c *Conn) (BinlogEvent, error) {

// baseShowTables is part of the Flavor interface.
func (mysqlFlavor) baseShowTables() string {
return "SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()"
return BaseShowTables
}

const BaseShowTables = `SELECT t.table_name,
t.table_type,
UNIX_TIMESTAMP(t.create_time),
t.table_comment
FROM information_schema.tables t
WHERE
t.table_schema = database()
`

// TablesWithSize80 is a query to select table along with size for mysql 8.0
//
// Note the following:
Expand Down
15 changes: 11 additions & 4 deletions go/mysql/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,21 @@ var BaseShowTablesFields = []*querypb.Field{{
ColumnLength: 6144,
Charset: uint32(collations.SystemCollation.Collation),
Flags: uint32(querypb.MySqlFlag_NOT_NULL_FLAG),
}, {
}}

var BaseShowTablesWithSizesFields = append(BaseShowTablesFields, &querypb.Field{
Name: "i.file_size",
Type: querypb.Type_INT64,
ColumnLength: 11,
Charset: collations.CollationBinaryID,
Flags: uint32(querypb.MySqlFlag_BINARY_FLAG | querypb.MySqlFlag_NUM_FLAG),
}, {
}, &querypb.Field{
Name: "i.allocated_size",
Type: querypb.Type_INT64,
ColumnLength: 11,
Charset: collations.CollationBinaryID,
Flags: uint32(querypb.MySqlFlag_BINARY_FLAG | querypb.MySqlFlag_NUM_FLAG),
}}
})

// BaseShowTablesRow returns the fields from a BaseShowTables or
// BaseShowTablesForTable command.
Expand All @@ -104,9 +106,14 @@ func BaseShowTablesRow(tableName string, isView bool, comment string) []sqltypes
sqltypes.MakeTrusted(sqltypes.VarChar, []byte(tableType)),
sqltypes.MakeTrusted(sqltypes.Int64, []byte("1427325875")), // unix_timestamp(create_time)
sqltypes.MakeTrusted(sqltypes.VarChar, []byte(comment)),
}
}

func BaseShowTablesWithSizesRow(tableName string, isView bool, comment string) []sqltypes.Value {
return append(BaseShowTablesRow(tableName, isView, comment),
sqltypes.MakeTrusted(sqltypes.Int64, []byte("100")), // file_size
sqltypes.MakeTrusted(sqltypes.Int64, []byte("150")), // allocated_size
}
)
}

// ShowPrimaryFields contains the fields for a BaseShowPrimary.
Expand Down
17 changes: 13 additions & 4 deletions go/vt/vtexplain/vtexplain_vttablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,9 @@ func newTabletEnvironment(ddls []sqlparser.DDLStatement, opts *Options, collatio
tEnv.addResult(query, result)
}

showTableRows := make([][]sqltypes.Value, 0, 4)
showTableRows := make([][]sqltypes.Value, 0, len(ddls))
showTableWithSizesRows := make([][]sqltypes.Value, 0, len(ddls))

for _, ddl := range ddls {
table := ddl.GetTable().Name.String()
options := ""
Expand All @@ -442,14 +444,21 @@ func newTabletEnvironment(ddls []sqlparser.DDLStatement, opts *Options, collatio
}
}
showTableRows = append(showTableRows, mysql.BaseShowTablesRow(table, false, options))
showTableWithSizesRows = append(showTableWithSizesRows, mysql.BaseShowTablesWithSizesRow(table, true, options))
}
tEnv.addResult(mysql.TablesWithSize57, &sqltypes.Result{

tEnv.addResult(mysql.BaseShowTables, &sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
Rows: showTableRows,
})

tEnv.addResult(mysql.TablesWithSize57, &sqltypes.Result{
Fields: mysql.BaseShowTablesWithSizesFields,
Rows: showTableWithSizesRows,
})
tEnv.addResult(mysql.TablesWithSize80, &sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
Rows: showTableRows,
Fields: mysql.BaseShowTablesWithSizesFields,
Rows: showTableWithSizesRows,
})

indexRows := make([][]sqltypes.Value, 0, 4)
Expand Down
28 changes: 28 additions & 0 deletions go/vt/vttablet/tabletserver/health_streamer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,17 @@ func TestReloadSchema(t *testing.T) {
"product|BASE TABLE|1684735966||114688|114688",
"users|BASE TABLE|1684735966||114688|114688",
))

db.AddQuery(mysql.BaseShowTables,
sqltypes.MakeTestResult(
sqltypes.MakeTestFields(
"TABLE_NAME | TABLE_TYPE | UNIX_TIMESTAMP(t.create_time) | TABLE_COMMENT",
"varchar|varchar|int64|varchar",
),
"product|BASE TABLE|1684735966|",
"users|BASE TABLE|1684735966|",
))

db.AddQueryPattern("SELECT COLUMN_NAME as column_name.*", sqltypes.MakeTestResult(
sqltypes.MakeTestFields(
"column_name",
Expand Down Expand Up @@ -293,6 +304,16 @@ func TestReloadSchema(t *testing.T) {
"users|BASE TABLE|1684735967||114688|114688",
))

db.AddQuery(mysql.BaseShowTables,
sqltypes.MakeTestResult(
sqltypes.MakeTestFields(
"TABLE_NAME | TABLE_TYPE | UNIX_TIMESTAMP(t.create_time) | TABLE_COMMENT",
"varchar|varchar|int64|varchar",
),
"product|BASE TABLE|1684735967|",
"users|BASE TABLE|1684735967|",
))

var wg sync.WaitGroup
wg.Add(1)
go func() {
Expand Down Expand Up @@ -359,6 +380,13 @@ func TestReloadView(t *testing.T) {
"varchar|varchar|int64|varchar|int64|int64",
),
))
db.AddQuery(mysql.BaseShowTables,
sqltypes.MakeTestResult(
sqltypes.MakeTestFields(
"TABLE_NAME | TABLE_TYPE | UNIX_TIMESTAMP(t.create_time) | TABLE_COMMENT",
"varchar|varchar|int64|varchar",
),
))
db.AddQueryPattern("SELECT COLUMN_NAME as column_name.*", sqltypes.MakeTestResult(
sqltypes.MakeTestFields(
"column_name",
Expand Down
25 changes: 18 additions & 7 deletions go/vt/vttablet/tabletserver/query_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,26 @@ func TestGetPlanPanicDuetoEmptyQuery(t *testing.T) {
}

func addSchemaEngineQueries(db *fakesqldb.DB) {
db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
db.AddQueryPattern(baseShowTablesWithSizesPattern, &sqltypes.Result{
Fields: mysql.BaseShowTablesWithSizesFields,
Rows: [][]sqltypes.Value{
mysql.BaseShowTablesRow("test_table_01", false, ""),
mysql.BaseShowTablesRow("test_table_02", false, ""),
mysql.BaseShowTablesRow("test_table_03", false, ""),
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"),
mysql.BaseShowTablesWithSizesRow("test_table_01", false, ""),
mysql.BaseShowTablesWithSizesRow("test_table_02", false, ""),
mysql.BaseShowTablesWithSizesRow("test_table_03", false, ""),
mysql.BaseShowTablesWithSizesRow("seq", false, "vitess_sequence"),
mysql.BaseShowTablesWithSizesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"),
}})
db.AddQuery(mysql.BaseShowTables,
&sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
Rows: [][]sqltypes.Value{
mysql.BaseShowTablesRow("test_table_01", false, ""),
mysql.BaseShowTablesRow("test_table_02", false, ""),
mysql.BaseShowTablesRow("test_table_03", false, ""),
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"),
},
})
db.AddQuery("show status like 'Innodb_rows_read'", sqltypes.MakeTestResult(sqltypes.MakeTestFields(
"Variable_name|Value",
"varchar|int64"),
Expand Down
21 changes: 15 additions & 6 deletions go/vt/vttablet/tabletserver/query_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1591,18 +1591,27 @@ func setUpQueryExecutorTest(t *testing.T) *fakesqldb.DB {
return db
}

const baseShowTablesPattern = `SELECT t\.table_name.*`
const baseShowTablesWithSizesPattern = `SELECT t\.table_name.*SUM\(i\.file_size\).*`

func initQueryExecutorTestDB(db *fakesqldb.DB) {
addQueryExecutorSupportedQueries(db)
db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
db.AddQueryPattern(baseShowTablesWithSizesPattern, &sqltypes.Result{
Fields: mysql.BaseShowTablesWithSizesFields,
Rows: [][]sqltypes.Value{
mysql.BaseShowTablesRow("test_table", false, ""),
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"),
mysql.BaseShowTablesWithSizesRow("test_table", false, ""),
mysql.BaseShowTablesWithSizesRow("seq", false, "vitess_sequence"),
mysql.BaseShowTablesWithSizesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"),
},
})
db.AddQuery(mysql.BaseShowTables,
&sqltypes.Result{
Fields: mysql.BaseShowTablesFields,
Rows: [][]sqltypes.Value{
mysql.BaseShowTablesRow("test_table", false, ""),
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"),
},
})
db.AddQuery("show status like 'Innodb_rows_read'", sqltypes.MakeTestResult(sqltypes.MakeTestFields(
"Variable_name|Value",
"varchar|int64"),
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/tabletserver/schema/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (se *Engine) Open() error {
}
se.notifiers = make(map[string]notifier)

if err := se.reload(ctx, true); err != nil {
if err := se.reload(ctx, false); err != nil {
return err
}
if !se.SkipMetaCheck {
Expand Down
Loading

0 comments on commit f1f2596

Please sign in to comment.