From 1995d2821c8c8c8184313981c2221fde9a6ed3fc Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Mon, 26 Jun 2023 09:28:55 +0000 Subject: [PATCH] refactored query again to combat the many unit test query format assumptions Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/mysql/flavor_mysql.go | 46 +++++++++---------- .../tabletserver/query_executor_test.go | 2 +- .../tabletserver/schema/engine_test.go | 2 +- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/go/mysql/flavor_mysql.go b/go/mysql/flavor_mysql.go index 027c381fba3..9b7152844e9 100644 --- a/go/mysql/flavor_mysql.go +++ b/go/mysql/flavor_mysql.go @@ -348,34 +348,32 @@ 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) -const TablesWithSize80 = ` -SELECT - t1.table_name, - t1.table_type, - UNIX_TIMESTAMP(t1.create_time), - t1.table_comment, - i1.file_size, - i1.allocated_size - FROM information_schema.tables t1 - LEFT JOIN information_schema.innodb_tablespaces i1 - ON i1.name = CONCAT(t1.table_schema, '/', t1.table_name) COLLATE utf8_general_ci +const TablesWithSize80 = `SELECT t.table_name, + t.table_type, + UNIX_TIMESTAMP(t.create_time), + t.table_comment, + i.file_size, + i.allocated_size + FROM information_schema.tables t + LEFT JOIN information_schema.innodb_tablespaces i + ON i.name = CONCAT(t.table_schema, '/', t.table_name) COLLATE utf8_general_ci WHERE - t1.table_schema = database() AND t1.create_options != 'partitioned' + t.table_schema = database() AND t.create_options != 'partitioned' UNION ALL -SELECT - t2.table_name, - t2.table_type, - UNIX_TIMESTAMP(t2.create_time), - t2.table_comment, - SUM(i2.file_size), - SUM(i2.allocated_size) - FROM information_schema.tables t2 - LEFT JOIN information_schema.innodb_tablespaces i2 - ON i2.name LIKE (CONCAT(t2.table_schema, '/', t2.table_name, '#p#%') COLLATE utf8_general_ci ) + SELECT + t.table_name, + t.table_type, + UNIX_TIMESTAMP(t.create_time), + t.table_comment, + SUM(i.file_size), + SUM(i.allocated_size) + FROM information_schema.tables t + LEFT JOIN information_schema.innodb_tablespaces i + ON i.name LIKE (CONCAT(t.table_schema, '/', t.table_name, '#p#%') COLLATE utf8_general_ci ) WHERE - t2.table_schema = database() AND t2.create_options = 'partitioned' + t.table_schema = database() AND t.create_options = 'partitioned' GROUP BY - t2.table_name, t2.table_type, t2.create_time, t2.table_comment + t.table_name, t.table_type, t.create_time, t.table_comment ` // baseShowTablesWithSizes is part of the Flavor interface. diff --git a/go/vt/vttablet/tabletserver/query_executor_test.go b/go/vt/vttablet/tabletserver/query_executor_test.go index 2a88c4a4854..526419c4f49 100644 --- a/go/vt/vttablet/tabletserver/query_executor_test.go +++ b/go/vt/vttablet/tabletserver/query_executor_test.go @@ -1369,7 +1369,7 @@ func setUpQueryExecutorTest(t *testing.T) *fakesqldb.DB { return db } -const baseShowTablesPattern = `[\s]*SELECT[\s]+(t|t1)[.]table_name.*` +const baseShowTablesPattern = `SELECT t\.table_name.*` func initQueryExecutorTestDB(db *fakesqldb.DB) { addQueryExecutorSupportedQueries(db) diff --git a/go/vt/vttablet/tabletserver/schema/engine_test.go b/go/vt/vttablet/tabletserver/schema/engine_test.go index 072e39400ef..c38a63e2481 100644 --- a/go/vt/vttablet/tabletserver/schema/engine_test.go +++ b/go/vt/vttablet/tabletserver/schema/engine_test.go @@ -43,7 +43,7 @@ import ( querypb "vitess.io/vitess/go/vt/proto/query" ) -const baseShowTablesPattern = `[\s]*SELECT[\s]+(t|t1)[.]table_name.*` +const baseShowTablesPattern = `SELECT t\.table_name.*` var mustMatch = utils.MustMatchFn(".Mutex")