Re: Violation of principle that plan trees are read-only

From: Nico Williams <nico(at)cryptonector(dot)com>
To: Isaac Morland <isaac(dot)morland(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: Violation of principle that plan trees are read-only
Date: 2025-05-20 20:43:55
Message-ID: aCzpi+c+tUNM4z4q@ubby
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, May 19, 2025 at 08:41:06AM -0400, Isaac Morland wrote:
> I assume this question has an obvious negative answer, but why can't we
> attach const declarations to the various structures that make up the plan
> tree (at all levels, all the way down)? I know const doesn't actually
> prevent a value from changing, but at least the compiler would complain if
> code accidentally tried.

What you want is for C to have a type attribute that denotes
immutability all the way down. `const` doesn't do that. One thing that
could be done is to write a utility that creates const-all-the-way-down
clones of given types, but such a tool can't be written as C
pre-processor macros -- it would have to be a tool that parses the
actual type definitions, or uses DWARF or similar to from the
compilation of a file (I've done this latter before, but this weds you
to compilers that output DWARF, which MSVC doesn't, for example).

Really, the C committee ought to add this at some point, darn it. It
would be the opposite of Rust's &mut.

Nico
--

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Scott Mead 2025-05-20 20:58:28 Re: Disable parallel query by default
Previous Message Andres Freund 2025-05-20 20:40:34 Re: Violation of principle that plan trees are read-only