public inbox for [email protected]
help / color / mirror / Atom feedFrom: Ranier Vilela <[email protected]>
To: Pg Hackers <[email protected]>
Subject: Avoid multiple calls to memcpy (src/backend/access/index/genam.c)
Date: Mon, 9 Mar 2026 10:16:20 -0300
Message-ID: <CAEudQApbWon+3Eb9x4WW_D-JkSt2mvfx99dXu9VZ4AeCuTh=fw@mail.gmail.com> (raw)
Hi.
In the functions *systable_beginscan* and *systable_beginscan_ordered*,
is possible a small optimization.
The array *idxkey* can be constructed in one go with a single call to
mempcy.
The excess might not make much of a difference, but I think it's worth the
effort.
patch attached.
best regards,
Ranier Vilela
Attachments:
[application/octet-stream] avoid-multiple-calls-to-memcpy-genam.patch (1.1K, 3-avoid-multiple-calls-to-memcpy-genam.patch)
download | inline diff:
diff --git a/src/backend/access/index/genam.c b/src/backend/access/index/genam.c
index 5e89b86a62..affaed2c48 100644
--- a/src/backend/access/index/genam.c
+++ b/src/backend/access/index/genam.c
@@ -435,13 +435,13 @@ systable_beginscan(Relation heapRelation,
idxkey = palloc_array(ScanKeyData, nkeys);
+ memcpy(idxkey, key, nkeys * sizeof(ScanKeyData));
+
/* Convert attribute numbers to be index column numbers. */
for (i = 0; i < nkeys; i++)
{
int j;
- memcpy(&idxkey[i], &key[i], sizeof(ScanKeyData));
-
for (j = 0; j < IndexRelationGetNumberOfAttributes(irel); j++)
{
if (key[i].sk_attno == irel->rd_index->indkey.values[j])
@@ -688,13 +688,13 @@ systable_beginscan_ordered(Relation heapRelation,
idxkey = palloc_array(ScanKeyData, nkeys);
+ memcpy(idxkey, key, nkeys * sizeof(ScanKeyData));
+
/* Convert attribute numbers to be index column numbers. */
for (i = 0; i < nkeys; i++)
{
int j;
- memcpy(&idxkey[i], &key[i], sizeof(ScanKeyData));
-
for (j = 0; j < IndexRelationGetNumberOfAttributes(indexRelation); j++)
{
if (key[i].sk_attno == indexRelation->rd_index->indkey.values[j])
view thread (17+ 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]
Subject: Re: Avoid multiple calls to memcpy (src/backend/access/index/genam.c)
In-Reply-To: <CAEudQApbWon+3Eb9x4WW_D-JkSt2mvfx99dXu9VZ4AeCuTh=fw@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