From f8da474ecd9f19f719a96d067f7687abe24b1928 Mon Sep 17 00:00:00 2001 From: Nick Tobey Date: Fri, 28 Feb 2025 13:51:44 -0800 Subject: [PATCH 1/2] Allow SHOW CREATE to display auto increment for tables that store AutoIncrement but don't support writing it. --- sql/rowexec/show_iters.go | 4 ++-- sql/tables.go | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sql/rowexec/show_iters.go b/sql/rowexec/show_iters.go index c75e099bc9..cf618c3b42 100644 --- a/sql/rowexec/show_iters.go +++ b/sql/rowexec/show_iters.go @@ -531,9 +531,9 @@ func getForeignKeyTable(t sql.Table) (sql.ForeignKeyTable, error) { } } -func getAutoIncrementTable(t sql.Table) sql.AutoIncrementTable { +func getAutoIncrementTable(t sql.Table) sql.AutoIncrementGetter { switch t := t.(type) { - case sql.AutoIncrementTable: + case sql.AutoIncrementGetter: return t case sql.TableWrapper: return getAutoIncrementTable(t.Underlying()) diff --git a/sql/tables.go b/sql/tables.go index 7b203aab25..d3a6e87182 100644 --- a/sql/tables.go +++ b/sql/tables.go @@ -342,6 +342,13 @@ type AutoIncrementTable interface { AutoIncrementSetter(*Context) AutoIncrementSetter } +// AutoIncrementGetter provides support for reading a table's AUTO_INCREMENT value. +// This can include tables that don't implement AutoIncrementTable if the table is a read-only snapshot +// of an auto-incremented table. +type AutoIncrementGetter interface { + PeekNextAutoIncrementValue(ctx *Context) (uint64, error) +} + // AutoIncrementSetter provides support for altering a table's // AUTO_INCREMENT sequence, eg 'ALTER TABLE t AUTO_INCREMENT = 10;' type AutoIncrementSetter interface { From e36d9fa19ceb5697c83005f641f558b67a4bdb0b Mon Sep 17 00:00:00 2001 From: Nick Tobey Date: Fri, 28 Feb 2025 16:47:23 -0800 Subject: [PATCH 2/2] Incorporate PR feedback. --- sql/tables.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/tables.go b/sql/tables.go index d3a6e87182..4c43b8d467 100644 --- a/sql/tables.go +++ b/sql/tables.go @@ -330,9 +330,7 @@ type TruncateableTable interface { // AUTO_INCREMENT sequence. These methods should only be used for tables with and AUTO_INCREMENT column in their schema. type AutoIncrementTable interface { Table - // PeekNextAutoIncrementValue returns the next AUTO_INCREMENT value without incrementing the current - // auto_increment counter. - PeekNextAutoIncrementValue(ctx *Context) (uint64, error) + AutoIncrementGetter // GetNextAutoIncrementValue gets the next AUTO_INCREMENT value. In the case that a table with an autoincrement // column is passed in a row with the autoinc column failed, the next auto increment value must // update its internal state accordingly and use the insert val at runtime. @@ -346,6 +344,8 @@ type AutoIncrementTable interface { // This can include tables that don't implement AutoIncrementTable if the table is a read-only snapshot // of an auto-incremented table. type AutoIncrementGetter interface { + // PeekNextAutoIncrementValue returns the next AUTO_INCREMENT value without incrementing the current + // auto_increment counter. PeekNextAutoIncrementValue(ctx *Context) (uint64, error) }