Skip to content

Commit

Permalink
planner: create new column slice in PreparePossibleProperties (#24342)
Browse files Browse the repository at this point in the history
  • Loading branch information
francis0407 authored May 11, 2021
1 parent 263a47e commit 7d41c86
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
17 changes: 17 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3597,6 +3597,23 @@ func (s *testIntegrationSuite) TestIssue24095(c *C) {
}
}

func (s *testIntegrationSuite) TestIssue24281(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists member, agent, deposit, view_member_agents")
tk.MustExec("create table member(login varchar(50) NOT NULL, agent_login varchar(100) DEFAULT NULL, PRIMARY KEY(login))")
tk.MustExec("create table agent(login varchar(50) NOT NULL, data varchar(100) DEFAULT NULL, share_login varchar(50) NOT NULL, PRIMARY KEY(login))")
tk.MustExec("create table deposit(id varchar(50) NOT NULL, member_login varchar(50) NOT NULL, transfer_amount int NOT NULL, PRIMARY KEY(id), KEY midx(member_login, transfer_amount))")
tk.MustExec("create definer='root'@'localhost' view view_member_agents (member, share_login) as select m.login as member, a.share_login AS share_login from member as m join agent as a on m.agent_login = a.login")

tk.MustExec(" select s.member_login as v1, SUM(s.transfer_amount) AS v2 " +
"FROM deposit AS s " +
"JOIN view_member_agents AS v ON s.member_login = v.member " +
"WHERE 1 = 1 AND v.share_login = 'somevalue' " +
"GROUP BY s.member_login " +
"UNION select 1 as v1, 2 as v2")
}

func (s *testIntegrationSuite) TestConflictReadFromStorage(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
15 changes: 8 additions & 7 deletions planner/core/property_cols_prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,22 @@ func (p *LogicalProjection) PreparePossibleProperties(schema *expression.Schema,
}
}
tmpSchema := expression.NewSchema(oldCols...)
for i := len(childProperties) - 1; i >= 0; i-- {
for j, col := range childProperties[i] {
newProperties := make([][]*expression.Column, 0, len(childProperties))
for _, childProperty := range childProperties {
newChildProperty := make([]*expression.Column, 0, len(childProperty))
for _, col := range childProperty {
pos := tmpSchema.ColumnIndex(col)
if pos >= 0 {
childProperties[i][j] = newCols[pos]
newChildProperty = append(newChildProperty, newCols[pos])
} else {
childProperties[i] = childProperties[i][:j]
break
}
}
if len(childProperties[i]) == 0 {
childProperties = append(childProperties[:i], childProperties[i+1:]...)
if len(newChildProperty) != 0 {
newProperties = append(newProperties, newChildProperty)
}
}
return childProperties
return newProperties
}

func clonePossibleProperties(props [][]*expression.Column) [][]*expression.Column {
Expand Down

0 comments on commit 7d41c86

Please sign in to comment.