You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@impala.apache.org by "Jim Apple (Code Review)" <ge...@cloudera.org> on 2016/08/01 00:48:56 UTC

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Jim Apple has uploaded a new change for review.

  http://gerrit.cloudera.org:8080/3822

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................

IMPALA-2581: LIMIT can be propagated down into some aggregations

SELECT DISTINCT f FROM t LIMIT n

Can pass the LIMIT all the way down to the pre-aggregation, which
leads to a nearly unbounded speedup on these queries in large tables
when n is low.

Queries like

SELECT f, COUNT(*) FROM t GROUP BY f LIMIT n

cannot pass the LIMIT down to the pre-aggregation, and so experience a
smaller speedup.

Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
---
M be/src/exec/partitioned-aggregation-node-ir.cc
M be/src/exec/partitioned-aggregation-node.cc
M be/src/exec/partitioned-aggregation-node.h
M fe/src/main/java/com/cloudera/impala/planner/DistributedPlanner.java
M testdata/workloads/functional-planner/queries/PlannerTest/aggregation.test
M testdata/workloads/functional-planner/queries/PlannerTest/tpcds-all.test
M testdata/workloads/targeted-perf/queries/aggregation.test
7 files changed, 68 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/22/3822/1
-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 1
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Jim Apple (Code Review)" <ge...@cloudera.org>.
Jim Apple has uploaded a new patch set (#4).

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................

IMPALA-2581: LIMIT can be propagated down into some aggregations

SELECT DISTINCT f FROM t LIMIT n

Can pass the LIMIT all the way down to the pre-aggregation, which
leads to a nearly unbounded speedup on these queries in large tables
when n is low.

Queries like

SELECT f, COUNT(*) FROM t GROUP BY f LIMIT n

cannot pass the LIMIT down to the pre-aggregation, and so experience a
smaller speedup.

Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
---
M be/src/exec/exec-node.h
M be/src/exec/partitioned-aggregation-node-ir.cc
M be/src/exec/partitioned-aggregation-node.cc
M be/src/exec/partitioned-aggregation-node.h
M fe/src/main/java/com/cloudera/impala/analysis/AggregateInfoBase.java
M fe/src/main/java/com/cloudera/impala/planner/DistributedPlanner.java
M testdata/workloads/functional-planner/queries/PlannerTest/aggregation.test
M testdata/workloads/functional-planner/queries/PlannerTest/tpcds-all.test
M testdata/workloads/functional-query/queries/QueryTest/spilling.test
M testdata/workloads/targeted-perf/queries/aggregation.test
10 files changed, 87 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/22/3822/4
-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Tim Armstrong (Code Review)" <ge...@cloudera.org>.
Tim Armstrong has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 1:

(4 comments)

I thought some more about this during the day and I think there are some subtle  issues around spilling and passthrough aggs with limits that we don't have test coverage for.

http://gerrit.cloudera.org:8080/#/c/3822/1/be/src/exec/partitioned-aggregation-node-ir.cc
File be/src/exec/partitioned-aggregation-node-ir.cc:

Line 130:   if (group_count_ < max_groups_) {
> We can turn this into a one-liner without an else.
This will also give incorrect results for spilling aggregations. If AGGREGATED_ROWS is true, this is processing a spilled row that was already aggregated, so will double-count that group.

I think we should add a test to test_spilling.py that exercises this code path (e.g. a large agg with a high limit).


Line 250:     if (group_count_ >= max_groups_) {
I think this should should actually occur before the remaining_capacity check. Otherwise we'll pass through rows even when we already have enough groups (meaning the limit isn't correctly enforced and we do unnecessary work).


http://gerrit.cloudera.org:8080/#/c/3822/1/be/src/exec/partitioned-aggregation-node.cc
File be/src/exec/partitioned-aggregation-node.cc:

PS1, Line 506: ReachedLimit
Do we actually need these limit checks for grouping aggregations now? If not, we should remove the redundant checks and document how the limit is enforced.


Line 519: Status PartitionedAggregationNode::GetRowsStreaming(RuntimeState* state,
We don't actually implement limit checks in GetRowsStreaming(), since previously limits were never applied.

I think in some circumstances (e.g. if it switches into streaming mode) the current version of the patch will return more rows than the limit. I think if you fix my other comment in -ir.cc this may not be the case, but it would be good to think through and document why the explicit limit check isn't necessary (if it indeed isn't).


-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 1
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Jim Apple (Code Review)" <ge...@cloudera.org>.
Jim Apple has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 2:

PS2 is only rebasing (for LZO changes from Impala-LZO repo)

-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 2
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Jim Apple (Code Review)" <ge...@cloudera.org>.
Jim Apple has abandoned this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Abandoned

I hope to get back to this sometime, but it is low priority for now.

-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: abandon
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Alex Behm (Code Review)" <ge...@cloudera.org>.
Alex Behm has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 4:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/3822/4/fe/src/main/java/com/cloudera/impala/analysis/AggregateInfoBase.java
File fe/src/main/java/com/cloudera/impala/analysis/AggregateInfoBase.java:

Line 182:   public boolean isPreaggLimitable() {
I think this optimization will produce a wrong plan for queries like this one:

select distinct a.int_col, a.bigint_col, b.int_col, b.bigint_col
from functional.alltypes a, functional.alltypes b
where a.id = b.id
having a.int_col + b.int_col < 10

Unfortunately, our planner is not clever enough to move this predicate below the aggregation, but it shows that this optimization does rely on an additional assumption that is not always true for us.

I think we can only safely move the limit into the pre-agg if there are no HAVING-clause predicates. Alternatively, we can also move the HAVING clause predicates into the pre-agg.


-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Jim Apple (Code Review)" <ge...@cloudera.org>.
Jim Apple has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 1:

(2 comments)

http://gerrit.cloudera.org:8080/#/c/3822/1/be/src/exec/partitioned-aggregation-node.cc
File be/src/exec/partitioned-aggregation-node.cc:

PS1, Line 506: ReachedLimit
> Do we actually need these limit checks for grouping aggregations now? If no
Where do you think that documentation would be most useful?


Line 519: Status PartitionedAggregationNode::GetRowsStreaming(RuntimeState* state,
> We don't actually implement limit checks in GetRowsStreaming(), since previ
When you say "why THE explicit limit check isn't necessary" [emphasis mine], you mean why GetRowsStreaming doesn't need a limit check?


-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 1
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Jim Apple (Code Review)" <ge...@cloudera.org>.
Jim Apple has uploaded a new patch set (#3).

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................

IMPALA-2581: LIMIT can be propagated down into some aggregations

SELECT DISTINCT f FROM t LIMIT n

Can pass the LIMIT all the way down to the pre-aggregation, which
leads to a nearly unbounded speedup on these queries in large tables
when n is low.

Queries like

SELECT f, COUNT(*) FROM t GROUP BY f LIMIT n

cannot pass the LIMIT down to the pre-aggregation, and so experience a
smaller speedup.

Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
---
M be/src/exec/exec-node.h
M be/src/exec/partitioned-aggregation-node-ir.cc
M be/src/exec/partitioned-aggregation-node.cc
M be/src/exec/partitioned-aggregation-node.h
M fe/src/main/java/com/cloudera/impala/analysis/AggregateInfoBase.java
M fe/src/main/java/com/cloudera/impala/planner/DistributedPlanner.java
M testdata/workloads/functional-planner/queries/PlannerTest/aggregation.test
M testdata/workloads/functional-planner/queries/PlannerTest/tpcds-all.test
M testdata/workloads/functional-query/queries/QueryTest/spilling.test
M testdata/workloads/targeted-perf/queries/aggregation.test
10 files changed, 85 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/22/3822/3
-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 3
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Tim Armstrong (Code Review)" <ge...@cloudera.org>.
Tim Armstrong has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 4:

Thanks for the comment Alex - I totally missed the case of LIMIT + conjuncts. I think the implications of this for the backend are:

* We can't limit max_groups_ if there are conjuncts, since we don't know how many groups will be filtered by the conjuncts.
* We therefore need to add back in the ReachedLimit() checks for the merge aggregation that I erroneously thought we could remove.

-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Jim Apple (Code Review)" <ge...@cloudera.org>.
Jim Apple has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 4:

(7 comments)

http://gerrit.cloudera.org:8080/#/c/3822/3/be/src/exec/partitioned-aggregation-node.h
File be/src/exec/partitioned-aggregation-node.h:

PS3, Line 294: //
> ///
Done


PS3, Line 298:  max_groups_ is checked by comparing it to group_count_, th
> Maybe a little misleading. I think the important check is in the -ir.cc fil
Done


Line 299:   /// partitions. If the partitions hold more than max_groups_ groups, no new groups need
> could be a little clearer: something like "limiting the number of groups in
Done


PS3, Line 671: 
> ///
Done


Line 675:   /// that this function can return true when the rows have not been returned from this
> I think the name is misleading because it's not really enforcing the same t
Done


http://gerrit.cloudera.org:8080/#/c/3822/3/fe/src/main/java/com/cloudera/impala/planner/DistributedPlanner.java
File fe/src/main/java/com/cloudera/impala/planner/DistributedPlanner.java:

PS3, Line 910: isPreaggLim
> isPreaggLimitable()?
Done


http://gerrit.cloudera.org:8080/#/c/3822/3/testdata/workloads/functional-query/queries/QueryTest/spilling.test
File testdata/workloads/functional-query/queries/QueryTest/spilling.test:

Line 632: # Test spilling an agg with a LIMIT; see IMPALA-2581
> Were you able to reproduce the bug? I'd feel a lot more comfortable if we h
Yes - with PS1 and PS2 do not work with this query


-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Jim Apple (Code Review)" <ge...@cloudera.org>.
Jim Apple has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 4:

> LIMIT + conjuncts

Do you have a particular shape of query in mind?

-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Tim Armstrong (Code Review)" <ge...@cloudera.org>.
Tim Armstrong has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 4:

I think we need a grouping aggregation with a limit and a having clause. I don't think we need anything complicated, just a straightforward group by with having clause on one of the alltypes tables to show that we return the correct number of rows after filtering

It's not clear to me that we can have a select distinct where conjuncts are place at the aggregation, since they should always be able to be pushed before the aggregation.

-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Alex Behm (Code Review)" <ge...@cloudera.org>.
Alex Behm has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 4:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/3822/4/fe/src/main/java/com/cloudera/impala/analysis/AggregateInfoBase.java
File fe/src/main/java/com/cloudera/impala/analysis/AggregateInfoBase.java:

Line 182:   public boolean isPreaggLimitable() {
> How would you feel about adding the no-HAVING-clause restriction here and a
Works for me.


-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Tim Armstrong (Code Review)" <ge...@cloudera.org>.
Tim Armstrong has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 4: -Code-Review

I'm seeing some odd behaviour playing around with this. It looks like the streaming aggregation is still processing its full input, so e.g. select distinct * from tpch_20_parquet.lineitem limit 10 takes a while. I think what's happening is that it doesn't return eos to the DataStreamSender, which then keeps repeatedly calling GetNext().



Operator       #Hosts  Avg Time  Max Time    #Rows  Est. #Rows  Peak Mem  Est. Peak Mem  Detail                         
------------------------------------------------------------------------------------------------------------------------
04:EXCHANGE         1  38.626us  38.626us       10          10         0        -1.00 B  UNPARTITIONED                  
03:AGGREGATE        3  54.343ms  57.428ms       28          10   2.48 MB       10.00 MB  FINALIZE                       
02:EXCHANGE         3  44.995us  54.989us       28          10         0              0  HASH(tpch_20_parquet.lineit... 
01:AGGREGATE        3  33s149ms  33s383ms       30          10   5.00 MB       10.00 MB  STREAMING                      
00:SCAN HDFS        3  16s484ms  21s155ms  119.99M     119.99M   1.35 GB        1.38 GB  tpch_20_parquet.lineitem

-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Jim Apple (Code Review)" <ge...@cloudera.org>.
Jim Apple has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 4:

> it doesn't return
 > eos to the DataStreamSender, which then keeps repeatedly calling
 > GetNext().

Sorry, you lost me a little there. What is the "it" that doesn't return eos to the DataStreamSender? And do you think the streaming pre-agg node or the exchange node is calling GetNext() too many times? (or something else, maybe?)

-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Tim Armstrong (Code Review)" <ge...@cloudera.org>.
Tim Armstrong has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 4: Code-Review+1

-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Jim Apple (Code Review)" <ge...@cloudera.org>.
Jim Apple has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 4:

> I will be able to look at this again in about 9 days.

I will be working on doing an upstream release for the moment, delaying this patch.

-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Tim Armstrong (Code Review)" <ge...@cloudera.org>.
Tim Armstrong has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 1:

(10 comments)

Nice! I mainly focused on the backend, assuming Alex will also look at the FE changes.

http://gerrit.cloudera.org:8080/#/c/3822/1/be/src/exec/partitioned-aggregation-node-ir.cc
File be/src/exec/partitioned-aggregation-node-ir.cc:

Line 130:   if (group_count_ < max_groups_) {
We can turn this into a one-liner without an else.

if (group_count_ >= max_groups_) return Status::OK();
++group_count_

I was thinking about whether it's worth it to try and optimise out the branch with codegen. It'd be straightforward if you a have non-inlined function call has_max_groups() or even just max_groups() and use FindAndReplaceConstant(). I think the difference in perf is probably negligible right now since AddIntermediateTuple() isn't codegen'd, so I'm ok either way


Line 184:   if (group_count_ >= max_groups_ && aggregate_evaluators_.empty()) {
I don't think there's any advantage to cross-compiling this code, so it'd be better to do this check in the caller.


PS1, Line 185: child_eos_
This is overloading this variable. I'd rather keep the invariant that child_eos_ means the child returned eos.


http://gerrit.cloudera.org:8080/#/c/3822/1/be/src/exec/partitioned-aggregation-node.cc
File be/src/exec/partitioned-aggregation-node.cc:

PS1, Line 330: group_count_ >= max_groups_ && aggregate_evaluators_.empty()
I think it would be good to factor this out into an inline function, e.g. IsDoneProcessingInput() - or some better name. Will make it easier to follow the flow of the calling functions and avoid some duplication of logic.


PS1, Line 331: eos
I think this is overloading the meaning of this 'eos' variable. Maybe rename it to 'done' so the name doesn't imply that there's the end of some stream.

Actually, it seems like it would make more sense to do this check after batch.Reset() below or before calling GetNext() above, then just breaking out of the loop. Otherwise we're fetching an extra batch that we're not processing.


Line 573:     child_batch_->Reset(); // All rows from child_batch_ were processed.
I think we can move the check from ProcessBatchStreaming() to either after this Reset() or before GetNext() above, instead of setting child_eos_ to break out of this loop.


http://gerrit.cloudera.org:8080/#/c/3822/1/be/src/exec/partitioned-aggregation-node.h
File be/src/exec/partitioned-aggregation-node.h:

Line 295:   // ExecNode.
Document that it's always a positive value, and set to the max value of int64 if there's no limit.


http://gerrit.cloudera.org:8080/#/c/3822/1/fe/src/main/java/com/cloudera/impala/planner/DistributedPlanner.java
File fe/src/main/java/com/cloudera/impala/planner/DistributedPlanner.java:

Line 806:     if (!(node.getAggInfo().getAggregateExprs().isEmpty()
This needs a comment to explain the intent. Or, maybe better, factor this check and the one below out into a shared method with a meaningful name.


PS1, Line 807:       || 
|| normally goes on the previous line.


PS1, Line 911: !(node.getAggInfo().getAggregateExprs().isEmpty()
             :               || node.getAggInfo().getGroupingExprs().isEmpty()
Make this a method of AggInfo?


-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 1
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Jim Apple (Code Review)" <ge...@cloudera.org>.
Jim Apple has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 4:

(1 comment)

http://gerrit.cloudera.org:8080/#/c/3822/4/fe/src/main/java/com/cloudera/impala/analysis/AggregateInfoBase.java
File fe/src/main/java/com/cloudera/impala/analysis/AggregateInfoBase.java:

Line 182:   public boolean isPreaggLimitable() {
> I think this optimization will produce a wrong plan for queries like this o
How would you feel about adding the no-HAVING-clause restriction here and adding a TODO or a JIRA about moving the HAVING into pre-agg?


-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Tim Armstrong (Code Review)" <ge...@cloudera.org>.
Tim Armstrong has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 3:

(7 comments)

http://gerrit.cloudera.org:8080/#/c/3822/3/be/src/exec/partitioned-aggregation-node.h
File be/src/exec/partitioned-aggregation-node.h:

PS3, Line 294: //
///


PS3, Line 298: max_groups_ is checked via ReachedAggregationLimit() below.
Maybe a little misleading. I think the important check is in the -ir.cc file before adding a new row to the hash table. ReachedAggregationLimit() is just an optimisation to return early.


Line 299:   // needed for limiting the number of rows returned, since the limit is applied in the
could be a little clearer: something like "limiting the number of groups in a grouping aggregation is sufficient to limit the number of output rows".


PS3, Line 671:   
///


Line 675:   bool ReachedAggregationLimit() const {
I think the name is misleading because it's not really enforcing the same thing as ReachedLimit() (your comment does mention this). ReachedLimit() which checks if the node has output enough rows. Whereas this is checking if it's consumed enough input rows. Maybe ConsumedEnoughInput()?


http://gerrit.cloudera.org:8080/#/c/3822/3/fe/src/main/java/com/cloudera/impala/planner/DistributedPlanner.java
File fe/src/main/java/com/cloudera/impala/planner/DistributedPlanner.java:

PS3, Line 910: isLimitable
isPreaggLimitable()?


http://gerrit.cloudera.org:8080/#/c/3822/3/testdata/workloads/functional-query/queries/QueryTest/spilling.test
File testdata/workloads/functional-query/queries/QueryTest/spilling.test:

Line 632: # Test spilling an agg with a LIMIT; see IMPALA-2581
Were you able to reproduce the bug? I'd feel a lot more comfortable if we had test coverage for that case since it's easy to get wrong.


-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 3
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Jim Apple (Code Review)" <ge...@cloudera.org>.
Jim Apple has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 3:

(15 comments)

http://gerrit.cloudera.org:8080/#/c/3822/1/be/src/exec/partitioned-aggregation-node-ir.cc
File be/src/exec/partitioned-aggregation-node-ir.cc:

Line 130:   if (group_count_ >= max_groups_) return Status::OK();
> This will also give incorrect results for spilling aggregations. If AGGREGA
Done


Line 184:   const int cache_size = expr_vals_cache->capacity();
> I don't think there's any advantage to cross-compiling this code, so it'd b
Done


PS1, Line 185: r (int gro
> This is overloading this variable. I'd rather keep the invariant that child
Done


Line 250:       // Avoid repeatedly trying to add tuples when under memory pressure.
> I think this should should actually occur before the remaining_capacity che
Done


http://gerrit.cloudera.org:8080/#/c/3822/1/be/src/exec/partitioned-aggregation-node.cc
File be/src/exec/partitioned-aggregation-node.cc:

PS1, Line 330: here is grouping, so we will do partitioned aggregation.
> I think it would be good to factor this out into an inline function, e.g. I
Done


PS1, Line 331: (pr
> I think this is overloading the meaning of this 'eos' variable. Maybe renam
Done


PS1, Line 506: 
> Probably in the header with max_groups_. I think we should also add a DCHEC
Done


Line 519:   DCHECK(!child_eos_);
> Yep exactly. Before this change it didn't need a limit check because the pl
Documentation added on to new member variables.


Line 573: 
> I think we can move the check from ProcessBatchStreaming() to either after 
Done


http://gerrit.cloudera.org:8080/#/c/3822/1/be/src/exec/partitioned-aggregation-node.h
File be/src/exec/partitioned-aggregation-node.h:

Line 295:   // ExecNode. max_groups_ equals limit_ if limit_ is non-negative, and is the maximum
> Document that it's always a positive value, and set to the max value of int
Done


http://gerrit.cloudera.org:8080/#/c/3822/2/be/src/exec/partitioned-aggregation-node.h
File be/src/exec/partitioned-aggregation-node.h:

PS2, Line 296: // int6
> const?
Done


PS2, Line 339: aggregated_parti
> A nice new feature of c++11, but since we initialize in the initialization 
Done


http://gerrit.cloudera.org:8080/#/c/3822/1/fe/src/main/java/com/cloudera/impala/planner/DistributedPlanner.java
File fe/src/main/java/com/cloudera/impala/planner/DistributedPlanner.java:

Line 806:     if (!node.getAggInfo().isLimitable()) {
> This needs a comment to explain the intent. Or, maybe better, factor this c
Done


PS1, Line 807: node.unse
> || normally goes on the previous line.
removed


PS1, Line 911: de.unsetLimit();
             :       }
> Make this a method of AggInfo?
Done


-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 3
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Tim Armstrong (Code Review)" <ge...@cloudera.org>.
Tim Armstrong has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 1:

(2 comments)

http://gerrit.cloudera.org:8080/#/c/3822/1/be/src/exec/partitioned-aggregation-node.cc
File be/src/exec/partitioned-aggregation-node.cc:

PS1, Line 506: ReachedLimit
> Where do you think that documentation would be most useful?
Probably in the header with max_groups_. I think we should also add a DCHECK below: limit_ == -1 || num_rows_returned_ <= limit_

Same with the streaming case.


Line 519: Status PartitionedAggregationNode::GetRowsStreaming(RuntimeState* state,
> When you say "why THE explicit limit check isn't necessary" [emphasis mine]
Yep exactly. Before this change it didn't need a limit check because the planner never applied limits to streaming aggregations. After this change it's less obviously correct.


-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 1
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Jim Apple (Code Review)" <ge...@cloudera.org>.
Jim Apple has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 4:

I will be able to look at this again in about 9 days.

-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 4
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: No

[Impala-ASF-CR] IMPALA-2581: LIMIT can be propagated down into some aggregations

Posted by "Matthew Jacobs (Code Review)" <ge...@cloudera.org>.
Matthew Jacobs has posted comments on this change.

Change subject: IMPALA-2581: LIMIT can be propagated down into some aggregations
......................................................................


Patch Set 2:

(2 comments)

A few nits to add to Tim's comments which haven't been addressed in rev2 yet...

http://gerrit.cloudera.org:8080/#/c/3822/2/be/src/exec/partitioned-aggregation-node.h
File be/src/exec/partitioned-aggregation-node.h:

PS2, Line 296: int64_t
const?


PS2, Line 339: group_count_ = 0
A nice new feature of c++11, but since we initialize in the initialization lists it'd be best to put it there for consistency.


-- 
To view, visit http://gerrit.cloudera.org:8080/3822
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I59c5b7af7a73ccdbc5496b28eacb9b6859d202bc
Gerrit-PatchSet: 2
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-Owner: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Alex Behm <al...@cloudera.com>
Gerrit-Reviewer: Jim Apple <jb...@cloudera.com>
Gerrit-Reviewer: Matthew Jacobs <mj...@cloudera.com>
Gerrit-Reviewer: Tim Armstrong <ta...@cloudera.com>
Gerrit-HasComments: Yes