You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: alter_table_locality.go
    path of file: ./repos/cockroach/pkg/sql
    
    the code of the file until where you have to start completion: // Copyright 2020 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package sql

import (
	"context"
	"fmt"

	"github.com/cockroachdb/cockroach/pkg/kv"
	"github.com/cockroachdb/cockroach/pkg/server/telemetry"
	"github.com/cockroachdb/cockroach/pkg/sql/catalog"
	"github.com/cockroachdb/cockroach/pkg/sql/catalog/catenumpb"
	"github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb"
	"github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo"
	"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
	"github.com/cockroachdb/cockroach/pkg/sql/catalog/descs"
	"github.com/cockroachdb/cockroach/pkg/sql/catalog/multiregion"
	"github.com/cockroachdb/cockroach/pkg/sql/catalog/schemaexpr"
	"github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc"
	"github.com/cockroachdb/cockroach/pkg/sql/catalog/typedesc"
	"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
	"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
	"github.com/cockroachdb/cockroach/pkg/sql/sem/catid"
	"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
	"github.com/cockroachdb/
    
func (n *alterTableSetLocalityNode) startExec(params runParams) error {
	newLocality := n.n.Locality
	existingLocality := n.tableDesc.LocalityConfig

	existingLocalityTelemetryName, err := multiregion.TelemetryNameForLocalityConfig(existingLocality)
	if err != nil {
		return err
	}
	telemetry.Inc(
		sqltelemetry.AlterTableLocalityCounter(
			existingLocalityTelemetryName,
			multiregion.TelemetryNameForLocality(newLocality),
		),
	)

	// We should check index zone configs if moving to REGIONAL BY ROW.
	if err := params.p.validateZoneConfigForMultiRegionTableWasNotModifiedByUser(
		params.ctx,
		n.dbDesc,
		n.tableDesc,
	); err != nil {
		return err
	}

	// Look at the existing locality, and implement any changes required to move to
	// the new locality.
	switch existingLocality.Locality.(type) {
	case *catpb.LocalityConfig_Global_:
		switch newLocality.LocalityLevel {
		case tree.LocalityLevelGlobal:
			if err := n.alterTableLocalityToGlobal(params); err != nil {
				return err
			}
		case tree.LocalityLevelRow:
			if err := n.alterTableLocalityToRegionalByRow(
				params,
				newLocality,
			); err != nil {
				return err
			}
		case tree.LocalityLevelTable:
			if err := n.alterTableLocalityGlobalToRegionalByTable(params); err != nil {
				return err
			}
		default:
			return errors.AssertionFailedf("unknown table locality: %v", newLocality)
		}
	case *catpb.LocalityConfig_RegionalByTable_:
		switch newLocality.LocalityLevel {
		case tree.LocalityLevelGlobal:
			if err := n.alterTableLocalityToGlobal(params); err != nil {
				return err
			}
		case tree.LocalityLevelRow:
			if err := n.alterTableLocalityToRegionalByRow(
				params,
				newLocality,
			); err != nil {
				return err
			}
		case tree.LocalityLevelTable:
			if err := n.alterTableLocalityRegionalByTableToRegionalByTable(params); err != nil {
				return err
			}
		default:
			return errors.AssertionFailedf("unknown table locality: %v", newLocality)
		}
	case *catpb.LocalityConfig_RegionalByRow_:
		explicitColStart := n.tableDesc.PrimaryIndex.ExplicitColumnStartIdx()
		switch newLocality.LocalityLevel {
		case tree.LocalityLevelGlobal:
			return n.alterTableLocalityFromOrToRegionalByRow(
				params,
				tabledesc.LocalityConfigGlobal(),
				nil, /* mutationIdxAllowedInSameTxn */
				nil, /* newColumnName */
				nil, /*	newColumnID */
				nil, /*	newColumnDefaultExpr */
				n.tableDesc.PrimaryIndex.KeyColumnNames[explicitColStart:],
				n.tableDesc.PrimaryIndex.KeyColumnDirections[explicitColStart:],
			)
		case tree.LocalityLevelRow:
			if err := n.alterTableLocalityToRegionalByRow(
				params,
				newLocality,
			); err != nil {
				return err
			}
		case tree.LocalityLevelTable:
			return n.alterTableLocalityFromOrToRegionalByRow(
				params,
				tabledesc.LocalityConfigRegionalByTable(n.n.Locality.TableRegion),
				nil, /* mutationIdxAllowedInSameTxn */
				nil, /* newColumnName */
				nil, /*	newColumnID */
				nil, /*	newColumnDefaultExpr */
				n.tableDesc.PrimaryIndex.KeyColumnNames[explicitColStart:],
				n.tableDesc.PrimaryIndex.KeyColumnDirections[explicitColStart:],
			)
		default:
			return errors.AssertionFailedf("unknown table locality: %v", newLocality)
		}
	default:
		return errors.AssertionFailedf("unknown table locality: %v", existingLocality)
	}

	// Record this table alteration in the event log. This is an auditable log
	// event and is recorded in the same transaction as the table descriptor
	// update.
	return params.p.logEvent(params.ctx,
		n.tableDesc.ID,
		&eventpb.AlterTable{
			TableName: n.n.Name.String(),
		})
}