public inbox for [email protected]
help / color / mirror / Atom feedFrom: Michel Pelletier <[email protected]>
To: Tom Lane <[email protected]>
Cc: Pavel Stehule <[email protected]>
Cc: [email protected]
Subject: Re: Using Expanded Objects other than Arrays from plpgsql
Date: Wed, 25 Dec 2024 12:25:18 -0800
Message-ID: <CACxu=v+ZyWad6JpToJrUhTTYJneMsTGwGdgNCb39QaG7Tc359Q@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CACxu=vJaKFNsYxooSnW1wEgsAO5u_v1XYBacfVJ14wgJV_PYeg@mail.gmail.com>
<[email protected]>
<CACxu=vLXvpzN4X3k+9jsMt6ujuOvFVUSkA80t_cROSsF4y2jQQ@mail.gmail.com>
<[email protected]>
<CACxu=vKEF8Qa-OaADFxf0uMg-xw6gH_CNCWd2s+xaqh-gY4=xg@mail.gmail.com>
<[email protected]>
<[email protected]>
<CACxu=v++HNmss59yGUDkRny7g=M8tZ2YXF07AUXqKVGqcSfxGQ@mail.gmail.com>
<[email protected]>
<[email protected]>
<CACxu=v+dn37zr8gx5xNP-EZY3OLtGLTHrbx_ZkCQc40HpyMLKA@mail.gmail.com>
<[email protected]>
<CACxu=vL7i_U_iSNpREe8eCAMEyKHuPpk9THRpBhk+ar0U1EdOw@mail.gmail.com>
<CACxu=vKLc6f5N8_DR58LKkE1eohWSxTvThTeGsLm7p7QH1aFBA@mail.gmail.com>
<CACxu=vJf2S=ysun_h=zmYNu6oUM47+egbpX5mMC0X9BJK=EQwQ@mail.gmail.com>
<CACxu=vK+S6BXN8ZYyBvqQBWrcwHXqtue1-ZuKO3+XtHGBYcDUQ@mail.gmail.com>
<CAFj8pRCd6xcH-AYEyHFdGdU89O9JjZ-v-pyQnOwd9zNJkCEdhQ@mail.gmail.com>
<[email protected]>
<CACxu=vKCSSqO6y0ES4SJnFSMBa8szANOykQkG3L1LsLnN2v0JA@mail.gmail.com>
<CACxu=vL4g2pPgEg66F-ttZ5jVuMba8K31vsoEYKbTJ7q6jk0hg@mail.gmail.com>
<[email protected]>
<CACxu=vKjvJSftCgBPa78tbdpBnJOq9DCrtV8x=o0_cuCOoxLbA@mail.gmail.com>
<[email protected]>
On Mon, Dec 23, 2024 at 8:26 AM Tom Lane <[email protected]> wrote:
> Michel Pelletier <[email protected]> writes:
> > ...
> > I agree it makes sense to have more use cases before making deeper
> > changes. I only work with expanded forms, but need to call wait() to
> > pre-expand the object to avoid multiple expansions in functions that can
> > take the same object in multiple parameters.
>
> Hmm. I agree that the wait() call is a bit ugly, but there are at
> least two things that seem worth looking into before we go so far
> as inventing type-support infrastructure:
>
2. If the problem is primarily with passing the same object to
> multiple parameters of a function, couldn't you detect and optimize
> that within the function? It would be messier than just blindly
> applying DatumGetWhatever() to each parameter position; but with a
> bit of thought I bet you could create some support logic that would
> hide most of the mess.
>
Ah that's a great idea, and it works beautifully! Now I can do an
efficient triangle count without even needing a function, see below
expand_matrix is only called once:
postgres=# select reduce_scalar(mxm(graph, graph, mask=>graph, c=>graph)) /
6 as tcount from vlivejournals ;
DEBUG: matrix_mxm
DEBUG: DatumGetMatrix
DEBUG: expand_matrix -- only called once!
DEBUG: new_matrix
DEBUG: DatumGetMatrixMaybeA
DEBUG: DatumGetMatrixMaybeAB
DEBUG: DatumGetMatrixMaybeABC
DEBUG: matrix_reduce_scalar
DEBUG: DatumGetMatrix
DEBUG: new_scalar
DEBUG: scalar_div_int32
DEBUG: new_scalar
DEBUG: scalar_out
┌─────────────────┐
│ tcount │
├─────────────────┤
│ int32:177820130 │
└─────────────────┘
What a wonderful Christmas present to me, thank you Tom!
That pretty much resolves my main issues. I'm still in an exploratory
phase but I think this gets me pretty far. Is this something that has to
wait for 18 to be released? Also do you need any further testing or code
reviewing from me?
-Michel
view thread (34+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: Re: Using Expanded Objects other than Arrays from plpgsql
In-Reply-To: <CACxu=v+ZyWad6JpToJrUhTTYJneMsTGwGdgNCb39QaG7Tc359Q@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox