Skip to content

Commit

Permalink
planner: collect all columns meta by sync load (#53137)
Browse files Browse the repository at this point in the history
close #53141
  • Loading branch information
hawkingrei authored May 14, 2024
1 parent 98e5cfb commit a2037fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 6 additions & 7 deletions pkg/planner/core/collect_column_stats_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,17 @@ func (c *columnStatsUsageCollector) addHistNeededColumns(ds *DataSource) {
colIDSet.Insert(int(col.ID))
c.histNeededCols[tblColID] = true
}
for _, col := range ds.Columns {
for _, column := range ds.tableInfo.Columns {
// If the column is plan-generated one, Skip it.
// TODO: we may need to consider the ExtraHandle.
if col.ID < 0 {
if column.ID < 0 {
continue
}
if !colIDSet.Has(int(col.ID)) && !col.Hidden {
tblColID := model.TableItemID{TableID: ds.physicalTableID, ID: col.ID, IsIndex: false}
if _, ok := c.histNeededCols[tblColID]; ok {
continue
if !column.Hidden {
tblColID := model.TableItemID{TableID: ds.physicalTableID, ID: column.ID, IsIndex: false}
if _, ok := c.histNeededCols[tblColID]; !ok {
c.histNeededCols[tblColID] = false
}
c.histNeededCols[tblColID] = false
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/planner/core/collect_column_stats_usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,23 +316,23 @@ func TestCollectHistNeededColumns(t *testing.T) {
},
{
sql: "select b, count(a) from t where b > 1 group by b having count(a) > 2",
res: []string{"t.a meta", "t.b full"},
res: []string{"t.a meta", "t.b full", "t.c meta", "t.c_str meta", "t.d meta", "t.d_str meta", "t.e meta", "t.e_str meta", "t.f meta", "t.g meta", "t.h meta", "t.i_date meta"},
},
{
sql: "select * from t as x join t2 as y on x.b + y.b > 2 and x.c > 1 and y.a < 1",
res: []string{"t.a meta", "t.b meta", "t.c full", "t.c_str meta", "t.d meta", "t.d_str meta", "t.e meta", "t.e_str meta", "t.f meta", "t.g meta", "t.h meta", "t.i_date meta", "t2.a full", "t2.b meta", "t2.c meta"},
},
{
sql: "select * from t2 where t2.b > all(select b from t where t.c > 2)",
res: []string{"t.b meta", "t.c full", "t2.a meta", "t2.b meta", "t2.c meta"},
res: []string{"t.a meta", "t.b meta", "t.c full", "t.c_str meta", "t.d meta", "t.d_str meta", "t.e meta", "t.e_str meta", "t.f meta", "t.g meta", "t.h meta", "t.i_date meta", "t2.a meta", "t2.b meta", "t2.c meta"},
},
{
sql: "select * from t2 where t2.b > any(select b from t where t.c > 2)",
res: []string{"t.b meta", "t.c full", "t2.a meta", "t2.b meta", "t2.c meta"},
res: []string{"t.a meta", "t.b meta", "t.c full", "t.c_str meta", "t.d meta", "t.d_str meta", "t.e meta", "t.e_str meta", "t.f meta", "t.g meta", "t.h meta", "t.i_date meta", "t2.a meta", "t2.b meta", "t2.c meta"},
},
{
sql: "select * from t2 where t2.b in (select b from t where t.c > 2)",
res: []string{"t.b meta", "t.c full", "t2.a meta", "t2.b meta", "t2.c meta"},
res: []string{"t.a meta", "t.b meta", "t.c full", "t.c_str meta", "t.d meta", "t.d_str meta", "t.e meta", "t.e_str meta", "t.f meta", "t.g meta", "t.h meta", "t.i_date meta", "t2.a meta", "t2.b meta", "t2.c meta"},
},
{
pruneMode: "static",
Expand Down

0 comments on commit a2037fe

Please sign in to comment.