Skip to content

Commit 06f284e

Browse files
committed
sql: add hints package
This commit adds a new `sql/hints` package along with a `StatementHints` protobuf struct and some utility functions for working with it. Epic: None Release note: None
1 parent 7a39b97 commit 06f284e

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

pkg/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,7 @@ GO_TARGETS = [
20612061
"//pkg/sql/gcjob:gcjob",
20622062
"//pkg/sql/gcjob:gcjob_test",
20632063
"//pkg/sql/gcjob_test:gcjob_test_test",
2064+
"//pkg/sql/hints:hints",
20642065
"//pkg/sql/idxrecommendations:idxrecommendations",
20652066
"//pkg/sql/idxrecommendations:idxrecommendations_test",
20662067
"//pkg/sql/idxusage:idxusage",

pkg/gen/protobuf.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ PROTOBUF_SRCS = [
6363
"//pkg/sql/catalog/schematelemetry/schematelemetrycontroller:schematelemetrycontroller_go_proto",
6464
"//pkg/sql/contentionpb:contentionpb_go_proto",
6565
"//pkg/sql/execinfrapb:execinfrapb_go_proto",
66+
"//pkg/sql/hints:hints_go_proto",
6667
"//pkg/sql/inverted:inverted_go_proto",
6768
"//pkg/sql/lex:lex_go_proto",
6869
"//pkg/sql/pgwire/pgerror:pgerror_go_proto",

pkg/sql/hints/BUILD.bazel

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
load("@rules_proto//proto:defs.bzl", "proto_library")
2+
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
3+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
4+
5+
go_library(
6+
name = "hints",
7+
srcs = ["statement_hint.go"],
8+
embed = [":hints_go_proto"],
9+
importpath = "github.com/cockroachdb/cockroach/pkg/sql/hints",
10+
visibility = ["//visibility:public"],
11+
deps = ["//pkg/util/protoutil"],
12+
)
13+
14+
go_proto_library(
15+
name = "hints_go_proto",
16+
compilers = ["//pkg/cmd/protoc-gen-gogoroach:protoc-gen-gogoroach_compiler"],
17+
importpath = "github.com/cockroachdb/cockroach/pkg/sql/hints",
18+
proto = ":hints_proto",
19+
visibility = ["//visibility:public"],
20+
deps = ["@com_github_gogo_protobuf//gogoproto"],
21+
)
22+
23+
proto_library(
24+
name = "hints_proto",
25+
srcs = ["statement_hint.proto"],
26+
strip_import_prefix = "/pkg",
27+
visibility = ["//visibility:public"],
28+
deps = ["@com_github_gogo_protobuf//gogoproto:gogo_proto"],
29+
)

pkg/sql/hints/statement_hint.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2025 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the CockroachDB Software License
4+
// included in the /LICENSE file.
5+
6+
package hints
7+
8+
import "github.com/cockroachdb/cockroach/pkg/util/protoutil"
9+
10+
// NewStatementHints converts the raw bytes from system.statement_hints into a
11+
// StatementHints object.
12+
func NewStatementHints(bytes []byte) (*StatementHints, error) {
13+
res := &StatementHints{}
14+
if err := protoutil.Unmarshal(bytes, res); err != nil {
15+
return nil, err
16+
}
17+
return res, nil
18+
}
19+
20+
// ToBytes converts the StatementHints to a raw bytes representation that can be
21+
// inserted into the system.statement_hints table.
22+
func (hints *StatementHints) ToBytes() ([]byte, error) {
23+
return protoutil.Marshal(hints)
24+
}

pkg/sql/hints/statement_hint.proto

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2025 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the CockroachDB Software License
4+
// included in the /LICENSE file.
5+
6+
syntax = "proto3";
7+
package hints;
8+
9+
import "gogoproto/gogo.proto";
10+
11+
// StatementHints consolidates the "external" hints that can be applied to
12+
// statements with a given fingerprint using the system.statement_hints table.
13+
message StatementHints {
14+
// TODO: add a field for each type of statement hint.
15+
}

0 commit comments

Comments
 (0)