Skip to content

Commit

Permalink
executor: skip execution when build query for VIEW in I_S (#58203) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Dec 13, 2024
1 parent 12fecbc commit 6ec3d04
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ func (e *hugeMemTableRetriever) dataForColumnsInTable(
// 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.GetPlanCtx(), is, hint.NewQBHintHandler(nil))
planBuilder, _ := plannercore.NewPlanBuilder(plannercore.PlanBuilderOptNoExecution{}).Init(s.GetPlanCtx(), is, hint.NewQBHintHandler(nil))
var err error
viewLogicalPlan, err = planBuilder.BuildDataSourceFromView(ctx, schema, tbl, nil, nil)
return errors.Trace(err)
Expand Down
14 changes: 8 additions & 6 deletions pkg/executor/infoschema_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,21 +744,23 @@ func TestShowColumnsWithSubQueryView(t *testing.T) {
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")

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

tk.MustExec("CREATE TABLE added (`id` int(11), `name` text, `some_date` timestamp);")
tk.MustExec("CREATE TABLE incremental (`id` int(11), `name`text, `some_date` timestamp);")
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")`))
testfailpoint.Enable(t, "tikvclient/tikvStoreSendReqResult", `return("timeout")`)
testfailpoint.Enable(t, "github.com/pingcap/tidb/pkg/planner/core/BuildDataSourceFailed", "panic")

tk.MustQuery("show columns from temp_view;").Check(testkit.Rows(
"id int(11) YES <nil> ",
"name text YES <nil> ",
"some_date timestamp YES <nil> "))
require.NoError(t, failpoint.Disable("tikvclient/tikvStoreSendReqResult"))
tk.MustQuery("select COLUMN_NAME from information_schema.columns where table_name = 'temp_view';").Check(testkit.Rows("id", "name", "some_date"))
}

// Code below are helper utilities for the test cases.
Expand Down
1 change: 1 addition & 0 deletions pkg/planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5000,6 +5000,7 @@ func (b *PlanBuilder) BuildDataSourceFromView(ctx context.Context, dbName pmodel
terror.ErrorNotEqual(err, plannererrors.ErrNotSupportedYet) {
err = plannererrors.ErrViewInvalid.GenWithStackByArgs(dbName.O, tableInfo.Name.O)
}
failpoint.Inject("BuildDataSourceFailed", func() {})
return nil, err
}
pm := privilege.GetPrivilegeManager(b.ctx)
Expand Down

0 comments on commit 6ec3d04

Please sign in to comment.