public inbox for [email protected]  
help / color / mirror / Atom feed
From: Dean Rasheed <[email protected]>
To: Yugo Nagata <[email protected]>
Cc: Andres Freund <[email protected]>
Cc: [email protected]
Subject: Re: Allow to collect statistics on virtual generated columns
Date: Thu, 26 Mar 2026 17:25:23 +0000
Message-ID: <CAEZATCXkZwJ_6FCM7RMKFiNC4ui+CLmL-=Y9AiYmDpnPS+ftWw@mail.gmail.com> (raw)
In-Reply-To: <CAEZATCWkQhG0fwz5Z34vn=LcKdCb3DGfomPPwcXL_qtKfEt5+w@mail.gmail.com>
References: <[email protected]>
	<kp43uuykq64fyqxnlihq2rzntarextvzibuzturajfucl6bayo@6fcnflboemtt>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<CAEZATCV6=q0-5HFBMg4jFS-j1ZCwANhp1sLXBQZYsK2ZLwq0AQ@mail.gmail.com>
	<[email protected]>
	<CAEZATCUR5B=6M7H2bwRU0_6FrbSE8yHe_+9bTbRUdU=jE33yog@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<CAEZATCWkQhG0fwz5Z34vn=LcKdCb3DGfomPPwcXL_qtKfEt5+w@mail.gmail.com>

On Thu, 26 Mar 2026 at 16:00, Dean Rasheed <[email protected]> wrote:
>
> On Thu, 26 Mar 2026 at 15:09, Yugo Nagata <[email protected]> wrote:
> >
> > I've attached an updated patch including the documentation and tests.

Looking at get_relation_statistics(), I think that you need to call
expand_generated_columns_in_expr() *before* ChangeVarNodes() so that
Vars in the expanded expression end up with the correct varno.

This obviously affects queries with more than one table in the FROM
clause, e.g.:

drop table if exists foo;
create table foo (a int, b int generated always as (a*2) virtual);
insert into foo select x from generate_series(1,10) x;
insert into foo select 100 from generate_series(1,500);
create statistics s on b from foo;
analyse foo;
explain select * from foo f1, foo f2 where f1.b = 200 and f2.b = 200;

                            QUERY PLAN
-------------------------------------------------------------------
 Nested Loop  (cost=0.00..47.56 rows=1500 width=16)
   ->  Seq Scan on foo f1  (cost=0.00..10.65 rows=500 width=4)
         Filter: ((a * 2) = 200)
   ->  Materialize  (cost=0.00..10.66 rows=3 width=4)
         ->  Seq Scan on foo f2  (cost=0.00..10.65 rows=3 width=4)
               Filter: ((a * 2) = 200)
(6 rows)

Regards,
Dean





view thread (21+ 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]
  Subject: Re: Allow to collect statistics on virtual generated columns
  In-Reply-To: <CAEZATCXkZwJ_6FCM7RMKFiNC4ui+CLmL-=Y9AiYmDpnPS+ftWw@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