Skip to content

Commit

Permalink
fix err
Browse files Browse the repository at this point in the history
Signed-off-by: guo-shaoge <shaoge1994@163.com>
  • Loading branch information
guo-shaoge authored and ti-chi-bot committed May 12, 2023
1 parent e664465 commit f8763f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion executor/cte.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (e *CTEExec) computeSeedPart(ctx context.Context) (err error) {
err = errors.Errorf("%v", r)
}
}()
failpoint.Inject("testCTEPanic", nil)
failpoint.Inject("testCTESeedPanic", nil)
e.curIter = 0
e.iterInTbl.SetIter(e.curIter)
chks := make([]*chunk.Chunk, 0, 10)
Expand Down Expand Up @@ -272,6 +272,7 @@ func (e *CTEExec) computeRecursivePart(ctx context.Context) (err error) {
err = errors.Errorf("%v", r)
}
}()
failpoint.Inject("testCTERecursivePanic", nil)
if e.recursiveExec == nil || e.iterInTbl.NumChunks() == 0 {
return
}
Expand Down
14 changes: 11 additions & 3 deletions executor/cte_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,15 +461,23 @@ func TestCTEsInView(t *testing.T) {
tk.MustQuery("select * from test.v;").Check(testkit.Rows("1"))
}

func TestCTESeedPanic(t *testing.T) {
func TestCTEPanic(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
tk.MustExec("create table t1(c1 int)")
tk.MustExec("insert into t1 values(1), (2), (3)")

fpPathPrefix := "github.com/pingcap/tidb/executor/"
require.NoError(t, failpoint.Enable(fpPathPrefix+"testCTEPanic", `panic("testCTEPanic")`))
fp := "testCTESeedPanic"
require.NoError(t, failpoint.Enable(fpPathPrefix+fp, fmt.Sprintf(`panic("%s")`, fp)))
err := tk.QueryToErr("with recursive cte1 as (select c1 from t1 union all select c1 + 1 from cte1 where c1 < 5) select t_alias_1.c1 from cte1 as t_alias_1 inner join cte1 as t_alias_2 on t_alias_1.c1 = t_alias_2.c1 order by c1")
require.Contains(t, err.Error(), "testCTEPanic")
require.Contains(t, err.Error(), fp)
require.NoError(t, failpoint.Disable(fpPathPrefix+fp))

fp = "testCTERecursivePanic"
require.NoError(t, failpoint.Enable(fpPathPrefix+fp, fmt.Sprintf(`panic("%s")`, fp)))
err = tk.QueryToErr("with recursive cte1 as (select c1 from t1 union all select c1 + 1 from cte1 where c1 < 5) select t_alias_1.c1 from cte1 as t_alias_1 inner join cte1 as t_alias_2 on t_alias_1.c1 = t_alias_2.c1 order by c1")
require.Contains(t, err.Error(), fp)
require.NoError(t, failpoint.Disable(fpPathPrefix+fp))
}

0 comments on commit f8763f0

Please sign in to comment.