From 7eff8ce629d00cf4ab1eeda82a1ecd5a4e394b02 Mon Sep 17 00:00:00 2001 From: bb7133 Date: Wed, 3 May 2023 10:53:54 +0800 Subject: [PATCH] executor: fix the wrong `ORDINAL_POSTITION` in columns view (#43491) close pingcap/tidb#43379 --- executor/infoschema_reader.go | 5 ++--- executor/infoschema_reader_test.go | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/executor/infoschema_reader.go b/executor/infoschema_reader.go index 5e315b9ff7086..f2fbf822f24d3 100644 --- a/executor/infoschema_reader.go +++ b/executor/infoschema_reader.go @@ -878,13 +878,13 @@ func (e *hugeMemTableRetriever) dataForColumnsInTable(ctx context.Context, sctx } } } - i := 1 + i := 0 ForColumnsTag: for _, col := range tbl.Columns { if col.Hidden { continue } - + i++ ft := &(col.FieldType) if tbl.IsView() { e.viewMu.RLock() @@ -1018,7 +1018,6 @@ ForColumnsTag: col.GeneratedExprString, // GENERATION_EXPRESSION ) e.rows = append(e.rows, record) - i++ } } diff --git a/executor/infoschema_reader_test.go b/executor/infoschema_reader_test.go index cae75d72c35e0..9804a25d33e82 100644 --- a/executor/infoschema_reader_test.go +++ b/executor/infoschema_reader_test.go @@ -174,6 +174,10 @@ func TestColumnsTables(t *testing.T) { tk.MustExec("CREATE TABLE t (`COL3` bit(1) NOT NULL,b year) ;") tk.MustQuery("select column_type from information_schema.columns where TABLE_SCHEMA = 'test' and TABLE_NAME = 't';"). Check(testkit.Rows("bit(1)", "year(4)")) + + // For issue: https://github.com/pingcap/tidb/issues/43379 + tk.MustQuery("select ordinal_position from information_schema.columns where table_schema=database() and table_name='t' and column_name='b'"). + Check(testkit.Rows("2")) } func TestEngines(t *testing.T) {