Skip to content

Commit

Permalink
add table comments to information_schema.tables (#2458)
Browse files Browse the repository at this point in the history
  • Loading branch information
jycor authored Apr 15, 2024
1 parent 25f3461 commit 81cd0b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions enginetest/queries/information_schema_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
7 changes: 6 additions & 1 deletion sql/information_schema/information_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand All @@ -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
Expand Down

0 comments on commit 81cd0b0

Please sign in to comment.