diff --git a/pkg/sql/alter_table.go b/pkg/sql/alter_table.go index e5653dfb740d..4b73449bf5d2 100644 --- a/pkg/sql/alter_table.go +++ b/pkg/sql/alter_table.go @@ -346,8 +346,7 @@ func (n *alterTableNode) startExec(params runParams) error { case *tree.AlterTableAlterPrimaryKey: // Make sure that all nodes in the cluster are able to perform primary key changes before proceeding. - version := params.p.ExecCfg().Settings.Version.ActiveVersionOrEmpty(params.ctx) - if !version.IsActive(clusterversion.VersionPrimaryKeyChanges) { + if !params.p.ExecCfg().Settings.Version.IsActive(params.ctx, clusterversion.VersionPrimaryKeyChanges) { return pgerror.Newf(pgcode.FeatureNotSupported, "all nodes are not the correct version for primary key changes") } @@ -358,7 +357,7 @@ func (n *alterTableNode) startExec(params runParams) error { } if t.Sharded != nil { - if !version.IsActive(clusterversion.VersionHashShardedIndexes) { + if !params.p.ExecCfg().Settings.Version.IsActive(params.ctx, clusterversion.VersionHashShardedIndexes) { return invalidClusterForShardedIndexError } if !params.p.EvalContext().SessionData.HashShardedIndexesEnabled { diff --git a/pkg/sql/create_table.go b/pkg/sql/create_table.go index dae1992bd6d2..8b0b8bb348c7 100644 --- a/pkg/sql/create_table.go +++ b/pkg/sql/create_table.go @@ -1181,14 +1181,12 @@ func MakeTableDesc( // If all nodes in the cluster know how to handle secondary indexes with column families, // write the new version into new index descriptors. indexEncodingVersion := sqlbase.BaseIndexFormatVersion - // We can't use st.Version.IsActive because this method is sometimes called - // before the version has been initialized, leading to a panic. There are also - // cases where this function is called in tests where st is nil. - if st != nil { - if version := st.Version.ActiveVersionOrEmpty(ctx); version != (clusterversion.ClusterVersion{}) && - version.IsActive(clusterversion.VersionSecondaryIndexColumnFamilies) { - indexEncodingVersion = sqlbase.SecondaryIndexFamilyFormatVersion - } + // We can't use st.Version.IsActive because this method is used during + // server setup before the cluster version has been initialized. + version := st.Version.ActiveVersionOrEmpty(ctx) + if version != (clusterversion.ClusterVersion{}) && + version.IsActive(clusterversion.VersionSecondaryIndexColumnFamilies) { + indexEncodingVersion = sqlbase.SecondaryIndexFamilyFormatVersion } for i, def := range n.Defs { @@ -1210,7 +1208,7 @@ func MakeTableDesc( if st == nil { return desc, invalidClusterForShardedIndexError } - if version := st.Version.ActiveVersionOrEmpty(ctx); version == (clusterversion.ClusterVersion{}) || + if version == (clusterversion.ClusterVersion{}) || !version.IsActive(clusterversion.VersionHashShardedIndexes) { return desc, invalidClusterForShardedIndexError }