Skip to content

Commit

Permalink
Added partitions in information_schema.placement_rules
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonss committed Oct 12, 2021
1 parent 742a5f7 commit a491ae5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
10 changes: 10 additions & 0 deletions ddl/placement_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,11 @@ func (s *testDBSuite6) TestAlterTablePartitionWithPlacementPolicy(c *C) {
"PARTITION p1 VALUES LESS THAN (11)," +
"PARTITION p2 VALUES LESS THAN (16)," +
"PARTITION p3 VALUES LESS THAN (21));")
tk.MustQuery("SELECT " +
"CATALOG_NAME,POLICY_NAME,SCHEMA_NAME,TABLE_NAME,PARTITION_NAME," +
"PRIMARY_REGION,REGIONS,CONSTRAINTS,LEADER_CONSTRAINTS,FOLLOWER_CONSTRAINTS,LEARNER_CONSTRAINTS," +
"SCHEDULE,FOLLOWERS,LEARNERS FROM INFORMATION_SCHEMA.placement_rules WHERE table_NAME='t1'").Check(
testkit.Rows())

tk.MustExec("alter table t1 partition p0 " +
"PRIMARY_REGION=\"cn-east-1\" " +
Expand All @@ -550,6 +555,11 @@ func (s *testDBSuite6) TestAlterTablePartitionWithPlacementPolicy(c *C) {
c.Assert(policySetting.Schedule, Equals, "")
}
checkFunc(ptDef.DirectPlacementOpts)
tk.MustQuery("SELECT " +
"CATALOG_NAME,POLICY_NAME,SCHEMA_NAME,TABLE_NAME,PARTITION_NAME," +
"PRIMARY_REGION,REGIONS,CONSTRAINTS,LEADER_CONSTRAINTS,FOLLOWER_CONSTRAINTS,LEARNER_CONSTRAINTS," +
"SCHEDULE,FOLLOWERS,LEARNERS FROM INFORMATION_SCHEMA.placement_rules WHERE TABLE_NAME='t1'").Check(
testkit.Rows("def <nil> test t1 p0 cn-east-1 cn-east-1, cn-east-2 2 0"))

//Direct placement option and placement policy can't co-exist.
_, err := tk.Exec("alter table t1 partition p0 " +
Expand Down
25 changes: 24 additions & 1 deletion executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2882,7 +2882,30 @@ func (e *memtableRetriever) setDataFromPlacementRules(ctx context.Context, sctx
continue
}
anyTablePriv = true
// TODO: get DIRECT PLACEMENT from partitions
if partInfo := table.GetPartitionInfo(); partInfo != nil {
for _, pi := range partInfo.Definitions {
if pi.DirectPlacementOpts != nil {
record := types.MakeDatums(
nil, // PLACEMENT POLICY ID, null since direct placement
infoschema.CatalogVal, // CATALOG
nil, // PLACEMENT POLICY, null since direct placement
schema.Name.O, // SCHEMA
table.Name.O, // TABLE
pi.Name.O, // PARTITION
pi.DirectPlacementOpts.PrimaryRegion,
pi.DirectPlacementOpts.Regions,
pi.DirectPlacementOpts.Constraints,
pi.DirectPlacementOpts.LeaderConstraints,
pi.DirectPlacementOpts.FollowerConstraints,
pi.DirectPlacementOpts.LearnerConstraints,
pi.DirectPlacementOpts.Schedule,
pi.DirectPlacementOpts.Followers,
pi.DirectPlacementOpts.Learners,
)
rows = append(rows, record)
}
}
}
if table.DirectPlacementOpts == nil {
continue
}
Expand Down

0 comments on commit a491ae5

Please sign in to comment.