Skip to content

After running ANALYZE, the stats version of the table is still 0 #64400

@0xPoe

Description

@0xPoe

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

func TestAutoAnalyzeAfterAnalyzeVersionChange(t *testing.T) {
	store, dom := testkit.CreateMockStoreAndDomain(t)
	tk := testkit.NewTestKit(t, store)
	h := dom.StatsHandle()

	// Trigger the sync load by query.
	// set lease > 0 to trigger on-demand stats load.
	h.SetLease(time.Millisecond)
	// Set analyze version to 1.
	tk.MustExec("set @@tidb_analyze_version = 1")
	tk.MustExec("use test")
	tk.MustExec("create table t (a int, b int, index idx(a));")
	tk.MustExec("insert into t values (1, 2);")
	tk.MustExec("analyze table t")
	tbl, err := dom.InfoSchema().TableByName(context.Background(), ast.NewCIStr("test"), ast.NewCIStr("t"))
	require.NoError(t, err)
	tableInfo := tbl.Meta()
	statsTbl := h.GetPhysicalTableStats(tableInfo.ID, tableInfo)
	require.NotZero(t, statsTbl.LastAnalyzeVersion)
	require.Equal(t, 0, statsTbl.StatsVer)
}

2. What did you expect to see? (Required)

The stats version is 1.

3. What did you see instead (Required)

The stats version is 0.

4. What is your TiDB version? (Required)

master

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions