Skip to content

Commit 6efed41

Browse files
authored
information_schema uppercase rule doesn't apply to processlist table (#2764)
1 parent 27b055d commit 6efed41

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

enginetest/enginetests.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,51 @@ func TestInfoSchema(t *testing.T, h Harness) {
313313
}, nil, nil, nil)
314314
})
315315

316+
t.Run("information_schema.processlist projection case", func(t *testing.T) {
317+
e := mustNewEngine(t, h)
318+
defer e.Close()
319+
320+
if IsServerEngine(e) {
321+
t.Skip("skipping for server engine as the processlist returned from server differs")
322+
}
323+
p := sqle.NewProcessList()
324+
p.AddConnection(1, "localhost")
325+
326+
ctx := NewContext(h)
327+
ctx.Session.SetClient(sql.Client{Address: "localhost", User: "root"})
328+
ctx.Session.SetConnectionId(1)
329+
ctx.ProcessList = p
330+
ctx.SetCurrentDatabase("")
331+
332+
p.ConnectionReady(ctx.Session)
333+
334+
ctx, err := p.BeginQuery(ctx, "SELECT foo")
335+
require.NoError(t, err)
336+
337+
p.AddConnection(2, "otherhost")
338+
sess2 := sql.NewBaseSessionWithClientServer("localhost", sql.Client{Address: "otherhost", User: "root"}, 2)
339+
sess2.SetCurrentDatabase("otherdb")
340+
p.ConnectionReady(sess2)
341+
ctx2 := sql.NewContext(context.Background(), sql.WithPid(2), sql.WithSession(sess2))
342+
ctx2, err = p.BeginQuery(ctx2, "SELECT bar")
343+
require.NoError(t, err)
344+
p.EndQuery(ctx2)
345+
346+
TestQueryWithContext(t, ctx, e, h,
347+
"SELECT id, uSeR, hOST FROM information_schema.processlist ORDER BY id",
348+
[]sql.Row{
349+
{uint64(1), "root", "localhost"},
350+
{uint64(2), "root", "otherhost"},
351+
},
352+
sql.Schema{
353+
{Name: "id", Type: types.Uint64},
354+
{Name: "uSeR", Type: types.MustCreateString(sqltypes.VarChar, 96, sql.Collation_Information_Schema_Default)},
355+
{Name: "hOST", Type: types.MustCreateString(sqltypes.VarChar, 783, sql.Collation_Information_Schema_Default)},
356+
},
357+
nil, nil,
358+
)
359+
})
360+
316361
for _, tt := range queries.SkippedInfoSchemaQueries {
317362
t.Run(tt.Query, func(t *testing.T) {
318363
t.Skip()

sql/planbuilder/scope.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,9 @@ func (c scopeColumn) unwrapGetFieldAliasId() columnId {
613613
}
614614

615615
func (c scopeColumn) withOriginal(col string) scopeColumn {
616-
if !strings.EqualFold(c.db, sql.InformationSchemaDatabaseName) {
617-
// info schema columns always presented as uppercase
616+
// info schema columns always presented as uppercase, except for processlist
617+
// can't reference information_schema.ProcessListTableName because of import cycles
618+
if !strings.EqualFold(c.db, sql.InformationSchemaDatabaseName) || (strings.EqualFold(c.db, sql.InformationSchemaDatabaseName) && strings.EqualFold(c.table, "processlist")) {
618619
c.originalCol = col
619620
}
620621
return c

0 commit comments

Comments
 (0)