pgcentralfoundation / pgrx

Build Postgres Extensions with Rust!
Other
3.42k stars 224 forks source link

`pg_aggregate` needs a makeover #1362

Open workingjubilee opened 8 months ago

workingjubilee commented 8 months ago

Initially inspired from https://github.com/pgcentralfoundation/pgrx/pull/1357 and its discoveries.

Other issues related to aggregates specifically:

Related to all SQL generation:

workingjubilee commented 1 month ago

effectively blocked on #1661

workingjubilee commented 1 week ago

Lifted from #1731:

The problem isn't with Aggregate, per se, it's with certain types.

These are aggregates that are supposed to manage composite types. But we know composite types are allocated in Postgres, thus are effectively lifetime-bound. But #[pg_aggregate] and Aggregate don't know how to convey the lifetimes through. Thus even annotating it with something like this does not actually fix the problem:


#[pg_aggregate]
impl<'a> Aggregate for SumScritches<'a> {
type State = i32;
const INITIAL_CONDITION: Option<&'static str> = Some("0");
type Args = pgrx::name!(value, pgrx::composite_type!('a, "Dog"));
fn state(
    current: Self::State,
    arg: Self::Args,
    _fcinfo: pg_sys::FunctionCallInfo,
) -> Self::State {
    todo!()
}

}


> Thus in order to make aggregates work for complex cases we must break the world for them as well, making all their functions use the correct, lifetime-bound types. Hopefully this will let us simplify the code expansion for them as well.