From dcd4047b4e4c1901471875a652ae115d0813c535 Mon Sep 17 00:00:00 2001 From: lance6716 Date: Fri, 13 Dec 2024 09:17:40 +0800 Subject: [PATCH 1/3] executor: skip execution when build query for VIEW in I_S (#58203) Signed-off-by: lance6716 --- executor/infoschema_reader.go | 76 ++++++++++++++-------------- executor/infoschema_reader_test.go | 3 ++ planner/core/logical_plan_builder.go | 1 + 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/executor/infoschema_reader.go b/executor/infoschema_reader.go index 98424e50fb15a..0d2656468e01e 100644 --- a/executor/infoschema_reader.go +++ b/executor/infoschema_reader.go @@ -842,7 +842,7 @@ func (e *hugeMemTableRetriever) dataForColumnsInTable(ctx context.Context, sctx // Build plan is not thread safe, there will be concurrency on sessionctx. if err := runWithSystemSession(internalCtx, sctx, func(s sessionctx.Context) error { is := sessiontxn.GetTxnManager(s).GetTxnInfoSchema() - planBuilder, _ := plannercore.NewPlanBuilder().Init(s, is, &hint.BlockHintProcessor{}) + planBuilder, _ := plannercore.NewPlanBuilder(plannercore.PlanBuilderOptNoExecution{}).Init(s, is, &hint.BlockHintProcessor{}) var err error viewLogicalPlan, err = planBuilder.BuildDataSourceFromView(ctx, schema.Name, tbl, nil, nil) return errors.Trace(err) @@ -1003,27 +1003,27 @@ ForColumnsTag: } } record := types.MakeDatums( - infoschema.CatalogVal, // TABLE_CATALOG - schema.Name.O, // TABLE_SCHEMA - tbl.Name.O, // TABLE_NAME - col.Name.O, // COLUMN_NAME - i, // ORDINAL_POSITION - columnDefault, // COLUMN_DEFAULT - columnDesc.Null, // IS_NULLABLE - types.TypeToStr(ft.GetType(), ft.GetCharset()), // DATA_TYPE - charMaxLen, // CHARACTER_MAXIMUM_LENGTH - charOctLen, // CHARACTER_OCTET_LENGTH - numericPrecision, // NUMERIC_PRECISION - numericScale, // NUMERIC_SCALE - datetimePrecision, // DATETIME_PRECISION - columnDesc.Charset, // CHARACTER_SET_NAME - columnDesc.Collation, // COLLATION_NAME - columnType, // COLUMN_TYPE - columnDesc.Key, // COLUMN_KEY - columnDesc.Extra, // EXTRA + infoschema.CatalogVal, // TABLE_CATALOG + schema.Name.O, // TABLE_SCHEMA + tbl.Name.O, // TABLE_NAME + col.Name.O, // COLUMN_NAME + i, // ORDINAL_POSITION + columnDefault, // COLUMN_DEFAULT + columnDesc.Null, // IS_NULLABLE + types.TypeToStr(ft.GetType(), ft.GetCharset()), // DATA_TYPE + charMaxLen, // CHARACTER_MAXIMUM_LENGTH + charOctLen, // CHARACTER_OCTET_LENGTH + numericPrecision, // NUMERIC_PRECISION + numericScale, // NUMERIC_SCALE + datetimePrecision, // DATETIME_PRECISION + columnDesc.Charset, // CHARACTER_SET_NAME + columnDesc.Collation, // COLLATION_NAME + columnType, // COLUMN_TYPE + columnDesc.Key, // COLUMN_KEY + columnDesc.Extra, // EXTRA strings.ToLower(privileges.PrivToString(priv, mysql.AllColumnPrivs, mysql.Priv2Str)), // PRIVILEGES - columnDesc.Comment, // COLUMN_COMMENT - col.GeneratedExprString, // GENERATION_EXPRESSION + columnDesc.Comment, // COLUMN_COMMENT + col.GeneratedExprString, // GENERATION_EXPRESSION ) e.rows = append(e.rows, record) i++ @@ -1460,12 +1460,12 @@ func (e *memtableRetriever) setDataFromEngines() { var rows [][]types.Datum rows = append(rows, types.MakeDatums( - "InnoDB", // Engine - "DEFAULT", // Support + "InnoDB", // Engine + "DEFAULT", // Support "Supports transactions, row-level locking, and foreign keys", // Comment - "YES", // Transactions - "YES", // XA - "YES", // Savepoints + "YES", // Transactions + "YES", // XA + "YES", // Savepoints ), ) e.rows = rows @@ -2229,14 +2229,14 @@ func (e *memtableRetriever) setDataForServersInfo(ctx sessionctx.Context) error rows := make([][]types.Datum, 0, len(serversInfo)) for _, info := range serversInfo { row := types.MakeDatums( - info.ID, // DDL_ID - info.IP, // IP - int(info.Port), // PORT - int(info.StatusPort), // STATUS_PORT - info.Lease, // LEASE - info.Version, // VERSION - info.GitHash, // GIT_HASH - info.BinlogStatus, // BINLOG_STATUS + info.ID, // DDL_ID + info.IP, // IP + int(info.Port), // PORT + int(info.StatusPort), // STATUS_PORT + info.Lease, // LEASE + info.Version, // VERSION + info.GitHash, // GIT_HASH + info.BinlogStatus, // BINLOG_STATUS stringutil.BuildStringFromLabels(info.Labels), // LABELS ) if sem.IsEnabled() { @@ -2314,10 +2314,10 @@ func (e *memtableRetriever) dataForTableTiFlashReplica(ctx sessionctx.Context, s progressString := types.TruncateFloatToString(progress, 2) progress, _ = strconv.ParseFloat(progressString, 64) record := types.MakeDatums( - schema.Name.O, // TABLE_SCHEMA - tbl.Name.O, // TABLE_NAME - tbl.ID, // TABLE_ID - int64(tbl.TiFlashReplica.Count), // REPLICA_COUNT + schema.Name.O, // TABLE_SCHEMA + tbl.Name.O, // TABLE_NAME + tbl.ID, // TABLE_ID + int64(tbl.TiFlashReplica.Count), // REPLICA_COUNT strings.Join(tbl.TiFlashReplica.LocationLabels, ","), // LOCATION_LABELS tbl.TiFlashReplica.Available, // AVAILABLE progress, // PROGRESS diff --git a/executor/infoschema_reader_test.go b/executor/infoschema_reader_test.go index ed6eed4fb4607..d6be579c46eba 100644 --- a/executor/infoschema_reader_test.go +++ b/executor/infoschema_reader_test.go @@ -855,11 +855,14 @@ func TestShowColumnsWithSubQueryView(t *testing.T) { tk.MustExec("create view temp_view as (select * from `added` where id > (select max(id) from `incremental`));") // Show columns should not send coprocessor request to the storage. require.NoError(t, failpoint.Enable("tikvclient/tikvStoreSendReqResult", `return("timeout")`)) + require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/planner/core/BuildDataSourceFailed", "panic")) tk.MustQuery("show columns from temp_view;").Check(testkit.Rows( "id int(11) YES ", "name text YES ", "some_date timestamp YES ")) + tk.MustQuery("select COLUMN_NAME from information_schema.columns where table_name = 'temp_view';").Check(testkit.Rows("id", "name", "some_date")) require.NoError(t, failpoint.Disable("tikvclient/tikvStoreSendReqResult")) + require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/planner/core/BuildDataSourceFailed")) } func TestNullColumns(t *testing.T) { diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 3c330c341d728..5c62614faa902 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -5324,6 +5324,7 @@ func (b *PlanBuilder) BuildDataSourceFromView(ctx context.Context, dbName model. terror.ErrorNotEqual(err, ErrNotSupportedYet) { err = ErrViewInvalid.GenWithStackByArgs(dbName.O, tableInfo.Name.O) } + failpoint.Inject("BuildDataSourceFailed", func() {}) return nil, err } pm := privilege.GetPrivilegeManager(b.ctx) From 8e10a7907423185a3a4f58f96d57b5ff1cddfec3 Mon Sep 17 00:00:00 2001 From: lance6716 Date: Fri, 13 Dec 2024 09:29:38 +0800 Subject: [PATCH 2/3] fix bazel Signed-off-by: lance6716 --- tools/check/check-bazel-prepare.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/check/check-bazel-prepare.sh b/tools/check/check-bazel-prepare.sh index 2a8d97ebdc767..3a0d285f3a0f7 100755 --- a/tools/check/check-bazel-prepare.sh +++ b/tools/check/check-bazel-prepare.sh @@ -19,6 +19,7 @@ # -o pipefail: sets the exit code of a pipeline to that of the rightmost command to exit with a non-zero status, # or to zero if all commands of the pipeline exit successfully. set -euo pipefail +rm -rf /home/jenkins/.cache/bazel/_bazel_jenkins/install/a09dbb90c658248f08f9aa0eba11997d before_checksum=`find . -type f \( -name '*.bazel' -o -name '*.bzl' \) -exec md5sum {} \;| sort -k 2` make bazel_prepare From 66a878c5946a997b6b63b0766ea364d564dcad2e Mon Sep 17 00:00:00 2001 From: lance6716 Date: Fri, 13 Dec 2024 09:43:51 +0800 Subject: [PATCH 3/3] fix fmt Signed-off-by: lance6716 --- executor/infoschema_reader.go | 74 +++++++++++++++++------------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/executor/infoschema_reader.go b/executor/infoschema_reader.go index 0d2656468e01e..ef11df6fb6870 100644 --- a/executor/infoschema_reader.go +++ b/executor/infoschema_reader.go @@ -1003,27 +1003,27 @@ ForColumnsTag: } } record := types.MakeDatums( - infoschema.CatalogVal, // TABLE_CATALOG - schema.Name.O, // TABLE_SCHEMA - tbl.Name.O, // TABLE_NAME - col.Name.O, // COLUMN_NAME - i, // ORDINAL_POSITION - columnDefault, // COLUMN_DEFAULT - columnDesc.Null, // IS_NULLABLE - types.TypeToStr(ft.GetType(), ft.GetCharset()), // DATA_TYPE - charMaxLen, // CHARACTER_MAXIMUM_LENGTH - charOctLen, // CHARACTER_OCTET_LENGTH - numericPrecision, // NUMERIC_PRECISION - numericScale, // NUMERIC_SCALE - datetimePrecision, // DATETIME_PRECISION - columnDesc.Charset, // CHARACTER_SET_NAME - columnDesc.Collation, // COLLATION_NAME - columnType, // COLUMN_TYPE - columnDesc.Key, // COLUMN_KEY - columnDesc.Extra, // EXTRA + infoschema.CatalogVal, // TABLE_CATALOG + schema.Name.O, // TABLE_SCHEMA + tbl.Name.O, // TABLE_NAME + col.Name.O, // COLUMN_NAME + i, // ORDINAL_POSITION + columnDefault, // COLUMN_DEFAULT + columnDesc.Null, // IS_NULLABLE + types.TypeToStr(ft.GetType(), ft.GetCharset()), // DATA_TYPE + charMaxLen, // CHARACTER_MAXIMUM_LENGTH + charOctLen, // CHARACTER_OCTET_LENGTH + numericPrecision, // NUMERIC_PRECISION + numericScale, // NUMERIC_SCALE + datetimePrecision, // DATETIME_PRECISION + columnDesc.Charset, // CHARACTER_SET_NAME + columnDesc.Collation, // COLLATION_NAME + columnType, // COLUMN_TYPE + columnDesc.Key, // COLUMN_KEY + columnDesc.Extra, // EXTRA strings.ToLower(privileges.PrivToString(priv, mysql.AllColumnPrivs, mysql.Priv2Str)), // PRIVILEGES - columnDesc.Comment, // COLUMN_COMMENT - col.GeneratedExprString, // GENERATION_EXPRESSION + columnDesc.Comment, // COLUMN_COMMENT + col.GeneratedExprString, // GENERATION_EXPRESSION ) e.rows = append(e.rows, record) i++ @@ -1460,12 +1460,12 @@ func (e *memtableRetriever) setDataFromEngines() { var rows [][]types.Datum rows = append(rows, types.MakeDatums( - "InnoDB", // Engine - "DEFAULT", // Support + "InnoDB", // Engine + "DEFAULT", // Support "Supports transactions, row-level locking, and foreign keys", // Comment - "YES", // Transactions - "YES", // XA - "YES", // Savepoints + "YES", // Transactions + "YES", // XA + "YES", // Savepoints ), ) e.rows = rows @@ -2229,14 +2229,14 @@ func (e *memtableRetriever) setDataForServersInfo(ctx sessionctx.Context) error rows := make([][]types.Datum, 0, len(serversInfo)) for _, info := range serversInfo { row := types.MakeDatums( - info.ID, // DDL_ID - info.IP, // IP - int(info.Port), // PORT - int(info.StatusPort), // STATUS_PORT - info.Lease, // LEASE - info.Version, // VERSION - info.GitHash, // GIT_HASH - info.BinlogStatus, // BINLOG_STATUS + info.ID, // DDL_ID + info.IP, // IP + int(info.Port), // PORT + int(info.StatusPort), // STATUS_PORT + info.Lease, // LEASE + info.Version, // VERSION + info.GitHash, // GIT_HASH + info.BinlogStatus, // BINLOG_STATUS stringutil.BuildStringFromLabels(info.Labels), // LABELS ) if sem.IsEnabled() { @@ -2314,10 +2314,10 @@ func (e *memtableRetriever) dataForTableTiFlashReplica(ctx sessionctx.Context, s progressString := types.TruncateFloatToString(progress, 2) progress, _ = strconv.ParseFloat(progressString, 64) record := types.MakeDatums( - schema.Name.O, // TABLE_SCHEMA - tbl.Name.O, // TABLE_NAME - tbl.ID, // TABLE_ID - int64(tbl.TiFlashReplica.Count), // REPLICA_COUNT + schema.Name.O, // TABLE_SCHEMA + tbl.Name.O, // TABLE_NAME + tbl.ID, // TABLE_ID + int64(tbl.TiFlashReplica.Count), // REPLICA_COUNT strings.Join(tbl.TiFlashReplica.LocationLabels, ","), // LOCATION_LABELS tbl.TiFlashReplica.Available, // AVAILABLE progress, // PROGRESS