Skip to content

Commit

Permalink
sql: version gate inverted index creation
Browse files Browse the repository at this point in the history
Make sure that it's not possible to create an inverted index until the
cluster is at a new enough version.

Release note: None
  • Loading branch information
jordanlewis committed Jun 4, 2022
1 parent f94de67 commit 9a18193
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/generated/settings/settings-for-tenants.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <host>:<port>. If no port is specified, 4317 will be used.
trace.span_registry.enabled boolean true if set, ongoing traces can be seen at https://<ui>/#/debug/tracez
trace.zipkin.collector string the address of a Zipkin instance to receive traces, as <host>:<port>. If no port is specified, 9411 will be used.
version version 22.1-8 set the active cluster version in the format '<major>.<minor>'
version version 22.1-10 set the active cluster version in the format '<major>.<minor>'
2 changes: 1 addition & 1 deletion docs/generated/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,6 @@
<tr><td><code>trace.opentelemetry.collector</code></td><td>string</td><td><code></code></td><td>address of an OpenTelemetry trace collector to receive traces using the otel gRPC protocol, as <host>:<port>. If no port is specified, 4317 will be used.</td></tr>
<tr><td><code>trace.span_registry.enabled</code></td><td>boolean</td><td><code>true</code></td><td>if set, ongoing traces can be seen at https://<ui>/#/debug/tracez</td></tr>
<tr><td><code>trace.zipkin.collector</code></td><td>string</td><td><code></code></td><td>the address of a Zipkin instance to receive traces, as <host>:<port>. If no port is specified, 9411 will be used.</td></tr>
<tr><td><code>version</code></td><td>version</td><td><code>22.1-8</code></td><td>set the active cluster version in the format '<major>.<minor>'</td></tr>
<tr><td><code>version</code></td><td>version</td><td><code>22.1-10</code></td><td>set the active cluster version in the format '<major>.<minor>'</td></tr>
</tbody>
</table>
8 changes: 8 additions & 0 deletions pkg/clusterversion/cockroach_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions pkg/clusterversion/key_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions pkg/sql/create_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -219,7 +221,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
}
}
Expand Down Expand Up @@ -312,7 +315,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 = []catpb.InvertedIndexColumnKind{catpb.InvertedIndexColumnKind_DEFAULT}
switch column.GetType().Family() {
Expand Down Expand Up @@ -349,6 +356,11 @@ func populateInvertedIndexDescriptor(
// we're going to inverted index.
switch invCol.OpClass {
case "gin_trgm_ops", "gist_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\""),
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 9a18193

Please sign in to comment.