Skip to content

Commit 8d0f9c3

Browse files
committed
sql/hints: change StatementHint protobuf struct to union
This commit makes a few changes to the protobuf message used for serializing statement hints in the `system.statement_hints` table to prepare for future commits/PRs. No release note or migrations are necessary, since nothing is currently store nor read from the table. Epic: None Release note: None
1 parent 321213f commit 8d0f9c3

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

pkg/sql/hints/statement_hint.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@ package hints
77

88
import "github.com/cockroachdb/cockroach/pkg/util/protoutil"
99

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{}
10+
type StatementHint interface {
11+
protoutil.Message
12+
}
13+
14+
// NewStatementHint converts the raw bytes from system.statement_hints into a
15+
// StatementHintUnion object.
16+
func NewStatementHint(bytes []byte) (*StatementHintUnion, error) {
17+
res := &StatementHintUnion{}
1418
if err := protoutil.Unmarshal(bytes, res); err != nil {
1519
return nil, err
1620
}
1721
return res, nil
1822
}
1923

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+
// ToBytes converts the StatementHintUnion to a raw bytes representation that
25+
// can be inserted into the system.statement_hints table.
26+
func (hint *StatementHintUnion) ToBytes() ([]byte, error) {
27+
return protoutil.Marshal(hint)
2428
}

pkg/sql/hints/statement_hint.proto

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ package hints;
88

99
import "gogoproto/gogo.proto";
1010

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 {
11+
// StatementHintsUnion contains exactly one type of "external" statement hint
12+
// that can be applied to statements with a given fingerprint using the
13+
// system.statement_hints table.
14+
message StatementHintUnion {
1415
// TODO: add a field for each type of statement hint.
16+
// oneof value {}
1517
}

0 commit comments

Comments
 (0)