Change the bool member of the Query structure to bits

Started by Quan Zongliangover 2 years ago6 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t49218
psql -h localhost -U postgres

Built from patchset v2 (message #2), July 27, 2026 at 11:18 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t49218_2 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t49218_2 && git checkout t49218_2

Patchset v2 (message #2) is on t49218_2

Jump to latest
#1Quan Zongliang
quanzongliang@yeah.net

The Query structure has an increasing number of bool attributes. This is
likely to increase in the future. And they have the same properties.
Wouldn't it be better to store them in bits? Common statements don't use
them, so they have little impact. This also saves memory space.

--
Quan Zongliang

Attachments:

query-bits.patchtext/plain; charset=UTF-8; name=query-bits.patchDownload+303-257
#2Quan Zongliang
quanzongliang@yeah.net
In reply to: Quan Zongliang (#1)
Re: Change the bool member of the Query structure to bits

Sorry. I forgot to save a file. This is the latest.

Show quoted text

On 2024/2/20 18:07, Quan Zongliang wrote:

The Query structure has an increasing number of bool attributes. This is
likely to increase in the future. And they have the same properties.
Wouldn't it be better to store them in bits? Common statements don't use
them, so they have little impact. This also saves memory space.

--
Quan Zongliang

Attachments:

t49218_2
query-bits.patchtext/plain; charset=UTF-8; name=query-bits.patchDownload+303-257
#3Tomas Vondra
tomas.vondra@2ndquadrant.com
In reply to: Quan Zongliang (#2)
Re: Change the bool member of the Query structure to bits

On 2/20/24 11:11, Quan Zongliang wrote:

Sorry. I forgot to save a file. This is the latest.

On 2024/2/20 18:07, Quan Zongliang wrote:

The Query structure has an increasing number of bool attributes. This
is likely to increase in the future. And they have the same
properties. Wouldn't it be better to store them in bits? Common
statements don't use them, so they have little impact. This also saves
memory space.

Hi,

Are we really adding bools to Query that often? A bit of git-blame says
it's usually multiple years to add a single new flag, which is what I'd
expect. I doubt that'll change.

As for the memory savings, can you quantify how much memory this would save?

I highly doubt that's actually true (or at least measurable). The Query
struct has ~256B, the patch cuts that to ~232B. But we allocate stuff in
power-of-2, so we'll allocate 256B chunk anyway. And we allocate very
few of those objects anyway ...

regards

--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Quan Zongliang (#1)
Re: Change the bool member of the Query structure to bits

Quan Zongliang <quanzongliang@yeah.net> writes:

The Query structure has an increasing number of bool attributes. This is
likely to increase in the future. And they have the same properties.
Wouldn't it be better to store them in bits? Common statements don't use
them, so they have little impact. This also saves memory space.

I'm -1 on that, for three reasons:

* The amount of space saved is quite negligible. If queries had many
Query structs then it could matter, but they don't.

* This causes enough code churn to create a headache for back-patching.

* This'll completely destroy the readability of these flags in
pprint output.

I'm not greatly in love with the macro layer you propose, either,
but those details don't matter because I think we should just
leave well enough alone.

regards, tom lane

#5Quan Zongliang
quanzongliang@yeah.net
In reply to: Tom Lane (#4)
Re: Change the bool member of the Query structure to bits

On 2024/2/20 23:45, Tom Lane wrote:

Quan Zongliang <quanzongliang@yeah.net> writes:

The Query structure has an increasing number of bool attributes. This is
likely to increase in the future. And they have the same properties.
Wouldn't it be better to store them in bits? Common statements don't use
them, so they have little impact. This also saves memory space.

I'm -1 on that, for three reasons:

* The amount of space saved is quite negligible. If queries had many
Query structs then it could matter, but they don't.

* This causes enough code churn to create a headache for back-patching.

* This'll completely destroy the readability of these flags in
pprint output.

I'm not greatly in love with the macro layer you propose, either,
but those details don't matter because I think we should just
leave well enough alone.

regards, tom lane

I get it. Withdraw.

#6Quan Zongliang
quanzongliang@yeah.net
In reply to: Tomas Vondra (#3)
Re: Change the bool member of the Query structure to bits

On 2024/2/20 19:18, Tomas Vondra wrote:

On 2/20/24 11:11, Quan Zongliang wrote:

Sorry. I forgot to save a file. This is the latest.

On 2024/2/20 18:07, Quan Zongliang wrote:

The Query structure has an increasing number of bool attributes. This
is likely to increase in the future. And they have the same
properties. Wouldn't it be better to store them in bits? Common
statements don't use them, so they have little impact. This also saves
memory space.

Hi,

Are we really adding bools to Query that often? A bit of git-blame says
it's usually multiple years to add a single new flag, which is what I'd
expect. I doubt that'll change.

As for the memory savings, can you quantify how much memory this would save?

I highly doubt that's actually true (or at least measurable). The Query
struct has ~256B, the patch cuts that to ~232B. But we allocate stuff in
power-of-2, so we'll allocate 256B chunk anyway. And we allocate very
few of those objects anyway ...

regards

That makes sense. Withdraw.