Skip to content

Commit e1390af

Browse files
author
James Cor
committed
fix and test
1 parent bad32f1 commit e1390af

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
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()

enginetest/queries/information_schema_queries.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ var InfoSchemaQueries = []QueryTest{
3838
GROUP BY index_name;`,
3939
ExpectedColumns: sql.Schema{
4040
{
41-
Name: "table_name",
41+
Name: "TABLE_NAME",
4242
Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default),
4343
},
4444
{
45-
Name: "index_name",
45+
Name: "INDEX_NAME",
4646
Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default),
4747
},
4848
{
49-
Name: "comment",
49+
Name: "COMMENT",
5050
Type: types.MustCreateString(sqltypes.VarChar, 8, sql.Collation_Information_Schema_Default),
5151
},
5252
{
53-
Name: "non_unique",
53+
Name: "NON_UNIQUE",
5454
Type: types.Int32,
5555
},
5656
{
@@ -68,7 +68,7 @@ var InfoSchemaQueries = []QueryTest{
6868
Query: `select table_name from information_schema.tables where table_name = 'mytable' limit 1;`,
6969
ExpectedColumns: sql.Schema{
7070
{
71-
Name: "table_name",
71+
Name: "TABLE_NAME",
7272
Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default),
7373
},
7474
},
@@ -77,9 +77,9 @@ var InfoSchemaQueries = []QueryTest{
7777
{
7878
Query: `select table_catalog, table_schema, table_name from information_schema.tables where table_name = 'mytable' limit 1;`,
7979
ExpectedColumns: sql.Schema{
80-
{Name: "table_catalog", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default)},
81-
{Name: "table_schema", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default)},
82-
{Name: "table_name", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default)},
80+
{Name: "TABLE_CATALOG", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default)},
81+
{Name: "TABLE_SCHEMA", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default)},
82+
{Name: "TABLE_NAME", Type: types.MustCreateString(sqltypes.VarChar, 64, sql.Collation_Information_Schema_Default)},
8383
},
8484
Expected: []sql.Row{{"def", "mydb", "mytable"}},
8585
},

sql/planbuilder/scope.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,11 @@ func (c scopeColumn) unwrapGetFieldAliasId() columnId {
613613
}
614614

615615
func (c scopeColumn) withOriginal(col string) scopeColumn {
616-
c.originalCol = col
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")) {
619+
c.originalCol = col
620+
}
617621
return c
618622
}
619623

0 commit comments

Comments
 (0)