Repository: pingcap/tidb
File: pkg/planner/core/casetest/integration_test.go (Go)

Code before:
			Plan []string
		}
		integrationSuiteData := GetIntegrationSuiteData()
		integrationSuiteData.LoadTestCases(t, &input, &output, cascades, caller)
		for i, tt := range input {
			testdata.OnRecord(func() {
				output[i].SQL = tt
				output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery(tt).Rows())
			})
			res := tk.MustQuery(tt)
			res.Check(testkit.Rows(output[i].Plan...))
		}

		tk.MustExec("drop table if exists t31240")
		tk.MustExec("create table t31240(a int, b int);")
		tk.MustExec("set @@tidb_allow_mpp = 0")
		tk.MustExec("set @@session.tidb_allow_tiflash_cop=ON")
		tbl, err := dom.InfoSchema().TableByName(context.Background(), ast.CIStr{O: "test", L: "test"}, ast.CIStr{O: "t31240", L: "t31240"})
		require.NoError(t, err)
		tbl.Meta().TiFlashReplica = &model.TiFlashReplicaInfo{Count: 1, Available: true}
		var issueInput []string
		var issueOutput []struct {
			SQL  string
			Plan []string
		}
		integrationSuiteData.LoadTestCasesByName("TestIssue31240", t, &issueInput, &issueOutput, cascades, caller)
		for i, tt := range issueInput {
			testdata.OnRecord(func() {
				issueOutput[i].SQL = tt
			})
			if strings.HasPrefix(tt, "set") {
				tk.MustExec(tt)
				continue
			}
			testdata.OnRecord(func() {
				issueOutput[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery(tt).Rows())
			})
			tk.MustQuery(tt).Check(testkit.Rows(issueOutput[i].Plan...))
		}
		tk.MustExec("drop table if exists t31240")

		tk.MustExec("CREATE TABLE `partsupp` (" +
			" `PS_PARTKEY` bigint(20) NOT NULL," +
			"`PS_SUPPKEY` bigint(20) NOT NULL," +
			"`PS_AVAILQTY` bigint(20) NOT NULL," +
			"`PS_SUPPLYCOST` decimal(15,2) NOT NULL," +
			"`PS_COMMENT` varchar(199) NOT NULL," +
			"PRIMARY KEY (`PS_PARTKEY`,`PS_SUPPKEY`) /*T![clustered_index] NONCLUSTERED */)")
		tk.MustExec("CREATE TABLE `supplier` (" +
			"`S_SUPPKEY` bigint(20) NOT NULL," +
			"`S_NAME` char(25) NOT NULL," +

Review comment (suggestion):
Two tables are created (partsupp and supplier) but only one DDL event is handled. This pattern is inconsistent with other tests in the codebase (e.g., TestCBOWithoutAnalyze in cbo_test.go:45-48) where each table creation is followed by a HandleNextDDLEventWithTxn call. A second call should be added to handle the DDL event for the supplier table.
```suggestion
		require.NoError(t, err)
		err = statstestutil.HandleNextDDLEventWithTxn(h)
		require.NoError(t, err)
```

Code after:

		var input []string
		var output []struct {
			SQL  string
			Plan []string
		}
		integrationSuiteData := GetIntegrationSuiteData()
		tk.MustExec("CREATE TABLE `partsupp` (" +
			" `PS_PARTKEY` bigint(20) NOT NULL," +
			"`PS_SUPPKEY` bigint(20) NOT NULL," +
			"`PS_AVAILQTY` bigint(20) NOT NULL," +
			"`PS_SUPPLYCOST` decimal(15,2) NOT NULL," +
			"`PS_COMMENT` varchar(199) NOT NULL," +
			"PRIMARY KEY (`PS_PARTKEY`,`PS_SUPPKEY`) /*T![clustered_index] NONCLUSTERED */)")
		tk.MustExec("CREATE TABLE `supplier` (" +
			"`S_SUPPKEY` bigint(20) NOT NULL," +
			"`S_NAME` char(25) NOT NULL," +
			"`S_ADDRESS` varchar(40) NOT NULL," +
			"`S_NATIONKEY` bigint(20) NOT NULL," +
			"`S_PHONE` char(15) NOT NULL," +
			"`S_ACCTBAL` decimal(15,2) NOT NULL," +
			"`S_COMMENT` varchar(101) NOT NULL," +
			"PRIMARY KEY (`S_SUPPKEY`) /*T![clustered_index] CLUSTERED */)")
		h := dom.StatsHandle()
		err := statstestutil.HandleNextDDLEventWithTxn(h)
		require.NoError(t, err)

		testkit.SetTiFlashReplica(t, dom, "test", "partsupp")
		testkit.SetTiFlashReplica(t, dom, "test", "supplier")

		tbl1, err := dom.InfoSchema().TableByName(context.Background(), ast.CIStr{O: "test", L: "test"}, ast.CIStr{O: "partsupp", L: "partsupp"})
		require.NoError(t, err)
		tbl2, err := dom.InfoSchema().TableByName(context.Background(), ast.CIStr{O: "test", L: "test"}, ast.CIStr{O: "supplier", L: "supplier"})
		require.NoError(t, err)
		statsTbl1 := h.GetPhysicalTableStats(tbl1.Meta().ID, tbl1.Meta())
		statsTbl1.RealtimeCount = 800000
		statsTbl2 := h.GetPhysicalTableStats(tbl2.Meta().ID, tbl2.Meta())
		statsTbl2.RealtimeCount = 10000

		integrationSuiteData.LoadTestCases(t, &input, &output, cascades, caller)
		for i, tt := range input {
			setStmt := strings.HasPrefix(tt, "set")
			testdata.OnRecord(func() {
				output[i].SQL = tt
				if !setStmt {
					output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery(tt).Rows())
				}
			})
			if setStmt {
				tk.MustExec(tt)
				continue