Skip to content

Commit

Permalink
Do not load table stats when booting vttablet. (#15715)
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schreiber <[email protected]>
  • Loading branch information
arthurschreiber committed Jun 10, 2024
1 parent c5379de commit e414183
Show file tree
Hide file tree
Showing 10 changed files with 230 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 @@ -259,9 +259,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()
`

// 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 @@ -105,19 +105,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 @@ -131,9 +133,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 @@ -416,7 +416,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 @@ -429,14 +431,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
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 @@ -252,6 +252,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 @@ -296,6 +307,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 @@ -364,6 +385,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 @@ -113,15 +113,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 @@ -1548,18 +1548,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 @@ -255,7 +255,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 e414183

Please sign in to comment.