Skip to content

Commit

Permalink
Do not load table stats when booting vttablet. (vitessio#15715)
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 11, 2024
1 parent d8df704 commit 580806b
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 105 deletions.
11 changes: 10 additions & 1 deletion go/mysql/flavor_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,18 @@ func (mysqlFlavor) disableBinlogPlaybackCommand() string {

// 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()
`

// TablesWithSize56 is a query to select table along with size for mysql 5.6
const TablesWithSize56 = `SELECT table_name,
table_type,
Expand Down
15 changes: 11 additions & 4 deletions go/mysql/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,21 @@ var BaseShowTablesFields = []*querypb.Field{{
ColumnLength: 6144,
Charset: collations.CollationUtf8ID,
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 @@ -192,9 +194,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 @@ -399,7 +399,9 @@ func newTabletEnvironment(ddls []sqlparser.DDLStatement, opts *Options) (*tablet
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 @@ -412,14 +414,21 @@ func newTabletEnvironment(ddls []sqlparser.DDLStatement, opts *Options) (*tablet
}
}
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
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 @@ -112,15 +112,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 @@ -1533,18 +1533,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 @@ -246,7 +246,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 580806b

Please sign in to comment.