Skip to content

Commit 8637b99

Browse files
authored
Merge pull request #2864 from dolthub/nicktobey/autoincrement
Allow SHOW CREATE to display auto increment for tables that store AutoIncrement but don't support writing it.
2 parents e1e2733 + e36d9fa commit 8637b99

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

sql/rowexec/show_iters.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,9 @@ func getForeignKeyTable(t sql.Table) (sql.ForeignKeyTable, error) {
531531
}
532532
}
533533

534-
func getAutoIncrementTable(t sql.Table) sql.AutoIncrementTable {
534+
func getAutoIncrementTable(t sql.Table) sql.AutoIncrementGetter {
535535
switch t := t.(type) {
536-
case sql.AutoIncrementTable:
536+
case sql.AutoIncrementGetter:
537537
return t
538538
case sql.TableWrapper:
539539
return getAutoIncrementTable(t.Underlying())

sql/tables.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,7 @@ type TruncateableTable interface {
330330
// AUTO_INCREMENT sequence. These methods should only be used for tables with and AUTO_INCREMENT column in their schema.
331331
type AutoIncrementTable interface {
332332
Table
333-
// PeekNextAutoIncrementValue returns the next AUTO_INCREMENT value without incrementing the current
334-
// auto_increment counter.
335-
PeekNextAutoIncrementValue(ctx *Context) (uint64, error)
333+
AutoIncrementGetter
336334
// GetNextAutoIncrementValue gets the next AUTO_INCREMENT value. In the case that a table with an autoincrement
337335
// column is passed in a row with the autoinc column failed, the next auto increment value must
338336
// update its internal state accordingly and use the insert val at runtime.
@@ -342,6 +340,15 @@ type AutoIncrementTable interface {
342340
AutoIncrementSetter(*Context) AutoIncrementSetter
343341
}
344342

343+
// AutoIncrementGetter provides support for reading a table's AUTO_INCREMENT value.
344+
// This can include tables that don't implement AutoIncrementTable if the table is a read-only snapshot
345+
// of an auto-incremented table.
346+
type AutoIncrementGetter interface {
347+
// PeekNextAutoIncrementValue returns the next AUTO_INCREMENT value without incrementing the current
348+
// auto_increment counter.
349+
PeekNextAutoIncrementValue(ctx *Context) (uint64, error)
350+
}
351+
345352
// AutoIncrementSetter provides support for altering a table's
346353
// AUTO_INCREMENT sequence, eg 'ALTER TABLE t AUTO_INCREMENT = 10;'
347354
type AutoIncrementSetter interface {

0 commit comments

Comments
 (0)