Skip to content

Commit 0da7963

Browse files
committed
rollups work
1 parent aa05b0f commit 0da7963

File tree

5 files changed

+43
-19
lines changed

5 files changed

+43
-19
lines changed

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/AggregateIndexMatchCandidate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ public NonnullPair<List<Value>, Value> getGroupingAndAggregateAccessors(final in
490490
Verify.verify(deconstructedRecord.size() > numGroupings);
491491
final var groupingAccessorValues =
492492
ImmutableList.copyOf(deconstructedRecord.subList(0, numGroupings));
493-
final var aggregateAccessorValue = deconstructedRecord.get(deconstructedRecord.size() - 1);
493+
final var aggregateAccessorValue = deconstructedRecord.get(numGroupings);
494494
return NonnullPair.of(groupingAccessorValues, aggregateAccessorValue);
495495
}
496496

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/RequestedOrdering.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.apple.foundationdb.record.query.plan.cascades.values.Values;
2929
import com.apple.foundationdb.record.query.plan.cascades.values.simplification.OrderingValueComputationRuleSet;
3030
import com.apple.foundationdb.record.query.plan.cascades.values.simplification.RequestedOrderingValueSimplificationRuleSet;
31+
import com.apple.foundationdb.record.query.plan.cascades.values.translation.TranslationMap;
3132
import com.google.common.base.Suppliers;
3233
import com.google.common.base.Verify;
3334
import com.google.common.collect.ImmutableList;
@@ -87,6 +88,7 @@ private RequestedOrdering(@Nonnull final List<RequestedOrderingPart> orderingPar
8788
this.valueRequestedSortOrderMapSupplier = Suppliers.memoize(this::computeValueSortOrderMap);
8889
}
8990

91+
@Nonnull
9092
public Distinctness getDistinctness() {
9193
return distinctness;
9294
}
@@ -218,6 +220,20 @@ public RequestedOrdering pushDown(@Nonnull Value value,
218220
return new RequestedOrdering(pushedDownOrderingPartsBuilder.build(), Distinctness.PRESERVE_DISTINCTNESS, isExhaustive());
219221
}
220222

223+
@Nonnull
224+
public RequestedOrdering translate(@Nonnull TranslationMap translationMap) {
225+
//
226+
// Need to push every participating value of this requested ordering through the value.
227+
//
228+
final var pushedDownOrderingPartsBuilder = ImmutableList.<RequestedOrderingPart>builder();
229+
for (final var orderingPart : orderingParts) {
230+
final var orderingValue = orderingPart.getValue();
231+
final var translatedOrderingValue = orderingValue.translateCorrelations(translationMap);
232+
pushedDownOrderingPartsBuilder.add(new RequestedOrderingPart(translatedOrderingValue, orderingPart.getSortOrder()));
233+
}
234+
return new RequestedOrdering(pushedDownOrderingPartsBuilder.build(), Distinctness.PRESERVE_DISTINCTNESS, isExhaustive());
235+
}
236+
221237
@Nonnull
222238
private Map<Value, RequestedSortOrder> computeValueSortOrderMap() {
223239
return getOrderingParts()
Binary file not shown.
Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
agg-empty-table-tests:
2-
- query: EXPLAIN select sum(col2) / count(col2) from T2 group by col1;
3-
explain: 'AISCAN(T2_I6 <,> BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) ∩ AISCAN(T2_I4
4-
<,> BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) COMPARE BY (_._0._0) WITH q0,
5-
q1 RETURN (q0._0 AS _0, q0._1 AS _1, q1._1 AS _2) | MAP (_._1 / _._2 AS _0)'
6-
task_count: 317
7-
task_total_time_ms: 11
8-
transform_count: 115
9-
transform_time_ms: 10
10-
transform_yield_count: 51
11-
insert_time_ms: 0
12-
insert_new_count: 16
13-
insert_reused_count: 0
2+
- query: EXPLAIN select col1, min(col2) from T3 group by col1, col3;
3+
explain: 'AISCAN(T3_I2 <,> BY_GROUP -> [_0: KEY:[0], _1: KEY:[2], _2: KEY:[1]])
4+
| MAP (_._0 AS COL1, _._2 AS _1)'
5+
task_count: 418
6+
task_total_time_ms: 105
7+
transform_count: 145
8+
transform_time_ms: 82
9+
transform_yield_count: 50
10+
insert_time_ms: 3
11+
insert_new_count: 50
12+
insert_reused_count: 4

yaml-tests/src/test/resources/composite-aggregates.yamsql

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@
2121
schema_template:
2222
create table t1(id bigint, col1 bigint, col2 bigint, col3 bigint, primary key(id))
2323
create table t2(id bigint, col1 bigint, col2 bigint, primary key(id))
24-
create table t3(id bigint, col1 bigint, col2 bigint, primary key(id))
25-
create index t1_i1 as select sum(col1) from t1 group by col2, col3
26-
create index t1_i2 as select count(*) from t1 group by col2
24+
create table t3(id bigint, col1 bigint, col2 bigint, col3 bigint, primary key(id))
25+
create index t1_i1 as select count(col1) from t1 group by col2, col3
26+
create index t1_i2 as select col2, sum(col1) from t1 group by col2
2727
create index t2_i1 as select count(*) from t2
2828
create index t2_i2 as select count(*) from t2 group by col1
2929
create index t2_i3 as select count(col2) from t2
3030
create index t2_i4 as select count(col2) from t2 group by col1
3131
create index t2_i5 as select sum(col1) from t2
3232
create index t2_i6 as select sum(col2) from t2 group by col1
3333
create index t2_i7 as select count(*) from t2 group by col1, col2
34+
create index t3_i1 as select col1, max(col2), col3 from T3 group by col1, col3 order by col1, max(col2), col3
35+
create index t3_i2 as select col1, min(col2), col3 from T3 group by col1, col3 order by col1, min(col2), col3
3436

3537
---
3638
setup:
@@ -93,9 +95,16 @@ test_block:
9395
# - query: select sum(col2), count(col2) from T2 where col1 < 2 group by col1 having sum(col2) = 17;
9496
# - explain: "AISCAN(T2_I6 [[LESS_THAN promote(@c16 AS LONG)]] BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) ∩ AISCAN(T2_I4 [[LESS_THAN promote(@c16 AS LONG)]] BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) COMPARE BY (_._0._0) WITH q0, q1 RETURN (q0._0 AS _0, q0._1 AS _1, q1._1 AS _2) | FILTER _._1 EQUALS promote(@c26 AS LONG) | MAP (_._1 AS _0, _._2 AS _1)"
9597
# - result: [{!l 17, !l 4}]
98+
#-
99+
# - query: select sum(col1) / count(col1) from T1 group by col2;
100+
# - explain: "AISCAN(T2_I6 <,> BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) ∩ AISCAN(T2_I4 <,> BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) COMPARE BY (_._0._0) WITH q0, q1 RETURN (q0._0 AS _0, q0._1 AS _1, q1._1 AS _2) | MAP (_._1 / _._2 AS _0)"
101+
# - result: []
102+
#-
103+
# - query: select col2, sum(col1) / count(col1) from T1 where col2 < 2 group by col2 having sum(col1) = 17;
104+
# - explain: "AISCAN(T1_I2 [[LESS_THAN promote(@c16 AS LONG)]] BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) ∩ AISCAN(T1_I1 [[LESS_THAN promote(@c16 AS LONG)]] BY_GROUP -> [_0: KEY:[0], _1: KEY:[1], _2: VALUE:[0]]) | AGG sum_l(_._1) GROUP BY (_._0 AS _0) COMPARE BY (_._0._0) WITH q0, q1 RETURN (q0._0 AS _0, q0._1 AS _1, q1._1 AS _2) | FILTER _._1 EQUALS promote(@c26 AS LONG) | MAP (_._1 / _._2 AS _0)"
105+
# - result: []
96106
-
97-
- query: select sum(col1) / count(*) from T1 group by col2;
98-
- explain: "AISCAN(T2_I6 <,> BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) ∩ AISCAN(T2_I4 <,> BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) COMPARE BY (_._0._0) WITH q0, q1 RETURN (q0._0 AS _0, q0._1 AS _1, q1._1 AS _2) | MAP (_._1 / _._2 AS _0)"
107+
- query: select col1, min(col2), max(col2) from T3 group by col1, col3;
108+
- explain: "AISCAN(T3_I2 <,> BY_GROUP -> [_0: KEY:[0], _1: KEY:[2], _2: KEY:[1]]) | MAP (_._0 AS COL1, _._2 AS _1)"
99109
- result: []
100-
101110
...

0 commit comments

Comments
 (0)