Re: libpq: PQfnumber overload for not null-terminated strings

From: Ivan Trofimov <i(dot)trofimow(at)yandex(dot)ru>
To: Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: libpq: PQfnumber overload for not null-terminated strings
Date: 2024-02-27 14:49:02
Message-ID: 310dea21-cd4e-385e-d312-e6ea786836da@yandex.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> However, I do think you could convert this per-row overhead in your
> case to per-query overhead by caching the result of PQfnumber for each
> unique C++ string_view. Afaict that should solve your performance
> problem.

Absolutely, you're right.

The problem here is not that it's impossible to write it in a performant
way, but rather that it's impossible to do so in a performant _and_
clean way given the convenient abstractions wrapper-libraries provide:
here's a `Result`, which consists of `Row`s, which in turn consist of
`Field`s.
The most natural and straightforward way to iterate over a `Result`
would be in the lines of that loop, and people do write code like that
because it's what they expect to just work given the abstractions (and
it does, it's just slow).
Caching the result of PQfnumber could be done, but would result in
somewhat of a mess on a call-site.

I like your idea of 'PQfnumberRaw': initially i was only concerned about
a null-terminated string requirement affecting my interfaces (because
users complained about that to me,
https://github.com/userver-framework/userver/issues/494), but I think
PQfnumberRaw could solve both problems (PQfnumber being a bottleneck
when called repeatedly and a null-terminated string requirement)
simultaneously.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2024-02-27 14:55:58 Re: Improve eviction algorithm in ReorderBuffer
Previous Message Stephen Frost 2024-02-27 14:48:54 Re: [PATCH] updates to docs about HOT updates for BRIN