From 81cd0b0b8f5144083f8491d2413fa5c8e0382b67 Mon Sep 17 00:00:00 2001 From: James Cor Date: Mon, 15 Apr 2024 16:46:54 -0700 Subject: [PATCH] add table comments to `information_schema.tables` (#2458) --- enginetest/queries/information_schema_queries.go | 15 +++++++++++++++ sql/information_schema/information_schema.go | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/enginetest/queries/information_schema_queries.go b/enginetest/queries/information_schema_queries.go index 1581452a67..5df834cd35 100644 --- a/enginetest/queries/information_schema_queries.go +++ b/enginetest/queries/information_schema_queries.go @@ -1717,6 +1717,21 @@ from information_schema.routines where routine_schema = 'mydb' and routine_type }, }, }, + { + + Name: "information_schema.tables has table comments", + SetUpScript: []string{ + "create table t (i int primary key) comment 'this is a table comment';", + }, + Assertions: []ScriptTestAssertion{ + { + Query: "select table_comment from information_schema.tables where table_name = 't';", + Expected: []sql.Row{ + {"this is a table comment"}, + }, + }, + }, + }, } var SkippedInfoSchemaScripts = []ScriptTest{ diff --git a/sql/information_schema/information_schema.go b/sql/information_schema/information_schema.go index b234dac661..64c8392456 100644 --- a/sql/information_schema/information_schema.go +++ b/sql/information_schema/information_schema.go @@ -1822,6 +1822,7 @@ func tablesRowIter(ctx *Context, cat Catalog) (RowIter, error) { y2k, _, _ := types.Timestamp.Convert("2000-01-01 00:00:00") err := DBTableIter(ctx, db, func(t Table) (cont bool, err error) { tableCollation = t.Collation().String() + comment := "" if db.Name() != InformationSchemaDatabaseName { if st, ok := t.(StatisticsTable); ok { tableRows, _, err = st.RowCount(ctx) @@ -1856,6 +1857,10 @@ func tablesRowIter(ctx *Context, cat Catalog) (RowIter, error) { autoInc = nil } } + + if commentedTable, ok := t.(CommentedTable); ok { + comment = commentedTable.Comment() + } } rows = append(rows, Row{ @@ -1879,7 +1884,7 @@ func tablesRowIter(ctx *Context, cat Catalog) (RowIter, error) { tableCollation, // table_collation nil, // checksum "", // create_options - "", // table_comment + comment, // table_comment }) return true, nil