From e1390af84985c9caecdd12cea6e9a8692f971914 Mon Sep 17 00:00:00 2001 From: James Cor Date: Wed, 27 Nov 2024 15:12:25 -0800 Subject: [PATCH] fix and test --- enginetest/enginetests.go | 45 +++++++++++++++++++ .../queries/information_schema_queries.go | 16 +++---- sql/planbuilder/scope.go | 6 ++- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/enginetest/enginetests.go b/enginetest/enginetests.go index 6dde55b703..fab5b3c37f 100644 --- a/enginetest/enginetests.go +++ b/enginetest/enginetests.go @@ -313,6 +313,51 @@ func TestInfoSchema(t *testing.T, h Harness) { }, nil, nil, nil) }) + t.Run("information_schema.processlist projection case", func(t *testing.T) { + e := mustNewEngine(t, h) + defer e.Close() + + if IsServerEngine(e) { + t.Skip("skipping for server engine as the processlist returned from server differs") + } + p := sqle.NewProcessList() + p.AddConnection(1, "localhost") + + ctx := NewContext(h) + ctx.Session.SetClient(sql.Client{Address: "localhost", User: "root"}) + ctx.Session.SetConnectionId(1) + ctx.ProcessList = p + ctx.SetCurrentDatabase("") + + p.ConnectionReady(ctx.Session) + + ctx, err := p.BeginQuery(ctx, "SELECT foo") + require.NoError(t, err) + + p.AddConnection(2, "otherhost") + sess2 := sql.NewBaseSessionWithClientServer("localhost", sql.Client{Address: "otherhost", User: "root"}, 2) + sess2.SetCurrentDatabase("otherdb") + p.ConnectionReady(sess2) + ctx2 := sql.NewContext(context.Background(), sql.WithPid(2), sql.WithSession(sess2)) + ctx2, err = p.BeginQuery(ctx2, "SELECT bar") + require.NoError(t, err) + p.EndQuery(ctx2) + + TestQueryWithContext(t, ctx, e, h, + "SELECT id, uSeR, hOST FROM information_schema.processlist ORDER BY id", + []sql.Row{ + {uint64(1), "root", "localhost"}, + {uint64(2), "root", "otherhost"}, + }, + sql.Schema{ + {Name: "id", Type: types.Uint64}, + {Name: "uSeR", Type: types.MustCreateString(sqltypes.VarChar, 96, sql.Collation_Information_Schema_Default)}, + {Name: "hOST", Type: types.MustCreateString(sqltypes.VarChar, 783, sql.Collation_Information_Schema_Default)}, + }, + nil, nil, + ) + }) + for _, tt := range queries.SkippedInfoSchemaQueries { t.Run(tt.Query, func(t *testing.T) { t.Skip() diff --git a/enginetest/queries/information_schema_queries.go b/enginetest/queries/information_schema_queries.go index ec2ff8fe4d..e1a751aa33 100644 --- a/enginetest/queries/information_schema_queries.go +++ b/enginetest/queries/information_schema_queries.go @@ -38,19 +38,19 @@ var InfoSchemaQueries = []QueryTest{ GROUP BY index_name;`, ExpectedColumns: sql.Schema{ { - Name: "table_name", + Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default), }, { - Name: "index_name", + Name: "INDEX_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default), }, { - Name: "comment", + Name: "COMMENT", Type: types.MustCreateString(sqltypes.VarChar, 8, sql.Collation_Information_Schema_Default), }, { - Name: "non_unique", + Name: "NON_UNIQUE", Type: types.Int32, }, { @@ -68,7 +68,7 @@ var InfoSchemaQueries = []QueryTest{ Query: `select table_name from information_schema.tables where table_name = 'mytable' limit 1;`, ExpectedColumns: sql.Schema{ { - Name: "table_name", + Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default), }, }, @@ -77,9 +77,9 @@ var InfoSchemaQueries = []QueryTest{ { Query: `select table_catalog, table_schema, table_name from information_schema.tables where table_name = 'mytable' limit 1;`, ExpectedColumns: sql.Schema{ - {Name: "table_catalog", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default)}, - {Name: "table_schema", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default)}, - {Name: "table_name", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default)}, + {Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default)}, + {Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default)}, + {Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default)}, }, Expected: []sql.Row{{"def", "mydb", "mytable"}}, }, diff --git a/sql/planbuilder/scope.go b/sql/planbuilder/scope.go index 2e6b5632ad..4b12ae8099 100644 --- a/sql/planbuilder/scope.go +++ b/sql/planbuilder/scope.go @@ -613,7 +613,11 @@ func (c scopeColumn) unwrapGetFieldAliasId() columnId { } func (c scopeColumn) withOriginal(col string) scopeColumn { - c.originalCol = col + // info schema columns always presented as uppercase, except for processlist + // can't reference information_schema.ProcessListTableName because of import cycles + if !strings.EqualFold(c.db, sql.InformationSchemaDatabaseName) || (strings.EqualFold(c.db, sql.InformationSchemaDatabaseName) && strings.EqualFold(c.table, "processlist")) { + c.originalCol = col + } return c }