Skip to content

Commit 3ccd7e6

Browse files
authored
executor: skip execution when build query for VIEW in I_S (#58203)
close #58184
1 parent 1d53c85 commit 3ccd7e6

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

pkg/executor/infoschema_reader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ func (e *hugeMemTableRetriever) dataForColumnsInTable(
10621062
// Build plan is not thread safe, there will be concurrency on sessionctx.
10631063
if err := runWithSystemSession(internalCtx, sctx, func(s sessionctx.Context) error {
10641064
is := sessiontxn.GetTxnManager(s).GetTxnInfoSchema()
1065-
planBuilder, _ := plannercore.NewPlanBuilder().Init(s.GetPlanCtx(), is, hint.NewQBHintHandler(nil))
1065+
planBuilder, _ := plannercore.NewPlanBuilder(plannercore.PlanBuilderOptNoExecution{}).Init(s.GetPlanCtx(), is, hint.NewQBHintHandler(nil))
10661066
var err error
10671067
viewLogicalPlan, err = planBuilder.BuildDataSourceFromView(ctx, schema, tbl, nil, nil)
10681068
return errors.Trace(err)

pkg/executor/infoschema_reader_test.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -746,21 +746,23 @@ func TestShowColumnsWithSubQueryView(t *testing.T) {
746746
tk := testkit.NewTestKit(t, store)
747747
tk.MustExec("use test")
748748

749-
if tk.MustQuery("select @@tidb_schema_cache_size > 0").Equal(testkit.Rows("1")) {
750-
// infoschema v2 requires network, so it cannot be tested this way.
751-
t.Skip()
752-
}
749+
tk.MustExec("set @@global.tidb_schema_cache_size = 0;")
750+
t.Cleanup(func() {
751+
tk.MustExec("set @@global.tidb_schema_cache_size = default;")
752+
})
753753

754754
tk.MustExec("CREATE TABLE added (`id` int(11), `name` text, `some_date` timestamp);")
755755
tk.MustExec("CREATE TABLE incremental (`id` int(11), `name`text, `some_date` timestamp);")
756756
tk.MustExec("create view temp_view as (select * from `added` where id > (select max(id) from `incremental`));")
757757
// Show columns should not send coprocessor request to the storage.
758-
require.NoError(t, failpoint.Enable("tikvclient/tikvStoreSendReqResult", `return("timeout")`))
758+
testfailpoint.Enable(t, "tikvclient/tikvStoreSendReqResult", `return("timeout")`)
759+
testfailpoint.Enable(t, "github.com/pingcap/tidb/pkg/planner/core/BuildDataSourceFailed", "panic")
760+
759761
tk.MustQuery("show columns from temp_view;").Check(testkit.Rows(
760762
"id int(11) YES <nil> ",
761763
"name text YES <nil> ",
762764
"some_date timestamp YES <nil> "))
763-
require.NoError(t, failpoint.Disable("tikvclient/tikvStoreSendReqResult"))
765+
tk.MustQuery("select COLUMN_NAME from information_schema.columns where table_name = 'temp_view';").Check(testkit.Rows("id", "name", "some_date"))
764766
}
765767

766768
// Code below are helper utilities for the test cases.

pkg/planner/core/logical_plan_builder.go

+1
Original file line numberDiff line numberDiff line change
@@ -5000,6 +5000,7 @@ func (b *PlanBuilder) BuildDataSourceFromView(ctx context.Context, dbName pmodel
50005000
terror.ErrorNotEqual(err, plannererrors.ErrNotSupportedYet) {
50015001
err = plannererrors.ErrViewInvalid.GenWithStackByArgs(dbName.O, tableInfo.Name.O)
50025002
}
5003+
failpoint.Inject("BuildDataSourceFailed", func() {})
50035004
return nil, err
50045005
}
50055006
pm := privilege.GetPrivilegeManager(b.ctx)

0 commit comments

Comments
 (0)