Skip to content

Commit

Permalink
change tests
Browse files Browse the repository at this point in the history
  • Loading branch information
winoros committed Mar 15, 2022
1 parent f2d0b3d commit 1c363a2
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions planner/funcdep/extract_fd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,33 @@ func TestFDSet_ExtractFD(t *testing.T) {
},
{
sql: "select b+1, sum(a) from t1 group by(b)",
// since b is projected out, b --> b+1 and b ~~> sum(a) is eliminated.
// The final ones are b -> (b+1), b -> sum(a)
best: "DataScan(t1)->Aggr(sum(test.t1.a),firstrow(test.t1.b))->Projection",
fd: "{(1)-->(2,3), (2,3)~~>(1)} >>> {(2)~~>(4)} >>> {(2)~~>(4), (2)-->(5)}",
fd: "{(1)-->(2,3), (2,3)~~>(1)} >>> {(1)-->(2,3), (2,3)~~>(1), (2)-->(4)} >>> {(2)-->(4,5)}",
},
{
sql: "select b+1, b, sum(a) from t1 group by(b)",
sql: "select b+1, b, sum(a) from t1 group by(b)",
// The final ones are b -> (b+1), b -> sum(a)
best: "DataScan(t1)->Aggr(sum(test.t1.a),firstrow(test.t1.b))->Projection",
fd: "{(1)-->(2,3), (2,3)~~>(1)} >>> {(2)~~>(4)} >>> {(2)~~>(4), (2)-->(5)}",
fd: "{(1)-->(2,3), (2,3)~~>(1)} >>> {(1)-->(2,3), (2,3)~~>(1), (2)-->(4)} >>> {(2)-->(4,5)}",
},
// test for table x1 and x2
{
sql: "select a from x1 group by a,b,c",
best: "DataScan(x1)->Projection",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {}",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(1)-->(2,3), (2,3)~~>(1)}",
},
{
sql: "select b from x1 group by b",
best: "DataScan(x1)->Aggr(firstrow(test.x1.b))->Projection",
// b --> b is natural existed, so it won't exist in fd.
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {} >>> {}",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {}",
},
{
sql: "select b as e from x1 group by b",
best: "DataScan(x1)->Aggr(firstrow(test.x1.b))->Projection",
// b --> b is naturally existed, so it won't exist in fd.
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {} >>> {}",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {}",
},
{
sql: "select b+c from x1 group by b+c",
Expand All @@ -110,23 +111,23 @@ func TestFDSet_ExtractFD(t *testing.T) {
// b+c is an expr assigned with new plan ID when building upper-layer projection.
// when extracting FD after build phase is done, we should be able to recognize a+b in lower-layer group by item with the same unique ID.
// that's why we introduce session variable MapHashCode2UniqueID4ExtendedCol in.
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(2,3)-->(5), (5)~~>(2,3)} >>> {(2,3)-->(5), (5)~~>(2,3)}",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3), (2,3)-->(5)} >>> {(2,3)-->(5)}",
},
{
sql: "select b+c, min(a) from x1 group by b+c, b-c",
best: "DataScan(x1)->Aggr(min(test.x1.a),firstrow(test.x1.b),firstrow(test.x1.c))->Projection",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(2,3)-->(6,8), (6,8)~~>(2,3,5)} >>> {(2,3)-->(6)}",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3), (2,3)-->(6,7), (6,7)-->(5)} >>> {(2,3)-->(6,7), (6,7)-->(5)}",
},
{
sql: "select b+c, min(a) from x1 group by b, c",
best: "DataScan(x1)->Aggr(min(test.x1.a),firstrow(test.x1.b),firstrow(test.x1.c))->Projection",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(2,3)~~>(5)} >>> {(2,3)~~>(5), (2,3)-->(6)}",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3), (2,3)-->(5)} >>> {(2,3)-->(5,6)}",
},
{
sql: "select b+c from x1 group by b,c",
best: "DataScan(x1)->Aggr(firstrow(test.x1.b),firstrow(test.x1.c))->Projection",
// b --> b is naturally existed, so it won't exist in fd.
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {} >>> {(2,3)-->(5)}",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(2,3)-->(5)}",
},
{
sql: "select case b when 1 then c when 2 then d else d end from x1 group by b,c,d",
Expand All @@ -137,23 +138,23 @@ func TestFDSet_ExtractFD(t *testing.T) {
// scalar sub query will be substituted with constant datum.
sql: "select c > (select b from x1) from x1 group by c",
best: "DataScan(x1)->Aggr(firstrow(test.x1.c))->Projection",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {} >>> {(3)-->(15)}",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(3)-->(15)}",
},
{
sql: "select exists (select * from x1) from x1 group by d",
best: "DataScan(x1)->Aggr(firstrow(1))->Projection",
// 14 is added in the logicAgg pruning process cause all the columns of agg has been pruned.
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(4)~~>(14)} >>> {()-->(13)}",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {()-->(13)}",
},
{
sql: "select c is null from x1 group by c",
best: "DataScan(x1)->Aggr(firstrow(test.x1.c))->Projection",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {} >>> {(3)-->(5)}",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(3)-->(5)}",
},
{
sql: "select c is true from x1 group by c",
best: "DataScan(x1)->Aggr(firstrow(test.x1.c))->Projection",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {} >>> {(3)-->(5)}",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(3)-->(5)}",
},
{
sql: "select (c+b)*d from x1 group by c,b,d",
Expand All @@ -169,7 +170,7 @@ func TestFDSet_ExtractFD(t *testing.T) {
{
sql: "select b like '%a' from x1 group by b",
best: "DataScan(x1)->Aggr(firstrow(test.x1.b))->Projection",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {} >>> {(2)-->(5)}",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(2)-->(5)}",
},
// test functional dependency on primary key
{
Expand All @@ -191,7 +192,7 @@ func TestFDSet_ExtractFD(t *testing.T) {
// c = d derives:
// 1: c and d are not null, make lax FD (2,3)~~>(1,4) to be strict one.
// 2: c and d are equivalent.
fd: "{(1)-->(2-4), (2,3)-->(1,4), (2,4)-->(1,3), (3,4)==(3,4)} >>> {(1)-->(2-4), (2,3)-->(1,4), (2,4)-->(1,3), (3,4)==(3,4)} >>> {(1)-->(2-4), (2,3)-->(1,4), (2,4)-->(1,3), (3,4)==(3,4)}",
fd: "{(1)-->(2-4), (2,3)~~>(1,4), (2,4)-->(1,3)} >>> {(1)-->(2-4), (2,3)-->(1,4), (2,4)-->(1,3), (3,4)==(3,4)} >>> {(1)-->(2-4), (2,3)-->(1,4), (2,4)-->(1,3), (3,4)==(3,4)}",
},
}

Expand Down

0 comments on commit 1c363a2

Please sign in to comment.