Skip to content

Commit

Permalink
sql: add sequence option info for identity columns under information_…
Browse files Browse the repository at this point in the history
…schema

Previously, for a column created with the `GENERATED ... AS IDENTITY
(seq_options)` syntax, the info for the sequence option is not saved in the
information schema.

This commit is to fix it. We parse the sequence options saved as a string in the
descriptor, so that it's much easier to extract specific option such as
sequence's start value or increment size.

To make sure that we get the same sequence option to generate
the sequence, we reuse `assignSequenceOptions()` by breaking it into several
helper functions.

fixes #82064

Release note (sql): add sequence option info for identity columns under
information_schema
  • Loading branch information
ZhouXing19 committed Jul 7, 2022
1 parent e67e47f commit f3c4e6f
Show file tree
Hide file tree
Showing 8 changed files with 645 additions and 273 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/catalog/schemaexpr/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func FormatColumnForDisplay(
f.WriteString(" GENERATED BY DEFAULT AS IDENTITY")
}
if col.HasGeneratedAsIdentitySequenceOption() {
seqOpt := col.GetGeneratedAsIdentitySequenceOption()
seqOpt := col.GetGeneratedAsIdentitySequenceOptionStr()
s := formatGeneratedAsIdentitySequenceOption(seqOpt)
f.WriteString(s)
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/sql/catalog/table_elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,14 @@ type Column interface {
// `GENERATED AS IDENTITY` column.
HasGeneratedAsIdentitySequenceOption() bool

// GetGeneratedAsIdentitySequenceOptionStr returns the string representation
// of the column's `GENERATED AS IDENTITY` sequence option if it exists, empty
// string otherwise.
GetGeneratedAsIdentitySequenceOptionStr() string

// GetGeneratedAsIdentitySequenceOption returns the column's `GENERATED AS
// IDENTITY` sequence option if it exists, empty string otherwise.
GetGeneratedAsIdentitySequenceOption() string
GetGeneratedAsIdentitySequenceOption() *descpb.TableDescriptor_SequenceOpts
}

// ConstraintToUpdate is an interface around a constraint mutation.
Expand Down
Loading

0 comments on commit f3c4e6f

Please sign in to comment.