Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions contrib/auto_explain/expected/auto_explain_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ LOG: statement: SELECT count(*) FROM auto_explain_test.t1, auto_explain_test.t2
LOG: duration: 180.126 ms plan:
Query Text: SELECT count(*) FROM auto_explain_test.t1, auto_explain_test.t2;
Finalize Aggregate (cost=0.00..1326086.34 rows=1 width=8) (actual rows=1 loops=1)
Output: count()
Output: count(*)
-> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..1326086.34 rows=1 width=8) (actual rows=3 loops=1)
Output: (PARTIAL count())
Output: (PARTIAL count(*))
-> Partial Aggregate (cost=0.00..1326086.34 rows=1 width=8) (actual rows=1 loops=1)
Output: PARTIAL count()
Output: PARTIAL count(*)
-> Nested Loop (cost=0.00..1326086.34 rows=334001 width=1) (actual rows=340340 loops=1)
Join Filter: true
-> Broadcast Motion 3:3 (slice2; segments: 3) (cost=0.00..431.02 rows=1001 width=1) (actual rows=1001 loops=1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ where i < (select count(*) from smallt where smallt.i = smallt2.i);
---------------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..862.02 rows=50 width=15)
-> Result (cost=0.00..862.01 rows=17 width=15)
Filter: (smallt2.i < COALESCE((count()), '0'::bigint))
Filter: (smallt2.i < COALESCE((count(*)), '0'::bigint))
-> Hash Left Join (cost=0.00..862.01 rows=17 width=23)
Hash Cond: (smallt2.i = smallt.i)
-> Seq Scan on smallt2 (cost=0.00..431.00 rows=17 width=15)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,11 @@ select count(*) from gist_tbl;
QUERY PLAN
------------------------------------------------------------------------------------------------------------
Finalize Aggregate
Output: count()
Output: count(*)
-> Gather Motion 3:1 (slice1; segments: 3)
Output: (PARTIAL count())
Output: (PARTIAL count(*))
-> Partial Aggregate
Output: PARTIAL count()
Output: PARTIAL count(*)
-> Seq Scan on public.gist_tbl
Settings: enable_bitmapscan = 'off', enable_indexonlyscan = 'on', enable_seqscan = 'off', optimizer = 'on'
Optimizer: Pivotal Optimizer (GPORCA)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12893,7 +12893,7 @@ select * from foo join (select a, count(*) + 5 as cnt from tbtree where tbtree.a
-> Seq Scan on foo
Filter: (a < 5000)
-> Result
Filter: ((count()) < 2)
Filter: ((count(*)) < 2)
-> HashAggregate
Group Key: tbtree.a
-> Index Only Scan using tbtreexa on tbtree
Expand Down Expand Up @@ -12921,7 +12921,7 @@ select * from foo join (select a, count(*) + 5 as cnt from tbitmap where tbitmap
-> Seq Scan on foo
Filter: (a < 5000)
-> Result
Filter: ((count()) < 2)
Filter: ((count(*)) < 2)
-> HashAggregate
Group Key: tbitmap.a
-> Bitmap Heap Scan on tbitmap
Expand Down Expand Up @@ -12988,9 +12988,9 @@ select * from foo join (select a, count(*) + cnt1 as cnt2 from (select a, count(
-> Seq Scan on foo
Filter: (a < 5000)
-> Result
Filter: ((count()) < 2)
Filter: ((count(*)) < 2)
-> HashAggregate
Group Key: tbtree.a, count()
Group Key: tbtree.a, count(*)
-> HashAggregate
Group Key: tbtree.a
-> Index Only Scan using tbtreexa on tbtree
Expand Down Expand Up @@ -13030,7 +13030,7 @@ select * from foo join (select a, count(*) as cnt from tbitmap group by a) grby
--------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Nested Loop
Join Filter: ((foo.a = tbitmap.a) AND (foo.b = (count())))
Join Filter: ((foo.a = tbitmap.a) AND (foo.b = (count(*))))
-> Seq Scan on foo
-> HashAggregate
Group Key: tbitmap.a
Expand Down Expand Up @@ -13074,7 +13074,7 @@ select * from foo join (select b, count(*) as cnt from tbtree group by b) grby o
------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Nested Loop
Join Filter: (foo.a = (count()))
Join Filter: (foo.a = (count(*)))
-> Broadcast Motion 3:3 (slice3; segments: 3)
-> Seq Scan on foo
-> Materialize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ order by count(*);
QUERY PLAN
------------------------------------------------------------------------------
Sort
Sort Key: (count())
Sort Key: (count(*))
-> Finalize Aggregate
-> Gather Motion 3:1 (slice1; segments: 3)
-> Partial Aggregate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ SELECT count(*) FROM
QUERY PLAN
-----------------------------------------------------------------------------
Aggregate
Output: count()
Output: count(*)
-> Gather Motion 3:1 (slice1; segments: 3)
-> GroupAggregate
Group Key: tenk1.two, tenk1.four, tenk1.two
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ explain select * from csq_pullup t0 where 1= (select count(*) from csq_pullup t1
---------------------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..862.00 rows=1 width=17)
-> Result (cost=0.00..862.00 rows=1 width=17)
Filter: (1 = COALESCE((count()), '0'::bigint))
Filter: (1 = COALESCE((count(*)), '0'::bigint))
-> Hash Left Join (cost=0.00..862.00 rows=1 width=25)
Hash Cond: (t0.t = t1.t)
-> Seq Scan on csq_pullup t0 (cost=0.00..431.00 rows=1 width=17)
Expand Down Expand Up @@ -642,7 +642,7 @@ explain select * from csq_pullup t0 where 1= (select count(*) from csq_pullup t1
------------------------------------------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..862.00 rows=1 width=17)
-> Result (cost=0.00..862.00 rows=1 width=17)
Filter: (1 = COALESCE((count()), '0'::bigint))
Filter: (1 = COALESCE((count(*)), '0'::bigint))
-> Hash Left Join (cost=0.00..862.00 rows=1 width=25)
Hash Cond: (t0.t = (t1.v)::text)
-> Seq Scan on csq_pullup t0 (cost=0.00..431.00 rows=1 width=17)
Expand Down Expand Up @@ -672,7 +672,7 @@ explain select * from csq_pullup t0 where 1= (select count(*) from csq_pullup t1
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------
Result (cost=0.00..862.00 rows=1 width=17)
Filter: (1 = COALESCE((count()), '0'::bigint))
Filter: (1 = COALESCE((count(*)), '0'::bigint))
-> Hash Left Join (cost=0.00..862.00 rows=2 width=25)
Hash Cond: (t0.n = t1.n)
-> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..431.00 rows=1 width=17)
Expand Down Expand Up @@ -789,13 +789,13 @@ explain select * from csq_pullup t0 where 1= (select count(*) from csq_pullup t1
---------------------------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..862.00 rows=1 width=17)
-> Result (cost=0.00..862.00 rows=1 width=17)
Filter: (1 = COALESCE((count()), '0'::bigint))
Filter: (1 = COALESCE((count(*)), '0'::bigint))
-> Hash Left Join (cost=0.00..862.00 rows=1 width=25)
Hash Cond: (t0.t = t1.t)
-> Seq Scan on csq_pullup t0 (cost=0.00..431.00 rows=1 width=17)
-> Hash (cost=431.00..431.00 rows=1 width=12)
-> Result (cost=0.00..431.00 rows=1 width=12)
Filter: ((count()) < 10)
Filter: ((count(*)) < 10)
-> GroupAggregate (cost=0.00..431.00 rows=1 width=20)
Group Key: t1.t
-> Sort (cost=0.00..431.00 rows=1 width=4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ where (exists(select 1 from tenk1 k where k.unique1 = t.unique2) or ten < 0);
-> Gather Motion 3:1 (slice1; segments: 3)
-> Partial Aggregate
-> Result
Filter: ((COALESCE((count()), '0'::bigint) > '0'::bigint) OR (t.ten < 0))
Filter: ((COALESCE((count(*)), '0'::bigint) > '0'::bigint) OR (t.ten < 0))
-> Hash Left Join
Hash Cond: (t.unique2 = k.unique1)
-> Redistribute Motion 3:3 (slice2; segments: 3)
Expand Down Expand Up @@ -955,7 +955,7 @@ select * from exists_tbl t1
----------------------------------------------------------------------------------------
Gather Motion 3:1 (slice1; segments: 3)
-> Result
Filter: ((COALESCE((count()), '0'::bigint) > '0'::bigint) OR (t1.c3 < 0))
Filter: ((COALESCE((count(*)), '0'::bigint) > '0'::bigint) OR (t1.c3 < 0))
-> Hash Left Join
Hash Cond: (t1.c1 = t2.c2)
-> Dynamic Seq Scan on exists_tbl t1
Expand Down
20 changes: 10 additions & 10 deletions contrib/postgres_fdw/expected/gp2pg_postgres_fdw_optimizer.out
Original file line number Diff line number Diff line change
Expand Up @@ -3328,7 +3328,7 @@ select count(*), sum(t1.c1), avg(t2.c1) from ft1 t1 inner join ft1 t2 on (t1.c2
QUERY PLAN
------------------------------------------------------------------------------------
Aggregate
Output: count(), sum(t1.c1), avg(t2.c1)
Output: count(*), sum(t1.c1), avg(t2.c1)
-> Hash Join
Output: t1.c1, t2.c1
Hash Cond: (t1.c2 = t2.c2)
Expand Down Expand Up @@ -3569,7 +3569,7 @@ select count(*) from (select c5, count(c1) from ft1 group by c5, sqrt(c2) having
QUERY PLAN
-------------------------------------------------------------------------------------------------------------
Aggregate
Output: count()
Output: count(*)
-> Result
Filter: (((((avg(ft1.c1)) / (avg(ft1.c1))))::double precision * random()) <= '1'::double precision)
-> Result
Expand Down Expand Up @@ -4298,10 +4298,10 @@ select count(*), x.b from ft1, (select c2 a, sum(c1) b from ft1 group by c2) x w
QUERY PLAN
-------------------------------------------------------------------------------
Sort
Output: (count()), (sum(ft1_1.c1))
Sort Key: (count()), (sum(ft1_1.c1))
Output: (count(*)), (sum(ft1_1.c1))
Sort Key: (count(*)), (sum(ft1_1.c1))
-> HashAggregate
Output: count(), (sum(ft1_1.c1))
Output: count(*), (sum(ft1_1.c1))
Group Key: (sum(ft1_1.c1))
-> Hash Join
Output: (sum(ft1_1.c1))
Expand Down Expand Up @@ -4378,7 +4378,7 @@ select count(*), sum(t1.c1), avg(t2.c1) from (select c1 from ft4 where c1 betwee
QUERY PLAN
------------------------------------------------------------------------------------------------
Aggregate
Output: count(), sum(ft4.c1), avg(ft5.c1)
Output: count(*), sum(ft4.c1), avg(ft5.c1)
-> Hash Full Join
Output: ft4.c1, ft5.c1
Hash Cond: (ft4.c1 = ft5.c1)
Expand Down Expand Up @@ -7545,7 +7545,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT count(*) FROM ft1 WHERE c2 < 0;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------
Aggregate
Output: count()
Output: count(*)
-> Result
Output: NULL::integer, NULL::tid, NULL::xid, NULL::cid, NULL::xid, NULL::cid, NULL::oid, NULL::integer
One-Time Filter: false
Expand All @@ -7564,7 +7564,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT count(*) FROM ft1 WHERE c2 < 0;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------
Aggregate
Output: count()
Output: count(*)
-> Result
Output: NULL::integer, NULL::tid, NULL::xid, NULL::cid, NULL::xid, NULL::cid, NULL::oid, NULL::integer
One-Time Filter: false
Expand Down Expand Up @@ -7599,7 +7599,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT count(*) FROM ft1 WHERE c2 >= 0;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------
Aggregate
Output: count()
Output: count(*)
-> Result
Output: NULL::integer, NULL::tid, NULL::xid, NULL::cid, NULL::xid, NULL::cid, NULL::oid, NULL::integer
One-Time Filter: false
Expand All @@ -7618,7 +7618,7 @@ EXPLAIN (VERBOSE, COSTS OFF) SELECT count(*) FROM ft1 WHERE c2 >= 0;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------
Aggregate
Output: count()
Output: count(*)
-> Result
Output: NULL::integer, NULL::tid, NULL::xid, NULL::cid, NULL::xid, NULL::cid, NULL::oid, NULL::integer
One-Time Filter: false
Expand Down
1 change: 1 addition & 0 deletions src/backend/gpopt/translate/CTranslatorDXLToScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ CTranslatorDXLToScalar::TranslateDXLScalarAggrefToScalar(
aggref->aggargtypes = NIL;
aggref->aggno = -1;
aggref->aggtransno = -1;
aggref->aggstar = dxlop->IsAggStar();

CMDIdGPDB *agg_mdid =
GPOS_NEW(m_mp) CMDIdGPDB(IMDId::EmdidGeneral, aggref->aggfnoid);
Expand Down
11 changes: 5 additions & 6 deletions src/backend/gpopt/translate/CTranslatorScalarToDXL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,8 @@ CTranslatorScalarToDXL::TranslateAggrefToDXL(
{
GPOS_ASSERT(IsA(expr, Aggref));
const Aggref *aggref = (Aggref *) expr;
BOOL is_distinct = false;
BOOL is_distinct;
BOOL is_agg_star;

if (aggref->aggorder != NIL && GPOS_FTRACE(EopttraceDisableOrderedAgg))
{
Expand All @@ -1435,10 +1436,8 @@ CTranslatorScalarToDXL::TranslateAggrefToDXL(
"Ordered aggregates disabled. Enable by setting optimizer_enable_orderedagg=on"));
}

if (aggref->aggdistinct)
{
is_distinct = true;
}
is_distinct = aggref->aggdistinct;
is_agg_star = aggref->aggstar;

/*
* We shouldn't see any partial aggregates in the parse tree, they're produced
Expand Down Expand Up @@ -1486,7 +1485,7 @@ CTranslatorScalarToDXL::TranslateAggrefToDXL(

CDXLScalarAggref *aggref_scalar = GPOS_NEW(m_mp) CDXLScalarAggref(
m_mp, agg_mdid, resolved_ret_type, is_distinct, agg_stage,
CTranslatorUtils::GetAggKind(aggref->aggkind), aggargtypes_values);
CTranslatorUtils::GetAggKind(aggref->aggkind), aggargtypes_values, is_agg_star);

// create the DXL node holding the scalar aggref
CDXLNode *dxlnode = GPOS_NEW(m_mp) CDXLNode(m_mp, aggref_scalar);
Expand Down
14 changes: 8 additions & 6 deletions src/backend/gporca/libgpopt/include/gpopt/base/CUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,16 @@ class CUtils
static CScalarAggFunc *PopAggFunc(
CMemoryPool *mp, IMDId *pmdidAggFunc, const CWStringConst *pstrAggFunc,
BOOL is_distinct, EAggfuncStage eaggfuncstage, BOOL fSplit,
IMDId *
pmdidResolvedReturnType, // return type to be used if original return type is ambiguous
EAggfuncKind aggkind, ULongPtrArray *argtypes, BOOL fRepSafe);
IMDId * pmdidResolvedReturnType, // return type to be used if original return type is ambiguous
EAggfuncKind aggkind, ULongPtrArray *argtypes, BOOL fRepSafe,
BOOL is_agg_star);

// generate an aggregate function
static CExpression *PexprAggFunc(CMemoryPool *mp, IMDId *pmdidAggFunc,
const CWStringConst *pstrAggFunc,
const CColRef *colref, BOOL is_distinct,
EAggfuncStage eaggfuncstage, BOOL fSplit);
EAggfuncStage eaggfuncstage, BOOL fSplit,
BOOL is_agg_star);

// generate a count(*) expression
static CExpression *PexprCountStar(CMemoryPool *mp);
Expand Down Expand Up @@ -288,7 +289,7 @@ class CUtils

// generate a count(col) expression
static CExpression *PexprCount(CMemoryPool *mp, const CColRef *colref,
BOOL is_distinct);
BOOL is_distinct, BOOL is_agg_star);

// generate a min(col) expression
static CExpression *PexprMin(CMemoryPool *mp, CMDAccessor *md_accessor,
Expand All @@ -297,7 +298,8 @@ class CUtils
// generate an aggregate expression
static CExpression *PexprAgg(CMemoryPool *mp, CMDAccessor *md_accessor,
IMDType::EAggType agg_type,
const CColRef *colref, BOOL is_distinct);
const CColRef *colref, BOOL is_distinct,
BOOL is_agg_star);

// generate a select expression
static CExpression *PexprLogicalSelect(CMemoryPool *mp, CExpression *pexpr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class CScalarAggFunc : public CScalar
// is aggregate replicate slice execution safe
BOOL m_fRepSafe;

// is agg(*)
BOOL m_is_agg_star;

public:
CScalarAggFunc(const CScalarAggFunc &) = delete;

Expand All @@ -97,7 +100,7 @@ class CScalarAggFunc : public CScalar
IMDId *resolved_rettype, const CWStringConst *pstrAggFunc,
BOOL is_distinct, EAggfuncStage eaggfuncstage, BOOL fSplit,
EAggfuncKind aggkind, ULongPtrArray *argtypes,
BOOL fRepSafe);
BOOL fRepSafe, BOOL m_is_agg_star);

// dtor
~CScalarAggFunc() override
Expand Down Expand Up @@ -172,6 +175,12 @@ class CScalarAggFunc : public CScalar
return m_is_distinct;
}

BOOL
IsAggStar() const
{
return m_is_agg_star;
}

void
SetIsDistinct(BOOL val)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class CXformEagerAgg : public CXformExploration
CMemoryPool *mp, // memory pool
IMDId *agg_mdid, // original global aggregate function
CWStringConst *agg_name, CExpressionArray *agg_arg_array,
BOOL is_distinct, ULongPtrArray *arg_types,
BOOL is_distinct, BOOL is_agg_star, ULongPtrArray *arg_types,
CExpression **lower_proj_elem_expr // output project element of the new
// lower aggregate
);
Expand All @@ -111,7 +111,7 @@ class CXformEagerAgg : public CXformExploration
CMemoryPool *mp, // memory pool
IMDId *agg_mdid, // aggregate mdid to create
CWStringConst *agg_name, CColRef *lower_colref, CColRef *output_colref,
BOOL is_distinct, ULongPtrArray *arg_types,
BOOL is_distinct, BOOL is_agg_star, ULongPtrArray *arg_types,
CExpression **upper_proj_elem_expr // output project element of the new
// upper aggregate
);
Expand Down
Loading
Loading