Re: Violation of principle that plan trees are read-only - Mailing list pgsql-hackers

From Jose Luis Tallon
Subject Re: Violation of principle that plan trees are read-only
Date
Msg-id 2437dab7-396e-fa2c-82a4-dec101621061@adv-solutions.net
Whole thread Raw
In response to Re: Violation of principle that plan trees are read-only  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On 19/5/25 16:45, Tom Lane wrote:
> [snip]
> For one thing, I'm not sure how to teach the compiler that casting
> "Query *" to "ConstQuery *" is okay but vice versa isn't.
>
> Does C++ have a better story in this area?

Hi,

     A C++ compiler *does* enforce "const correctness" (for examples 
see, for example, Meyer's fantastic "Efficient C++" series).

It seems that Postgres is approaching the class of complexity/maturity 
that (modern) C++ was designed to solve. It should be unmatched in that 
area. I believe that, with recent platform deprecations, the vast 
majority of systems where one can compile a modern Postgres should 
already have a decent C++ compiler available (g++ & clang probably cover 
 >95%)

As opposed to say, rewriting in Rust ---where the compilar also does a 
very substantial checking of semantics at compile time---, introducing 
some C++ in Postgres could be as simple as throwing some "#ifdef 
__cplusplus__  extern "C" { #endif" in the headers and use the required 
subset in certain modules *only*.

     (this is how, for instance, Bacula did it ~two decades ago)

The planner and parts of the bufmgr / arenas (palloc et al.) seem to me 
as the most obvious candidates to try. I'm not sure whether it'd 
introduce any unintended regressions, though.

> I haven't touched it
> in so long that I don't remember.

C++ 17 would be the standard to tackle, IMHO.


HTH,

     J.L.

-- 
Parkinson's Law: Work expands to fill the time alloted to it.




pgsql-hackers by date:

Previous
From: Nico Williams
Date:
Subject: Re: Should we optimize the `ORDER BY random() LIMIT x` case?
Next
From: Nathan Bossart
Date:
Subject: Re: Remove Instruction Synchronization Barrier in spin_delay() for ARM64 architecture