code: func (d *ddlCtx) GetTableMaxRowID(startTS uint64, tbl table.PhysicalTable) (maxRowID int64, emptyTable bool, err error) {
  	maxRowID = int64(math.MaxInt64)
  	var columns []*model.ColumnInfo
  	if tbl.Meta().PKIsHandle {
  		for _, col := range tbl.Meta().Columns {
  			if mysql.HasPriKeyFlag(col.Flag) {
  				columns = []*model.ColumnInfo{col}
  				break
  			}
  		}
  	} else {
  		columns = []*model.ColumnInfo{model.NewExtraHandleColInfo()}
  	}
  
  	ctx := context.Background()
  	// build a desc scan of tblInfo, which limit is 1, we can use it to retrieve the last handle of the table.
  	result, err := d.buildDescTableScan(ctx, startTS, tbl, columns, 1)
  	if err != nil {
  		return maxRowID, false, errors.Trace(err)
  	}
  	defer terror.Call(result.Close)
  
  	chk := chunk.New(getColumnsTypes(columns), 1, 1)
  	err = result.Next(ctx, chk)
  	if err != nil {
  		return maxRowID, false, errors.Trace(err)
  	}
  
  	if chk.NumRows() == 0 {
  		// empty table
  		return maxRowID, true, nil
  	}
  	row := chk.GetRow(0)
  	maxRowID = row.GetInt64(0)
  	return maxRowID, false, nil
  }
docs: // GetTableMaxRowID gets the last row id of the table partition.