Skip to content

Commit

Permalink
executor: fix a bug that global temporary table send cop request (#58882
Browse files Browse the repository at this point in the history
) (#58979)

close #58875
  • Loading branch information
ti-chi-bot authored Jan 16, 2025
1 parent ed7e195 commit fea86c8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
24 changes: 12 additions & 12 deletions pkg/executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3539,6 +3539,10 @@ func buildNoRangeTableReader(b *executorBuilder, v *plannercore.PhysicalTableRea
dagReq.OutputOffsets = append(dagReq.OutputOffsets, uint32(i))
}

if e.table.Meta().TempTableType != model.TempTableNone {
e.dummy = true
}

return e, nil
}

Expand Down Expand Up @@ -3654,10 +3658,6 @@ func (b *executorBuilder) buildTableReader(v *plannercore.PhysicalTableReader) e
return nil
}

if ret.table.Meta().TempTableType != model.TempTableNone {
ret.dummy = true
}

ret.ranges = ts.Ranges
sctx := b.ctx.GetSessionVars().StmtCtx
sctx.TableIDs = append(sctx.TableIDs, ts.Table.ID)
Expand Down Expand Up @@ -3871,6 +3871,10 @@ func buildNoRangeIndexReader(b *executorBuilder, v *plannercore.PhysicalIndexRea
dagReq.OutputOffsets = append(dagReq.OutputOffsets, uint32(col.Index))
}

if e.table.Meta().TempTableType != model.TempTableNone {
e.dummy = true
}

return e, nil
}

Expand All @@ -3887,10 +3891,6 @@ func (b *executorBuilder) buildIndexReader(v *plannercore.PhysicalIndexReader) e
return nil
}

if ret.table.Meta().TempTableType != model.TempTableNone {
ret.dummy = true
}

ret.ranges = is.Ranges
sctx := b.ctx.GetSessionVars().StmtCtx
sctx.IndexNames = append(sctx.IndexNames, is.Table.Name.O+":"+is.Index.Name.O)
Expand Down Expand Up @@ -4057,6 +4057,10 @@ func buildNoRangeIndexLookUpReader(b *executorBuilder, v *plannercore.PhysicalIn
e.handleCols = v.CommonHandleCols
e.primaryKeyIndex = tables.FindPrimaryIndex(tbl.Meta())
}

if e.table.Meta().TempTableType != model.TempTableNone {
e.dummy = true
}
return e, nil
}

Expand All @@ -4073,10 +4077,6 @@ func (b *executorBuilder) buildIndexLookUpReader(v *plannercore.PhysicalIndexLoo
return nil
}

if ret.table.Meta().TempTableType != model.TempTableNone {
ret.dummy = true
}

ts := v.TablePlans[0].(*plannercore.PhysicalTableScan)

ret.ranges = is.Ranges
Expand Down
20 changes: 20 additions & 0 deletions pkg/executor/temporary_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package executor_test

import (
"context"
"strings"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -162,3 +163,22 @@ func assertTemporaryTableNoNetwork(t *testing.T, createTable func(*testkit.TestK
tk.MustExec("select * from tmp_t where id > 1 for update")
tk.MustExec("rollback")
}

func TestIssue58875(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)

tk.MustExec("use test")
tk.MustExec("drop table if exists users, users1;")
tk.MustExec("CREATE GLOBAL TEMPORARY TABLE users ( id BIGINT, v1 int, v2 int, v3 int, v4 int, PRIMARY KEY(id), index v1_index(v1,v2,v3) ) ON COMMIT DELETE ROWS;")
tk.MustExec("create table users1(id int, value int, index index_value(value));")
tk.MustExec("insert into users1 values(1,2);")
tk.MustExec("begin;")
res := tk.MustQuery("explain analyze select /*+ inl_join(users) */ * from users use index(v1_index) where v1 in (select value from users1);").Rows()
for _, row := range res {
// if access object contains 'table:users', the execution info should be empty.
if strings.Contains(row[4].(string), "table:users") && !strings.Contains(row[4].(string), "table:users1") {
require.Len(t, row[5].(string), 0)
}
}
}

0 comments on commit fea86c8

Please sign in to comment.