Re: [HACKERS] GROUP BY before JOIN

2015-08-04 Thread Ashutosh Bapat
On Tue, Aug 4, 2015 at 4:00 PM, David Rowley david.row...@2ndquadrant.com wrote: On 4 August 2015 at 21:56, Ashutosh Bapat ashutosh.ba...@enterprisedb.com wrote: This looks like one example of general problem of finding optimal order for SQL operations. Consider a query defined as

[HACKERS] GROUP BY before JOIN

2015-08-04 Thread David Rowley
== Overview == As of today we always perform GROUP BY at the final stage, after each relation in the query has been joined. This of course works, but it's not always the most optimal way of executing the query. Consider the following two relations: create table product (product_id int primary

Re: [HACKERS] GROUP BY before JOIN

2015-08-04 Thread Ashutosh Bapat
This looks like one example of general problem of finding optimal order for SQL operations. Consider a query defined as sql_op1(sql_op2(sql_op3(A, B), sql_op4(C, D), sql_op5(E, F where sql_op can be SQL operation like join, grouping, aggregation, projection, union, intersection, limit,

Re: [HACKERS] GROUP BY before JOIN

2015-08-04 Thread David Rowley
On 4 August 2015 at 21:56, Ashutosh Bapat ashutosh.ba...@enterprisedb.com wrote: This looks like one example of general problem of finding optimal order for SQL operations. Consider a query defined as sql_op1(sql_op2(sql_op3(A, B), sql_op4(C, D), sql_op5(E, F where sql_op can be SQL