From 0d81af2f9e6759aa40f05c5663aa49ebb3e849f4 Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Fri, 20 May 2022 15:48:15 -0400 Subject: [PATCH] sql: version gate inverted index creation Make sure that it's not possible to create an inverted index until the cluster is at a new enough version. Release note: None --- docs/generated/settings/settings-for-tenants.txt | 2 +- docs/generated/settings/settings.html | 2 +- pkg/clusterversion/cockroach_versions.go | 8 ++++++++ pkg/clusterversion/key_string.go | 5 +++-- pkg/sql/create_index.go | 16 ++++++++++++++-- pkg/sql/create_table.go | 3 ++- 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/docs/generated/settings/settings-for-tenants.txt b/docs/generated/settings/settings-for-tenants.txt index 224523e98256..b8ea3233ef46 100644 --- a/docs/generated/settings/settings-for-tenants.txt +++ b/docs/generated/settings/settings-for-tenants.txt @@ -282,4 +282,4 @@ trace.jaeger.agent string the address of a Jaeger agent to receive traces using trace.opentelemetry.collector string address of an OpenTelemetry trace collector to receive traces using the otel gRPC protocol, as :. If no port is specified, 4317 will be used. trace.span_registry.enabled boolean true if set, ongoing traces can be seen at https:///#/debug/tracez trace.zipkin.collector string the address of a Zipkin instance to receive traces, as :. If no port is specified, 9411 will be used. -version version 22.1-8 set the active cluster version in the format '.' +version version 22.1-10 set the active cluster version in the format '.' diff --git a/docs/generated/settings/settings.html b/docs/generated/settings/settings.html index e957ab767320..776fb23bb5c7 100644 --- a/docs/generated/settings/settings.html +++ b/docs/generated/settings/settings.html @@ -213,6 +213,6 @@ trace.opentelemetry.collectorstringaddress of an OpenTelemetry trace collector to receive traces using the otel gRPC protocol, as :. If no port is specified, 4317 will be used. trace.span_registry.enabledbooleantrueif set, ongoing traces can be seen at https:///#/debug/tracez trace.zipkin.collectorstringthe address of a Zipkin instance to receive traces, as :. If no port is specified, 9411 will be used. -versionversion22.1-8set the active cluster version in the format '.' +versionversion22.1-10set the active cluster version in the format '.' diff --git a/pkg/clusterversion/cockroach_versions.go b/pkg/clusterversion/cockroach_versions.go index db06df6b7638..657798412435 100644 --- a/pkg/clusterversion/cockroach_versions.go +++ b/pkg/clusterversion/cockroach_versions.go @@ -366,6 +366,10 @@ const ( // keys at the Pebble layer. EnablePebbleFormatVersionRangeKeys + // TrigramInvertedIndexes enables the creation of trigram inverted indexes + // on strings. + TrigramInvertedIndexes + // ************************************************* // Step (1): Add new versions here. // Do not add new versions to a patch release. @@ -638,6 +642,10 @@ var versionsSingleton = keyedVersions{ Key: EnablePebbleFormatVersionRangeKeys, Version: roachpb.Version{Major: 22, Minor: 1, Internal: 8}, }, + { + Key: TrigramInvertedIndexes, + Version: roachpb.Version{Major: 22, Minor: 1, Internal: 10}, + }, // ************************************************* // Step (2): Add new versions here. diff --git a/pkg/clusterversion/key_string.go b/pkg/clusterversion/key_string.go index 12cb3c011ba6..21121db4e19d 100644 --- a/pkg/clusterversion/key_string.go +++ b/pkg/clusterversion/key_string.go @@ -67,11 +67,12 @@ func _() { _ = x[LocalTimestamps-56] _ = x[EnsurePebbleFormatVersionRangeKeys-57] _ = x[EnablePebbleFormatVersionRangeKeys-58] + _ = x[TrigramInvertedIndexes-59] } -const _Key_name = "V21_2Start22_1TargetBytesAvoidExcessAvoidDrainingNamesDrainingNamesMigrationTraceIDDoesntImplyStructuredRecordingAlterSystemTableStatisticsAddAvgSizeColAlterSystemStmtDiagReqsMVCCAddSSTableInsertPublicSchemaNamespaceEntryOnRestoreUnsplitRangesInAsyncGCJobsValidateGrantOptionPebbleFormatBlockPropertyCollectorProbeRequestSelectRPCsTakeTracingInfoInbandPreSeedTenantSpanConfigsSeedTenantSpanConfigsPublicSchemasWithDescriptorsEnsureSpanConfigReconciliationEnsureSpanConfigSubscriptionEnableSpanConfigStoreScanWholeRowsSCRAMAuthenticationUnsafeLossOfQuorumRecoveryRangeLogAlterSystemProtectedTimestampAddColumnEnableProtectedTimestampsForTenantDeleteCommentsWithDroppedIndexesRemoveIncompatibleDatabasePrivilegesAddRaftAppliedIndexTermMigrationPostAddRaftAppliedIndexTermMigrationDontProposeWriteTimestampForLeaseTransfersTenantSettingsTableEnablePebbleFormatVersionBlockPropertiesDisableSystemConfigGossipTriggerMVCCIndexBackfillerEnableLeaseHolderRemovalBackupResolutionInJobLooselyCoupledRaftLogTruncationChangefeedIdlenessBackupDoesNotOverwriteLatestAndCheckpointEnableDeclarativeSchemaChangerRowLevelTTLPebbleFormatSplitUserKeysMarkedIncrementalBackupSubdirDateStyleIntervalStyleCastRewriteEnableNewStoreRebalancerClusterLocksVirtualTableAutoStatsTableSettingsForecastStatsSuperRegionsEnableNewChangefeedOptionsSpanCountTablePreSeedSpanCountTableSeedSpanCountTableV22_1Start22_2LocalTimestampsEnsurePebbleFormatVersionRangeKeysEnablePebbleFormatVersionRangeKeys" +const _Key_name = "V21_2Start22_1TargetBytesAvoidExcessAvoidDrainingNamesDrainingNamesMigrationTraceIDDoesntImplyStructuredRecordingAlterSystemTableStatisticsAddAvgSizeColAlterSystemStmtDiagReqsMVCCAddSSTableInsertPublicSchemaNamespaceEntryOnRestoreUnsplitRangesInAsyncGCJobsValidateGrantOptionPebbleFormatBlockPropertyCollectorProbeRequestSelectRPCsTakeTracingInfoInbandPreSeedTenantSpanConfigsSeedTenantSpanConfigsPublicSchemasWithDescriptorsEnsureSpanConfigReconciliationEnsureSpanConfigSubscriptionEnableSpanConfigStoreScanWholeRowsSCRAMAuthenticationUnsafeLossOfQuorumRecoveryRangeLogAlterSystemProtectedTimestampAddColumnEnableProtectedTimestampsForTenantDeleteCommentsWithDroppedIndexesRemoveIncompatibleDatabasePrivilegesAddRaftAppliedIndexTermMigrationPostAddRaftAppliedIndexTermMigrationDontProposeWriteTimestampForLeaseTransfersTenantSettingsTableEnablePebbleFormatVersionBlockPropertiesDisableSystemConfigGossipTriggerMVCCIndexBackfillerEnableLeaseHolderRemovalBackupResolutionInJobLooselyCoupledRaftLogTruncationChangefeedIdlenessBackupDoesNotOverwriteLatestAndCheckpointEnableDeclarativeSchemaChangerRowLevelTTLPebbleFormatSplitUserKeysMarkedIncrementalBackupSubdirDateStyleIntervalStyleCastRewriteEnableNewStoreRebalancerClusterLocksVirtualTableAutoStatsTableSettingsForecastStatsSuperRegionsEnableNewChangefeedOptionsSpanCountTablePreSeedSpanCountTableSeedSpanCountTableV22_1Start22_2LocalTimestampsEnsurePebbleFormatVersionRangeKeysEnablePebbleFormatVersionRangeKeysTrigramInvertedIndexes" -var _Key_index = [...]uint16{0, 5, 14, 36, 54, 76, 113, 152, 175, 189, 230, 256, 275, 309, 321, 352, 376, 397, 425, 455, 483, 504, 517, 536, 570, 608, 642, 674, 710, 742, 778, 820, 839, 879, 911, 930, 954, 975, 1006, 1024, 1065, 1095, 1106, 1137, 1160, 1193, 1217, 1241, 1263, 1276, 1288, 1314, 1328, 1349, 1367, 1372, 1381, 1396, 1430, 1464} +var _Key_index = [...]uint16{0, 5, 14, 36, 54, 76, 113, 152, 175, 189, 230, 256, 275, 309, 321, 352, 376, 397, 425, 455, 483, 504, 517, 536, 570, 608, 642, 674, 710, 742, 778, 820, 839, 879, 911, 930, 954, 975, 1006, 1024, 1065, 1095, 1106, 1137, 1160, 1193, 1217, 1241, 1263, 1276, 1288, 1314, 1328, 1349, 1367, 1372, 1381, 1396, 1430, 1464, 1486} func (i Key) String() string { if i < 0 || i >= Key(len(_Key_index)-1) { diff --git a/pkg/sql/create_index.go b/pkg/sql/create_index.go index 34d9aae34096..b9a6fd16cbc2 100644 --- a/pkg/sql/create_index.go +++ b/pkg/sql/create_index.go @@ -14,9 +14,11 @@ import ( "context" "time" + "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/docs" "github.com/cockroachdb/cockroach/pkg/geo/geoindex" "github.com/cockroachdb/cockroach/pkg/server/telemetry" + "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql/catalog" "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" @@ -217,7 +219,8 @@ func makeIndexDescriptor( if err != nil { return nil, err } - if err := populateInvertedIndexDescriptor(column, &indexDesc, invCol); err != nil { + if err := populateInvertedIndexDescriptor( + params.ctx, params.ExecCfg().Settings, column, &indexDesc, invCol); err != nil { return nil, err } } @@ -303,7 +306,11 @@ func makeIndexDescriptor( // match (column is the catalog column, and invCol is the grammar node of // the column in the index creation statement). func populateInvertedIndexDescriptor( - column catalog.Column, indexDesc *descpb.IndexDescriptor, invCol tree.IndexElem, + ctx context.Context, + cs *cluster.Settings, + column catalog.Column, + indexDesc *descpb.IndexDescriptor, + invCol tree.IndexElem, ) error { indexDesc.InvertedColumnKinds = []descpb.IndexDescriptor_InvertedIndexColumnKind{descpb.IndexDescriptor_DEFAULT} switch column.GetType().Family() { @@ -340,6 +347,11 @@ func populateInvertedIndexDescriptor( // we're going to inverted index. switch invCol.OpClass { case "gin_trgm_ops": + if !cs.Version.IsActive(ctx, clusterversion.TrigramInvertedIndexes) { + return pgerror.Newf(pgcode.FeatureNotSupported, + "version %v must be finalized to create trigram inverted indexes", + clusterversion.ByKey(clusterversion.TrigramInvertedIndexes)) + } case "": return errors.WithHint( pgerror.New(pgcode.UndefinedObject, "data type text has no default operator class for access method \"gin\""), diff --git a/pkg/sql/create_table.go b/pkg/sql/create_table.go index ed10235647f0..fb4a2769cdae 100644 --- a/pkg/sql/create_table.go +++ b/pkg/sql/create_table.go @@ -1802,7 +1802,8 @@ func NewTableDesc( if err != nil { return nil, err } - if err := populateInvertedIndexDescriptor(column, &idx, columns[len(columns)-1]); err != nil { + if err := populateInvertedIndexDescriptor( + ctx, evalCtx.Settings, column, &idx, columns[len(columns)-1]); err != nil { return nil, err } }