my-ship-it commented on PR #1167:
URL: https://github.com/apache/cloudberry/pull/1167#issuecomment-2987442425
> > Just tried. Should ORCA reuse same transno here?
> > ```
> > CREATE FUNCTION my_sum_trans(state int, val int) RETURNS int AS $$
> > BEGIN
> > RETURN state + val;
> > END;
> > $$ LANGUAGE plpgsql;
> >
> > CREATE AGGREGATE my_sum1(int) (
> > SFUNC = my_sum_trans,
> > STYPE = int,
> > INITCOND = '0'
> > );
> >
> > CREATE AGGREGATE my_sum2(int) (
> > SFUNC = my_sum_trans,
> > STYPE = int,
> > INITCOND = '0'
> > );
> >
> > postgres=# set debug_print_aggref_in_explain to on;
> > SET
> > postgres=# explain select my_sum1(v1), my_sum2(v2) from tgb1;
> > QUERY PLAN
> >
------------------------------------------------------------------------------------
> > Aggregate (cost=0.00..431.00 rows=1 width=8)
> > AggRefs(TargetList): [(0, 0), (1, 1)]
> > -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..431.00
rows=1 width=8)
> > -> Seq Scan on tgb1 (cost=0.00..431.00 rows=1 width=8)
> > Optimizer: GPORCA
> > (5 rows)
> > ```
>
> nope, same as PG
>
> ```
> postgres=# explain select my_sum1(v1), my_sum2(v2) from tgb1;
> QUERY PLAN
>
-----------------------------------------------------------------------------------------
> Aggregate (cost=44519.00..44519.01 rows=1 width=8)
> AggRefs(TargetList): [(0, 0), (1, 1)]
> -> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..1469.00
rows=86100 width=8)
> -> Seq Scan on tgb1 (cost=0.00..321.00 rows=28700 width=8)
> Optimizer: Postgres query optimizer
> (5 rows)
> ```
>
> The `find_compatible_agg` logical is if current `aggno` not match, the
output `same_input_transnos` is empty. so `aggtransno` always be -1 in this
case.
My faults, tried as following with **FINALFUNC_MODIFY = SHAREABLE**
specified, and it works
```
CREATE FUNCTION my_sum_trans(state int, val int) RETURNS int AS $$
BEGIN
RETURN state + val;
END;
$$ LANGUAGE plpgsql;
CREATE AGGREGATE my_sum1(int) (
SFUNC = my_sum_trans,
STYPE = int,
INITCOND = '0',
FINALFUNC_MODIFY = SHAREABLE
);
CREATE AGGREGATE my_sum2(int) (
SFUNC = my_sum_trans,
STYPE = int,
INITCOND = '0',
FINALFUNC_MODIFY = SHAREABLE
);
postgres=# set debug_print_aggref_in_explain to on;
SET
postgres=# explain select my_sum1(v), my_sum2(v) from tbl;
QUERY PLAN
------------------------------------------------------------------------------------
Aggregate (cost=0.00..431.00 rows=1 width=8)
AggRefs(TargetList): [(0, 0), (1, 0)]
-> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..431.00 rows=1
width=4)
-> Seq Scan on tbl (cost=0.00..431.00 rows=1 width=4)
Optimizer: GPORCA
(5 rows)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]