From c8afcd7a5ab2cbee6149508b25d5ce77ceea7315 Mon Sep 17 00:00:00 2001 From: ethan-xiao <308056554@qq.com> Date: Thu, 16 Feb 2023 10:17:29 +0800 Subject: [PATCH 1/3] fix: resolve duplicate fields generated when inheriting multiple tables --- internal/sql/catalog/table.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/sql/catalog/table.go b/internal/sql/catalog/table.go index 6595fcbace..5d1c5d1018 100644 --- a/internal/sql/catalog/table.go +++ b/internal/sql/catalog/table.go @@ -236,12 +236,21 @@ func (c *Catalog) createTable(stmt *ast.CreateTableStmt) error { } tbl := Table{Rel: stmt.Name, Comment: stmt.Comment} + m := make(map[string]struct{}) // used to check for duplicate column names for _, inheritTable := range stmt.Inherits { t, _, err := schema.getTable(inheritTable) if err != nil { return err } - tbl.Columns = append(tbl.Columns, t.Columns...) + for _, col := range t.Columns { + if _, ok := m[col.Name]; ok { + continue + } else { + m[col.Name] = struct{}{} + tbl.Columns = append(tbl.Columns, col) + } + } + //tbl.Columns = append(tbl.Columns, t.Columns...) } if stmt.ReferTable != nil && len(stmt.Cols) != 0 { From 5030ba48437c8ad3ee3f6368815927c1817f0f4f Mon Sep 17 00:00:00 2001 From: ethan-xiao <308056554@qq.com> Date: Thu, 16 Feb 2023 10:23:21 +0800 Subject: [PATCH 2/3] chore: comments --- internal/sql/catalog/table.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/sql/catalog/table.go b/internal/sql/catalog/table.go index 5d1c5d1018..c1759ea73e 100644 --- a/internal/sql/catalog/table.go +++ b/internal/sql/catalog/table.go @@ -242,6 +242,7 @@ func (c *Catalog) createTable(stmt *ast.CreateTableStmt) error { if err != nil { return err } + // check and ignore duplicate columns for _, col := range t.Columns { if _, ok := m[col.Name]; ok { continue @@ -250,7 +251,6 @@ func (c *Catalog) createTable(stmt *ast.CreateTableStmt) error { tbl.Columns = append(tbl.Columns, col) } } - //tbl.Columns = append(tbl.Columns, t.Columns...) } if stmt.ReferTable != nil && len(stmt.Cols) != 0 { From c95bd7dc392451c4dbd35c77173ae17ad4d411c8 Mon Sep 17 00:00:00 2001 From: Ethan Xiao Date: Thu, 16 Feb 2023 10:25:36 +0800 Subject: [PATCH 3/3] fix: resolve duplicate fields generated when inheriting multiple tables (#1) --- internal/sql/catalog/table.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/sql/catalog/table.go b/internal/sql/catalog/table.go index 6595fcbace..c1759ea73e 100644 --- a/internal/sql/catalog/table.go +++ b/internal/sql/catalog/table.go @@ -236,12 +236,21 @@ func (c *Catalog) createTable(stmt *ast.CreateTableStmt) error { } tbl := Table{Rel: stmt.Name, Comment: stmt.Comment} + m := make(map[string]struct{}) // used to check for duplicate column names for _, inheritTable := range stmt.Inherits { t, _, err := schema.getTable(inheritTable) if err != nil { return err } - tbl.Columns = append(tbl.Columns, t.Columns...) + // check and ignore duplicate columns + for _, col := range t.Columns { + if _, ok := m[col.Name]; ok { + continue + } else { + m[col.Name] = struct{}{} + tbl.Columns = append(tbl.Columns, col) + } + } } if stmt.ReferTable != nil && len(stmt.Cols) != 0 {