agora inbox for [email protected]
help / color / mirror / Atom feedDeleting older versions in unique indexes to avoid page splits
1661+ messages / 7 participants
[nested] [flat]
* Deleting older versions in unique indexes to avoid page splits
@ 2020-07-01 00:03 Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
0 siblings, 1 reply; 1661+ messages in thread
From: Peter Geoghegan @ 2020-07-01 00:03 UTC (permalink / raw)
To: PostgreSQL Hackers <[email protected]>
Attached is a POC patch that teaches nbtree to delete old duplicate
versions from unique indexes. The optimization targets non-HOT
duplicate version bloat. Although the patch is rather rough, it
nevertheless manages to more or less eliminate a whole class of index
bloat: Unique index bloat from non-HOT updates in workloads where no
transaction lasts for more than a few seconds. For example, it
eliminates index bloat with a custom pgbench workload that uses an
INCLUDE unique index on pgbench_accounts.aid (with abalance as the
non-key attribute), instead of the usual accounts primary key.
Similarly, with a standard pgbench_accounts primary key alongside an
extra non-unique index on abalance, the primary key will never have
any page splits with the patch applied. It's almost as if the updates
were actually HOT updates, at least if you focus on the unique index
(assuming that there are no long-running transactions).
The patch repurposes the deduplication infrastructure to delete
duplicates within unique indexes, provided they're actually safe to
VACUUM. This is somewhat different to the _bt_unique_check() LP_DEAD
bit setting stuff, in that we have to access heap pages that we
probably would not have to access otherwise -- it's something that we
go out of our way to make happen at the point that the page is about
to split, not something that happens in passing at no extra cost. The
general idea is to exploit the fact that duplicates in unique indexes
are usually deadwood.
We only need to "stay one step ahead" of the bloat to avoid all page
splits in many important cases. So we usually only have to access a
couple of heap pages to avoid a page split in each case. In
traditional serial/identity column primary key indexes, any page split
that happens that isn't a split of the current rightmost page must be
caused by version churn. It should be possible to avoid these
"unnecessary" page splits altogether (again, barring long-running
transactions).
I would like to get early feedback on high level direction. While the
patch seems quite promising, I am uncertain about my general approach,
and how it might fit into some much broader effort to control bloat in
general.
There are some clear downsides to my approach. The patch has grotty
heuristics that try to limit the extra work performed to avoid page
splits -- the cost of accessing additional heap pages while a buffer
lock is held on the leaf page needs to be kept. under control. No
doubt this regresses some workloads without giving them a clear
benefit. Also, the optimization only ever gets used with unique
indexes, since they're the only case where a duplicate naturally
suggests version churn, which can be targeted fairly directly, and
without wasting too many cycles when it doesn't work out.
It's not at all clear how we could do something like this with
non-unique indexes. One related-though-distinct idea that might be
worth considering occurs to me: teach nbtree to try to set LP_DEAD
bits in non-unique indexes, in about the same way as it will in
_bt_check_unique() for unique indexes. Perhaps the executor could hint
to btinsert()/aminsert() that it's inserting a duplicate caused by a
non-HOT update, so it's worth trying to LP_DEAD nearby duplicates --
especially if they're on the same heap page as the incoming item.
There is a wholly separate question about index bloat that is of long
term strategic importance to the Postgres project: what should we do
about long running transactions? I tend to think that we can address
problems in that area by indicating that it is safe to delete
"intermediate" versions -- tuples that are not too old to be seen by
the oldest transaction, that are nevertheless not needed (they're too
new to be interesting to the old transaction's snapshot, but also too
old to be interesting to any other snapshot). Perhaps this
optimization could be pursued in a phased fashion, starting with index
AMs, where it seems less scary.
I recently read a paper that had some ideas about what we could do
here [1]. IMV it is past time that we thrashed together a "remove
useless intermediate versions" design that is compatible with the
current heapam design.
[1] https://dl.acm.org/doi/pdf/10.1145/3318464.3389714
--
Peter Geoghegan
Attachments:
[application/octet-stream] 0001-Non-opportunistically-delete-B-Tree-items.patch (14.4K, ../../CAH2-Wzm+maE3apHB8NOtmM=p-DO65j2V5GzAWCOEEuy3JZgb2g@mail.gmail.com/2-0001-Non-opportunistically-delete-B-Tree-items.patch)
download | inline diff:
From 4b93191614e76d703b77eb80faec8259f91374fc Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Tue, 30 Jun 2020 16:29:27 -0700
Subject: [PATCH] Non-opportunistically delete B-Tree items.
Repurpose deduplication infrastructure to delete items in unique indexes
at the point where we'd usually have to split the page, even when they
don't have their LP_DEAD bits set. Testing has shown that this is
almost completely effective at preventing "version bloat" from non-HOT
updates in unique indexes, provided there are no long running
transactions.
Note that INCLUDE indexes support the optimization.
---
src/include/access/nbtree.h | 2 +-
src/backend/access/nbtree/README | 13 +-
src/backend/access/nbtree/nbtdedup.c | 332 +++++++++++++++++++++++++-
src/backend/access/nbtree/nbtinsert.c | 9 +-
4 files changed, 349 insertions(+), 7 deletions(-)
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index 79506c748b..3c6b3c1cf4 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -1029,7 +1029,7 @@ extern void _bt_parallel_advance_array_keys(IndexScanDesc scan);
*/
extern void _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
IndexTuple newitem, Size newitemsz,
- bool checkingunique);
+ bool checkingunique, bool allequalimage);
extern void _bt_dedup_start_pending(BTDedupState state, IndexTuple base,
OffsetNumber baseoff);
extern bool _bt_dedup_save_htid(BTDedupState state, IndexTuple itup);
diff --git a/src/backend/access/nbtree/README b/src/backend/access/nbtree/README
index 216d419841..27d1ef2669 100644
--- a/src/backend/access/nbtree/README
+++ b/src/backend/access/nbtree/README
@@ -800,7 +800,18 @@ Deduplication in unique indexes helps to prevent these pathological page
splits. Storing duplicates in a space efficient manner is not the goal,
since in the long run there won't be any duplicates anyway. Rather, we're
buying time for standard garbage collection mechanisms to run before a
-page split is needed.
+page split is needed. Also, the deduplication pass performs a targeted
+form of opportunistic deletion in the case of unique indexes.
+
+The deduplication code first opportunistically delete whatever duplicates
+happen to be present on the page with a unique indexes, since in general
+some of them are likely to already be dead to everybody. This mechanism
+is quite similar to on-the-fly deletion of index tuples that will already
+have failed to prevent a page split by the time deduplication is
+considered. The main difference is that the tuples that get deleted are
+not opportunistically marked LP_DEAD by transactions that had to read the
+tuples in any case. The implementation must weigh the need to avoid a
+page split against the extra work performed with a buffer lock held.
Unique index leaf pages only get a deduplication pass when an insertion
(that might have to split the page) observed an existing duplicate on the
diff --git a/src/backend/access/nbtree/nbtdedup.c b/src/backend/access/nbtree/nbtdedup.c
index f6be865b17..16123bf820 100644
--- a/src/backend/access/nbtree/nbtdedup.c
+++ b/src/backend/access/nbtree/nbtdedup.c
@@ -16,6 +16,8 @@
#include "access/nbtree.h"
#include "access/nbtxlog.h"
+#include "access/tableam.h"
+#include "catalog/catalog.h"
#include "miscadmin.h"
#include "utils/rel.h"
@@ -23,6 +25,14 @@ static bool _bt_do_singleval(Relation rel, Page page, BTDedupState state,
OffsetNumber minoff, IndexTuple newitem);
static void _bt_singleval_fillfactor(Page page, BTDedupState state,
Size newitemsz);
+static bool _bt_dedup_vacuum_one_page(Relation rel, Buffer buffer,
+ Relation heapRel, Size itemsz);
+static void _bt_dedup_vacuum_finish_pending(BTDedupState state);
+static bool _bt_dedup_delete_item(Relation heapRel,
+ Snapshot SnapshotNonVacuumable,
+ IndexTuple itup, int *heapaccesses);
+static int _bt_intervalcmp(const void *arg1, const void *arg2);
+static int _bt_offsetnumbercmp(const void *arg1, const void *arg2);
#ifdef USE_ASSERT_CHECKING
static bool _bt_posting_valid(IndexTuple posting);
#endif
@@ -54,7 +64,8 @@ static bool _bt_posting_valid(IndexTuple posting);
*/
void
_bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
- IndexTuple newitem, Size newitemsz, bool checkingunique)
+ IndexTuple newitem, Size newitemsz, bool checkingunique,
+ bool allequalimage)
{
OffsetNumber offnum,
minoff,
@@ -108,6 +119,30 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
maxoff = PageGetMaxOffsetNumber(page);
}
+ /*
+ * Before we actually deduplicate, see if we can non-opportunistically
+ * free some duplicate if this is special checkingunique case
+ */
+ if (checkingunique)
+ {
+ if (_bt_dedup_vacuum_one_page(rel, buf, heapRel, newitemsz))
+ return;
+
+ /*
+ * Reconsider number of items on page, in case
+ * _bt_dedup_vacuum_one_page() managed to delete an item or two
+ */
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
+ }
+
+ /*
+ * Can't actually deduplicate, so give up and split page (only here to see
+ * if we can delete non-opportunistically)
+ */
+ if (!allequalimage)
+ return;
+
/* Passed-in newitemsz is MAXALIGNED but does not include line pointer */
newitemsz += sizeof(ItemIdData);
@@ -809,6 +844,301 @@ _bt_swap_posting(IndexTuple newitem, IndexTuple oposting, int postingoff)
return nposting;
}
+/*
+ * See if duplicate unique index tuples in a unique index are eligible to be
+ * deleted, even though they don't have their LP_DEAD bit set already.
+ * Concentrate on groups of duplicates, since we're most likely to be
+ * successful there. Give up if we have to access more than a few heap pages
+ * before we can free enough space to avoid a page split.
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
+ *
+ * FIXME: Be less eager with tuples that contain NULLs, since they can be
+ * duplicates without that signaling anything about version churn. Just
+ * because we're checkingunique (which implies that incoming newitem isn't
+ * a NULL) doesn't mean there aren't lots of other NULLs on the page.
+ *
+ * FIXME: Skip over duplicates of the incoming item, which will surely have
+ * been considered within _bt_check_unique().
+ */
+static bool
+_bt_dedup_vacuum_one_page(Relation rel, Buffer buffer, Relation heapRel,
+ Size itemsz)
+{
+ OffsetNumber deletable[MaxIndexTuplesPerPage];
+ int heapaccesses = 0;
+ int ndeletable = 0;
+ OffsetNumber offnum,
+ minoff,
+ maxoff;
+ Size freespace;
+ Page page = BufferGetPage(buffer);
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+ bool finished = false;
+ bool success = false;
+ BTDedupState state;
+ SnapshotData SnapshotNonVacuumable;
+ TransactionId OldestXmin;
+ int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+
+ state = (BTDedupState) palloc(sizeof(BTDedupStateData));
+ state->deduplicate = true;
+ state->nmaxitems = 0;
+ /* Final "posting list" size should not restrict anything */
+ state->maxpostingsize = BLCKSZ;
+ state->base = NULL;
+ state->baseoff = InvalidOffsetNumber;
+ state->basetupsize = 0;
+ state->htids = palloc(state->maxpostingsize);
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+ state->nintervals = 0;
+
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
+ for (offnum = minoff;
+ offnum <= maxoff;
+ offnum = OffsetNumberNext(offnum))
+ {
+ ItemId itemid = PageGetItemId(page, offnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+
+ Assert(!ItemIdIsDead(itemid));
+
+ if (offnum == minoff)
+ {
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ else if (state->deduplicate &&
+ _bt_keep_natts_fast(rel, state->base, itup) > nkeyatts &&
+ _bt_dedup_save_htid(state, itup))
+ {
+
+ }
+ else
+ {
+ _bt_dedup_vacuum_finish_pending(state);
+
+ /* itup starts new pending posting list */
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ }
+ /* Handle the last item */
+ _bt_dedup_vacuum_finish_pending(state);
+
+ if (state->nintervals == 0)
+ {
+ pfree(state->htids);
+ pfree(state);
+ return false;
+ }
+
+ /* Access items in order of nitems, then asc page offset number order */
+ qsort(state->intervals, state->nintervals, sizeof(BTDedupInterval),
+ _bt_intervalcmp);
+
+ if (IsCatalogRelation(rel) ||
+ RelationIsAccessibleInLogicalDecoding(rel))
+ OldestXmin = RecentGlobalXmin;
+ else
+ OldestXmin =
+ TransactionIdLimitedForOldSnapshots(RecentGlobalDataXmin, rel);
+
+ InitNonVacuumableSnapshot(SnapshotNonVacuumable, OldestXmin);
+
+ freespace = PageGetFreeSpace(page);
+ for (int i = 0; i < state->nintervals; i++)
+ {
+ BTDedupInterval interval = state->intervals[i];
+ bool killed_in_interval = false;
+
+ Assert(interval.nitems > 0);
+ /* Iterate through tuples of given value */
+ for (int j = 0; j < interval.nitems; j++)
+ {
+ OffsetNumber ioff = interval.baseoff + j;
+ ItemId itemid = PageGetItemId(page, ioff);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+
+ if (killed_in_interval && j == 1 && interval.nitems == 2)
+ {
+ /*
+ * If we already killed first item in interval, and there are
+ * only two items, then assume that this isn't going to be
+ * another kill -- move on to next interval
+ */
+ break;
+ }
+
+ if (_bt_dedup_delete_item(heapRel, &SnapshotNonVacuumable, itup,
+ &heapaccesses))
+ {
+ /* Delete item */
+ ItemIdMarkDead(itemid);
+ MarkBufferDirtyHint(buffer, true);
+ deletable[ndeletable++] = ioff;
+ freespace += ItemIdGetLength(itemid);
+ killed_in_interval = true;
+
+ if (freespace >= itemsz)
+ {
+ /*
+ * We successfully avoided a page split, so we're done.
+ *
+ * XXX: We should probably find a way of doing a bit more
+ * work in passing. That should probably be accomplished
+ * by pushing much of this logic down into heapam, which
+ * can judge when it's worth going a bit further than
+ * strictly needed.
+ */
+ success = true;
+ finished = true;
+ break;
+ }
+ }
+
+ if (heapaccesses >= 10)
+ {
+ finished = true;
+ break;
+ }
+ }
+
+ if (finished)
+ break;
+ if (i >= 50)
+ break;
+ }
+
+ if (ndeletable > 0)
+ {
+ /* Have to give array to _bt_delitems_delete in asc order */
+ qsort(deletable, ndeletable, sizeof(OffsetNumber),
+ _bt_offsetnumbercmp);
+ _bt_delitems_delete(rel, buffer, deletable, ndeletable, heapRel);
+ }
+
+ pfree(state->htids);
+ pfree(state);
+
+ return success;
+}
+
+static void
+_bt_dedup_vacuum_finish_pending(BTDedupState state)
+{
+ Assert(state->nitems > 0);
+ Assert(state->nitems <= state->nhtids);
+ Assert(state->intervals[state->nintervals].baseoff == state->baseoff);
+
+ if (state->nitems == 1)
+ {
+ /* Don't merge */
+ }
+ else
+ {
+ /* Save final number of items for posting list */
+ state->intervals[state->nintervals].nitems = state->nitems;
+ /* Increment nintervals, since we wrote a new posting list tuple */
+ state->nintervals++;
+ }
+
+ /* Reset state for next pending posting list */
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+}
+
+static bool
+_bt_dedup_delete_item(Relation heapRel, Snapshot SnapshotNonVacuumable,
+ IndexTuple itup, int *heapaccesses)
+{
+ bool all_dead;
+ ItemPointerData htid;
+
+ all_dead = false;
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ Assert(ItemPointerIsValid(&itup->t_tid));
+
+ (*heapaccesses)++;
+ htid = itup->t_tid;
+ if (table_index_fetch_tuple_check(heapRel, &htid,
+ SnapshotNonVacuumable, &all_dead))
+ return false;
+
+ if (!all_dead)
+ return false;
+ }
+ else
+ {
+ Assert(_bt_posting_valid(itup));
+
+ for (int i = 0; i < BTreeTupleGetNPosting(itup); i++)
+ {
+ (*heapaccesses)++;
+ htid = *BTreeTupleGetPostingN(itup, i);
+ if (table_index_fetch_tuple_check(heapRel,
+ &htid,
+ SnapshotNonVacuumable,
+ &all_dead))
+ return false;
+
+ if (!all_dead)
+ return false;
+ }
+ }
+
+ /* All tuples in HOT chain are vacuumable */
+ return true;
+}
+
+/*
+ * qsort-style comparator used by _bt_dedup_vacuum_one_page()
+ */
+static int
+_bt_intervalcmp(const void *arg1, const void *arg2)
+{
+ BTDedupInterval *inter1 = (BTDedupInterval *) arg1;
+ BTDedupInterval *inter2 = (BTDedupInterval *) arg2;
+
+ /* Note: This sorts intervals in descending order */
+ if (inter1->nitems > inter2->nitems)
+ return -1;
+ if (inter1->nitems < inter2->nitems)
+ return 1;
+
+ /* Now tiebreak on itemoffsetnumber order, asc */
+ if (inter1->baseoff > inter2->baseoff)
+ return 1;
+ if (inter1->baseoff < inter2->baseoff)
+ return -1;
+
+ return 0;
+}
+
+/*
+ * qsort-style comparator used by _bt_dedup_vacuum_one_page()
+ */
+static int
+_bt_offsetnumbercmp(const void *arg1, const void *arg2)
+{
+ OffsetNumber *inter1 = (OffsetNumber *) arg1;
+ OffsetNumber *inter2 = (OffsetNumber *) arg2;
+
+ if (*inter1 > *inter2)
+ return 1;
+ if (*inter1 < *inter2)
+ return -1;
+
+ Assert(false);
+
+ return 0;
+}
+
/*
* Verify posting list invariants for "posting", which must be a posting list
* tuple. Used within assertions.
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index b86c122763..17549ba24f 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -874,7 +874,9 @@ _bt_findinsertloc(Relation rel,
* If the target page is full, see if we can obtain enough space by
* erasing LP_DEAD items. If that fails to free enough space, see if
* we can avoid a page split by performing a deduplication pass over
- * the page.
+ * the page. If it's a unique index we will try to delete whatever
+ * duplicates happen to be on the page, which might be enough to avoid
+ * a page split.
*
* We only perform a deduplication pass for a checkingunique caller
* when the incoming item is a duplicate of an existing item on the
@@ -893,13 +895,12 @@ _bt_findinsertloc(Relation rel,
uniquedup = true;
}
- if (itup_key->allequalimage && BTGetDeduplicateItems(rel) &&
- (!checkingunique || uniquedup) &&
+ if (BTGetDeduplicateItems(rel) && (!checkingunique || uniquedup) &&
PageGetFreeSpace(page) < insertstate->itemsz)
{
_bt_dedup_one_page(rel, insertstate->buf, heapRel,
insertstate->itup, insertstate->itemsz,
- checkingunique);
+ checkingunique, itup_key->allequalimage);
insertstate->bounds_valid = false;
}
}
--
2.25.1
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-10-07 23:48 ` Peter Geoghegan <[email protected]>
2020-10-12 10:47 ` Re: Deleting older versions in unique indexes to avoid page splits Andrey Borodin <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-21 15:25 ` Re: Deleting older versions in unique indexes to avoid page splits Robert Haas <[email protected]>
0 siblings, 3 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-10-07 23:48 UTC (permalink / raw)
To: PostgreSQL Hackers <[email protected]>
On Tue, Jun 30, 2020 at 5:03 PM Peter Geoghegan <[email protected]> wrote:
> Attached is a POC patch that teaches nbtree to delete old duplicate
> versions from unique indexes. The optimization targets non-HOT
> duplicate version bloat. Although the patch is rather rough, it
> nevertheless manages to more or less eliminate a whole class of index
> bloat: Unique index bloat from non-HOT updates in workloads where no
> transaction lasts for more than a few seconds.
I'm slightly surprised that this thread didn't generate more interest
back in June. After all, maintaining the pristine initial state of
(say) a primary key index even after many high throughput non-HOT
updates (i.e. avoiding "logically unnecessary" page splits entirely)
is quite appealing. It arguably goes some way towards addressing long
held criticisms of our approach to MVCC. Especially if it can be
generalized to all b-tree indexes -- the Uber blog post mentioned
tables that have several indexes, which presumably means that there
can be no HOT updates (the author of the blog post didn't seem to be
aware of HOT at all).
I've been trying to generalize my approach to work with all indexes. I
think that I can find a strategy that is largely effective at
preventing version churn page splits that take place with workloads
that have many non-HOT updates, without any serious downsides for
workloads that do not benefit. I want to get feedback on that now,
since I expect that it will be controversial. Teaching indexes about
how tuples are versioned or chaining tuples seems like a non-starter,
so the trick will be to come up with something that behaves in
approximately the same way as that in cases where it helps.
The approach I have in mind is to pass down a hint from the executor
to btinsert(), which lets nbtree know that the index tuple insert is
in fact associated with a non-HOT update. This hint is only given when
the update did not logically modify the columns that the index covers
(so presumably the majority of unchanged indexes get the hint, but not
the one or two indexes whose columns were modified by our update
statement -- or maybe the non-HOT update was caused by not being able
to fit a new version on the same heap page, in which case all the
btinsert() calls/all the indexes on the table get the hint). Of
course, this hint makes it all but certain that the index tuple is the
successor for some other index tuple located on the same leaf page. We
don't actually include information about which other existing tuple it
is, since it pretty much doesn't matter. Even if we did, we definitely
cannot opportunistically delete it, because it needs to stay in the
index at least until our transaction commits (this should be obvious).
Actually, we already try to delete it from within _bt_check_unique()
today for unique indexes -- we just never opportunistically mark it
dead at that point (as I said, it's needed until the xact commits at
the earliest).
Here is the maybe-controversial part: The algorithm initially assumes
that all indexes more or less have the same properties as unique
indexes from a versioning point of view, even though that's clearly
not true. That is, it initially assumes that the only reason why there
can be duplicates on any leaf page it looks at is because some
previous transaction also did a non-HOT update that added a new,
unchanged index tuple. The new algorithm only runs when the hint is
passed down from the executor and when the only alternative is to
split the page (or have a deduplication pass), so clearly there is
some justification for this assumption -- it really is highly unlikely
that this update (which is on the verge of splitting the page) just so
happened to be the first such update that affected the page.
It's extremely likely that there will be at least a couple of other
tuples like that on the page, and probably quite a few more. And even
if we only manage to free one or two tuples, that'll still generally
be enough to fit the incoming tuple. In general that is usually quite
valuable. Even with a busy database, that might buy us minutes or
hours before the question of splitting the same leaf page arises
again. By the time that happens, longer running transactions may have
committed, VACUUM may have run, etc. Like unique index deduplication,
this isn't about freeing space -- it's about buying time.
To be blunt: It may be controversial that we're accessing multiple
heap pages while holding an exclusive lock on a leaf page, in the
hopes that we can avoid a page split, but without any certainty that
it'll work out.
Sometimes (maybe even most of the time), this assumption turns out to
be mostly correct, and we benefit in the obvious way -- no
"unnecessary" page splits for affected non-unique indexes. Other times
it won't work out, usually because the duplicates are in fact logical
duplicates from distinct logical rows. When the new deletion thing
doesn't work out, the situation works itself out in the obvious way:
we get a deduplication pass. If that doesn't work out we get a page
split. So we have three legitimate strategies for resolving the
"pressure" against a leaf page: last minute emergency duplicate checks
+ deletion (the new thing), a deduplication pass, or a page split. The
strategies are in competition with each other (though only when we
have non-HOT updates).
We're only willing to access a fixed number of heap pages (heap pages
pointed to by duplicate index tuples) to try to delete some index
tuples and avoid a split, and only in the specific context of the hint
being received at the point a leaf page fills and it looks like we
might have to split it. I think that we should probably avoid doing
anything with posting list tuples left behind by deduplication, except
maybe if there are only 2 or 3 TIDs -- just skip over them. That way,
cases with duplicates across logical rows (not version churn) tend to
get made into a posting list early (e.g. during an index build), so we
don't even bother trying to delete from them later. Non-posting-list
duplicates suggest recency, which suggests version churn -- those dups
must at least have come after the most recent deduplication pass. Plus
we have heuristics that maximize the chances of finding versions to
kill. And we tend to look at the same blocks again and again -- like
in the patch I posted, we look at the value with the most dups for
things to kill first, and so on. So repeated version deletion passes
won't end up accessing totally different heap blocks each time, unless
they're successful at killing old versions.
(I think that this new feature should be framed as extending the
deduplication infrastructure to do deletes -- so it can only be used
on indexes that use deduplication.)
Even if this new mechanism ends up slowing down non-HOT updates
noticeably -- which is *not* something that I can see with my
benchmarks now -- then that could still be okay. I think that there is
something sensible about imposing a penalty on non-HOT update queries
that can cause problems for everybody today. Why shouldn't they have
to clean up their own mess? I think that it buys us a lot to condition
cleanup on avoiding page splits, because any possible penalty is only
paid in cases where there isn't something else that keeps the bloat
under control. If something like the kill_prior_tuple mechanism mostly
keeps bloat under control already, then we'll resolve the situation
that way instead.
An important point about this technique is that it's just a back stop,
so it can run very infrequently while still preventing an index from
growing -- an index that can double in size today. If existing
mechanisms against "logically unnecessary" page splits are 99%
effective today, then they may still almost be useless to users --
your index still doubles in size. It just takes a little longer in
Postgres 13 (with deduplication) compared to Postgres 12. So there is
a really huge asymmetry that we still aren't doing enough about, even
with deduplication.
Deduplication cannot prevent the first "wave" of page splits with
primary key style indexes due to the dimensions of the index tuples on
the page. The first wave may be all that matters (deduplication does
help more when things get really bad, but I'd like to avoid "merely
bad" performance characteristics, too). Consider the simplest possible
real world example. If we start out with 366 items on a leaf page
initially (the actual number with default fillfactor + 64-bit
alignment for the pgbench indexes), we can store another 40 non-HOT
dups on the same leaf page before the page splits. We only save 4
bytes by merging a dup into one of the 366 original tuples. It's
unlikely that many of the 40 dups that go on the page will be
duplicates of *each other*, and deduplication only really starts to
save space when posting list tuples have 4 or 5 TIDs each. So
eventually all of the original leaf pages split when they really
shouldn't, despite the availability of deduplication.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-10-12 10:47 ` Andrey Borodin <[email protected]>
2020-10-12 21:45 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2 siblings, 1 reply; 1661+ messages in thread
From: Andrey Borodin @ 2020-10-12 10:47 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
> 8 окт. 2020 г., в 04:48, Peter Geoghegan <[email protected]> написал(а):
>
> On Tue, Jun 30, 2020 at 5:03 PM Peter Geoghegan <[email protected]> wrote:
>> Attached is a POC patch that teaches nbtree to delete old duplicate
>> versions from unique indexes. The optimization targets non-HOT
>> duplicate version bloat. Although the patch is rather rough, it
>> nevertheless manages to more or less eliminate a whole class of index
>> bloat: Unique index bloat from non-HOT updates in workloads where no
>> transaction lasts for more than a few seconds.
>
> I'm slightly surprised that this thread didn't generate more interest
> back in June.
The idea looks very interesting.
It resembles GiST microvacuum: GiST tries to vacuum single page before split.
I'm curious how cost of page deduplication is compared to cost of page split? Should we do deduplication of page will still remain 99% full?
Best regards, Andrey Borodin.
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-12 10:47 ` Re: Deleting older versions in unique indexes to avoid page splits Andrey Borodin <[email protected]>
@ 2020-10-12 21:45 ` Peter Geoghegan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-10-12 21:45 UTC (permalink / raw)
To: Andrey Borodin <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Mon, Oct 12, 2020 at 3:47 AM Andrey Borodin <[email protected]> wrote:
> The idea looks very interesting.
> It resembles GiST microvacuum: GiST tries to vacuum single page before split.
AFAICT the GiST microvacuum mechanism is based on the one in nbtree,
which is based on setting LP_DEAD bits when index scans find that the
TIDs are dead-to-all. That's easy to justify, because it is easy and
cheap to save future index scans the trouble of following the TIDs
just to discover the same thing for themselves.
The difference here is that we're simply making an intelligent guess
-- there have been no index scans, but we're going to do a kind of
special index scan at the last minute to see if we can avoid a page
split. I think that this is okay because in practice we can do it in a
reasonably targeted way. We will never do it with INSERTs, for example
(except in unique indexes, though only when we know that there are
duplicates because we saw them in _bt_check_unique()). In the worst
case we make non-HOT updates a bit slower...and I'm not even sure that
that's a bad thing when we don't manage to delete anything. After all,
non-HOT updates impose a huge cost on the system. They have "negative
externalities".
Another way to look at it is that the mechanism I propose to add takes
advantage of "convexity" [1]. (Actually, several of my indexing ideas
are based on similar principles -- like the nbtsplitloc.c stuff.)
Attached is v2. It controls the cost of visiting the heap by finding
the heap page that has the most TIDs that we might be able to kill
(among those that are duplicates on a leaf page). It also adds a
hinting mechanism to the executor to avoid uselessly applying the
optimization with INSERTs.
> I'm curious how cost of page deduplication is compared to cost of page split? Should we do deduplication of page will still remain 99% full?
It depends on how you measure it, but in general I would say that the
cost of traditional Postgres 13 deduplication is much lower.
Especially as measured in WAL volume. I also believe that the same is
true for this new delete deduplication mechanism. The way we determine
which heap pages to visit maximizes the chances that we'll get lucky
while minimizing the cost (currently we don't visit more than 2 heap
pages unless we get at least one kill -- I think I could be more
conservative here without losing much). A page split also has to
exclusive lock two other pages (the right sibling page and parent
page), so even the locking is perhaps better.
The attached patch can completely or almost completely avoid index
bloat in extreme cases with non-HOT updates. This can easily increase
throughput by 2x or more, depending on how extreme you make it (i.e.
how many indexes you have). It seems like the main problem caused by
non-HOT updates is in fact page splits themselves. It is not so much a
problem with dirtying of pages.
You can test this with a benchmark like the one that was used for WARM
back in 2017:
https://www.postgresql.org/message-id/flat/CABOikdMNy6yowA%2BwTGK9RVd8iw%2BCzqHeQSGpW7Yka_4RSZ_LOQ%4...
I suspect that it's maybe even more effective than WARM was with this benchmark.
[1] https://fooledbyrandomness.com/ConvexityScience.pdf
--
Peter Geoghegan
Attachments:
[application/octet-stream] v2-0001-Add-delete-deduplication-to-nbtree.patch (56.0K, ../../CAH2-Wz=CEKFa74EScx_hFVshCOn6AA5T-ajFASTdzipdkLTNQQ@mail.gmail.com/2-v2-0001-Add-delete-deduplication-to-nbtree.patch)
download | inline diff:
From fede132a3d4f98bfdfcfade582e6f5da56014ce2 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Tue, 30 Jun 2020 16:29:27 -0700
Subject: [PATCH v2] Add delete deduplication to nbtree.
Repurpose deduplication infrastructure to delete items in indexes at the
point where we'd usually have to split the page, even when they don't
have their LP_DEAD bits set. Testing has shown that this is almost
completely effective at preventing "version index bloat" from non-HOT
updates, provided there are no long running transactions.
This is primarily valuable with leaf pages that contain mostly-distinct
index tuples, particularly with unique indexes. It is intended to
complement deduplication. Heuristics are used to guess which index
tuples are likely to point to no longer needed old table row versions.
Note that INCLUDE indexes support the optimization.
---
src/include/access/genam.h | 15 +
src/include/access/heapam.h | 3 +-
src/include/access/nbtree.h | 5 +-
src/include/access/tableam.h | 43 ++-
src/include/executor/executor.h | 3 +-
src/backend/access/heap/heapam.c | 12 +-
src/backend/access/heap/heapam_handler.c | 5 +-
src/backend/access/nbtree/README | 50 ++-
src/backend/access/nbtree/nbtdedup.c | 429 +++++++++++++++++++++--
src/backend/access/nbtree/nbtinsert.c | 40 ++-
src/backend/access/nbtree/nbtsort.c | 12 +-
src/backend/access/nbtree/nbtxlog.c | 4 +-
src/backend/access/table/tableam.c | 243 ++++++++++++-
src/backend/commands/copy.c | 5 +-
src/backend/executor/execIndexing.c | 41 ++-
src/backend/executor/execReplication.c | 4 +-
src/backend/executor/nodeModifyTable.c | 11 +-
17 files changed, 845 insertions(+), 80 deletions(-)
diff --git a/src/include/access/genam.h b/src/include/access/genam.h
index 68d90f5141..7002da0716 100644
--- a/src/include/access/genam.h
+++ b/src/include/access/genam.h
@@ -108,10 +108,25 @@ typedef struct ParallelIndexScanDescData *ParallelIndexScanDesc;
* call is made with UNIQUE_CHECK_EXISTING. The tuple is already in the
* index in this case, so it should not be inserted again. Rather, just
* check for conflicting live tuples (possibly blocking).
+ *
+ * UNIQUE_CHECK_NO indicates the absence of any unique checking.
+ * UNIQUE_CHECK_NO_WITH_UNCHANGED is a variant of UNIQUE_CHECK_NO that
+ * indicates that the index tuple comes from an UPDATE that did not modify
+ * the row in respect of any columns that are indexed. The implementation
+ * requires a successor version, but there is no logical change. Some
+ * index access AMs can use this as hint that can trigger optimizations.
+ *
+ * XXX: Adding UNIQUE_CHECK_NO_WITH_UNCHANGED like this kind of makes
+ * sense, since it's pretty natural to leave it up to index AMs to figure
+ * it out with unique indexes. But what about when we insert NULLs into a
+ * unique index? Isn't that case UNIQUE_CHECK_YES, and yet also a thing
+ * that nbtree pretty much treats as UNIQUE_CHECK_NO once it sees that the
+ * index tuple has NULLs?
*/
typedef enum IndexUniqueCheck
{
UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */
+ UNIQUE_CHECK_NO_WITH_UNCHANGED, /* "No logical change" duplicate */
UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */
UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */
UNIQUE_CHECK_EXISTING /* Check if existing tuple is unique */
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 92b19dba32..d950083a7d 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -148,7 +148,8 @@ extern void heap_abort_speculative(Relation relation, ItemPointer tid);
extern TM_Result heap_update(Relation relation, ItemPointer otid,
HeapTuple newtup,
CommandId cid, Snapshot crosscheck, bool wait,
- struct TM_FailureData *tmfd, LockTupleMode *lockmode);
+ struct TM_FailureData *tmfd, LockTupleMode *lockmode,
+ Bitmapset **modified_attrs_hint);
extern TM_Result heap_lock_tuple(Relation relation, HeapTuple tuple,
CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy,
bool follow_update,
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index 65d9698b89..33d9b429c0 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -1029,11 +1029,12 @@ extern void _bt_parallel_advance_array_keys(IndexScanDesc scan);
*/
extern void _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
IndexTuple newitem, Size newitemsz,
- bool checkingunique);
+ bool checkingunique, bool nologicalchange,
+ bool allequalimage);
extern void _bt_dedup_start_pending(BTDedupState state, IndexTuple base,
OffsetNumber baseoff);
extern bool _bt_dedup_save_htid(BTDedupState state, IndexTuple itup);
-extern Size _bt_dedup_finish_pending(Page newpage, BTDedupState state);
+extern Size _bt_dedup_merge_finish_pending(Page newpage, BTDedupState state);
extern IndexTuple _bt_form_posting(IndexTuple base, ItemPointer htids,
int nhtids);
extern void _bt_update_posting(BTVacuumPosting vacposting);
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 387eb34a61..d545a4abdf 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -128,6 +128,17 @@ typedef struct TM_FailureData
bool traversed;
} TM_FailureData;
+/*
+ * State used by table_index_batch_check() to perform "bottom up" deletion of
+ * duplicate index tuples
+ */
+typedef struct TM_IndexDelete
+{
+ OffsetNumber ioffnum; /* Index am identifies entries with this */
+ ItemPointerData tid; /* table TID from index tuple */
+ bool isdead; /* Is tuple dead? */
+} TM_IndexDelete;
+
/* "options" flag bits for table_tuple_insert */
/* TABLE_INSERT_SKIP_WAL was 0x0001; RelationNeedsWAL() now governs */
#define TABLE_INSERT_SKIP_FSM 0x0002
@@ -396,7 +407,8 @@ typedef struct TableAmRoutine
bool wait,
TM_FailureData *tmfd,
LockTupleMode *lockmode,
- bool *update_indexes);
+ bool *update_indexes,
+ Bitmapset **modified_attrs_hint);
/* see table_tuple_lock() for reference about parameters */
TM_Result (*tuple_lock) (Relation rel,
@@ -1041,16 +1053,32 @@ table_index_fetch_tuple(struct IndexFetchTableData *scan,
}
/*
- * This is a convenience wrapper around table_index_fetch_tuple() which
- * returns whether there are table tuple items corresponding to an index
- * entry. This likely is only useful to verify if there's a conflict in a
- * unique index.
+ * These are convenience wrappers around table_index_fetch_tuple() which
+ * indicate whether there are table tuple items corresponding to an index
+ * entry. Can be used to verify if there's a conflict in a unique index.
+ *
+ * table_index_batch_check() is a variant that is specialized to garbage
+ * collection of dead tuples in index access methods. Duplicates are
+ * commonly caused by MVCC version churn when an optimization like
+ * heapam's HOT cannot be applied. It can make sense to opportunistically
+ * guess that many index tuples are dead versions, particularly in unique
+ * indexes.
+ *
+ * Note that table_index_batch_check() sorts the duptids array so that the
+ * order of access is optimized. Callers need to be able to deal with
+ * that.
*/
extern bool table_index_fetch_tuple_check(Relation rel,
ItemPointer tid,
Snapshot snapshot,
bool *all_dead);
+extern int table_index_batch_check(Relation rel,
+ TM_IndexDelete *duptids,
+ int nduptids,
+ Snapshot snapshot,
+ int nkillsneeded,
+ int *nblocksaccessed);
/* ------------------------------------------------------------------------
* Functions for non-modifying operations on individual tuples
@@ -1311,12 +1339,13 @@ static inline TM_Result
table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot,
CommandId cid, Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode,
- bool *update_indexes)
+ bool *update_indexes, Bitmapset **modified_attrs_hint)
{
return rel->rd_tableam->tuple_update(rel, otid, slot,
cid, snapshot, crosscheck,
wait, tmfd,
- lockmode, update_indexes);
+ lockmode, update_indexes,
+ modified_attrs_hint);
}
/*
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h
index 415e117407..8dffae8e56 100644
--- a/src/include/executor/executor.h
+++ b/src/include/executor/executor.h
@@ -574,7 +574,8 @@ extern TupleTableSlot *ExecGetReturningSlot(EState *estate, ResultRelInfo *relIn
extern void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative);
extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
extern List *ExecInsertIndexTuples(TupleTableSlot *slot, EState *estate, bool noDupErr,
- bool *specConflict, List *arbiterIndexes);
+ bool *specConflict, List *arbiterIndexes,
+ Bitmapset *modified_attrs_hint);
extern bool ExecCheckIndexConstraints(TupleTableSlot *slot, EState *estate,
ItemPointer conflictTid, List *arbiterIndexes);
extern void check_exclusion_constraint(Relation heap, Relation index,
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 1585861a02..fa7ca33289 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2892,7 +2892,8 @@ simple_heap_delete(Relation relation, ItemPointer tid)
TM_Result
heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
CommandId cid, Snapshot crosscheck, bool wait,
- TM_FailureData *tmfd, LockTupleMode *lockmode)
+ TM_FailureData *tmfd, LockTupleMode *lockmode,
+ Bitmapset **modified_attrs_hint)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -3758,10 +3759,15 @@ l2:
if (old_key_tuple != NULL && old_key_copied)
heap_freetuple(old_key_tuple);
+ /* Save for no logical changes hint when non-HOT update performed */
+ if (!use_hot_update && modified_attrs_hint)
+ *modified_attrs_hint = modified_attrs;
+ else
+ bms_free(modified_attrs);
+
bms_free(hot_attrs);
bms_free(key_attrs);
bms_free(id_attrs);
- bms_free(modified_attrs);
bms_free(interesting_attrs);
return TM_Ok;
@@ -3891,7 +3897,7 @@ simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
result = heap_update(relation, otid, tup,
GetCurrentCommandId(true), InvalidSnapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode);
+ &tmfd, &lockmode, NULL);
switch (result)
{
case TM_SelfModified:
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index dcaea7135f..f32ed0a5f2 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -314,7 +314,8 @@ static TM_Result
heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
CommandId cid, Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
- LockTupleMode *lockmode, bool *update_indexes)
+ LockTupleMode *lockmode, bool *update_indexes,
+ Bitmapset **modified_attrs_hint)
{
bool shouldFree = true;
HeapTuple tuple = ExecFetchSlotHeapTuple(slot, true, &shouldFree);
@@ -325,7 +326,7 @@ heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
tuple->t_tableOid = slot->tts_tableOid;
result = heap_update(relation, otid, tuple, cid, crosscheck, wait,
- tmfd, lockmode);
+ tmfd, lockmode, modified_attrs_hint);
ItemPointerCopy(&tuple->t_self, &slot->tts_tid);
/*
diff --git a/src/backend/access/nbtree/README b/src/backend/access/nbtree/README
index 9692e4cdf6..1bfc3d4526 100644
--- a/src/backend/access/nbtree/README
+++ b/src/backend/access/nbtree/README
@@ -807,7 +807,55 @@ Deduplication in unique indexes helps to prevent these pathological page
splits. Storing duplicates in a space efficient manner is not the goal,
since in the long run there won't be any duplicates anyway. Rather, we're
buying time for standard garbage collection mechanisms to run before a
-page split is needed.
+page split is needed. Also, the deduplication pass performs a targeted
+form of opportunistic deletion for unique indexes with version churn
+duplicates, as well as in cases where an UPDATE statement did not
+logically modify any indexed column, but nevertheless requires a successor
+index tuple. The latter case happens when tableam optimizations such as
+heapam's HOT cannot be applied. (We don't want to distinguish between
+version churn from UPDATEs and version churn from related INSERTs and
+DELETEs within a unique index.)
+
+The deduplication module usually opportunistically deletes whatever
+duplicates happen to be present on the page before moving on to
+deduplication proper, since in general some duplicates are likely to
+already be dead to everybody. This mechanism is quite similar to
+on-the-fly deletion of index tuples that will already have failed to
+prevent a page split by the time deduplication is considered. The main
+difference is that the tuples that get deleted are not opportunistically
+marked LP_DEAD by transactions that had to read the tuples in any case.
+
+The implementation must weigh the need to avoid a page split against the
+extra work performed with an exclusive buffer lock held. It's possible to
+make this trade-off sensibly despite the uncertainty about versioning and
+update chains within nbtree. In a unique index it's clear that there can
+only be one most recent committed version for any given value, which makes
+it certain that we'll delete some of the old versions --- at least in the
+absence of either a long running transaction that holds back the xmin
+horizon, and barring extreme churn concentrated in one part of the key
+space.
+
+Deduplication-deletion in non-unique indexes is trickier (the
+implementation is almost the same, but the justification is more
+complicated). In general there is nothing that assures us that there
+cannot be many logical rows that all have the same value in respect of an
+indexed column, which will cause us to waste time trying to find "old dead
+versions" among the duplicates that are actually distinct logical rows.
+We assume that all indexes work more or less like a unique index. This
+works better than you'd think. We at least know that there is some chance
+of UPDATE version churn in affected pages; the tuple we're trying to
+insert on the page at the point that this happens certainly originated
+that way, so there is a good change that the same is true of existing,
+committed tuples. We're only willing to access a small number of
+heap/table pages to determine if our guess is correct, so if we're totally
+wrong then we'll have accessed no more than 2 or so heap/table pages.
+Finally, and perhaps most importantly, we'll learn from our mistake. The
+natural consequence of failing to deduplicate-delete is to do a
+conventional deduplication pass. That will merge together the duplicate
+index tuples that correspond to multiple extant logical rows. Future
+attempts at deduplication deletion on the same page will skip over the
+resulting posting list tuple, only examining more recent and more
+promising duplicates.
Unique index leaf pages only get a deduplication pass when an insertion
(that might have to split the page) observed an existing duplicate on the
diff --git a/src/backend/access/nbtree/nbtdedup.c b/src/backend/access/nbtree/nbtdedup.c
index f6be865b17..9a2b2b637d 100644
--- a/src/backend/access/nbtree/nbtdedup.c
+++ b/src/backend/access/nbtree/nbtdedup.c
@@ -16,13 +16,24 @@
#include "access/nbtree.h"
#include "access/nbtxlog.h"
+#include "access/tableam.h"
#include "miscadmin.h"
#include "utils/rel.h"
+static bool _bt_dedup_delete_one_page(Relation rel, Buffer buf,
+ Relation heapRel, Size newitemsz,
+ bool checkingunique,
+ bool logicallymodified,
+ bool *dedupmerge);
+static void _bt_dedup_merge_one_page(Relation rel, Buffer buf,
+ Relation heapRel, IndexTuple newitem,
+ Size newitemsz, bool checkingunique);
+static void _bt_dedup_delete_finish_pending(BTDedupState state);
static bool _bt_do_singleval(Relation rel, Page page, BTDedupState state,
OffsetNumber minoff, IndexTuple newitem);
static void _bt_singleval_fillfactor(Page page, BTDedupState state,
Size newitemsz);
+static int _bt_offsetnumbercmp(const void *arg1, const void *arg2);
#ifdef USE_ASSERT_CHECKING
static bool _bt_posting_valid(IndexTuple posting);
#endif
@@ -32,16 +43,12 @@ static bool _bt_posting_valid(IndexTuple posting);
* if we cannot successfully free at least newitemsz (we also need space for
* newitem's line pointer, which isn't included in caller's newitemsz).
*
- * The general approach taken here is to perform as much deduplication as
- * possible to free as much space as possible. Note, however, that "single
- * value" strategy is sometimes used for !checkingunique callers, in which
- * case deduplication will leave a few tuples untouched at the end of the
- * page. The general idea is to prepare the page for an anticipated page
- * split that uses nbtsplitloc.c's "single value" strategy to determine a
- * split point. (There is no reason to deduplicate items that will end up on
- * the right half of the page after the anticipated page split; better to
- * handle those if and when the anticipated right half page gets its own
- * deduplication pass, following further inserts of duplicates.)
+ * There are two types of deduplication pass: The merge deduplication pass,
+ * where we merge together duplicate index tuples into a new posting list, and
+ * the delete deduplication pass, where old garbage version index tuples are
+ * deleted based on visibility information that we fetch from the table. We
+ * generally expect to perform only one type of deduplication pass per call
+ * here, but it's possible that we'll end up doing both.
*
* This function should be called during insertion, when the page doesn't have
* enough space to fit an incoming newitem. If the BTP_HAS_GARBAGE page flag
@@ -54,27 +61,23 @@ static bool _bt_posting_valid(IndexTuple posting);
*/
void
_bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
- IndexTuple newitem, Size newitemsz, bool checkingunique)
+ IndexTuple newitem, Size newitemsz, bool checkingunique,
+ bool logicallymodified, bool allequalimage)
{
OffsetNumber offnum,
minoff,
maxoff;
Page page = BufferGetPage(buf);
BTPageOpaque opaque;
- Page newpage;
OffsetNumber deletable[MaxIndexTuplesPerPage];
- BTDedupState state;
int ndeletable = 0;
- Size pagesaving = 0;
- bool singlevalstrat = false;
- int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
/*
* We can't assume that there are no LP_DEAD items. For one thing, VACUUM
* will clear the BTP_HAS_GARBAGE hint without reliably removing items
* that are marked LP_DEAD. We don't want to unnecessarily unset LP_DEAD
- * bits when deduplicating items. Allowing it would be correct, though
- * wasteful.
+ * bits when deduplicating items by merging. Allowing it would be
+ * correct, though wasteful.
*/
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
minoff = P_FIRSTDATAKEY(opaque);
@@ -99,18 +102,330 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
*/
if (PageGetFreeSpace(page) >= newitemsz)
return;
-
- /*
- * Reconsider number of items on page, in case _bt_delitems_delete()
- * managed to delete an item or two
- */
- minoff = P_FIRSTDATAKEY(opaque);
- maxoff = PageGetMaxOffsetNumber(page);
}
+ minoff = maxoff = InvalidOffsetNumber; /* Invalidate */
+
+ /*
+ * We're willing to do dedup deletion with a unique index that is not
+ * generally safe for deduplication (though only when deduplicate_items
+ * storage param is not explicitly set to 'off', which our caller checks
+ * for us).
+ *
+ * The logic used by the !checkingunique _bt_dedup_delete_one_page() case
+ * relies on regular deduplication passes occurring, and merging together
+ * index entries that point to distinct logical table rows that happen to
+ * have the same key value (this might not happen immediately, but it
+ * should happen before too long). We're not willing to deduplicate when
+ * the index isn't a unique index and isn't an index that is generally
+ * safe for deduplication. Exit early if we see that.
+ */
+ if (!allequalimage && !checkingunique)
+ return;
+
/* Passed-in newitemsz is MAXALIGNED but does not include line pointer */
newitemsz += sizeof(ItemIdData);
+ if (checkingunique || !logicallymodified)
+ {
+ bool dedupmerge = true;
+
+ /* Perform delete deduplication pass */
+ if (_bt_dedup_delete_one_page(rel, buf, heapRel, newitemsz,
+ checkingunique, logicallymodified,
+ &dedupmerge))
+ return;
+
+ /*
+ * _bt_dedup_delete_one_page() may occasionally indicate no
+ * duplicates, in which case we should give up now
+ */
+ if (!dedupmerge)
+ return;
+
+ /* Fall back on merge deduplication. This happens infrequently. */
+ }
+
+ /*
+ * Perform merge deduplication pass, though only when index is
+ * allequalimage -- otherwise it's not safe
+ */
+ if (allequalimage)
+ _bt_dedup_merge_one_page(rel, buf, heapRel, newitem, newitemsz,
+ checkingunique);
+}
+
+/*
+ * Perform a delete deduplication pass.
+ *
+ * See if duplicate index tuples are eligible to be deleted, even though they
+ * don't have their LP_DEAD bit set already. Give up if we have to access
+ * more than a few heap pages before we can free enough space to fit newitem.
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
+ *
+ * FIXME: Be less eager with tuples that contain NULLs for checkingunique
+ * callers, since NULLs can be duplicates without that signaling anything
+ * about version churn. Just because we're checkingunique (which implies that
+ * incoming newitem isn't a NULL) doesn't mean there aren't lots of other
+ * NULLs on the page.
+ */
+static bool
+_bt_dedup_delete_one_page(Relation rel, Buffer buf, Relation heapRel,
+ Size newitemsz, bool checkingunique,
+ bool logicallymodified, bool *dedupmerge)
+{
+ OffsetNumber offnum,
+ minoff,
+ maxoff;
+ Size freespace;
+ Page page = BufferGetPage(buf);
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+ BTDedupState state;
+ TM_IndexDelete *duptids;
+ int nduptids;
+ int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+
+ state = (BTDedupState) palloc(sizeof(BTDedupStateData));
+ state->deduplicate = true;
+ state->nmaxitems = 0;
+ /* Final "posting list" size should not restrict anything */
+ state->maxpostingsize = BLCKSZ;
+ state->base = NULL;
+ state->baseoff = InvalidOffsetNumber;
+ state->basetupsize = 0;
+ state->htids = palloc(state->maxpostingsize);
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+ state->nintervals = 0;
+
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
+ for (offnum = minoff;
+ offnum <= maxoff;
+ offnum = OffsetNumberNext(offnum))
+ {
+ ItemId itemid = PageGetItemId(page, offnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+
+ Assert(!ItemIdIsDead(itemid));
+
+ if (offnum == minoff)
+ {
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ else if (_bt_keep_natts_fast(rel, state->base, itup) > nkeyatts &&
+ _bt_dedup_save_htid(state, itup))
+ {
+
+ }
+ else
+ {
+ _bt_dedup_delete_finish_pending(state);
+
+ /* itup starts new pending posting list */
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ }
+ /* Handle the final interval, which is still pending */
+ _bt_dedup_delete_finish_pending(state);
+
+ if (state->nintervals == 0)
+ {
+ /* No duplicates */
+ pfree(state->htids);
+ pfree(state);
+ /* Caller should avoid deduplication-by-merging pass */
+ *dedupmerge = false;
+ return false;
+ }
+
+ /*
+ * Accumulate an array of duplicate TIDs to pass to heapam from dedup
+ * intervals
+ */
+ nduptids = 0;
+ duptids = palloc0(maxoff * sizeof(TM_IndexDelete));
+ for (int i = 0; i < state->nintervals; i++)
+ {
+ BTDedupInterval interval = state->intervals[i];
+
+ Assert(interval.nitems > 0);
+ /* Iterate through tuples of given interval/value */
+ for (int j = 0; j < interval.nitems; j++)
+ {
+ OffsetNumber dupoffnum = interval.baseoff + j;
+ ItemId itemid = PageGetItemId(page, dupoffnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+
+ /*
+ * Don't include any posting list tuples. We still always count
+ * plain non-pivot tuples that are the only non-pivot tuples
+ * within the whole interval, though.
+ *
+ * The fact that a previous merge deduplication pass was ever able
+ * to take place suggests that the TIDs mostly point to distinct
+ * logical rows in the table. We may have tried to delete these
+ * same TIDs just before this merge pass, and if we did it's
+ * unlikely that we'll have better luck with them now. (It's also
+ * quite possible that there was no previous delete deduplication
+ * pass for this page at all, which should also discourage us from
+ * including the posting list tuple.)
+ *
+ * XXX: It might make sense to do more here for checkingunique
+ * callers. Thoughts on that design:
+ *
+ * Benchmarking currently suggests that being more sophisticated
+ * with unique index posting list tuples here wouldn't actually
+ * make all that much difference. It's something that we could do
+ * when we get desperate, but how long can we really expect to
+ * hold off a page split once things get that bad? We ought to
+ * make non-HOT UPDATEs "work hard" to prove that a page split
+ * caused by version churn it truly necessary, but clearly it's
+ * possible to go too far with that.
+ *
+ * Consider the extreme case. We certainly don't want to make
+ * non-HOT UPDATEs completely exhaust every possible avenue before
+ * they may split a leaf page. That hurts cases with buffer lock
+ * contention way too much, and might even make the problem worse
+ * indirectly by hindering moving the xmin horizon forward.
+ * Version driven page splits are not _inherently_ a bad thing;
+ * they still make sense as an extreme solution to an extreme (and
+ * extremely rare) problem.
+ */
+ if (BTreeTupleIsPosting(itup))
+ continue;
+
+ /* Save relevant index tuple info for tableam call */
+ duptids[nduptids].ioffnum = dupoffnum;
+ duptids[nduptids].tid = itup->t_tid;
+ nduptids++;
+ }
+ }
+
+ /* Done with dedup state */
+ pfree(state->htids);
+ pfree(state);
+
+ /* Record exact freespace left on page (incudes line pointer overhead) */
+ freespace = PageGetExactFreeSpace(page);
+
+ if (nduptids > 0)
+ {
+ SnapshotData SnapshotNonVacuumable;
+ OffsetNumber deletable[MaxIndexTuplesPerPage];
+ int nheapblocksaccessed;
+ int ntableamkills;
+ int ndeletable = 0;
+
+ /*
+ * Determine which TIDs are dead among dups.
+ *
+ * We aim to delete one eighth of the duplicates (or 5 total,
+ * whichever is greater). There would be a good chance of deleting as
+ * many as half of the duplicates in some common scenarios if we were
+ * eager, but being lazy is a better trade-off.
+ */
+ InitNonVacuumableSnapshot(SnapshotNonVacuumable,
+ GlobalVisTestFor(heapRel));
+ ntableamkills = table_index_batch_check(heapRel, duptids, nduptids,
+ &SnapshotNonVacuumable,
+ Max(nduptids / 8, 5),
+ &nheapblocksaccessed);
+
+ /*
+ * Look through dups array, which probably has some items that we can
+ * delete now.
+ *
+ * Note: The dups array is no longer in its original order (table am
+ * sorted it based on its own criteria). We don't care about the
+ * order, though.
+ */
+ for (int i = 0; i < nduptids; i++)
+ {
+ if (duptids[i].isdead)
+ {
+ OffsetNumber deadoffnum = duptids[i].ioffnum;
+ ItemId itemid = PageGetItemId(page, deadoffnum);
+
+ /*
+ * Delete item, and tally how much space will be saved when
+ * we're done with the page.
+ *
+ * No MarkBufferDirtyHint() call needed -- we'll physically
+ * delete item in a moment anyway, even when we know that we
+ * won't have freed enough space to avoid a page split (must
+ * not return before reaching _bt_delitems_delete()).
+ *
+ * (Actually, we don't really need to mark the ItemId dead
+ * either, but we do so anyway because it's expected in
+ * opportunistic deletion code called below.)
+ */
+ ItemIdMarkDead(itemid);
+ deletable[ndeletable++] = deadoffnum;
+ freespace += MAXALIGN(ItemIdGetLength(itemid)) +
+ sizeof(ItemIdData);
+ }
+
+ if (ntableamkills == ndeletable)
+ break;
+ }
+
+ Assert(ntableamkills == ndeletable);
+
+ if (ndeletable > 0)
+ {
+ /* Have to give array to _bt_delitems_delete in asc order */
+ qsort(deletable, ndeletable, sizeof(OffsetNumber),
+ _bt_offsetnumbercmp);
+
+ /* Actually delete items */
+ _bt_delitems_delete(rel, buf, deletable, ndeletable, heapRel);
+ }
+ }
+
+ pfree(duptids);
+
+ /* Return success when page split (or merge deduplication pass) avoided */
+ Assert(freespace == PageGetExactFreeSpace(page));
+ return freespace >= newitemsz;
+}
+
+/*
+ * Perform a merge deduplication pass.
+ *
+ * The general approach taken here is to perform as much deduplication as
+ * possible to free as much space as possible. Note, however, that "single
+ * value" strategy is sometimes used for !checkingunique callers, in which
+ * case deduplication will leave a few tuples untouched at the end of the
+ * page. The general idea is to prepare the page for an anticipated page
+ * split that uses nbtsplitloc.c's "single value" strategy to determine a
+ * split point. (There is no reason to deduplicate items that will end up on
+ * the right half of the page after the anticipated page split; better to
+ * handle those if and when the anticipated right half page gets its own
+ * deduplication pass, following further inserts of duplicates.)
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
+ */
+static void
+_bt_dedup_merge_one_page(Relation rel, Buffer buf, Relation heapRel,
+ IndexTuple newitem, Size newitemsz,
+ bool checkingunique)
+{
+ OffsetNumber offnum,
+ minoff,
+ maxoff;
+ Page page = BufferGetPage(buf);
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+ Page newpage;
+ BTDedupState state;
+ Size pagesaving = 0;
+ bool singlevalstrat = false;
+ int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+
/*
* By here, it's clear that deduplication will definitely be attempted.
* Initialize deduplication state.
@@ -138,6 +453,9 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
/* nintervals should be initialized to zero */
state->nintervals = 0;
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
+
/* Determine if "single value" strategy should be used */
if (!checkingunique)
singlevalstrat = _bt_do_singleval(rel, page, state, minoff, newitem);
@@ -203,7 +521,7 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
* form new posting tuple, and actually update the page. Else
* reset the state and move on without modifying the page.
*/
- pagesaving += _bt_dedup_finish_pending(newpage, state);
+ pagesaving += _bt_dedup_merge_finish_pending(newpage, state);
if (singlevalstrat)
{
@@ -235,7 +553,7 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
}
/* Handle the last item */
- pagesaving += _bt_dedup_finish_pending(newpage, state);
+ pagesaving += _bt_dedup_merge_finish_pending(newpage, state);
/*
* If no items suitable for deduplication were found, newpage must be
@@ -317,8 +635,8 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
* Every tuple processed by deduplication either becomes the base tuple for a
* posting list, or gets its heap TID(s) accepted into a pending posting list.
* A tuple that starts out as the base tuple for a posting list will only
- * actually be rewritten within _bt_dedup_finish_pending() when it turns out
- * that there are duplicates that can be merged into the base tuple.
+ * actually be rewritten within _bt_dedup_merge_finish_pending() when it turns
+ * out that there are duplicates that can be merged into the base tuple.
*/
void
_bt_dedup_start_pending(BTDedupState state, IndexTuple base,
@@ -443,7 +761,7 @@ _bt_dedup_save_htid(BTDedupState state, IndexTuple itup)
* where no deduplication was possible.
*/
Size
-_bt_dedup_finish_pending(Page newpage, BTDedupState state)
+_bt_dedup_merge_finish_pending(Page newpage, BTDedupState state)
{
OffsetNumber tupoff;
Size tuplesz;
@@ -496,6 +814,38 @@ _bt_dedup_finish_pending(Page newpage, BTDedupState state)
return spacesaving;
}
+/*
+ * Stripped down version of _bt_dedup_merge_finish_pending() used by
+ * _bt_dedup_delete_one_page().
+ *
+ * Finalize deduplication interval/duplicate group without materializing the
+ * would-be posting list tuple.
+ */
+static void
+_bt_dedup_delete_finish_pending(BTDedupState state)
+{
+ Assert(state->nitems > 0);
+ Assert(state->nitems <= state->nhtids);
+ Assert(state->intervals[state->nintervals].baseoff == state->baseoff);
+
+ if (state->nitems == 1)
+ {
+ /* Don't merge */
+ }
+ else
+ {
+ /* Save final number of items for posting list */
+ state->intervals[state->nintervals].nitems = state->nitems;
+ /* Increment nintervals, since we wrote a new posting list tuple */
+ state->nintervals++;
+ }
+
+ /* Reset state for next pending posting list */
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+}
+
/*
* Determine if page non-pivot tuples (data items) are all duplicates of the
* same value -- if they are, deduplication's "single value" strategy should
@@ -809,6 +1159,25 @@ _bt_swap_posting(IndexTuple newitem, IndexTuple oposting, int postingoff)
return nposting;
}
+/*
+ * qsort-style comparator used by _bt_dedup_delete_one_page()
+ */
+static int
+_bt_offsetnumbercmp(const void *arg1, const void *arg2)
+{
+ OffsetNumber *inter1 = (OffsetNumber *) arg1;
+ OffsetNumber *inter2 = (OffsetNumber *) arg2;
+
+ if (*inter1 > *inter2)
+ return 1;
+ if (*inter1 < *inter2)
+ return -1;
+
+ Assert(false);
+
+ return 0;
+}
+
/*
* Verify posting list invariants for "posting", which must be a posting list
* tuple. Used within assertions.
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index d36f7557c8..af5aa849ef 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -37,6 +37,7 @@ static TransactionId _bt_check_unique(Relation rel, BTInsertState insertstate,
static OffsetNumber _bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool logicallymodified,
BTStack stack,
Relation heapRel);
static void _bt_stepright(Relation rel, BTInsertState insertstate, BTStack stack);
@@ -86,7 +87,9 @@ _bt_doinsert(Relation rel, IndexTuple itup,
BTInsertStateData insertstate;
BTScanInsert itup_key;
BTStack stack;
- bool checkingunique = (checkUnique != UNIQUE_CHECK_NO);
+ bool checkingunique = (checkUnique != UNIQUE_CHECK_NO &&
+ checkUnique != UNIQUE_CHECK_NO_WITH_UNCHANGED);
+ bool logicallymodified = (checkUnique != UNIQUE_CHECK_NO_WITH_UNCHANGED);
/* we need an insertion scan key to do our search, so build one */
itup_key = _bt_mkscankey(rel, itup);
@@ -235,7 +238,7 @@ search:
* checkingunique.
*/
newitemoff = _bt_findinsertloc(rel, &insertstate, checkingunique,
- stack, heapRel);
+ logicallymodified, stack, heapRel);
_bt_insertonpg(rel, itup_key, insertstate.buf, InvalidBuffer, stack,
itup, insertstate.itemsz, newitemoff,
insertstate.postingoff, false);
@@ -767,6 +770,11 @@ _bt_check_unique(Relation rel, BTInsertState insertstate, Relation heapRel,
* the right, rather than the first page. In that case, this function
* moves right to the correct target page.
*
+ * If 'logicallymodified' is false, this is for an UPDATE that didn't
+ * logically change the indexed value, but must nevertheless have a new
+ * entry to point to a successor version. This hint from the executor
+ * influences the behavior of deduplication.
+ *
* (In a !heapkeyspace index, there can be multiple pages with the same
* high key, where the new tuple could legitimately be placed on. In
* that case, the caller passes the first page containing duplicates,
@@ -790,6 +798,7 @@ static OffsetNumber
_bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool logicallymodified,
BTStack stack,
Relation heapRel)
{
@@ -873,14 +882,21 @@ _bt_findinsertloc(Relation rel,
/*
* If the target page is full, see if we can obtain enough space by
* erasing LP_DEAD items. If that fails to free enough space, see if
- * we can avoid a page split by performing a deduplication pass over
- * the page.
+ * we can avoid a page split by performing deduplication. Usually
+ * this means a deduplication merge pass, though a deduplication
+ * delete pass is preferred when it looks like version churn is the
+ * source of most of the duplicates (nbtdedup.c decides which approach
+ * to take based on the checkingunique and logicallymodified flags).
*
- * We only perform a deduplication pass for a checkingunique caller
- * when the incoming item is a duplicate of an existing item on the
- * leaf page. This heuristic avoids wasting cycles -- we only expect
- * to benefit from deduplicating a unique index page when most or all
- * recently added items are duplicates. See nbtree/README.
+ * We only consider deduplication for a checkingunique caller when the
+ * incoming item is a known duplicate of an existing item on the leaf
+ * page. This heuristic avoids wasting cycles. The overarching goal
+ * within a unique index is to prevent an unnecessary page split
+ * altogether by delaying splits again and again (the goal is not to
+ * save space). If even one incoming tuple that gets added to this
+ * page originates with an INSERT statement then a page split is all
+ * but inevitable anyway --- that's why it's okay that our heuristic
+ * only considers the current incoming newitem. See nbtree/README.
*/
if (PageGetFreeSpace(page) < insertstate->itemsz)
{
@@ -893,13 +909,13 @@ _bt_findinsertloc(Relation rel,
uniquedup = true;
}
- if (itup_key->allequalimage && BTGetDeduplicateItems(rel) &&
- (!checkingunique || uniquedup) &&
+ if (BTGetDeduplicateItems(rel) && (!checkingunique || uniquedup) &&
PageGetFreeSpace(page) < insertstate->itemsz)
{
_bt_dedup_one_page(rel, insertstate->buf, heapRel,
insertstate->itup, insertstate->itemsz,
- checkingunique);
+ checkingunique, logicallymodified,
+ itup_key->allequalimage);
insertstate->bounds_valid = false;
}
}
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index efee86784b..ecfe79badb 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -273,7 +273,7 @@ static void _bt_sortaddtup(Page page, Size itemsize,
bool newfirstdataitem);
static void _bt_buildadd(BTWriteState *wstate, BTPageState *state,
IndexTuple itup, Size truncextra);
-static void _bt_sort_dedup_finish_pending(BTWriteState *wstate,
+static void _bt_dedup_sort_finish_pending(BTWriteState *wstate,
BTPageState *state,
BTDedupState dstate);
static void _bt_uppershutdown(BTWriteState *wstate, BTPageState *state);
@@ -1068,11 +1068,11 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup,
* Finalize pending posting list tuple, and add it to the index. Final tuple
* is based on saved base tuple, and saved list of heap TIDs.
*
- * This is almost like _bt_dedup_finish_pending(), but it adds a new tuple
- * using _bt_buildadd().
+ * This is almost like _bt_dedup_merge_finish_pending(), but it adds a new
+ * tuple using _bt_buildadd().
*/
static void
-_bt_sort_dedup_finish_pending(BTWriteState *wstate, BTPageState *state,
+_bt_dedup_sort_finish_pending(BTWriteState *wstate, BTPageState *state,
BTDedupState dstate)
{
Assert(dstate->nitems > 0);
@@ -1371,7 +1371,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
* _bt_dedup_save_htid() opted to not merge current item into
* pending posting list.
*/
- _bt_sort_dedup_finish_pending(wstate, state, dstate);
+ _bt_dedup_sort_finish_pending(wstate, state, dstate);
pfree(dstate->base);
/* start new pending posting list with itup copy */
@@ -1390,7 +1390,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
* Handle the last item (there must be a last item when the
* tuplesort returned one or more tuples)
*/
- _bt_sort_dedup_finish_pending(wstate, state, dstate);
+ _bt_dedup_sort_finish_pending(wstate, state, dstate);
pfree(dstate->base);
pfree(dstate->htids);
}
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index bda9be2348..9186bdeea5 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -530,12 +530,12 @@ btree_xlog_dedup(XLogReaderState *record)
}
else
{
- _bt_dedup_finish_pending(newpage, state);
+ _bt_dedup_merge_finish_pending(newpage, state);
_bt_dedup_start_pending(state, itup, offnum);
}
}
- _bt_dedup_finish_pending(newpage, state);
+ _bt_dedup_merge_finish_pending(newpage, state);
Assert(state->nintervals == xlrec->nintervals);
Assert(memcmp(state->intervals, intervals,
state->nintervals * sizeof(BTDedupInterval)) == 0);
diff --git a/src/backend/access/table/tableam.c b/src/backend/access/table/tableam.c
index 6438c45716..d5030930ee 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -30,6 +30,11 @@
#include "storage/shmem.h"
#include "storage/smgr.h"
+static void table_index_batch_check_block_count_sort(TM_IndexDelete *duptids,
+ int nduptids);
+static int indexdelete_tids_cmp(const void *arg1, const void *arg2);
+static int indexdeletecount_ntids_cmp(const void *arg1, const void *arg2);
+
/*
* Constants to control the behavior of block allocation to parallel workers
* during a parallel seqscan. Technically these values do not need to be
@@ -207,9 +212,9 @@ table_beginscan_parallel(Relation relation, ParallelTableScanDesc parallel_scan)
/*
* To perform that check simply start an index scan, create the necessary
* slot, do the heap lookup, and shut everything down again. This could be
- * optimized, but is unlikely to matter from a performance POV. If there
- * frequently are live index pointers also matching a unique index key, the
- * CPU overhead of this routine is unlikely to matter.
+ * optimized, but is unlikely to matter from a performance POV. Note that
+ * table_index_batch_check() is optimized in this way, since it is designed
+ * as a batch operation.
*
* Note that *tid may be modified when we return true if the AM supports
* storing multiple row versions reachable via a single index entry (like
@@ -236,6 +241,112 @@ table_index_fetch_tuple_check(Relation rel,
return found;
}
+/*
+ * Specialized variant of table_index_fetch_tuple_check() that can be used
+ * by index AMs to perform "bottom up" deletion of duplicate index tuples.
+ * This is particularly likely to work well with unique indexes.
+ *
+ * Note: This routine sorts the duptids array, but does not modify any
+ * individual entry accept to mark it as dead for caller.
+ *
+ * Returns total number of duptids that can be killed in index by caller.
+ *
+ * TODO: This should be combined with the equivalent of a call to
+ * table_compute_xid_horizon_for_tuples().
+ */
+int
+table_index_batch_check(Relation rel, TM_IndexDelete *duptids, int nduptids,
+ Snapshot snapshot, int nkillsneeded,
+ int *nblocksaccessed)
+{
+ IndexFetchTableData *scan;
+ TupleTableSlot *slot;
+ int nkills = 0;
+ BlockNumber last = InvalidBlockNumber;
+ bool final_block = false;
+
+ slot = table_slot_create(rel, NULL);
+ scan = table_index_fetch_begin(rel);
+
+ *nblocksaccessed = 0;
+ table_index_batch_check_block_count_sort(duptids, nduptids);
+ for (int i = 0; i < nduptids; i++)
+ {
+ ItemPointer tid = &(duptids + i)->tid;
+ bool new_block = last != ItemPointerGetBlockNumber(tid);
+ ItemPointerData tmp;
+ bool call_again = false;
+ bool all_dead = false;
+ bool found;
+
+ Assert(!duptids[i].isdead);
+
+ /*
+ * Never access more than 5 blocks, no matter what.
+ */
+ if (new_block && *nblocksaccessed >= 5)
+ break;
+
+ /*
+ * New block encountered, but last block we processed is supposed to
+ * be final block. Quit now -- don't access this new block at all.
+ */
+ if (new_block && final_block)
+ break;
+
+ /*
+ * Quit when we're about to access a third table block and have no
+ * kills to show for accessing the first two.
+ */
+ if (new_block && *nblocksaccessed >= 2 && nkills == 0)
+ break;
+
+ /*
+ * Lower the bar when we've already accessed 3 blocks, and would
+ * otherwise access a fourth now -- quit when we have only had 3+
+ * kills
+ */
+ if (new_block && *nblocksaccessed >= 3 && nkills >= 3)
+ break;
+
+ tmp = *tid;
+ found = table_index_fetch_tuple(scan, &tmp, snapshot, slot,
+ &call_again, &all_dead);
+
+ if (new_block)
+ (*nblocksaccessed)++;
+ last = ItemPointerGetBlockNumber(tid);
+ if (!found && all_dead)
+ {
+ duptids[i].isdead = true;
+ nkills++;
+ }
+
+ if (nkills >= nkillsneeded)
+ {
+ /*
+ * Caller is satisfied, so we can quit now. But before we do,
+ * might as well finish off remaining TIDs on same table page (if
+ * any). Indicate that the current block we're processing is the
+ * final one we intend to process.
+ *
+ * We only quit when we've accessed at least two blocks already
+ * (at least within a typical identity column style primary key
+ * with version churn). It's not uncommon for us to find all the
+ * kills that caller needs having only accessed one table block,
+ * but when that happens it seems like a good idea to be ambitious
+ * about finding more tuples to kill.
+ */
+ if (*nblocksaccessed >= 2)
+ final_block = true;
+ }
+ }
+
+ table_index_fetch_end(scan);
+ ExecDropSingleTupleTableSlot(slot);
+
+ return nkills;
+}
/* ------------------------------------------------------------------------
* Functions for non-modifying operations on individual tuples
@@ -356,7 +467,7 @@ simple_table_tuple_update(Relation rel, ItemPointer otid,
GetCurrentCommandId(true),
snapshot, InvalidSnapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode, update_indexes);
+ &tmfd, &lockmode, update_indexes, NULL);
switch (result)
{
@@ -763,3 +874,127 @@ table_block_relation_estimate_size(Relation rel, int32 *attr_widths,
else
*allvisfrac = (double) relallvisible / curpages;
}
+
+typedef struct TM_IndexDeleteCounts
+{
+ BlockNumber table_block;
+ int ntids_in_block;
+} TM_IndexDeleteCounts;
+
+/*
+ * table_index_batch_check() requires that the duptids array be in a certain
+ * order before it gets started. This helper routine handles that.
+ *
+ * TIDs are grouped together by block number, with ascending TID order within
+ * each group (i.e. in ascending TID offset number order). The block number
+ * groups are ordered according to the total number of candidate TIDs. This
+ * order maximizes the final number of TIDs that caller can kill in index
+ * relative to the number of tableam blocks accessed.
+ *
+ * The goal of the sort order is to process as many dup table TIDs as
+ * possible with as few table buffer accesses as possible. In practice it's
+ * frequently possible to kill relatively many TIDs with only one or two
+ * table page accesses due to the effect of locality.
+ */
+static void
+table_index_batch_check_block_count_sort(TM_IndexDelete *duptids, int nduptids)
+{
+ TM_IndexDeleteCounts *blockcounts;
+ TM_IndexDelete *reorderedduptids;
+ BlockNumber curblock = InvalidBlockNumber;
+ int nblock_groups = 0;
+ int ncopied = 0;
+
+ Assert(nduptids > 0);
+
+ /* First sort array by TID */
+ qsort(duptids, nduptids, sizeof(TM_IndexDelete), indexdelete_tids_cmp);
+
+ /* Calculate per-table-block count of TIDs */
+ blockcounts = palloc(sizeof(TM_IndexDeleteCounts) * nduptids);
+ for (int i = 0; i < nduptids; i++)
+ {
+ ItemPointer duptid = &duptids[i].tid;
+
+ if (curblock != ItemPointerGetBlockNumber(duptid))
+ {
+ /* New block group */
+ nblock_groups++;
+
+ curblock = ItemPointerGetBlockNumber(duptid);
+ blockcounts[nblock_groups - 1].table_block = curblock;
+ blockcounts[nblock_groups - 1].ntids_in_block = 1;
+ }
+ else
+ {
+ blockcounts[nblock_groups - 1].ntids_in_block++;
+ }
+ }
+
+ /* Sort blockcounts by count in desc order, then tiebreak on block number */
+ qsort(blockcounts, nblock_groups, sizeof(TM_IndexDeleteCounts),
+ indexdeletecount_ntids_cmp);
+ reorderedduptids = palloc0(nduptids * sizeof(TM_IndexDelete));
+ for (int i = 0; i < nblock_groups; i++)
+ {
+ TM_IndexDeleteCounts *blockgroup = blockcounts + i;
+
+ for (int j = 0; j < nduptids; j++)
+ {
+ ItemPointer tid = &duptids[j].tid;
+
+ if (blockgroup->table_block == ItemPointerGetBlockNumber(tid))
+ {
+ memcpy(reorderedduptids + ncopied, duptids + j,
+ sizeof(TM_IndexDelete) * blockgroup->ntids_in_block);
+ ncopied += blockgroup->ntids_in_block;
+ break; /* Move on to next table block group */
+ }
+ }
+ }
+
+ /* Copy back final sorted array into caller's array */
+ memcpy(duptids, reorderedduptids, sizeof(TM_IndexDelete) * nduptids);
+
+ /* be tidy */
+ pfree(reorderedduptids);
+ pfree(blockcounts);
+}
+
+/*
+ * qsort-style comparator used in table_index_batch_check_block_count_sort()
+ */
+static int
+indexdelete_tids_cmp(const void *arg1, const void *arg2)
+{
+ TM_IndexDelete *indexdelete1 = (TM_IndexDelete *) arg1;
+ TM_IndexDelete *indexdelete2 = (TM_IndexDelete *) arg2;
+
+ return ItemPointerCompare(&indexdelete1->tid, &indexdelete2->tid);
+}
+
+/*
+ * qsort-style comparator used in table_index_batch_check_block_count_sort()
+ */
+static int
+indexdeletecount_ntids_cmp(const void *arg1, const void *arg2)
+{
+ TM_IndexDeleteCounts *count1 = (TM_IndexDeleteCounts *) arg1;
+ TM_IndexDeleteCounts *count2 = (TM_IndexDeleteCounts *) arg2;
+
+ /* Invert usual order here to get desc ntids_in_block sort order */
+ if (count1->ntids_in_block > count2->ntids_in_block)
+ return -1;
+ if (count1->ntids_in_block < count2->ntids_in_block)
+ return 1;
+
+ /* Tiebreak on block number (this is asc order) */
+ if (count1->table_block > count2->table_block)
+ return 1;
+ if (count1->table_block < count2->table_block)
+ return -1;
+
+ Assert(false);
+
+ return 0;
+}
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 2047557e52..06e40f16b9 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -2521,7 +2521,7 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
cstate->cur_lineno = buffer->linenos[i];
recheckIndexes =
ExecInsertIndexTuples(buffer->slots[i], estate, false, NULL,
- NIL);
+ NIL, NULL);
ExecARInsertTriggers(estate, resultRelInfo,
slots[i], recheckIndexes,
cstate->transition_capture);
@@ -3295,7 +3295,8 @@ CopyFrom(CopyState cstate)
estate,
false,
NULL,
- NIL);
+ NIL,
+ NULL);
}
/* AFTER ROW INSERT Triggers */
diff --git a/src/backend/executor/execIndexing.c b/src/backend/executor/execIndexing.c
index 1862af621b..1d96b76cef 100644
--- a/src/backend/executor/execIndexing.c
+++ b/src/backend/executor/execIndexing.c
@@ -274,7 +274,8 @@ ExecInsertIndexTuples(TupleTableSlot *slot,
EState *estate,
bool noDupErr,
bool *specConflict,
- List *arbiterIndexes)
+ List *arbiterIndexes,
+ Bitmapset *modified_attrs_hint)
{
ItemPointer tupleid = &slot->tts_tid;
List *result = NIL;
@@ -390,6 +391,44 @@ ExecInsertIndexTuples(TupleTableSlot *slot,
else
checkUnique = UNIQUE_CHECK_PARTIAL;
+ /*
+ * We may have to hint to index am that this is a logically unchanged
+ * index tuple. This happens when we're inserting a duplicate tuple
+ * just to represent the successor version.
+ */
+ if (checkUnique == UNIQUE_CHECK_NO && modified_attrs_hint)
+ {
+ bool logicallyModified = false;
+
+ for (int attr = 0; attr < indexInfo->ii_NumIndexAttrs; attr++)
+ {
+ int keycol = indexInfo->ii_IndexAttrNumbers[attr];
+
+ if (keycol > 0)
+ {
+ logicallyModified =
+ bms_is_member(keycol - FirstLowInvalidHeapAttributeNumber,
+ modified_attrs_hint);
+ if (logicallyModified)
+ break;
+ }
+ else
+ {
+ /*
+ * XXX: For now we always assume that expression indexes
+ * and indexes with whole-row vars were not modified by an
+ * UPDATE (i.e. they just use the dedup delete
+ * optimization regardless of the details of the UPDATE).
+ * Review this decision when the high level design is a
+ * bit better worked out.
+ */
+ }
+ }
+
+ if (!logicallyModified)
+ checkUnique = UNIQUE_CHECK_NO_WITH_UNCHANGED;
+ }
+
satisfiesConstraint =
index_insert(indexRelation, /* index relation */
values, /* array of index Datums */
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index b29db7bf4f..279b4f3b08 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -443,7 +443,7 @@ ExecSimpleRelationInsert(EState *estate, TupleTableSlot *slot)
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(slot, estate, false, NULL,
- NIL);
+ NIL, NULL);
/* AFTER ROW INSERT Triggers */
ExecARInsertTriggers(estate, resultRelInfo, slot,
@@ -509,7 +509,7 @@ ExecSimpleRelationUpdate(EState *estate, EPQState *epqstate,
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
recheckIndexes = ExecInsertIndexTuples(slot, estate, false, NULL,
- NIL);
+ NIL, NULL);
/* AFTER ROW UPDATE Triggers */
ExecARUpdateTriggers(estate, resultRelInfo,
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 9812089161..f466707a2f 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -584,7 +584,7 @@ ExecInsert(ModifyTableState *mtstate,
/* insert index entries for tuple */
recheckIndexes = ExecInsertIndexTuples(slot, estate, true,
&specConflict,
- arbiterIndexes);
+ arbiterIndexes, NULL);
/* adjust the tuple's state accordingly */
table_tuple_complete_speculative(resultRelationDesc, slot,
@@ -622,7 +622,7 @@ ExecInsert(ModifyTableState *mtstate,
/* insert index entries for tuple */
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(slot, estate, false, NULL,
- NIL);
+ NIL, NULL);
}
}
@@ -1080,6 +1080,7 @@ ExecUpdate(ModifyTableState *mtstate,
TM_Result result;
TM_FailureData tmfd;
List *recheckIndexes = NIL;
+ Bitmapset *modified_attrs_hint = NULL;
TupleConversionMap *saved_tcs_map = NULL;
/*
@@ -1345,7 +1346,8 @@ lreplace:;
estate->es_snapshot,
estate->es_crosscheck_snapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode, &update_indexes);
+ &tmfd, &lockmode, &update_indexes,
+ &modified_attrs_hint);
switch (result)
{
@@ -1476,7 +1478,8 @@ lreplace:;
/* insert index entries for tuple if necessary */
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
- recheckIndexes = ExecInsertIndexTuples(slot, estate, false, NULL, NIL);
+ recheckIndexes = ExecInsertIndexTuples(slot, estate, false, NULL,
+ NIL, modified_attrs_hint);
}
if (canSetTag)
--
2.25.1
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-10-14 14:07 ` Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2 siblings, 1 reply; 1661+ messages in thread
From: Anastasia Lubennikova @ 2020-10-14 14:07 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; PostgreSQL Hackers <[email protected]>
On 08.10.2020 02:48, Peter Geoghegan wrote:
> On Tue, Jun 30, 2020 at 5:03 PM Peter Geoghegan <[email protected]> wrote:
>> Attached is a POC patch that teaches nbtree to delete old duplicate
>> versions from unique indexes. The optimization targets non-HOT
>> duplicate version bloat. Although the patch is rather rough, it
>> nevertheless manages to more or less eliminate a whole class of index
>> bloat: Unique index bloat from non-HOT updates in workloads where no
>> transaction lasts for more than a few seconds.
> I'm slightly surprised that this thread didn't generate more interest
> back in June. After all, maintaining the pristine initial state of
> (say) a primary key index even after many high throughput non-HOT
> updates (i.e. avoiding "logically unnecessary" page splits entirely)
> is quite appealing. It arguably goes some way towards addressing long
> held criticisms of our approach to MVCC. Especially if it can be
> generalized to all b-tree indexes -- the Uber blog post mentioned
> tables that have several indexes, which presumably means that there
> can be no HOT updates (the author of the blog post didn't seem to be
> aware of HOT at all).
The idea seems very promising, especially when extended to handle
non-unique indexes too.
> I've been trying to generalize my approach to work with all indexes. I
> think that I can find a strategy that is largely effective at
> preventing version churn page splits that take place with workloads
> that have many non-HOT updates, without any serious downsides for
> workloads that do not benefit. I want to get feedback on that now,
> since I expect that it will be controversial. Teaching indexes about
> how tuples are versioned or chaining tuples seems like a non-starter,
> so the trick will be to come up with something that behaves in
> approximately the same way as that in cases where it helps.
>
> The approach I have in mind is to pass down a hint from the executor
> to btinsert(), which lets nbtree know that the index tuple insert is
> in fact associated with a non-HOT update. This hint is only given when
> the update did not logically modify the columns that the index covers
That's exactly what I wanted to discuss after the first letter. If we
could make (non)HOT-updates index specific, I think it could improve
performance a lot.
> Here is the maybe-controversial part: The algorithm initially assumes
> that all indexes more or less have the same properties as unique
> indexes from a versioning point of view, even though that's clearly
> not true. That is, it initially assumes that the only reason why there
> can be duplicates on any leaf page it looks at is because some
> previous transaction also did a non-HOT update that added a new,
> unchanged index tuple. The new algorithm only runs when the hint is
> passed down from the executor and when the only alternative is to
> split the page (or have a deduplication pass), so clearly there is
> some justification for this assumption -- it really is highly unlikely
> that this update (which is on the verge of splitting the page) just so
> happened to be the first such update that affected the page.
> To be blunt: It may be controversial that we're accessing multiple
> heap pages while holding an exclusive lock on a leaf page, in the
> hopes that we can avoid a page split, but without any certainty that
> it'll work out.
>
> Sometimes (maybe even most of the time), this assumption turns out to
> be mostly correct, and we benefit in the obvious way -- no
> "unnecessary" page splits for affected non-unique indexes. Other times
> it won't work out, usually because the duplicates are in fact logical
> duplicates from distinct logical rows.
I think that this optimization can affect low cardinality indexes
negatively, but it is hard to estimate impact without tests. Maybe it
won't be a big deal, given that we attempt to eliminate old copies not
very often and that low cardinality b-trees are already not very useful.
Besides, we can always make this thing optional, so that users could
tune it to their workload.
I wonder, how this new feature will interact with physical replication?
Replica may have quite different performance profile. For example, there
can be long running queries, that now prevent vacuumfrom removing
recently-dead rows. How will we handle same situation with this
optimized deletion?
--
Anastasia Lubennikova
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
@ 2020-10-14 14:40 ` Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
0 siblings, 1 reply; 1661+ messages in thread
From: Peter Geoghegan @ 2020-10-14 14:40 UTC (permalink / raw)
To: Anastasia Lubennikova <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Wed, Oct 14, 2020 at 7:07 AM Anastasia Lubennikova
<[email protected]> wrote:
> The idea seems very promising, especially when extended to handle non-unique indexes too.
Thanks!
> That's exactly what I wanted to discuss after the first letter. If we could make (non)HOT-updates index specific, I think it could improve performance a lot.
Do you mean accomplishing the same goal in heapam, by making the
optimization more intelligent about which indexes need new versions?
We did have a patch that did that in 2007, as you may recall -- this
was called WARM:
https://www.postgresql.org/message-id/flat/CABOikdMNy6yowA%2BwTGK9RVd8iw%2BCzqHeQSGpW7Yka_4RSZ_LOQ%4...
This didn't go anywhere. I think that this solution in more pragmatic.
It's cheap enough to remove it if a better solution becomes available
in the future. But this is a pretty good solution by all important
measures.
> I think that this optimization can affect low cardinality indexes negatively, but it is hard to estimate impact without tests. Maybe it won't be a big deal, given that we attempt to eliminate old copies not very often and that low cardinality b-trees are already not very useful. Besides, we can always make this thing optional, so that users could tune it to their workload.
Right. The trick is to pay only a fixed low cost (maybe as low as one
heap page access) when we start out, and ratchet it up only if the
first heap page access looks promising. And to avoid posting list
tuples. Regular deduplication takes place when this fails. It's useful
for the usual reasons, but also because this new mechanism learns not
to try the posting list TIDs.
> I wonder, how this new feature will interact with physical replication? Replica may have quite different performance profile.
I think of that as equivalent to having a long running transaction on
the primary. When I first started working on this patch I thought
about having "long running transaction detection". But I quickly
realized that that isn't a meaningful concept. A transaction is only
truly long running relative to the writes that take place that have
obsolete row versions that cannot be cleaned up. It has to be
something we can deal with, but it cannot be meaningfully
special-cased.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-10-16 19:12 ` Peter Geoghegan <[email protected]>
2020-10-16 19:59 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
0 siblings, 2 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-10-16 19:12 UTC (permalink / raw)
To: Anastasia Lubennikova <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Wed, Oct 14, 2020 at 7:40 AM Peter Geoghegan <[email protected]> wrote:
> Right. The trick is to pay only a fixed low cost (maybe as low as one
> heap page access) when we start out, and ratchet it up only if the
> first heap page access looks promising.
Just as an example of how the patch can help, consider the following
pgbench variant script:
\set aid1 random_gaussian(1, 100000 * :scale, 2.0)
\set aid2 random_gaussian(1, 100000 * :scale, 2.5)
\set aid3 random_gaussian(1, 100000 * :scale, 2.2)
\set bid random(1, 1 * :scale)
\set tid random(1, 10 * :scale)
\set delta random(-5000, 5000)
BEGIN;
UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
END;
(These details you see here are a bit arbitrary; don't worry about the
specifics too much.)
Before running the script with pgbench, I initialized pgbench to scale
1500, and made some changes to the indexing (in order to actually test
the patch). There was no standard pgbench_accounts PK. Instead, I
created a unique index that had an include column, which is enough to
make every update a non-HOT update. I also added two more redundant
non-unique indexes to create more overhead from non-HOT updates. It
looked like this:
create unique index aid_pkey_include_abalance on pgbench_accounts
(aid) include (abalance);
create index one on pgbench_accounts (aid);
create index two on pgbench_accounts (aid);
So 3 indexes on the accounts table.
I ran the script for two hours and 16 clients with the patch, then for
another two hours with master. After that time, all 3 indexes were
exactly the same size with the patch, but had almost doubled in size
on master:
aid_pkey_include_abalance: 784,264 pages (or ~5.983 GiB)
one: 769,545 pages (or ~5.871 GiB)
two: 770,295 pages (or ~5.876 GiB)
(With the patch, all three indexes were 100% pristine -- they remained
precisely 411,289 pages in size by the end, which is ~3.137 GiB.)
Note that traditional deduplication is used by the indexes I've called
"one" and "two" here, but not the include index called
"aid_pkey_include_abalance". But it makes little difference, for
reasons that will be obvious if you think about what this looks like
at the leaf page level. Cases that Postgres 13 deduplication does
badly with are often the ones that this new mechanism does well with.
Deduplication by deleting and by merging are truly complementary -- I
haven't just structured the code that way because it was convenient to
use dedup infrastructure just to get the dups at the start. (Yes, it
*was* convenient, but there clearly are cases where each mechanism
competes initially, before nbtree converges on the best strategy at
the local level. So FWIW this patch is a natural and logical extension
of the deduplication work in my mind.)
The TPS/throughput is about what you'd expect for the two hour run:
18,988.762398 TPS for the patch
11,123.551707 TPS for the master branch.
This is a ~1.7x improvement, but I can get more than 3x by changing
the details at the start -- just add more indexes. I don't think that
the precise throughput difference you see here matters. The important
point is that we've more or less fixed a pathological set of behaviors
that have poorly understood cascading effects. Full disclosure: I rate
limited pgbench to 20k for this run, which probably wasn't significant
because neither patch nor master hit that limit for long.
Big latency improvements for that same run, too:
Patch:
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.000 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.000 \set aid3 random_gaussian(1, 100000 * :scale, 2.2)
0.000 \set bid random(1, 1 * :scale)
0.000 \set tid random(1, 10 * :scale)
0.000 \set delta random(-5000, 5000)
0.057 BEGIN;
0.294 UPDATE pgbench_accounts SET abalance = abalance +
:delta WHERE aid = :aid1;
0.204 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.195 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.090 END;
Master:
statement latencies in milliseconds:
0.002 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 2.2)
0.001 \set bid random(1, 1 * :scale)
0.000 \set tid random(1, 10 * :scale)
0.001 \set delta random(-5000, 5000)
0.084 BEGIN;
0.604 UPDATE pgbench_accounts SET abalance = abalance +
:delta WHERE aid = :aid1;
0.317 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.311 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.120 END;
Note that the mechanism added by the patch naturally limits the number
of versions that are in the index for each logical row, which seems
much more important than the total amount of garbage tuples cleaned
up. It's great that the index is half its original size, but even that
is less important than the effect of more or less bounding the worst
case number of heap pages accessed by point index scans. Even though
this patch shows big performance improvements (as well as very small
performance regressions for small indexes with skew), the patch is
mostly about stability. I believe that Postgres users want greater
stability and predictability in this area more than anything else.
The behavior of the system as a whole that we see for the master
branch here is not anywhere near linear. Page splits are of course
expensive, but they also occur in distinct waves [1] and have lasting
consequences. They're very often highly correlated, with clear tipping
points, so you see relatively sudden slow downs in the real world.
Worse still, with skew the number of hot pages that you have can
double in a short period of time. This very probably happens at the
worst possible time for the user, since the database was likely
already organically experiencing very high index writes at the point
of experiencing the first wave of splits (splits correlated both
within and across indexes on the same table). And, from that point on,
the number of FPIs for the same workload also doubles forever (or at
least until REINDEX).
[1] https://btw.informatik.uni-rostock.de/download/tagungsband/B2-2.pdf
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-10-16 19:59 ` Victor Yegorov <[email protected]>
2020-10-16 20:58 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
1 sibling, 1 reply; 1661+ messages in thread
From: Victor Yegorov @ 2020-10-16 19:59 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
пт, 16 окт. 2020 г. в 21:12, Peter Geoghegan <[email protected]>:
> I ran the script for two hours and 16 clients with the patch, then for
> another two hours with master. After that time, all 3 indexes were
> exactly the same size with the patch, but had almost doubled in size
> on master:
>
> aid_pkey_include_abalance: 784,264 pages (or ~5.983 GiB)
> one: 769,545 pages (or ~5.871 GiB)
> two: 770,295 pages (or ~5.876 GiB)
>
> (With the patch, all three indexes were 100% pristine -- they remained
> precisely 411,289 pages in size by the end, which is ~3.137 GiB.)
>
> …
>
> The TPS/throughput is about what you'd expect for the two hour run:
>
> 18,988.762398 TPS for the patch
> 11,123.551707 TPS for the master branch.
>
I really like these results, great work!
I'm also wondering how IO numbers changed due to these improvements,
shouldn't be difficult to look into.
Peter, according to cfbot patch no longer compiles.
Can you send and update, please?
--
Victor Yegorov
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:59 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
@ 2020-10-16 20:58 ` Peter Geoghegan <[email protected]>
2020-10-20 02:37 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
0 siblings, 1 reply; 1661+ messages in thread
From: Peter Geoghegan @ 2020-10-16 20:58 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Fri, Oct 16, 2020 at 1:00 PM Victor Yegorov <[email protected]> wrote:
> I really like these results, great work!
Thanks Victor!
> I'm also wondering how IO numbers changed due to these improvements, shouldn't be difficult to look into.
Here is the pg_statio_user_indexes for patch for the same run:
schemaname | relname | indexrelname |
idx_blks_read | idx_blks_hit
------------+------------------+---------------------------+---------------+---------------
public | pgbench_accounts | aid_pkey_include_abalance |
12,828,736 | 534,819,826
public | pgbench_accounts | one |
12,750,275 | 534,486,742
public | pgbench_accounts | two |
2,474,893 | 2,216,047,568
(3 rows)
And for master:
schemaname | relname | indexrelname |
idx_blks_read | idx_blks_hit
------------+------------------+---------------------------+---------------+---------------
public | pgbench_accounts | aid_pkey_include_abalance |
29,526,568 | 292,705,432
public | pgbench_accounts | one |
28,239,187 | 293,164,160
public | pgbench_accounts | two |
6,505,615 | 1,318,164,692
(3 rows)
Here is pg_statio_user_tables patch:
schemaname | relname | heap_blks_read | heap_blks_hit |
idx_blks_read | idx_blks_hit | toast_blks_read | toast_blks_hit |
tidx_blks_read | tidx_blks_hit
------------+------------------+----------------+---------------+---------------+---------------+-----------------+----------------+----------------+---------------
public | pgbench_accounts | 123,195,496 | 696,805,485 |
28,053,904 | 3,285,354,136 | | |
|
public | pgbench_branches | 11 | 1,553 |
| | | |
|
public | pgbench_history | 0 | 0 |
| | | |
|
public | pgbench_tellers | 86 | 15,416 |
| | | |
|
(4 rows)
And the pg_statio_user_tables for master:
schemaname | relname | heap_blks_read | heap_blks_hit |
idx_blks_read | idx_blks_hit | toast_blks_read | toast_blks_hit |
tidx_blks_read | tidx_blks_hit
------------+------------------+----------------+---------------+---------------+---------------+-----------------+----------------+----------------+---------------
public | pgbench_accounts | 106,502,089 | 334,875,058 |
64,271,370 | 1,904,034,284 | | |
|
public | pgbench_branches | 11 | 1,553 |
| | | |
|
public | pgbench_history | 0 | 0 |
| | | |
|
public | pgbench_tellers | 86 | 15,416 |
| | | |
|
(4 rows)
Of course, it isn't fair to make a direct comparison because we're
doing ~1.7x times more work with the patch. But even still, the
idx_blks_read is less than half with the patch.
BTW, the extra heap_blks_hit from the patch are not only due to the
fact that the system does more directly useful work. It's also due to
the extra garbage collection triggered in indexes. The same is
probably *not* true with heap_blks_read, though. I minimize the number
of heap pages accessed by the new cleamup mechanism each time, and
temporal locality will help a lot. I think that we delete index
entries pointing to garbage in the heap at pretty predictable
intervals. Heap pages full of LP_DEAD line pointer garbage only get
processed with a few times close together in time, after which they're
bound to either get VACUUM'd or get evicted from shared buffers.
> Peter, according to cfbot patch no longer compiles.
> Can you send and update, please?
Attached is v3, which is rebased against the master branch as of
today. No real changes, though.
--
Peter Geoghegan
Attachments:
[application/octet-stream] v3-0001-Add-delete-deduplication-to-nbtree.patch (57.1K, ../../CAH2-WzmzGO7j2wCesRvyqZNL4XTc8896W=W0wX8bX1vX3XGPag@mail.gmail.com/2-v3-0001-Add-delete-deduplication-to-nbtree.patch)
download | inline diff:
From a792d50306718ae7904b07d03be565b4203d075c Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Tue, 30 Jun 2020 16:29:27 -0700
Subject: [PATCH v3] Add delete deduplication to nbtree.
Repurpose deduplication infrastructure to delete items in indexes at the
point where we'd usually have to split the page, even when they don't
have their LP_DEAD bits set. Testing has shown that this is almost
completely effective at preventing "version index bloat" from non-HOT
updates, provided there are no long running transactions.
This is primarily valuable with leaf pages that contain mostly-distinct
index tuples, particularly with unique indexes. It is intended to
complement deduplication. Heuristics are used to guess which index
tuples are likely to point to no longer needed old table row versions.
Note that INCLUDE indexes support the optimization.
---
src/include/access/genam.h | 15 +
src/include/access/heapam.h | 3 +-
src/include/access/nbtree.h | 5 +-
src/include/access/tableam.h | 43 ++-
src/include/executor/executor.h | 3 +-
src/backend/access/heap/heapam.c | 12 +-
src/backend/access/heap/heapam_handler.c | 5 +-
src/backend/access/nbtree/README | 70 +++-
src/backend/access/nbtree/nbtdedup.c | 429 +++++++++++++++++++++--
src/backend/access/nbtree/nbtinsert.c | 40 ++-
src/backend/access/nbtree/nbtsort.c | 12 +-
src/backend/access/nbtree/nbtxlog.c | 4 +-
src/backend/access/table/tableam.c | 243 ++++++++++++-
src/backend/commands/copy.c | 5 +-
src/backend/executor/execIndexing.c | 41 ++-
src/backend/executor/execReplication.c | 4 +-
src/backend/executor/nodeModifyTable.c | 11 +-
17 files changed, 865 insertions(+), 80 deletions(-)
diff --git a/src/include/access/genam.h b/src/include/access/genam.h
index 68d90f5141..7002da0716 100644
--- a/src/include/access/genam.h
+++ b/src/include/access/genam.h
@@ -108,10 +108,25 @@ typedef struct ParallelIndexScanDescData *ParallelIndexScanDesc;
* call is made with UNIQUE_CHECK_EXISTING. The tuple is already in the
* index in this case, so it should not be inserted again. Rather, just
* check for conflicting live tuples (possibly blocking).
+ *
+ * UNIQUE_CHECK_NO indicates the absence of any unique checking.
+ * UNIQUE_CHECK_NO_WITH_UNCHANGED is a variant of UNIQUE_CHECK_NO that
+ * indicates that the index tuple comes from an UPDATE that did not modify
+ * the row in respect of any columns that are indexed. The implementation
+ * requires a successor version, but there is no logical change. Some
+ * index access AMs can use this as hint that can trigger optimizations.
+ *
+ * XXX: Adding UNIQUE_CHECK_NO_WITH_UNCHANGED like this kind of makes
+ * sense, since it's pretty natural to leave it up to index AMs to figure
+ * it out with unique indexes. But what about when we insert NULLs into a
+ * unique index? Isn't that case UNIQUE_CHECK_YES, and yet also a thing
+ * that nbtree pretty much treats as UNIQUE_CHECK_NO once it sees that the
+ * index tuple has NULLs?
*/
typedef enum IndexUniqueCheck
{
UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */
+ UNIQUE_CHECK_NO_WITH_UNCHANGED, /* "No logical change" duplicate */
UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */
UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */
UNIQUE_CHECK_EXISTING /* Check if existing tuple is unique */
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 92b19dba32..d950083a7d 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -148,7 +148,8 @@ extern void heap_abort_speculative(Relation relation, ItemPointer tid);
extern TM_Result heap_update(Relation relation, ItemPointer otid,
HeapTuple newtup,
CommandId cid, Snapshot crosscheck, bool wait,
- struct TM_FailureData *tmfd, LockTupleMode *lockmode);
+ struct TM_FailureData *tmfd, LockTupleMode *lockmode,
+ Bitmapset **modified_attrs_hint);
extern TM_Result heap_lock_tuple(Relation relation, HeapTuple tuple,
CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy,
bool follow_update,
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index 65d9698b89..33d9b429c0 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -1029,11 +1029,12 @@ extern void _bt_parallel_advance_array_keys(IndexScanDesc scan);
*/
extern void _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
IndexTuple newitem, Size newitemsz,
- bool checkingunique);
+ bool checkingunique, bool nologicalchange,
+ bool allequalimage);
extern void _bt_dedup_start_pending(BTDedupState state, IndexTuple base,
OffsetNumber baseoff);
extern bool _bt_dedup_save_htid(BTDedupState state, IndexTuple itup);
-extern Size _bt_dedup_finish_pending(Page newpage, BTDedupState state);
+extern Size _bt_dedup_merge_finish_pending(Page newpage, BTDedupState state);
extern IndexTuple _bt_form_posting(IndexTuple base, ItemPointer htids,
int nhtids);
extern void _bt_update_posting(BTVacuumPosting vacposting);
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 387eb34a61..d545a4abdf 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -128,6 +128,17 @@ typedef struct TM_FailureData
bool traversed;
} TM_FailureData;
+/*
+ * State used by table_index_batch_check() to perform "bottom up" deletion of
+ * duplicate index tuples
+ */
+typedef struct TM_IndexDelete
+{
+ OffsetNumber ioffnum; /* Index am identifies entries with this */
+ ItemPointerData tid; /* table TID from index tuple */
+ bool isdead; /* Is tuple dead? */
+} TM_IndexDelete;
+
/* "options" flag bits for table_tuple_insert */
/* TABLE_INSERT_SKIP_WAL was 0x0001; RelationNeedsWAL() now governs */
#define TABLE_INSERT_SKIP_FSM 0x0002
@@ -396,7 +407,8 @@ typedef struct TableAmRoutine
bool wait,
TM_FailureData *tmfd,
LockTupleMode *lockmode,
- bool *update_indexes);
+ bool *update_indexes,
+ Bitmapset **modified_attrs_hint);
/* see table_tuple_lock() for reference about parameters */
TM_Result (*tuple_lock) (Relation rel,
@@ -1041,16 +1053,32 @@ table_index_fetch_tuple(struct IndexFetchTableData *scan,
}
/*
- * This is a convenience wrapper around table_index_fetch_tuple() which
- * returns whether there are table tuple items corresponding to an index
- * entry. This likely is only useful to verify if there's a conflict in a
- * unique index.
+ * These are convenience wrappers around table_index_fetch_tuple() which
+ * indicate whether there are table tuple items corresponding to an index
+ * entry. Can be used to verify if there's a conflict in a unique index.
+ *
+ * table_index_batch_check() is a variant that is specialized to garbage
+ * collection of dead tuples in index access methods. Duplicates are
+ * commonly caused by MVCC version churn when an optimization like
+ * heapam's HOT cannot be applied. It can make sense to opportunistically
+ * guess that many index tuples are dead versions, particularly in unique
+ * indexes.
+ *
+ * Note that table_index_batch_check() sorts the duptids array so that the
+ * order of access is optimized. Callers need to be able to deal with
+ * that.
*/
extern bool table_index_fetch_tuple_check(Relation rel,
ItemPointer tid,
Snapshot snapshot,
bool *all_dead);
+extern int table_index_batch_check(Relation rel,
+ TM_IndexDelete *duptids,
+ int nduptids,
+ Snapshot snapshot,
+ int nkillsneeded,
+ int *nblocksaccessed);
/* ------------------------------------------------------------------------
* Functions for non-modifying operations on individual tuples
@@ -1311,12 +1339,13 @@ static inline TM_Result
table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot,
CommandId cid, Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode,
- bool *update_indexes)
+ bool *update_indexes, Bitmapset **modified_attrs_hint)
{
return rel->rd_tableam->tuple_update(rel, otid, slot,
cid, snapshot, crosscheck,
wait, tmfd,
- lockmode, update_indexes);
+ lockmode, update_indexes,
+ modified_attrs_hint);
}
/*
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h
index b7978cd22e..f056a7b124 100644
--- a/src/include/executor/executor.h
+++ b/src/include/executor/executor.h
@@ -579,7 +579,8 @@ extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
extern List *ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot, EState *estate,
bool noDupErr,
- bool *specConflict, List *arbiterIndexes);
+ bool *specConflict, List *arbiterIndexes,
+ Bitmapset *modified_attrs_hint);
extern bool ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot,
EState *estate, ItemPointer conflictTid,
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 1585861a02..fa7ca33289 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2892,7 +2892,8 @@ simple_heap_delete(Relation relation, ItemPointer tid)
TM_Result
heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
CommandId cid, Snapshot crosscheck, bool wait,
- TM_FailureData *tmfd, LockTupleMode *lockmode)
+ TM_FailureData *tmfd, LockTupleMode *lockmode,
+ Bitmapset **modified_attrs_hint)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -3758,10 +3759,15 @@ l2:
if (old_key_tuple != NULL && old_key_copied)
heap_freetuple(old_key_tuple);
+ /* Save for no logical changes hint when non-HOT update performed */
+ if (!use_hot_update && modified_attrs_hint)
+ *modified_attrs_hint = modified_attrs;
+ else
+ bms_free(modified_attrs);
+
bms_free(hot_attrs);
bms_free(key_attrs);
bms_free(id_attrs);
- bms_free(modified_attrs);
bms_free(interesting_attrs);
return TM_Ok;
@@ -3891,7 +3897,7 @@ simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
result = heap_update(relation, otid, tup,
GetCurrentCommandId(true), InvalidSnapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode);
+ &tmfd, &lockmode, NULL);
switch (result)
{
case TM_SelfModified:
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index dcaea7135f..f32ed0a5f2 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -314,7 +314,8 @@ static TM_Result
heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
CommandId cid, Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
- LockTupleMode *lockmode, bool *update_indexes)
+ LockTupleMode *lockmode, bool *update_indexes,
+ Bitmapset **modified_attrs_hint)
{
bool shouldFree = true;
HeapTuple tuple = ExecFetchSlotHeapTuple(slot, true, &shouldFree);
@@ -325,7 +326,7 @@ heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
tuple->t_tableOid = slot->tts_tableOid;
result = heap_update(relation, otid, tuple, cid, crosscheck, wait,
- tmfd, lockmode);
+ tmfd, lockmode, modified_attrs_hint);
ItemPointerCopy(&tuple->t_self, &slot->tts_tid);
/*
diff --git a/src/backend/access/nbtree/README b/src/backend/access/nbtree/README
index 9692e4cdf6..8560c5f6c3 100644
--- a/src/backend/access/nbtree/README
+++ b/src/backend/access/nbtree/README
@@ -807,7 +807,75 @@ Deduplication in unique indexes helps to prevent these pathological page
splits. Storing duplicates in a space efficient manner is not the goal,
since in the long run there won't be any duplicates anyway. Rather, we're
buying time for standard garbage collection mechanisms to run before a
-page split is needed.
+page split is needed. Also, the deduplication pass performs a targeted
+form of opportunistic deletion for unique indexes with version churn
+duplicates, as well as in cases where an UPDATE statement did not
+logically modify any indexed column, but nevertheless requires a successor
+index tuple. The latter case happens when tableam optimizations such as
+heapam's HOT cannot be applied. (We don't want to distinguish between
+version churn from UPDATEs and version churn from related INSERTs and
+DELETEs within a unique index.)
+
+The deduplication module usually opportunistically deletes whatever
+duplicates happen to be present on the page before moving on to
+deduplication proper, since in general some duplicates are likely to
+already be dead to everybody. This mechanism is quite similar to
+on-the-fly deletion of index tuples that will already have failed to
+prevent a page split by the time deduplication is considered. The main
+difference is that the tuples that get deleted are not opportunistically
+marked LP_DEAD by transactions that had to read the tuples in any case.
+
+The implementation must weigh the need to avoid a page split against the
+extra work performed with an exclusive buffer lock held. It's possible to
+make this trade-off sensibly despite the uncertainty about versioning and
+update chains within nbtree. In a unique index it's clear that there can
+only be one most recent committed version for any given value, which makes
+it certain that we'll delete some of the old versions --- at least in the
+absence of either a long running transaction that holds back the xmin
+horizon, and barring extreme churn concentrated in one part of the key
+space.
+
+Deduplication-deletion in non-unique indexes is trickier (the
+implementation is almost the same, but the justification is more
+complicated). In general there is nothing that assures us that there
+cannot be many logical rows that all have the same value in respect of an
+indexed column, which will cause us to waste time trying to find "old dead
+versions" among the duplicates that are actually distinct logical rows.
+We assume that all indexes work more or less like a unique index. This
+works better than you'd think. We at least know that there is some chance
+of UPDATE version churn in affected pages; the tuple we're trying to
+insert on the page at the point that this happens certainly originated
+that way, so there is a good chance that the same is true of existing,
+committed tuples. We're only willing to access a small number of
+heap/table pages to determine if our guess is correct, so if we're totally
+wrong then we'll have accessed no more than 2 or so heap/table pages.
+Finally, and perhaps most importantly, we'll learn from our mistake. The
+natural consequence of failing to deduplicate-delete is to do a
+deduplicate-merge pass. That will merge together the duplicate index
+tuples -- we surmise that these correspond to multiple extant logical
+rows. If and when there is another deduplication-delete pass on the same
+page, we'll skip over the posting list tuple.
+
+A posting list tuple may not actually point to one distinct logical row
+per TID, of course. Even when our inference is totally wrong it still
+seems like a good idea to skip posting lists like this. In general, the
+deduplication-deletion algorithm aims to maximize the chances of deleting
+_some_ tuples, while paying only a low fixed cost to access visibility
+information from the table. In general it's possible that deleting just
+one or two index tuples will buy us many hours or days before the question
+of splitting the same leaf page comes up again -- and VACUUM may well
+visit the page in that time anyway. If there really is intense pressure
+against the page, with many deduplication-delete passes occurring only
+milliseconds apart, then a version-driven page split is practically
+guaranteed to occur before long. This resolves the situation.
+
+Negative feedback (such as failing to dedup-delete any tuples) is not
+really undesirable. At worst it is an unavoidable part of how the
+algorithm works. We require that our various approaches to handling an
+overflowing page (due partially or entirely to version churn) compete to
+determine how best to handle the problem in a localized fashion. We
+expect to converge on a stable and roughly optimal behavior at each part
+of the key space in each index affected by version churn.
Unique index leaf pages only get a deduplication pass when an insertion
(that might have to split the page) observed an existing duplicate on the
diff --git a/src/backend/access/nbtree/nbtdedup.c b/src/backend/access/nbtree/nbtdedup.c
index f6be865b17..9a2b2b637d 100644
--- a/src/backend/access/nbtree/nbtdedup.c
+++ b/src/backend/access/nbtree/nbtdedup.c
@@ -16,13 +16,24 @@
#include "access/nbtree.h"
#include "access/nbtxlog.h"
+#include "access/tableam.h"
#include "miscadmin.h"
#include "utils/rel.h"
+static bool _bt_dedup_delete_one_page(Relation rel, Buffer buf,
+ Relation heapRel, Size newitemsz,
+ bool checkingunique,
+ bool logicallymodified,
+ bool *dedupmerge);
+static void _bt_dedup_merge_one_page(Relation rel, Buffer buf,
+ Relation heapRel, IndexTuple newitem,
+ Size newitemsz, bool checkingunique);
+static void _bt_dedup_delete_finish_pending(BTDedupState state);
static bool _bt_do_singleval(Relation rel, Page page, BTDedupState state,
OffsetNumber minoff, IndexTuple newitem);
static void _bt_singleval_fillfactor(Page page, BTDedupState state,
Size newitemsz);
+static int _bt_offsetnumbercmp(const void *arg1, const void *arg2);
#ifdef USE_ASSERT_CHECKING
static bool _bt_posting_valid(IndexTuple posting);
#endif
@@ -32,16 +43,12 @@ static bool _bt_posting_valid(IndexTuple posting);
* if we cannot successfully free at least newitemsz (we also need space for
* newitem's line pointer, which isn't included in caller's newitemsz).
*
- * The general approach taken here is to perform as much deduplication as
- * possible to free as much space as possible. Note, however, that "single
- * value" strategy is sometimes used for !checkingunique callers, in which
- * case deduplication will leave a few tuples untouched at the end of the
- * page. The general idea is to prepare the page for an anticipated page
- * split that uses nbtsplitloc.c's "single value" strategy to determine a
- * split point. (There is no reason to deduplicate items that will end up on
- * the right half of the page after the anticipated page split; better to
- * handle those if and when the anticipated right half page gets its own
- * deduplication pass, following further inserts of duplicates.)
+ * There are two types of deduplication pass: The merge deduplication pass,
+ * where we merge together duplicate index tuples into a new posting list, and
+ * the delete deduplication pass, where old garbage version index tuples are
+ * deleted based on visibility information that we fetch from the table. We
+ * generally expect to perform only one type of deduplication pass per call
+ * here, but it's possible that we'll end up doing both.
*
* This function should be called during insertion, when the page doesn't have
* enough space to fit an incoming newitem. If the BTP_HAS_GARBAGE page flag
@@ -54,27 +61,23 @@ static bool _bt_posting_valid(IndexTuple posting);
*/
void
_bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
- IndexTuple newitem, Size newitemsz, bool checkingunique)
+ IndexTuple newitem, Size newitemsz, bool checkingunique,
+ bool logicallymodified, bool allequalimage)
{
OffsetNumber offnum,
minoff,
maxoff;
Page page = BufferGetPage(buf);
BTPageOpaque opaque;
- Page newpage;
OffsetNumber deletable[MaxIndexTuplesPerPage];
- BTDedupState state;
int ndeletable = 0;
- Size pagesaving = 0;
- bool singlevalstrat = false;
- int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
/*
* We can't assume that there are no LP_DEAD items. For one thing, VACUUM
* will clear the BTP_HAS_GARBAGE hint without reliably removing items
* that are marked LP_DEAD. We don't want to unnecessarily unset LP_DEAD
- * bits when deduplicating items. Allowing it would be correct, though
- * wasteful.
+ * bits when deduplicating items by merging. Allowing it would be
+ * correct, though wasteful.
*/
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
minoff = P_FIRSTDATAKEY(opaque);
@@ -99,18 +102,330 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
*/
if (PageGetFreeSpace(page) >= newitemsz)
return;
-
- /*
- * Reconsider number of items on page, in case _bt_delitems_delete()
- * managed to delete an item or two
- */
- minoff = P_FIRSTDATAKEY(opaque);
- maxoff = PageGetMaxOffsetNumber(page);
}
+ minoff = maxoff = InvalidOffsetNumber; /* Invalidate */
+
+ /*
+ * We're willing to do dedup deletion with a unique index that is not
+ * generally safe for deduplication (though only when deduplicate_items
+ * storage param is not explicitly set to 'off', which our caller checks
+ * for us).
+ *
+ * The logic used by the !checkingunique _bt_dedup_delete_one_page() case
+ * relies on regular deduplication passes occurring, and merging together
+ * index entries that point to distinct logical table rows that happen to
+ * have the same key value (this might not happen immediately, but it
+ * should happen before too long). We're not willing to deduplicate when
+ * the index isn't a unique index and isn't an index that is generally
+ * safe for deduplication. Exit early if we see that.
+ */
+ if (!allequalimage && !checkingunique)
+ return;
+
/* Passed-in newitemsz is MAXALIGNED but does not include line pointer */
newitemsz += sizeof(ItemIdData);
+ if (checkingunique || !logicallymodified)
+ {
+ bool dedupmerge = true;
+
+ /* Perform delete deduplication pass */
+ if (_bt_dedup_delete_one_page(rel, buf, heapRel, newitemsz,
+ checkingunique, logicallymodified,
+ &dedupmerge))
+ return;
+
+ /*
+ * _bt_dedup_delete_one_page() may occasionally indicate no
+ * duplicates, in which case we should give up now
+ */
+ if (!dedupmerge)
+ return;
+
+ /* Fall back on merge deduplication. This happens infrequently. */
+ }
+
+ /*
+ * Perform merge deduplication pass, though only when index is
+ * allequalimage -- otherwise it's not safe
+ */
+ if (allequalimage)
+ _bt_dedup_merge_one_page(rel, buf, heapRel, newitem, newitemsz,
+ checkingunique);
+}
+
+/*
+ * Perform a delete deduplication pass.
+ *
+ * See if duplicate index tuples are eligible to be deleted, even though they
+ * don't have their LP_DEAD bit set already. Give up if we have to access
+ * more than a few heap pages before we can free enough space to fit newitem.
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
+ *
+ * FIXME: Be less eager with tuples that contain NULLs for checkingunique
+ * callers, since NULLs can be duplicates without that signaling anything
+ * about version churn. Just because we're checkingunique (which implies that
+ * incoming newitem isn't a NULL) doesn't mean there aren't lots of other
+ * NULLs on the page.
+ */
+static bool
+_bt_dedup_delete_one_page(Relation rel, Buffer buf, Relation heapRel,
+ Size newitemsz, bool checkingunique,
+ bool logicallymodified, bool *dedupmerge)
+{
+ OffsetNumber offnum,
+ minoff,
+ maxoff;
+ Size freespace;
+ Page page = BufferGetPage(buf);
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+ BTDedupState state;
+ TM_IndexDelete *duptids;
+ int nduptids;
+ int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+
+ state = (BTDedupState) palloc(sizeof(BTDedupStateData));
+ state->deduplicate = true;
+ state->nmaxitems = 0;
+ /* Final "posting list" size should not restrict anything */
+ state->maxpostingsize = BLCKSZ;
+ state->base = NULL;
+ state->baseoff = InvalidOffsetNumber;
+ state->basetupsize = 0;
+ state->htids = palloc(state->maxpostingsize);
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+ state->nintervals = 0;
+
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
+ for (offnum = minoff;
+ offnum <= maxoff;
+ offnum = OffsetNumberNext(offnum))
+ {
+ ItemId itemid = PageGetItemId(page, offnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+
+ Assert(!ItemIdIsDead(itemid));
+
+ if (offnum == minoff)
+ {
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ else if (_bt_keep_natts_fast(rel, state->base, itup) > nkeyatts &&
+ _bt_dedup_save_htid(state, itup))
+ {
+
+ }
+ else
+ {
+ _bt_dedup_delete_finish_pending(state);
+
+ /* itup starts new pending posting list */
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ }
+ /* Handle the final interval, which is still pending */
+ _bt_dedup_delete_finish_pending(state);
+
+ if (state->nintervals == 0)
+ {
+ /* No duplicates */
+ pfree(state->htids);
+ pfree(state);
+ /* Caller should avoid deduplication-by-merging pass */
+ *dedupmerge = false;
+ return false;
+ }
+
+ /*
+ * Accumulate an array of duplicate TIDs to pass to heapam from dedup
+ * intervals
+ */
+ nduptids = 0;
+ duptids = palloc0(maxoff * sizeof(TM_IndexDelete));
+ for (int i = 0; i < state->nintervals; i++)
+ {
+ BTDedupInterval interval = state->intervals[i];
+
+ Assert(interval.nitems > 0);
+ /* Iterate through tuples of given interval/value */
+ for (int j = 0; j < interval.nitems; j++)
+ {
+ OffsetNumber dupoffnum = interval.baseoff + j;
+ ItemId itemid = PageGetItemId(page, dupoffnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+
+ /*
+ * Don't include any posting list tuples. We still always count
+ * plain non-pivot tuples that are the only non-pivot tuples
+ * within the whole interval, though.
+ *
+ * The fact that a previous merge deduplication pass was ever able
+ * to take place suggests that the TIDs mostly point to distinct
+ * logical rows in the table. We may have tried to delete these
+ * same TIDs just before this merge pass, and if we did it's
+ * unlikely that we'll have better luck with them now. (It's also
+ * quite possible that there was no previous delete deduplication
+ * pass for this page at all, which should also discourage us from
+ * including the posting list tuple.)
+ *
+ * XXX: It might make sense to do more here for checkingunique
+ * callers. Thoughts on that design:
+ *
+ * Benchmarking currently suggests that being more sophisticated
+ * with unique index posting list tuples here wouldn't actually
+ * make all that much difference. It's something that we could do
+ * when we get desperate, but how long can we really expect to
+ * hold off a page split once things get that bad? We ought to
+ * make non-HOT UPDATEs "work hard" to prove that a page split
+ * caused by version churn it truly necessary, but clearly it's
+ * possible to go too far with that.
+ *
+ * Consider the extreme case. We certainly don't want to make
+ * non-HOT UPDATEs completely exhaust every possible avenue before
+ * they may split a leaf page. That hurts cases with buffer lock
+ * contention way too much, and might even make the problem worse
+ * indirectly by hindering moving the xmin horizon forward.
+ * Version driven page splits are not _inherently_ a bad thing;
+ * they still make sense as an extreme solution to an extreme (and
+ * extremely rare) problem.
+ */
+ if (BTreeTupleIsPosting(itup))
+ continue;
+
+ /* Save relevant index tuple info for tableam call */
+ duptids[nduptids].ioffnum = dupoffnum;
+ duptids[nduptids].tid = itup->t_tid;
+ nduptids++;
+ }
+ }
+
+ /* Done with dedup state */
+ pfree(state->htids);
+ pfree(state);
+
+ /* Record exact freespace left on page (incudes line pointer overhead) */
+ freespace = PageGetExactFreeSpace(page);
+
+ if (nduptids > 0)
+ {
+ SnapshotData SnapshotNonVacuumable;
+ OffsetNumber deletable[MaxIndexTuplesPerPage];
+ int nheapblocksaccessed;
+ int ntableamkills;
+ int ndeletable = 0;
+
+ /*
+ * Determine which TIDs are dead among dups.
+ *
+ * We aim to delete one eighth of the duplicates (or 5 total,
+ * whichever is greater). There would be a good chance of deleting as
+ * many as half of the duplicates in some common scenarios if we were
+ * eager, but being lazy is a better trade-off.
+ */
+ InitNonVacuumableSnapshot(SnapshotNonVacuumable,
+ GlobalVisTestFor(heapRel));
+ ntableamkills = table_index_batch_check(heapRel, duptids, nduptids,
+ &SnapshotNonVacuumable,
+ Max(nduptids / 8, 5),
+ &nheapblocksaccessed);
+
+ /*
+ * Look through dups array, which probably has some items that we can
+ * delete now.
+ *
+ * Note: The dups array is no longer in its original order (table am
+ * sorted it based on its own criteria). We don't care about the
+ * order, though.
+ */
+ for (int i = 0; i < nduptids; i++)
+ {
+ if (duptids[i].isdead)
+ {
+ OffsetNumber deadoffnum = duptids[i].ioffnum;
+ ItemId itemid = PageGetItemId(page, deadoffnum);
+
+ /*
+ * Delete item, and tally how much space will be saved when
+ * we're done with the page.
+ *
+ * No MarkBufferDirtyHint() call needed -- we'll physically
+ * delete item in a moment anyway, even when we know that we
+ * won't have freed enough space to avoid a page split (must
+ * not return before reaching _bt_delitems_delete()).
+ *
+ * (Actually, we don't really need to mark the ItemId dead
+ * either, but we do so anyway because it's expected in
+ * opportunistic deletion code called below.)
+ */
+ ItemIdMarkDead(itemid);
+ deletable[ndeletable++] = deadoffnum;
+ freespace += MAXALIGN(ItemIdGetLength(itemid)) +
+ sizeof(ItemIdData);
+ }
+
+ if (ntableamkills == ndeletable)
+ break;
+ }
+
+ Assert(ntableamkills == ndeletable);
+
+ if (ndeletable > 0)
+ {
+ /* Have to give array to _bt_delitems_delete in asc order */
+ qsort(deletable, ndeletable, sizeof(OffsetNumber),
+ _bt_offsetnumbercmp);
+
+ /* Actually delete items */
+ _bt_delitems_delete(rel, buf, deletable, ndeletable, heapRel);
+ }
+ }
+
+ pfree(duptids);
+
+ /* Return success when page split (or merge deduplication pass) avoided */
+ Assert(freespace == PageGetExactFreeSpace(page));
+ return freespace >= newitemsz;
+}
+
+/*
+ * Perform a merge deduplication pass.
+ *
+ * The general approach taken here is to perform as much deduplication as
+ * possible to free as much space as possible. Note, however, that "single
+ * value" strategy is sometimes used for !checkingunique callers, in which
+ * case deduplication will leave a few tuples untouched at the end of the
+ * page. The general idea is to prepare the page for an anticipated page
+ * split that uses nbtsplitloc.c's "single value" strategy to determine a
+ * split point. (There is no reason to deduplicate items that will end up on
+ * the right half of the page after the anticipated page split; better to
+ * handle those if and when the anticipated right half page gets its own
+ * deduplication pass, following further inserts of duplicates.)
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
+ */
+static void
+_bt_dedup_merge_one_page(Relation rel, Buffer buf, Relation heapRel,
+ IndexTuple newitem, Size newitemsz,
+ bool checkingunique)
+{
+ OffsetNumber offnum,
+ minoff,
+ maxoff;
+ Page page = BufferGetPage(buf);
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+ Page newpage;
+ BTDedupState state;
+ Size pagesaving = 0;
+ bool singlevalstrat = false;
+ int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+
/*
* By here, it's clear that deduplication will definitely be attempted.
* Initialize deduplication state.
@@ -138,6 +453,9 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
/* nintervals should be initialized to zero */
state->nintervals = 0;
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
+
/* Determine if "single value" strategy should be used */
if (!checkingunique)
singlevalstrat = _bt_do_singleval(rel, page, state, minoff, newitem);
@@ -203,7 +521,7 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
* form new posting tuple, and actually update the page. Else
* reset the state and move on without modifying the page.
*/
- pagesaving += _bt_dedup_finish_pending(newpage, state);
+ pagesaving += _bt_dedup_merge_finish_pending(newpage, state);
if (singlevalstrat)
{
@@ -235,7 +553,7 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
}
/* Handle the last item */
- pagesaving += _bt_dedup_finish_pending(newpage, state);
+ pagesaving += _bt_dedup_merge_finish_pending(newpage, state);
/*
* If no items suitable for deduplication were found, newpage must be
@@ -317,8 +635,8 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
* Every tuple processed by deduplication either becomes the base tuple for a
* posting list, or gets its heap TID(s) accepted into a pending posting list.
* A tuple that starts out as the base tuple for a posting list will only
- * actually be rewritten within _bt_dedup_finish_pending() when it turns out
- * that there are duplicates that can be merged into the base tuple.
+ * actually be rewritten within _bt_dedup_merge_finish_pending() when it turns
+ * out that there are duplicates that can be merged into the base tuple.
*/
void
_bt_dedup_start_pending(BTDedupState state, IndexTuple base,
@@ -443,7 +761,7 @@ _bt_dedup_save_htid(BTDedupState state, IndexTuple itup)
* where no deduplication was possible.
*/
Size
-_bt_dedup_finish_pending(Page newpage, BTDedupState state)
+_bt_dedup_merge_finish_pending(Page newpage, BTDedupState state)
{
OffsetNumber tupoff;
Size tuplesz;
@@ -496,6 +814,38 @@ _bt_dedup_finish_pending(Page newpage, BTDedupState state)
return spacesaving;
}
+/*
+ * Stripped down version of _bt_dedup_merge_finish_pending() used by
+ * _bt_dedup_delete_one_page().
+ *
+ * Finalize deduplication interval/duplicate group without materializing the
+ * would-be posting list tuple.
+ */
+static void
+_bt_dedup_delete_finish_pending(BTDedupState state)
+{
+ Assert(state->nitems > 0);
+ Assert(state->nitems <= state->nhtids);
+ Assert(state->intervals[state->nintervals].baseoff == state->baseoff);
+
+ if (state->nitems == 1)
+ {
+ /* Don't merge */
+ }
+ else
+ {
+ /* Save final number of items for posting list */
+ state->intervals[state->nintervals].nitems = state->nitems;
+ /* Increment nintervals, since we wrote a new posting list tuple */
+ state->nintervals++;
+ }
+
+ /* Reset state for next pending posting list */
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+}
+
/*
* Determine if page non-pivot tuples (data items) are all duplicates of the
* same value -- if they are, deduplication's "single value" strategy should
@@ -809,6 +1159,25 @@ _bt_swap_posting(IndexTuple newitem, IndexTuple oposting, int postingoff)
return nposting;
}
+/*
+ * qsort-style comparator used by _bt_dedup_delete_one_page()
+ */
+static int
+_bt_offsetnumbercmp(const void *arg1, const void *arg2)
+{
+ OffsetNumber *inter1 = (OffsetNumber *) arg1;
+ OffsetNumber *inter2 = (OffsetNumber *) arg2;
+
+ if (*inter1 > *inter2)
+ return 1;
+ if (*inter1 < *inter2)
+ return -1;
+
+ Assert(false);
+
+ return 0;
+}
+
/*
* Verify posting list invariants for "posting", which must be a posting list
* tuple. Used within assertions.
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index d36f7557c8..af5aa849ef 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -37,6 +37,7 @@ static TransactionId _bt_check_unique(Relation rel, BTInsertState insertstate,
static OffsetNumber _bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool logicallymodified,
BTStack stack,
Relation heapRel);
static void _bt_stepright(Relation rel, BTInsertState insertstate, BTStack stack);
@@ -86,7 +87,9 @@ _bt_doinsert(Relation rel, IndexTuple itup,
BTInsertStateData insertstate;
BTScanInsert itup_key;
BTStack stack;
- bool checkingunique = (checkUnique != UNIQUE_CHECK_NO);
+ bool checkingunique = (checkUnique != UNIQUE_CHECK_NO &&
+ checkUnique != UNIQUE_CHECK_NO_WITH_UNCHANGED);
+ bool logicallymodified = (checkUnique != UNIQUE_CHECK_NO_WITH_UNCHANGED);
/* we need an insertion scan key to do our search, so build one */
itup_key = _bt_mkscankey(rel, itup);
@@ -235,7 +238,7 @@ search:
* checkingunique.
*/
newitemoff = _bt_findinsertloc(rel, &insertstate, checkingunique,
- stack, heapRel);
+ logicallymodified, stack, heapRel);
_bt_insertonpg(rel, itup_key, insertstate.buf, InvalidBuffer, stack,
itup, insertstate.itemsz, newitemoff,
insertstate.postingoff, false);
@@ -767,6 +770,11 @@ _bt_check_unique(Relation rel, BTInsertState insertstate, Relation heapRel,
* the right, rather than the first page. In that case, this function
* moves right to the correct target page.
*
+ * If 'logicallymodified' is false, this is for an UPDATE that didn't
+ * logically change the indexed value, but must nevertheless have a new
+ * entry to point to a successor version. This hint from the executor
+ * influences the behavior of deduplication.
+ *
* (In a !heapkeyspace index, there can be multiple pages with the same
* high key, where the new tuple could legitimately be placed on. In
* that case, the caller passes the first page containing duplicates,
@@ -790,6 +798,7 @@ static OffsetNumber
_bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool logicallymodified,
BTStack stack,
Relation heapRel)
{
@@ -873,14 +882,21 @@ _bt_findinsertloc(Relation rel,
/*
* If the target page is full, see if we can obtain enough space by
* erasing LP_DEAD items. If that fails to free enough space, see if
- * we can avoid a page split by performing a deduplication pass over
- * the page.
+ * we can avoid a page split by performing deduplication. Usually
+ * this means a deduplication merge pass, though a deduplication
+ * delete pass is preferred when it looks like version churn is the
+ * source of most of the duplicates (nbtdedup.c decides which approach
+ * to take based on the checkingunique and logicallymodified flags).
*
- * We only perform a deduplication pass for a checkingunique caller
- * when the incoming item is a duplicate of an existing item on the
- * leaf page. This heuristic avoids wasting cycles -- we only expect
- * to benefit from deduplicating a unique index page when most or all
- * recently added items are duplicates. See nbtree/README.
+ * We only consider deduplication for a checkingunique caller when the
+ * incoming item is a known duplicate of an existing item on the leaf
+ * page. This heuristic avoids wasting cycles. The overarching goal
+ * within a unique index is to prevent an unnecessary page split
+ * altogether by delaying splits again and again (the goal is not to
+ * save space). If even one incoming tuple that gets added to this
+ * page originates with an INSERT statement then a page split is all
+ * but inevitable anyway --- that's why it's okay that our heuristic
+ * only considers the current incoming newitem. See nbtree/README.
*/
if (PageGetFreeSpace(page) < insertstate->itemsz)
{
@@ -893,13 +909,13 @@ _bt_findinsertloc(Relation rel,
uniquedup = true;
}
- if (itup_key->allequalimage && BTGetDeduplicateItems(rel) &&
- (!checkingunique || uniquedup) &&
+ if (BTGetDeduplicateItems(rel) && (!checkingunique || uniquedup) &&
PageGetFreeSpace(page) < insertstate->itemsz)
{
_bt_dedup_one_page(rel, insertstate->buf, heapRel,
insertstate->itup, insertstate->itemsz,
- checkingunique);
+ checkingunique, logicallymodified,
+ itup_key->allequalimage);
insertstate->bounds_valid = false;
}
}
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index efee86784b..ecfe79badb 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -273,7 +273,7 @@ static void _bt_sortaddtup(Page page, Size itemsize,
bool newfirstdataitem);
static void _bt_buildadd(BTWriteState *wstate, BTPageState *state,
IndexTuple itup, Size truncextra);
-static void _bt_sort_dedup_finish_pending(BTWriteState *wstate,
+static void _bt_dedup_sort_finish_pending(BTWriteState *wstate,
BTPageState *state,
BTDedupState dstate);
static void _bt_uppershutdown(BTWriteState *wstate, BTPageState *state);
@@ -1068,11 +1068,11 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup,
* Finalize pending posting list tuple, and add it to the index. Final tuple
* is based on saved base tuple, and saved list of heap TIDs.
*
- * This is almost like _bt_dedup_finish_pending(), but it adds a new tuple
- * using _bt_buildadd().
+ * This is almost like _bt_dedup_merge_finish_pending(), but it adds a new
+ * tuple using _bt_buildadd().
*/
static void
-_bt_sort_dedup_finish_pending(BTWriteState *wstate, BTPageState *state,
+_bt_dedup_sort_finish_pending(BTWriteState *wstate, BTPageState *state,
BTDedupState dstate)
{
Assert(dstate->nitems > 0);
@@ -1371,7 +1371,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
* _bt_dedup_save_htid() opted to not merge current item into
* pending posting list.
*/
- _bt_sort_dedup_finish_pending(wstate, state, dstate);
+ _bt_dedup_sort_finish_pending(wstate, state, dstate);
pfree(dstate->base);
/* start new pending posting list with itup copy */
@@ -1390,7 +1390,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
* Handle the last item (there must be a last item when the
* tuplesort returned one or more tuples)
*/
- _bt_sort_dedup_finish_pending(wstate, state, dstate);
+ _bt_dedup_sort_finish_pending(wstate, state, dstate);
pfree(dstate->base);
pfree(dstate->htids);
}
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index bda9be2348..9186bdeea5 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -530,12 +530,12 @@ btree_xlog_dedup(XLogReaderState *record)
}
else
{
- _bt_dedup_finish_pending(newpage, state);
+ _bt_dedup_merge_finish_pending(newpage, state);
_bt_dedup_start_pending(state, itup, offnum);
}
}
- _bt_dedup_finish_pending(newpage, state);
+ _bt_dedup_merge_finish_pending(newpage, state);
Assert(state->nintervals == xlrec->nintervals);
Assert(memcmp(state->intervals, intervals,
state->nintervals * sizeof(BTDedupInterval)) == 0);
diff --git a/src/backend/access/table/tableam.c b/src/backend/access/table/tableam.c
index 6438c45716..abe69db84e 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -30,6 +30,11 @@
#include "storage/shmem.h"
#include "storage/smgr.h"
+static void table_index_batch_check_block_count_sort(TM_IndexDelete *duptids,
+ int nduptids);
+static int indexdelete_tids_cmp(const void *arg1, const void *arg2);
+static int indexdeletecount_ntids_cmp(const void *arg1, const void *arg2);
+
/*
* Constants to control the behavior of block allocation to parallel workers
* during a parallel seqscan. Technically these values do not need to be
@@ -207,9 +212,9 @@ table_beginscan_parallel(Relation relation, ParallelTableScanDesc parallel_scan)
/*
* To perform that check simply start an index scan, create the necessary
* slot, do the heap lookup, and shut everything down again. This could be
- * optimized, but is unlikely to matter from a performance POV. If there
- * frequently are live index pointers also matching a unique index key, the
- * CPU overhead of this routine is unlikely to matter.
+ * optimized, but is unlikely to matter from a performance POV. Note that
+ * table_index_batch_check() is optimized in this way, since it is designed
+ * as a batch operation.
*
* Note that *tid may be modified when we return true if the AM supports
* storing multiple row versions reachable via a single index entry (like
@@ -236,6 +241,112 @@ table_index_fetch_tuple_check(Relation rel,
return found;
}
+/*
+ * Specialized variant of table_index_fetch_tuple_check() that can be used
+ * by index AMs to perform "bottom up" deletion of duplicate index tuples.
+ * This is particularly likely to work well with unique indexes.
+ *
+ * Note: This routine sorts the duptids array, but does not modify any
+ * individual entry accept to mark it as dead for caller.
+ *
+ * Returns total number of duptids that can be killed in index by caller.
+ *
+ * TODO: This should be combined with the equivalent of a call to
+ * table_compute_xid_horizon_for_tuples().
+ */
+int
+table_index_batch_check(Relation rel, TM_IndexDelete *duptids, int nduptids,
+ Snapshot snapshot, int nkillsneeded,
+ int *nblocksaccessed)
+{
+ IndexFetchTableData *scan;
+ TupleTableSlot *slot;
+ int nkills = 0;
+ BlockNumber last = InvalidBlockNumber;
+ bool final_block = false;
+
+ slot = table_slot_create(rel, NULL);
+ scan = table_index_fetch_begin(rel);
+
+ *nblocksaccessed = 0;
+ table_index_batch_check_block_count_sort(duptids, nduptids);
+ for (int i = 0; i < nduptids; i++)
+ {
+ ItemPointer tid = &(duptids + i)->tid;
+ bool new_block = last != ItemPointerGetBlockNumber(tid);
+ ItemPointerData tmp;
+ bool call_again = false;
+ bool all_dead = false;
+ bool found;
+
+ Assert(!duptids[i].isdead);
+
+ /*
+ * Never access more than 5 blocks, no matter what.
+ */
+ if (new_block && *nblocksaccessed >= 5)
+ break;
+
+ /*
+ * New block encountered, but last block we processed is supposed to
+ * be final block. Quit now -- don't access this new block at all.
+ */
+ if (new_block && final_block)
+ break;
+
+ /*
+ * Quit when we're about to access a third table block and have no
+ * kills to show for accessing the first two.
+ */
+ if (new_block && *nblocksaccessed >= 2 && nkills == 0)
+ break;
+
+ /*
+ * Lower the bar when we've already accessed 3 blocks, and would
+ * otherwise access a fourth now -- quit when we have only had 3+
+ * kills
+ */
+ if (new_block && *nblocksaccessed >= 3 && nkills >= 3)
+ break;
+
+ tmp = *tid;
+ found = table_index_fetch_tuple(scan, &tmp, snapshot, slot,
+ &call_again, &all_dead);
+
+ if (new_block)
+ (*nblocksaccessed)++;
+ last = ItemPointerGetBlockNumber(tid);
+ if (!found && all_dead)
+ {
+ duptids[i].isdead = true;
+ nkills++;
+ }
+
+ if (nkills >= nkillsneeded)
+ {
+ /*
+ * Caller is satisfied, so we can quit now. But before we do,
+ * might as well finish off remaining TIDs on same table page (if
+ * any). Indicate that the current block we're processing is the
+ * final one we intend to process.
+ *
+ * We only quit when we've accessed at least two blocks already
+ * (at least within a typical identity column style primary key
+ * with version churn). It's not uncommon for us to find all the
+ * kills that caller needs having only accessed one table block,
+ * but when that happens it seems like a good idea to be ambitious
+ * about finding more tuples to kill.
+ */
+ if (*nblocksaccessed >= 2)
+ final_block = true;
+ }
+ }
+
+ table_index_fetch_end(scan);
+ ExecDropSingleTupleTableSlot(slot);
+
+ return nkills;
+}
/* ------------------------------------------------------------------------
* Functions for non-modifying operations on individual tuples
@@ -356,7 +467,7 @@ simple_table_tuple_update(Relation rel, ItemPointer otid,
GetCurrentCommandId(true),
snapshot, InvalidSnapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode, update_indexes);
+ &tmfd, &lockmode, update_indexes, NULL);
switch (result)
{
@@ -763,3 +874,127 @@ table_block_relation_estimate_size(Relation rel, int32 *attr_widths,
else
*allvisfrac = (double) relallvisible / curpages;
}
+
+typedef struct TM_IndexDeleteCounts
+{
+ BlockNumber table_block;
+ int ntids_in_block;
+} TM_IndexDeleteCounts;
+
+/*
+ * table_index_batch_check() requires that the duptids array be in a certain
+ * order before it gets started. This helper routine handles that.
+ *
+ * TIDs are grouped together by block number, with ascending TID order within
+ * each group (i.e. in ascending TID offset number order). The block number
+ * groups are ordered according to the total number of candidate TIDs. This
+ * order maximizes the final number of TIDs that caller can kill in index
+ * relative to the number of tableam blocks accessed.
+ *
+ * The goal of the sort order is to process as many dup table TIDs as
+ * possible with as few table buffer accesses as possible. In practice it's
+ * frequently possible to kill relatively many TIDs with only one or two
+ * table page accesses due to the effect of locality.
+ */
+static void
+table_index_batch_check_block_count_sort(TM_IndexDelete *duptids, int nduptids)
+{
+ TM_IndexDeleteCounts *blockcounts;
+ TM_IndexDelete *reorderedduptids;
+ BlockNumber curblock = InvalidBlockNumber;
+ int nblock_groups = 0;
+ int ncopied = 0;
+
+ Assert(nduptids > 0);
+
+ /* First sort caller's array by TID */
+ qsort(duptids, nduptids, sizeof(TM_IndexDelete), indexdelete_tids_cmp);
+
+ /* Calculate per-table-block count of TIDs */
+ blockcounts = palloc(sizeof(TM_IndexDeleteCounts) * nduptids);
+ for (int i = 0; i < nduptids; i++)
+ {
+ ItemPointer duptid = &duptids[i].tid;
+
+ if (curblock != ItemPointerGetBlockNumber(duptid))
+ {
+ /* New block group */
+ nblock_groups++;
+
+ curblock = ItemPointerGetBlockNumber(duptid);
+ blockcounts[nblock_groups - 1].table_block = curblock;
+ blockcounts[nblock_groups - 1].ntids_in_block = 1;
+ }
+ else
+ {
+ blockcounts[nblock_groups - 1].ntids_in_block++;
+ }
+ }
+
+ /* Sort blockcounts by count in desc order, then tiebreak on block number */
+ qsort(blockcounts, nblock_groups, sizeof(TM_IndexDeleteCounts),
+ indexdeletecount_ntids_cmp);
+ reorderedduptids = palloc0(nduptids * sizeof(TM_IndexDelete));
+ for (int i = 0; i < nblock_groups; i++)
+ {
+ TM_IndexDeleteCounts *blockgroup = blockcounts + i;
+
+ for (int j = 0; j < nduptids; j++)
+ {
+ ItemPointer tid = &duptids[j].tid;
+
+ if (blockgroup->table_block == ItemPointerGetBlockNumber(tid))
+ {
+ memcpy(reorderedduptids + ncopied, duptids + j,
+ sizeof(TM_IndexDelete) * blockgroup->ntids_in_block);
+ ncopied += blockgroup->ntids_in_block;
+ break; /* Move on to next table block group */
+ }
+ }
+ }
+
+ /* Copy back final sorted array into caller's array */
+ memcpy(duptids, reorderedduptids, sizeof(TM_IndexDelete) * nduptids);
+
+ /* be tidy */
+ pfree(reorderedduptids);
+ pfree(blockcounts);
+}
+
+/*
+ * qsort-style comparator used in table_index_batch_check_block_count_sort()
+ */
+static int
+indexdelete_tids_cmp(const void *arg1, const void *arg2)
+{
+ TM_IndexDelete *indexdelete1 = (TM_IndexDelete *) arg1;
+ TM_IndexDelete *indexdelete2 = (TM_IndexDelete *) arg2;
+
+ return ItemPointerCompare(&indexdelete1->tid, &indexdelete2->tid);
+}
+
+/*
+ * qsort-style comparator used in table_index_batch_check_block_count_sort()
+ */
+static int
+indexdeletecount_ntids_cmp(const void *arg1, const void *arg2)
+{
+ TM_IndexDeleteCounts *count1 = (TM_IndexDeleteCounts *) arg1;
+ TM_IndexDeleteCounts *count2 = (TM_IndexDeleteCounts *) arg2;
+
+ /* Invert usual order here to get desc ntids_in_block sort order */
+ if (count1->ntids_in_block > count2->ntids_in_block)
+ return -1;
+ if (count1->ntids_in_block < count2->ntids_in_block)
+ return 1;
+
+ /* Tiebreak on block number (this is asc order) */
+ if (count1->table_block > count2->table_block)
+ return 1;
+ if (count1->table_block < count2->table_block)
+ return -1;
+
+ Assert(false);
+
+ return 0;
+}
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 531bd7c73a..b9b625b883 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -2523,7 +2523,7 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
recheckIndexes =
ExecInsertIndexTuples(resultRelInfo,
buffer->slots[i], estate, false, NULL,
- NIL);
+ NIL, NULL);
ExecARInsertTriggers(estate, resultRelInfo,
slots[i], recheckIndexes,
cstate->transition_capture);
@@ -3285,7 +3285,8 @@ CopyFrom(CopyState cstate)
estate,
false,
NULL,
- NIL);
+ NIL,
+ NULL);
}
/* AFTER ROW INSERT Triggers */
diff --git a/src/backend/executor/execIndexing.c b/src/backend/executor/execIndexing.c
index c6b5bcba7b..d171d26b69 100644
--- a/src/backend/executor/execIndexing.c
+++ b/src/backend/executor/execIndexing.c
@@ -275,7 +275,8 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
EState *estate,
bool noDupErr,
bool *specConflict,
- List *arbiterIndexes)
+ List *arbiterIndexes,
+ Bitmapset *modified_attrs_hint)
{
ItemPointer tupleid = &slot->tts_tid;
List *result = NIL;
@@ -389,6 +390,44 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
else
checkUnique = UNIQUE_CHECK_PARTIAL;
+ /*
+ * We may have to hint to index am that this is a logically unchanged
+ * index tuple. This happens when we're inserting a duplicate tuple
+ * just to represent the successor version.
+ */
+ if (checkUnique == UNIQUE_CHECK_NO && modified_attrs_hint)
+ {
+ bool logicallyModified = false;
+
+ for (int attr = 0; attr < indexInfo->ii_NumIndexAttrs; attr++)
+ {
+ int keycol = indexInfo->ii_IndexAttrNumbers[attr];
+
+ if (keycol > 0)
+ {
+ logicallyModified =
+ bms_is_member(keycol - FirstLowInvalidHeapAttributeNumber,
+ modified_attrs_hint);
+ if (logicallyModified)
+ break;
+ }
+ else
+ {
+ /*
+ * XXX: For now we always assume that expression indexes
+ * and indexes with whole-row vars were not modified by an
+ * UPDATE (i.e. they just use the dedup delete
+ * optimization regardless of the details of the UPDATE).
+ * Review this decision when the high level design is a
+ * bit better worked out.
+ */
+ }
+ }
+
+ if (!logicallyModified)
+ checkUnique = UNIQUE_CHECK_NO_WITH_UNCHANGED;
+ }
+
satisfiesConstraint =
index_insert(indexRelation, /* index relation */
values, /* array of index Datums */
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index 01d26881e7..e97d05b448 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -445,7 +445,7 @@ ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false, NULL,
- NIL);
+ NIL, NULL);
/* AFTER ROW INSERT Triggers */
ExecARInsertTriggers(estate, resultRelInfo, slot,
@@ -513,7 +513,7 @@ ExecSimpleRelationUpdate(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false, NULL,
- NIL);
+ NIL, NULL);
/* AFTER ROW UPDATE Triggers */
ExecARUpdateTriggers(estate, resultRelInfo,
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 0c055ed408..a522c952e5 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -605,7 +605,7 @@ ExecInsert(ModifyTableState *mtstate,
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, true,
&specConflict,
- arbiterIndexes);
+ arbiterIndexes, NULL);
/* adjust the tuple's state accordingly */
table_tuple_complete_speculative(resultRelationDesc, slot,
@@ -644,7 +644,7 @@ ExecInsert(ModifyTableState *mtstate,
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false,
- NULL, NIL);
+ NULL, NIL, NULL);
}
}
@@ -1238,6 +1238,7 @@ ExecUpdate(ModifyTableState *mtstate,
TM_Result result;
TM_FailureData tmfd;
List *recheckIndexes = NIL;
+ Bitmapset *modified_attrs_hint = NULL;
/*
* abort the operation if not running transactions
@@ -1401,7 +1402,8 @@ lreplace:;
estate->es_snapshot,
estate->es_crosscheck_snapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode, &update_indexes);
+ &tmfd, &lockmode, &update_indexes,
+ &modified_attrs_hint);
switch (result)
{
@@ -1534,7 +1536,8 @@ lreplace:;
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false,
- NULL, NIL);
+ NULL, NIL,
+ modified_attrs_hint);
}
if (canSetTag)
--
2.25.1
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:59 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-10-16 20:58 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-10-20 02:37 ` Peter Geoghegan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-10-20 02:37 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Fri, Oct 16, 2020 at 1:58 PM Peter Geoghegan <[email protected]> wrote:
> Attached is v3, which is rebased against the master branch as of
> today. No real changes, though.
And now here's v4.
This version adds handling of posting list tuples, which I was
skipping over before. Highly contended leaf pages with posting list
tuples could still sometimes get "logically unnecessary" page splits
in v3, which this seems to fix (barring the most extreme cases of
version churn, where the patch cannot and should not prevent page
splits). Actually, posting list tuple handling was something that we
had in v1 but lost in v2, because v2 changed our general strategy to
focus on what is convenient to the heap/tableam, which is the most
important thing by far (the cost of failing must be a low, fixed, well
understood and well targeted cost). The fix was to include TIDs from
posting lists, while marking them "non-promising". Only plain tuples
that are duplicates are considered promising. Only promising tuples
influence where we look for tuples to kill most of the time. The
exception is when there is an even number of promising tuples on two
heap pages, where we tiebreak on the total number of TIDs that point
to the heap page from the leaf page.
I seem to be able to cap the costs paid when the optimization doesn't
work out to the extent that we can get away with visiting only *one*
heap page before giving up. And, we now never visit more than 3 total
(2 is the common case when the optimization is really effective). This
may sound conservative -- because it is -- but it seems to work in
practice. I may change my mind about that and decide to be less
conservative, but so far all of the evidence I've seen suggests that
it doesn't matter -- the heuristics seem to really work. Might as well
be completely conservative. I'm *sure* that we can afford one heap
access here -- we currently *always* visit at least one heap tuple in
roughly the same way during each and every unique index tuple insert
(not just when the page fills).
Posting list TIDs are not the only kind of TIDs that are marked
non-promising. We now also include TIDs from non-duplicate tuples. So
we're prepared to kill any of the TIDs on the page, though we only
really expect it to happen with the "promising" tuples (duplicates).
But why not be open to the possibility of killing some extra TIDs in
passing? We don't have to visit any extra heap pages to do so, so it's
practically free. Empirical evidence shows that this happens quite
often.
Here's why this posting list tuple strategy is a good one: we consider
posting list tuple TIDs non-promising to represent that we think that
there are probably actually multiple logical rows involved, or at
least to represent that they didn't work -- simple trial and error
suggests that they aren't very "promising", whatever the true reason
happens to be. But why not "keep an open mind" about the TIDs not each
being for distinct logical rows? If it just so happens that the
posting list TIDs really were multiple versions of the same logical
row all along, then there is a reasonable chance that there'll be even
more versions on that same heap page later on. When this happens and
when we end up back on the same B-Tree leaf page to think about dedup
deletion once again, it's pretty likely that we'll also naturally end
up looking into the later additional versions on this same heap page
from earlier. At which point we won't miss the opportunity to check
the posting lists TIDs in passing. So we get to delete the posting
list after all!
(If you're thinking "but we probably won't get lucky like that", then
consider that it doesn't have to happen on the next occasion when
delete deduplication happens on the same leaf page. Just at some point
in the future. This is due to the way we visit the heap pages that
look most promising first. It might take a couple of rounds of dedup
deletion to get back to the same heap page, but that's okay. The
simple heuristics proposed in the patch seem to have some really
interesting and useful consequences in practice. It's hard to quantify
how important these kinds of accidents of locality will be. I haven't
targeted this or that effect -- my heuristics are dead simple, and
based almost entirely on keeping costs down. You can think of it as
"increase the number of TIDs to increase our chances of success" if
you prefer.)
The life cycle of logical rows/heap tuples seems to naturally lead to
these kinds of opportunities. Obviously heapam is naturally very keen
on storing related versions on the same heap block already, without
any input from this patch. The patch is still evolving, and the
overall structure and interface certainly still needs work -- I've
focussed on the algorithm so far. I could really use some feedback on
high level direction, though. It's a relatively short patch, even with
all of my README commentary. But...it's not an easy concept to digest.
Note: I'm not really sure if it's necessary to provide specialized
qsort routines for the sorting we do to lists of TIDs, etc. I did do
some experimentation with that, and it's an open question. So for now
I rely on the patch that Thomas Munro posted to do that a little while
back, which is why that's included here. The question of whether this
is truly needed is unsettled.
--
Peter Geoghegan
Attachments:
[application/x-patch] v4-0001-Add-sort_template.h-for-making-fast-sort-function.patch (13.7K, ../../CAH2-WzmUAf=MSWxh28xV_veWiOmn-fmUPLbfhqX=t+RG6X9kbg@mail.gmail.com/2-v4-0001-Add-sort_template.h-for-making-fast-sort-function.patch)
download | inline diff:
From dbd44a9982b772e751f5da9630a4151794131380 Mon Sep 17 00:00:00 2001
From: Thomas Munro <[email protected]>
Date: Mon, 17 Aug 2020 21:31:56 +1200
Subject: [PATCH v4 1/2] Add sort_template.h for making fast sort functions.
Move our qsort implementation into a header that can be used to
define specialized functions for better performance.
Discussion: https://postgr.es/m/CA%2BhUKGKMQFVpjr106gRhwk6R-nXv0qOcTreZuQzxgpHESAL6dw%40mail.gmail.com
---
src/include/lib/sort_template.h | 428 ++++++++++++++++++++++++++++++++
1 file changed, 428 insertions(+)
create mode 100644 src/include/lib/sort_template.h
diff --git a/src/include/lib/sort_template.h b/src/include/lib/sort_template.h
new file mode 100644
index 0000000000..a279bcf959
--- /dev/null
+++ b/src/include/lib/sort_template.h
@@ -0,0 +1,428 @@
+/*-------------------------------------------------------------------------
+ *
+ * sort_template.h
+ *
+ * A template for a sort algorithm that supports varying degrees of
+ * specialization.
+ *
+ * Copyright (c) 2020, PostgreSQL Global Development Group
+ *
+ * Usage notes:
+ *
+ * To generate functions specialized for a type, the following parameter
+ * macros should be #define'd before this file is included.
+ *
+ * - ST_SORT - the name of a sort function to be generated
+ * - ST_ELEMENT_TYPE - type of the referenced elements
+ * - ST_DECLARE - if defined the functions and types are declared
+ * - ST_DEFINE - if defined the functions and types are defined
+ * - ST_SCOPE - scope (e.g. extern, static inline) for functions
+ *
+ * Instead of ST_ELEMENT_TYPE, ST_ELEMENT_TYPE_VOID can be defined. Then
+ * the generated functions will automatically gain an "element_size"
+ * parameter. This allows us to generate a traditional qsort function.
+ *
+ * One of the following macros must be defined, to show how to compare
+ * elements. The first two options are arbitrary expressions depending
+ * on whether an extra pass-through argument is desired, and the third
+ * option should be defined if the sort function should receive a
+ * function pointer at runtime.
+ *
+ * - ST_COMPARE(a, b) - a simple comparison expression
+ * - ST_COMPARE(a, b, arg) - variant that takes an extra argument
+ * - ST_COMPARE_RUNTIME_POINTER - sort function takes a function pointer
+ *
+ * To say that the comparator and therefore also sort function should
+ * receive an extra pass-through argument, specify the type of the
+ * argument.
+ *
+ * - ST_COMPARE_ARG_TYPE - type of extra argument
+ *
+ * The prototype of the generated sort function is:
+ *
+ * void ST_SORT(ST_ELEMENT_TYPE *data, size_t n,
+ * [size_t element_size,]
+ * [ST_SORT_compare_function compare,]
+ * [ST_COMPARE_ARG_TYPE *arg]);
+ *
+ * ST_SORT_compare_function is a function pointer of the following type:
+ *
+ * int (*)(const ST_ELEMENT_TYPE *a, const ST_ELEMENT_TYPE *b,
+ * [ST_COMPARE_ARG_TYPE *arg])
+ *
+ * HISTORY
+ *
+ * Modifications from vanilla NetBSD source:
+ * - Add do ... while() macro fix
+ * - Remove __inline, _DIAGASSERTs, __P
+ * - Remove ill-considered "swap_cnt" switch to insertion sort, in favor
+ * of a simple check for presorted input.
+ * - Take care to recurse on the smaller partition, to bound stack usage
+ * - Convert into a header that can generate specialized functions
+ *
+ * IDENTIFICATION
+ * src/include/lib/sort_template.h
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/* $NetBSD: qsort.c,v 1.13 2003/08/07 16:43:42 agc Exp $ */
+
+/*-
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Qsort routine based on J. L. Bentley and M. D. McIlroy,
+ * "Engineering a sort function",
+ * Software--Practice and Experience 23 (1993) 1249-1265.
+ *
+ * We have modified their original by adding a check for already-sorted
+ * input, which seems to be a win per discussions on pgsql-hackers around
+ * 2006-03-21.
+ *
+ * Also, we recurse on the smaller partition and iterate on the larger one,
+ * which ensures we cannot recurse more than log(N) levels (since the
+ * partition recursed to is surely no more than half of the input). Bentley
+ * and McIlroy explicitly rejected doing this on the grounds that it's "not
+ * worth the effort", but we have seen crashes in the field due to stack
+ * overrun, so that judgment seems wrong.
+ */
+
+#define ST_MAKE_PREFIX(a) CppConcat(a,_)
+#define ST_MAKE_NAME(a,b) ST_MAKE_NAME_(ST_MAKE_PREFIX(a),b)
+#define ST_MAKE_NAME_(a,b) CppConcat(a,b)
+
+/*
+ * If the element type is void, we'll also need an element_size argument
+ * because we don't know the size.
+ */
+#ifdef ST_ELEMENT_TYPE_VOID
+#define ST_ELEMENT_TYPE void
+#define ST_SORT_PROTO_SIZE , size_t element_size
+#define ST_SORT_INVOKE_SIZE , element_size
+#else
+#define ST_SORT_PROTO_SIZE
+#define ST_SORT_INVOKE_SIZE
+#endif
+
+/*
+ * If the user wants to be able to pass in compare functions at runtime,
+ * we'll need to make that an argument of the sort and med3 functions.
+ */
+#ifdef ST_COMPARE_RUNTIME_POINTER
+/*
+ * The type of the comparator function pointer that ST_SORT will take, unless
+ * you've already declared a type name manually and want to use that instead of
+ * having a new one defined.
+ */
+#ifndef ST_COMPARATOR_TYPE_NAME
+#define ST_COMPARATOR_TYPE_NAME ST_MAKE_NAME(ST_SORT, compare_function)
+#endif
+#define ST_COMPARE compare
+#ifndef ST_COMPARE_ARG_TYPE
+#define ST_SORT_PROTO_COMPARE , ST_COMPARATOR_TYPE_NAME compare
+#define ST_SORT_INVOKE_COMPARE , compare
+#else
+#define ST_SORT_PROTO_COMPARE , ST_COMPARATOR_TYPE_NAME compare
+#define ST_SORT_INVOKE_COMPARE , compare
+#endif
+#else
+#define ST_SORT_PROTO_COMPARE
+#define ST_SORT_INVOKE_COMPARE
+#endif
+
+/*
+ * If the user wants to use a compare function or expression that takes an
+ * extra argument, we'll need to make that an argument of the sort, compare and
+ * med3 functions.
+ */
+#ifdef ST_COMPARE_ARG_TYPE
+#define ST_SORT_PROTO_ARG , ST_COMPARE_ARG_TYPE *arg
+#define ST_SORT_INVOKE_ARG , arg
+#else
+#define ST_SORT_PROTO_ARG
+#define ST_SORT_INVOKE_ARG
+#endif
+
+#ifdef ST_DECLARE
+
+#ifdef ST_COMPARE_RUNTIME_POINTER
+typedef int (*ST_COMPARATOR_TYPE_NAME)(const ST_ELEMENT_TYPE *,
+ const ST_ELEMENT_TYPE *
+ ST_SORT_PROTO_ARG);
+#endif
+
+/* Declare the sort function. Note optional arguments at end. */
+ST_SCOPE void ST_SORT(ST_ELEMENT_TYPE *first, size_t n
+ ST_SORT_PROTO_SIZE
+ ST_SORT_PROTO_COMPARE
+ ST_SORT_PROTO_ARG);
+
+#endif
+
+#ifdef ST_DEFINE
+
+/* sort private helper functions */
+#define ST_MED3 ST_MAKE_NAME(ST_SORT, med3)
+#define ST_SWAP ST_MAKE_NAME(ST_SORT, swap)
+#define ST_SWAPN ST_MAKE_NAME(ST_SORT, swapn)
+
+/* Users expecting to run very large sorts may need them to be interruptible. */
+#ifdef ST_CHECK_FOR_INTERRUPTS
+#define DO_CHECK_FOR_INTERRUPTS() CHECK_FOR_INTERRUPTS()
+#else
+#define DO_CHECK_FOR_INTERRUPTS()
+#endif
+
+/*
+ * Create wrapper macros that know how to invoke compare, med3 and sort with
+ * the right arguments.
+ */
+#ifdef ST_COMPARE_RUNTIME_POINTER
+#define DO_COMPARE(a_, b_) ST_COMPARE((a_), (b_) ST_SORT_INVOKE_ARG)
+#elif defined(ST_COMPARE_ARG_TYPE)
+#define DO_COMPARE(a_, b_) ST_COMPARE((a_), (b_), arg)
+#else
+#define DO_COMPARE(a_, b_) ST_COMPARE((a_), (b_))
+#endif
+#define DO_MED3(a_, b_, c_) \
+ ST_MED3((a_), (b_), (c_) \
+ ST_SORT_INVOKE_COMPARE \
+ ST_SORT_INVOKE_ARG)
+#define DO_SORT(a_, n_) \
+ ST_SORT((a_), (n_) \
+ ST_SORT_INVOKE_SIZE \
+ ST_SORT_INVOKE_COMPARE \
+ ST_SORT_INVOKE_ARG)
+
+/*
+ * If we're working with void pointers, we'll use pointer arithmetic based on
+ * uint8, and use the runtime element_size to step through the array and swap
+ * elements. Otherwise we'll work with ST_ELEMENT_TYPE.
+ */
+#ifndef ST_ELEMENT_TYPE_VOID
+#define ST_POINTER_TYPE ST_ELEMENT_TYPE
+#define ST_POINTER_STEP 1
+#define DO_SWAPN(a_, b_, n_) ST_SWAPN((a_), (b_), (n_))
+#define DO_SWAP(a_, b_) ST_SWAP((a_), (b_))
+#else
+#define ST_POINTER_TYPE uint8
+#define ST_POINTER_STEP element_size
+#define DO_SWAPN(a_, b_, n_) ST_SWAPN((a_), (b_), (n_))
+#define DO_SWAP(a_, b_) DO_SWAPN((a_), (b_), element_size)
+#endif
+
+/*
+ * Find the median of three values. Currently, performance seems to be best
+ * if the the comparator is inlined here, but the med3 function is not inlined
+ * in the qsort function.
+ */
+static pg_noinline ST_ELEMENT_TYPE *
+ST_MED3(ST_ELEMENT_TYPE *a,
+ ST_ELEMENT_TYPE *b,
+ ST_ELEMENT_TYPE *c
+ ST_SORT_PROTO_COMPARE
+ ST_SORT_PROTO_ARG)
+{
+ return DO_COMPARE(a, b) < 0 ?
+ (DO_COMPARE(b, c) < 0 ? b : (DO_COMPARE(a, c) < 0 ? c : a))
+ : (DO_COMPARE(b, c) > 0 ? b : (DO_COMPARE(a, c) < 0 ? a : c));
+}
+
+static inline void
+ST_SWAP(ST_POINTER_TYPE *a, ST_POINTER_TYPE *b)
+{
+ ST_POINTER_TYPE tmp = *a;
+
+ *a = *b;
+ *b = tmp;
+}
+
+static inline void
+ST_SWAPN(ST_POINTER_TYPE *a, ST_POINTER_TYPE *b, size_t n)
+{
+ for (size_t i = 0; i < n; ++i)
+ ST_SWAP(&a[i], &b[i]);
+}
+
+/*
+ * Sort an array.
+ */
+ST_SCOPE void
+ST_SORT(ST_ELEMENT_TYPE *data, size_t n
+ ST_SORT_PROTO_SIZE
+ ST_SORT_PROTO_COMPARE
+ ST_SORT_PROTO_ARG)
+{
+ ST_POINTER_TYPE *a = (ST_POINTER_TYPE *) data,
+ *pa,
+ *pb,
+ *pc,
+ *pd,
+ *pl,
+ *pm,
+ *pn;
+ size_t d1,
+ d2;
+ int r,
+ presorted;
+
+loop:
+ DO_CHECK_FOR_INTERRUPTS();
+ if (n < 7)
+ {
+ for (pm = a + ST_POINTER_STEP; pm < a + n * ST_POINTER_STEP;
+ pm += ST_POINTER_STEP)
+ for (pl = pm; pl > a && DO_COMPARE(pl - ST_POINTER_STEP, pl) > 0;
+ pl -= ST_POINTER_STEP)
+ DO_SWAP(pl, pl - ST_POINTER_STEP);
+ return;
+ }
+ presorted = 1;
+ for (pm = a + ST_POINTER_STEP; pm < a + n * ST_POINTER_STEP;
+ pm += ST_POINTER_STEP)
+ {
+ DO_CHECK_FOR_INTERRUPTS();
+ if (DO_COMPARE(pm - ST_POINTER_STEP, pm) > 0)
+ {
+ presorted = 0;
+ break;
+ }
+ }
+ if (presorted)
+ return;
+ pm = a + (n / 2) * ST_POINTER_STEP;
+ if (n > 7)
+ {
+ pl = a;
+ pn = a + (n - 1) * ST_POINTER_STEP;
+ if (n > 40)
+ {
+ size_t d = (n / 8) * ST_POINTER_STEP;
+
+ pl = DO_MED3(pl, pl + d, pl + 2 * d);
+ pm = DO_MED3(pm - d, pm, pm + d);
+ pn = DO_MED3(pn - 2 * d, pn - d, pn);
+ }
+ pm = DO_MED3(pl, pm, pn);
+ }
+ DO_SWAP(a, pm);
+ pa = pb = a + ST_POINTER_STEP;
+ pc = pd = a + (n - 1) * ST_POINTER_STEP;
+ for (;;)
+ {
+ while (pb <= pc && (r = DO_COMPARE(pb, a)) <= 0)
+ {
+ if (r == 0)
+ {
+ DO_SWAP(pa, pb);
+ pa += ST_POINTER_STEP;
+ }
+ pb += ST_POINTER_STEP;
+ DO_CHECK_FOR_INTERRUPTS();
+ }
+ while (pb <= pc && (r = DO_COMPARE(pc, a)) >= 0)
+ {
+ if (r == 0)
+ {
+ DO_SWAP(pc, pd);
+ pd -= ST_POINTER_STEP;
+ }
+ pc -= ST_POINTER_STEP;
+ DO_CHECK_FOR_INTERRUPTS();
+ }
+ if (pb > pc)
+ break;
+ DO_SWAP(pb, pc);
+ pb += ST_POINTER_STEP;
+ pc -= ST_POINTER_STEP;
+ }
+ pn = a + n * ST_POINTER_STEP;
+ d1 = Min(pa - a, pb - pa);
+ DO_SWAPN(a, pb - d1, d1);
+ d1 = Min(pd - pc, pn - pd - ST_POINTER_STEP);
+ DO_SWAPN(pb, pn - d1, d1);
+ d1 = pb - pa;
+ d2 = pd - pc;
+ if (d1 <= d2)
+ {
+ /* Recurse on left partition, then iterate on right partition */
+ if (d1 > ST_POINTER_STEP)
+ DO_SORT(a, d1 / ST_POINTER_STEP);
+ if (d2 > ST_POINTER_STEP)
+ {
+ /* Iterate rather than recurse to save stack space */
+ /* DO_SORT(pn - d2, d2 / ST_POINTER_STEP) */
+ a = pn - d2;
+ n = d2 / ST_POINTER_STEP;
+ goto loop;
+ }
+ }
+ else
+ {
+ /* Recurse on right partition, then iterate on left partition */
+ if (d2 > ST_POINTER_STEP)
+ DO_SORT(pn - d2, d2 / ST_POINTER_STEP);
+ if (d1 > ST_POINTER_STEP)
+ {
+ /* Iterate rather than recurse to save stack space */
+ /* DO_SORT(a, d1 / ST_POINTER_STEP) */
+ n = d1 / ST_POINTER_STEP;
+ goto loop;
+ }
+ }
+}
+#endif
+
+#undef DO_COMPARE
+#undef DO_MED3
+#undef DO_SORT
+#undef DO_SWAP
+#undef DO_SWAPN
+#undef ST_COMPARATOR_TYPE_NAME
+#undef ST_COMPARE
+#undef ST_COMPARE_ARG_TYPE
+#undef ST_COMPARE_RUNTIME_POINTER
+#undef ST_ELEMENT_TYPE
+#undef ST_ELEMENT_TYPE_VOID
+#undef ST_MAKE_NAME
+#undef ST_MAKE_NAME_
+#undef ST_MAKE_PREFIX
+#undef ST_MED3
+#undef ST_POINTER_STEP
+#undef ST_POINTER_TYPE
+#undef ST_SORT
+#undef ST_SORT_INVOKE_ARG
+#undef ST_SORT_INVOKE_COMPARE
+#undef ST_SORT_INVOKE_SIZE
+#undef ST_SORT_PROTO_ARG
+#undef ST_SORT_PROTO_COMPARE
+#undef ST_SORT_PROTO_SIZE
+#undef ST_SWAP
+#undef ST_SWAPN
--
2.25.1
[application/x-patch] v4-0002-Add-delete-deduplication-to-nbtree.patch (63.1K, ../../CAH2-WzmUAf=MSWxh28xV_veWiOmn-fmUPLbfhqX=t+RG6X9kbg@mail.gmail.com/3-v4-0002-Add-delete-deduplication-to-nbtree.patch)
download | inline diff:
From 96e78aa55eaae66e8efec4fb528f851977e71c1d Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Tue, 30 Jun 2020 16:29:27 -0700
Subject: [PATCH v4 2/2] Add delete deduplication to nbtree.
Repurpose deduplication infrastructure to delete items in indexes at the
point where we'd usually have to split the page, even when they don't
have their LP_DEAD bits set. Testing has shown that this is almost
completely effective at preventing "version index bloat" from non-HOT
updates, provided there are no long running transactions.
This is primarily valuable with leaf pages that contain mostly-distinct
index tuples, particularly with unique indexes. It is intended to
complement deduplication. Heuristics are used to guess which index
tuples are likely to point to no longer needed old table row versions.
Note that INCLUDE indexes support the optimization.
---
src/include/access/genam.h | 15 +
src/include/access/heapam.h | 3 +-
src/include/access/nbtree.h | 5 +-
src/include/access/tableam.h | 44 +-
src/include/executor/executor.h | 3 +-
src/backend/access/heap/heapam.c | 12 +-
src/backend/access/heap/heapam_handler.c | 5 +-
src/backend/access/nbtree/README | 70 ++-
src/backend/access/nbtree/nbtdedup.c | 566 +++++++++++++++++++++--
src/backend/access/nbtree/nbtinsert.c | 41 +-
src/backend/access/nbtree/nbtsort.c | 12 +-
src/backend/access/nbtree/nbtxlog.c | 4 +-
src/backend/access/table/tableam.c | 299 +++++++++++-
src/backend/commands/copy.c | 5 +-
src/backend/executor/execIndexing.c | 41 +-
src/backend/executor/execReplication.c | 4 +-
src/backend/executor/nodeModifyTable.c | 14 +-
17 files changed, 1063 insertions(+), 80 deletions(-)
diff --git a/src/include/access/genam.h b/src/include/access/genam.h
index 68d90f5141..7002da0716 100644
--- a/src/include/access/genam.h
+++ b/src/include/access/genam.h
@@ -108,10 +108,25 @@ typedef struct ParallelIndexScanDescData *ParallelIndexScanDesc;
* call is made with UNIQUE_CHECK_EXISTING. The tuple is already in the
* index in this case, so it should not be inserted again. Rather, just
* check for conflicting live tuples (possibly blocking).
+ *
+ * UNIQUE_CHECK_NO indicates the absence of any unique checking.
+ * UNIQUE_CHECK_NO_WITH_UNCHANGED is a variant of UNIQUE_CHECK_NO that
+ * indicates that the index tuple comes from an UPDATE that did not modify
+ * the row in respect of any columns that are indexed. The implementation
+ * requires a successor version, but there is no logical change. Some
+ * index access AMs can use this as hint that can trigger optimizations.
+ *
+ * XXX: Adding UNIQUE_CHECK_NO_WITH_UNCHANGED like this kind of makes
+ * sense, since it's pretty natural to leave it up to index AMs to figure
+ * it out with unique indexes. But what about when we insert NULLs into a
+ * unique index? Isn't that case UNIQUE_CHECK_YES, and yet also a thing
+ * that nbtree pretty much treats as UNIQUE_CHECK_NO once it sees that the
+ * index tuple has NULLs?
*/
typedef enum IndexUniqueCheck
{
UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */
+ UNIQUE_CHECK_NO_WITH_UNCHANGED, /* "No logical change" duplicate */
UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */
UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */
UNIQUE_CHECK_EXISTING /* Check if existing tuple is unique */
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 92b19dba32..d950083a7d 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -148,7 +148,8 @@ extern void heap_abort_speculative(Relation relation, ItemPointer tid);
extern TM_Result heap_update(Relation relation, ItemPointer otid,
HeapTuple newtup,
CommandId cid, Snapshot crosscheck, bool wait,
- struct TM_FailureData *tmfd, LockTupleMode *lockmode);
+ struct TM_FailureData *tmfd, LockTupleMode *lockmode,
+ Bitmapset **modified_attrs_hint);
extern TM_Result heap_lock_tuple(Relation relation, HeapTuple tuple,
CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy,
bool follow_update,
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index 65d9698b89..05956c8868 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -1029,11 +1029,12 @@ extern void _bt_parallel_advance_array_keys(IndexScanDesc scan);
*/
extern void _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
IndexTuple newitem, Size newitemsz,
- bool checkingunique);
+ bool checkingunique, bool dedupdelete,
+ bool allequalimage);
extern void _bt_dedup_start_pending(BTDedupState state, IndexTuple base,
OffsetNumber baseoff);
extern bool _bt_dedup_save_htid(BTDedupState state, IndexTuple itup);
-extern Size _bt_dedup_finish_pending(Page newpage, BTDedupState state);
+extern Size _bt_dedup_merge_finish_pending(Page newpage, BTDedupState state);
extern IndexTuple _bt_form_posting(IndexTuple base, ItemPointer htids,
int nhtids);
extern void _bt_update_posting(BTVacuumPosting vacposting);
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 387eb34a61..8fc41d950f 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -128,6 +128,18 @@ typedef struct TM_FailureData
bool traversed;
} TM_FailureData;
+/*
+ * State used by table_index_batch_check() to perform "bottom up" deletion of
+ * duplicate index tuples
+ */
+typedef struct TM_IndexDelete
+{
+ ItemPointerData tid; /* table TID from index tuple */
+ OffsetNumber ioffnum; /* Index am identifies entries with this */
+ bool ispromising; /* Contribute to order we visit table blocks? */
+ bool isdead; /* Was tuple found dead? */
+} TM_IndexDelete;
+
/* "options" flag bits for table_tuple_insert */
/* TABLE_INSERT_SKIP_WAL was 0x0001; RelationNeedsWAL() now governs */
#define TABLE_INSERT_SKIP_FSM 0x0002
@@ -396,7 +408,8 @@ typedef struct TableAmRoutine
bool wait,
TM_FailureData *tmfd,
LockTupleMode *lockmode,
- bool *update_indexes);
+ bool *update_indexes,
+ Bitmapset **modified_attrs_hint);
/* see table_tuple_lock() for reference about parameters */
TM_Result (*tuple_lock) (Relation rel,
@@ -1041,16 +1054,32 @@ table_index_fetch_tuple(struct IndexFetchTableData *scan,
}
/*
- * This is a convenience wrapper around table_index_fetch_tuple() which
- * returns whether there are table tuple items corresponding to an index
- * entry. This likely is only useful to verify if there's a conflict in a
- * unique index.
+ * These are convenience wrappers around table_index_fetch_tuple() which
+ * indicate whether there are table tuple items corresponding to an index
+ * entry. Can be used to verify if there's a conflict in a unique index.
+ *
+ * table_index_batch_check() is a variant that is specialized to garbage
+ * collection of dead tuples in index access methods. Duplicates are
+ * commonly caused by MVCC version churn when an optimization like
+ * heapam's HOT cannot be applied. It can make sense to opportunistically
+ * guess that many index tuples are dead versions, particularly in unique
+ * indexes.
+ *
+ * Note that table_index_batch_check() sorts the deltids array so that the
+ * order of access is optimized. Callers need to be able to deal with
+ * that.
*/
extern bool table_index_fetch_tuple_check(Relation rel,
ItemPointer tid,
Snapshot snapshot,
bool *all_dead);
+extern int table_index_batch_check(Relation rel,
+ TM_IndexDelete *deltids,
+ int ndeltids,
+ Snapshot snapshot,
+ int npromisingkillsneeded,
+ int *nblocksaccessed);
/* ------------------------------------------------------------------------
* Functions for non-modifying operations on individual tuples
@@ -1311,12 +1340,13 @@ static inline TM_Result
table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot,
CommandId cid, Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode,
- bool *update_indexes)
+ bool *update_indexes, Bitmapset **modified_attrs_hint)
{
return rel->rd_tableam->tuple_update(rel, otid, slot,
cid, snapshot, crosscheck,
wait, tmfd,
- lockmode, update_indexes);
+ lockmode, update_indexes,
+ modified_attrs_hint);
}
/*
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h
index b7978cd22e..f056a7b124 100644
--- a/src/include/executor/executor.h
+++ b/src/include/executor/executor.h
@@ -579,7 +579,8 @@ extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
extern List *ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot, EState *estate,
bool noDupErr,
- bool *specConflict, List *arbiterIndexes);
+ bool *specConflict, List *arbiterIndexes,
+ Bitmapset *modified_attrs_hint);
extern bool ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot,
EState *estate, ItemPointer conflictTid,
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 1585861a02..fa7ca33289 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2892,7 +2892,8 @@ simple_heap_delete(Relation relation, ItemPointer tid)
TM_Result
heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
CommandId cid, Snapshot crosscheck, bool wait,
- TM_FailureData *tmfd, LockTupleMode *lockmode)
+ TM_FailureData *tmfd, LockTupleMode *lockmode,
+ Bitmapset **modified_attrs_hint)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -3758,10 +3759,15 @@ l2:
if (old_key_tuple != NULL && old_key_copied)
heap_freetuple(old_key_tuple);
+ /* Save for no logical changes hint when non-HOT update performed */
+ if (!use_hot_update && modified_attrs_hint)
+ *modified_attrs_hint = modified_attrs;
+ else
+ bms_free(modified_attrs);
+
bms_free(hot_attrs);
bms_free(key_attrs);
bms_free(id_attrs);
- bms_free(modified_attrs);
bms_free(interesting_attrs);
return TM_Ok;
@@ -3891,7 +3897,7 @@ simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
result = heap_update(relation, otid, tup,
GetCurrentCommandId(true), InvalidSnapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode);
+ &tmfd, &lockmode, NULL);
switch (result)
{
case TM_SelfModified:
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index dcaea7135f..f32ed0a5f2 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -314,7 +314,8 @@ static TM_Result
heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
CommandId cid, Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
- LockTupleMode *lockmode, bool *update_indexes)
+ LockTupleMode *lockmode, bool *update_indexes,
+ Bitmapset **modified_attrs_hint)
{
bool shouldFree = true;
HeapTuple tuple = ExecFetchSlotHeapTuple(slot, true, &shouldFree);
@@ -325,7 +326,7 @@ heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
tuple->t_tableOid = slot->tts_tableOid;
result = heap_update(relation, otid, tuple, cid, crosscheck, wait,
- tmfd, lockmode);
+ tmfd, lockmode, modified_attrs_hint);
ItemPointerCopy(&tuple->t_self, &slot->tts_tid);
/*
diff --git a/src/backend/access/nbtree/README b/src/backend/access/nbtree/README
index 9692e4cdf6..8560c5f6c3 100644
--- a/src/backend/access/nbtree/README
+++ b/src/backend/access/nbtree/README
@@ -807,7 +807,75 @@ Deduplication in unique indexes helps to prevent these pathological page
splits. Storing duplicates in a space efficient manner is not the goal,
since in the long run there won't be any duplicates anyway. Rather, we're
buying time for standard garbage collection mechanisms to run before a
-page split is needed.
+page split is needed. Also, the deduplication pass performs a targeted
+form of opportunistic deletion for unique indexes with version churn
+duplicates, as well as in cases where an UPDATE statement did not
+logically modify any indexed column, but nevertheless requires a successor
+index tuple. The latter case happens when tableam optimizations such as
+heapam's HOT cannot be applied. (We don't want to distinguish between
+version churn from UPDATEs and version churn from related INSERTs and
+DELETEs within a unique index.)
+
+The deduplication module usually opportunistically deletes whatever
+duplicates happen to be present on the page before moving on to
+deduplication proper, since in general some duplicates are likely to
+already be dead to everybody. This mechanism is quite similar to
+on-the-fly deletion of index tuples that will already have failed to
+prevent a page split by the time deduplication is considered. The main
+difference is that the tuples that get deleted are not opportunistically
+marked LP_DEAD by transactions that had to read the tuples in any case.
+
+The implementation must weigh the need to avoid a page split against the
+extra work performed with an exclusive buffer lock held. It's possible to
+make this trade-off sensibly despite the uncertainty about versioning and
+update chains within nbtree. In a unique index it's clear that there can
+only be one most recent committed version for any given value, which makes
+it certain that we'll delete some of the old versions --- at least in the
+absence of either a long running transaction that holds back the xmin
+horizon, and barring extreme churn concentrated in one part of the key
+space.
+
+Deduplication-deletion in non-unique indexes is trickier (the
+implementation is almost the same, but the justification is more
+complicated). In general there is nothing that assures us that there
+cannot be many logical rows that all have the same value in respect of an
+indexed column, which will cause us to waste time trying to find "old dead
+versions" among the duplicates that are actually distinct logical rows.
+We assume that all indexes work more or less like a unique index. This
+works better than you'd think. We at least know that there is some chance
+of UPDATE version churn in affected pages; the tuple we're trying to
+insert on the page at the point that this happens certainly originated
+that way, so there is a good chance that the same is true of existing,
+committed tuples. We're only willing to access a small number of
+heap/table pages to determine if our guess is correct, so if we're totally
+wrong then we'll have accessed no more than 2 or so heap/table pages.
+Finally, and perhaps most importantly, we'll learn from our mistake. The
+natural consequence of failing to deduplicate-delete is to do a
+deduplicate-merge pass. That will merge together the duplicate index
+tuples -- we surmise that these correspond to multiple extant logical
+rows. If and when there is another deduplication-delete pass on the same
+page, we'll skip over the posting list tuple.
+
+A posting list tuple may not actually point to one distinct logical row
+per TID, of course. Even when our inference is totally wrong it still
+seems like a good idea to skip posting lists like this. In general, the
+deduplication-deletion algorithm aims to maximize the chances of deleting
+_some_ tuples, while paying only a low fixed cost to access visibility
+information from the table. In general it's possible that deleting just
+one or two index tuples will buy us many hours or days before the question
+of splitting the same leaf page comes up again -- and VACUUM may well
+visit the page in that time anyway. If there really is intense pressure
+against the page, with many deduplication-delete passes occurring only
+milliseconds apart, then a version-driven page split is practically
+guaranteed to occur before long. This resolves the situation.
+
+Negative feedback (such as failing to dedup-delete any tuples) is not
+really undesirable. At worst it is an unavoidable part of how the
+algorithm works. We require that our various approaches to handling an
+overflowing page (due partially or entirely to version churn) compete to
+determine how best to handle the problem in a localized fashion. We
+expect to converge on a stable and roughly optimal behavior at each part
+of the key space in each index affected by version churn.
Unique index leaf pages only get a deduplication pass when an insertion
(that might have to split the page) observed an existing duplicate on the
diff --git a/src/backend/access/nbtree/nbtdedup.c b/src/backend/access/nbtree/nbtdedup.c
index f6be865b17..2c6e5740bc 100644
--- a/src/backend/access/nbtree/nbtdedup.c
+++ b/src/backend/access/nbtree/nbtdedup.c
@@ -16,13 +16,25 @@
#include "access/nbtree.h"
#include "access/nbtxlog.h"
+#include "access/tableam.h"
#include "miscadmin.h"
#include "utils/rel.h"
+static bool _bt_dedup_delete_pass(Relation rel, Buffer buf,
+ Relation heapRel, Size newitemsz,
+ bool *merge);
+static void _bt_dedup_merge_pass(Relation rel, Buffer buf,
+ Relation heapRel, IndexTuple newitem,
+ Size newitemsz, bool checkingunique);
+static void _bt_dedup_delete_finish_pending(BTDedupState state,
+ TM_IndexDelete *deltids,
+ int *ndeltids);
static bool _bt_do_singleval(Relation rel, Page page, BTDedupState state,
OffsetNumber minoff, IndexTuple newitem);
static void _bt_singleval_fillfactor(Page page, BTDedupState state,
Size newitemsz);
+static inline int _bt_indexdelete_cmp(TM_IndexDelete *indexdelete1,
+ TM_IndexDelete *indexdelete2);
#ifdef USE_ASSERT_CHECKING
static bool _bt_posting_valid(IndexTuple posting);
#endif
@@ -32,16 +44,12 @@ static bool _bt_posting_valid(IndexTuple posting);
* if we cannot successfully free at least newitemsz (we also need space for
* newitem's line pointer, which isn't included in caller's newitemsz).
*
- * The general approach taken here is to perform as much deduplication as
- * possible to free as much space as possible. Note, however, that "single
- * value" strategy is sometimes used for !checkingunique callers, in which
- * case deduplication will leave a few tuples untouched at the end of the
- * page. The general idea is to prepare the page for an anticipated page
- * split that uses nbtsplitloc.c's "single value" strategy to determine a
- * split point. (There is no reason to deduplicate items that will end up on
- * the right half of the page after the anticipated page split; better to
- * handle those if and when the anticipated right half page gets its own
- * deduplication pass, following further inserts of duplicates.)
+ * There are two types of deduplication pass: The merge deduplication pass,
+ * where we merge together duplicate index tuples into a new posting list, and
+ * the delete deduplication pass, where old garbage version index tuples are
+ * deleted based on visibility information that we fetch from the table. We
+ * generally expect to perform only one type of deduplication pass per call
+ * here, but it's possible that we'll end up doing both.
*
* This function should be called during insertion, when the page doesn't have
* enough space to fit an incoming newitem. If the BTP_HAS_GARBAGE page flag
@@ -54,27 +62,23 @@ static bool _bt_posting_valid(IndexTuple posting);
*/
void
_bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
- IndexTuple newitem, Size newitemsz, bool checkingunique)
+ IndexTuple newitem, Size newitemsz, bool checkingunique,
+ bool dedupdelete, bool allequalimage)
{
OffsetNumber offnum,
minoff,
maxoff;
Page page = BufferGetPage(buf);
BTPageOpaque opaque;
- Page newpage;
OffsetNumber deletable[MaxIndexTuplesPerPage];
- BTDedupState state;
int ndeletable = 0;
- Size pagesaving = 0;
- bool singlevalstrat = false;
- int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
/*
* We can't assume that there are no LP_DEAD items. For one thing, VACUUM
* will clear the BTP_HAS_GARBAGE hint without reliably removing items
* that are marked LP_DEAD. We don't want to unnecessarily unset LP_DEAD
- * bits when deduplicating items. Allowing it would be correct, though
- * wasteful.
+ * bits when deduplicating items by merging. Allowing it would be
+ * correct, though wasteful.
*/
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
minoff = P_FIRSTDATAKEY(opaque);
@@ -99,18 +103,417 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
*/
if (PageGetFreeSpace(page) >= newitemsz)
return;
-
- /*
- * Reconsider number of items on page, in case _bt_delitems_delete()
- * managed to delete an item or two
- */
- minoff = P_FIRSTDATAKEY(opaque);
- maxoff = PageGetMaxOffsetNumber(page);
}
+ minoff = maxoff = InvalidOffsetNumber; /* Invalidate */
+
+ /*
+ * We're willing to do dedup deletion with a unique index that is not
+ * generally safe for deduplication (though only when deduplicate_items
+ * storage param is not explicitly set to 'off', which our caller checks
+ * for us).
+ *
+ * The logic used by the !checkingunique _bt_dedup_delete_pass() case
+ * relies on regular deduplication passes occurring, and merging together
+ * index entries that point to distinct logical table rows that happen to
+ * have the same key value (this might not happen immediately, but it
+ * should happen before too long). We're not willing to deduplicate when
+ * the index isn't a unique index and isn't an index that is generally
+ * safe for deduplication. Exit early if we see that.
+ */
+ if (!allequalimage && !checkingunique)
+ return;
+
/* Passed-in newitemsz is MAXALIGNED but does not include line pointer */
newitemsz += sizeof(ItemIdData);
+ if (checkingunique || dedupdelete)
+ {
+ bool merge = true;
+
+ /* Perform delete deduplication pass */
+ if (_bt_dedup_delete_pass(rel, buf, heapRel, newitemsz, &merge))
+ return;
+
+ /*
+ * _bt_dedup_delete_pass() may occasionally indicate no duplicates, in
+ * which case we should give up now
+ */
+ if (!merge)
+ return;
+
+ /* Fall back on merge deduplication. This happens infrequently. */
+ }
+
+ /*
+ * Perform merge deduplication pass, though only when index is
+ * allequalimage -- otherwise it's not safe
+ */
+ if (allequalimage)
+ _bt_dedup_merge_pass(rel, buf, heapRel, newitem, newitemsz,
+ checkingunique);
+}
+
+#define ST_SORT qsort_deltids
+#define ST_ELEMENT_TYPE TM_IndexDelete
+#define ST_COMPARE(a, b) (_bt_indexdelete_cmp(a, b))
+#define ST_SCOPE static
+#define ST_DEFINE
+#include "lib/sort_template.h"
+
+/*
+ * Perform a delete deduplication pass.
+ *
+ * See if duplicate index tuples are eligible to be deleted, even though they
+ * don't have their LP_DEAD bit set already. Give up if we have to access
+ * more than a few heap pages before we can free enough space to fit newitem.
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
+ */
+static bool
+_bt_dedup_delete_pass(Relation rel, Buffer buf, Relation heapRel,
+ Size newitemsz, bool *merge)
+{
+ OffsetNumber offnum,
+ minoff,
+ maxoff;
+ Page page = BufferGetPage(buf);
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+ BTDedupState state;
+ TM_IndexDelete *deltids;
+ int ndeltids,
+ npromisingdeltids,
+ ntableamkills,
+ ndeletable;
+ SnapshotData SnapshotNonVacuumable;
+ OffsetNumber deletable[MaxIndexTuplesPerPage];
+ int nblocksaccessed;
+ int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+
+ state = (BTDedupState) palloc(sizeof(BTDedupStateData));
+ state->deduplicate = true;
+ state->nmaxitems = 0;
+ /* Final "posting list" size should not restrict anything */
+ state->maxpostingsize = BLCKSZ;
+ state->base = NULL;
+ state->baseoff = InvalidOffsetNumber;
+ state->basetupsize = 0;
+ state->htids = palloc(state->maxpostingsize);
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+ state->nintervals = 0;
+
+ ndeltids = 0;
+ npromisingdeltids = 0;
+ deltids = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexDelete));
+
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
+ for (offnum = minoff;
+ offnum <= maxoff;
+ offnum = OffsetNumberNext(offnum))
+ {
+ ItemId itemid = PageGetItemId(page, offnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+
+ Assert(!ItemIdIsDead(itemid));
+
+ if (offnum == minoff)
+ {
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ else if (_bt_keep_natts_fast(rel, state->base, itup) > nkeyatts &&
+ _bt_dedup_save_htid(state, itup))
+ {
+
+ }
+ else
+ {
+ /* Handle interval, saving TIDs when "non-promising" */
+ _bt_dedup_delete_finish_pending(state, deltids, &ndeltids);
+
+ /* itup starts new pending interval */
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ }
+ /* Handle the final interval, saving TIDs when "non-promising" */
+ _bt_dedup_delete_finish_pending(state, deltids, &ndeltids);
+
+ if (state->nintervals == 0)
+ {
+ /* No duplicates/promising tuples, don't bother trying */
+ pfree(state->htids);
+ pfree(state);
+ pfree(deltids);
+ /* Caller should avoid deduplication-by-merging pass */
+ *merge = false;
+ return false;
+ }
+
+ /*
+ * deltids array now contains non-duplicate tuples, all of which are
+ * marked non-promising.
+ *
+ * Add known duplicates to array now by extracting them from the dedup
+ * intervals we just formed. Most of the tuples are marked promising so
+ * that the tableam infrastructure can focus its efforts there. See
+ * comment block below for a full explanation of promising tuples.
+ */
+ for (int i = 0; i < state->nintervals; i++)
+ {
+ BTDedupInterval interval = state->intervals[i];
+
+ Assert(interval.nitems > 0);
+
+ for (int j = 0; j < interval.nitems; j++)
+ {
+ OffsetNumber dupoffnum = interval.baseoff + j;
+ ItemId itemid = PageGetItemId(page, dupoffnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ /*
+ * Plain non-pivot tuple duplicate -- TID is promising
+ */
+ deltids[ndeltids].tid = itup->t_tid;
+ deltids[ndeltids].ioffnum = dupoffnum;
+ deltids[ndeltids].ispromising = true;
+ deltids[ndeltids].isdead = false; /* for now */
+ ndeltids++;
+ npromisingdeltids++;
+ }
+ else
+ {
+ /*
+ * Posting list tuple duplicate -- TIDs are not promising, but
+ * tableam might manage to delete them in passing
+ */
+ Assert(_bt_posting_valid(itup));
+
+ for (int p = 0; p < BTreeTupleGetNPosting(itup); p++)
+ {
+ ItemPointer htid = BTreeTupleGetPostingN(itup, p);
+
+ deltids[ndeltids].tid = *htid;
+ deltids[ndeltids].ioffnum = dupoffnum;
+ deltids[ndeltids].ispromising = false;
+ deltids[ndeltids].isdead = false; /* for now */
+ ndeltids++;
+ }
+ }
+ }
+ }
+
+ /* Done with dedup state */
+ pfree(state->htids);
+ pfree(state);
+
+ /*
+ * Determine which TIDs are dead in deltids array (if we have any
+ * duplicates at all, since we only really expect to find dead tuples
+ * among duplicates).
+ *
+ * We aim to delete 10 "promising" tuples in total (i.e. to delete 10
+ * non-pivot tuple duplicates that we consider promising). This is
+ * helpful when the same page receives very frequent delete deduplication
+ * passes, where it makes sense to have fewer slightly larger WAL records.
+ *
+ * You might wonder why we don't tell tableam more about our preferences
+ * (for example, we don't register a callback that figures out when
+ * tableam has found enough dead TIDs to allow us to free just enough leaf
+ * page space to avoid a page split -- even though that interface is quite
+ * feasible). Our precise preferences are unimportant because the high
+ * level design of delete deduplication assumes asymmetry: the cost of
+ * failing to delete even one tuple once per page is drastically lower
+ * than the potential upside of never having to split a page affected by
+ * version churn.
+ *
+ * Each failure to delete even one tuple here is, in effect, a learning
+ * experience. It results in caller falling back on splitting the page
+ * (or on a merge deduplication pass), discouraging future calls back here
+ * for the same page. We converge on the most effective strategy for each
+ * page in the index over time, through trial and error. We accept well
+ * understood small negative outcomes as the price of a potentially huge
+ * (though uncertain) upside. We are not interested in barely managing to
+ * avoid a page split once -- we're playing a long game.
+ *
+ * We don't mark posting list tuples as promising specifically so that
+ * cases where we have a failed delete deduplication pass followed by a
+ * successfully merge deduplication pass do not go on to waste time on
+ * posting list tuples during any future delete deduplication passes. We
+ * effectively learned our lesson about the TIDs in the posting list
+ * tuples -- all of the TIDs probably point to distinct logical rows that
+ * we have no chance of deleting. (Though even then we have some chance
+ * of getting lucky if they really were version churn tuples, since there
+ * might have been even more version churn affecting the same tableam
+ * block, which we'll try to target directly -- the non-promising posting
+ * list TIDs might well get picked up.)
+ */
+ Assert(ndeltids > 0);
+ ntableamkills = 0;
+ if (npromisingdeltids > 0)
+ {
+ InitNonVacuumableSnapshot(SnapshotNonVacuumable,
+ GlobalVisTestFor(heapRel));
+ ntableamkills = table_index_batch_check(heapRel, deltids, ndeltids,
+ &SnapshotNonVacuumable,
+ Min(10, npromisingdeltids),
+ &nblocksaccessed);
+ }
+
+ if (ntableamkills == 0)
+ {
+ pfree(deltids);
+ return false;
+ }
+
+ /*
+ * We have at least one TID to kill (though maybe not if it comes from a
+ * posting list due to the restriction on those below). Deal with that.
+ *
+ * Must first sort deltids in order expected by loop. See
+ * _bt_indexdelete_cmp().
+ */
+ qsort_deltids(deltids, ndeltids);
+ ndeletable = 0;
+ for (int i = 0; i < ndeltids; i++)
+ {
+ OffsetNumber deadoffnum = deltids[i].ioffnum;
+ ItemId itemid = PageGetItemId(page, deadoffnum);
+ IndexTuple itup;
+ bool killtuple = false;
+
+ /* Skip if not dead to tableam, or when item already marked */
+ if (!deltids[i].isdead || ItemIdIsDead(itemid))
+ continue;
+
+ /*
+ * See if we can actually delete the item. For a plain non-pivot this
+ * is trivial (we can). But we'll only delete a posting list tuple
+ * when all of its TIDs are dead.
+ *
+ * XXX: It actually wouldn't be that hard to do VACUUM-style granular
+ * posting list TID deletes here (using _bt_update_posting()). For
+ * now we don't bother with that because it's not clear if it's
+ * actually worth anything. (We really want to kill duplicate tuple
+ * groups before they can become posting list tuples in the first
+ * place.)
+ */
+ itup = (IndexTuple) PageGetItem(page, itemid);
+ if (!BTreeTupleIsPosting(itup))
+ killtuple = true;
+ else
+ {
+ ItemPointer dtid = &deltids[i].tid;
+ int pi = i + 1;
+ int nposting = BTreeTupleGetNPosting(itup);
+ int j;
+
+ Assert(_bt_posting_valid(itup));
+
+ for (j = 0; j < nposting; j++)
+ {
+ ItemPointer item = BTreeTupleGetPostingN(itup, j);
+
+ if (!ItemPointerEquals(item, dtid))
+ break; /* out of posting list loop */
+
+ /*
+ * Read-ahead to next duplicate TID here.
+ *
+ * We rely on the assumption that not advancing dtid here will
+ * prevent us from considering the posting list tuple fully
+ * dead by not matching its next table TID in next outer loop
+ * iteration.
+ *
+ * If, on the other hand, this is the final table TID in the
+ * posting list tuple, then tuple gets killed regardless (i.e.
+ * we handle the case where the last item is also the last
+ * table TID in the last index tuple correctly -- posting
+ * tuple still gets killed).
+ */
+ if (pi < ndeltids && deltids[pi].isdead)
+ dtid = &deltids[pi++].tid;
+ }
+
+ if (j == nposting)
+ killtuple = true;
+ }
+
+ if (killtuple)
+ {
+ /*
+ * Remember item as one we'll delete.
+ *
+ * No MarkBufferDirtyHint() call needed -- we'll physically delete
+ * item in a moment anyway. N.B.: We must not return before
+ * reaching _bt_delitems_delete() when we reach here even once.
+ *
+ * (Actually, we don't really need to mark the ItemId dead either,
+ * but we do so anyway because it's expected in opportunistic
+ * deletion code called below. XXX: We also rely on it being set
+ * to avoid processing a posting list tuple twice, but that should
+ * probably be fixed.)
+ */
+ ItemIdMarkDead(itemid);
+ deletable[ndeletable++] = deadoffnum;
+ }
+
+ /* Try to break out early */
+ if (ntableamkills == ndeletable)
+ break;
+ }
+
+ Assert(ntableamkills >= ndeletable);
+
+ /* Done with deltids state */
+ pfree(deltids);
+
+ if (unlikely(ndeletable == 0))
+ return false;
+
+ /* Go through with deleting items we found */
+ _bt_delitems_delete(rel, buf, deletable, ndeletable, heapRel);
+
+ /* Return success when page split (or merge deduplication pass) avoided */
+ return PageGetExactFreeSpace(page) >= newitemsz;
+}
+
+/*
+ * Perform a merge deduplication pass.
+ *
+ * The general approach taken here is to perform as much deduplication as
+ * possible to free as much space as possible. Note, however, that "single
+ * value" strategy is sometimes used for !checkingunique callers, in which
+ * case deduplication will leave a few tuples untouched at the end of the
+ * page. The general idea is to prepare the page for an anticipated page
+ * split that uses nbtsplitloc.c's "single value" strategy to determine a
+ * split point. (There is no reason to deduplicate items that will end up on
+ * the right half of the page after the anticipated page split; better to
+ * handle those if and when the anticipated right half page gets its own
+ * deduplication pass, following further inserts of duplicates.)
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
+ */
+static void
+_bt_dedup_merge_pass(Relation rel, Buffer buf, Relation heapRel,
+ IndexTuple newitem, Size newitemsz, bool checkingunique)
+{
+ OffsetNumber offnum,
+ minoff,
+ maxoff;
+ Page page = BufferGetPage(buf);
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+ Page newpage;
+ BTDedupState state;
+ Size pagesaving = 0;
+ bool singlevalstrat = false;
+ int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+
/*
* By here, it's clear that deduplication will definitely be attempted.
* Initialize deduplication state.
@@ -138,6 +541,9 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
/* nintervals should be initialized to zero */
state->nintervals = 0;
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
+
/* Determine if "single value" strategy should be used */
if (!checkingunique)
singlevalstrat = _bt_do_singleval(rel, page, state, minoff, newitem);
@@ -203,7 +609,7 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
* form new posting tuple, and actually update the page. Else
* reset the state and move on without modifying the page.
*/
- pagesaving += _bt_dedup_finish_pending(newpage, state);
+ pagesaving += _bt_dedup_merge_finish_pending(newpage, state);
if (singlevalstrat)
{
@@ -235,7 +641,7 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
}
/* Handle the last item */
- pagesaving += _bt_dedup_finish_pending(newpage, state);
+ pagesaving += _bt_dedup_merge_finish_pending(newpage, state);
/*
* If no items suitable for deduplication were found, newpage must be
@@ -317,8 +723,8 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
* Every tuple processed by deduplication either becomes the base tuple for a
* posting list, or gets its heap TID(s) accepted into a pending posting list.
* A tuple that starts out as the base tuple for a posting list will only
- * actually be rewritten within _bt_dedup_finish_pending() when it turns out
- * that there are duplicates that can be merged into the base tuple.
+ * actually be rewritten within _bt_dedup_merge_finish_pending() when it turns
+ * out that there are duplicates that can be merged into the base tuple.
*/
void
_bt_dedup_start_pending(BTDedupState state, IndexTuple base,
@@ -443,7 +849,7 @@ _bt_dedup_save_htid(BTDedupState state, IndexTuple itup)
* where no deduplication was possible.
*/
Size
-_bt_dedup_finish_pending(Page newpage, BTDedupState state)
+_bt_dedup_merge_finish_pending(Page newpage, BTDedupState state)
{
OffsetNumber tupoff;
Size tuplesz;
@@ -496,6 +902,68 @@ _bt_dedup_finish_pending(Page newpage, BTDedupState state)
return spacesaving;
}
+/*
+ * Stripped down version of _bt_dedup_merge_finish_pending() used by
+ * _bt_dedup_delete_pass().
+ *
+ * Finalize interval of duplicates (duplicate group) without materializing the
+ * would-be posting list tuple. We store all TIDs on the leaf page in the
+ * array, but only TIDs that we determine are duplicates are marked as
+ * promising. (Non-promising TIDs only get considered in passing, when they
+ * happen to be on the same table am page as promising TIDs.)
+ */
+static void
+_bt_dedup_delete_finish_pending(BTDedupState state, TM_IndexDelete *deltids,
+ int *ndeltids)
+{
+ Assert(state->nitems > 0);
+ Assert(state->nitems <= state->nhtids);
+ Assert(state->intervals[state->nintervals].baseoff == state->baseoff);
+
+ if (state->nitems == 1)
+ {
+ /* Remember non-duplicate's TID, but mark it not promising */
+ OffsetNumber offnum = state->baseoff;
+ IndexTuple itup = state->base;
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ deltids[*ndeltids].tid = itup->t_tid;
+ deltids[*ndeltids].ioffnum = offnum;
+ deltids[*ndeltids].ispromising = false;
+ deltids[*ndeltids].isdead = false; /* for now */
+ (*ndeltids)++;
+ }
+ else
+ {
+ Assert(_bt_posting_valid(itup));
+
+ for (int p = 0; p < BTreeTupleGetNPosting(itup); p++)
+ {
+ ItemPointer htid = BTreeTupleGetPostingN(itup, p);
+
+ deltids[*ndeltids].tid = *htid;
+ deltids[*ndeltids].ioffnum = offnum;
+ deltids[*ndeltids].ispromising = false;
+ deltids[*ndeltids].isdead = false; /* for now */
+ (*ndeltids)++;
+ }
+ }
+ }
+ else
+ {
+ /* Dups in interval -- store in deltids later */
+ state->intervals[state->nintervals].nitems = state->nitems;
+ /* Increment nintervals, since we wrote a new posting list tuple */
+ state->nintervals++;
+ }
+
+ /* Reset state for next pending posting list */
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+}
+
/*
* Determine if page non-pivot tuples (data items) are all duplicates of the
* same value -- if they are, deduplication's "single value" strategy should
@@ -809,6 +1277,44 @@ _bt_swap_posting(IndexTuple newitem, IndexTuple oposting, int postingoff)
return nposting;
}
+/*
+ * qsort-style comparator used by _bt_dedup_delete_pass()
+ */
+static inline int
+_bt_indexdelete_cmp(TM_IndexDelete *indexdelete1, TM_IndexDelete *indexdelete2)
+{
+ OffsetNumber offset1 = indexdelete1->ioffnum;
+ OffsetNumber offset2 = indexdelete2->ioffnum;
+ ItemPointer tid1 = &indexdelete1->tid;
+ ItemPointer tid2 = &indexdelete2->tid;
+
+ if (offset1 > offset2)
+ return 1;
+ if (offset1 < offset2)
+ return -1;
+
+ /* Must be posting list tuple -- restore TID order */
+ {
+ BlockNumber blk1 = ItemPointerGetBlockNumber(tid1);
+ BlockNumber blk2 = ItemPointerGetBlockNumber(tid2);
+
+ if (blk1 != blk2)
+ return (blk1 < blk2) ? -1 : 1;
+ }
+ {
+ OffsetNumber pos1 = ItemPointerGetOffsetNumber(tid1);
+ OffsetNumber pos2 = ItemPointerGetOffsetNumber(tid2);
+
+ if (pos1 != pos2)
+ return (pos1 < pos2) ? -1 : 1;
+ }
+
+ /* ItemPointer values should never be equal */
+ Assert(false);
+
+ return 0;
+}
+
/*
* Verify posting list invariants for "posting", which must be a posting list
* tuple. Used within assertions.
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index d36f7557c8..0dda82e823 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -37,6 +37,7 @@ static TransactionId _bt_check_unique(Relation rel, BTInsertState insertstate,
static OffsetNumber _bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool logicallymodified,
BTStack stack,
Relation heapRel);
static void _bt_stepright(Relation rel, BTInsertState insertstate, BTStack stack);
@@ -86,7 +87,9 @@ _bt_doinsert(Relation rel, IndexTuple itup,
BTInsertStateData insertstate;
BTScanInsert itup_key;
BTStack stack;
- bool checkingunique = (checkUnique != UNIQUE_CHECK_NO);
+ bool checkingunique = (checkUnique != UNIQUE_CHECK_NO &&
+ checkUnique != UNIQUE_CHECK_NO_WITH_UNCHANGED);
+ bool logicallymodified = (checkUnique != UNIQUE_CHECK_NO_WITH_UNCHANGED);
/* we need an insertion scan key to do our search, so build one */
itup_key = _bt_mkscankey(rel, itup);
@@ -235,7 +238,7 @@ search:
* checkingunique.
*/
newitemoff = _bt_findinsertloc(rel, &insertstate, checkingunique,
- stack, heapRel);
+ logicallymodified, stack, heapRel);
_bt_insertonpg(rel, itup_key, insertstate.buf, InvalidBuffer, stack,
itup, insertstate.itemsz, newitemoff,
insertstate.postingoff, false);
@@ -767,6 +770,11 @@ _bt_check_unique(Relation rel, BTInsertState insertstate, Relation heapRel,
* the right, rather than the first page. In that case, this function
* moves right to the correct target page.
*
+ * If 'logicallymodified' is false, this is for an UPDATE that didn't
+ * logically change the indexed value, but must nevertheless have a new
+ * entry to point to a successor version. This hint from the executor
+ * influences the behavior of deduplication.
+ *
* (In a !heapkeyspace index, there can be multiple pages with the same
* high key, where the new tuple could legitimately be placed on. In
* that case, the caller passes the first page containing duplicates,
@@ -790,6 +798,7 @@ static OffsetNumber
_bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool logicallymodified,
BTStack stack,
Relation heapRel)
{
@@ -873,14 +882,20 @@ _bt_findinsertloc(Relation rel,
/*
* If the target page is full, see if we can obtain enough space by
* erasing LP_DEAD items. If that fails to free enough space, see if
- * we can avoid a page split by performing a deduplication pass over
- * the page.
+ * we can avoid a page split by performing deduplication. Usually
+ * this means a deduplication merge pass, though a deduplication
+ * delete pass is preferred when it looks like version churn is the
+ * source of most of the duplicates.
*
- * We only perform a deduplication pass for a checkingunique caller
- * when the incoming item is a duplicate of an existing item on the
- * leaf page. This heuristic avoids wasting cycles -- we only expect
- * to benefit from deduplicating a unique index page when most or all
- * recently added items are duplicates. See nbtree/README.
+ * We only consider deduplication for a checkingunique caller when the
+ * incoming item is a known duplicate of an existing item on the leaf
+ * page. This heuristic avoids wasting cycles. The overarching goal
+ * within a unique index is to prevent an unnecessary page split
+ * altogether by delaying splits again and again (the goal is not to
+ * save space). If even one incoming tuple that gets added to this
+ * page originates with an INSERT statement then a page split is all
+ * but inevitable anyway --- that's why it's okay that our heuristic
+ * only considers the current incoming newitem. See nbtree/README.
*/
if (PageGetFreeSpace(page) < insertstate->itemsz)
{
@@ -893,13 +908,15 @@ _bt_findinsertloc(Relation rel,
uniquedup = true;
}
- if (itup_key->allequalimage && BTGetDeduplicateItems(rel) &&
- (!checkingunique || uniquedup) &&
+ if (BTGetDeduplicateItems(rel) && (!checkingunique || uniquedup) &&
PageGetFreeSpace(page) < insertstate->itemsz)
{
+ bool dedupdelete = !logicallymodified;
+
_bt_dedup_one_page(rel, insertstate->buf, heapRel,
insertstate->itup, insertstate->itemsz,
- checkingunique);
+ checkingunique, dedupdelete,
+ itup_key->allequalimage);
insertstate->bounds_valid = false;
}
}
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index efee86784b..ecfe79badb 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -273,7 +273,7 @@ static void _bt_sortaddtup(Page page, Size itemsize,
bool newfirstdataitem);
static void _bt_buildadd(BTWriteState *wstate, BTPageState *state,
IndexTuple itup, Size truncextra);
-static void _bt_sort_dedup_finish_pending(BTWriteState *wstate,
+static void _bt_dedup_sort_finish_pending(BTWriteState *wstate,
BTPageState *state,
BTDedupState dstate);
static void _bt_uppershutdown(BTWriteState *wstate, BTPageState *state);
@@ -1068,11 +1068,11 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup,
* Finalize pending posting list tuple, and add it to the index. Final tuple
* is based on saved base tuple, and saved list of heap TIDs.
*
- * This is almost like _bt_dedup_finish_pending(), but it adds a new tuple
- * using _bt_buildadd().
+ * This is almost like _bt_dedup_merge_finish_pending(), but it adds a new
+ * tuple using _bt_buildadd().
*/
static void
-_bt_sort_dedup_finish_pending(BTWriteState *wstate, BTPageState *state,
+_bt_dedup_sort_finish_pending(BTWriteState *wstate, BTPageState *state,
BTDedupState dstate)
{
Assert(dstate->nitems > 0);
@@ -1371,7 +1371,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
* _bt_dedup_save_htid() opted to not merge current item into
* pending posting list.
*/
- _bt_sort_dedup_finish_pending(wstate, state, dstate);
+ _bt_dedup_sort_finish_pending(wstate, state, dstate);
pfree(dstate->base);
/* start new pending posting list with itup copy */
@@ -1390,7 +1390,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
* Handle the last item (there must be a last item when the
* tuplesort returned one or more tuples)
*/
- _bt_sort_dedup_finish_pending(wstate, state, dstate);
+ _bt_dedup_sort_finish_pending(wstate, state, dstate);
pfree(dstate->base);
pfree(dstate->htids);
}
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index bda9be2348..9186bdeea5 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -530,12 +530,12 @@ btree_xlog_dedup(XLogReaderState *record)
}
else
{
- _bt_dedup_finish_pending(newpage, state);
+ _bt_dedup_merge_finish_pending(newpage, state);
_bt_dedup_start_pending(state, itup, offnum);
}
}
- _bt_dedup_finish_pending(newpage, state);
+ _bt_dedup_merge_finish_pending(newpage, state);
Assert(state->nintervals == xlrec->nintervals);
Assert(memcmp(state->intervals, intervals,
state->nintervals * sizeof(BTDedupInterval)) == 0);
diff --git a/src/backend/access/table/tableam.c b/src/backend/access/table/tableam.c
index 6438c45716..5ef3530df4 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -30,6 +30,20 @@
#include "storage/shmem.h"
#include "storage/smgr.h"
+typedef struct TM_IndexDeleteCounts
+{
+ BlockNumber table_block;
+ int16 npromisingtids_in_block;
+ int16 ntids_in_block;
+} TM_IndexDeleteCounts;
+
+static int table_index_batch_check_block_sort(TM_IndexDelete *deltids,
+ int ndeltids);
+static inline int indexdelete_tids_cmp(TM_IndexDelete *indexdelete1,
+ TM_IndexDelete *indexdelete2);
+static inline int indexdeletecount_ntids_cmp(TM_IndexDeleteCounts *count1,
+ TM_IndexDeleteCounts *count2);
+
/*
* Constants to control the behavior of block allocation to parallel workers
* during a parallel seqscan. Technically these values do not need to be
@@ -207,9 +221,9 @@ table_beginscan_parallel(Relation relation, ParallelTableScanDesc parallel_scan)
/*
* To perform that check simply start an index scan, create the necessary
* slot, do the heap lookup, and shut everything down again. This could be
- * optimized, but is unlikely to matter from a performance POV. If there
- * frequently are live index pointers also matching a unique index key, the
- * CPU overhead of this routine is unlikely to matter.
+ * optimized, but is unlikely to matter from a performance POV. Note that
+ * table_index_batch_check() is optimized in this way, since it is designed
+ * as a batch operation.
*
* Note that *tid may be modified when we return true if the AM supports
* storing multiple row versions reachable via a single index entry (like
@@ -236,6 +250,116 @@ table_index_fetch_tuple_check(Relation rel,
return found;
}
+/*
+ * Specialized variant of table_index_fetch_tuple_check() that can be used
+ * by index AMs to perform "bottom up" deletion of duplicate index tuples.
+ * This is particularly likely to work well with unique indexes.
+ *
+ * Note: This routine sorts the deltids array, but does not modify any
+ * individual entry accept to mark it as dead for caller.
+ *
+ * Returns total number of deltids that can be killed in index by caller.
+ *
+ * TODO: This should be combined with the equivalent of a call to
+ * table_compute_xid_horizon_for_tuples().
+ */
+int
+table_index_batch_check(Relation rel, TM_IndexDelete *deltids, int ndeltids,
+ Snapshot snapshot, int npromisingkillsneeded,
+ int *nblocksaccessed)
+{
+ IndexFetchTableData *scan;
+ TupleTableSlot *slot;
+ int nkills = 0;
+ int npromkills = 0;
+ BlockNumber last = InvalidBlockNumber;
+ bool final_block = false;
+ int nblocks_promising;
+
+ slot = table_slot_create(rel, NULL);
+ scan = table_index_fetch_begin(rel);
+
+ *nblocksaccessed = 0;
+ nblocks_promising = table_index_batch_check_block_sort(deltids, ndeltids);
+ for (int i = 0; i < ndeltids; i++)
+ {
+ ItemPointer tid = &deltids[i].tid;
+ bool ispromising = deltids[i].ispromising;
+ bool new_block = last != ItemPointerGetBlockNumber(tid);
+ ItemPointerData tmp;
+ bool call_again = false;
+ bool all_dead = false;
+ bool found;
+
+ Assert(!deltids[i].isdead);
+
+ /*
+ * When we were just finishing off a table block we'd already started
+ * with at the point we reached caller's requirements, quit. (We quit
+ * here when we already decided not to access the new block. We're
+ * carrying out that earlier decision now.)
+ */
+ if (final_block && new_block)
+ break;
+
+ if (new_block)
+ {
+ /*
+ * Each time we're about to access a new block we end up here to
+ * consider if it's really worth accessing. Apply the following
+ * tests, and quit without accessing block if any test fails:
+ *
+ * 1. Give up when we'd otherwise access the second table block in
+ * line and have no kills (promising or otherwise) to show for
+ * accessing the first/"most promising" block.
+ *
+ * 2. Give up once we just finished final block that has at least
+ * one promising tuple (or when there were no promising tuples in
+ * the first place). We never access a new block just to get to
+ * non-promising tuples because the chances of success are
+ * precisely zero with many workloads.
+ *
+ * 3. Give up before accessing a fourth block, no matter what.
+ */
+ if (*nblocksaccessed == 1 && nkills == 0)
+ break;
+ if (nblocks_promising-- == 0)
+ break;
+ if (*nblocksaccessed == 3)
+ break;
+ }
+
+ tmp = *tid;
+ found = table_index_fetch_tuple(scan, &tmp, snapshot, slot,
+ &call_again, &all_dead);
+
+ if (new_block)
+ (*nblocksaccessed)++;
+ last = ItemPointerGetBlockNumber(tid);
+ if (!found && all_dead)
+ {
+ deltids[i].isdead = true;
+ nkills++;
+ if (ispromising)
+ npromkills++;
+ }
+
+ if (npromkills >= npromisingkillsneeded)
+ {
+ /*
+ * Caller is satisfied, so we can quit now. But before we do,
+ * might as well finish off remaining TIDs on same table block (if
+ * any).
+ */
+ final_block = true;
+ }
+ }
+
+ table_index_fetch_end(scan);
+ ExecDropSingleTupleTableSlot(slot);
+
+ return nkills;
+}
/* ------------------------------------------------------------------------
* Functions for non-modifying operations on individual tuples
@@ -356,7 +480,7 @@ simple_table_tuple_update(Relation rel, ItemPointer otid,
GetCurrentCommandId(true),
snapshot, InvalidSnapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode, update_indexes);
+ &tmfd, &lockmode, update_indexes, NULL);
switch (result)
{
@@ -763,3 +887,170 @@ table_block_relation_estimate_size(Relation rel, int32 *attr_widths,
else
*allvisfrac = (double) relallvisible / curpages;
}
+
+#define ST_SORT qsort_deltids_promising
+#define ST_ELEMENT_TYPE TM_IndexDelete
+#define ST_COMPARE(a, b) (indexdelete_tids_cmp(a, b))
+#define ST_SCOPE static
+#define ST_DEFINE
+#include "lib/sort_template.h"
+
+#define ST_SORT qsort_blockgroup
+#define ST_ELEMENT_TYPE TM_IndexDeleteCounts
+#define ST_COMPARE(a, b) (indexdeletecount_ntids_cmp(a, b))
+#define ST_SCOPE static
+#define ST_DEFINE
+#include "lib/sort_template.h"
+
+/*
+ * table_index_batch_check() requires that the deltids array be in a certain
+ * order before it gets started. This helper routine handles that.
+ *
+ * TIDs are grouped together by block number, with ascending TID order within
+ * each group (i.e. in ascending TID offset number order). The block number
+ * groups are ordered according to the total number of promising candidate
+ * TIDs. This order maximizes the final number of TIDs that caller can kill
+ * in index relative to the number of tableam blocks accessed.
+ *
+ * The goal of the sort order is to process as many dup table TIDs as
+ * possible with as few table buffer accesses as possible. In practice it's
+ * frequently possible to kill relatively many TIDs with only one or two
+ * table page accesses due to the effect of locality.
+ */
+static int
+table_index_batch_check_block_sort(TM_IndexDelete *deltids, int ndeltids)
+{
+ TM_IndexDeleteCounts *blockcounts;
+ TM_IndexDelete *reordereddeltids;
+ BlockNumber curblock = InvalidBlockNumber;
+ int nblock_groups = 0;
+ int nblocks_promising = 0;
+ int ncopied = 0;
+
+ Assert(ndeltids > 0);
+
+ /* First sort caller's array by TID */
+ qsort_deltids_promising(deltids, ndeltids);
+
+ /* Calculate per-table-block count of TIDs */
+ blockcounts = palloc(sizeof(TM_IndexDeleteCounts) * ndeltids);
+ for (int i = 0; i < ndeltids; i++)
+ {
+ ItemPointer deltid = &deltids[i].tid;
+ bool ispromising = deltids[i].ispromising;
+
+ if (curblock != ItemPointerGetBlockNumber(deltid))
+ {
+ /* New block group */
+ nblock_groups++;
+
+ curblock = ItemPointerGetBlockNumber(deltid);
+ blockcounts[nblock_groups - 1].table_block = curblock;
+ blockcounts[nblock_groups - 1].ntids_in_block = 1;
+ blockcounts[nblock_groups - 1].npromisingtids_in_block = 0;
+ }
+ else
+ {
+ blockcounts[nblock_groups - 1].ntids_in_block++;
+ }
+
+ if (ispromising)
+ blockcounts[nblock_groups - 1].npromisingtids_in_block++;
+ }
+
+ /*
+ * Sort blockcounts by "promising" TID count in desc order, then tiebreak
+ * on block number
+ */
+ qsort_blockgroup(blockcounts, nblock_groups);
+ reordereddeltids = palloc(ndeltids * sizeof(TM_IndexDelete));
+ for (int i = 0; i < nblock_groups; i++)
+ {
+ TM_IndexDeleteCounts *blockgroup = blockcounts + i;
+
+ for (int j = 0; j < ndeltids; j++)
+ {
+ ItemPointer tid = &deltids[j].tid;
+
+ if (blockgroup->table_block == ItemPointerGetBlockNumber(tid))
+ {
+ memcpy(reordereddeltids + ncopied, deltids + j,
+ sizeof(TM_IndexDelete) * blockgroup->ntids_in_block);
+ ncopied += blockgroup->ntids_in_block;
+ if (blockgroup->npromisingtids_in_block > 0)
+ nblocks_promising++;
+ break; /* Move on to next table block group */
+ }
+ }
+ }
+
+ /* Copy back final sorted array into caller's array */
+ memcpy(deltids, reordereddeltids, sizeof(TM_IndexDelete) * ndeltids);
+
+ /* be tidy */
+ pfree(reordereddeltids);
+ pfree(blockcounts);
+
+ return nblocks_promising;
+}
+
+/*
+ * qsort-style comparator used in table_index_batch_check_block_sort()
+ */
+static inline int
+indexdelete_tids_cmp(TM_IndexDelete *indexdelete1,
+ TM_IndexDelete *indexdelete2)
+{
+ ItemPointer tid1 = &indexdelete1->tid;
+ ItemPointer tid2 = &indexdelete2->tid;
+
+ {
+ BlockNumber blk1 = ItemPointerGetBlockNumber(tid1);
+ BlockNumber blk2 = ItemPointerGetBlockNumber(tid2);
+
+ if (blk1 != blk2)
+ return (blk1 < blk2) ? -1 : 1;
+ }
+ {
+ OffsetNumber pos1 = ItemPointerGetOffsetNumber(tid1);
+ OffsetNumber pos2 = ItemPointerGetOffsetNumber(tid2);
+
+ if (pos1 != pos2)
+ return (pos1 < pos2) ? -1 : 1;
+ }
+
+ /* ItemPointer values should never be equal */
+ Assert(false);
+
+ return 0;
+}
+
+/*
+ * qsort-style comparator used in table_index_batch_check_block_sort()
+ */
+static inline int
+indexdeletecount_ntids_cmp(TM_IndexDeleteCounts *count1,
+ TM_IndexDeleteCounts *count2)
+{
+ /* Invert usual order here (desc npromisingtids_in_block sort order) */
+ if (count1->npromisingtids_in_block > count2->npromisingtids_in_block)
+ return -1;
+ if (count1->npromisingtids_in_block < count2->npromisingtids_in_block)
+ return 1;
+
+ /* Tiebreak: desc ntids_in_block sort order */
+ if (count1->ntids_in_block > count2->ntids_in_block)
+ return -1;
+ if (count1->ntids_in_block < count2->ntids_in_block)
+ return 1;
+
+ /* Tiebreak: block number (asc order) */
+ if (count1->table_block > count2->table_block)
+ return 1;
+ if (count1->table_block < count2->table_block)
+ return -1;
+
+ Assert(false);
+
+ return 0;
+}
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 531bd7c73a..b9b625b883 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -2523,7 +2523,7 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
recheckIndexes =
ExecInsertIndexTuples(resultRelInfo,
buffer->slots[i], estate, false, NULL,
- NIL);
+ NIL, NULL);
ExecARInsertTriggers(estate, resultRelInfo,
slots[i], recheckIndexes,
cstate->transition_capture);
@@ -3285,7 +3285,8 @@ CopyFrom(CopyState cstate)
estate,
false,
NULL,
- NIL);
+ NIL,
+ NULL);
}
/* AFTER ROW INSERT Triggers */
diff --git a/src/backend/executor/execIndexing.c b/src/backend/executor/execIndexing.c
index c6b5bcba7b..d171d26b69 100644
--- a/src/backend/executor/execIndexing.c
+++ b/src/backend/executor/execIndexing.c
@@ -275,7 +275,8 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
EState *estate,
bool noDupErr,
bool *specConflict,
- List *arbiterIndexes)
+ List *arbiterIndexes,
+ Bitmapset *modified_attrs_hint)
{
ItemPointer tupleid = &slot->tts_tid;
List *result = NIL;
@@ -389,6 +390,44 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
else
checkUnique = UNIQUE_CHECK_PARTIAL;
+ /*
+ * We may have to hint to index am that this is a logically unchanged
+ * index tuple. This happens when we're inserting a duplicate tuple
+ * just to represent the successor version.
+ */
+ if (checkUnique == UNIQUE_CHECK_NO && modified_attrs_hint)
+ {
+ bool logicallyModified = false;
+
+ for (int attr = 0; attr < indexInfo->ii_NumIndexAttrs; attr++)
+ {
+ int keycol = indexInfo->ii_IndexAttrNumbers[attr];
+
+ if (keycol > 0)
+ {
+ logicallyModified =
+ bms_is_member(keycol - FirstLowInvalidHeapAttributeNumber,
+ modified_attrs_hint);
+ if (logicallyModified)
+ break;
+ }
+ else
+ {
+ /*
+ * XXX: For now we always assume that expression indexes
+ * and indexes with whole-row vars were not modified by an
+ * UPDATE (i.e. they just use the dedup delete
+ * optimization regardless of the details of the UPDATE).
+ * Review this decision when the high level design is a
+ * bit better worked out.
+ */
+ }
+ }
+
+ if (!logicallyModified)
+ checkUnique = UNIQUE_CHECK_NO_WITH_UNCHANGED;
+ }
+
satisfiesConstraint =
index_insert(indexRelation, /* index relation */
values, /* array of index Datums */
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index 01d26881e7..e97d05b448 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -445,7 +445,7 @@ ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false, NULL,
- NIL);
+ NIL, NULL);
/* AFTER ROW INSERT Triggers */
ExecARInsertTriggers(estate, resultRelInfo, slot,
@@ -513,7 +513,7 @@ ExecSimpleRelationUpdate(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false, NULL,
- NIL);
+ NIL, NULL);
/* AFTER ROW UPDATE Triggers */
ExecARUpdateTriggers(estate, resultRelInfo,
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 0c055ed408..718539d7b8 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -605,7 +605,7 @@ ExecInsert(ModifyTableState *mtstate,
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, true,
&specConflict,
- arbiterIndexes);
+ arbiterIndexes, NULL);
/* adjust the tuple's state accordingly */
table_tuple_complete_speculative(resultRelationDesc, slot,
@@ -644,7 +644,7 @@ ExecInsert(ModifyTableState *mtstate,
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false,
- NULL, NIL);
+ NULL, NIL, NULL);
}
}
@@ -1238,6 +1238,7 @@ ExecUpdate(ModifyTableState *mtstate,
TM_Result result;
TM_FailureData tmfd;
List *recheckIndexes = NIL;
+ Bitmapset *modified_attrs_hint = NULL;
/*
* abort the operation if not running transactions
@@ -1401,7 +1402,8 @@ lreplace:;
estate->es_snapshot,
estate->es_crosscheck_snapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode, &update_indexes);
+ &tmfd, &lockmode, &update_indexes,
+ &modified_attrs_hint);
switch (result)
{
@@ -1532,9 +1534,13 @@ lreplace:;
/* insert index entries for tuple if necessary */
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
+ {
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false,
- NULL, NIL);
+ NULL, NIL,
+ modified_attrs_hint);
+ bms_free(modified_attrs_hint);
+ }
}
if (canSetTag)
--
2.25.1
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-10-22 17:11 ` Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
1 sibling, 1 reply; 1661+ messages in thread
From: Simon Riggs @ 2020-10-22 17:11 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: Anastasia Lubennikova <[email protected]>; PostgreSQL Hackers <[email protected]>
On Fri, 16 Oct 2020 at 20:12, Peter Geoghegan <[email protected]> wrote:
> The TPS/throughput is about what you'd expect for the two hour run:
>
> 18,988.762398 TPS for the patch
> 11,123.551707 TPS for the master branch.
Very good.
> Patch:
>
> statement latencies in milliseconds:
> 0.294 UPDATE pgbench_accounts SET abalance = abalance +
> :delta WHERE aid = :aid1;
>
> Master:
>
> statement latencies in milliseconds:
> 0.604 UPDATE pgbench_accounts SET abalance = abalance +
> :delta WHERE aid = :aid1;
The average latency is x2. What is the distribution of latencies?
Occasional very long or all uniformly x2?
I would guess that holding the page locks will also slow down SELECT
workload, so I think you should also report that workload as well.
Hopefully that will be better in the latest version.
I wonder whether we can put this work into a background process rather
than pay the cost in the foreground? Perhaps that might not need us to
hold page locks??
--
Simon Riggs http://www.EnterpriseDB.com/
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
@ 2020-10-22 17:42 ` Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
0 siblings, 1 reply; 1661+ messages in thread
From: Peter Geoghegan @ 2020-10-22 17:42 UTC (permalink / raw)
To: Simon Riggs <[email protected]>; +Cc: Anastasia Lubennikova <[email protected]>; PostgreSQL Hackers <[email protected]>
On Thu, Oct 22, 2020 at 10:12 AM Simon Riggs <[email protected]> wrote:
> > 18,988.762398 TPS for the patch
> > 11,123.551707 TPS for the master branch.
>
> Very good.
I'm happy with this result, but as I said it's not really the point. I
can probably get up to a 5x or more improvement in TPS if I simply add
enough indexes.
The point is that we're preventing pathological behavior. The patch
does not so much add something helpful as subtract something harmful.
You can contrive a case that has as much of that harmful element as
you like.
> The average latency is x2. What is the distribution of latencies?
> Occasional very long or all uniformly x2?
The latency is generally very even with the patch. There is a constant
hum of cleanup by the new mechanism in the case of the benchmark
workload. As opposed to a cascade of page splits, which occur in
clearly distinct correlated waves.
> I would guess that holding the page locks will also slow down SELECT
> workload, so I think you should also report that workload as well.
>
> Hopefully that will be better in the latest version.
But the same benchmark that you're asking about here has two SELECT
statements and only one UPDATE. It already is read-heavy in that
sense. And we see that the latency is also significantly improved for
the SELECT queries.
Even if there was often a performance hit rather than a benefit (which
is definitely not what we see), it would still probably be worth it.
Users create indexes for a reason. I believe that we are obligated to
maintain the indexes to a reasonable degree, and not just when it
happens to be convenient to do so in passing.
> I wonder whether we can put this work into a background process rather
> than pay the cost in the foreground? Perhaps that might not need us to
> hold page locks??
Holding a lock on the leaf page is unavoidable.
This patch is very effective because it intervenes at precisely the
right moment in precisely the right place only. We don't really have
to understand anything about workload characteristics to be sure of
this, because it's all based on the enormous asymmetries I've
described, which are so huge that it just seems impossible that
anything else could matter. Trying to do any work in a background
process works against this local-first, bottom-up laissez faire
strategy. The strength of the design is in how clever it isn't.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-10-23 16:03 ` Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
0 siblings, 1 reply; 1661+ messages in thread
From: Simon Riggs @ 2020-10-23 16:03 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: Anastasia Lubennikova <[email protected]>; PostgreSQL Hackers <[email protected]>
On Thu, 22 Oct 2020 at 18:42, Peter Geoghegan <[email protected]> wrote:
> > The average latency is x2. What is the distribution of latencies?
> > Occasional very long or all uniformly x2?
>
> The latency is generally very even with the patch. There is a constant
> hum of cleanup by the new mechanism in the case of the benchmark
> workload. As opposed to a cascade of page splits, which occur in
> clearly distinct correlated waves.
Please publish details of how long a pre-split cleaning operation
takes and what that does to transaction latency. It *might* be true
that the cost of avoiding splits is worth it in balance against the
cost of splitting, but it might not.
You've shown us a very nice paper analysing the page split waves, but
we need a similar detailed analysis so we can understand if what you
propose is better or not (and in what situations).
> > I would guess that holding the page locks will also slow down SELECT
> > workload, so I think you should also report that workload as well.
> >
> > Hopefully that will be better in the latest version.
>
> But the same benchmark that you're asking about here has two SELECT
> statements and only one UPDATE. It already is read-heavy in that
> sense. And we see that the latency is also significantly improved for
> the SELECT queries.
>
> Even if there was often a performance hit rather than a benefit (which
> is definitely not what we see), it would still probably be worth it.
> Users create indexes for a reason. I believe that we are obligated to
> maintain the indexes to a reasonable degree, and not just when it
> happens to be convenient to do so in passing.
The leaf page locks are held for longer, so we need to perform
sensible tests that show if this has a catastrophic effect on related
workloads, or not.
The SELECT tests proposed need to be aimed at the same table, at the same time.
> The strength of the design is in how clever it isn't.
What it doesn't do could be good or bad so we need to review more
details on behavior. Since the whole idea of the patch is to change
behavior, that seems a reasonable ask. I don't have any doubt about
the validity of the approach or coding.
What you've done so far is very good and I am very positive about
this, well done.
--
Simon Riggs http://www.EnterpriseDB.com/
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
@ 2020-10-23 17:13 ` Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
0 siblings, 1 reply; 1661+ messages in thread
From: Peter Geoghegan @ 2020-10-23 17:13 UTC (permalink / raw)
To: Simon Riggs <[email protected]>; +Cc: Anastasia Lubennikova <[email protected]>; PostgreSQL Hackers <[email protected]>
On Fri, Oct 23, 2020 at 9:03 AM Simon Riggs <[email protected]> wrote:
> Please publish details of how long a pre-split cleaning operation
> takes and what that does to transaction latency. It *might* be true
> that the cost of avoiding splits is worth it in balance against the
> cost of splitting, but it might not.
I don't think that you understand how the patch works. I cannot very
well isolate that cost because the patch is designed to only pay it
when there is a strong chance of getting a much bigger reward, and
when the only alternative is to split the page. When it fails the
question naturally doesn't come up again for the same two pages that
follow from the page split. As far as I know the only cases that are
regressed all involve small indexes with lots of contention, which is
not surprising. And not necessarily due to the heap page accesses -
making indexes smaller sometimes has that effect, even when it happens
due to things like better page split heuristics.
If anybody finds a serious problem with my patch then it'll be a
weakness or hole in the argument I just made -- it won't have much to
do with how expensive any of these operations are in isolation. It
usually isn't sensible to talk about page splits as isolated things.
Most of my work on B-Trees in the past couple of years built on the
observation that sometimes successive page splits are related to each
other in one way or another.
It is a fallacy of composition to think of the patch as a thing that
prevents some page splits. The patch is valuable because it more or
less eliminates *unnecessary* page splits (and makes it so that there
cannot be very many TIDs for each logical row in affected indexes).
The overall effect is not linear. If you added code to artificially
make the mechanism fail randomly 10% of the time (at the point where
it becomes clear that the current operation would otherwise be
successful) that wouldn't make the resulting code 90% as useful as the
original. It would actually make it approximately 0% as useful. On
human timescales the behavioral difference between this hobbled
version of my patch and the master branch would be almost
imperceptible.
It's obvious that a page split is more expensive than the delete
operation (when it works out). It doesn't need a microbenchmark (and I
really can't think of one that would make any sense). Page splits
typically have WAL records that are ~4KB in size, whereas the
opportunistic delete records are almost always less than 100 bytes,
and typically close to 64 bytes -- which is the same size as most
individual leaf page insert WAL records. Plus you have almost double
the FPIs going forward with the page split.
> You've shown us a very nice paper analysing the page split waves, but
> we need a similar detailed analysis so we can understand if what you
> propose is better or not (and in what situations).
That paper was just referenced in passing. It isn't essential to the
main argument.
> The leaf page locks are held for longer, so we need to perform
> sensible tests that show if this has a catastrophic effect on related
> workloads, or not.
>
> The SELECT tests proposed need to be aimed at the same table, at the same time.
But that's exactly what I did the first time!
I had two SELECT statements against the same table. They use almost
the same distribution as the UPDATE, so that they'd hit the same part
of the key space without it being exactly the same as the UPDATE from
the same xact in each case (I thought that if it was exactly the same
part of the table then that might unfairly favor my patch).
> > The strength of the design is in how clever it isn't.
>
> What it doesn't do could be good or bad so we need to review more
> details on behavior. Since the whole idea of the patch is to change
> behavior, that seems a reasonable ask. I don't have any doubt about
> the validity of the approach or coding.
I agree, but the patch isn't the sum of its parts. You need to talk
about a workload or a set of conditions, and how things develop over
time.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-10-24 09:55 ` Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
0 siblings, 1 reply; 1661+ messages in thread
From: Simon Riggs @ 2020-10-24 09:55 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: Anastasia Lubennikova <[email protected]>; PostgreSQL Hackers <[email protected]>
On Fri, 23 Oct 2020 at 18:14, Peter Geoghegan <[email protected]> wrote:
> It's obvious that a page split is more expensive than the delete
> operation (when it works out).
The problem I highlighted is that the average UPDATE latency is x2
what it is on current HEAD. That is not consistent with the reported
TPS, so it remains an issue and that isn't obvious.
> It doesn't need a microbenchmark (and I
> really can't think of one that would make any sense).
I'm asking for detailed timings so we can understand the latency
issue. I didn't ask for a microbenchmark.
I celebrate your results, but we do need to understand the issue, somehow.
--
Simon Riggs http://www.EnterpriseDB.com/
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
@ 2020-10-24 15:01 ` Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
0 siblings, 1 reply; 1661+ messages in thread
From: Peter Geoghegan @ 2020-10-24 15:01 UTC (permalink / raw)
To: Simon Riggs <[email protected]>; +Cc: Anastasia Lubennikova <[email protected]>; PostgreSQL Hackers <[email protected]>
On Sat, Oct 24, 2020 at 2:55 AM Simon Riggs <[email protected]> wrote:
> The problem I highlighted is that the average UPDATE latency is x2
> what it is on current HEAD. That is not consistent with the reported
> TPS, so it remains an issue and that isn't obvious.
Why do you say that? I reported that the UPDATE latency is less than
half for the benchmark.
There probably are some workloads with worse latency and throughput,
but generally only with high contention/small indexes. I'll try to
fine tune those, but some amount of it is probably inevitable. On
average query latency is quite a lot lower with the patch (where it is
affected at all - the mechanism is only used with non-hot updates).
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-10-26 21:15 ` Peter Geoghegan <[email protected]>
2020-10-27 09:43 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-28 23:05 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-10-29 22:05 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
0 siblings, 4 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-10-26 21:15 UTC (permalink / raw)
To: Simon Riggs <[email protected]>; +Cc: Anastasia Lubennikova <[email protected]>; PostgreSQL Hackers <[email protected]>
On Sat, Oct 24, 2020 at 8:01 AM Peter Geoghegan <[email protected]> wrote:
> There probably are some workloads with worse latency and throughput,
> but generally only with high contention/small indexes. I'll try to
> fine tune those, but some amount of it is probably inevitable. On
> average query latency is quite a lot lower with the patch (where it is
> affected at all - the mechanism is only used with non-hot updates).
Attached is v5, which has changes that are focused on two important
high level goals:
1. Keeping costs down generally, especially in high contention cases
where costs are most noticeable.
2. Making indexes on low cardinality columns that naturally really
benefit from merge deduplication in Postgres 13 receive largely the
same benefits that you've already seen with high cardinality indexes
(at least outside of the extreme cases where it isn't sensible to
try).
CPU costs (especially from sorting temp work arrays) seem to be the
big cost overall. It turns out that the costs of accessing heap pages
within the new mechanism is not really noticeable. This isn't all that
surprising, though. The heap pages are accessed in a way that
naturally exploits locality across would-be page splits in different
indexes.
To some degree the two goals that I describe conflict with each other.
If merge deduplication increases the number of logical rows that "fit
on each leaf page" (by increasing the initial number of TIDs on each
leaf page by over 3x when the index is in the pristine CREATE INDEX
state), then naturally the average amount of work required to maintain
indexes in their pristine state is increased. We cannot expect to pay
nothing to avoid "unnecessary page splits" -- we can only expect to
come out ahead over time.
The main new thing that allowed me to more or less accomplish the
second goal is granular deletion in posting list tuples. That is, v5
teaches the delete mechanism to do VACUUM-style granular TID deletion
within posting lists. This factor turned out to matter a lot.
Here is an extreme benchmark that I ran this morning for this patch,
which shows both strengths and weaknesses:
pgbench scale 1000 (with customizations to indexing that I go into
below), 16 + 32 clients, 30 minutes per run (so 2 hours total
excluding initial data loading). Same queries as last time:
\set aid1 random_gaussian(1, 100000 * :scale, 4.0)
\set aid2 random_gaussian(1, 100000 * :scale, 4.5)
\set aid3 random_gaussian(1, 100000 * :scale, 4.2)
\set bid random(1, 1 * :scale)
\set tid random(1, 10 * :scale)
\set delta random(-5000, 5000)
BEGIN;
UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
END;
And just like last time, we replace the usual pgbench_accounts index
with an INCLUDE index to artificially make every UPDATE a non-HOT
UPDATE:
create unique index aid_pkey_include_abalance on pgbench_accounts
(aid) include(abalance);
Unlike last time we have a variety of useless-to-us *low cardinality*
indexes. These are much smaller than aid_pkey_include_abalance due to
merge deduplication, but are still quite similar to it:
create index fiver on pgbench_accounts ((aid - (aid%5)));
create index tenner on pgbench_accounts ((aid - (aid%10)));
create index score on pgbench_accounts ((aid - (aid%20)));
The silly indexes this time around are designed to have the same skew
as the PK, but with low cardinality data. So, for example "score", has
twenty distinct logical rows for each distinct aid value. Which is
pretty extreme as far as the delete mechanism is concerned. That's why
this is more of a mixed picture compared to the earlier benchmark. I'm
trying to really put the patch through its paces, not make it look
good.
First the good news. The patch held up perfectly in one important way
-- the size of the indexes didn't change at all compared to the
original pristine size. That looked like this at the start for both
patch + master:
aid_pkey_include_abalance: 274,194 pages/2142 MB
fiver: 142,348 pages/1112 MB
tenner: 115,352 pages/901 MB
score: 94,677 pages/740 MB
By the end, master looked like this:
aid_pkey_include_abalance: 428,759 pages (~1.56x original size)
fiver: 220,114 pages (~1.54x original size)
tenner: 176,983 pages (~1.53x original size)
score: 178,165 pages (~1.88x original size)
(As I said, no change in the size of indexes with the patch -- not
even one single page split.)
Now for the not-so-good news. The TPS numbers looked like this
(results in original chronological order of the runs, which I've
interleaved):
patch_1_run_16.out: "tps = 30452.530518 (including connections establishing)"
master_1_run_16.out: "tps = 35101.867559 (including connections establishing)"
patch_1_run_32.out: "tps = 26000.991486 (including connections establishing)"
master_1_run_32.out: "tps = 32582.129545 (including connections establishing)"
The latency numbers aren't great for the patch, either. Take the 16 client case:
number of transactions actually processed: 54814992
latency average = 0.525 ms
latency stddev = 0.326 ms
tps = 30452.530518 (including connections establishing)
tps = 30452.612796 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 4.0)
0.000 \set aid2 random_gaussian(1, 100000 * :scale, 4.5)
0.000 \set aid3 random_gaussian(1, 100000 * :scale, 4.2)
0.000 \set bid random(1, 1 * :scale)
0.000 \set tid random(1, 10 * :scale)
0.000 \set delta random(-5000, 5000)
0.046 BEGIN;
0.159 UPDATE pgbench_accounts SET abalance = abalance +
:delta WHERE aid = :aid1;
0.153 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.091 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.075 END;
vs master's 16 client case:
number of transactions actually processed: 63183870
latency average = 0.455 ms
latency stddev = 0.307 ms
tps = 35101.867559 (including connections establishing)
tps = 35101.914573 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 4.0)
0.000 \set aid2 random_gaussian(1, 100000 * :scale, 4.5)
0.000 \set aid3 random_gaussian(1, 100000 * :scale, 4.2)
0.000 \set bid random(1, 1 * :scale)
0.000 \set tid random(1, 10 * :scale)
0.000 \set delta random(-5000, 5000)
0.049 BEGIN;
0.117 UPDATE pgbench_accounts SET abalance = abalance +
:delta WHERE aid = :aid1;
0.120 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.091 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.077 END;
Earlier variations of this same workload that were run with a 10k TPS
rate limit had SELECT statements that had somewhat lower latency with
the patch, while the UPDATE statements were slower by roughly the same
amount as you see here. Here we see that at least the aid3 SELECT is
just as fast with the patch. (Don't have a proper example of this
rate-limited phenomenon close at hand now, since I saw it happen back
when the patch was less well optimized.)
This benchmark is designed to be extreme, and to really stress the
patch. For one thing we have absolutely no index scans for all but one
of the four indexes, so controlling the bloat there isn't going to
give you the main expected benefit. Which is that index scans don't
even have to visit heap pages from old versions, since they're not in
the index for very long (unless there aren't very many versions for
the logical rows in question, which isn't really a problem for us).
For another the new mechanism is constantly needed, which just isn't
very realistic. It seems as if the cost is mostly paid by non-HOT
updaters, which seems exactly right to me.
I probably could have cheated by making the aid_pkey_include_abalance
index a non-unique index, denying the master branch the benefit of
LP_DEAD setting within _bt_check_unique(). Or I could have cheated
(perhaps I should just say "gone for something a bit more
sympathetic") by not having skew on all the indexes (say by hashing on
aid in the indexes that use merge deduplication). I also think that
the TPS gap would have been smaller if I'd spent more time on each
run, but I didn't have time for that today. In the past I've seen it
take a couple of hours or more for the advantages of the patch to come
through (it takes that long for reasons that should be obvious).
Even the overhead we see here is pretty tolerable IMV. I believe that
it will be far more common for the new mechanism to hardly get used at
all, and yet have a pretty outsized effect on index bloat. To give you
a simple example of how that can happen, consider that if this did
happen in a real workload it would probably be caused by a surge in
demand -- now we don't have to live with the bloat consequences of an
isolated event forever (or until the next REINDEX). I can make more
sophisticated arguments than that one, but it doesn't seem useful
right now so I'll refrain.
The patch adds a backstop. It seems to me that that's really what we
need here. Predictability over time and under a large variety of
different conditions. Real workloads constantly fluctuate.
Even if people end up not buying my argument that it's worth it for
workloads like this, there are various options. And, I bet I can
further improve the high contention cases without losing the valuable
part -- there are a number of ways in which I can get the CPU costs
down further that haven't been fully explored (yes, it really does
seem to be CPU costs, especially due to TID sorting). Again, this
patch is all about extreme pathological workloads, system stability,
and system efficiency over time -- it is not simply about increasing
system throughput. There are some aspects of this design (that come up
with extreme workloads) that may in the end come down to value
judgments. I'm not going to tell somebody that they're wrong for
prioritizing different things (within reason, at least). In my opinion
almost all of the problems we have with VACUUM are ultimately
stability problems, not performance problems per se. And, I suspect
that we do very well with stupid benchmarks like this compared to
other DB systems precisely because we currently allow non-HOT updaters
to "live beyond their means" (which could in theory be great if you
frame it a certain way that seems pretty absurd to me). This suggests
we can "afford" to go a bit slower here as far as the competitive
pressures determine what we should do (notice that this is a distinct
argument to my favorite argument, which is that we cannot afford to
*not* go a bit slower in certain extreme cases).
I welcome debate about this.
--
Peter Geoghegan
Attachments:
[application/octet-stream] v5-0001-Add-sort_template.h-for-making-fast-sort-function.patch (13.7K, ../../CAH2-Wzkaj6OhVSvB46t_ybosd0cH1Qaiao+0dSopGUDmEM37Hw@mail.gmail.com/2-v5-0001-Add-sort_template.h-for-making-fast-sort-function.patch)
download | inline diff:
From c62bb3c5f9f2e8319cf54344a6d168fe95f62879 Mon Sep 17 00:00:00 2001
From: Thomas Munro <[email protected]>
Date: Mon, 17 Aug 2020 21:31:56 +1200
Subject: [PATCH v5 1/2] Add sort_template.h for making fast sort functions.
Move our qsort implementation into a header that can be used to
define specialized functions for better performance.
Discussion: https://postgr.es/m/CA%2BhUKGKMQFVpjr106gRhwk6R-nXv0qOcTreZuQzxgpHESAL6dw%40mail.gmail.com
---
src/include/lib/sort_template.h | 428 ++++++++++++++++++++++++++++++++
1 file changed, 428 insertions(+)
create mode 100644 src/include/lib/sort_template.h
diff --git a/src/include/lib/sort_template.h b/src/include/lib/sort_template.h
new file mode 100644
index 0000000000..a279bcf959
--- /dev/null
+++ b/src/include/lib/sort_template.h
@@ -0,0 +1,428 @@
+/*-------------------------------------------------------------------------
+ *
+ * sort_template.h
+ *
+ * A template for a sort algorithm that supports varying degrees of
+ * specialization.
+ *
+ * Copyright (c) 2020, PostgreSQL Global Development Group
+ *
+ * Usage notes:
+ *
+ * To generate functions specialized for a type, the following parameter
+ * macros should be #define'd before this file is included.
+ *
+ * - ST_SORT - the name of a sort function to be generated
+ * - ST_ELEMENT_TYPE - type of the referenced elements
+ * - ST_DECLARE - if defined the functions and types are declared
+ * - ST_DEFINE - if defined the functions and types are defined
+ * - ST_SCOPE - scope (e.g. extern, static inline) for functions
+ *
+ * Instead of ST_ELEMENT_TYPE, ST_ELEMENT_TYPE_VOID can be defined. Then
+ * the generated functions will automatically gain an "element_size"
+ * parameter. This allows us to generate a traditional qsort function.
+ *
+ * One of the following macros must be defined, to show how to compare
+ * elements. The first two options are arbitrary expressions depending
+ * on whether an extra pass-through argument is desired, and the third
+ * option should be defined if the sort function should receive a
+ * function pointer at runtime.
+ *
+ * - ST_COMPARE(a, b) - a simple comparison expression
+ * - ST_COMPARE(a, b, arg) - variant that takes an extra argument
+ * - ST_COMPARE_RUNTIME_POINTER - sort function takes a function pointer
+ *
+ * To say that the comparator and therefore also sort function should
+ * receive an extra pass-through argument, specify the type of the
+ * argument.
+ *
+ * - ST_COMPARE_ARG_TYPE - type of extra argument
+ *
+ * The prototype of the generated sort function is:
+ *
+ * void ST_SORT(ST_ELEMENT_TYPE *data, size_t n,
+ * [size_t element_size,]
+ * [ST_SORT_compare_function compare,]
+ * [ST_COMPARE_ARG_TYPE *arg]);
+ *
+ * ST_SORT_compare_function is a function pointer of the following type:
+ *
+ * int (*)(const ST_ELEMENT_TYPE *a, const ST_ELEMENT_TYPE *b,
+ * [ST_COMPARE_ARG_TYPE *arg])
+ *
+ * HISTORY
+ *
+ * Modifications from vanilla NetBSD source:
+ * - Add do ... while() macro fix
+ * - Remove __inline, _DIAGASSERTs, __P
+ * - Remove ill-considered "swap_cnt" switch to insertion sort, in favor
+ * of a simple check for presorted input.
+ * - Take care to recurse on the smaller partition, to bound stack usage
+ * - Convert into a header that can generate specialized functions
+ *
+ * IDENTIFICATION
+ * src/include/lib/sort_template.h
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/* $NetBSD: qsort.c,v 1.13 2003/08/07 16:43:42 agc Exp $ */
+
+/*-
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Qsort routine based on J. L. Bentley and M. D. McIlroy,
+ * "Engineering a sort function",
+ * Software--Practice and Experience 23 (1993) 1249-1265.
+ *
+ * We have modified their original by adding a check for already-sorted
+ * input, which seems to be a win per discussions on pgsql-hackers around
+ * 2006-03-21.
+ *
+ * Also, we recurse on the smaller partition and iterate on the larger one,
+ * which ensures we cannot recurse more than log(N) levels (since the
+ * partition recursed to is surely no more than half of the input). Bentley
+ * and McIlroy explicitly rejected doing this on the grounds that it's "not
+ * worth the effort", but we have seen crashes in the field due to stack
+ * overrun, so that judgment seems wrong.
+ */
+
+#define ST_MAKE_PREFIX(a) CppConcat(a,_)
+#define ST_MAKE_NAME(a,b) ST_MAKE_NAME_(ST_MAKE_PREFIX(a),b)
+#define ST_MAKE_NAME_(a,b) CppConcat(a,b)
+
+/*
+ * If the element type is void, we'll also need an element_size argument
+ * because we don't know the size.
+ */
+#ifdef ST_ELEMENT_TYPE_VOID
+#define ST_ELEMENT_TYPE void
+#define ST_SORT_PROTO_SIZE , size_t element_size
+#define ST_SORT_INVOKE_SIZE , element_size
+#else
+#define ST_SORT_PROTO_SIZE
+#define ST_SORT_INVOKE_SIZE
+#endif
+
+/*
+ * If the user wants to be able to pass in compare functions at runtime,
+ * we'll need to make that an argument of the sort and med3 functions.
+ */
+#ifdef ST_COMPARE_RUNTIME_POINTER
+/*
+ * The type of the comparator function pointer that ST_SORT will take, unless
+ * you've already declared a type name manually and want to use that instead of
+ * having a new one defined.
+ */
+#ifndef ST_COMPARATOR_TYPE_NAME
+#define ST_COMPARATOR_TYPE_NAME ST_MAKE_NAME(ST_SORT, compare_function)
+#endif
+#define ST_COMPARE compare
+#ifndef ST_COMPARE_ARG_TYPE
+#define ST_SORT_PROTO_COMPARE , ST_COMPARATOR_TYPE_NAME compare
+#define ST_SORT_INVOKE_COMPARE , compare
+#else
+#define ST_SORT_PROTO_COMPARE , ST_COMPARATOR_TYPE_NAME compare
+#define ST_SORT_INVOKE_COMPARE , compare
+#endif
+#else
+#define ST_SORT_PROTO_COMPARE
+#define ST_SORT_INVOKE_COMPARE
+#endif
+
+/*
+ * If the user wants to use a compare function or expression that takes an
+ * extra argument, we'll need to make that an argument of the sort, compare and
+ * med3 functions.
+ */
+#ifdef ST_COMPARE_ARG_TYPE
+#define ST_SORT_PROTO_ARG , ST_COMPARE_ARG_TYPE *arg
+#define ST_SORT_INVOKE_ARG , arg
+#else
+#define ST_SORT_PROTO_ARG
+#define ST_SORT_INVOKE_ARG
+#endif
+
+#ifdef ST_DECLARE
+
+#ifdef ST_COMPARE_RUNTIME_POINTER
+typedef int (*ST_COMPARATOR_TYPE_NAME)(const ST_ELEMENT_TYPE *,
+ const ST_ELEMENT_TYPE *
+ ST_SORT_PROTO_ARG);
+#endif
+
+/* Declare the sort function. Note optional arguments at end. */
+ST_SCOPE void ST_SORT(ST_ELEMENT_TYPE *first, size_t n
+ ST_SORT_PROTO_SIZE
+ ST_SORT_PROTO_COMPARE
+ ST_SORT_PROTO_ARG);
+
+#endif
+
+#ifdef ST_DEFINE
+
+/* sort private helper functions */
+#define ST_MED3 ST_MAKE_NAME(ST_SORT, med3)
+#define ST_SWAP ST_MAKE_NAME(ST_SORT, swap)
+#define ST_SWAPN ST_MAKE_NAME(ST_SORT, swapn)
+
+/* Users expecting to run very large sorts may need them to be interruptible. */
+#ifdef ST_CHECK_FOR_INTERRUPTS
+#define DO_CHECK_FOR_INTERRUPTS() CHECK_FOR_INTERRUPTS()
+#else
+#define DO_CHECK_FOR_INTERRUPTS()
+#endif
+
+/*
+ * Create wrapper macros that know how to invoke compare, med3 and sort with
+ * the right arguments.
+ */
+#ifdef ST_COMPARE_RUNTIME_POINTER
+#define DO_COMPARE(a_, b_) ST_COMPARE((a_), (b_) ST_SORT_INVOKE_ARG)
+#elif defined(ST_COMPARE_ARG_TYPE)
+#define DO_COMPARE(a_, b_) ST_COMPARE((a_), (b_), arg)
+#else
+#define DO_COMPARE(a_, b_) ST_COMPARE((a_), (b_))
+#endif
+#define DO_MED3(a_, b_, c_) \
+ ST_MED3((a_), (b_), (c_) \
+ ST_SORT_INVOKE_COMPARE \
+ ST_SORT_INVOKE_ARG)
+#define DO_SORT(a_, n_) \
+ ST_SORT((a_), (n_) \
+ ST_SORT_INVOKE_SIZE \
+ ST_SORT_INVOKE_COMPARE \
+ ST_SORT_INVOKE_ARG)
+
+/*
+ * If we're working with void pointers, we'll use pointer arithmetic based on
+ * uint8, and use the runtime element_size to step through the array and swap
+ * elements. Otherwise we'll work with ST_ELEMENT_TYPE.
+ */
+#ifndef ST_ELEMENT_TYPE_VOID
+#define ST_POINTER_TYPE ST_ELEMENT_TYPE
+#define ST_POINTER_STEP 1
+#define DO_SWAPN(a_, b_, n_) ST_SWAPN((a_), (b_), (n_))
+#define DO_SWAP(a_, b_) ST_SWAP((a_), (b_))
+#else
+#define ST_POINTER_TYPE uint8
+#define ST_POINTER_STEP element_size
+#define DO_SWAPN(a_, b_, n_) ST_SWAPN((a_), (b_), (n_))
+#define DO_SWAP(a_, b_) DO_SWAPN((a_), (b_), element_size)
+#endif
+
+/*
+ * Find the median of three values. Currently, performance seems to be best
+ * if the the comparator is inlined here, but the med3 function is not inlined
+ * in the qsort function.
+ */
+static pg_noinline ST_ELEMENT_TYPE *
+ST_MED3(ST_ELEMENT_TYPE *a,
+ ST_ELEMENT_TYPE *b,
+ ST_ELEMENT_TYPE *c
+ ST_SORT_PROTO_COMPARE
+ ST_SORT_PROTO_ARG)
+{
+ return DO_COMPARE(a, b) < 0 ?
+ (DO_COMPARE(b, c) < 0 ? b : (DO_COMPARE(a, c) < 0 ? c : a))
+ : (DO_COMPARE(b, c) > 0 ? b : (DO_COMPARE(a, c) < 0 ? a : c));
+}
+
+static inline void
+ST_SWAP(ST_POINTER_TYPE *a, ST_POINTER_TYPE *b)
+{
+ ST_POINTER_TYPE tmp = *a;
+
+ *a = *b;
+ *b = tmp;
+}
+
+static inline void
+ST_SWAPN(ST_POINTER_TYPE *a, ST_POINTER_TYPE *b, size_t n)
+{
+ for (size_t i = 0; i < n; ++i)
+ ST_SWAP(&a[i], &b[i]);
+}
+
+/*
+ * Sort an array.
+ */
+ST_SCOPE void
+ST_SORT(ST_ELEMENT_TYPE *data, size_t n
+ ST_SORT_PROTO_SIZE
+ ST_SORT_PROTO_COMPARE
+ ST_SORT_PROTO_ARG)
+{
+ ST_POINTER_TYPE *a = (ST_POINTER_TYPE *) data,
+ *pa,
+ *pb,
+ *pc,
+ *pd,
+ *pl,
+ *pm,
+ *pn;
+ size_t d1,
+ d2;
+ int r,
+ presorted;
+
+loop:
+ DO_CHECK_FOR_INTERRUPTS();
+ if (n < 7)
+ {
+ for (pm = a + ST_POINTER_STEP; pm < a + n * ST_POINTER_STEP;
+ pm += ST_POINTER_STEP)
+ for (pl = pm; pl > a && DO_COMPARE(pl - ST_POINTER_STEP, pl) > 0;
+ pl -= ST_POINTER_STEP)
+ DO_SWAP(pl, pl - ST_POINTER_STEP);
+ return;
+ }
+ presorted = 1;
+ for (pm = a + ST_POINTER_STEP; pm < a + n * ST_POINTER_STEP;
+ pm += ST_POINTER_STEP)
+ {
+ DO_CHECK_FOR_INTERRUPTS();
+ if (DO_COMPARE(pm - ST_POINTER_STEP, pm) > 0)
+ {
+ presorted = 0;
+ break;
+ }
+ }
+ if (presorted)
+ return;
+ pm = a + (n / 2) * ST_POINTER_STEP;
+ if (n > 7)
+ {
+ pl = a;
+ pn = a + (n - 1) * ST_POINTER_STEP;
+ if (n > 40)
+ {
+ size_t d = (n / 8) * ST_POINTER_STEP;
+
+ pl = DO_MED3(pl, pl + d, pl + 2 * d);
+ pm = DO_MED3(pm - d, pm, pm + d);
+ pn = DO_MED3(pn - 2 * d, pn - d, pn);
+ }
+ pm = DO_MED3(pl, pm, pn);
+ }
+ DO_SWAP(a, pm);
+ pa = pb = a + ST_POINTER_STEP;
+ pc = pd = a + (n - 1) * ST_POINTER_STEP;
+ for (;;)
+ {
+ while (pb <= pc && (r = DO_COMPARE(pb, a)) <= 0)
+ {
+ if (r == 0)
+ {
+ DO_SWAP(pa, pb);
+ pa += ST_POINTER_STEP;
+ }
+ pb += ST_POINTER_STEP;
+ DO_CHECK_FOR_INTERRUPTS();
+ }
+ while (pb <= pc && (r = DO_COMPARE(pc, a)) >= 0)
+ {
+ if (r == 0)
+ {
+ DO_SWAP(pc, pd);
+ pd -= ST_POINTER_STEP;
+ }
+ pc -= ST_POINTER_STEP;
+ DO_CHECK_FOR_INTERRUPTS();
+ }
+ if (pb > pc)
+ break;
+ DO_SWAP(pb, pc);
+ pb += ST_POINTER_STEP;
+ pc -= ST_POINTER_STEP;
+ }
+ pn = a + n * ST_POINTER_STEP;
+ d1 = Min(pa - a, pb - pa);
+ DO_SWAPN(a, pb - d1, d1);
+ d1 = Min(pd - pc, pn - pd - ST_POINTER_STEP);
+ DO_SWAPN(pb, pn - d1, d1);
+ d1 = pb - pa;
+ d2 = pd - pc;
+ if (d1 <= d2)
+ {
+ /* Recurse on left partition, then iterate on right partition */
+ if (d1 > ST_POINTER_STEP)
+ DO_SORT(a, d1 / ST_POINTER_STEP);
+ if (d2 > ST_POINTER_STEP)
+ {
+ /* Iterate rather than recurse to save stack space */
+ /* DO_SORT(pn - d2, d2 / ST_POINTER_STEP) */
+ a = pn - d2;
+ n = d2 / ST_POINTER_STEP;
+ goto loop;
+ }
+ }
+ else
+ {
+ /* Recurse on right partition, then iterate on left partition */
+ if (d2 > ST_POINTER_STEP)
+ DO_SORT(pn - d2, d2 / ST_POINTER_STEP);
+ if (d1 > ST_POINTER_STEP)
+ {
+ /* Iterate rather than recurse to save stack space */
+ /* DO_SORT(a, d1 / ST_POINTER_STEP) */
+ n = d1 / ST_POINTER_STEP;
+ goto loop;
+ }
+ }
+}
+#endif
+
+#undef DO_COMPARE
+#undef DO_MED3
+#undef DO_SORT
+#undef DO_SWAP
+#undef DO_SWAPN
+#undef ST_COMPARATOR_TYPE_NAME
+#undef ST_COMPARE
+#undef ST_COMPARE_ARG_TYPE
+#undef ST_COMPARE_RUNTIME_POINTER
+#undef ST_ELEMENT_TYPE
+#undef ST_ELEMENT_TYPE_VOID
+#undef ST_MAKE_NAME
+#undef ST_MAKE_NAME_
+#undef ST_MAKE_PREFIX
+#undef ST_MED3
+#undef ST_POINTER_STEP
+#undef ST_POINTER_TYPE
+#undef ST_SORT
+#undef ST_SORT_INVOKE_ARG
+#undef ST_SORT_INVOKE_COMPARE
+#undef ST_SORT_INVOKE_SIZE
+#undef ST_SORT_PROTO_ARG
+#undef ST_SORT_PROTO_COMPARE
+#undef ST_SORT_PROTO_SIZE
+#undef ST_SWAP
+#undef ST_SWAPN
--
2.25.1
[application/octet-stream] v5-0002-Add-delete-deduplication-to-nbtree.patch (86.1K, ../../CAH2-Wzkaj6OhVSvB46t_ybosd0cH1Qaiao+0dSopGUDmEM37Hw@mail.gmail.com/3-v5-0002-Add-delete-deduplication-to-nbtree.patch)
download | inline diff:
From 7709510dab61f471b0a182a325adc39fe0cb63d4 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Tue, 30 Jun 2020 16:29:27 -0700
Subject: [PATCH v5 2/2] Add delete deduplication to nbtree.
Repurpose deduplication infrastructure to delete items in indexes at the
point where we'd usually have to split the page, even when they don't
have their LP_DEAD bits set. Testing has shown that this is almost
completely effective at preventing "version index bloat" from non-HOT
updates, provided there are no long running transactions.
This is primarily valuable with leaf pages that contain mostly-distinct
index tuples, particularly with unique indexes. It is intended to
complement deduplication. Heuristics are used to guess which index
tuples are likely to point to no longer needed old table row versions.
Note that INCLUDE indexes support the optimization.
---
src/include/access/genam.h | 15 +
src/include/access/heapam.h | 8 +-
src/include/access/nbtree.h | 11 +-
src/include/access/nbtxlog.h | 7 +-
src/include/access/tableam.h | 53 +-
src/include/executor/executor.h | 3 +-
src/backend/access/heap/heapam.c | 406 ++++++++++++-
src/backend/access/heap/heapam_handler.c | 5 +-
src/backend/access/nbtree/README | 33 +-
src/backend/access/nbtree/nbtdedup.c | 707 +++++++++++++++++++++--
src/backend/access/nbtree/nbtinsert.c | 62 +-
src/backend/access/nbtree/nbtpage.c | 122 +++-
src/backend/access/nbtree/nbtsort.c | 12 +-
src/backend/access/nbtree/nbtxlog.c | 55 +-
src/backend/access/table/tableam.c | 30 +-
src/backend/commands/copy.c | 5 +-
src/backend/executor/execIndexing.c | 41 +-
src/backend/executor/execReplication.c | 4 +-
src/backend/executor/nodeModifyTable.c | 14 +-
19 files changed, 1475 insertions(+), 118 deletions(-)
diff --git a/src/include/access/genam.h b/src/include/access/genam.h
index 68d90f5141..7002da0716 100644
--- a/src/include/access/genam.h
+++ b/src/include/access/genam.h
@@ -108,10 +108,25 @@ typedef struct ParallelIndexScanDescData *ParallelIndexScanDesc;
* call is made with UNIQUE_CHECK_EXISTING. The tuple is already in the
* index in this case, so it should not be inserted again. Rather, just
* check for conflicting live tuples (possibly blocking).
+ *
+ * UNIQUE_CHECK_NO indicates the absence of any unique checking.
+ * UNIQUE_CHECK_NO_WITH_UNCHANGED is a variant of UNIQUE_CHECK_NO that
+ * indicates that the index tuple comes from an UPDATE that did not modify
+ * the row in respect of any columns that are indexed. The implementation
+ * requires a successor version, but there is no logical change. Some
+ * index access AMs can use this as hint that can trigger optimizations.
+ *
+ * XXX: Adding UNIQUE_CHECK_NO_WITH_UNCHANGED like this kind of makes
+ * sense, since it's pretty natural to leave it up to index AMs to figure
+ * it out with unique indexes. But what about when we insert NULLs into a
+ * unique index? Isn't that case UNIQUE_CHECK_YES, and yet also a thing
+ * that nbtree pretty much treats as UNIQUE_CHECK_NO once it sees that the
+ * index tuple has NULLs?
*/
typedef enum IndexUniqueCheck
{
UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */
+ UNIQUE_CHECK_NO_WITH_UNCHANGED, /* "No logical change" duplicate */
UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */
UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */
UNIQUE_CHECK_EXISTING /* Check if existing tuple is unique */
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 92b19dba32..7713110ebe 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -148,7 +148,8 @@ extern void heap_abort_speculative(Relation relation, ItemPointer tid);
extern TM_Result heap_update(Relation relation, ItemPointer otid,
HeapTuple newtup,
CommandId cid, Snapshot crosscheck, bool wait,
- struct TM_FailureData *tmfd, LockTupleMode *lockmode);
+ struct TM_FailureData *tmfd, LockTupleMode *lockmode,
+ Bitmapset **modified_attrs_hint);
extern TM_Result heap_lock_tuple(Relation relation, HeapTuple tuple,
CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy,
bool follow_update,
@@ -170,6 +171,11 @@ extern void simple_heap_update(Relation relation, ItemPointer otid,
extern TransactionId heap_compute_xid_horizon_for_tuples(Relation rel,
ItemPointerData *items,
int nitems);
+extern TransactionId heap_index_batch_check(Relation rel, TM_IndexDelete *deltids,
+ TM_IndexDeleteStatus *statusdeltids,
+ int ndeltids, Snapshot snapshot,
+ int minscore, bool uniqueindex,
+ int *ntiddeletes, int *finalndeltids);
/* in heap/pruneheap.c */
struct GlobalVisState;
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index 65d9698b89..b2279cccb2 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -77,6 +77,7 @@ typedef BTPageOpaqueData *BTPageOpaque;
#define BTP_SPLIT_END (1 << 5) /* rightmost page of split group */
#define BTP_HAS_GARBAGE (1 << 6) /* page has LP_DEAD tuples */
#define BTP_INCOMPLETE_SPLIT (1 << 7) /* right sibling's downlink is missing */
+#define BTP_HAS_DUPS (1 << 8) /* page has at least one version duplicate */
/*
* The max allowed value of a cycle ID is a bit less than 64K. This is
@@ -219,6 +220,7 @@ typedef struct BTMetaPageData
#define P_IGNORE(opaque) (((opaque)->btpo_flags & (BTP_DELETED|BTP_HALF_DEAD)) != 0)
#define P_HAS_GARBAGE(opaque) (((opaque)->btpo_flags & BTP_HAS_GARBAGE) != 0)
#define P_INCOMPLETE_SPLIT(opaque) (((opaque)->btpo_flags & BTP_INCOMPLETE_SPLIT) != 0)
+#define P_HAS_DUPS(opaque) (((opaque)->btpo_flags & BTP_HAS_DUPS) != 0)
/*
* Lehman and Yao's algorithm requires a ``high key'' on every non-rightmost
@@ -1029,11 +1031,12 @@ extern void _bt_parallel_advance_array_keys(IndexScanDesc scan);
*/
extern void _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
IndexTuple newitem, Size newitemsz,
- bool checkingunique);
+ bool checkingunique, bool dedupdelete,
+ bool allequalimage);
extern void _bt_dedup_start_pending(BTDedupState state, IndexTuple base,
OffsetNumber baseoff);
extern bool _bt_dedup_save_htid(BTDedupState state, IndexTuple itup);
-extern Size _bt_dedup_finish_pending(Page newpage, BTDedupState state);
+extern Size _bt_dedup_merge_finish_pending(Page newpage, BTDedupState state);
extern IndexTuple _bt_form_posting(IndexTuple base, ItemPointer htids,
int nhtids);
extern void _bt_update_posting(BTVacuumPosting vacposting);
@@ -1084,7 +1087,9 @@ extern void _bt_delitems_vacuum(Relation rel, Buffer buf,
BTVacuumPosting *updatable, int nupdatable);
extern void _bt_delitems_delete(Relation rel, Buffer buf,
OffsetNumber *deletable, int ndeletable,
- Relation heapRel);
+ BTVacuumPosting *updatable, int nupdatable,
+ Relation heapRel, bool isdedup,
+ TransactionId dedupLatestRemovedXid);
extern uint32 _bt_pagedel(Relation rel, Buffer leafbuf,
TransactionId *oldestBtpoXact);
diff --git a/src/include/access/nbtxlog.h b/src/include/access/nbtxlog.h
index 5c014bdc66..1fd047bc66 100644
--- a/src/include/access/nbtxlog.h
+++ b/src/include/access/nbtxlog.h
@@ -187,12 +187,15 @@ typedef struct xl_btree_dedup
typedef struct xl_btree_delete
{
TransactionId latestRemovedXid;
- uint32 ndeleted;
+ uint16 ndeleted;
+ uint16 nupdated;
/* DELETED TARGET OFFSET NUMBERS FOLLOW */
+ /* UPDATED TARGET OFFSET NUMBERS FOLLOW */
+ /* UPDATED TUPLES METADATA ARRAY FOLLOWS */
} xl_btree_delete;
-#define SizeOfBtreeDelete (offsetof(xl_btree_delete, ndeleted) + sizeof(uint32))
+#define SizeOfBtreeDelete (offsetof(xl_btree_delete, nupdated) + sizeof(uint16))
/*
* This is what we need to know about page reuse within btree. This record
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 387eb34a61..e90c6a55ff 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -128,6 +128,28 @@ typedef struct TM_FailureData
bool traversed;
} TM_FailureData;
+/*
+ * State used by table_index_batch_check() to perform "bottom up" deletion of
+ * duplicate index tuples.
+ *
+ * We store this in two structs, even though it would be more natural to just
+ * have one struct (and one array). We really need to keep the TM_IndexDelete
+ * struct small (8 bytes) so that we can do an initial sort by TID as quickly
+ * as possible.
+ */
+typedef struct TM_IndexDelete
+{
+ ItemPointerData tid; /* table TID from index tuple */
+ int16 id; /* Offset into TM_IndexDeleteStatus array */
+} TM_IndexDelete;
+
+typedef struct TM_IndexDeleteStatus
+{
+ OffsetNumber ioffnum; /* Index am identifies entries with this */
+ bool ispromising; /* Contribute to order we visit table blocks? */
+ bool isdead; /* Was tuple found dead? */
+} TM_IndexDeleteStatus;
+
/* "options" flag bits for table_tuple_insert */
/* TABLE_INSERT_SKIP_WAL was 0x0001; RelationNeedsWAL() now governs */
#define TABLE_INSERT_SKIP_FSM 0x0002
@@ -396,7 +418,8 @@ typedef struct TableAmRoutine
bool wait,
TM_FailureData *tmfd,
LockTupleMode *lockmode,
- bool *update_indexes);
+ bool *update_indexes,
+ Bitmapset **modified_attrs_hint);
/* see table_tuple_lock() for reference about parameters */
TM_Result (*tuple_lock) (Relation rel,
@@ -1041,16 +1064,31 @@ table_index_fetch_tuple(struct IndexFetchTableData *scan,
}
/*
- * This is a convenience wrapper around table_index_fetch_tuple() which
- * returns whether there are table tuple items corresponding to an index
- * entry. This likely is only useful to verify if there's a conflict in a
- * unique index.
+ * These are convenience wrappers around table_index_fetch_tuple() which
+ * indicate whether there are table tuple items corresponding to an index
+ * entry. Can be used to verify if there's a conflict in a unique index.
+ *
+ * table_index_batch_check() is a variant that is specialized to garbage
+ * collection of dead tuples in index access methods. Duplicates are
+ * commonly caused by MVCC version churn when an optimization like
+ * heapam's HOT cannot be applied. It can make sense to opportunistically
+ * guess that many index tuples are dead versions, particularly in unique
+ * indexes.
+ *
+ * Note that table_index_batch_check() sorts the deltids array so that the
+ * order of access is optimized. Callers need to be able to deal with
+ * that.
*/
extern bool table_index_fetch_tuple_check(Relation rel,
ItemPointer tid,
Snapshot snapshot,
bool *all_dead);
+extern int table_index_batch_check(Relation rel,
+ TM_IndexDelete *deltids,
+ int ndeltids,
+ Snapshot snapshot,
+ int npromisingkillsneeded);
/* ------------------------------------------------------------------------
* Functions for non-modifying operations on individual tuples
@@ -1311,12 +1349,13 @@ static inline TM_Result
table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot,
CommandId cid, Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode,
- bool *update_indexes)
+ bool *update_indexes, Bitmapset **modified_attrs_hint)
{
return rel->rd_tableam->tuple_update(rel, otid, slot,
cid, snapshot, crosscheck,
wait, tmfd,
- lockmode, update_indexes);
+ lockmode, update_indexes,
+ modified_attrs_hint);
}
/*
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h
index 0c48d2a519..6e6e56583b 100644
--- a/src/include/executor/executor.h
+++ b/src/include/executor/executor.h
@@ -582,7 +582,8 @@ extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
extern List *ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot, EState *estate,
bool noDupErr,
- bool *specConflict, List *arbiterIndexes);
+ bool *specConflict, List *arbiterIndexes,
+ Bitmapset *modified_attrs_hint);
extern bool ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot,
EState *estate, ItemPointer conflictTid,
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 1585861a02..11041d09ad 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -70,6 +70,12 @@
#include "utils/snapmgr.h"
#include "utils/spccache.h"
+typedef struct IndexDeleteCounts
+{
+ BlockNumber block;
+ int16 npromisingtids;
+ int16 ntids;
+} IndexDeleteCounts;
static HeapTuple heap_prepare_insert(Relation relation, HeapTuple tup,
TransactionId xid, CommandId cid, int options);
@@ -102,6 +108,13 @@ static void MultiXactIdWait(MultiXactId multi, MultiXactStatus status, uint16 in
int *remaining);
static bool ConditionalMultiXactIdWait(MultiXactId multi, MultiXactStatus status,
uint16 infomask, Relation rel, int *remaining);
+static int heap_index_batch_check_block_sort(TM_IndexDelete *deltids,
+ TM_IndexDeleteStatus *statusdeltids,
+ int ndeltids);
+static inline int indexdelete_tids_cmp(TM_IndexDelete *indexdelete1,
+ TM_IndexDelete *indexdelete2);
+static inline int indexdeletecount_ntids_cmp(IndexDeleteCounts *count1,
+ IndexDeleteCounts *count2);
static XLogRecPtr log_heap_new_cid(Relation relation, HeapTuple tup);
static HeapTuple ExtractReplicaIdentity(Relation rel, HeapTuple tup, bool key_changed,
bool *copy);
@@ -2892,7 +2905,8 @@ simple_heap_delete(Relation relation, ItemPointer tid)
TM_Result
heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
CommandId cid, Snapshot crosscheck, bool wait,
- TM_FailureData *tmfd, LockTupleMode *lockmode)
+ TM_FailureData *tmfd, LockTupleMode *lockmode,
+ Bitmapset **modified_attrs_hint)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -3758,10 +3772,15 @@ l2:
if (old_key_tuple != NULL && old_key_copied)
heap_freetuple(old_key_tuple);
+ /* Save for no logical changes hint when non-HOT update performed */
+ if (!use_hot_update && modified_attrs_hint)
+ *modified_attrs_hint = modified_attrs;
+ else
+ bms_free(modified_attrs);
+
bms_free(hot_attrs);
bms_free(key_attrs);
bms_free(id_attrs);
- bms_free(modified_attrs);
bms_free(interesting_attrs);
return TM_Ok;
@@ -3891,7 +3910,7 @@ simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
result = heap_update(relation, otid, tup,
GetCurrentCommandId(true), InvalidSnapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode);
+ &tmfd, &lockmode, NULL);
switch (result)
{
case TM_SelfModified:
@@ -6987,6 +7006,9 @@ xid_horizon_prefetch_buffer(Relation rel,
* deleting hundreds of tuples from a single index block. To amortize that
* cost to some degree, this uses prefetching and combines repeat accesses to
* the same block.
+ *
+ * Note: The logic for maintaining latestRemovedXid here is duplicated by code
+ * within heap_index_batch_check(). Make sure that they stay in sync.
*/
TransactionId
heap_compute_xid_horizon_for_tuples(Relation rel,
@@ -7086,7 +7108,6 @@ heap_compute_xid_horizon_for_tuples(Relation rel,
{
hoffnum = ItemIdGetRedirect(hitemid);
hitemid = PageGetItemId(hpage, hoffnum);
- CHECK_FOR_INTERRUPTS();
}
/*
@@ -7134,6 +7155,383 @@ heap_compute_xid_horizon_for_tuples(Relation rel,
return latestRemovedXid;
}
+/*
+ * Help with "bottom up" deletion of duplicate index tuples from index AMs.
+ * This is particularly likely to work well with unique indexes.
+ *
+ * This routine sorts the deltids array, but does not modify any individual
+ * entry except to mark it as dead for caller. *ntiddeletes is set to the
+ * number of items marked dead in caller's deltids array. *finaldeltids is
+ * set to the size of the subset of the final sorted deltids array that
+ * contains all entries marked dead for caller (the subset begins at the
+ * start of deltids and ends after *finaldeltids array elements). Caller
+ * will only need to consider this interesting subset of deltids, but note
+ * that only some of the subset's elements are actually marked dead/safe to
+ * delete in index.
+ *
+ * Returns the latestRemovedXid from the heap pages pointed at by the deltids
+ * index tuples that caller will delete. Caller deletes all deltids related
+ * index tuples that get marked dead here, and uses latestRemovedXid to
+ * generate a recovery conflict (if and when a conflict is required).
+ *
+ * Note: The logic for maintaining latestRemovedXid here is duplicated by code
+ * within heap_compute_xid_horizon_for_tuples(). Make sure that they stay in
+ * sync.
+ */
+TransactionId
+heap_index_batch_check(Relation rel, TM_IndexDelete *deltids,
+ TM_IndexDeleteStatus *statusdeltids, int ndeltids,
+ Snapshot snapshot, int minscore, bool uniqueindex,
+ int *ntiddeletes, int *finalndeltids)
+{
+ TransactionId latestRemovedXid = InvalidTransactionId;
+ BlockNumber hblkno = InvalidBlockNumber;
+ Buffer buf = InvalidBuffer;
+ Page hpage;
+ bool finalhpage = false;
+ int nblocksaccessed = 0;
+ int score = 0;
+
+ *ntiddeletes = 0;
+ *finalndeltids = 0;
+
+ /*
+ * Sort and shrink deltids array so that it consists only of TIDs from 3
+ * most promising blocks. We expect the most promising block first (and
+ * third most promising block third/last).
+ */
+ ndeltids = heap_index_batch_check_block_sort(deltids, statusdeltids,
+ ndeltids);
+ for (int i = 0; i < ndeltids; i++)
+ {
+ TM_IndexDeleteStatus *status = statusdeltids + deltids[i].id;
+ ItemPointer htid = &deltids[i].tid;
+ ItemPointerData tmp;
+ bool all_dead = false;
+ bool found;
+ ItemId hitemid;
+ OffsetNumber hoffnum;
+ HeapTupleData heapTuple;
+
+ Assert(!status->isdead);
+
+ if (hblkno == InvalidBlockNumber ||
+ ItemPointerGetBlockNumber(htid) != hblkno)
+ {
+ /*
+ * We usually do a little extra work on the final heap page after
+ * caller's minimum required score has been reached. The cost of
+ * accessing the final heap page we'll need to visit has already
+ * been paid by that point. We finish off the entire final heap
+ * page because it's cheap to do so.
+ *
+ * We don't want to unnecessarily visit the next page in line.
+ * Handle that here (when we just finished final page).
+ */
+ if (finalhpage)
+ break;
+
+ /*
+ * Each time we're about to access a new page we consider if it's
+ * really worth it. We apply various tests before we visit the
+ * next page, and give up if any test fails. These tests are:
+ *
+ * 1. Give up when we'd otherwise access the second heap page in
+ * line and have nothing to show for accessing the first/"most
+ * promising" page. But only with a unique index, where not
+ * finding items that are safe to delete in the first heap page
+ * accessed is considered a particularly discouraging sign.
+ *
+ * 2. Give up when we'd otherwise access the third heap page in
+ * line and have nothing to show for it in the case of non-unique
+ * indexes. The policy is more lax here because there is a small
+ * chance that we'll get unlucky on the first heap page when
+ * caller cannot easily distinguish between version churn and
+ * multiple logical rows. But two heap pages accessed at the same
+ * time with nothing to delete from either is close to a sure sign
+ * that accessing a third heap page would be wasted effort.
+ *
+ * 3. Give up before accessing a fourth page, no matter what.
+ * (This last test is defensive, since the deltids array was
+ * shrunk, and now only contains TIDs from the three most
+ * promising blocks.)
+ */
+ if (uniqueindex && nblocksaccessed == 1 && score == 0)
+ break;
+ if (!uniqueindex && nblocksaccessed == 2 && score == 0)
+ break;
+ if (nblocksaccessed == 3)
+ break;
+
+ /* Now access next page */
+ if (BufferIsValid(buf))
+ {
+ LockBuffer(buf, BUFFER_LOCK_UNLOCK);
+ ReleaseBuffer(buf);
+ }
+
+ /*
+ * We could prune the heap page in passing here, but that doesn't
+ * seem like a good idea. Caller holds locks of its own.
+ */
+ hblkno = ItemPointerGetBlockNumber(htid);
+ buf = ReadBuffer(rel, hblkno);
+ hpage = BufferGetPage(buf);
+ nblocksaccessed++;
+
+ /* Need to lock buffer for visibility checks */
+ LockBuffer(buf, BUFFER_LOCK_SHARE);
+ }
+
+ tmp = *htid;
+ found = heap_hot_search_buffer(&tmp, rel, buf, snapshot, &heapTuple,
+ &all_dead, true);
+
+ if (found || !all_dead)
+ continue;
+
+ /* Caller can delete this TID from index */
+ *finalndeltids = i + 1;
+ (*ntiddeletes)++;
+ status->isdead = true;
+ if (status->ispromising)
+ score += 2;
+ else
+ score++;
+
+ if (score >= minscore)
+ {
+ /*
+ * Caller's score requirement has now been met. Finish off the
+ * current/final heap page before finishing.
+ */
+ finalhpage = true;
+ }
+
+ /*
+ * One last step required for TID that caller will delete. Must
+ * maintain latestRemovedXid for caller's delete operation.
+ */
+ hoffnum = ItemPointerGetOffsetNumber(htid);
+ hitemid = PageGetItemId(hpage, hoffnum);
+
+ while (ItemIdIsRedirected(hitemid))
+ {
+ hoffnum = ItemIdGetRedirect(hitemid);
+ hitemid = PageGetItemId(hpage, hoffnum);
+ }
+
+ /*
+ * If the heap item has storage, then read the header and use that to
+ * set latestRemovedXid.
+ *
+ * Some LP_DEAD items may not be accessible, so we ignore them.
+ */
+ if (ItemIdHasStorage(hitemid))
+ {
+ HeapTupleHeader htuphdr;
+
+ htuphdr = (HeapTupleHeader) PageGetItem(hpage, hitemid);
+
+ HeapTupleHeaderAdvanceLatestRemovedXid(htuphdr, &latestRemovedXid);
+ }
+ else if (ItemIdIsDead(hitemid))
+ {
+ /*
+ * Conjecture: if hitemid is dead then it had xids before the xids
+ * marked on LP_NORMAL items. So we just ignore this item and move
+ * onto the next, for the purposes of calculating
+ * latestRemovedXid.
+ */
+ }
+ else
+ Assert(!ItemIdIsUsed(hitemid));
+ }
+
+ if (BufferIsValid(buf))
+ {
+ LockBuffer(buf, BUFFER_LOCK_UNLOCK);
+ ReleaseBuffer(buf);
+ }
+
+ /*
+ * If all heap tuples were LP_DEAD then we will be returning
+ * InvalidTransactionId here, which avoids conflicts. This matches
+ * existing logic which assumes that LP_DEAD tuples must already be older
+ * than the latestRemovedXid on the cleanup record that set them as
+ * LP_DEAD, hence must already have generated a conflict.
+ */
+
+ return latestRemovedXid;
+}
+
+#define ST_SORT qsort_deltids_by_tid
+#define ST_ELEMENT_TYPE TM_IndexDelete
+#define ST_COMPARE(a, b) (indexdelete_tids_cmp(a, b))
+#define ST_SCOPE static
+#define ST_DEFINE
+#include "lib/sort_template.h"
+
+#define ST_SORT qsort_blockgroup
+#define ST_ELEMENT_TYPE IndexDeleteCounts
+#define ST_COMPARE(a, b) (indexdeletecount_ntids_cmp(a, b))
+#define ST_SCOPE static
+#define ST_DEFINE
+#include "lib/sort_template.h"
+
+/*
+ * heap_index_batch_check() helper function. Sorts deltids array in the
+ * order needed for useful processing.
+ *
+ * Groups heap TIDs from deltids into heap block number groupings. From
+ * there, sorts each heap block grouping by the total number of "promising"
+ * TIDs it contains (in desc order). For blocks with the same number of
+ * promising TIDs, tiebreak on the total heap TID count (also desc order).
+ *
+ * heap_index_batch_check() only visits 1 - 3 heap blocks due to the
+ * speculative nature of the batch index deletion optimization. These heap
+ * blocks had better be the most promising available.
+ *
+ * Returns new size of deltids array (ndeltids). deltids will only have TIDs
+ * from the 3 most promising heap blocks when we return (which is usually far
+ * fewer).
+ */
+static int
+heap_index_batch_check_block_sort(TM_IndexDelete *deltids,
+ TM_IndexDeleteStatus *statusdeltids,
+ int ndeltids)
+{
+ IndexDeleteCounts *blockcounts;
+ TM_IndexDelete *reordereddeltids;
+ BlockNumber curblock = InvalidBlockNumber;
+ int nblockgroups = 0;
+ int ncopied = 0;
+
+ Assert(ndeltids > 0);
+
+ /* First sort caller's array by TID */
+ qsort_deltids_by_tid(deltids, ndeltids);
+
+ /* Calculate per-heap-block count of TIDs */
+ blockcounts = palloc(sizeof(IndexDeleteCounts) * ndeltids);
+ for (int i = 0; i < ndeltids; i++)
+ {
+ ItemPointer deltid = &deltids[i].tid;
+ TM_IndexDeleteStatus *status = statusdeltids + deltids[i].id;
+ bool ispromising = status->ispromising;
+
+ if (curblock != ItemPointerGetBlockNumber(deltid))
+ {
+ /* New block group */
+ nblockgroups++;
+
+ curblock = ItemPointerGetBlockNumber(deltid);
+ blockcounts[nblockgroups - 1].block = curblock;
+ blockcounts[nblockgroups - 1].ntids = 1;
+ blockcounts[nblockgroups - 1].npromisingtids = 0;
+ }
+ else
+ {
+ blockcounts[nblockgroups - 1].ntids++;
+ }
+
+ if (ispromising)
+ blockcounts[nblockgroups - 1].npromisingtids++;
+ }
+
+ qsort_blockgroup(blockcounts, nblockgroups);
+ reordereddeltids = palloc(ndeltids * sizeof(TM_IndexDelete));
+ /* Caller only visits 3 blocks at most, so just copy that many groups */
+ nblockgroups = Min(3, nblockgroups);
+ for (int i = 0; i < nblockgroups; i++)
+ {
+ IndexDeleteCounts *blockgroup = blockcounts + i;
+
+ for (int j = 0; j < ndeltids; j++)
+ {
+ ItemPointer tid = &deltids[j].tid;
+
+ if (blockgroup->block == ItemPointerGetBlockNumber(tid))
+ {
+ memcpy(reordereddeltids + ncopied, deltids + j,
+ sizeof(TM_IndexDelete) * blockgroup->ntids);
+ ncopied += blockgroup->ntids;
+ break; /* Move on to next heap block group */
+ }
+ }
+ }
+
+ /* Copy back final sorted array into caller's array */
+ memcpy(deltids, reordereddeltids, sizeof(TM_IndexDelete) * ncopied);
+
+ /* be tidy */
+ pfree(reordereddeltids);
+ pfree(blockcounts);
+
+ return ncopied;
+}
+
+/*
+ * qsort-style comparator used in heap_index_batch_check_block_sort()
+ */
+static inline int
+indexdelete_tids_cmp(TM_IndexDelete *indexdelete1,
+ TM_IndexDelete *indexdelete2)
+{
+ ItemPointer tid1 = &indexdelete1->tid;
+ ItemPointer tid2 = &indexdelete2->tid;
+
+ {
+ BlockNumber blk1 = ItemPointerGetBlockNumber(tid1);
+ BlockNumber blk2 = ItemPointerGetBlockNumber(tid2);
+
+ if (blk1 != blk2)
+ return (blk1 < blk2) ? -1 : 1;
+ }
+ {
+ OffsetNumber pos1 = ItemPointerGetOffsetNumber(tid1);
+ OffsetNumber pos2 = ItemPointerGetOffsetNumber(tid2);
+
+ if (pos1 != pos2)
+ return (pos1 < pos2) ? -1 : 1;
+ }
+
+ /* ItemPointer values should never be equal */
+ Assert(false);
+
+ return 0;
+}
+
+/*
+ * qsort-style comparator used in heap_index_batch_check_block_sort()
+ */
+static inline int
+indexdeletecount_ntids_cmp(IndexDeleteCounts *count1,
+ IndexDeleteCounts *count2)
+{
+ /* Invert usual order here (desc npromisingtids sort order) */
+ if (count1->npromisingtids > count2->npromisingtids)
+ return -1;
+ if (count1->npromisingtids < count2->npromisingtids)
+ return 1;
+
+ /* Tiebreak: desc ntids sort order */
+ if (count1->ntids > count2->ntids)
+ return -1;
+ if (count1->ntids < count2->ntids)
+ return 1;
+
+ /* Tiebreak: block number (asc order) */
+ if (count1->block > count2->block)
+ return 1;
+ if (count1->block < count2->block)
+ return -1;
+
+ Assert(false);
+
+ return 0;
+}
+
/*
* Perform XLogInsert to register a heap cleanup info message. These
* messages are sent once per VACUUM and are required because
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index dcaea7135f..f32ed0a5f2 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -314,7 +314,8 @@ static TM_Result
heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
CommandId cid, Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
- LockTupleMode *lockmode, bool *update_indexes)
+ LockTupleMode *lockmode, bool *update_indexes,
+ Bitmapset **modified_attrs_hint)
{
bool shouldFree = true;
HeapTuple tuple = ExecFetchSlotHeapTuple(slot, true, &shouldFree);
@@ -325,7 +326,7 @@ heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
tuple->t_tableOid = slot->tts_tableOid;
result = heap_update(relation, otid, tuple, cid, crosscheck, wait,
- tmfd, lockmode);
+ tmfd, lockmode, modified_attrs_hint);
ItemPointerCopy(&tuple->t_self, &slot->tts_tid);
/*
diff --git a/src/backend/access/nbtree/README b/src/backend/access/nbtree/README
index 9692e4cdf6..3ae4551f84 100644
--- a/src/backend/access/nbtree/README
+++ b/src/backend/access/nbtree/README
@@ -807,7 +807,8 @@ Deduplication in unique indexes helps to prevent these pathological page
splits. Storing duplicates in a space efficient manner is not the goal,
since in the long run there won't be any duplicates anyway. Rather, we're
buying time for standard garbage collection mechanisms to run before a
-page split is needed.
+page split is needed. (The same principle is behind delete deduplication,
+which also targets version churn.)
Unique index leaf pages only get a deduplication pass when an insertion
(that might have to split the page) observed an existing duplicate on the
@@ -874,6 +875,36 @@ that need a page split anyway. Besides, supporting variable "split points"
while splitting posting lists won't actually improve overall space
utilization.
+Delete deduplication
+--------------------
+
+The deduplication module usually opportunistically deletes whatever
+duplicates happen to be present on the page before moving on to
+deduplication proper, since in general some duplicates are likely to
+already be dead to everybody. This happens before regular merge
+deduplication, but only when we receive a hint that optimizations like
+heapam's HOT have not worked out -- the incoming tuple must be a logically
+unchanged duplicate which is needed for MVCC purposes.
+
+This mechanism is quite similar to on-the-fly deletion of index tuples
+(that will already have failed to prevent a page split by the time delete
+deduplication is considered). The main difference is that the tuples that
+get deleted are not opportunistically marked LP_DEAD by transactions that
+had to read the tuples in any case. Rather, we infer that duplicates are
+likely to be dead tuples based on heuristics (starting with the hint from
+the executor), and look for visibility information about the likely-dead
+tuples in the hopes that that inference will work out. There is some risk
+that this won't work out, but the upside of avoiding version driven page
+splits is so large that it is worth it.
+
+Negative feedback (such as failing to dedup-delete any tuples) is not
+really undesirable. At worst it is an unavoidable part of how the
+algorithm works. We require that our various approaches to handling an
+overflowing page (due partially or entirely to version churn) compete to
+determine how best to handle the problem in a localized fashion. We
+expect to converge on a stable and roughly optimal behavior at each part
+of the key space in each index affected by version churn.
+
Notes About Data Representation
-------------------------------
diff --git a/src/backend/access/nbtree/nbtdedup.c b/src/backend/access/nbtree/nbtdedup.c
index f6be865b17..e9e30a306e 100644
--- a/src/backend/access/nbtree/nbtdedup.c
+++ b/src/backend/access/nbtree/nbtdedup.c
@@ -15,14 +15,27 @@
#include "postgres.h"
#include "access/nbtree.h"
+#include "access/heapam.h"
#include "access/nbtxlog.h"
+#include "access/tableam.h"
#include "miscadmin.h"
#include "utils/rel.h"
-static bool _bt_do_singleval(Relation rel, Page page, BTDedupState state,
- OffsetNumber minoff, IndexTuple newitem);
+static bool _bt_dedup_delete_pass(Relation rel, Buffer buf, Relation heapRel,
+ Size newitemsz, bool checkingunique,
+ bool *merge);
+static void _bt_dedup_merge_pass(Relation rel, Buffer buf, Relation heapRel,
+ IndexTuple newitem, Size newitemsz,
+ bool checkingunique, bool singleval);
+static void _bt_dedup_delete_finish_pending(BTDedupState state,
+ TM_IndexDelete *deltids,
+ TM_IndexDeleteStatus *statusdeltids,
+ int *ndeltids);
+static bool _bt_do_singleval(Relation rel, Page page, OffsetNumber minoff,
+ IndexTuple newitem);
static void _bt_singleval_fillfactor(Page page, BTDedupState state,
Size newitemsz);
+static int _bt_indexdelete_cmp(const void *a, const void *b, void *arg);
#ifdef USE_ASSERT_CHECKING
static bool _bt_posting_valid(IndexTuple posting);
#endif
@@ -32,16 +45,12 @@ static bool _bt_posting_valid(IndexTuple posting);
* if we cannot successfully free at least newitemsz (we also need space for
* newitem's line pointer, which isn't included in caller's newitemsz).
*
- * The general approach taken here is to perform as much deduplication as
- * possible to free as much space as possible. Note, however, that "single
- * value" strategy is sometimes used for !checkingunique callers, in which
- * case deduplication will leave a few tuples untouched at the end of the
- * page. The general idea is to prepare the page for an anticipated page
- * split that uses nbtsplitloc.c's "single value" strategy to determine a
- * split point. (There is no reason to deduplicate items that will end up on
- * the right half of the page after the anticipated page split; better to
- * handle those if and when the anticipated right half page gets its own
- * deduplication pass, following further inserts of duplicates.)
+ * There are two types of deduplication pass: The merge deduplication pass,
+ * where we merge together duplicate index tuples into a new posting list, and
+ * the delete deduplication pass, where old garbage version index tuples are
+ * deleted based on visibility information that we fetch from the table. We
+ * generally expect to perform only one type of deduplication pass per call
+ * here, but it's possible that we'll end up doing both.
*
* This function should be called during insertion, when the page doesn't have
* enough space to fit an incoming newitem. If the BTP_HAS_GARBAGE page flag
@@ -54,27 +63,24 @@ static bool _bt_posting_valid(IndexTuple posting);
*/
void
_bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
- IndexTuple newitem, Size newitemsz, bool checkingunique)
+ IndexTuple newitem, Size newitemsz, bool checkingunique,
+ bool dedupdelete, bool allequalimage)
{
OffsetNumber offnum,
minoff,
maxoff;
Page page = BufferGetPage(buf);
BTPageOpaque opaque;
- Page newpage;
OffsetNumber deletable[MaxIndexTuplesPerPage];
- BTDedupState state;
int ndeletable = 0;
- Size pagesaving = 0;
- bool singlevalstrat = false;
- int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+ bool singleval;
/*
* We can't assume that there are no LP_DEAD items. For one thing, VACUUM
* will clear the BTP_HAS_GARBAGE hint without reliably removing items
* that are marked LP_DEAD. We don't want to unnecessarily unset LP_DEAD
- * bits when deduplicating items. Allowing it would be correct, though
- * wasteful.
+ * bits when deduplicating items by merging. Allowing it would be
+ * correct, though wasteful.
*/
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
minoff = P_FIRSTDATAKEY(opaque);
@@ -91,7 +97,9 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
if (ndeletable > 0)
{
- _bt_delitems_delete(rel, buf, deletable, ndeletable, heapRel);
+ _bt_delitems_delete(rel, buf, deletable, ndeletable,
+ NULL, 0,
+ heapRel, false, InvalidTransactionId);
/*
* Return when a split will be avoided. This is equivalent to
@@ -100,17 +108,516 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
if (PageGetFreeSpace(page) >= newitemsz)
return;
- /*
- * Reconsider number of items on page, in case _bt_delitems_delete()
- * managed to delete an item or two
- */
- minoff = P_FIRSTDATAKEY(opaque);
- maxoff = PageGetMaxOffsetNumber(page);
+ maxoff = InvalidOffsetNumber; /* Invalidate */
}
/* Passed-in newitemsz is MAXALIGNED but does not include line pointer */
newitemsz += sizeof(ItemIdData);
+ /* Determine if page is all one value */
+ singleval = _bt_do_singleval(rel, page, minoff, newitem);
+
+ /*
+ * Perform delete deduplication pass when caller asked for it explicitly,
+ * or for a unique index.
+ *
+ * Don't delete dedup when page contains only one value, unless it's from
+ * a unique index where we always try to delete. We only get called about
+ * checkingunique cases when page is known to have at least one or two
+ * non-NULL duplicates. Clearly duplicates in a unique index are bound to
+ * become dead-to-all before long, so we should always try to delete them.
+ */
+ if ((dedupdelete && !singleval) || checkingunique)
+ {
+ bool merge = true;
+
+ if (_bt_dedup_delete_pass(rel, buf, heapRel, newitemsz,
+ checkingunique, &merge))
+ return;
+
+ /*
+ * _bt_dedup_delete_pass() may occasionally indicate no duplicates, in
+ * which case we should give up now
+ */
+ if (!merge)
+ return;
+
+ /* Fall back on merge deduplication. This happens infrequently. */
+ }
+
+ /*
+ * Perform merge deduplication pass, though only when it is safe to do so.
+ * Index must be an allequalimage index -- otherwise it's not safe.
+ */
+ if (allequalimage)
+ _bt_dedup_merge_pass(rel, buf, heapRel, newitem, newitemsz,
+ checkingunique, singleval);
+}
+
+/*
+ * Perform a delete deduplication pass.
+ *
+ * See if duplicate index tuples are eligible to be deleted, even though they
+ * don't have their LP_DEAD bit set already. Give up if we have to access
+ * more than a few heap pages before we can free enough space to fit newitem.
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
+ */
+static bool
+_bt_dedup_delete_pass(Relation rel, Buffer buf, Relation heapRel,
+ Size newitemsz, bool checkingunique, bool *merge)
+{
+ OffsetNumber offnum,
+ minoff,
+ maxoff,
+ skippostinglistoffnum = InvalidOffsetNumber;
+ Page page = BufferGetPage(buf);
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+ BTDedupState state;
+ TM_IndexDelete *deltids;
+ TM_IndexDeleteStatus *statusdeltids;
+ int ndeltids,
+ npromisingdeltids,
+ ntiddeletes,
+ ndeletable,
+ nupdatable;
+ int finalndeltids;
+ TransactionId dedupLatestRemovedXid = InvalidTransactionId;
+ OffsetNumber deletable[MaxIndexTuplesPerPage];
+ BTVacuumPosting updatable[MaxIndexTuplesPerPage];
+ int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+
+ state = (BTDedupState) palloc(sizeof(BTDedupStateData));
+ state->deduplicate = true;
+ state->nmaxitems = 0;
+ /* Final "posting list" size should not restrict anything */
+ state->maxpostingsize = BLCKSZ;
+ state->base = NULL;
+ state->baseoff = InvalidOffsetNumber;
+ state->basetupsize = 0;
+ state->htids = palloc(state->maxpostingsize);
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+ state->nintervals = 0;
+
+ /*
+ * deltids and statusdeltids are allocated separately as a performance
+ * optimization. You can think of them as one array artificially split in
+ * two for performance reasons.
+ */
+ ndeltids = 0;
+ npromisingdeltids = 0;
+ deltids = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexDelete));
+ statusdeltids = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexDeleteStatus));
+
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
+ for (offnum = minoff;
+ offnum <= maxoff;
+ offnum = OffsetNumberNext(offnum))
+ {
+ ItemId itemid = PageGetItemId(page, offnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+
+ Assert(!ItemIdIsDead(itemid));
+
+ if (offnum == minoff)
+ {
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ else if (_bt_keep_natts_fast(rel, state->base, itup) > nkeyatts &&
+ _bt_dedup_save_htid(state, itup))
+ {
+
+ }
+ else
+ {
+ /* Handle interval, saving TIDs when "non-promising" */
+ _bt_dedup_delete_finish_pending(state, deltids, statusdeltids,
+ &ndeltids);
+
+ /* itup starts new pending interval */
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ }
+ /* Handle the final interval, saving TIDs when "non-promising" */
+ _bt_dedup_delete_finish_pending(state, deltids, statusdeltids, &ndeltids);
+
+ if (state->nintervals == 0)
+ {
+ /* No duplicates/promising tuples, don't bother trying */
+ pfree(state->htids);
+ pfree(state);
+ pfree(deltids);
+ pfree(statusdeltids);
+ /* Caller should avoid merge deduplication pass */
+ *merge = false;
+ return false;
+ }
+
+ /*
+ * deltids array now contains non-duplicate tuples, all of which are
+ * marked non-promising.
+ *
+ * Add known duplicates to array now by extracting them from the dedup
+ * intervals we just formed. Tuples are marked promising so that the
+ * tableam infrastructure can focus its efforts there (actually we don't
+ * do that for posting list TIDs). See comment block below for a full
+ * explanation of promising tuples.
+ */
+ for (int i = 0; i < state->nintervals; i++)
+ {
+ BTDedupInterval interval = state->intervals[i];
+
+ for (int j = 0; j < interval.nitems; j++)
+ {
+ OffsetNumber dupoffnum = interval.baseoff + j;
+ ItemId itemid = PageGetItemId(page, dupoffnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ /*
+ * Plain non-pivot tuple duplicate -- TID is promising
+ */
+ deltids[ndeltids].tid = itup->t_tid;
+ deltids[ndeltids].id = ndeltids;
+ statusdeltids[ndeltids].ioffnum = dupoffnum;
+ statusdeltids[ndeltids].ispromising = true;
+ statusdeltids[ndeltids].isdead = false; /* for now */
+ ndeltids++;
+ npromisingdeltids++;
+ }
+ else
+ {
+ /*
+ * Posting list tuple duplicate -- TIDs are not promising, but
+ * tableam might manage to delete them in passing
+ */
+ int nitem = BTreeTupleGetNPosting(itup);
+
+ Assert(_bt_posting_valid(itup));
+
+ for (int p = 0; p < nitem; p++)
+ {
+ ItemPointer htid = BTreeTupleGetPostingN(itup, p);
+
+ deltids[ndeltids].tid = *htid;
+ deltids[ndeltids].id = ndeltids;
+ statusdeltids[ndeltids].ioffnum = dupoffnum;
+ statusdeltids[ndeltids].ispromising = false;
+ statusdeltids[ndeltids].isdead = false; /* for now */
+ ndeltids++;
+ }
+ }
+ }
+ }
+
+ /* Done with dedup state */
+ pfree(state->htids);
+ pfree(state);
+
+ /*
+ * Determine which TIDs are dead in deltids array (if we have any
+ * duplicates at all, since we only really expect to find dead tuples
+ * among duplicates).
+ *
+ * Each failure to delete a duplicate/promising tuple here is a kind of
+ * learning experience. It results in caller falling back on splitting
+ * the page (or on a merge deduplication pass), discouraging future calls
+ * back here for the same key space range covered by a failed page (or at
+ * least discouraging processing the original duplicates in case where
+ * caller falls back on a successful merge deduplication pass). We
+ * converge on the most effective strategy for each page in the index over
+ * time, through trial and error. We accept well understood small
+ * negative outcomes (effort on deleting that didn't immediately pay off)
+ * as the price of a potentially huge (though uncertain) upside (no
+ * unnecessary page splits).
+ *
+ * We don't mark posting list tuple TIDs as promising specifically so that
+ * cases where we have a failed delete deduplication pass followed by a
+ * successfully merge deduplication pass do not go on to waste time on the
+ * TIDs during any future delete deduplication passes. This is helpful
+ * when posting list tuples generally point to multiple distinct logical
+ * rows in the table. If it turns out that they really are all old
+ * versions of a single logical table row, we still have a pretty good
+ * chance of being able to delete them in a future dedup delete pass (not
+ * necessarily the next one for the leaf page). We could easily pick up
+ * the dead TIDs from such a posting list tuple when the tableam goes on
+ * to place even more similar version churn tuples on the same table
+ * block. We'll naturally target the newer version churn tuples directly,
+ * and then discover dead TIDs from posting list tuples that weren't
+ * dead/possible to delete earlier (i.e. back when we "were under the
+ * mistaken impression" that the posting list TIDs were for multiple
+ * logical table rows).
+ */
+ Assert(ndeltids > 0);
+ ntiddeletes = 0;
+ if (npromisingdeltids > 0)
+ {
+ SnapshotData SnapshotNonVacuumable;
+
+ InitNonVacuumableSnapshot(SnapshotNonVacuumable,
+ GlobalVisTestFor(heapRel));
+
+ /*
+ * We require a score of 25 from the tableam. A promising TID is
+ * worth 2, while a non-promising TID is worth only 1.
+ *
+ * You might wonder why we don't tell the tableam more about our
+ * preferences (for example, we don't register a callback that figures
+ * out when tableam has found enough dead TIDs to allow us to free
+ * just enough leaf page space to avoid a page split -- even though
+ * that interface is quite feasible). Our precise preferences are
+ * unimportant because the high level design of delete deduplication
+ * is highly opportunistic. This generally works out because of the
+ * asymmetry. The cost of failing to delete even one tuple once per
+ * page is drastically lower than the potential upside of never having
+ * to split a page affected by version churn.
+ *
+ * We're not trying to prevent just any kind of page split. We're
+ * trying to delay _unnecessary_ version churn page splits
+ * indefinitely, which is the same thing as preventing them altogether
+ * if you look at the situation on a long enough time line (think
+ * hours, days, or even months).
+ *
+ * The tableam will regularly give us a final score which is much
+ * higher than what we ask for (a score of 25). It often happens to
+ * be convenient for the tableam to process extra TIDs. Our target
+ * score is really just a way of balancing costs over time for pages
+ * that are more or less constantly at risk of unnecessary page
+ * splits, but are not expected to split for any other reason. (If
+ * there are even a few inserts of new logical row TIDs on the page
+ * then a page split is practically inevitable, and will probably
+ * happen very quickly in practice. We don't worry about these "in
+ * between" cases because they're too unstable to last and so too rare
+ * to matter.)
+ */
+ dedupLatestRemovedXid =
+ heap_index_batch_check(heapRel, deltids, statusdeltids, ndeltids,
+ &SnapshotNonVacuumable, 25, checkingunique,
+ &ntiddeletes, &finalndeltids);
+
+ /*
+ * TODO: Obviously we should be going through a new tableam shim
+ * function rather than calling into heapam directly like this. We
+ * don't bother with that for now because the interface is still
+ * unsettled. See also: WIP table_index_batch_check() shim.
+ */
+ }
+
+ if (ntiddeletes == 0)
+ {
+ pfree(deltids);
+ pfree(statusdeltids);
+ return false;
+ }
+
+ /*
+ * We have at least one dead TID to delete. All that remains is to
+ * construct a leaf-page-wise description of what to delete that can be
+ * used by _bt_delitems_delete().
+ *
+ * Sort deltids in useful order, then process sorted array in loop (loop
+ * expects items in offset number order, or by TID among entries that have
+ * equal offset numbers -- which happens when there are posting list
+ * tuples that we want to delete some TIDs from).
+ *
+ * Note: We only process the subset of elements at the start of deltids
+ * that pertain to table blocks actually accessed by the tableam (the
+ * first finalndeltids elements). This approach saves a few cycles.
+ */
+ Assert(finalndeltids > 0);
+ qsort_arg(deltids, finalndeltids, sizeof(TM_IndexDelete),
+ _bt_indexdelete_cmp, statusdeltids);
+ ndeletable = 0;
+ nupdatable = 0;
+ for (int i = 0; i < finalndeltids; i++)
+ {
+ TM_IndexDeleteStatus *status = statusdeltids + deltids[i].id;
+ OffsetNumber savedoffnum = status->ioffnum;
+ ItemId itemid = PageGetItemId(page, savedoffnum);
+ IndexTuple itup;
+ int nitem;
+ BTVacuumPosting vacposting = NULL;
+
+ itup = (IndexTuple) PageGetItem(page, itemid);
+
+ /*
+ * If this is a posting list and we already reached the first dead
+ * tuple in the posting list, skip remaining items
+ */
+ if (skippostinglistoffnum == savedoffnum)
+ {
+ Assert(BTreeTupleIsPosting(itup));
+ Assert(!status->ispromising);
+ continue;
+ }
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ /*
+ * For a plain non-pivot tuple, simply being found marked dead
+ * means we can kill
+ */
+ Assert(ItemPointerEquals(&itup->t_tid, &deltids[i].tid));
+ if (status->isdead)
+ deletable[ndeletable++] = savedoffnum;
+ continue;
+ }
+
+ /*
+ * For a posting list tuple we have to work a bit harder, since we may
+ * either delete or update (i.e. update to delete a subset of its
+ * TIDs).
+ *
+ * We'll be skipping over future TIDs from this same posting list in
+ * outer loop, since we want to process all TIDs in tuple together
+ * once in inner loop. Remember to do that at top of outer loop now.
+ */
+ Assert(_bt_posting_valid(itup));
+ skippostinglistoffnum = savedoffnum;
+ nitem = BTreeTupleGetNPosting(itup);
+ for (int j = 0; j < nitem; j++)
+ {
+ ItemPointer htid;
+ int cmp;
+ int tidi = i;
+
+ htid = BTreeTupleGetPostingN(itup, j);
+
+ for (;;)
+ {
+ cmp = ItemPointerCompare(htid, &deltids[tidi].tid);
+ if (cmp == 0)
+ break;
+ tidi++;
+ if (tidi >= finalndeltids ||
+ (statusdeltids + deltids[tidi].id)->ioffnum != savedoffnum)
+ {
+ /*
+ * If this later tidi deltid doesn't even relate to same
+ * posting list index tuple from page, we're done with
+ * this TID from itup (posting list tuple).
+ */
+ cmp = -1;
+ break;
+ }
+ }
+
+ /* Final check for exact TID match */
+ if (cmp != 0)
+ continue;
+
+ /* Only interested in dead TIDs */
+ if (!(statusdeltids + deltids[tidi].id)->isdead)
+ continue;
+
+ if (vacposting == NULL)
+ {
+ /*
+ * First dead table TID encountered.
+ *
+ * Start maintaining metadata describing how to update
+ * existing posting list tuple.
+ */
+ vacposting = palloc(offsetof(BTVacuumPostingData, deletetids) +
+ nitem * sizeof(uint16));
+ vacposting->itup = itup;
+ vacposting->updatedoffset = savedoffnum;
+ vacposting->ndeletedtids = 0;
+ }
+ vacposting->deletetids[vacposting->ndeletedtids++] = j;
+ }
+
+ /* Decide what to do with TIDs in posting list tuple */
+
+ if (vacposting == NULL)
+ {
+ /* No TIDs to delete in posting list tuple */
+ }
+ else if (vacposting->ndeletedtids == nitem)
+ {
+ /* Straight delete -- won't need update state */
+ deletable[ndeletable++] = savedoffnum;
+ pfree(vacposting);
+ }
+ else
+ {
+ /* Going to delete some but not all TIDs in posting list */
+ Assert(vacposting->ndeletedtids > 0 &&
+ vacposting->ndeletedtids < nitem);
+ updatable[nupdatable++] = vacposting;
+ }
+ }
+
+ /* Done with deltids state */
+ pfree(deltids);
+ pfree(statusdeltids);
+
+ /*
+ * Should not get this far if we don't have at least some TIDs to delete,
+ * but be paranoid
+ */
+ if (ndeletable == 0 && nupdatable == 0)
+ {
+ Assert(false);
+ return false;
+ }
+
+ /*
+ * Go through with deleting TIDs that we found are safe to delete.
+ *
+ * No MarkBufferDirtyHint() call is needed here, since we don't ever mark
+ * line pointers LP_DEAD. Any and all modifications to the page are made
+ * in the critical section in _bt_delitems_delete().
+ */
+ _bt_delitems_delete(rel, buf, deletable, ndeletable,
+ updatable, nupdatable,
+ heapRel, true, dedupLatestRemovedXid);
+
+ /* be tidy */
+ for (int i = 0; i < nupdatable; i++)
+ pfree(updatable[i]);
+
+ /* Return success when page split (or merge deduplication pass) avoided */
+ return PageGetExactFreeSpace(page) >= newitemsz;
+}
+
+/*
+ * Perform a merge deduplication pass.
+ *
+ * The general approach taken here is to perform as much deduplication as
+ * possible to free as much space as possible. Note, however, that "single
+ * value" strategy is used for singleval callers, in which case deduplication
+ * will leave a few tuples untouched at the end of the page. The general idea
+ * is to prepare the page for an anticipated page split that uses
+ * nbtsplitloc.c's "single value" strategy to determine a split point. (There
+ * is no reason to deduplicate items that will end up on the right half of the
+ * page after the anticipated page split; better to handle those if and when
+ * the anticipated right half page gets its own deduplication pass, following
+ * further inserts of duplicates.)
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
+ */
+static void
+_bt_dedup_merge_pass(Relation rel, Buffer buf, Relation heapRel,
+ IndexTuple newitem, Size newitemsz, bool checkingunique,
+ bool singleval)
+{
+ OffsetNumber offnum,
+ minoff,
+ maxoff;
+ Page page = BufferGetPage(buf);
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+ Page newpage;
+ BTDedupState state;
+ Size pagesaving = 0;
+ int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+
/*
* By here, it's clear that deduplication will definitely be attempted.
* Initialize deduplication state.
@@ -138,9 +645,8 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
/* nintervals should be initialized to zero */
state->nintervals = 0;
- /* Determine if "single value" strategy should be used */
- if (!checkingunique)
- singlevalstrat = _bt_do_singleval(rel, page, state, minoff, newitem);
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
/*
* Deduplicate items from page, and write them to newpage.
@@ -203,9 +709,9 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
* form new posting tuple, and actually update the page. Else
* reset the state and move on without modifying the page.
*/
- pagesaving += _bt_dedup_finish_pending(newpage, state);
+ pagesaving += _bt_dedup_merge_finish_pending(newpage, state);
- if (singlevalstrat)
+ if (singleval)
{
/*
* Single value strategy's extra steps.
@@ -225,7 +731,7 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
else if (state->nmaxitems == 6)
{
state->deduplicate = false;
- singlevalstrat = false; /* won't be back here */
+ singleval = false; /* won't be back here */
}
}
@@ -235,7 +741,7 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
}
/* Handle the last item */
- pagesaving += _bt_dedup_finish_pending(newpage, state);
+ pagesaving += _bt_dedup_merge_finish_pending(newpage, state);
/*
* If no items suitable for deduplication were found, newpage must be
@@ -263,6 +769,8 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
* still falsely set, just to keep things tidy. (We can't rely on
* _bt_vacuum_one_page() having done this already, and we can't rely on a
* page split or VACUUM getting to it in the near future.)
+ *
+ * Deliberately don't unset BTP_HAS_DUPS here.
*/
if (P_HAS_GARBAGE(opaque))
{
@@ -317,8 +825,8 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
* Every tuple processed by deduplication either becomes the base tuple for a
* posting list, or gets its heap TID(s) accepted into a pending posting list.
* A tuple that starts out as the base tuple for a posting list will only
- * actually be rewritten within _bt_dedup_finish_pending() when it turns out
- * that there are duplicates that can be merged into the base tuple.
+ * actually be rewritten within _bt_dedup_merge_finish_pending() when it turns
+ * out that there are duplicates that can be merged into the base tuple.
*/
void
_bt_dedup_start_pending(BTDedupState state, IndexTuple base,
@@ -443,7 +951,7 @@ _bt_dedup_save_htid(BTDedupState state, IndexTuple itup)
* where no deduplication was possible.
*/
Size
-_bt_dedup_finish_pending(Page newpage, BTDedupState state)
+_bt_dedup_merge_finish_pending(Page newpage, BTDedupState state)
{
OffsetNumber tupoff;
Size tuplesz;
@@ -496,10 +1004,76 @@ _bt_dedup_finish_pending(Page newpage, BTDedupState state)
return spacesaving;
}
+/*
+ * Stripped down version of _bt_dedup_merge_finish_pending() used by
+ * _bt_dedup_delete_pass().
+ *
+ * Finalize interval of duplicates (duplicate group) without materializing the
+ * would-be posting list tuple. We store all TIDs on the leaf page in the
+ * array, but only TIDs that we determine are duplicates are marked as
+ * promising. (Non-promising TIDs only get considered in passing, when they
+ * happen to be on the same table am page as promising TIDs.)
+ */
+static void
+_bt_dedup_delete_finish_pending(BTDedupState state, TM_IndexDelete *deltids,
+ TM_IndexDeleteStatus *statusdeltids, int *ndeltids)
+{
+ Assert(state->nitems > 0);
+ Assert(state->nitems <= state->nhtids);
+ Assert(state->intervals[state->nintervals].baseoff == state->baseoff);
+
+ if (state->nitems == 1)
+ {
+ /* Remember non-duplicate's TID, but mark it not promising */
+ OffsetNumber offnum = state->baseoff;
+ IndexTuple itup = state->base;
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ deltids[*ndeltids].tid = itup->t_tid;
+ deltids[*ndeltids].id = *ndeltids;
+ statusdeltids[*ndeltids].ioffnum = offnum;
+ statusdeltids[*ndeltids].ispromising = false;
+ statusdeltids[*ndeltids].isdead = false; /* for now */
+ (*ndeltids)++;
+ }
+ else
+ {
+ int nitem = BTreeTupleGetNPosting(itup);
+
+ Assert(_bt_posting_valid(itup));
+
+ for (int i = 0; i < nitem; i++)
+ {
+ ItemPointer htid = BTreeTupleGetPostingN(itup, i);
+
+ deltids[*ndeltids].tid = *htid;
+ deltids[*ndeltids].id = *ndeltids;
+ statusdeltids[*ndeltids].ioffnum = offnum;
+ statusdeltids[*ndeltids].ispromising = false;
+ statusdeltids[*ndeltids].isdead = false; /* for now */
+ (*ndeltids)++;
+ }
+ }
+ }
+ else
+ {
+ /* Dups in interval -- store in deltids later */
+ state->intervals[state->nintervals].nitems = state->nitems;
+ /* Increment nintervals, since we wrote a new posting list tuple */
+ state->nintervals++;
+ }
+
+ /* Reset state for next pending posting list */
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+}
+
/*
* Determine if page non-pivot tuples (data items) are all duplicates of the
- * same value -- if they are, deduplication's "single value" strategy should
- * be applied. The general goal of this strategy is to ensure that
+ * same value -- if they are, merge deduplication's "single value" strategy
+ * should be applied. The general goal of this strategy is to ensure that
* nbtsplitloc.c (which uses its own single value strategy) will find a useful
* split point as further duplicates are inserted, and successive rightmost
* page splits occur among pages that store the same duplicate value. When
@@ -531,8 +1105,8 @@ _bt_dedup_finish_pending(Page newpage, BTDedupState state)
* here.
*/
static bool
-_bt_do_singleval(Relation rel, Page page, BTDedupState state,
- OffsetNumber minoff, IndexTuple newitem)
+_bt_do_singleval(Relation rel, Page page, OffsetNumber minoff,
+ IndexTuple newitem)
{
int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
ItemId itemid;
@@ -809,6 +1383,57 @@ _bt_swap_posting(IndexTuple newitem, IndexTuple oposting, int postingoff)
return nposting;
}
+/*
+ * qsort-style comparator used by _bt_dedup_delete_pass()
+ *
+ * TM_IndexDelete and TM_IndexDeleteStatus are two different structs for
+ * performance reasons (initial TID sort needs to be very fast because it
+ * happens before any of the TIDs have been eliminated). It would be more
+ * natural if there was only one struct with all the fields from each of the
+ * two structs.
+ *
+ * This qsort_arg comparator deals with finding the TM_IndexDeleteStatus of
+ * the TM_IndexDelete entries that we sort.
+ */
+static int
+_bt_indexdelete_cmp(const void *a, const void *b, void *arg)
+{
+ TM_IndexDelete *indexdelete1 = (TM_IndexDelete *) a;
+ TM_IndexDelete *indexdelete2 = (TM_IndexDelete *) b;
+ TM_IndexDeleteStatus *statusdeltids = (TM_IndexDeleteStatus *) arg;
+
+ OffsetNumber offset1 = (statusdeltids + indexdelete1->id)->ioffnum;
+ OffsetNumber offset2 = (statusdeltids + indexdelete2->id)->ioffnum;
+ ItemPointer tid1 = &indexdelete1->tid;
+ ItemPointer tid2 = &indexdelete2->tid;
+
+ if (offset1 > offset2)
+ return 1;
+ if (offset1 < offset2)
+ return -1;
+
+ /* Must be posting list tuple -- restore TID order */
+ {
+ BlockNumber blk1 = ItemPointerGetBlockNumber(tid1);
+ BlockNumber blk2 = ItemPointerGetBlockNumber(tid2);
+
+ if (blk1 != blk2)
+ return (blk1 < blk2) ? -1 : 1;
+ }
+ {
+ OffsetNumber pos1 = ItemPointerGetOffsetNumber(tid1);
+ OffsetNumber pos2 = ItemPointerGetOffsetNumber(tid2);
+
+ if (pos1 != pos2)
+ return (pos1 < pos2) ? -1 : 1;
+ }
+
+ /* ItemPointer values should never be equal */
+ Assert(false);
+
+ return 0;
+}
+
/*
* Verify posting list invariants for "posting", which must be a posting list
* tuple. Used within assertions.
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index d36f7557c8..6377a024ba 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -37,6 +37,7 @@ static TransactionId _bt_check_unique(Relation rel, BTInsertState insertstate,
static OffsetNumber _bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool logicallymodified,
BTStack stack,
Relation heapRel);
static void _bt_stepright(Relation rel, BTInsertState insertstate, BTStack stack);
@@ -86,7 +87,9 @@ _bt_doinsert(Relation rel, IndexTuple itup,
BTInsertStateData insertstate;
BTScanInsert itup_key;
BTStack stack;
- bool checkingunique = (checkUnique != UNIQUE_CHECK_NO);
+ bool checkingunique = (checkUnique != UNIQUE_CHECK_NO &&
+ checkUnique != UNIQUE_CHECK_NO_WITH_UNCHANGED);
+ bool logicallymodified = (checkUnique != UNIQUE_CHECK_NO_WITH_UNCHANGED);
/* we need an insertion scan key to do our search, so build one */
itup_key = _bt_mkscankey(rel, itup);
@@ -235,7 +238,7 @@ search:
* checkingunique.
*/
newitemoff = _bt_findinsertloc(rel, &insertstate, checkingunique,
- stack, heapRel);
+ logicallymodified, stack, heapRel);
_bt_insertonpg(rel, itup_key, insertstate.buf, InvalidBuffer, stack,
itup, insertstate.itemsz, newitemoff,
insertstate.postingoff, false);
@@ -767,6 +770,11 @@ _bt_check_unique(Relation rel, BTInsertState insertstate, Relation heapRel,
* the right, rather than the first page. In that case, this function
* moves right to the correct target page.
*
+ * If 'logicallymodified' is false, this is for an UPDATE that didn't
+ * logically change the indexed value, but must nevertheless have a new
+ * entry to point to a successor version. This hint from the executor
+ * influences the behavior of deduplication.
+ *
* (In a !heapkeyspace index, there can be multiple pages with the same
* high key, where the new tuple could legitimately be placed on. In
* that case, the caller passes the first page containing duplicates,
@@ -790,6 +798,7 @@ static OffsetNumber
_bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool logicallymodified,
BTStack stack,
Relation heapRel)
{
@@ -873,14 +882,20 @@ _bt_findinsertloc(Relation rel,
/*
* If the target page is full, see if we can obtain enough space by
* erasing LP_DEAD items. If that fails to free enough space, see if
- * we can avoid a page split by performing a deduplication pass over
- * the page.
+ * we can avoid a page split by performing deduplication. Usually
+ * this means a deduplication merge pass, though a deduplication
+ * delete pass is preferred when it looks like version churn is the
+ * source of most of the duplicates.
*
- * We only perform a deduplication pass for a checkingunique caller
- * when the incoming item is a duplicate of an existing item on the
- * leaf page. This heuristic avoids wasting cycles -- we only expect
- * to benefit from deduplicating a unique index page when most or all
- * recently added items are duplicates. See nbtree/README.
+ * We only consider deduplication for a checkingunique caller when the
+ * incoming item is a known duplicate of an existing item on the leaf
+ * page. This heuristic avoids wasting cycles. The overarching goal
+ * within a unique index is to prevent an unnecessary page split
+ * altogether by delaying splits again and again (the goal is not to
+ * save space). If even one incoming tuple that gets added to this
+ * page originates with an INSERT statement then a page split is all
+ * but inevitable anyway --- that's why it's okay that our heuristic
+ * only considers the current incoming newitem. See nbtree/README.
*/
if (PageGetFreeSpace(page) < insertstate->itemsz)
{
@@ -893,16 +908,24 @@ _bt_findinsertloc(Relation rel,
uniquedup = true;
}
- if (itup_key->allequalimage && BTGetDeduplicateItems(rel) &&
- (!checkingunique || uniquedup) &&
+ if (BTGetDeduplicateItems(rel) && (!checkingunique || uniquedup) &&
PageGetFreeSpace(page) < insertstate->itemsz)
{
+ bool dedupdelete = !logicallymodified || P_HAS_DUPS(lpageop);
+
_bt_dedup_one_page(rel, insertstate->buf, heapRel,
insertstate->itup, insertstate->itemsz,
- checkingunique);
+ checkingunique, dedupdelete,
+ itup_key->allequalimage);
insertstate->bounds_valid = false;
}
}
+ else if (!logicallymodified && !P_HAS_DUPS(lpageop))
+ {
+ lpageop->btpo_flags |= BTP_HAS_DUPS;
+
+ MarkBufferDirtyHint(insertstate->buf, true);
+ }
}
else
{
@@ -1525,11 +1548,11 @@ _bt_split(Relation rel, BTScanInsert itup_key, Buffer buf, Buffer cbuf,
lopaque = (BTPageOpaque) PageGetSpecialPointer(leftpage);
/*
- * leftpage won't be the root when we're done. Also, clear the SPLIT_END
- * and HAS_GARBAGE flags.
+ * leftpage won't be the root when we're done. Also, clear the SPLIT_END,
+ * HAS_GARBAGE, and HAS_DUPS flags.
*/
lopaque->btpo_flags = oopaque->btpo_flags;
- lopaque->btpo_flags &= ~(BTP_ROOT | BTP_SPLIT_END | BTP_HAS_GARBAGE);
+ lopaque->btpo_flags &= ~(BTP_ROOT | BTP_SPLIT_END | BTP_HAS_GARBAGE | BTP_HAS_DUPS);
/* set flag in leftpage indicating that rightpage has no downlink yet */
lopaque->btpo_flags |= BTP_INCOMPLETE_SPLIT;
lopaque->btpo_prev = oopaque->btpo_prev;
@@ -1712,11 +1735,11 @@ _bt_split(Relation rel, BTScanInsert itup_key, Buffer buf, Buffer cbuf,
lopaque->btpo_cycleid = _bt_vacuum_cycleid(rel);
/*
- * rightpage won't be the root when we're done. Also, clear the SPLIT_END
- * and HAS_GARBAGE flags.
+ * rightpage won't be the root when we're done. Also, clear the
+ * SPLIT_END, HAS_GARBAGE and HAS_DUPS flags.
*/
ropaque->btpo_flags = oopaque->btpo_flags;
- ropaque->btpo_flags &= ~(BTP_ROOT | BTP_SPLIT_END | BTP_HAS_GARBAGE);
+ ropaque->btpo_flags &= ~(BTP_ROOT | BTP_SPLIT_END | BTP_HAS_GARBAGE | BTP_HAS_DUPS);
ropaque->btpo_prev = origpagenumber;
ropaque->btpo_next = oopaque->btpo_next;
ropaque->btpo.level = oopaque->btpo.level;
@@ -2659,7 +2682,8 @@ _bt_vacuum_one_page(Relation rel, Buffer buffer, Relation heapRel)
}
if (ndeletable > 0)
- _bt_delitems_delete(rel, buffer, deletable, ndeletable, heapRel);
+ _bt_delitems_delete(rel, buffer, deletable, ndeletable, NULL, 0,
+ heapRel, false, InvalidTransactionId);
/*
* Note: if we didn't find any LP_DEAD items, then the page's
diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c
index 7f392480ac..3acc31bcce 100644
--- a/src/backend/access/nbtree/nbtpage.c
+++ b/src/backend/access/nbtree/nbtpage.c
@@ -1117,8 +1117,7 @@ _bt_page_recyclable(Page page)
* We record VACUUMs and b-tree deletes differently in WAL. Deletes must
* generate their own latestRemovedXid by accessing the heap directly, whereas
* VACUUMs rely on the initial heap scan taking care of it indirectly. Also,
- * only VACUUM can perform granular deletes of individual TIDs in posting list
- * tuples.
+ * we remove the VACUUM cycle ID from pages, which b-tree deletes don't do.
*/
void
_bt_delitems_vacuum(Relation rel, Buffer buf,
@@ -1277,36 +1276,114 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
* Delete item(s) from a btree leaf page during single-page cleanup.
*
* This routine assumes that the caller has pinned and write locked the
- * buffer. Also, the given deletable array *must* be sorted in ascending
- * order.
+ * buffer. Also, the given deletable and updatable arrays *must* be sorted in
+ * ascending order.
*
* This is nearly the same as _bt_delitems_vacuum as far as what it does to
* the page, but it needs to generate its own latestRemovedXid by accessing
* the heap. This is used by the REDO routine to generate recovery conflicts.
- * Also, it doesn't handle posting list tuples unless the entire tuple can be
- * deleted as a whole (since there is only one LP_DEAD bit per line pointer).
+ * Though note that dedup deletion caller will provide its own
+ * latestRemovedXid, since it's convenient for it to determine that at the
+ * same point that it determines that the items are dead (it won't set LP_DEAD
+ * items). Another difference is that we don't clear page's vacuum cycle ID.
*/
void
_bt_delitems_delete(Relation rel, Buffer buf,
OffsetNumber *deletable, int ndeletable,
- Relation heapRel)
+ BTVacuumPosting *updatable, int nupdatable,
+ Relation heapRel, bool isdedup,
+ TransactionId dedupLatestRemovedXid)
{
Page page = BufferGetPage(buf);
BTPageOpaque opaque;
TransactionId latestRemovedXid = InvalidTransactionId;
+ Size itemsz;
+ char *updatedbuf = NULL;
+ Size updatedbuflen = 0;
+ OffsetNumber updatedoffsets[MaxIndexTuplesPerPage];
/* Shouldn't be called unless there's something to do */
- Assert(ndeletable > 0);
+ Assert(ndeletable > 0 || nupdatable > 0);
+ /* Shouldn't update posting lists unless for dedup caller */
+ Assert(isdedup || nupdatable == 0);
if (XLogStandbyInfoActive() && RelationNeedsWAL(rel))
- latestRemovedXid =
- _bt_xid_horizon(rel, heapRel, page, deletable, ndeletable);
+ {
+ if (!isdedup)
+ latestRemovedXid =
+ _bt_xid_horizon(rel, heapRel, page, deletable,
+ ndeletable);
+ else
+ latestRemovedXid = dedupLatestRemovedXid;
+ }
+
+ for (int i = 0; i < nupdatable; i++)
+ {
+ /* Replace work area IndexTuple with updated version */
+ _bt_update_posting(updatable[i]);
+
+ /* Maintain array of updatable page offsets for WAL record */
+ updatedoffsets[i] = updatable[i]->updatedoffset;
+ }
+
+ /* XLOG stuff -- allocate and fill buffer before critical section */
+ if (nupdatable > 0 && RelationNeedsWAL(rel))
+ {
+ Size offset = 0;
+
+ for (int i = 0; i < nupdatable; i++)
+ {
+ BTVacuumPosting vacposting = updatable[i];
+
+ itemsz = SizeOfBtreeUpdate +
+ vacposting->ndeletedtids * sizeof(uint16);
+ updatedbuflen += itemsz;
+ }
+
+ updatedbuf = palloc(updatedbuflen);
+ for (int i = 0; i < nupdatable; i++)
+ {
+ BTVacuumPosting vacposting = updatable[i];
+ xl_btree_update update;
+
+ update.ndeletedtids = vacposting->ndeletedtids;
+ memcpy(updatedbuf + offset, &update.ndeletedtids,
+ SizeOfBtreeUpdate);
+ offset += SizeOfBtreeUpdate;
+
+ itemsz = update.ndeletedtids * sizeof(uint16);
+ memcpy(updatedbuf + offset, vacposting->deletetids, itemsz);
+ offset += itemsz;
+ }
+ }
/* No ereport(ERROR) until changes are logged */
START_CRIT_SECTION();
- /* Fix the page */
- PageIndexMultiDelete(page, deletable, ndeletable);
+ /*
+ * Handle posting tuple updates.
+ *
+ * Deliberately do this before handling simple deletes. If we did it the
+ * other way around (i.e. WAL record order -- simple deletes before
+ * updates) then we'd have to make compensating changes to the 'updatable'
+ * array of offset numbers.
+ */
+ for (int i = 0; i < nupdatable; i++)
+ {
+ OffsetNumber updatedoffset = updatedoffsets[i];
+ IndexTuple itup;
+
+ itup = updatable[i]->itup;
+ itemsz = MAXALIGN(IndexTupleSize(itup));
+ if (!PageIndexTupleOverwrite(page, updatedoffset, (Item) itup,
+ itemsz))
+ elog(PANIC, "failed to update partially dead item in block %u of index \"%s\"",
+ BufferGetBlockNumber(buf), RelationGetRelationName(rel));
+ }
+
+ /* Now handle simple deletes of entire tuples */
+ if (ndeletable > 0)
+ PageIndexMultiDelete(page, deletable, ndeletable);
/*
* Unlike _bt_delitems_vacuum, we *must not* clear the vacuum cycle ID,
@@ -1326,6 +1403,7 @@ _bt_delitems_delete(Relation rel, Buffer buf,
xlrec_delete.latestRemovedXid = latestRemovedXid;
xlrec_delete.ndeleted = ndeletable;
+ xlrec_delete.nupdated = nupdatable;
XLogBeginInsert();
XLogRegisterBuffer(0, buf, REGBUF_STANDARD);
@@ -1336,8 +1414,16 @@ _bt_delitems_delete(Relation rel, Buffer buf,
* When XLogInsert stores the whole buffer, the array need not be
* stored too.
*/
- XLogRegisterBufData(0, (char *) deletable,
- ndeletable * sizeof(OffsetNumber));
+ if (ndeletable > 0)
+ XLogRegisterBufData(0, (char *) deletable,
+ ndeletable * sizeof(OffsetNumber));
+
+ if (nupdatable > 0)
+ {
+ XLogRegisterBufData(0, (char *) updatedoffsets,
+ nupdatable * sizeof(OffsetNumber));
+ XLogRegisterBufData(0, updatedbuf, updatedbuflen);
+ }
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_DELETE);
@@ -1345,6 +1431,13 @@ _bt_delitems_delete(Relation rel, Buffer buf,
}
END_CRIT_SECTION();
+
+ /* can't leak memory here */
+ if (updatedbuf != NULL)
+ pfree(updatedbuf);
+ /* free tuples generated by calling _bt_update_posting() */
+ for (int i = 0; i < nupdatable; i++)
+ pfree(updatable[i]->itup);
}
/*
@@ -1376,7 +1469,6 @@ _bt_xid_horizon(Relation rel, Relation heapRel, Page page,
itemid = PageGetItemId(page, deletable[i]);
itup = (IndexTuple) PageGetItem(page, itemid);
- Assert(ItemIdIsDead(itemid));
Assert(!BTreeTupleIsPivot(itup));
if (!BTreeTupleIsPosting(itup))
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index efee86784b..ecfe79badb 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -273,7 +273,7 @@ static void _bt_sortaddtup(Page page, Size itemsize,
bool newfirstdataitem);
static void _bt_buildadd(BTWriteState *wstate, BTPageState *state,
IndexTuple itup, Size truncextra);
-static void _bt_sort_dedup_finish_pending(BTWriteState *wstate,
+static void _bt_dedup_sort_finish_pending(BTWriteState *wstate,
BTPageState *state,
BTDedupState dstate);
static void _bt_uppershutdown(BTWriteState *wstate, BTPageState *state);
@@ -1068,11 +1068,11 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup,
* Finalize pending posting list tuple, and add it to the index. Final tuple
* is based on saved base tuple, and saved list of heap TIDs.
*
- * This is almost like _bt_dedup_finish_pending(), but it adds a new tuple
- * using _bt_buildadd().
+ * This is almost like _bt_dedup_merge_finish_pending(), but it adds a new
+ * tuple using _bt_buildadd().
*/
static void
-_bt_sort_dedup_finish_pending(BTWriteState *wstate, BTPageState *state,
+_bt_dedup_sort_finish_pending(BTWriteState *wstate, BTPageState *state,
BTDedupState dstate)
{
Assert(dstate->nitems > 0);
@@ -1371,7 +1371,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
* _bt_dedup_save_htid() opted to not merge current item into
* pending posting list.
*/
- _bt_sort_dedup_finish_pending(wstate, state, dstate);
+ _bt_dedup_sort_finish_pending(wstate, state, dstate);
pfree(dstate->base);
/* start new pending posting list with itup copy */
@@ -1390,7 +1390,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
* Handle the last item (there must be a last item when the
* tuplesort returned one or more tuples)
*/
- _bt_sort_dedup_finish_pending(wstate, state, dstate);
+ _bt_dedup_sort_finish_pending(wstate, state, dstate);
pfree(dstate->base);
pfree(dstate->htids);
}
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index bda9be2348..0a8e1d8295 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -530,12 +530,12 @@ btree_xlog_dedup(XLogReaderState *record)
}
else
{
- _bt_dedup_finish_pending(newpage, state);
+ _bt_dedup_merge_finish_pending(newpage, state);
_bt_dedup_start_pending(state, itup, offnum);
}
}
- _bt_dedup_finish_pending(newpage, state);
+ _bt_dedup_merge_finish_pending(newpage, state);
Assert(state->nintervals == xlrec->nintervals);
Assert(memcmp(state->intervals, intervals,
state->nintervals * sizeof(BTDedupInterval)) == 0);
@@ -675,7 +675,56 @@ btree_xlog_delete(XLogReaderState *record)
page = (Page) BufferGetPage(buffer);
- PageIndexMultiDelete(page, (OffsetNumber *) ptr, xlrec->ndeleted);
+ if (xlrec->nupdated > 0)
+ {
+ OffsetNumber *updatedoffsets;
+ xl_btree_update *updates;
+
+ updatedoffsets = (OffsetNumber *)
+ (ptr + xlrec->ndeleted * sizeof(OffsetNumber));
+ updates = (xl_btree_update *) ((char *) updatedoffsets +
+ xlrec->nupdated *
+ sizeof(OffsetNumber));
+
+ for (int i = 0; i < xlrec->nupdated; i++)
+ {
+ BTVacuumPosting vacposting;
+ IndexTuple origtuple;
+ ItemId itemid;
+ Size itemsz;
+
+ itemid = PageGetItemId(page, updatedoffsets[i]);
+ origtuple = (IndexTuple) PageGetItem(page, itemid);
+
+ vacposting = palloc(offsetof(BTVacuumPostingData, deletetids) +
+ updates->ndeletedtids * sizeof(uint16));
+ vacposting->updatedoffset = updatedoffsets[i];
+ vacposting->itup = origtuple;
+ vacposting->ndeletedtids = updates->ndeletedtids;
+ memcpy(vacposting->deletetids,
+ (char *) updates + SizeOfBtreeUpdate,
+ updates->ndeletedtids * sizeof(uint16));
+
+ _bt_update_posting(vacposting);
+
+ /* Overwrite updated version of tuple */
+ itemsz = MAXALIGN(IndexTupleSize(vacposting->itup));
+ if (!PageIndexTupleOverwrite(page, updatedoffsets[i],
+ (Item) vacposting->itup, itemsz))
+ elog(PANIC, "failed to update partially dead item");
+
+ pfree(vacposting->itup);
+ pfree(vacposting);
+
+ /* advance to next xl_btree_update from array */
+ updates = (xl_btree_update *)
+ ((char *) updates + SizeOfBtreeUpdate +
+ updates->ndeletedtids * sizeof(uint16));
+ }
+ }
+
+ if (xlrec->ndeleted > 0)
+ PageIndexMultiDelete(page, (OffsetNumber *) ptr, xlrec->ndeleted);
/* Mark the page as not containing any LP_DEAD items */
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
diff --git a/src/backend/access/table/tableam.c b/src/backend/access/table/tableam.c
index 6438c45716..a19b1b78c7 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -207,9 +207,9 @@ table_beginscan_parallel(Relation relation, ParallelTableScanDesc parallel_scan)
/*
* To perform that check simply start an index scan, create the necessary
* slot, do the heap lookup, and shut everything down again. This could be
- * optimized, but is unlikely to matter from a performance POV. If there
- * frequently are live index pointers also matching a unique index key, the
- * CPU overhead of this routine is unlikely to matter.
+ * optimized, but is unlikely to matter from a performance POV. Note that
+ * table_index_batch_check() is optimized in this way, since it is designed
+ * as a batch operation.
*
* Note that *tid may be modified when we return true if the AM supports
* storing multiple row versions reachable via a single index entry (like
@@ -236,6 +236,28 @@ table_index_fetch_tuple_check(Relation rel,
return found;
}
+/*
+ * Specialized variant of table_index_fetch_tuple_check() that can be used
+ * by index AMs to perform "bottom up" deletion of duplicate index tuples.
+ * This is particularly likely to work well with unique indexes.
+ *
+ * Note: This routine sorts the deltids array, but does not modify any
+ * individual entry accept to mark it as dead for caller.
+ *
+ * Returns total number of deltids that can be killed in index by caller.
+ */
+int
+table_index_batch_check(Relation rel, TM_IndexDelete *deltids, int ndeltids,
+ Snapshot snapshot, int npromisingkillsneeded)
+{
+ /*
+ * TODO -- call heapam's heap_index_batch_check() function here, and make
+ * nbtdedup.c call here instead of calling heap_index_batch_check()
+ * directly
+ */
+
+ return 0;
+}
/* ------------------------------------------------------------------------
* Functions for non-modifying operations on individual tuples
@@ -356,7 +378,7 @@ simple_table_tuple_update(Relation rel, ItemPointer otid,
GetCurrentCommandId(true),
snapshot, InvalidSnapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode, update_indexes);
+ &tmfd, &lockmode, update_indexes, NULL);
switch (result)
{
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 36ddcdccdb..816f3702fb 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -2523,7 +2523,7 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
recheckIndexes =
ExecInsertIndexTuples(resultRelInfo,
buffer->slots[i], estate, false, NULL,
- NIL);
+ NIL, NULL);
ExecARInsertTriggers(estate, resultRelInfo,
slots[i], recheckIndexes,
cstate->transition_capture);
@@ -3268,7 +3268,8 @@ CopyFrom(CopyState cstate)
estate,
false,
NULL,
- NIL);
+ NIL,
+ NULL);
}
/* AFTER ROW INSERT Triggers */
diff --git a/src/backend/executor/execIndexing.c b/src/backend/executor/execIndexing.c
index c6b5bcba7b..d171d26b69 100644
--- a/src/backend/executor/execIndexing.c
+++ b/src/backend/executor/execIndexing.c
@@ -275,7 +275,8 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
EState *estate,
bool noDupErr,
bool *specConflict,
- List *arbiterIndexes)
+ List *arbiterIndexes,
+ Bitmapset *modified_attrs_hint)
{
ItemPointer tupleid = &slot->tts_tid;
List *result = NIL;
@@ -389,6 +390,44 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
else
checkUnique = UNIQUE_CHECK_PARTIAL;
+ /*
+ * We may have to hint to index am that this is a logically unchanged
+ * index tuple. This happens when we're inserting a duplicate tuple
+ * just to represent the successor version.
+ */
+ if (checkUnique == UNIQUE_CHECK_NO && modified_attrs_hint)
+ {
+ bool logicallyModified = false;
+
+ for (int attr = 0; attr < indexInfo->ii_NumIndexAttrs; attr++)
+ {
+ int keycol = indexInfo->ii_IndexAttrNumbers[attr];
+
+ if (keycol > 0)
+ {
+ logicallyModified =
+ bms_is_member(keycol - FirstLowInvalidHeapAttributeNumber,
+ modified_attrs_hint);
+ if (logicallyModified)
+ break;
+ }
+ else
+ {
+ /*
+ * XXX: For now we always assume that expression indexes
+ * and indexes with whole-row vars were not modified by an
+ * UPDATE (i.e. they just use the dedup delete
+ * optimization regardless of the details of the UPDATE).
+ * Review this decision when the high level design is a
+ * bit better worked out.
+ */
+ }
+ }
+
+ if (!logicallyModified)
+ checkUnique = UNIQUE_CHECK_NO_WITH_UNCHANGED;
+ }
+
satisfiesConstraint =
index_insert(indexRelation, /* index relation */
values, /* array of index Datums */
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index 01d26881e7..e97d05b448 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -445,7 +445,7 @@ ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false, NULL,
- NIL);
+ NIL, NULL);
/* AFTER ROW INSERT Triggers */
ExecARInsertTriggers(estate, resultRelInfo, slot,
@@ -513,7 +513,7 @@ ExecSimpleRelationUpdate(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false, NULL,
- NIL);
+ NIL, NULL);
/* AFTER ROW UPDATE Triggers */
ExecARUpdateTriggers(estate, resultRelInfo,
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 29e07b7228..d76e371595 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -601,7 +601,7 @@ ExecInsert(ModifyTableState *mtstate,
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, true,
&specConflict,
- arbiterIndexes);
+ arbiterIndexes, NULL);
/* adjust the tuple's state accordingly */
table_tuple_complete_speculative(resultRelationDesc, slot,
@@ -640,7 +640,7 @@ ExecInsert(ModifyTableState *mtstate,
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false,
- NULL, NIL);
+ NULL, NIL, NULL);
}
}
@@ -1219,6 +1219,7 @@ ExecUpdate(ModifyTableState *mtstate,
TM_Result result;
TM_FailureData tmfd;
List *recheckIndexes = NIL;
+ Bitmapset *modified_attrs_hint = NULL;
/*
* abort the operation if not running transactions
@@ -1382,7 +1383,8 @@ lreplace:;
estate->es_snapshot,
estate->es_crosscheck_snapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode, &update_indexes);
+ &tmfd, &lockmode, &update_indexes,
+ &modified_attrs_hint);
switch (result)
{
@@ -1513,9 +1515,13 @@ lreplace:;
/* insert index entries for tuple if necessary */
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
+ {
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false,
- NULL, NIL);
+ NULL, NIL,
+ modified_attrs_hint);
+ bms_free(modified_attrs_hint);
+ }
}
if (canSetTag)
--
2.25.1
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-10-27 09:43 ` Simon Riggs <[email protected]>
2020-10-27 18:35 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
3 siblings, 1 reply; 1661+ messages in thread
From: Simon Riggs @ 2020-10-27 09:43 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: Anastasia Lubennikova <[email protected]>; PostgreSQL Hackers <[email protected]>
On Mon, 26 Oct 2020 at 21:15, Peter Geoghegan <[email protected]> wrote:
> Now for the not-so-good news. The TPS numbers looked like this
> (results in original chronological order of the runs, which I've
> interleaved):
While it is important we investigate the worst cases, I don't see this
is necessarily bad.
HOT was difficult to measure, but on a 2+ hour run on a larger table,
the latency graph was what showed it was a winner. Short runs and
in-memory data masked the benefits in our early analyses.
So I suggest not looking at the totals and averages but on the peaks
and the long term trend. Showing that in graphical form is best.
> The patch adds a backstop. It seems to me that that's really what we
> need here. Predictability over time and under a large variety of
> different conditions. Real workloads constantly fluctuate.
Yeh, agreed. This is looking like a winner now, but lets check.
> Even if people end up not buying my argument that it's worth it for
> workloads like this, there are various options. And, I bet I can
> further improve the high contention cases without losing the valuable
> part -- there are a number of ways in which I can get the CPU costs
> down further that haven't been fully explored (yes, it really does
> seem to be CPU costs, especially due to TID sorting). Again, this
> patch is all about extreme pathological workloads, system stability,
> and system efficiency over time -- it is not simply about increasing
> system throughput. There are some aspects of this design (that come up
> with extreme workloads) that may in the end come down to value
> judgments. I'm not going to tell somebody that they're wrong for
> prioritizing different things (within reason, at least). In my opinion
> almost all of the problems we have with VACUUM are ultimately
> stability problems, not performance problems per se. And, I suspect
> that we do very well with stupid benchmarks like this compared to
> other DB systems precisely because we currently allow non-HOT updaters
> to "live beyond their means" (which could in theory be great if you
> frame it a certain way that seems pretty absurd to me). This suggests
> we can "afford" to go a bit slower here as far as the competitive
> pressures determine what we should do (notice that this is a distinct
> argument to my favorite argument, which is that we cannot afford to
> *not* go a bit slower in certain extreme cases).
>
> I welcome debate about this.
Agreed, we can trade initial speed for long term consistency. I guess
there are some heuristics there on that tradeoff.
--
Simon Riggs http://www.EnterpriseDB.com/
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-27 09:43 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
@ 2020-10-27 18:35 ` Peter Geoghegan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-10-27 18:35 UTC (permalink / raw)
To: Simon Riggs <[email protected]>; +Cc: Anastasia Lubennikova <[email protected]>; PostgreSQL Hackers <[email protected]>
On Tue, Oct 27, 2020 at 2:44 AM Simon Riggs <[email protected]> wrote:
> While it is important we investigate the worst cases, I don't see this
> is necessarily bad.
I looked at "perf top" a few times when the test from yesterday ran. I
saw that the proposed delete mechanism was the top consumer of CPU
cycles. It seemed as if the mechanism was very expensive. However,
that's definitely the wrong conclusion about what happens in the
general case, or even in slightly less extreme cases. It at least
needs to be put in context.
I reran exactly the same benchmark overnight, but added a 10k TPS rate
limit this time (so about a third of the TPS that's possible without a
limit). I also ran it for longer, and saw much improved latency. (More
on the latency aspect below, for now I want to talk about "perf top").
The picture with "perf top" changed significantly with a 10k TPS rate
limit, even though the workload itself is very similar. Certainly the
new mechanism/function is still quite close to the top consumer of CPU
cycles. But it no longer uses more cycles than the familiar super hot
functions that you expect to see right at the top with pgbench (e.g.
_bt_compare(), hash_search_with_hash_value()). It's now something like
the 4th or 5th hottest function (I think that that means that the cost
in cycles is more than an order of magnitude lower, but I didn't
check). Just adding this 10k TPS rate limit makes the number of CPU
cycles consumed by the new mechanism seem quite reasonable. The
benefits that the patch brings are not diminished at all compared to
the original no-rate-limit variant -- the master branch now only takes
slightly longer to completely bloat all its indexes with this 10k TPS
limit (while the patch avoids even a single page split -- no change
there).
Again, this is because the mechanism is a backstop. It only works as
hard as needed to avoid unnecessary page splits. When the system is
working as hard as possible to add version churn to indexes (which is
what the original/unthrottled test involved), then the mechanism also
works quite hard. In this artificial and contrived scenario, any
cycles we can save from cleaning up bloat (by micro optimizing the
code in the patch) go towards adding even more bloat instead...which
necessitates doing more cleanup. This is why optimizing the code in
the patch with this unrealistic scenario in mind is subject to sharp
diminishing returns. It's also why you can get a big benefit from the
patch when the new mechanism is barely ever used. I imagine that if I
ran the same test again but with a 1k TPS limit I would hardly see the
new mechanism in "perf top" at all....but in the end the bloat
situation would be very similar.
I think that you could model this probabilistically if you had the
inclination. Yes, the more you throttle throughput (by lowering the
pgbench rate limit further), the less chance you have of any given
leaf page splitting moment to moment (for the master branch). But in
the long run every original leaf page splits at least once anyway,
because each leaf page still only has to be unlucky once. It is still
inevitable that they'll all get split eventually (and probably not
before too long), unless and until you *drastically* throttle pgbench.
I believe that things like opportunistic HOT chain truncation (heap
pruning) and index tuple LP_DEAD bit setting are very effective much
of the time. The problem is that it's easy to utterly rely on them
without even realizing it, which creates hidden risk that may or may
not result in big blow ups down the line. There is nothing inherently
wrong with being lazy or opportunistic about cleaning up garbage
tuples -- I think that there are significant advantages, in fact. But
only if it isn't allowed to create systemic risk. More concretely,
bloat cannot be allowed to become concentrated in any one place -- no
individual query should have to deal with more than 2 or 3 versions
for any given logical row. If we're focussed on the *average* number
of physical versions per logical row then we may reach dramatically
wrong conclusions about what to do (which is a problem in a world
where autovacuum is supposed to do most garbage collection...unless
your app happens to look like standard pgbench!).
And now back to latency with this 10k TPS limited variant I ran last
night. After 16 hours we have performed 8 runs, each lasting 2 hours.
In the original chronological order, these runs are:
patch_1_run_16.out: "tps = 10000.095914 (including connections establishing)"
master_1_run_16.out: "tps = 10000.171945 (including connections establishing)"
patch_1_run_32.out: "tps = 10000.082975 (including connections establishing)"
master_1_run_32.out: "tps = 10000.533370 (including connections establishing)"
patch_2_run_16.out: "tps = 10000.076865 (including connections establishing)"
master_2_run_16.out: "tps = 9997.933215 (including connections establishing)"
patch_2_run_32.out: "tps = 9999.911988 (including connections establishing)"
master_2_run_32.out: "tps = 10000.864031 (including connections establishing)"
Here is what I see at the end of "patch_2_run_32.out" (i.e. at the end
of the final 2 hour run for the patch):
number of transactions actually processed: 71999872
latency average = 0.265 ms
latency stddev = 0.110 ms
rate limit schedule lag: avg 0.046 (max 30.274) ms
tps = 9999.911988 (including connections establishing)
tps = 9999.915766 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 4.0)
0.000 \set aid2 random_gaussian(1, 100000 * :scale, 4.5)
0.000 \set aid3 random_gaussian(1, 100000 * :scale, 4.2)
0.000 \set bid random(1, 1 * :scale)
0.000 \set tid random(1, 10 * :scale)
0.000 \set delta random(-5000, 5000)
0.023 BEGIN;
0.099 UPDATE pgbench_accounts SET abalance = abalance +
:delta WHERE aid = :aid1;
0.036 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.034 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.025 END;
Here is what I see at the end of "master_2_run_32.out" (i.e. at the
end of the final run for master):
number of transactions actually processed: 72006803
latency average = 0.266 ms
latency stddev = 2.722 ms
rate limit schedule lag: avg 0.074 (max 396.853) ms
tps = 10000.864031 (including connections establishing)
tps = 10000.868545 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 4.0)
0.000 \set aid2 random_gaussian(1, 100000 * :scale, 4.5)
0.000 \set aid3 random_gaussian(1, 100000 * :scale, 4.2)
0.000 \set bid random(1, 1 * :scale)
0.000 \set tid random(1, 10 * :scale)
0.000 \set delta random(-5000, 5000)
0.022 BEGIN;
0.073 UPDATE pgbench_accounts SET abalance = abalance +
:delta WHERE aid = :aid1;
0.036 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.034 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.025 END;
Notice the following:
1. The overall "latency average" for the patch is very slightly lower.
2. The overall "latency stddev" for the patch is far far lower -- over
20x lower, in fact.
3. The patch's latency for the UPDATE statement is still somewhat
higher, but it's not so bad. We're still visibly paying a price in
some sense, but at least we're imposing the new costs squarely on the
query that is responsible for all of our problems.
4. The patch's latency for the SELECT statements is exactly the same
for the patch. We're not imposing any new cost on "innocent" SELECT
statements that didn't create the problem, even if they didn't quite
manage to benefit here. (Without LP_DEAD setting in _bt_check_unique()
I'm sure that the SELECT latency would be significantly lower for the
patch.)
The full results (with lots of details pulled from standard system
views after each run) can be downloaded as a .tar.gz archive from:
https://drive.google.com/file/d/1Dn8rSifZqT7pOOIgyKstl-tdACWH-hqO/view?usp=sharing
(It's probably not that interesting to drill down any further, but I
make the full set of results available just in case. There are loads
of things included just because I automatically capture them when
benchmarking anything at all.)
> HOT was difficult to measure, but on a 2+ hour run on a larger table,
> the latency graph was what showed it was a winner. Short runs and
> in-memory data masked the benefits in our early analyses.
Yeah, that's what was nice about working on sorting -- almost instant
feedback. Who wants to spend at least 2 hours to test out every little
theory? :-)
> So I suggest not looking at the totals and averages but on the peaks
> and the long term trend. Showing that in graphical form is best.
I think that you're right that a graphical representation with an
X-axis that shows how much time has passed would be very useful. I'll
try to find a way of incorporating that into my benchmarking workflow.
This is especially likely to help when modelling how cases with a long
running xact/snapshot behave. That isn't a specific goal of mine here,
but I expect that it'll help with that a lot too. For now I'm just
focussing on downsides and not upsides, for the usual reasons.
> Agreed, we can trade initial speed for long term consistency. I guess
> there are some heuristics there on that tradeoff.
Right. Another way of looking at it is this: it should be possible for
reasonably good DBAs to develop good intuitions about how the system
will hold up over time, based on past experience and common sense --
no chaos theory required. Whatever the cost of the mechanism is, at
least it's only something that gets shaved off the top minute to
minute. It seems almost impossible for the cost to cause sudden
surprises (except maybe once, after an initial upgrade to Postgres 14,
though I doubt it). Whereas it seems very likely to prevent many large
and unpleasant surprises caused by hidden, latent risk.
I believe that approximately 100% of DBAs would gladly take that
trade-off, even if the total cost in cycles was higher. It happens to
also be true that they're very likely to use far fewer cycles over
time, but that's really just a bonus.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-10-28 23:05 ` Victor Yegorov <[email protected]>
2020-10-29 23:30 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
3 siblings, 1 reply; 1661+ messages in thread
From: Victor Yegorov @ 2020-10-28 23:05 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
пн, 26 окт. 2020 г. в 22:15, Peter Geoghegan <[email protected]>:
> Attached is v5, which has changes that are focused on two important
> high level goals:
>
I've reviewed v5 of the patch and did some testing.
First things first, the niceties must be observed:
Patch applies, compiles and passes checks without any issues.
It has a good amount of comments that describe the changes very well.
Now to its contents.
I now see what you mean by saying that this patch is a natural and logical
extension of the deduplication v13 work. I agree with this.
Basically, 2 major deduplication strategies exist now:
- by merging duplicates into a posting list; suits non-unique indexes
better,
'cos actual duplicates come from the logically different tuples. This is
existing functionality.
- by deleting dead tuples and reducing need for deduplication at all; suits
unique indexes mostly. This is a subject of this patch and it (to some
extent) undoes v13 functionality around unique indexes, making it better.
Some comments on the patch.
1. In the following comment:
+ * table_index_batch_check() is a variant that is specialized to garbage
+ * collection of dead tuples in index access methods. Duplicates are
+ * commonly caused by MVCC version churn when an optimization like
+ * heapam's HOT cannot be applied. It can make sense to opportunistically
+ * guess that many index tuples are dead versions, particularly in unique
+ * indexes.
I don't quite like the last sentence. Given that this code is committed,
I would rather make it:
… cannot be applied. Therefore we opportunistically check for dead tuples
and reuse the space, delaying leaf page splits.
I understand that "we" shouldn't be used here, but I fail to think of a
proper way to express this.
2. in _bt_dedup_delete_pass() and heap_index_batch_check() you're using some
constants, like:
- expected score of 25
- nblocksaccessed checks for 1, 2 and 3 blocks
- maybe more, but the ones above caught my attention.
Perhaps, it'd be better to use #define-s here instead?
3. Do we really need to touch another heap page, if all conditions are met?
+ if (uniqueindex && nblocksaccessed == 1 && score == 0)
+ break;
+ if (!uniqueindex && nblocksaccessed == 2 && score == 0)
+ break;
+ if (nblocksaccessed == 3)
+ break;
I was really wondering why to look into 2 heap pages. By not doing it
straight away,
we just delay the work for the next occasion that'll work on the same page
we're
processing. I've modified this piece and included it in my tests (see
below), I reduced
2nd condition to just 1 block and limited the 3rd case to 2 blocks (just a
quick hack).
Now for the tests.
I used an i3en.6xlarge EC2 instance with EBS disks attached (24 cores,
192GB RAM).
I've employed the same tests Peter described on Oct 16 (right after v2 of
the patch).
There were some config changes (attached), mostly to produce more logs and
enable
proper query monitoring with pg_stat_statements.
This server is used also for other tests, therefore I am not able to
utilize all core/RAM.
I'm interested in doing so though, subject for the next run of tests.
I've used scale factor 10 000, adjusted indexes (resulting in a 189GB size
database)
and run the following pgbench:
pgbench -f testcase.pgbench -r -c32 -j8 -T 3600 bench
Results (see also attachment):
/* 1, master */
latency average = 16.482 ms
tps = 1941.513487 (excluding connections establishing)
statement latencies in milliseconds:
4.476 UPDATE pgbench_accounts SET abalance = abalance + :delta
WHERE aid = :aid1;
2.084 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
2.090 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
/* 2, v5-patch */
latency average = 12.509 ms
tps = 2558.119453 (excluding connections establishing)
statement latencies in milliseconds:
2.009 UPDATE pgbench_accounts SET abalance = abalance + :delta
WHERE aid = :aid1;
0.868 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.893 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
/* 3, v5-restricted */
latency average = 12.338 ms
tps = 2593.519240 (excluding connections establishing)
statement latencies in milliseconds:
1.955 UPDATE pgbench_accounts SET abalance = abalance + :delta
WHERE aid = :aid1;
0.846 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.866 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
I can see a clear benefit from this patch *under specified conditions, YMMW*
- 32% increase in TPS
- 24% drop in average latency
- most important — stable index size!
Looking at the attached graphs (including statement specific ones):
- CPU activity, Disk reads (reads, not hits) and Transaction throughput are
very
stable for patched version
- CPU's "iowait" is stable and reduced for patched version (expected)
- CPU's "user" peaks out when master starts to split leafs, no such peaks
for the patched version
- there's expected increase in amount of "Disk reads" for patched versions,
although on master we start pretty much on the same level and by the end
of
the test we seem to climb up on reads
- on master, UPDATEs are spending 2x more time on average, reading 3x more
pages than on patched versions
- in fact, "Average query time" and "Query stages" graphs show very nice
caching
effect for patched UPDATEs, a bit clumsy for SELECTs, but still visible
Comparing original and restricted patch versions:
- there's no visible difference in amount of "Disk reads"
- on restricted version UPDATEs behave more gradually, I like this pattern
more, as it feels more stable and predictable
In my opinion, patch provides clear benefits from IO reduction and index
size
control perspective. I really like the stability of operations on patched
version. I would rather stick to the "restricted" version of the patch
though.
Hope this helps. I'm open to do more tests if necessary.
P.S. I am using automated monitoring for graphs, do not have metrics
around, sorry.
--
Victor Yegorov
/* master, conf1, -c32 -j8 -T 3600 // 11:37-12:38 */
transaction type: testcase.pgbench
scaling factor: 10000
query mode: simple
number of clients: 32
number of threads: 8
duration: 3600 s
number of transactions actually processed: 6989491
latency average = 16.482 ms
tps = 1941.512095 (including connections establishing)
tps = 1941.513487 (excluding connections establishing)
statement latencies in milliseconds:
0.002 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 2.2)
0.000 \set bid random(1, 1 * :scale)
0.000 \set tid random(1, 10 * :scale)
0.000 \set delta random(-5000, 5000)
0.043 BEGIN;
4.476 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
2.084 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
2.090 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
7.794 END;
/* v5, conf1, -c32 -j8 -T 3600 // 15:06-16:07 */
transaction type: testcase.pgbench
scaling factor: 10000
query mode: simple
number of clients: 32
number of threads: 8
duration: 3600 s
number of transactions actually processed: 9209274
latency average = 12.509 ms
tps = 2558.117717 (including connections establishing)
tps = 2558.119453 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 2.2)
0.000 \set bid random(1, 1 * :scale)
0.000 \set tid random(1, 10 * :scale)
0.000 \set delta random(-5000, 5000)
0.044 BEGIN;
2.009 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
0.868 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.893 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
8.699 END;
/* v5-restricted, conf1, -c32 -j8 -T 3600 // 18:07-19:08 */
transaction type: testcase.pgbench
scaling factor: 10000
query mode: simple
number of clients: 32
number of threads: 8
duration: 3600 s
number of transactions actually processed: 9336856
latency average = 12.338 ms
tps = 2593.517543 (including connections establishing)
tps = 2593.519240 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 2.2)
0.000 \set bid random(1, 1 * :scale)
0.000 \set tid random(1, 10 * :scale)
0.000 \set delta random(-5000, 5000)
0.044 BEGIN;
1.955 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
0.846 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.866 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
8.633 END;
Attachments:
[text/plain] 20201028-v5-results.txt (3.1K, ../../CAGnEboiJDPdYR4mRsbVZ_VXYXBFv553w3ZbXQKfQAd=9ihW8qg@mail.gmail.com/3-20201028-v5-results.txt)
download | inline:
/* master, conf1, -c32 -j8 -T 3600 // 11:37-12:38 */
transaction type: testcase.pgbench
scaling factor: 10000
query mode: simple
number of clients: 32
number of threads: 8
duration: 3600 s
number of transactions actually processed: 6989491
latency average = 16.482 ms
tps = 1941.512095 (including connections establishing)
tps = 1941.513487 (excluding connections establishing)
statement latencies in milliseconds:
0.002 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 2.2)
0.000 \set bid random(1, 1 * :scale)
0.000 \set tid random(1, 10 * :scale)
0.000 \set delta random(-5000, 5000)
0.043 BEGIN;
4.476 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
2.084 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
2.090 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
7.794 END;
/* v5, conf1, -c32 -j8 -T 3600 // 15:06-16:07 */
transaction type: testcase.pgbench
scaling factor: 10000
query mode: simple
number of clients: 32
number of threads: 8
duration: 3600 s
number of transactions actually processed: 9209274
latency average = 12.509 ms
tps = 2558.117717 (including connections establishing)
tps = 2558.119453 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 2.2)
0.000 \set bid random(1, 1 * :scale)
0.000 \set tid random(1, 10 * :scale)
0.000 \set delta random(-5000, 5000)
0.044 BEGIN;
2.009 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
0.868 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.893 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
8.699 END;
/* v5-restricted, conf1, -c32 -j8 -T 3600 // 18:07-19:08 */
transaction type: testcase.pgbench
scaling factor: 10000
query mode: simple
number of clients: 32
number of threads: 8
duration: 3600 s
number of transactions actually processed: 9336856
latency average = 12.338 ms
tps = 2593.517543 (including connections establishing)
tps = 2593.519240 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 2.2)
0.000 \set bid random(1, 1 * :scale)
0.000 \set tid random(1, 10 * :scale)
0.000 \set delta random(-5000, 5000)
0.044 BEGIN;
1.955 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
0.846 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.866 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
8.633 END;
[image/png] 20201028-v5-cpu.png (187.8K, ../../CAGnEboiJDPdYR4mRsbVZ_VXYXBFv553w3ZbXQKfQAd=9ihW8qg@mail.gmail.com/4-20201028-v5-cpu.png)
download | view image
[image/png] 20201028-v5-dr.png (213.8K, ../../CAGnEboiJDPdYR4mRsbVZ_VXYXBFv553w3ZbXQKfQAd=9ihW8qg@mail.gmail.com/5-20201028-v5-dr.png)
download | view image
[image/png] 20201028-v5-txn.png (147.7K, ../../CAGnEboiJDPdYR4mRsbVZ_VXYXBFv553w3ZbXQKfQAd=9ihW8qg@mail.gmail.com/6-20201028-v5-txn.png)
download | view image
[image/png] 20201028-v5-tqt.png (220.7K, ../../CAGnEboiJDPdYR4mRsbVZ_VXYXBFv553w3ZbXQKfQAd=9ihW8qg@mail.gmail.com/7-20201028-v5-tqt.png)
download | view image
[image/png] 20201028-v5-update-1-master.png (218.9K, ../../CAGnEboiJDPdYR4mRsbVZ_VXYXBFv553w3ZbXQKfQAd=9ihW8qg@mail.gmail.com/8-20201028-v5-update-1-master.png)
download | view image
[image/png] 20201028-v5-update-2-patch.png (214.3K, ../../CAGnEboiJDPdYR4mRsbVZ_VXYXBFv553w3ZbXQKfQAd=9ihW8qg@mail.gmail.com/9-20201028-v5-update-2-patch.png)
download | view image
[image/png] 20201028-v5-update-3-restricted.png (210.4K, ../../CAGnEboiJDPdYR4mRsbVZ_VXYXBFv553w3ZbXQKfQAd=9ihW8qg@mail.gmail.com/10-20201028-v5-update-3-restricted.png)
download | view image
[image/png] 20201028-v5-select-1-master.png (218.7K, ../../CAGnEboiJDPdYR4mRsbVZ_VXYXBFv553w3ZbXQKfQAd=9ihW8qg@mail.gmail.com/11-20201028-v5-select-1-master.png)
download | view image
[image/png] 20201028-v5-select-2-patch.png (218.7K, ../../CAGnEboiJDPdYR4mRsbVZ_VXYXBFv553w3ZbXQKfQAd=9ihW8qg@mail.gmail.com/12-20201028-v5-select-2-patch.png)
download | view image
[image/png] 20201028-v5-select-3-restricted.png (219.1K, ../../CAGnEboiJDPdYR4mRsbVZ_VXYXBFv553w3ZbXQKfQAd=9ihW8qg@mail.gmail.com/13-20201028-v5-select-3-restricted.png)
download | view image
[application/octet-stream] testcase.pgbench (449B, ../../CAGnEboiJDPdYR4mRsbVZ_VXYXBFv553w3ZbXQKfQAd=9ihW8qg@mail.gmail.com/14-testcase.pgbench)
download
[application/octet-stream] postgresql.auto.conf (479B, ../../CAGnEboiJDPdYR4mRsbVZ_VXYXBFv553w3ZbXQKfQAd=9ihW8qg@mail.gmail.com/15-postgresql.auto.conf)
download
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-28 23:05 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
@ 2020-10-29 23:30 ` Peter Geoghegan <[email protected]>
2020-10-30 00:32 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
0 siblings, 1 reply; 1661+ messages in thread
From: Peter Geoghegan @ 2020-10-29 23:30 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Wed, Oct 28, 2020 at 4:05 PM Victor Yegorov <[email protected]> wrote:
> I've reviewed v5 of the patch and did some testing.
Thanks!
> I now see what you mean by saying that this patch is a natural and logical
> extension of the deduplication v13 work. I agree with this.
I tried the patch out with a long running transaction yesterday. I
think that the synergy with the v13 deduplication work really helped.
It took a really long time for an old snapshot to lead to pgbench page
splits (relative to the master branch, running a benchmark like the
one I talked about recently -- the fiver, tenner, score, etc index
benchmark). When the page splits finally started, they seemed much
more gradual -- I don't think that I saw the familiar pattern of
distinct waves of page splits that are clearly all correlated. I think
that the indexes grew at a low steady rate, which looked like the rate
that heap relations usually grow at.
We see a kind of "tick tock" pattern with this new mechanism + v13
deduplication: even when we don't delete very many TIDs, we still free
a few, and then merge the remaining TIDs to buy more time. Very
possibly enough time that a long running transaction goes away by the
time the question of splitting the page comes up again. Maybe there is
another long running transaction by then, but deleting just a few of
the TIDs the last time around is enough to not waste time on that
block this time around, and therefore to actually succeed despite the
second, newer long running transaction (we can delete older TIDs, just
not the now-oldest TIDs that the newer long running xact might still
need).
If this scenario sounds unlikely, bear in mind that "unnecessary" page
splits (which are all we really care about here) are usually only
barely necessary today, if you think about it in a localized/page
level way. What the master branch shows is that most individual
"unnecessary" page splits are in a sense *barely* unnecessary (which
of course doesn't make the consequences any better). We could buy many
hours until the next time the question of splitting a page comes up by
just freeing a small number of tuples -- even on a very busy database.
I found that the "fiver" and "tenner" indexes in particular took a
very long time to have even one page split with a long running
transaction. Another interesting effect was that all page splits
suddenly stopped when my one hour 30 minute long transaction/snapshot
finally went away -- the indexes stopped growing instantly when I
killed the psql session. But on the master branch the cascading
version driven page splits took at least several minutes to stop when
I killed the psql session/snapshot at that same point of the benchmark
(maybe longer). With the master branch, we can get behind on LP_DEAD
index tuple bit setting, and then have no chance of catching up.
Whereas the patch gives us a second chance for each page.
(I really have only started to think about long running transactions
this week, so my understanding is still very incomplete, and based on
guesses and intuitions.)
> I don't quite like the last sentence. Given that this code is committed,
> I would rather make it:
>
> … cannot be applied. Therefore we opportunistically check for dead tuples
> and reuse the space, delaying leaf page splits.
>
> I understand that "we" shouldn't be used here, but I fail to think of a
> proper way to express this.
Makes sense.
> 2. in _bt_dedup_delete_pass() and heap_index_batch_check() you're using some
> constants, like:
> - expected score of 25
> - nblocksaccessed checks for 1, 2 and 3 blocks
> - maybe more, but the ones above caught my attention.
>
> Perhaps, it'd be better to use #define-s here instead?
Yeah. It's still evolving, which is why it's still rough.
It's not easy to come up with a good interface here. Not because it's
very important and subtle. It's actually very *unimportant*, in a way.
nbtree cannot really expect too much from heapam here (though it might
get much more than expected too, when it happens to be easy for
heapam). The important thing is always what happens to be possible at
the local/page level -- the exact preferences of nbtree are not so
important. Beggars cannot be choosers.
It only makes sense to have a "score" like this because sometimes the
situation is so favorable (i.e. there are so many TIDs that can be
killed) that we want to avoid vastly exceeding what is likely to be
useful to nbtree. Actually, this situation isn't that rare (which
maybe means I was wrong to say the score thing was unimportant, but
hopefully you get the idea).
Easily hitting our target score of 25 on the first heap page probably
happens almost all the time when certain kinds of unique indexes use
the mechanism, for example. And when that happens it is nice to only
have to visit one heap block. We're almost sure that it isn't worth
visiting a second, regardless of how many TIDs we're likely to find
there.
> 3. Do we really need to touch another heap page, if all conditions are met?
>
> + if (uniqueindex && nblocksaccessed == 1 && score == 0)
> + break;
> + if (!uniqueindex && nblocksaccessed == 2 && score == 0)
> + break;
> + if (nblocksaccessed == 3)
> + break;
>
> I was really wondering why to look into 2 heap pages. By not doing it straight away,
> we just delay the work for the next occasion that'll work on the same page we're
> processing. I've modified this piece and included it in my tests (see below), I reduced
> 2nd condition to just 1 block and limited the 3rd case to 2 blocks (just a quick hack).
The benchmark that you ran involved indexes that are on a column whose
values are already unique, pgbench_accounts.aid (the extra indexes are
not actually unique indexes, but they could work as unique indexes).
If you actually made them unique indexes then you would have seen the
same behavior anyway.
The 2 heap pages thing is useful with low cardinality indexes. Maybe
that could be better targeted - not sure. Things are still moving
quite fast, and I'm still working on the patch by solving the biggest
problem I see on the horizon. So I will probably change this and then
change it again in the next week anyway.
I've had further success microoptimizing the sorts in heapam.c in the
past couple of days. I think that the regression that I reported can
be further shrunk. To recap, we saw a ~15% lost of throughput/TPS with
16 clients, extreme contention (no rate limiting), several low
cardinality indexes, with everything still fitting in shared_buffers.
It now looks like I can get that down to ~7%, which seems acceptable
to me given the extreme nature of the workload (and given the fact
that we still win on efficiency here -- no index growth).
> I've used scale factor 10 000, adjusted indexes (resulting in a 189GB size database)
> and run the following pgbench:
>
> pgbench -f testcase.pgbench -r -c32 -j8 -T 3600 bench
> I can see a clear benefit from this patch *under specified conditions, YMMW*
> - 32% increase in TPS
> - 24% drop in average latency
> - most important — stable index size!
Nice. When I did a similar test on October 16th it was on a much
smaller database. I think that I saw a bigger improvement because the
initial DB size was close to shared_buffers. So not going over
shared_buffers makes a much bigger difference. Whereas here the DB
size is several times larger, so there is no question about
significantly exceeding shared_buffers -- it's going to happen for the
master branch as well as the patch. (This is kind of obvious, but
pointing it out just in case.)
> In my opinion, patch provides clear benefits from IO reduction and index size
> control perspective. I really like the stability of operations on patched
> version. I would rather stick to the "restricted" version of the patch though.
You're using EBS here, which probably has much higher latency than
what I have here (an NVME SSD). What you have is probably more
relevant to the real world, though.
> Hope this helps. I'm open to do more tests if necessary.
It's great, thanks!
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-28 23:05 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-10-29 23:30 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-10-30 00:32 ` Peter Geoghegan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-10-30 00:32 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Thu, Oct 29, 2020 at 4:30 PM Peter Geoghegan <[email protected]> wrote:
> I found that the "fiver" and "tenner" indexes in particular took a
> very long time to have even one page split with a long running
> transaction. Another interesting effect was that all page splits
> suddenly stopped when my one hour 30 minute long transaction/snapshot
> finally went away -- the indexes stopped growing instantly when I
> killed the psql session. But on the master branch the cascading
> version driven page splits took at least several minutes to stop when
> I killed the psql session/snapshot at that same point of the benchmark
> (maybe longer). With the master branch, we can get behind on LP_DEAD
> index tuple bit setting, and then have no chance of catching up.
> Whereas the patch gives us a second chance for each page.
I forgot to say that this long running xact/snapshot test I ran
yesterday was standard pgbench (more or less) -- no custom indexes.
Unlike my other testing, the only possible source of non-HOT updates
here was not being able to fit a heap tuple on the same heap page
(typically because we couldn't truncate HOT chains in time due to a
long running xact holding back cleanup).
The normal state (without a long running xact/snapshot) is no page
splits, both with the patch and with master. But when you introduce a
long running xact, both master and patch will get page splits. The
difference with the patch is that it'll take much longer to start up
compared to master, the page splits are more gradual and smoother with
the patch, and the patch will stop having page splits just as soon as
the xact goes away -- the same second. With the master branch we're
reliant on LP_DEAD bit setting, and if that gets temporarily held back
by a long snapshot then we have little chance of catching up after the
snapshot goes away but before some pages have unnecessary
version-driven page splits.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-10-29 22:05 ` Victor Yegorov <[email protected]>
2020-10-29 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
3 siblings, 1 reply; 1661+ messages in thread
From: Victor Yegorov @ 2020-10-29 22:05 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
пн, 26 окт. 2020 г. в 22:15, Peter Geoghegan <[email protected]>:
> Attached is v5, which has changes that are focused on two important
> high level goals:
>
And some more comments after another round of reading the patch.
1. Looks like UNIQUE_CHECK_NO_WITH_UNCHANGED is used for HOT updates,
should we use UNIQUE_CHECK_NO_HOT here? It is better understood like
this.
2. You're modifying the table_tuple_update() function on 1311 line of
include/access/tableam.h,
adding modified_attrs_hint. There's a large comment right before it
describing parameters,
I think there should be a note about modified_attrs_hint parameter in
that comment, 'cos
it is referenced from other places in tableam.h and also from
backend/access/heap/heapam.c
3. Can you elaborate on the scoring model you're using?
Why do we expect a score of 25, what's the rationale behind this number?
And should it be #define-d ?
4. heap_compute_xid_horizon_for_tuples contains duplicate logic. Is it
possible to avoid this?
5. In this comment
+ * heap_index_batch_check() helper function. Sorts deltids array in the
+ * order needed for useful processing.
perhaps it is better to replace "useful" with more details? Or point to
the place
where "useful processing" is described.
6. In this snippet in _bt_dedup_delete_pass()
+ else if (_bt_keep_natts_fast(rel, state->base, itup) > nkeyatts &&
+ _bt_dedup_save_htid(state, itup))
+ {
+
+ }
I would rather add a comment, explaining that the empty body of the
clause is actually expected.
7. In the _bt_dedup_delete_finish_pending() you're setting ispromising to
false for both
posting and non-posting tuples. This contradicts comments before
function.
--
Victor Yegorov
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-29 22:05 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
@ 2020-10-29 23:48 ` Peter Geoghegan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-10-29 23:48 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Thu, Oct 29, 2020 at 3:05 PM Victor Yegorov <[email protected]> wrote:
> And some more comments after another round of reading the patch.
>
> 1. Looks like UNIQUE_CHECK_NO_WITH_UNCHANGED is used for HOT updates,
> should we use UNIQUE_CHECK_NO_HOT here? It is better understood like this.
This would probably get me arrested by the tableam police, though.
FWIW the way that that works is still kind of a hack. I think that I
actually need a new boolean flag, rather than overloading the enum
like this.
> 2. You're modifying the table_tuple_update() function on 1311 line of include/access/tableam.h,
> adding modified_attrs_hint. There's a large comment right before it describing parameters,
> I think there should be a note about modified_attrs_hint parameter in that comment, 'cos
> it is referenced from other places in tableam.h and also from backend/access/heap/heapam.c
Okay, makes sense.
> 3. Can you elaborate on the scoring model you're using?
> Why do we expect a score of 25, what's the rationale behind this number?
> And should it be #define-d ?
See my remarks on this from the earlier e-mail.
> 4. heap_compute_xid_horizon_for_tuples contains duplicate logic. Is it possible to avoid this?
Maybe? I think that duplicating code is sometimes the lesser evil.
Like in tuplesort.c, for example. I'm not sure if that's true here,
but it certainly can be true. This is the kind of thing that I usually
only make my mind up about at the last minute. It's a matter of taste.
> 5. In this comment
>
> + * heap_index_batch_check() helper function. Sorts deltids array in the
> + * order needed for useful processing.
>
> perhaps it is better to replace "useful" with more details? Or point to the place
> where "useful processing" is described.
Okay.
> + else if (_bt_keep_natts_fast(rel, state->base, itup) > nkeyatts &&
> + _bt_dedup_save_htid(state, itup))
> + {
> +
> + }
>
> I would rather add a comment, explaining that the empty body of the clause is actually expected.
Okay. Makes sense.
> 7. In the _bt_dedup_delete_finish_pending() you're setting ispromising to false for both
> posting and non-posting tuples. This contradicts comments before function.
The idea is that we can have plain tuples (non-posting list tuples)
that are non-promising when they're duplicates. Because why not?
Somebody might have deleted them (rather than updating them). It is
fine to have an open mind about this possibility despite the fact that
it is close to zero (in the general case). Including these TIDs
doesn't increase the amount of work we do in heapam. Even when we
don't succeed in finding any of the non-dup TIDs as dead (which is
very much the common case), telling heapam about their existence could
help indirectly (which is somewhat more common). This factor alone
could influence which heap pages heapam visits when there is no
concentration of promising tuples on heap pages (since the total
number of TIDs on each block is the tie-breaker condition when
comparing heap blocks with an equal number of promising tuples during
the block group sort in heapam.c). I believe that this approach tends
to result in heapam going after older TIDs when it wouldn't otherwise,
at least in some cases.
You're right, though -- this is still unclear. Actually, I think that
I should move the handling of promising/duplicate tuples into
_bt_dedup_delete_finish_pending(), too (move it from
_bt_dedup_delete_pass()). That would allow me to talk about all of the
TIDs that get added to the deltids array (promising and non-promising)
in one central function. I'll do it that way soon.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-11-03 20:44 ` Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
3 siblings, 1 reply; 1661+ messages in thread
From: Peter Geoghegan @ 2020-11-03 20:44 UTC (permalink / raw)
To: Simon Riggs <[email protected]>; +Cc: Anastasia Lubennikova <[email protected]>; PostgreSQL Hackers <[email protected]>; Victor Yegorov <[email protected]>
On Mon, Oct 26, 2020 at 2:15 PM Peter Geoghegan <[email protected]> wrote:
> Now for the not-so-good news.
> The latency numbers aren't great for the patch, either. Take the 16 client case:
Attached is v6, which more or less totally fixes the problem we saw
with this silly "lots of low cardinality indexes" benchmark.
I wasn't really expecting this to happen -- the benchmark in question
is extreme and rather unrealistic -- but I had some new insights that
made it possible (more details on the code changes towards the end of
this email). Now I don't have to convince anyone that the performance
hit for extreme cases is worth it in order to realize big benefits for
other workloads. There pretty much isn't a performance hit to speak of
now (or so it would seem). I've managed to take this small loss of
performance and turn it into a small gain. And without having to make
any compromises on the core goal of the patch ("no unnecessary page
splits caused by version churn").
With the same indexes ("score", "tenner", "fiver", etc) as before on
pgbench_accounts, and same pgbench-variant queries, we once again see
lots of index bloat with master, but no index bloat at all with v6 of
the patch (no change there). The raw latency numbers are where we see
new improvements for v6. Summary:
2020-11-02 17:35:29 -0800 - Start of initial data load for run
"patch.r1c16" (DB is also used by later runs)
2020-11-02 17:40:21 -0800 - End of initial data load for run "patch.r1c16"
2020-11-02 17:40:21 -0800 - Start of pgbench run "patch.r1c16"
2020-11-02 19:40:31 -0800 - End of pgbench run "patch.r1c16":
patch.r1c16.bench.out: "tps = 9998.129224 (including connections
establishing)" "latency average = 0.243 ms" "latency stddev = 0.088
ms"
2020-11-02 19:40:46 -0800 - Start of initial data load for run
"master.r1c16" (DB is also used by later runs)
2020-11-02 19:45:42 -0800 - End of initial data load for run "master.r1c16"
2020-11-02 19:45:42 -0800 - Start of pgbench run "master.r1c16"
2020-11-02 21:45:52 -0800 - End of pgbench run "master.r1c16":
master.r1c16.bench.out: "tps = 9998.674505 (including connections
establishing)" "latency average = 0.231 ms" "latency stddev = 0.717
ms"
2020-11-02 21:46:10 -0800 - Start of pgbench run "patch.r1c32"
2020-11-02 23:46:23 -0800 - End of pgbench run "patch.r1c32":
patch.r1c32.bench.out: "tps = 9999.968794 (including connections
establishing)" "latency average = 0.256 ms" "latency stddev = 0.104
ms"
2020-11-02 23:46:39 -0800 - Start of pgbench run "master.r1c32"
2020-11-03 01:46:54 -0800 - End of pgbench run "master.r1c32":
master.r1c32.bench.out: "tps = 10001.097045 (including connections
establishing)" "latency average = 0.250 ms" "latency stddev = 1.858
ms"
2020-11-03 01:47:32 -0800 - Start of pgbench run "patch.r2c16"
2020-11-03 03:47:45 -0800 - End of pgbench run "patch.r2c16":
patch.r2c16.bench.out: "tps = 9999.290688 (including connections
establishing)" "latency average = 0.247 ms" "latency stddev = 0.103
ms"
2020-11-03 03:48:04 -0800 - Start of pgbench run "master.r2c16"
2020-11-03 05:48:18 -0800 - End of pgbench run "master.r2c16":
master.r2c16.bench.out: "tps = 10000.424117 (including connections
establishing)" "latency average = 0.241 ms" "latency stddev = 1.587
ms"
2020-11-03 05:48:39 -0800 - Start of pgbench run "patch.r2c32"
2020-11-03 07:48:52 -0800 - End of pgbench run "patch.r2c32":
patch.r2c32.bench.out: "tps = 9999.539730 (including connections
establishing)" "latency average = 0.258 ms" "latency stddev = 0.125
ms"
2020-11-03 07:49:11 -0800 - Start of pgbench run "master.r2c32"
2020-11-03 09:49:26 -0800 - End of pgbench run "master.r2c32":
master.r2c32.bench.out: "tps = 10000.833754 (including connections
establishing)" "latency average = 0.250 ms" "latency stddev = 0.997
ms"
These are 2 hour runs, 16 and 32 clients -- same as last time (though
note the 10k TPS limit). So 4 pairs of runs (each pair of runs is a
pair of patch/master runs) making 8 runs total, lasting 16 hours total
(not including initial data loading).
Notice that the final pair of runs shows that the master branch
eventually gets to the point of having far higher latency stddev. The
stddev starts high and gets higher as time goes on. Here is the
latency breakdown for the final pair of runs:
patch.r2c32.bench.out:
scaling factor: 1000
query mode: prepared
number of clients: 32
number of threads: 8
duration: 7200 s
number of transactions actually processed: 71997119
latency average = 0.258 ms
latency stddev = 0.125 ms
rate limit schedule lag: avg 0.046 (max 39.151) ms
tps = 9999.539730 (including connections establishing)
tps = 9999.544743 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 4.0)
0.000 \set aid2 random_gaussian(1, 100000 * :scale, 4.5)
0.000 \set aid3 random_gaussian(1, 100000 * :scale, 4.2)
0.000 \set bid random(1, 1 * :scale)
0.000 \set tid random(1, 10 * :scale)
0.000 \set delta random(-5000, 5000)
0.022 BEGIN;
0.091 UPDATE pgbench_accounts SET abalance = abalance +
:delta WHERE aid = :aid1;
0.036 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.034 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.025 END;
master.r2c32.bench.out:
query mode: prepared
number of clients: 32
number of threads: 8
duration: 7200 s
number of transactions actually processed: 72006667
latency average = 0.250 ms
latency stddev = 0.997 ms
rate limit schedule lag: avg 0.053 (max 233.045) ms
tps = 10000.833754 (including connections establishing)
tps = 10000.839935 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 4.0)
0.000 \set aid2 random_gaussian(1, 100000 * :scale, 4.5)
0.000 \set aid3 random_gaussian(1, 100000 * :scale, 4.2)
0.000 \set bid random(1, 1 * :scale)
0.000 \set tid random(1, 10 * :scale)
0.000 \set delta random(-5000, 5000)
0.023 BEGIN;
0.075 UPDATE pgbench_accounts SET abalance = abalance +
:delta WHERE aid = :aid1;
0.037 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.035 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.026 END;
There is only one aspect of this that the master branch still wins on
by the end -- the latency on the UPDATE is still a little lower on
master. This happens for the obvious reason: the UPDATE doesn't clean
up after itself on the master branch (to the extent that the average
xact latency is still a tiny bit higher with the patch). But the
SELECT queries are never actually slower with the patch, even during
earlier runs -- they're just as fast as the master branch (and faster
than the master branch by the end). Only the UPDATEs can ever be made
slower, so AFAICT any new cost is only experienced by the queries that
create the problem for the system as a whole. We're imposing new costs
fairly.
Performance with the patch is consistently much more stable. We don't
get overwhelmed by FPIs in the way we see with the master branch,
which causes sudden gluts that are occasionally very severe (notice
that master.r2c16.bench.out was a big stddev outlier). Maybe the most
notable thing is the max rate limit schedule lag. In the last run we
see max 39.151 ms for the patch vs max 233.045 ms for master.
Now for a breakdown of the code enhancements behind the improved
benchmark numbers. They are:
* The most notable improvement is to the sort order of the heap block
groups within heapam.c. We now round up to the next power of two when
sorting candidate heap blocks (this is the sort used to decide which
heap blocks to visit, and in what order). The "number of promising
TIDs" field (as well as the "number of TIDs total" tiebreaker) is
rounded up so that we ignore relatively small differences. We now tend
to process related groups of contiguous pages in relatively big
batches -- though only where appropriate.
* A closely related optimization was also added to heapam.c:
"favorable blocks". That is, we recognize groups of related heap
blocks that are contiguous. When we encounter these blocks we make
heapam.c effectively increase its per-call batch size, so that it
processes more blocks in the short term but does less absolute work in
the long run.
The key insight behind both of these enhancements is that physically
close heap blocks are generally also close together in time, and
generally share similar characteristics (mostly LP_DEAD items vs
mostly live items, already in shared_buffers, etc). So we're focussing
more on heap locality when the hint we get from nbtree isn't giving us
a very strong signal about what to do (we need to be very judicious
because we are still only willing to access a small number of heap
blocks at a time). While in general the best information heapam has to
go on comes from nbtree, heapam should not care about noise-level
variations in that information -- better to focus on heap locality
(IOW heapam.c needs to have a sophisticated understanding of the
limitations of the hints it receives from nbtree). As a result of
these two changes, heapam.c tends to process earlier blocks/records
first, in order, in a way that is correlated across time and across
indexes -- with more sequential I/O and more confidence in a
successful outcome when we undertake work. (Victor should note that
heapam.c no longer has any patience when it encounters even a single
heap block with no dead TIDs -- he was right about that. The new
heapam.c stuff works well enough that there is no possible upside to
"being patient", even with indexes on low cardinality data that
experience lots of version churn, a workload that my recent
benchmarking exemplifies.)
* nbtdedup.c will now give heapam.c an accurate idea about its
requirements -- it now expresses those in terms of space freed, which
heapam.c now cares about directly. This matters a lot with low
cardinality data, where freeing an entire index tuple is a lot more
valuable to nbtree than freeing just one TID in a posting list
(because the former case frees up 20 bytes at a minimum, while the
latter case usually only frees up 6 bytes).
I said something to Victor about nbtree's wishes not being important
here -- heapam.c is in charge. But that now seems like the wrong
mental model. After all, how can nbtree not be important if it is
entitled to call heapam.c as many times as it feels like, without
caring about the cost of thrashing (as we saw with low cardinality
data prior to v6)? With v6 of the patch I took my own advice about not
thinking of each operation as an isolated event. So now heapam.c has a
more nuanced understanding of the requirements of nbtree, and can be
either more eager or more lazy according to 1) nbtree requirements,
and 2.) conditions local to heapam.c.
* Improved handling of low cardinality data in nbtdedup.c -- we now
always merge together items with low cardinality data, regardless of
how well we do with deleting TIDs. This buys more time before the next
delete attempt for the same page.
* Specialized shellsort implementations for heapam.c.
Shellsort is sometimes used as a lightweight system qsort in embedded
systems. It has many of the same useful properties as a well optimized
quicksort for smaller datasets, and also has the merit of compiling to
far fewer instructions when specialized like this. Specializing on
qsort (as in v5) results in machine code that seems rather heavyweight
given the heapam.c requirements. Instruction cache matters here
(although that's easy to miss when profiling).
v6 still needs more polishing -- my focus has still been on the
algorithm itself. But I think I'm almost done with that part -- it
seems unlikely that I'll be able to make any additional significant
improvements in that area after v6. The new bucketized heap block
sorting behavior seems to be really effective, especially with low
cardinality data, and especially over time, as the heap naturally
becomes more fragmented. We're now blending together locality from
nbtree and heapam in an adaptive way.
I'm pretty sure that the performance on sympathetic cases (such as the
case Victor tested) will also be a lot better, though I didn't look
into that on v6. If Victor is in a position to run further benchmarks
on v6, that would certainly be welcome (independent validation always
helps).
I'm not aware of any remaining cases that it would be fair to describe
as being regressed by the patch -- can anybody else think of any
possible candidates?
BTW, I will probably rename the mechanism added by the patch to
"bottom-up index vacuuming", or perhaps "bottom-up index deletion" --
that seems to capture the general nature of what the patch does quite
well. Now regular index vacuuming can be thought of as a top-down
complementary mechanism that takes care of remaining diffuse spots of
garbage tuples that queries happen to miss (more or less). Also, while
it is true that there are some ways in which the patch is related to
deduplication, it doesn't seem useful to emphasize that part anymore.
Plus clarifying which kind of deduplication I'm talking about in code
comments is starting to become really annoying.
--
Peter Geoghegan
Attachments:
[application/octet-stream] v6-0001-Add-delete-deduplication-to-nbtree.patch (98.4K, ../../CAH2-WznT15uA_86JxvCf5fPPTAn-H7uS8TS3CzvToqERbuU52A@mail.gmail.com/2-v6-0001-Add-delete-deduplication-to-nbtree.patch)
download | inline diff:
From bc045efdfc672f26428b56b105e53dcd9ead08b9 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Tue, 30 Jun 2020 16:29:27 -0700
Subject: [PATCH v6] Add delete deduplication to nbtree.
Repurpose deduplication infrastructure to delete items in indexes at the
point where we'd usually have to split the page, even when they don't
have their LP_DEAD bits set. Testing has shown that this is almost
completely effective at preventing "version index bloat" from non-HOT
updates, provided there are no long running transactions.
This is primarily valuable with leaf pages that contain mostly-distinct
index tuples, particularly with unique indexes. It is intended to
complement deduplication. Heuristics are used to guess which index
tuples are likely to point to no longer needed old table row versions.
Note that INCLUDE indexes support the optimization.
---
src/include/access/genam.h | 15 +
src/include/access/heapam.h | 7 +-
src/include/access/nbtree.h | 11 +-
src/include/access/nbtxlog.h | 9 +-
src/include/access/tableam.h | 61 +-
src/include/executor/executor.h | 3 +-
src/backend/access/heap/heapam.c | 617 +++++++++++++++++-
src/backend/access/heap/heapam_handler.c | 5 +-
src/backend/access/nbtree/README | 33 +-
src/backend/access/nbtree/nbtdedup.c | 763 +++++++++++++++++++++--
src/backend/access/nbtree/nbtinsert.c | 62 +-
src/backend/access/nbtree/nbtpage.c | 121 +++-
src/backend/access/nbtree/nbtsort.c | 12 +-
src/backend/access/nbtree/nbtxlog.c | 55 +-
src/backend/access/table/tableam.c | 29 +-
src/backend/commands/copy.c | 5 +-
src/backend/executor/execIndexing.c | 41 +-
src/backend/executor/execReplication.c | 4 +-
src/backend/executor/nodeModifyTable.c | 14 +-
19 files changed, 1749 insertions(+), 118 deletions(-)
diff --git a/src/include/access/genam.h b/src/include/access/genam.h
index 68d90f5141..7002da0716 100644
--- a/src/include/access/genam.h
+++ b/src/include/access/genam.h
@@ -108,10 +108,25 @@ typedef struct ParallelIndexScanDescData *ParallelIndexScanDesc;
* call is made with UNIQUE_CHECK_EXISTING. The tuple is already in the
* index in this case, so it should not be inserted again. Rather, just
* check for conflicting live tuples (possibly blocking).
+ *
+ * UNIQUE_CHECK_NO indicates the absence of any unique checking.
+ * UNIQUE_CHECK_NO_WITH_UNCHANGED is a variant of UNIQUE_CHECK_NO that
+ * indicates that the index tuple comes from an UPDATE that did not modify
+ * the row in respect of any columns that are indexed. The implementation
+ * requires a successor version, but there is no logical change. Some
+ * index access AMs can use this as hint that can trigger optimizations.
+ *
+ * XXX: Adding UNIQUE_CHECK_NO_WITH_UNCHANGED like this kind of makes
+ * sense, since it's pretty natural to leave it up to index AMs to figure
+ * it out with unique indexes. But what about when we insert NULLs into a
+ * unique index? Isn't that case UNIQUE_CHECK_YES, and yet also a thing
+ * that nbtree pretty much treats as UNIQUE_CHECK_NO once it sees that the
+ * index tuple has NULLs?
*/
typedef enum IndexUniqueCheck
{
UNIQUE_CHECK_NO, /* Don't do any uniqueness checking */
+ UNIQUE_CHECK_NO_WITH_UNCHANGED, /* "No logical change" duplicate */
UNIQUE_CHECK_YES, /* Enforce uniqueness at insertion time */
UNIQUE_CHECK_PARTIAL, /* Test uniqueness, but no error */
UNIQUE_CHECK_EXISTING /* Check if existing tuple is unique */
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 92b19dba32..49ef64b2bb 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -148,7 +148,8 @@ extern void heap_abort_speculative(Relation relation, ItemPointer tid);
extern TM_Result heap_update(Relation relation, ItemPointer otid,
HeapTuple newtup,
CommandId cid, Snapshot crosscheck, bool wait,
- struct TM_FailureData *tmfd, LockTupleMode *lockmode);
+ struct TM_FailureData *tmfd, LockTupleMode *lockmode,
+ Bitmapset **modified_attrs_hint);
extern TM_Result heap_lock_tuple(Relation relation, HeapTuple tuple,
CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy,
bool follow_update,
@@ -170,6 +171,10 @@ extern void simple_heap_update(Relation relation, ItemPointer otid,
extern TransactionId heap_compute_xid_horizon_for_tuples(Relation rel,
ItemPointerData *items,
int nitems);
+extern TransactionId heapam_index_delete_check(Relation rel, TM_IndexDelete *deltids,
+ TM_IndexDeleteStatus *statusdeltids,
+ int ndeltids, int targetfreespace,
+ int *finalndeltids);
/* in heap/pruneheap.c */
struct GlobalVisState;
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index 65d9698b89..b2279cccb2 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -77,6 +77,7 @@ typedef BTPageOpaqueData *BTPageOpaque;
#define BTP_SPLIT_END (1 << 5) /* rightmost page of split group */
#define BTP_HAS_GARBAGE (1 << 6) /* page has LP_DEAD tuples */
#define BTP_INCOMPLETE_SPLIT (1 << 7) /* right sibling's downlink is missing */
+#define BTP_HAS_DUPS (1 << 8) /* page has at least one version duplicate */
/*
* The max allowed value of a cycle ID is a bit less than 64K. This is
@@ -219,6 +220,7 @@ typedef struct BTMetaPageData
#define P_IGNORE(opaque) (((opaque)->btpo_flags & (BTP_DELETED|BTP_HALF_DEAD)) != 0)
#define P_HAS_GARBAGE(opaque) (((opaque)->btpo_flags & BTP_HAS_GARBAGE) != 0)
#define P_INCOMPLETE_SPLIT(opaque) (((opaque)->btpo_flags & BTP_INCOMPLETE_SPLIT) != 0)
+#define P_HAS_DUPS(opaque) (((opaque)->btpo_flags & BTP_HAS_DUPS) != 0)
/*
* Lehman and Yao's algorithm requires a ``high key'' on every non-rightmost
@@ -1029,11 +1031,12 @@ extern void _bt_parallel_advance_array_keys(IndexScanDesc scan);
*/
extern void _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
IndexTuple newitem, Size newitemsz,
- bool checkingunique);
+ bool checkingunique, bool dedupdelete,
+ bool allequalimage);
extern void _bt_dedup_start_pending(BTDedupState state, IndexTuple base,
OffsetNumber baseoff);
extern bool _bt_dedup_save_htid(BTDedupState state, IndexTuple itup);
-extern Size _bt_dedup_finish_pending(Page newpage, BTDedupState state);
+extern Size _bt_dedup_merge_finish_pending(Page newpage, BTDedupState state);
extern IndexTuple _bt_form_posting(IndexTuple base, ItemPointer htids,
int nhtids);
extern void _bt_update_posting(BTVacuumPosting vacposting);
@@ -1084,7 +1087,9 @@ extern void _bt_delitems_vacuum(Relation rel, Buffer buf,
BTVacuumPosting *updatable, int nupdatable);
extern void _bt_delitems_delete(Relation rel, Buffer buf,
OffsetNumber *deletable, int ndeletable,
- Relation heapRel);
+ BTVacuumPosting *updatable, int nupdatable,
+ Relation heapRel, bool isdedup,
+ TransactionId dedupLatestRemovedXid);
extern uint32 _bt_pagedel(Relation rel, Buffer leafbuf,
TransactionId *oldestBtpoXact);
diff --git a/src/include/access/nbtxlog.h b/src/include/access/nbtxlog.h
index 5c014bdc66..4006872d7a 100644
--- a/src/include/access/nbtxlog.h
+++ b/src/include/access/nbtxlog.h
@@ -187,12 +187,15 @@ typedef struct xl_btree_dedup
typedef struct xl_btree_delete
{
TransactionId latestRemovedXid;
- uint32 ndeleted;
+ uint16 ndeleted;
+ uint16 nupdated;
/* DELETED TARGET OFFSET NUMBERS FOLLOW */
+ /* UPDATED TARGET OFFSET NUMBERS FOLLOW */
+ /* UPDATED TUPLES METADATA ARRAY FOLLOWS */
} xl_btree_delete;
-#define SizeOfBtreeDelete (offsetof(xl_btree_delete, ndeleted) + sizeof(uint32))
+#define SizeOfBtreeDelete (offsetof(xl_btree_delete, nupdated) + sizeof(uint16))
/*
* This is what we need to know about page reuse within btree. This record
@@ -213,7 +216,7 @@ typedef struct xl_btree_reuse_page
/*
* This is what we need to know about which TIDs to remove from an individual
* posting list tuple during vacuuming. An array of these may appear at the
- * end of xl_btree_vacuum records.
+ * end of xl_btree_vacuum and xl_btree_delete records.
*/
typedef struct xl_btree_update
{
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 387eb34a61..127de234aa 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -128,6 +128,29 @@ typedef struct TM_FailureData
bool traversed;
} TM_FailureData;
+/*
+ * State used by table_index_delete_check() to perform "bottom up" deletion of
+ * duplicate index tuples.
+ *
+ * We store this in two structs, even though it would be more natural to just
+ * have one struct (and one array). We really need to keep the TM_IndexDelete
+ * struct small (8 bytes) so that we can do an initial sort by TID as quickly
+ * as possible.
+ */
+typedef struct TM_IndexDelete
+{
+ ItemPointerData tid; /* table TID from index tuple */
+ int16 id; /* Offset into TM_IndexDeleteStatus array */
+} TM_IndexDelete;
+
+typedef struct TM_IndexDeleteStatus
+{
+ OffsetNumber ioffnum; /* Index am identifies entries with this */
+ bool ispromising; /* Contribute to order we visit table blocks? */
+ bool isdead; /* Was tuple found dead? */
+ int16 tupsize; /* Space freed in index if tuple found dead */
+} TM_IndexDeleteStatus;
+
/* "options" flag bits for table_tuple_insert */
/* TABLE_INSERT_SKIP_WAL was 0x0001; RelationNeedsWAL() now governs */
#define TABLE_INSERT_SKIP_FSM 0x0002
@@ -396,7 +419,8 @@ typedef struct TableAmRoutine
bool wait,
TM_FailureData *tmfd,
LockTupleMode *lockmode,
- bool *update_indexes);
+ bool *update_indexes,
+ Bitmapset **modified_attrs_hint);
/* see table_tuple_lock() for reference about parameters */
TM_Result (*tuple_lock) (Relation rel,
@@ -1041,16 +1065,35 @@ table_index_fetch_tuple(struct IndexFetchTableData *scan,
}
/*
- * This is a convenience wrapper around table_index_fetch_tuple() which
- * returns whether there are table tuple items corresponding to an index
- * entry. This likely is only useful to verify if there's a conflict in a
- * unique index.
+ * These are convenience wrappers around table_index_fetch_tuple() which
+ * indicate whether there are table tuple items corresponding to an index
+ * entry. Can be used to verify if there's a conflict in a unique index.
+ *
+ * table_index_delete_check() is used for garbage collection of dead tuples in
+ * index access methods. Index AMs use it to request that we check for dead
+ * tuples among recent duplicates. This happens when the index tuples are
+ * suspected to be older versions of logical rows that were unchanged by
+ * successive UPDATEs, but still required successor versions in indexes
+ * (because an optimization like heapam's HOT could not be applied). Index
+ * AMs that use the optimization base their inferences about old versions in
+ * part on a hint from the executor (that indicates when an incoming tuple is
+ * for a successor version with no logical changes in respect of any indexed
+ * attribute).
+ *
+ * Note that table_index_delete_check() sorts the deltids array so that the
+ * order of access is optimized. Callers need to be able to deal with
+ * that.
*/
extern bool table_index_fetch_tuple_check(Relation rel,
ItemPointer tid,
Snapshot snapshot,
bool *all_dead);
+extern int table_index_delete_check(Relation rel,
+ TM_IndexDelete *deltids,
+ int ndeltids,
+ Snapshot snapshot,
+ int npromisingkillsneeded);
/* ------------------------------------------------------------------------
* Functions for non-modifying operations on individual tuples
@@ -1292,6 +1335,9 @@ table_tuple_delete(Relation rel, ItemPointer tid, CommandId cid,
* lockmode - filled with lock mode acquired on tuple
* update_indexes - in success cases this is set to true if new index entries
* are required for this tuple
+ * modified_attrs_hint - which attributes were logically modified by the
+ * update. Passed down to index AMs as a hint from the executor.
+ * Enables table_index_delete_check() optimization.
*
* Normal, successful return value is TM_Ok, which means we did actually
* update it. Failure return codes are TM_SelfModified, TM_Updated, and
@@ -1311,12 +1357,13 @@ static inline TM_Result
table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot,
CommandId cid, Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode,
- bool *update_indexes)
+ bool *update_indexes, Bitmapset **modified_attrs_hint)
{
return rel->rd_tableam->tuple_update(rel, otid, slot,
cid, snapshot, crosscheck,
wait, tmfd,
- lockmode, update_indexes);
+ lockmode, update_indexes,
+ modified_attrs_hint);
}
/*
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h
index 0c48d2a519..6e6e56583b 100644
--- a/src/include/executor/executor.h
+++ b/src/include/executor/executor.h
@@ -582,7 +582,8 @@ extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
extern List *ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot, EState *estate,
bool noDupErr,
- bool *specConflict, List *arbiterIndexes);
+ bool *specConflict, List *arbiterIndexes,
+ Bitmapset *modified_attrs_hint);
extern bool ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot,
EState *estate, ItemPointer conflictTid,
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 1585861a02..4f41071687 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -55,6 +55,7 @@
#include "miscadmin.h"
#include "pgstat.h"
#include "port/atomics.h"
+#include "port/pg_bitutils.h"
#include "storage/bufmgr.h"
#include "storage/freespace.h"
#include "storage/lmgr.h"
@@ -70,6 +71,17 @@
#include "utils/snapmgr.h"
#include "utils/spccache.h"
+typedef struct IndexDeleteCounts
+{
+ int16 npromisingtids;
+ int16 ntids;
+ int16 ideltids;
+} IndexDeleteCounts;
+
+/*
+ * Shellsort gap sequence taken from Sedgewick-Incerpi paper
+ */
+static const int shellsort_gaps[8] = {861, 336, 112, 48, 21, 7, 3, 1};
static HeapTuple heap_prepare_insert(Relation relation, HeapTuple tup,
TransactionId xid, CommandId cid, int options);
@@ -102,6 +114,17 @@ static void MultiXactIdWait(MultiXactId multi, MultiXactStatus status, uint16 in
int *remaining);
static bool ConditionalMultiXactIdWait(MultiXactId multi, MultiXactStatus status,
uint16 infomask, Relation rel, int *remaining);
+static int heapam_index_delete_check_sort(Relation rel, TM_IndexDelete *deltids,
+ TM_IndexDeleteStatus *statusdeltids,
+ int ndeltids, int *nblocksfavorable);
+static void top_block_groups_favorable(IndexDeleteCounts *blockcounts,
+ int nblockgroups, TM_IndexDelete *deltids,
+ int *nblocksfavorable);
+static void heap_tid_shellsort(TM_IndexDelete *deltids, int ndeltids);
+static void index_delete_shellsort(IndexDeleteCounts *blockcounts, int nblockgroups);
+static inline int indexdelete_tids_cmp(ItemPointer tid1, ItemPointer tid2);
+static inline int indexdeletecount_cmp(IndexDeleteCounts *count1,
+ IndexDeleteCounts *count2);
static XLogRecPtr log_heap_new_cid(Relation relation, HeapTuple tup);
static HeapTuple ExtractReplicaIdentity(Relation rel, HeapTuple tup, bool key_changed,
bool *copy);
@@ -2892,7 +2915,8 @@ simple_heap_delete(Relation relation, ItemPointer tid)
TM_Result
heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
CommandId cid, Snapshot crosscheck, bool wait,
- TM_FailureData *tmfd, LockTupleMode *lockmode)
+ TM_FailureData *tmfd, LockTupleMode *lockmode,
+ Bitmapset **modified_attrs_hint)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -3758,10 +3782,15 @@ l2:
if (old_key_tuple != NULL && old_key_copied)
heap_freetuple(old_key_tuple);
+ /* Save for no logical changes hint when non-HOT update performed */
+ if (!use_hot_update && modified_attrs_hint)
+ *modified_attrs_hint = modified_attrs;
+ else
+ bms_free(modified_attrs);
+
bms_free(hot_attrs);
bms_free(key_attrs);
bms_free(id_attrs);
- bms_free(modified_attrs);
bms_free(interesting_attrs);
return TM_Ok;
@@ -3891,7 +3920,7 @@ simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
result = heap_update(relation, otid, tup,
GetCurrentCommandId(true), InvalidSnapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode);
+ &tmfd, &lockmode, NULL);
switch (result)
{
case TM_SelfModified:
@@ -6987,6 +7016,9 @@ xid_horizon_prefetch_buffer(Relation rel,
* deleting hundreds of tuples from a single index block. To amortize that
* cost to some degree, this uses prefetching and combines repeat accesses to
* the same block.
+ *
+ * Note: The logic for maintaining latestRemovedXid here is duplicated by code
+ * within heapam_index_delete_check(). Make sure that they stay in sync.
*/
TransactionId
heap_compute_xid_horizon_for_tuples(Relation rel,
@@ -7086,7 +7118,6 @@ heap_compute_xid_horizon_for_tuples(Relation rel,
{
hoffnum = ItemIdGetRedirect(hitemid);
hitemid = PageGetItemId(hpage, hoffnum);
- CHECK_FOR_INTERRUPTS();
}
/*
@@ -7134,6 +7165,584 @@ heap_compute_xid_horizon_for_tuples(Relation rel,
return latestRemovedXid;
}
+#define MAX_DELETE_HEAP_BLOCKS 4
+#define FAVORABLE_BLOCK_STRIDE 3
+
+/*
+ * Help with "bottom up" deletion of duplicate index tuples from index AMs.
+ *
+ * Index am caller provides target amount of space to free in index. We try
+ * to honor caller's request, but it must be weighed against the need to not
+ * do too much work all at once. We determine the total amount of free space
+ * that caller will be able to free by adding the value of the tupsize field
+ * from the deltids elements that pertain to the heap tuples that are found
+ * dead here.
+ *
+ * We also want to avoid doing too little work when we see an opportunity to
+ * save work in the long run. Though the main thing that influences which
+ * heap pages are accessed is which TIDs caller has marked promising" (which
+ * caller takes from duplicate index tuples believed to have been inserted in
+ * index recently), we also take advantage of heapam locality here. We
+ * sometimes favor larger batch sizes for our own reasons. For example we
+ * consider contiguous heap blocks favorable and try to process more of these
+ * each call here, which can happen quite often due to the way we prioritize
+ * which blocks to process. We expect to be called multiple times for related
+ * records in at least some cases. The cost of all of these calls taken
+ * together is the most important consideration (the cost of any individual
+ * call is less important).
+ *
+ * This routine sorts the deltids array, but does not modify any individual
+ * entry except to mark it as dead for caller. *finaldeltids is set to the
+ * size of the subset of the final sorted deltids array that contains all
+ * entries marked dead for caller (the subset begins at the start of deltids
+ * and ends after *finaldeltids array elements). Caller will only need to
+ * consider this interesting subset of deltids, but note that only some of the
+ * subset's elements are actually marked dead/safe to delete in index. Caller
+ * should do nothing when finalndeltids is set to 0.
+ *
+ * Returns the latestRemovedXid from the heap pages pointed at by the deltids
+ * index tuples that caller will delete. Caller deletes all deltids related
+ * index tuples that get marked dead here, and uses latestRemovedXid to
+ * generate a recovery conflict (if and when a conflict is required).
+ *
+ * Note: The logic for maintaining latestRemovedXid here is duplicated by code
+ * within heap_compute_xid_horizon_for_tuples(). Make sure that they stay in
+ * sync.
+ */
+TransactionId
+heapam_index_delete_check(Relation rel, TM_IndexDelete *deltids,
+ TM_IndexDeleteStatus *statusdeltids, int ndeltids,
+ int targetfreespace, int *finalndeltids)
+{
+ TransactionId latestRemovedXid = InvalidTransactionId;
+ BlockNumber hblkno = InvalidBlockNumber;
+ Buffer buf = InvalidBuffer;
+ Page hpage;
+ bool finalhpage = false;
+ int nblocksaccessed = 0;
+ int nblocksfavorable = 0;
+ int spacefreed = 0;
+ int spacefreedbeforecurhpage = 0;
+ SnapshotData SnapshotNonVacuumable;
+
+ InitNonVacuumableSnapshot(SnapshotNonVacuumable, GlobalVisTestFor(rel));
+
+ *finalndeltids = 0;
+
+ /*
+ * Sort and shrink deltids array so that it consists only of TIDs from 3
+ * most promising blocks. We expect the most promising block first (and
+ * third most promising block third/last).
+ */
+ ndeltids = heapam_index_delete_check_sort(rel, deltids, statusdeltids,
+ ndeltids, &nblocksfavorable);
+ for (int i = 0; i < ndeltids; i++)
+ {
+ TM_IndexDeleteStatus *status = statusdeltids + deltids[i].id;
+ ItemPointer htid = &deltids[i].tid;
+ ItemPointerData tmp;
+ bool all_dead = false;
+ bool found;
+ ItemId hitemid;
+ OffsetNumber hoffnum;
+ HeapTupleData heapTuple;
+
+ Assert(!status->isdead);
+
+ if (hblkno == InvalidBlockNumber ||
+ ItemPointerGetBlockNumber(htid) != hblkno)
+ {
+ /*
+ * We usually do a little extra work on the final heap page after
+ * caller's target space to free has been reached. The cost of
+ * accessing the final heap page we'll need to visit has already
+ * been paid by that point. We finish off the entire final heap
+ * page because it's cheap to do so.
+ *
+ * We don't want to unnecessarily visit the next page in line.
+ * Handle that here (when we just finished final page).
+ */
+ if (finalhpage)
+ break;
+
+ /*
+ * Each time we're about to access a new page we consider if it's
+ * really worth it. We apply two tests before we visit the next
+ * page, and give up if either fails:
+ *
+ * 1. Give up when we didn't enable our caller to free any
+ * additional space as a result of processing the most recent heap
+ * page visited. We expect to make steady progress or no
+ * progress.
+ *
+ * 2. Give up when MAX_DELETE_HEAP_BLOCKS have been accessed
+ * already, no matter what. (This is defensive, since the deltids
+ * array was shrunk before we started. It should now contain TIDs
+ * from pages not exceeding MAX_DELETE_HEAP_BLOCKS in number.)
+ */
+ if (nblocksaccessed >= 1 && spacefreed == spacefreedbeforecurhpage)
+ break;
+ if (nblocksaccessed == MAX_DELETE_HEAP_BLOCKS)
+ break;
+
+ /*
+ * After visiting and processing the first heap page, aggressively
+ * decay target space freed (the request from index am caller)
+ * before accessing each new heap page (starting with the second
+ * in line). But only start decaying when we encounter our first
+ * non-favorable block.
+ *
+ * Favorable blocks are contiguous groups of heap blocks that are
+ * likely to have related heap tuples that are cheaper to process
+ * in larger batches. It doesn't make sense to be stingy here.
+ * The index am may end up calling us about the same heap TIDs
+ * before much time has passed if we do that.
+ *
+ * Note that even favorable blocks are required to enable caller
+ * to free at least some space -- otherwise we give up before
+ * accessing the next block in line. If a favorable block cannot
+ * be freed then there is probably an old snapshot that frustrates
+ * progress here in general.
+ */
+ if (nblocksaccessed >= 1 && nblocksfavorable == 0)
+ targetfreespace /= 2;
+
+ /* Now access next page */
+ if (BufferIsValid(buf))
+ {
+ LockBuffer(buf, BUFFER_LOCK_UNLOCK);
+ ReleaseBuffer(buf);
+ }
+
+ /*
+ * We could prune the heap page in passing here, but that doesn't
+ * seem like a good idea. (Index am caller is expected to hold
+ * locks of its own.)
+ */
+ hblkno = ItemPointerGetBlockNumber(htid);
+ buf = ReadBuffer(rel, hblkno);
+ hpage = BufferGetPage(buf);
+ nblocksaccessed++;
+ if (nblocksfavorable > 0)
+ nblocksfavorable--;
+ spacefreedbeforecurhpage = spacefreed;
+
+ /* Need to lock buffer for visibility checks */
+ LockBuffer(buf, BUFFER_LOCK_SHARE);
+ }
+
+ tmp = *htid;
+ found = heap_hot_search_buffer(&tmp, rel, buf, &SnapshotNonVacuumable,
+ &heapTuple, &all_dead, true);
+
+ if (found || !all_dead)
+ continue;
+
+ /* Caller can delete this TID from index */
+ *finalndeltids = i + 1;
+ status->isdead = true;
+ spacefreed += status->tupsize;
+
+ if (spacefreed >= targetfreespace)
+ {
+ /*
+ * Caller's free space target has now been met (maybe...target may
+ * have decayed one or more times from original value if we
+ * weren't accessing favorable/contiguous blocks).
+ *
+ * Finish off the current/final heap page before finishing.
+ */
+ finalhpage = true;
+ }
+
+ /*
+ * One last step required for TID that caller will delete. Must
+ * maintain latestRemovedXid for caller's delete operation.
+ */
+ hoffnum = ItemPointerGetOffsetNumber(htid);
+ hitemid = PageGetItemId(hpage, hoffnum);
+
+ while (ItemIdIsRedirected(hitemid))
+ {
+ hoffnum = ItemIdGetRedirect(hitemid);
+ hitemid = PageGetItemId(hpage, hoffnum);
+ }
+
+ /*
+ * If the heap item has storage, then read the header and use that to
+ * set latestRemovedXid.
+ *
+ * Some LP_DEAD items may not be accessible, so we ignore them.
+ */
+ if (ItemIdHasStorage(hitemid))
+ {
+ HeapTupleHeader htuphdr;
+
+ htuphdr = (HeapTupleHeader) PageGetItem(hpage, hitemid);
+
+ HeapTupleHeaderAdvanceLatestRemovedXid(htuphdr, &latestRemovedXid);
+ }
+ else if (ItemIdIsDead(hitemid))
+ {
+ /*
+ * Conjecture: if hitemid is dead then it had xids before the xids
+ * marked on LP_NORMAL items. So we just ignore this item and move
+ * onto the next, for the purposes of calculating
+ * latestRemovedXid.
+ */
+ }
+ else
+ Assert(!ItemIdIsUsed(hitemid));
+ }
+
+ if (BufferIsValid(buf))
+ {
+ LockBuffer(buf, BUFFER_LOCK_UNLOCK);
+ ReleaseBuffer(buf);
+ }
+
+ /*
+ * If all heap tuples were LP_DEAD then we will be returning
+ * InvalidTransactionId here, which avoids conflicts. This matches
+ * existing logic which assumes that LP_DEAD tuples must already be older
+ * than the latestRemovedXid on the cleanup record that set them as
+ * LP_DEAD, hence must already have generated a conflict.
+ */
+
+ return latestRemovedXid;
+}
+
+/*
+ * heapam_index_delete_check() helper function. Sorts deltids array in the
+ * order needed for useful processing.
+ *
+ * Groups heap TIDs from deltids into heap block number groupings. From
+ * there, sorts each heap block grouping by the total number of "promising"
+ * TIDs it contains (in desc order). For blocks with the same number of
+ * promising TIDs, tiebreak on the total heap TID count (also desc order).
+ *
+ * heapam_index_delete_check() only visits 1 - MAX_DELETE_HEAP_BLOCKS heap
+ * blocks due to the speculative nature of the batch index deletion
+ * optimization. These heap blocks had better be the most promising
+ * available, based on a variety of criteria. We make sure of that here.
+ *
+ * Returns new size of deltids array (ndeltids). deltids will only have TIDs
+ * from the MAX_DELETE_HEAP_BLOCKS most promising heap blocks when we return
+ * (which is usually far fewer).
+ */
+static int
+heapam_index_delete_check_sort(Relation rel, TM_IndexDelete *deltids,
+ TM_IndexDeleteStatus *statusdeltids,
+ int ndeltids, int *nblocksfavorable)
+{
+ IndexDeleteCounts *blockcounts;
+ TM_IndexDelete *reordereddeltids;
+ BlockNumber curblock = InvalidBlockNumber;
+ int nblockgroups = 0;
+ int ncopied = 0;
+
+ Assert(ndeltids > 0);
+
+ /* First sort caller's array by TID */
+ heap_tid_shellsort(deltids, ndeltids);
+
+ /* Calculate per-heap-block count of TIDs */
+ blockcounts = palloc(sizeof(IndexDeleteCounts) * ndeltids);
+ for (int i = 0; i < ndeltids; i++)
+ {
+ ItemPointer deltid = &deltids[i].tid;
+ TM_IndexDeleteStatus *status = statusdeltids + deltids[i].id;
+ bool ispromising = status->ispromising;
+
+ if (curblock != ItemPointerGetBlockNumber(deltid))
+ {
+ /* New block group */
+ nblockgroups++;
+
+ Assert(curblock < ItemPointerGetBlockNumber(deltid) ||
+ !BlockNumberIsValid(curblock));
+
+ curblock = ItemPointerGetBlockNumber(deltid);
+ blockcounts[nblockgroups - 1].ideltids = i;
+ blockcounts[nblockgroups - 1].ntids = 1;
+ blockcounts[nblockgroups - 1].npromisingtids = 0;
+ }
+ else
+ {
+ blockcounts[nblockgroups - 1].ntids++;
+ }
+
+ if (ispromising)
+ blockcounts[nblockgroups - 1].npromisingtids++;
+ }
+
+ /*
+ * We're about ready to use index_delete_shellsort() to determine the
+ * optimal order for visiting heap pages. But before we do, round the
+ * number of promising tuples for each block group up to the nearest
+ * power-of-two (unless there are zero promising tuples). This scheme
+ * usefully divides heap pages into buckets. Each bucket contains heap
+ * pages that are approximately equally promising, that we want to treat
+ * as exactly equivalent (at least initially).
+ *
+ * While in general the presence of promising tuples (the hint that index
+ * AMs provide) is the best information that we have to go on, it is based
+ * on simple heuristics about duplicates in indexes that are understood to
+ * have specific flaws. We should not let the most promising heap pages
+ * win or lose on the basis of _relatively_ small differences in the total
+ * number of promising tuples. Small differences between the most
+ * promising few heap pages are effectively ignored by applying this
+ * power-of-two bucketing scheme.
+ *
+ * When we have lots of ties on the final bucket-ized npromisingtids among
+ * the most promising heap pages, we let heap locality determine the order
+ * in which we visit heap pages. This is helpful because it exploits the
+ * natural tendency for earlier heap blocks to accumulate more LP_DEAD
+ * items sooner in workloads with many non-HOT updates. It's also helpful
+ * because the effect over time is that we process related heap blocks
+ * sequentially, possibly with multiple rounds of processing over the same
+ * related heap blocks that are subject to continuous non-HOT updates over
+ * time.
+ *
+ * Note that we effectively have the same power-of-two bucketing scheme
+ * with the ntids field (which is compared after npromisingtids). The
+ * only reason that we don't fix nhtids here is that the original values
+ * will be needed when copying the final TIDs from winning block groups
+ * back into caller's deltids array.
+ */
+ for (int b = 0; b < nblockgroups; b++)
+ {
+ IndexDeleteCounts *blockgroup = blockcounts + b;
+
+ if (blockgroup->npromisingtids != 0)
+ blockgroup->npromisingtids =
+ pg_nextpower2_32((uint32) blockgroup->npromisingtids);
+ }
+
+ /* Sort groups and rearrange caller's deltids array */
+ index_delete_shellsort(blockcounts, nblockgroups);
+ reordereddeltids = palloc(ndeltids * sizeof(TM_IndexDelete));
+
+ nblockgroups = Min(MAX_DELETE_HEAP_BLOCKS, nblockgroups);
+ top_block_groups_favorable(blockcounts, nblockgroups, deltids,
+ nblocksfavorable);
+ for (int b = 0; b < nblockgroups; b++)
+ {
+ IndexDeleteCounts *blockgroup = blockcounts + b;
+ TM_IndexDelete *firstingroup = deltids + blockgroup->ideltids;
+
+ memcpy(reordereddeltids + ncopied, firstingroup,
+ sizeof(TM_IndexDelete) * blockgroup->ntids);
+ ncopied += blockgroup->ntids;
+ }
+
+ /* Copy final grouped and sorted TIDs back into start of caller's array */
+ memcpy(deltids, reordereddeltids, sizeof(TM_IndexDelete) * ncopied);
+
+ /* be tidy */
+ pfree(reordereddeltids);
+ pfree(blockcounts);
+
+ return ncopied;
+}
+
+/*
+ * Determine if heapam_index_delete_check() is about to process largely or
+ * entirely contiguous heap blocks.
+ *
+ * Returns true index delete operation is 'favorable'. This results in our
+ * processing more heap pages on average, to better amortize costs.
+ *
+ * As a general rule, operations where all of the most promising heap blocks
+ * are homogeneous and have their sort order determined by physical heap block
+ * number also end up being favorable. This is common with low cardinality
+ * data sets (from the point of view of the index AM).
+ */
+static void
+top_block_groups_favorable(IndexDeleteCounts *blockcounts, int nblockgroups,
+ TM_IndexDelete *deltids, int *nblocksfavorable)
+{
+ BlockNumber lastblock = InvalidBlockNumber;
+
+ /*
+ * Note: We always end up with at least one favorable block (the first in
+ * line to process), but heapam_index_delete_check() never gives up before
+ * accessing the first heap page anyway, so it makes no difference
+ */
+ *nblocksfavorable = 0;
+ for (int b = 0; b < nblockgroups; b++)
+ {
+ IndexDeleteCounts *blockgroup = blockcounts + b;
+ TM_IndexDelete *firstingroup = deltids + blockgroup->ideltids;
+ BlockNumber thisblock = ItemPointerGetBlockNumber(&firstingroup->tid);
+
+ if (BlockNumberIsValid(lastblock) &&
+ (thisblock < lastblock ||
+ thisblock > lastblock + FAVORABLE_BLOCK_STRIDE))
+ break;
+
+ (*nblocksfavorable)++;
+ lastblock = Min(thisblock, MaxBlockNumber - FAVORABLE_BLOCK_STRIDE);
+ }
+}
+
+/*
+ * Two hand written shellshort implementations.
+ *
+ * The two sort operations needed by heapam_index_delete_check_sort() become
+ * quite noticeable on profiles of workloads with lots of index contention
+ * caused by non-HOT updates. Keeping costs down is important enough to
+ * justify several micro-optimizations. We could just use qsort() instead,
+ * but the indirection that it imposes is expensive enough to matter here.
+ * (The size of array elements also matters, which is why we keep it under 8
+ * bytes - swaps should be as fast as reasonably possible).
+ *
+ * We use shellsort here because it has many of the same strengths as an
+ * industrial-strength quicksort implementation, but is also lightweight in
+ * the sense that the entire implementation compiles to relatively few machine
+ * instructions. It is adaptive to inputs with some presorted subsets (which
+ * are typical here).
+ *
+ * This implementation is fast with array sizes up to about 1900. This covers
+ * all supported BLCKSZ values.
+ */
+static void
+heap_tid_shellsort(TM_IndexDelete *deltids, int ndeltids)
+{
+ int low = 0;
+
+ /* Think carefully before changing anything here */
+ StaticAssertStmt(sizeof(TM_IndexDelete) <= 8,
+ "element size exceeds 8 bytes");
+
+ for (int g = 0; g < lengthof(shellsort_gaps); g++)
+ {
+ for (int hi = shellsort_gaps[g], i = low + hi; i < ndeltids; i++)
+ {
+ TM_IndexDelete d = deltids[i];
+ int j = i;
+
+ while (j >= hi &&
+ indexdelete_tids_cmp(&deltids[j - hi].tid, &d.tid) >= 0)
+ {
+ deltids[j] = deltids[j - hi];
+ j -= hi;
+ }
+ deltids[j] = d;
+ }
+ }
+}
+
+static void
+index_delete_shellsort(IndexDeleteCounts *blockcounts, int nblockgroups)
+{
+ int low = 0;
+
+ /* Think carefully before changing anything here */
+ StaticAssertStmt(sizeof(IndexDeleteCounts) <= 8,
+ "element size exceeds 8 bytes");
+
+ for (int g = 0; g < lengthof(shellsort_gaps); g++)
+ {
+ for (int hi = shellsort_gaps[g], i = low + hi; i < nblockgroups; i++)
+ {
+ IndexDeleteCounts c = blockcounts[i];
+ int j = i;
+
+ while (j >= hi &&
+ indexdeletecount_cmp(&blockcounts[j - hi], &c) >= 0)
+ {
+ blockcounts[j] = blockcounts[j - hi];
+ j -= hi;
+ }
+ blockcounts[j] = c;
+ }
+ }
+}
+
+static inline int
+indexdelete_tids_cmp(ItemPointer tid1, ItemPointer tid2)
+{
+ {
+ BlockNumber blk1 = ItemPointerGetBlockNumber(tid1);
+ BlockNumber blk2 = ItemPointerGetBlockNumber(tid2);
+
+ if (blk1 != blk2)
+ return (blk1 < blk2) ? -1 : 1;
+ }
+ {
+ OffsetNumber pos1 = ItemPointerGetOffsetNumber(tid1);
+ OffsetNumber pos2 = ItemPointerGetOffsetNumber(tid2);
+
+ if (pos1 != pos2)
+ return (pos1 < pos2) ? -1 : 1;
+ }
+
+ pg_unreachable();
+
+ return 0;
+}
+
+static inline int
+indexdeletecount_cmp(IndexDeleteCounts *count1, IndexDeleteCounts *count2)
+{
+ uint32 ntids1,
+ ntids2;
+
+ /* We expect power-of-two values for npromisingtids fields */
+ Assert(count1->npromisingtids == 0 ||
+ ((count1->npromisingtids - 1) & count1->npromisingtids) == 0);
+ Assert(count2->npromisingtids == 0 ||
+ ((count2->npromisingtids - 1) & count2->npromisingtids) == 0);
+
+ /*
+ * Most significant field is npromisingtids, which we sort on in desc
+ * order. The usual asc comparison order is deliberately inverted here.
+ */
+ if (count1->npromisingtids > count2->npromisingtids)
+ return -1;
+ if (count1->npromisingtids < count2->npromisingtids)
+ return 1;
+
+ /*
+ * Tiebreak: desc ntids sort order.
+ *
+ * We cannot expect power-of-two values for ntids fields. We should
+ * behave as if they were already rounded up for us instead.
+ */
+ ntids1 = count1->ntids;
+ ntids2 = count2->ntids;
+ if (ntids1 != ntids2)
+ {
+ ntids1 = pg_nextpower2_32(ntids1);
+ ntids2 = pg_nextpower2_32(ntids2);
+
+ if (ntids1 > ntids2)
+ return -1;
+ if (ntids1 < ntids2)
+ return 1;
+ }
+
+ /*
+ * Tiebreak: asc offset-into-deltids-for-block (offset to first TID for
+ * block in deltids array) order.
+ *
+ * This is equivalent to sorting in ascending heap block number order
+ * (among otherwise equal subsets of the array). This approach allows us
+ * to avoid accessing the out-of-line TID. (We rely on the assumption
+ * that the deltids array was sorted in ascending heap TID order when
+ * these offsets to the first TID from each heap block group were formed.)
+ */
+ if (count1->ideltids > count2->ideltids)
+ return 1;
+ if (count1->ideltids < count2->ideltids)
+ return -1;
+
+ pg_unreachable();
+
+ return 0;
+}
+
/*
* Perform XLogInsert to register a heap cleanup info message. These
* messages are sent once per VACUUM and are required because
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index dcaea7135f..f32ed0a5f2 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -314,7 +314,8 @@ static TM_Result
heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
CommandId cid, Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
- LockTupleMode *lockmode, bool *update_indexes)
+ LockTupleMode *lockmode, bool *update_indexes,
+ Bitmapset **modified_attrs_hint)
{
bool shouldFree = true;
HeapTuple tuple = ExecFetchSlotHeapTuple(slot, true, &shouldFree);
@@ -325,7 +326,7 @@ heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
tuple->t_tableOid = slot->tts_tableOid;
result = heap_update(relation, otid, tuple, cid, crosscheck, wait,
- tmfd, lockmode);
+ tmfd, lockmode, modified_attrs_hint);
ItemPointerCopy(&tuple->t_self, &slot->tts_tid);
/*
diff --git a/src/backend/access/nbtree/README b/src/backend/access/nbtree/README
index 9692e4cdf6..3ae4551f84 100644
--- a/src/backend/access/nbtree/README
+++ b/src/backend/access/nbtree/README
@@ -807,7 +807,8 @@ Deduplication in unique indexes helps to prevent these pathological page
splits. Storing duplicates in a space efficient manner is not the goal,
since in the long run there won't be any duplicates anyway. Rather, we're
buying time for standard garbage collection mechanisms to run before a
-page split is needed.
+page split is needed. (The same principle is behind delete deduplication,
+which also targets version churn.)
Unique index leaf pages only get a deduplication pass when an insertion
(that might have to split the page) observed an existing duplicate on the
@@ -874,6 +875,36 @@ that need a page split anyway. Besides, supporting variable "split points"
while splitting posting lists won't actually improve overall space
utilization.
+Delete deduplication
+--------------------
+
+The deduplication module usually opportunistically deletes whatever
+duplicates happen to be present on the page before moving on to
+deduplication proper, since in general some duplicates are likely to
+already be dead to everybody. This happens before regular merge
+deduplication, but only when we receive a hint that optimizations like
+heapam's HOT have not worked out -- the incoming tuple must be a logically
+unchanged duplicate which is needed for MVCC purposes.
+
+This mechanism is quite similar to on-the-fly deletion of index tuples
+(that will already have failed to prevent a page split by the time delete
+deduplication is considered). The main difference is that the tuples that
+get deleted are not opportunistically marked LP_DEAD by transactions that
+had to read the tuples in any case. Rather, we infer that duplicates are
+likely to be dead tuples based on heuristics (starting with the hint from
+the executor), and look for visibility information about the likely-dead
+tuples in the hopes that that inference will work out. There is some risk
+that this won't work out, but the upside of avoiding version driven page
+splits is so large that it is worth it.
+
+Negative feedback (such as failing to dedup-delete any tuples) is not
+really undesirable. At worst it is an unavoidable part of how the
+algorithm works. We require that our various approaches to handling an
+overflowing page (due partially or entirely to version churn) compete to
+determine how best to handle the problem in a localized fashion. We
+expect to converge on a stable and roughly optimal behavior at each part
+of the key space in each index affected by version churn.
+
Notes About Data Representation
-------------------------------
diff --git a/src/backend/access/nbtree/nbtdedup.c b/src/backend/access/nbtree/nbtdedup.c
index f6be865b17..3caadbe6aa 100644
--- a/src/backend/access/nbtree/nbtdedup.c
+++ b/src/backend/access/nbtree/nbtdedup.c
@@ -15,14 +15,27 @@
#include "postgres.h"
#include "access/nbtree.h"
+#include "access/heapam.h"
#include "access/nbtxlog.h"
+#include "access/tableam.h"
#include "miscadmin.h"
#include "utils/rel.h"
-static bool _bt_do_singleval(Relation rel, Page page, BTDedupState state,
- OffsetNumber minoff, IndexTuple newitem);
+static bool _bt_dedup_delete_pass(Relation rel, Buffer buf, Relation heapRel,
+ Size newitemsz, bool checkingunique,
+ bool *merge);
+static void _bt_dedup_merge_pass(Relation rel, Buffer buf, Relation heapRel,
+ IndexTuple newitem, Size newitemsz,
+ bool checkingunique, bool singleval);
+static void _bt_dedup_delete_finish_pending(BTDedupState state,
+ TM_IndexDelete *deltids,
+ TM_IndexDeleteStatus *statusdeltids,
+ int *ndeltids);
+static bool _bt_do_singleval(Relation rel, Page page, OffsetNumber minoff,
+ IndexTuple newitem);
static void _bt_singleval_fillfactor(Page page, BTDedupState state,
Size newitemsz);
+static int _bt_indexdelete_cmp(const void *a, const void *b, void *arg);
#ifdef USE_ASSERT_CHECKING
static bool _bt_posting_valid(IndexTuple posting);
#endif
@@ -32,16 +45,12 @@ static bool _bt_posting_valid(IndexTuple posting);
* if we cannot successfully free at least newitemsz (we also need space for
* newitem's line pointer, which isn't included in caller's newitemsz).
*
- * The general approach taken here is to perform as much deduplication as
- * possible to free as much space as possible. Note, however, that "single
- * value" strategy is sometimes used for !checkingunique callers, in which
- * case deduplication will leave a few tuples untouched at the end of the
- * page. The general idea is to prepare the page for an anticipated page
- * split that uses nbtsplitloc.c's "single value" strategy to determine a
- * split point. (There is no reason to deduplicate items that will end up on
- * the right half of the page after the anticipated page split; better to
- * handle those if and when the anticipated right half page gets its own
- * deduplication pass, following further inserts of duplicates.)
+ * There are two types of deduplication pass: The merge deduplication pass,
+ * where we merge together duplicate index tuples into a new posting list, and
+ * the delete deduplication pass, where old garbage version index tuples are
+ * deleted based on visibility information that we fetch from the table. We
+ * generally expect to perform only one type of deduplication pass per call
+ * here, but it's possible that we'll end up doing both.
*
* This function should be called during insertion, when the page doesn't have
* enough space to fit an incoming newitem. If the BTP_HAS_GARBAGE page flag
@@ -54,27 +63,24 @@ static bool _bt_posting_valid(IndexTuple posting);
*/
void
_bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
- IndexTuple newitem, Size newitemsz, bool checkingunique)
+ IndexTuple newitem, Size newitemsz, bool checkingunique,
+ bool dedupdelete, bool allequalimage)
{
OffsetNumber offnum,
minoff,
maxoff;
Page page = BufferGetPage(buf);
BTPageOpaque opaque;
- Page newpage;
OffsetNumber deletable[MaxIndexTuplesPerPage];
- BTDedupState state;
int ndeletable = 0;
- Size pagesaving = 0;
- bool singlevalstrat = false;
- int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+ bool singleval;
/*
* We can't assume that there are no LP_DEAD items. For one thing, VACUUM
* will clear the BTP_HAS_GARBAGE hint without reliably removing items
* that are marked LP_DEAD. We don't want to unnecessarily unset LP_DEAD
- * bits when deduplicating items. Allowing it would be correct, though
- * wasteful.
+ * bits when deduplicating items by merging. Allowing it would be
+ * correct, though wasteful.
*/
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
minoff = P_FIRSTDATAKEY(opaque);
@@ -91,7 +97,9 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
if (ndeletable > 0)
{
- _bt_delitems_delete(rel, buf, deletable, ndeletable, heapRel);
+ _bt_delitems_delete(rel, buf, deletable, ndeletable,
+ NULL, 0,
+ heapRel, false, InvalidTransactionId);
/*
* Return when a split will be avoided. This is equivalent to
@@ -100,17 +108,563 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
if (PageGetFreeSpace(page) >= newitemsz)
return;
- /*
- * Reconsider number of items on page, in case _bt_delitems_delete()
- * managed to delete an item or two
- */
- minoff = P_FIRSTDATAKEY(opaque);
- maxoff = PageGetMaxOffsetNumber(page);
+ maxoff = InvalidOffsetNumber; /* Invalidate */
}
/* Passed-in newitemsz is MAXALIGNED but does not include line pointer */
newitemsz += sizeof(ItemIdData);
+ /* Determine if page is all one value */
+ singleval = _bt_do_singleval(rel, page, minoff, newitem);
+
+ /*
+ * Perform delete deduplication pass when caller asked for it explicitly,
+ * or for a unique index.
+ *
+ * Don't delete dedup when page contains only one value, unless it's from
+ * a unique index where we always try to delete. We only get called about
+ * checkingunique cases when page is known to have at least one or two
+ * non-NULL duplicates. Clearly duplicates in a unique index are bound to
+ * become dead-to-all before long, so we should always try to delete them.
+ */
+ if ((dedupdelete && !singleval) || checkingunique)
+ {
+ bool merge = true;
+
+ if (_bt_dedup_delete_pass(rel, buf, heapRel, newitemsz,
+ checkingunique, &merge))
+ return;
+
+ /*
+ * _bt_dedup_delete_pass() may occasionally indicate no duplicates, in
+ * which case we should give up now
+ */
+ if (!merge)
+ return;
+
+ /* Fall back on merge deduplication. This happens infrequently. */
+ }
+
+ /*
+ * Perform merge deduplication pass, though only when it is safe to do so.
+ * Index must be an allequalimage index -- otherwise it's not safe.
+ */
+ if (allequalimage)
+ _bt_dedup_merge_pass(rel, buf, heapRel, newitem, newitemsz,
+ checkingunique, singleval);
+}
+
+/*
+ * Perform a delete deduplication pass.
+ *
+ * See if duplicate index tuples are eligible to be deleted, even though they
+ * don't have their LP_DEAD bit set already. Give up if we have to access
+ * more than a few tableam pages before we can free enough space to fit
+ * newitem.
+ *
+ * Returns true on success, in which case caller can assume page split will be
+ * avoided for a reasonable amount of time. Returns false when caller should
+ * deduplicate the page (if possible at all).
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
+ */
+static bool
+_bt_dedup_delete_pass(Relation rel, Buffer buf, Relation heapRel,
+ Size newitemsz, bool checkingunique, bool *merge)
+{
+ OffsetNumber offnum,
+ minoff,
+ maxoff,
+ skippostinglistoffnum = InvalidOffsetNumber;
+ Page page = BufferGetPage(buf);
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+ BTDedupState state;
+ TM_IndexDelete *deltids;
+ TM_IndexDeleteStatus *statusdeltids;
+ int ndeltids,
+ npromisingdeltids,
+ ndeletable,
+ nupdatable;
+ int finalndeltids;
+ TransactionId dedupLatestRemovedXid = InvalidTransactionId;
+ OffsetNumber deletable[MaxIndexTuplesPerPage];
+ BTVacuumPosting updatable[MaxIndexTuplesPerPage];
+ int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+ bool lowcardinalitydata = false;
+
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
+
+ /*
+ * Be careful when there are far fewer index tuples on the page than might
+ * be expected with a page full of index tuples of typical width. The
+ * likely explanation is that there are relatively few tuples with large
+ * posting lists. Low cardinality data requires special care here.
+ *
+ * We need to avoid thrashing when we can barely keep up with index tuple
+ * version churn on any page with low cardinality data -- pages that might
+ * fit entries for over a thousand distinct logical rows with default
+ * BLCKSZ when in their pristine CREATE INDEX state (deduplication makes
+ * this possible -- it can increase this pristine page logical row
+ * capacity by over 3x).
+ *
+ * We provide useful back pressure against version churn in these cases by
+ * forcing further merge deduplication, even if we go on to delete many
+ * TIDs. We also ask heapam to free more space for the same reason.
+ */
+ if (!checkingunique && maxoff < MaxIndexTuplesPerPage / 3)
+ lowcardinalitydata = true;
+
+ state = (BTDedupState) palloc(sizeof(BTDedupStateData));
+ state->deduplicate = true;
+ state->nmaxitems = 0;
+ /* Final "posting list" size should not restrict anything */
+ state->maxpostingsize = BLCKSZ;
+ state->base = NULL;
+ state->baseoff = InvalidOffsetNumber;
+ state->basetupsize = 0;
+ state->htids = palloc(state->maxpostingsize);
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+ state->nintervals = 0;
+
+ /*
+ * deltids and statusdeltids are allocated separately as a performance
+ * optimization. You can think of them as one array artificially split in
+ * two for performance reasons.
+ */
+ ndeltids = 0;
+ npromisingdeltids = 0;
+ deltids = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexDelete));
+ statusdeltids = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexDeleteStatus));
+
+ for (offnum = minoff;
+ offnum <= maxoff;
+ offnum = OffsetNumberNext(offnum))
+ {
+ ItemId itemid = PageGetItemId(page, offnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+
+ Assert(!ItemIdIsDead(itemid));
+
+ if (offnum == minoff)
+ {
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ else if (_bt_keep_natts_fast(rel, state->base, itup) > nkeyatts &&
+ _bt_dedup_save_htid(state, itup))
+ {
+ /*
+ * Tuple is equal to base tuple of pending interval. Heap TID(s)
+ * for itup have been saved in state.
+ */
+ }
+ else
+ {
+ /* Handle interval, saving TIDs when "non-promising" */
+ _bt_dedup_delete_finish_pending(state, deltids, statusdeltids,
+ &ndeltids);
+
+ /* itup starts new pending interval */
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ }
+ /* Handle the final interval, saving TIDs when "non-promising" */
+ _bt_dedup_delete_finish_pending(state, deltids, statusdeltids, &ndeltids);
+
+ if (state->nintervals == 0)
+ {
+ /* No duplicates/promising tuples, don't bother trying */
+ pfree(state->htids);
+ pfree(state);
+ pfree(deltids);
+ pfree(statusdeltids);
+ /* Caller should avoid merge deduplication pass */
+ *merge = false;
+ return false;
+ }
+
+ /*
+ * deltids array now contains non-duplicate tuples, all of which are
+ * marked non-promising.
+ *
+ * Add known duplicates to array now by extracting them from the dedup
+ * intervals we just formed. Tuples are marked promising so that the
+ * tableam infrastructure can focus its efforts there (actually we don't
+ * do that for posting list TIDs). See comment block below for a full
+ * explanation of promising tuples.
+ */
+ for (int i = 0; i < state->nintervals; i++)
+ {
+ BTDedupInterval interval = state->intervals[i];
+
+ for (int j = 0; j < interval.nitems; j++)
+ {
+ OffsetNumber dupoffnum = interval.baseoff + j;
+ ItemId itemid = PageGetItemId(page, dupoffnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ /*
+ * Plain non-pivot tuple duplicate -- TID is promising
+ */
+ deltids[ndeltids].tid = itup->t_tid;
+ deltids[ndeltids].id = ndeltids;
+ statusdeltids[ndeltids].ioffnum = dupoffnum;
+ statusdeltids[ndeltids].ispromising = true;
+ statusdeltids[ndeltids].isdead = false; /* for now */
+ statusdeltids[ndeltids].tupsize =
+ ItemIdGetLength(itemid) + sizeof(ItemIdData);
+ ndeltids++;
+ npromisingdeltids++;
+ }
+ else
+ {
+ /*
+ * Posting list tuple duplicate -- TIDs are not promising, but
+ * tableam might manage to delete them in passing
+ */
+ int nitem = BTreeTupleGetNPosting(itup);
+ BlockNumber min = ItemPointerGetBlockNumber(BTreeTupleGetHeapTID(itup));
+ BlockNumber mid = ItemPointerGetBlockNumber(BTreeTupleGetPostingN(itup, nitem / 2));
+ BlockNumber max = ItemPointerGetBlockNumber(BTreeTupleGetMaxHeapTID(itup));
+ bool ispromisingfirst = (min == mid);
+ bool ispromisinglast = (!ispromisingfirst && mid == max);
+
+ Assert(_bt_posting_valid(itup));
+
+ for (int p = 0; p < nitem; p++)
+ {
+ ItemPointer htid = BTreeTupleGetPostingN(itup, p);
+
+ deltids[ndeltids].tid = *htid;
+ deltids[ndeltids].id = ndeltids;
+ statusdeltids[ndeltids].ioffnum = dupoffnum;
+
+ if (ispromisingfirst && p == 0)
+ statusdeltids[ndeltids].ispromising = true;
+ else if (ispromisinglast && p == nitem - 1)
+ statusdeltids[ndeltids].ispromising = true;
+ else
+ statusdeltids[ndeltids].ispromising = false;
+
+ statusdeltids[ndeltids].isdead = false; /* for now */
+
+ /*
+ * Add one byte to size to represent amortized saving from
+ * removing entire posting list tuple
+ */
+ statusdeltids[ndeltids].tupsize =
+ sizeof(ItemPointerData) + 1;
+ ndeltids++;
+ }
+ }
+ }
+ }
+
+ /* Done with dedup state */
+ pfree(state->htids);
+ pfree(state);
+
+ /*
+ * Determine which TIDs are dead in deltids array (if we have any
+ * duplicates at all, since we only really expect to find dead tuples
+ * among duplicates).
+ *
+ * Note that we're not trying to prevent just any kind of page split.
+ * We're trying to delay _unnecessary_ version churn page splits
+ * indefinitely, which is the same thing as preventing them altogether if
+ * you look at the situation on a long enough time line (think hours,
+ * days, or even months).
+ *
+ * Each failure to delete a duplicate/promising tuple here is a kind of
+ * learning experience. It results in caller falling back on splitting
+ * the page (or on a merge deduplication pass), discouraging future calls
+ * back here for the same key space range covered by a failed page (or at
+ * least discouraging processing the original duplicates in case where
+ * caller falls back on a successful merge deduplication pass). We
+ * converge on the most effective strategy for each page in the index over
+ * time, through trial and error. We accept well understood small
+ * negative outcomes (effort on deleting that didn't immediately pay off)
+ * as the price of a potentially huge (though uncertain) upside (no
+ * unnecessary page splits).
+ *
+ * We don't mark posting list tuple TIDs as promising specifically so that
+ * cases where we have a failed delete deduplication pass followed by a
+ * successfully merge deduplication pass do not go on to waste time on the
+ * TIDs during any future delete deduplication passes. This is helpful
+ * when posting list tuples generally point to multiple distinct logical
+ * rows in the table. If it turns out that they really are all old
+ * versions of a single logical table row, we still have a pretty good
+ * chance of being able to delete them in a future dedup delete pass (not
+ * necessarily the next one for the leaf page). We could easily pick up
+ * the dead TIDs from such a posting list tuple when the tableam goes on
+ * to place even more similar version churn tuples on the same table
+ * block. We'll naturally target the newer version churn tuples directly,
+ * and then discover dead TIDs from posting list tuples that weren't
+ * dead/possible to delete earlier (i.e. back when we "were under the
+ * mistaken impression" that the posting list TIDs were for multiple
+ * logical table rows).
+ */
+ Assert(ndeltids > 0);
+ finalndeltids = 0;
+ if (npromisingdeltids > 0)
+ {
+ int targetfreespace;
+
+ /*
+ * We ask tableam to free 1/64 of BLCKSZ (1/16 of BLCKSZ with low
+ * cardinality data or a unique index). We don't usually expect to
+ * have to free much space each call here in order to avoid page
+ * splits. We don't want to be too aggressive because tableam has to
+ * access additional heap blocks to satisfy our requirements. In
+ * general we try to be conservative about what we ask for, while
+ * leaving it up to heapam to be more aggressive when conditions
+ * happen to favor it.
+ *
+ * The tableam will regularly free much more space than we actually
+ * ask for. It often happens to be convenient for it to process extra
+ * TIDs in passing. Our requested target free space size is mostly
+ * just a way of balancing costs over time with pages that are more or
+ * less constantly at risk of unnecessary page splits, but are not
+ * expected to split for any other reason. (It's also useful because
+ * it allows the tableam to understand that freeing one posting list
+ * TID is much less helpful to us than freeing an entire index tuple.)
+ */
+ targetfreespace = (BLCKSZ / 64);
+ if (checkingunique || lowcardinalitydata)
+ targetfreespace = (BLCKSZ / 16);
+
+ dedupLatestRemovedXid =
+ heapam_index_delete_check(heapRel, deltids, statusdeltids,
+ ndeltids, targetfreespace,
+ &finalndeltids);
+
+ /*
+ * TODO: Obviously we should be going through a new tableam shim
+ * function rather than calling into heapam directly like this. We
+ * don't bother with that for now because the interface is still
+ * unsettled. See also: WIP table_index_delete_check() shim.
+ */
+ }
+
+ if (finalndeltids == 0)
+ {
+ pfree(deltids);
+ pfree(statusdeltids);
+ return false;
+ }
+
+ /*
+ * We have at least one dead TID to delete. All that remains is to
+ * construct a leaf-page-wise description of what to delete that can be
+ * used by _bt_delitems_delete().
+ *
+ * Sort deltids in useful order, then process sorted array in loop (loop
+ * expects items in offset number order, or by TID among entries that have
+ * equal offset numbers -- which happens when there are posting list
+ * tuples that we want to delete some TIDs from).
+ *
+ * Note: We only process the subset of elements at the start of deltids
+ * that pertain to table blocks actually accessed by the tableam (the
+ * first finalndeltids elements). This approach saves a few cycles.
+ */
+ Assert(finalndeltids > 0);
+ qsort_arg(deltids, finalndeltids, sizeof(TM_IndexDelete),
+ _bt_indexdelete_cmp, statusdeltids);
+ ndeletable = 0;
+ nupdatable = 0;
+ for (int i = 0; i < finalndeltids; i++)
+ {
+ TM_IndexDeleteStatus *status = statusdeltids + deltids[i].id;
+ OffsetNumber savedoffnum = status->ioffnum;
+ ItemId itemid = PageGetItemId(page, savedoffnum);
+ IndexTuple itup;
+ int nitem;
+ BTVacuumPosting vacposting = NULL;
+
+ itup = (IndexTuple) PageGetItem(page, itemid);
+
+ /*
+ * If this is a posting list and we already reached the first dead
+ * tuple in the posting list, skip remaining items
+ */
+ if (skippostinglistoffnum == savedoffnum)
+ {
+ Assert(BTreeTupleIsPosting(itup));
+ Assert(!status->ispromising);
+ continue;
+ }
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ /*
+ * For a plain non-pivot tuple, simply being found marked dead
+ * means we can kill
+ */
+ Assert(ItemPointerEquals(&itup->t_tid, &deltids[i].tid));
+ if (status->isdead)
+ deletable[ndeletable++] = savedoffnum;
+ continue;
+ }
+
+ /*
+ * For a posting list tuple we have to work a bit harder, since we may
+ * either delete or update (i.e. update to delete a subset of its
+ * TIDs).
+ *
+ * We'll be skipping over future TIDs from this same posting list in
+ * outer loop, since we want to process all TIDs in tuple together
+ * once in inner loop. Remember to do that at top of outer loop now.
+ */
+ Assert(_bt_posting_valid(itup));
+ skippostinglistoffnum = savedoffnum;
+ nitem = BTreeTupleGetNPosting(itup);
+ for (int j = 0; j < nitem; j++)
+ {
+ ItemPointer htid;
+ int cmp;
+ int tidi = i;
+
+ htid = BTreeTupleGetPostingN(itup, j);
+
+ for (;;)
+ {
+ cmp = ItemPointerCompare(htid, &deltids[tidi].tid);
+ if (cmp == 0)
+ break;
+ tidi++;
+ if (tidi >= finalndeltids ||
+ (statusdeltids + deltids[tidi].id)->ioffnum != savedoffnum)
+ {
+ /*
+ * If this later tidi deltid doesn't even relate to same
+ * posting list index tuple from page, we're done with
+ * this TID from itup (posting list tuple).
+ */
+ cmp = -1;
+ break;
+ }
+ }
+
+ /* Final check for exact TID match */
+ if (cmp != 0)
+ continue;
+
+ /* Only interested in dead TIDs */
+ if (!(statusdeltids + deltids[tidi].id)->isdead)
+ continue;
+
+ if (vacposting == NULL)
+ {
+ /*
+ * First dead table TID encountered.
+ *
+ * Start maintaining metadata describing how to update
+ * existing posting list tuple.
+ */
+ vacposting = palloc(offsetof(BTVacuumPostingData, deletetids) +
+ nitem * sizeof(uint16));
+ vacposting->itup = itup;
+ vacposting->updatedoffset = savedoffnum;
+ vacposting->ndeletedtids = 0;
+ }
+ vacposting->deletetids[vacposting->ndeletedtids++] = j;
+ }
+
+ /* Decide what to do with TIDs in posting list tuple */
+
+ if (vacposting == NULL)
+ {
+ /* No TIDs to delete in posting list tuple */
+ }
+ else if (vacposting->ndeletedtids == nitem)
+ {
+ /* Straight delete -- won't need update state */
+ deletable[ndeletable++] = savedoffnum;
+ pfree(vacposting);
+ }
+ else
+ {
+ /* Going to delete some but not all TIDs in posting list */
+ Assert(vacposting->ndeletedtids > 0 &&
+ vacposting->ndeletedtids < nitem);
+ updatable[nupdatable++] = vacposting;
+ }
+ }
+
+ /* Done with deltids state */
+ pfree(deltids);
+ pfree(statusdeltids);
+
+ /*
+ * Should not get this far if we don't have at least some TIDs to delete,
+ * but be paranoid
+ */
+ if (ndeletable == 0 && nupdatable == 0)
+ {
+ Assert(false);
+ return false;
+ }
+
+ /*
+ * Go through with deleting TIDs that we found are safe to delete.
+ *
+ * No MarkBufferDirtyHint() call is needed here, since we don't ever mark
+ * line pointers LP_DEAD. Any and all modifications to the page are made
+ * in the critical section in _bt_delitems_delete().
+ */
+ _bt_delitems_delete(rel, buf, deletable, ndeletable,
+ updatable, nupdatable,
+ heapRel, true, dedupLatestRemovedXid);
+
+ /* be tidy */
+ for (int i = 0; i < nupdatable; i++)
+ pfree(updatable[i]);
+
+ /* Always dedup with low cardinality data */
+ if (lowcardinalitydata)
+ return false;
+
+ /* Return success when page split won't be needed any time soon */
+ return PageGetExactFreeSpace(page) >= Max(BLCKSZ / 64, newitemsz);
+}
+
+/*
+ * Perform a merge deduplication pass.
+ *
+ * The general approach taken here is to perform as much deduplication as
+ * possible to free as much space as possible. Note, however, that "single
+ * value" strategy is used for singleval callers, in which case deduplication
+ * will leave a few tuples untouched at the end of the page. The general idea
+ * is to prepare the page for an anticipated page split that uses
+ * nbtsplitloc.c's "single value" strategy to determine a split point. (There
+ * is no reason to deduplicate items that will end up on the right half of the
+ * page after the anticipated page split; better to handle those if and when
+ * the anticipated right half page gets its own deduplication pass, following
+ * further inserts of duplicates.)
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
+ */
+static void
+_bt_dedup_merge_pass(Relation rel, Buffer buf, Relation heapRel,
+ IndexTuple newitem, Size newitemsz, bool checkingunique,
+ bool singleval)
+{
+ OffsetNumber offnum,
+ minoff,
+ maxoff;
+ Page page = BufferGetPage(buf);
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+ Page newpage;
+ BTDedupState state;
+ Size pagesaving = 0;
+ int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+
/*
* By here, it's clear that deduplication will definitely be attempted.
* Initialize deduplication state.
@@ -138,9 +692,8 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
/* nintervals should be initialized to zero */
state->nintervals = 0;
- /* Determine if "single value" strategy should be used */
- if (!checkingunique)
- singlevalstrat = _bt_do_singleval(rel, page, state, minoff, newitem);
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
/*
* Deduplicate items from page, and write them to newpage.
@@ -203,9 +756,9 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
* form new posting tuple, and actually update the page. Else
* reset the state and move on without modifying the page.
*/
- pagesaving += _bt_dedup_finish_pending(newpage, state);
+ pagesaving += _bt_dedup_merge_finish_pending(newpage, state);
- if (singlevalstrat)
+ if (singleval)
{
/*
* Single value strategy's extra steps.
@@ -225,7 +778,7 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
else if (state->nmaxitems == 6)
{
state->deduplicate = false;
- singlevalstrat = false; /* won't be back here */
+ singleval = false; /* won't be back here */
}
}
@@ -235,7 +788,7 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
}
/* Handle the last item */
- pagesaving += _bt_dedup_finish_pending(newpage, state);
+ pagesaving += _bt_dedup_merge_finish_pending(newpage, state);
/*
* If no items suitable for deduplication were found, newpage must be
@@ -263,6 +816,8 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
* still falsely set, just to keep things tidy. (We can't rely on
* _bt_vacuum_one_page() having done this already, and we can't rely on a
* page split or VACUUM getting to it in the near future.)
+ *
+ * Deliberately don't unset BTP_HAS_DUPS here.
*/
if (P_HAS_GARBAGE(opaque))
{
@@ -317,8 +872,8 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
* Every tuple processed by deduplication either becomes the base tuple for a
* posting list, or gets its heap TID(s) accepted into a pending posting list.
* A tuple that starts out as the base tuple for a posting list will only
- * actually be rewritten within _bt_dedup_finish_pending() when it turns out
- * that there are duplicates that can be merged into the base tuple.
+ * actually be rewritten within _bt_dedup_merge_finish_pending() when it turns
+ * out that there are duplicates that can be merged into the base tuple.
*/
void
_bt_dedup_start_pending(BTDedupState state, IndexTuple base,
@@ -443,7 +998,7 @@ _bt_dedup_save_htid(BTDedupState state, IndexTuple itup)
* where no deduplication was possible.
*/
Size
-_bt_dedup_finish_pending(Page newpage, BTDedupState state)
+_bt_dedup_merge_finish_pending(Page newpage, BTDedupState state)
{
OffsetNumber tupoff;
Size tuplesz;
@@ -496,10 +1051,85 @@ _bt_dedup_finish_pending(Page newpage, BTDedupState state)
return spacesaving;
}
+/*
+ * Finalize interval of duplicates (duplicate group).
+ *
+ * Non-promising/non-duplicate tuples are handled here -- they're stored in
+ * deltids. Promising/duplicate tuples are remembered in state's interval
+ * array for processing later, in a separate pass over dedup state.
+ *
+ * Note that we deliberately don't mark posting lists tuples as promising here
+ * because the lack of any duplicate physical tuples suggests that the posting
+ * list relates to multiple logical rows (not multiple physical versions of a
+ * logical row). Only duplicate tuples from the recent past are likely to be
+ * old version index tuples.
+ *
+ * TODO: Add promising tuples/duplicates here too, for consistency?
+ */
+static void
+_bt_dedup_delete_finish_pending(BTDedupState state, TM_IndexDelete *deltids,
+ TM_IndexDeleteStatus *statusdeltids,
+ int *ndeltids)
+{
+ Assert(state->nitems > 0);
+ Assert(state->nitems <= state->nhtids);
+ Assert(state->intervals[state->nintervals].baseoff == state->baseoff);
+
+ if (state->nitems == 1)
+ {
+ /* Remember non-duplicate's TID, but mark it not promising */
+ OffsetNumber offnum = state->baseoff;
+ IndexTuple itup = state->base;
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ deltids[*ndeltids].tid = itup->t_tid;
+ deltids[*ndeltids].id = *ndeltids;
+ statusdeltids[*ndeltids].ioffnum = offnum;
+ statusdeltids[*ndeltids].ispromising = false;
+ statusdeltids[*ndeltids].isdead = false; /* for now */
+ statusdeltids[*ndeltids].tupsize =
+ IndexTupleSize(itup) + sizeof(ItemIdData);
+ (*ndeltids)++;
+ }
+ else
+ {
+ int nitem = BTreeTupleGetNPosting(itup);
+
+ Assert(_bt_posting_valid(itup));
+
+ for (int i = 0; i < nitem; i++)
+ {
+ ItemPointer htid = BTreeTupleGetPostingN(itup, i);
+
+ deltids[*ndeltids].tid = *htid;
+ deltids[*ndeltids].id = *ndeltids;
+ statusdeltids[*ndeltids].ioffnum = offnum;
+ statusdeltids[*ndeltids].ispromising = false;
+ statusdeltids[*ndeltids].isdead = false; /* for now */
+ statusdeltids[*ndeltids].tupsize = sizeof(ItemPointerData) + 1;
+ (*ndeltids)++;
+ }
+ }
+ }
+ else
+ {
+ /* Dups in interval -- store in deltids later */
+ state->intervals[state->nintervals].nitems = state->nitems;
+ /* Increment nintervals, since we wrote a new posting list tuple */
+ state->nintervals++;
+ }
+
+ /* Reset state for next pending posting list */
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+}
+
/*
* Determine if page non-pivot tuples (data items) are all duplicates of the
- * same value -- if they are, deduplication's "single value" strategy should
- * be applied. The general goal of this strategy is to ensure that
+ * same value -- if they are, merge deduplication's "single value" strategy
+ * should be applied. The general goal of this strategy is to ensure that
* nbtsplitloc.c (which uses its own single value strategy) will find a useful
* split point as further duplicates are inserted, and successive rightmost
* page splits occur among pages that store the same duplicate value. When
@@ -531,8 +1161,8 @@ _bt_dedup_finish_pending(Page newpage, BTDedupState state)
* here.
*/
static bool
-_bt_do_singleval(Relation rel, Page page, BTDedupState state,
- OffsetNumber minoff, IndexTuple newitem)
+_bt_do_singleval(Relation rel, Page page, OffsetNumber minoff,
+ IndexTuple newitem)
{
int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
ItemId itemid;
@@ -809,6 +1439,57 @@ _bt_swap_posting(IndexTuple newitem, IndexTuple oposting, int postingoff)
return nposting;
}
+/*
+ * qsort-style comparator used by _bt_dedup_delete_pass()
+ *
+ * TM_IndexDelete and TM_IndexDeleteStatus are two different structs for
+ * performance reasons (initial TID sort needs to be very fast because it
+ * happens before any of the TIDs have been eliminated). It would be more
+ * natural if there was only one struct with all the fields from each of the
+ * two structs.
+ *
+ * This qsort_arg comparator deals with finding the TM_IndexDeleteStatus of
+ * the TM_IndexDelete entries that we sort.
+ */
+static int
+_bt_indexdelete_cmp(const void *a, const void *b, void *arg)
+{
+ TM_IndexDelete *indexdelete1 = (TM_IndexDelete *) a;
+ TM_IndexDelete *indexdelete2 = (TM_IndexDelete *) b;
+ TM_IndexDeleteStatus *statusdeltids = (TM_IndexDeleteStatus *) arg;
+
+ OffsetNumber offset1 = (statusdeltids + indexdelete1->id)->ioffnum;
+ OffsetNumber offset2 = (statusdeltids + indexdelete2->id)->ioffnum;
+ ItemPointer tid1 = &indexdelete1->tid;
+ ItemPointer tid2 = &indexdelete2->tid;
+
+ if (offset1 > offset2)
+ return 1;
+ if (offset1 < offset2)
+ return -1;
+
+ /* Must be posting list tuple -- restore TID order */
+ {
+ BlockNumber blk1 = ItemPointerGetBlockNumber(tid1);
+ BlockNumber blk2 = ItemPointerGetBlockNumber(tid2);
+
+ if (blk1 != blk2)
+ return (blk1 < blk2) ? -1 : 1;
+ }
+ {
+ OffsetNumber pos1 = ItemPointerGetOffsetNumber(tid1);
+ OffsetNumber pos2 = ItemPointerGetOffsetNumber(tid2);
+
+ if (pos1 != pos2)
+ return (pos1 < pos2) ? -1 : 1;
+ }
+
+ /* ItemPointer values should never be equal */
+ Assert(false);
+
+ return 0;
+}
+
/*
* Verify posting list invariants for "posting", which must be a posting list
* tuple. Used within assertions.
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index d36f7557c8..6377a024ba 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -37,6 +37,7 @@ static TransactionId _bt_check_unique(Relation rel, BTInsertState insertstate,
static OffsetNumber _bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool logicallymodified,
BTStack stack,
Relation heapRel);
static void _bt_stepright(Relation rel, BTInsertState insertstate, BTStack stack);
@@ -86,7 +87,9 @@ _bt_doinsert(Relation rel, IndexTuple itup,
BTInsertStateData insertstate;
BTScanInsert itup_key;
BTStack stack;
- bool checkingunique = (checkUnique != UNIQUE_CHECK_NO);
+ bool checkingunique = (checkUnique != UNIQUE_CHECK_NO &&
+ checkUnique != UNIQUE_CHECK_NO_WITH_UNCHANGED);
+ bool logicallymodified = (checkUnique != UNIQUE_CHECK_NO_WITH_UNCHANGED);
/* we need an insertion scan key to do our search, so build one */
itup_key = _bt_mkscankey(rel, itup);
@@ -235,7 +238,7 @@ search:
* checkingunique.
*/
newitemoff = _bt_findinsertloc(rel, &insertstate, checkingunique,
- stack, heapRel);
+ logicallymodified, stack, heapRel);
_bt_insertonpg(rel, itup_key, insertstate.buf, InvalidBuffer, stack,
itup, insertstate.itemsz, newitemoff,
insertstate.postingoff, false);
@@ -767,6 +770,11 @@ _bt_check_unique(Relation rel, BTInsertState insertstate, Relation heapRel,
* the right, rather than the first page. In that case, this function
* moves right to the correct target page.
*
+ * If 'logicallymodified' is false, this is for an UPDATE that didn't
+ * logically change the indexed value, but must nevertheless have a new
+ * entry to point to a successor version. This hint from the executor
+ * influences the behavior of deduplication.
+ *
* (In a !heapkeyspace index, there can be multiple pages with the same
* high key, where the new tuple could legitimately be placed on. In
* that case, the caller passes the first page containing duplicates,
@@ -790,6 +798,7 @@ static OffsetNumber
_bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool logicallymodified,
BTStack stack,
Relation heapRel)
{
@@ -873,14 +882,20 @@ _bt_findinsertloc(Relation rel,
/*
* If the target page is full, see if we can obtain enough space by
* erasing LP_DEAD items. If that fails to free enough space, see if
- * we can avoid a page split by performing a deduplication pass over
- * the page.
+ * we can avoid a page split by performing deduplication. Usually
+ * this means a deduplication merge pass, though a deduplication
+ * delete pass is preferred when it looks like version churn is the
+ * source of most of the duplicates.
*
- * We only perform a deduplication pass for a checkingunique caller
- * when the incoming item is a duplicate of an existing item on the
- * leaf page. This heuristic avoids wasting cycles -- we only expect
- * to benefit from deduplicating a unique index page when most or all
- * recently added items are duplicates. See nbtree/README.
+ * We only consider deduplication for a checkingunique caller when the
+ * incoming item is a known duplicate of an existing item on the leaf
+ * page. This heuristic avoids wasting cycles. The overarching goal
+ * within a unique index is to prevent an unnecessary page split
+ * altogether by delaying splits again and again (the goal is not to
+ * save space). If even one incoming tuple that gets added to this
+ * page originates with an INSERT statement then a page split is all
+ * but inevitable anyway --- that's why it's okay that our heuristic
+ * only considers the current incoming newitem. See nbtree/README.
*/
if (PageGetFreeSpace(page) < insertstate->itemsz)
{
@@ -893,16 +908,24 @@ _bt_findinsertloc(Relation rel,
uniquedup = true;
}
- if (itup_key->allequalimage && BTGetDeduplicateItems(rel) &&
- (!checkingunique || uniquedup) &&
+ if (BTGetDeduplicateItems(rel) && (!checkingunique || uniquedup) &&
PageGetFreeSpace(page) < insertstate->itemsz)
{
+ bool dedupdelete = !logicallymodified || P_HAS_DUPS(lpageop);
+
_bt_dedup_one_page(rel, insertstate->buf, heapRel,
insertstate->itup, insertstate->itemsz,
- checkingunique);
+ checkingunique, dedupdelete,
+ itup_key->allequalimage);
insertstate->bounds_valid = false;
}
}
+ else if (!logicallymodified && !P_HAS_DUPS(lpageop))
+ {
+ lpageop->btpo_flags |= BTP_HAS_DUPS;
+
+ MarkBufferDirtyHint(insertstate->buf, true);
+ }
}
else
{
@@ -1525,11 +1548,11 @@ _bt_split(Relation rel, BTScanInsert itup_key, Buffer buf, Buffer cbuf,
lopaque = (BTPageOpaque) PageGetSpecialPointer(leftpage);
/*
- * leftpage won't be the root when we're done. Also, clear the SPLIT_END
- * and HAS_GARBAGE flags.
+ * leftpage won't be the root when we're done. Also, clear the SPLIT_END,
+ * HAS_GARBAGE, and HAS_DUPS flags.
*/
lopaque->btpo_flags = oopaque->btpo_flags;
- lopaque->btpo_flags &= ~(BTP_ROOT | BTP_SPLIT_END | BTP_HAS_GARBAGE);
+ lopaque->btpo_flags &= ~(BTP_ROOT | BTP_SPLIT_END | BTP_HAS_GARBAGE | BTP_HAS_DUPS);
/* set flag in leftpage indicating that rightpage has no downlink yet */
lopaque->btpo_flags |= BTP_INCOMPLETE_SPLIT;
lopaque->btpo_prev = oopaque->btpo_prev;
@@ -1712,11 +1735,11 @@ _bt_split(Relation rel, BTScanInsert itup_key, Buffer buf, Buffer cbuf,
lopaque->btpo_cycleid = _bt_vacuum_cycleid(rel);
/*
- * rightpage won't be the root when we're done. Also, clear the SPLIT_END
- * and HAS_GARBAGE flags.
+ * rightpage won't be the root when we're done. Also, clear the
+ * SPLIT_END, HAS_GARBAGE and HAS_DUPS flags.
*/
ropaque->btpo_flags = oopaque->btpo_flags;
- ropaque->btpo_flags &= ~(BTP_ROOT | BTP_SPLIT_END | BTP_HAS_GARBAGE);
+ ropaque->btpo_flags &= ~(BTP_ROOT | BTP_SPLIT_END | BTP_HAS_GARBAGE | BTP_HAS_DUPS);
ropaque->btpo_prev = origpagenumber;
ropaque->btpo_next = oopaque->btpo_next;
ropaque->btpo.level = oopaque->btpo.level;
@@ -2659,7 +2682,8 @@ _bt_vacuum_one_page(Relation rel, Buffer buffer, Relation heapRel)
}
if (ndeletable > 0)
- _bt_delitems_delete(rel, buffer, deletable, ndeletable, heapRel);
+ _bt_delitems_delete(rel, buffer, deletable, ndeletable, NULL, 0,
+ heapRel, false, InvalidTransactionId);
/*
* Note: if we didn't find any LP_DEAD items, then the page's
diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c
index 7f392480ac..898da4bf26 100644
--- a/src/backend/access/nbtree/nbtpage.c
+++ b/src/backend/access/nbtree/nbtpage.c
@@ -1117,8 +1117,7 @@ _bt_page_recyclable(Page page)
* We record VACUUMs and b-tree deletes differently in WAL. Deletes must
* generate their own latestRemovedXid by accessing the heap directly, whereas
* VACUUMs rely on the initial heap scan taking care of it indirectly. Also,
- * only VACUUM can perform granular deletes of individual TIDs in posting list
- * tuples.
+ * we remove the VACUUM cycle ID from pages, which b-tree deletes don't do.
*/
void
_bt_delitems_vacuum(Relation rel, Buffer buf,
@@ -1277,36 +1276,114 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
* Delete item(s) from a btree leaf page during single-page cleanup.
*
* This routine assumes that the caller has pinned and write locked the
- * buffer. Also, the given deletable array *must* be sorted in ascending
- * order.
+ * buffer. Also, the given deletable and updatable arrays *must* be sorted in
+ * ascending order.
*
* This is nearly the same as _bt_delitems_vacuum as far as what it does to
* the page, but it needs to generate its own latestRemovedXid by accessing
* the heap. This is used by the REDO routine to generate recovery conflicts.
- * Also, it doesn't handle posting list tuples unless the entire tuple can be
- * deleted as a whole (since there is only one LP_DEAD bit per line pointer).
+ * Though note that dedup deletion caller will provide its own
+ * latestRemovedXid, since it's convenient for it to determine that at the
+ * same point that it determines that the items are dead (it won't set LP_DEAD
+ * items). Another difference is that we don't clear page's vacuum cycle ID.
*/
void
_bt_delitems_delete(Relation rel, Buffer buf,
OffsetNumber *deletable, int ndeletable,
- Relation heapRel)
+ BTVacuumPosting *updatable, int nupdatable,
+ Relation heapRel, bool isdedup,
+ TransactionId dedupLatestRemovedXid)
{
Page page = BufferGetPage(buf);
BTPageOpaque opaque;
TransactionId latestRemovedXid = InvalidTransactionId;
+ Size itemsz;
+ char *updatedbuf = NULL;
+ Size updatedbuflen = 0;
+ OffsetNumber updatedoffsets[MaxIndexTuplesPerPage];
/* Shouldn't be called unless there's something to do */
- Assert(ndeletable > 0);
+ Assert(ndeletable > 0 || nupdatable > 0);
+ /* Shouldn't update posting lists unless for dedup caller */
+ Assert(isdedup || nupdatable == 0);
if (XLogStandbyInfoActive() && RelationNeedsWAL(rel))
- latestRemovedXid =
- _bt_xid_horizon(rel, heapRel, page, deletable, ndeletable);
+ {
+ if (!isdedup)
+ latestRemovedXid =
+ _bt_xid_horizon(rel, heapRel, page, deletable,
+ ndeletable);
+ else
+ latestRemovedXid = dedupLatestRemovedXid;
+ }
+
+ for (int i = 0; i < nupdatable; i++)
+ {
+ /* Replace work area IndexTuple with updated version */
+ _bt_update_posting(updatable[i]);
+
+ /* Maintain array of updatable page offsets for WAL record */
+ updatedoffsets[i] = updatable[i]->updatedoffset;
+ }
+
+ /* XLOG stuff -- allocate and fill buffer before critical section */
+ if (nupdatable > 0 && RelationNeedsWAL(rel))
+ {
+ Size offset = 0;
+
+ for (int i = 0; i < nupdatable; i++)
+ {
+ BTVacuumPosting vacposting = updatable[i];
+
+ itemsz = SizeOfBtreeUpdate +
+ vacposting->ndeletedtids * sizeof(uint16);
+ updatedbuflen += itemsz;
+ }
+
+ updatedbuf = palloc(updatedbuflen);
+ for (int i = 0; i < nupdatable; i++)
+ {
+ BTVacuumPosting vacposting = updatable[i];
+ xl_btree_update update;
+
+ update.ndeletedtids = vacposting->ndeletedtids;
+ memcpy(updatedbuf + offset, &update.ndeletedtids,
+ SizeOfBtreeUpdate);
+ offset += SizeOfBtreeUpdate;
+
+ itemsz = update.ndeletedtids * sizeof(uint16);
+ memcpy(updatedbuf + offset, vacposting->deletetids, itemsz);
+ offset += itemsz;
+ }
+ }
/* No ereport(ERROR) until changes are logged */
START_CRIT_SECTION();
- /* Fix the page */
- PageIndexMultiDelete(page, deletable, ndeletable);
+ /*
+ * Handle posting tuple updates.
+ *
+ * Deliberately do this before handling simple deletes. If we did it the
+ * other way around (i.e. WAL record order -- simple deletes before
+ * updates) then we'd have to make compensating changes to the 'updatable'
+ * array of offset numbers.
+ */
+ for (int i = 0; i < nupdatable; i++)
+ {
+ OffsetNumber updatedoffset = updatedoffsets[i];
+ IndexTuple itup;
+
+ itup = updatable[i]->itup;
+ itemsz = MAXALIGN(IndexTupleSize(itup));
+ if (!PageIndexTupleOverwrite(page, updatedoffset, (Item) itup,
+ itemsz))
+ elog(PANIC, "failed to update partially dead item in block %u of index \"%s\"",
+ BufferGetBlockNumber(buf), RelationGetRelationName(rel));
+ }
+
+ /* Now handle simple deletes of entire tuples */
+ if (ndeletable > 0)
+ PageIndexMultiDelete(page, deletable, ndeletable);
/*
* Unlike _bt_delitems_vacuum, we *must not* clear the vacuum cycle ID,
@@ -1326,6 +1403,7 @@ _bt_delitems_delete(Relation rel, Buffer buf,
xlrec_delete.latestRemovedXid = latestRemovedXid;
xlrec_delete.ndeleted = ndeletable;
+ xlrec_delete.nupdated = nupdatable;
XLogBeginInsert();
XLogRegisterBuffer(0, buf, REGBUF_STANDARD);
@@ -1336,8 +1414,16 @@ _bt_delitems_delete(Relation rel, Buffer buf,
* When XLogInsert stores the whole buffer, the array need not be
* stored too.
*/
- XLogRegisterBufData(0, (char *) deletable,
- ndeletable * sizeof(OffsetNumber));
+ if (ndeletable > 0)
+ XLogRegisterBufData(0, (char *) deletable,
+ ndeletable * sizeof(OffsetNumber));
+
+ if (nupdatable > 0)
+ {
+ XLogRegisterBufData(0, (char *) updatedoffsets,
+ nupdatable * sizeof(OffsetNumber));
+ XLogRegisterBufData(0, updatedbuf, updatedbuflen);
+ }
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_DELETE);
@@ -1345,6 +1431,13 @@ _bt_delitems_delete(Relation rel, Buffer buf,
}
END_CRIT_SECTION();
+
+ /* can't leak memory here */
+ if (updatedbuf != NULL)
+ pfree(updatedbuf);
+ /* free tuples generated by calling _bt_update_posting() */
+ for (int i = 0; i < nupdatable; i++)
+ pfree(updatable[i]->itup);
}
/*
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index 8730de25ed..3c10552f94 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -273,7 +273,7 @@ static void _bt_sortaddtup(Page page, Size itemsize,
bool newfirstdataitem);
static void _bt_buildadd(BTWriteState *wstate, BTPageState *state,
IndexTuple itup, Size truncextra);
-static void _bt_sort_dedup_finish_pending(BTWriteState *wstate,
+static void _bt_dedup_sort_finish_pending(BTWriteState *wstate,
BTPageState *state,
BTDedupState dstate);
static void _bt_uppershutdown(BTWriteState *wstate, BTPageState *state);
@@ -1068,11 +1068,11 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup,
* Finalize pending posting list tuple, and add it to the index. Final tuple
* is based on saved base tuple, and saved list of heap TIDs.
*
- * This is almost like _bt_dedup_finish_pending(), but it adds a new tuple
- * using _bt_buildadd().
+ * This is almost like _bt_dedup_merge_finish_pending(), but it adds a new
+ * tuple using _bt_buildadd().
*/
static void
-_bt_sort_dedup_finish_pending(BTWriteState *wstate, BTPageState *state,
+_bt_dedup_sort_finish_pending(BTWriteState *wstate, BTPageState *state,
BTDedupState dstate)
{
Assert(dstate->nitems > 0);
@@ -1371,7 +1371,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
* _bt_dedup_save_htid() opted to not merge current item into
* pending posting list.
*/
- _bt_sort_dedup_finish_pending(wstate, state, dstate);
+ _bt_dedup_sort_finish_pending(wstate, state, dstate);
pfree(dstate->base);
/* start new pending posting list with itup copy */
@@ -1390,7 +1390,7 @@ _bt_load(BTWriteState *wstate, BTSpool *btspool, BTSpool *btspool2)
* Handle the last item (there must be a last item when the
* tuplesort returned one or more tuples)
*/
- _bt_sort_dedup_finish_pending(wstate, state, dstate);
+ _bt_dedup_sort_finish_pending(wstate, state, dstate);
pfree(dstate->base);
pfree(dstate->htids);
}
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index bda9be2348..0a8e1d8295 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -530,12 +530,12 @@ btree_xlog_dedup(XLogReaderState *record)
}
else
{
- _bt_dedup_finish_pending(newpage, state);
+ _bt_dedup_merge_finish_pending(newpage, state);
_bt_dedup_start_pending(state, itup, offnum);
}
}
- _bt_dedup_finish_pending(newpage, state);
+ _bt_dedup_merge_finish_pending(newpage, state);
Assert(state->nintervals == xlrec->nintervals);
Assert(memcmp(state->intervals, intervals,
state->nintervals * sizeof(BTDedupInterval)) == 0);
@@ -675,7 +675,56 @@ btree_xlog_delete(XLogReaderState *record)
page = (Page) BufferGetPage(buffer);
- PageIndexMultiDelete(page, (OffsetNumber *) ptr, xlrec->ndeleted);
+ if (xlrec->nupdated > 0)
+ {
+ OffsetNumber *updatedoffsets;
+ xl_btree_update *updates;
+
+ updatedoffsets = (OffsetNumber *)
+ (ptr + xlrec->ndeleted * sizeof(OffsetNumber));
+ updates = (xl_btree_update *) ((char *) updatedoffsets +
+ xlrec->nupdated *
+ sizeof(OffsetNumber));
+
+ for (int i = 0; i < xlrec->nupdated; i++)
+ {
+ BTVacuumPosting vacposting;
+ IndexTuple origtuple;
+ ItemId itemid;
+ Size itemsz;
+
+ itemid = PageGetItemId(page, updatedoffsets[i]);
+ origtuple = (IndexTuple) PageGetItem(page, itemid);
+
+ vacposting = palloc(offsetof(BTVacuumPostingData, deletetids) +
+ updates->ndeletedtids * sizeof(uint16));
+ vacposting->updatedoffset = updatedoffsets[i];
+ vacposting->itup = origtuple;
+ vacposting->ndeletedtids = updates->ndeletedtids;
+ memcpy(vacposting->deletetids,
+ (char *) updates + SizeOfBtreeUpdate,
+ updates->ndeletedtids * sizeof(uint16));
+
+ _bt_update_posting(vacposting);
+
+ /* Overwrite updated version of tuple */
+ itemsz = MAXALIGN(IndexTupleSize(vacposting->itup));
+ if (!PageIndexTupleOverwrite(page, updatedoffsets[i],
+ (Item) vacposting->itup, itemsz))
+ elog(PANIC, "failed to update partially dead item");
+
+ pfree(vacposting->itup);
+ pfree(vacposting);
+
+ /* advance to next xl_btree_update from array */
+ updates = (xl_btree_update *)
+ ((char *) updates + SizeOfBtreeUpdate +
+ updates->ndeletedtids * sizeof(uint16));
+ }
+ }
+
+ if (xlrec->ndeleted > 0)
+ PageIndexMultiDelete(page, (OffsetNumber *) ptr, xlrec->ndeleted);
/* Mark the page as not containing any LP_DEAD items */
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
diff --git a/src/backend/access/table/tableam.c b/src/backend/access/table/tableam.c
index 6438c45716..c2092c21d5 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -207,9 +207,9 @@ table_beginscan_parallel(Relation relation, ParallelTableScanDesc parallel_scan)
/*
* To perform that check simply start an index scan, create the necessary
* slot, do the heap lookup, and shut everything down again. This could be
- * optimized, but is unlikely to matter from a performance POV. If there
- * frequently are live index pointers also matching a unique index key, the
- * CPU overhead of this routine is unlikely to matter.
+ * optimized, but is unlikely to matter from a performance POV. Note that
+ * table_index_delete_check() is optimized in this way, since it is designed
+ * as a batch operation.
*
* Note that *tid may be modified when we return true if the AM supports
* storing multiple row versions reachable via a single index entry (like
@@ -236,6 +236,27 @@ table_index_fetch_tuple_check(Relation rel,
return found;
}
+/*
+ * Specialized variant of table_index_fetch_tuple_check() that can be used
+ * by index AMs to perform "bottom up" deletion of duplicate index tuples.
+ * This is particularly likely to work well with unique indexes.
+ *
+ * Note: This routine sorts the deltids array, but does not modify any
+ * individual entry accept to mark it as dead for caller.
+ *
+ * Returns total number of deltids that can be killed in index by caller.
+ */
+int
+table_index_delete_check(Relation rel, TM_IndexDelete *deltids, int ndeltids,
+ Snapshot snapshot, int npromisingkillsneeded)
+{
+ /*
+ * TODO -- call heapam's heapam_index_delete_check() function here, and
+ * make nbtdedup.c call this shim function
+ */
+
+ return 0;
+}
/* ------------------------------------------------------------------------
* Functions for non-modifying operations on individual tuples
@@ -356,7 +377,7 @@ simple_table_tuple_update(Relation rel, ItemPointer otid,
GetCurrentCommandId(true),
snapshot, InvalidSnapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode, update_indexes);
+ &tmfd, &lockmode, update_indexes, NULL);
switch (result)
{
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 115860a9d4..514d8f0cce 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -2523,7 +2523,7 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
recheckIndexes =
ExecInsertIndexTuples(resultRelInfo,
buffer->slots[i], estate, false, NULL,
- NIL);
+ NIL, NULL);
ExecARInsertTriggers(estate, resultRelInfo,
slots[i], recheckIndexes,
cstate->transition_capture);
@@ -3268,7 +3268,8 @@ CopyFrom(CopyState cstate)
estate,
false,
NULL,
- NIL);
+ NIL,
+ NULL);
}
/* AFTER ROW INSERT Triggers */
diff --git a/src/backend/executor/execIndexing.c b/src/backend/executor/execIndexing.c
index c6b5bcba7b..d171d26b69 100644
--- a/src/backend/executor/execIndexing.c
+++ b/src/backend/executor/execIndexing.c
@@ -275,7 +275,8 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
EState *estate,
bool noDupErr,
bool *specConflict,
- List *arbiterIndexes)
+ List *arbiterIndexes,
+ Bitmapset *modified_attrs_hint)
{
ItemPointer tupleid = &slot->tts_tid;
List *result = NIL;
@@ -389,6 +390,44 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
else
checkUnique = UNIQUE_CHECK_PARTIAL;
+ /*
+ * We may have to hint to index am that this is a logically unchanged
+ * index tuple. This happens when we're inserting a duplicate tuple
+ * just to represent the successor version.
+ */
+ if (checkUnique == UNIQUE_CHECK_NO && modified_attrs_hint)
+ {
+ bool logicallyModified = false;
+
+ for (int attr = 0; attr < indexInfo->ii_NumIndexAttrs; attr++)
+ {
+ int keycol = indexInfo->ii_IndexAttrNumbers[attr];
+
+ if (keycol > 0)
+ {
+ logicallyModified =
+ bms_is_member(keycol - FirstLowInvalidHeapAttributeNumber,
+ modified_attrs_hint);
+ if (logicallyModified)
+ break;
+ }
+ else
+ {
+ /*
+ * XXX: For now we always assume that expression indexes
+ * and indexes with whole-row vars were not modified by an
+ * UPDATE (i.e. they just use the dedup delete
+ * optimization regardless of the details of the UPDATE).
+ * Review this decision when the high level design is a
+ * bit better worked out.
+ */
+ }
+ }
+
+ if (!logicallyModified)
+ checkUnique = UNIQUE_CHECK_NO_WITH_UNCHANGED;
+ }
+
satisfiesConstraint =
index_insert(indexRelation, /* index relation */
values, /* array of index Datums */
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index 01d26881e7..e97d05b448 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -445,7 +445,7 @@ ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false, NULL,
- NIL);
+ NIL, NULL);
/* AFTER ROW INSERT Triggers */
ExecARInsertTriggers(estate, resultRelInfo, slot,
@@ -513,7 +513,7 @@ ExecSimpleRelationUpdate(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false, NULL,
- NIL);
+ NIL, NULL);
/* AFTER ROW UPDATE Triggers */
ExecARUpdateTriggers(estate, resultRelInfo,
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 29e07b7228..d76e371595 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -601,7 +601,7 @@ ExecInsert(ModifyTableState *mtstate,
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, true,
&specConflict,
- arbiterIndexes);
+ arbiterIndexes, NULL);
/* adjust the tuple's state accordingly */
table_tuple_complete_speculative(resultRelationDesc, slot,
@@ -640,7 +640,7 @@ ExecInsert(ModifyTableState *mtstate,
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false,
- NULL, NIL);
+ NULL, NIL, NULL);
}
}
@@ -1219,6 +1219,7 @@ ExecUpdate(ModifyTableState *mtstate,
TM_Result result;
TM_FailureData tmfd;
List *recheckIndexes = NIL;
+ Bitmapset *modified_attrs_hint = NULL;
/*
* abort the operation if not running transactions
@@ -1382,7 +1383,8 @@ lreplace:;
estate->es_snapshot,
estate->es_crosscheck_snapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode, &update_indexes);
+ &tmfd, &lockmode, &update_indexes,
+ &modified_attrs_hint);
switch (result)
{
@@ -1513,9 +1515,13 @@ lreplace:;
/* insert index entries for tuple if necessary */
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
+ {
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false,
- NULL, NIL);
+ NULL, NIL,
+ modified_attrs_hint);
+ bms_free(modified_attrs_hint);
+ }
}
if (canSetTag)
--
2.25.1
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-11-09 17:20 ` Peter Geoghegan <[email protected]>
2020-11-11 14:17 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-11 20:58 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
0 siblings, 2 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-11-09 17:20 UTC (permalink / raw)
To: Simon Riggs <[email protected]>; +Cc: Anastasia Lubennikova <[email protected]>; PostgreSQL Hackers <[email protected]>; Victor Yegorov <[email protected]>
On Tue, Nov 3, 2020 at 12:44 PM Peter Geoghegan <[email protected]> wrote:
> v6 still needs more polishing -- my focus has still been on the
> algorithm itself. But I think I'm almost done with that part -- it
> seems unlikely that I'll be able to make any additional significant
> improvements in that area after v6.
Attached is v7, which tidies everything up. The project is now broken
up into multiple patches, which can be committed separately. Every
patch has a descriptive commit message. This should make it a lot
easier to review.
I've renamed the feature to "bottom-up index deletion" in this latest
revision. This seems like a better name than "dedup deletion". This
name suggests that the feature complements "top-down index deletion"
by VACUUM. This name is descriptive of what the new mechanism is
supposed to do at a high level.
Other changes in v7 include:
* We now fully use the tableam interface -- see the first patch.
The bottom-up index deletion API has been fully worked out. There is
now an optional callback/shim function. The bottom-up index deletion
caller (nbtree) is decoupled from the callee (heapam) by the tableam
shim. This was what allowed me to break the patch into multiple
pieces/patches.
* The executor no longer uses a IndexUniqueCheck-enum-constant as a
hint to nbtree. Rather, we have a new aminsert() bool argument/flag
that hints to the index AM -- see the second patch.
To recap, the hint tells nbtree that the incoming tuple is a duplicate
of an existing tuple caused by an UPDATE, without any logical changes
for the indexed columns. Bottom-up deletion is effective when there is
a local concentration of these index tuples that become garbage
quickly.
A dedicated aminsert() argument seems a lot cleaner. Though I wonder
if this approach can be generalized a bit further, so that we can
support other similar aminsert() hints in the future without adding
even more arguments. Maybe some new enum instead of a boolean?
* Code cleanup for the nbtdedup.c changes. Better explanation of when
and how posting list TIDs are marked promising, and why.
* Streamlined handling of the various strategies that nbtinsert.c uses
to avoid a page split (e.g. traditional LP_DEAD deletion,
deduplication).
A new unified function in nbtinsert.c was added. This organization is
a lot cleaner -- it greatly simplifies _bt_findinsertloc(), which
became more complicated than it really needed to be due to the changes
needed for deduplication in PostgreSQL 13. This change almost seems
like an independently useful piece of work.
--
Peter Geoghegan
Attachments:
[application/octet-stream] v7-0004-Teach-heapam-to-support-bottom-up-index-deletion.patch (24.8K, ../../CAH2-WzmP5AymEfT_n3wAdvW8D7DduapHPqRzds5kv7VjnXsx6Q@mail.gmail.com/2-v7-0004-Teach-heapam-to-support-bottom-up-index-deletion.patch)
download | inline diff:
From bd085fe6370276ed9ed2999ee650fc9808fd2795 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Sat, 7 Nov 2020 14:07:14 -0800
Subject: [PATCH v7 4/4] Teach heapam to support bottom-up index deletion.
This commit finalizes work started by recent related bottom-up index
deletion commits. This is the last piece required for the feature to
actually work.
Author: Peter Geoghegan <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wz=CEKFa74EScx_hFVshCOn6AA5T-ajFASTdzipdkLTNQQ@mail.gmail.com
---
src/include/access/heapam.h | 2 +
src/backend/access/heap/heapam.c | 613 +++++++++++++++++++++++
src/backend/access/heap/heapam_handler.c | 2 +-
3 files changed, 616 insertions(+), 1 deletion(-)
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index d950083a7d..b12579aa2f 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -171,6 +171,8 @@ extern void simple_heap_update(Relation relation, ItemPointer otid,
extern TransactionId heap_compute_xid_horizon_for_tuples(Relation rel,
ItemPointerData *items,
int nitems);
+extern TransactionId heapam_index_delete_check(Relation rel,
+ TM_IndexDeleteOp *vstate);
/* in heap/pruneheap.c */
struct GlobalVisState;
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 082aa7b687..6699044920 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -55,6 +55,7 @@
#include "miscadmin.h"
#include "pgstat.h"
#include "port/atomics.h"
+#include "port/pg_bitutils.h"
#include "storage/bufmgr.h"
#include "storage/freespace.h"
#include "storage/lmgr.h"
@@ -102,6 +103,7 @@ static void MultiXactIdWait(MultiXactId multi, MultiXactStatus status, uint16 in
int *remaining);
static bool ConditionalMultiXactIdWait(MultiXactId multi, MultiXactStatus status,
uint16 infomask, Relation rel, int *remaining);
+static int heapam_index_delete_check_sort(Relation rel, TM_IndexDeleteOp *vstate);
static XLogRecPtr log_heap_new_cid(Relation relation, HeapTuple tup);
static HeapTuple ExtractReplicaIdentity(Relation rel, HeapTuple tup, bool key_changed,
bool *copy);
@@ -178,6 +180,17 @@ typedef struct
} XidHorizonPrefetchState;
#endif
+/*
+ * heapam_index_delete_check uses this structure to determine which heap pages
+ * to visit, and in what order
+ */
+typedef struct IndexDeleteCounts
+{
+ int16 npromisingtids;
+ int16 ntids;
+ int16 ideltids;
+} IndexDeleteCounts;
+
/*
* This table maps tuple lock strength values for each particular
* MultiXactStatus value.
@@ -192,6 +205,11 @@ static const int MultiXactStatusLock[MaxMultiXactStatus + 1] =
LockTupleExclusive /* Update */
};
+/*
+ * Shellsort gap sequence (taken from Sedgewick-Incerpi paper)
+ */
+static const int ShellsortGaps[8] = {861, 336, 112, 48, 21, 7, 3, 1};
+
/* Get the LockTupleMode for a given MultiXactStatus */
#define TUPLOCK_from_mxstatus(status) \
(MultiXactStatusLock[(status)])
@@ -6993,6 +7011,9 @@ xid_horizon_prefetch_buffer(Relation rel,
* deleting hundreds of tuples from a single index block. To amortize that
* cost to some degree, this uses prefetching and combines repeat accesses to
* the same block.
+ *
+ * Note: The logic for maintaining latestRemovedXid here is duplicated by code
+ * within heapam_index_delete_check(). Make sure that they stay in sync.
*/
TransactionId
heap_compute_xid_horizon_for_tuples(Relation rel,
@@ -7139,6 +7160,598 @@ heap_compute_xid_horizon_for_tuples(Relation rel,
return latestRemovedXid;
}
+#define MAX_DELETE_HEAP_BLOCKS 4
+#define FAVORABLE_BLOCK_STRIDE 3
+
+/*
+ * Determine which heap tuples from a list of TIDs provided by caller are
+ * dead. It is safe to delete index tuples that point to these dead heap
+ * tuples.
+ *
+ * This is used by index AMs that support "bottom up" deletion of duplicate
+ * index tuples in batches of just a few heap pages at a time. Index AMs call
+ * here through the table_index_delete_check() interface. See tableam
+ * interface details (for the TM_IndexDeleteOp struct) for more information.
+ *
+ * Though the main thing that influences which heap pages are accessed here is
+ * the presence of tuples that index AM caller has marked "promising" (which
+ * relate to duplicate index tuples believed to have been inserted in index
+ * recently), there are other considerations. The approach taken here
+ * considers both spatial and temporal locality inside the heap structure.
+ * This is especially helpful when there are several heap blocks with
+ * approximately the same amount of promising tuples. Multiple calls here for
+ * the same index will tend to consistently delete the oldest index tuples,
+ * which keeps the number of buffer misses here to a minimum.
+ *
+ * Sometimes larger batch sizes are preferred here, even when that means that
+ * we might actually exceed caller's immediate requirement for free space in
+ * the index. Contiguous heap blocks are considered "favorable". The
+ * presence of favorable blocks makes the call as a whole access more blocks
+ * to better amortize costs. We expect to be called multiple times for
+ * related records in at least some cases, and have to consider costs over
+ * time. The cost of any individual call is less important.
+ *
+ * Returns the latestRemovedXid from the heap tuples pointed to by the deltids
+ * index tuples that caller finds marked safe to delete.
+ *
+ * Note: The logic for maintaining latestRemovedXid here is duplicated by code
+ * within heap_compute_xid_horizon_for_tuples(). Make sure that they stay in
+ * sync.
+ */
+TransactionId
+heapam_index_delete_check(Relation rel, TM_IndexDeleteOp *vstate)
+{
+ TransactionId latestRemovedXid = InvalidTransactionId;
+ BlockNumber hblkno = InvalidBlockNumber;
+ Buffer buf = InvalidBuffer;
+ Page hpage;
+ bool finalhpage = false;
+ int finalndeltids = 0;
+ int nblocksaccessed = 0;
+ int nblocksfavorable = 0;
+ int spacefreed = 0;
+ int spacefreedbeforecurhpage = 0;
+ SnapshotData SnapshotNonVacuumable;
+ TM_IndexDelete *deltids = vstate->deltids;
+ TM_IndexStatus *tidstatuses = vstate->tidstatuses;
+ int targetfreespace = vstate->targetfreespace;
+
+ InitNonVacuumableSnapshot(SnapshotNonVacuumable, GlobalVisTestFor(rel));
+
+ /*
+ * Sort and shrink deltids array so that it consists only of TIDs from
+ * just a few of the most promising blocks
+ */
+ nblocksfavorable = heapam_index_delete_check_sort(rel, vstate);
+ for (int i = 0; i < vstate->ndeltids; i++)
+ {
+ TM_IndexStatus *status = tidstatuses + deltids[i].id;
+ ItemPointer htid = &deltids[i].tid;
+ ItemPointerData tmp;
+ bool all_dead = false;
+ bool found;
+ ItemId hitemid;
+ OffsetNumber hoffnum;
+ HeapTupleData heapTuple;
+
+ Assert(!status->deleteitup);
+
+ if (hblkno == InvalidBlockNumber ||
+ ItemPointerGetBlockNumber(htid) != hblkno)
+ {
+ /*
+ * We usually do a little extra work on the final heap page after
+ * caller's target space to free has been reached. The cost of
+ * accessing the final heap page we'll need to visit has already
+ * been paid by that point. We finish off the entire final heap
+ * page because it's cheap to do so.
+ *
+ * We don't want to unnecessarily visit the next page in line.
+ * Handle that here (when we just finished final page).
+ */
+ if (finalhpage)
+ break;
+
+ /*
+ * Each time we're about to access a new page we consider if it's
+ * really worth it. We apply two tests before we visit the next
+ * page, and give up if either fails:
+ *
+ * 1. Give up when we didn't enable our caller to free any
+ * additional space as a result of processing the most recent heap
+ * page visited. We expect to make steady progress or no
+ * progress.
+ *
+ * 2. Give up when MAX_DELETE_HEAP_BLOCKS have been accessed
+ * already, no matter what. (This is defensive, since the deltids
+ * array was shrunk before we started. It should now contain TIDs
+ * from pages not exceeding MAX_DELETE_HEAP_BLOCKS in number.)
+ */
+ if (nblocksaccessed >= 1 && spacefreed == spacefreedbeforecurhpage)
+ break;
+ if (nblocksaccessed == MAX_DELETE_HEAP_BLOCKS)
+ break;
+
+ /*
+ * After visiting and processing the first heap page, aggressively
+ * decay target space freed (the request from index AM caller)
+ * before accessing each new heap page (starting with the second
+ * in line). But only start decaying when we encounter our first
+ * non-favorable block.
+ *
+ * Favorable blocks are contiguous groups of heap blocks that are
+ * likely to have related heap tuples that are cheaper to process
+ * in larger batches. It doesn't make sense to be stingy here.
+ * The index AM may end up calling us about the same heap TIDs
+ * before much time has passed if we do that.
+ *
+ * Note that even favorable blocks are required to enable caller
+ * to free at least some space -- otherwise we give up before
+ * accessing the next block in line. If a favorable block cannot
+ * be freed then there is probably an old snapshot that frustrates
+ * progress here in general.
+ */
+ if (nblocksfavorable == 0)
+ {
+ targetfreespace /= 2;
+
+ /* Must always start out with at least 1 favorable block */
+ Assert(nblocksaccessed >= 1);
+ }
+
+ /* Now access next page */
+ if (BufferIsValid(buf))
+ {
+ LockBuffer(buf, BUFFER_LOCK_UNLOCK);
+ ReleaseBuffer(buf);
+ }
+
+ /*
+ * We could prune the heap page in passing here, but that doesn't
+ * seem like a good idea. (Index AM caller is expected to hold
+ * locks of its own.)
+ */
+ hblkno = ItemPointerGetBlockNumber(htid);
+ buf = ReadBuffer(rel, hblkno);
+ hpage = BufferGetPage(buf);
+ nblocksaccessed++;
+ if (nblocksfavorable > 0)
+ nblocksfavorable--;
+ spacefreedbeforecurhpage = spacefreed;
+
+ /* Need to lock buffer for visibility checks */
+ LockBuffer(buf, BUFFER_LOCK_SHARE);
+ }
+
+ tmp = *htid;
+ found = heap_hot_search_buffer(&tmp, rel, buf, &SnapshotNonVacuumable,
+ &heapTuple, &all_dead, true);
+
+ if (found || !all_dead)
+ continue;
+
+ /* Caller can delete this TID from index */
+ finalndeltids = i + 1;
+ status->deleteitup = true;
+ spacefreed += status->tupsize;
+
+ if (spacefreed >= targetfreespace)
+ {
+ /*
+ * Caller's free space target has now been met (maybe...target may
+ * have decayed one or more times from original value if we
+ * weren't accessing favorable/contiguous blocks).
+ *
+ * Finish off the current/final heap page before finishing.
+ */
+ finalhpage = true;
+ }
+
+ /*
+ * One last step required for TID that caller will delete. Must
+ * maintain latestRemovedXid for caller's delete operation.
+ */
+ hoffnum = ItemPointerGetOffsetNumber(htid);
+ hitemid = PageGetItemId(hpage, hoffnum);
+
+ while (ItemIdIsRedirected(hitemid))
+ {
+ hoffnum = ItemIdGetRedirect(hitemid);
+ hitemid = PageGetItemId(hpage, hoffnum);
+ }
+
+ /*
+ * If the heap item has storage, then read the header and use that to
+ * set latestRemovedXid.
+ *
+ * Some LP_DEAD items may not be accessible, so we ignore them.
+ */
+ if (ItemIdHasStorage(hitemid))
+ {
+ HeapTupleHeader htuphdr;
+
+ htuphdr = (HeapTupleHeader) PageGetItem(hpage, hitemid);
+
+ HeapTupleHeaderAdvanceLatestRemovedXid(htuphdr, &latestRemovedXid);
+ }
+ else if (ItemIdIsDead(hitemid))
+ {
+ /*
+ * Conjecture: if hitemid is dead then it had xids before the xids
+ * marked on LP_NORMAL items. So we just ignore this item and move
+ * onto the next, for the purposes of calculating
+ * latestRemovedXid.
+ */
+ }
+ else
+ Assert(!ItemIdIsUsed(hitemid));
+ }
+
+ if (BufferIsValid(buf))
+ {
+ LockBuffer(buf, BUFFER_LOCK_UNLOCK);
+ ReleaseBuffer(buf);
+ }
+
+ vstate->ndeltids = finalndeltids;
+
+ /*
+ * If all heap tuples were LP_DEAD then we will be returning
+ * InvalidTransactionId here, which avoids conflicts. This matches
+ * existing logic which assumes that LP_DEAD tuples must already be older
+ * than the latestRemovedXid on the cleanup record that set them as
+ * LP_DEAD, hence must already have generated a conflict.
+ */
+
+ return latestRemovedXid;
+}
+
+/*
+ * Determine how many favorable blocks are among blocks we'll access (which
+ * have been sorted by heapam_index_delete_check_sort() by the time we get
+ * called). The exact approach taken by heapam_index_delete_check() is
+ * influenced by the number of favorable blocks.
+ *
+ * Returns number of favorable blocks, starting from (and including) the first
+ * block in line for processing.
+ *
+ * Favorable blocks are contiguous heap blocks, which are likely to have
+ * relatively many dead items. These blocks are cheaper to access together
+ * all at once. Having many favorable blocks is common with low cardinality
+ * index tuples, where heap locality has a relatively large influence on which
+ * heap blocks we visit (and the order they're processed in). Being more
+ * aggressive with favorable blocks is slightly more expensive in the short
+ * term, but less expensive across related heapam_index_delete_check() calls.
+ *
+ * Note: We always indicate that there is at least 1 favorable block (the
+ * first in line to process). The first block must always be in sorted order
+ * because the ordering is relative to the first block (or previous block).
+ * This degenerate case isn't a problem for heapam_index_delete_check(), which
+ * is supposed to always visit the first heap page in line, regardless of any
+ * other factor.
+ */
+static int
+top_block_groups_favorable(IndexDeleteCounts *blockcounts, int nblockgroups,
+ TM_IndexDelete *deltids)
+{
+ int nblocksfavorable = 0;
+ BlockNumber lastblock = InvalidBlockNumber;
+
+ for (int b = 0; b < nblockgroups; b++)
+ {
+ IndexDeleteCounts *blockgroup = blockcounts + b;
+ TM_IndexDelete *firstingroup = deltids + blockgroup->ideltids;
+ BlockNumber thisblock = ItemPointerGetBlockNumber(&firstingroup->tid);
+
+ if (BlockNumberIsValid(lastblock) &&
+ (thisblock < lastblock ||
+ thisblock > lastblock + FAVORABLE_BLOCK_STRIDE))
+ break;
+
+ nblocksfavorable++;
+ lastblock = Min(thisblock, MaxBlockNumber - FAVORABLE_BLOCK_STRIDE);
+ }
+
+ Assert(nblocksfavorable >= 1);
+
+ return nblocksfavorable;
+}
+
+static inline int
+indexdelete_tids_cmp(ItemPointer tid1, ItemPointer tid2)
+{
+ {
+ BlockNumber blk1 = ItemPointerGetBlockNumber(tid1);
+ BlockNumber blk2 = ItemPointerGetBlockNumber(tid2);
+
+ if (blk1 != blk2)
+ return (blk1 < blk2) ? -1 : 1;
+ }
+ {
+ OffsetNumber pos1 = ItemPointerGetOffsetNumber(tid1);
+ OffsetNumber pos2 = ItemPointerGetOffsetNumber(tid2);
+
+ if (pos1 != pos2)
+ return (pos1 < pos2) ? -1 : 1;
+ }
+
+ pg_unreachable();
+
+ return 0;
+}
+
+static inline int
+indexdeletecount_cmp(IndexDeleteCounts *count1, IndexDeleteCounts *count2)
+{
+ uint32 ntids1,
+ ntids2;
+
+ /* We expect power-of-two values for npromisingtids fields */
+ Assert(count1->npromisingtids == 0 ||
+ ((count1->npromisingtids - 1) & count1->npromisingtids) == 0);
+ Assert(count2->npromisingtids == 0 ||
+ ((count2->npromisingtids - 1) & count2->npromisingtids) == 0);
+
+ /*
+ * Most significant field is npromisingtids, which we sort on in desc
+ * order. The usual asc comparison order is deliberately inverted here.
+ */
+ if (count1->npromisingtids > count2->npromisingtids)
+ return -1;
+ if (count1->npromisingtids < count2->npromisingtids)
+ return 1;
+
+ /*
+ * Tiebreak: desc ntids sort order.
+ *
+ * We cannot expect power-of-two values for ntids fields. We should
+ * behave as if they were already rounded up for us instead.
+ */
+ ntids1 = count1->ntids;
+ ntids2 = count2->ntids;
+ if (ntids1 != ntids2)
+ {
+ ntids1 = pg_nextpower2_32(ntids1);
+ ntids2 = pg_nextpower2_32(ntids2);
+
+ if (ntids1 > ntids2)
+ return -1;
+ if (ntids1 < ntids2)
+ return 1;
+ }
+
+ /*
+ * Tiebreak: asc offset-into-deltids-for-block (offset to first TID for
+ * block in deltids array) order.
+ *
+ * This is equivalent to sorting in ascending heap block number order
+ * (among otherwise equal subsets of the array). This approach allows us
+ * to avoid accessing the out-of-line TID. (We rely on the assumption
+ * that the deltids array was sorted in ascending heap TID order when
+ * these offsets to the first TID from each heap block group were formed.)
+ */
+ if (count1->ideltids > count2->ideltids)
+ return 1;
+ if (count1->ideltids < count2->ideltids)
+ return -1;
+
+ pg_unreachable();
+
+ return 0;
+}
+
+/*
+ * Two hand written shellshort implementations.
+ *
+ * The two sort operations needed by heapam_index_delete_check_sort() become
+ * quite noticeable on profiles of workloads with lots of index contention
+ * caused by non-HOT updates. Keeping costs down is important enough to
+ * justify several micro-optimizations. We could just use qsort() instead,
+ * but the indirection that it imposes is expensive enough to matter here.
+ * (The size of array elements also matters, which is why we keep it under 8
+ * bytes - swaps should be as fast as reasonably possible).
+ *
+ * We use shellsort here because it has many of the same strengths as an
+ * industrial-strength quicksort implementation, but is also lightweight in
+ * the sense that the entire implementation compiles to relatively few machine
+ * instructions. It is adaptive to inputs with some presorted subsets (which
+ * are typical here).
+ *
+ * This implementation is fast with array sizes up to about 1900. This covers
+ * all supported BLCKSZ values.
+ */
+static void
+heap_tid_shellsort(TM_IndexDelete *deltids, int ndeltids)
+{
+ int low = 0;
+
+ /* Think carefully before changing anything here */
+ StaticAssertStmt(sizeof(TM_IndexDelete) <= 8,
+ "element size exceeds 8 bytes");
+
+ for (int g = 0; g < lengthof(ShellsortGaps); g++)
+ {
+ for (int hi = ShellsortGaps[g], i = low + hi; i < ndeltids; i++)
+ {
+ TM_IndexDelete d = deltids[i];
+ int j = i;
+
+ while (j >= hi &&
+ indexdelete_tids_cmp(&deltids[j - hi].tid, &d.tid) >= 0)
+ {
+ deltids[j] = deltids[j - hi];
+ j -= hi;
+ }
+ deltids[j] = d;
+ }
+ }
+}
+
+static void
+index_delete_shellsort(IndexDeleteCounts *blockcounts, int nblockgroups)
+{
+ int low = 0;
+
+ /* Think carefully before changing anything here */
+ StaticAssertStmt(sizeof(IndexDeleteCounts) <= 8,
+ "element size exceeds 8 bytes");
+
+ for (int g = 0; g < lengthof(ShellsortGaps); g++)
+ {
+ for (int hi = ShellsortGaps[g], i = low + hi; i < nblockgroups; i++)
+ {
+ IndexDeleteCounts c = blockcounts[i];
+ int j = i;
+
+ while (j >= hi &&
+ indexdeletecount_cmp(&blockcounts[j - hi], &c) >= 0)
+ {
+ blockcounts[j] = blockcounts[j - hi];
+ j -= hi;
+ }
+ blockcounts[j] = c;
+ }
+ }
+}
+
+/*
+ * heapam_index_delete_check() helper function. Sorts deltids array in the
+ * order needed for useful processing.
+ *
+ * Groups heap TIDs from deltids into heap block number groupings. From
+ * there, sorts each heap block grouping by the total number of "promising"
+ * TIDs it contains (in desc order). For blocks with the same number of
+ * promising TIDs, tiebreak on the total heap TID count (also desc order).
+ *
+ * heapam_index_delete_check() only visits 1 - MAX_DELETE_HEAP_BLOCKS heap
+ * blocks due to the speculative nature of the batch index deletion
+ * optimization. These heap blocks had better be the most promising
+ * available, based on a variety of criteria. We make sure of that here.
+ *
+ * Sets new size of deltids array (ndeltids) in state. deltids will only have
+ * TIDs from the MAX_DELETE_HEAP_BLOCKS most promising heap blocks when we
+ * return (which is usually far fewer).
+ *
+ * Returns number of "favorable" blocks.
+ */
+static int
+heapam_index_delete_check_sort(Relation rel, TM_IndexDeleteOp *vstate)
+{
+ IndexDeleteCounts *blockcounts;
+ TM_IndexDelete *reordereddeltids;
+ BlockNumber curblock = InvalidBlockNumber;
+ int nblockgroups = 0;
+ int ncopied = 0;
+ int nblocksfavorable = 0;
+
+ Assert(vstate->ndeltids > 0);
+
+ /* First sort caller's array by TID */
+ heap_tid_shellsort(vstate->deltids, vstate->ndeltids);
+
+ /* Calculate per-heap-block count of TIDs */
+ blockcounts = palloc(sizeof(IndexDeleteCounts) * vstate->ndeltids);
+ for (int i = 0; i < vstate->ndeltids; i++)
+ {
+ ItemPointer deltid = &vstate->deltids[i].tid;
+ TM_IndexStatus *status = vstate->tidstatuses + vstate->deltids[i].id;
+ bool ispromising = status->ispromising;
+
+ if (curblock != ItemPointerGetBlockNumber(deltid))
+ {
+ /* New block group */
+ nblockgroups++;
+
+ Assert(curblock < ItemPointerGetBlockNumber(deltid) ||
+ !BlockNumberIsValid(curblock));
+
+ curblock = ItemPointerGetBlockNumber(deltid);
+ blockcounts[nblockgroups - 1].ideltids = i;
+ blockcounts[nblockgroups - 1].ntids = 1;
+ blockcounts[nblockgroups - 1].npromisingtids = 0;
+ }
+ else
+ {
+ blockcounts[nblockgroups - 1].ntids++;
+ }
+
+ if (ispromising)
+ blockcounts[nblockgroups - 1].npromisingtids++;
+ }
+
+ /*
+ * We're about ready to use index_delete_shellsort() to determine the
+ * optimal order for visiting heap pages. But before we do, round the
+ * number of promising tuples for each block group up to the nearest
+ * power-of-two (unless there are zero promising tuples). This scheme
+ * usefully divides heap pages into buckets. Each bucket contains heap
+ * pages that are approximately equally promising, that we want to treat
+ * as exactly equivalent (at least initially).
+ *
+ * While in general the presence of promising tuples (the hint that index
+ * AMs provide) is the best information that we have to go on, it is based
+ * on simple heuristics about duplicates in indexes that are understood to
+ * have specific flaws. We should not let the most promising heap pages
+ * win or lose on the basis of _relatively_ small differences in the total
+ * number of promising tuples. Small differences between the most
+ * promising few heap pages are effectively ignored by applying this
+ * power-of-two bucketing scheme.
+ *
+ * When we have lots of ties on the final bucket-ized npromisingtids among
+ * the most promising heap pages, we let heap locality determine the order
+ * in which we visit heap pages. This is helpful because it exploits the
+ * natural tendency for earlier heap blocks to accumulate more LP_DEAD
+ * items sooner in workloads with many non-HOT updates. It's also helpful
+ * because the effect over time is that we process related heap blocks
+ * sequentially, possibly with multiple rounds of processing over the same
+ * related heap blocks that are subject to continuous non-HOT updates over
+ * time.
+ *
+ * Note that we effectively have the same power-of-two bucketing scheme
+ * with the ntids field (which is compared after npromisingtids). The
+ * only reason that we don't fix nhtids here is that the original values
+ * will be needed when copying the final TIDs from winning block groups
+ * back into caller's deltids array.
+ */
+ for (int b = 0; b < nblockgroups; b++)
+ {
+ IndexDeleteCounts *blockgroup = blockcounts + b;
+
+ if (blockgroup->npromisingtids != 0)
+ blockgroup->npromisingtids =
+ pg_nextpower2_32((uint32) blockgroup->npromisingtids);
+ }
+
+ /* Sort groups and rearrange caller's deltids array */
+ index_delete_shellsort(blockcounts, nblockgroups);
+ reordereddeltids = palloc(vstate->ndeltids * sizeof(TM_IndexDelete));
+
+ nblockgroups = Min(MAX_DELETE_HEAP_BLOCKS, nblockgroups);
+ /* Determine number of favorable blocks at the start of array */
+ nblocksfavorable = top_block_groups_favorable(blockcounts, nblockgroups,
+ vstate->deltids);
+ for (int b = 0; b < nblockgroups; b++)
+ {
+ IndexDeleteCounts *blockgroup = blockcounts + b;
+ TM_IndexDelete *firstingroup = vstate->deltids + blockgroup->ideltids;
+
+ memcpy(reordereddeltids + ncopied, firstingroup,
+ sizeof(TM_IndexDelete) * blockgroup->ntids);
+ ncopied += blockgroup->ntids;
+ }
+
+ /* Copy final grouped and sorted TIDs back into start of caller's array */
+ memcpy(vstate->deltids, reordereddeltids,
+ sizeof(TM_IndexDelete) * ncopied);
+ vstate->ndeltids = ncopied;
+
+ /* be tidy */
+ pfree(reordereddeltids);
+ pfree(blockcounts);
+
+ return nblocksfavorable;
+}
+
/*
* Perform XLogInsert to register a heap cleanup info message. These
* messages are sent once per VACUUM and are required because
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 0dab0ae634..2ab25c72e8 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2534,7 +2534,7 @@ static const TableAmRoutine heapam_methods = {
.tuple_delete = heapam_tuple_delete,
.tuple_update = heapam_tuple_update,
.tuple_lock = heapam_tuple_lock,
- .index_delete_check = NULL,
+ .index_delete_check = heapam_index_delete_check,
.tuple_fetch_row_version = heapam_fetch_row_version,
.tuple_get_latest_tid = heap_get_latest_tid,
--
2.25.1
[application/octet-stream] v7-0002-Pass-down-logically-unchanged-index-hint.patch (25.7K, ../../CAH2-WzmP5AymEfT_n3wAdvW8D7DduapHPqRzds5kv7VjnXsx6Q@mail.gmail.com/3-v7-0002-Pass-down-logically-unchanged-index-hint.patch)
download | inline diff:
From dfe10af79d1866fdb7a46fa826309d10f77c02bc Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Sat, 7 Nov 2020 14:07:14 -0800
Subject: [PATCH v7 2/4] Pass down "logically unchanged index" hint.
Add an executor aminsert() hinting mechanism that informs index AMs that
the incoming index tuple (the tuple that accompanies the hint) is not
being inserted because of a logical change to indexed columns (from an
UPDATE or INSERT statement). This "logically unchanged" hint indicates
that the incoming item must be a duplicate of some existing item in the
index (a physical tuple that represents an obsolescent version of the
logical row affected by an UPDATE). When this happens the new tuple is
only needed so that the index will have a separate entry for the latest
logical row (it's latest version/HOT chain).
An aminsert() call which gets the hint is fundamentally different to any
aminsert() call needed for an INSERT statement. It's also fundamentally
difference to an aminsert() call needed for an UPDATE statement where
the index is logically changed by the UPDATE. Recognizing this
difference can allow cleanup of garbage tuples in index access methods
to work better. Cleanup can intelligently target tuples that are likely
to be garbage, without wasting too many cycles on less promising tuples.
This commit is infrastructure for an upcoming commit that will teach
nbtree to perform bottom-up index deletion. No index AM applies the
hint at this point. It is not useful on its own.
Author: Peter Geoghegan <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wz=CEKFa74EScx_hFVshCOn6AA5T-ajFASTdzipdkLTNQQ@mail.gmail.com
---
src/include/access/amapi.h | 1 +
src/include/access/brin_internal.h | 1 +
src/include/access/genam.h | 1 +
src/include/access/gin_private.h | 1 +
src/include/access/gist_private.h | 1 +
src/include/access/hash.h | 1 +
src/include/access/heapam.h | 3 +-
src/include/access/nbtree.h | 1 +
src/include/access/spgist.h | 1 +
src/include/access/tableam.h | 11 ++++--
src/include/executor/executor.h | 3 +-
src/backend/access/brin/brin.c | 1 +
src/backend/access/common/toast_internals.c | 2 +-
src/backend/access/gin/gininsert.c | 1 +
src/backend/access/gist/gist.c | 1 +
src/backend/access/hash/hash.c | 1 +
src/backend/access/heap/heapam.c | 12 ++++--
src/backend/access/heap/heapam_handler.c | 6 ++-
src/backend/access/index/indexam.c | 4 +-
src/backend/access/nbtree/nbtree.c | 1 +
src/backend/access/spgist/spginsert.c | 1 +
src/backend/access/table/tableam.c | 2 +-
src/backend/catalog/indexing.c | 1 +
src/backend/commands/constraint.c | 2 +-
src/backend/commands/copy.c | 5 ++-
src/backend/executor/execIndexing.c | 43 ++++++++++++++++++++-
src/backend/executor/execReplication.c | 4 +-
src/backend/executor/nodeModifyTable.c | 14 +++++--
doc/src/sgml/indexam.sgml | 13 +++++++
29 files changed, 116 insertions(+), 23 deletions(-)
diff --git a/src/include/access/amapi.h b/src/include/access/amapi.h
index 85b4766016..50422c9195 100644
--- a/src/include/access/amapi.h
+++ b/src/include/access/amapi.h
@@ -110,6 +110,7 @@ typedef bool (*aminsert_function) (Relation indexRelation,
ItemPointer heap_tid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
/* bulk delete */
diff --git a/src/include/access/brin_internal.h b/src/include/access/brin_internal.h
index 9ffc9100c0..5016b8035f 100644
--- a/src/include/access/brin_internal.h
+++ b/src/include/access/brin_internal.h
@@ -91,6 +91,7 @@ extern void brinbuildempty(Relation index);
extern bool brininsert(Relation idxRel, Datum *values, bool *nulls,
ItemPointer heaptid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
extern IndexScanDesc brinbeginscan(Relation r, int nkeys, int norderbys);
extern int64 bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
diff --git a/src/include/access/genam.h b/src/include/access/genam.h
index 68d90f5141..43bf62fbcc 100644
--- a/src/include/access/genam.h
+++ b/src/include/access/genam.h
@@ -143,6 +143,7 @@ extern bool index_insert(Relation indexRelation,
ItemPointer heap_t_ctid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
extern IndexScanDesc index_beginscan(Relation heapRelation,
diff --git a/src/include/access/gin_private.h b/src/include/access/gin_private.h
index 5cb2f72e4c..99541b82e8 100644
--- a/src/include/access/gin_private.h
+++ b/src/include/access/gin_private.h
@@ -116,6 +116,7 @@ extern void ginbuildempty(Relation index);
extern bool gininsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
extern void ginEntryInsert(GinState *ginstate,
OffsetNumber attnum, Datum key, GinNullCategory category,
diff --git a/src/include/access/gist_private.h b/src/include/access/gist_private.h
index b68c01a5f2..6adccb26a0 100644
--- a/src/include/access/gist_private.h
+++ b/src/include/access/gist_private.h
@@ -403,6 +403,7 @@ extern void gistbuildempty(Relation index);
extern bool gistinsert(Relation r, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
extern MemoryContext createTempGistContext(void);
extern GISTSTATE *initGISTstate(Relation index);
diff --git a/src/include/access/hash.h b/src/include/access/hash.h
index bab4d9f1b0..d832dd03de 100644
--- a/src/include/access/hash.h
+++ b/src/include/access/hash.h
@@ -364,6 +364,7 @@ extern void hashbuildempty(Relation index);
extern bool hashinsert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
extern bool hashgettuple(IndexScanDesc scan, ScanDirection dir);
extern int64 hashgetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 92b19dba32..d950083a7d 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -148,7 +148,8 @@ extern void heap_abort_speculative(Relation relation, ItemPointer tid);
extern TM_Result heap_update(Relation relation, ItemPointer otid,
HeapTuple newtup,
CommandId cid, Snapshot crosscheck, bool wait,
- struct TM_FailureData *tmfd, LockTupleMode *lockmode);
+ struct TM_FailureData *tmfd, LockTupleMode *lockmode,
+ Bitmapset **modified_attrs_hint);
extern TM_Result heap_lock_tuple(Relation relation, HeapTuple tuple,
CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy,
bool follow_update,
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index 65d9698b89..f002e5ff17 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -996,6 +996,7 @@ extern void btbuildempty(Relation index);
extern bool btinsert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
extern IndexScanDesc btbeginscan(Relation rel, int nkeys, int norderbys);
extern Size btestimateparallelscan(void);
diff --git a/src/include/access/spgist.h b/src/include/access/spgist.h
index 9f2ccc1730..3a4a570d8c 100644
--- a/src/include/access/spgist.h
+++ b/src/include/access/spgist.h
@@ -199,6 +199,7 @@ extern void spgbuildempty(Relation index);
extern bool spginsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
/* spgscan.c */
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 4aa131da0d..19b9c996a5 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -465,7 +465,8 @@ typedef struct TableAmRoutine
bool wait,
TM_FailureData *tmfd,
LockTupleMode *lockmode,
- bool *update_indexes);
+ bool *update_indexes,
+ Bitmapset **modified_attrs_hint);
/* see table_tuple_lock() for reference about parameters */
TM_Result (*tuple_lock) (Relation rel,
@@ -1372,6 +1373,9 @@ table_tuple_delete(Relation rel, ItemPointer tid, CommandId cid,
* lockmode - filled with lock mode acquired on tuple
* update_indexes - in success cases this is set to true if new index entries
* are required for this tuple
+ * modified_attrs_hint - which attributes were logically modified by the
+ * update. Passed down to index AMs as a hint from the executor.
+ * Enables table_index_delete_check() optimization.
*
* Normal, successful return value is TM_Ok, which means we did actually
* update it. Failure return codes are TM_SelfModified, TM_Updated, and
@@ -1391,12 +1395,13 @@ static inline TM_Result
table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot,
CommandId cid, Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode,
- bool *update_indexes)
+ bool *update_indexes, Bitmapset **modified_attrs_hint)
{
return rel->rd_tableam->tuple_update(rel, otid, slot,
cid, snapshot, crosscheck,
wait, tmfd,
- lockmode, update_indexes);
+ lockmode, update_indexes,
+ modified_attrs_hint);
}
/*
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h
index 0c48d2a519..6e6e56583b 100644
--- a/src/include/executor/executor.h
+++ b/src/include/executor/executor.h
@@ -582,7 +582,8 @@ extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
extern List *ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot, EState *estate,
bool noDupErr,
- bool *specConflict, List *arbiterIndexes);
+ bool *specConflict, List *arbiterIndexes,
+ Bitmapset *modified_attrs_hint);
extern bool ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot,
EState *estate, ItemPointer conflictTid,
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index 1f72562c60..d295c592be 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -151,6 +151,7 @@ bool
brininsert(Relation idxRel, Datum *values, bool *nulls,
ItemPointer heaptid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo)
{
BlockNumber pagesPerRange;
diff --git a/src/backend/access/common/toast_internals.c b/src/backend/access/common/toast_internals.c
index 25a81e5ec6..e206e67756 100644
--- a/src/backend/access/common/toast_internals.c
+++ b/src/backend/access/common/toast_internals.c
@@ -328,7 +328,7 @@ toast_save_datum(Relation rel, Datum value,
toastrel,
toastidxs[i]->rd_index->indisunique ?
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
- NULL);
+ false, NULL);
}
/*
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index 77433dc8a4..6a1e8560a3 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -488,6 +488,7 @@ bool
gininsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo)
{
GinState *ginstate = (GinState *) indexInfo->ii_AmCache;
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index 25b42e38f2..09b585547b 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -156,6 +156,7 @@ bool
gistinsert(Relation r, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo)
{
GISTSTATE *giststate = (GISTSTATE *) indexInfo->ii_AmCache;
diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c
index 7c9ccf446c..2ff72bd9f9 100644
--- a/src/backend/access/hash/hash.c
+++ b/src/backend/access/hash/hash.c
@@ -247,6 +247,7 @@ bool
hashinsert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo)
{
Datum index_values[1];
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 1b2f70499e..082aa7b687 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2892,7 +2892,8 @@ simple_heap_delete(Relation relation, ItemPointer tid)
TM_Result
heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
CommandId cid, Snapshot crosscheck, bool wait,
- TM_FailureData *tmfd, LockTupleMode *lockmode)
+ TM_FailureData *tmfd, LockTupleMode *lockmode,
+ Bitmapset **modified_attrs_hint)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -3758,10 +3759,15 @@ l2:
if (old_key_tuple != NULL && old_key_copied)
heap_freetuple(old_key_tuple);
+ /* Save for no logical changes hint when non-HOT update performed */
+ if (!use_hot_update && modified_attrs_hint)
+ *modified_attrs_hint = modified_attrs;
+ else
+ bms_free(modified_attrs);
+
bms_free(hot_attrs);
bms_free(key_attrs);
bms_free(id_attrs);
- bms_free(modified_attrs);
bms_free(interesting_attrs);
return TM_Ok;
@@ -3891,7 +3897,7 @@ simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
result = heap_update(relation, otid, tup,
GetCurrentCommandId(true), InvalidSnapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode);
+ &tmfd, &lockmode, NULL);
switch (result)
{
case TM_SelfModified:
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index a08c494034..0dab0ae634 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -314,7 +314,8 @@ static TM_Result
heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
CommandId cid, Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
- LockTupleMode *lockmode, bool *update_indexes)
+ LockTupleMode *lockmode, bool *update_indexes,
+ Bitmapset **modified_attrs_hint)
{
bool shouldFree = true;
HeapTuple tuple = ExecFetchSlotHeapTuple(slot, true, &shouldFree);
@@ -325,7 +326,7 @@ heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
tuple->t_tableOid = slot->tts_tableOid;
result = heap_update(relation, otid, tuple, cid, crosscheck, wait,
- tmfd, lockmode);
+ tmfd, lockmode, modified_attrs_hint);
ItemPointerCopy(&tuple->t_self, &slot->tts_tid);
/*
@@ -1931,6 +1932,7 @@ heapam_index_validate_scan(Relation heapRelation,
heapRelation,
indexInfo->ii_Unique ?
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
+ false,
indexInfo);
state->tups_inserted += 1;
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index 3fb8688f8f..0d7fc965e0 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -179,6 +179,7 @@ index_insert(Relation indexRelation,
ItemPointer heap_t_ctid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo)
{
RELATION_CHECKS;
@@ -191,7 +192,8 @@ index_insert(Relation indexRelation,
return indexRelation->rd_indam->aminsert(indexRelation, values, isnull,
heap_t_ctid, heapRelation,
- checkUnique, indexInfo);
+ checkUnique, indexunchanged,
+ indexInfo);
}
/*
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index c4f22f1c69..8eeb7bb64e 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -199,6 +199,7 @@ bool
btinsert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo)
{
bool result;
diff --git a/src/backend/access/spgist/spginsert.c b/src/backend/access/spgist/spginsert.c
index e4508a2b92..8e55f3d711 100644
--- a/src/backend/access/spgist/spginsert.c
+++ b/src/backend/access/spgist/spginsert.c
@@ -207,6 +207,7 @@ bool
spginsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo)
{
SpGistState spgstate;
diff --git a/src/backend/access/table/tableam.c b/src/backend/access/table/tableam.c
index e19bdd246a..35975efbc1 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -356,7 +356,7 @@ simple_table_tuple_update(Relation rel, ItemPointer otid,
GetCurrentCommandId(true),
snapshot, InvalidSnapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode, update_indexes);
+ &tmfd, &lockmode, update_indexes, NULL);
switch (result)
{
diff --git a/src/backend/catalog/indexing.c b/src/backend/catalog/indexing.c
index 538f6a06b8..3e577dd183 100644
--- a/src/backend/catalog/indexing.c
+++ b/src/backend/catalog/indexing.c
@@ -162,6 +162,7 @@ CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
heapRelation,
index->rd_index->indisunique ?
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
+ false,
indexInfo);
}
diff --git a/src/backend/commands/constraint.c b/src/backend/commands/constraint.c
index fc19307bf2..79bd12b7de 100644
--- a/src/backend/commands/constraint.c
+++ b/src/backend/commands/constraint.c
@@ -175,7 +175,7 @@ unique_key_recheck(PG_FUNCTION_ARGS)
*/
index_insert(indexRel, values, isnull, &checktid,
trigdata->tg_relation, UNIQUE_CHECK_EXISTING,
- indexInfo);
+ false, indexInfo);
}
else
{
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 115860a9d4..514d8f0cce 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -2523,7 +2523,7 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
recheckIndexes =
ExecInsertIndexTuples(resultRelInfo,
buffer->slots[i], estate, false, NULL,
- NIL);
+ NIL, NULL);
ExecARInsertTriggers(estate, resultRelInfo,
slots[i], recheckIndexes,
cstate->transition_capture);
@@ -3268,7 +3268,8 @@ CopyFrom(CopyState cstate)
estate,
false,
NULL,
- NIL);
+ NIL,
+ NULL);
}
/* AFTER ROW INSERT Triggers */
diff --git a/src/backend/executor/execIndexing.c b/src/backend/executor/execIndexing.c
index c6b5bcba7b..9a05c04de8 100644
--- a/src/backend/executor/execIndexing.c
+++ b/src/backend/executor/execIndexing.c
@@ -275,7 +275,8 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
EState *estate,
bool noDupErr,
bool *specConflict,
- List *arbiterIndexes)
+ List *arbiterIndexes,
+ Bitmapset *modified_attrs_hint)
{
ItemPointer tupleid = &slot->tts_tid;
List *result = NIL;
@@ -287,6 +288,7 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
ExprContext *econtext;
Datum values[INDEX_MAX_KEYS];
bool isnull[INDEX_MAX_KEYS];
+ bool indexunchanged;
Assert(ItemPointerIsValid(tupleid));
@@ -389,6 +391,44 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
else
checkUnique = UNIQUE_CHECK_PARTIAL;
+ /*
+ * We may have to hint to index AM that this is a logically unchanged
+ * index tuple. This happens when we're an UPDATE inserting a
+ * duplicate tuple just to represent the successor version (though
+ * only for the subset of indexes where that's actually true).
+ */
+ if (!modified_attrs_hint)
+ indexunchanged = false; /* Probably from an INSERT */
+ else
+ {
+ indexunchanged = true; /* Assume no logical changes for now */
+
+ for (int attr = 0; attr < indexInfo->ii_NumIndexAttrs; attr++)
+ {
+ int keycol = indexInfo->ii_IndexAttrNumbers[attr];
+
+ /*
+ * XXX: With expression indexes we always ignore logical
+ * changes affecting index (i.e. we don't bother noticing
+ * changes affected only indexed expressions, passing down
+ * "indexunchanged = true" hint in more cases as a result).
+ *
+ * It would make more sense if we made the opposite assumption
+ * (though we probably shouldn't make any assumptions at all).
+ */
+ if (keycol <= 0)
+ continue;
+
+ if (bms_is_member(keycol - FirstLowInvalidHeapAttributeNumber,
+ modified_attrs_hint))
+ {
+ /* Changed column -- don't hint for this index */
+ indexunchanged = false;
+ break;
+ }
+ }
+ }
+
satisfiesConstraint =
index_insert(indexRelation, /* index relation */
values, /* array of index Datums */
@@ -396,6 +436,7 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
tupleid, /* tid of heap tuple */
heapRelation, /* heap relation */
checkUnique, /* type of uniqueness check to do */
+ indexunchanged, /* UPDATE without logical change? */
indexInfo); /* index AM may need this */
/*
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index 01d26881e7..e97d05b448 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -445,7 +445,7 @@ ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false, NULL,
- NIL);
+ NIL, NULL);
/* AFTER ROW INSERT Triggers */
ExecARInsertTriggers(estate, resultRelInfo, slot,
@@ -513,7 +513,7 @@ ExecSimpleRelationUpdate(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false, NULL,
- NIL);
+ NIL, NULL);
/* AFTER ROW UPDATE Triggers */
ExecARUpdateTriggers(estate, resultRelInfo,
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 29e07b7228..d76e371595 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -601,7 +601,7 @@ ExecInsert(ModifyTableState *mtstate,
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, true,
&specConflict,
- arbiterIndexes);
+ arbiterIndexes, NULL);
/* adjust the tuple's state accordingly */
table_tuple_complete_speculative(resultRelationDesc, slot,
@@ -640,7 +640,7 @@ ExecInsert(ModifyTableState *mtstate,
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false,
- NULL, NIL);
+ NULL, NIL, NULL);
}
}
@@ -1219,6 +1219,7 @@ ExecUpdate(ModifyTableState *mtstate,
TM_Result result;
TM_FailureData tmfd;
List *recheckIndexes = NIL;
+ Bitmapset *modified_attrs_hint = NULL;
/*
* abort the operation if not running transactions
@@ -1382,7 +1383,8 @@ lreplace:;
estate->es_snapshot,
estate->es_crosscheck_snapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode, &update_indexes);
+ &tmfd, &lockmode, &update_indexes,
+ &modified_attrs_hint);
switch (result)
{
@@ -1513,9 +1515,13 @@ lreplace:;
/* insert index entries for tuple if necessary */
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
+ {
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false,
- NULL, NIL);
+ NULL, NIL,
+ modified_attrs_hint);
+ bms_free(modified_attrs_hint);
+ }
}
if (canSetTag)
diff --git a/doc/src/sgml/indexam.sgml b/doc/src/sgml/indexam.sgml
index 80473e0f1a..5f7c9a1d54 100644
--- a/doc/src/sgml/indexam.sgml
+++ b/doc/src/sgml/indexam.sgml
@@ -280,6 +280,7 @@ aminsert (Relation indexRelation,
ItemPointer heap_tid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo);
</programlisting>
Insert a new tuple into an existing index. The <literal>values</literal> and
@@ -295,6 +296,18 @@ aminsert (Relation indexRelation,
look into the heap to verify tuple liveness).
</para>
+ <para>
+ The <literal>indexunchanged</literal> boolean value gives a hint
+ about the nature of the tuple to be indexed. When it is true,
+ the tuple is a duplicate of some existing tuple in the index. The
+ new tuple is a logically unchanged successor MVCC tuple version. This
+ happens when an <command>UPDATE</command> takes place that does not
+ modify any columns covered by the index, but nevertheless requires a
+ new version in the index. The index AM may use this hint to decide
+ to apply bottom-up index deletion in parts of the index where many
+ versions of the same logical row accumulate.
+ </para>
+
<para>
The function's Boolean result value is significant only when
<literal>checkUnique</literal> is <literal>UNIQUE_CHECK_PARTIAL</literal>.
--
2.25.1
[application/octet-stream] v7-0003-Teach-nbtree-to-use-bottom-up-index-deletion.patch (67.5K, ../../CAH2-WzmP5AymEfT_n3wAdvW8D7DduapHPqRzds5kv7VjnXsx6Q@mail.gmail.com/4-v7-0003-Teach-nbtree-to-use-bottom-up-index-deletion.patch)
download | inline diff:
From a586b9f1ba41b9b7f2c9bfa713531a2e0d9f5953 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Sat, 7 Nov 2020 14:07:14 -0800
Subject: [PATCH v7 3/4] Teach nbtree to use bottom-up index deletion.
Teach nbtree to eagerly delete duplicate of tuples representing old
versions in the event of a localized flood of version churn. This
situation is detected using heuristics, including the recently added
"index is logically unchanged by an UPDATE" executor hint.
This commit alone changes very little about how nbtree behaves. We
still lack tableam-side support. An upcoming commit that adds support
for bottom-up index deletion to heapam will follow, completing the
picture.
The immediate goal of bottom-up index deletion in nbtree is to avoid
"unnecessary" page splits caused entirely by duplicates needed only for
MVCC/versioning purposes. It naturally has an even more useful effect,
though: it acts as a backstop against accumulating an excessive number
of index tuple versions for any given _logical row_. Note that the
relationship between this localized condition and the proportion of
garbage tuples in the entire index is very loose, and can be very
volatile. Bottom-up index deletion complements what we might now call
"top-down index deletion": index vacuuming performed by VACUUM. It
responds to the immediate local needs of queries, while leaving it up to
autovacuum to perform infrequent clean sweeps of the index.
Bottom-up index deletion is very effective despite not changing anything
about the fundamental invariants for Postgres index access methods in
general (and despite not changing any invariants for nbtree in
particular). That is, it is still inherently necessary to keep around
multiple versions together on the same leaf page, at least in some cases
(no change there). But nothing forbids us from being proactive in
keeping the number of tuples for any given logical row under control, if
and when that seems to makes sense at the page/local level. In practice
it is seldom strictly necessary to have more than a couple of physical
index tuple versions present for any given logical row.
You can think of bottom-up index deletion as bringing the effectiveness
of garbage collection in nbtree far closer to the true theoretical
limits imposed on it by the core system. In practice nbtree could fall
significantly short of this ideal before now, often in ways that could
not easily be predicted or reasoned about, and often in the absence of
obvious stressors (like very long running transactions that hold open an
MVCC snapshot). This may not have happened in production all that
often, but when it happened it had a significant impact on query
latency, often at the most inconvenient time possible.
Handling of the various strategies that we have to avoid a page split
when it looks like a leaf page is about to overflow (deleting LP_DEAD
items, deduplication, and now bottom-up deletion) is streamlined by this
commit. This has an independently useful consequence: nbtree no longer
relies on the BTP_HAS_GARBAGE page level flag/hint for anything
important. We still set and unset the flag in the same way as before,
but it's no longer treated as a gating condition when considering if we
should check for already-set LP_DEAD bits. This happens at the point
where the page looks like it might have to be split anyway, so simply
checking the LP_DEAD bits in passing is practically free. This avoids
missing LP_DEAD bits just because the page-level hint is unset, which is
probably reasonably common (e.g. it happens when VACUUM unsets the
page-level flag without actually removing index tuples whose LP_DEAD-bit
was set recently, after the VACUUM operation began but before it reached
the leaf page in question).
(We don't completely remove the BTP_HAS_GARBAGE flag because we still
rely on it as a gating condition with pg_upgrade'd indexes from before
B-tree version 4/PostgreSQL 12. That makes sense because we sometimes
have to make a choice among pages full of duplicates when inserting a
tuple with pre version 4 indexes. It probably still pays to avoid
accessing the line pointer array of a page there, since it won't yet be
clear whether we'll insert on to the page in question at all, let alone
split it as a result.)
Bump XLOG_PAGE_MAGIC because xl_btree_delete changed.
No bump in BTREE_VERSION, since the on-disk representation of nbtree
indexes has not been changed. Indexes built on PostgreSQL 12 or
PostgreSQL 13 will be able to use the optimization without a REINDEX
follow an upgrade using pg_upgrade. Users upgrading from earlier
PostgreSQL versions using pg_upgrade will need to REINDEX in order to
use the optimization, however.
Author: Peter Geoghegan <[email protected]>
Reviewed-By: Victor Yegorov <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wzm+maE3apHB8NOtmM=p-DO65j2V5GzAWCOEEuy3JZgb2g@mail.gmail.com
---
src/include/access/nbtree.h | 15 +-
src/include/access/nbtxlog.h | 9 +-
src/backend/access/nbtree/README | 73 ++-
src/backend/access/nbtree/nbtdedup.c | 629 +++++++++++++++++++++++---
src/backend/access/nbtree/nbtinsert.c | 209 ++++++---
src/backend/access/nbtree/nbtpage.c | 171 +++++--
src/backend/access/nbtree/nbtree.c | 2 +-
src/backend/access/nbtree/nbtutils.c | 3 +-
src/backend/access/nbtree/nbtxlog.c | 54 ++-
9 files changed, 997 insertions(+), 168 deletions(-)
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index f002e5ff17..f8faae525a 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -75,7 +75,7 @@ typedef BTPageOpaqueData *BTPageOpaque;
#define BTP_META (1 << 3) /* meta-page */
#define BTP_HALF_DEAD (1 << 4) /* empty, but still in tree */
#define BTP_SPLIT_END (1 << 5) /* rightmost page of split group */
-#define BTP_HAS_GARBAGE (1 << 6) /* page has LP_DEAD tuples */
+#define BTP_HAS_GARBAGE (1 << 6) /* page has LP_DEAD tuples (deprecated) */
#define BTP_INCOMPLETE_SPLIT (1 << 7) /* right sibling's downlink is missing */
/*
@@ -1028,9 +1028,11 @@ extern void _bt_parallel_advance_array_keys(IndexScanDesc scan);
/*
* prototypes for functions in nbtdedup.c
*/
-extern void _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
- IndexTuple newitem, Size newitemsz,
- bool checkingunique);
+extern void _bt_dedup_pass(Relation rel, Buffer buf, Relation heapRel,
+ IndexTuple newitem, Size newitemsz,
+ bool checkingunique);
+extern bool _bt_bottomup_pass(Relation rel, Buffer buf, Relation heapRel,
+ Size newitemsz, bool checkingunique);
extern void _bt_dedup_start_pending(BTDedupState state, IndexTuple base,
OffsetNumber baseoff);
extern bool _bt_dedup_save_htid(BTDedupState state, IndexTuple itup);
@@ -1045,7 +1047,8 @@ extern IndexTuple _bt_swap_posting(IndexTuple newitem, IndexTuple oposting,
* prototypes for functions in nbtinsert.c
*/
extern bool _bt_doinsert(Relation rel, IndexTuple itup,
- IndexUniqueCheck checkUnique, Relation heapRel);
+ IndexUniqueCheck checkUnique, Relation heapRel,
+ bool indexunchanged);
extern void _bt_finish_split(Relation rel, Buffer lbuf, BTStack stack);
extern Buffer _bt_getstackbuf(Relation rel, BTStack stack, BlockNumber child);
@@ -1084,7 +1087,9 @@ extern void _bt_delitems_vacuum(Relation rel, Buffer buf,
OffsetNumber *deletable, int ndeletable,
BTVacuumPosting *updatable, int nupdatable);
extern void _bt_delitems_delete(Relation rel, Buffer buf,
+ bool bottomup, TransactionId bottomupXid,
OffsetNumber *deletable, int ndeletable,
+ BTVacuumPosting *updatable, int nupdatable,
Relation heapRel);
extern uint32 _bt_pagedel(Relation rel, Buffer leafbuf,
TransactionId *oldestBtpoXact);
diff --git a/src/include/access/nbtxlog.h b/src/include/access/nbtxlog.h
index 5c014bdc66..4006872d7a 100644
--- a/src/include/access/nbtxlog.h
+++ b/src/include/access/nbtxlog.h
@@ -187,12 +187,15 @@ typedef struct xl_btree_dedup
typedef struct xl_btree_delete
{
TransactionId latestRemovedXid;
- uint32 ndeleted;
+ uint16 ndeleted;
+ uint16 nupdated;
/* DELETED TARGET OFFSET NUMBERS FOLLOW */
+ /* UPDATED TARGET OFFSET NUMBERS FOLLOW */
+ /* UPDATED TUPLES METADATA ARRAY FOLLOWS */
} xl_btree_delete;
-#define SizeOfBtreeDelete (offsetof(xl_btree_delete, ndeleted) + sizeof(uint32))
+#define SizeOfBtreeDelete (offsetof(xl_btree_delete, nupdated) + sizeof(uint16))
/*
* This is what we need to know about page reuse within btree. This record
@@ -213,7 +216,7 @@ typedef struct xl_btree_reuse_page
/*
* This is what we need to know about which TIDs to remove from an individual
* posting list tuple during vacuuming. An array of these may appear at the
- * end of xl_btree_vacuum records.
+ * end of xl_btree_vacuum and xl_btree_delete records.
*/
typedef struct xl_btree_update
{
diff --git a/src/backend/access/nbtree/README b/src/backend/access/nbtree/README
index 27f555177e..0ce27c09d3 100644
--- a/src/backend/access/nbtree/README
+++ b/src/backend/access/nbtree/README
@@ -439,12 +439,14 @@ from the index immediately; since index scans only stop "between" pages,
no scan can lose its place from such a deletion. We separate the steps
because we allow LP_DEAD to be set with only a share lock (it's exactly
like a hint bit for a heap tuple), but physically removing tuples requires
-exclusive lock. In the current code we try to remove LP_DEAD tuples when
-we are otherwise faced with having to split a page to do an insertion (and
-hence have exclusive lock on it already). Deduplication can also prevent
-a page split, but removing LP_DEAD tuples is the preferred approach.
-(Note that posting list tuples can only have their LP_DEAD bit set when
-every table TID within the posting list is known dead.)
+exclusive lock. We try to remove LP_DEAD tuples when we are otherwise
+faced with having to split a page to do an insertion (and hence have
+exclusive lock on it already). Deduplication and bottom-up index deletion
+can also prevent a page split, but removing LP_DEAD tuples is always the
+preferred approach. (Note that posting list tuples can only have their
+LP_DEAD bit set when every table TID within the posting list is known
+dead. This isn't much of a problem because bottom-up deletion supports
+granular deletion of TIDs from posting lists.)
This leaves the index in a state where it has no entry for a dead tuple
that still exists in the heap. This is not a problem for the current
@@ -767,9 +769,10 @@ into a single physical tuple with a posting list (a simple array of heap
TIDs with the standard item pointer format). Deduplication is always
applied lazily, at the point where it would otherwise be necessary to
perform a page split. It occurs only when LP_DEAD items have been
-removed, as our last line of defense against splitting a leaf page. We
-can set the LP_DEAD bit with posting list tuples, though only when all
-TIDs are known dead.
+removed, as our last line of defense against splitting a leaf page
+(bottom-up index vacuuming may be attempted first, as our second last line
+of defense). We can set the LP_DEAD bit with posting list tuples, though
+only when all TIDs are known dead.
Our lazy approach to deduplication allows the page space accounting used
during page splits to have absolutely minimal special case logic for
@@ -826,6 +829,16 @@ delay a split that is probably inevitable anyway. This allows us to avoid
the overhead of attempting to deduplicate with unique indexes that always
have few or no duplicates.
+Note: Avoiding "unnecessary" page splits driven by version churn is also
+the goal of bottom-up index deletion, which was added to PostgreSQL 14.
+Bottom-up index deletion is now the preferred way to deal with this
+problem (with all kinds of indexes, though especially with unique
+indexes). Still, deduplication can sometimes augment bottom-up index
+deletion. When deletion cannot free tuples (due to an old snapshot
+holding up cleanup), falling back on deduplication provides additional
+capacity. Delaying the page split by deduplicating can allow a future
+bottom-up deletion pass of the same page to succeed.
+
Posting list splits
-------------------
@@ -880,6 +893,48 @@ that need a page split anyway. Besides, supporting variable "split points"
while splitting posting lists won't actually improve overall space
utilization.
+Bottom-up index deletion
+------------------------
+
+We sometimes delete whatever duplicates happen to be present on the page
+before moving on to deduplication. This only happens when we receive a
+hint that optimizations like heapam's HOT have not worked out for the
+index -- the incoming tuple must be a logically unchanged duplicate which
+is needed for MVCC purposes. (Actually it also happens with unique
+indexes in some extra cases that don't get this hint.)
+
+There are certain ways in which this mechanism is similar to on-the-fly
+deletion of index tuples (that will already have failed to prevent a page
+split by the time bottom-up deletion is attempted). For example, the same
+WAL records are used. There are also significant differences. Index
+tuples that get deleted by this mechanism won't have already been marked
+LP_DEAD in passing by queries. Rather, we figure out whether or not
+they're deletable in principle at the last point before splitting a page
+by accessing tableam blocks to get visibility information. We us
+heuristics to access as few tableam blocks as possible while still
+expecting to find a reasonably large number of tuples that are safe to
+delete each time. We expect to perform regular bottom-up deletion
+operations against pages that are at constant risk of unnecessary page
+splits caused only by version churn. When the mechanism works well we'll
+constantly be on the verge of having lots of version churn driven page
+splits, but never actually have any.
+
+Bottom-up index deletion can be thought of as a backstop mechanism against
+unnecessary version-driven page splits. When we have a reasonable
+suspicion that a would-be page split may not actually be necessary, we
+fight back. There is very little to lose and much to gain by spending a
+few cycles to become reasonably sure that it is in fact necessary -- page
+splits are very expensive and practically irreversible. This approach
+works well in a large variety of workloads because we give up before
+spending very many cycles on trying, and because our heuristics are good
+enough to spot unnecessary page splits fairly reliably in practice.
+Unnecessary page splits occur due to pathological amounts of version
+churn. In practice this pathological condition can be detected before too
+long using simple heuristics. We don't have to understand the universe of
+possible workloads; we only have to understand the nature of the
+underlying pathology. We're helped out by additional heuristics within
+tableams such as heapam.
+
Notes About Data Representation
-------------------------------
diff --git a/src/backend/access/nbtree/nbtdedup.c b/src/backend/access/nbtree/nbtdedup.c
index f6be865b17..e389f8c6b6 100644
--- a/src/backend/access/nbtree/nbtdedup.c
+++ b/src/backend/access/nbtree/nbtdedup.c
@@ -16,21 +16,23 @@
#include "access/nbtree.h"
#include "access/nbtxlog.h"
+#include "access/tableam.h"
#include "miscadmin.h"
#include "utils/rel.h"
+static int _bt_bottomup_finish_pending(Page page, TM_IndexDeleteOp *vstate,
+ BTDedupState state);
static bool _bt_do_singleval(Relation rel, Page page, BTDedupState state,
OffsetNumber minoff, IndexTuple newitem);
static void _bt_singleval_fillfactor(Page page, BTDedupState state,
Size newitemsz);
+static int _bt_indexdelete_cmp(const void *a, const void *b, void *arg);
#ifdef USE_ASSERT_CHECKING
static bool _bt_posting_valid(IndexTuple posting);
#endif
/*
- * Deduplicate items on a leaf page. The page will have to be split by caller
- * if we cannot successfully free at least newitemsz (we also need space for
- * newitem's line pointer, which isn't included in caller's newitemsz).
+ * Perform a deduplication pass.
*
* The general approach taken here is to perform as much deduplication as
* possible to free as much space as possible. Note, however, that "single
@@ -43,76 +45,32 @@ static bool _bt_posting_valid(IndexTuple posting);
* handle those if and when the anticipated right half page gets its own
* deduplication pass, following further inserts of duplicates.)
*
- * This function should be called during insertion, when the page doesn't have
- * enough space to fit an incoming newitem. If the BTP_HAS_GARBAGE page flag
- * was set, caller should have removed any LP_DEAD items by calling
- * _bt_vacuum_one_page() before calling here. We may still have to kill
- * LP_DEAD items here when the page's BTP_HAS_GARBAGE hint is falsely unset,
- * but that should be rare. Also, _bt_vacuum_one_page() won't unset the
- * BTP_HAS_GARBAGE flag when it finds no LP_DEAD items, so a successful
- * deduplication pass will always clear it, just to keep things tidy.
+ * The page will have to be split if we cannot successfully free at least
+ * newitemsz (we also need space for newitem's line pointer, which isn't
+ * included in caller's newitemsz).
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
*/
void
-_bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
- IndexTuple newitem, Size newitemsz, bool checkingunique)
+_bt_dedup_pass(Relation rel, Buffer buf, Relation heapRel, IndexTuple newitem,
+ Size newitemsz, bool checkingunique)
{
OffsetNumber offnum,
minoff,
maxoff;
Page page = BufferGetPage(buf);
- BTPageOpaque opaque;
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
Page newpage;
- OffsetNumber deletable[MaxIndexTuplesPerPage];
BTDedupState state;
- int ndeletable = 0;
Size pagesaving = 0;
bool singlevalstrat = false;
int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
- /*
- * We can't assume that there are no LP_DEAD items. For one thing, VACUUM
- * will clear the BTP_HAS_GARBAGE hint without reliably removing items
- * that are marked LP_DEAD. We don't want to unnecessarily unset LP_DEAD
- * bits when deduplicating items. Allowing it would be correct, though
- * wasteful.
- */
- opaque = (BTPageOpaque) PageGetSpecialPointer(page);
- minoff = P_FIRSTDATAKEY(opaque);
- maxoff = PageGetMaxOffsetNumber(page);
- for (offnum = minoff;
- offnum <= maxoff;
- offnum = OffsetNumberNext(offnum))
- {
- ItemId itemid = PageGetItemId(page, offnum);
-
- if (ItemIdIsDead(itemid))
- deletable[ndeletable++] = offnum;
- }
-
- if (ndeletable > 0)
- {
- _bt_delitems_delete(rel, buf, deletable, ndeletable, heapRel);
-
- /*
- * Return when a split will be avoided. This is equivalent to
- * avoiding a split using the usual _bt_vacuum_one_page() path.
- */
- if (PageGetFreeSpace(page) >= newitemsz)
- return;
-
- /*
- * Reconsider number of items on page, in case _bt_delitems_delete()
- * managed to delete an item or two
- */
- minoff = P_FIRSTDATAKEY(opaque);
- maxoff = PageGetMaxOffsetNumber(page);
- }
-
/* Passed-in newitemsz is MAXALIGNED but does not include line pointer */
newitemsz += sizeof(ItemIdData);
/*
- * By here, it's clear that deduplication will definitely be attempted.
* Initialize deduplication state.
*
* It would be possible for maxpostingsize (limit on posting list tuple
@@ -138,6 +96,9 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
/* nintervals should be initialized to zero */
state->nintervals = 0;
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
+
/* Determine if "single value" strategy should be used */
if (!checkingunique)
singlevalstrat = _bt_do_singleval(rel, page, state, minoff, newitem);
@@ -259,10 +220,9 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
/*
* By here, it's clear that deduplication will definitely go ahead.
*
- * Clear the BTP_HAS_GARBAGE page flag in the unlikely event that it is
- * still falsely set, just to keep things tidy. (We can't rely on
- * _bt_vacuum_one_page() having done this already, and we can't rely on a
- * page split or VACUUM getting to it in the near future.)
+ * Clear the BTP_HAS_GARBAGE page flag. The index must be a heapkeyspace
+ * index, and as such we'll never pay attention to BTP_HAS_GARBAGE anyway.
+ * But keep things tidy.
*/
if (P_HAS_GARBAGE(opaque))
{
@@ -311,6 +271,343 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
pfree(state);
}
+/*
+ * Perform bottom-up index deletion pass.
+ *
+ * See if duplicate index tuples are eligible to be deleted by accessing
+ * visibility information from the tableam. Give up if we have to access more
+ * than a few tableam blocks. Caller tries to avoid "unnecessary" page splits
+ * (splits driven only by version churn) by calling here when it looks like
+ * that's about to happen. It's normal for there to be a lot of calls here
+ * for pages that are constantly at risk of an unnecessary split.
+ *
+ * Each failure to delete a duplicate/promising tuple here is a kind of
+ * learning experience. It results in caller falling back on splitting the
+ * page (or on a deduplication pass), discouraging future calls back here for
+ * the same key space range covered by a failed page (or at least discouraging
+ * processing the original duplicates in case where caller falls back on a
+ * successful deduplication pass). We converge on the most effective strategy
+ * for each page in the index over time, sometimes through trial and error.
+ *
+ * The page will have to be split if we cannot successfully free at least
+ * newitemsz (we also need space for newitem's line pointer, which isn't
+ * included in caller's newitemsz).
+ *
+ * Returns true on success, in which case caller can assume page split will be
+ * avoided for a reasonable amount of time. Returns false when caller should
+ * deduplicate the page (if possible at all).
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
+ *
+ * Note: occasionally a true return value does not indicate success -- it just
+ * indicates that caller should not go on to perform a deduplication pass.
+ * Caller is not expected to care about the difference.
+ */
+bool
+_bt_bottomup_pass(Relation rel, Buffer buf, Relation heapRel, Size newitemsz,
+ bool checkingunique)
+{
+ OffsetNumber offnum,
+ minoff,
+ maxoff,
+ postingidxoffnum;
+ Page page = BufferGetPage(buf);
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+ BTDedupState state;
+ TM_IndexDeleteOp vstate;
+ int nhtidspage = 0;
+ int ndistinctvalspage = 0;
+ TransactionId latestRemovedXid;
+ int ndeletable,
+ nupdatable;
+ OffsetNumber deletable[MaxIndexTuplesPerPage];
+ BTVacuumPosting updatable[MaxIndexTuplesPerPage];
+ int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+
+ /* Passed-in newitemsz is MAXALIGNED but does not include line pointer */
+ newitemsz += sizeof(ItemIdData);
+
+ /* Initialize deduplication state */
+ state = (BTDedupState) palloc(sizeof(BTDedupStateData));
+ state->deduplicate = true;
+ state->nmaxitems = 0;
+ state->maxpostingsize = BLCKSZ; /* "posting list size" not a concern */
+ state->base = NULL;
+ state->baseoff = InvalidOffsetNumber;
+ state->basetupsize = 0;
+ state->htids = palloc(state->maxpostingsize);
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+ state->nintervals = 0;
+
+ /*
+ * Initialize tableam state that describes bottom-up index deletion
+ * operation.
+ *
+ * We will ask tableam to free 1/16 of BLCKSZ. We don't usually expect to
+ * have to free much space each call here in order to avoid page splits.
+ * We don't want to be too aggressive since in general the tableam will
+ * have to access more table blocks when we ask for more free space. In
+ * general we try to be conservative about what we ask for (though not too
+ * conservative), while leaving it up to the tableam to ramp up the number
+ * of tableam blocks accessed when conditions in the table structure
+ * happen to favor it.
+ *
+ * We expect to end up back here again and again for any leaf page that is
+ * more or less constantly at risk of unnecessary page splits -- in fact
+ * that's what happens when bottom-up deletion really helps. We must
+ * avoid thrashing when this becomes very frequent at the level of an
+ * individual page. Our free space target helps with that. It balances
+ * the costs and benefits over time and across related bottom-up deletion
+ * passes.
+ */
+ vstate.ndeltids = 0;
+ vstate.deltids = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexDelete));
+ vstate.tidstatuses = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexStatus));
+ vstate.targetfreespace = Max(BLCKSZ / 16, newitemsz);
+
+ /* Now remember details of the page in the state we'll pass to tableam */
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
+ for (offnum = minoff;
+ offnum <= maxoff;
+ offnum = OffsetNumberNext(offnum))
+ {
+ ItemId itemid = PageGetItemId(page, offnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+
+ Assert(!ItemIdIsDead(itemid));
+
+ if (offnum == minoff)
+ {
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ else if (_bt_keep_natts_fast(rel, state->base, itup) > nkeyatts &&
+ _bt_dedup_save_htid(state, itup))
+ {
+ /* Tuple is equal to base tuple of pending interval */
+ }
+ else
+ {
+ /* Handle interval -- save TIDs in deltids now */
+ nhtidspage += _bt_bottomup_finish_pending(page, &vstate, state);
+ ndistinctvalspage++;
+
+ /* itup starts new pending interval */
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ }
+ /* Handle final interval -- save TIDs in deltids now */
+ nhtidspage += _bt_bottomup_finish_pending(page, &vstate, state);
+ ndistinctvalspage++;
+
+ if (state->nintervals == 0)
+ {
+ /*
+ * No duplicates on existing page. Apparently the incoming item that
+ * won't fit on the page just so happens to be the first duplicate
+ * version tuple that belongs on the page. This is only barely
+ * possible.
+ *
+ * Tell caller we were successful here to prevent a deduplication
+ * pass, even though technically that's a lie. This is a simple way
+ * of avoiding wasting more cycles on the page. The page will have to
+ * be split.
+ */
+ pfree(state->htids);
+ pfree(state);
+ pfree(vstate.deltids);
+ pfree(vstate.tidstatuses);
+
+ return true;
+ }
+
+ /* Done with dedup state */
+ pfree(state->htids);
+ pfree(state);
+
+ /* Now use tableam interface to determine which tuples to delete */
+ latestRemovedXid = table_index_delete_check(heapRel, &vstate);
+
+ if (vstate.ndeltids == 0)
+ {
+ /* The tableam has nothing for us */
+ pfree(vstate.deltids);
+ pfree(vstate.tidstatuses);
+ return false;
+ }
+
+ /*
+ * By here we know that we have at least one deletable index tuple (or
+ * TID) in final deltids array. All that remains is to construct a
+ * leaf-page-wise description of what _bt_delitems_delete() needs to do to
+ * physically delete index tuples from the page.
+ *
+ * Sort deltids array (which is typically much smaller now) in the order
+ * expected by loop: the original leaf-page-wise order (the order the
+ * array was in before the tableam sorted it for its own reasons).
+ */
+ qsort_arg(vstate.deltids, vstate.ndeltids, sizeof(TM_IndexDelete),
+ _bt_indexdelete_cmp, vstate.tidstatuses);
+ postingidxoffnum = InvalidOffsetNumber;
+ ndeletable = 0;
+ nupdatable = 0;
+ for (int i = 0; i < vstate.ndeltids; i++)
+ {
+ TM_IndexStatus *status = vstate.tidstatuses + vstate.deltids[i].id;
+ OffsetNumber idxoffnum = status->idxoffnum;
+ ItemId itemid = PageGetItemId(page, idxoffnum);
+ IndexTuple itup;
+ int nitem;
+ BTVacuumPosting vacposting = NULL;
+
+ itup = (IndexTuple) PageGetItem(page, itemid);
+
+ if (idxoffnum == postingidxoffnum)
+ {
+ /*
+ * This deltid entry is a TID from a posting list tuple that has
+ * already been completely processed (since we do whole posting
+ * lists all at once, when the first deltid for the posting list
+ * tuple is encountered -- see below).
+ */
+ Assert(BTreeTupleIsPosting(itup));
+ continue;
+ }
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ /*
+ * For a plain non-pivot tuple, simply being found marked dead
+ * means we can kill
+ */
+ Assert(ItemPointerEquals(&itup->t_tid, &vstate.deltids[i].tid));
+ if (status->deleteitup)
+ deletable[ndeletable++] = idxoffnum;
+ continue;
+ }
+
+ /*
+ * For a posting list tuple we have to work a bit harder, since we may
+ * either delete or update (i.e. update to delete a subset of its
+ * TIDs).
+ *
+ * We'll be skipping over future TIDs from this same posting list at
+ * the top of the outer loop, since we want to process all TIDs in
+ * tuple together once in inner loop. Remember to do that now.
+ */
+ postingidxoffnum = idxoffnum;
+ nitem = BTreeTupleGetNPosting(itup);
+ for (int j = 0; j < nitem; j++)
+ {
+ ItemPointer htid;
+ int cmp;
+ int tidi = i;
+
+ htid = BTreeTupleGetPostingN(itup, j);
+
+ for (;;)
+ {
+ cmp = ItemPointerCompare(htid, &vstate.deltids[tidi].tid);
+ if (cmp == 0)
+ break;
+ tidi++;
+ if (tidi >= vstate.ndeltids ||
+ (vstate.tidstatuses + vstate.deltids[tidi].id)->idxoffnum != idxoffnum)
+ {
+ /*
+ * If this later tidi deltid doesn't even relate to same
+ * posting list index tuple from page, we're done with
+ * this TID from itup (posting list tuple).
+ */
+ cmp = -1;
+ break;
+ }
+ }
+
+ /* Final check for exact TID match */
+ if (cmp != 0)
+ continue;
+
+ /* Only interested in dead TIDs */
+ if (!(vstate.tidstatuses + vstate.deltids[tidi].id)->deleteitup)
+ continue;
+
+ if (vacposting == NULL)
+ {
+ /*
+ * First dead table TID encountered.
+ *
+ * Start maintaining metadata describing how to update
+ * existing posting list tuple.
+ */
+ vacposting = palloc(offsetof(BTVacuumPostingData, deletetids) +
+ nitem * sizeof(uint16));
+ vacposting->itup = itup;
+ vacposting->updatedoffset = idxoffnum;
+ vacposting->ndeletedtids = 0;
+ }
+ vacposting->deletetids[vacposting->ndeletedtids++] = j;
+ }
+
+ /* Decide what to do with TIDs in posting list tuple */
+
+ if (vacposting == NULL)
+ {
+ /* No TIDs to delete in posting list tuple -- do nothing */
+ }
+ else if (vacposting->ndeletedtids == nitem)
+ {
+ /* Straight delete -- won't need update state */
+ deletable[ndeletable++] = idxoffnum;
+ pfree(vacposting);
+ }
+ else
+ {
+ /* Going to delete some but not all TIDs in posting list */
+ Assert(vacposting->ndeletedtids > 0 &&
+ vacposting->ndeletedtids < nitem);
+ updatable[nupdatable++] = vacposting;
+ }
+ }
+
+ /* Done with deltids state */
+ pfree(vstate.deltids);
+ pfree(vstate.tidstatuses);
+
+ /*
+ * Go through with deleting TIDs that we found are safe to delete.
+ *
+ * No MarkBufferDirtyHint() call is needed here, since we don't ever mark
+ * line pointers LP_DEAD. Any and all modifications to the page are made
+ * in the critical section in _bt_delitems_delete().
+ */
+ _bt_delitems_delete(rel, buf, true, latestRemovedXid,
+ deletable, ndeletable, updatable, nupdatable,
+ heapRel);
+
+ /* be tidy */
+ for (int i = 0; i < nupdatable; i++)
+ pfree(updatable[i]);
+
+ /*
+ * If page is low cardinality, we should deduplicate proactively. We do
+ * so even when we managed to delete many TIDs.
+ *
+ * This provides useful back pressure against intense version churn
+ * causing thrashing. We don't want to end up here again for the same
+ * leaf page in the near future.
+ */
+ if (nhtidspage > ndistinctvalspage * 3)
+ return false;
+
+ /* Don't dedup when we won't end up back here any time soon anyway */
+ return PageGetExactFreeSpace(page) >=
+ Max(vstate.targetfreespace / 2, newitemsz);
+}
+
/*
* Create a new pending posting list tuple based on caller's base tuple.
*
@@ -496,6 +793,171 @@ _bt_dedup_finish_pending(Page newpage, BTDedupState state)
return spacesaving;
}
+/*
+ * Finalize interval during bottom-up index deletion.
+ *
+ * Determines which TIDs are to be marked promising based no heuristics.
+ *
+ * Returns number of heap TIDs in pending interval, regardless of whether it
+ * is remembered as an interval. Return value can be used to count the
+ * precise number of TIDs on the page in all cases.
+ */
+static int
+_bt_bottomup_finish_pending(Page page, TM_IndexDeleteOp *vstate,
+ BTDedupState state)
+{
+ bool dupinterval = (state->nitems > 1);
+ int nhtids = state->nhtids;
+
+ Assert(state->nitems > 0);
+ Assert(state->nitems <= state->nhtids);
+ Assert(state->intervals[state->nintervals].baseoff == state->baseoff);
+
+ /*
+ * All TIDs from all tuples are at least recording in state. Tuples are
+ * marked promising when they're duplicates (i.e. when they appear in an
+ * interval with more than one item, as when we expect create a new postng
+ * list tuple in the deduplication case).
+ *
+ * It's easy to see what this means in the plain non-pivot tuple case:
+ * TIDs from duplicate plain tuples are promising. Posting list tuples
+ * are more subtle. We ought to do something with posting list tuples,
+ * though plain tuples tend to be more promising targets. (Plain tuples
+ * are the most likely to be dead/deletable because they suggest version
+ * churn. And they allow us to free more space when we actually succeed).
+ */
+ for (int i = 0; i < state->nitems; i++)
+ {
+ OffsetNumber offnum = state->baseoff + i;
+ ItemId itemid = PageGetItemId(page, offnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+ TM_IndexDelete *cdeltid;
+ TM_IndexStatus *cstatusdeltid;
+
+ cdeltid = &vstate->deltids[vstate->ndeltids];
+ cstatusdeltid = &vstate->tidstatuses[vstate->ndeltids];
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ /* Easy case: A plain non-pivot tuple's TID */
+ cdeltid->tid = itup->t_tid;
+ cdeltid->id = vstate->ndeltids;
+ cstatusdeltid->idxoffnum = offnum;
+ cstatusdeltid->ispromising = dupinterval;
+ cstatusdeltid->deleteitup = false; /* for now */
+ cstatusdeltid->tupsize =
+ ItemIdGetLength(itemid) + sizeof(ItemIdData);
+ vstate->ndeltids++;
+ }
+ else
+ {
+ /*
+ * Harder case: A posting list tuple's TIDs (multiple TIDs).
+ *
+ * Only a single TID from a posting list tuple may be promising,
+ * and only when it appears in a duplicate tuple (just like plain
+ * tuple case). In general there is a good chance that the
+ * posting list tuple relates to multiple logical rows, rather
+ * than multiple versions of just one logical row. (It can only
+ * be the latter case when a previous bottom-up deletion pass
+ * failed, necessitating a deduplication pass, which isn't all
+ * that common.)
+ *
+ * There is a pretty good chance that at least one of the logical
+ * rows from the posting list was updated, and so had a successor
+ * version (about as good a chance as it is in the regular tuple
+ * case, at least). We should at least try to follow the regular
+ * tuple case while making the conservative assumption that there
+ * can only be one affected logical row per posting list tuple. We
+ * do that by picking one TID when it appears to be from the
+ * predominant tableam block in the posting list (if any one
+ * tableam block predominates). The approach we take is to either
+ * choose the first or last TID in the posting list (if any at
+ * all). We go with whichever one is on the same tableam block at
+ * the middle tuple (and only the first TID when both the first
+ * and last TIDs relate to the same tableam block -- we could
+ * easily be too aggressive here).
+ *
+ * If it turns out that there are multiple old versions of a
+ * single logical table row, we still have a pretty good chance of
+ * being able to delete them this way. We don't want to give too
+ * strong a signal to the tableam. But we should always try to
+ * give some useful hints. Even cases with considerable
+ * uncertainty can consistently avoid an unnecessary page split,
+ * in part because the tableam will have tricks of its own for
+ * figuring out where to look in marginal cases.
+ */
+ int nitem = BTreeTupleGetNPosting(itup);
+ bool firstpromise = false;
+ bool lastpromise = false;
+
+ Assert(_bt_posting_valid(itup));
+
+ if (dupinterval)
+ {
+ /* Figure out if there really should be promising TIDs */
+ BlockNumber minblocklist,
+ midblocklist,
+ maxblocklist;
+ ItemPointer mintid,
+ midtid,
+ maxtid;
+
+ mintid = BTreeTupleGetHeapTID(itup);
+ midtid = BTreeTupleGetPostingN(itup, nitem / 2);
+ maxtid = BTreeTupleGetMaxHeapTID(itup);
+ minblocklist = ItemPointerGetBlockNumber(mintid);
+ midblocklist = ItemPointerGetBlockNumber(midtid);
+ maxblocklist = ItemPointerGetBlockNumber(maxtid);
+
+ firstpromise = (minblocklist == midblocklist);
+ lastpromise = (!firstpromise && midblocklist == maxblocklist);
+ }
+
+ /* Assert that at most one TID is promising */
+ Assert(!firstpromise || !lastpromise);
+
+ for (int p = 0; p < nitem; p++)
+ {
+ ItemPointer htid = BTreeTupleGetPostingN(itup, p);
+
+ cdeltid->tid = *htid;
+ cdeltid->id = vstate->ndeltids;
+ cstatusdeltid->idxoffnum = offnum;
+ cstatusdeltid->ispromising = false;
+
+ if ((firstpromise && p == 0) ||
+ (lastpromise && p == nitem - 1))
+ cstatusdeltid->ispromising = true;
+
+ cstatusdeltid->deleteitup = false; /* for now */
+ cstatusdeltid->tupsize = sizeof(ItemPointerData) + 1;
+ vstate->ndeltids++;
+
+ cdeltid++;
+ cstatusdeltid++;
+ }
+ }
+ }
+
+ if (dupinterval)
+ {
+ /*
+ * Maintain interval state for consistency with true deduplication
+ * case
+ */
+ state->intervals[state->nintervals].nitems = state->nitems;
+ state->nintervals++;
+ }
+
+ /* Reset state for next interval */
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+
+ return nhtids;
+}
+
/*
* Determine if page non-pivot tuples (data items) are all duplicates of the
* same value -- if they are, deduplication's "single value" strategy should
@@ -666,8 +1128,8 @@ _bt_form_posting(IndexTuple base, ItemPointer htids, int nhtids)
* Generate a replacement tuple by "updating" a posting list tuple so that it
* no longer has TIDs that need to be deleted.
*
- * Used by VACUUM. Caller's vacposting argument points to the existing
- * posting list tuple to be updated.
+ * Used by both VACUUM and bottom-up index deletion. Caller's vacposting
+ * argument points to the existing posting list tuple to be updated.
*
* On return, caller's vacposting argument will point to final "updated"
* tuple, which will be palloc()'d in caller's memory context.
@@ -809,6 +1271,49 @@ _bt_swap_posting(IndexTuple newitem, IndexTuple oposting, int postingoff)
return nposting;
}
+/*
+ * Comparator used by _bt_bottomup_pass() to restore deltids array back to its
+ * original sort order
+ */
+static int
+_bt_indexdelete_cmp(const void *a, const void *b, void *arg)
+{
+ TM_IndexDelete *indexdelete1 = (TM_IndexDelete *) a;
+ TM_IndexDelete *indexdelete2 = (TM_IndexDelete *) b;
+ TM_IndexStatus *tidstatuses = (TM_IndexStatus *) arg;
+
+ OffsetNumber offset1 = (tidstatuses + indexdelete1->id)->idxoffnum;
+ OffsetNumber offset2 = (tidstatuses + indexdelete2->id)->idxoffnum;
+ ItemPointer tid1 = &indexdelete1->tid;
+ ItemPointer tid2 = &indexdelete2->tid;
+
+ if (offset1 > offset2)
+ return 1;
+ if (offset1 < offset2)
+ return -1;
+
+ /* Must be posting list tuple -- restore TID order */
+ {
+ BlockNumber blk1 = ItemPointerGetBlockNumber(tid1);
+ BlockNumber blk2 = ItemPointerGetBlockNumber(tid2);
+
+ if (blk1 != blk2)
+ return (blk1 < blk2) ? -1 : 1;
+ }
+ {
+ OffsetNumber pos1 = ItemPointerGetOffsetNumber(tid1);
+ OffsetNumber pos2 = ItemPointerGetOffsetNumber(tid2);
+
+ if (pos1 != pos2)
+ return (pos1 < pos2) ? -1 : 1;
+ }
+
+ /* ItemPointer values should never be equal */
+ Assert(false);
+
+ return 0;
+}
+
/*
* Verify posting list invariants for "posting", which must be a posting list
* tuple. Used within assertions.
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index d36f7557c8..b9072b13d4 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -37,6 +37,7 @@ static TransactionId _bt_check_unique(Relation rel, BTInsertState insertstate,
static OffsetNumber _bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool indexunchanged,
BTStack stack,
Relation heapRel);
static void _bt_stepright(Relation rel, BTInsertState insertstate, BTStack stack);
@@ -58,7 +59,10 @@ static void _bt_insert_parent(Relation rel, Buffer buf, Buffer rbuf,
static Buffer _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf);
static inline bool _bt_pgaddtup(Page page, Size itemsize, IndexTuple itup,
OffsetNumber itup_off, bool newfirstdataitem);
-static void _bt_vacuum_one_page(Relation rel, Buffer buffer, Relation heapRel);
+static void _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
+ BTInsertState insertstate,
+ bool lpdeadonly, bool checkingunique,
+ bool uniquedup, bool indexunchanged);
/*
* _bt_doinsert() -- Handle insertion of a single index tuple in the tree.
@@ -80,7 +84,8 @@ static void _bt_vacuum_one_page(Relation rel, Buffer buffer, Relation heapRel);
*/
bool
_bt_doinsert(Relation rel, IndexTuple itup,
- IndexUniqueCheck checkUnique, Relation heapRel)
+ IndexUniqueCheck checkUnique, Relation heapRel,
+ bool indexunchanged)
{
bool is_unique = false;
BTInsertStateData insertstate;
@@ -235,7 +240,7 @@ search:
* checkingunique.
*/
newitemoff = _bt_findinsertloc(rel, &insertstate, checkingunique,
- stack, heapRel);
+ indexunchanged, stack, heapRel);
_bt_insertonpg(rel, itup_key, insertstate.buf, InvalidBuffer, stack,
itup, insertstate.itemsz, newitemoff,
insertstate.postingoff, false);
@@ -663,7 +668,8 @@ _bt_check_unique(Relation rel, BTInsertState insertstate, Relation heapRel,
/*
* The conflicting tuple (or all HOT chains pointed to by
* all posting list TIDs) is dead to everyone, so mark the
- * index entry killed.
+ * index entry killed. (Note that we only rely on the
+ * page-level flag in !heapkeyspace indexes.)
*/
ItemIdMarkDead(curitemid);
opaque->btpo_flags |= BTP_HAS_GARBAGE;
@@ -774,6 +780,12 @@ _bt_check_unique(Relation rel, BTInsertState insertstate, Relation heapRel,
* room for the new tuple, this function moves right, trying to find a
* legal page that does.)
*
+ * If 'indexunchanged' is true, this is for an UPDATE that didn't
+ * logically change the indexed value, but must nevertheless have a new
+ * entry to point to a successor version. This hint from the executor
+ * will influence our behavior when the page might have to be split and
+ * we must consider if it's avoidable.
+ *
* On exit, insertstate buffer contains the chosen insertion page, and
* the offset within that page is returned. If _bt_findinsertloc needed
* to move right, the lock and pin on the original page are released, and
@@ -790,6 +802,7 @@ static OffsetNumber
_bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool indexunchanged,
BTStack stack,
Relation heapRel)
{
@@ -814,7 +827,7 @@ _bt_findinsertloc(Relation rel,
if (itup_key->heapkeyspace)
{
/* Keep track of whether checkingunique duplicate seen */
- bool uniquedup = false;
+ bool uniquedup = indexunchanged;
/*
* If we're inserting into a unique index, we may have to walk right
@@ -871,38 +884,15 @@ _bt_findinsertloc(Relation rel,
}
/*
- * If the target page is full, see if we can obtain enough space by
- * erasing LP_DEAD items. If that fails to free enough space, see if
- * we can avoid a page split by performing a deduplication pass over
- * the page.
- *
- * We only perform a deduplication pass for a checkingunique caller
- * when the incoming item is a duplicate of an existing item on the
- * leaf page. This heuristic avoids wasting cycles -- we only expect
- * to benefit from deduplicating a unique index page when most or all
- * recently added items are duplicates. See nbtree/README.
+ * If the target page is full, see if we can obtain enough space using
+ * one or more strategies (e.g. erasing LP_DEAD items, deduplication).
+ * Page splits are expensive, and should only go ahead when truly
+ * necessary.
*/
if (PageGetFreeSpace(page) < insertstate->itemsz)
- {
- if (P_HAS_GARBAGE(lpageop))
- {
- _bt_vacuum_one_page(rel, insertstate->buf, heapRel);
- insertstate->bounds_valid = false;
-
- /* Might as well assume duplicates (if checkingunique) */
- uniquedup = true;
- }
-
- if (itup_key->allequalimage && BTGetDeduplicateItems(rel) &&
- (!checkingunique || uniquedup) &&
- PageGetFreeSpace(page) < insertstate->itemsz)
- {
- _bt_dedup_one_page(rel, insertstate->buf, heapRel,
- insertstate->itup, insertstate->itemsz,
- checkingunique);
- insertstate->bounds_valid = false;
- }
- }
+ _bt_delete_or_dedup_one_page(rel, heapRel, insertstate, false,
+ checkingunique, uniquedup,
+ indexunchanged);
}
else
{
@@ -942,8 +932,10 @@ _bt_findinsertloc(Relation rel,
*/
if (P_HAS_GARBAGE(lpageop))
{
- _bt_vacuum_one_page(rel, insertstate->buf, heapRel);
- insertstate->bounds_valid = false;
+ /* Erase LP_DEAD items (won't deduplicate) */
+ _bt_delete_or_dedup_one_page(rel, heapRel, insertstate, true,
+ checkingunique, false,
+ indexunchanged);
if (PageGetFreeSpace(page) >= insertstate->itemsz)
break; /* OK, now we have enough space */
@@ -993,14 +985,17 @@ _bt_findinsertloc(Relation rel,
* performing a posting list split, so delete all LP_DEAD items early.
* This is the only case where LP_DEAD deletes happen even though
* there is space for newitem on the page.
+ *
+ * This can only erase LP_DEAD items (it won't deduplicate).
*/
- _bt_vacuum_one_page(rel, insertstate->buf, heapRel);
+ _bt_delete_or_dedup_one_page(rel, heapRel, insertstate, true,
+ checkingunique, false, indexunchanged);
/*
* Do new binary search. New insert location cannot overlap with any
* posting list now.
*/
- insertstate->bounds_valid = false;
+ Assert(!insertstate->bounds_valid);
insertstate->postingoff = 0;
newitemoff = _bt_binsrch_insert(rel, insertstate);
Assert(insertstate->postingoff == 0);
@@ -2623,32 +2618,80 @@ _bt_pgaddtup(Page page,
}
/*
- * _bt_vacuum_one_page - vacuum just one index page.
+ * _bt_delete_or_dedup_one_page - Try to avoid a leaf page split by attempting
+ * a variety of operations.
*
- * Try to remove LP_DEAD items from the given page. The passed buffer
- * must be exclusive-locked, but unlike a real VACUUM, we don't need a
- * super-exclusive "cleanup" lock (see nbtree/README).
+ * There are three operations performed here: deleting items already marked
+ * LP_DEAD, deduplication, and bottom-up index deletion. If all three
+ * operations fail to free enough space for the incoming item then caller will
+ * go on to split the page. We always attempt our preferred strategy (which
+ * is to delete items whose LP_DEAD bit are set) first. If that doesn't work
+ * out we consider alternatives. Most calls here will not exhaustively
+ * attempt all three operations. Deduplication and bottom-up index deletion
+ * are relatively expensive operations, so we try to pick one or the other up
+ * front (whichever one seems better for this specific page).
+ *
+ * Caller's checkingunique, uniquedup, and indexunchanged arguments help us
+ * decide which alternative strategy we should attempt (or attempt first).
+ * Deduplication is primarily useful with low cardinality data. Bottom-up
+ * index deletion is a backstop against version churn caused by repeated
+ * UPDATE statements where affected indexes don't receive logical changes
+ * (because an optimization like heapam's HOT cannot be applied in the
+ * tableam). But useful interplay between both techniques over time is
+ * sometimes possible.
+ *
+ * Deduplication can sometimes step in when bottom-up index deletion fails due
+ * to it simply being unsafe to delete old version tuples that accumulate on a
+ * leaf page (usually because of one old snapshot that might need the old
+ * versions, and thereby disrupts the cleanup of garbage tuples generally).
+ * Deduplication may buy time for bottom-up index deletion, which can
+ * ultimately succeed because the question of splitting a page affected by
+ * version churn is delayed long enough for the snapshot that held back
+ * deletion to go away naturally. Note that bottom-up deletion can perform
+ * granular deletion of posting list TIDs, just like VACUUM (but unlike our
+ * preferred strategy).
+ *
+ * Callers that only want us to look for/delete LP_DEAD items can ask for that
+ * directly by passing true 'lpdeadonly' argument.
+ *
+ * Note: We used to only delete LP_DEAD items when the BTP_HAS_GARBAGE page
+ * level flag was found set. The flag was useful back when there wasn't
+ * necessarily one single page for a duplicate tuple to go on (before heap TID
+ * became a part of the key space in version 4 indexes). But we don't
+ * actually look at the flag anymore (it's not a gating condition for our
+ * caller). That would cause us to miss tuples that are safe to delete,
+ * without getting any benefit in return. We know that the alternative is to
+ * split the page; scanning the line pointer array in passing won't have
+ * noticeable overhead. (We still maintain the BTP_HAS_GARBAGE flag despite
+ * all this because !heapkeyspace indexes must still do a "getting tired"
+ * linear search in the same way, and so are likely to still benefit.
+ * !heapkeyspace callers do in fact use the BTP_HAS_GARBAGE flag as a gating
+ * condition.)
*/
static void
-_bt_vacuum_one_page(Relation rel, Buffer buffer, Relation heapRel)
+_bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
+ BTInsertState insertstate,
+ bool lpdeadonly, bool checkingunique,
+ bool uniquedup, bool indexunchanged)
{
OffsetNumber deletable[MaxIndexTuplesPerPage];
int ndeletable = 0;
OffsetNumber offnum,
- minoff,
maxoff;
+ Buffer buffer = insertstate->buf;
+ BTScanInsert itup_key = insertstate->itup_key;
Page page = BufferGetPage(buffer);
BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
Assert(P_ISLEAF(opaque));
+ Assert(lpdeadonly || itup_key->heapkeyspace);
/*
* Scan over all items to see which ones need to be deleted according to
* LP_DEAD flags.
*/
- minoff = P_FIRSTDATAKEY(opaque);
maxoff = PageGetMaxOffsetNumber(page);
- for (offnum = minoff;
+ for (offnum = P_FIRSTDATAKEY(opaque);
offnum <= maxoff;
offnum = OffsetNumberNext(offnum))
{
@@ -2659,12 +2702,74 @@ _bt_vacuum_one_page(Relation rel, Buffer buffer, Relation heapRel)
}
if (ndeletable > 0)
- _bt_delitems_delete(rel, buffer, deletable, ndeletable, heapRel);
+ {
+ _bt_delitems_delete(rel, buffer, false, InvalidTransactionId,
+ deletable, ndeletable, NULL, 0, heapRel);
+ insertstate->bounds_valid = false;
+
+ /* Return when a page split has already been avoided */
+ if (PageGetFreeSpace(page) >= insertstate->itemsz)
+ return;
+
+ /* Might as well assume duplicates (if checkingunique) */
+ uniquedup = true;
+ }
/*
- * Note: if we didn't find any LP_DEAD items, then the page's
- * BTP_HAS_GARBAGE hint bit is falsely set. We do not bother expending a
- * separate write to clear it, however. We will clear it when we split
- * the page, or when deduplication runs.
+ * Some callers only want to delete LP_DEAD items. Return early for these
+ * callers.
+ *
+ * Note: The page's BTP_HAS_GARBAGE hint flag may still be set when we
+ * return at this point (or when we go on the try either or both of our
+ * other strategies and they also fail). We do not bother expending a
+ * separate write to clear it, however. Caller will definitely clear it
+ * when it goes on to split the page (plus deduplication knows to clear
+ * the flag when it actually modifies the page).
*/
+ if (lpdeadonly)
+ return;
+
+ /*
+ * We can get called in the checkingunique case when there is no reason to
+ * believe that there are any duplicates on the page; we should at least
+ * still check for LP_DEAD items. Now that we have, and now that it has
+ * not helped, give up and let caller split the page.
+ *
+ * We give up because the other types of operations that might avoid a
+ * page split are also unlikely to work out, but are much more expensive
+ * to try. That cannot be justified given there is no reason to think
+ * that there are duplicates that we can target.
+ */
+ if (checkingunique && !uniquedup)
+ return;
+
+ /* Assume bounds about to be invalidated (this is almost certain now) */
+ insertstate->bounds_valid = false;
+
+ /*
+ * Perform bottom-up index deletion pass when executor hint indicated that
+ * incoming item is logically unchanged, or for a unique index that is
+ * known to have physical duplicates for some other reason. (There is a
+ * large overlap between these two cases for a unique index. It's worth
+ * having both triggering conditions in order to apply the optimization in
+ * the event of successive related INSERT and DELETE statements.)
+ *
+ * We'll go on to do a deduplication pass when a bottom-up pass either
+ * fails to delete an acceptable amount of free space (a non-trivial
+ * fraction of the page that typically exceeds the new item's size), or
+ * when we're dealing with low cardinality data that has relatively few
+ * tuples (with large posting lists).
+ */
+ if ((indexunchanged || uniquedup) &&
+ _bt_bottomup_pass(rel, buffer, heapRel, insertstate->itemsz,
+ checkingunique))
+ return;
+
+ /*
+ * Perform deduplication pass, though only when it is enabled for the
+ * index and known to be safe (it must be an allequalimage index).
+ */
+ if (BTGetDeduplicateItems(rel) && itup_key->allequalimage)
+ _bt_dedup_pass(rel, buffer, heapRel, insertstate->itup,
+ insertstate->itemsz, checkingunique);
}
diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c
index 7f392480ac..9a72de23a5 100644
--- a/src/backend/access/nbtree/nbtpage.c
+++ b/src/backend/access/nbtree/nbtpage.c
@@ -1110,15 +1110,14 @@ _bt_page_recyclable(Page page)
* sorted in ascending order.
*
* Routine deals with deleting TIDs when some (but not all) of the heap TIDs
- * in an existing posting list item are to be removed by VACUUM. This works
- * by updating/overwriting an existing item with caller's new version of the
- * item (a version that lacks the TIDs that are to be deleted).
+ * in an existing posting list item are to be removed. This works by
+ * updating/overwriting an existing item with caller's new version of the item
+ * (a version that lacks the TIDs that are to be deleted).
*
* We record VACUUMs and b-tree deletes differently in WAL. Deletes must
* generate their own latestRemovedXid by accessing the heap directly, whereas
* VACUUMs rely on the initial heap scan taking care of it indirectly. Also,
- * only VACUUM can perform granular deletes of individual TIDs in posting list
- * tuples.
+ * we remove the VACUUM cycle ID from pages, which b-tree deletes don't do.
*/
void
_bt_delitems_vacuum(Relation rel, Buffer buf,
@@ -1187,8 +1186,15 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
* array of offset numbers.
*
* PageIndexTupleOverwrite() won't unset each item's LP_DEAD bit when it
- * happens to already be set. Although we unset the BTP_HAS_GARBAGE page
- * level flag, unsetting individual LP_DEAD bits should still be avoided.
+ * happens to already be set. It's important that we not interfere with
+ * garbage collection mechanisms that use _bt_delitems_delete().
+ *
+ * Eagerly removing items with their LP_DEAD bit set seems unwise, because
+ * in practice bottom-up techniques do a good job of taking care of the
+ * problem at a rate that makes sense at a keyspace-local level. Plus
+ * it'd just be messy. We'd have to explicitly log a latestRemovedXid
+ * cutoff, just like _bt_delitems_delete(). Accessing tableam blocks
+ * again from here is rather unappealing.
*/
for (int i = 0; i < nupdatable; i++)
{
@@ -1215,20 +1221,12 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
opaque->btpo_cycleid = 0;
/*
- * Mark the page as not containing any LP_DEAD items. This is not
- * certainly true (there might be some that have recently been marked, but
- * weren't targeted by VACUUM's heap scan), but it will be true often
- * enough. VACUUM does not delete items purely because they have their
- * LP_DEAD bit set, since doing so would necessitate explicitly logging a
- * latestRemovedXid cutoff (this is how _bt_delitems_delete works).
+ * Clear the BTP_HAS_GARBAGE page flag.
*
- * The consequences of falsely unsetting BTP_HAS_GARBAGE should be fairly
- * limited, since we never falsely unset an LP_DEAD bit. Workloads that
- * are particularly dependent on LP_DEAD bits being set quickly will
- * usually manage to set the BTP_HAS_GARBAGE flag before the page fills up
- * again anyway. Furthermore, attempting a deduplication pass will remove
- * all LP_DEAD items, regardless of whether the BTP_HAS_GARBAGE hint bit
- * is set or not.
+ * This flag indicates the presence of LP_DEAD items on the page (though
+ * not reliably). We only use it with pg_upgrade'd !heapkeyspace indexes.
+ * (Otherwise we check all of the line pointers directly. The cost of
+ * doing it that way is negligible compared to splitting the page.)
*/
opaque->btpo_flags &= ~BTP_HAS_GARBAGE;
@@ -1277,43 +1275,134 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
* Delete item(s) from a btree leaf page during single-page cleanup.
*
* This routine assumes that the caller has pinned and write locked the
- * buffer. Also, the given deletable array *must* be sorted in ascending
- * order.
+ * buffer. Also, the given deletable and updatable arrays *must* be sorted in
+ * ascending order.
+ *
+ * Routine deals with deleting TIDs when some (but not all) of the heap TIDs
+ * in an existing posting list item are to be removed. This works by
+ * updating/overwriting an existing item with caller's new version of the item
+ * (a version that lacks the TIDs that are to be deleted).
*
* This is nearly the same as _bt_delitems_vacuum as far as what it does to
* the page, but it needs to generate its own latestRemovedXid by accessing
* the heap. This is used by the REDO routine to generate recovery conflicts.
- * Also, it doesn't handle posting list tuples unless the entire tuple can be
- * deleted as a whole (since there is only one LP_DEAD bit per line pointer).
+ * Though note that bottom-up index deletion caller will provide its own
+ * latestRemovedXid, since it's convenient for it to determine that at the
+ * same point that it determines that the items are dead (it won't set LP_DEAD
+ * items on leaf page at all). Also, we don't clear page's VACUUM cycle ID.
*/
void
_bt_delitems_delete(Relation rel, Buffer buf,
+ bool bottomup, TransactionId bottomupXid,
OffsetNumber *deletable, int ndeletable,
+ BTVacuumPosting *updatable, int nupdatable,
Relation heapRel)
{
Page page = BufferGetPage(buf);
BTPageOpaque opaque;
TransactionId latestRemovedXid = InvalidTransactionId;
+ Size itemsz;
+ char *updatedbuf = NULL;
+ Size updatedbuflen = 0;
+ OffsetNumber updatedoffsets[MaxIndexTuplesPerPage];
/* Shouldn't be called unless there's something to do */
- Assert(ndeletable > 0);
+ Assert(ndeletable > 0 || nupdatable > 0);
+ /* Shouldn't update posting lists unless it's for bottom-up caller */
+ Assert(nupdatable == 0 || bottomup);
if (XLogStandbyInfoActive() && RelationNeedsWAL(rel))
- latestRemovedXid =
- _bt_xid_horizon(rel, heapRel, page, deletable, ndeletable);
+ {
+ if (!bottomup)
+ latestRemovedXid =
+ _bt_xid_horizon(rel, heapRel, page, deletable,
+ ndeletable);
+ else
+ latestRemovedXid = bottomupXid;
+ }
+
+ for (int i = 0; i < nupdatable; i++)
+ {
+ /* Replace work area IndexTuple with updated version */
+ _bt_update_posting(updatable[i]);
+
+ /* Maintain array of updatable page offsets for WAL record */
+ updatedoffsets[i] = updatable[i]->updatedoffset;
+ }
+
+ /* XLOG stuff -- allocate and fill buffer before critical section */
+ if (nupdatable > 0 && RelationNeedsWAL(rel))
+ {
+ Size offset = 0;
+
+ for (int i = 0; i < nupdatable; i++)
+ {
+ BTVacuumPosting vacposting = updatable[i];
+
+ itemsz = SizeOfBtreeUpdate +
+ vacposting->ndeletedtids * sizeof(uint16);
+ updatedbuflen += itemsz;
+ }
+
+ updatedbuf = palloc(updatedbuflen);
+ for (int i = 0; i < nupdatable; i++)
+ {
+ BTVacuumPosting vacposting = updatable[i];
+ xl_btree_update update;
+
+ update.ndeletedtids = vacposting->ndeletedtids;
+ memcpy(updatedbuf + offset, &update.ndeletedtids,
+ SizeOfBtreeUpdate);
+ offset += SizeOfBtreeUpdate;
+
+ itemsz = update.ndeletedtids * sizeof(uint16);
+ memcpy(updatedbuf + offset, vacposting->deletetids, itemsz);
+ offset += itemsz;
+ }
+ }
/* No ereport(ERROR) until changes are logged */
START_CRIT_SECTION();
- /* Fix the page */
- PageIndexMultiDelete(page, deletable, ndeletable);
+ /*
+ * Handle posting tuple updates.
+ *
+ * Deliberately do this before handling simple deletes. If we did it the
+ * other way around (i.e. WAL record order -- simple deletes before
+ * updates) then we'd have to make compensating changes to the 'updatable'
+ * array of offset numbers.
+ */
+ for (int i = 0; i < nupdatable; i++)
+ {
+ OffsetNumber updatedoffset = updatedoffsets[i];
+ IndexTuple itup;
+
+ itup = updatable[i]->itup;
+ itemsz = MAXALIGN(IndexTupleSize(itup));
+ if (!PageIndexTupleOverwrite(page, updatedoffset, (Item) itup,
+ itemsz))
+ elog(PANIC, "failed to update partially dead item in block %u of index \"%s\"",
+ BufferGetBlockNumber(buf), RelationGetRelationName(rel));
+ }
+
+ /* Now handle simple deletes of entire tuples */
+ if (ndeletable > 0)
+ PageIndexMultiDelete(page, deletable, ndeletable);
/*
* Unlike _bt_delitems_vacuum, we *must not* clear the vacuum cycle ID,
- * because this is not called by VACUUM. Just clear the BTP_HAS_GARBAGE
- * page flag, since we deleted all items with their LP_DEAD bit set.
+ * because this is not called by VACUUM
*/
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+
+ /*
+ * Clear the BTP_HAS_GARBAGE page flag.
+ *
+ * This flag indicates the presence of LP_DEAD items on the page (though
+ * not reliably). We only use it with pg_upgrade'd !heapkeyspace indexes.
+ * (Otherwise we check all of the line pointers directly. The cost of
+ * doing it that way is negligible compared to splitting the page.)
+ */
opaque->btpo_flags &= ~BTP_HAS_GARBAGE;
MarkBufferDirty(buf);
@@ -1326,6 +1415,7 @@ _bt_delitems_delete(Relation rel, Buffer buf,
xlrec_delete.latestRemovedXid = latestRemovedXid;
xlrec_delete.ndeleted = ndeletable;
+ xlrec_delete.nupdated = nupdatable;
XLogBeginInsert();
XLogRegisterBuffer(0, buf, REGBUF_STANDARD);
@@ -1336,8 +1426,16 @@ _bt_delitems_delete(Relation rel, Buffer buf,
* When XLogInsert stores the whole buffer, the array need not be
* stored too.
*/
- XLogRegisterBufData(0, (char *) deletable,
- ndeletable * sizeof(OffsetNumber));
+ if (ndeletable > 0)
+ XLogRegisterBufData(0, (char *) deletable,
+ ndeletable * sizeof(OffsetNumber));
+
+ if (nupdatable > 0)
+ {
+ XLogRegisterBufData(0, (char *) updatedoffsets,
+ nupdatable * sizeof(OffsetNumber));
+ XLogRegisterBufData(0, updatedbuf, updatedbuflen);
+ }
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_DELETE);
@@ -1345,6 +1443,13 @@ _bt_delitems_delete(Relation rel, Buffer buf,
}
END_CRIT_SECTION();
+
+ /* can't leak memory here */
+ if (updatedbuf != NULL)
+ pfree(updatedbuf);
+ /* free tuples generated by calling _bt_update_posting() */
+ for (int i = 0; i < nupdatable; i++)
+ pfree(updatable[i]->itup);
}
/*
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index 8eeb7bb64e..bc82cd4e7d 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -209,7 +209,7 @@ btinsert(Relation rel, Datum *values, bool *isnull,
itup = index_form_tuple(RelationGetDescr(rel), values, isnull);
itup->t_tid = *ht_ctid;
- result = _bt_doinsert(rel, itup, checkUnique, heapRel);
+ result = _bt_doinsert(rel, itup, checkUnique, heapRel, indexunchanged);
pfree(itup);
diff --git a/src/backend/access/nbtree/nbtutils.c b/src/backend/access/nbtree/nbtutils.c
index 81589b9056..2f5f14e527 100644
--- a/src/backend/access/nbtree/nbtutils.c
+++ b/src/backend/access/nbtree/nbtutils.c
@@ -1877,7 +1877,8 @@ _bt_killitems(IndexScanDesc scan)
* Since this can be redone later if needed, mark as dirty hint.
*
* Whenever we mark anything LP_DEAD, we also set the page's
- * BTP_HAS_GARBAGE flag, which is likewise just a hint.
+ * BTP_HAS_GARBAGE flag, which is likewise just a hint. (Note that we
+ * only rely on the page-level flag in !heapkeyspace indexes.)
*/
if (killedsomething)
{
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index e913226760..d2142f3e89 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -675,7 +675,56 @@ btree_xlog_delete(XLogReaderState *record)
page = (Page) BufferGetPage(buffer);
- PageIndexMultiDelete(page, (OffsetNumber *) ptr, xlrec->ndeleted);
+ if (xlrec->nupdated > 0)
+ {
+ OffsetNumber *updatedoffsets;
+ xl_btree_update *updates;
+
+ updatedoffsets = (OffsetNumber *)
+ (ptr + xlrec->ndeleted * sizeof(OffsetNumber));
+ updates = (xl_btree_update *) ((char *) updatedoffsets +
+ xlrec->nupdated *
+ sizeof(OffsetNumber));
+
+ for (int i = 0; i < xlrec->nupdated; i++)
+ {
+ BTVacuumPosting vacposting;
+ IndexTuple origtuple;
+ ItemId itemid;
+ Size itemsz;
+
+ itemid = PageGetItemId(page, updatedoffsets[i]);
+ origtuple = (IndexTuple) PageGetItem(page, itemid);
+
+ vacposting = palloc(offsetof(BTVacuumPostingData, deletetids) +
+ updates->ndeletedtids * sizeof(uint16));
+ vacposting->updatedoffset = updatedoffsets[i];
+ vacposting->itup = origtuple;
+ vacposting->ndeletedtids = updates->ndeletedtids;
+ memcpy(vacposting->deletetids,
+ (char *) updates + SizeOfBtreeUpdate,
+ updates->ndeletedtids * sizeof(uint16));
+
+ _bt_update_posting(vacposting);
+
+ /* Overwrite updated version of tuple */
+ itemsz = MAXALIGN(IndexTupleSize(vacposting->itup));
+ if (!PageIndexTupleOverwrite(page, updatedoffsets[i],
+ (Item) vacposting->itup, itemsz))
+ elog(PANIC, "failed to update partially dead item");
+
+ pfree(vacposting->itup);
+ pfree(vacposting);
+
+ /* advance to next xl_btree_update from array */
+ updates = (xl_btree_update *)
+ ((char *) updates + SizeOfBtreeUpdate +
+ updates->ndeletedtids * sizeof(uint16));
+ }
+ }
+
+ if (xlrec->ndeleted > 0)
+ PageIndexMultiDelete(page, (OffsetNumber *) ptr, xlrec->ndeleted);
/* Mark the page as not containing any LP_DEAD items */
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
@@ -1065,7 +1114,8 @@ btree_mask(char *pagedata, BlockNumber blkno)
/*
* BTP_HAS_GARBAGE is just an un-logged hint bit. So, mask it. See
- * _bt_killitems(), _bt_check_unique() for details.
+ * _bt_delete_or_dedup_one_page(), _bt_killitems(), and _bt_check_unique()
+ * for details.
*/
maskopaq->btpo_flags &= ~BTP_HAS_GARBAGE;
--
2.25.1
[application/octet-stream] v7-0001-Make-tableam-interface-support-bottom-up-deletion.patch (7.8K, ../../CAH2-WzmP5AymEfT_n3wAdvW8D7DduapHPqRzds5kv7VjnXsx6Q@mail.gmail.com/5-v7-0001-Make-tableam-interface-support-bottom-up-deletion.patch)
download | inline diff:
From 43da316463a4081ebbf59c137067f1f2be36899e Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Sat, 7 Nov 2020 14:07:14 -0800
Subject: [PATCH v7 1/4] Make tableam interface support bottom-up deletion.
Teach tableam about bottom-up index deletion. This mechanism allows an
index AM to cooperate with a tableam in deleting index tuples at regular
intervals. The general idea is to avoid accumulating too many versions
in the index for any given logically row, without doing any extra work
before the situation gets out of hand at a localized page in an index.
This commit isn't useful on its own. An upcoming commit will add
support to nbtree. A further commit will provide complete functionality
by adding support to heapam.
Author: Peter Geoghegan <[email protected]>
Reviewed-By: Victor Yegorov <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wzm+maE3apHB8NOtmM=p-DO65j2V5GzAWCOEEuy3JZgb2g@mail.gmail.com
---
src/include/access/tableam.h | 99 ++++++++++++++++++++++++
src/backend/access/heap/heapam_handler.c | 1 +
src/backend/access/table/tableam.c | 6 +-
3 files changed, 103 insertions(+), 3 deletions(-)
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 387eb34a61..4aa131da0d 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -128,6 +128,75 @@ typedef struct TM_FailureData
bool traversed;
} TM_FailureData;
+/*
+ * State used when calling table_index_delete_check() to perform "bottom up"
+ * deletion of duplicate index tuples. State is intialized by index AM
+ * caller, while state is finalized by tableam, which modifies state.
+ */
+typedef struct TM_IndexDelete
+{
+ ItemPointerData tid; /* table TID from index tuple */
+ int16 id; /* Offset into TM_IndexStatus array */
+} TM_IndexDelete;
+
+typedef struct TM_IndexStatus
+{
+ OffsetNumber idxoffnum; /* Index am page offset number */
+ int16 tupsize; /* Space freed in index if tuple deleted */
+ bool ispromising; /* Is a duplicate within index? */
+ bool deleteitup; /* Was tableam tuple found dead? */
+} TM_IndexStatus;
+
+/*
+ * State representing one single bottom-up index deletion operation.
+ *
+ * Index am caller provides a TM_IndexDeleteOp, which points to two palloc()'d
+ * arrays. Each array has one entry per TID that the tableam is asked to
+ * consider (typically these are all of the TIDs from a single index page, so
+ * there could be hundreds or even thousand of entries in arrays). ndeltids
+ * tracks the current number of entries.
+ *
+ * The two arrays are conceptually one single array. Two arrays/structs are
+ * used for performance reasons. (We really need to keep the TM_IndexDelete
+ * struct small so that the tableam can do an initial sort by TID as quickly
+ * as possible.)
+ *
+ * The index AM should keep track of which index tuple relates to which entry
+ * by setting idxoffnum (and/or relying on each entry being uniquely
+ * identifiable using tid). Index AM requests target free space indicated by
+ * "targetfreespace". Index AM also represents the space saving for each TID
+ * by filling in the tupsize for each array element. The tableam must balance
+ * the requirements of the index AM against the costs paid in the tableam.
+ *
+ * The index AM provides strong hints about where to look to the tableam by
+ * marking some entries as "promising". Index AM does this with duplicate
+ * index tuples that are strongly suspected to be old versions left behind by
+ * UPDATEs that did not logically changed any indexed values. Index AM may
+ * find it helpful to only mark TIDs/entries as promising when they're thought
+ * to have been affected by such an UPDATE in the recent past.
+ *
+ * The tableam marks individual entries as deletable for the index AM. It's
+ * common for the final array to be shrunk in size. The index AM caller
+ * should do nothing if on return vstate.ndeltids is found set to zero. The
+ * index AM caller only needs to consider the first ndeltids from the final
+ * array, which is typically much smaller than its original size (tableam
+ * updates ndeltids in state). One reason for this is that the tableam can
+ * naturally only afford to a few tableam blocks on each call -- it typically
+ * won't even try to check most of the entries from the tableam.
+ *
+ * The tableam typically sorts the vstate.deltids array by TID. The index AM
+ * should be prepared to restore the array to its useful/original order. The
+ * array is typically far smaller than its original size by then, so that step
+ * should be relatively fast.
+ */
+typedef struct TM_IndexDeleteOp
+{
+ int ndeltids; /* Number of deltids/tidstatuses for op */
+ TM_IndexDelete *deltids;
+ TM_IndexStatus *tidstatuses;
+ int targetfreespace; /* Guides tableam on requirements */
+} TM_IndexDeleteOp;
+
/* "options" flag bits for table_tuple_insert */
/* TABLE_INSERT_SKIP_WAL was 0x0001; RelationNeedsWAL() now governs */
#define TABLE_INSERT_SKIP_FSM 0x0002
@@ -409,6 +478,17 @@ typedef struct TableAmRoutine
uint8 flags,
TM_FailureData *tmfd);
+ /*
+ * Help index AMs to perform bottom-up index deletion.
+ *
+ * Optional callback. See TM_IndexDeleteOp struct for full details.
+ *
+ * Returns a latestRemovedXid transaction ID that index AM must use to
+ * generate a recovery conflict when required.
+ */
+ TransactionId (*index_delete_check) (Relation rel,
+ TM_IndexDeleteOp *vstate);
+
/*
* Perform operations necessary to complete insertions made via
* tuple_insert and multi_insert with a BulkInsertState specified. In-tree
@@ -1363,6 +1443,25 @@ table_tuple_lock(Relation rel, ItemPointer tid, Snapshot snapshot,
flags, tmfd);
}
+/*
+ * Bottom-up index deletion interface for index AMs.
+ *
+ * Sets deletable tuples in entries from caller's TM_IndexDeleteOp state that
+ * are found to point to already-dead tuples in the tableam structure.
+ *
+ * See TM_IndexDeleteOp struct for full details.
+ */
+static inline TransactionId
+table_index_delete_check(Relation rel, TM_IndexDeleteOp *vstate)
+{
+ /* optional callback */
+ if (rel->rd_tableam && rel->rd_tableam->index_delete_check)
+ return rel->rd_tableam->index_delete_check(rel, vstate);
+
+ vstate->ndeltids = 0;
+ return InvalidTransactionId;
+}
+
/*
* Perform operations necessary to complete insertions made via
* tuple_insert and multi_insert with a BulkInsertState specified.
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index dcaea7135f..a08c494034 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2532,6 +2532,7 @@ static const TableAmRoutine heapam_methods = {
.tuple_delete = heapam_tuple_delete,
.tuple_update = heapam_tuple_update,
.tuple_lock = heapam_tuple_lock,
+ .index_delete_check = NULL,
.tuple_fetch_row_version = heapam_fetch_row_version,
.tuple_get_latest_tid = heap_get_latest_tid,
diff --git a/src/backend/access/table/tableam.c b/src/backend/access/table/tableam.c
index 6438c45716..e19bdd246a 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -207,9 +207,9 @@ table_beginscan_parallel(Relation relation, ParallelTableScanDesc parallel_scan)
/*
* To perform that check simply start an index scan, create the necessary
* slot, do the heap lookup, and shut everything down again. This could be
- * optimized, but is unlikely to matter from a performance POV. If there
- * frequently are live index pointers also matching a unique index key, the
- * CPU overhead of this routine is unlikely to matter.
+ * optimized, but is unlikely to matter from a performance POV. Note that
+ * table_index_delete_check() is optimized in this way, since it is designed
+ * as a batch operation.
*
* Note that *tid may be modified when we return true if the AM supports
* storing multiple row versions reachable via a single index entry (like
--
2.25.1
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-11-11 14:17 ` Victor Yegorov <[email protected]>
2020-11-12 22:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
1 sibling, 1 reply; 1661+ messages in thread
From: Victor Yegorov @ 2020-11-11 14:17 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
пн, 9 нояб. 2020 г. в 18:21, Peter Geoghegan <[email protected]>:
> On Tue, Nov 3, 2020 at 12:44 PM Peter Geoghegan <[email protected]> wrote:
> > v6 still needs more polishing -- my focus has still been on the
> > algorithm itself. But I think I'm almost done with that part -- it
> > seems unlikely that I'll be able to make any additional significant
> > improvements in that area after v6.
>
> Attached is v7, which tidies everything up. The project is now broken
> up into multiple patches, which can be committed separately. Every
> patch has a descriptive commit message. This should make it a lot
> easier to review.
>
I've looked at the latest (v7) patchset.
I've decided to use a quite common (in my practice) setup with an indexed
mtime column over scale 1000 set:
alter table pgbench_accounts add mtime timestamp default now();
create or replace function fill_mtime() returns trigger as $$begin
NEW.mtime=now(); return NEW; END;$$ language plpgsql;
create trigger t_accounts_mtime before update on pgbench_accounts for each
row execute function fill_mtime();
create index accounts_mtime on pgbench_accounts (mtime, aid);
create index tenner on pgbench_accounts ((aid - (aid%10)));
ANALYZE pgbench_accounts;
For the test, I've used 3 pgbench scripts (started in parallel sessions):
1. UPDATE + single PK SELECT in a transaction
2. three PK SELECTs in a transaction
3. SELECT of all modifications for the last 15 minutes
Given the size of the set, all data was cached and UPDATEs were fast enough
to make 3rd query sit on disk-based sorting.
Some figures follow.
Master sizes
------------
relkind | relname | nrows | blk_before | mb_before |
blk_after | mb_after
---------+-----------------------+-----------+------------+-----------+-----------+----------
r | pgbench_accounts | 100000000 | 1639345 | 12807.4 |
1677861 | 13182.8
i | accounts_mtime | 100000000 | 385042 | 3008.1 |
424413 | 3565.6
i | pgbench_accounts_pkey | 100000000 | 274194 | 2142.1 |
274194 | 2142.3
i | tenner | 100000000 | 115352 | 901.2 |
128513 | 1402.9
(4 rows)
Patchset v7 sizes
-----------------
relkind | relname | nrows | blk_before | mb_before |
blk_after | mb_after
---------+-----------------------+-----------+------------+-----------+-----------+----------
r | pgbench_accounts | 100000000 | 1639345 | 12807.4 |
1676887 | 13170.2
i | accounts_mtime | 100000000 | 385042 | 3008.1 |
424521 | 3536.4
i | pgbench_accounts_pkey | 100000000 | 274194 | 2142.1 |
274194 | 2142.1
i | tenner | 100000000 | 115352 | 901.2 |
115352 | 901.2
(4 rows)
TPS
---
query | Master TPS | Patched TPS
----------------+------------+-------------
UPDATE + SELECT | 5150 | 4884
3 SELECT in txn | 23133 | 23193
15min SELECT | 0.75 | 0.78
We can see that:
- unused index is not suffering from not-HOT updates at all, which is the
point of the patch
- we have ordinary queries performing on the same level as on master
- we have 5,2% slowdown in UPDATE speed
Looking at graphs (attached), I can see that on the patched version we're
doing some IO (which is expected) during UPADTEs.
We're also reading quite a lot from disks for simple SELECTs, compared to
the master version.
I'm not sure if this should be counted as regression, though, as graphs go
on par pretty much.
Still, I would like to understand why this combination of indexes and
queries slows down UPDATEs.
During compilation I got one warning for make -C contrib:
blutils.c: In function ‘blhandler’:
blutils.c:133:22: warning: assignment from incompatible pointer type
[-Wincompatible-pointer-types]
amroutine->aminsert = blinsert;
I agree with the rename to "bottom-up index deletion", using "vacuuming"
generally makes users think
that functionality is used only during VACUUM (misleading).
I haven't looked at the code yet.
--
Victor Yegorov
Master
------
dbname | nspname | relkind | relname | nrows | nblocks | mb
--------+---------+---------+-----------------------+-----------+---------+---------
bench | public | r | pgbench_accounts | 100000000 | 1639345 | 12807.4
| | i | accounts_mtime | 100000000 | 385042 | 3008.1
| | i | pgbench_accounts_pkey | 100000000 | 274194 | 2142.1
| | i | tenner | 100000000 | 115352 | 901.2
(4 rows)
dbname | nspname | relkind | relname | nrows | nblocks | mb
--------+---------+---------+-----------------------+-----------+---------+---------
bench | public | r | pgbench_accounts | 99995400 | 1677861 | 13182.8
| | i | accounts_mtime | 99995400 | 424413 | 3565.6
| | i | pgbench_accounts_pkey | 99995400 | 274194 | 2142.3
| | i | tenner | 99995400 | 128513 | 1402.9
(4 rows)
scaling factor: 1000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 18543141
latency average = 1.553 ms
tps = 5150.839541 (including connections establishing)
tps = 5150.842233 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.000 \set delta random(-5000, 5000)
0.046 BEGIN;
0.171 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
0.106 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
1.222 END;
scaling factor: 1000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 83279844
latency average = 0.346 ms
tps = 23133.287719 (including connections establishing)
tps = 23133.300225 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 3.2)
0.035 BEGIN;
0.092 SELECT abalance FROM pgbench_accounts WHERE aid = :aid1;
0.088 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.088 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.039 END;
scaling factor: 1000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 2716
latency average = 10623.770 ms
tps = 0.753028 (including connections establishing)
tps = 0.753029 (excluding connections establishing)
statement latencies in milliseconds:
10611.948 SELECT abalance FROM pgbench_accounts WHERE mtime > now() - INTERVAL '15min' ORDER BY aid;
Patched
-------
dbname | nspname | relkind | relname | nrows | nblocks | mb
--------+---------+---------+-----------------------+-----------+---------+---------
bench | public | r | pgbench_accounts | 100000000 | 1639345 | 12807.4
| | i | accounts_mtime | 100000000 | 385042 | 3008.1
| | i | pgbench_accounts_pkey | 100000000 | 274194 | 2142.1
| | i | tenner | 100000000 | 115352 | 901.2
(4 rows)
dbname | nspname | relkind | relname | nrows | nblocks | mb
--------+---------+---------+-----------------------+----------+---------+---------
bench | public | r | pgbench_accounts | 99995200 | 1676887 | 13170.2
| | i | accounts_mtime | 99995200 | 424521 | 3536.4
| | i | pgbench_accounts_pkey | 99995200 | 274194 | 2142.1
| | i | tenner | 99995200 | 115352 | 901.2
(4 rows)
scaling factor: 1000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 17583489
latency average = 1.638 ms
tps = 4884.300945 (including connections establishing)
tps = 4884.303575 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.000 \set delta random(-5000, 5000)
0.046 BEGIN;
0.175 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
0.107 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
1.303 END;
scaling factor: 1000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 83497828
latency average = 0.345 ms
tps = 23193.839378 (including connections establishing)
tps = 23193.852972 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 3.2)
0.035 BEGIN;
0.091 SELECT abalance FROM pgbench_accounts WHERE aid = :aid1;
0.088 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.087 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.039 END;
scaling factor: 1000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 2839
latency average = 10160.741 ms
tps = 0.787344 (including connections establishing)
tps = 0.787345 (excluding connections establishing)
statement latencies in milliseconds:
10154.700 SELECT abalance FROM pgbench_accounts WHERE mtime > now() - INTERVAL '15min' ORDER BY aid;
Attachments:
[text/plain] 20201110-results-master.txt (2.9K, ../../CAGnEbohC0-4m=BAj-YCFkKoBfmsCT1iDHSbfRmsV2yCfm8QmKA@mail.gmail.com/3-20201110-results-master.txt)
download | inline:
Master
------
dbname | nspname | relkind | relname | nrows | nblocks | mb
--------+---------+---------+-----------------------+-----------+---------+---------
bench | public | r | pgbench_accounts | 100000000 | 1639345 | 12807.4
| | i | accounts_mtime | 100000000 | 385042 | 3008.1
| | i | pgbench_accounts_pkey | 100000000 | 274194 | 2142.1
| | i | tenner | 100000000 | 115352 | 901.2
(4 rows)
dbname | nspname | relkind | relname | nrows | nblocks | mb
--------+---------+---------+-----------------------+-----------+---------+---------
bench | public | r | pgbench_accounts | 99995400 | 1677861 | 13182.8
| | i | accounts_mtime | 99995400 | 424413 | 3565.6
| | i | pgbench_accounts_pkey | 99995400 | 274194 | 2142.3
| | i | tenner | 99995400 | 128513 | 1402.9
(4 rows)
scaling factor: 1000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 18543141
latency average = 1.553 ms
tps = 5150.839541 (including connections establishing)
tps = 5150.842233 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.000 \set delta random(-5000, 5000)
0.046 BEGIN;
0.171 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
0.106 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
1.222 END;
scaling factor: 1000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 83279844
latency average = 0.346 ms
tps = 23133.287719 (including connections establishing)
tps = 23133.300225 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 3.2)
0.035 BEGIN;
0.092 SELECT abalance FROM pgbench_accounts WHERE aid = :aid1;
0.088 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.088 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.039 END;
scaling factor: 1000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 2716
latency average = 10623.770 ms
tps = 0.753028 (including connections establishing)
tps = 0.753029 (excluding connections establishing)
statement latencies in milliseconds:
10611.948 SELECT abalance FROM pgbench_accounts WHERE mtime > now() - INTERVAL '15min' ORDER BY aid;
[image/png] 20201110-q1-UPDATE.png (265.5K, ../../CAGnEbohC0-4m=BAj-YCFkKoBfmsCT1iDHSbfRmsV2yCfm8QmKA@mail.gmail.com/4-20201110-q1-UPDATE.png)
download | view image
[image/png] 20201110-q2-SELECT.png (229.0K, ../../CAGnEbohC0-4m=BAj-YCFkKoBfmsCT1iDHSbfRmsV2yCfm8QmKA@mail.gmail.com/5-20201110-q2-SELECT.png)
download | view image
[image/png] 20201110-q3-15min-SELECT.png (242.4K, ../../CAGnEbohC0-4m=BAj-YCFkKoBfmsCT1iDHSbfRmsV2yCfm8QmKA@mail.gmail.com/6-20201110-q3-15min-SELECT.png)
download | view image
[application/octet-stream] 20201110-postgresql.auto.conf (704B, ../../CAGnEbohC0-4m=BAj-YCFkKoBfmsCT1iDHSbfRmsV2yCfm8QmKA@mail.gmail.com/7-20201110-postgresql.auto.conf)
download
[application/octet-stream] 20201110-testcase1.pgbench (278B, ../../CAGnEbohC0-4m=BAj-YCFkKoBfmsCT1iDHSbfRmsV2yCfm8QmKA@mail.gmail.com/8-20201110-testcase1.pgbench)
download
[application/octet-stream] 20201110-testcase2.pgbench (336B, ../../CAGnEbohC0-4m=BAj-YCFkKoBfmsCT1iDHSbfRmsV2yCfm8QmKA@mail.gmail.com/9-20201110-testcase2.pgbench)
download
[application/octet-stream] 20201110-testcase3.pgbench (92B, ../../CAGnEbohC0-4m=BAj-YCFkKoBfmsCT1iDHSbfRmsV2yCfm8QmKA@mail.gmail.com/10-20201110-testcase3.pgbench)
download
[text/plain] 20201110-results-patched.txt (2.9K, ../../CAGnEbohC0-4m=BAj-YCFkKoBfmsCT1iDHSbfRmsV2yCfm8QmKA@mail.gmail.com/11-20201110-results-patched.txt)
download | inline:
Patched
-------
dbname | nspname | relkind | relname | nrows | nblocks | mb
--------+---------+---------+-----------------------+-----------+---------+---------
bench | public | r | pgbench_accounts | 100000000 | 1639345 | 12807.4
| | i | accounts_mtime | 100000000 | 385042 | 3008.1
| | i | pgbench_accounts_pkey | 100000000 | 274194 | 2142.1
| | i | tenner | 100000000 | 115352 | 901.2
(4 rows)
dbname | nspname | relkind | relname | nrows | nblocks | mb
--------+---------+---------+-----------------------+----------+---------+---------
bench | public | r | pgbench_accounts | 99995200 | 1676887 | 13170.2
| | i | accounts_mtime | 99995200 | 424521 | 3536.4
| | i | pgbench_accounts_pkey | 99995200 | 274194 | 2142.1
| | i | tenner | 99995200 | 115352 | 901.2
(4 rows)
scaling factor: 1000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 17583489
latency average = 1.638 ms
tps = 4884.300945 (including connections establishing)
tps = 4884.303575 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.000 \set delta random(-5000, 5000)
0.046 BEGIN;
0.175 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
0.107 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
1.303 END;
scaling factor: 1000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 83497828
latency average = 0.345 ms
tps = 23193.839378 (including connections establishing)
tps = 23193.852972 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 3.2)
0.035 BEGIN;
0.091 SELECT abalance FROM pgbench_accounts WHERE aid = :aid1;
0.088 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.087 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.039 END;
scaling factor: 1000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 2839
latency average = 10160.741 ms
tps = 0.787344 (including connections establishing)
tps = 0.787345 (excluding connections establishing)
statement latencies in milliseconds:
10154.700 SELECT abalance FROM pgbench_accounts WHERE mtime > now() - INTERVAL '15min' ORDER BY aid;
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 14:17 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
@ 2020-11-12 22:00 ` Peter Geoghegan <[email protected]>
2020-11-17 15:05 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-17 15:16 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
0 siblings, 2 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-11-12 22:00 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Wed, Nov 11, 2020 at 6:17 AM Victor Yegorov <[email protected]> wrote:
> I've looked at the latest (v7) patchset.
> I've decided to use a quite common (in my practice) setup with an indexed mtime column over scale 1000 set:
Thanks for testing!
> We can see that:
> - unused index is not suffering from not-HOT updates at all, which is the point of the patch
> - we have ordinary queries performing on the same level as on master
> - we have 5,2% slowdown in UPDATE speed
I think that I made a mistake with v7: I changed the way that we
detect low cardinality data during bottom-up deletion, which made us
do extra/early deduplication in more cases than we really should. I
suspect that this partially explains the slowdown in UPDATE latency
that you reported. I will fix this in v8.
I don't think that the solution is to go back to the v6 behavior in
this area, though. I now believe that this whole "proactive
deduplication for low cardinality data" thing only made sense as a way
of compensating for deficiencies in earlier versions of the patch.
Deficiencies that I've since fixed anyway. The best solution now is to
simplify. We can have generic criteria for "should we dedup the page
early after bottom-up deletion finishes without freeing up very much
space?". This seemed to work well during my latest testing. Probably
because heapam.c is now smart about the requirements from nbtree, as
well as the cost of accessing heap pages.
> I'm not sure if this should be counted as regression, though, as graphs go on par pretty much.
> Still, I would like to understand why this combination of indexes and queries slows down UPDATEs.
Another thing that I'll probably add to v8: Prefetching. This is
probably necessary just so I can have parity with the existing
heapam.c function that the new code is based on,
heap_compute_xid_horizon_for_tuples(). That will probably help here,
too.
> During compilation I got one warning for make -C contrib:
Oops.
> I agree with the rename to "bottom-up index deletion", using "vacuuming" generally makes users think
> that functionality is used only during VACUUM (misleading).
Yeah. That's kind of a problem already, because sometimes we use the
word VACUUM when talking about the long established LP_DEAD deletion
stuff. But I see that as a problem to be fixed. Actually, I would like
to fix it very soon.
> I haven't looked at the code yet.
It would be helpful if you could take a look at the nbtree patch --
particularly the changes related to deprecating the page-level
BTP_HAS_GARBAGE flag. I would like to break those parts out into a
separate patch, and commit it in the next week or two. It's just
refactoring, really. (This commit can also make nbtree only use the
word VACUUM for things that strictly involve VACUUM. For example,
it'll rename _bt_vacuum_one_page() to _bt_delete_or_dedup_one_page().)
We almost don't care about the flag already, so there is almost no
behavioral change from deprecated BTP_HAS_GARBAGE in this way.
Indexes that use deduplication already don't rely on BTP_HAS_GARBAGE
being set ever since deduplication was added to Postgres 13 (the
deduplication code doesn't want to deal with LP_DEAD bits, and cannot
trust that no LP_DEAD bits can be set just because BTP_HAS_GARBAGE
isn't set in the special area). Trusting the BTP_HAS_GARBAGE flag can
cause us to miss out on deleting items with their LP_DEAD bits set --
we're better off "assuming that BTP_HAS_GARBAGE is always set", and
finding out if there really are LP_DEAD bits set for ourselves each
time.
Missing LP_DEAD bits like this can happen when VACUUM unsets the
page-level flag without actually deleting the items at the same time,
which is expected when the items became garbage (and actually had
their LP_DEAD bits set) after VACUUM began, but before VACUUM reached
the leaf pages. That's really wasteful, and doesn't actually have any
upside -- we're scanning all of the line pointers only when we're
about to split (or dedup) the same page anyway, so the extra work is
practically free.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 14:17 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 22:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-11-17 15:05 ` Victor Yegorov <[email protected]>
2020-11-17 16:24 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
1 sibling, 1 reply; 1661+ messages in thread
From: Victor Yegorov @ 2020-11-17 15:05 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
чт, 12 нояб. 2020 г. в 23:00, Peter Geoghegan <[email protected]>:
> It would be helpful if you could take a look at the nbtree patch --
> particularly the changes related to deprecating the page-level
> BTP_HAS_GARBAGE flag. I would like to break those parts out into a
> separate patch, and commit it in the next week or two. It's just
> refactoring, really. (This commit can also make nbtree only use the
> word VACUUM for things that strictly involve VACUUM. For example,
> it'll rename _bt_vacuum_one_page() to _bt_delete_or_dedup_one_page().)
>
> We almost don't care about the flag already, so there is almost no
> behavioral change from deprecated BTP_HAS_GARBAGE in this way.
>
> Indexes that use deduplication already don't rely on BTP_HAS_GARBAGE
> being set ever since deduplication was added to Postgres 13 (the
> deduplication code doesn't want to deal with LP_DEAD bits, and cannot
> trust that no LP_DEAD bits can be set just because BTP_HAS_GARBAGE
> isn't set in the special area). Trusting the BTP_HAS_GARBAGE flag can
> cause us to miss out on deleting items with their LP_DEAD bits set --
> we're better off "assuming that BTP_HAS_GARBAGE is always set", and
> finding out if there really are LP_DEAD bits set for ourselves each
> time.
>
> Missing LP_DEAD bits like this can happen when VACUUM unsets the
> page-level flag without actually deleting the items at the same time,
> which is expected when the items became garbage (and actually had
> their LP_DEAD bits set) after VACUUM began, but before VACUUM reached
> the leaf pages. That's really wasteful, and doesn't actually have any
> upside -- we're scanning all of the line pointers only when we're
> about to split (or dedup) the same page anyway, so the extra work is
> practically free.
>
I've looked over the BTP_HAS_GARBAGE modifications, they look sane.
I've double checked that heapkeyspace indexes don't use this flag (don't
rely on it),
while pre-v4 ones still use it.
I have a question. This flag is raised in the _bt_check_unique() and
in _bt_killitems().
If we're deprecating this flag, perhaps it'd be good to either avoid
raising it at least for
_bt_check_unique(), as it seems to me that conditions are dealing with
postings, therefore
we are speaking of heapkeyspace indexes here.
If we'll conditionally raise this flag in the functions above, we can get
rid of blocks that drop it
in _bt_delitems_delete(), I think.
--
Victor Yegorov
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 14:17 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 22:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-17 15:05 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
@ 2020-11-17 16:24 ` Peter Geoghegan <[email protected]>
2020-11-17 17:19 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
0 siblings, 1 reply; 1661+ messages in thread
From: Peter Geoghegan @ 2020-11-17 16:24 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Tue, Nov 17, 2020 at 7:05 AM Victor Yegorov <[email protected]> wrote:
> I've looked over the BTP_HAS_GARBAGE modifications, they look sane.
> I've double checked that heapkeyspace indexes don't use this flag (don't rely on it),
> while pre-v4 ones still use it.
Cool.
> I have a question. This flag is raised in the _bt_check_unique() and in _bt_killitems().
> If we're deprecating this flag, perhaps it'd be good to either avoid raising it at least for
> _bt_check_unique(), as it seems to me that conditions are dealing with postings, therefore
> we are speaking of heapkeyspace indexes here.
Well, we still want to mark LP_DEAD bits set in all cases, just as
before. The difference is that heapkeyspace indexes won't rely on the
page-level flag later on.
> If we'll conditionally raise this flag in the functions above, we can get rid of blocks that drop it
> in _bt_delitems_delete(), I think.
I prefer to continue to maintain the flag in the same way, regardless
of which B-Tree version is in use (i.e. if it's heapkeyspace or not).
Maintaining the flag is not expensive, may have some small value for
forensic or debugging purposes, and saves callers the trouble of
telling _bt_delitems_delete() (and code like it) whether or not this
is a heapkeyspace index.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 14:17 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 22:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-17 15:05 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-17 16:24 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-11-17 17:19 ` Victor Yegorov <[email protected]>
2020-11-17 17:47 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
0 siblings, 1 reply; 1661+ messages in thread
From: Victor Yegorov @ 2020-11-17 17:19 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
вт, 17 нояб. 2020 г. в 17:24, Peter Geoghegan <[email protected]>:
> I prefer to continue to maintain the flag in the same way, regardless
> of which B-Tree version is in use (i.e. if it's heapkeyspace or not).
> Maintaining the flag is not expensive, may have some small value for
> forensic or debugging purposes, and saves callers the trouble of
> telling _bt_delitems_delete() (and code like it) whether or not this
> is a heapkeyspace index.
>
OK. Can you explain what deprecation means here?
If this functionality is left as is, it is not really deprecation?..
--
Victor Yegorov
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 14:17 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 22:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-17 15:05 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-17 16:24 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-17 17:19 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
@ 2020-11-17 17:47 ` Peter Geoghegan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-11-17 17:47 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Tue, Nov 17, 2020 at 9:19 AM Victor Yegorov <[email protected]> wrote:
> OK. Can you explain what deprecation means here?
> If this functionality is left as is, it is not really deprecation?..
It just means that we only keep it around for compatibility purposes.
We would like to remove it, but can't right now. If we ever stop
supporting version 3 indexes, then we can probably remove it entirely.
I would like to avoid special cases across B-Tree index versions.
Simply maintaining the page flag in the same way as we always have is
the simplest approach.
Pushed the BTP_HAS_GARBAGE patch just now. I'll post a rebased version
of the patch series later on today.
Thanks
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 14:17 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 22:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-11-17 15:16 ` Victor Yegorov <[email protected]>
2020-11-17 21:38 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
1 sibling, 1 reply; 1661+ messages in thread
From: Victor Yegorov @ 2020-11-17 15:16 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
чт, 12 нояб. 2020 г. в 23:00, Peter Geoghegan <[email protected]>:
> Another thing that I'll probably add to v8: Prefetching. This is
> probably necessary just so I can have parity with the existing
> heapam.c function that the new code is based on,
> heap_compute_xid_horizon_for_tuples(). That will probably help here,
> too.
>
I don't quite see this part. Do you mean top_block_groups_favorable() here?
--
Victor Yegorov
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 14:17 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 22:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-17 15:16 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
@ 2020-11-17 21:38 ` Peter Geoghegan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-11-17 21:38 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Tue, Nov 17, 2020 at 7:17 AM Victor Yegorov <[email protected]> wrote:
> чт, 12 нояб. 2020 г. в 23:00, Peter Geoghegan <[email protected]>:
>> Another thing that I'll probably add to v8: Prefetching. This is
>> probably necessary just so I can have parity with the existing
>> heapam.c function that the new code is based on,
>> heap_compute_xid_horizon_for_tuples(). That will probably help here,
>> too.
>
> I don't quite see this part. Do you mean top_block_groups_favorable() here?
I meant to add prefetching to the version of the patch that became v8,
but that didn't happen because I ran out of time. I wanted to get out
a version with the low cardinality fix, to see if that helped with the
regression you talked about last week. (Prefetching seems to make a
small difference when we're I/O bound, so it may not be that
important.)
Attached is v9 of the patch series. This actually has prefetching in
heapam.c. Prefetching is not just applied to favorable blocks, though
-- it's applied to all the blocks that we might visit, even though we
often won't really visit the last few blocks in line. This needs more
testing. The specific choices I made around prefetching were
definitely a bit arbitrary. To be honest, it was a bit of a
box-ticking thing (parity with similar code for its own sake). But
maybe I failed to consider particular scenarios in which prefetching
really is important.
My high level goal for v9 was to do cleanup of v8. There isn't very
much that you could call a new enhancement (just the prefetching
thing).
Other changes in v9 include:
* Much simpler approach to passing down an aminsert() hint from the
executor in v9-0002* patch.
Rather than exposing some HOT implementation details from
heap_update(), we use executor state that tracks updated columns. Now
all we have to do is tell ExecInsertIndexTuples() "this round of index
tuple inserts is for an UPDATE statement". It then figures out the
specific details (whether it passes the hint or not) on an index by
index basis. This interface feels much more natural to me.
This also made it easy to handle expression indexes sensibly. And, we
get support for the logical replication UPDATE caller to
ExecInsertIndexTuples(). It only has to say "this is for an UPDATE",
in the usual way, without any special effort (actually I need to test
logical replication, just to be sure, but I think that it works fine
in v9).
* New B-Tree sgml documentation in v9-0003* patch. I've added an
extensive user-facing description of the feature to the end of
"Chapter 64. B-Tree Indexes", near the existing discussion of
deduplication.
* New delete_items storage parameter. This makes it possible to
disable the optimization. Like deduplicate_items in Postgres 13, it is
not expected to be set to "off" very often.
I'm not yet 100% sure that a storage parameter is truly necessary -- I
might still change my mind and remove it later.
Thanks
--
Peter Geoghegan
Attachments:
[application/octet-stream] v9-0001-Make-tableam-interface-support-bottom-up-deletion.patch (7.8K, ../../CAH2-WzmFsqz_dbFCv1+jhdA8C_e3JcnnR=wh0=HD3imY-MbyXQ@mail.gmail.com/2-v9-0001-Make-tableam-interface-support-bottom-up-deletion.patch)
download | inline diff:
From 09c4ccf9f02e1a3b1e00e696ad7da1a96a4da0aa Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Mon, 9 Nov 2020 12:59:29 -0800
Subject: [PATCH v9 1/4] Make tableam interface support bottom-up deletion.
Teach tableam about bottom-up index deletion. This mechanism allows an
index AM to cooperate with a tableam in deleting index tuples at regular
intervals. The general idea is to avoid accumulating too many versions
in the index for any given logically row, without doing any extra work
before the situation gets out of hand at a localized page in an index.
This commit isn't useful on its own. An upcoming commit will add
support to nbtree. A further commit will provide complete functionality
by adding support to heapam.
Author: Peter Geoghegan <[email protected]>
Reviewed-By: Victor Yegorov <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wzm+maE3apHB8NOtmM=p-DO65j2V5GzAWCOEEuy3JZgb2g@mail.gmail.com
---
src/include/access/tableam.h | 99 ++++++++++++++++++++++++
src/backend/access/heap/heapam_handler.c | 1 +
src/backend/access/table/tableam.c | 6 +-
3 files changed, 103 insertions(+), 3 deletions(-)
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 387eb34a61..5cd698c885 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -128,6 +128,75 @@ typedef struct TM_FailureData
bool traversed;
} TM_FailureData;
+/*
+ * State used when calling table_index_delete_check() to perform "bottom up"
+ * deletion of duplicate index tuples. State is intialized by index AM
+ * caller, while state is finalized by tableam, which modifies state.
+ */
+typedef struct TM_IndexDelete
+{
+ ItemPointerData tid; /* table TID from index tuple */
+ int16 id; /* Offset into TM_IndexStatus array */
+} TM_IndexDelete;
+
+typedef struct TM_IndexStatus
+{
+ OffsetNumber idxoffnum; /* Index am page offset number */
+ int16 tupsize; /* Space freed in index if tuple deleted */
+ bool ispromising; /* Is a duplicate within index? */
+ bool deleteitup; /* Was tableam tuple found dead? */
+} TM_IndexStatus;
+
+/*
+ * State representing one single bottom-up index deletion operation.
+ *
+ * Index am caller provides a TM_IndexDeleteOp, which points to two palloc()'d
+ * arrays. Each array has one entry per TID that the tableam is asked to
+ * consider (typically these are all of the TIDs from a single index page, so
+ * there could be hundreds or even thousand of entries in arrays). ndeltids
+ * tracks the current number of entries.
+ *
+ * The two arrays are conceptually one single array. Two arrays/structs are
+ * used for performance reasons. (We really need to keep the TM_IndexDelete
+ * struct small so that the tableam can do an initial sort by TID as quickly
+ * as possible.)
+ *
+ * The index AM should keep track of which index tuple relates to which entry
+ * by setting idxoffnum (and/or relying on each entry being uniquely
+ * identifiable using tid). Index AM requests target free space indicated by
+ * "targetfreespace". Index AM also represents the space saving for each TID
+ * by filling in the tupsize for each array element. The tableam must balance
+ * the requirements of the index AM against the costs paid in the tableam.
+ *
+ * The index AM provides strong hints about where to look to the tableam by
+ * marking some entries as "promising". Index AM does this with duplicate
+ * index tuples that are strongly suspected to be old versions left behind by
+ * UPDATEs that did not logically changed any indexed values. Index AM may
+ * find it helpful to only mark TIDs/entries as promising when they're thought
+ * to have been affected by such an UPDATE in the recent past.
+ *
+ * The tableam marks individual entries as deletable for the index AM. It's
+ * common for the final array to be shrunk in size. The index AM caller
+ * should do nothing if on return delstate.ndeltids is found set to zero. The
+ * index AM caller only needs to consider the first ndeltids from the final
+ * array, which is typically much smaller than its original size (tableam
+ * updates ndeltids in state). One reason for this is that the tableam can
+ * naturally only afford to a few tableam blocks on each call -- it typically
+ * won't even try to check most of the entries from the tableam.
+ *
+ * The tableam typically sorts the delstate.deltids array by TID. The index
+ * AM should be prepared to restore the array to its useful/original order.
+ * The array is typically far smaller than its original size by then, so that
+ * step should be relatively fast.
+ */
+typedef struct TM_IndexDeleteOp
+{
+ int ndeltids; /* Number of deltids/status for op */
+ TM_IndexDelete *deltids;
+ TM_IndexStatus *status;
+ int targetfreespace; /* Guides tableam on requirements */
+} TM_IndexDeleteOp;
+
/* "options" flag bits for table_tuple_insert */
/* TABLE_INSERT_SKIP_WAL was 0x0001; RelationNeedsWAL() now governs */
#define TABLE_INSERT_SKIP_FSM 0x0002
@@ -409,6 +478,17 @@ typedef struct TableAmRoutine
uint8 flags,
TM_FailureData *tmfd);
+ /*
+ * Help index AMs to perform bottom-up index deletion.
+ *
+ * Optional callback. See TM_IndexDeleteOp struct for full details.
+ *
+ * Returns a latestRemovedXid transaction ID that index AM must use to
+ * generate a recovery conflict when required.
+ */
+ TransactionId (*index_delete_check) (Relation rel,
+ TM_IndexDeleteOp *delstate);
+
/*
* Perform operations necessary to complete insertions made via
* tuple_insert and multi_insert with a BulkInsertState specified. In-tree
@@ -1363,6 +1443,25 @@ table_tuple_lock(Relation rel, ItemPointer tid, Snapshot snapshot,
flags, tmfd);
}
+/*
+ * Bottom-up index deletion interface for index AMs.
+ *
+ * Sets deletable tuples in entries from caller's TM_IndexDeleteOp state that
+ * are found to point to already-dead tuples in the tableam structure.
+ *
+ * See TM_IndexDeleteOp struct for full details.
+ */
+static inline TransactionId
+table_index_delete_check(Relation rel, TM_IndexDeleteOp *delstate)
+{
+ /* optional callback */
+ if (rel->rd_tableam && rel->rd_tableam->index_delete_check)
+ return rel->rd_tableam->index_delete_check(rel, delstate);
+
+ delstate->ndeltids = 0;
+ return InvalidTransactionId;
+}
+
/*
* Perform operations necessary to complete insertions made via
* tuple_insert and multi_insert with a BulkInsertState specified.
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index dcaea7135f..a08c494034 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2532,6 +2532,7 @@ static const TableAmRoutine heapam_methods = {
.tuple_delete = heapam_tuple_delete,
.tuple_update = heapam_tuple_update,
.tuple_lock = heapam_tuple_lock,
+ .index_delete_check = NULL,
.tuple_fetch_row_version = heapam_fetch_row_version,
.tuple_get_latest_tid = heap_get_latest_tid,
diff --git a/src/backend/access/table/tableam.c b/src/backend/access/table/tableam.c
index 6438c45716..e19bdd246a 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -207,9 +207,9 @@ table_beginscan_parallel(Relation relation, ParallelTableScanDesc parallel_scan)
/*
* To perform that check simply start an index scan, create the necessary
* slot, do the heap lookup, and shut everything down again. This could be
- * optimized, but is unlikely to matter from a performance POV. If there
- * frequently are live index pointers also matching a unique index key, the
- * CPU overhead of this routine is unlikely to matter.
+ * optimized, but is unlikely to matter from a performance POV. Note that
+ * table_index_delete_check() is optimized in this way, since it is designed
+ * as a batch operation.
*
* Note that *tid may be modified when we return true if the AM supports
* storing multiple row versions reachable via a single index entry (like
--
2.25.1
[application/octet-stream] v9-0002-Pass-down-logically-unchanged-index-hint.patch (28.6K, ../../CAH2-WzmFsqz_dbFCv1+jhdA8C_e3JcnnR=wh0=HD3imY-MbyXQ@mail.gmail.com/3-v9-0002-Pass-down-logically-unchanged-index-hint.patch)
download | inline diff:
From b4f8c4c693bc9f4c6b451d347e57a11d65dfd8c7 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Mon, 9 Nov 2020 12:59:30 -0800
Subject: [PATCH v9 2/4] Pass down "logically unchanged index" hint.
Add an executor aminsert() hinting mechanism that informs index AMs that
the incoming index tuple (the tuple that accompanies the hint) is not
being inserted because of a logical change to indexed columns (from an
UPDATE or INSERT statement). This "logically unchanged" hint indicates
that the incoming item must be a duplicate of some existing item in the
index (a physical tuple that represents an obsolescent version of the
logical row affected by an UPDATE). When this happens the new tuple is
only needed so that the index will have a separate entry for the latest
logical row (it's latest version/HOT chain).
An aminsert() call which gets the hint is fundamentally different to any
aminsert() call needed for an INSERT statement. It's also fundamentally
difference to an aminsert() call needed for an UPDATE statement where
the index is logically changed by the UPDATE. Recognizing this
difference can allow cleanup of garbage tuples in index access methods
to work better. Cleanup can intelligently target tuples that are likely
to be garbage, without wasting too many cycles on less promising tuples.
This commit is infrastructure for an upcoming commit that will teach
nbtree to perform bottom-up index deletion. No index AM applies the
hint at this point. It is not useful on its own.
Author: Peter Geoghegan <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wz=CEKFa74EScx_hFVshCOn6AA5T-ajFASTdzipdkLTNQQ@mail.gmail.com
---
src/include/access/amapi.h | 1 +
src/include/access/brin_internal.h | 1 +
src/include/access/genam.h | 1 +
src/include/access/gin_private.h | 1 +
src/include/access/gist_private.h | 1 +
src/include/access/hash.h | 1 +
src/include/access/nbtree.h | 1 +
src/include/access/spgist.h | 1 +
src/include/executor/executor.h | 1 +
src/backend/access/brin/brin.c | 1 +
src/backend/access/common/toast_internals.c | 2 +-
src/backend/access/gin/gininsert.c | 1 +
src/backend/access/gist/gist.c | 1 +
src/backend/access/hash/hash.c | 1 +
src/backend/access/heap/heapam_handler.c | 1 +
src/backend/access/index/indexam.c | 4 +-
src/backend/access/nbtree/nbtree.c | 1 +
src/backend/access/spgist/spginsert.c | 1 +
src/backend/catalog/indexing.c | 1 +
src/backend/commands/constraint.c | 2 +-
src/backend/commands/copy.c | 5 +-
src/backend/commands/trigger.c | 6 +-
src/backend/executor/execIndexing.c | 151 +++++++++++++++++-
src/backend/executor/execMain.c | 8 +-
src/backend/executor/execReplication.c | 8 +-
src/backend/executor/nodeModifyTable.c | 6 +-
contrib/bloom/blinsert.c | 1 +
contrib/bloom/bloom.h | 1 +
doc/src/sgml/indexam.sgml | 15 ++
.../modules/dummy_index_am/dummy_index_am.c | 1 +
30 files changed, 203 insertions(+), 24 deletions(-)
diff --git a/src/include/access/amapi.h b/src/include/access/amapi.h
index 85b4766016..499119468d 100644
--- a/src/include/access/amapi.h
+++ b/src/include/access/amapi.h
@@ -110,6 +110,7 @@ typedef bool (*aminsert_function) (Relation indexRelation,
ItemPointer heap_tid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
/* bulk delete */
diff --git a/src/include/access/brin_internal.h b/src/include/access/brin_internal.h
index 9ffc9100c0..74a0e7eb29 100644
--- a/src/include/access/brin_internal.h
+++ b/src/include/access/brin_internal.h
@@ -91,6 +91,7 @@ extern void brinbuildempty(Relation index);
extern bool brininsert(Relation idxRel, Datum *values, bool *nulls,
ItemPointer heaptid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
extern IndexScanDesc brinbeginscan(Relation r, int nkeys, int norderbys);
extern int64 bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
diff --git a/src/include/access/genam.h b/src/include/access/genam.h
index 68d90f5141..bf2c2278d9 100644
--- a/src/include/access/genam.h
+++ b/src/include/access/genam.h
@@ -143,6 +143,7 @@ extern bool index_insert(Relation indexRelation,
ItemPointer heap_t_ctid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
extern IndexScanDesc index_beginscan(Relation heapRelation,
diff --git a/src/include/access/gin_private.h b/src/include/access/gin_private.h
index 5cb2f72e4c..ff60f5708e 100644
--- a/src/include/access/gin_private.h
+++ b/src/include/access/gin_private.h
@@ -116,6 +116,7 @@ extern void ginbuildempty(Relation index);
extern bool gininsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
extern void ginEntryInsert(GinState *ginstate,
OffsetNumber attnum, Datum key, GinNullCategory category,
diff --git a/src/include/access/gist_private.h b/src/include/access/gist_private.h
index b68c01a5f2..09f9ad6d95 100644
--- a/src/include/access/gist_private.h
+++ b/src/include/access/gist_private.h
@@ -403,6 +403,7 @@ extern void gistbuildempty(Relation index);
extern bool gistinsert(Relation r, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
extern MemoryContext createTempGistContext(void);
extern GISTSTATE *initGISTstate(Relation index);
diff --git a/src/include/access/hash.h b/src/include/access/hash.h
index bab4d9f1b0..d5e65ff2be 100644
--- a/src/include/access/hash.h
+++ b/src/include/access/hash.h
@@ -364,6 +364,7 @@ extern void hashbuildempty(Relation index);
extern bool hashinsert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
extern bool hashgettuple(IndexScanDesc scan, ScanDirection dir);
extern int64 hashgetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index e8fecc6026..3b60e696eb 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -996,6 +996,7 @@ extern void btbuildempty(Relation index);
extern bool btinsert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
extern IndexScanDesc btbeginscan(Relation rel, int nkeys, int norderbys);
extern Size btestimateparallelscan(void);
diff --git a/src/include/access/spgist.h b/src/include/access/spgist.h
index 9f2ccc1730..544f240d1f 100644
--- a/src/include/access/spgist.h
+++ b/src/include/access/spgist.h
@@ -199,6 +199,7 @@ extern void spgbuildempty(Relation index);
extern bool spginsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
/* spgscan.c */
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h
index 0c48d2a519..c8185bf8ce 100644
--- a/src/include/executor/executor.h
+++ b/src/include/executor/executor.h
@@ -581,6 +581,7 @@ extern void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative);
extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
extern List *ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot, EState *estate,
+ bool update,
bool noDupErr,
bool *specConflict, List *arbiterIndexes);
extern bool ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo,
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index 1f72562c60..bea078944c 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -151,6 +151,7 @@ bool
brininsert(Relation idxRel, Datum *values, bool *nulls,
ItemPointer heaptid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
BlockNumber pagesPerRange;
diff --git a/src/backend/access/common/toast_internals.c b/src/backend/access/common/toast_internals.c
index 25a81e5ec6..e206e67756 100644
--- a/src/backend/access/common/toast_internals.c
+++ b/src/backend/access/common/toast_internals.c
@@ -328,7 +328,7 @@ toast_save_datum(Relation rel, Datum value,
toastrel,
toastidxs[i]->rd_index->indisunique ?
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
- NULL);
+ false, NULL);
}
/*
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index 77433dc8a4..7fa880fc6c 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -488,6 +488,7 @@ bool
gininsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
GinState *ginstate = (GinState *) indexInfo->ii_AmCache;
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index 25b42e38f2..1fb145c891 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -156,6 +156,7 @@ bool
gistinsert(Relation r, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
GISTSTATE *giststate = (GISTSTATE *) indexInfo->ii_AmCache;
diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c
index 7c9ccf446c..7da8b892f4 100644
--- a/src/backend/access/hash/hash.c
+++ b/src/backend/access/hash/hash.c
@@ -247,6 +247,7 @@ bool
hashinsert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
Datum index_values[1];
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index a08c494034..bba68e6898 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -1931,6 +1931,7 @@ heapam_index_validate_scan(Relation heapRelation,
heapRelation,
indexInfo->ii_Unique ?
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
+ false,
indexInfo);
state->tups_inserted += 1;
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index 3fb8688f8f..9ad1a18a31 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -179,6 +179,7 @@ index_insert(Relation indexRelation,
ItemPointer heap_t_ctid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
RELATION_CHECKS;
@@ -191,7 +192,8 @@ index_insert(Relation indexRelation,
return indexRelation->rd_indam->aminsert(indexRelation, values, isnull,
heap_t_ctid, heapRelation,
- checkUnique, indexInfo);
+ checkUnique, indexUnchanged,
+ indexInfo);
}
/*
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index c4f22f1c69..d6c8ad5d27 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -199,6 +199,7 @@ bool
btinsert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
bool result;
diff --git a/src/backend/access/spgist/spginsert.c b/src/backend/access/spgist/spginsert.c
index e4508a2b92..dcffb76e16 100644
--- a/src/backend/access/spgist/spginsert.c
+++ b/src/backend/access/spgist/spginsert.c
@@ -207,6 +207,7 @@ bool
spginsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
SpGistState spgstate;
diff --git a/src/backend/catalog/indexing.c b/src/backend/catalog/indexing.c
index 538f6a06b8..3e577dd183 100644
--- a/src/backend/catalog/indexing.c
+++ b/src/backend/catalog/indexing.c
@@ -162,6 +162,7 @@ CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
heapRelation,
index->rd_index->indisunique ?
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
+ false,
indexInfo);
}
diff --git a/src/backend/commands/constraint.c b/src/backend/commands/constraint.c
index fc19307bf2..79bd12b7de 100644
--- a/src/backend/commands/constraint.c
+++ b/src/backend/commands/constraint.c
@@ -175,7 +175,7 @@ unique_key_recheck(PG_FUNCTION_ARGS)
*/
index_insert(indexRel, values, isnull, &checktid,
trigdata->tg_relation, UNIQUE_CHECK_EXISTING,
- indexInfo);
+ false, indexInfo);
}
else
{
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 115860a9d4..94005d8e53 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -2522,8 +2522,8 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
cstate->cur_lineno = buffer->linenos[i];
recheckIndexes =
ExecInsertIndexTuples(resultRelInfo,
- buffer->slots[i], estate, false, NULL,
- NIL);
+ buffer->slots[i], estate, false, false,
+ NULL, NIL);
ExecARInsertTriggers(estate, resultRelInfo,
slots[i], recheckIndexes,
cstate->transition_capture);
@@ -3267,6 +3267,7 @@ CopyFrom(CopyState cstate)
myslot,
estate,
false,
+ false,
NULL,
NIL);
}
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index c336b238aa..8c663fcda5 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -71,10 +71,8 @@ int SessionReplicationRole = SESSION_REPLICATION_ROLE_ORIGIN;
static int MyTriggerDepth = 0;
/*
- * Note that similar macros also exist in executor/execMain.c. There does not
- * appear to be any good header to put them into, given the structures that
- * they use, so we let them be duplicated. Be sure to update all if one needs
- * to be changed, however.
+ * The authoritative version of this macro is in executor/execMain.c. Be sure
+ * to keep everything in sync.
*/
#define GetAllUpdatedColumns(relinfo, estate) \
(bms_union(exec_rt_fetch((relinfo)->ri_RangeTableIndex, estate)->updatedCols, \
diff --git a/src/backend/executor/execIndexing.c b/src/backend/executor/execIndexing.c
index c6b5bcba7b..c9efb3941a 100644
--- a/src/backend/executor/execIndexing.c
+++ b/src/backend/executor/execIndexing.c
@@ -124,6 +124,14 @@ typedef enum
CEOUC_LIVELOCK_PREVENTING_WAIT
} CEOUC_WAIT_MODE;
+/*
+ * The authoritative version of this macro is in executor/execMain.c. Be sure
+ * to keep everything in sync.
+ */
+#define GetAllUpdatedColumns(relinfo, estate) \
+ (bms_union(exec_rt_fetch((relinfo)->ri_RangeTableIndex, estate)->updatedCols, \
+ exec_rt_fetch((relinfo)->ri_RangeTableIndex, estate)->extraUpdatedCols))
+
static bool check_exclusion_or_unique_constraint(Relation heap, Relation index,
IndexInfo *indexInfo,
ItemPointer tupleid,
@@ -136,6 +144,11 @@ static bool check_exclusion_or_unique_constraint(Relation heap, Relation index,
static bool index_recheck_constraint(Relation index, Oid *constr_procs,
Datum *existing_values, bool *existing_isnull,
Datum *new_values);
+static bool index_unchanged_by_update(IndexInfo *indexInfo,
+ Relation indexRelation,
+ Bitmapset *updatedCols);
+static bool index_unchanged_by_update_var_walker(Node *node,
+ Bitmapset *updatedCols);
/* ----------------------------------------------------------------
* ExecOpenIndices
@@ -254,6 +267,16 @@ ExecCloseIndices(ResultRelInfo *resultRelInfo)
* into all the relations indexing the result relation
* when a heap tuple is inserted into the result relation.
*
+ * When 'update' is true, executor is performing an UPDATE
+ * that could not use an optimization like heapam's HOT (in
+ * more general terms a call to table_tuple_update() took
+ * place and set 'update_indexes' to true). Receiving this
+ * hint makes us consider if we should pass down the
+ * 'indexUnchanged' hint in turn. That's something that we
+ * figure out for each index_insert() call iff 'update' is
+ * true. (When 'update' is false we already know not to pass
+ * the hint to any index.)
+ *
* Unique and exclusion constraints are enforced at the same
* time. This returns a list of index OIDs for any unique or
* exclusion constraints that are deferred and that had
@@ -263,16 +286,13 @@ ExecCloseIndices(ResultRelInfo *resultRelInfo)
*
* If 'arbiterIndexes' is nonempty, noDupErr applies only to
* those indexes. NIL means noDupErr applies to all indexes.
- *
- * CAUTION: this must not be called for a HOT update.
- * We can't defend against that here for lack of info.
- * Should we change the API to make it safer?
* ----------------------------------------------------------------
*/
List *
ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot,
EState *estate,
+ bool update,
bool noDupErr,
bool *specConflict,
List *arbiterIndexes)
@@ -287,6 +307,7 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
ExprContext *econtext;
Datum values[INDEX_MAX_KEYS];
bool isnull[INDEX_MAX_KEYS];
+ Bitmapset *updatedCols = NULL;
Assert(ItemPointerIsValid(tupleid));
@@ -310,6 +331,10 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
/* Arrange for econtext's scan tuple to be the tuple under test */
econtext->ecxt_scantuple = slot;
+ /* Calculate updated columns when needed */
+ if (update)
+ updatedCols = GetAllUpdatedColumns(resultRelInfo, estate);
+
/*
* for each index, form and insert the index tuple
*/
@@ -319,6 +344,7 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
IndexInfo *indexInfo;
bool applyNoDupErr;
IndexUniqueCheck checkUnique;
+ bool indexUnchanged;
bool satisfiesConstraint;
if (indexRelation == NULL)
@@ -389,6 +415,15 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
else
checkUnique = UNIQUE_CHECK_PARTIAL;
+ /*
+ * There's definitely going to be an index_insert() call for this
+ * index. If we're being called as part of an UPDATE statement,
+ * consider if the 'indexUnchanged' = true hint should be passed.
+ */
+ indexUnchanged = update && index_unchanged_by_update(indexInfo,
+ indexRelation,
+ updatedCols);
+
satisfiesConstraint =
index_insert(indexRelation, /* index relation */
values, /* array of index Datums */
@@ -396,6 +431,7 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
tupleid, /* tid of heap tuple */
heapRelation, /* heap relation */
checkUnique, /* type of uniqueness check to do */
+ indexUnchanged, /* UPDATE without logical change? */
indexInfo); /* index AM may need this */
/*
@@ -457,6 +493,9 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
}
}
+ if (update)
+ bms_free(updatedCols);
+
return result;
}
@@ -899,3 +938,107 @@ index_recheck_constraint(Relation index, Oid *constr_procs,
return true;
}
+
+/*
+ * Check if ExecInsertIndexTuples() should pass indexUnchanged hint.
+ *
+ * When the executor performs an UPDATE that requires a new round of index
+ * tuples, determine if we should pass 'indexUnchanged' = true hint for one
+ * single index.
+ */
+static bool
+index_unchanged_by_update(IndexInfo *indexInfo, Relation indexRelation,
+ Bitmapset *updatedCols)
+{
+ bool hasexpression = false;
+ bool found;
+ List *idxExprs;
+
+ /*
+ * Check for indexed attribute overlap with updated columns.
+ *
+ * Only do this for key columns. A change to a non-key column within an
+ * INCLUDE index should not be considered because that's just payload to
+ * the index (they're not unlike table TIDs to the index AM).
+ */
+ for (int attr = 0; attr < indexInfo->ii_NumIndexKeyAttrs; attr++)
+ {
+ int keycol = indexInfo->ii_IndexAttrNumbers[attr];
+
+ if (keycol <= 0)
+ {
+ /*
+ * Skip expressions for now, but remember to deal with them later
+ * on
+ */
+ hasexpression = true;
+ continue;
+ }
+
+ if (bms_is_member(keycol - FirstLowInvalidHeapAttributeNumber,
+ updatedCols))
+ {
+ /* Changed key column -- don't hint for this index */
+ return false;
+ }
+ }
+
+ /*
+ * When we get this far and index has no expressions, return true so that
+ * index_insert() call will go on to pass 'indexUnchanged' = true hint.
+ *
+ * The _absence_ of an indexed key attribute that overlaps with updated
+ * attributes (in addition to the total absence of indexed expressions)
+ * shows that the index as a whole is logically unchanged by UPDATE.
+ */
+ if (!hasexpression)
+ return true;
+
+ /*
+ * We have to work slightly harder in the event of indexed expressions,
+ * but the principle is the same as before: try to find columns (Vars,
+ * actually) that overlap with known-updated columns.
+ *
+ * If we find any matching Vars, don't pass hint for index. Otherwise
+ * pass hint.
+ */
+ idxExprs = RelationGetIndexExpressions(indexRelation);
+ found = index_unchanged_by_update_var_walker((Node *) idxExprs,
+ updatedCols);
+ list_free(idxExprs);
+
+ if (found)
+ return false;
+
+ return true;
+}
+
+/*
+ * Indexed expression helper for index_unchanged_by_update().
+ *
+ * Returns true when Var that appears within updatedCols located.
+ */
+static bool
+index_unchanged_by_update_var_walker(Node *node, Bitmapset *updatedCols)
+{
+ if (node == NULL)
+ return false;
+
+ if (IsA(node, Var))
+ {
+ Var *var = (Var *) node;
+
+ if (bms_is_member(var->varattno - FirstLowInvalidHeapAttributeNumber,
+ updatedCols))
+ {
+ /* Var was updated -- indicates that we should not hint */
+ return true;
+ }
+
+ /* Still haven't found a reason to not pass the hint */
+ return false;
+ }
+
+ return expression_tree_walker(node, index_unchanged_by_update_var_walker,
+ (void *) updatedCols);
+}
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 7179f589f9..ae9e7d4c60 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -101,10 +101,10 @@ static char *ExecBuildSlotValueDescription(Oid reloid,
static void EvalPlanQualStart(EPQState *epqstate, Plan *planTree);
/*
- * Note that GetAllUpdatedColumns() also exists in commands/trigger.c. There does
- * not appear to be any good header to put it into, given the structures that
- * it uses, so we let them be duplicated. Be sure to update both if one needs
- * to be changed, however.
+ * Note that GetAllUpdatedColumns() also exists in commands/trigger.c and in
+ * execIndexing.c. There does not appear to be any good header to put it
+ * into, given the structures that it uses, so we let them be duplicated. Be
+ * sure to keep everything in sync.
*/
#define GetInsertedColumns(relinfo, estate) \
(exec_rt_fetch((relinfo)->ri_RangeTableIndex, estate)->insertedCols)
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index 01d26881e7..1be26f84d9 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -444,8 +444,8 @@ ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
- slot, estate, false, NULL,
- NIL);
+ slot, estate, false, false,
+ NULL, NIL);
/* AFTER ROW INSERT Triggers */
ExecARInsertTriggers(estate, resultRelInfo, slot,
@@ -512,8 +512,8 @@ ExecSimpleRelationUpdate(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
- slot, estate, false, NULL,
- NIL);
+ slot, estate, true, false,
+ NULL, NIL);
/* AFTER ROW UPDATE Triggers */
ExecARUpdateTriggers(estate, resultRelInfo,
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 29e07b7228..1546a2cfb4 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -599,7 +599,7 @@ ExecInsert(ModifyTableState *mtstate,
/* insert index entries for tuple */
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
- slot, estate, true,
+ slot, estate, false, true,
&specConflict,
arbiterIndexes);
@@ -640,7 +640,7 @@ ExecInsert(ModifyTableState *mtstate,
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false,
- NULL, NIL);
+ false, NULL, NIL);
}
}
@@ -1514,7 +1514,7 @@ lreplace:;
/* insert index entries for tuple if necessary */
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
- slot, estate, false,
+ slot, estate, true, false,
NULL, NIL);
}
diff --git a/contrib/bloom/blinsert.c b/contrib/bloom/blinsert.c
index 6d3fd5c432..ce4e7486e9 100644
--- a/contrib/bloom/blinsert.c
+++ b/contrib/bloom/blinsert.c
@@ -198,6 +198,7 @@ bool
blinsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
BloomState blstate;
diff --git a/contrib/bloom/bloom.h b/contrib/bloom/bloom.h
index 23aa7ac441..59ae83d7aa 100644
--- a/contrib/bloom/bloom.h
+++ b/contrib/bloom/bloom.h
@@ -192,6 +192,7 @@ extern bool blvalidate(Oid opclassoid);
extern bool blinsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
extern IndexScanDesc blbeginscan(Relation r, int nkeys, int norderbys);
extern int64 blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
diff --git a/doc/src/sgml/indexam.sgml b/doc/src/sgml/indexam.sgml
index f00268d5b5..ec5741df6d 100644
--- a/doc/src/sgml/indexam.sgml
+++ b/doc/src/sgml/indexam.sgml
@@ -293,6 +293,7 @@ aminsert (Relation indexRelation,
ItemPointer heap_tid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo);
</programlisting>
Insert a new tuple into an existing index. The <literal>values</literal> and
@@ -308,6 +309,20 @@ aminsert (Relation indexRelation,
look into the heap to verify tuple liveness).
</para>
+ <para>
+ The <literal>indexUnchanged</literal> boolean value gives a hint
+ about the nature of the tuple to be indexed. When it is true,
+ the tuple is a duplicate of some existing tuple in the index. The
+ new tuple is a logically unchanged successor MVCC tuple version. This
+ happens when an <command>UPDATE</command> takes place that does not
+ modify any columns covered by the index, but nevertheless requires a
+ new version in the index. The index AM may use this hint to decide
+ to apply bottom-up index deletion in parts of the index where many
+ versions of the same logical row accumulate. Note that updating a
+ non-key column does not affect the value of
+ <literal>indexUnchanged</literal>.
+ </para>
+
<para>
The function's Boolean result value is significant only when
<literal>checkUnique</literal> is <literal>UNIQUE_CHECK_PARTIAL</literal>.
diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c
index 8f4cdab1b3..bcd0b48bf0 100644
--- a/src/test/modules/dummy_index_am/dummy_index_am.c
+++ b/src/test/modules/dummy_index_am/dummy_index_am.c
@@ -168,6 +168,7 @@ static bool
diinsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
/* nothing to do */
--
2.25.1
[application/octet-stream] v9-0003-Teach-nbtree-to-use-bottom-up-index-deletion.patch (68.6K, ../../CAH2-WzmFsqz_dbFCv1+jhdA8C_e3JcnnR=wh0=HD3imY-MbyXQ@mail.gmail.com/4-v9-0003-Teach-nbtree-to-use-bottom-up-index-deletion.patch)
download | inline diff:
From 42b9b24968032dfa6d88166281dc56a0025816e1 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Mon, 9 Nov 2020 12:59:30 -0800
Subject: [PATCH v9 3/4] Teach nbtree to use bottom-up index deletion.
Teach nbtree to eagerly delete duplicate of tuples representing old
versions in the event of a localized flood of version churn. This
situation is detected using heuristics, including the recently added
"index is logically unchanged by an UPDATE" executor hint.
This commit alone changes very little about how nbtree behaves. We
still lack tableam-side support. An upcoming commit that adds support
for bottom-up index deletion to heapam will follow, completing the
picture.
The immediate goal of bottom-up index deletion in nbtree is to avoid
"unnecessary" page splits caused entirely by duplicates needed only for
MVCC/versioning purposes. It naturally has an even more useful effect,
though: it acts as a backstop against accumulating an excessive number
of index tuple versions for any given _logical row_. Note that the
relationship between this localized condition and the proportion of
garbage tuples in the entire index is very loose, and can be very
volatile. Bottom-up index deletion complements what we might now call
"top-down index deletion": index vacuuming performed by VACUUM. It
responds to the immediate local needs of queries, while leaving it up to
autovacuum to perform infrequent clean sweeps of the index.
Bottom-up index deletion is very effective despite not changing anything
about the fundamental invariants for Postgres index access methods in
general (and despite not changing any invariants for nbtree in
particular). That is, it is still inherently necessary to keep around
multiple versions together on the same leaf page, at least in some cases
(no change there). But nothing forbids us from being proactive in
keeping the number of tuples for any given logical row under control, if
and when that seems to makes sense at the page/local level. In practice
it is seldom strictly necessary to have more than a couple of physical
index tuple versions present for any given logical row.
You can think of bottom-up index deletion as bringing the effectiveness
of garbage collection in nbtree far closer to the true theoretical
limits imposed on it by the core system. In practice nbtree could fall
significantly short of this ideal before now, often in ways that could
not easily be predicted or reasoned about, and often in the absence of
obvious stressors (like very long running transactions that hold open an
MVCC snapshot). This may not have happened in production all that
often, but when it happened it had a significant impact on query
latency, often at the most inconvenient time possible.
Bottom-up deletion uses the same WAL record that we use when deleting
LP_DEAD items (the xl_btree_delete record). This commit extends
_bt_delitems_delete() to support granular TID deletion in posting list
tuples, and to support a caller-supplied latestRemovedXid. Only its
bottom-up index deletion caller makes use of these new facilities.
Bump XLOG_PAGE_MAGIC because xl_btree_delete changed.
No bump in BTREE_VERSION, since there are no changes to the on-disk
representation of nbtree indexes. Indexes built on PostgreSQL 12 or
PostgreSQL 13 will automatically benefit from the optimization (i.e. no
reindexing required) following a pg_upgrade.
Author: Peter Geoghegan <[email protected]>
Reviewed-By: Victor Yegorov <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wzm+maE3apHB8NOtmM=p-DO65j2V5GzAWCOEEuy3JZgb2g@mail.gmail.com
---
src/include/access/nbtree.h | 13 +-
src/include/access/nbtxlog.h | 12 +-
src/backend/access/common/reloptions.c | 10 +
src/backend/access/nbtree/README | 74 +++-
src/backend/access/nbtree/nbtdedup.c | 505 ++++++++++++++++++++++++-
src/backend/access/nbtree/nbtinsert.c | 84 +++-
src/backend/access/nbtree/nbtpage.c | 242 ++++++++----
src/backend/access/nbtree/nbtree.c | 2 +-
src/backend/access/nbtree/nbtutils.c | 9 +-
src/backend/access/nbtree/nbtxlog.c | 51 ++-
src/bin/psql/tab-complete.c | 4 +-
doc/src/sgml/btree.sgml | 109 +++++-
doc/src/sgml/ref/create_index.sgml | 16 +
13 files changed, 1007 insertions(+), 124 deletions(-)
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index 3b60e696eb..b376e1a77a 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -963,6 +963,7 @@ typedef struct BTOptions
/* fraction of newly inserted tuples prior to trigger index cleanup */
float8 vacuum_cleanup_index_scale_factor;
bool deduplicate_items; /* Try to deduplicate items? */
+ bool delete_items; /* Bottom-up delete items? */
} BTOptions;
#define BTGetFillFactor(relation) \
@@ -978,6 +979,11 @@ typedef struct BTOptions
relation->rd_rel->relam == BTREE_AM_OID), \
((relation)->rd_options ? \
((BTOptions *) (relation)->rd_options)->deduplicate_items : true))
+#define BTGetDeleteItems(relation) \
+ (AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
+ relation->rd_rel->relam == BTREE_AM_OID), \
+ ((relation)->rd_options ? \
+ ((BTOptions *) (relation)->rd_options)->delete_items : true))
/*
* Constant definition for progress reporting. Phase numbers must match
@@ -1031,6 +1037,8 @@ extern void _bt_parallel_advance_array_keys(IndexScanDesc scan);
extern void _bt_dedup_pass(Relation rel, Buffer buf, Relation heapRel,
IndexTuple newitem, Size newitemsz,
bool checkingunique);
+extern bool _bt_bottomup_pass(Relation rel, Buffer buf, Relation heapRel,
+ Size newitemsz);
extern void _bt_dedup_start_pending(BTDedupState state, IndexTuple base,
OffsetNumber baseoff);
extern bool _bt_dedup_save_htid(BTDedupState state, IndexTuple itup);
@@ -1045,7 +1053,8 @@ extern IndexTuple _bt_swap_posting(IndexTuple newitem, IndexTuple oposting,
* prototypes for functions in nbtinsert.c
*/
extern bool _bt_doinsert(Relation rel, IndexTuple itup,
- IndexUniqueCheck checkUnique, Relation heapRel);
+ IndexUniqueCheck checkUnique, Relation heapRel,
+ bool indexUnchanged);
extern void _bt_finish_split(Relation rel, Buffer lbuf, BTStack stack);
extern Buffer _bt_getstackbuf(Relation rel, BTStack stack, BlockNumber child);
@@ -1084,7 +1093,9 @@ extern void _bt_delitems_vacuum(Relation rel, Buffer buf,
OffsetNumber *deletable, int ndeletable,
BTVacuumPosting *updatable, int nupdatable);
extern void _bt_delitems_delete(Relation rel, Buffer buf,
+ bool bottomup, TransactionId bottomupXid,
OffsetNumber *deletable, int ndeletable,
+ BTVacuumPosting *updatable, int nupdatable,
Relation heapRel);
extern uint32 _bt_pagedel(Relation rel, Buffer leafbuf,
TransactionId *oldestBtpoXact);
diff --git a/src/include/access/nbtxlog.h b/src/include/access/nbtxlog.h
index 5c014bdc66..994fbe3670 100644
--- a/src/include/access/nbtxlog.h
+++ b/src/include/access/nbtxlog.h
@@ -180,19 +180,23 @@ typedef struct xl_btree_dedup
* This is what we need to know about delete of individual leaf index tuples.
* The WAL record can represent deletion of any number of index tuples on a
* single index page when *not* executed by VACUUM. Deletion of a subset of
- * the TIDs within a posting list tuple is not supported.
+ * the TIDs within a posting list tuple is supported, though only for the
+ * bottom-up index deletion caller.
*
* Backup Blk 0: index page
*/
typedef struct xl_btree_delete
{
TransactionId latestRemovedXid;
- uint32 ndeleted;
+ uint16 ndeleted;
+ uint16 nupdated;
/* DELETED TARGET OFFSET NUMBERS FOLLOW */
+ /* UPDATED TARGET OFFSET NUMBERS FOLLOW */
+ /* UPDATED TUPLES METADATA ARRAY FOLLOWS */
} xl_btree_delete;
-#define SizeOfBtreeDelete (offsetof(xl_btree_delete, ndeleted) + sizeof(uint32))
+#define SizeOfBtreeDelete (offsetof(xl_btree_delete, nupdated) + sizeof(uint16))
/*
* This is what we need to know about page reuse within btree. This record
@@ -213,7 +217,7 @@ typedef struct xl_btree_reuse_page
/*
* This is what we need to know about which TIDs to remove from an individual
* posting list tuple during vacuuming. An array of these may appear at the
- * end of xl_btree_vacuum records.
+ * end of xl_btree_vacuum and xl_btree_delete records.
*/
typedef struct xl_btree_update
{
diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c
index 8ccc228a8c..95e29345de 100644
--- a/src/backend/access/common/reloptions.c
+++ b/src/backend/access/common/reloptions.c
@@ -168,6 +168,16 @@ static relopt_bool boolRelOpts[] =
},
true
},
+ {
+ {
+ "delete_items",
+ "Enables \"bottom-up index deletion\" feature for this btree index",
+ RELOPT_KIND_BTREE,
+ ShareUpdateExclusiveLock /* since it applies only to later
+ * inserts */
+ },
+ true
+ },
/* list terminator */
{{NULL}}
};
diff --git a/src/backend/access/nbtree/README b/src/backend/access/nbtree/README
index 27f555177e..7855392212 100644
--- a/src/backend/access/nbtree/README
+++ b/src/backend/access/nbtree/README
@@ -439,12 +439,14 @@ from the index immediately; since index scans only stop "between" pages,
no scan can lose its place from such a deletion. We separate the steps
because we allow LP_DEAD to be set with only a share lock (it's exactly
like a hint bit for a heap tuple), but physically removing tuples requires
-exclusive lock. In the current code we try to remove LP_DEAD tuples when
-we are otherwise faced with having to split a page to do an insertion (and
-hence have exclusive lock on it already). Deduplication can also prevent
-a page split, but removing LP_DEAD tuples is the preferred approach.
-(Note that posting list tuples can only have their LP_DEAD bit set when
-every table TID within the posting list is known dead.)
+exclusive lock. We try to remove LP_DEAD tuples when we are otherwise
+faced with having to split a page to do an insertion (and hence have
+exclusive lock on it already). Deduplication and bottom-up index deletion
+can also prevent a page split, but removing LP_DEAD tuples is always the
+preferred approach. (Note that posting list tuples can only have their
+LP_DEAD bit set when every table TID within the posting list is known
+dead. This isn't much of a problem because bottom-up deletion supports
+granular deletion of TIDs from posting lists.)
This leaves the index in a state where it has no entry for a dead tuple
that still exists in the heap. This is not a problem for the current
@@ -767,9 +769,10 @@ into a single physical tuple with a posting list (a simple array of heap
TIDs with the standard item pointer format). Deduplication is always
applied lazily, at the point where it would otherwise be necessary to
perform a page split. It occurs only when LP_DEAD items have been
-removed, as our last line of defense against splitting a leaf page. We
-can set the LP_DEAD bit with posting list tuples, though only when all
-TIDs are known dead.
+removed, as our last line of defense against splitting a leaf page
+(bottom-up index deletion may be attempted first, as our second last line
+of defense). We can set the LP_DEAD bit with posting list tuples, though
+only when all TIDs are known dead.
Our lazy approach to deduplication allows the page space accounting used
during page splits to have absolutely minimal special case logic for
@@ -826,6 +829,16 @@ delay a split that is probably inevitable anyway. This allows us to avoid
the overhead of attempting to deduplicate with unique indexes that always
have few or no duplicates.
+Note: Avoiding "unnecessary" page splits driven by version churn is also
+the goal of bottom-up index deletion, which was added to PostgreSQL 14.
+Bottom-up index deletion is now the preferred way to deal with this
+problem (with all kinds of indexes, though especially with unique
+indexes). Still, deduplication can sometimes augment bottom-up index
+deletion. When deletion cannot free tuples (due to an old snapshot
+holding up cleanup), falling back on deduplication provides additional
+capacity. Delaying the page split by deduplicating can allow a future
+bottom-up deletion pass of the same page to succeed.
+
Posting list splits
-------------------
@@ -880,6 +893,49 @@ that need a page split anyway. Besides, supporting variable "split points"
while splitting posting lists won't actually improve overall space
utilization.
+Bottom-up index deletion
+------------------------
+
+We sometimes delete whatever duplicates happen to be present on the page
+before moving on to deduplication. This only happens when we receive a
+hint that optimizations like heapam's HOT have not worked out for the
+index -- the incoming tuple must be a logically unchanged duplicate which
+is needed for MVCC purposes. (Actually it also happens with unique
+indexes in some extra cases that don't get this hint.)
+
+There are certain ways in which this mechanism is similar to on-the-fly
+deletion of index tuples (that will already have failed to prevent a page
+split by the time bottom-up deletion is attempted). For example, the same
+WAL records are used. There are also significant differences. Index
+tuples that get deleted by this mechanism won't have already been marked
+LP_DEAD in passing by queries. Rather, we figure out whether or not
+they're deletable in principle at the last point before splitting a page
+by accessing tableam blocks to get visibility information. We use
+heuristics to access as few tableam blocks as possible while still
+expecting to find a reasonably large number of tuples that are safe to
+delete each time (actually, we outsource much of this to the tableam, that
+understands how all this works pretty well). We expect to perform regular
+bottom-up deletion operations against pages that are at constant risk of
+unnecessary page splits caused only by version churn. When the mechanism
+works well we'll constantly be on the verge of having lots of version
+churn driven page splits, but never actually have any.
+
+Bottom-up index deletion can be thought of as a backstop mechanism against
+unnecessary version-driven page splits. When we have a reasonable
+suspicion that a would-be page split may not actually be necessary, we
+fight back. There is very little to lose and much to gain by spending a
+few cycles to become reasonably sure that it is in fact necessary -- page
+splits are very expensive and practically irreversible. This approach
+works well with a large variety of workloads because we give up before
+spending very many cycles on trying, and because our heuristics are good
+enough to spot unnecessary page splits fairly reliably in practice.
+Unnecessary page splits occur due to pathological amounts of version
+churn. In practice this pathological condition can be detected before too
+long using simple heuristics. We don't have to understand the universe of
+possible workloads; we only have to understand the nature of the
+underlying pathology. We're helped out by additional heuristics within
+tableams such as heapam.
+
Notes About Data Representation
-------------------------------
diff --git a/src/backend/access/nbtree/nbtdedup.c b/src/backend/access/nbtree/nbtdedup.c
index 9e535124c4..deb2fdd8f0 100644
--- a/src/backend/access/nbtree/nbtdedup.c
+++ b/src/backend/access/nbtree/nbtdedup.c
@@ -16,13 +16,17 @@
#include "access/nbtree.h"
#include "access/nbtxlog.h"
+#include "access/tableam.h"
#include "miscadmin.h"
#include "utils/rel.h"
+static void _bt_bottomup_finish_pending(Page page, TM_IndexDeleteOp *delstate,
+ BTDedupState state);
static bool _bt_do_singleval(Relation rel, Page page, BTDedupState state,
OffsetNumber minoff, IndexTuple newitem);
static void _bt_singleval_fillfactor(Page page, BTDedupState state,
Size newitemsz);
+static int _bt_indexdelete_cmp(const void *a, const void *b);
#ifdef USE_ASSERT_CHECKING
static bool _bt_posting_valid(IndexTuple posting);
#endif
@@ -267,6 +271,325 @@ _bt_dedup_pass(Relation rel, Buffer buf, Relation heapRel, IndexTuple newitem,
pfree(state);
}
+/*
+ * Perform bottom-up index deletion pass.
+ *
+ * See if duplicate index tuples are eligible to be deleted by accessing
+ * visibility information from the tableam. Give up if we have to access more
+ * than a few tableam blocks. Caller tries to avoid "unnecessary" page splits
+ * (splits driven only by version churn) by calling here when it looks like
+ * that's about to happen. It's normal for there to be a lot of calls here
+ * for pages that are constantly at risk of an unnecessary split.
+ *
+ * Each failure to delete a duplicate/promising tuple here is a kind of
+ * learning experience. It results in caller falling back on splitting the
+ * page (or on a deduplication pass), discouraging future calls back here for
+ * the same key space range covered by a failed page (or at least discouraging
+ * processing the original duplicates in case where caller falls back on a
+ * successful deduplication pass). We converge on the most effective strategy
+ * for each page in the index over time.
+ *
+ * Returns true on success, in which case caller can assume page split will be
+ * avoided for a reasonable amount of time. Returns false when caller should
+ * deduplicate the page (if possible at all).
+ *
+ * Note: occasionally a true return value does not actually indicate that any
+ * items could be deleted. It might just indicate that caller should not go
+ * on to perform a deduplication pass. Caller is not expected to care about
+ * the difference.
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
+ */
+bool
+_bt_bottomup_pass(Relation rel, Buffer buf, Relation heapRel, Size newitemsz)
+{
+ OffsetNumber offnum,
+ minoff,
+ maxoff,
+ postingidxoffnum;
+ Page page = BufferGetPage(buf);
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+ BTDedupState state;
+ TM_IndexDeleteOp delstate;
+ bool neverdedup = false;
+ TransactionId latestRemovedXid;
+ int ndeletable,
+ nupdatable;
+ OffsetNumber deletable[MaxIndexTuplesPerPage];
+ BTVacuumPosting updatable[MaxIndexTuplesPerPage];
+ int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+
+ /* Fall out fast when tableam lacks table_index_delete_check() support */
+ if (!heapRel->rd_tableam || !heapRel->rd_tableam->index_delete_check)
+ return false;
+
+ /* Passed-in newitemsz is MAXALIGNED but does not include line pointer */
+ newitemsz += sizeof(ItemIdData);
+
+ /* Initialize deduplication state */
+ state = (BTDedupState) palloc(sizeof(BTDedupStateData));
+ state->deduplicate = true;
+ state->nmaxitems = 0;
+ state->maxpostingsize = BLCKSZ; /* "posting list size" not a concern */
+ state->base = NULL;
+ state->baseoff = InvalidOffsetNumber;
+ state->basetupsize = 0;
+ state->htids = palloc(state->maxpostingsize);
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+ state->nintervals = 0;
+
+ /*
+ * Initialize tableam state that describes bottom-up index deletion
+ * operation.
+ *
+ * We will ask tableam to free 1/16 of BLCKSZ. We don't usually expect to
+ * have to free much space each call here in order to avoid page splits.
+ * We don't want to be too aggressive since in general the tableam will
+ * have to access more table blocks when we ask for more free space. In
+ * general we try to be conservative about what we ask for (though not too
+ * conservative), while leaving it up to the tableam to ramp up the number
+ * of tableam blocks accessed when conditions in the table structure
+ * happen to favor it.
+ *
+ * We expect to end up back here again and again for any leaf page that is
+ * more or less constantly at risk of unnecessary page splits -- in fact
+ * that's what happens when bottom-up deletion really helps. We must
+ * avoid thrashing when this becomes very frequent at the level of an
+ * individual page. Our free space target helps with that. It balances
+ * the costs and benefits over time and across related bottom-up deletion
+ * passes.
+ */
+ delstate.ndeltids = 0;
+ delstate.deltids = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexDelete));
+ delstate.status = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexStatus));
+ delstate.targetfreespace = Max(BLCKSZ / 16, newitemsz);
+
+ /* Now remember details of the page in the state we'll pass to tableam */
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
+ for (offnum = minoff;
+ offnum <= maxoff;
+ offnum = OffsetNumberNext(offnum))
+ {
+ ItemId itemid = PageGetItemId(page, offnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+
+ Assert(!ItemIdIsDead(itemid));
+
+ if (offnum == minoff)
+ {
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ else if (_bt_keep_natts_fast(rel, state->base, itup) > nkeyatts &&
+ _bt_dedup_save_htid(state, itup))
+ {
+ /* Tuple is equal; just added its TIDs to pending interval */
+ }
+ else
+ {
+ /* Finalize interval -- move its TIDs to bottom-up state */
+ _bt_bottomup_finish_pending(page, &delstate, state);
+
+ /* itup starts new pending interval */
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ }
+ /* Finalize final interval -- move its TIDs to bottom-up state */
+ _bt_bottomup_finish_pending(page, &delstate, state);
+
+ /*
+ * When there are now duplicates on the page at all, we should not tell
+ * caller to deduplicate later on.
+ *
+ * Note: We accept the possibility that there may be no promising
+ * tuples/duplicates at all (we always finish what we started). The
+ * tableam has its own heuristics that it can fall back on, so it still
+ * has some chance of success.
+ */
+ if (state->nintervals == 0)
+ neverdedup = true;
+
+ /* Done with dedup state */
+ pfree(state->htids);
+ pfree(state);
+
+ /* Now use tableam interface to determine which tuples to delete */
+ latestRemovedXid = table_index_delete_check(heapRel, &delstate);
+
+ if (delstate.ndeltids == 0)
+ {
+ /* The tableam has nothing for us */
+ pfree(delstate.deltids);
+ pfree(delstate.status);
+
+ if (neverdedup)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * By here we know that we have at least one deletable index tuple (or
+ * posting list's TID) in final deltids array. All that remains is to
+ * construct a leaf-page-wise description of what _bt_delitems_delete()
+ * needs to do to physically delete index tuples from the page.
+ *
+ * Sort deltids array (which is typically much smaller now) in the order
+ * expected by loop: the original leaf-page-wise order (the order the
+ * array was in before the tableam sorted it for its own reasons).
+ */
+ qsort(delstate.deltids, delstate.ndeltids, sizeof(TM_IndexDelete),
+ _bt_indexdelete_cmp);
+ postingidxoffnum = InvalidOffsetNumber;
+ ndeletable = 0;
+ nupdatable = 0;
+ for (int i = 0; i < delstate.ndeltids; i++)
+ {
+ TM_IndexStatus *dstatus = delstate.status + delstate.deltids[i].id;
+ OffsetNumber idxoffnum = dstatus->idxoffnum;
+ ItemId itemid = PageGetItemId(page, idxoffnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+ int tidi,
+ nitem;
+ BTVacuumPosting vacposting;
+
+ if (idxoffnum == postingidxoffnum)
+ {
+ /*
+ * This deltid entry is a TID from a posting list tuple that has
+ * already been completely processed (since we process all of a
+ * posting lists TIDs together, once)
+ */
+ Assert(BTreeTupleIsPosting(itup));
+ continue;
+ }
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ /* Plain non-pivot tuple */
+ Assert(ItemPointerEquals(&itup->t_tid, &delstate.deltids[i].tid));
+ if (dstatus->deleteitup)
+ deletable[ndeletable++] = idxoffnum;
+ continue;
+ }
+
+ /*
+ * Posting list tuple. Process all of its TIDs together, at once.
+ *
+ * tidi is a posting-list-tid local iterator for array. We're going
+ * to peak at later entries in deltid array here. Remember to skip
+ * over the itup-related entries that we peak at here later on. We
+ * should not do anything more with them when get back to the top of
+ * the outermost deltids loop (we should just skip them).
+ *
+ * Innermost loop exploits the fact that both itup's TIDs and the
+ * entries from the array (whose TIDs came from itup) are in ascending
+ * TID order. We avoid unnecessary TID comparisons by starting each
+ * execution of the innermost loop at the point where the previous
+ * execution (for previous TID from itup) left off at.
+ */
+ postingidxoffnum = idxoffnum; /* Remember: process itup once only */
+ tidi = i; /* Initialize for itup's first TID */
+ vacposting = NULL; /* Describes what to do with itup */
+ nitem = BTreeTupleGetNPosting(itup);
+ for (int j = 0; j < nitem; j++)
+ {
+ ItemPointer htid = BTreeTupleGetPostingN(itup, j);
+ int cmp = -1;
+
+ for (; tidi < delstate.ndeltids; tidi++)
+ {
+ TM_IndexDelete *tcdeltid = &delstate.deltids[tidi];
+ TM_IndexStatus *tdstatus = (delstate.status + tcdeltid->id);
+
+ /* Stop when we get to first entry beyond itup's entries */
+ Assert(tdstatus->idxoffnum >= idxoffnum);
+ if (tdstatus->idxoffnum != idxoffnum)
+ break;
+
+ /* Skip any non-deletable entries for itup */
+ if (!tdstatus->deleteitup)
+ continue;
+
+ /* Have we found matching deletable entry for htid? */
+ cmp = ItemPointerCompare(htid, &tcdeltid->tid);
+
+ /* Keep going until equal or greater tid from array located */
+ if (cmp <= 0)
+ break;
+ }
+
+ /* Final check on htid: must match a deletable array entry */
+ if (cmp != 0)
+ continue;
+
+ if (vacposting == NULL)
+ {
+ /*
+ * First deletable TID for itup found. Start maintaining
+ * metadata describing which TIDs to delete from itup.
+ */
+ vacposting = palloc(offsetof(BTVacuumPostingData, deletetids) +
+ nitem * sizeof(uint16));
+ vacposting->itup = itup;
+ vacposting->updatedoffset = idxoffnum;
+ vacposting->ndeletedtids = 0;
+ }
+
+ /* htid will be deleted from itup */
+ vacposting->deletetids[vacposting->ndeletedtids++] = j;
+ }
+
+ if (vacposting == NULL)
+ {
+ /* No TIDs to delete from itup -- do nothing */
+ }
+ else if (vacposting->ndeletedtids == nitem)
+ {
+ /* Straight delete of itup (to delete all TIDs) */
+ deletable[ndeletable++] = idxoffnum;
+ /* Turns out we won't need granular information */
+ pfree(vacposting);
+ }
+ else
+ {
+ /* Delete some but not all TIDs from itup */
+ Assert(vacposting->ndeletedtids > 0 &&
+ vacposting->ndeletedtids < nitem);
+ updatable[nupdatable++] = vacposting;
+ }
+ }
+
+ /* Done with bottom-up deletion state */
+ pfree(delstate.deltids);
+ pfree(delstate.status);
+
+ /*
+ * Go through with deleting TIDs that we found are safe to delete.
+ *
+ * No MarkBufferDirtyHint() call is needed here, since we don't ever mark
+ * line pointers LP_DEAD. Any and all modifications to the page are made
+ * in the critical section in _bt_delitems_delete().
+ */
+ _bt_delitems_delete(rel, buf, true, latestRemovedXid,
+ deletable, ndeletable, updatable, nupdatable,
+ heapRel);
+
+ /* be tidy */
+ for (int i = 0; i < nupdatable; i++)
+ pfree(updatable[i]);
+
+ /* Carry out earlier decision to have caller avoid deduplication now */
+ if (neverdedup)
+ return true;
+
+ /* Don't dedup when we won't end up back here any time soon anyway */
+ return PageGetExactFreeSpace(page) >= Max(BLCKSZ / 24, newitemsz);
+}
+
/*
* Create a new pending posting list tuple based on caller's base tuple.
*
@@ -452,6 +775,164 @@ _bt_dedup_finish_pending(Page newpage, BTDedupState state)
return spacesaving;
}
+/*
+ * Finalize interval during bottom-up index deletion.
+ *
+ * Determines which TIDs are to be marked promising based on heuristics.
+ */
+static void
+_bt_bottomup_finish_pending(Page page, TM_IndexDeleteOp *delstate,
+ BTDedupState state)
+{
+ bool dupinterval = (state->nitems > 1);
+
+ Assert(state->nitems > 0);
+ Assert(state->nitems <= state->nhtids);
+ Assert(state->intervals[state->nintervals].baseoff == state->baseoff);
+
+ /*
+ * All TIDs from all tuples are at least recording in state. Tuples are
+ * marked promising when they're duplicates (i.e. when they appear in an
+ * interval with more than one item, as when we expect create a new
+ * posting list tuple in the deduplication case).
+ *
+ * It's easy to see what this means in the plain non-pivot tuple case:
+ * TIDs from duplicate plain tuples are promising. Posting list tuples
+ * are more subtle. We ought to do something with posting list tuples,
+ * though plain tuples tend to be more promising targets. (Plain tuples
+ * are the most likely to be dead/deletable because they suggest version
+ * churn. And they allow us to free more space when we actually succeed).
+ */
+ for (int i = 0; i < state->nitems; i++)
+ {
+ OffsetNumber offnum = state->baseoff + i;
+ ItemId itemid = PageGetItemId(page, offnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+ TM_IndexDelete *cdeltid;
+ TM_IndexStatus *dstatus;
+
+ cdeltid = &delstate->deltids[delstate->ndeltids];
+ dstatus = &delstate->status[delstate->ndeltids];
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ /* Easy case: A plain non-pivot tuple's TID */
+ cdeltid->tid = itup->t_tid;
+ cdeltid->id = delstate->ndeltids;
+ dstatus->idxoffnum = offnum;
+ dstatus->ispromising = dupinterval;
+ dstatus->deleteitup = false; /* for now */
+ dstatus->tupsize =
+ ItemIdGetLength(itemid) + sizeof(ItemIdData);
+ delstate->ndeltids++;
+ }
+ else
+ {
+ /*
+ * Harder case: A posting list tuple's TIDs (multiple TIDs).
+ *
+ * Only a single TID from a posting list tuple may be promising,
+ * and only when it appears in a duplicate tuple (just like plain
+ * tuple case). In general there is a good chance that the
+ * posting list tuple relates to multiple logical rows, rather
+ * than multiple versions of just one logical row. (It can only
+ * be the latter case when a previous bottom-up deletion pass
+ * failed, necessitating a deduplication pass, which isn't all
+ * that common.)
+ *
+ * There is a pretty good chance that at least one of the logical
+ * rows from the posting list was updated, and so had a successor
+ * version (about as good a chance as it is in the regular tuple
+ * case, at least). We should at least try to follow the regular
+ * tuple case while making the conservative assumption that there
+ * can only be one affected logical row per posting list tuple. We
+ * do that by picking one TID when it appears to be from the
+ * predominant tableam block in the posting list (if any one
+ * tableam block predominates). The approach we take is to either
+ * choose the first or last TID in the posting list (if any at
+ * all). We go with whichever one is on the same tableam block at
+ * the middle tuple (and only the first TID when both the first
+ * and last TIDs relate to the same tableam block -- we could
+ * easily be too aggressive here).
+ *
+ * If it turns out that there are multiple old versions of a
+ * single logical table row, we still have a pretty good chance of
+ * being able to delete them this way. We don't want to give too
+ * strong a signal to the tableam. But we should always try to
+ * give some useful hints. Even cases with considerable
+ * uncertainty can consistently avoid an unnecessary page split,
+ * in part because the tableam will have tricks of its own for
+ * figuring out where to look in marginal cases.
+ */
+ int nitem = BTreeTupleGetNPosting(itup);
+ bool firstpromise = false;
+ bool lastpromise = false;
+
+ Assert(_bt_posting_valid(itup));
+
+ if (dupinterval)
+ {
+ /* Figure out if there really should be promising TIDs */
+ BlockNumber minblocklist,
+ midblocklist,
+ maxblocklist;
+ ItemPointer mintid,
+ midtid,
+ maxtid;
+
+ mintid = BTreeTupleGetHeapTID(itup);
+ midtid = BTreeTupleGetPostingN(itup, nitem / 2);
+ maxtid = BTreeTupleGetMaxHeapTID(itup);
+ minblocklist = ItemPointerGetBlockNumber(mintid);
+ midblocklist = ItemPointerGetBlockNumber(midtid);
+ maxblocklist = ItemPointerGetBlockNumber(maxtid);
+
+ firstpromise = (minblocklist == midblocklist);
+ lastpromise = (!firstpromise && midblocklist == maxblocklist);
+ }
+
+ /* No more than one TID from itup can be promising */
+ Assert(!(firstpromise && lastpromise));
+
+ for (int p = 0; p < nitem; p++)
+ {
+ ItemPointer htid = BTreeTupleGetPostingN(itup, p);
+
+ cdeltid->tid = *htid;
+ cdeltid->id = delstate->ndeltids;
+ dstatus->idxoffnum = offnum;
+ dstatus->ispromising = false;
+
+ if ((firstpromise && p == 0) ||
+ (lastpromise && p == nitem - 1))
+ dstatus->ispromising = true;
+
+ dstatus->deleteitup = false; /* for now */
+ dstatus->tupsize = sizeof(ItemPointerData) + 1;
+ delstate->ndeltids++;
+
+ cdeltid++;
+ dstatus++;
+ }
+ }
+ }
+
+ if (dupinterval)
+ {
+ /*
+ * Maintain interval state for consistency with true deduplication
+ * case
+ */
+ state->intervals[state->nintervals].nitems = state->nitems;
+ state->nintervals++;
+ }
+
+ /* Reset state for next interval */
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+}
+
/*
* Determine if page non-pivot tuples (data items) are all duplicates of the
* same value -- if they are, deduplication's "single value" strategy should
@@ -622,8 +1103,8 @@ _bt_form_posting(IndexTuple base, ItemPointer htids, int nhtids)
* Generate a replacement tuple by "updating" a posting list tuple so that it
* no longer has TIDs that need to be deleted.
*
- * Used by VACUUM. Caller's vacposting argument points to the existing
- * posting list tuple to be updated.
+ * Used by both VACUUM and bottom-up index deletion. Caller's vacposting
+ * argument points to the existing posting list tuple to be updated.
*
* On return, caller's vacposting argument will point to final "updated"
* tuple, which will be palloc()'d in caller's memory context.
@@ -765,6 +1246,26 @@ _bt_swap_posting(IndexTuple newitem, IndexTuple oposting, int postingoff)
return nposting;
}
+/*
+ * Comparator used by _bt_bottomup_pass() to restore deltids array back to its
+ * original sort order
+ */
+static int
+_bt_indexdelete_cmp(const void *a, const void *b)
+{
+ TM_IndexDelete *indexdelete1 = (TM_IndexDelete *) a;
+ TM_IndexDelete *indexdelete2 = (TM_IndexDelete *) b;
+
+ if (indexdelete1->id > indexdelete2->id)
+ return 1;
+ if (indexdelete1->id < indexdelete2->id)
+ return -1;
+
+ Assert(false);
+
+ return 0;
+}
+
/*
* Verify posting list invariants for "posting", which must be a posting list
* tuple. Used within assertions.
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index dde43b1415..94c4ea5076 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -37,6 +37,7 @@ static TransactionId _bt_check_unique(Relation rel, BTInsertState insertstate,
static OffsetNumber _bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool indexUnchanged,
BTStack stack,
Relation heapRel);
static void _bt_stepright(Relation rel, BTInsertState insertstate, BTStack stack);
@@ -61,7 +62,7 @@ static inline bool _bt_pgaddtup(Page page, Size itemsize, IndexTuple itup,
static void _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
BTInsertState insertstate,
bool lpdeadonly, bool checkingunique,
- bool uniquedup);
+ bool uniquedup, bool indexUnchanged);
/*
* _bt_doinsert() -- Handle insertion of a single index tuple in the tree.
@@ -83,7 +84,8 @@ static void _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
*/
bool
_bt_doinsert(Relation rel, IndexTuple itup,
- IndexUniqueCheck checkUnique, Relation heapRel)
+ IndexUniqueCheck checkUnique, Relation heapRel,
+ bool indexUnchanged)
{
bool is_unique = false;
BTInsertStateData insertstate;
@@ -238,7 +240,7 @@ search:
* checkingunique.
*/
newitemoff = _bt_findinsertloc(rel, &insertstate, checkingunique,
- stack, heapRel);
+ indexUnchanged, stack, heapRel);
_bt_insertonpg(rel, itup_key, insertstate.buf, InvalidBuffer, stack,
itup, insertstate.itemsz, newitemoff,
insertstate.postingoff, false);
@@ -777,6 +779,17 @@ _bt_check_unique(Relation rel, BTInsertState insertstate, Relation heapRel,
* room for the new tuple, this function moves right, trying to find a
* legal page that does.)
*
+ * If 'indexUnchanged' is true, this is for an UPDATE that didn't
+ * logically change the indexed value, but must nevertheless have a new
+ * entry to point to a successor version. This hint from the executor
+ * will influence our behavior when the page might have to be split and
+ * we must consider our options. Bottom-up index deletion can avoid
+ * pathological version-driven page splits, but we only want to go to the
+ * trouble of trying it when we already have moderate confidence that
+ * it's appropriate. The hint should not significantly affect our
+ * behavior over time unless practically all inserts on to the leaf page
+ * get the hint.
+ *
* On exit, insertstate buffer contains the chosen insertion page, and
* the offset within that page is returned. If _bt_findinsertloc needed
* to move right, the lock and pin on the original page are released, and
@@ -793,6 +806,7 @@ static OffsetNumber
_bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool indexUnchanged,
BTStack stack,
Relation heapRel)
{
@@ -817,7 +831,7 @@ _bt_findinsertloc(Relation rel,
if (itup_key->heapkeyspace)
{
/* Keep track of whether checkingunique duplicate seen */
- bool uniquedup = false;
+ bool uniquedup = indexUnchanged;
/*
* If we're inserting into a unique index, we may have to walk right
@@ -881,7 +895,8 @@ _bt_findinsertloc(Relation rel,
*/
if (PageGetFreeSpace(page) < insertstate->itemsz)
_bt_delete_or_dedup_one_page(rel, heapRel, insertstate, false,
- checkingunique, uniquedup);
+ checkingunique, uniquedup,
+ indexUnchanged);
}
else
{
@@ -923,7 +938,8 @@ _bt_findinsertloc(Relation rel,
{
/* Erase LP_DEAD items (won't deduplicate) */
_bt_delete_or_dedup_one_page(rel, heapRel, insertstate, true,
- checkingunique, false);
+ checkingunique, false,
+ indexUnchanged);
if (PageGetFreeSpace(page) >= insertstate->itemsz)
break; /* OK, now we have enough space */
@@ -977,7 +993,7 @@ _bt_findinsertloc(Relation rel,
* This can only erase LP_DEAD items (it won't deduplicate).
*/
_bt_delete_or_dedup_one_page(rel, heapRel, insertstate, true,
- checkingunique, false);
+ checkingunique, false, indexUnchanged);
/*
* Do new binary search. New insert location cannot overlap with any
@@ -2609,15 +2625,24 @@ _bt_pgaddtup(Page page,
* _bt_delete_or_dedup_one_page - Try to avoid a leaf page split by attempting
* a variety of operations.
*
- * There are two operations performed here: deleting items already marked
- * LP_DEAD, and deduplication. If both operations fail to free enough space
- * for the incoming item then caller will go on to split the page. We always
- * attempt our preferred strategy (which is to delete items whose LP_DEAD bit
- * are set) first. If that doesn't work out we move on to deduplication.
+ * There are three operations performed here: deleting items already marked
+ * LP_DEAD, bottom-up index deletion, and deduplication. If all three
+ * operations fail to free enough space for the incoming item then caller will
+ * go on to split the page. We always attempt our preferred strategy (which
+ * is to delete items whose LP_DEAD bit are set) first. If that doesn't work
+ * out we consider alternatives. Most calls here will not exhaustively
+ * attempt all three operations. Deduplication and bottom-up index deletion
+ * are relatively expensive operations, so we try to pick one or the other up
+ * front (whichever one seems better for this specific page).
*
- * Caller's checkingunique and uniquedup arguments help us decide if we should
- * perform deduplication, which is primarily useful with low cardinality data,
- * but can sometimes absorb version churn.
+ * Caller's checkingunique, uniquedup, and indexUnchanged arguments help us
+ * decide which alternative strategy we should attempt (or attempt first).
+ * Deduplication is primarily useful with low cardinality data. Bottom-up
+ * index deletion is a backstop against version churn caused by repeated
+ * UPDATE statements where affected indexes don't receive logical changes
+ * (because an optimization like heapam's HOT cannot be applied in the
+ * tableam). But useful interplay between both techniques over time is
+ * sometimes possible.
*
* Callers that only want us to look for/delete LP_DEAD items can ask for that
* directly by passing true 'lpdeadonly' argument.
@@ -2639,7 +2664,7 @@ static void
_bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
BTInsertState insertstate,
bool lpdeadonly, bool checkingunique,
- bool uniquedup)
+ bool uniquedup, bool indexUnchanged)
{
OffsetNumber deletable[MaxIndexTuplesPerPage];
int ndeletable = 0;
@@ -2670,7 +2695,8 @@ _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
if (ndeletable > 0)
{
- _bt_delitems_delete(rel, buffer, deletable, ndeletable, heapRel);
+ _bt_delitems_delete(rel, buffer, false, InvalidTransactionId,
+ deletable, ndeletable, NULL, 0, heapRel);
insertstate->bounds_valid = false;
/* Return when a page split has already been avoided */
@@ -2699,8 +2725,12 @@ _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
* We can get called in the checkingunique case when there is no reason to
* believe that there are any duplicates on the page; we should at least
* still check for LP_DEAD items. If that didn't work out, give up and
- * let caller split the page. Deduplication cannot be justified given
- * there is no reason to think that there are duplicates.
+ * let caller split the page.
+ *
+ * We give up because the other types of operations that might avoid a
+ * page split are also unlikely to work out, but are much more expensive
+ * to try. That cannot be justified given there is no reason to think
+ * that there are duplicates that we can target.
*/
if (checkingunique && !uniquedup)
return;
@@ -2708,6 +2738,22 @@ _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
/* Assume bounds about to be invalidated (this is almost certain now) */
insertstate->bounds_valid = false;
+ /*
+ * Perform bottom-up index deletion pass when executor hint indicated that
+ * incoming item is logically unchanged, or for a unique index that is
+ * known to have physical duplicates for some other reason. (There is a
+ * large overlap between these two cases for a unique index. It's worth
+ * having both triggering conditions in order to apply the optimization in
+ * the event of successive related INSERT and DELETE statements.)
+ *
+ * We'll go on to do a deduplication pass when a bottom-up pass fails to
+ * delete an acceptable amount of free space (a non-trivial fraction of
+ * the page that typically exceeds the new item's size).
+ */
+ if (BTGetDeleteItems(rel) && (indexUnchanged || uniquedup) &&
+ _bt_bottomup_pass(rel, buffer, heapRel, insertstate->itemsz))
+ return;
+
/*
* Perform deduplication pass, though only when it is enabled for the
* index and known to be safe (it must be an allequalimage index).
diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c
index 848123d921..150cebb31f 100644
--- a/src/backend/access/nbtree/nbtpage.c
+++ b/src/backend/access/nbtree/nbtpage.c
@@ -38,6 +38,10 @@
static BTMetaPageData *_bt_getmeta(Relation rel, Buffer metabuf);
static void _bt_log_reuse_page(Relation rel, BlockNumber blkno,
TransactionId latestRemovedXid);
+static char *_bt_delitems_updates(BTVacuumPosting *updatable, int nupdatable,
+ OffsetNumber *updatedoffsets,
+ Size *updatedbuflen,
+ bool needswal);
static TransactionId _bt_xid_horizon(Relation rel, Relation heapRel, Page page,
OffsetNumber *deletable, int ndeletable);
static bool _bt_mark_page_halfdead(Relation rel, Buffer leafbuf,
@@ -1110,15 +1114,14 @@ _bt_page_recyclable(Page page)
* sorted in ascending order.
*
* Routine deals with deleting TIDs when some (but not all) of the heap TIDs
- * in an existing posting list item are to be removed by VACUUM. This works
- * by updating/overwriting an existing item with caller's new version of the
- * item (a version that lacks the TIDs that are to be deleted).
+ * in an existing posting list item are to be removed. This works by
+ * updating/overwriting an existing item with caller's new version of the item
+ * (a version that lacks the TIDs that are to be deleted).
*
* We record VACUUMs and b-tree deletes differently in WAL. Deletes must
* generate their own latestRemovedXid by accessing the heap directly, whereas
* VACUUMs rely on the initial heap scan taking care of it indirectly. Also,
- * only VACUUM can perform granular deletes of individual TIDs in posting list
- * tuples.
+ * we remove the VACUUM cycle ID from pages, which b-tree deletes don't do.
*/
void
_bt_delitems_vacuum(Relation rel, Buffer buf,
@@ -1127,7 +1130,7 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
{
Page page = BufferGetPage(buf);
BTPageOpaque opaque;
- Size itemsz;
+ bool needswal = RelationNeedsWAL(rel);
char *updatedbuf = NULL;
Size updatedbuflen = 0;
OffsetNumber updatedoffsets[MaxIndexTuplesPerPage];
@@ -1135,45 +1138,11 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
/* Shouldn't be called unless there's something to do */
Assert(ndeletable > 0 || nupdatable > 0);
- for (int i = 0; i < nupdatable; i++)
- {
- /* Replace work area IndexTuple with updated version */
- _bt_update_posting(updatable[i]);
-
- /* Maintain array of updatable page offsets for WAL record */
- updatedoffsets[i] = updatable[i]->updatedoffset;
- }
-
- /* XLOG stuff -- allocate and fill buffer before critical section */
- if (nupdatable > 0 && RelationNeedsWAL(rel))
- {
- Size offset = 0;
-
- for (int i = 0; i < nupdatable; i++)
- {
- BTVacuumPosting vacposting = updatable[i];
-
- itemsz = SizeOfBtreeUpdate +
- vacposting->ndeletedtids * sizeof(uint16);
- updatedbuflen += itemsz;
- }
-
- updatedbuf = palloc(updatedbuflen);
- for (int i = 0; i < nupdatable; i++)
- {
- BTVacuumPosting vacposting = updatable[i];
- xl_btree_update update;
-
- update.ndeletedtids = vacposting->ndeletedtids;
- memcpy(updatedbuf + offset, &update.ndeletedtids,
- SizeOfBtreeUpdate);
- offset += SizeOfBtreeUpdate;
-
- itemsz = update.ndeletedtids * sizeof(uint16);
- memcpy(updatedbuf + offset, vacposting->deletetids, itemsz);
- offset += itemsz;
- }
- }
+ /* Generate new version of posting lists without deleted TIDs */
+ if (nupdatable > 0)
+ updatedbuf = _bt_delitems_updates(updatable, nupdatable,
+ updatedoffsets, &updatedbuflen,
+ needswal);
/* No ereport(ERROR) until changes are logged */
START_CRIT_SECTION();
@@ -1194,6 +1163,7 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
{
OffsetNumber updatedoffset = updatedoffsets[i];
IndexTuple itup;
+ Size itemsz;
itup = updatable[i]->itup;
itemsz = MAXALIGN(IndexTupleSize(itup));
@@ -1227,7 +1197,7 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
MarkBufferDirty(buf);
/* XLOG stuff */
- if (RelationNeedsWAL(rel))
+ if (needswal)
{
XLogRecPtr recptr;
xl_btree_vacuum xlrec_vacuum;
@@ -1260,7 +1230,7 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
/* can't leak memory here */
if (updatedbuf != NULL)
pfree(updatedbuf);
- /* free tuples generated by calling _bt_update_posting() */
+ /* free tuples allocated within _bt_delitems_updates() */
for (int i = 0; i < nupdatable; i++)
pfree(updatable[i]->itup);
}
@@ -1269,36 +1239,89 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
* Delete item(s) from a btree leaf page during single-page cleanup.
*
* This routine assumes that the caller has pinned and write locked the
- * buffer. Also, the given deletable array *must* be sorted in ascending
- * order.
+ * buffer. Also, the given deletable and updatable arrays *must* be sorted in
+ * ascending order.
+ *
+ * Routine deals with deleting TIDs when some (but not all) of the heap TIDs
+ * in an existing posting list item are to be removed. This works by
+ * updating/overwriting an existing item with caller's new version of the item
+ * (a version that lacks the TIDs that are to be deleted).
*
* This is nearly the same as _bt_delitems_vacuum as far as what it does to
* the page, but it needs to generate its own latestRemovedXid by accessing
* the heap. This is used by the REDO routine to generate recovery conflicts.
- * Also, it doesn't handle posting list tuples unless the entire tuple can be
- * deleted as a whole (since there is only one LP_DEAD bit per line pointer).
+ * Though note that bottom-up index deletion caller will provide its own
+ * latestRemovedXid, since it's convenient for it to calculate a cut-off XID
+ * at the same point that it determines that TIDs point to dead items in
+ * tableam blocks (bottom-up deletion doesn't rely on LP_DEAD bits at all).
+ *
+ * The other difference is that _bt_delitems_vacuum will clear page's VACUUM
+ * cycle ID. We must never do that.
*/
void
_bt_delitems_delete(Relation rel, Buffer buf,
+ bool bottomup, TransactionId bottomupXid,
OffsetNumber *deletable, int ndeletable,
+ BTVacuumPosting *updatable, int nupdatable,
Relation heapRel)
{
Page page = BufferGetPage(buf);
BTPageOpaque opaque;
+ bool needswal = RelationNeedsWAL(rel);
+ char *updatedbuf = NULL;
+ Size updatedbuflen = 0;
+ OffsetNumber updatedoffsets[MaxIndexTuplesPerPage];
TransactionId latestRemovedXid = InvalidTransactionId;
/* Shouldn't be called unless there's something to do */
- Assert(ndeletable > 0);
+ Assert(ndeletable > 0 || nupdatable > 0);
+ /* Only update posting list tuples for bottom-up caller */
+ Assert(nupdatable == 0 || bottomup);
- if (XLogStandbyInfoActive() && RelationNeedsWAL(rel))
- latestRemovedXid =
- _bt_xid_horizon(rel, heapRel, page, deletable, ndeletable);
+ /* Generate new versions of posting lists without deleted TIDs */
+ if (nupdatable > 0)
+ updatedbuf = _bt_delitems_updates(updatable, nupdatable,
+ updatedoffsets, &updatedbuflen,
+ needswal);
+
+ if (XLogStandbyInfoActive() && needswal)
+ {
+ if (!bottomup)
+ latestRemovedXid =
+ _bt_xid_horizon(rel, heapRel, page, deletable,
+ ndeletable);
+ else
+ latestRemovedXid = bottomupXid;
+ }
/* No ereport(ERROR) until changes are logged */
START_CRIT_SECTION();
- /* Fix the page */
- PageIndexMultiDelete(page, deletable, ndeletable);
+ /*
+ * Handle posting tuple updates.
+ *
+ * Deliberately do this before handling simple deletes. If we did it the
+ * other way around (i.e. WAL record order -- simple deletes before
+ * updates) then we'd have to make compensating changes to the 'updatable'
+ * array of offset numbers.
+ */
+ for (int i = 0; i < nupdatable; i++)
+ {
+ OffsetNumber updatedoffset = updatedoffsets[i];
+ IndexTuple itup;
+ Size itemsz;
+
+ itup = updatable[i]->itup;
+ itemsz = MAXALIGN(IndexTupleSize(itup));
+ if (!PageIndexTupleOverwrite(page, updatedoffset, (Item) itup,
+ itemsz))
+ elog(PANIC, "failed to update partially dead item in block %u of index \"%s\"",
+ BufferGetBlockNumber(buf), RelationGetRelationName(rel));
+ }
+
+ /* Now handle simple deletes of entire tuples */
+ if (ndeletable > 0)
+ PageIndexMultiDelete(page, deletable, ndeletable);
/*
* Unlike _bt_delitems_vacuum, we *must not* clear the vacuum cycle ID,
@@ -1318,25 +1341,29 @@ _bt_delitems_delete(Relation rel, Buffer buf,
MarkBufferDirty(buf);
/* XLOG stuff */
- if (RelationNeedsWAL(rel))
+ if (needswal)
{
XLogRecPtr recptr;
xl_btree_delete xlrec_delete;
xlrec_delete.latestRemovedXid = latestRemovedXid;
xlrec_delete.ndeleted = ndeletable;
+ xlrec_delete.nupdated = nupdatable;
XLogBeginInsert();
XLogRegisterBuffer(0, buf, REGBUF_STANDARD);
XLogRegisterData((char *) &xlrec_delete, SizeOfBtreeDelete);
- /*
- * The deletable array is not in the buffer, but pretend that it is.
- * When XLogInsert stores the whole buffer, the array need not be
- * stored too.
- */
- XLogRegisterBufData(0, (char *) deletable,
- ndeletable * sizeof(OffsetNumber));
+ if (ndeletable > 0)
+ XLogRegisterBufData(0, (char *) deletable,
+ ndeletable * sizeof(OffsetNumber));
+
+ if (nupdatable > 0)
+ {
+ XLogRegisterBufData(0, (char *) updatedoffsets,
+ nupdatable * sizeof(OffsetNumber));
+ XLogRegisterBufData(0, updatedbuf, updatedbuflen);
+ }
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_DELETE);
@@ -1344,6 +1371,88 @@ _bt_delitems_delete(Relation rel, Buffer buf,
}
END_CRIT_SECTION();
+
+ /* can't leak memory here */
+ if (updatedbuf != NULL)
+ pfree(updatedbuf);
+ /* free tuples allocated within _bt_delitems_updates() */
+ for (int i = 0; i < nupdatable; i++)
+ pfree(updatable[i]->itup);
+}
+
+/*
+ * Set up state needed to delete TIDs from posting list tuples via "updating"
+ * the tuple. Performs steps common to both _bt_delitems_vacuum and
+ * _bt_delitems_delete. These steps must take place before each function's
+ * critical section begins.
+ *
+ * updatabable and nupdatable are inputs, though note that we will use
+ * _bt_update_posting() to replace the original itup with a pointer to a final
+ * version in palloc()'d memory. Caller should free the tuples when its done.
+ *
+ * The first nupdatable entries from updatedoffsets are set to the page offset
+ * number for posting list tuples that caller updates. This is mostly useful
+ * because caller may need to WAL-log the page offsets (though we always do
+ * this for caller out of convenience).
+ *
+ * Returns buffer consisting of an array of xl_btree_update structs that
+ * describe the steps we perform here for caller (though only when needswal is
+ * true). Also sets *updatedbuflen to the final size of the buffer. This
+ * buffer is used by caller when WAL logging is required.
+ */
+static char *
+_bt_delitems_updates(BTVacuumPosting *updatable, int nupdatable,
+ OffsetNumber *updatedoffsets, Size *updatedbuflen,
+ bool needswal)
+{
+ char *updatedbuf = NULL;
+ Size buflen = 0;
+
+ /* Shouldn't be called unless there's something to do */
+ Assert(nupdatable > 0);
+
+ for (int i = 0; i < nupdatable; i++)
+ {
+ BTVacuumPosting vacposting = updatable[i];
+ Size itemsz;
+
+ /* Replace work area IndexTuple with updated version */
+ _bt_update_posting(vacposting);
+
+ /* Keep track of size of xl_btree_update for updatedbuf in passing */
+ itemsz = SizeOfBtreeUpdate + vacposting->ndeletedtids * sizeof(uint16);
+ buflen += itemsz;
+
+ /* Build updatedoffsets buffer in passing */
+ updatedoffsets[i] = vacposting->updatedoffset;
+ }
+
+ /* XLOG stuff */
+ if (needswal)
+ {
+ Size offset = 0;
+
+ /* Allocate, set final size for caller */
+ updatedbuf = palloc(buflen);
+ *updatedbuflen = buflen;
+ for (int i = 0; i < nupdatable; i++)
+ {
+ BTVacuumPosting vacposting = updatable[i];
+ Size itemsz;
+ xl_btree_update update;
+
+ update.ndeletedtids = vacposting->ndeletedtids;
+ memcpy(updatedbuf + offset, &update.ndeletedtids,
+ SizeOfBtreeUpdate);
+ offset += SizeOfBtreeUpdate;
+
+ itemsz = update.ndeletedtids * sizeof(uint16);
+ memcpy(updatedbuf + offset, vacposting->deletetids, itemsz);
+ offset += itemsz;
+ }
+ }
+
+ return updatedbuf;
}
/*
@@ -1353,6 +1462,9 @@ _bt_delitems_delete(Relation rel, Buffer buf,
* This is a specialized version of index_compute_xid_horizon_for_tuples().
* It's needed because btree tuples don't always store table TID using the
* standard index tuple header field.
+ *
+ * Note that the bottom-up index deletion caller does not call here. It must
+ * provide its own latestRemovedXid value.
*/
static TransactionId
_bt_xid_horizon(Relation rel, Relation heapRel, Page page,
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index d6c8ad5d27..4233986ed1 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -209,7 +209,7 @@ btinsert(Relation rel, Datum *values, bool *isnull,
itup = index_form_tuple(RelationGetDescr(rel), values, isnull);
itup->t_tid = *ht_ctid;
- result = _bt_doinsert(rel, itup, checkUnique, heapRel);
+ result = _bt_doinsert(rel, itup, checkUnique, heapRel, indexUnchanged);
pfree(itup);
diff --git a/src/backend/access/nbtree/nbtutils.c b/src/backend/access/nbtree/nbtutils.c
index 2f5f14e527..2a978ba217 100644
--- a/src/backend/access/nbtree/nbtutils.c
+++ b/src/backend/access/nbtree/nbtutils.c
@@ -2108,7 +2108,9 @@ btoptions(Datum reloptions, bool validate)
{"vacuum_cleanup_index_scale_factor", RELOPT_TYPE_REAL,
offsetof(BTOptions, vacuum_cleanup_index_scale_factor)},
{"deduplicate_items", RELOPT_TYPE_BOOL,
- offsetof(BTOptions, deduplicate_items)}
+ offsetof(BTOptions, deduplicate_items)},
+ {"delete_items", RELOPT_TYPE_BOOL,
+ offsetof(BTOptions, delete_items)}
};
@@ -2414,6 +2416,11 @@ _bt_keep_natts(Relation rel, IndexTuple lastleft, IndexTuple firstright,
* This weaker guarantee is good enough for nbtsplitloc.c caller, since false
* negatives generally only have the effect of making leaf page splits use a
* more balanced split point.
+ *
+ * The differences between this function and _bt_keep_natts may actually be
+ * helpful to the bottom-up index deletion caller. A bottom-up pass tries to
+ * find old versions left behind by UPDATEs, but only when those UPDATEs
+ * didn't logically modify columns that are covered by the index.
*/
int
_bt_keep_natts_fast(Relation rel, IndexTuple lastleft, IndexTuple firstright)
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index 5135b800af..d2142f3e89 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -675,7 +675,56 @@ btree_xlog_delete(XLogReaderState *record)
page = (Page) BufferGetPage(buffer);
- PageIndexMultiDelete(page, (OffsetNumber *) ptr, xlrec->ndeleted);
+ if (xlrec->nupdated > 0)
+ {
+ OffsetNumber *updatedoffsets;
+ xl_btree_update *updates;
+
+ updatedoffsets = (OffsetNumber *)
+ (ptr + xlrec->ndeleted * sizeof(OffsetNumber));
+ updates = (xl_btree_update *) ((char *) updatedoffsets +
+ xlrec->nupdated *
+ sizeof(OffsetNumber));
+
+ for (int i = 0; i < xlrec->nupdated; i++)
+ {
+ BTVacuumPosting vacposting;
+ IndexTuple origtuple;
+ ItemId itemid;
+ Size itemsz;
+
+ itemid = PageGetItemId(page, updatedoffsets[i]);
+ origtuple = (IndexTuple) PageGetItem(page, itemid);
+
+ vacposting = palloc(offsetof(BTVacuumPostingData, deletetids) +
+ updates->ndeletedtids * sizeof(uint16));
+ vacposting->updatedoffset = updatedoffsets[i];
+ vacposting->itup = origtuple;
+ vacposting->ndeletedtids = updates->ndeletedtids;
+ memcpy(vacposting->deletetids,
+ (char *) updates + SizeOfBtreeUpdate,
+ updates->ndeletedtids * sizeof(uint16));
+
+ _bt_update_posting(vacposting);
+
+ /* Overwrite updated version of tuple */
+ itemsz = MAXALIGN(IndexTupleSize(vacposting->itup));
+ if (!PageIndexTupleOverwrite(page, updatedoffsets[i],
+ (Item) vacposting->itup, itemsz))
+ elog(PANIC, "failed to update partially dead item");
+
+ pfree(vacposting->itup);
+ pfree(vacposting);
+
+ /* advance to next xl_btree_update from array */
+ updates = (xl_btree_update *)
+ ((char *) updates + SizeOfBtreeUpdate +
+ updates->ndeletedtids * sizeof(uint16));
+ }
+ }
+
+ if (xlrec->ndeleted > 0)
+ PageIndexMultiDelete(page, (OffsetNumber *) ptr, xlrec->ndeleted);
/* Mark the page as not containing any LP_DEAD items */
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 5238a960f7..f7f998ad06 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -1765,14 +1765,14 @@ psql_completion(const char *text, int start, int end)
/* ALTER INDEX <foo> SET|RESET ( */
else if (Matches("ALTER", "INDEX", MatchAny, "RESET", "("))
COMPLETE_WITH("fillfactor",
- "vacuum_cleanup_index_scale_factor", "deduplicate_items", /* BTREE */
+ "vacuum_cleanup_index_scale_factor", "deduplicate_items", "delete_items", /* BTREE */
"fastupdate", "gin_pending_list_limit", /* GIN */
"buffering", /* GiST */
"pages_per_range", "autosummarize" /* BRIN */
);
else if (Matches("ALTER", "INDEX", MatchAny, "SET", "("))
COMPLETE_WITH("fillfactor =",
- "vacuum_cleanup_index_scale_factor =", "deduplicate_items =", /* BTREE */
+ "vacuum_cleanup_index_scale_factor =", "deduplicate_items =", "delete_items =", /* BTREE */
"fastupdate =", "gin_pending_list_limit =", /* GIN */
"buffering =", /* GiST */
"pages_per_range =", "autosummarize =" /* BRIN */
diff --git a/doc/src/sgml/btree.sgml b/doc/src/sgml/btree.sgml
index bb395e6a85..9e4abf40d2 100644
--- a/doc/src/sgml/btree.sgml
+++ b/doc/src/sgml/btree.sgml
@@ -629,6 +629,86 @@ options(<replaceable>relopts</replaceable> <type>local_relopts *</type>) returns
</para>
</sect2>
+ <sect2 id="btree-deletion">
+ <title>Bottom-up index deletion</title>
+ <para>
+ B-Tree indexes are not directly aware that under MVCC, there might
+ be multiple extant versions of the same logical table row; to an
+ index, each tuple is an independent object that needs its own index
+ entry. <quote>Version churn</quote> tuples may sometimes
+ accumulate and adversely affect query latency and throughput. This
+ typically occurs with <command>UPDATE</command>-heavy workloads
+ where most individual updates cannot apply the
+ <acronym>HOT</acronym> optimization. Changing the value of only
+ one column covered by one index during an <command>UPDATE</command>
+ <emphasis>always</emphasis> necessitates a new set of index tuples
+ — one for <emphasis>each and every</emphasis> index on the
+ table. Note in particular that this includes indexes that were not
+ <quote>logically modified</quote> by the <command>UPDATE</command>.
+ All indexes will need a successor physical index tuple that points
+ to the latest version in the table. Each new tuple within each
+ index will generally need to coexist with the original
+ <quote>updated</quote> tuple for a short period of time (typically
+ until some time after the <command>UPDATE</command> transaction
+ commits). This process produces the majority of all garbage index
+ tuples in some scenarios.
+ </para>
+ <para>
+ <firstterm>Bottom-up index deletion</firstterm> targets this
+ particular variety of index tuple garbage. It effectively enforces
+ a soft limit on how many versions there can be in each index for
+ any given logical row. It is generally very effective provided
+ there are no long lived snapshots that hold back cleanup.
+ Bottom-up index deletion complements the <quote>top-down</quote>
+ index cleanup performed by <command>VACUUM</command>. It targets
+ leaf pages that are disproportionately affected by the accumulation
+ of garbage index tuples, while leaving it up to
+ <command>VACUUM</command> to perform infrequent clean sweeps of all
+ indexes. A bottom-up deletion pass takes place when a leaf page
+ does not have enough free space to fit an incoming tuple, though
+ only when the incoming tuple originates from an
+ <command>UPDATE</command> that did not logically change any of the
+ columns covered by the index in question.
+ </para>
+ <para>
+ The deletion process must closely cooperate with the table access
+ method. Despite the lack of convenient access to
+ <emphasis>authoritative</emphasis> information about how index
+ tuples represent versions or are related to each other, it is
+ possible for the B-Tree implementation to target garbage index
+ tuples using relatively simple heuristics. These heuristics decide
+ on which table blocks to visit based on where dead tuples seem most
+ likely to be concentrated. Some number of table blocks must be
+ accessed to get the required authoritative information, but it
+ isn't necessary to access very many table blocks each time. Also,
+ each table block access has to actually enable the implementation
+ to delete at least one additional index tuple. The whole process
+ ends when any single table block access fails to yield any index
+ tuples deletes.
+ </para>
+ <para>
+ The <literal>delete_items</literal> storage parameter can be used
+ to disable bottom-up index deletion within individual indexes.
+ Disabling bottom-up index deletion isn't usually helpful.
+ </para>
+ <note>
+ <para>
+ It's also possible for index tuple deletion to take place
+ following opportunistic setting of <literal>LP_DEAD</literal>
+ status bits. This avoids a relatively expensive bottom-up
+ deletion pass, which must access table blocks directly.
+ </para>
+ <para>
+ <literal>LP_DEAD</literal> status bits are set when passing index
+ scans happen to notice that an index tuple is dead to every
+ possible MVCC snapshot (not just their own).
+ <literal>LP_DEAD</literal>-set tuples are already known to be safe
+ to delete, so it isn't necessary to access the table blocks
+ directly.
+ </para>
+ </note>
+ </sect2>
+
<sect2 id="btree-deduplication">
<title>Deduplication</title>
<para>
@@ -702,25 +782,16 @@ options(<replaceable>relopts</replaceable> <type>local_relopts *</type>) returns
deduplication isn't usually helpful.
</para>
<para>
- B-Tree indexes are not directly aware that under MVCC, there might
- be multiple extant versions of the same logical table row; to an
- index, each tuple is an independent object that needs its own index
- entry. <quote>Version duplicates</quote> may sometimes accumulate
- and adversely affect query latency and throughput. This typically
- occurs with <command>UPDATE</command>-heavy workloads where most
- individual updates cannot apply the <acronym>HOT</acronym>
- optimization (often because at least one indexed column gets
- modified, necessitating a new set of index tuple versions —
- one new tuple for <emphasis>each and every</emphasis> index). In
- effect, B-Tree deduplication ameliorates index bloat caused by
- version churn. Note that even the tuples from a unique index are
- not necessarily <emphasis>physically</emphasis> unique when stored
- on disk due to version churn. The deduplication optimization is
- selectively applied within unique indexes. It targets those pages
- that appear to have version duplicates. The high level goal is to
- give <command>VACUUM</command> more time to run before an
- <quote>unnecessary</quote> page split caused by version churn can
- take place.
+ It is sometimes possible for unique indexes (as well as unique
+ constraints) to use deduplication. This allows leaf pages to
+ temporarily <quote>absorb</quote> extra version churn duplicates.
+ Deduplication in unique indexes augments bottom-up index deletion,
+ especially in cases where a long-running transactions holds a
+ snapshot that blocks garbage collection. The goal is to buy time
+ for the bottom-up index deletion strategy to become effective
+ again. Delaying page splits until a single long-running
+ transaction naturally goes away can allow a bottom-up deletion pass
+ to succeed where an earlier deletion pass failed.
</para>
<tip>
<para>
diff --git a/doc/src/sgml/ref/create_index.sgml b/doc/src/sgml/ref/create_index.sgml
index 29dee5689e..573a3e2894 100644
--- a/doc/src/sgml/ref/create_index.sgml
+++ b/doc/src/sgml/ref/create_index.sgml
@@ -435,6 +435,22 @@ CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ] <replaceable class=
</listitem>
</varlistentry>
+ <varlistentry id="index-reloption-delete-items" xreflabel="delete_items">
+ <term><literal>delete_items</literal> (<type>boolean</type>)
+ <indexterm>
+ <primary><varname>delete_items</varname> storage parameter</primary>
+ </indexterm>
+ </term>
+ <listitem>
+ <para>
+ Controls usage of the B-tree bottom-up index deletion technique
+ described in <xref linkend="btree-deletion"/>. Set to
+ <literal>ON</literal> or <literal>OFF</literal> to enable or
+ disable the optimization. The default is <literal>ON</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="index-reloption-vacuum-cleanup-index-scale-factor" xreflabel="vacuum_cleanup_index_scale_factor">
<term><literal>vacuum_cleanup_index_scale_factor</literal> (<type>floating point</type>)
<indexterm>
--
2.25.1
[application/octet-stream] v9-0004-Teach-heapam-to-support-bottom-up-index-deletion.patch (25.4K, ../../CAH2-WzmFsqz_dbFCv1+jhdA8C_e3JcnnR=wh0=HD3imY-MbyXQ@mail.gmail.com/5-v9-0004-Teach-heapam-to-support-bottom-up-index-deletion.patch)
download | inline diff:
From d99680d0cf88b19e381b8c480ed8301a90af48fb Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Mon, 9 Nov 2020 12:59:30 -0800
Subject: [PATCH v9 4/4] Teach heapam to support bottom-up index deletion.
This commit finalizes work started by recent related bottom-up index
deletion commits. This is the last piece required for the feature to
actually work.
Author: Peter Geoghegan <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wz=CEKFa74EScx_hFVshCOn6AA5T-ajFASTdzipdkLTNQQ@mail.gmail.com
---
src/include/access/heapam.h | 2 +
src/backend/access/heap/heapam.c | 636 +++++++++++++++++++++++
src/backend/access/heap/heapam_handler.c | 2 +-
3 files changed, 639 insertions(+), 1 deletion(-)
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 92b19dba32..923f9432e6 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -170,6 +170,8 @@ extern void simple_heap_update(Relation relation, ItemPointer otid,
extern TransactionId heap_compute_xid_horizon_for_tuples(Relation rel,
ItemPointerData *items,
int nitems);
+extern TransactionId heapam_index_delete_check(Relation rel,
+ TM_IndexDeleteOp *delstate);
/* in heap/pruneheap.c */
struct GlobalVisState;
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 1b2f70499e..85f23dbd39 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -55,6 +55,7 @@
#include "miscadmin.h"
#include "pgstat.h"
#include "port/atomics.h"
+#include "port/pg_bitutils.h"
#include "storage/bufmgr.h"
#include "storage/freespace.h"
#include "storage/lmgr.h"
@@ -102,6 +103,7 @@ static void MultiXactIdWait(MultiXactId multi, MultiXactStatus status, uint16 in
int *remaining);
static bool ConditionalMultiXactIdWait(MultiXactId multi, MultiXactStatus status,
uint16 infomask, Relation rel, int *remaining);
+static int heapam_index_delete_check_sort(Relation rel, TM_IndexDeleteOp *delstate);
static XLogRecPtr log_heap_new_cid(Relation relation, HeapTuple tup);
static HeapTuple ExtractReplicaIdentity(Relation rel, HeapTuple tup, bool key_changed,
bool *copy);
@@ -178,6 +180,17 @@ typedef struct
} XidHorizonPrefetchState;
#endif
+/*
+ * heapam_index_delete_check uses this structure to determine which heap pages
+ * to visit, and in what order
+ */
+typedef struct IndexDeleteCounts
+{
+ int16 npromisingtids;
+ int16 ntids;
+ int16 ideltids;
+} IndexDeleteCounts;
+
/*
* This table maps tuple lock strength values for each particular
* MultiXactStatus value.
@@ -192,6 +205,11 @@ static const int MultiXactStatusLock[MaxMultiXactStatus + 1] =
LockTupleExclusive /* Update */
};
+/*
+ * Shellsort gap sequence (taken from Sedgewick-Incerpi paper)
+ */
+static const int ShellsortGaps[8] = {861, 336, 112, 48, 21, 7, 3, 1};
+
/* Get the LockTupleMode for a given MultiXactStatus */
#define TUPLOCK_from_mxstatus(status) \
(MultiXactStatusLock[(status)])
@@ -6987,6 +7005,9 @@ xid_horizon_prefetch_buffer(Relation rel,
* deleting hundreds of tuples from a single index block. To amortize that
* cost to some degree, this uses prefetching and combines repeat accesses to
* the same block.
+ *
+ * Note: The logic for maintaining latestRemovedXid here is duplicated by code
+ * within heapam_index_delete_check(). Make sure that they stay in sync.
*/
TransactionId
heap_compute_xid_horizon_for_tuples(Relation rel,
@@ -7133,6 +7154,621 @@ heap_compute_xid_horizon_for_tuples(Relation rel,
return latestRemovedXid;
}
+#define MAX_DELETE_HEAP_BLOCKS 4
+#define FAVORABLE_BLOCK_STRIDE 3
+
+/*
+ * Determine which heap tuples from a list of TIDs provided by caller are
+ * dead. It is safe to delete index tuples that point to these dead heap
+ * tuples.
+ *
+ * This is used by index AMs that support "bottom up" deletion of duplicate
+ * index tuples in batches of just a few heap pages at a time. Index AMs call
+ * here through the table_index_delete_check() interface. See tableam
+ * interface details (for the TM_IndexDeleteOp struct) for more information.
+ *
+ * Though the main thing that influences which heap pages are accessed here is
+ * the presence of tuples that index AM caller has marked "promising" (which
+ * relate to duplicate index tuples believed to have been inserted in index
+ * recently), there are other considerations. The approach taken here
+ * considers both spatial and temporal locality inside the heap structure.
+ * This is especially helpful when there are several heap blocks with
+ * approximately the same amount of promising tuples. Multiple calls here for
+ * the same index will tend to consistently delete the oldest index tuples,
+ * which keeps the number of buffer misses here to a minimum.
+ *
+ * Sometimes larger batch sizes are preferred here, even when that means that
+ * we might actually exceed caller's immediate requirement for free space in
+ * the index. Contiguous heap blocks are considered "favorable". The
+ * presence of favorable blocks makes the call as a whole access more blocks
+ * to better amortize costs. We expect to be called multiple times for
+ * related records in at least some cases, and have to consider costs over
+ * time. The cost of any individual call is less important.
+ *
+ * Returns the latestRemovedXid from the heap tuples pointed to by the deltids
+ * index tuples that caller finds marked safe to delete.
+ *
+ * Note: The logic for maintaining latestRemovedXid here is duplicated by code
+ * within heap_compute_xid_horizon_for_tuples(). Make sure that they stay in
+ * sync.
+ */
+TransactionId
+heapam_index_delete_check(Relation rel, TM_IndexDeleteOp *delstate)
+{
+ TransactionId latestRemovedXid = InvalidTransactionId;
+ BlockNumber hblkno = InvalidBlockNumber;
+ Buffer buf = InvalidBuffer;
+ Page hpage;
+ bool finalhpage = false;
+ int finalndeltids = 0;
+ int nblocksaccessed = 0;
+ int nblocksfavorable = 0;
+ int spacefreed = 0;
+ int spacefreedbeforecurhpage = 0;
+ SnapshotData SnapshotNonVacuumable;
+ TM_IndexDelete *deltids = delstate->deltids;
+ TM_IndexStatus *status = delstate->status;
+ int targetfreespace = delstate->targetfreespace;
+
+ InitNonVacuumableSnapshot(SnapshotNonVacuumable, GlobalVisTestFor(rel));
+
+ /*
+ * Sort and shrink deltids array so that it consists only of TIDs from
+ * just a few of the most promising blocks
+ */
+ nblocksfavorable = heapam_index_delete_check_sort(rel, delstate);
+ for (int i = 0; i < delstate->ndeltids; i++)
+ {
+ TM_IndexStatus *dstatus = status + deltids[i].id;
+ ItemPointer htid = &deltids[i].tid;
+ ItemPointerData tmp;
+ bool all_dead = false;
+ bool found;
+ ItemId hitemid;
+ OffsetNumber hoffnum;
+ HeapTupleData heapTuple;
+
+ Assert(!dstatus->deleteitup);
+
+ if (hblkno == InvalidBlockNumber ||
+ ItemPointerGetBlockNumber(htid) != hblkno)
+ {
+ /*
+ * We usually do a little extra work on the final heap page after
+ * caller's target space to free has been reached. The cost of
+ * accessing the final heap page we'll need to visit has already
+ * been paid by that point. We finish off the entire final heap
+ * page because it's cheap to do so.
+ *
+ * We don't want to unnecessarily visit the next page in line.
+ * Handle that here (when we just finished final page).
+ */
+ if (finalhpage)
+ break;
+
+ /*
+ * Each time we're about to access a new page we consider if it's
+ * really worth it. We apply two tests before we visit the next
+ * page, and give up if either fails:
+ *
+ * 1. Give up when we didn't enable our caller to free any
+ * additional space as a result of processing the most recent heap
+ * page visited. We expect to make steady progress or no
+ * progress.
+ *
+ * 2. Give up when MAX_DELETE_HEAP_BLOCKS have been accessed
+ * already, no matter what. (This is defensive, since the deltids
+ * array was shrunk before we started. It should now contain TIDs
+ * from pages not exceeding MAX_DELETE_HEAP_BLOCKS in number.)
+ */
+ if (nblocksaccessed >= 1 && spacefreed == spacefreedbeforecurhpage)
+ break;
+ if (nblocksaccessed == MAX_DELETE_HEAP_BLOCKS)
+ break;
+
+ /*
+ * After visiting and processing the first heap page, aggressively
+ * decay target space freed (the request from index AM caller)
+ * before accessing each new heap page (starting with the second
+ * in line). But only start decaying when we encounter our first
+ * non-favorable block.
+ *
+ * Favorable blocks are contiguous groups of heap blocks that are
+ * likely to have related heap tuples that are cheaper to process
+ * in larger batches. It doesn't make sense to be stingy here.
+ * The index AM may end up calling us about the same heap TIDs
+ * before much time has passed if we do that.
+ *
+ * Note that even favorable blocks are required to enable caller
+ * to free at least some space -- otherwise we give up before
+ * accessing the next block in line. If a favorable block cannot
+ * be freed then there is probably an old snapshot that frustrates
+ * progress here in general.
+ */
+ if (nblocksfavorable == 0)
+ {
+ targetfreespace /= 2;
+
+ /* Must always start out with at least 1 favorable block */
+ Assert(nblocksaccessed >= 1);
+ }
+
+ /* Now access next page */
+ if (BufferIsValid(buf))
+ {
+ LockBuffer(buf, BUFFER_LOCK_UNLOCK);
+ ReleaseBuffer(buf);
+ }
+
+ /*
+ * We could prune the heap page in passing here, but that doesn't
+ * seem like a good idea. (Index AM caller is expected to hold
+ * locks of its own.)
+ */
+ hblkno = ItemPointerGetBlockNumber(htid);
+ buf = ReadBuffer(rel, hblkno);
+ hpage = BufferGetPage(buf);
+ nblocksaccessed++;
+ if (nblocksfavorable > 0)
+ nblocksfavorable--;
+ spacefreedbeforecurhpage = spacefreed;
+
+ /* Need to lock buffer for visibility checks */
+ LockBuffer(buf, BUFFER_LOCK_SHARE);
+ }
+
+ tmp = *htid;
+ found = heap_hot_search_buffer(&tmp, rel, buf, &SnapshotNonVacuumable,
+ &heapTuple, &all_dead, true);
+
+ if (found || !all_dead)
+ continue;
+
+ /* Caller can delete this TID from index */
+ finalndeltids = i + 1;
+ dstatus->deleteitup = true;
+ spacefreed += dstatus->tupsize;
+
+ if (spacefreed >= targetfreespace)
+ {
+ /*
+ * Caller's free space target has now been met (maybe...target may
+ * have decayed one or more times from original value if we
+ * weren't accessing favorable/contiguous blocks).
+ *
+ * Finish off the current/final heap page before finishing.
+ */
+ finalhpage = true;
+ }
+
+ /*
+ * One last step required for TID that caller will delete. Must
+ * maintain latestRemovedXid for caller's delete operation.
+ */
+ hoffnum = ItemPointerGetOffsetNumber(htid);
+ hitemid = PageGetItemId(hpage, hoffnum);
+
+ while (ItemIdIsRedirected(hitemid))
+ {
+ hoffnum = ItemIdGetRedirect(hitemid);
+ hitemid = PageGetItemId(hpage, hoffnum);
+ }
+
+ /*
+ * If the heap item has storage, then read the header and use that to
+ * set latestRemovedXid.
+ *
+ * Some LP_DEAD items may not be accessible, so we ignore them.
+ */
+ if (ItemIdHasStorage(hitemid))
+ {
+ HeapTupleHeader htuphdr;
+
+ htuphdr = (HeapTupleHeader) PageGetItem(hpage, hitemid);
+
+ HeapTupleHeaderAdvanceLatestRemovedXid(htuphdr, &latestRemovedXid);
+ }
+ else if (ItemIdIsDead(hitemid))
+ {
+ /*
+ * Conjecture: if hitemid is dead then it had xids before the xids
+ * marked on LP_NORMAL items. So we just ignore this item and move
+ * onto the next, for the purposes of calculating
+ * latestRemovedXid.
+ */
+ }
+ else
+ Assert(!ItemIdIsUsed(hitemid));
+ }
+
+ if (BufferIsValid(buf))
+ {
+ LockBuffer(buf, BUFFER_LOCK_UNLOCK);
+ ReleaseBuffer(buf);
+ }
+
+ /*
+ * If all heap tuples were LP_DEAD then we will be returning
+ * InvalidTransactionId here, which avoids conflicts. This matches
+ * existing logic which assumes that LP_DEAD tuples must already be older
+ * than the latestRemovedXid on the cleanup record that set them as
+ * LP_DEAD, hence must already have generated a conflict.
+ */
+ delstate->ndeltids = finalndeltids;
+
+ return latestRemovedXid;
+}
+
+/*
+ * Determine how many favorable blocks are among blocks we'll access (which
+ * have been sorted by heapam_index_delete_check_sort() by the time we get
+ * called). The exact approach taken by heapam_index_delete_check() is
+ * influenced by the number of favorable blocks.
+ *
+ * Returns number of favorable blocks, starting from (and including) the first
+ * block in line for processing.
+ *
+ * Favorable blocks are contiguous heap blocks, which are likely to have
+ * relatively many dead items. These blocks are cheaper to access together
+ * all at once. Having many favorable blocks is common with low cardinality
+ * index tuples, where heap locality has a relatively large influence on which
+ * heap blocks we visit (and the order they're processed in). Being more
+ * aggressive with favorable blocks is slightly more expensive in the short
+ * term, but less expensive across related heapam_index_delete_check() calls.
+ *
+ * Note: We always indicate that there is at least 1 favorable block (the
+ * first in line to process). The first block must always be in sorted order
+ * because the ordering is relative to the first block (or previous block).
+ * This degenerate case isn't a problem for heapam_index_delete_check(), which
+ * is supposed to always visit the first heap page in line, regardless of any
+ * other factor.
+ */
+static int
+top_block_groups_favorable(IndexDeleteCounts *blockcounts, int nblockgroups,
+ TM_IndexDelete *deltids)
+{
+ int nblocksfavorable = 0;
+ BlockNumber lastblock = InvalidBlockNumber;
+
+ for (int b = 0; b < nblockgroups; b++)
+ {
+ IndexDeleteCounts *blockgroup = blockcounts + b;
+ TM_IndexDelete *firstgroup = deltids + blockgroup->ideltids;
+ BlockNumber thisblock = ItemPointerGetBlockNumber(&firstgroup->tid);
+
+ if (BlockNumberIsValid(lastblock) &&
+ (thisblock < lastblock ||
+ thisblock > lastblock + FAVORABLE_BLOCK_STRIDE))
+ break;
+
+ nblocksfavorable++;
+ lastblock = Min(thisblock, MaxBlockNumber - FAVORABLE_BLOCK_STRIDE);
+ }
+
+ Assert(nblocksfavorable >= 1);
+
+ return nblocksfavorable;
+}
+
+static inline int
+indexdelete_tids_cmp(ItemPointer tid1, ItemPointer tid2)
+{
+ {
+ BlockNumber blk1 = ItemPointerGetBlockNumber(tid1);
+ BlockNumber blk2 = ItemPointerGetBlockNumber(tid2);
+
+ if (blk1 != blk2)
+ return (blk1 < blk2) ? -1 : 1;
+ }
+ {
+ OffsetNumber pos1 = ItemPointerGetOffsetNumber(tid1);
+ OffsetNumber pos2 = ItemPointerGetOffsetNumber(tid2);
+
+ if (pos1 != pos2)
+ return (pos1 < pos2) ? -1 : 1;
+ }
+
+ pg_unreachable();
+
+ return 0;
+}
+
+static inline int
+indexdeletecount_cmp(IndexDeleteCounts *count1, IndexDeleteCounts *count2)
+{
+ uint32 ntids1,
+ ntids2;
+
+ /* We expect power-of-two values for npromisingtids fields */
+ Assert(count1->npromisingtids == 0 ||
+ ((count1->npromisingtids - 1) & count1->npromisingtids) == 0);
+ Assert(count2->npromisingtids == 0 ||
+ ((count2->npromisingtids - 1) & count2->npromisingtids) == 0);
+
+ /*
+ * Most significant field is npromisingtids, which we sort on in desc
+ * order. The usual asc comparison order is deliberately inverted here.
+ */
+ if (count1->npromisingtids > count2->npromisingtids)
+ return -1;
+ if (count1->npromisingtids < count2->npromisingtids)
+ return 1;
+
+ /*
+ * Tiebreak: desc ntids sort order.
+ *
+ * We cannot expect power-of-two values for ntids fields. We should
+ * behave as if they were already rounded up for us instead.
+ */
+ ntids1 = count1->ntids;
+ ntids2 = count2->ntids;
+ if (ntids1 != ntids2)
+ {
+ ntids1 = pg_nextpower2_32(ntids1);
+ ntids2 = pg_nextpower2_32(ntids2);
+
+ if (ntids1 > ntids2)
+ return -1;
+ if (ntids1 < ntids2)
+ return 1;
+ }
+
+ /*
+ * Tiebreak: asc offset-into-deltids-for-block (offset to first TID for
+ * block in deltids array) order.
+ *
+ * This is equivalent to sorting in ascending heap block number order
+ * (among otherwise equal subsets of the array). This approach allows us
+ * to avoid accessing the out-of-line TID. (We rely on the assumption
+ * that the deltids array was sorted in ascending heap TID order when
+ * these offsets to the first TID from each heap block group were formed.)
+ */
+ if (count1->ideltids > count2->ideltids)
+ return 1;
+ if (count1->ideltids < count2->ideltids)
+ return -1;
+
+ pg_unreachable();
+
+ return 0;
+}
+
+/*
+ * Two hand written shellshort implementations.
+ *
+ * The two sort operations needed by heapam_index_delete_check_sort() become
+ * quite noticeable on profiles of workloads with lots of index contention
+ * caused by non-HOT updates. Keeping costs down is important enough to
+ * justify several micro-optimizations. We could just use qsort() instead,
+ * but the indirection that it imposes is expensive enough to matter here.
+ * (The size of array elements also matters, which is why we keep it under 8
+ * bytes - swaps should be as fast as reasonably possible).
+ *
+ * We use shellsort here because it has many of the same strengths as an
+ * industrial-strength quicksort implementation, but is also lightweight in
+ * the sense that the entire implementation compiles to relatively few machine
+ * instructions. It is adaptive to inputs with some presorted subsets (which
+ * are typical here).
+ *
+ * This implementation is fast with array sizes up to about 1900. This covers
+ * all supported BLCKSZ values.
+ */
+static void
+heap_tid_shellsort(TM_IndexDelete *deltids, int ndeltids)
+{
+ int low = 0;
+
+ /* Think carefully before changing anything here */
+ StaticAssertStmt(sizeof(TM_IndexDelete) <= 8,
+ "element size exceeds 8 bytes");
+
+ for (int g = 0; g < lengthof(ShellsortGaps); g++)
+ {
+ for (int hi = ShellsortGaps[g], i = low + hi; i < ndeltids; i++)
+ {
+ TM_IndexDelete d = deltids[i];
+ int j = i;
+
+ while (j >= hi &&
+ indexdelete_tids_cmp(&deltids[j - hi].tid, &d.tid) >= 0)
+ {
+ deltids[j] = deltids[j - hi];
+ j -= hi;
+ }
+ deltids[j] = d;
+ }
+ }
+}
+
+static void
+index_delete_shellsort(IndexDeleteCounts *blockcounts, int nblockgroups)
+{
+ int low = 0;
+
+ /* Think carefully before changing anything here */
+ StaticAssertStmt(sizeof(IndexDeleteCounts) <= 8,
+ "element size exceeds 8 bytes");
+
+ for (int g = 0; g < lengthof(ShellsortGaps); g++)
+ {
+ for (int hi = ShellsortGaps[g], i = low + hi; i < nblockgroups; i++)
+ {
+ IndexDeleteCounts c = blockcounts[i];
+ int j = i;
+
+ while (j >= hi &&
+ indexdeletecount_cmp(&blockcounts[j - hi], &c) >= 0)
+ {
+ blockcounts[j] = blockcounts[j - hi];
+ j -= hi;
+ }
+ blockcounts[j] = c;
+ }
+ }
+}
+
+/*
+ * heapam_index_delete_check() helper function. Sorts deltids array in the
+ * order needed for useful processing.
+ *
+ * Groups heap TIDs from deltids into heap block number groupings. From
+ * there, sorts each heap block grouping by the total number of "promising"
+ * TIDs it contains (in desc order). For blocks with the same number of
+ * promising TIDs, tiebreak on the total heap TID count (also desc order).
+ *
+ * heapam_index_delete_check() only visits up to MAX_DELETE_HEAP_BLOCKS heap
+ * blocks due to the speculative nature of the batch index deletion
+ * optimization. These heap blocks had better be the most promising
+ * available, based on a variety of criteria. We make sure of that here.
+ *
+ * Sets new size of deltids array (ndeltids) in state. deltids will only have
+ * TIDs from the MAX_DELETE_HEAP_BLOCKS most promising heap blocks when we
+ * return (which is usually far fewer).
+ *
+ * Returns number of "favorable" blocks.
+ */
+static int
+heapam_index_delete_check_sort(Relation rel, TM_IndexDeleteOp *delstate)
+{
+ IndexDeleteCounts *blockcounts;
+ TM_IndexDelete *reordereddeltids;
+ BlockNumber curblock = InvalidBlockNumber;
+ int nblockgroups = 0;
+ int ncopied = 0;
+ int nblocksfavorable = 0;
+#ifdef USE_PREFETCH
+ int prefetch_distance;
+#endif
+
+ Assert(delstate->ndeltids > 0);
+
+ /* First sort caller's array by TID */
+ heap_tid_shellsort(delstate->deltids, delstate->ndeltids);
+
+ /* Calculate per-heap-block count of TIDs */
+ blockcounts = palloc(sizeof(IndexDeleteCounts) * delstate->ndeltids);
+ for (int i = 0; i < delstate->ndeltids; i++)
+ {
+ ItemPointer deltid = &delstate->deltids[i].tid;
+ TM_IndexStatus *dstatus = delstate->status + delstate->deltids[i].id;
+ bool ispromising = dstatus->ispromising;
+
+ if (curblock != ItemPointerGetBlockNumber(deltid))
+ {
+ /* New block group */
+ nblockgroups++;
+
+ Assert(curblock < ItemPointerGetBlockNumber(deltid) ||
+ !BlockNumberIsValid(curblock));
+
+ curblock = ItemPointerGetBlockNumber(deltid);
+ blockcounts[nblockgroups - 1].ideltids = i;
+ blockcounts[nblockgroups - 1].ntids = 1;
+ blockcounts[nblockgroups - 1].npromisingtids = 0;
+ }
+ else
+ {
+ blockcounts[nblockgroups - 1].ntids++;
+ }
+
+ if (ispromising)
+ blockcounts[nblockgroups - 1].npromisingtids++;
+ }
+
+ /*
+ * We're about ready to use index_delete_shellsort() to determine the
+ * optimal order for visiting heap pages. But before we do, round the
+ * number of promising tuples for each block group up to the nearest
+ * power-of-two (unless there are zero promising tuples). This scheme
+ * usefully divides heap pages into buckets. Each bucket contains heap
+ * pages that are approximately equally promising, that we want to treat
+ * as exactly equivalent (at least initially).
+ *
+ * While in general the presence of promising tuples (the hint that index
+ * AMs provide) is the best information that we have to go on, it is based
+ * on simple heuristics about duplicates in indexes that are understood to
+ * have specific flaws. We should not let the most promising heap pages
+ * win or lose on the basis of _relatively_ small differences in the total
+ * number of promising tuples. Small differences between the most
+ * promising few heap pages are effectively ignored by applying this
+ * power-of-two bucketing scheme.
+ *
+ * When we have lots of ties on the final bucket-ized npromisingtids among
+ * the most promising heap pages, we let heap locality determine the order
+ * in which we visit heap pages. This is helpful because it exploits the
+ * natural tendency for earlier heap blocks to accumulate more LP_DEAD
+ * items sooner in workloads with many non-HOT updates. It's also helpful
+ * because the effect over time is that we process related heap blocks
+ * sequentially, possibly with multiple rounds of processing over the same
+ * related heap blocks that are subject to continuous non-HOT updates over
+ * time.
+ *
+ * Note that we effectively have the same power-of-two bucketing scheme
+ * with the ntids field (which is compared after npromisingtids). The
+ * only reason that we don't fix nhtids here is that the original values
+ * will be needed when copying the final TIDs from winning block groups
+ * back into caller's deltids array.
+ */
+ for (int b = 0; b < nblockgroups; b++)
+ {
+ IndexDeleteCounts *blockgroup = blockcounts + b;
+
+ if (blockgroup->npromisingtids != 0)
+ blockgroup->npromisingtids =
+ pg_nextpower2_32((uint32) blockgroup->npromisingtids);
+ }
+
+ /* Sort groups and rearrange caller's deltids array */
+ index_delete_shellsort(blockcounts, nblockgroups);
+ reordereddeltids = palloc(delstate->ndeltids * sizeof(TM_IndexDelete));
+
+ nblockgroups = Min(MAX_DELETE_HEAP_BLOCKS, nblockgroups);
+ /* Determine number of favorable blocks at the start of array */
+ nblocksfavorable = top_block_groups_favorable(blockcounts, nblockgroups,
+ delstate->deltids);
+
+#ifdef USE_PREFETCH
+ /* Compute the prefetch distance that we will attempt to maintain */
+ if (IsCatalogRelation(rel))
+ prefetch_distance = maintenance_io_concurrency;
+ else
+ prefetch_distance =
+ get_tablespace_maintenance_io_concurrency(rel->rd_rel->reltablespace);
+
+ prefetch_distance = Min(prefetch_distance, nblockgroups);
+#endif
+
+ for (int b = 0; b < nblockgroups; b++)
+ {
+ IndexDeleteCounts *blockgroup = blockcounts + b;
+ TM_IndexDelete *firstgroup = delstate->deltids + blockgroup->ideltids;
+
+ memcpy(reordereddeltids + ncopied, firstgroup,
+ sizeof(TM_IndexDelete) * blockgroup->ntids);
+ ncopied += blockgroup->ntids;
+
+#ifdef USE_PREFETCH
+ if (prefetch_distance-- > 0)
+ {
+ BlockNumber hblock = ItemPointerGetBlockNumber(&firstgroup->tid);
+
+ PrefetchBuffer(rel, MAIN_FORKNUM, hblock);
+ }
+#endif
+ }
+
+ /* Copy final grouped and sorted TIDs back into start of caller's array */
+ memcpy(delstate->deltids, reordereddeltids,
+ sizeof(TM_IndexDelete) * ncopied);
+ delstate->ndeltids = ncopied;
+
+ /* be tidy */
+ pfree(reordereddeltids);
+ pfree(blockcounts);
+
+ return nblocksfavorable;
+}
+
/*
* Perform XLogInsert to register a heap cleanup info message. These
* messages are sent once per VACUUM and are required because
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index bba68e6898..21c3b5b740 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2533,7 +2533,7 @@ static const TableAmRoutine heapam_methods = {
.tuple_delete = heapam_tuple_delete,
.tuple_update = heapam_tuple_update,
.tuple_lock = heapam_tuple_lock,
- .index_delete_check = NULL,
+ .index_delete_check = heapam_index_delete_check,
.tuple_fetch_row_version = heapam_fetch_row_version,
.tuple_get_latest_tid = heap_get_latest_tid,
--
2.25.1
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-11-11 20:58 ` Victor Yegorov <[email protected]>
2020-11-12 23:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
1 sibling, 1 reply; 1661+ messages in thread
From: Victor Yegorov @ 2020-11-11 20:58 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
пн, 9 нояб. 2020 г. в 18:21, Peter Geoghegan <[email protected]>:
> On Tue, Nov 3, 2020 at 12:44 PM Peter Geoghegan <[email protected]> wrote:
> > v6 still needs more polishing -- my focus has still been on the
> > algorithm itself. But I think I'm almost done with that part -- it
> > seems unlikely that I'll be able to make any additional significant
> > improvements in that area after v6.
>
> Attached is v7, which tidies everything up. The project is now broken
> up into multiple patches, which can be committed separately. Every
> patch has a descriptive commit message. This should make it a lot
> easier to review.
>
And another test session, this time with scale=2000 and shared_buffers=512MB
(vs scale=1000 and shared_buffers=16GB previously). The rest of the setup
is the same:
- mtime column that is tracks update time
- index on (mtime, aid)
- tenner low cardinality index from Peter's earlier e-mail
- 3 pgbench scripts run in parallel on master and on v7 patchset (scripts
from the previous e-mail used here).
(I just realized that the size-after figures in my previous e-mail are off,
'cos failed
to ANALYZE table after the tests.)
Master
------
relkind | relname | nrows | blk_before | mb_before |
blk_after | mb_after | Diff
---------+-----------------------+-----------+------------+-----------+-----------+----------+-------
r | pgbench_accounts | 200000000 | 3278689 | 25614.8 |
3314951 | 25898.1 | +1.1%
i | accounts_mtime | 200000000 | 770080 | 6016.3 |
811946 | 6343.3 | +5.4%
i | pgbench_accounts_pkey | 200000000 | 548383 | 4284.2 |
548383 | 4284.2 | 0
i | tenner | 200000000 | 230701 | 1802.4 |
252346 | 1971.5 | +9.4%
(4 rows)
Patched
-------
relkind | relname | nrows | blk_before | mb_before |
blk_after | mb_after | Diff
---------+-----------------------+-----------+------------+-----------+-----------+----------+-------
r | pgbench_accounts | 200000000 | 3278689 | 25614.8 |
3330788 | 26021.8 | +1.6%
i | accounts_mtime | 200000000 | 770080 | 6016.3 |
806920 | 6304.1 | +4.8%
i | pgbench_accounts_pkey | 200000000 | 548383 | 4284.2 |
548383 | 4284.2 | 0
i | tenner | 200000000 | 230701 | 1802.4 |
230701 | 1802.4 | 0
(4 rows)
TPS
---
query | Master TPS | Patched TPS | Diff
----------------+------------+-------------+------
UPDATE + SELECT | 3024 | 2661 | -12%
3 SELECT in txn | 19073 | 19852 | +4%
15min SELECT | 2.4 | 3.9 | +60%
We can see that the patched version does much less disk writes during
UPDATEs and simple SELECTs and
eliminates write amplification for not involved indexes. (I'm really
excited to see these figures.)
On the other hand, there's quite a big drop on the UPDATEs throughput. For
sure, undersized shared_bufefrs
contribute to this drop. Still, my experience tells me that under
conditions at hand (disabled HOT due to index
over update time column) tables will tend to accumulate bloat and produce
unnecessary IO also from WAL.
Perhaps I need to conduct a longer test session, say 8+ hours to make
obstacles appear more like in real life.
--
Victor Yegorov
Master
------
relkind | relname | nrows | blk_before | mb_before | blk_after | mb_after | Diff
---------+-----------------------+-----------+------------+-----------+-----------+----------+-------
r | pgbench_accounts | 200000000 | 3278689 | 25614.8 | 3314951 | 25898.1 | +1.1%
i | accounts_mtime | 200000000 | 770080 | 6016.3 | 811946 | 6343.3 | +5.4%
i | pgbench_accounts_pkey | 200000000 | 548383 | 4284.2 | 548383 | 4284.2 | 0
i | tenner | 200000000 | 230701 | 1802.4 | 252346 | 1971.5 | +9.4%
(4 rows)
scaling factor: 2000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 10888764
latency average = 2.645 ms
tps = 3024.655171 (including connections establishing)
tps = 3024.656457 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.000 \set delta random(-5000, 5000)
0.045 BEGIN;
0.270 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
0.160 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
2.164 END;
scaling factor: 2000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 68662449
latency average = 0.419 ms
tps = 19072.900643 (including connections establishing)
tps = 19072.908953 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 3.2)
0.033 BEGIN;
0.117 SELECT abalance FROM pgbench_accounts WHERE aid = :aid1;
0.113 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.113 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.038 END;
scaling factor: 2000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 8731
latency average = 3306.752 ms
tps = 2.419293 (including connections establishing)
tps = 2.419294 (excluding connections establishing)
statement latencies in milliseconds:
3306.620 SELECT abalance FROM pgbench_accounts WHERE mtime > now() - INTERVAL '15min' ORDER BY aid;
Patched
-------
relkind | relname | nrows | blk_before | mb_before | blk_after | mb_after | Diff
---------+-----------------------+-----------+------------+-----------+-----------+----------+-------
r | pgbench_accounts | 200000000 | 3278689 | 25614.8 | 3330788 | 26021.8 | +1.6%
i | accounts_mtime | 200000000 | 770080 | 6016.3 | 806920 | 6304.1 | +4.8%
i | pgbench_accounts_pkey | 200000000 | 548383 | 4284.2 | 548383 | 4284.2 | 0
i | tenner | 200000000 | 230701 | 1802.4 | 230701 | 1802.4 | 0
(4 rows)
scaling factor: 2000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 9581078
latency average = 3.006 ms
tps = 2661.408684 (including connections establishing)
tps = 2661.409851 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.000 \set delta random(-5000, 5000)
0.044 BEGIN;
0.263 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
0.144 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
2.549 END;
scaling factor: 2000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 71467156
latency average = 0.403 ms
tps = 19851.985574 (including connections establishing)
tps = 19851.994168 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 3.2)
0.033 BEGIN;
0.112 SELECT abalance FROM pgbench_accounts WHERE aid = :aid1;
0.109 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.107 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.037 END;
scaling factor: 2000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 14115
latency average = 2047.201 ms
tps = 3.907774 (including connections establishing)
tps = 3.907776 (excluding connections establishing)
statement latencies in milliseconds:
2047.098 SELECT abalance FROM pgbench_accounts WHERE mtime > now() - INTERVAL '15min' ORDER BY aid;
Attachments:
[text/plain] 20201111-results-master.txt (2.5K, ../../CAGnEboh5ZsoTAeXX027=o-OBVdupx4C_scxjQ5epDtJ-gWrapA@mail.gmail.com/3-20201111-results-master.txt)
download | inline:
Master
------
relkind | relname | nrows | blk_before | mb_before | blk_after | mb_after | Diff
---------+-----------------------+-----------+------------+-----------+-----------+----------+-------
r | pgbench_accounts | 200000000 | 3278689 | 25614.8 | 3314951 | 25898.1 | +1.1%
i | accounts_mtime | 200000000 | 770080 | 6016.3 | 811946 | 6343.3 | +5.4%
i | pgbench_accounts_pkey | 200000000 | 548383 | 4284.2 | 548383 | 4284.2 | 0
i | tenner | 200000000 | 230701 | 1802.4 | 252346 | 1971.5 | +9.4%
(4 rows)
scaling factor: 2000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 10888764
latency average = 2.645 ms
tps = 3024.655171 (including connections establishing)
tps = 3024.656457 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.000 \set delta random(-5000, 5000)
0.045 BEGIN;
0.270 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
0.160 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
2.164 END;
scaling factor: 2000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 68662449
latency average = 0.419 ms
tps = 19072.900643 (including connections establishing)
tps = 19072.908953 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 3.2)
0.033 BEGIN;
0.117 SELECT abalance FROM pgbench_accounts WHERE aid = :aid1;
0.113 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.113 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.038 END;
scaling factor: 2000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 8731
latency average = 3306.752 ms
tps = 2.419293 (including connections establishing)
tps = 2.419294 (excluding connections establishing)
statement latencies in milliseconds:
3306.620 SELECT abalance FROM pgbench_accounts WHERE mtime > now() - INTERVAL '15min' ORDER BY aid;
[image/png] 20201111-transactions-and-disks.png (335.9K, ../../CAGnEboh5ZsoTAeXX027=o-OBVdupx4C_scxjQ5epDtJ-gWrapA@mail.gmail.com/4-20201111-transactions-and-disks.png)
download | view image
[image/png] 20201111-q1-UPDATE.png (323.4K, ../../CAGnEboh5ZsoTAeXX027=o-OBVdupx4C_scxjQ5epDtJ-gWrapA@mail.gmail.com/5-20201111-q1-UPDATE.png)
download | view image
[image/png] 20201111-q2-SELECT.png (294.4K, ../../CAGnEboh5ZsoTAeXX027=o-OBVdupx4C_scxjQ5epDtJ-gWrapA@mail.gmail.com/6-20201111-q2-SELECT.png)
download | view image
[image/png] 20201111-q3-15min-SELECT.png (286.0K, ../../CAGnEboh5ZsoTAeXX027=o-OBVdupx4C_scxjQ5epDtJ-gWrapA@mail.gmail.com/7-20201111-q3-15min-SELECT.png)
download | view image
[application/octet-stream] 20201111-postgresql.auto.conf (704B, ../../CAGnEboh5ZsoTAeXX027=o-OBVdupx4C_scxjQ5epDtJ-gWrapA@mail.gmail.com/8-20201111-postgresql.auto.conf)
download
[text/plain] 20201111-results-patched.txt (2.5K, ../../CAGnEboh5ZsoTAeXX027=o-OBVdupx4C_scxjQ5epDtJ-gWrapA@mail.gmail.com/9-20201111-results-patched.txt)
download | inline:
Patched
-------
relkind | relname | nrows | blk_before | mb_before | blk_after | mb_after | Diff
---------+-----------------------+-----------+------------+-----------+-----------+----------+-------
r | pgbench_accounts | 200000000 | 3278689 | 25614.8 | 3330788 | 26021.8 | +1.6%
i | accounts_mtime | 200000000 | 770080 | 6016.3 | 806920 | 6304.1 | +4.8%
i | pgbench_accounts_pkey | 200000000 | 548383 | 4284.2 | 548383 | 4284.2 | 0
i | tenner | 200000000 | 230701 | 1802.4 | 230701 | 1802.4 | 0
(4 rows)
scaling factor: 2000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 9581078
latency average = 3.006 ms
tps = 2661.408684 (including connections establishing)
tps = 2661.409851 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.000 \set delta random(-5000, 5000)
0.044 BEGIN;
0.263 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
0.144 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
2.549 END;
scaling factor: 2000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 71467156
latency average = 0.403 ms
tps = 19851.985574 (including connections establishing)
tps = 19851.994168 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 3.2)
0.033 BEGIN;
0.112 SELECT abalance FROM pgbench_accounts WHERE aid = :aid1;
0.109 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.107 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.037 END;
scaling factor: 2000
query mode: simple
number of clients: 8
number of threads: 2
duration: 3600 s
number of transactions actually processed: 14115
latency average = 2047.201 ms
tps = 3.907774 (including connections establishing)
tps = 3.907776 (excluding connections establishing)
statement latencies in milliseconds:
2047.098 SELECT abalance FROM pgbench_accounts WHERE mtime > now() - INTERVAL '15min' ORDER BY aid;
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 20:58 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
@ 2020-11-12 23:00 ` Peter Geoghegan <[email protected]>
2020-11-12 23:18 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-15 22:29 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-17 15:24 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
0 siblings, 3 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-11-12 23:00 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Wed, Nov 11, 2020 at 12:58 PM Victor Yegorov <[email protected]> wrote:
> On the other hand, there's quite a big drop on the UPDATEs throughput. For sure, undersized shared_bufefrs
> contribute to this drop. Still, my experience tells me that under conditions at hand (disabled HOT due to index
> over update time column) tables will tend to accumulate bloat and produce unnecessary IO also from WAL.
I think that the big SELECT statement with an "ORDER BY mtime ... "
was a good way of demonstrating the advantages of the patch.
Attached is v8, which has the enhancements for low cardinality data
that I mentioned earlier today. It also simplifies the logic for
dealing with posting lists that we need to delete some TIDs from.
These posting list simplifications also make the code a bit more
efficient, which might be noticeable during benchmarking.
Perhaps your "we have 5,2% slowdown in UPDATE speed" issue will be at
least somewhat fixed by the enhancements to v8?
Another consideration when testing the patch is the behavioral
differences we see between cases where system throughput is as high as
possible, versus similar cases where we have a limit in place (i.e.
pgbench --rate=? was used). These two cases are quite different with
the patch because the patch can no longer be lazy without a limit --
we tend to see noticeably more CPU cycles spent doing bottom-up
deletion, though everything else about the profile looks similar (I
generally use "perf top" to keep an eye on these things).
It's possible to sometimes see increases in latency (regressions) when
running without a limit, at least in the short term. These increases
can go away when a rate limit is imposed that is perhaps as high as
50% of the max TPS. In general, I think that it makes sense to focus
on latency when we have some kind of limit in place. A
non-rate-limited case is less realistic.
> Perhaps I need to conduct a longer test session, say 8+ hours to make obstacles appear more like in real life.
That would be ideal. It is inconvenient to run longer benchmarks, but
it's an important part of performance validation.
BTW, another related factor is that the patch takes longer to "warm
up". I notice this "warm-up" effect on the second or subsequent runs,
where we have lots of garbage in indexes even with the patch, and even
in the first 5 seconds of execution. The extra I/Os for heap page
accesses end up being buffer misses instead of buffer hits, until the
cache warms. This is not really a problem with fewer longer runs,
because there is relatively little "special warm-up time". (We rarely
experience heap page misses during ordinary execution because the
heapam.c code is smart about locality of access.)
I noticed that the pgbench_accounts_pkey index doesn't grow at all on
the master branch in 20201111-results-master.txt. But it's always just
a matter of time until that happens without the patch. The PK/unique
index takes longer to bloat because it alone benefits from LP_DEAD
setting, especially within _bt_check_unique(). But this advantage will
naturally erode over time. It'll probably take a couple of hours or
more with larger scale factors -- I'm thinking of pgbench scale
factors over 2000.
When the LP_DEAD bit setting isn't very effective (say it's 50%
effective), it's only a matter of time until every original page
splits. But that's also true when LP_DEAD setting is 99% effective.
While it is much less likely that any individual page will split when
LP_DEAD bits are almost always set, the fundamental problem remains,
even with 99% effectiveness. That problem is: each page only has to be
unlucky once. On a long enough timeline, the difference between 50%
effective and 99% effective may be very small. And "long enough
timeline" may not actually be very long, at least to a human.
Of course, the patch still benefits from LP_DEAD bits getting set by
queries -- no change there. It just doesn't *rely* on LP_DEAD bits
keeping up with transactions that create bloat on every leaf page.
Maybe the patch will behave exactly the same way as the master branch
-- it's workload dependent. Actually, it behaves in exactly the same
way for about the first 5 - 15 minutes following pgbench
initialization. This is roughly how long it takes before the master
branch has even one page split. You could say that the patch "makes
the first 5 minutes last forever".
(Not sure if any of this is obvious to you by now, just saying.)
Thanks!
--
Peter Geoghegan
Attachments:
[application/octet-stream] v8-0001-Deprecate-nbtree-s-BTP_HAS_GARBAGE-flag.patch (21.8K, ../../CAH2-Wzm46rS1JDmRO0fbnQDpYyD2PrX2cYsa8-5=nhp7nT_w9A@mail.gmail.com/2-v8-0001-Deprecate-nbtree-s-BTP_HAS_GARBAGE-flag.patch)
download | inline diff:
From e410e2deed62c66e924a869548fd39895b79e0aa Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Mon, 9 Nov 2020 12:59:29 -0800
Subject: [PATCH v8 1/5] Deprecate nbtree's BTP_HAS_GARBAGE flag.
Streamline handling of the various strategies that we have to avoid a
page split in nbtinsert.c. When it looks like a leaf page is about to
overflow, we now perform deleting LP_DEAD items and deduplication in one
central place. This greatly simplifies _bt_findinsertloc().
This has an independently useful consequence: nbtree no longer relies on
the BTP_HAS_GARBAGE page level flag/hint for anything important. We
still set and unset the flag in the same way as before, but it's no
longer treated as a gating condition when considering if we should check
for already-set LP_DEAD bits. This happens at the point where the page
looks like it might have to be split anyway, so simply checking the
LP_DEAD bits in passing is practically free. This avoids missing
LP_DEAD bits just because the page-level hint is unset, which is
probably reasonably common (e.g. it happens when VACUUM unsets the
page-level flag without actually removing index tuples whose LP_DEAD-bit
was set recently, after the VACUUM operation began but before it reached
the leaf page in question).
Note that this isn't a big behavioral change compared to PostgreSQL 13.
We were already checking for set LP_DEAD bits regardless of whether the
BTP_HAS_GARBAGE page level flag was set before we considered doing a
deduplication pass. This commit only goes slightly further by doing the
same check for all indexes, even indexes where deduplication won't be
performed.
We don't completely remove the BTP_HAS_GARBAGE flag. We still rely on
it as a gating condition with pg_upgrade'd indexes from before B-tree
version 4/PostgreSQL 12. That makes sense because we sometimes have to
make a choice among pages full of duplicates when inserting a tuple with
pre version 4 indexes. It probably still pays to avoid accessing the
line pointer array of a page there, since it won't yet be clear whether
we'll insert on to the page in question at all, let alone split it as a
result.
Author: Peter Geoghegan <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wzm+maE3apHB8NOtmM=p-DO65j2V5GzAWCOEEuy3JZgb2g@mail.gmail.com
---
src/include/access/nbtree.h | 8 +-
src/backend/access/nbtree/nbtdedup.c | 76 +++-----------
src/backend/access/nbtree/nbtinsert.c | 144 +++++++++++++++++---------
src/backend/access/nbtree/nbtpage.c | 37 ++++---
src/backend/access/nbtree/nbtutils.c | 3 +-
src/backend/access/nbtree/nbtxlog.c | 3 +-
6 files changed, 141 insertions(+), 130 deletions(-)
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index 65d9698b89..e8fecc6026 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -75,7 +75,7 @@ typedef BTPageOpaqueData *BTPageOpaque;
#define BTP_META (1 << 3) /* meta-page */
#define BTP_HALF_DEAD (1 << 4) /* empty, but still in tree */
#define BTP_SPLIT_END (1 << 5) /* rightmost page of split group */
-#define BTP_HAS_GARBAGE (1 << 6) /* page has LP_DEAD tuples */
+#define BTP_HAS_GARBAGE (1 << 6) /* page has LP_DEAD tuples (deprecated) */
#define BTP_INCOMPLETE_SPLIT (1 << 7) /* right sibling's downlink is missing */
/*
@@ -1027,9 +1027,9 @@ extern void _bt_parallel_advance_array_keys(IndexScanDesc scan);
/*
* prototypes for functions in nbtdedup.c
*/
-extern void _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
- IndexTuple newitem, Size newitemsz,
- bool checkingunique);
+extern void _bt_dedup_pass(Relation rel, Buffer buf, Relation heapRel,
+ IndexTuple newitem, Size newitemsz,
+ bool checkingunique);
extern void _bt_dedup_start_pending(BTDedupState state, IndexTuple base,
OffsetNumber baseoff);
extern bool _bt_dedup_save_htid(BTDedupState state, IndexTuple itup);
diff --git a/src/backend/access/nbtree/nbtdedup.c b/src/backend/access/nbtree/nbtdedup.c
index f6be865b17..9e535124c4 100644
--- a/src/backend/access/nbtree/nbtdedup.c
+++ b/src/backend/access/nbtree/nbtdedup.c
@@ -28,9 +28,7 @@ static bool _bt_posting_valid(IndexTuple posting);
#endif
/*
- * Deduplicate items on a leaf page. The page will have to be split by caller
- * if we cannot successfully free at least newitemsz (we also need space for
- * newitem's line pointer, which isn't included in caller's newitemsz).
+ * Perform a deduplication pass.
*
* The general approach taken here is to perform as much deduplication as
* possible to free as much space as possible. Note, however, that "single
@@ -43,76 +41,32 @@ static bool _bt_posting_valid(IndexTuple posting);
* handle those if and when the anticipated right half page gets its own
* deduplication pass, following further inserts of duplicates.)
*
- * This function should be called during insertion, when the page doesn't have
- * enough space to fit an incoming newitem. If the BTP_HAS_GARBAGE page flag
- * was set, caller should have removed any LP_DEAD items by calling
- * _bt_vacuum_one_page() before calling here. We may still have to kill
- * LP_DEAD items here when the page's BTP_HAS_GARBAGE hint is falsely unset,
- * but that should be rare. Also, _bt_vacuum_one_page() won't unset the
- * BTP_HAS_GARBAGE flag when it finds no LP_DEAD items, so a successful
- * deduplication pass will always clear it, just to keep things tidy.
+ * The page will have to be split if we cannot successfully free at least
+ * newitemsz (we also need space for newitem's line pointer, which isn't
+ * included in caller's newitemsz).
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
*/
void
-_bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
- IndexTuple newitem, Size newitemsz, bool checkingunique)
+_bt_dedup_pass(Relation rel, Buffer buf, Relation heapRel, IndexTuple newitem,
+ Size newitemsz, bool checkingunique)
{
OffsetNumber offnum,
minoff,
maxoff;
Page page = BufferGetPage(buf);
- BTPageOpaque opaque;
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
Page newpage;
- OffsetNumber deletable[MaxIndexTuplesPerPage];
BTDedupState state;
- int ndeletable = 0;
Size pagesaving = 0;
bool singlevalstrat = false;
int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
- /*
- * We can't assume that there are no LP_DEAD items. For one thing, VACUUM
- * will clear the BTP_HAS_GARBAGE hint without reliably removing items
- * that are marked LP_DEAD. We don't want to unnecessarily unset LP_DEAD
- * bits when deduplicating items. Allowing it would be correct, though
- * wasteful.
- */
- opaque = (BTPageOpaque) PageGetSpecialPointer(page);
- minoff = P_FIRSTDATAKEY(opaque);
- maxoff = PageGetMaxOffsetNumber(page);
- for (offnum = minoff;
- offnum <= maxoff;
- offnum = OffsetNumberNext(offnum))
- {
- ItemId itemid = PageGetItemId(page, offnum);
-
- if (ItemIdIsDead(itemid))
- deletable[ndeletable++] = offnum;
- }
-
- if (ndeletable > 0)
- {
- _bt_delitems_delete(rel, buf, deletable, ndeletable, heapRel);
-
- /*
- * Return when a split will be avoided. This is equivalent to
- * avoiding a split using the usual _bt_vacuum_one_page() path.
- */
- if (PageGetFreeSpace(page) >= newitemsz)
- return;
-
- /*
- * Reconsider number of items on page, in case _bt_delitems_delete()
- * managed to delete an item or two
- */
- minoff = P_FIRSTDATAKEY(opaque);
- maxoff = PageGetMaxOffsetNumber(page);
- }
-
/* Passed-in newitemsz is MAXALIGNED but does not include line pointer */
newitemsz += sizeof(ItemIdData);
/*
- * By here, it's clear that deduplication will definitely be attempted.
* Initialize deduplication state.
*
* It would be possible for maxpostingsize (limit on posting list tuple
@@ -138,6 +92,9 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
/* nintervals should be initialized to zero */
state->nintervals = 0;
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
+
/* Determine if "single value" strategy should be used */
if (!checkingunique)
singlevalstrat = _bt_do_singleval(rel, page, state, minoff, newitem);
@@ -259,10 +216,9 @@ _bt_dedup_one_page(Relation rel, Buffer buf, Relation heapRel,
/*
* By here, it's clear that deduplication will definitely go ahead.
*
- * Clear the BTP_HAS_GARBAGE page flag in the unlikely event that it is
- * still falsely set, just to keep things tidy. (We can't rely on
- * _bt_vacuum_one_page() having done this already, and we can't rely on a
- * page split or VACUUM getting to it in the near future.)
+ * Clear the BTP_HAS_GARBAGE page flag. The index must be a heapkeyspace
+ * index, and as such we'll never pay attention to BTP_HAS_GARBAGE anyway.
+ * But keep things tidy.
*/
if (P_HAS_GARBAGE(opaque))
{
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index d36f7557c8..1ab98588c8 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -58,7 +58,10 @@ static void _bt_insert_parent(Relation rel, Buffer buf, Buffer rbuf,
static Buffer _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf);
static inline bool _bt_pgaddtup(Page page, Size itemsize, IndexTuple itup,
OffsetNumber itup_off, bool newfirstdataitem);
-static void _bt_vacuum_one_page(Relation rel, Buffer buffer, Relation heapRel);
+static void _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
+ BTInsertState insertstate,
+ bool lpdeadonly, bool checkingunique,
+ bool uniquedup);
/*
* _bt_doinsert() -- Handle insertion of a single index tuple in the tree.
@@ -871,38 +874,14 @@ _bt_findinsertloc(Relation rel,
}
/*
- * If the target page is full, see if we can obtain enough space by
- * erasing LP_DEAD items. If that fails to free enough space, see if
- * we can avoid a page split by performing a deduplication pass over
- * the page.
- *
- * We only perform a deduplication pass for a checkingunique caller
- * when the incoming item is a duplicate of an existing item on the
- * leaf page. This heuristic avoids wasting cycles -- we only expect
- * to benefit from deduplicating a unique index page when most or all
- * recently added items are duplicates. See nbtree/README.
+ * If the target page is full, see if we can obtain enough space using
+ * one or more strategies (e.g. erasing LP_DEAD items, deduplication).
+ * Page splits are expensive, and should only go ahead when truly
+ * necessary.
*/
if (PageGetFreeSpace(page) < insertstate->itemsz)
- {
- if (P_HAS_GARBAGE(lpageop))
- {
- _bt_vacuum_one_page(rel, insertstate->buf, heapRel);
- insertstate->bounds_valid = false;
-
- /* Might as well assume duplicates (if checkingunique) */
- uniquedup = true;
- }
-
- if (itup_key->allequalimage && BTGetDeduplicateItems(rel) &&
- (!checkingunique || uniquedup) &&
- PageGetFreeSpace(page) < insertstate->itemsz)
- {
- _bt_dedup_one_page(rel, insertstate->buf, heapRel,
- insertstate->itup, insertstate->itemsz,
- checkingunique);
- insertstate->bounds_valid = false;
- }
- }
+ _bt_delete_or_dedup_one_page(rel, heapRel, insertstate, false,
+ checkingunique, uniquedup);
}
else
{
@@ -942,8 +921,9 @@ _bt_findinsertloc(Relation rel,
*/
if (P_HAS_GARBAGE(lpageop))
{
- _bt_vacuum_one_page(rel, insertstate->buf, heapRel);
- insertstate->bounds_valid = false;
+ /* Erase LP_DEAD items (won't deduplicate) */
+ _bt_delete_or_dedup_one_page(rel, heapRel, insertstate, true,
+ checkingunique, false);
if (PageGetFreeSpace(page) >= insertstate->itemsz)
break; /* OK, now we have enough space */
@@ -993,14 +973,17 @@ _bt_findinsertloc(Relation rel,
* performing a posting list split, so delete all LP_DEAD items early.
* This is the only case where LP_DEAD deletes happen even though
* there is space for newitem on the page.
+ *
+ * This can only erase LP_DEAD items (it won't deduplicate).
*/
- _bt_vacuum_one_page(rel, insertstate->buf, heapRel);
+ _bt_delete_or_dedup_one_page(rel, heapRel, insertstate, true,
+ checkingunique, false);
/*
* Do new binary search. New insert location cannot overlap with any
* posting list now.
*/
- insertstate->bounds_valid = false;
+ Assert(!insertstate->bounds_valid);
insertstate->postingoff = 0;
newitemoff = _bt_binsrch_insert(rel, insertstate);
Assert(insertstate->postingoff == 0);
@@ -2623,32 +2606,60 @@ _bt_pgaddtup(Page page,
}
/*
- * _bt_vacuum_one_page - vacuum just one index page.
+ * _bt_delete_or_dedup_one_page - Try to avoid a leaf page split by attempting
+ * a variety of operations.
*
- * Try to remove LP_DEAD items from the given page. The passed buffer
- * must be exclusive-locked, but unlike a real VACUUM, we don't need a
- * super-exclusive "cleanup" lock (see nbtree/README).
+ * There are two operations performed here: deleting items already marked
+ * LP_DEAD, and deduplication. If both operations fail to free enough space
+ * for the incoming item then caller will go on to split the page. We always
+ * attempt our preferred strategy (which is to delete items whose LP_DEAD bit
+ * are set) first. If that doesn't work out we move on to deduplication.
+ *
+ * Caller's checkingunique and uniquedup arguments help us decide if we should
+ * perform deduplication, which is primarily useful with low cardinality data,
+ * but can sometimes absorb version churn.
+ *
+ * Callers that only want us to look for/delete LP_DEAD items can ask for that
+ * directly by passing true 'lpdeadonly' argument.
+ *
+ * Note: We used to only delete LP_DEAD items when the BTP_HAS_GARBAGE page
+ * level flag was found set. The flag was useful back when there wasn't
+ * necessarily one single page for a duplicate tuple to go on (before heap TID
+ * became a part of the key space in version 4 indexes). But we don't
+ * actually look at the flag anymore (it's not a gating condition for our
+ * caller). That would cause us to miss tuples that are safe to delete,
+ * without getting any benefit in return. We know that the alternative is to
+ * split the page; scanning the line pointer array in passing won't have
+ * noticeable overhead. (We still maintain the BTP_HAS_GARBAGE flag despite
+ * all this because !heapkeyspace indexes must still do a "getting tired"
+ * linear search in the same way, and so are likely to still benefit.
+ * !heapkeyspace callers do in fact use the BTP_HAS_GARBAGE flag as a gating
+ * condition.)
*/
static void
-_bt_vacuum_one_page(Relation rel, Buffer buffer, Relation heapRel)
+_bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
+ BTInsertState insertstate,
+ bool lpdeadonly, bool checkingunique,
+ bool uniquedup)
{
OffsetNumber deletable[MaxIndexTuplesPerPage];
int ndeletable = 0;
OffsetNumber offnum,
- minoff,
maxoff;
+ Buffer buffer = insertstate->buf;
+ BTScanInsert itup_key = insertstate->itup_key;
Page page = BufferGetPage(buffer);
BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
Assert(P_ISLEAF(opaque));
+ Assert(lpdeadonly || itup_key->heapkeyspace);
/*
* Scan over all items to see which ones need to be deleted according to
* LP_DEAD flags.
*/
- minoff = P_FIRSTDATAKEY(opaque);
maxoff = PageGetMaxOffsetNumber(page);
- for (offnum = minoff;
+ for (offnum = P_FIRSTDATAKEY(opaque);
offnum <= maxoff;
offnum = OffsetNumberNext(offnum))
{
@@ -2659,12 +2670,51 @@ _bt_vacuum_one_page(Relation rel, Buffer buffer, Relation heapRel)
}
if (ndeletable > 0)
+ {
_bt_delitems_delete(rel, buffer, deletable, ndeletable, heapRel);
+ insertstate->bounds_valid = false;
+
+ /* Return when a page split has already been avoided */
+ if (PageGetFreeSpace(page) >= insertstate->itemsz)
+ return;
+
+ /* Might as well assume duplicates (if checkingunique) */
+ uniquedup = true;
+ }
/*
- * Note: if we didn't find any LP_DEAD items, then the page's
- * BTP_HAS_GARBAGE hint bit is falsely set. We do not bother expending a
- * separate write to clear it, however. We will clear it when we split
- * the page, or when deduplication runs.
+ * Some callers only want to delete LP_DEAD items. Return early for these
+ * callers.
+ *
+ * Note: The page's BTP_HAS_GARBAGE hint flag may still be set when we
+ * return at this point (or when we go on the try either or both of our
+ * other strategies and they also fail). We do not bother expending a
+ * separate write to clear it, however. Caller will definitely clear it
+ * when it goes on to split the page (plus deduplication knows to clear
+ * the flag when it actually modifies the page).
*/
+ if (lpdeadonly)
+ return;
+
+ /*
+ * We can get called in the checkingunique case when there is no reason to
+ * believe that there are any duplicates on the page; we should at least
+ * still check for LP_DEAD items. Now that we have, and now that it has
+ * not helped, give up and let caller split the page. Deduplication
+ * cannot be justified given there is no reason to think that there are
+ * duplicates.
+ */
+ if (checkingunique && !uniquedup)
+ return;
+
+ /* Assume bounds about to be invalidated (this is almost certain now) */
+ insertstate->bounds_valid = false;
+
+ /*
+ * Perform deduplication pass, though only when it is enabled for the
+ * index and known to be safe (it must be an allequalimage index).
+ */
+ if (BTGetDeduplicateItems(rel) && itup_key->allequalimage)
+ _bt_dedup_pass(rel, buffer, heapRel, insertstate->itup,
+ insertstate->itemsz, checkingunique);
}
diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c
index 7f392480ac..e192873f19 100644
--- a/src/backend/access/nbtree/nbtpage.c
+++ b/src/backend/access/nbtree/nbtpage.c
@@ -1187,8 +1187,11 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
* array of offset numbers.
*
* PageIndexTupleOverwrite() won't unset each item's LP_DEAD bit when it
- * happens to already be set. Although we unset the BTP_HAS_GARBAGE page
- * level flag, unsetting individual LP_DEAD bits should still be avoided.
+ * happens to already be set. It's important that we not interfere with
+ * garbage collection mechanisms that use _bt_delitems_delete(). Besides,
+ * it'd just be messy. We'd have to explicitly log a latestRemovedXid
+ * cutoff, just like _bt_delitems_delete(). Accessing tableam blocks
+ * again from here is rather unappealing.
*/
for (int i = 0; i < nupdatable; i++)
{
@@ -1215,20 +1218,12 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
opaque->btpo_cycleid = 0;
/*
- * Mark the page as not containing any LP_DEAD items. This is not
- * certainly true (there might be some that have recently been marked, but
- * weren't targeted by VACUUM's heap scan), but it will be true often
- * enough. VACUUM does not delete items purely because they have their
- * LP_DEAD bit set, since doing so would necessitate explicitly logging a
- * latestRemovedXid cutoff (this is how _bt_delitems_delete works).
+ * Clear the BTP_HAS_GARBAGE page flag.
*
- * The consequences of falsely unsetting BTP_HAS_GARBAGE should be fairly
- * limited, since we never falsely unset an LP_DEAD bit. Workloads that
- * are particularly dependent on LP_DEAD bits being set quickly will
- * usually manage to set the BTP_HAS_GARBAGE flag before the page fills up
- * again anyway. Furthermore, attempting a deduplication pass will remove
- * all LP_DEAD items, regardless of whether the BTP_HAS_GARBAGE hint bit
- * is set or not.
+ * This flag indicates the presence of LP_DEAD items on the page (though
+ * not reliably). We only use it with pg_upgrade'd !heapkeyspace indexes.
+ * (Otherwise we check all of the line pointers directly. The cost of
+ * doing it that way is negligible compared to splitting the page.)
*/
opaque->btpo_flags &= ~BTP_HAS_GARBAGE;
@@ -1310,10 +1305,18 @@ _bt_delitems_delete(Relation rel, Buffer buf,
/*
* Unlike _bt_delitems_vacuum, we *must not* clear the vacuum cycle ID,
- * because this is not called by VACUUM. Just clear the BTP_HAS_GARBAGE
- * page flag, since we deleted all items with their LP_DEAD bit set.
+ * because this is not called by VACUUM
*/
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+
+ /*
+ * Clear the BTP_HAS_GARBAGE page flag.
+ *
+ * This flag indicates the presence of LP_DEAD items on the page (though
+ * not reliably). We only use it with pg_upgrade'd !heapkeyspace indexes.
+ * (Otherwise we check all of the line pointers directly. The cost of
+ * doing it that way is negligible compared to splitting the page.)
+ */
opaque->btpo_flags &= ~BTP_HAS_GARBAGE;
MarkBufferDirty(buf);
diff --git a/src/backend/access/nbtree/nbtutils.c b/src/backend/access/nbtree/nbtutils.c
index 81589b9056..2f5f14e527 100644
--- a/src/backend/access/nbtree/nbtutils.c
+++ b/src/backend/access/nbtree/nbtutils.c
@@ -1877,7 +1877,8 @@ _bt_killitems(IndexScanDesc scan)
* Since this can be redone later if needed, mark as dirty hint.
*
* Whenever we mark anything LP_DEAD, we also set the page's
- * BTP_HAS_GARBAGE flag, which is likewise just a hint.
+ * BTP_HAS_GARBAGE flag, which is likewise just a hint. (Note that we
+ * only rely on the page-level flag in !heapkeyspace indexes.)
*/
if (killedsomething)
{
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index e913226760..5135b800af 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -1065,7 +1065,8 @@ btree_mask(char *pagedata, BlockNumber blkno)
/*
* BTP_HAS_GARBAGE is just an un-logged hint bit. So, mask it. See
- * _bt_killitems(), _bt_check_unique() for details.
+ * _bt_delete_or_dedup_one_page(), _bt_killitems(), and _bt_check_unique()
+ * for details.
*/
maskopaq->btpo_flags &= ~BTP_HAS_GARBAGE;
--
2.25.1
[application/octet-stream] v8-0002-Make-tableam-interface-support-bottom-up-deletion.patch (7.8K, ../../CAH2-Wzm46rS1JDmRO0fbnQDpYyD2PrX2cYsa8-5=nhp7nT_w9A@mail.gmail.com/3-v8-0002-Make-tableam-interface-support-bottom-up-deletion.patch)
download | inline diff:
From 6df2542da208621a9d8ec09c3b4f39ca20b5a5b6 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Mon, 9 Nov 2020 12:59:29 -0800
Subject: [PATCH v8 2/5] Make tableam interface support bottom-up deletion.
Teach tableam about bottom-up index deletion. This mechanism allows an
index AM to cooperate with a tableam in deleting index tuples at regular
intervals. The general idea is to avoid accumulating too many versions
in the index for any given logically row, without doing any extra work
before the situation gets out of hand at a localized page in an index.
This commit isn't useful on its own. An upcoming commit will add
support to nbtree. A further commit will provide complete functionality
by adding support to heapam.
Author: Peter Geoghegan <[email protected]>
Reviewed-By: Victor Yegorov <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wzm+maE3apHB8NOtmM=p-DO65j2V5GzAWCOEEuy3JZgb2g@mail.gmail.com
---
src/include/access/tableam.h | 99 ++++++++++++++++++++++++
src/backend/access/heap/heapam_handler.c | 1 +
src/backend/access/table/tableam.c | 6 +-
3 files changed, 103 insertions(+), 3 deletions(-)
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 387eb34a61..5cd698c885 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -128,6 +128,75 @@ typedef struct TM_FailureData
bool traversed;
} TM_FailureData;
+/*
+ * State used when calling table_index_delete_check() to perform "bottom up"
+ * deletion of duplicate index tuples. State is intialized by index AM
+ * caller, while state is finalized by tableam, which modifies state.
+ */
+typedef struct TM_IndexDelete
+{
+ ItemPointerData tid; /* table TID from index tuple */
+ int16 id; /* Offset into TM_IndexStatus array */
+} TM_IndexDelete;
+
+typedef struct TM_IndexStatus
+{
+ OffsetNumber idxoffnum; /* Index am page offset number */
+ int16 tupsize; /* Space freed in index if tuple deleted */
+ bool ispromising; /* Is a duplicate within index? */
+ bool deleteitup; /* Was tableam tuple found dead? */
+} TM_IndexStatus;
+
+/*
+ * State representing one single bottom-up index deletion operation.
+ *
+ * Index am caller provides a TM_IndexDeleteOp, which points to two palloc()'d
+ * arrays. Each array has one entry per TID that the tableam is asked to
+ * consider (typically these are all of the TIDs from a single index page, so
+ * there could be hundreds or even thousand of entries in arrays). ndeltids
+ * tracks the current number of entries.
+ *
+ * The two arrays are conceptually one single array. Two arrays/structs are
+ * used for performance reasons. (We really need to keep the TM_IndexDelete
+ * struct small so that the tableam can do an initial sort by TID as quickly
+ * as possible.)
+ *
+ * The index AM should keep track of which index tuple relates to which entry
+ * by setting idxoffnum (and/or relying on each entry being uniquely
+ * identifiable using tid). Index AM requests target free space indicated by
+ * "targetfreespace". Index AM also represents the space saving for each TID
+ * by filling in the tupsize for each array element. The tableam must balance
+ * the requirements of the index AM against the costs paid in the tableam.
+ *
+ * The index AM provides strong hints about where to look to the tableam by
+ * marking some entries as "promising". Index AM does this with duplicate
+ * index tuples that are strongly suspected to be old versions left behind by
+ * UPDATEs that did not logically changed any indexed values. Index AM may
+ * find it helpful to only mark TIDs/entries as promising when they're thought
+ * to have been affected by such an UPDATE in the recent past.
+ *
+ * The tableam marks individual entries as deletable for the index AM. It's
+ * common for the final array to be shrunk in size. The index AM caller
+ * should do nothing if on return delstate.ndeltids is found set to zero. The
+ * index AM caller only needs to consider the first ndeltids from the final
+ * array, which is typically much smaller than its original size (tableam
+ * updates ndeltids in state). One reason for this is that the tableam can
+ * naturally only afford to a few tableam blocks on each call -- it typically
+ * won't even try to check most of the entries from the tableam.
+ *
+ * The tableam typically sorts the delstate.deltids array by TID. The index
+ * AM should be prepared to restore the array to its useful/original order.
+ * The array is typically far smaller than its original size by then, so that
+ * step should be relatively fast.
+ */
+typedef struct TM_IndexDeleteOp
+{
+ int ndeltids; /* Number of deltids/status for op */
+ TM_IndexDelete *deltids;
+ TM_IndexStatus *status;
+ int targetfreespace; /* Guides tableam on requirements */
+} TM_IndexDeleteOp;
+
/* "options" flag bits for table_tuple_insert */
/* TABLE_INSERT_SKIP_WAL was 0x0001; RelationNeedsWAL() now governs */
#define TABLE_INSERT_SKIP_FSM 0x0002
@@ -409,6 +478,17 @@ typedef struct TableAmRoutine
uint8 flags,
TM_FailureData *tmfd);
+ /*
+ * Help index AMs to perform bottom-up index deletion.
+ *
+ * Optional callback. See TM_IndexDeleteOp struct for full details.
+ *
+ * Returns a latestRemovedXid transaction ID that index AM must use to
+ * generate a recovery conflict when required.
+ */
+ TransactionId (*index_delete_check) (Relation rel,
+ TM_IndexDeleteOp *delstate);
+
/*
* Perform operations necessary to complete insertions made via
* tuple_insert and multi_insert with a BulkInsertState specified. In-tree
@@ -1363,6 +1443,25 @@ table_tuple_lock(Relation rel, ItemPointer tid, Snapshot snapshot,
flags, tmfd);
}
+/*
+ * Bottom-up index deletion interface for index AMs.
+ *
+ * Sets deletable tuples in entries from caller's TM_IndexDeleteOp state that
+ * are found to point to already-dead tuples in the tableam structure.
+ *
+ * See TM_IndexDeleteOp struct for full details.
+ */
+static inline TransactionId
+table_index_delete_check(Relation rel, TM_IndexDeleteOp *delstate)
+{
+ /* optional callback */
+ if (rel->rd_tableam && rel->rd_tableam->index_delete_check)
+ return rel->rd_tableam->index_delete_check(rel, delstate);
+
+ delstate->ndeltids = 0;
+ return InvalidTransactionId;
+}
+
/*
* Perform operations necessary to complete insertions made via
* tuple_insert and multi_insert with a BulkInsertState specified.
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index dcaea7135f..a08c494034 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2532,6 +2532,7 @@ static const TableAmRoutine heapam_methods = {
.tuple_delete = heapam_tuple_delete,
.tuple_update = heapam_tuple_update,
.tuple_lock = heapam_tuple_lock,
+ .index_delete_check = NULL,
.tuple_fetch_row_version = heapam_fetch_row_version,
.tuple_get_latest_tid = heap_get_latest_tid,
diff --git a/src/backend/access/table/tableam.c b/src/backend/access/table/tableam.c
index 6438c45716..e19bdd246a 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -207,9 +207,9 @@ table_beginscan_parallel(Relation relation, ParallelTableScanDesc parallel_scan)
/*
* To perform that check simply start an index scan, create the necessary
* slot, do the heap lookup, and shut everything down again. This could be
- * optimized, but is unlikely to matter from a performance POV. If there
- * frequently are live index pointers also matching a unique index key, the
- * CPU overhead of this routine is unlikely to matter.
+ * optimized, but is unlikely to matter from a performance POV. Note that
+ * table_index_delete_check() is optimized in this way, since it is designed
+ * as a batch operation.
*
* Note that *tid may be modified when we return true if the AM supports
* storing multiple row versions reachable via a single index entry (like
--
2.25.1
[application/octet-stream] v8-0004-Teach-nbtree-to-use-bottom-up-index-deletion.patch (53.1K, ../../CAH2-Wzm46rS1JDmRO0fbnQDpYyD2PrX2cYsa8-5=nhp7nT_w9A@mail.gmail.com/4-v8-0004-Teach-nbtree-to-use-bottom-up-index-deletion.patch)
download | inline diff:
From fbb49d2cb449cf808a1f776d281052b7b0e69578 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Mon, 9 Nov 2020 12:59:30 -0800
Subject: [PATCH v8 4/5] Teach nbtree to use bottom-up index deletion.
Teach nbtree to eagerly delete duplicate of tuples representing old
versions in the event of a localized flood of version churn. This
situation is detected using heuristics, including the recently added
"index is logically unchanged by an UPDATE" executor hint.
This commit alone changes very little about how nbtree behaves. We
still lack tableam-side support. An upcoming commit that adds support
for bottom-up index deletion to heapam will follow, completing the
picture.
The immediate goal of bottom-up index deletion in nbtree is to avoid
"unnecessary" page splits caused entirely by duplicates needed only for
MVCC/versioning purposes. It naturally has an even more useful effect,
though: it acts as a backstop against accumulating an excessive number
of index tuple versions for any given _logical row_. Note that the
relationship between this localized condition and the proportion of
garbage tuples in the entire index is very loose, and can be very
volatile. Bottom-up index deletion complements what we might now call
"top-down index deletion": index vacuuming performed by VACUUM. It
responds to the immediate local needs of queries, while leaving it up to
autovacuum to perform infrequent clean sweeps of the index.
Bottom-up index deletion is very effective despite not changing anything
about the fundamental invariants for Postgres index access methods in
general (and despite not changing any invariants for nbtree in
particular). That is, it is still inherently necessary to keep around
multiple versions together on the same leaf page, at least in some cases
(no change there). But nothing forbids us from being proactive in
keeping the number of tuples for any given logical row under control, if
and when that seems to makes sense at the page/local level. In practice
it is seldom strictly necessary to have more than a couple of physical
index tuple versions present for any given logical row.
You can think of bottom-up index deletion as bringing the effectiveness
of garbage collection in nbtree far closer to the true theoretical
limits imposed on it by the core system. In practice nbtree could fall
significantly short of this ideal before now, often in ways that could
not easily be predicted or reasoned about, and often in the absence of
obvious stressors (like very long running transactions that hold open an
MVCC snapshot). This may not have happened in production all that
often, but when it happened it had a significant impact on query
latency, often at the most inconvenient time possible.
Bottom-up deletion uses the same WAL record that we use when deleting
LP_DEAD items (the xl_btree_delete record). This commit extends
_bt_delitems_delete() to support granular TID deletion in posting list
tuples, and to support a caller-supplied latestRemovedXid. Only its
bottom-up index deletion caller makes use of these new facilities.
Bump XLOG_PAGE_MAGIC because xl_btree_delete changed.
No bump in BTREE_VERSION, since there are no changes to the on-disk
representation of nbtree indexes. Indexes built on PostgreSQL 12 or
PostgreSQL 13 will automatically benefit from the optimization (i.e. no
reindexing required) following a pg_upgrade.
Author: Peter Geoghegan <[email protected]>
Reviewed-By: Victor Yegorov <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wzm+maE3apHB8NOtmM=p-DO65j2V5GzAWCOEEuy3JZgb2g@mail.gmail.com
---
src/include/access/nbtree.h | 7 +-
src/include/access/nbtxlog.h | 9 +-
src/backend/access/nbtree/README | 74 +++-
src/backend/access/nbtree/nbtdedup.c | 505 +++++++++++++++++++++++++-
src/backend/access/nbtree/nbtinsert.c | 94 ++++-
src/backend/access/nbtree/nbtpage.c | 136 ++++++-
src/backend/access/nbtree/nbtree.c | 2 +-
src/backend/access/nbtree/nbtutils.c | 5 +
src/backend/access/nbtree/nbtxlog.c | 51 ++-
9 files changed, 829 insertions(+), 54 deletions(-)
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index d1b3e0ba6a..f8faae525a 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -1031,6 +1031,8 @@ extern void _bt_parallel_advance_array_keys(IndexScanDesc scan);
extern void _bt_dedup_pass(Relation rel, Buffer buf, Relation heapRel,
IndexTuple newitem, Size newitemsz,
bool checkingunique);
+extern bool _bt_bottomup_pass(Relation rel, Buffer buf, Relation heapRel,
+ Size newitemsz, bool checkingunique);
extern void _bt_dedup_start_pending(BTDedupState state, IndexTuple base,
OffsetNumber baseoff);
extern bool _bt_dedup_save_htid(BTDedupState state, IndexTuple itup);
@@ -1045,7 +1047,8 @@ extern IndexTuple _bt_swap_posting(IndexTuple newitem, IndexTuple oposting,
* prototypes for functions in nbtinsert.c
*/
extern bool _bt_doinsert(Relation rel, IndexTuple itup,
- IndexUniqueCheck checkUnique, Relation heapRel);
+ IndexUniqueCheck checkUnique, Relation heapRel,
+ bool indexunchanged);
extern void _bt_finish_split(Relation rel, Buffer lbuf, BTStack stack);
extern Buffer _bt_getstackbuf(Relation rel, BTStack stack, BlockNumber child);
@@ -1084,7 +1087,9 @@ extern void _bt_delitems_vacuum(Relation rel, Buffer buf,
OffsetNumber *deletable, int ndeletable,
BTVacuumPosting *updatable, int nupdatable);
extern void _bt_delitems_delete(Relation rel, Buffer buf,
+ bool bottomup, TransactionId bottomupXid,
OffsetNumber *deletable, int ndeletable,
+ BTVacuumPosting *updatable, int nupdatable,
Relation heapRel);
extern uint32 _bt_pagedel(Relation rel, Buffer leafbuf,
TransactionId *oldestBtpoXact);
diff --git a/src/include/access/nbtxlog.h b/src/include/access/nbtxlog.h
index 5c014bdc66..4006872d7a 100644
--- a/src/include/access/nbtxlog.h
+++ b/src/include/access/nbtxlog.h
@@ -187,12 +187,15 @@ typedef struct xl_btree_dedup
typedef struct xl_btree_delete
{
TransactionId latestRemovedXid;
- uint32 ndeleted;
+ uint16 ndeleted;
+ uint16 nupdated;
/* DELETED TARGET OFFSET NUMBERS FOLLOW */
+ /* UPDATED TARGET OFFSET NUMBERS FOLLOW */
+ /* UPDATED TUPLES METADATA ARRAY FOLLOWS */
} xl_btree_delete;
-#define SizeOfBtreeDelete (offsetof(xl_btree_delete, ndeleted) + sizeof(uint32))
+#define SizeOfBtreeDelete (offsetof(xl_btree_delete, nupdated) + sizeof(uint16))
/*
* This is what we need to know about page reuse within btree. This record
@@ -213,7 +216,7 @@ typedef struct xl_btree_reuse_page
/*
* This is what we need to know about which TIDs to remove from an individual
* posting list tuple during vacuuming. An array of these may appear at the
- * end of xl_btree_vacuum records.
+ * end of xl_btree_vacuum and xl_btree_delete records.
*/
typedef struct xl_btree_update
{
diff --git a/src/backend/access/nbtree/README b/src/backend/access/nbtree/README
index 27f555177e..7855392212 100644
--- a/src/backend/access/nbtree/README
+++ b/src/backend/access/nbtree/README
@@ -439,12 +439,14 @@ from the index immediately; since index scans only stop "between" pages,
no scan can lose its place from such a deletion. We separate the steps
because we allow LP_DEAD to be set with only a share lock (it's exactly
like a hint bit for a heap tuple), but physically removing tuples requires
-exclusive lock. In the current code we try to remove LP_DEAD tuples when
-we are otherwise faced with having to split a page to do an insertion (and
-hence have exclusive lock on it already). Deduplication can also prevent
-a page split, but removing LP_DEAD tuples is the preferred approach.
-(Note that posting list tuples can only have their LP_DEAD bit set when
-every table TID within the posting list is known dead.)
+exclusive lock. We try to remove LP_DEAD tuples when we are otherwise
+faced with having to split a page to do an insertion (and hence have
+exclusive lock on it already). Deduplication and bottom-up index deletion
+can also prevent a page split, but removing LP_DEAD tuples is always the
+preferred approach. (Note that posting list tuples can only have their
+LP_DEAD bit set when every table TID within the posting list is known
+dead. This isn't much of a problem because bottom-up deletion supports
+granular deletion of TIDs from posting lists.)
This leaves the index in a state where it has no entry for a dead tuple
that still exists in the heap. This is not a problem for the current
@@ -767,9 +769,10 @@ into a single physical tuple with a posting list (a simple array of heap
TIDs with the standard item pointer format). Deduplication is always
applied lazily, at the point where it would otherwise be necessary to
perform a page split. It occurs only when LP_DEAD items have been
-removed, as our last line of defense against splitting a leaf page. We
-can set the LP_DEAD bit with posting list tuples, though only when all
-TIDs are known dead.
+removed, as our last line of defense against splitting a leaf page
+(bottom-up index deletion may be attempted first, as our second last line
+of defense). We can set the LP_DEAD bit with posting list tuples, though
+only when all TIDs are known dead.
Our lazy approach to deduplication allows the page space accounting used
during page splits to have absolutely minimal special case logic for
@@ -826,6 +829,16 @@ delay a split that is probably inevitable anyway. This allows us to avoid
the overhead of attempting to deduplicate with unique indexes that always
have few or no duplicates.
+Note: Avoiding "unnecessary" page splits driven by version churn is also
+the goal of bottom-up index deletion, which was added to PostgreSQL 14.
+Bottom-up index deletion is now the preferred way to deal with this
+problem (with all kinds of indexes, though especially with unique
+indexes). Still, deduplication can sometimes augment bottom-up index
+deletion. When deletion cannot free tuples (due to an old snapshot
+holding up cleanup), falling back on deduplication provides additional
+capacity. Delaying the page split by deduplicating can allow a future
+bottom-up deletion pass of the same page to succeed.
+
Posting list splits
-------------------
@@ -880,6 +893,49 @@ that need a page split anyway. Besides, supporting variable "split points"
while splitting posting lists won't actually improve overall space
utilization.
+Bottom-up index deletion
+------------------------
+
+We sometimes delete whatever duplicates happen to be present on the page
+before moving on to deduplication. This only happens when we receive a
+hint that optimizations like heapam's HOT have not worked out for the
+index -- the incoming tuple must be a logically unchanged duplicate which
+is needed for MVCC purposes. (Actually it also happens with unique
+indexes in some extra cases that don't get this hint.)
+
+There are certain ways in which this mechanism is similar to on-the-fly
+deletion of index tuples (that will already have failed to prevent a page
+split by the time bottom-up deletion is attempted). For example, the same
+WAL records are used. There are also significant differences. Index
+tuples that get deleted by this mechanism won't have already been marked
+LP_DEAD in passing by queries. Rather, we figure out whether or not
+they're deletable in principle at the last point before splitting a page
+by accessing tableam blocks to get visibility information. We use
+heuristics to access as few tableam blocks as possible while still
+expecting to find a reasonably large number of tuples that are safe to
+delete each time (actually, we outsource much of this to the tableam, that
+understands how all this works pretty well). We expect to perform regular
+bottom-up deletion operations against pages that are at constant risk of
+unnecessary page splits caused only by version churn. When the mechanism
+works well we'll constantly be on the verge of having lots of version
+churn driven page splits, but never actually have any.
+
+Bottom-up index deletion can be thought of as a backstop mechanism against
+unnecessary version-driven page splits. When we have a reasonable
+suspicion that a would-be page split may not actually be necessary, we
+fight back. There is very little to lose and much to gain by spending a
+few cycles to become reasonably sure that it is in fact necessary -- page
+splits are very expensive and practically irreversible. This approach
+works well with a large variety of workloads because we give up before
+spending very many cycles on trying, and because our heuristics are good
+enough to spot unnecessary page splits fairly reliably in practice.
+Unnecessary page splits occur due to pathological amounts of version
+churn. In practice this pathological condition can be detected before too
+long using simple heuristics. We don't have to understand the universe of
+possible workloads; we only have to understand the nature of the
+underlying pathology. We're helped out by additional heuristics within
+tableams such as heapam.
+
Notes About Data Representation
-------------------------------
diff --git a/src/backend/access/nbtree/nbtdedup.c b/src/backend/access/nbtree/nbtdedup.c
index 9e535124c4..db86541f42 100644
--- a/src/backend/access/nbtree/nbtdedup.c
+++ b/src/backend/access/nbtree/nbtdedup.c
@@ -16,13 +16,17 @@
#include "access/nbtree.h"
#include "access/nbtxlog.h"
+#include "access/tableam.h"
#include "miscadmin.h"
#include "utils/rel.h"
+static void _bt_bottomup_finish_pending(Page page, TM_IndexDeleteOp *delstate,
+ BTDedupState state);
static bool _bt_do_singleval(Relation rel, Page page, BTDedupState state,
OffsetNumber minoff, IndexTuple newitem);
static void _bt_singleval_fillfactor(Page page, BTDedupState state,
Size newitemsz);
+static int _bt_indexdelete_cmp(const void *a, const void *b);
#ifdef USE_ASSERT_CHECKING
static bool _bt_posting_valid(IndexTuple posting);
#endif
@@ -267,6 +271,325 @@ _bt_dedup_pass(Relation rel, Buffer buf, Relation heapRel, IndexTuple newitem,
pfree(state);
}
+/*
+ * Perform bottom-up index deletion pass.
+ *
+ * See if duplicate index tuples are eligible to be deleted by accessing
+ * visibility information from the tableam. Give up if we have to access more
+ * than a few tableam blocks. Caller tries to avoid "unnecessary" page splits
+ * (splits driven only by version churn) by calling here when it looks like
+ * that's about to happen. It's normal for there to be a lot of calls here
+ * for pages that are constantly at risk of an unnecessary split.
+ *
+ * Each failure to delete a duplicate/promising tuple here is a kind of
+ * learning experience. It results in caller falling back on splitting the
+ * page (or on a deduplication pass), discouraging future calls back here for
+ * the same key space range covered by a failed page (or at least discouraging
+ * processing the original duplicates in case where caller falls back on a
+ * successful deduplication pass). We converge on the most effective strategy
+ * for each page in the index over time.
+ *
+ * Returns true on success, in which case caller can assume page split will be
+ * avoided for a reasonable amount of time. Returns false when caller should
+ * deduplicate the page (if possible at all).
+ *
+ * Note: occasionally a true return value does not actually indicate that any
+ * items could be deleted. It might just indicate that caller should not go
+ * on to perform a deduplication pass. Caller is not expected to care about
+ * the difference.
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
+ */
+bool
+_bt_bottomup_pass(Relation rel, Buffer buf, Relation heapRel, Size newitemsz,
+ bool checkingunique)
+{
+ OffsetNumber offnum,
+ minoff,
+ maxoff,
+ postingidxoffnum;
+ Page page = BufferGetPage(buf);
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+ BTDedupState state;
+ TM_IndexDeleteOp delstate;
+ bool neverdedup = false;
+ TransactionId latestRemovedXid;
+ int ndeletable,
+ nupdatable;
+ OffsetNumber deletable[MaxIndexTuplesPerPage];
+ BTVacuumPosting updatable[MaxIndexTuplesPerPage];
+ int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+
+ /* Passed-in newitemsz is MAXALIGNED but does not include line pointer */
+ newitemsz += sizeof(ItemIdData);
+
+ /* Initialize deduplication state */
+ state = (BTDedupState) palloc(sizeof(BTDedupStateData));
+ state->deduplicate = true;
+ state->nmaxitems = 0;
+ state->maxpostingsize = BLCKSZ; /* "posting list size" not a concern */
+ state->base = NULL;
+ state->baseoff = InvalidOffsetNumber;
+ state->basetupsize = 0;
+ state->htids = palloc(state->maxpostingsize);
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+ state->nintervals = 0;
+
+ /*
+ * Initialize tableam state that describes bottom-up index deletion
+ * operation.
+ *
+ * We will ask tableam to free 1/16 of BLCKSZ. We don't usually expect to
+ * have to free much space each call here in order to avoid page splits.
+ * We don't want to be too aggressive since in general the tableam will
+ * have to access more table blocks when we ask for more free space. In
+ * general we try to be conservative about what we ask for (though not too
+ * conservative), while leaving it up to the tableam to ramp up the number
+ * of tableam blocks accessed when conditions in the table structure
+ * happen to favor it.
+ *
+ * We expect to end up back here again and again for any leaf page that is
+ * more or less constantly at risk of unnecessary page splits -- in fact
+ * that's what happens when bottom-up deletion really helps. We must
+ * avoid thrashing when this becomes very frequent at the level of an
+ * individual page. Our free space target helps with that. It balances
+ * the costs and benefits over time and across related bottom-up deletion
+ * passes.
+ */
+ delstate.ndeltids = 0;
+ delstate.deltids = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexDelete));
+ delstate.status = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexStatus));
+ delstate.targetfreespace = Max(BLCKSZ / 16, newitemsz);
+
+ /* Now remember details of the page in the state we'll pass to tableam */
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
+ for (offnum = minoff;
+ offnum <= maxoff;
+ offnum = OffsetNumberNext(offnum))
+ {
+ ItemId itemid = PageGetItemId(page, offnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+
+ Assert(!ItemIdIsDead(itemid));
+
+ if (offnum == minoff)
+ {
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ else if (_bt_keep_natts_fast(rel, state->base, itup) > nkeyatts &&
+ _bt_dedup_save_htid(state, itup))
+ {
+ /* Tuple is equal; just added its TIDs to pending interval */
+ }
+ else
+ {
+ /* Finalize interval -- move its TIDs to bottom-up state */
+ _bt_bottomup_finish_pending(page, &delstate, state);
+
+ /* itup starts new pending interval */
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ }
+ /* Finalize final interval -- move its TIDs to bottom-up state */
+ _bt_bottomup_finish_pending(page, &delstate, state);
+
+ /*
+ * Remember to tell caller to never deduplicate later on, regardless of
+ * how much space we free when there are no duplicates on existing page.
+ *
+ * Note: We sometimes proceed with calling table_index_delete_check() with
+ * no promising tuples. This is possible in cases with a unique index
+ * that caller just erased LP_DEAD items on, as well as cases where we
+ * deduplicated just a moment ago. We finish what we started. The
+ * tableam has its own heuristics that it can fall back on, and so it
+ * still has some chance of success.
+ */
+ if (state->nintervals == 0)
+ neverdedup = true;
+
+ /* Done with dedup state */
+ pfree(state->htids);
+ pfree(state);
+
+ /* Now use tableam interface to determine which tuples to delete */
+ latestRemovedXid = table_index_delete_check(heapRel, &delstate);
+
+ if (delstate.ndeltids == 0)
+ {
+ /* The tableam has nothing for us */
+ pfree(delstate.deltids);
+ pfree(delstate.status);
+
+ if (neverdedup)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * By here we know that we have at least one deletable index tuple (or
+ * posting list's TID) in final deltids array. All that remains is to
+ * construct a leaf-page-wise description of what _bt_delitems_delete()
+ * needs to do to physically delete index tuples from the page.
+ *
+ * Sort deltids array (which is typically much smaller now) in the order
+ * expected by loop: the original leaf-page-wise order (the order the
+ * array was in before the tableam sorted it for its own reasons).
+ */
+ qsort(delstate.deltids, delstate.ndeltids, sizeof(TM_IndexDelete),
+ _bt_indexdelete_cmp);
+ postingidxoffnum = InvalidOffsetNumber;
+ ndeletable = 0;
+ nupdatable = 0;
+ for (int i = 0; i < delstate.ndeltids; i++)
+ {
+ TM_IndexStatus *dstatus = delstate.status + delstate.deltids[i].id;
+ OffsetNumber idxoffnum = dstatus->idxoffnum;
+ ItemId itemid = PageGetItemId(page, idxoffnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+ int tidi,
+ nitem;
+ BTVacuumPosting vacposting;
+
+ if (idxoffnum == postingidxoffnum)
+ {
+ /*
+ * This deltid entry is a TID from a posting list tuple that has
+ * already been completely processed (since we process all of a
+ * posting lists TIDs together, once)
+ */
+ Assert(BTreeTupleIsPosting(itup));
+ continue;
+ }
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ /* Plain non-pivot tuple */
+ Assert(ItemPointerEquals(&itup->t_tid, &delstate.deltids[i].tid));
+ if (dstatus->deleteitup)
+ deletable[ndeletable++] = idxoffnum;
+ continue;
+ }
+
+ /*
+ * Posting list tuple. Process all of its TIDs together, at once.
+ *
+ * tidi is a posting-list-tid local iterator for array. We're going
+ * to peak at later entries in deltid array here. Remember to skip
+ * over the itup-related entries that we peak at here later on. We
+ * should not do anything more with them when get back to the top of
+ * the outermost deltids loop (we should just skip them).
+ *
+ * Innermost loop exploits the fact that both itup's TIDs and the
+ * entries from the array (whose TIDs came from itup) are in ascending
+ * TID order. We avoid unnecessary TID comparisons by starting each
+ * execution of the innermost loop at the point where the previous
+ * execution (for previous TID from itup) left off at.
+ */
+ postingidxoffnum = idxoffnum; /* Remember: process itup once only */
+ tidi = i; /* Initialize for itup's first TID */
+ vacposting = NULL; /* Describes what to do with itup */
+ nitem = BTreeTupleGetNPosting(itup);
+ for (int j = 0; j < nitem; j++)
+ {
+ ItemPointer htid = BTreeTupleGetPostingN(itup, j);
+ int cmp = -1;
+
+ for (; tidi < delstate.ndeltids; tidi++)
+ {
+ TM_IndexDelete *tcdeltid = &delstate.deltids[tidi];
+ TM_IndexStatus *tdstatus = (delstate.status + tcdeltid->id);
+
+ /* Stop when we get to first entry beyond itup's entries */
+ Assert(tdstatus->idxoffnum >= idxoffnum);
+ if (tdstatus->idxoffnum != idxoffnum)
+ break;
+
+ /* Skip any non-deletable entries for itup */
+ if (!tdstatus->deleteitup)
+ continue;
+
+ /* Have we found matching deletable entry for htid? */
+ cmp = ItemPointerCompare(htid, &tcdeltid->tid);
+
+ /* Keep going until equal or greater tid from array located */
+ if (cmp <= 0)
+ break;
+ }
+
+ /* Final check on htid: must match a deletable array entry */
+ if (cmp != 0)
+ continue;
+
+ if (vacposting == NULL)
+ {
+ /*
+ * First deletable TID for itup found. Start maintaining
+ * metadata describing which TIDs to delete from itup.
+ */
+ vacposting = palloc(offsetof(BTVacuumPostingData, deletetids) +
+ nitem * sizeof(uint16));
+ vacposting->itup = itup;
+ vacposting->updatedoffset = idxoffnum;
+ vacposting->ndeletedtids = 0;
+ }
+
+ /* htid will be deleted from itup */
+ vacposting->deletetids[vacposting->ndeletedtids++] = j;
+ }
+
+ if (vacposting == NULL)
+ {
+ /* No TIDs to delete from itup -- do nothing */
+ }
+ else if (vacposting->ndeletedtids == nitem)
+ {
+ /* Straight delete of itup (to delete all TIDs) */
+ deletable[ndeletable++] = idxoffnum;
+ /* Turns out we won't need granular information */
+ pfree(vacposting);
+ }
+ else
+ {
+ /* Delete some but not all TIDs from itup */
+ Assert(vacposting->ndeletedtids > 0 &&
+ vacposting->ndeletedtids < nitem);
+ updatable[nupdatable++] = vacposting;
+ }
+ }
+
+ /* Done with bottom-up deletion state */
+ pfree(delstate.deltids);
+ pfree(delstate.status);
+
+ /*
+ * Go through with deleting TIDs that we found are safe to delete.
+ *
+ * No MarkBufferDirtyHint() call is needed here, since we don't ever mark
+ * line pointers LP_DEAD. Any and all modifications to the page are made
+ * in the critical section in _bt_delitems_delete().
+ */
+ _bt_delitems_delete(rel, buf, true, latestRemovedXid,
+ deletable, ndeletable, updatable, nupdatable,
+ heapRel);
+
+ /* be tidy */
+ for (int i = 0; i < nupdatable; i++)
+ pfree(updatable[i]);
+
+ /* Carry out earlier decision to have caller avoid deduplication now */
+ if (neverdedup)
+ return true;
+
+ /* Don't dedup when we won't end up back here any time soon anyway */
+ return PageGetExactFreeSpace(page) >=
+ Max(delstate.targetfreespace / 2, newitemsz);
+}
+
/*
* Create a new pending posting list tuple based on caller's base tuple.
*
@@ -452,6 +775,164 @@ _bt_dedup_finish_pending(Page newpage, BTDedupState state)
return spacesaving;
}
+/*
+ * Finalize interval during bottom-up index deletion.
+ *
+ * Determines which TIDs are to be marked promising based on heuristics.
+ */
+static void
+_bt_bottomup_finish_pending(Page page, TM_IndexDeleteOp *delstate,
+ BTDedupState state)
+{
+ bool dupinterval = (state->nitems > 1);
+
+ Assert(state->nitems > 0);
+ Assert(state->nitems <= state->nhtids);
+ Assert(state->intervals[state->nintervals].baseoff == state->baseoff);
+
+ /*
+ * All TIDs from all tuples are at least recording in state. Tuples are
+ * marked promising when they're duplicates (i.e. when they appear in an
+ * interval with more than one item, as when we expect create a new
+ * posting list tuple in the deduplication case).
+ *
+ * It's easy to see what this means in the plain non-pivot tuple case:
+ * TIDs from duplicate plain tuples are promising. Posting list tuples
+ * are more subtle. We ought to do something with posting list tuples,
+ * though plain tuples tend to be more promising targets. (Plain tuples
+ * are the most likely to be dead/deletable because they suggest version
+ * churn. And they allow us to free more space when we actually succeed).
+ */
+ for (int i = 0; i < state->nitems; i++)
+ {
+ OffsetNumber offnum = state->baseoff + i;
+ ItemId itemid = PageGetItemId(page, offnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+ TM_IndexDelete *cdeltid;
+ TM_IndexStatus *dstatus;
+
+ cdeltid = &delstate->deltids[delstate->ndeltids];
+ dstatus = &delstate->status[delstate->ndeltids];
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ /* Easy case: A plain non-pivot tuple's TID */
+ cdeltid->tid = itup->t_tid;
+ cdeltid->id = delstate->ndeltids;
+ dstatus->idxoffnum = offnum;
+ dstatus->ispromising = dupinterval;
+ dstatus->deleteitup = false; /* for now */
+ dstatus->tupsize =
+ ItemIdGetLength(itemid) + sizeof(ItemIdData);
+ delstate->ndeltids++;
+ }
+ else
+ {
+ /*
+ * Harder case: A posting list tuple's TIDs (multiple TIDs).
+ *
+ * Only a single TID from a posting list tuple may be promising,
+ * and only when it appears in a duplicate tuple (just like plain
+ * tuple case). In general there is a good chance that the
+ * posting list tuple relates to multiple logical rows, rather
+ * than multiple versions of just one logical row. (It can only
+ * be the latter case when a previous bottom-up deletion pass
+ * failed, necessitating a deduplication pass, which isn't all
+ * that common.)
+ *
+ * There is a pretty good chance that at least one of the logical
+ * rows from the posting list was updated, and so had a successor
+ * version (about as good a chance as it is in the regular tuple
+ * case, at least). We should at least try to follow the regular
+ * tuple case while making the conservative assumption that there
+ * can only be one affected logical row per posting list tuple. We
+ * do that by picking one TID when it appears to be from the
+ * predominant tableam block in the posting list (if any one
+ * tableam block predominates). The approach we take is to either
+ * choose the first or last TID in the posting list (if any at
+ * all). We go with whichever one is on the same tableam block at
+ * the middle tuple (and only the first TID when both the first
+ * and last TIDs relate to the same tableam block -- we could
+ * easily be too aggressive here).
+ *
+ * If it turns out that there are multiple old versions of a
+ * single logical table row, we still have a pretty good chance of
+ * being able to delete them this way. We don't want to give too
+ * strong a signal to the tableam. But we should always try to
+ * give some useful hints. Even cases with considerable
+ * uncertainty can consistently avoid an unnecessary page split,
+ * in part because the tableam will have tricks of its own for
+ * figuring out where to look in marginal cases.
+ */
+ int nitem = BTreeTupleGetNPosting(itup);
+ bool firstpromise = false;
+ bool lastpromise = false;
+
+ Assert(_bt_posting_valid(itup));
+
+ if (dupinterval)
+ {
+ /* Figure out if there really should be promising TIDs */
+ BlockNumber minblocklist,
+ midblocklist,
+ maxblocklist;
+ ItemPointer mintid,
+ midtid,
+ maxtid;
+
+ mintid = BTreeTupleGetHeapTID(itup);
+ midtid = BTreeTupleGetPostingN(itup, nitem / 2);
+ maxtid = BTreeTupleGetMaxHeapTID(itup);
+ minblocklist = ItemPointerGetBlockNumber(mintid);
+ midblocklist = ItemPointerGetBlockNumber(midtid);
+ maxblocklist = ItemPointerGetBlockNumber(maxtid);
+
+ firstpromise = (minblocklist == midblocklist);
+ lastpromise = (!firstpromise && midblocklist == maxblocklist);
+ }
+
+ /* No more than one TID from itup can be promising */
+ Assert(!(firstpromise && lastpromise));
+
+ for (int p = 0; p < nitem; p++)
+ {
+ ItemPointer htid = BTreeTupleGetPostingN(itup, p);
+
+ cdeltid->tid = *htid;
+ cdeltid->id = delstate->ndeltids;
+ dstatus->idxoffnum = offnum;
+ dstatus->ispromising = false;
+
+ if ((firstpromise && p == 0) ||
+ (lastpromise && p == nitem - 1))
+ dstatus->ispromising = true;
+
+ dstatus->deleteitup = false; /* for now */
+ dstatus->tupsize = sizeof(ItemPointerData) + 1;
+ delstate->ndeltids++;
+
+ cdeltid++;
+ dstatus++;
+ }
+ }
+ }
+
+ if (dupinterval)
+ {
+ /*
+ * Maintain interval state for consistency with true deduplication
+ * case
+ */
+ state->intervals[state->nintervals].nitems = state->nitems;
+ state->nintervals++;
+ }
+
+ /* Reset state for next interval */
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+}
+
/*
* Determine if page non-pivot tuples (data items) are all duplicates of the
* same value -- if they are, deduplication's "single value" strategy should
@@ -622,8 +1103,8 @@ _bt_form_posting(IndexTuple base, ItemPointer htids, int nhtids)
* Generate a replacement tuple by "updating" a posting list tuple so that it
* no longer has TIDs that need to be deleted.
*
- * Used by VACUUM. Caller's vacposting argument points to the existing
- * posting list tuple to be updated.
+ * Used by both VACUUM and bottom-up index deletion. Caller's vacposting
+ * argument points to the existing posting list tuple to be updated.
*
* On return, caller's vacposting argument will point to final "updated"
* tuple, which will be palloc()'d in caller's memory context.
@@ -765,6 +1246,26 @@ _bt_swap_posting(IndexTuple newitem, IndexTuple oposting, int postingoff)
return nposting;
}
+/*
+ * Comparator used by _bt_bottomup_pass() to restore deltids array back to its
+ * original sort order
+ */
+static int
+_bt_indexdelete_cmp(const void *a, const void *b)
+{
+ TM_IndexDelete *indexdelete1 = (TM_IndexDelete *) a;
+ TM_IndexDelete *indexdelete2 = (TM_IndexDelete *) b;
+
+ if (indexdelete1->id > indexdelete2->id)
+ return 1;
+ if (indexdelete1->id < indexdelete2->id)
+ return -1;
+
+ Assert(false);
+
+ return 0;
+}
+
/*
* Verify posting list invariants for "posting", which must be a posting list
* tuple. Used within assertions.
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index 1ab98588c8..ed73a30456 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -37,6 +37,7 @@ static TransactionId _bt_check_unique(Relation rel, BTInsertState insertstate,
static OffsetNumber _bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool indexunchanged,
BTStack stack,
Relation heapRel);
static void _bt_stepright(Relation rel, BTInsertState insertstate, BTStack stack);
@@ -61,7 +62,7 @@ static inline bool _bt_pgaddtup(Page page, Size itemsize, IndexTuple itup,
static void _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
BTInsertState insertstate,
bool lpdeadonly, bool checkingunique,
- bool uniquedup);
+ bool uniquedup, bool indexunchanged);
/*
* _bt_doinsert() -- Handle insertion of a single index tuple in the tree.
@@ -83,7 +84,8 @@ static void _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
*/
bool
_bt_doinsert(Relation rel, IndexTuple itup,
- IndexUniqueCheck checkUnique, Relation heapRel)
+ IndexUniqueCheck checkUnique, Relation heapRel,
+ bool indexunchanged)
{
bool is_unique = false;
BTInsertStateData insertstate;
@@ -238,7 +240,7 @@ search:
* checkingunique.
*/
newitemoff = _bt_findinsertloc(rel, &insertstate, checkingunique,
- stack, heapRel);
+ indexunchanged, stack, heapRel);
_bt_insertonpg(rel, itup_key, insertstate.buf, InvalidBuffer, stack,
itup, insertstate.itemsz, newitemoff,
insertstate.postingoff, false);
@@ -777,6 +779,12 @@ _bt_check_unique(Relation rel, BTInsertState insertstate, Relation heapRel,
* room for the new tuple, this function moves right, trying to find a
* legal page that does.)
*
+ * If 'indexunchanged' is true, this is for an UPDATE that didn't
+ * logically change the indexed value, but must nevertheless have a new
+ * entry to point to a successor version. This hint from the executor
+ * will influence our behavior when the page might have to be split and
+ * we must consider if it's avoidable.
+ *
* On exit, insertstate buffer contains the chosen insertion page, and
* the offset within that page is returned. If _bt_findinsertloc needed
* to move right, the lock and pin on the original page are released, and
@@ -793,6 +801,7 @@ static OffsetNumber
_bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool indexunchanged,
BTStack stack,
Relation heapRel)
{
@@ -817,7 +826,7 @@ _bt_findinsertloc(Relation rel,
if (itup_key->heapkeyspace)
{
/* Keep track of whether checkingunique duplicate seen */
- bool uniquedup = false;
+ bool uniquedup = indexunchanged;
/*
* If we're inserting into a unique index, we may have to walk right
@@ -881,7 +890,8 @@ _bt_findinsertloc(Relation rel,
*/
if (PageGetFreeSpace(page) < insertstate->itemsz)
_bt_delete_or_dedup_one_page(rel, heapRel, insertstate, false,
- checkingunique, uniquedup);
+ checkingunique, uniquedup,
+ indexunchanged);
}
else
{
@@ -923,7 +933,8 @@ _bt_findinsertloc(Relation rel,
{
/* Erase LP_DEAD items (won't deduplicate) */
_bt_delete_or_dedup_one_page(rel, heapRel, insertstate, true,
- checkingunique, false);
+ checkingunique, false,
+ indexunchanged);
if (PageGetFreeSpace(page) >= insertstate->itemsz)
break; /* OK, now we have enough space */
@@ -977,7 +988,7 @@ _bt_findinsertloc(Relation rel,
* This can only erase LP_DEAD items (it won't deduplicate).
*/
_bt_delete_or_dedup_one_page(rel, heapRel, insertstate, true,
- checkingunique, false);
+ checkingunique, false, indexunchanged);
/*
* Do new binary search. New insert location cannot overlap with any
@@ -2609,15 +2620,35 @@ _bt_pgaddtup(Page page,
* _bt_delete_or_dedup_one_page - Try to avoid a leaf page split by attempting
* a variety of operations.
*
- * There are two operations performed here: deleting items already marked
- * LP_DEAD, and deduplication. If both operations fail to free enough space
- * for the incoming item then caller will go on to split the page. We always
- * attempt our preferred strategy (which is to delete items whose LP_DEAD bit
- * are set) first. If that doesn't work out we move on to deduplication.
+ * There are three operations performed here: deleting items already marked
+ * LP_DEAD, deduplication, and bottom-up index deletion. If all three
+ * operations fail to free enough space for the incoming item then caller will
+ * go on to split the page. We always attempt our preferred strategy (which
+ * is to delete items whose LP_DEAD bit are set) first. If that doesn't work
+ * out we consider alternatives. Most calls here will not exhaustively
+ * attempt all three operations. Deduplication and bottom-up index deletion
+ * are relatively expensive operations, so we try to pick one or the other up
+ * front (whichever one seems better for this specific page).
*
- * Caller's checkingunique and uniquedup arguments help us decide if we should
- * perform deduplication, which is primarily useful with low cardinality data,
- * but can sometimes absorb version churn.
+ * Caller's checkingunique, uniquedup, and indexunchanged arguments help us
+ * decide which alternative strategy we should attempt (or attempt first).
+ * Deduplication is primarily useful with low cardinality data. Bottom-up
+ * index deletion is a backstop against version churn caused by repeated
+ * UPDATE statements where affected indexes don't receive logical changes
+ * (because an optimization like heapam's HOT cannot be applied in the
+ * tableam). But useful interplay between both techniques over time is
+ * sometimes possible.
+ *
+ * Deduplication can sometimes step in when bottom-up index deletion fails due
+ * to it simply being unsafe to delete old version tuples that accumulate on a
+ * leaf page (usually because of one old snapshot that might need the old
+ * versions, and thereby disrupts the cleanup of garbage tuples generally).
+ * Deduplication may buy time for bottom-up index deletion, which can
+ * ultimately succeed because the question of splitting a page affected by
+ * version churn is delayed long enough for the snapshot that held back
+ * deletion to go away naturally. Note that bottom-up deletion can perform
+ * granular deletion of posting list TIDs, just like VACUUM (but unlike our
+ * preferred strategy).
*
* Callers that only want us to look for/delete LP_DEAD items can ask for that
* directly by passing true 'lpdeadonly' argument.
@@ -2640,7 +2671,7 @@ static void
_bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
BTInsertState insertstate,
bool lpdeadonly, bool checkingunique,
- bool uniquedup)
+ bool uniquedup, bool indexunchanged)
{
OffsetNumber deletable[MaxIndexTuplesPerPage];
int ndeletable = 0;
@@ -2671,7 +2702,8 @@ _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
if (ndeletable > 0)
{
- _bt_delitems_delete(rel, buffer, deletable, ndeletable, heapRel);
+ _bt_delitems_delete(rel, buffer, false, InvalidTransactionId,
+ deletable, ndeletable, NULL, 0, heapRel);
insertstate->bounds_valid = false;
/* Return when a page split has already been avoided */
@@ -2700,9 +2732,12 @@ _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
* We can get called in the checkingunique case when there is no reason to
* believe that there are any duplicates on the page; we should at least
* still check for LP_DEAD items. Now that we have, and now that it has
- * not helped, give up and let caller split the page. Deduplication
- * cannot be justified given there is no reason to think that there are
- * duplicates.
+ * not helped, give up and let caller split the page.
+ *
+ * We give up because the other types of operations that might avoid a
+ * page split are also unlikely to work out, but are much more expensive
+ * to try. That cannot be justified given there is no reason to think
+ * that there are duplicates that we can target.
*/
if (checkingunique && !uniquedup)
return;
@@ -2710,6 +2745,25 @@ _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
/* Assume bounds about to be invalidated (this is almost certain now) */
insertstate->bounds_valid = false;
+ /*
+ * Perform bottom-up index deletion pass when executor hint indicated that
+ * incoming item is logically unchanged, or for a unique index that is
+ * known to have physical duplicates for some other reason. (There is a
+ * large overlap between these two cases for a unique index. It's worth
+ * having both triggering conditions in order to apply the optimization in
+ * the event of successive related INSERT and DELETE statements.)
+ *
+ * We'll go on to do a deduplication pass when a bottom-up pass either
+ * fails to delete an acceptable amount of free space (a non-trivial
+ * fraction of the page that typically exceeds the new item's size), or
+ * when we're dealing with low cardinality data that has relatively few
+ * tuples (with large posting lists).
+ */
+ if ((indexunchanged || uniquedup) &&
+ _bt_bottomup_pass(rel, buffer, heapRel, insertstate->itemsz,
+ checkingunique))
+ return;
+
/*
* Perform deduplication pass, though only when it is enabled for the
* index and known to be safe (it must be an allequalimage index).
diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c
index e192873f19..9a72de23a5 100644
--- a/src/backend/access/nbtree/nbtpage.c
+++ b/src/backend/access/nbtree/nbtpage.c
@@ -1110,15 +1110,14 @@ _bt_page_recyclable(Page page)
* sorted in ascending order.
*
* Routine deals with deleting TIDs when some (but not all) of the heap TIDs
- * in an existing posting list item are to be removed by VACUUM. This works
- * by updating/overwriting an existing item with caller's new version of the
- * item (a version that lacks the TIDs that are to be deleted).
+ * in an existing posting list item are to be removed. This works by
+ * updating/overwriting an existing item with caller's new version of the item
+ * (a version that lacks the TIDs that are to be deleted).
*
* We record VACUUMs and b-tree deletes differently in WAL. Deletes must
* generate their own latestRemovedXid by accessing the heap directly, whereas
* VACUUMs rely on the initial heap scan taking care of it indirectly. Also,
- * only VACUUM can perform granular deletes of individual TIDs in posting list
- * tuples.
+ * we remove the VACUUM cycle ID from pages, which b-tree deletes don't do.
*/
void
_bt_delitems_vacuum(Relation rel, Buffer buf,
@@ -1188,7 +1187,11 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
*
* PageIndexTupleOverwrite() won't unset each item's LP_DEAD bit when it
* happens to already be set. It's important that we not interfere with
- * garbage collection mechanisms that use _bt_delitems_delete(). Besides,
+ * garbage collection mechanisms that use _bt_delitems_delete().
+ *
+ * Eagerly removing items with their LP_DEAD bit set seems unwise, because
+ * in practice bottom-up techniques do a good job of taking care of the
+ * problem at a rate that makes sense at a keyspace-local level. Plus
* it'd just be messy. We'd have to explicitly log a latestRemovedXid
* cutoff, just like _bt_delitems_delete(). Accessing tableam blocks
* again from here is rather unappealing.
@@ -1272,36 +1275,119 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
* Delete item(s) from a btree leaf page during single-page cleanup.
*
* This routine assumes that the caller has pinned and write locked the
- * buffer. Also, the given deletable array *must* be sorted in ascending
- * order.
+ * buffer. Also, the given deletable and updatable arrays *must* be sorted in
+ * ascending order.
+ *
+ * Routine deals with deleting TIDs when some (but not all) of the heap TIDs
+ * in an existing posting list item are to be removed. This works by
+ * updating/overwriting an existing item with caller's new version of the item
+ * (a version that lacks the TIDs that are to be deleted).
*
* This is nearly the same as _bt_delitems_vacuum as far as what it does to
* the page, but it needs to generate its own latestRemovedXid by accessing
* the heap. This is used by the REDO routine to generate recovery conflicts.
- * Also, it doesn't handle posting list tuples unless the entire tuple can be
- * deleted as a whole (since there is only one LP_DEAD bit per line pointer).
+ * Though note that bottom-up index deletion caller will provide its own
+ * latestRemovedXid, since it's convenient for it to determine that at the
+ * same point that it determines that the items are dead (it won't set LP_DEAD
+ * items on leaf page at all). Also, we don't clear page's VACUUM cycle ID.
*/
void
_bt_delitems_delete(Relation rel, Buffer buf,
+ bool bottomup, TransactionId bottomupXid,
OffsetNumber *deletable, int ndeletable,
+ BTVacuumPosting *updatable, int nupdatable,
Relation heapRel)
{
Page page = BufferGetPage(buf);
BTPageOpaque opaque;
TransactionId latestRemovedXid = InvalidTransactionId;
+ Size itemsz;
+ char *updatedbuf = NULL;
+ Size updatedbuflen = 0;
+ OffsetNumber updatedoffsets[MaxIndexTuplesPerPage];
/* Shouldn't be called unless there's something to do */
- Assert(ndeletable > 0);
+ Assert(ndeletable > 0 || nupdatable > 0);
+ /* Shouldn't update posting lists unless it's for bottom-up caller */
+ Assert(nupdatable == 0 || bottomup);
if (XLogStandbyInfoActive() && RelationNeedsWAL(rel))
- latestRemovedXid =
- _bt_xid_horizon(rel, heapRel, page, deletable, ndeletable);
+ {
+ if (!bottomup)
+ latestRemovedXid =
+ _bt_xid_horizon(rel, heapRel, page, deletable,
+ ndeletable);
+ else
+ latestRemovedXid = bottomupXid;
+ }
+
+ for (int i = 0; i < nupdatable; i++)
+ {
+ /* Replace work area IndexTuple with updated version */
+ _bt_update_posting(updatable[i]);
+
+ /* Maintain array of updatable page offsets for WAL record */
+ updatedoffsets[i] = updatable[i]->updatedoffset;
+ }
+
+ /* XLOG stuff -- allocate and fill buffer before critical section */
+ if (nupdatable > 0 && RelationNeedsWAL(rel))
+ {
+ Size offset = 0;
+
+ for (int i = 0; i < nupdatable; i++)
+ {
+ BTVacuumPosting vacposting = updatable[i];
+
+ itemsz = SizeOfBtreeUpdate +
+ vacposting->ndeletedtids * sizeof(uint16);
+ updatedbuflen += itemsz;
+ }
+
+ updatedbuf = palloc(updatedbuflen);
+ for (int i = 0; i < nupdatable; i++)
+ {
+ BTVacuumPosting vacposting = updatable[i];
+ xl_btree_update update;
+
+ update.ndeletedtids = vacposting->ndeletedtids;
+ memcpy(updatedbuf + offset, &update.ndeletedtids,
+ SizeOfBtreeUpdate);
+ offset += SizeOfBtreeUpdate;
+
+ itemsz = update.ndeletedtids * sizeof(uint16);
+ memcpy(updatedbuf + offset, vacposting->deletetids, itemsz);
+ offset += itemsz;
+ }
+ }
/* No ereport(ERROR) until changes are logged */
START_CRIT_SECTION();
- /* Fix the page */
- PageIndexMultiDelete(page, deletable, ndeletable);
+ /*
+ * Handle posting tuple updates.
+ *
+ * Deliberately do this before handling simple deletes. If we did it the
+ * other way around (i.e. WAL record order -- simple deletes before
+ * updates) then we'd have to make compensating changes to the 'updatable'
+ * array of offset numbers.
+ */
+ for (int i = 0; i < nupdatable; i++)
+ {
+ OffsetNumber updatedoffset = updatedoffsets[i];
+ IndexTuple itup;
+
+ itup = updatable[i]->itup;
+ itemsz = MAXALIGN(IndexTupleSize(itup));
+ if (!PageIndexTupleOverwrite(page, updatedoffset, (Item) itup,
+ itemsz))
+ elog(PANIC, "failed to update partially dead item in block %u of index \"%s\"",
+ BufferGetBlockNumber(buf), RelationGetRelationName(rel));
+ }
+
+ /* Now handle simple deletes of entire tuples */
+ if (ndeletable > 0)
+ PageIndexMultiDelete(page, deletable, ndeletable);
/*
* Unlike _bt_delitems_vacuum, we *must not* clear the vacuum cycle ID,
@@ -1329,6 +1415,7 @@ _bt_delitems_delete(Relation rel, Buffer buf,
xlrec_delete.latestRemovedXid = latestRemovedXid;
xlrec_delete.ndeleted = ndeletable;
+ xlrec_delete.nupdated = nupdatable;
XLogBeginInsert();
XLogRegisterBuffer(0, buf, REGBUF_STANDARD);
@@ -1339,8 +1426,16 @@ _bt_delitems_delete(Relation rel, Buffer buf,
* When XLogInsert stores the whole buffer, the array need not be
* stored too.
*/
- XLogRegisterBufData(0, (char *) deletable,
- ndeletable * sizeof(OffsetNumber));
+ if (ndeletable > 0)
+ XLogRegisterBufData(0, (char *) deletable,
+ ndeletable * sizeof(OffsetNumber));
+
+ if (nupdatable > 0)
+ {
+ XLogRegisterBufData(0, (char *) updatedoffsets,
+ nupdatable * sizeof(OffsetNumber));
+ XLogRegisterBufData(0, updatedbuf, updatedbuflen);
+ }
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_DELETE);
@@ -1348,6 +1443,13 @@ _bt_delitems_delete(Relation rel, Buffer buf,
}
END_CRIT_SECTION();
+
+ /* can't leak memory here */
+ if (updatedbuf != NULL)
+ pfree(updatedbuf);
+ /* free tuples generated by calling _bt_update_posting() */
+ for (int i = 0; i < nupdatable; i++)
+ pfree(updatable[i]->itup);
}
/*
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index 8eeb7bb64e..bc82cd4e7d 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -209,7 +209,7 @@ btinsert(Relation rel, Datum *values, bool *isnull,
itup = index_form_tuple(RelationGetDescr(rel), values, isnull);
itup->t_tid = *ht_ctid;
- result = _bt_doinsert(rel, itup, checkUnique, heapRel);
+ result = _bt_doinsert(rel, itup, checkUnique, heapRel, indexunchanged);
pfree(itup);
diff --git a/src/backend/access/nbtree/nbtutils.c b/src/backend/access/nbtree/nbtutils.c
index 2f5f14e527..b6a60ce1cb 100644
--- a/src/backend/access/nbtree/nbtutils.c
+++ b/src/backend/access/nbtree/nbtutils.c
@@ -2414,6 +2414,11 @@ _bt_keep_natts(Relation rel, IndexTuple lastleft, IndexTuple firstright,
* This weaker guarantee is good enough for nbtsplitloc.c caller, since false
* negatives generally only have the effect of making leaf page splits use a
* more balanced split point.
+ *
+ * The differences between this function and _bt_keep_natts may actually be
+ * helpful to the bottom-up index deletion caller. A bottom-up pass tries to
+ * find old versions left behind by UPDATEs, but only when those UPDATEs
+ * didn't logically modify columns that are covered by the index.
*/
int
_bt_keep_natts_fast(Relation rel, IndexTuple lastleft, IndexTuple firstright)
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index 5135b800af..d2142f3e89 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -675,7 +675,56 @@ btree_xlog_delete(XLogReaderState *record)
page = (Page) BufferGetPage(buffer);
- PageIndexMultiDelete(page, (OffsetNumber *) ptr, xlrec->ndeleted);
+ if (xlrec->nupdated > 0)
+ {
+ OffsetNumber *updatedoffsets;
+ xl_btree_update *updates;
+
+ updatedoffsets = (OffsetNumber *)
+ (ptr + xlrec->ndeleted * sizeof(OffsetNumber));
+ updates = (xl_btree_update *) ((char *) updatedoffsets +
+ xlrec->nupdated *
+ sizeof(OffsetNumber));
+
+ for (int i = 0; i < xlrec->nupdated; i++)
+ {
+ BTVacuumPosting vacposting;
+ IndexTuple origtuple;
+ ItemId itemid;
+ Size itemsz;
+
+ itemid = PageGetItemId(page, updatedoffsets[i]);
+ origtuple = (IndexTuple) PageGetItem(page, itemid);
+
+ vacposting = palloc(offsetof(BTVacuumPostingData, deletetids) +
+ updates->ndeletedtids * sizeof(uint16));
+ vacposting->updatedoffset = updatedoffsets[i];
+ vacposting->itup = origtuple;
+ vacposting->ndeletedtids = updates->ndeletedtids;
+ memcpy(vacposting->deletetids,
+ (char *) updates + SizeOfBtreeUpdate,
+ updates->ndeletedtids * sizeof(uint16));
+
+ _bt_update_posting(vacposting);
+
+ /* Overwrite updated version of tuple */
+ itemsz = MAXALIGN(IndexTupleSize(vacposting->itup));
+ if (!PageIndexTupleOverwrite(page, updatedoffsets[i],
+ (Item) vacposting->itup, itemsz))
+ elog(PANIC, "failed to update partially dead item");
+
+ pfree(vacposting->itup);
+ pfree(vacposting);
+
+ /* advance to next xl_btree_update from array */
+ updates = (xl_btree_update *)
+ ((char *) updates + SizeOfBtreeUpdate +
+ updates->ndeletedtids * sizeof(uint16));
+ }
+ }
+
+ if (xlrec->ndeleted > 0)
+ PageIndexMultiDelete(page, (OffsetNumber *) ptr, xlrec->ndeleted);
/* Mark the page as not containing any LP_DEAD items */
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
--
2.25.1
[application/octet-stream] v8-0005-Teach-heapam-to-support-bottom-up-index-deletion.patch (24.8K, ../../CAH2-Wzm46rS1JDmRO0fbnQDpYyD2PrX2cYsa8-5=nhp7nT_w9A@mail.gmail.com/5-v8-0005-Teach-heapam-to-support-bottom-up-index-deletion.patch)
download | inline diff:
From e7c8f6a0e112b345e9c0a3de33ba5ca86977b294 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Mon, 9 Nov 2020 12:59:30 -0800
Subject: [PATCH v8 5/5] Teach heapam to support bottom-up index deletion.
This commit finalizes work started by recent related bottom-up index
deletion commits. This is the last piece required for the feature to
actually work.
Author: Peter Geoghegan <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wz=CEKFa74EScx_hFVshCOn6AA5T-ajFASTdzipdkLTNQQ@mail.gmail.com
---
src/include/access/heapam.h | 2 +
src/backend/access/heap/heapam.c | 613 +++++++++++++++++++++++
src/backend/access/heap/heapam_handler.c | 2 +-
3 files changed, 616 insertions(+), 1 deletion(-)
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index d950083a7d..6d2ce8b540 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -171,6 +171,8 @@ extern void simple_heap_update(Relation relation, ItemPointer otid,
extern TransactionId heap_compute_xid_horizon_for_tuples(Relation rel,
ItemPointerData *items,
int nitems);
+extern TransactionId heapam_index_delete_check(Relation rel,
+ TM_IndexDeleteOp *delstate);
/* in heap/pruneheap.c */
struct GlobalVisState;
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 082aa7b687..856c26e03b 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -55,6 +55,7 @@
#include "miscadmin.h"
#include "pgstat.h"
#include "port/atomics.h"
+#include "port/pg_bitutils.h"
#include "storage/bufmgr.h"
#include "storage/freespace.h"
#include "storage/lmgr.h"
@@ -102,6 +103,7 @@ static void MultiXactIdWait(MultiXactId multi, MultiXactStatus status, uint16 in
int *remaining);
static bool ConditionalMultiXactIdWait(MultiXactId multi, MultiXactStatus status,
uint16 infomask, Relation rel, int *remaining);
+static int heapam_index_delete_check_sort(Relation rel, TM_IndexDeleteOp *delstate);
static XLogRecPtr log_heap_new_cid(Relation relation, HeapTuple tup);
static HeapTuple ExtractReplicaIdentity(Relation rel, HeapTuple tup, bool key_changed,
bool *copy);
@@ -178,6 +180,17 @@ typedef struct
} XidHorizonPrefetchState;
#endif
+/*
+ * heapam_index_delete_check uses this structure to determine which heap pages
+ * to visit, and in what order
+ */
+typedef struct IndexDeleteCounts
+{
+ int16 npromisingtids;
+ int16 ntids;
+ int16 ideltids;
+} IndexDeleteCounts;
+
/*
* This table maps tuple lock strength values for each particular
* MultiXactStatus value.
@@ -192,6 +205,11 @@ static const int MultiXactStatusLock[MaxMultiXactStatus + 1] =
LockTupleExclusive /* Update */
};
+/*
+ * Shellsort gap sequence (taken from Sedgewick-Incerpi paper)
+ */
+static const int ShellsortGaps[8] = {861, 336, 112, 48, 21, 7, 3, 1};
+
/* Get the LockTupleMode for a given MultiXactStatus */
#define TUPLOCK_from_mxstatus(status) \
(MultiXactStatusLock[(status)])
@@ -6993,6 +7011,9 @@ xid_horizon_prefetch_buffer(Relation rel,
* deleting hundreds of tuples from a single index block. To amortize that
* cost to some degree, this uses prefetching and combines repeat accesses to
* the same block.
+ *
+ * Note: The logic for maintaining latestRemovedXid here is duplicated by code
+ * within heapam_index_delete_check(). Make sure that they stay in sync.
*/
TransactionId
heap_compute_xid_horizon_for_tuples(Relation rel,
@@ -7139,6 +7160,598 @@ heap_compute_xid_horizon_for_tuples(Relation rel,
return latestRemovedXid;
}
+#define MAX_DELETE_HEAP_BLOCKS 4
+#define FAVORABLE_BLOCK_STRIDE 3
+
+/*
+ * Determine which heap tuples from a list of TIDs provided by caller are
+ * dead. It is safe to delete index tuples that point to these dead heap
+ * tuples.
+ *
+ * This is used by index AMs that support "bottom up" deletion of duplicate
+ * index tuples in batches of just a few heap pages at a time. Index AMs call
+ * here through the table_index_delete_check() interface. See tableam
+ * interface details (for the TM_IndexDeleteOp struct) for more information.
+ *
+ * Though the main thing that influences which heap pages are accessed here is
+ * the presence of tuples that index AM caller has marked "promising" (which
+ * relate to duplicate index tuples believed to have been inserted in index
+ * recently), there are other considerations. The approach taken here
+ * considers both spatial and temporal locality inside the heap structure.
+ * This is especially helpful when there are several heap blocks with
+ * approximately the same amount of promising tuples. Multiple calls here for
+ * the same index will tend to consistently delete the oldest index tuples,
+ * which keeps the number of buffer misses here to a minimum.
+ *
+ * Sometimes larger batch sizes are preferred here, even when that means that
+ * we might actually exceed caller's immediate requirement for free space in
+ * the index. Contiguous heap blocks are considered "favorable". The
+ * presence of favorable blocks makes the call as a whole access more blocks
+ * to better amortize costs. We expect to be called multiple times for
+ * related records in at least some cases, and have to consider costs over
+ * time. The cost of any individual call is less important.
+ *
+ * Returns the latestRemovedXid from the heap tuples pointed to by the deltids
+ * index tuples that caller finds marked safe to delete.
+ *
+ * Note: The logic for maintaining latestRemovedXid here is duplicated by code
+ * within heap_compute_xid_horizon_for_tuples(). Make sure that they stay in
+ * sync.
+ */
+TransactionId
+heapam_index_delete_check(Relation rel, TM_IndexDeleteOp *delstate)
+{
+ TransactionId latestRemovedXid = InvalidTransactionId;
+ BlockNumber hblkno = InvalidBlockNumber;
+ Buffer buf = InvalidBuffer;
+ Page hpage;
+ bool finalhpage = false;
+ int finalndeltids = 0;
+ int nblocksaccessed = 0;
+ int nblocksfavorable = 0;
+ int spacefreed = 0;
+ int spacefreedbeforecurhpage = 0;
+ SnapshotData SnapshotNonVacuumable;
+ TM_IndexDelete *deltids = delstate->deltids;
+ TM_IndexStatus *status = delstate->status;
+ int targetfreespace = delstate->targetfreespace;
+
+ InitNonVacuumableSnapshot(SnapshotNonVacuumable, GlobalVisTestFor(rel));
+
+ /*
+ * Sort and shrink deltids array so that it consists only of TIDs from
+ * just a few of the most promising blocks
+ */
+ nblocksfavorable = heapam_index_delete_check_sort(rel, delstate);
+ for (int i = 0; i < delstate->ndeltids; i++)
+ {
+ TM_IndexStatus *dstatus = status + deltids[i].id;
+ ItemPointer htid = &deltids[i].tid;
+ ItemPointerData tmp;
+ bool all_dead = false;
+ bool found;
+ ItemId hitemid;
+ OffsetNumber hoffnum;
+ HeapTupleData heapTuple;
+
+ Assert(!dstatus->deleteitup);
+
+ if (hblkno == InvalidBlockNumber ||
+ ItemPointerGetBlockNumber(htid) != hblkno)
+ {
+ /*
+ * We usually do a little extra work on the final heap page after
+ * caller's target space to free has been reached. The cost of
+ * accessing the final heap page we'll need to visit has already
+ * been paid by that point. We finish off the entire final heap
+ * page because it's cheap to do so.
+ *
+ * We don't want to unnecessarily visit the next page in line.
+ * Handle that here (when we just finished final page).
+ */
+ if (finalhpage)
+ break;
+
+ /*
+ * Each time we're about to access a new page we consider if it's
+ * really worth it. We apply two tests before we visit the next
+ * page, and give up if either fails:
+ *
+ * 1. Give up when we didn't enable our caller to free any
+ * additional space as a result of processing the most recent heap
+ * page visited. We expect to make steady progress or no
+ * progress.
+ *
+ * 2. Give up when MAX_DELETE_HEAP_BLOCKS have been accessed
+ * already, no matter what. (This is defensive, since the deltids
+ * array was shrunk before we started. It should now contain TIDs
+ * from pages not exceeding MAX_DELETE_HEAP_BLOCKS in number.)
+ */
+ if (nblocksaccessed >= 1 && spacefreed == spacefreedbeforecurhpage)
+ break;
+ if (nblocksaccessed == MAX_DELETE_HEAP_BLOCKS)
+ break;
+
+ /*
+ * After visiting and processing the first heap page, aggressively
+ * decay target space freed (the request from index AM caller)
+ * before accessing each new heap page (starting with the second
+ * in line). But only start decaying when we encounter our first
+ * non-favorable block.
+ *
+ * Favorable blocks are contiguous groups of heap blocks that are
+ * likely to have related heap tuples that are cheaper to process
+ * in larger batches. It doesn't make sense to be stingy here.
+ * The index AM may end up calling us about the same heap TIDs
+ * before much time has passed if we do that.
+ *
+ * Note that even favorable blocks are required to enable caller
+ * to free at least some space -- otherwise we give up before
+ * accessing the next block in line. If a favorable block cannot
+ * be freed then there is probably an old snapshot that frustrates
+ * progress here in general.
+ */
+ if (nblocksfavorable == 0)
+ {
+ targetfreespace /= 2;
+
+ /* Must always start out with at least 1 favorable block */
+ Assert(nblocksaccessed >= 1);
+ }
+
+ /* Now access next page */
+ if (BufferIsValid(buf))
+ {
+ LockBuffer(buf, BUFFER_LOCK_UNLOCK);
+ ReleaseBuffer(buf);
+ }
+
+ /*
+ * We could prune the heap page in passing here, but that doesn't
+ * seem like a good idea. (Index AM caller is expected to hold
+ * locks of its own.)
+ */
+ hblkno = ItemPointerGetBlockNumber(htid);
+ buf = ReadBuffer(rel, hblkno);
+ hpage = BufferGetPage(buf);
+ nblocksaccessed++;
+ if (nblocksfavorable > 0)
+ nblocksfavorable--;
+ spacefreedbeforecurhpage = spacefreed;
+
+ /* Need to lock buffer for visibility checks */
+ LockBuffer(buf, BUFFER_LOCK_SHARE);
+ }
+
+ tmp = *htid;
+ found = heap_hot_search_buffer(&tmp, rel, buf, &SnapshotNonVacuumable,
+ &heapTuple, &all_dead, true);
+
+ if (found || !all_dead)
+ continue;
+
+ /* Caller can delete this TID from index */
+ finalndeltids = i + 1;
+ dstatus->deleteitup = true;
+ spacefreed += dstatus->tupsize;
+
+ if (spacefreed >= targetfreespace)
+ {
+ /*
+ * Caller's free space target has now been met (maybe...target may
+ * have decayed one or more times from original value if we
+ * weren't accessing favorable/contiguous blocks).
+ *
+ * Finish off the current/final heap page before finishing.
+ */
+ finalhpage = true;
+ }
+
+ /*
+ * One last step required for TID that caller will delete. Must
+ * maintain latestRemovedXid for caller's delete operation.
+ */
+ hoffnum = ItemPointerGetOffsetNumber(htid);
+ hitemid = PageGetItemId(hpage, hoffnum);
+
+ while (ItemIdIsRedirected(hitemid))
+ {
+ hoffnum = ItemIdGetRedirect(hitemid);
+ hitemid = PageGetItemId(hpage, hoffnum);
+ }
+
+ /*
+ * If the heap item has storage, then read the header and use that to
+ * set latestRemovedXid.
+ *
+ * Some LP_DEAD items may not be accessible, so we ignore them.
+ */
+ if (ItemIdHasStorage(hitemid))
+ {
+ HeapTupleHeader htuphdr;
+
+ htuphdr = (HeapTupleHeader) PageGetItem(hpage, hitemid);
+
+ HeapTupleHeaderAdvanceLatestRemovedXid(htuphdr, &latestRemovedXid);
+ }
+ else if (ItemIdIsDead(hitemid))
+ {
+ /*
+ * Conjecture: if hitemid is dead then it had xids before the xids
+ * marked on LP_NORMAL items. So we just ignore this item and move
+ * onto the next, for the purposes of calculating
+ * latestRemovedXid.
+ */
+ }
+ else
+ Assert(!ItemIdIsUsed(hitemid));
+ }
+
+ if (BufferIsValid(buf))
+ {
+ LockBuffer(buf, BUFFER_LOCK_UNLOCK);
+ ReleaseBuffer(buf);
+ }
+
+ /*
+ * If all heap tuples were LP_DEAD then we will be returning
+ * InvalidTransactionId here, which avoids conflicts. This matches
+ * existing logic which assumes that LP_DEAD tuples must already be older
+ * than the latestRemovedXid on the cleanup record that set them as
+ * LP_DEAD, hence must already have generated a conflict.
+ */
+ delstate->ndeltids = finalndeltids;
+
+ return latestRemovedXid;
+}
+
+/*
+ * Determine how many favorable blocks are among blocks we'll access (which
+ * have been sorted by heapam_index_delete_check_sort() by the time we get
+ * called). The exact approach taken by heapam_index_delete_check() is
+ * influenced by the number of favorable blocks.
+ *
+ * Returns number of favorable blocks, starting from (and including) the first
+ * block in line for processing.
+ *
+ * Favorable blocks are contiguous heap blocks, which are likely to have
+ * relatively many dead items. These blocks are cheaper to access together
+ * all at once. Having many favorable blocks is common with low cardinality
+ * index tuples, where heap locality has a relatively large influence on which
+ * heap blocks we visit (and the order they're processed in). Being more
+ * aggressive with favorable blocks is slightly more expensive in the short
+ * term, but less expensive across related heapam_index_delete_check() calls.
+ *
+ * Note: We always indicate that there is at least 1 favorable block (the
+ * first in line to process). The first block must always be in sorted order
+ * because the ordering is relative to the first block (or previous block).
+ * This degenerate case isn't a problem for heapam_index_delete_check(), which
+ * is supposed to always visit the first heap page in line, regardless of any
+ * other factor.
+ */
+static int
+top_block_groups_favorable(IndexDeleteCounts *blockcounts, int nblockgroups,
+ TM_IndexDelete *deltids)
+{
+ int nblocksfavorable = 0;
+ BlockNumber lastblock = InvalidBlockNumber;
+
+ for (int b = 0; b < nblockgroups; b++)
+ {
+ IndexDeleteCounts *blockgroup = blockcounts + b;
+ TM_IndexDelete *firstingroup = deltids + blockgroup->ideltids;
+ BlockNumber thisblock = ItemPointerGetBlockNumber(&firstingroup->tid);
+
+ if (BlockNumberIsValid(lastblock) &&
+ (thisblock < lastblock ||
+ thisblock > lastblock + FAVORABLE_BLOCK_STRIDE))
+ break;
+
+ nblocksfavorable++;
+ lastblock = Min(thisblock, MaxBlockNumber - FAVORABLE_BLOCK_STRIDE);
+ }
+
+ Assert(nblocksfavorable >= 1);
+
+ return nblocksfavorable;
+}
+
+static inline int
+indexdelete_tids_cmp(ItemPointer tid1, ItemPointer tid2)
+{
+ {
+ BlockNumber blk1 = ItemPointerGetBlockNumber(tid1);
+ BlockNumber blk2 = ItemPointerGetBlockNumber(tid2);
+
+ if (blk1 != blk2)
+ return (blk1 < blk2) ? -1 : 1;
+ }
+ {
+ OffsetNumber pos1 = ItemPointerGetOffsetNumber(tid1);
+ OffsetNumber pos2 = ItemPointerGetOffsetNumber(tid2);
+
+ if (pos1 != pos2)
+ return (pos1 < pos2) ? -1 : 1;
+ }
+
+ pg_unreachable();
+
+ return 0;
+}
+
+static inline int
+indexdeletecount_cmp(IndexDeleteCounts *count1, IndexDeleteCounts *count2)
+{
+ uint32 ntids1,
+ ntids2;
+
+ /* We expect power-of-two values for npromisingtids fields */
+ Assert(count1->npromisingtids == 0 ||
+ ((count1->npromisingtids - 1) & count1->npromisingtids) == 0);
+ Assert(count2->npromisingtids == 0 ||
+ ((count2->npromisingtids - 1) & count2->npromisingtids) == 0);
+
+ /*
+ * Most significant field is npromisingtids, which we sort on in desc
+ * order. The usual asc comparison order is deliberately inverted here.
+ */
+ if (count1->npromisingtids > count2->npromisingtids)
+ return -1;
+ if (count1->npromisingtids < count2->npromisingtids)
+ return 1;
+
+ /*
+ * Tiebreak: desc ntids sort order.
+ *
+ * We cannot expect power-of-two values for ntids fields. We should
+ * behave as if they were already rounded up for us instead.
+ */
+ ntids1 = count1->ntids;
+ ntids2 = count2->ntids;
+ if (ntids1 != ntids2)
+ {
+ ntids1 = pg_nextpower2_32(ntids1);
+ ntids2 = pg_nextpower2_32(ntids2);
+
+ if (ntids1 > ntids2)
+ return -1;
+ if (ntids1 < ntids2)
+ return 1;
+ }
+
+ /*
+ * Tiebreak: asc offset-into-deltids-for-block (offset to first TID for
+ * block in deltids array) order.
+ *
+ * This is equivalent to sorting in ascending heap block number order
+ * (among otherwise equal subsets of the array). This approach allows us
+ * to avoid accessing the out-of-line TID. (We rely on the assumption
+ * that the deltids array was sorted in ascending heap TID order when
+ * these offsets to the first TID from each heap block group were formed.)
+ */
+ if (count1->ideltids > count2->ideltids)
+ return 1;
+ if (count1->ideltids < count2->ideltids)
+ return -1;
+
+ pg_unreachable();
+
+ return 0;
+}
+
+/*
+ * Two hand written shellshort implementations.
+ *
+ * The two sort operations needed by heapam_index_delete_check_sort() become
+ * quite noticeable on profiles of workloads with lots of index contention
+ * caused by non-HOT updates. Keeping costs down is important enough to
+ * justify several micro-optimizations. We could just use qsort() instead,
+ * but the indirection that it imposes is expensive enough to matter here.
+ * (The size of array elements also matters, which is why we keep it under 8
+ * bytes - swaps should be as fast as reasonably possible).
+ *
+ * We use shellsort here because it has many of the same strengths as an
+ * industrial-strength quicksort implementation, but is also lightweight in
+ * the sense that the entire implementation compiles to relatively few machine
+ * instructions. It is adaptive to inputs with some presorted subsets (which
+ * are typical here).
+ *
+ * This implementation is fast with array sizes up to about 1900. This covers
+ * all supported BLCKSZ values.
+ */
+static void
+heap_tid_shellsort(TM_IndexDelete *deltids, int ndeltids)
+{
+ int low = 0;
+
+ /* Think carefully before changing anything here */
+ StaticAssertStmt(sizeof(TM_IndexDelete) <= 8,
+ "element size exceeds 8 bytes");
+
+ for (int g = 0; g < lengthof(ShellsortGaps); g++)
+ {
+ for (int hi = ShellsortGaps[g], i = low + hi; i < ndeltids; i++)
+ {
+ TM_IndexDelete d = deltids[i];
+ int j = i;
+
+ while (j >= hi &&
+ indexdelete_tids_cmp(&deltids[j - hi].tid, &d.tid) >= 0)
+ {
+ deltids[j] = deltids[j - hi];
+ j -= hi;
+ }
+ deltids[j] = d;
+ }
+ }
+}
+
+static void
+index_delete_shellsort(IndexDeleteCounts *blockcounts, int nblockgroups)
+{
+ int low = 0;
+
+ /* Think carefully before changing anything here */
+ StaticAssertStmt(sizeof(IndexDeleteCounts) <= 8,
+ "element size exceeds 8 bytes");
+
+ for (int g = 0; g < lengthof(ShellsortGaps); g++)
+ {
+ for (int hi = ShellsortGaps[g], i = low + hi; i < nblockgroups; i++)
+ {
+ IndexDeleteCounts c = blockcounts[i];
+ int j = i;
+
+ while (j >= hi &&
+ indexdeletecount_cmp(&blockcounts[j - hi], &c) >= 0)
+ {
+ blockcounts[j] = blockcounts[j - hi];
+ j -= hi;
+ }
+ blockcounts[j] = c;
+ }
+ }
+}
+
+/*
+ * heapam_index_delete_check() helper function. Sorts deltids array in the
+ * order needed for useful processing.
+ *
+ * Groups heap TIDs from deltids into heap block number groupings. From
+ * there, sorts each heap block grouping by the total number of "promising"
+ * TIDs it contains (in desc order). For blocks with the same number of
+ * promising TIDs, tiebreak on the total heap TID count (also desc order).
+ *
+ * heapam_index_delete_check() only visits 1 - MAX_DELETE_HEAP_BLOCKS heap
+ * blocks due to the speculative nature of the batch index deletion
+ * optimization. These heap blocks had better be the most promising
+ * available, based on a variety of criteria. We make sure of that here.
+ *
+ * Sets new size of deltids array (ndeltids) in state. deltids will only have
+ * TIDs from the MAX_DELETE_HEAP_BLOCKS most promising heap blocks when we
+ * return (which is usually far fewer).
+ *
+ * Returns number of "favorable" blocks.
+ */
+static int
+heapam_index_delete_check_sort(Relation rel, TM_IndexDeleteOp *delstate)
+{
+ IndexDeleteCounts *blockcounts;
+ TM_IndexDelete *reordereddeltids;
+ BlockNumber curblock = InvalidBlockNumber;
+ int nblockgroups = 0;
+ int ncopied = 0;
+ int nblocksfavorable = 0;
+
+ Assert(delstate->ndeltids > 0);
+
+ /* First sort caller's array by TID */
+ heap_tid_shellsort(delstate->deltids, delstate->ndeltids);
+
+ /* Calculate per-heap-block count of TIDs */
+ blockcounts = palloc(sizeof(IndexDeleteCounts) * delstate->ndeltids);
+ for (int i = 0; i < delstate->ndeltids; i++)
+ {
+ ItemPointer deltid = &delstate->deltids[i].tid;
+ TM_IndexStatus *dstatus = delstate->status + delstate->deltids[i].id;
+ bool ispromising = dstatus->ispromising;
+
+ if (curblock != ItemPointerGetBlockNumber(deltid))
+ {
+ /* New block group */
+ nblockgroups++;
+
+ Assert(curblock < ItemPointerGetBlockNumber(deltid) ||
+ !BlockNumberIsValid(curblock));
+
+ curblock = ItemPointerGetBlockNumber(deltid);
+ blockcounts[nblockgroups - 1].ideltids = i;
+ blockcounts[nblockgroups - 1].ntids = 1;
+ blockcounts[nblockgroups - 1].npromisingtids = 0;
+ }
+ else
+ {
+ blockcounts[nblockgroups - 1].ntids++;
+ }
+
+ if (ispromising)
+ blockcounts[nblockgroups - 1].npromisingtids++;
+ }
+
+ /*
+ * We're about ready to use index_delete_shellsort() to determine the
+ * optimal order for visiting heap pages. But before we do, round the
+ * number of promising tuples for each block group up to the nearest
+ * power-of-two (unless there are zero promising tuples). This scheme
+ * usefully divides heap pages into buckets. Each bucket contains heap
+ * pages that are approximately equally promising, that we want to treat
+ * as exactly equivalent (at least initially).
+ *
+ * While in general the presence of promising tuples (the hint that index
+ * AMs provide) is the best information that we have to go on, it is based
+ * on simple heuristics about duplicates in indexes that are understood to
+ * have specific flaws. We should not let the most promising heap pages
+ * win or lose on the basis of _relatively_ small differences in the total
+ * number of promising tuples. Small differences between the most
+ * promising few heap pages are effectively ignored by applying this
+ * power-of-two bucketing scheme.
+ *
+ * When we have lots of ties on the final bucket-ized npromisingtids among
+ * the most promising heap pages, we let heap locality determine the order
+ * in which we visit heap pages. This is helpful because it exploits the
+ * natural tendency for earlier heap blocks to accumulate more LP_DEAD
+ * items sooner in workloads with many non-HOT updates. It's also helpful
+ * because the effect over time is that we process related heap blocks
+ * sequentially, possibly with multiple rounds of processing over the same
+ * related heap blocks that are subject to continuous non-HOT updates over
+ * time.
+ *
+ * Note that we effectively have the same power-of-two bucketing scheme
+ * with the ntids field (which is compared after npromisingtids). The
+ * only reason that we don't fix nhtids here is that the original values
+ * will be needed when copying the final TIDs from winning block groups
+ * back into caller's deltids array.
+ */
+ for (int b = 0; b < nblockgroups; b++)
+ {
+ IndexDeleteCounts *blockgroup = blockcounts + b;
+
+ if (blockgroup->npromisingtids != 0)
+ blockgroup->npromisingtids =
+ pg_nextpower2_32((uint32) blockgroup->npromisingtids);
+ }
+
+ /* Sort groups and rearrange caller's deltids array */
+ index_delete_shellsort(blockcounts, nblockgroups);
+ reordereddeltids = palloc(delstate->ndeltids * sizeof(TM_IndexDelete));
+
+ nblockgroups = Min(MAX_DELETE_HEAP_BLOCKS, nblockgroups);
+ /* Determine number of favorable blocks at the start of array */
+ nblocksfavorable = top_block_groups_favorable(blockcounts, nblockgroups,
+ delstate->deltids);
+ for (int b = 0; b < nblockgroups; b++)
+ {
+ IndexDeleteCounts *blockgroup = blockcounts + b;
+ TM_IndexDelete *firstingroup =
+ delstate->deltids + blockgroup->ideltids;
+
+ memcpy(reordereddeltids + ncopied, firstingroup,
+ sizeof(TM_IndexDelete) * blockgroup->ntids);
+ ncopied += blockgroup->ntids;
+ }
+
+ /* Copy final grouped and sorted TIDs back into start of caller's array */
+ memcpy(delstate->deltids, reordereddeltids,
+ sizeof(TM_IndexDelete) * ncopied);
+ delstate->ndeltids = ncopied;
+
+ /* be tidy */
+ pfree(reordereddeltids);
+ pfree(blockcounts);
+
+ return nblocksfavorable;
+}
+
/*
* Perform XLogInsert to register a heap cleanup info message. These
* messages are sent once per VACUUM and are required because
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 0dab0ae634..2ab25c72e8 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2534,7 +2534,7 @@ static const TableAmRoutine heapam_methods = {
.tuple_delete = heapam_tuple_delete,
.tuple_update = heapam_tuple_update,
.tuple_lock = heapam_tuple_lock,
- .index_delete_check = NULL,
+ .index_delete_check = heapam_index_delete_check,
.tuple_fetch_row_version = heapam_fetch_row_version,
.tuple_get_latest_tid = heap_get_latest_tid,
--
2.25.1
[application/octet-stream] v8-0003-Pass-down-logically-unchanged-index-hint.patch (26.7K, ../../CAH2-Wzm46rS1JDmRO0fbnQDpYyD2PrX2cYsa8-5=nhp7nT_w9A@mail.gmail.com/6-v8-0003-Pass-down-logically-unchanged-index-hint.patch)
download | inline diff:
From 89da9180a688e746c6f64d2c9ca6cf2faf593f11 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Mon, 9 Nov 2020 12:59:30 -0800
Subject: [PATCH v8 3/5] Pass down "logically unchanged index" hint.
Add an executor aminsert() hinting mechanism that informs index AMs that
the incoming index tuple (the tuple that accompanies the hint) is not
being inserted because of a logical change to indexed columns (from an
UPDATE or INSERT statement). This "logically unchanged" hint indicates
that the incoming item must be a duplicate of some existing item in the
index (a physical tuple that represents an obsolescent version of the
logical row affected by an UPDATE). When this happens the new tuple is
only needed so that the index will have a separate entry for the latest
logical row (it's latest version/HOT chain).
An aminsert() call which gets the hint is fundamentally different to any
aminsert() call needed for an INSERT statement. It's also fundamentally
difference to an aminsert() call needed for an UPDATE statement where
the index is logically changed by the UPDATE. Recognizing this
difference can allow cleanup of garbage tuples in index access methods
to work better. Cleanup can intelligently target tuples that are likely
to be garbage, without wasting too many cycles on less promising tuples.
This commit is infrastructure for an upcoming commit that will teach
nbtree to perform bottom-up index deletion. No index AM applies the
hint at this point. It is not useful on its own.
Author: Peter Geoghegan <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wz=CEKFa74EScx_hFVshCOn6AA5T-ajFASTdzipdkLTNQQ@mail.gmail.com
---
src/include/access/amapi.h | 1 +
src/include/access/brin_internal.h | 1 +
src/include/access/genam.h | 1 +
src/include/access/gin_private.h | 1 +
src/include/access/gist_private.h | 1 +
src/include/access/hash.h | 1 +
src/include/access/heapam.h | 3 +-
src/include/access/nbtree.h | 1 +
src/include/access/spgist.h | 1 +
src/include/access/tableam.h | 11 ++++--
src/include/executor/executor.h | 3 +-
src/backend/access/brin/brin.c | 1 +
src/backend/access/common/toast_internals.c | 2 +-
src/backend/access/gin/gininsert.c | 1 +
src/backend/access/gist/gist.c | 1 +
src/backend/access/hash/hash.c | 1 +
src/backend/access/heap/heapam.c | 12 ++++--
src/backend/access/heap/heapam_handler.c | 6 ++-
src/backend/access/index/indexam.c | 4 +-
src/backend/access/nbtree/nbtree.c | 1 +
src/backend/access/spgist/spginsert.c | 1 +
src/backend/access/table/tableam.c | 2 +-
src/backend/catalog/indexing.c | 1 +
src/backend/commands/constraint.c | 2 +-
src/backend/commands/copy.c | 5 ++-
src/backend/executor/execIndexing.c | 43 ++++++++++++++++++++-
src/backend/executor/execReplication.c | 4 +-
src/backend/executor/nodeModifyTable.c | 14 +++++--
contrib/bloom/blinsert.c | 1 +
contrib/bloom/bloom.h | 1 +
doc/src/sgml/indexam.sgml | 13 +++++++
31 files changed, 118 insertions(+), 23 deletions(-)
diff --git a/src/include/access/amapi.h b/src/include/access/amapi.h
index 85b4766016..50422c9195 100644
--- a/src/include/access/amapi.h
+++ b/src/include/access/amapi.h
@@ -110,6 +110,7 @@ typedef bool (*aminsert_function) (Relation indexRelation,
ItemPointer heap_tid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
/* bulk delete */
diff --git a/src/include/access/brin_internal.h b/src/include/access/brin_internal.h
index 9ffc9100c0..5016b8035f 100644
--- a/src/include/access/brin_internal.h
+++ b/src/include/access/brin_internal.h
@@ -91,6 +91,7 @@ extern void brinbuildempty(Relation index);
extern bool brininsert(Relation idxRel, Datum *values, bool *nulls,
ItemPointer heaptid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
extern IndexScanDesc brinbeginscan(Relation r, int nkeys, int norderbys);
extern int64 bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
diff --git a/src/include/access/genam.h b/src/include/access/genam.h
index 68d90f5141..43bf62fbcc 100644
--- a/src/include/access/genam.h
+++ b/src/include/access/genam.h
@@ -143,6 +143,7 @@ extern bool index_insert(Relation indexRelation,
ItemPointer heap_t_ctid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
extern IndexScanDesc index_beginscan(Relation heapRelation,
diff --git a/src/include/access/gin_private.h b/src/include/access/gin_private.h
index 5cb2f72e4c..99541b82e8 100644
--- a/src/include/access/gin_private.h
+++ b/src/include/access/gin_private.h
@@ -116,6 +116,7 @@ extern void ginbuildempty(Relation index);
extern bool gininsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
extern void ginEntryInsert(GinState *ginstate,
OffsetNumber attnum, Datum key, GinNullCategory category,
diff --git a/src/include/access/gist_private.h b/src/include/access/gist_private.h
index b68c01a5f2..6adccb26a0 100644
--- a/src/include/access/gist_private.h
+++ b/src/include/access/gist_private.h
@@ -403,6 +403,7 @@ extern void gistbuildempty(Relation index);
extern bool gistinsert(Relation r, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
extern MemoryContext createTempGistContext(void);
extern GISTSTATE *initGISTstate(Relation index);
diff --git a/src/include/access/hash.h b/src/include/access/hash.h
index bab4d9f1b0..d832dd03de 100644
--- a/src/include/access/hash.h
+++ b/src/include/access/hash.h
@@ -364,6 +364,7 @@ extern void hashbuildempty(Relation index);
extern bool hashinsert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
extern bool hashgettuple(IndexScanDesc scan, ScanDirection dir);
extern int64 hashgetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 92b19dba32..d950083a7d 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -148,7 +148,8 @@ extern void heap_abort_speculative(Relation relation, ItemPointer tid);
extern TM_Result heap_update(Relation relation, ItemPointer otid,
HeapTuple newtup,
CommandId cid, Snapshot crosscheck, bool wait,
- struct TM_FailureData *tmfd, LockTupleMode *lockmode);
+ struct TM_FailureData *tmfd, LockTupleMode *lockmode,
+ Bitmapset **modified_attrs_hint);
extern TM_Result heap_lock_tuple(Relation relation, HeapTuple tuple,
CommandId cid, LockTupleMode mode, LockWaitPolicy wait_policy,
bool follow_update,
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index e8fecc6026..d1b3e0ba6a 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -996,6 +996,7 @@ extern void btbuildempty(Relation index);
extern bool btinsert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
extern IndexScanDesc btbeginscan(Relation rel, int nkeys, int norderbys);
extern Size btestimateparallelscan(void);
diff --git a/src/include/access/spgist.h b/src/include/access/spgist.h
index 9f2ccc1730..3a4a570d8c 100644
--- a/src/include/access/spgist.h
+++ b/src/include/access/spgist.h
@@ -199,6 +199,7 @@ extern void spgbuildempty(Relation index);
extern bool spginsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
/* spgscan.c */
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 5cd698c885..f5f778680a 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -465,7 +465,8 @@ typedef struct TableAmRoutine
bool wait,
TM_FailureData *tmfd,
LockTupleMode *lockmode,
- bool *update_indexes);
+ bool *update_indexes,
+ Bitmapset **modified_attrs_hint);
/* see table_tuple_lock() for reference about parameters */
TM_Result (*tuple_lock) (Relation rel,
@@ -1372,6 +1373,9 @@ table_tuple_delete(Relation rel, ItemPointer tid, CommandId cid,
* lockmode - filled with lock mode acquired on tuple
* update_indexes - in success cases this is set to true if new index entries
* are required for this tuple
+ * modified_attrs_hint - which attributes were logically modified by the
+ * update. Passed down to index AMs as a hint from the executor.
+ * Enables table_index_delete_check() optimization.
*
* Normal, successful return value is TM_Ok, which means we did actually
* update it. Failure return codes are TM_SelfModified, TM_Updated, and
@@ -1391,12 +1395,13 @@ static inline TM_Result
table_tuple_update(Relation rel, ItemPointer otid, TupleTableSlot *slot,
CommandId cid, Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd, LockTupleMode *lockmode,
- bool *update_indexes)
+ bool *update_indexes, Bitmapset **modified_attrs_hint)
{
return rel->rd_tableam->tuple_update(rel, otid, slot,
cid, snapshot, crosscheck,
wait, tmfd,
- lockmode, update_indexes);
+ lockmode, update_indexes,
+ modified_attrs_hint);
}
/*
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h
index 0c48d2a519..6e6e56583b 100644
--- a/src/include/executor/executor.h
+++ b/src/include/executor/executor.h
@@ -582,7 +582,8 @@ extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
extern List *ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot, EState *estate,
bool noDupErr,
- bool *specConflict, List *arbiterIndexes);
+ bool *specConflict, List *arbiterIndexes,
+ Bitmapset *modified_attrs_hint);
extern bool ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot,
EState *estate, ItemPointer conflictTid,
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index 1f72562c60..d295c592be 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -151,6 +151,7 @@ bool
brininsert(Relation idxRel, Datum *values, bool *nulls,
ItemPointer heaptid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo)
{
BlockNumber pagesPerRange;
diff --git a/src/backend/access/common/toast_internals.c b/src/backend/access/common/toast_internals.c
index 25a81e5ec6..e206e67756 100644
--- a/src/backend/access/common/toast_internals.c
+++ b/src/backend/access/common/toast_internals.c
@@ -328,7 +328,7 @@ toast_save_datum(Relation rel, Datum value,
toastrel,
toastidxs[i]->rd_index->indisunique ?
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
- NULL);
+ false, NULL);
}
/*
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index 77433dc8a4..6a1e8560a3 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -488,6 +488,7 @@ bool
gininsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo)
{
GinState *ginstate = (GinState *) indexInfo->ii_AmCache;
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index 25b42e38f2..09b585547b 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -156,6 +156,7 @@ bool
gistinsert(Relation r, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo)
{
GISTSTATE *giststate = (GISTSTATE *) indexInfo->ii_AmCache;
diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c
index 7c9ccf446c..2ff72bd9f9 100644
--- a/src/backend/access/hash/hash.c
+++ b/src/backend/access/hash/hash.c
@@ -247,6 +247,7 @@ bool
hashinsert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo)
{
Datum index_values[1];
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 1b2f70499e..082aa7b687 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -2892,7 +2892,8 @@ simple_heap_delete(Relation relation, ItemPointer tid)
TM_Result
heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
CommandId cid, Snapshot crosscheck, bool wait,
- TM_FailureData *tmfd, LockTupleMode *lockmode)
+ TM_FailureData *tmfd, LockTupleMode *lockmode,
+ Bitmapset **modified_attrs_hint)
{
TM_Result result;
TransactionId xid = GetCurrentTransactionId();
@@ -3758,10 +3759,15 @@ l2:
if (old_key_tuple != NULL && old_key_copied)
heap_freetuple(old_key_tuple);
+ /* Save for no logical changes hint when non-HOT update performed */
+ if (!use_hot_update && modified_attrs_hint)
+ *modified_attrs_hint = modified_attrs;
+ else
+ bms_free(modified_attrs);
+
bms_free(hot_attrs);
bms_free(key_attrs);
bms_free(id_attrs);
- bms_free(modified_attrs);
bms_free(interesting_attrs);
return TM_Ok;
@@ -3891,7 +3897,7 @@ simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
result = heap_update(relation, otid, tup,
GetCurrentCommandId(true), InvalidSnapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode);
+ &tmfd, &lockmode, NULL);
switch (result)
{
case TM_SelfModified:
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index a08c494034..0dab0ae634 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -314,7 +314,8 @@ static TM_Result
heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
CommandId cid, Snapshot snapshot, Snapshot crosscheck,
bool wait, TM_FailureData *tmfd,
- LockTupleMode *lockmode, bool *update_indexes)
+ LockTupleMode *lockmode, bool *update_indexes,
+ Bitmapset **modified_attrs_hint)
{
bool shouldFree = true;
HeapTuple tuple = ExecFetchSlotHeapTuple(slot, true, &shouldFree);
@@ -325,7 +326,7 @@ heapam_tuple_update(Relation relation, ItemPointer otid, TupleTableSlot *slot,
tuple->t_tableOid = slot->tts_tableOid;
result = heap_update(relation, otid, tuple, cid, crosscheck, wait,
- tmfd, lockmode);
+ tmfd, lockmode, modified_attrs_hint);
ItemPointerCopy(&tuple->t_self, &slot->tts_tid);
/*
@@ -1931,6 +1932,7 @@ heapam_index_validate_scan(Relation heapRelation,
heapRelation,
indexInfo->ii_Unique ?
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
+ false,
indexInfo);
state->tups_inserted += 1;
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index 3fb8688f8f..0d7fc965e0 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -179,6 +179,7 @@ index_insert(Relation indexRelation,
ItemPointer heap_t_ctid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo)
{
RELATION_CHECKS;
@@ -191,7 +192,8 @@ index_insert(Relation indexRelation,
return indexRelation->rd_indam->aminsert(indexRelation, values, isnull,
heap_t_ctid, heapRelation,
- checkUnique, indexInfo);
+ checkUnique, indexunchanged,
+ indexInfo);
}
/*
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index c4f22f1c69..8eeb7bb64e 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -199,6 +199,7 @@ bool
btinsert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo)
{
bool result;
diff --git a/src/backend/access/spgist/spginsert.c b/src/backend/access/spgist/spginsert.c
index e4508a2b92..8e55f3d711 100644
--- a/src/backend/access/spgist/spginsert.c
+++ b/src/backend/access/spgist/spginsert.c
@@ -207,6 +207,7 @@ bool
spginsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo)
{
SpGistState spgstate;
diff --git a/src/backend/access/table/tableam.c b/src/backend/access/table/tableam.c
index e19bdd246a..35975efbc1 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -356,7 +356,7 @@ simple_table_tuple_update(Relation rel, ItemPointer otid,
GetCurrentCommandId(true),
snapshot, InvalidSnapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode, update_indexes);
+ &tmfd, &lockmode, update_indexes, NULL);
switch (result)
{
diff --git a/src/backend/catalog/indexing.c b/src/backend/catalog/indexing.c
index 538f6a06b8..3e577dd183 100644
--- a/src/backend/catalog/indexing.c
+++ b/src/backend/catalog/indexing.c
@@ -162,6 +162,7 @@ CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
heapRelation,
index->rd_index->indisunique ?
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
+ false,
indexInfo);
}
diff --git a/src/backend/commands/constraint.c b/src/backend/commands/constraint.c
index fc19307bf2..79bd12b7de 100644
--- a/src/backend/commands/constraint.c
+++ b/src/backend/commands/constraint.c
@@ -175,7 +175,7 @@ unique_key_recheck(PG_FUNCTION_ARGS)
*/
index_insert(indexRel, values, isnull, &checktid,
trigdata->tg_relation, UNIQUE_CHECK_EXISTING,
- indexInfo);
+ false, indexInfo);
}
else
{
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index 115860a9d4..514d8f0cce 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -2523,7 +2523,7 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
recheckIndexes =
ExecInsertIndexTuples(resultRelInfo,
buffer->slots[i], estate, false, NULL,
- NIL);
+ NIL, NULL);
ExecARInsertTriggers(estate, resultRelInfo,
slots[i], recheckIndexes,
cstate->transition_capture);
@@ -3268,7 +3268,8 @@ CopyFrom(CopyState cstate)
estate,
false,
NULL,
- NIL);
+ NIL,
+ NULL);
}
/* AFTER ROW INSERT Triggers */
diff --git a/src/backend/executor/execIndexing.c b/src/backend/executor/execIndexing.c
index c6b5bcba7b..e6e8232cca 100644
--- a/src/backend/executor/execIndexing.c
+++ b/src/backend/executor/execIndexing.c
@@ -275,7 +275,8 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
EState *estate,
bool noDupErr,
bool *specConflict,
- List *arbiterIndexes)
+ List *arbiterIndexes,
+ Bitmapset *modified_attrs_hint)
{
ItemPointer tupleid = &slot->tts_tid;
List *result = NIL;
@@ -287,6 +288,7 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
ExprContext *econtext;
Datum values[INDEX_MAX_KEYS];
bool isnull[INDEX_MAX_KEYS];
+ bool indexunchanged;
Assert(ItemPointerIsValid(tupleid));
@@ -389,6 +391,44 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
else
checkUnique = UNIQUE_CHECK_PARTIAL;
+ /*
+ * We may have to hint to index AM that this is a logically unchanged
+ * index tuple. This happens when we're an UPDATE inserting a
+ * duplicate tuple just to represent the successor version (though
+ * only for the subset of indexes where that's actually true).
+ */
+ if (!modified_attrs_hint)
+ indexunchanged = false; /* Probably from an INSERT */
+ else
+ {
+ indexunchanged = true; /* Assume no logical changes for now */
+
+ for (int attr = 0; attr < indexInfo->ii_NumIndexAttrs; attr++)
+ {
+ int keycol = indexInfo->ii_IndexAttrNumbers[attr];
+
+ /*
+ * XXX: With expression indexes we always ignore logical
+ * changes affecting index (i.e. we don't bother noticing
+ * changes affected only indexed expressions, passing down
+ * "indexunchanged = true" hint in more cases as a result).
+ *
+ * It would make more sense if we made the opposite assumption
+ * (though we probably shouldn't make any assumptions at all).
+ */
+ if (keycol <= 0)
+ continue;
+
+ if (bms_is_member(keycol - FirstLowInvalidHeapAttributeNumber,
+ modified_attrs_hint))
+ {
+ /* Changed column -- don't hint for this index */
+ indexunchanged = false;
+ break;
+ }
+ }
+ }
+
satisfiesConstraint =
index_insert(indexRelation, /* index relation */
values, /* array of index Datums */
@@ -396,6 +436,7 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
tupleid, /* tid of heap tuple */
heapRelation, /* heap relation */
checkUnique, /* type of uniqueness check to do */
+ indexunchanged, /* UPDATE without logical change? */
indexInfo); /* index AM may need this */
/*
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index 01d26881e7..e97d05b448 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -445,7 +445,7 @@ ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false, NULL,
- NIL);
+ NIL, NULL);
/* AFTER ROW INSERT Triggers */
ExecARInsertTriggers(estate, resultRelInfo, slot,
@@ -513,7 +513,7 @@ ExecSimpleRelationUpdate(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false, NULL,
- NIL);
+ NIL, NULL);
/* AFTER ROW UPDATE Triggers */
ExecARUpdateTriggers(estate, resultRelInfo,
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 29e07b7228..d76e371595 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -601,7 +601,7 @@ ExecInsert(ModifyTableState *mtstate,
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, true,
&specConflict,
- arbiterIndexes);
+ arbiterIndexes, NULL);
/* adjust the tuple's state accordingly */
table_tuple_complete_speculative(resultRelationDesc, slot,
@@ -640,7 +640,7 @@ ExecInsert(ModifyTableState *mtstate,
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false,
- NULL, NIL);
+ NULL, NIL, NULL);
}
}
@@ -1219,6 +1219,7 @@ ExecUpdate(ModifyTableState *mtstate,
TM_Result result;
TM_FailureData tmfd;
List *recheckIndexes = NIL;
+ Bitmapset *modified_attrs_hint = NULL;
/*
* abort the operation if not running transactions
@@ -1382,7 +1383,8 @@ lreplace:;
estate->es_snapshot,
estate->es_crosscheck_snapshot,
true /* wait for commit */ ,
- &tmfd, &lockmode, &update_indexes);
+ &tmfd, &lockmode, &update_indexes,
+ &modified_attrs_hint);
switch (result)
{
@@ -1513,9 +1515,13 @@ lreplace:;
/* insert index entries for tuple if necessary */
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
+ {
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false,
- NULL, NIL);
+ NULL, NIL,
+ modified_attrs_hint);
+ bms_free(modified_attrs_hint);
+ }
}
if (canSetTag)
diff --git a/contrib/bloom/blinsert.c b/contrib/bloom/blinsert.c
index 6d3fd5c432..be94f2eae8 100644
--- a/contrib/bloom/blinsert.c
+++ b/contrib/bloom/blinsert.c
@@ -198,6 +198,7 @@ bool
blinsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo)
{
BloomState blstate;
diff --git a/contrib/bloom/bloom.h b/contrib/bloom/bloom.h
index 23aa7ac441..7c7a0b47df 100644
--- a/contrib/bloom/bloom.h
+++ b/contrib/bloom/bloom.h
@@ -192,6 +192,7 @@ extern bool blvalidate(Oid opclassoid);
extern bool blinsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
struct IndexInfo *indexInfo);
extern IndexScanDesc blbeginscan(Relation r, int nkeys, int norderbys);
extern int64 blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
diff --git a/doc/src/sgml/indexam.sgml b/doc/src/sgml/indexam.sgml
index 80473e0f1a..5f7c9a1d54 100644
--- a/doc/src/sgml/indexam.sgml
+++ b/doc/src/sgml/indexam.sgml
@@ -280,6 +280,7 @@ aminsert (Relation indexRelation,
ItemPointer heap_tid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
+ bool indexunchanged,
IndexInfo *indexInfo);
</programlisting>
Insert a new tuple into an existing index. The <literal>values</literal> and
@@ -295,6 +296,18 @@ aminsert (Relation indexRelation,
look into the heap to verify tuple liveness).
</para>
+ <para>
+ The <literal>indexunchanged</literal> boolean value gives a hint
+ about the nature of the tuple to be indexed. When it is true,
+ the tuple is a duplicate of some existing tuple in the index. The
+ new tuple is a logically unchanged successor MVCC tuple version. This
+ happens when an <command>UPDATE</command> takes place that does not
+ modify any columns covered by the index, but nevertheless requires a
+ new version in the index. The index AM may use this hint to decide
+ to apply bottom-up index deletion in parts of the index where many
+ versions of the same logical row accumulate.
+ </para>
+
<para>
The function's Boolean result value is significant only when
<literal>checkUnique</literal> is <literal>UNIQUE_CHECK_PARTIAL</literal>.
--
2.25.1
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 20:58 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 23:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-11-12 23:18 ` Peter Geoghegan <[email protected]>
2 siblings, 0 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-11-12 23:18 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Thu, Nov 12, 2020 at 3:00 PM Peter Geoghegan <[email protected]> wrote:
> Attached is v8, which has the enhancements for low cardinality data
> that I mentioned earlier today. It also simplifies the logic for
> dealing with posting lists that we need to delete some TIDs from.
> These posting list simplifications also make the code a bit more
> efficient, which might be noticeable during benchmarking.
One more thing: I repeated a pgbench test that was similar to my
earlier low cardinality tests -- same indexes (fiver, tenner, score,
aid_pkey_include_abalance). And same queries. But longer runs: 4 hours
each. Plus a larger DB: scale 2,500. Plus a rate-limit of 5000 TPS.
Here is the high level report, with 4 runs -- one pair with 16
clients, another pair with 32 clients:
2020-11-11 19:03:26 -0800 - Start of initial data load for run
"patch.r1c16" (DB is also used by later runs)
2020-11-11 19:18:16 -0800 - End of initial data load for run "patch.r1c16"
2020-11-11 19:18:16 -0800 - Start of pgbench run "patch.r1c16"
2020-11-11 23:18:43 -0800 - End of pgbench run "patch.r1c16":
patch.r1c16.bench.out: "tps = 4999.100006 (including connections
establishing)" "latency average = 3.355 ms" "latency stddev = 58.455
ms"
2020-11-11 23:19:12 -0800 - Start of initial data load for run
"master.r1c16" (DB is also used by later runs)
2020-11-11 23:34:33 -0800 - End of initial data load for run "master.r1c16"
2020-11-11 23:34:33 -0800 - Start of pgbench run "master.r1c16"
2020-11-12 03:35:01 -0800 - End of pgbench run "master.r1c16":
master.r1c16.bench.out: "tps = 5000.061623 (including connections
establishing)" "latency average = 8.591 ms" "latency stddev = 64.851
ms"
2020-11-12 03:35:41 -0800 - Start of pgbench run "patch.r1c32"
2020-11-12 07:36:10 -0800 - End of pgbench run "patch.r1c32":
patch.r1c32.bench.out: "tps = 5000.141420 (including connections
establishing)" "latency average = 1.253 ms" "latency stddev = 9.935
ms"
2020-11-12 07:36:40 -0800 - Start of pgbench run "master.r1c32"
2020-11-12 11:37:19 -0800 - End of pgbench run "master.r1c32":
master.r1c32.bench.out: "tps = 5000.542942 (including connections
establishing)" "latency average = 3.069 ms" "latency stddev = 24.640
ms"
2020-11-12 11:38:18 -0800 - Start of pgbench run "patch.r2c16"
We see a very significant latency advantage for the patch here. Here
is the breakdown on query latency from the final patch run,
patch.r1c32:
scaling factor: 2500
query mode: prepared
number of clients: 32
number of threads: 8
duration: 14400 s
number of transactions actually processed: 72002280
latency average = 1.253 ms
latency stddev = 9.935 ms
rate limit schedule lag: avg 0.406 (max 694.645) ms
tps = 5000.141420 (including connections establishing)
tps = 5000.142503 (excluding connections establishing)
statement latencies in milliseconds:
0.002 \set aid1 random_gaussian(1, 100000 * :scale, 4.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 4.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 4.2)
0.001 \set bid random(1, 1 * :scale)
0.001 \set tid random(1, 10 * :scale)
0.001 \set delta random(-5000, 5000)
0.063 BEGIN;
0.361 UPDATE pgbench_accounts SET abalance = abalance +
:delta WHERE aid = :aid1;
0.171 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.172 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.074 END;
Here is the equivalent for master:
scaling factor: 2500
query mode: prepared
number of clients: 32
number of threads: 8
duration: 14400 s
number of transactions actually processed: 72008125
latency average = 3.069 ms
latency stddev = 24.640 ms
rate limit schedule lag: avg 1.695 (max 1097.628) ms
tps = 5000.542942 (including connections establishing)
tps = 5000.544213 (excluding connections establishing)
statement latencies in milliseconds:
0.002 \set aid1 random_gaussian(1, 100000 * :scale, 4.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 4.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 4.2)
0.001 \set bid random(1, 1 * :scale)
0.001 \set tid random(1, 10 * :scale)
0.001 \set delta random(-5000, 5000)
0.078 BEGIN;
0.560 UPDATE pgbench_accounts SET abalance = abalance +
:delta WHERE aid = :aid1;
0.320 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.308 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.102 END;
So even the UPDATE is much faster here.
This is also something we see with pg_statio_tables, which looked like
this by the end for patch:
-[ RECORD 1 ]---+-----------------
schemaname | public
relname | pgbench_accounts
heap_blks_read | 117,384,599
heap_blks_hit | 1,051,175,835
idx_blks_read | 24,761,513
idx_blks_hit | 4,024,776,723
For the patch:
-[ RECORD 1 ]---+-----------------
schemaname | public
relname | pgbench_accounts
heap_blks_read | 191,947,522
heap_blks_hit | 904,536,584
idx_blks_read | 65,653,885
idx_blks_hit | 4,002,061,803
Notice that heap_blks_read is down from 191,947,522 on master, to
117,384,599 with the patch -- so it's ~0.611x with the patch. A huge
reduction like this is possible with the patch because it effectively
amortizes the cost of accessing heap blocks to find garbage to clean
up ("nipping the [index bloat] problem in the bud" is much cheaper
than letting it get out of hand for many reasons, locality in
shared_buffers is one more reason). The patch accesses garbage tuples
in heap blocks close together in time for all indexes, at a point in
time when the blocks are still likely to be found in shared_buffers.
Also notice that idx_blks_read is ~0.38x with the patch. That's less
important, but still significant.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 20:58 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 23:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-11-15 22:29 ` Victor Yegorov <[email protected]>
2020-11-17 04:59 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2 siblings, 1 reply; 1661+ messages in thread
From: Victor Yegorov @ 2020-11-15 22:29 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
пт, 13 нояб. 2020 г. в 00:01, Peter Geoghegan <[email protected]>:
> On Wed, Nov 11, 2020 at 12:58 PM Victor Yegorov <[email protected]>
> wrote:
> > On the other hand, there's quite a big drop on the UPDATEs throughput.
> For sure, undersized shared_bufefrs
> > contribute to this drop. Still, my experience tells me that under
> conditions at hand (disabled HOT due to index
> > over update time column) tables will tend to accumulate bloat and
> produce unnecessary IO also from WAL.
>
> I think that the big SELECT statement with an "ORDER BY mtime ... "
> was a good way of demonstrating the advantages of the patch.
>
> Attached is v8, which has the enhancements for low cardinality data
> that I mentioned earlier today. It also simplifies the logic for
> dealing with posting lists that we need to delete some TIDs from.
> These posting list simplifications also make the code a bit more
> efficient, which might be noticeable during benchmarking.
>
> Perhaps your "we have 5,2% slowdown in UPDATE speed" issue will be at
> least somewhat fixed by the enhancements to v8?
>
Yes, v8 looks very nice!
I've done two 8 hour long sessions with scale=2000 and shared_buffers=512MB
(previously sent postgresql.auto.conf used here with no changes).
The rest of the setup is the same:
- mtime column that is tracks update time
- index on (mtime, aid)
- tenner low cardinality index from Peter's earlier e-mail
- 3 pgbench scripts run in parallel on master and on v8 patchset (scripts
from the previous e-mail used here).
Master
------
relname | nrows | blk_before | mb_before | blk_after |
mb_after | diff
-----------------------+-----------+------------+-----------+-----------+----------+--------
pgbench_accounts | 300000000 | 4918033 | 38422.1 | 5066589 |
39582.7 | +3.0%
accounts_mtime | 300000000 | 1155119 | 9024.4 | 1422354 |
11112.1 | +23.1%
pgbench_accounts_pkey | 300000000 | 822573 | 6426.4 | 822573 |
6426.4 | 0
tenner | 300000000 | 346050 | 2703.5 | 563101 |
4399.2 | +62.7%
(4 rows)
DB size: 59.3..64.5 (+5.2GB / +8.8%)
Patched
-------
relname | nrows | blk_before | mb_before | blk_after |
mb_after | diff
-----------------------+-----------+------------+-----------+-----------+----------+--------
pgbench_accounts | 300000000 | 4918033 | 38422.1 | 5068092 |
39594.5 | +3.0%
accounts_mtime | 300000000 | 1155119 | 9024.4 | 1428972 |
11163.8 | +23.7%
pgbench_accounts_pkey | 300000000 | 822573 | 6426.4 | 822573 |
6426.4 | 0
tenner | 300000000 | 346050 | 2703.5 | 346050 |
2703.5 | 0
(4 rows)
DB size: 59.3..62.8 (+3.5GB / +5.9%)
TPS
---
query | Master TPS | Patched TPS | diff
----------------+------------+-------------+-------
UPDATE + SELECT | 2413 | 2473 | +2.5%
3 SELECT in txn | 19737 | 19545 | -0.9%
15min SELECT | 0.74 | 1.03 | +39%
Based on the figures and also on the graphs attached, I can tell v8 has no
visible regression
in terms of TPS, IO pattern changes slightly, but the end result is worth
it.
In my view, this patch can be applied from a performance POV.
I wanted to share these before I'll finish with the code review, I'm
planning to send it tomorrow.
--
Victor Yegorov
scaling factor: 3000
query mode: simple
number of clients: 8
number of threads: 2
duration: 28800 s
number of transactions actually processed: 69500073
latency average = 3.315 ms
tps = 2413.196788 (including connections establishing)
tps = 2413.196914 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.000 \set delta random(-5000, 5000)
0.044 BEGIN;
0.275 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
0.146 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
2.846 END;
scaling factor: 3000
query mode: simple
number of clients: 8
number of threads: 2
duration: 28800 s
number of transactions actually processed: 568423448
latency average = 0.405 ms
tps = 19736.925054 (including connections establishing)
tps = 19736.926125 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.000 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 3.2)
0.032 BEGIN;
0.113 SELECT abalance FROM pgbench_accounts WHERE aid = :aid1;
0.110 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.108 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.037 END;
scaling factor: 3000
query mode: simple
number of clients: 8
number of threads: 2
duration: 28800 s
number of transactions actually processed: 21258
latency average = 10838.799 ms
tps = 0.738089 (including connections establishing)
tps = 0.738089 (excluding connections establishing)
statement latencies in milliseconds:
10838.685 SELECT abalance FROM pgbench_accounts WHERE mtime > now() - INTERVAL '15min' ORDER BY aid;
scaling factor: 3000
query mode: simple
number of clients: 8
number of threads: 2
duration: 28800 s
number of transactions actually processed: 71221374
latency average = 3.235 ms
tps = 2472.964179 (including connections establishing)
tps = 2472.964309 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.000 \set delta random(-5000, 5000)
0.044 BEGIN;
0.280 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
0.149 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
2.758 END;
scaling factor: 3000
query mode: simple
number of clients: 8
number of threads: 2
duration: 28800 s
number of transactions actually processed: 562888005
latency average = 0.409 ms
tps = 19544.722130 (including connections establishing)
tps = 19544.723213 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 3.2)
0.033 BEGIN;
0.115 SELECT abalance FROM pgbench_accounts WHERE aid = :aid1;
0.111 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.109 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.037 END;
scaling factor: 3000
query mode: simple
number of clients: 8
number of threads: 2
duration: 28800 s
number of transactions actually processed: 29715
latency average = 7754.629 ms
tps = 1.031642 (including connections establishing)
tps = 1.031642 (excluding connections establishing)
statement latencies in milliseconds:
7754.543 SELECT abalance FROM pgbench_accounts WHERE mtime > now() - INTERVAL '15min' ORDER BY aid;
Attachments:
[text/plain] 20201114-results-master.txt (1.9K, ../../CAGnEbohYF_K6b0v=2uc289=v67qNhc3n01Ftic8X94zP7kKqtw@mail.gmail.com/3-20201114-results-master.txt)
download | inline:
scaling factor: 3000
query mode: simple
number of clients: 8
number of threads: 2
duration: 28800 s
number of transactions actually processed: 69500073
latency average = 3.315 ms
tps = 2413.196788 (including connections establishing)
tps = 2413.196914 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.000 \set delta random(-5000, 5000)
0.044 BEGIN;
0.275 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
0.146 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
2.846 END;
scaling factor: 3000
query mode: simple
number of clients: 8
number of threads: 2
duration: 28800 s
number of transactions actually processed: 568423448
latency average = 0.405 ms
tps = 19736.925054 (including connections establishing)
tps = 19736.926125 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.000 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 3.2)
0.032 BEGIN;
0.113 SELECT abalance FROM pgbench_accounts WHERE aid = :aid1;
0.110 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.108 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.037 END;
scaling factor: 3000
query mode: simple
number of clients: 8
number of threads: 2
duration: 28800 s
number of transactions actually processed: 21258
latency average = 10838.799 ms
tps = 0.738089 (including connections establishing)
tps = 0.738089 (excluding connections establishing)
statement latencies in milliseconds:
10838.685 SELECT abalance FROM pgbench_accounts WHERE mtime > now() - INTERVAL '15min' ORDER BY aid;
[image/png] 20201114-q1-UPDATE-master.png (408.5K, ../../CAGnEbohYF_K6b0v=2uc289=v67qNhc3n01Ftic8X94zP7kKqtw@mail.gmail.com/4-20201114-q1-UPDATE-master.png)
download | view image
[image/png] 20201114-q2-SELECT-master.png (340.5K, ../../CAGnEbohYF_K6b0v=2uc289=v67qNhc3n01Ftic8X94zP7kKqtw@mail.gmail.com/5-20201114-q2-SELECT-master.png)
download | view image
[image/png] 20201114-q3-15min-SELECT-master.png (345.5K, ../../CAGnEbohYF_K6b0v=2uc289=v67qNhc3n01Ftic8X94zP7kKqtw@mail.gmail.com/6-20201114-q3-15min-SELECT-master.png)
download | view image
[image/png] 20201114-overview-master.png (526.2K, ../../CAGnEbohYF_K6b0v=2uc289=v67qNhc3n01Ftic8X94zP7kKqtw@mail.gmail.com/7-20201114-overview-master.png)
download | view image
[image/png] 20201114-q1-UPDATE-v8.png (381.6K, ../../CAGnEbohYF_K6b0v=2uc289=v67qNhc3n01Ftic8X94zP7kKqtw@mail.gmail.com/8-20201114-q1-UPDATE-v8.png)
download | view image
[image/png] 20201114-q2-SELECT-v8.png (312.3K, ../../CAGnEbohYF_K6b0v=2uc289=v67qNhc3n01Ftic8X94zP7kKqtw@mail.gmail.com/9-20201114-q2-SELECT-v8.png)
download | view image
[image/png] 20201114-q3-15min-SELECT-v8.png (344.9K, ../../CAGnEbohYF_K6b0v=2uc289=v67qNhc3n01Ftic8X94zP7kKqtw@mail.gmail.com/10-20201114-q3-15min-SELECT-v8.png)
download | view image
[image/png] 20201114-overview-v8.png (519.6K, ../../CAGnEbohYF_K6b0v=2uc289=v67qNhc3n01Ftic8X94zP7kKqtw@mail.gmail.com/11-20201114-overview-v8.png)
download | view image
[text/plain] 20201114-results-patched.txt (1.9K, ../../CAGnEbohYF_K6b0v=2uc289=v67qNhc3n01Ftic8X94zP7kKqtw@mail.gmail.com/12-20201114-results-patched.txt)
download | inline:
scaling factor: 3000
query mode: simple
number of clients: 8
number of threads: 2
duration: 28800 s
number of transactions actually processed: 71221374
latency average = 3.235 ms
tps = 2472.964179 (including connections establishing)
tps = 2472.964309 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.000 \set delta random(-5000, 5000)
0.044 BEGIN;
0.280 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid1;
0.149 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
2.758 END;
scaling factor: 3000
query mode: simple
number of clients: 8
number of threads: 2
duration: 28800 s
number of transactions actually processed: 562888005
latency average = 0.409 ms
tps = 19544.722130 (including connections establishing)
tps = 19544.723213 (excluding connections establishing)
statement latencies in milliseconds:
0.001 \set aid1 random_gaussian(1, 100000 * :scale, 2.0)
0.001 \set aid2 random_gaussian(1, 100000 * :scale, 2.5)
0.001 \set aid3 random_gaussian(1, 100000 * :scale, 3.2)
0.033 BEGIN;
0.115 SELECT abalance FROM pgbench_accounts WHERE aid = :aid1;
0.111 SELECT abalance FROM pgbench_accounts WHERE aid = :aid2;
0.109 SELECT abalance FROM pgbench_accounts WHERE aid = :aid3;
0.037 END;
scaling factor: 3000
query mode: simple
number of clients: 8
number of threads: 2
duration: 28800 s
number of transactions actually processed: 29715
latency average = 7754.629 ms
tps = 1.031642 (including connections establishing)
tps = 1.031642 (excluding connections establishing)
statement latencies in milliseconds:
7754.543 SELECT abalance FROM pgbench_accounts WHERE mtime > now() - INTERVAL '15min' ORDER BY aid;
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 20:58 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 23:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-15 22:29 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
@ 2020-11-17 04:59 ` Peter Geoghegan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-11-17 04:59 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Sun, Nov 15, 2020 at 2:29 PM Victor Yegorov <[email protected]> wrote:
> TPS
> ---
> query | Master TPS | Patched TPS | diff
> ----------------+------------+-------------+-------
> UPDATE + SELECT | 2413 | 2473 | +2.5%
> 3 SELECT in txn | 19737 | 19545 | -0.9%
> 15min SELECT | 0.74 | 1.03 | +39%
>
> Based on the figures and also on the graphs attached, I can tell v8 has no visible regression
> in terms of TPS, IO pattern changes slightly, but the end result is worth it.
> In my view, this patch can be applied from a performance POV.
Great, thanks for testing!
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 20:58 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 23:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-11-17 15:24 ` Victor Yegorov <[email protected]>
2020-11-17 20:45 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2 siblings, 1 reply; 1661+ messages in thread
From: Victor Yegorov @ 2020-11-17 15:24 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
пт, 13 нояб. 2020 г. в 00:01, Peter Geoghegan <[email protected]>:
> Attached is v8, which has the enhancements for low cardinality data
> that I mentioned earlier today. It also simplifies the logic for
> dealing with posting lists that we need to delete some TIDs from.
> These posting list simplifications also make the code a bit more
> efficient, which might be noticeable during benchmarking.
>
I've looked through the code and it looks very good from my end:
- plenty comments, good description of what's going on
- I found no loose ends in terms of AM integration
- magic constants replaced with defines
Code looks good. Still, it'd be good if somebody with more experience could
look into this patch.
Question: why in the comments you're using double spaces after dots?
Is this a convention of the project?
I am thinking of two more scenarios that require testing:
- queue in the table, with a high rate of INSERTs+DELETEs and a long
transaction.
Currently I've seen such conditions yield indexes of several GB in size
wil holding less
than a thousand of live records.
- upgraded cluster with !heapkeyspace indexes.
--
Victor Yegorov
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 20:58 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 23:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-17 15:24 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
@ 2020-11-17 20:45 ` Peter Geoghegan <[email protected]>
2020-11-25 04:35 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
0 siblings, 1 reply; 1661+ messages in thread
From: Peter Geoghegan @ 2020-11-17 20:45 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Tue, Nov 17, 2020 at 7:24 AM Victor Yegorov <[email protected]> wrote:
> I've looked through the code and it looks very good from my end:
> - plenty comments, good description of what's going on
> - I found no loose ends in terms of AM integration
> - magic constants replaced with defines
> Code looks good. Still, it'd be good if somebody with more experience could look into this patch.
Great, thank you.
> Question: why in the comments you're using double spaces after dots?
> Is this a convention of the project?
Not really. It's based on my habit of trying to be as consistent as
possible with existing code.
There seems to be a weak consensus among English speakers on this
question, which is: the two space convention is antiquated, and only
ever made sense in the era of mechanical typewriters. I don't really
care either way, and I doubt that any other committer pays much
attention to these things. You may have noticed that I use only one
space in my e-mails.
Actually, I probably shouldn't care about it myself. It's just what I
decided to do at some point. I find it useful to decide that this or
that practice is now a best practice, and then stick to it without
thinking about it very much (this frees up space in my head to think
about more important things). But this particular habit of mine around
spaces is definitely not something I'd insist on from other
contributors. It's just that: a habit.
> I am thinking of two more scenarios that require testing:
> - queue in the table, with a high rate of INSERTs+DELETEs and a long transaction.
I see your point. This is going to be hard to make work outside of
unique indexes, though. Unique indexes are already not dependent on
the executor hint -- they can just use the "uniquedup" hint. The code
for unique indexes is prepared to notice duplicates in
_bt_check_unique() in passing, and apply the optimization for that
reason.
Maybe there is some argument to forgetting about the hint entirely,
and always assuming that we should try to find tuples to delete at the
point that a page is about to be split. I think that that argument is
a lot harder to make, though. And it can be revisited in the future.
It would be nice to do better with INSERTs+DELETEs, but that's surely
not the big problem for us right now.
I realize that this unique indexes/_bt_check_unique() thing is not
even really a partial fix to the problem you describe. The indexes
that have real problems with such an INSERTs+DELETEs workload will
naturally not be unique indexes -- _bt_check_unique() already does a
fairly good job of controlling bloat without bottom-up deletion.
> - upgraded cluster with !heapkeyspace indexes.
I do have a patch that makes that easy to test, that I used for the
Postgres 13 deduplication work -- I can rebase it and post it if you
like. You will be able to apply the patch, and run the regression
tests with a !heapkeyspace index. This works with only one or two
tweaks to the tests (IIRC the amcheck tests need to be tweaked in one
place for this to work). I don't anticipate that !heapkeyspace indexes
will be a problem, because they won't use any of the new stuff anyway,
and because nothing about the on-disk format is changed by bottom-up
index deletion.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 20:58 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 23:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-17 15:24 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-17 20:45 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-11-25 04:35 ` Peter Geoghegan <[email protected]>
2020-11-25 12:43 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
0 siblings, 1 reply; 1661+ messages in thread
From: Peter Geoghegan @ 2020-11-25 04:35 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Tue, Nov 17, 2020 at 12:45 PM Peter Geoghegan <[email protected]> wrote:
> > I am thinking of two more scenarios that require testing:
> > - queue in the table, with a high rate of INSERTs+DELETEs and a long transaction.
>
> I see your point. This is going to be hard to make work outside of
> unique indexes, though. Unique indexes are already not dependent on
> the executor hint -- they can just use the "uniquedup" hint. The code
> for unique indexes is prepared to notice duplicates in
> _bt_check_unique() in passing, and apply the optimization for that
> reason.
I thought about this some more. My first idea was to simply always try
out bottom-up deletion (i.e. behave as if the hint from the executor
always indicates that it's favorable). I couldn't really justify that
approach, though. It results in many bottom-up deletion passes that
end up wasting cycles (and unnecessarily accessing heap blocks).
Then I had a much better idea: Make the existing LP_DEAD stuff a
little more like bottom-up index deletion. We usually have to access
heap blocks that the index tuples point to today, in order to have a
latestRemovedXid cutoff (to generate recovery conflicts). It's worth
scanning the leaf page for index tuples with TIDs whose heap block
matches the index tuples that actually have their LP_DEAD bits set.
This only consumes a few more CPU cycles. We don't have to access any
more heap blocks to try these extra TIDs, so it seems like a very good
idea to try them out.
I ran the regression tests with an enhanced version of the patch, with
this LP_DEAD-deletion-with-extra-TIDs thing. It also had custom
instrumentation that showed exactly what happens in each case. We
manage to delete at least a small number of extra index tuples in
almost all cases -- so we get some benefit in practically all cases.
And in the majority of cases we can delete significantly more. It's
not uncommon to increase the number of index tuples deleted. It could
go from 1 - 10 or so without the enhancement to LP_DEAD deletion, to
50 - 250 with the LP_DEAD enhancement. Some individual LP_DEAD
deletion calls can free more than 50% of the space on the leaf page.
I believe that this is a lower risk way of doing better when there is
a high rate of INSERTs+DELETEs. Most of the regression test cases I
looked at were in the larger system catalog indexes, which often look
like that.
We don't have to be that lucky for a passing index scan to set at
least one or two LP_DEAD bits. If there is any kind of
physical/logical correlation, then we're bound to also end up deleting
some extra index tuples by the time that the page looks like it might
need to be split.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 20:58 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 23:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-17 15:24 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-17 20:45 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-25 04:35 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-11-25 12:43 ` Victor Yegorov <[email protected]>
2020-11-25 18:41 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
0 siblings, 1 reply; 1661+ messages in thread
From: Victor Yegorov @ 2020-11-25 12:43 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
ср, 25 нояб. 2020 г. в 05:35, Peter Geoghegan <[email protected]>:
> Then I had a much better idea: Make the existing LP_DEAD stuff a
> little more like bottom-up index deletion. We usually have to access
> heap blocks that the index tuples point to today, in order to have a
> latestRemovedXid cutoff (to generate recovery conflicts). It's worth
> scanning the leaf page for index tuples with TIDs whose heap block
> matches the index tuples that actually have their LP_DEAD bits set.
> This only consumes a few more CPU cycles. We don't have to access any
> more heap blocks to try these extra TIDs, so it seems like a very good
> idea to try them out.
>
I don't seem to understand this.
Is it: we're scanning the leaf page for all LP_DEAD tuples that point to
the same
heap block? Which heap block we're talking about here, the one that holds
entry we're about to add (the one that triggered bottom-up-deletion due to
lack
of space I mean)?
I ran the regression tests with an enhanced version of the patch, with
> this LP_DEAD-deletion-with-extra-TIDs thing. It also had custom
> instrumentation that showed exactly what happens in each case. We
> manage to delete at least a small number of extra index tuples in
> almost all cases -- so we get some benefit in practically all cases.
> And in the majority of cases we can delete significantly more. It's
> not uncommon to increase the number of index tuples deleted. It could
> go from 1 - 10 or so without the enhancement to LP_DEAD deletion, to
> 50 - 250 with the LP_DEAD enhancement. Some individual LP_DEAD
> deletion calls can free more than 50% of the space on the leaf page.
>
I am missing a general perspective here.
Is it true, that despite the long (vacuum preventing) transaction we can
re-use space,
as after the DELETE statements commits, IndexScans are setting LP_DEAD
hints after
they check the state of the corresponding heap tuple?
If my thinking is correct for both cases — nature of LP_DEAD hint bits and
the mechanics of
suggested optimization — then I consider this a very promising improvement!
I haven't done any testing so far since sending my last e-mail.
If you'll have a chance to send a new v10 version with
LP_DEAD-deletion-with-extra-TIDs thing,
I will do some tests (planned).
--
Victor Yegorov
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 20:58 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 23:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-17 15:24 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-17 20:45 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-25 04:35 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-25 12:43 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
@ 2020-11-25 18:41 ` Peter Geoghegan <[email protected]>
2020-11-25 21:20 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-30 19:50 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
0 siblings, 2 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-11-25 18:41 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Wed, Nov 25, 2020 at 4:43 AM Victor Yegorov <[email protected]> wrote:
>> Then I had a much better idea: Make the existing LP_DEAD stuff a
>> little more like bottom-up index deletion. We usually have to access
>> heap blocks that the index tuples point to today, in order to have a
>> latestRemovedXid cutoff (to generate recovery conflicts). It's worth
>> scanning the leaf page for index tuples with TIDs whose heap block
>> matches the index tuples that actually have their LP_DEAD bits set.
>> This only consumes a few more CPU cycles. We don't have to access any
>> more heap blocks to try these extra TIDs, so it seems like a very good
>> idea to try them out.
>
>
> I don't seem to understand this.
>
> Is it: we're scanning the leaf page for all LP_DEAD tuples that point to the same
> heap block? Which heap block we're talking about here, the one that holds
> entry we're about to add (the one that triggered bottom-up-deletion due to lack
> of space I mean)?
No, the incoming tuple isn't significant.
As you know, bottom-up index deletion uses heuristics that are
concerned with duplicates on the page, and the "logically unchanged by
an UPDATE" hint that the executor passes to btinsert(). Bottom-up
deletion runs when all LP_DEAD bits have been cleared (either because
there never were any LP_DEAD bits set, or because they were set and
then deleted, which wasn't enough).
But before bottom-up deletion may run, traditional deletion of LP_DEAD
index tuples runs -- this is always our preferred strategy because
index tuples with their LP_DEAD bits set are already known to be
deletable. We can make this existing process (which has been around
since PostgreSQL 8.2) better by applying similar principles.
We have promising tuples for bottom-up deletion. Why not have
"promising heap blocks" for traditional LP_DEAD index tuple deletion?
Or if you prefer, we can consider index tuples that *don't* have their
LP_DEAD bits set already but happen to point to the *same heap block*
as other tuples that *do* have their LP_DEAD bits set promising. (The
tuples with their LP_DEAD bits set are not just promising -- they're
already a sure thing.)
This means that traditional LP_DEAD deletion is now slightly more
speculative in one way (it speculates about what is likely to be true
using heuristics). But it's much less speculative than bottom-up index
deletion. We are required to visit these heap blocks anyway, since a
call to _bt_delitems_delete() for LP_DEAD deletion must already call
table_compute_xid_horizon_for_tuples(), which has to access the blocks
to get a latestRemovedXid for the WAL record.
The only thing that we have to lose here is a few CPU cycles to find
extra TIDs to consider. We'll visit exactly the same number of heap
blocks as before. (Actually, _bt_delitems_delete() does not have to do
that in all cases, actually, but it has to do it with a logged table
with wal_level >= replica, which is the vast majority of cases in
practice.)
This means that traditional LP_DEAD deletion reuses some of the
bottom-up index deletion infrastructure. So maybe nbtree never calls
table_compute_xid_horizon_for_tuples() now, since everything goes
through the new heapam stuff instead (which knows how to check extra
TIDs that might not be dead at all).
> I am missing a general perspective here.
>
> Is it true, that despite the long (vacuum preventing) transaction we can re-use space,
> as after the DELETE statements commits, IndexScans are setting LP_DEAD hints after
> they check the state of the corresponding heap tuple?
The enhancement to traditional LP_DEAD deletion that I just described
does not affect the current restrictions on setting LP_DEAD bits in
the presence of a long-running transaction, or anything like that.
That seems like an unrelated project. The value of this enhancement is
purely its ability to delete *extra* index tuples that could have had
their LP_DEAD bits set already (it was possible in principle), but
didn't. And only when they are nearby to index tuples that really do
have their LP_DEAD bits set.
> I haven't done any testing so far since sending my last e-mail.
> If you'll have a chance to send a new v10 version with LP_DEAD-deletion-with-extra-TIDs thing,
> I will do some tests (planned).
Thanks! I think that it will be next week. It's a relatively big change.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 20:58 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 23:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-17 15:24 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-17 20:45 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-25 04:35 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-25 12:43 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-25 18:41 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-11-25 21:20 ` Victor Yegorov <[email protected]>
2020-11-26 01:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
1 sibling, 1 reply; 1661+ messages in thread
From: Victor Yegorov @ 2020-11-25 21:20 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
ср, 25 нояб. 2020 г. в 19:41, Peter Geoghegan <[email protected]>:
> We have promising tuples for bottom-up deletion. Why not have
> "promising heap blocks" for traditional LP_DEAD index tuple deletion?
> Or if you prefer, we can consider index tuples that *don't* have their
> LP_DEAD bits set already but happen to point to the *same heap block*
> as other tuples that *do* have their LP_DEAD bits set promising. (The
> tuples with their LP_DEAD bits set are not just promising -- they're
> already a sure thing.)
>
In the _bt_delete_or_dedup_one_page() we start with the simple loop over
items on the page and
if there're any LP_DEAD tuples, we're kicking off _bt_delitems_delete().
So if I understood you right, you plan to make this loop (or a similar one
somewhere around)
to track TIDs of the LP_DEAD tuples and then (perhaps on a second loop over
the page) compare all other
currently-not-LP_DEAD tuples and mark those pages, that have at least 2
TIDs pointing at (one LP_DEAD and other not)
as a promising one.
Later, should we require to kick deduplication, we'll go visit promising
pages first.
Is my understanding correct?
> I am missing a general perspective here.
> >
> > Is it true, that despite the long (vacuum preventing) transaction we can
> re-use space,
> > as after the DELETE statements commits, IndexScans are setting LP_DEAD
> hints after
> > they check the state of the corresponding heap tuple?
>
> The enhancement to traditional LP_DEAD deletion that I just described
> does not affect the current restrictions on setting LP_DEAD bits in
> the presence of a long-running transaction, or anything like that.
> That seems like an unrelated project. The value of this enhancement is
> purely its ability to delete *extra* index tuples that could have had
> their LP_DEAD bits set already (it was possible in principle), but
> didn't. And only when they are nearby to index tuples that really do
> have their LP_DEAD bits set.
>
I wasn't considering improvements here, that was a general question about
how this works
(trying to clear up gaps in my understanding).
What I meant to ask — will LP_DEAD be set by IndexScan in the presence of
the long transaction?
--
Victor Yegorov
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 20:58 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 23:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-17 15:24 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-17 20:45 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-25 04:35 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-25 12:43 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-25 18:41 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-25 21:20 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
@ 2020-11-26 01:00 ` Peter Geoghegan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-11-26 01:00 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Wed, Nov 25, 2020 at 1:20 PM Victor Yegorov <[email protected]> wrote:
> In the _bt_delete_or_dedup_one_page() we start with the simple loop over items on the page and
> if there're any LP_DEAD tuples, we're kicking off _bt_delitems_delete().
Right.
> So if I understood you right, you plan to make this loop (or a similar one somewhere around)
> to track TIDs of the LP_DEAD tuples and then (perhaps on a second loop over the page) compare all other
> currently-not-LP_DEAD tuples and mark those pages, that have at least 2 TIDs pointing at (one LP_DEAD and other not)
> as a promising one.
Yes. We notice extra TIDs that can be included in our heapam test "for
free". The cost is low, but the benefits are also often quite high: in
practice there are *natural* correlations that we can exploit.
For example: maybe there were non-HOT updates, and some but not all of
the versions got marked LP_DEAD. We can get them all in one go,
avoiding a true bottom-up index deletion pass for much longer
(compared to doing LP_DEAD deletion the old way, which is what happens
in v9 of the patch). We're better off doing the deletions all at once.
It's cheaper.
(We still really need to have bottom-up deletion passes, of course,
because that covers the important case where there are no LP_DEAD bits
set at all, which is an important goal of this project.)
Minor note: Technically there aren't any promising tuples involved,
because that only makes sense when we are not going to visit every
possible heap page (just the "most promising" heap pages). But we are
going to visit every possible heap page with the new LP_DEAD bit
deletion code (which could occasionally mean visiting 10 or more heap
pages, which is a lot more than bottom-up index deletion will ever
visit). All we need to do with the new LP_DEAD deletion logic is to
include all possible matching TIDs (not just those that are marked
LP_DEAD already).
> What I meant to ask — will LP_DEAD be set by IndexScan in the presence of the long transaction?
That works in the same way as before, even with the new LP_DEAD
deletion code. The new code uses the same information as before (set
LP_DEAD bits), which is generated in the same way as before. The
difference is in how the information is actually used during LP_DEAD
deletion -- we can now delete some extra things in certain common
cases.
In practice this (and bottom-up deletion) make nbtree more robust
against disruption caused by long running transactions that hold a
snapshot open. It's hard to give a simple explanation of why that is,
because it's a second order effect. The patch is going to make it
possible to recover when LP_DEAD bits suddenly stop being set because
of an old snapshot -- now we'll have a "second chance", and maybe even
a third chance. But if the snapshot is held open *forever*, then a
second chance has no value.
Here is a thought experiment that might be helpful:
Imagine Postgres just as it is today (without the patch), except that
VACUUM runs very frequently, and is infinitely fast (this is a magical
version of VACUUM). This solves many problems, but does not solve all
problems. Magic Postgres will become just as slow as earthly Postgres
when there is a snapshot that is held open for a very long time. That
will take longer to happen compared to earthly/mortal Postgres, but
eventually there will be no difference between the two at all. But,
when you don't have such an extreme problem, magic Postgres really is
much faster.
I think that it will be possible to approximate the behavior of magic
Postgres using techniques like bottom-up deletion, the new LP_DEAD
deletion thing we've been talking today, and maybe other enhancements
in other areas (like in heap pruning). It doesn't matter that we don't
physically remove garbage immediately, as long as we "logically"
remove it immediately. The actually physical removal can occur in a
just in time, incremental fashion, creating the illusion that VACUUM
really does run infinitely fast. No magic required.
Actually, in a way this isn't new; we have always "logically" removed
garbage at the earliest opportunity (by which I mean we allow that it
can be physically removed according to an oldestXmin style cutoff,
which can be reacquired/updated the second the oldest MVCC snapshot
goes away). We don't think of useless old versions as being "logically
removed" the instant an old snapshot goes away. But maybe we should --
it's a useful mental model.
It will also be very helpful to add "remove useless intermediate
versions" logic at some point. This is quite a distinct area to what I
just described, but it's also important. We need both, I think.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Re: Deleting older versions in unique indexes to avoid page splits Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-22 17:42 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-23 17:13 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Re: Deleting older versions in unique indexes to avoid page splits Simon Riggs <[email protected]>
2020-10-24 15:01 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-11 20:58 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-12 23:00 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-17 15:24 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-17 20:45 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-25 04:35 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-11-25 12:43 ` Re: Deleting older versions in unique indexes to avoid page splits Victor Yegorov <[email protected]>
2020-11-25 18:41 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-11-30 19:50 ` Peter Geoghegan <[email protected]>
1 sibling, 0 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-11-30 19:50 UTC (permalink / raw)
To: Victor Yegorov <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Wed, Nov 25, 2020 at 10:41 AM Peter Geoghegan <[email protected]> wrote:
> We have promising tuples for bottom-up deletion. Why not have
> "promising heap blocks" for traditional LP_DEAD index tuple deletion?
> Or if you prefer, we can consider index tuples that *don't* have their
> LP_DEAD bits set already but happen to point to the *same heap block*
> as other tuples that *do* have their LP_DEAD bits set promising. (The
> tuples with their LP_DEAD bits set are not just promising -- they're
> already a sure thing.)
>
> This means that traditional LP_DEAD deletion is now slightly more
> speculative in one way (it speculates about what is likely to be true
> using heuristics). But it's much less speculative than bottom-up index
> deletion. We are required to visit these heap blocks anyway, since a
> call to _bt_delitems_delete() for LP_DEAD deletion must already call
> table_compute_xid_horizon_for_tuples(), which has to access the blocks
> to get a latestRemovedXid for the WAL record.
>
> The only thing that we have to lose here is a few CPU cycles to find
> extra TIDs to consider. We'll visit exactly the same number of heap
> blocks as before. (Actually, _bt_delitems_delete() does not have to do
> that in all cases, actually, but it has to do it with a logged table
> with wal_level >= replica, which is the vast majority of cases in
> practice.)
>
> This means that traditional LP_DEAD deletion reuses some of the
> bottom-up index deletion infrastructure. So maybe nbtree never calls
> table_compute_xid_horizon_for_tuples() now, since everything goes
> through the new heapam stuff instead (which knows how to check extra
> TIDs that might not be dead at all).
Attached is v10, which has this LP_DEAD deletion enhancement I
described. (It also fixed bitrot -- v9 no longer applies.)
This revision does a little refactoring to make this possible. Now
there is less new code in nbtdedup.c, and more code in nbtpage.c,
because some of the logic used by bottom-up deletion has been
generalized (in order to be used by the new-to-v10 LP_DEAD deletion
enhancement).
Other than that, no big changes between this v10 and v9. Just
polishing and refactoring. I decided to make it mandatory for tableams
to support the new interface that heapam implements, since it's hardly
okay for them to not allow LP_DEAD deletion in nbtree (which is what
making supporting the interface optional would imply, given the
LP_DEAD changes). So now the heapam and tableam changes are including
in one patch/commit, which is to be applied first among patches in the
series.
--
Peter Geoghegan
Attachments:
[application/octet-stream] v10-0001-Teach-heapam-to-support-bottom-up-index-deletion.patch (34.2K, ../../CAH2-WzmX21q+en6g0aH4VfUCNk+QODWA6hrqhga0Ym06tHiHgA@mail.gmail.com/2-v10-0001-Teach-heapam-to-support-bottom-up-index-deletion.patch)
download | inline diff:
From ba9e0be13c2573b63639452ababcd0116d2674be Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Mon, 9 Nov 2020 12:59:29 -0800
Subject: [PATCH v10 1/3] Teach heapam to support bottom-up index deletion.
Teach heapam about bottom-up index deletion. This mechanism allows an
index AM to cooperate with a tableam in deleting index tuples at regular
intervals. The general idea is to avoid accumulating too many versions
in the index for any given logically row, without doing any extra work
before the situation gets out of hand at a localized page in an index.
This commit isn't useful on its own. An upcoming commit will add
support to nbtree.
Author: Peter Geoghegan <[email protected]>
Reviewed-By: Victor Yegorov <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wzm+maE3apHB8NOtmM=p-DO65j2V5GzAWCOEEuy3JZgb2g@mail.gmail.com
---
src/include/access/heapam.h | 2 +
src/include/access/tableam.h | 113 ++++
src/backend/access/heap/heapam.c | 660 +++++++++++++++++++++++
src/backend/access/heap/heapam_handler.c | 1 +
src/backend/access/table/tableam.c | 6 +-
5 files changed, 779 insertions(+), 3 deletions(-)
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 54b2eb7378..289d0ca5c6 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -169,6 +169,8 @@ extern void simple_heap_update(Relation relation, ItemPointer otid,
extern TransactionId heap_compute_xid_horizon_for_tuples(Relation rel,
ItemPointerData *items,
int nitems);
+extern TransactionId heapam_index_delete_check(Relation rel,
+ TM_IndexDeleteOp *delstate);
/* in heap/pruneheap.c */
struct GlobalVisState;
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index 387eb34a61..998f8b2996 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -128,6 +128,99 @@ typedef struct TM_FailureData
bool traversed;
} TM_FailureData;
+/*
+ * State used when calling table_index_delete_check() to perform "bottom up"
+ * deletion of duplicate index tuples. State is intialized by index AM
+ * caller, while state is finalized by tableam, which modifies state.
+ */
+typedef struct TM_IndexDelete
+{
+ ItemPointerData tid; /* table TID from index tuple */
+ int16 id; /* Offset into TM_IndexStatus array */
+} TM_IndexDelete;
+
+typedef struct TM_IndexStatus
+{
+ OffsetNumber idxoffnum; /* Index am page offset number */
+ int16 tupsize; /* Space freed in index if tuple deleted */
+ bool ispromising; /* Duplicate in index? */
+ bool deleteitup; /* Known dead-to-all? */
+} TM_IndexStatus;
+
+/*
+ * State representing one single bottom-up index deletion operation.
+ *
+ * Index am caller provides a TM_IndexDeleteOp, which points to two palloc()'d
+ * arrays. Each array has one entry per TID that the tableam is asked to
+ * consider (typically these are all of the TIDs from a single index page, so
+ * there could be hundreds or even thousand of entries in arrays). ndeltids
+ * tracks the current number of entries. It is set by index AM initially, and
+ * generally modified by tableam (which conceptually shrinks the array for
+ * most calls).
+ *
+ * The two arrays are conceptually one single array. Two arrays/structs are
+ * used for performance reasons. (We really need to keep the TM_IndexDelete
+ * struct small so that the tableam can do an initial sort by TID as quickly
+ * as possible.)
+ *
+ * The index AM should keep track of which index tuple relates to which entry
+ * by setting idxoffnum (and/or relying on each entry being uniquely
+ * identifiable using tid). Index AM requests target free space indicated by
+ * "targetfreespace". Index AM also represents the space saving for each TID
+ * by filling in the tupsize for each array element. The tableam must balance
+ * the requirements of the index AM against the costs paid in the tableam.
+ *
+ * Callers that simply want the tableam to visit all the table blocks from any
+ * TIDs should set alltids = true. Callers that do that can initialize any
+ * field concerned with managing the cost of visiting table blocks to 0, since
+ * they won't be used at all.
+ *
+ * The index AM provides strong hints about where to look to the tableam by
+ * marking some entries as "promising". Index AM does this with duplicate
+ * index tuples that are strongly suspected to be old versions left behind by
+ * UPDATEs that did not logically changed any indexed values. Index AM may
+ * find it helpful to only mark TIDs/entries as promising when they're thought
+ * to have been affected by such an UPDATE in the recent past. Though none of
+ * this matters to alltids callers, since the tableam will be obligated to
+ * visit every table block anyway.
+ *
+ * The tableam marks individual entries as deletable for the index AM. It's
+ * common for the final array to be shrunk in size. The index AM caller
+ * should do nothing if on return delstate.ndeltids is found set to zero. The
+ * index AM caller only needs to consider the first ndeltids from the final
+ * array, which is typically much smaller than its original size (tableam
+ * updates ndeltids in state). One reason for this is that the tableam can
+ * naturally only afford to a few tableam blocks on each call -- it typically
+ * won't even try to check most of the entries from the tableam.
+ *
+ * Note that index AM caller can mark entries that are known dead-to-all as
+ * deletable up-front, saving the tableam a little work. This is only allowed
+ * for callers that specify alltids, though. The tableam will check entries
+ * that are initially marked !deleteitup on a best-effort basis (it should be
+ * able to process every entry for an alltids caller in practice, but that
+ * isn't actually a requirement).
+ *
+ * In general, tableams use significant discretion about how much
+ * non-essential work they perform during each !alltids call. However, the
+ * tableam is obligated to do whatever it must to make it safe for the index
+ * AM to perform deletion of entries that it marked deleteitup up-front. The
+ * tableam cannot opt out of facilitating deletion of index tuples that are
+ * already marked LP_DEAD in index (again, only relevant to alltids calls).
+ *
+ * The tableam typically sorts the delstate.deltids array by TID. The index
+ * AM should be prepared to restore the array to its useful/original order.
+ * The array is typically far smaller than its original size by then, so that
+ * step should be relatively fast.
+ */
+typedef struct TM_IndexDeleteOp
+{
+ bool alltids; /* tableam must visit all blocks? */
+ int ndeltids; /* Number of deltids/status for op */
+ TM_IndexDelete *deltids;
+ TM_IndexStatus *status;
+ int targetfreespace; /* Guides tableam on requirements */
+} TM_IndexDeleteOp;
+
/* "options" flag bits for table_tuple_insert */
/* TABLE_INSERT_SKIP_WAL was 0x0001; RelationNeedsWAL() now governs */
#define TABLE_INSERT_SKIP_FSM 0x0002
@@ -409,6 +502,10 @@ typedef struct TableAmRoutine
uint8 flags,
TM_FailureData *tmfd);
+ /* see table_index_delete_check() for reference about parameters */
+ TransactionId (*index_delete_check) (Relation rel,
+ TM_IndexDeleteOp *delstate);
+
/*
* Perform operations necessary to complete insertions made via
* tuple_insert and multi_insert with a BulkInsertState specified. In-tree
@@ -1363,6 +1460,22 @@ table_tuple_lock(Relation rel, ItemPointer tid, Snapshot snapshot,
flags, tmfd);
}
+/*
+ * Index tuple deletion check, for use by index AMs.
+ *
+ * Sets deletable tuples in entries from caller's TM_IndexDeleteOp state that
+ * are found to point to dead-to-all tuples in the table, rel. See the
+ * TM_IndexDeleteOp struct for full details.
+ *
+ * Returns a latestRemovedXid transaction ID that index AM must use to
+ * generate a recovery conflict when required.
+ */
+static inline TransactionId
+table_index_delete_check(Relation rel, TM_IndexDeleteOp *delstate)
+{
+ return rel->rd_tableam->index_delete_check(rel, delstate);
+}
+
/*
* Perform operations necessary to complete insertions made via
* tuple_insert and multi_insert with a BulkInsertState specified.
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 1b2f70499e..78a59fd0b4 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -55,6 +55,7 @@
#include "miscadmin.h"
#include "pgstat.h"
#include "port/atomics.h"
+#include "port/pg_bitutils.h"
#include "storage/bufmgr.h"
#include "storage/freespace.h"
#include "storage/lmgr.h"
@@ -102,6 +103,7 @@ static void MultiXactIdWait(MultiXactId multi, MultiXactStatus status, uint16 in
int *remaining);
static bool ConditionalMultiXactIdWait(MultiXactId multi, MultiXactStatus status,
uint16 infomask, Relation rel, int *remaining);
+static int heapam_index_delete_check_sort(Relation rel, TM_IndexDeleteOp *delstate);
static XLogRecPtr log_heap_new_cid(Relation relation, HeapTuple tup);
static HeapTuple ExtractReplicaIdentity(Relation rel, HeapTuple tup, bool key_changed,
bool *copy);
@@ -178,6 +180,17 @@ typedef struct
} XidHorizonPrefetchState;
#endif
+/*
+ * heapam_index_delete_check uses this structure to determine which heap pages
+ * to visit, and in what order
+ */
+typedef struct IndexDeleteCounts
+{
+ int16 npromisingtids;
+ int16 ntids;
+ int16 ideltids;
+} IndexDeleteCounts;
+
/*
* This table maps tuple lock strength values for each particular
* MultiXactStatus value.
@@ -192,6 +205,11 @@ static const int MultiXactStatusLock[MaxMultiXactStatus + 1] =
LockTupleExclusive /* Update */
};
+/*
+ * Shellsort gap sequence (taken from Sedgewick-Incerpi paper)
+ */
+static const int ShellsortGaps[8] = {861, 336, 112, 48, 21, 7, 3, 1};
+
/* Get the LockTupleMode for a given MultiXactStatus */
#define TUPLOCK_from_mxstatus(status) \
(MultiXactStatusLock[(status)])
@@ -6987,6 +7005,9 @@ xid_horizon_prefetch_buffer(Relation rel,
* deleting hundreds of tuples from a single index block. To amortize that
* cost to some degree, this uses prefetching and combines repeat accesses to
* the same block.
+ *
+ * Note: The logic for maintaining latestRemovedXid here is duplicated by code
+ * within heapam_index_delete_check(). Make sure that they stay in sync.
*/
TransactionId
heap_compute_xid_horizon_for_tuples(Relation rel,
@@ -7133,6 +7154,645 @@ heap_compute_xid_horizon_for_tuples(Relation rel,
return latestRemovedXid;
}
+#define MAX_DELETE_HEAP_BLOCKS 4
+#define FAVORABLE_BLOCK_STRIDE 3
+
+/*
+ * Determine which heap tuples from a list of TIDs provided by caller are
+ * dead. It is safe to delete index tuples that point to these dead heap
+ * tuples.
+ *
+ * This is used by index AMs that support "bottom up" deletion of duplicate
+ * index tuples in batches of just a few heap pages at a time. Index AMs call
+ * here through the table_index_delete_check() interface. See tableam
+ * interface details (for the TM_IndexDeleteOp struct) for more information.
+ *
+ * Alternatively, this can be used by callers that want a batch version of
+ * heap_compute_xid_horizon_for_tuples(). These callers (alltids callers) can
+ * expect us to access every heap page exhaustively. They can still expect us
+ * to mark some extra entries deletable. We check if not-marked-deletable
+ * entries are deleteable in passing, and mark them deletable if the check
+ * works out, as in the bottom-up deletion case.
+ *
+ * Though the main thing that influences which heap pages are accessed here
+ * (for alltids/bottom-up callers) is the presence of tuples that index AM
+ * caller has marked "promising" (which relate to duplicate index tuples
+ * believed to have been inserted in index recently), there are other
+ * considerations. The approach taken here considers both spatial and
+ * temporal locality inside the heap structure. This is especially helpful
+ * when there are several heap blocks with approximately the same amount of
+ * promising tuples. Multiple calls here for the same index will tend to
+ * consistently delete the oldest index tuples, which keeps the number of
+ * buffer misses here to a minimum.
+ *
+ * Sometimes larger batch sizes are preferred here, even when that means that
+ * we might actually exceed caller's immediate requirement for free space in
+ * the index. Contiguous heap blocks are considered "favorable". The
+ * presence of favorable blocks makes the call as a whole access more blocks
+ * to better amortize costs. We expect to be called multiple times for
+ * related records in at least some cases, and have to consider costs over
+ * time. The cost of any individual call is less important.
+ *
+ * Returns the latestRemovedXid from the heap tuples pointed to by index
+ * tuples whose deltids entries are marked safe to delete.
+ *
+ * Note: The logic for maintaining latestRemovedXid here is duplicated by code
+ * within heap_compute_xid_horizon_for_tuples(). Make sure that they stay in
+ * sync.
+ */
+TransactionId
+heapam_index_delete_check(Relation rel, TM_IndexDeleteOp *delstate)
+{
+ TransactionId latestRemovedXid = InvalidTransactionId;
+ BlockNumber hblkno = InvalidBlockNumber;
+ Buffer buf = InvalidBuffer;
+ Page hpage;
+ bool finalhpage = false;
+ int finalndeltids = 0;
+ int nblocksaccessed = 0;
+ int nblocksfavorable = 0;
+ int spacefreed = 0;
+ int spacefreedbeforecurhpage = 0;
+ SnapshotData SnapshotNonVacuumable;
+ TM_IndexDelete *deltids = delstate->deltids;
+ TM_IndexStatus *status = delstate->status;
+ int targetfreespace = delstate->targetfreespace;
+
+ InitNonVacuumableSnapshot(SnapshotNonVacuumable, GlobalVisTestFor(rel));
+
+ /*
+ * Sort and shrink deltids array so that it consists only of TIDs from
+ * just a few of the most promising blocks for !alltids callers. (Just
+ * sort by TID for an alltids caller.)
+ */
+ nblocksfavorable = heapam_index_delete_check_sort(rel, delstate);
+ for (int i = 0; i < delstate->ndeltids; i++)
+ {
+ TM_IndexStatus *dstatus = status + deltids[i].id;
+ ItemPointer htid = &deltids[i].tid;
+ ItemId hitemid;
+ OffsetNumber hoffnum;
+ HeapTupleData heapTuple;
+
+ /* Only alltids callers may mark entries as deleteitup themselves */
+ Assert(delstate->alltids || !dstatus->deleteitup);
+
+ if (hblkno == InvalidBlockNumber ||
+ ItemPointerGetBlockNumber(htid) != hblkno)
+ {
+ /*
+ * We usually do a little extra work on the final heap page after
+ * caller's target space to free has been reached. The cost of
+ * accessing the final heap page we'll need to visit has already
+ * been paid by that point. We finish off the entire final heap
+ * page because it's cheap to do so.
+ *
+ * We don't want to unnecessarily visit the next page in line.
+ * Handle that here (when we just finished final page).
+ */
+ if (finalhpage)
+ break;
+
+ /*
+ * Each time we're about to access a new page we consider if it's
+ * really worth it. We apply two tests before we visit the next
+ * page, and give up if either fails (when caller is an !alltids
+ * caller, also known as a bottom-up deletion caller):
+ *
+ * 1. Give up when we didn't enable our caller to free any
+ * additional space as a result of processing the most recent heap
+ * page visited. We expect to make steady progress or no
+ * progress.
+ *
+ * 2. Give up when MAX_DELETE_HEAP_BLOCKS have been accessed
+ * already, no matter what. (This is defensive, since the deltids
+ * array was shrunk before we started. It should now contain TIDs
+ * from pages not exceeding MAX_DELETE_HEAP_BLOCKS in number.)
+ */
+ if (!delstate->alltids)
+ {
+ if (nblocksaccessed >= 1 && spacefreed == spacefreedbeforecurhpage)
+ break;
+ if (nblocksaccessed == MAX_DELETE_HEAP_BLOCKS)
+ break;
+ }
+
+ /*
+ * After visiting and processing the first heap page, aggressively
+ * decay target space freed (the request from index AM caller)
+ * before accessing each new heap page (starting with the second
+ * in line). But only start decaying when we encounter our first
+ * non-favorable block.
+ *
+ * Favorable blocks are contiguous groups of heap blocks that are
+ * likely to have related heap tuples that are cheaper to process
+ * in larger batches. It doesn't make sense to be stingy here.
+ * The index AM may end up calling us about the same heap TIDs
+ * before much time has passed if we do that.
+ *
+ * Note that even favorable blocks are required to enable caller
+ * to free at least some space -- otherwise we give up before
+ * accessing the next block in line. If a favorable block cannot
+ * be freed then there is probably an old snapshot that frustrates
+ * progress here in general.
+ */
+ if (nblocksfavorable == 0)
+ {
+ targetfreespace /= 2;
+
+ /* Must always start out with at least 1 favorable block */
+ Assert(nblocksaccessed >= 1);
+ }
+
+ /* Now access next page */
+ if (BufferIsValid(buf))
+ {
+ LockBuffer(buf, BUFFER_LOCK_UNLOCK);
+ ReleaseBuffer(buf);
+ }
+
+ /*
+ * We could prune the heap page in passing here, but that doesn't
+ * seem like a good idea. (Index AM caller is expected to hold
+ * locks of its own.)
+ */
+ hblkno = ItemPointerGetBlockNumber(htid);
+ buf = ReadBuffer(rel, hblkno);
+ hpage = BufferGetPage(buf);
+ nblocksaccessed++;
+ if (nblocksfavorable > 0)
+ nblocksfavorable--;
+ spacefreedbeforecurhpage = spacefreed;
+
+ /* Need to lock buffer for visibility checks */
+ LockBuffer(buf, BUFFER_LOCK_SHARE);
+ }
+
+ if (!dstatus->deleteitup)
+ {
+ ItemPointerData tmp;
+ bool all_dead,
+ found;
+
+ tmp = *htid; /* Don't modify htid */
+ all_dead = false; /* Check that whole HOT chain is vacuumable */
+ found = heap_hot_search_buffer(&tmp, rel, buf,
+ &SnapshotNonVacuumable, &heapTuple,
+ &all_dead, true);
+
+ if (found || !all_dead)
+ continue;
+ }
+
+ /* Caller can delete this TID from index */
+ finalndeltids = i + 1;
+ dstatus->deleteitup = true;
+ spacefreed += dstatus->tupsize;
+
+ if (spacefreed >= targetfreespace && !delstate->alltids)
+ {
+ /*
+ * Caller's free space target has now been met (maybe...target may
+ * have decayed one or more times from original value if we
+ * weren't accessing favorable/contiguous blocks).
+ *
+ * Finish off the current/final heap page before finishing.
+ */
+ finalhpage = true;
+ }
+
+ /*
+ * One last step required for TID that caller will delete. Must
+ * maintain latestRemovedXid for caller's delete operation.
+ */
+ hoffnum = ItemPointerGetOffsetNumber(htid);
+ hitemid = PageGetItemId(hpage, hoffnum);
+
+ while (ItemIdIsRedirected(hitemid))
+ {
+ hoffnum = ItemIdGetRedirect(hitemid);
+ hitemid = PageGetItemId(hpage, hoffnum);
+ }
+
+ /*
+ * If the heap item has storage, then read the header and use that to
+ * set latestRemovedXid.
+ *
+ * Some LP_DEAD items may not be accessible, so we ignore them.
+ */
+ if (ItemIdHasStorage(hitemid))
+ {
+ HeapTupleHeader htuphdr;
+
+ htuphdr = (HeapTupleHeader) PageGetItem(hpage, hitemid);
+
+ HeapTupleHeaderAdvanceLatestRemovedXid(htuphdr, &latestRemovedXid);
+ }
+ else if (ItemIdIsDead(hitemid))
+ {
+ /*
+ * Conjecture: if hitemid is dead then it had xids before the xids
+ * marked on LP_NORMAL items. So we just ignore this item and move
+ * onto the next, for the purposes of calculating
+ * latestRemovedXid.
+ */
+ }
+ else
+ Assert(!ItemIdIsUsed(hitemid));
+ }
+
+ if (BufferIsValid(buf))
+ {
+ LockBuffer(buf, BUFFER_LOCK_UNLOCK);
+ ReleaseBuffer(buf);
+ }
+
+ /*
+ * If all heap tuples were LP_DEAD then we will be returning
+ * InvalidTransactionId here, which avoids conflicts. This matches
+ * existing logic which assumes that LP_DEAD tuples must already be older
+ * than the latestRemovedXid on the cleanup record that set them as
+ * LP_DEAD, hence must already have generated a conflict.
+ */
+ delstate->ndeltids = finalndeltids;
+
+ return latestRemovedXid;
+}
+
+/*
+ * Determine how many favorable blocks are among blocks we'll access (which
+ * have been sorted by heapam_index_delete_check_sort() by the time we get
+ * called). The exact approach taken by heapam_index_delete_check() is
+ * influenced by the number of favorable blocks.
+ *
+ * Returns number of favorable blocks, starting from (and including) the first
+ * block in line for processing.
+ *
+ * Favorable blocks are contiguous heap blocks, which are likely to have
+ * relatively many dead items. These blocks are cheaper to access together
+ * all at once. Having many favorable blocks is common with low cardinality
+ * index tuples, where heap locality has a relatively large influence on which
+ * heap blocks we visit (and the order they're processed in). Being more
+ * aggressive with favorable blocks is slightly more expensive in the short
+ * term, but less expensive across related heapam_index_delete_check() calls.
+ *
+ * Note: We always indicate that there is at least 1 favorable block (the
+ * first in line to process). The first block must always be in sorted order
+ * because the ordering is relative to the first block (or previous block).
+ * This degenerate case isn't a problem for heapam_index_delete_check(), which
+ * is supposed to always visit the first heap page in line, regardless of any
+ * other factor.
+ */
+static int
+top_block_groups_favorable(IndexDeleteCounts *blockcounts, int nblockgroups,
+ TM_IndexDelete *deltids)
+{
+ int nblocksfavorable = 0;
+ BlockNumber lastblock = InvalidBlockNumber;
+
+ for (int b = 0; b < nblockgroups; b++)
+ {
+ IndexDeleteCounts *blockgroup = blockcounts + b;
+ TM_IndexDelete *firstgroup = deltids + blockgroup->ideltids;
+ BlockNumber thisblock = ItemPointerGetBlockNumber(&firstgroup->tid);
+
+ if (BlockNumberIsValid(lastblock) &&
+ (thisblock < lastblock ||
+ thisblock > lastblock + FAVORABLE_BLOCK_STRIDE))
+ break;
+
+ nblocksfavorable++;
+ lastblock = Min(thisblock, MaxBlockNumber - FAVORABLE_BLOCK_STRIDE);
+ }
+
+ Assert(nblocksfavorable >= 1);
+
+ return nblocksfavorable;
+}
+
+static inline int
+indexdelete_tids_cmp(ItemPointer tid1, ItemPointer tid2)
+{
+ {
+ BlockNumber blk1 = ItemPointerGetBlockNumber(tid1);
+ BlockNumber blk2 = ItemPointerGetBlockNumber(tid2);
+
+ if (blk1 != blk2)
+ return (blk1 < blk2) ? -1 : 1;
+ }
+ {
+ OffsetNumber pos1 = ItemPointerGetOffsetNumber(tid1);
+ OffsetNumber pos2 = ItemPointerGetOffsetNumber(tid2);
+
+ if (pos1 != pos2)
+ return (pos1 < pos2) ? -1 : 1;
+ }
+
+ pg_unreachable();
+
+ return 0;
+}
+
+static inline int
+indexdeletecount_cmp(IndexDeleteCounts *count1, IndexDeleteCounts *count2)
+{
+ uint32 ntids1,
+ ntids2;
+
+ /* We expect power-of-two values for npromisingtids fields */
+ Assert(count1->npromisingtids == 0 ||
+ ((count1->npromisingtids - 1) & count1->npromisingtids) == 0);
+ Assert(count2->npromisingtids == 0 ||
+ ((count2->npromisingtids - 1) & count2->npromisingtids) == 0);
+
+ /*
+ * Most significant field is npromisingtids, which we sort on in desc
+ * order. The usual asc comparison order is deliberately inverted here.
+ */
+ if (count1->npromisingtids > count2->npromisingtids)
+ return -1;
+ if (count1->npromisingtids < count2->npromisingtids)
+ return 1;
+
+ /*
+ * Tiebreak: desc ntids sort order.
+ *
+ * We cannot expect power-of-two values for ntids fields. We should
+ * behave as if they were already rounded up for us instead.
+ */
+ ntids1 = count1->ntids;
+ ntids2 = count2->ntids;
+ if (ntids1 != ntids2)
+ {
+ ntids1 = pg_nextpower2_32(ntids1);
+ ntids2 = pg_nextpower2_32(ntids2);
+
+ if (ntids1 > ntids2)
+ return -1;
+ if (ntids1 < ntids2)
+ return 1;
+ }
+
+ /*
+ * Tiebreak: asc offset-into-deltids-for-block (offset to first TID for
+ * block in deltids array) order.
+ *
+ * This is equivalent to sorting in ascending heap block number order
+ * (among otherwise equal subsets of the array). This approach allows us
+ * to avoid accessing the out-of-line TID. (We rely on the assumption
+ * that the deltids array was sorted in ascending heap TID order when
+ * these offsets to the first TID from each heap block group were formed.)
+ */
+ if (count1->ideltids > count2->ideltids)
+ return 1;
+ if (count1->ideltids < count2->ideltids)
+ return -1;
+
+ pg_unreachable();
+
+ return 0;
+}
+
+/*
+ * Two hand written shellshort implementations.
+ *
+ * The two sort operations needed by heapam_index_delete_check_sort() become
+ * quite noticeable on profiles of workloads with lots of index contention
+ * caused by non-HOT updates. Keeping costs down is important enough to
+ * justify several micro-optimizations. We could just use qsort() instead,
+ * but the indirection that it imposes is expensive enough to matter here.
+ * (The size of array elements also matters, which is why we keep it under 8
+ * bytes - swaps should be as fast as reasonably possible).
+ *
+ * We use shellsort here because it has many of the same strengths as an
+ * industrial-strength quicksort implementation, but is also lightweight in
+ * the sense that the entire implementation compiles to relatively few machine
+ * instructions. It is adaptive to inputs with some presorted subsets (which
+ * are typical here).
+ *
+ * This implementation is fast with array sizes up to about 1900. This covers
+ * all supported BLCKSZ values.
+ */
+static void
+heap_tid_shellsort(TM_IndexDelete *deltids, int ndeltids)
+{
+ int low = 0;
+
+ /* Think carefully before changing anything here */
+ StaticAssertStmt(sizeof(TM_IndexDelete) <= 8,
+ "element size exceeds 8 bytes");
+
+ for (int g = 0; g < lengthof(ShellsortGaps); g++)
+ {
+ for (int hi = ShellsortGaps[g], i = low + hi; i < ndeltids; i++)
+ {
+ TM_IndexDelete d = deltids[i];
+ int j = i;
+
+ while (j >= hi &&
+ indexdelete_tids_cmp(&deltids[j - hi].tid, &d.tid) >= 0)
+ {
+ deltids[j] = deltids[j - hi];
+ j -= hi;
+ }
+ deltids[j] = d;
+ }
+ }
+}
+
+static void
+index_delete_shellsort(IndexDeleteCounts *blockcounts, int nblockgroups)
+{
+ int low = 0;
+
+ /* Think carefully before changing anything here */
+ StaticAssertStmt(sizeof(IndexDeleteCounts) <= 8,
+ "element size exceeds 8 bytes");
+
+ for (int g = 0; g < lengthof(ShellsortGaps); g++)
+ {
+ for (int hi = ShellsortGaps[g], i = low + hi; i < nblockgroups; i++)
+ {
+ IndexDeleteCounts c = blockcounts[i];
+ int j = i;
+
+ while (j >= hi &&
+ indexdeletecount_cmp(&blockcounts[j - hi], &c) >= 0)
+ {
+ blockcounts[j] = blockcounts[j - hi];
+ j -= hi;
+ }
+ blockcounts[j] = c;
+ }
+ }
+}
+
+/*
+ * heapam_index_delete_check() helper function. Sorts deltids array in the
+ * order needed for useful processing.
+ *
+ * Groups heap TIDs from deltids into heap block number groupings. From
+ * there, sorts each heap block grouping by the total number of "promising"
+ * TIDs it contains (in desc order). For blocks with the same number of
+ * promising TIDs, tiebreak on the total heap TID count (also desc order).
+ *
+ * heapam_index_delete_check() only visits up to MAX_DELETE_HEAP_BLOCKS heap
+ * blocks due to the speculative nature of the batch index deletion
+ * optimization. These heap blocks had better be the most promising
+ * available, based on a variety of criteria. We make sure of that here.
+ *
+ * Sets new size of deltids array (ndeltids) in state. deltids will only have
+ * TIDs from the MAX_DELETE_HEAP_BLOCKS most promising heap blocks when we
+ * return (which is usually far fewer).
+ *
+ * Returns number of "favorable" blocks.
+ */
+static int
+heapam_index_delete_check_sort(Relation rel, TM_IndexDeleteOp *delstate)
+{
+ IndexDeleteCounts *blockcounts;
+ TM_IndexDelete *reordereddeltids;
+ BlockNumber curblock = InvalidBlockNumber;
+ int nblockgroups = 0;
+ int ncopied = 0;
+ int nblocksfavorable = 0;
+#ifdef USE_PREFETCH
+ int prefetch_distance;
+#endif
+
+ Assert(delstate->ndeltids > 0);
+
+ /* First sort caller's array by TID */
+ heap_tid_shellsort(delstate->deltids, delstate->ndeltids);
+
+ /* alltids caller visits all blocks, so make sure that happens */
+ if (delstate->alltids)
+ return delstate->ndeltids;
+
+ /* Calculate per-heap-block count of TIDs */
+ blockcounts = palloc(sizeof(IndexDeleteCounts) * delstate->ndeltids);
+ for (int i = 0; i < delstate->ndeltids; i++)
+ {
+ ItemPointer deltid = &delstate->deltids[i].tid;
+ TM_IndexStatus *dstatus = delstate->status + delstate->deltids[i].id;
+ bool ispromising = dstatus->ispromising;
+
+ if (curblock != ItemPointerGetBlockNumber(deltid))
+ {
+ /* New block group */
+ nblockgroups++;
+
+ Assert(curblock < ItemPointerGetBlockNumber(deltid) ||
+ !BlockNumberIsValid(curblock));
+
+ curblock = ItemPointerGetBlockNumber(deltid);
+ blockcounts[nblockgroups - 1].ideltids = i;
+ blockcounts[nblockgroups - 1].ntids = 1;
+ blockcounts[nblockgroups - 1].npromisingtids = 0;
+ }
+ else
+ {
+ blockcounts[nblockgroups - 1].ntids++;
+ }
+
+ if (ispromising)
+ blockcounts[nblockgroups - 1].npromisingtids++;
+ }
+
+ /*
+ * We're about ready to use index_delete_shellsort() to determine the
+ * optimal order for visiting heap pages. But before we do, round the
+ * number of promising tuples for each block group up to the nearest
+ * power-of-two (unless there are zero promising tuples). This scheme
+ * usefully divides heap pages into buckets. Each bucket contains heap
+ * pages that are approximately equally promising, that we want to treat
+ * as exactly equivalent (at least initially).
+ *
+ * While in general the presence of promising tuples (the hint that index
+ * AMs provide) is the best information that we have to go on, it is based
+ * on simple heuristics about duplicates in indexes that are understood to
+ * have specific flaws. We should not let the most promising heap pages
+ * win or lose on the basis of _relatively_ small differences in the total
+ * number of promising tuples. Small differences between the most
+ * promising few heap pages are effectively ignored by applying this
+ * power-of-two bucketing scheme.
+ *
+ * When we have lots of ties on the final bucket-ized npromisingtids among
+ * the most promising heap pages, we let heap locality determine the order
+ * in which we visit heap pages. This is helpful because it exploits the
+ * natural tendency for earlier heap blocks to accumulate more LP_DEAD
+ * items sooner in workloads with many non-HOT updates. It's also helpful
+ * because the effect over time is that we process related heap blocks
+ * sequentially, possibly with multiple rounds of processing over the same
+ * related heap blocks that are subject to continuous non-HOT updates over
+ * time.
+ *
+ * Note that we effectively have the same power-of-two bucketing scheme
+ * with the ntids field (which is compared after npromisingtids). The
+ * only reason that we don't fix nhtids here is that the original values
+ * will be needed when copying the final TIDs from winning block groups
+ * back into caller's deltids array.
+ */
+ for (int b = 0; b < nblockgroups; b++)
+ {
+ IndexDeleteCounts *blockgroup = blockcounts + b;
+
+ if (blockgroup->npromisingtids != 0)
+ blockgroup->npromisingtids =
+ pg_nextpower2_32((uint32) blockgroup->npromisingtids);
+ }
+
+ /* Sort groups and rearrange caller's deltids array */
+ index_delete_shellsort(blockcounts, nblockgroups);
+ reordereddeltids = palloc(delstate->ndeltids * sizeof(TM_IndexDelete));
+
+ nblockgroups = Min(MAX_DELETE_HEAP_BLOCKS, nblockgroups);
+ /* Determine number of favorable blocks at the start of array */
+ nblocksfavorable = top_block_groups_favorable(blockcounts, nblockgroups,
+ delstate->deltids);
+
+#ifdef USE_PREFETCH
+ /* Compute the prefetch distance that we will attempt to maintain */
+ if (IsCatalogRelation(rel))
+ prefetch_distance = maintenance_io_concurrency;
+ else
+ prefetch_distance =
+ get_tablespace_maintenance_io_concurrency(rel->rd_rel->reltablespace);
+
+ prefetch_distance = Min(prefetch_distance, nblockgroups);
+#endif
+
+ for (int b = 0; b < nblockgroups; b++)
+ {
+ IndexDeleteCounts *blockgroup = blockcounts + b;
+ TM_IndexDelete *firstgroup = delstate->deltids + blockgroup->ideltids;
+
+ memcpy(reordereddeltids + ncopied, firstgroup,
+ sizeof(TM_IndexDelete) * blockgroup->ntids);
+ ncopied += blockgroup->ntids;
+
+#ifdef USE_PREFETCH
+ if (prefetch_distance-- > 0)
+ {
+ BlockNumber hblock = ItemPointerGetBlockNumber(&firstgroup->tid);
+
+ PrefetchBuffer(rel, MAIN_FORKNUM, hblock);
+ }
+#endif
+ }
+
+ /* Copy final grouped and sorted TIDs back into start of caller's array */
+ memcpy(delstate->deltids, reordereddeltids,
+ sizeof(TM_IndexDelete) * ncopied);
+ delstate->ndeltids = ncopied;
+
+ /* be tidy */
+ pfree(reordereddeltids);
+ pfree(blockcounts);
+
+ return nblocksfavorable;
+}
+
/*
* Perform XLogInsert to register a heap cleanup info message. These
* messages are sent once per VACUUM and are required because
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index 3eea215b85..a4069d2ce0 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -2557,6 +2557,7 @@ static const TableAmRoutine heapam_methods = {
.tuple_delete = heapam_tuple_delete,
.tuple_update = heapam_tuple_update,
.tuple_lock = heapam_tuple_lock,
+ .index_delete_check = heapam_index_delete_check,
.tuple_fetch_row_version = heapam_fetch_row_version,
.tuple_get_latest_tid = heap_get_latest_tid,
diff --git a/src/backend/access/table/tableam.c b/src/backend/access/table/tableam.c
index 6438c45716..e19bdd246a 100644
--- a/src/backend/access/table/tableam.c
+++ b/src/backend/access/table/tableam.c
@@ -207,9 +207,9 @@ table_beginscan_parallel(Relation relation, ParallelTableScanDesc parallel_scan)
/*
* To perform that check simply start an index scan, create the necessary
* slot, do the heap lookup, and shut everything down again. This could be
- * optimized, but is unlikely to matter from a performance POV. If there
- * frequently are live index pointers also matching a unique index key, the
- * CPU overhead of this routine is unlikely to matter.
+ * optimized, but is unlikely to matter from a performance POV. Note that
+ * table_index_delete_check() is optimized in this way, since it is designed
+ * as a batch operation.
*
* Note that *tid may be modified when we return true if the AM supports
* storing multiple row versions reachable via a single index entry (like
--
2.25.1
[application/octet-stream] v10-0002-Pass-down-logically-unchanged-index-hint.patch (29.4K, ../../CAH2-WzmX21q+en6g0aH4VfUCNk+QODWA6hrqhga0Ym06tHiHgA@mail.gmail.com/3-v10-0002-Pass-down-logically-unchanged-index-hint.patch)
download | inline diff:
From 95153ab2d6e38b4d638e0671e443fbb93816029f Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Mon, 9 Nov 2020 12:59:30 -0800
Subject: [PATCH v10 2/3] Pass down "logically unchanged index" hint.
Add an executor aminsert() hinting mechanism that informs index AMs that
the incoming index tuple (the tuple that accompanies the hint) is not
being inserted because of a logical change to indexed columns (from an
UPDATE or INSERT statement). This "logically unchanged" hint indicates
that the incoming item must be a duplicate of some existing item in the
index (a physical tuple that represents an obsolescent version of the
logical row affected by an UPDATE). When this happens the new tuple is
only needed so that the index will have a separate entry for the latest
logical row (it's latest version/HOT chain).
An aminsert() call which gets the hint is fundamentally different to any
aminsert() call needed for an INSERT statement. It's also fundamentally
difference to an aminsert() call needed for an UPDATE statement where
the index is logically changed by the UPDATE. Recognizing this
difference can allow cleanup of garbage tuples in index access methods
to work better. Cleanup can intelligently target tuples that are likely
to be garbage, without wasting too many cycles on less promising tuples.
This commit is infrastructure for an upcoming commit that will teach
nbtree to perform bottom-up index deletion. No index AM applies the
hint at this point. It is not useful on its own.
Author: Peter Geoghegan <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wz=CEKFa74EScx_hFVshCOn6AA5T-ajFASTdzipdkLTNQQ@mail.gmail.com
---
src/include/access/amapi.h | 1 +
src/include/access/brin_internal.h | 1 +
src/include/access/genam.h | 1 +
src/include/access/gin_private.h | 1 +
src/include/access/gist_private.h | 1 +
src/include/access/hash.h | 1 +
src/include/access/nbtree.h | 1 +
src/include/access/spgist.h | 1 +
src/include/executor/executor.h | 1 +
src/backend/access/brin/brin.c | 1 +
src/backend/access/common/toast_internals.c | 2 +-
src/backend/access/gin/gininsert.c | 1 +
src/backend/access/gist/gist.c | 1 +
src/backend/access/hash/hash.c | 1 +
src/backend/access/heap/heapam_handler.c | 1 +
src/backend/access/index/indexam.c | 4 +-
src/backend/access/nbtree/nbtree.c | 1 +
src/backend/access/spgist/spginsert.c | 1 +
src/backend/catalog/indexing.c | 1 +
src/backend/commands/constraint.c | 2 +-
src/backend/commands/copyfrom.c | 5 +-
src/backend/commands/trigger.c | 6 +-
src/backend/executor/execIndexing.c | 160 +++++++++++++++++-
src/backend/executor/execMain.c | 8 +-
src/backend/executor/execReplication.c | 8 +-
src/backend/executor/nodeModifyTable.c | 6 +-
src/backend/replication/logical/worker.c | 3 +-
contrib/bloom/blinsert.c | 1 +
contrib/bloom/bloom.h | 1 +
doc/src/sgml/indexam.sgml | 15 ++
.../modules/dummy_index_am/dummy_index_am.c | 1 +
31 files changed, 214 insertions(+), 25 deletions(-)
diff --git a/src/include/access/amapi.h b/src/include/access/amapi.h
index 85b4766016..499119468d 100644
--- a/src/include/access/amapi.h
+++ b/src/include/access/amapi.h
@@ -110,6 +110,7 @@ typedef bool (*aminsert_function) (Relation indexRelation,
ItemPointer heap_tid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
/* bulk delete */
diff --git a/src/include/access/brin_internal.h b/src/include/access/brin_internal.h
index 9ffc9100c0..74a0e7eb29 100644
--- a/src/include/access/brin_internal.h
+++ b/src/include/access/brin_internal.h
@@ -91,6 +91,7 @@ extern void brinbuildempty(Relation index);
extern bool brininsert(Relation idxRel, Datum *values, bool *nulls,
ItemPointer heaptid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
extern IndexScanDesc brinbeginscan(Relation r, int nkeys, int norderbys);
extern int64 bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
diff --git a/src/include/access/genam.h b/src/include/access/genam.h
index 68d90f5141..bf2c2278d9 100644
--- a/src/include/access/genam.h
+++ b/src/include/access/genam.h
@@ -143,6 +143,7 @@ extern bool index_insert(Relation indexRelation,
ItemPointer heap_t_ctid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
extern IndexScanDesc index_beginscan(Relation heapRelation,
diff --git a/src/include/access/gin_private.h b/src/include/access/gin_private.h
index 5cb2f72e4c..ff60f5708e 100644
--- a/src/include/access/gin_private.h
+++ b/src/include/access/gin_private.h
@@ -116,6 +116,7 @@ extern void ginbuildempty(Relation index);
extern bool gininsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
extern void ginEntryInsert(GinState *ginstate,
OffsetNumber attnum, Datum key, GinNullCategory category,
diff --git a/src/include/access/gist_private.h b/src/include/access/gist_private.h
index b68c01a5f2..09f9ad6d95 100644
--- a/src/include/access/gist_private.h
+++ b/src/include/access/gist_private.h
@@ -403,6 +403,7 @@ extern void gistbuildempty(Relation index);
extern bool gistinsert(Relation r, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
extern MemoryContext createTempGistContext(void);
extern GISTSTATE *initGISTstate(Relation index);
diff --git a/src/include/access/hash.h b/src/include/access/hash.h
index bab4d9f1b0..d5e65ff2be 100644
--- a/src/include/access/hash.h
+++ b/src/include/access/hash.h
@@ -364,6 +364,7 @@ extern void hashbuildempty(Relation index);
extern bool hashinsert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
extern bool hashgettuple(IndexScanDesc scan, ScanDirection dir);
extern int64 hashgetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index e8fecc6026..3b60e696eb 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -996,6 +996,7 @@ extern void btbuildempty(Relation index);
extern bool btinsert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
extern IndexScanDesc btbeginscan(Relation rel, int nkeys, int norderbys);
extern Size btestimateparallelscan(void);
diff --git a/src/include/access/spgist.h b/src/include/access/spgist.h
index 9f2ccc1730..544f240d1f 100644
--- a/src/include/access/spgist.h
+++ b/src/include/access/spgist.h
@@ -199,6 +199,7 @@ extern void spgbuildempty(Relation index);
extern bool spginsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
/* spgscan.c */
diff --git a/src/include/executor/executor.h b/src/include/executor/executor.h
index 0c48d2a519..c8185bf8ce 100644
--- a/src/include/executor/executor.h
+++ b/src/include/executor/executor.h
@@ -581,6 +581,7 @@ extern void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative);
extern void ExecCloseIndices(ResultRelInfo *resultRelInfo);
extern List *ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot, EState *estate,
+ bool update,
bool noDupErr,
bool *specConflict, List *arbiterIndexes);
extern bool ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo,
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index 1f72562c60..bea078944c 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -151,6 +151,7 @@ bool
brininsert(Relation idxRel, Datum *values, bool *nulls,
ItemPointer heaptid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
BlockNumber pagesPerRange;
diff --git a/src/backend/access/common/toast_internals.c b/src/backend/access/common/toast_internals.c
index 25a81e5ec6..e206e67756 100644
--- a/src/backend/access/common/toast_internals.c
+++ b/src/backend/access/common/toast_internals.c
@@ -328,7 +328,7 @@ toast_save_datum(Relation rel, Datum value,
toastrel,
toastidxs[i]->rd_index->indisunique ?
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
- NULL);
+ false, NULL);
}
/*
diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c
index 77433dc8a4..7fa880fc6c 100644
--- a/src/backend/access/gin/gininsert.c
+++ b/src/backend/access/gin/gininsert.c
@@ -488,6 +488,7 @@ bool
gininsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
GinState *ginstate = (GinState *) indexInfo->ii_AmCache;
diff --git a/src/backend/access/gist/gist.c b/src/backend/access/gist/gist.c
index 25b42e38f2..1fb145c891 100644
--- a/src/backend/access/gist/gist.c
+++ b/src/backend/access/gist/gist.c
@@ -156,6 +156,7 @@ bool
gistinsert(Relation r, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
GISTSTATE *giststate = (GISTSTATE *) indexInfo->ii_AmCache;
diff --git a/src/backend/access/hash/hash.c b/src/backend/access/hash/hash.c
index 7c9ccf446c..7da8b892f4 100644
--- a/src/backend/access/hash/hash.c
+++ b/src/backend/access/hash/hash.c
@@ -247,6 +247,7 @@ bool
hashinsert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
Datum index_values[1];
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c
index a4069d2ce0..e95ff4ef9f 100644
--- a/src/backend/access/heap/heapam_handler.c
+++ b/src/backend/access/heap/heapam_handler.c
@@ -1956,6 +1956,7 @@ heapam_index_validate_scan(Relation heapRelation,
heapRelation,
indexInfo->ii_Unique ?
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
+ false,
indexInfo);
state->tups_inserted += 1;
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index 3fb8688f8f..9ad1a18a31 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -179,6 +179,7 @@ index_insert(Relation indexRelation,
ItemPointer heap_t_ctid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
RELATION_CHECKS;
@@ -191,7 +192,8 @@ index_insert(Relation indexRelation,
return indexRelation->rd_indam->aminsert(indexRelation, values, isnull,
heap_t_ctid, heapRelation,
- checkUnique, indexInfo);
+ checkUnique, indexUnchanged,
+ indexInfo);
}
/*
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index c4f22f1c69..d6c8ad5d27 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -199,6 +199,7 @@ bool
btinsert(Relation rel, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
bool result;
diff --git a/src/backend/access/spgist/spginsert.c b/src/backend/access/spgist/spginsert.c
index e4508a2b92..dcffb76e16 100644
--- a/src/backend/access/spgist/spginsert.c
+++ b/src/backend/access/spgist/spginsert.c
@@ -207,6 +207,7 @@ bool
spginsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
SpGistState spgstate;
diff --git a/src/backend/catalog/indexing.c b/src/backend/catalog/indexing.c
index 538f6a06b8..3e577dd183 100644
--- a/src/backend/catalog/indexing.c
+++ b/src/backend/catalog/indexing.c
@@ -162,6 +162,7 @@ CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
heapRelation,
index->rd_index->indisunique ?
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
+ false,
indexInfo);
}
diff --git a/src/backend/commands/constraint.c b/src/backend/commands/constraint.c
index fc19307bf2..79bd12b7de 100644
--- a/src/backend/commands/constraint.c
+++ b/src/backend/commands/constraint.c
@@ -175,7 +175,7 @@ unique_key_recheck(PG_FUNCTION_ARGS)
*/
index_insert(indexRel, values, isnull, &checktid,
trigdata->tg_relation, UNIQUE_CHECK_EXISTING,
- indexInfo);
+ false, indexInfo);
}
else
{
diff --git a/src/backend/commands/copyfrom.c b/src/backend/commands/copyfrom.c
index 1b14e9a6eb..a848edb8fd 100644
--- a/src/backend/commands/copyfrom.c
+++ b/src/backend/commands/copyfrom.c
@@ -340,8 +340,8 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
cstate->cur_lineno = buffer->linenos[i];
recheckIndexes =
ExecInsertIndexTuples(resultRelInfo,
- buffer->slots[i], estate, false, NULL,
- NIL);
+ buffer->slots[i], estate, false, false,
+ NULL, NIL);
ExecARInsertTriggers(estate, resultRelInfo,
slots[i], recheckIndexes,
cstate->transition_capture);
@@ -1085,6 +1085,7 @@ CopyFrom(CopyFromState cstate)
myslot,
estate,
false,
+ false,
NULL,
NIL);
}
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index c336b238aa..8c663fcda5 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -71,10 +71,8 @@ int SessionReplicationRole = SESSION_REPLICATION_ROLE_ORIGIN;
static int MyTriggerDepth = 0;
/*
- * Note that similar macros also exist in executor/execMain.c. There does not
- * appear to be any good header to put them into, given the structures that
- * they use, so we let them be duplicated. Be sure to update all if one needs
- * to be changed, however.
+ * The authoritative version of this macro is in executor/execMain.c. Be sure
+ * to keep everything in sync.
*/
#define GetAllUpdatedColumns(relinfo, estate) \
(bms_union(exec_rt_fetch((relinfo)->ri_RangeTableIndex, estate)->updatedCols, \
diff --git a/src/backend/executor/execIndexing.c b/src/backend/executor/execIndexing.c
index c6b5bcba7b..69bb51b6d0 100644
--- a/src/backend/executor/execIndexing.c
+++ b/src/backend/executor/execIndexing.c
@@ -124,6 +124,15 @@ typedef enum
CEOUC_LIVELOCK_PREVENTING_WAIT
} CEOUC_WAIT_MODE;
+/*
+ * The authoritative version of these macro are in executor/execMain.c. Be
+ * sure to keep everything in sync.
+ */
+#define GetUpdatedColumns(relinfo, estate) \
+ (exec_rt_fetch((relinfo)->ri_RangeTableIndex, estate)->updatedCols)
+#define GetExtraUpdatedColumns(relinfo, estate) \
+ (exec_rt_fetch((relinfo)->ri_RangeTableIndex, estate)->extraUpdatedCols)
+
static bool check_exclusion_or_unique_constraint(Relation heap, Relation index,
IndexInfo *indexInfo,
ItemPointer tupleid,
@@ -136,6 +145,11 @@ static bool check_exclusion_or_unique_constraint(Relation heap, Relation index,
static bool index_recheck_constraint(Relation index, Oid *constr_procs,
Datum *existing_values, bool *existing_isnull,
Datum *new_values);
+static bool index_unchanged_by_update(ResultRelInfo *resultRelInfo,
+ EState *estate, IndexInfo *indexInfo,
+ Relation indexRelation);
+static bool index_unchanged_by_update_var_walker(Node *node,
+ Bitmapset *allUpdatedCols);
/* ----------------------------------------------------------------
* ExecOpenIndices
@@ -254,6 +268,16 @@ ExecCloseIndices(ResultRelInfo *resultRelInfo)
* into all the relations indexing the result relation
* when a heap tuple is inserted into the result relation.
*
+ * When 'update' is true, executor is performing an UPDATE
+ * that could not use an optimization like heapam's HOT (in
+ * more general terms a call to table_tuple_update() took
+ * place and set 'update_indexes' to true). Receiving this
+ * hint makes us consider if we should pass down the
+ * 'indexUnchanged' hint in turn. That's something that we
+ * figure out for each index_insert() call iff 'update' is
+ * true. (When 'update' is false we already know not to pass
+ * the hint to any index.)
+ *
* Unique and exclusion constraints are enforced at the same
* time. This returns a list of index OIDs for any unique or
* exclusion constraints that are deferred and that had
@@ -263,16 +287,13 @@ ExecCloseIndices(ResultRelInfo *resultRelInfo)
*
* If 'arbiterIndexes' is nonempty, noDupErr applies only to
* those indexes. NIL means noDupErr applies to all indexes.
- *
- * CAUTION: this must not be called for a HOT update.
- * We can't defend against that here for lack of info.
- * Should we change the API to make it safer?
* ----------------------------------------------------------------
*/
List *
ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot,
EState *estate,
+ bool update,
bool noDupErr,
bool *specConflict,
List *arbiterIndexes)
@@ -319,6 +340,7 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
IndexInfo *indexInfo;
bool applyNoDupErr;
IndexUniqueCheck checkUnique;
+ bool indexUnchanged;
bool satisfiesConstraint;
if (indexRelation == NULL)
@@ -389,6 +411,16 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
else
checkUnique = UNIQUE_CHECK_PARTIAL;
+ /*
+ * There's definitely going to be an index_insert() call for this
+ * index. If we're being called as part of an UPDATE statement,
+ * consider if the 'indexUnchanged' = true hint should be passed.
+ */
+ indexUnchanged = update && index_unchanged_by_update(resultRelInfo,
+ estate,
+ indexInfo,
+ indexRelation);
+
satisfiesConstraint =
index_insert(indexRelation, /* index relation */
values, /* array of index Datums */
@@ -396,6 +428,7 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
tupleid, /* tid of heap tuple */
heapRelation, /* heap relation */
checkUnique, /* type of uniqueness check to do */
+ indexUnchanged, /* UPDATE without logical change? */
indexInfo); /* index AM may need this */
/*
@@ -899,3 +932,122 @@ index_recheck_constraint(Relation index, Oid *constr_procs,
return true;
}
+
+/*
+ * Check if ExecInsertIndexTuples() should pass indexUnchanged hint.
+ *
+ * When the executor performs an UPDATE that requires a new round of index
+ * tuples, determine if we should pass 'indexUnchanged' = true hint for one
+ * single index.
+ */
+static bool
+index_unchanged_by_update(ResultRelInfo *resultRelInfo, EState *estate,
+ IndexInfo *indexInfo, Relation indexRelation)
+{
+ Bitmapset *updatedCols = GetUpdatedColumns(resultRelInfo, estate);
+ Bitmapset *extraUpdatedCols = GetExtraUpdatedColumns(resultRelInfo, estate);
+ Bitmapset *allUpdatedCols;
+ bool hasexpression = false;
+ List *idxExprs;
+
+ /*
+ * Check for indexed attribute overlap with updated columns.
+ *
+ * Only do this for key columns. A change to a non-key column within an
+ * INCLUDE index should not be considered because that's just payload to
+ * the index (they're not unlike table TIDs to the index AM).
+ */
+ for (int attr = 0; attr < indexInfo->ii_NumIndexKeyAttrs; attr++)
+ {
+ int keycol = indexInfo->ii_IndexAttrNumbers[attr];
+
+ if (keycol <= 0)
+ {
+ /*
+ * Skip expressions for now, but remember to deal with them later
+ * on
+ */
+ hasexpression = true;
+ continue;
+ }
+
+ if (bms_is_member(keycol - FirstLowInvalidHeapAttributeNumber,
+ updatedCols) ||
+ bms_is_member(keycol - FirstLowInvalidHeapAttributeNumber,
+ extraUpdatedCols))
+ {
+ /* Changed key column -- don't hint for this index */
+ return false;
+ }
+ }
+
+ /*
+ * When we get this far and index has no expressions, return true so that
+ * index_insert() call will go on to pass 'indexUnchanged' = true hint.
+ *
+ * The _absence_ of an indexed key attribute that overlaps with updated
+ * attributes (in addition to the total absence of indexed expressions)
+ * shows that the index as a whole is logically unchanged by UPDATE.
+ */
+ if (!hasexpression)
+ return true;
+
+ /*
+ * Need to pass only one bms to expression_tree_walker helper function.
+ * Avoid allocating memory in common case where there are no extra cols.
+ */
+ if (!extraUpdatedCols)
+ allUpdatedCols = updatedCols;
+ else
+ allUpdatedCols = bms_union(updatedCols, extraUpdatedCols);
+
+ /*
+ * We have to work slightly harder in the event of indexed expressions,
+ * but the principle is the same as before: try to find columns (Vars,
+ * actually) that overlap with known-updated columns.
+ *
+ * If we find any matching Vars, don't pass hint for index. Otherwise
+ * pass hint.
+ */
+ idxExprs = RelationGetIndexExpressions(indexRelation);
+ hasexpression = index_unchanged_by_update_var_walker((Node *) idxExprs,
+ allUpdatedCols);
+ list_free(idxExprs);
+ if (extraUpdatedCols)
+ bms_free(allUpdatedCols);
+
+ if (hasexpression)
+ return false;
+
+ return true;
+}
+
+/*
+ * Indexed expression helper for index_unchanged_by_update().
+ *
+ * Returns true when Var that appears within allUpdatedCols located.
+ */
+static bool
+index_unchanged_by_update_var_walker(Node *node, Bitmapset *allUpdatedCols)
+{
+ if (node == NULL)
+ return false;
+
+ if (IsA(node, Var))
+ {
+ Var *var = (Var *) node;
+
+ if (bms_is_member(var->varattno - FirstLowInvalidHeapAttributeNumber,
+ allUpdatedCols))
+ {
+ /* Var was updated -- indicates that we should not hint */
+ return true;
+ }
+
+ /* Still haven't found a reason to not pass the hint */
+ return false;
+ }
+
+ return expression_tree_walker(node, index_unchanged_by_update_var_walker,
+ (void *) allUpdatedCols);
+}
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 7179f589f9..31cbc27fa1 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -101,10 +101,10 @@ static char *ExecBuildSlotValueDescription(Oid reloid,
static void EvalPlanQualStart(EPQState *epqstate, Plan *planTree);
/*
- * Note that GetAllUpdatedColumns() also exists in commands/trigger.c. There does
- * not appear to be any good header to put it into, given the structures that
- * it uses, so we let them be duplicated. Be sure to update both if one needs
- * to be changed, however.
+ * Note that variants of these macros exists in commands/trigger.c and in
+ * execIndexing.c. There does not appear to be any good header to put it
+ * into, given the structures that it uses, so we let them be duplicated. Be
+ * sure to keep everything in sync.
*/
#define GetInsertedColumns(relinfo, estate) \
(exec_rt_fetch((relinfo)->ri_RangeTableIndex, estate)->insertedCols)
diff --git a/src/backend/executor/execReplication.c b/src/backend/executor/execReplication.c
index 01d26881e7..1be26f84d9 100644
--- a/src/backend/executor/execReplication.c
+++ b/src/backend/executor/execReplication.c
@@ -444,8 +444,8 @@ ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
- slot, estate, false, NULL,
- NIL);
+ slot, estate, false, false,
+ NULL, NIL);
/* AFTER ROW INSERT Triggers */
ExecARInsertTriggers(estate, resultRelInfo, slot,
@@ -512,8 +512,8 @@ ExecSimpleRelationUpdate(ResultRelInfo *resultRelInfo,
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
- slot, estate, false, NULL,
- NIL);
+ slot, estate, true, false,
+ NULL, NIL);
/* AFTER ROW UPDATE Triggers */
ExecARUpdateTriggers(estate, resultRelInfo,
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index e0f24283b8..a9f0732bec 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -599,7 +599,7 @@ ExecInsert(ModifyTableState *mtstate,
/* insert index entries for tuple */
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
- slot, estate, true,
+ slot, estate, false, true,
&specConflict,
arbiterIndexes);
@@ -640,7 +640,7 @@ ExecInsert(ModifyTableState *mtstate,
if (resultRelInfo->ri_NumIndices > 0)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
slot, estate, false,
- NULL, NIL);
+ false, NULL, NIL);
}
}
@@ -1511,7 +1511,7 @@ lreplace:;
/* insert index entries for tuple if necessary */
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
- slot, estate, false,
+ slot, estate, true, false,
NULL, NIL);
}
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index 8c7fad8f74..294d1b5bdf 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -1309,7 +1309,8 @@ apply_handle_update(StringInfo s)
InitResultRelInfo(resultRelInfo, rel->localrel, 1, NULL, 0);
/*
- * Populate updatedCols so that per-column triggers can fire. This could
+ * Populate updatedCols so that per-column triggers can fire, and so
+ * executor can correctly pass down indexUnchanged hint. This could
* include more columns than were actually changed on the publisher
* because the logical replication protocol doesn't contain that
* information. But it would for example exclude columns that only exist
diff --git a/contrib/bloom/blinsert.c b/contrib/bloom/blinsert.c
index 6d3fd5c432..ce4e7486e9 100644
--- a/contrib/bloom/blinsert.c
+++ b/contrib/bloom/blinsert.c
@@ -198,6 +198,7 @@ bool
blinsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
BloomState blstate;
diff --git a/contrib/bloom/bloom.h b/contrib/bloom/bloom.h
index 23aa7ac441..59ae83d7aa 100644
--- a/contrib/bloom/bloom.h
+++ b/contrib/bloom/bloom.h
@@ -192,6 +192,7 @@ extern bool blvalidate(Oid opclassoid);
extern bool blinsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
struct IndexInfo *indexInfo);
extern IndexScanDesc blbeginscan(Relation r, int nkeys, int norderbys);
extern int64 blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
diff --git a/doc/src/sgml/indexam.sgml b/doc/src/sgml/indexam.sgml
index f00268d5b5..ec5741df6d 100644
--- a/doc/src/sgml/indexam.sgml
+++ b/doc/src/sgml/indexam.sgml
@@ -293,6 +293,7 @@ aminsert (Relation indexRelation,
ItemPointer heap_tid,
Relation heapRelation,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo);
</programlisting>
Insert a new tuple into an existing index. The <literal>values</literal> and
@@ -308,6 +309,20 @@ aminsert (Relation indexRelation,
look into the heap to verify tuple liveness).
</para>
+ <para>
+ The <literal>indexUnchanged</literal> boolean value gives a hint
+ about the nature of the tuple to be indexed. When it is true,
+ the tuple is a duplicate of some existing tuple in the index. The
+ new tuple is a logically unchanged successor MVCC tuple version. This
+ happens when an <command>UPDATE</command> takes place that does not
+ modify any columns covered by the index, but nevertheless requires a
+ new version in the index. The index AM may use this hint to decide
+ to apply bottom-up index deletion in parts of the index where many
+ versions of the same logical row accumulate. Note that updating a
+ non-key column does not affect the value of
+ <literal>indexUnchanged</literal>.
+ </para>
+
<para>
The function's Boolean result value is significant only when
<literal>checkUnique</literal> is <literal>UNIQUE_CHECK_PARTIAL</literal>.
diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c b/src/test/modules/dummy_index_am/dummy_index_am.c
index 8f4cdab1b3..bcd0b48bf0 100644
--- a/src/test/modules/dummy_index_am/dummy_index_am.c
+++ b/src/test/modules/dummy_index_am/dummy_index_am.c
@@ -168,6 +168,7 @@ static bool
diinsert(Relation index, Datum *values, bool *isnull,
ItemPointer ht_ctid, Relation heapRel,
IndexUniqueCheck checkUnique,
+ bool indexUnchanged,
IndexInfo *indexInfo)
{
/* nothing to do */
--
2.25.1
[application/octet-stream] v10-0003-Teach-nbtree-to-use-bottom-up-index-deletion.patch (89.1K, ../../CAH2-WzmX21q+en6g0aH4VfUCNk+QODWA6hrqhga0Ym06tHiHgA@mail.gmail.com/4-v10-0003-Teach-nbtree-to-use-bottom-up-index-deletion.patch)
download | inline diff:
From bf390a64d41ef61313bb4004916844f158c398d6 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <[email protected]>
Date: Mon, 9 Nov 2020 12:59:30 -0800
Subject: [PATCH v10 3/3] Teach nbtree to use bottom-up index deletion.
Teach nbtree to eagerly delete duplicate of tuples representing old
versions in the event of a localized flood of version churn. This
situation is detected using heuristics, including the recently added
"index is logically unchanged by an UPDATE" executor hint.
The immediate goal of bottom-up index deletion in nbtree is to avoid
"unnecessary" page splits caused entirely by duplicates needed only for
MVCC/versioning purposes. It naturally has an even more useful effect,
though: it acts as a backstop against accumulating an excessive number
of index tuple versions for any given _logical row_. Note that the
relationship between this localized condition and the proportion of
garbage tuples in the entire index is very loose, and can be very
volatile. Bottom-up index deletion complements what we might now call
"top-down index deletion": index vacuuming performed by VACUUM. It
responds to the immediate local needs of queries, while leaving it up to
autovacuum to perform infrequent clean sweeps of the index.
Also extend deletion of LP_DEAD-marked index tuples by teaching it to
delete extra index tuples (that are not LP_DEAD-marked) in passing.
This doesn't increase the number of table blocks accessed by deletion,
at least in the common case where the table is not unlogged and
wal_level >= replica. It increases the number of index tuples deleted
significantly in many cases. For example, it almost never fails to
delete at least a few extra index tuples when the regression tests run,
and can delete vastly more index tuples fairly often.
Bottom-up deletion uses the same WAL record that we use when deleting
LP_DEAD items (the xl_btree_delete record). This commit extends
_bt_delitems_delete() to support granular TID deletion in posting list
tuples, and to support a caller-supplied latestRemovedXid.
Bump XLOG_PAGE_MAGIC because xl_btree_delete changed.
No bump in BTREE_VERSION, since there are no changes to the on-disk
representation of nbtree indexes. Indexes built on PostgreSQL 12 or
PostgreSQL 13 will automatically benefit from the optimization (i.e. no
reindexing required) following a pg_upgrade.
This commit is the final major component of bottom-up index deletion,
following an earlier commit that added heapam support.
Author: Peter Geoghegan <[email protected]>
Reviewed-By: Victor Yegorov <[email protected]>
Discussion: https://postgr.es/m/CAH2-Wzm+maE3apHB8NOtmM=p-DO65j2V5GzAWCOEEuy3JZgb2g@mail.gmail.com
---
src/include/access/nbtree.h | 21 +-
src/include/access/nbtxlog.h | 101 ++---
src/backend/access/common/reloptions.c | 10 +
src/backend/access/nbtree/README | 133 ++++++-
src/backend/access/nbtree/nbtdedup.c | 315 +++++++++++++++-
src/backend/access/nbtree/nbtinsert.c | 346 +++++++++++++++--
src/backend/access/nbtree/nbtpage.c | 490 ++++++++++++++++++-------
src/backend/access/nbtree/nbtree.c | 2 +-
src/backend/access/nbtree/nbtsort.c | 1 -
src/backend/access/nbtree/nbtutils.c | 4 +-
src/backend/access/nbtree/nbtxlog.c | 94 +++--
src/bin/psql/tab-complete.c | 4 +-
doc/src/sgml/btree.sgml | 109 +++++-
doc/src/sgml/ref/create_index.sgml | 16 +
14 files changed, 1360 insertions(+), 286 deletions(-)
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index 3b60e696eb..3c93d7f9b5 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -17,6 +17,7 @@
#include "access/amapi.h"
#include "access/itup.h"
#include "access/sdir.h"
+#include "access/tableam.h"
#include "access/xlogreader.h"
#include "catalog/pg_am_d.h"
#include "catalog/pg_index.h"
@@ -767,7 +768,8 @@ typedef BTDedupStateData *BTDedupState;
/*
* BTVacuumPostingData is state that represents how to VACUUM a posting list
- * tuple when some (though not all) of its TIDs are to be deleted.
+ * tuple when some (though not all) of its TIDs are to be deleted. (Also used
+ * by bottom-up index deletion.)
*
* Convention is that itup field is the original posting list tuple on input,
* and palloc()'d final tuple used to overwrite existing tuple on output.
@@ -963,6 +965,7 @@ typedef struct BTOptions
/* fraction of newly inserted tuples prior to trigger index cleanup */
float8 vacuum_cleanup_index_scale_factor;
bool deduplicate_items; /* Try to deduplicate items? */
+ bool delete_items; /* Bottom-up delete items? */
} BTOptions;
#define BTGetFillFactor(relation) \
@@ -978,6 +981,11 @@ typedef struct BTOptions
relation->rd_rel->relam == BTREE_AM_OID), \
((relation)->rd_options ? \
((BTOptions *) (relation)->rd_options)->deduplicate_items : true))
+#define BTGetDeleteItems(relation) \
+ (AssertMacro(relation->rd_rel->relkind == RELKIND_INDEX && \
+ relation->rd_rel->relam == BTREE_AM_OID), \
+ ((relation)->rd_options ? \
+ ((BTOptions *) (relation)->rd_options)->delete_items : true))
/*
* Constant definition for progress reporting. Phase numbers must match
@@ -1031,6 +1039,8 @@ extern void _bt_parallel_advance_array_keys(IndexScanDesc scan);
extern void _bt_dedup_pass(Relation rel, Buffer buf, Relation heapRel,
IndexTuple newitem, Size newitemsz,
bool checkingunique);
+extern bool _bt_bottomup_pass(Relation rel, Buffer buf, Relation heapRel,
+ Size newitemsz);
extern void _bt_dedup_start_pending(BTDedupState state, IndexTuple base,
OffsetNumber baseoff);
extern bool _bt_dedup_save_htid(BTDedupState state, IndexTuple itup);
@@ -1045,7 +1055,8 @@ extern IndexTuple _bt_swap_posting(IndexTuple newitem, IndexTuple oposting,
* prototypes for functions in nbtinsert.c
*/
extern bool _bt_doinsert(Relation rel, IndexTuple itup,
- IndexUniqueCheck checkUnique, Relation heapRel);
+ IndexUniqueCheck checkUnique, bool indexUnchanged,
+ Relation heapRel);
extern void _bt_finish_split(Relation rel, Buffer lbuf, BTStack stack);
extern Buffer _bt_getstackbuf(Relation rel, BTStack stack, BlockNumber child);
@@ -1083,9 +1094,9 @@ extern bool _bt_page_recyclable(Page page);
extern void _bt_delitems_vacuum(Relation rel, Buffer buf,
OffsetNumber *deletable, int ndeletable,
BTVacuumPosting *updatable, int nupdatable);
-extern void _bt_delitems_delete(Relation rel, Buffer buf,
- OffsetNumber *deletable, int ndeletable,
- Relation heapRel);
+extern void _bt_delitems_delete_check(Relation rel, Buffer buf,
+ Relation heapRel,
+ TM_IndexDeleteOp *delstate);
extern uint32 _bt_pagedel(Relation rel, Buffer leafbuf,
TransactionId *oldestBtpoXact);
diff --git a/src/include/access/nbtxlog.h b/src/include/access/nbtxlog.h
index 5c014bdc66..db1eb11042 100644
--- a/src/include/access/nbtxlog.h
+++ b/src/include/access/nbtxlog.h
@@ -176,24 +176,6 @@ typedef struct xl_btree_dedup
#define SizeOfBtreeDedup (offsetof(xl_btree_dedup, nintervals) + sizeof(uint16))
-/*
- * This is what we need to know about delete of individual leaf index tuples.
- * The WAL record can represent deletion of any number of index tuples on a
- * single index page when *not* executed by VACUUM. Deletion of a subset of
- * the TIDs within a posting list tuple is not supported.
- *
- * Backup Blk 0: index page
- */
-typedef struct xl_btree_delete
-{
- TransactionId latestRemovedXid;
- uint32 ndeleted;
-
- /* DELETED TARGET OFFSET NUMBERS FOLLOW */
-} xl_btree_delete;
-
-#define SizeOfBtreeDelete (offsetof(xl_btree_delete, ndeleted) + sizeof(uint32))
-
/*
* This is what we need to know about page reuse within btree. This record
* only exists to generate a conflict point for Hot Standby.
@@ -211,9 +193,61 @@ typedef struct xl_btree_reuse_page
#define SizeOfBtreeReusePage (sizeof(xl_btree_reuse_page))
/*
- * This is what we need to know about which TIDs to remove from an individual
- * posting list tuple during vacuuming. An array of these may appear at the
- * end of xl_btree_vacuum records.
+ * xl_btree_vacuum and xl_btree_delete records describe deletion of index
+ * tuples on a leaf page. The former variant is used by VACUUM, while the
+ * latter variant is used by the ad-hoc deletions that sometimes take place
+ * when btinsert() is called.
+ *
+ * The records are very similar. The only difference is that xl_btree_delete
+ * has to include a latestRemovedXid field to generate recovery conflicts.
+ * (VACUUM operations can just rely on earlier conflicts generated during
+ * pruning of the table whose TIDs the to-be-deleted index tuples point to.
+ * There are also small differences between each REDO routine that we don't go
+ * into here.)
+ *
+ * xl_btree_vacuum and xl_btree_delete both represent deletion of any number
+ * of index tuples on a single leaf page using page offset numbers. Both also
+ * support "updates" of index tuples, which is how deletes of a subset of TIDs
+ * contained in an existing posting list tuple are implemented.
+ *
+ * Updated posting list tuples are represented using xl_btree_update metadata.
+ * The REDO routines each use the xl_btree_update entries (plus each
+ * corresponding original index tuple from the target leaf page) to generate
+ * the final updated tuple.
+ *
+ * Updates are only used when there will be some remaining TIDs left by the
+ * REDO routine. Otherwise the posting list tuple just gets deleted outright.
+ */
+typedef struct xl_btree_vacuum
+{
+ uint16 ndeleted;
+ uint16 nupdated;
+
+ /* DELETED TARGET OFFSET NUMBERS FOLLOW */
+ /* UPDATED TARGET OFFSET NUMBERS FOLLOW */
+ /* UPDATED TUPLES METADATA (xl_btree_update) ARRAY FOLLOWS */
+} xl_btree_vacuum;
+
+#define SizeOfBtreeVacuum (offsetof(xl_btree_vacuum, nupdated) + sizeof(uint16))
+
+typedef struct xl_btree_delete
+{
+ TransactionId latestRemovedXid;
+ uint16 ndeleted;
+ uint16 nupdated;
+
+ /* DELETED TARGET OFFSET NUMBERS FOLLOW */
+ /* UPDATED TARGET OFFSET NUMBERS FOLLOW */
+ /* UPDATED TUPLES METADATA (xl_btree_update) ARRAY FOLLOWS */
+} xl_btree_delete;
+
+#define SizeOfBtreeDelete (offsetof(xl_btree_delete, nupdated) + sizeof(uint16))
+
+/*
+ * The offsets that appear in xl_btree_update metadata are offsets into the
+ * original posting list from tuple, not page offset numbers. These are
+ * 0-based. The page offset number for the original posting list tuple comes
+ * from main xl_btree_delete/xl_btree_vacuum record.
*/
typedef struct xl_btree_update
{
@@ -224,31 +258,6 @@ typedef struct xl_btree_update
#define SizeOfBtreeUpdate (offsetof(xl_btree_update, ndeletedtids) + sizeof(uint16))
-/*
- * This is what we need to know about a VACUUM of a leaf page. The WAL record
- * can represent deletion of any number of index tuples on a single index page
- * when executed by VACUUM. It can also support "updates" of index tuples,
- * which is how deletes of a subset of TIDs contained in an existing posting
- * list tuple are implemented. (Updates are only used when there will be some
- * remaining TIDs once VACUUM finishes; otherwise the posting list tuple can
- * just be deleted).
- *
- * Updated posting list tuples are represented using xl_btree_update metadata.
- * The REDO routine uses each xl_btree_update (plus its corresponding original
- * index tuple from the target leaf page) to generate the final updated tuple.
- */
-typedef struct xl_btree_vacuum
-{
- uint16 ndeleted;
- uint16 nupdated;
-
- /* DELETED TARGET OFFSET NUMBERS FOLLOW */
- /* UPDATED TARGET OFFSET NUMBERS FOLLOW */
- /* UPDATED TUPLES METADATA ARRAY FOLLOWS */
-} xl_btree_vacuum;
-
-#define SizeOfBtreeVacuum (offsetof(xl_btree_vacuum, nupdated) + sizeof(uint16))
-
/*
* This is what we need to know about marking an empty subtree for deletion.
* The target identifies the tuple removed from the parent page (note that we
diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c
index 8ccc228a8c..95e29345de 100644
--- a/src/backend/access/common/reloptions.c
+++ b/src/backend/access/common/reloptions.c
@@ -168,6 +168,16 @@ static relopt_bool boolRelOpts[] =
},
true
},
+ {
+ {
+ "delete_items",
+ "Enables \"bottom-up index deletion\" feature for this btree index",
+ RELOPT_KIND_BTREE,
+ ShareUpdateExclusiveLock /* since it applies only to later
+ * inserts */
+ },
+ true
+ },
/* list terminator */
{{NULL}}
};
diff --git a/src/backend/access/nbtree/README b/src/backend/access/nbtree/README
index 27f555177e..ebe4408378 100644
--- a/src/backend/access/nbtree/README
+++ b/src/backend/access/nbtree/README
@@ -419,8 +419,8 @@ without a backend's cached page also being detected as invalidated, but
only when we happen to recycle a block that once again gets recycled as the
rightmost leaf page.
-On-the-Fly Deletion Of Index Tuples
------------------------------------
+On-the-Fly deletion of LP_DEAD-bit-set index tuples
+---------------------------------------------------
If a process visits a heap tuple and finds that it's dead and removable
(ie, dead to all open transactions, not only that process), then we can
@@ -439,19 +439,26 @@ from the index immediately; since index scans only stop "between" pages,
no scan can lose its place from such a deletion. We separate the steps
because we allow LP_DEAD to be set with only a share lock (it's exactly
like a hint bit for a heap tuple), but physically removing tuples requires
-exclusive lock. In the current code we try to remove LP_DEAD tuples when
-we are otherwise faced with having to split a page to do an insertion (and
-hence have exclusive lock on it already). Deduplication can also prevent
-a page split, but removing LP_DEAD tuples is the preferred approach.
-(Note that posting list tuples can only have their LP_DEAD bit set when
-every table TID within the posting list is known dead.)
+exclusive lock. Also, delaying the deletion often allows us to pick up
+extra index tuples that weren't initially safe for index scans to mark
+LP_DEAD. Live index tuples that are close to LP_DEAD-marked tuples in
+time and space are usually highly likely to become dead-to-all shortly.
+This makes workloads that greatly benefit from the LP_DEAD optimization
+resilient against intermittent disruption from long running transactions
+that hold open an MVCC snapshot (compared to the behavior prior to
+PostgreSQL 14, the version that taught the LP_DEAD deletion process to
+check if nearby index tuples are safe to delete in passing).
-This leaves the index in a state where it has no entry for a dead tuple
-that still exists in the heap. This is not a problem for the current
-implementation of VACUUM, but it could be a problem for anything that
-explicitly tries to find index entries for dead tuples. (However, the
-same situation is created by REINDEX, since it doesn't enter dead
-tuples into the index.)
+We only try to delete LP_DEAD tuples (and nearby tuples) when we are
+otherwise faced with having to split a page to do an insertion (and hence
+have exclusive lock on it already). Deduplication and bottom-up index
+deletion can also prevent a page split, but removing LP_DEAD tuples is
+always the preferred approach. (Note that posting list tuples can only
+have their LP_DEAD bit set when every table TID within the posting list is
+known dead. This isn't much of a problem because LP_DEAD deletion can
+often still do granular deletion of TIDs from a posting list. This will
+happen when the posting list tuple's TIDs point to a table block that some
+LP_DEAD-marked index tuple happens to point to.)
It's sufficient to have an exclusive lock on the index page, not a
super-exclusive lock, to do deletion of LP_DEAD items. It might seem
@@ -469,6 +476,87 @@ LSN of the page, and only act to set LP_DEAD bits when the LSN has not
changed at all. (Avoiding dropping the pin entirely also makes it safe, of
course.)
+Bottom-Up deletion
+------------------
+
+We attempt to delete whatever duplicates happen to be present on the page
+when the duplicates are suspected to be caused by version churn from
+successive UPDATEs. This only happens when we receive an executor hint
+indicating that optimizations like heapam's HOT have not worked out for
+the index -- the incoming tuple must be a logically unchanged duplicate
+which is needed for MVCC purposes, suggesting that that might well be the
+dominant source of new index tuples on the leaf page in question. (Also,
+bottom-up deletion is triggered within unique indexes in cases with
+continual INSERT and DELETE related churn, since that is easy to detect
+without any external hint.)
+
+On-the-fly deletion of LP_DEAD-bit-set items (which can include deletion
+of other close by index tuples) will already have failed to prevent a page
+split when a bottom-up deletion pass takes place (often because no LP_DEAD
+bits were ever set on the page). The two mechanisms have closely related
+implementations. The same WAL records are used for each operation, and
+the same tableam infrastructure is used to determine what TIDs/tuples are
+actually safe to delete. The implementations only differ in how they pick
+TIDs to consider for deletion, and whether or not the tableam will give up
+before accessing all table blocks (bottom-up deletion lives with the
+uncertainty of its success by keeping the cost of failure low). Even
+still, the two mechanisms are clearly distinct at the conceptual level.
+
+Bottom-up index deletion is driven entirely by heuristics (whereas
+on-the-fly deletion is guaranteed to delete at least those index tuples
+that are already LP_DEAD marked). We have no certainty that we'll find
+even one index tuple to delete. That's why we access as few tableam
+blocks as possible, and only commit to accessing the next table block in
+line when a positive outcome for the operation as a whole still looks
+likely. This means that the tableam needs to have a fairly good idea of
+how much space it has freed on the leaf page, to keep the costs and
+benefits in balance per operation (and even across successive operations
+affecting the same leaf page).
+
+Bottom-up index deletion can be thought of as a backstop mechanism against
+unnecessary version-driven page splits. It is based in part on an idea
+from generational garbage collection: the "generational hypothesis". This
+is the empirical observation that "most objects die young". Within
+nbtree, new index tuples often quickly appear in the same place, and then
+quickly become garbage. There can be intense concentrations of garbage in
+relatively few leaf pages (or there would be without the intervention of
+bottom-up deletion). This occurs with workloads that consist of skewed
+UPDATEs. There is little to lose and much to gain by spending a few
+cycles to become reasonably sure that a page split is truly necessary
+(when it seems like there is some chance of that) -- page splits are
+expensive, and practically irreversible.
+
+We expect to find a reasonably large number of tuples that are safe to
+delete within each bottom-up pass. If we don't then we won't need to
+consider the question of bottom-up deletion for the same leaf page for
+quite a while (usually because the page splits, which resolves the
+situation, at least for a while). We expect to perform regular bottom-up
+deletion operations against pages that are at constant risk of unnecessary
+page splits caused only by version churn. When the mechanism works well
+we'll constantly be "on the verge" of having version-churn-driven page
+splits, but never actually have even one.
+
+Our duplicate heuristics work well despite being fairly simple.
+Unnecessary page splits only occur when there are truly pathological
+levels of version churn (in theory a small amount of version churn could
+make a page split occur earlier than strictly necessary, but that's pretty
+harmless). We don't have to understand the underlying workload; we only
+have to understand the general nature of the pathology that we target.
+Version churn is easy to spot when it is truly pathological. Affected
+leaf pages are homogeneous.
+
+If version churn hasn't become a real problem then we don't actually want
+to do anything about it anyway (we should be lazy about cleaning it up, at
+least). All that really matters is that garbage does not become
+concentrated in any one part of the key space (the number of physical
+versions accessed by queries to read any given logical row should remain
+low over time and across all parts of the key space). Remaining garbage
+tuples can be thought of as "floating garbage" that VACUUM will eventually
+get around to removing (VACUUM can be thought of as a top-down mechanism
+that bottom-up garbage collection complements). The absolute number of
+garbage tuples (and even the proportion of all index tuples that are
+garbage) is generally much less important.
+
WAL Considerations
------------------
@@ -767,9 +855,10 @@ into a single physical tuple with a posting list (a simple array of heap
TIDs with the standard item pointer format). Deduplication is always
applied lazily, at the point where it would otherwise be necessary to
perform a page split. It occurs only when LP_DEAD items have been
-removed, as our last line of defense against splitting a leaf page. We
-can set the LP_DEAD bit with posting list tuples, though only when all
-TIDs are known dead.
+removed, as our last line of defense against splitting a leaf page
+(bottom-up index deletion may be attempted first, as our second last line
+of defense). We can set the LP_DEAD bit with posting list tuples, though
+only when all TIDs are known dead.
Our lazy approach to deduplication allows the page space accounting used
during page splits to have absolutely minimal special case logic for
@@ -826,6 +915,16 @@ delay a split that is probably inevitable anyway. This allows us to avoid
the overhead of attempting to deduplicate with unique indexes that always
have few or no duplicates.
+Note: Avoiding "unnecessary" page splits driven by version churn is also
+the goal of bottom-up index deletion, which was added to PostgreSQL 14.
+Bottom-up index deletion is now the preferred way to deal with this
+problem (with all kinds of indexes, though especially with unique
+indexes). Still, deduplication can sometimes augment bottom-up index
+deletion. When deletion cannot free tuples (due to an old snapshot
+holding up cleanup), falling back on deduplication provides additional
+capacity. Delaying the page split by deduplicating can allow a future
+bottom-up deletion pass of the same page to succeed.
+
Posting list splits
-------------------
diff --git a/src/backend/access/nbtree/nbtdedup.c b/src/backend/access/nbtree/nbtdedup.c
index 9e535124c4..a4050ddd68 100644
--- a/src/backend/access/nbtree/nbtdedup.c
+++ b/src/backend/access/nbtree/nbtdedup.c
@@ -19,6 +19,8 @@
#include "miscadmin.h"
#include "utils/rel.h"
+static void _bt_bottomup_finish_pending(Page page, TM_IndexDeleteOp *delstate,
+ BTDedupState state);
static bool _bt_do_singleval(Relation rel, Page page, BTDedupState state,
OffsetNumber minoff, IndexTuple newitem);
static void _bt_singleval_fillfactor(Page page, BTDedupState state,
@@ -267,6 +269,157 @@ _bt_dedup_pass(Relation rel, Buffer buf, Relation heapRel, IndexTuple newitem,
pfree(state);
}
+/*
+ * Perform bottom-up index deletion pass.
+ *
+ * See if duplicate index tuples are eligible to be deleted by accessing
+ * visibility information from the tableam. Give up if we have to access more
+ * than a few tableam blocks. Caller tries to avoid "unnecessary" page splits
+ * (splits driven only by version churn) by calling here when it looks like
+ * that's about to happen. It's normal for there to be a lot of calls here
+ * for pages that are constantly at risk of an unnecessary split.
+ *
+ * Each failure to delete a duplicate/promising tuple here is a kind of
+ * learning experience. It results in caller falling back on splitting the
+ * page (or on a deduplication pass), discouraging future calls back here for
+ * the same key space range covered by a failed page (or at least discouraging
+ * processing the original duplicates in case where caller falls back on a
+ * successful deduplication pass). We converge on the most effective strategy
+ * for each page in the index over time.
+ *
+ * Returns true on success, in which case caller can assume page split will be
+ * avoided for a reasonable amount of time. Returns false when caller should
+ * deduplicate the page (if possible at all).
+ *
+ * Note: occasionally a true return value does not actually indicate that any
+ * items could be deleted. It might just indicate that caller should not go
+ * on to perform a deduplication pass. Caller is not expected to care about
+ * the difference.
+ *
+ * Note: Caller should have already deleted all existing items with their
+ * LP_DEAD bits set.
+ */
+bool
+_bt_bottomup_pass(Relation rel, Buffer buf, Relation heapRel, Size newitemsz)
+{
+ OffsetNumber offnum,
+ minoff,
+ maxoff;
+ Page page = BufferGetPage(buf);
+ BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+ BTDedupState state;
+ TM_IndexDeleteOp delstate;
+ bool neverdedup = false;
+ int nkeyatts = IndexRelationGetNumberOfKeyAttributes(rel);
+
+ /* Passed-in newitemsz is MAXALIGNED but does not include line pointer */
+ newitemsz += sizeof(ItemIdData);
+
+ /* Initialize deduplication state */
+ state = (BTDedupState) palloc(sizeof(BTDedupStateData));
+ state->deduplicate = true;
+ state->nmaxitems = 0;
+ state->maxpostingsize = BLCKSZ; /* "posting list size" not a concern */
+ state->base = NULL;
+ state->baseoff = InvalidOffsetNumber;
+ state->basetupsize = 0;
+ state->htids = palloc(state->maxpostingsize);
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+ state->nintervals = 0;
+
+ /*
+ * Initialize tableam state that describes bottom-up index deletion
+ * operation.
+ *
+ * We will ask tableam to free 1/16 of BLCKSZ. We don't usually expect to
+ * have to free much space each call here in order to avoid page splits.
+ * We don't want to be too aggressive since in general the tableam will
+ * have to access more table blocks when we ask for more free space. In
+ * general we try to be conservative about what we ask for (though not too
+ * conservative), while leaving it up to the tableam to ramp up the number
+ * of tableam blocks accessed when conditions in the table structure
+ * happen to favor it.
+ *
+ * We expect to end up back here again and again for any leaf page that is
+ * more or less constantly at risk of unnecessary page splits -- in fact
+ * that's what happens when bottom-up deletion really helps. We must
+ * avoid thrashing when this becomes very frequent at the level of an
+ * individual page. Our free space target helps with that. It balances
+ * the costs and benefits over time and across related bottom-up deletion
+ * passes.
+ */
+ delstate.alltids = false; /* Only visit most promising table blocks */
+ delstate.ndeltids = 0;
+ delstate.deltids = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexDelete));
+ delstate.status = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexStatus));
+ delstate.targetfreespace = Max(BLCKSZ / 16, newitemsz);
+
+ /* Now remember details of the page in the state we'll pass to tableam */
+ minoff = P_FIRSTDATAKEY(opaque);
+ maxoff = PageGetMaxOffsetNumber(page);
+ for (offnum = minoff;
+ offnum <= maxoff;
+ offnum = OffsetNumberNext(offnum))
+ {
+ ItemId itemid = PageGetItemId(page, offnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+
+ Assert(!ItemIdIsDead(itemid));
+
+ if (offnum == minoff)
+ {
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ else if (_bt_keep_natts_fast(rel, state->base, itup) > nkeyatts &&
+ _bt_dedup_save_htid(state, itup))
+ {
+ /* Tuple is equal; just added its TIDs to pending interval */
+ }
+ else
+ {
+ /* Finalize interval -- move its TIDs to bottom-up state */
+ _bt_bottomup_finish_pending(page, &delstate, state);
+
+ /* itup starts new pending interval */
+ _bt_dedup_start_pending(state, itup, offnum);
+ }
+ }
+ /* Finalize final interval -- move its TIDs to bottom-up state */
+ _bt_bottomup_finish_pending(page, &delstate, state);
+
+ /*
+ * When there are now duplicates on the page at all, we should not tell
+ * caller to deduplicate later on.
+ *
+ * Note: We accept the possibility that there may be no promising
+ * tuples/duplicates at all (we always finish what we started). The
+ * tableam has its own heuristics that it can fall back on, so it still
+ * has some chance of success.
+ */
+ if (state->nintervals == 0)
+ neverdedup = true;
+
+ /* Done with dedup state */
+ pfree(state->htids);
+ pfree(state);
+
+ /* Confirm which TIDs are dead-to-all, then physically delete */
+ _bt_delitems_delete_check(rel, buf, heapRel, &delstate);
+
+ /* Done with deletion state */
+ pfree(delstate.deltids);
+ pfree(delstate.status);
+
+ /* Carry out earlier decision to have caller avoid deduplication now */
+ if (neverdedup)
+ return true;
+
+ /* Don't dedup when we won't end up back here any time soon anyway */
+ return PageGetExactFreeSpace(page) >= Max(BLCKSZ / 24, newitemsz);
+}
+
/*
* Create a new pending posting list tuple based on caller's base tuple.
*
@@ -452,6 +605,164 @@ _bt_dedup_finish_pending(Page newpage, BTDedupState state)
return spacesaving;
}
+/*
+ * Finalize interval during bottom-up index deletion.
+ *
+ * Determines which TIDs are to be marked promising based on heuristics.
+ */
+static void
+_bt_bottomup_finish_pending(Page page, TM_IndexDeleteOp *delstate,
+ BTDedupState state)
+{
+ bool dupinterval = (state->nitems > 1);
+
+ Assert(state->nitems > 0);
+ Assert(state->nitems <= state->nhtids);
+ Assert(state->intervals[state->nintervals].baseoff == state->baseoff);
+
+ /*
+ * All TIDs from all tuples are at least recording in state. Tuples are
+ * marked promising when they're duplicates (i.e. when they appear in an
+ * interval with more than one item, as when we expect create a new
+ * posting list tuple in the deduplication case).
+ *
+ * It's easy to see what this means in the plain non-pivot tuple case:
+ * TIDs from duplicate plain tuples are promising. Posting list tuples
+ * are more subtle. We ought to do something with posting list tuples,
+ * though plain tuples tend to be more promising targets. (Plain tuples
+ * are the most likely to be dead/deletable because they suggest version
+ * churn. And they allow us to free more space when we actually succeed).
+ */
+ for (int i = 0; i < state->nitems; i++)
+ {
+ OffsetNumber offnum = state->baseoff + i;
+ ItemId itemid = PageGetItemId(page, offnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+ TM_IndexDelete *cdeltid;
+ TM_IndexStatus *dstatus;
+
+ cdeltid = &delstate->deltids[delstate->ndeltids];
+ dstatus = &delstate->status[delstate->ndeltids];
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ /* Easy case: A plain non-pivot tuple's TID */
+ cdeltid->tid = itup->t_tid;
+ cdeltid->id = delstate->ndeltids;
+ dstatus->idxoffnum = offnum;
+ dstatus->ispromising = dupinterval;
+ dstatus->deleteitup = false; /* for now */
+ dstatus->tupsize =
+ ItemIdGetLength(itemid) + sizeof(ItemIdData);
+ delstate->ndeltids++;
+ }
+ else
+ {
+ /*
+ * Harder case: A posting list tuple's TIDs (multiple TIDs).
+ *
+ * Only a single TID from a posting list tuple may be promising,
+ * and only when it appears in a duplicate tuple (just like plain
+ * tuple case). In general there is a good chance that the
+ * posting list tuple relates to multiple logical rows, rather
+ * than multiple versions of just one logical row. (It can only
+ * be the latter case when a previous bottom-up deletion pass
+ * failed, necessitating a deduplication pass, which isn't all
+ * that common.)
+ *
+ * There is a pretty good chance that at least one of the logical
+ * rows from the posting list was updated, and so had a successor
+ * version (about as good a chance as it is in the regular tuple
+ * case, at least). We should at least try to follow the regular
+ * tuple case while making the conservative assumption that there
+ * can only be one affected logical row per posting list tuple. We
+ * do that by picking one TID when it appears to be from the
+ * predominant tableam block in the posting list (if any one
+ * tableam block predominates). The approach we take is to either
+ * choose the first or last TID in the posting list (if any at
+ * all). We go with whichever one is on the same tableam block at
+ * the middle tuple (and only the first TID when both the first
+ * and last TIDs relate to the same tableam block -- we could
+ * easily be too aggressive here).
+ *
+ * If it turns out that there are multiple old versions of a
+ * single logical table row, we still have a pretty good chance of
+ * being able to delete them this way. We don't want to give too
+ * strong a signal to the tableam. But we should always try to
+ * give some useful hints. Even cases with considerable
+ * uncertainty can consistently avoid an unnecessary page split,
+ * in part because the tableam will have tricks of its own for
+ * figuring out where to look in marginal cases.
+ */
+ int nitem = BTreeTupleGetNPosting(itup);
+ bool firstpromise = false;
+ bool lastpromise = false;
+
+ Assert(_bt_posting_valid(itup));
+
+ if (dupinterval)
+ {
+ /* Figure out if there really should be promising TIDs */
+ BlockNumber minblocklist,
+ midblocklist,
+ maxblocklist;
+ ItemPointer mintid,
+ midtid,
+ maxtid;
+
+ mintid = BTreeTupleGetHeapTID(itup);
+ midtid = BTreeTupleGetPostingN(itup, nitem / 2);
+ maxtid = BTreeTupleGetMaxHeapTID(itup);
+ minblocklist = ItemPointerGetBlockNumber(mintid);
+ midblocklist = ItemPointerGetBlockNumber(midtid);
+ maxblocklist = ItemPointerGetBlockNumber(maxtid);
+
+ firstpromise = (minblocklist == midblocklist);
+ lastpromise = (!firstpromise && midblocklist == maxblocklist);
+ }
+
+ /* No more than one TID from itup can be promising */
+ Assert(!(firstpromise && lastpromise));
+
+ for (int p = 0; p < nitem; p++)
+ {
+ ItemPointer htid = BTreeTupleGetPostingN(itup, p);
+
+ cdeltid->tid = *htid;
+ cdeltid->id = delstate->ndeltids;
+ dstatus->idxoffnum = offnum;
+ dstatus->ispromising = false;
+
+ if ((firstpromise && p == 0) ||
+ (lastpromise && p == nitem - 1))
+ dstatus->ispromising = true;
+
+ dstatus->deleteitup = false; /* for now */
+ dstatus->tupsize = sizeof(ItemPointerData) + 1;
+ delstate->ndeltids++;
+
+ cdeltid++;
+ dstatus++;
+ }
+ }
+ }
+
+ if (dupinterval)
+ {
+ /*
+ * Maintain interval state for consistency with true deduplication
+ * case
+ */
+ state->intervals[state->nintervals].nitems = state->nitems;
+ state->nintervals++;
+ }
+
+ /* Reset state for next interval */
+ state->nhtids = 0;
+ state->nitems = 0;
+ state->phystupsize = 0;
+}
+
/*
* Determine if page non-pivot tuples (data items) are all duplicates of the
* same value -- if they are, deduplication's "single value" strategy should
@@ -622,8 +933,8 @@ _bt_form_posting(IndexTuple base, ItemPointer htids, int nhtids)
* Generate a replacement tuple by "updating" a posting list tuple so that it
* no longer has TIDs that need to be deleted.
*
- * Used by VACUUM. Caller's vacposting argument points to the existing
- * posting list tuple to be updated.
+ * Used by both VACUUM and bottom-up index deletion. Caller's vacposting
+ * argument points to the existing posting list tuple to be updated.
*
* On return, caller's vacposting argument will point to final "updated"
* tuple, which will be palloc()'d in caller's memory context.
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index dde43b1415..4fc1d0001e 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -17,7 +17,6 @@
#include "access/nbtree.h"
#include "access/nbtxlog.h"
-#include "access/tableam.h"
#include "access/transam.h"
#include "access/xloginsert.h"
#include "miscadmin.h"
@@ -37,6 +36,7 @@ static TransactionId _bt_check_unique(Relation rel, BTInsertState insertstate,
static OffsetNumber _bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool indexUnchanged,
BTStack stack,
Relation heapRel);
static void _bt_stepright(Relation rel, BTInsertState insertstate, BTStack stack);
@@ -61,7 +61,13 @@ static inline bool _bt_pgaddtup(Page page, Size itemsize, IndexTuple itup,
static void _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
BTInsertState insertstate,
bool lpdeadonly, bool checkingunique,
- bool uniquedup);
+ bool uniquedup, bool indexUnchanged);
+static void _bt_lpdead_pass(Relation rel, Buffer buffer, Relation heapRel,
+ OffsetNumber *deletable, int ndeletable,
+ OffsetNumber minoff, OffsetNumber maxoff);
+static BlockNumber *_bt_lpdead_blocks(Page page, OffsetNumber *deletable,
+ int ndeletable, int *nblocks);
+static int _bt_lpdead_blocks_cmp(const void *arg1, const void *arg2);
/*
* _bt_doinsert() -- Handle insertion of a single index tuple in the tree.
@@ -75,6 +81,11 @@ static void _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
* For UNIQUE_CHECK_EXISTING we merely run the duplicate check, and
* don't actually insert.
*
+ * indexUnchanged executor hint indicates if itup is from an
+ * UPDATE that didn't logically change the indexed value, but
+ * must nevertheless have a new entry to point to a successor
+ * version.
+ *
* The result value is only significant for UNIQUE_CHECK_PARTIAL:
* it must be true if the entry is known unique, else false.
* (In the current implementation we'll also return true after a
@@ -83,7 +94,8 @@ static void _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
*/
bool
_bt_doinsert(Relation rel, IndexTuple itup,
- IndexUniqueCheck checkUnique, Relation heapRel)
+ IndexUniqueCheck checkUnique, bool indexUnchanged,
+ Relation heapRel)
{
bool is_unique = false;
BTInsertStateData insertstate;
@@ -238,7 +250,7 @@ search:
* checkingunique.
*/
newitemoff = _bt_findinsertloc(rel, &insertstate, checkingunique,
- stack, heapRel);
+ indexUnchanged, stack, heapRel);
_bt_insertonpg(rel, itup_key, insertstate.buf, InvalidBuffer, stack,
itup, insertstate.itemsz, newitemoff,
insertstate.postingoff, false);
@@ -777,6 +789,17 @@ _bt_check_unique(Relation rel, BTInsertState insertstate, Relation heapRel,
* room for the new tuple, this function moves right, trying to find a
* legal page that does.)
*
+ * If 'indexUnchanged' is true, this is for an UPDATE that didn't
+ * logically change the indexed value, but must nevertheless have a new
+ * entry to point to a successor version. This hint from the executor
+ * will influence our behavior when the page might have to be split and
+ * we must consider our options. Bottom-up index deletion can avoid
+ * pathological version-driven page splits, but we only want to go to the
+ * trouble of trying it when we already have moderate confidence that
+ * it's appropriate. The hint should not significantly affect our
+ * behavior over time unless practically all inserts on to the leaf page
+ * get the hint.
+ *
* On exit, insertstate buffer contains the chosen insertion page, and
* the offset within that page is returned. If _bt_findinsertloc needed
* to move right, the lock and pin on the original page are released, and
@@ -793,6 +816,7 @@ static OffsetNumber
_bt_findinsertloc(Relation rel,
BTInsertState insertstate,
bool checkingunique,
+ bool indexUnchanged,
BTStack stack,
Relation heapRel)
{
@@ -817,7 +841,7 @@ _bt_findinsertloc(Relation rel,
if (itup_key->heapkeyspace)
{
/* Keep track of whether checkingunique duplicate seen */
- bool uniquedup = false;
+ bool uniquedup = indexUnchanged;
/*
* If we're inserting into a unique index, we may have to walk right
@@ -881,7 +905,8 @@ _bt_findinsertloc(Relation rel,
*/
if (PageGetFreeSpace(page) < insertstate->itemsz)
_bt_delete_or_dedup_one_page(rel, heapRel, insertstate, false,
- checkingunique, uniquedup);
+ checkingunique, uniquedup,
+ indexUnchanged);
}
else
{
@@ -923,7 +948,8 @@ _bt_findinsertloc(Relation rel,
{
/* Erase LP_DEAD items (won't deduplicate) */
_bt_delete_or_dedup_one_page(rel, heapRel, insertstate, true,
- checkingunique, false);
+ checkingunique, false,
+ indexUnchanged);
if (PageGetFreeSpace(page) >= insertstate->itemsz)
break; /* OK, now we have enough space */
@@ -977,7 +1003,7 @@ _bt_findinsertloc(Relation rel,
* This can only erase LP_DEAD items (it won't deduplicate).
*/
_bt_delete_or_dedup_one_page(rel, heapRel, insertstate, true,
- checkingunique, false);
+ checkingunique, false, indexUnchanged);
/*
* Do new binary search. New insert location cannot overlap with any
@@ -2609,15 +2635,24 @@ _bt_pgaddtup(Page page,
* _bt_delete_or_dedup_one_page - Try to avoid a leaf page split by attempting
* a variety of operations.
*
- * There are two operations performed here: deleting items already marked
- * LP_DEAD, and deduplication. If both operations fail to free enough space
- * for the incoming item then caller will go on to split the page. We always
- * attempt our preferred strategy (which is to delete items whose LP_DEAD bit
- * are set) first. If that doesn't work out we move on to deduplication.
+ * There are three operations performed here: deleting items already marked
+ * LP_DEAD, bottom-up index deletion, and deduplication. If all three
+ * operations fail to free enough space for the incoming item then caller will
+ * go on to split the page. We always attempt our preferred strategy (which
+ * is to delete items whose LP_DEAD bit are set) first. If that doesn't work
+ * out we consider alternatives. Most calls here will not exhaustively
+ * attempt all three operations. Deduplication and bottom-up index deletion
+ * are relatively expensive operations, so we try to pick one or the other up
+ * front (whichever one seems better for this specific page).
*
- * Caller's checkingunique and uniquedup arguments help us decide if we should
- * perform deduplication, which is primarily useful with low cardinality data,
- * but can sometimes absorb version churn.
+ * Caller's checkingunique, uniquedup, and indexUnchanged arguments help us
+ * decide which alternative strategy we should attempt (or attempt first).
+ * Deduplication is primarily useful with low cardinality data. Bottom-up
+ * index deletion is a backstop against version churn caused by repeated
+ * UPDATE statements where affected indexes don't receive logical changes
+ * (because an optimization like heapam's HOT cannot be applied in the
+ * tableam). But useful interplay between both techniques over time is
+ * sometimes possible.
*
* Callers that only want us to look for/delete LP_DEAD items can ask for that
* directly by passing true 'lpdeadonly' argument.
@@ -2639,11 +2674,12 @@ static void
_bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
BTInsertState insertstate,
bool lpdeadonly, bool checkingunique,
- bool uniquedup)
+ bool uniquedup, bool indexUnchanged)
{
OffsetNumber deletable[MaxIndexTuplesPerPage];
int ndeletable = 0;
OffsetNumber offnum,
+ minoff,
maxoff;
Buffer buffer = insertstate->buf;
BTScanInsert itup_key = insertstate->itup_key;
@@ -2657,8 +2693,9 @@ _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
* Scan over all items to see which ones need to be deleted according to
* LP_DEAD flags.
*/
+ minoff = P_FIRSTDATAKEY(opaque);
maxoff = PageGetMaxOffsetNumber(page);
- for (offnum = P_FIRSTDATAKEY(opaque);
+ for (offnum = minoff;
offnum <= maxoff;
offnum = OffsetNumberNext(offnum))
{
@@ -2670,7 +2707,8 @@ _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
if (ndeletable > 0)
{
- _bt_delitems_delete(rel, buffer, deletable, ndeletable, heapRel);
+ _bt_lpdead_pass(rel, buffer, heapRel, deletable, ndeletable,
+ minoff, maxoff);
insertstate->bounds_valid = false;
/* Return when a page split has already been avoided */
@@ -2689,18 +2727,19 @@ _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
* return at this point (or when we go on the try either or both of our
* other strategies and they also fail). We do not bother expending a
* separate write to clear it, however. Caller will definitely clear it
- * when it goes on to split the page (plus deduplication knows to clear
- * the flag when it actually modifies the page).
+ * when it goes on to split the page (note also that deduplication process
+ * knows to clear the flag when it actually modifies the page).
*/
if (lpdeadonly)
return;
/*
* We can get called in the checkingunique case when there is no reason to
- * believe that there are any duplicates on the page; we should at least
- * still check for LP_DEAD items. If that didn't work out, give up and
- * let caller split the page. Deduplication cannot be justified given
- * there is no reason to think that there are duplicates.
+ * believe that there are any duplicates on the page; we just needed to
+ * check for LP_DEAD items. When we were called under these circumstances
+ * and get this far, LP_DEAD item deletion didn't work out, and so we give
+ * up and let caller split the page. (A bottom-up pass or deduplication
+ * pass are also unlikely to work out.)
*/
if (checkingunique && !uniquedup)
return;
@@ -2708,6 +2747,22 @@ _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
/* Assume bounds about to be invalidated (this is almost certain now) */
insertstate->bounds_valid = false;
+ /*
+ * Perform bottom-up index deletion pass when executor hint indicated that
+ * incoming item is logically unchanged, or for a unique index that is
+ * known to have physical duplicates for some other reason. (There is a
+ * large overlap between these two cases for a unique index. It's worth
+ * having both triggering conditions in order to apply the optimization in
+ * the event of successive related INSERT and DELETE statements.)
+ *
+ * We'll go on to do a deduplication pass when a bottom-up pass fails to
+ * delete an acceptable amount of free space (a non-trivial fraction of
+ * the page that exceeds the new item's size).
+ */
+ if (BTGetDeleteItems(rel) && (indexUnchanged || uniquedup) &&
+ _bt_bottomup_pass(rel, buffer, heapRel, insertstate->itemsz))
+ return;
+
/*
* Perform deduplication pass, though only when it is enabled for the
* index and known to be safe (it must be an allequalimage index).
@@ -2716,3 +2771,244 @@ _bt_delete_or_dedup_one_page(Relation rel, Relation heapRel,
_bt_dedup_pass(rel, buffer, heapRel, insertstate->itup,
insertstate->itemsz, checkingunique);
}
+
+/*
+ * _bt_lpdead_pass - Try to avoid a leaf page split by deleting LP_DEAD-set
+ * index tuples, as well as any other nearby tuples that are convenient to
+ * delete in passing.
+ *
+ * The tableam can inexpensively check extra index tuples whose TIDs happen to
+ * point to the same table blocks as a TID from an LP_DEAD-marked tuple's TID.
+ * This routine is responsible for gathering TIDs from LP_DEAD-marked index
+ * tuples (which are surely deletable) alongside index tuples with same-block
+ * TIDs (which are totally speculative) for processing by tableam. Physical
+ * deletion of the final known-safe TIDs from the leaf page takes place at the
+ * end.
+ *
+ * In practice it is often possible to delete at least a few extra tuples here
+ * for indexUnchanged callers. This will happen when LP_DEAD bit setting was
+ * temporarily disrupted by some transaction that held open an MVCC snapshot
+ * for a relatively long time; we can pick up newer version-duplicate index
+ * tuples that couldn't have their LP_DEAD bits set by UPDATEs, provided
+ * they're on the same tableam block as earlier versions that were marked (and
+ * provided the snapshot is no longer held open by now). We don't try to be
+ * clever, though. We simply focus on extra tuples that are practically free
+ * to check in passing. In practice the number of extra index tuples that
+ * turn out to be deletable often greatly exceeds the number of LP_DEAD-marked
+ * index tuples.
+ */
+static void
+_bt_lpdead_pass(Relation rel, Buffer buffer, Relation heapRel,
+ OffsetNumber *deletable, int ndeletable,
+ OffsetNumber minoff, OffsetNumber maxoff)
+{
+ Page page = BufferGetPage(buffer);
+ TM_IndexDeleteOp delstate;
+ BlockNumber *blocks;
+ int nblocks;
+ OffsetNumber offnum;
+
+ blocks = _bt_lpdead_blocks(page, deletable, ndeletable, &nblocks);
+
+ delstate.alltids = true; /* Not doing bottom-up deletion */
+ delstate.ndeltids = 0;
+ delstate.deltids = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexDelete));
+ delstate.status = palloc(MaxTIDsPerBTreePage * sizeof(TM_IndexStatus));
+ delstate.targetfreespace = 0; /* Visiting all table blocks anyway */
+
+ for (offnum = minoff;
+ offnum <= maxoff;
+ offnum = OffsetNumberNext(offnum))
+ {
+ ItemId itemid = PageGetItemId(page, offnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+ TM_IndexDelete *cdeltid;
+ TM_IndexStatus *dstatus;
+ BlockNumber tidblock;
+ BlockNumber *match;
+
+ cdeltid = &delstate.deltids[delstate.ndeltids];
+ dstatus = &delstate.status[delstate.ndeltids];
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ /* Plain non-pivot tuple's TID */
+ tidblock = ItemPointerGetBlockNumber(&itup->t_tid);
+
+ match = (BlockNumber *) bsearch(&tidblock, blocks, nblocks,
+ sizeof(BlockNumber),
+ _bt_lpdead_blocks_cmp);
+
+ if (!match)
+ continue;
+
+ /*
+ * TID has heap block among those pointed to by LP_DEAD-bit set
+ * tuples on leaf page
+ */
+ cdeltid->tid = itup->t_tid;
+ cdeltid->id = delstate.ndeltids;
+ dstatus->idxoffnum = offnum;
+ dstatus->ispromising = false; /* irrelevant */
+ dstatus->deleteitup = ItemIdIsDead(itemid); /* for now */
+ dstatus->tupsize = 1; /* irrelevant */
+ delstate.ndeltids++;
+ }
+ else
+ {
+ int nitem = BTreeTupleGetNPosting(itup);
+
+ for (int p = 0; p < nitem; p++)
+ {
+ ItemPointer htid = BTreeTupleGetPostingN(itup, p);
+
+ tidblock = ItemPointerGetBlockNumber(htid);
+
+ match = (BlockNumber *) bsearch(&tidblock, blocks, nblocks,
+ sizeof(BlockNumber),
+ _bt_lpdead_blocks_cmp);
+
+ if (!match)
+ continue;
+
+ /*
+ * TID has heap block among those pointed to by LP_DEAD-bit
+ * set tuples on leaf page
+ */
+ cdeltid->tid = *htid;
+ cdeltid->id = delstate.ndeltids;
+ dstatus->idxoffnum = offnum;
+ dstatus->ispromising = false; /* irrelevant */
+ dstatus->deleteitup = ItemIdIsDead(itemid); /* for now */
+ dstatus->tupsize = 1; /* irrelevant */
+ delstate.ndeltids++;
+
+ cdeltid++;
+ dstatus++;
+ }
+ }
+ }
+
+ Assert(delstate.ndeltids >= ndeletable);
+
+ /* Physically delete LP_DEAD tuples (plus extra dead-to-all TIDs) */
+ _bt_delitems_delete_check(rel, buffer, heapRel, &delstate);
+
+ /* be tidy */
+ pfree(blocks);
+ pfree(delstate.deltids);
+ pfree(delstate.status);
+}
+
+/*
+ * _bt_lpdead_blocks() -- Build a list of LP_DEAD related table blocks
+ *
+ * Build a list of those blocks pointed to by index tuples that caller found
+ * had their LP_DEAD bits set. Used by _bt_lpdead_pass to delete extra nearby
+ * tuples that are convenient to delete in passing.
+ */
+static BlockNumber *
+_bt_lpdead_blocks(Page page, OffsetNumber *deletable, int ndeletable,
+ int *nblocks)
+{
+ int spacenhtids;
+ int nhtids;
+ ItemPointer htids;
+ BlockNumber *blocks;
+ BlockNumber lastblock = InvalidBlockNumber;
+
+ /* Array will grow iff there are posting list tuples to consider */
+ spacenhtids = ndeletable;
+ nhtids = 0;
+ htids = (ItemPointer) palloc(sizeof(ItemPointerData) * spacenhtids);
+ for (int i = 0; i < ndeletable; i++)
+ {
+ ItemId itemid;
+ IndexTuple itup;
+
+ itemid = PageGetItemId(page, deletable[i]);
+ itup = (IndexTuple) PageGetItem(page, itemid);
+
+ Assert(ItemIdIsDead(itemid));
+ Assert(!BTreeTupleIsPivot(itup));
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ if (nhtids + 1 > spacenhtids)
+ {
+ spacenhtids *= 2;
+ htids = (ItemPointer)
+ repalloc(htids, sizeof(ItemPointerData) * spacenhtids);
+ }
+
+ Assert(ItemPointerIsValid(&itup->t_tid));
+ ItemPointerCopy(&itup->t_tid, &htids[nhtids]);
+ nhtids++;
+ }
+ else
+ {
+ int nposting = BTreeTupleGetNPosting(itup);
+
+ if (nhtids + nposting > spacenhtids)
+ {
+ spacenhtids = Max(spacenhtids * 2, nhtids + nposting);
+ htids = (ItemPointer)
+ repalloc(htids, sizeof(ItemPointerData) * spacenhtids);
+ }
+
+ for (int j = 0; j < nposting; j++)
+ {
+ ItemPointer htid = BTreeTupleGetPostingN(itup, j);
+
+ Assert(ItemPointerIsValid(htid));
+ ItemPointerCopy(htid, &htids[nhtids]);
+ nhtids++;
+ }
+ }
+ }
+
+ Assert(nhtids >= ndeletable);
+
+ qsort((void *) htids, nhtids, sizeof(ItemPointerData),
+ (int (*) (const void *, const void *)) ItemPointerCompare);
+
+ blocks = palloc(sizeof(BlockNumber) * nhtids);
+ *nblocks = 0;
+
+ for (int i = 0; i < nhtids; i++)
+ {
+ ItemPointer tid = htids + i;
+ BlockNumber tidblock = ItemPointerGetBlockNumber(tid);
+
+ if (tidblock == lastblock)
+ continue;
+
+ lastblock = tidblock;
+ blocks[*nblocks] = tidblock;
+ (*nblocks)++;
+ }
+
+ pfree(htids);
+
+ return blocks;
+}
+
+/*
+ * _bt_lpdead_blocks_cmp() -- BlockNumber comparator
+ *
+ * Used by _bt_lpdead_pass to search through its list of table blocks that are
+ * known to be pointed to by TIDs in LP_DEAD-marked index tuples.
+ */
+static int
+_bt_lpdead_blocks_cmp(const void *arg1, const void *arg2)
+{
+ BlockNumber b1 = *((BlockNumber *) arg1);
+ BlockNumber b2 = *((BlockNumber *) arg2);
+
+ if (b1 < b2)
+ return -1;
+ else if (b1 > b2)
+ return 1;
+
+ return 0;
+}
diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c
index 848123d921..63d2694d89 100644
--- a/src/backend/access/nbtree/nbtpage.c
+++ b/src/backend/access/nbtree/nbtpage.c
@@ -38,8 +38,15 @@
static BTMetaPageData *_bt_getmeta(Relation rel, Buffer metabuf);
static void _bt_log_reuse_page(Relation rel, BlockNumber blkno,
TransactionId latestRemovedXid);
-static TransactionId _bt_xid_horizon(Relation rel, Relation heapRel, Page page,
- OffsetNumber *deletable, int ndeletable);
+static void _bt_delitems_delete(Relation rel, Buffer buf,
+ TransactionId latestRemovedXid,
+ OffsetNumber *deletable, int ndeletable,
+ BTVacuumPosting *updatable, int nupdatable,
+ Relation heapRel);
+static char *_bt_delitems_updates(BTVacuumPosting *updatable, int nupdatable,
+ OffsetNumber *updatedoffsets,
+ Size *updatedbuflen,
+ bool needswal);
static bool _bt_mark_page_halfdead(Relation rel, Buffer leafbuf,
BTStack stack);
static bool _bt_unlink_halfdead_page(Relation rel, Buffer leafbuf,
@@ -1110,15 +1117,15 @@ _bt_page_recyclable(Page page)
* sorted in ascending order.
*
* Routine deals with deleting TIDs when some (but not all) of the heap TIDs
- * in an existing posting list item are to be removed by VACUUM. This works
- * by updating/overwriting an existing item with caller's new version of the
- * item (a version that lacks the TIDs that are to be deleted).
+ * in an existing posting list item are to be removed. This works by
+ * updating/overwriting an existing item with caller's new version of the item
+ * (a version that lacks the TIDs that are to be deleted).
*
* We record VACUUMs and b-tree deletes differently in WAL. Deletes must
- * generate their own latestRemovedXid by accessing the heap directly, whereas
- * VACUUMs rely on the initial heap scan taking care of it indirectly. Also,
- * only VACUUM can perform granular deletes of individual TIDs in posting list
- * tuples.
+ * generate their own latestRemovedXid by accessing the table directly,
+ * whereas VACUUMs rely on the initial heap scan taking care of it indirectly.
+ * Also, we remove the VACUUM cycle ID from pages, which b-tree deletes don't
+ * do.
*/
void
_bt_delitems_vacuum(Relation rel, Buffer buf,
@@ -1127,7 +1134,7 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
{
Page page = BufferGetPage(buf);
BTPageOpaque opaque;
- Size itemsz;
+ bool needswal = RelationNeedsWAL(rel);
char *updatedbuf = NULL;
Size updatedbuflen = 0;
OffsetNumber updatedoffsets[MaxIndexTuplesPerPage];
@@ -1135,45 +1142,11 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
/* Shouldn't be called unless there's something to do */
Assert(ndeletable > 0 || nupdatable > 0);
- for (int i = 0; i < nupdatable; i++)
- {
- /* Replace work area IndexTuple with updated version */
- _bt_update_posting(updatable[i]);
-
- /* Maintain array of updatable page offsets for WAL record */
- updatedoffsets[i] = updatable[i]->updatedoffset;
- }
-
- /* XLOG stuff -- allocate and fill buffer before critical section */
- if (nupdatable > 0 && RelationNeedsWAL(rel))
- {
- Size offset = 0;
-
- for (int i = 0; i < nupdatable; i++)
- {
- BTVacuumPosting vacposting = updatable[i];
-
- itemsz = SizeOfBtreeUpdate +
- vacposting->ndeletedtids * sizeof(uint16);
- updatedbuflen += itemsz;
- }
-
- updatedbuf = palloc(updatedbuflen);
- for (int i = 0; i < nupdatable; i++)
- {
- BTVacuumPosting vacposting = updatable[i];
- xl_btree_update update;
-
- update.ndeletedtids = vacposting->ndeletedtids;
- memcpy(updatedbuf + offset, &update.ndeletedtids,
- SizeOfBtreeUpdate);
- offset += SizeOfBtreeUpdate;
-
- itemsz = update.ndeletedtids * sizeof(uint16);
- memcpy(updatedbuf + offset, vacposting->deletetids, itemsz);
- offset += itemsz;
- }
- }
+ /* Generate new version of posting lists without deleted TIDs */
+ if (nupdatable > 0)
+ updatedbuf = _bt_delitems_updates(updatable, nupdatable,
+ updatedoffsets, &updatedbuflen,
+ needswal);
/* No ereport(ERROR) until changes are logged */
START_CRIT_SECTION();
@@ -1194,6 +1167,7 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
{
OffsetNumber updatedoffset = updatedoffsets[i];
IndexTuple itup;
+ Size itemsz;
itup = updatable[i]->itup;
itemsz = MAXALIGN(IndexTupleSize(itup));
@@ -1227,7 +1201,7 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
MarkBufferDirty(buf);
/* XLOG stuff */
- if (RelationNeedsWAL(rel))
+ if (needswal)
{
XLogRecPtr recptr;
xl_btree_vacuum xlrec_vacuum;
@@ -1260,7 +1234,7 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
/* can't leak memory here */
if (updatedbuf != NULL)
pfree(updatedbuf);
- /* free tuples generated by calling _bt_update_posting() */
+ /* free tuples allocated within _bt_delitems_updates() */
for (int i = 0; i < nupdatable; i++)
pfree(updatable[i]->itup);
}
@@ -1269,36 +1243,70 @@ _bt_delitems_vacuum(Relation rel, Buffer buf,
* Delete item(s) from a btree leaf page during single-page cleanup.
*
* This routine assumes that the caller has pinned and write locked the
- * buffer. Also, the given deletable array *must* be sorted in ascending
- * order.
+ * buffer. Also, the given deletable and updatable arrays *must* be sorted in
+ * ascending order.
+ *
+ * Routine deals with deleting TIDs when some (but not all) of the heap TIDs
+ * in an existing posting list item are to be removed. This works by
+ * updating/overwriting an existing item with caller's new version of the item
+ * (a version that lacks the TIDs that are to be deleted).
*
* This is nearly the same as _bt_delitems_vacuum as far as what it does to
- * the page, but it needs to generate its own latestRemovedXid by accessing
- * the heap. This is used by the REDO routine to generate recovery conflicts.
- * Also, it doesn't handle posting list tuples unless the entire tuple can be
- * deleted as a whole (since there is only one LP_DEAD bit per line pointer).
+ * the page, but it needs its own latestRemovedXid from called (caller gets
+ * this from tableam). This is used by the REDO routine to generate recovery
+ * conflicts. The other difference is that _bt_delitems_vacuum will clear
+ * page's VACUUM cycle ID. We must never do that.
*/
-void
-_bt_delitems_delete(Relation rel, Buffer buf,
+static void
+_bt_delitems_delete(Relation rel, Buffer buf, TransactionId latestRemovedXid,
OffsetNumber *deletable, int ndeletable,
+ BTVacuumPosting *updatable, int nupdatable,
Relation heapRel)
{
Page page = BufferGetPage(buf);
BTPageOpaque opaque;
- TransactionId latestRemovedXid = InvalidTransactionId;
+ bool needswal = RelationNeedsWAL(rel);
+ char *updatedbuf = NULL;
+ Size updatedbuflen = 0;
+ OffsetNumber updatedoffsets[MaxIndexTuplesPerPage];
/* Shouldn't be called unless there's something to do */
- Assert(ndeletable > 0);
+ Assert(ndeletable > 0 || nupdatable > 0);
- if (XLogStandbyInfoActive() && RelationNeedsWAL(rel))
- latestRemovedXid =
- _bt_xid_horizon(rel, heapRel, page, deletable, ndeletable);
+ /* Generate new versions of posting lists without deleted TIDs */
+ if (nupdatable > 0)
+ updatedbuf = _bt_delitems_updates(updatable, nupdatable,
+ updatedoffsets, &updatedbuflen,
+ needswal);
/* No ereport(ERROR) until changes are logged */
START_CRIT_SECTION();
- /* Fix the page */
- PageIndexMultiDelete(page, deletable, ndeletable);
+ /*
+ * Handle posting tuple updates.
+ *
+ * Deliberately do this before handling simple deletes. If we did it the
+ * other way around (i.e. WAL record order -- simple deletes before
+ * updates) then we'd have to make compensating changes to the 'updatable'
+ * array of offset numbers.
+ */
+ for (int i = 0; i < nupdatable; i++)
+ {
+ OffsetNumber updatedoffset = updatedoffsets[i];
+ IndexTuple itup;
+ Size itemsz;
+
+ itup = updatable[i]->itup;
+ itemsz = MAXALIGN(IndexTupleSize(itup));
+ if (!PageIndexTupleOverwrite(page, updatedoffset, (Item) itup,
+ itemsz))
+ elog(PANIC, "failed to update partially dead item in block %u of index \"%s\"",
+ BufferGetBlockNumber(buf), RelationGetRelationName(rel));
+ }
+
+ /* Now handle simple deletes of entire tuples */
+ if (ndeletable > 0)
+ PageIndexMultiDelete(page, deletable, ndeletable);
/*
* Unlike _bt_delitems_vacuum, we *must not* clear the vacuum cycle ID,
@@ -1318,25 +1326,29 @@ _bt_delitems_delete(Relation rel, Buffer buf,
MarkBufferDirty(buf);
/* XLOG stuff */
- if (RelationNeedsWAL(rel))
+ if (needswal)
{
XLogRecPtr recptr;
xl_btree_delete xlrec_delete;
xlrec_delete.latestRemovedXid = latestRemovedXid;
xlrec_delete.ndeleted = ndeletable;
+ xlrec_delete.nupdated = nupdatable;
XLogBeginInsert();
XLogRegisterBuffer(0, buf, REGBUF_STANDARD);
XLogRegisterData((char *) &xlrec_delete, SizeOfBtreeDelete);
- /*
- * The deletable array is not in the buffer, but pretend that it is.
- * When XLogInsert stores the whole buffer, the array need not be
- * stored too.
- */
- XLogRegisterBufData(0, (char *) deletable,
- ndeletable * sizeof(OffsetNumber));
+ if (ndeletable > 0)
+ XLogRegisterBufData(0, (char *) deletable,
+ ndeletable * sizeof(OffsetNumber));
+
+ if (nupdatable > 0)
+ {
+ XLogRegisterBufData(0, (char *) updatedoffsets,
+ nupdatable * sizeof(OffsetNumber));
+ XLogRegisterBufData(0, updatedbuf, updatedbuflen);
+ }
recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_DELETE);
@@ -1344,83 +1356,299 @@ _bt_delitems_delete(Relation rel, Buffer buf,
}
END_CRIT_SECTION();
+
+ /* can't leak memory here */
+ if (updatedbuf != NULL)
+ pfree(updatedbuf);
+ /* free tuples allocated within _bt_delitems_updates() */
+ for (int i = 0; i < nupdatable; i++)
+ pfree(updatable[i]->itup);
}
/*
- * Get the latestRemovedXid from the table entries pointed to by the non-pivot
- * tuples being deleted.
+ * Set up state needed to delete TIDs from posting list tuples via "updating"
+ * the tuple. Performs steps common to both _bt_delitems_vacuum and
+ * _bt_delitems_delete. These steps must take place before each function's
+ * critical section begins.
*
- * This is a specialized version of index_compute_xid_horizon_for_tuples().
- * It's needed because btree tuples don't always store table TID using the
- * standard index tuple header field.
+ * updatabable and nupdatable are inputs, though note that we will use
+ * _bt_update_posting() to replace the original itup with a pointer to a final
+ * version in palloc()'d memory. Caller should free the tuples when its done.
+ *
+ * The first nupdatable entries from updatedoffsets are set to the page offset
+ * number for posting list tuples that caller updates. This is mostly useful
+ * because caller may need to WAL-log the page offsets (though we always do
+ * this for caller out of convenience).
+ *
+ * Returns buffer consisting of an array of xl_btree_update structs that
+ * describe the steps we perform here for caller (though only when needswal is
+ * true). Also sets *updatedbuflen to the final size of the buffer. This
+ * buffer is used by caller when WAL logging is required.
*/
-static TransactionId
-_bt_xid_horizon(Relation rel, Relation heapRel, Page page,
- OffsetNumber *deletable, int ndeletable)
+static char *
+_bt_delitems_updates(BTVacuumPosting *updatable, int nupdatable,
+ OffsetNumber *updatedoffsets, Size *updatedbuflen,
+ bool needswal)
{
- TransactionId latestRemovedXid = InvalidTransactionId;
- int spacenhtids;
- int nhtids;
- ItemPointer htids;
+ char *updatedbuf = NULL;
+ Size buflen = 0;
- /* Array will grow iff there are posting list tuples to consider */
- spacenhtids = ndeletable;
- nhtids = 0;
- htids = (ItemPointer) palloc(sizeof(ItemPointerData) * spacenhtids);
- for (int i = 0; i < ndeletable; i++)
+ /* Shouldn't be called unless there's something to do */
+ Assert(nupdatable > 0);
+
+ for (int i = 0; i < nupdatable; i++)
{
- ItemId itemid;
- IndexTuple itup;
+ BTVacuumPosting vacposting = updatable[i];
+ Size itemsz;
- itemid = PageGetItemId(page, deletable[i]);
- itup = (IndexTuple) PageGetItem(page, itemid);
+ /* Replace work area IndexTuple with updated version */
+ _bt_update_posting(vacposting);
- Assert(ItemIdIsDead(itemid));
- Assert(!BTreeTupleIsPivot(itup));
+ /* Keep track of size of xl_btree_update for updatedbuf in passing */
+ itemsz = SizeOfBtreeUpdate + vacposting->ndeletedtids * sizeof(uint16);
+ buflen += itemsz;
- if (!BTreeTupleIsPosting(itup))
+ /* Build updatedoffsets buffer in passing */
+ updatedoffsets[i] = vacposting->updatedoffset;
+ }
+
+ /* XLOG stuff */
+ if (needswal)
+ {
+ Size offset = 0;
+
+ /* Allocate, set final size for caller */
+ updatedbuf = palloc(buflen);
+ *updatedbuflen = buflen;
+ for (int i = 0; i < nupdatable; i++)
{
- if (nhtids + 1 > spacenhtids)
- {
- spacenhtids *= 2;
- htids = (ItemPointer)
- repalloc(htids, sizeof(ItemPointerData) * spacenhtids);
- }
+ BTVacuumPosting vacposting = updatable[i];
+ Size itemsz;
+ xl_btree_update update;
- Assert(ItemPointerIsValid(&itup->t_tid));
- ItemPointerCopy(&itup->t_tid, &htids[nhtids]);
- nhtids++;
- }
- else
- {
- int nposting = BTreeTupleGetNPosting(itup);
+ update.ndeletedtids = vacposting->ndeletedtids;
+ memcpy(updatedbuf + offset, &update.ndeletedtids,
+ SizeOfBtreeUpdate);
+ offset += SizeOfBtreeUpdate;
- if (nhtids + nposting > spacenhtids)
- {
- spacenhtids = Max(spacenhtids * 2, nhtids + nposting);
- htids = (ItemPointer)
- repalloc(htids, sizeof(ItemPointerData) * spacenhtids);
- }
-
- for (int j = 0; j < nposting; j++)
- {
- ItemPointer htid = BTreeTupleGetPostingN(itup, j);
-
- Assert(ItemPointerIsValid(htid));
- ItemPointerCopy(htid, &htids[nhtids]);
- nhtids++;
- }
+ itemsz = update.ndeletedtids * sizeof(uint16);
+ memcpy(updatedbuf + offset, vacposting->deletetids, itemsz);
+ offset += itemsz;
}
}
- Assert(nhtids >= ndeletable);
+ return updatedbuf;
+}
- latestRemovedXid =
- table_compute_xid_horizon_for_tuples(heapRel, htids, nhtids);
+/*
+ * Comparator used by _bt_delitems_delete_check() to restore deltids array
+ * back to its original leaf-page-wise sort order
+ */
+static int
+_bt_delitems_cmp(const void *a, const void *b)
+{
+ TM_IndexDelete *indexdelete1 = (TM_IndexDelete *) a;
+ TM_IndexDelete *indexdelete2 = (TM_IndexDelete *) b;
- pfree(htids);
+ if (indexdelete1->id > indexdelete2->id)
+ return 1;
+ if (indexdelete1->id < indexdelete2->id)
+ return -1;
- return latestRemovedXid;
+ Assert(false);
+
+ return 0;
+}
+
+/*
+ * Try to delete item(s) from a btree leaf page during single-page cleanup.
+ *
+ * nbtree interface to table_index_delete_check(). Deletes a subset of index
+ * tuples that caller suspects to be dead-to-all: those that are actually
+ * dead-to-all, and therefore safe to delete. Used by bottom-up index
+ * deletion.
+ *
+ * Simple deletion of LP_DEAD-set index tuples caller goes through here too.
+ * It used to call _bt_delitems_delete() directly, but using this interface
+ * has distinct advantages. It often allows us to delete some extra index
+ * tuples that happen to be dead-to-all and happen to have not had their
+ * LP_DEAD bit set in passing (LP_DEAD caller includes these extra TIDs in
+ * delstate). The extra cost of this approach is acceptable because a
+ * latestRemovedXid value will be needed anyway. It will need to be acquired
+ * by visiting all relevant table blocks again, so including extra TIDs is
+ * cheap. (Actually, it's only strictly necessary to get a latestRemovedXid
+ * with logged indexes. LP_DEAD deletion still uses this approach in all
+ * cases, just to be consistent.)
+ *
+ * Note: We rely on the assumption that the delstate.deltids array is sorted
+ * on its id field, which is a proxy for the original leaf-page-wise order of
+ * index tuples. Caller must gather items in delstate in the natural way:
+ * through appending each TID that we consider in leaf-page-wise order.
+ */
+void
+_bt_delitems_delete_check(Relation rel, Buffer buf, Relation heapRel,
+ TM_IndexDeleteOp *delstate)
+{
+ Page page = BufferGetPage(buf);
+ TransactionId latestRemovedXid;
+ OffsetNumber postingidxoffnum;
+ int ndeletable,
+ nupdatable;
+ OffsetNumber deletable[MaxIndexTuplesPerPage];
+ BTVacuumPosting updatable[MaxIndexTuplesPerPage];
+
+ /*
+ * Use tableam interface to determine which tuples to delete first.
+ *
+ * There is a good chance that accessing table block buffers won't result
+ * in any misses. Temporal locality is important here.
+ */
+ latestRemovedXid = table_index_delete_check(heapRel, delstate);
+
+ /* The tableam may have nothing (though only for bottom-up caller) */
+ if (delstate->ndeltids == 0)
+ return;
+
+ /* Don't need to WAL-log latestRemovedXid in all cases */
+ if (!XLogStandbyInfoActive() || !RelationNeedsWAL(rel))
+ latestRemovedXid = InvalidTransactionId;
+
+ /*
+ * Construct a leaf-page-wise description of what _bt_delitems_delete()
+ * needs to do to physically delete index tuples from the page.
+ *
+ * Must sort deltids array (which is typically much smaller now) first.
+ * It must match the order expected by loop: leaf-page-wise order.
+ */
+ qsort(delstate->deltids, delstate->ndeltids, sizeof(TM_IndexDelete),
+ _bt_delitems_cmp);
+ postingidxoffnum = InvalidOffsetNumber;
+ ndeletable = 0;
+ nupdatable = 0;
+ for (int i = 0; i < delstate->ndeltids; i++)
+ {
+ TM_IndexStatus *dstatus = delstate->status + delstate->deltids[i].id;
+ OffsetNumber idxoffnum = dstatus->idxoffnum;
+ ItemId itemid = PageGetItemId(page, idxoffnum);
+ IndexTuple itup = (IndexTuple) PageGetItem(page, itemid);
+ int tidi,
+ nitem;
+ BTVacuumPosting vacposting;
+
+ if (idxoffnum == postingidxoffnum)
+ {
+ /*
+ * This deltid entry is a TID from a posting list tuple that has
+ * already been completely processed (since we process all of a
+ * posting lists TIDs together, once)
+ */
+ Assert(BTreeTupleIsPosting(itup));
+ continue;
+ }
+
+ if (!BTreeTupleIsPosting(itup))
+ {
+ /* Plain non-pivot tuple */
+ Assert(ItemPointerEquals(&itup->t_tid, &delstate->deltids[i].tid));
+ if (dstatus->deleteitup)
+ deletable[ndeletable++] = idxoffnum;
+ continue;
+ }
+
+ /*
+ * Posting list tuple. Process all of its TIDs together, at once.
+ *
+ * tidi is a posting-list-tid local iterator for array. We're going
+ * to peak at later entries in deltid array here. Remember to skip
+ * over the itup-related entries that we peak at here later on. We
+ * should not do anything more with them when get back to the top of
+ * the outermost deltids loop (we should just skip them).
+ *
+ * Innermost loop exploits the fact that both itup's TIDs and the
+ * entries from the array (whose TIDs came from itup) are in ascending
+ * TID order. We avoid unnecessary TID comparisons by starting each
+ * execution of the innermost loop at the point where the previous
+ * execution (for previous TID from itup) left off at.
+ */
+ postingidxoffnum = idxoffnum; /* Remember: process itup once only */
+ tidi = i; /* Initialize for itup's first TID */
+ vacposting = NULL; /* Describes what to do with itup */
+ nitem = BTreeTupleGetNPosting(itup);
+ for (int j = 0; j < nitem; j++)
+ {
+ ItemPointer htid = BTreeTupleGetPostingN(itup, j);
+ int cmp = -1;
+
+ for (; tidi < delstate->ndeltids; tidi++)
+ {
+ TM_IndexDelete *tcdeltid = &delstate->deltids[tidi];
+ TM_IndexStatus *tdstatus = (delstate->status + tcdeltid->id);
+
+ /* Stop when we get to first entry beyond itup's entries */
+ Assert(tdstatus->idxoffnum >= idxoffnum);
+ if (tdstatus->idxoffnum != idxoffnum)
+ break;
+
+ /* Skip any non-deletable entries for itup */
+ if (!tdstatus->deleteitup)
+ continue;
+
+ /* Have we found matching deletable entry for htid? */
+ cmp = ItemPointerCompare(htid, &tcdeltid->tid);
+
+ /* Keep going until equal or greater tid from array located */
+ if (cmp <= 0)
+ break;
+ }
+
+ /* Final check on htid: must match a deletable array entry */
+ if (cmp != 0)
+ continue;
+
+ if (vacposting == NULL)
+ {
+ /*
+ * First deletable TID for itup found. Start maintaining
+ * metadata describing which TIDs to delete from itup.
+ */
+ vacposting = palloc(offsetof(BTVacuumPostingData, deletetids) +
+ nitem * sizeof(uint16));
+ vacposting->itup = itup;
+ vacposting->updatedoffset = idxoffnum;
+ vacposting->ndeletedtids = 0;
+ }
+
+ /* htid will be deleted from itup */
+ vacposting->deletetids[vacposting->ndeletedtids++] = j;
+ }
+
+ if (vacposting == NULL)
+ {
+ /* No TIDs to delete from itup -- do nothing */
+ }
+ else if (vacposting->ndeletedtids == nitem)
+ {
+ /* Straight delete of itup (to delete all TIDs) */
+ deletable[ndeletable++] = idxoffnum;
+ /* Turns out we won't need granular information */
+ pfree(vacposting);
+ }
+ else
+ {
+ /* Delete some but not all TIDs from itup */
+ Assert(vacposting->ndeletedtids > 0 &&
+ vacposting->ndeletedtids < nitem);
+ updatable[nupdatable++] = vacposting;
+ }
+ }
+
+ /* Physically delete the dead-to-all TIDs we've located */
+ _bt_delitems_delete(rel, buf, latestRemovedXid, deletable, ndeletable,
+ updatable, nupdatable, heapRel);
+
+ /* be tidy */
+ for (int i = 0; i < nupdatable; i++)
+ pfree(updatable[i]);
}
/*
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index d6c8ad5d27..0d7f5199e5 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -209,7 +209,7 @@ btinsert(Relation rel, Datum *values, bool *isnull,
itup = index_form_tuple(RelationGetDescr(rel), values, isnull);
itup->t_tid = *ht_ctid;
- result = _bt_doinsert(rel, itup, checkUnique, heapRel);
+ result = _bt_doinsert(rel, itup, checkUnique, indexUnchanged, heapRel);
pfree(itup);
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index 8730de25ed..d5d90cf696 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -49,7 +49,6 @@
#include "access/parallel.h"
#include "access/relscan.h"
#include "access/table.h"
-#include "access/tableam.h"
#include "access/xact.h"
#include "access/xlog.h"
#include "access/xloginsert.h"
diff --git a/src/backend/access/nbtree/nbtutils.c b/src/backend/access/nbtree/nbtutils.c
index 2f5f14e527..831cc28eac 100644
--- a/src/backend/access/nbtree/nbtutils.c
+++ b/src/backend/access/nbtree/nbtutils.c
@@ -2108,7 +2108,9 @@ btoptions(Datum reloptions, bool validate)
{"vacuum_cleanup_index_scale_factor", RELOPT_TYPE_REAL,
offsetof(BTOptions, vacuum_cleanup_index_scale_factor)},
{"deduplicate_items", RELOPT_TYPE_BOOL,
- offsetof(BTOptions, deduplicate_items)}
+ offsetof(BTOptions, deduplicate_items)},
+ {"delete_items", RELOPT_TYPE_BOOL,
+ offsetof(BTOptions, delete_items)}
};
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index 5135b800af..3e7289fe49 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -556,6 +556,47 @@ btree_xlog_dedup(XLogReaderState *record)
UnlockReleaseBuffer(buf);
}
+static void
+btree_xlog_updates(Page page, OffsetNumber *updatedoffsets,
+ xl_btree_update *updates, int nupdated)
+{
+ BTVacuumPosting vacposting;
+ IndexTuple origtuple;
+ ItemId itemid;
+ Size itemsz;
+
+ for (int i = 0; i < nupdated; i++)
+ {
+ itemid = PageGetItemId(page, updatedoffsets[i]);
+ origtuple = (IndexTuple) PageGetItem(page, itemid);
+
+ vacposting = palloc(offsetof(BTVacuumPostingData, deletetids) +
+ updates->ndeletedtids * sizeof(uint16));
+ vacposting->updatedoffset = updatedoffsets[i];
+ vacposting->itup = origtuple;
+ vacposting->ndeletedtids = updates->ndeletedtids;
+ memcpy(vacposting->deletetids,
+ (char *) updates + SizeOfBtreeUpdate,
+ updates->ndeletedtids * sizeof(uint16));
+
+ _bt_update_posting(vacposting);
+
+ /* Overwrite updated version of tuple */
+ itemsz = MAXALIGN(IndexTupleSize(vacposting->itup));
+ if (!PageIndexTupleOverwrite(page, updatedoffsets[i],
+ (Item) vacposting->itup, itemsz))
+ elog(PANIC, "failed to update partially dead item");
+
+ pfree(vacposting->itup);
+ pfree(vacposting);
+
+ /* advance to next xl_btree_update from array */
+ updates = (xl_btree_update *)
+ ((char *) updates + SizeOfBtreeUpdate +
+ updates->ndeletedtids * sizeof(uint16));
+ }
+}
+
static void
btree_xlog_vacuum(XLogReaderState *record)
{
@@ -589,41 +630,7 @@ btree_xlog_vacuum(XLogReaderState *record)
xlrec->nupdated *
sizeof(OffsetNumber));
- for (int i = 0; i < xlrec->nupdated; i++)
- {
- BTVacuumPosting vacposting;
- IndexTuple origtuple;
- ItemId itemid;
- Size itemsz;
-
- itemid = PageGetItemId(page, updatedoffsets[i]);
- origtuple = (IndexTuple) PageGetItem(page, itemid);
-
- vacposting = palloc(offsetof(BTVacuumPostingData, deletetids) +
- updates->ndeletedtids * sizeof(uint16));
- vacposting->updatedoffset = updatedoffsets[i];
- vacposting->itup = origtuple;
- vacposting->ndeletedtids = updates->ndeletedtids;
- memcpy(vacposting->deletetids,
- (char *) updates + SizeOfBtreeUpdate,
- updates->ndeletedtids * sizeof(uint16));
-
- _bt_update_posting(vacposting);
-
- /* Overwrite updated version of tuple */
- itemsz = MAXALIGN(IndexTupleSize(vacposting->itup));
- if (!PageIndexTupleOverwrite(page, updatedoffsets[i],
- (Item) vacposting->itup, itemsz))
- elog(PANIC, "failed to update partially dead item");
-
- pfree(vacposting->itup);
- pfree(vacposting);
-
- /* advance to next xl_btree_update from array */
- updates = (xl_btree_update *)
- ((char *) updates + SizeOfBtreeUpdate +
- updates->ndeletedtids * sizeof(uint16));
- }
+ btree_xlog_updates(page, updatedoffsets, updates, xlrec->nupdated);
}
if (xlrec->ndeleted > 0)
@@ -675,7 +682,22 @@ btree_xlog_delete(XLogReaderState *record)
page = (Page) BufferGetPage(buffer);
- PageIndexMultiDelete(page, (OffsetNumber *) ptr, xlrec->ndeleted);
+ if (xlrec->nupdated > 0)
+ {
+ OffsetNumber *updatedoffsets;
+ xl_btree_update *updates;
+
+ updatedoffsets = (OffsetNumber *)
+ (ptr + xlrec->ndeleted * sizeof(OffsetNumber));
+ updates = (xl_btree_update *) ((char *) updatedoffsets +
+ xlrec->nupdated *
+ sizeof(OffsetNumber));
+
+ btree_xlog_updates(page, updatedoffsets, updates, xlrec->nupdated);
+ }
+
+ if (xlrec->ndeleted > 0)
+ PageIndexMultiDelete(page, (OffsetNumber *) ptr, xlrec->ndeleted);
/* Mark the page as not containing any LP_DEAD items */
opaque = (BTPageOpaque) PageGetSpecialPointer(page);
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 8afc780acc..497bf5c3ac 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -1765,14 +1765,14 @@ psql_completion(const char *text, int start, int end)
/* ALTER INDEX <foo> SET|RESET ( */
else if (Matches("ALTER", "INDEX", MatchAny, "RESET", "("))
COMPLETE_WITH("fillfactor",
- "vacuum_cleanup_index_scale_factor", "deduplicate_items", /* BTREE */
+ "vacuum_cleanup_index_scale_factor", "deduplicate_items", "delete_items", /* BTREE */
"fastupdate", "gin_pending_list_limit", /* GIN */
"buffering", /* GiST */
"pages_per_range", "autosummarize" /* BRIN */
);
else if (Matches("ALTER", "INDEX", MatchAny, "SET", "("))
COMPLETE_WITH("fillfactor =",
- "vacuum_cleanup_index_scale_factor =", "deduplicate_items =", /* BTREE */
+ "vacuum_cleanup_index_scale_factor =", "deduplicate_items =", "delete_items =", /* BTREE */
"fastupdate =", "gin_pending_list_limit =", /* GIN */
"buffering =", /* GiST */
"pages_per_range =", "autosummarize =" /* BRIN */
diff --git a/doc/src/sgml/btree.sgml b/doc/src/sgml/btree.sgml
index bb395e6a85..9e4abf40d2 100644
--- a/doc/src/sgml/btree.sgml
+++ b/doc/src/sgml/btree.sgml
@@ -629,6 +629,86 @@ options(<replaceable>relopts</replaceable> <type>local_relopts *</type>) returns
</para>
</sect2>
+ <sect2 id="btree-deletion">
+ <title>Bottom-up index deletion</title>
+ <para>
+ B-Tree indexes are not directly aware that under MVCC, there might
+ be multiple extant versions of the same logical table row; to an
+ index, each tuple is an independent object that needs its own index
+ entry. <quote>Version churn</quote> tuples may sometimes
+ accumulate and adversely affect query latency and throughput. This
+ typically occurs with <command>UPDATE</command>-heavy workloads
+ where most individual updates cannot apply the
+ <acronym>HOT</acronym> optimization. Changing the value of only
+ one column covered by one index during an <command>UPDATE</command>
+ <emphasis>always</emphasis> necessitates a new set of index tuples
+ — one for <emphasis>each and every</emphasis> index on the
+ table. Note in particular that this includes indexes that were not
+ <quote>logically modified</quote> by the <command>UPDATE</command>.
+ All indexes will need a successor physical index tuple that points
+ to the latest version in the table. Each new tuple within each
+ index will generally need to coexist with the original
+ <quote>updated</quote> tuple for a short period of time (typically
+ until some time after the <command>UPDATE</command> transaction
+ commits). This process produces the majority of all garbage index
+ tuples in some scenarios.
+ </para>
+ <para>
+ <firstterm>Bottom-up index deletion</firstterm> targets this
+ particular variety of index tuple garbage. It effectively enforces
+ a soft limit on how many versions there can be in each index for
+ any given logical row. It is generally very effective provided
+ there are no long lived snapshots that hold back cleanup.
+ Bottom-up index deletion complements the <quote>top-down</quote>
+ index cleanup performed by <command>VACUUM</command>. It targets
+ leaf pages that are disproportionately affected by the accumulation
+ of garbage index tuples, while leaving it up to
+ <command>VACUUM</command> to perform infrequent clean sweeps of all
+ indexes. A bottom-up deletion pass takes place when a leaf page
+ does not have enough free space to fit an incoming tuple, though
+ only when the incoming tuple originates from an
+ <command>UPDATE</command> that did not logically change any of the
+ columns covered by the index in question.
+ </para>
+ <para>
+ The deletion process must closely cooperate with the table access
+ method. Despite the lack of convenient access to
+ <emphasis>authoritative</emphasis> information about how index
+ tuples represent versions or are related to each other, it is
+ possible for the B-Tree implementation to target garbage index
+ tuples using relatively simple heuristics. These heuristics decide
+ on which table blocks to visit based on where dead tuples seem most
+ likely to be concentrated. Some number of table blocks must be
+ accessed to get the required authoritative information, but it
+ isn't necessary to access very many table blocks each time. Also,
+ each table block access has to actually enable the implementation
+ to delete at least one additional index tuple. The whole process
+ ends when any single table block access fails to yield any index
+ tuples deletes.
+ </para>
+ <para>
+ The <literal>delete_items</literal> storage parameter can be used
+ to disable bottom-up index deletion within individual indexes.
+ Disabling bottom-up index deletion isn't usually helpful.
+ </para>
+ <note>
+ <para>
+ It's also possible for index tuple deletion to take place
+ following opportunistic setting of <literal>LP_DEAD</literal>
+ status bits. This avoids a relatively expensive bottom-up
+ deletion pass, which must access table blocks directly.
+ </para>
+ <para>
+ <literal>LP_DEAD</literal> status bits are set when passing index
+ scans happen to notice that an index tuple is dead to every
+ possible MVCC snapshot (not just their own).
+ <literal>LP_DEAD</literal>-set tuples are already known to be safe
+ to delete, so it isn't necessary to access the table blocks
+ directly.
+ </para>
+ </note>
+ </sect2>
+
<sect2 id="btree-deduplication">
<title>Deduplication</title>
<para>
@@ -702,25 +782,16 @@ options(<replaceable>relopts</replaceable> <type>local_relopts *</type>) returns
deduplication isn't usually helpful.
</para>
<para>
- B-Tree indexes are not directly aware that under MVCC, there might
- be multiple extant versions of the same logical table row; to an
- index, each tuple is an independent object that needs its own index
- entry. <quote>Version duplicates</quote> may sometimes accumulate
- and adversely affect query latency and throughput. This typically
- occurs with <command>UPDATE</command>-heavy workloads where most
- individual updates cannot apply the <acronym>HOT</acronym>
- optimization (often because at least one indexed column gets
- modified, necessitating a new set of index tuple versions —
- one new tuple for <emphasis>each and every</emphasis> index). In
- effect, B-Tree deduplication ameliorates index bloat caused by
- version churn. Note that even the tuples from a unique index are
- not necessarily <emphasis>physically</emphasis> unique when stored
- on disk due to version churn. The deduplication optimization is
- selectively applied within unique indexes. It targets those pages
- that appear to have version duplicates. The high level goal is to
- give <command>VACUUM</command> more time to run before an
- <quote>unnecessary</quote> page split caused by version churn can
- take place.
+ It is sometimes possible for unique indexes (as well as unique
+ constraints) to use deduplication. This allows leaf pages to
+ temporarily <quote>absorb</quote> extra version churn duplicates.
+ Deduplication in unique indexes augments bottom-up index deletion,
+ especially in cases where a long-running transactions holds a
+ snapshot that blocks garbage collection. The goal is to buy time
+ for the bottom-up index deletion strategy to become effective
+ again. Delaying page splits until a single long-running
+ transaction naturally goes away can allow a bottom-up deletion pass
+ to succeed where an earlier deletion pass failed.
</para>
<tip>
<para>
diff --git a/doc/src/sgml/ref/create_index.sgml b/doc/src/sgml/ref/create_index.sgml
index 29dee5689e..573a3e2894 100644
--- a/doc/src/sgml/ref/create_index.sgml
+++ b/doc/src/sgml/ref/create_index.sgml
@@ -435,6 +435,22 @@ CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ] <replaceable class=
</listitem>
</varlistentry>
+ <varlistentry id="index-reloption-delete-items" xreflabel="delete_items">
+ <term><literal>delete_items</literal> (<type>boolean</type>)
+ <indexterm>
+ <primary><varname>delete_items</varname> storage parameter</primary>
+ </indexterm>
+ </term>
+ <listitem>
+ <para>
+ Controls usage of the B-tree bottom-up index deletion technique
+ described in <xref linkend="btree-deletion"/>. Set to
+ <literal>ON</literal> or <literal>OFF</literal> to enable or
+ disable the optimization. The default is <literal>ON</literal>.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="index-reloption-vacuum-cleanup-index-scale-factor" xreflabel="vacuum_cleanup_index_scale_factor">
<term><literal>vacuum_cleanup_index_scale_factor</literal> (<type>floating point</type>)
<indexterm>
--
2.25.1
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-10-21 15:25 ` Robert Haas <[email protected]>
2020-10-21 19:36 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2 siblings, 1 reply; 1661+ messages in thread
From: Robert Haas @ 2020-10-21 15:25 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Wed, Oct 7, 2020 at 7:48 PM Peter Geoghegan <[email protected]> wrote:
> To be blunt: It may be controversial that we're accessing multiple
> heap pages while holding an exclusive lock on a leaf page, in the
> hopes that we can avoid a page split, but without any certainty that
> it'll work out.
That certainly isn't great. I mean, it might be not be too terrible,
because it's a leaf index page isn't nearly as potentially hot as a VM
page or a clog page, but it hurts interruptibility and risks hurting
concurrency, but if it were possible to arrange to hold only a pin on
the page during all this rather than a lock, it would be better. I'm
not sure how realistic that is, though.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-21 15:25 ` Re: Deleting older versions in unique indexes to avoid page splits Robert Haas <[email protected]>
@ 2020-10-21 19:36 ` Peter Geoghegan <[email protected]>
2020-10-22 13:18 ` Re: Deleting older versions in unique indexes to avoid page splits Robert Haas <[email protected]>
0 siblings, 1 reply; 1661+ messages in thread
From: Peter Geoghegan @ 2020-10-21 19:36 UTC (permalink / raw)
To: Robert Haas <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Wed, Oct 21, 2020 at 8:25 AM Robert Haas <[email protected]> wrote:
> That certainly isn't great. I mean, it might be not be too terrible,
> because it's a leaf index page isn't nearly as potentially hot as a VM
> page or a clog page, but it hurts interruptibility and risks hurting
> concurrency, but if it were possible to arrange to hold only a pin on
> the page during all this rather than a lock, it would be better. I'm
> not sure how realistic that is, though.
I don't think that it's realistic. Well, technically you could do
something like that, but you'd end up with some logically equivalent
mechanism which would probably be slower. As you know, in nbtree pins
are generally much less helpful than within heapam (you cannot read a
page without a shared buffer lock, no matter what). Holding a pin only
provides a very weak guarantee about VACUUM and TID recycling that
usually doesn't come up.
Bear in mind that we actually do practically the same thing all the
time with the current LP_DEAD setting stuff, where we need to call
compute_xid_horizon_for_tuples/heap_compute_xid_horizon_for_tuples
with a leaf buffer lock held in almost the same way. That's actually
potentially far worse if you look at it in isolation, because you
could potentially have hundreds of heap pages, whereas this is just 1
- 3. (BTW, next version will also do that work in passing, so you're
practically guaranteed to do less with a buffer lock held compared to
the typical case of nbtree LP_DEAD setting, even without counting how
the LP_DEAD bits get set in the first place.)
I could also point out that something very similar happens in
_bt_check_unique().
Also bear in mind that the alternative is pretty much a page split, which means:
* Locking the leaf page
* Then obtaining relation extension lock
* Locking to create new right sibling
* Releasing relation extension lock
* Locking original right sibling page
* Release original right sibling page
* Release new right sibling page
* Lock parent page
* Release original now-split page
* Release parent page
(I will refrain from going into all of the absurd and near-permanent
secondary costs that just giving up and splitting the page imposes for
now. I didn't even include all of the information about locking --
there is one thing that didn't seem worth mentioning.)
The key concept here is of course asymmetry. The asymmetry here is not
only favorable; it's just outrageous. The other key concept is it's
fundamentally impossible to pay more than a very small fixed cost
without getting a benefit.
That said, I accept that there is still some uncertainty that all
workloads that get a benefit will be happy with the trade-off. I am
still fine tuning how this works in cases with high contention. I
welcome any help with that part. But note that this doesn't
necessarily have much to do with the heap page accesses. It's not
always strictly better to never have any bloat at all (it's pretty
close to that, but not quite). We saw this with the Postgres 12 work,
where small TPC-C test cases had some queries go slower simply because
a small highly contended index did not get bloated due to a smarter
split algorithm. There is no reason to believe that it had anything to
do with the cost of making better decisions. It was the decisions
themselves.
I don't want to completely prevent "version driven page splits"
(though a person could reasonably imagine that that is in fact my
precise goal); rather, I want to make non-hot updates work to prove
that it's almost certainly necessary to split the page due to version
churn - then and only then should it be accepted. Currently we meekly
roll over and let non-hot updaters impose negative externalities on
the system as a whole. The patch usually clearly benefits even
workloads that consist entirely of non-hot updaters. Negative
externalities are only good for the individual trying to impose costs
on the collective when they can be a true freeloader. It's always bad
for the collective, but it's even bad for the bad actors once they're
more than a small minority.
Currently non-hot updaters are not merely selfish to the extent that
they impose a downside on the collective or the system as a whole that
is roughly proportionate to the upside benefit they get. Not cleaning
up their mess as they go creates a downside that is a huge multiple of
any possible upside for them. To me this seems incontrovertible.
Worrying about the precise extent to which this is true in each
situation doesn't seem particularly productive to me. Whatever the
actual extent of the imbalance is, the solution is that you don't let
them do that.
This patch is not really about overall throughput. It could be
justified on that basis, but that's not how I like to think of it.
Rather, it's about providing a stabilizing backstop mechanism, which
tends to bound the amount of index bloat and the number of versions in
each index for each *logical row* -- that's the most important benefit
of the patch. There are workloads that will greatly benefit despite
only invoking the new mechanism very occasionally, as a backstop. And
even cases with a fair amount of contention don't really use it that
often (which is why the heap page access cost is pretty much a
question about specific high contention patterns only). The proposed
new cleanup mechanism may only be used in certain parts of the key
space for certain indexes at certain times, in a bottom-up fashion. We
don't have to be eager about cleaning up bloat most of the time, but
it's also true that there are cases where we ought to work very hard
at it in a localized way.
This explanation may sound unlikely, but the existing behaviors taken
together present us with outrageous cost/benefit asymmetry, arguably
in multiple dimensions.
I think that having this backstop cleanup mechanism (and likely others
in other areas) will help to make the assumptions underlying
autovacuum scheduling much more reasonable in realistic settings. Now
it really is okay that autovacuum doesn't really care about the needs
of queries, and is largely concerned with macro level things like free
space management. It's top down approach isn't so bad once it has true
bottom up complementary mechanisms. The LP_DEAD microvacuum stuff is
nice because it marks things as dead in passing, pretty much for free.
That's not enough on its own -- it's no backstop. The current LP_DEAD
stuff appears to work rather well, until one day it suddenly doesn't
and you curse Postgres for it. I could go on about the non-linear
nature of the system as a whole, hidden tipping points, and other
stuff like that. But I won't right now.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* Re: Deleting older versions in unique indexes to avoid page splits
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-21 15:25 ` Re: Deleting older versions in unique indexes to avoid page splits Robert Haas <[email protected]>
2020-10-21 19:36 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
@ 2020-10-22 13:18 ` Robert Haas <[email protected]>
2020-10-23 01:05 ` heapam and bottom-up garbage collection, keeping version chains short (Was: Deleting older versions in unique indexes to avoid page splits) Peter Geoghegan <[email protected]>
0 siblings, 1 reply; 1661+ messages in thread
From: Robert Haas @ 2020-10-22 13:18 UTC (permalink / raw)
To: Peter Geoghegan <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Wed, Oct 21, 2020 at 3:36 PM Peter Geoghegan <[email protected]> wrote:
> Bear in mind that we actually do practically the same thing all the
> time with the current LP_DEAD setting stuff, where we need to call
> compute_xid_horizon_for_tuples/heap_compute_xid_horizon_for_tuples
> with a leaf buffer lock held in almost the same way. That's actually
> potentially far worse if you look at it in isolation, because you
> could potentially have hundreds of heap pages, whereas this is just 1
> - 3. (BTW, next version will also do that work in passing, so you're
> practically guaranteed to do less with a buffer lock held compared to
> the typical case of nbtree LP_DEAD setting, even without counting how
> the LP_DEAD bits get set in the first place.)
That's fair. It's not that I'm trying to enforce some absolute coding
rule, as if I even had the right to do such a thing. But, people have
sometimes proposed patches which would have caused major regression in
this area and I think it's really important that we avoid that.
Normally, it doesn't matter: I/O requests complete quickly and
everything is fine. But, on a system where things are malfunctioning,
it makes a big difference whether you can regain control by hitting
^C. I expect you've probably at some point had the experience of being
unable to recover control of a terminal window because some process
was stuck in wait state D on the kernel level, and you probably
thought, "well, this sucks." It's even worse if the kernel's entire
process table fills up with such processes. This kind of thing is
essentially the same issue at the database level, and it's smart to do
what we can to mitigate it.
But that being said, I'm not trying to derail this patch. It isn't,
and shouldn't be, the job of this patch to solve that problem. It's
just better if it doesn't regress things, or maybe even (as you say)
makes them a little better. I think the idea you've got here is
basically good, and a lot of it comes down to how well it works in
practice. I completely agree that looking at amortized cost rather
than worst-case cost is a reasonable principle here; you can't take
that to a ridiculous extreme because people also care about
consistently of performance, but it seems pretty clear from your
description that your patch should not create any big problem in that
area, because the worst-case number of extra buffer accesses for a
single operation is tightly bounded. And, of course, containing index
bloat is its own reward.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
^ permalink raw reply [nested|flat] 1661+ messages in thread
* heapam and bottom-up garbage collection, keeping version chains short (Was: Deleting older versions in unique indexes to avoid page splits)
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-21 15:25 ` Re: Deleting older versions in unique indexes to avoid page splits Robert Haas <[email protected]>
2020-10-21 19:36 ` Re: Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-22 13:18 ` Re: Deleting older versions in unique indexes to avoid page splits Robert Haas <[email protected]>
@ 2020-10-23 01:05 ` Peter Geoghegan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Peter Geoghegan @ 2020-10-23 01:05 UTC (permalink / raw)
To: Robert Haas <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
On Thu, Oct 22, 2020 at 6:18 AM Robert Haas <[email protected]> wrote:
> But that being said, I'm not trying to derail this patch. It isn't,
> and shouldn't be, the job of this patch to solve that problem. It's
> just better if it doesn't regress things, or maybe even (as you say)
> makes them a little better. I think the idea you've got here is
> basically good, and a lot of it comes down to how well it works in
> practice.
Thanks. I would like to have a more general conversation about how
some of the principles embodied by this patch could be generalized to
heapam in the future. I think that we could do something similar with
pruning, or at least with the truncation of HOT chains. Here are a few
of the principles I'm thinking of, plus some details of how they might
be applied in heapam:
* The most important metric is not the total amount of dead tuples in
the whole table. Rather, it's something like the 90th + 99th
percentile length of version chains for each logical row, or maybe
only those logical rows actually accessed by index scans recently.
(Not saying that we should try to target this in some explicit way -
just that it should be kept low with real workloads as a natural
consequence of the design.)
* Have a variety of strategies for dealing with pruning that compete
with each other. Allow them to fight it out organically. Start with
the cheapest thing and work your way up. So for example, truncation of
HOT chains is always preferred, and works in just the same way as it
does today. Then it gets more complicated and more expensive, but in a
way that is a natural adjunct of the current proven design.
I believe that this creates a bit more pain earlier on, but avoids
much more pain later. There is no point powering ahead if we'll end up
hopelessly indebted with garbage tuples in the end.
For heapam we could escalate from regular pruning by using an old
version store for versions that were originally part of HOT chains,
but were found to not fit on the same page at the point of
opportunistic pruning. The old version store is for committed versions
only -- it isn't really much like UNDO. We leave forwarding
information on the original heap page.
We add old committed versions to the version store at the point when a
heap page is about to experience an event that is roughly the
equivalent of a B-Tree page split -- for heapam a "split" is being
unable to keep the same logical row on the same heap page over time in
the presence of many updates. This is our last line of defense against
this so-called page split situation. It occurs after regular pruning
(which is an earlier line of defense) fails to resolve the situation
inexpensively. We can make moving tuples into the old version store
WAL efficient by making it work like an actual B-Tree page split -- it
can describe the changes in a way that's mostly logical, and based on
the existing page image. And like an actual page split, we're
amortizing costs in a localized way.
It is also possible to apply differential compression to whole HOT
chains rather than storing them in the old version store, for example,
if that happens to look favorable (think of rows with something like a
pgbench_accounts.filler column -- not uncommon). We have options, we
can add new options in the future as new requirements come to light.
We allow the best option to present itself to us in a bottom-up
fashion. Sometimes the best strategy at the local level is actually a
combination of two different strategies applied alternately over time.
For example, we use differential compression first when we fail to
prune, then we prune the same page later (a little like merge
deduplication in my recent nbtree delete dedup patch).
Maybe each of these two strategies (differential compression +
traditional heap HOT chain truncation) get applied alternately against
the same heap page over time, in a tick-tock fashion. We naturally
avoid availing of the old version store structure, which is good,
since that is a relatively expensive strategy that we should apply
only as a last resort. This tick-tock behavior is an emergent property
of the workload rather than something planned or intelligent, and yet
it kind of appears to be an intelligent strategy. (Maybe it works that
way permanently in some parts of the heap, or maybe the same heap
blocks only tick-tock like this on Tuesdays. It may be possible for
stuff like that to happen sanely with well chosen simple heuristics
that exploit asymmetry.)
* Work with (not against) the way that Postgres strongly decouples the
physical representation of data from the logical contents of the
database compared to other DB systems. But at the same time, work hard
to make the physical representation of the data as close as is
practically possible to an idealized, imaginary logical version of the
data. Do this because it makes queries faster, not because it's
strictly necessary for concurrency control/recovery/whatever.
Concretely, this mostly means that we try our best to keep each
logical row (i.e. the latest physical version or two of each row)
located on the same physical heap block over time, using the
escalation strategy I described or something like it. Notice that
we're imposing a cost on queries that are arguably responsible for
creating garbage, but only when we really can't tolerate more garbage
collection debt. But if it doesn't work out that's okay -- we tried. I
have a feeling that it will in fact mostly work out. Why shouldn't it
be possible to have no more than one or two uncommitted row versions
in a heap page at any given time, just like with my nbtree patch? (I
think that the answer to that question is "weird workloads", but I'm
okay with the idea that they're a little slower or whatever.)
Notice that this makes the visibility map work better in practice. I
also think that the FSM needs to be taught that it isn't a good thing
to reuse a little fragment of space on its own, because it works
against our goal of trying to avoid relocating rows. The current logic
seems focussed on using every little scrap of free space no matter
what, which seems pretty misguided. Penny-wise, pound-foolish.
Also notice that fighting to keep the same logical row on the same
block has a non-linear payoff. We don't need to give up on that goal
at the first sign of trouble. If it's hard to do a conventional prune
after succeeding a thousand times then it's okay to work harder. Only
a sucker gives up at the first sign of trouble. We're playing a long
game here. If it becomes so hard that even applying a more aggressive
strategy fails, then it's probably also true that it has become
inherently impossible to sustain the original layout. We graciously
accept defeat and cut our losses, having only actually wasted a little
effort to learn that we need to move our incoming successor version to
some other heap block (especially because the cost is amortized across
versions that live on the same heap block).
* Don't try to completely remove VACUUM. Treat its top down approach
as complementary to the new bottom-up approaches we add.
There is nothing wrong with taking a long time to clean up garbage
tuples in heap pages that have very little garbage total. In fact I
think that it might be a good thing. Why be in a hurry to dirty the
page again? If it becomes a real problem in the short term then the
bottom-up stuff can take care of it. Under this old-but-new paradigm,
maybe VACUUM has to visit indexes a lot less (maybe it just decides
not to sometimes, based on stats about the indexes, like we see today
with vacuum_index_cleanup = off). VACUUM is for making infrequent
"clean sweeps", though it typically leaves most of the work to new
bottom-up approaches, that are well placed to understand the needs of
queries that touch nearby data. Autovacuum does not presume to
understand the needs of queries at all.
It would also be possible for VACUUM to make more regular sweeps over
the version store without disturbing the main relation under this
model. The version store isn't that different to a separate heap
relation, but naturally doesn't require traditional index cleanup or
freezing, and naturally stores things in approximately temporal order.
So we recycle space in the version store in a relatively eager,
circular fashion, because it naturally contains data that favors such
an approach. We make up the fixed cost of using the separate old
version store structure by reducing deferred costs like this. And by
only using it when it is demonstrably helpful.
It might also make sense for us to prioritize putting heap tuples that
represent versions whose indexed columns were changed by update
(basically a non-hot update) in the version store -- we work extra
hard on that (and just leave behind an LP_DEAD line pointer). That way
VACUUM can do retail index tuple deletion for the index whose columns
were modified when it finds them in the version store (presumably this
nbtree patch of mine works well enough with the logically unchanged
index entries for other indexes that we don't need to go out of our
way).
I'm sure that there are more than a few holes in this sketch of mine.
It's not really worked out, but it has certain properties that are
generally under appreciated -- especially the thing about the worst
case number of versions per logical row being extremely important, as
well as the idea that back pressure can be a good thing when push
comes to shove -- provided it is experienced locally, and only by
queries that update the same very hot logical rows. Back pressure
needs to be proportionate and approximately fair. Another important
point that I want to call out again here is that we should try to
exploit cost/benefit asymmetry opportunistically. That seems to have
worked out extremely well in my recent B-Tree delete dedup patch.
I don't really expect anybody to take this seriously -- especially as
a total blueprint. Maybe some elements of what I've sketched can be
used as part of some future big effort. You've got to start somewhere.
It has to be incremental.
--
Peter Geoghegan
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 7abdc62f41..586bec8466 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4594,6 +4594,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4651,11 +4652,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
- year_sign, abs(year), abs(mon),
- day_sign, (long long) i64abs(mday),
- sec_sign, (long long) i64abs(hour), abs(min));
- cp += strlen(cp);
+ data_len = sprintf(cp, "%c%d-%d %c%lld %c%lld:%02d:",
+ year_sign, abs(year), abs(mon),
+ day_sign, (long long) i64abs(mday),
+ sec_sign, (long long) i64abs(hour), abs(min));
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4665,16 +4666,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%lld %lld:%02d:",
- (long long) mday, (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld %lld:%02d:",
+ (long long) mday, (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%lld:%02d:", (long long) hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%lld:%02d:", (long long) hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.45.1
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20240912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
* [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls
@ 2024-09-11 04:21 Andy Fan <[email protected]>
0 siblings, 0 replies; 1661+ messages in thread
From: Andy Fan @ 2024-09-11 04:21 UTC (permalink / raw)
sprintf return the number of characters printed (not including the
trailing `\0'), so it is exactly same as strlen. so we can reuse that
value and avoid a strlen call.
---
src/backend/utils/adt/datetime.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index 8f25c15fcfc..83c3c85305b 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -4717,6 +4717,7 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
int fsec = itm->tm_usec;
bool is_before = false;
bool is_zero = true;
+ int data_len;
/*
* The sign of year and month are guaranteed to match, since they are
@@ -4774,11 +4775,11 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
char sec_sign = (hour < 0 || min < 0 ||
sec < 0 || fsec < 0) ? '-' : '+';
- sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%c%d-%d %c%" PRId64 " %c%" PRId64 ":%02d:",
year_sign, abs(year), abs(mon),
day_sign, i64abs(mday),
sec_sign, i64abs(hour), abs(min));
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
@@ -4788,16 +4789,16 @@ EncodeInterval(struct pg_itm *itm, int style, char *str)
}
else if (has_day)
{
- sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
+ data_len = sprintf(cp, "%" PRId64 " %" PRId64 ":%02d:",
mday, hour, min);
- cp += strlen(cp);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
else
{
- sprintf(cp, "%" PRId64 ":%02d:", hour, min);
- cp += strlen(cp);
+ data_len = sprintf(cp, "%" PRId64 ":%02d:", hour, min);
+ cp += data_len;
cp = AppendSeconds(cp, sec, fsec, MAX_INTERVAL_PRECISION, true);
*cp = '\0';
}
--
2.43.0
--=-=-=
Content-Type: text/x-diff
Content-Disposition: attachment;
filename=v20260912-0004-Make-printtup-a-bit-faster-intermediate-st.patch
^ permalink raw reply [nested|flat] 1661+ messages in thread
end of thread, other threads:[~2024-09-11 04:21 UTC | newest]
Thread overview: 1661+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-07-01 00:03 Deleting older versions in unique indexes to avoid page splits Peter Geoghegan <[email protected]>
2020-10-07 23:48 ` Peter Geoghegan <[email protected]>
2020-10-12 10:47 ` Andrey Borodin <[email protected]>
2020-10-12 21:45 ` Peter Geoghegan <[email protected]>
2020-10-14 14:07 ` Anastasia Lubennikova <[email protected]>
2020-10-14 14:40 ` Peter Geoghegan <[email protected]>
2020-10-16 19:12 ` Peter Geoghegan <[email protected]>
2020-10-16 19:59 ` Victor Yegorov <[email protected]>
2020-10-16 20:58 ` Peter Geoghegan <[email protected]>
2020-10-20 02:37 ` Peter Geoghegan <[email protected]>
2020-10-22 17:11 ` Simon Riggs <[email protected]>
2020-10-22 17:42 ` Peter Geoghegan <[email protected]>
2020-10-23 16:03 ` Simon Riggs <[email protected]>
2020-10-23 17:13 ` Peter Geoghegan <[email protected]>
2020-10-24 09:55 ` Simon Riggs <[email protected]>
2020-10-24 15:01 ` Peter Geoghegan <[email protected]>
2020-10-26 21:15 ` Peter Geoghegan <[email protected]>
2020-10-27 09:43 ` Simon Riggs <[email protected]>
2020-10-27 18:35 ` Peter Geoghegan <[email protected]>
2020-10-28 23:05 ` Victor Yegorov <[email protected]>
2020-10-29 23:30 ` Peter Geoghegan <[email protected]>
2020-10-30 00:32 ` Peter Geoghegan <[email protected]>
2020-10-29 22:05 ` Victor Yegorov <[email protected]>
2020-10-29 23:48 ` Peter Geoghegan <[email protected]>
2020-11-03 20:44 ` Peter Geoghegan <[email protected]>
2020-11-09 17:20 ` Peter Geoghegan <[email protected]>
2020-11-11 14:17 ` Victor Yegorov <[email protected]>
2020-11-12 22:00 ` Peter Geoghegan <[email protected]>
2020-11-17 15:05 ` Victor Yegorov <[email protected]>
2020-11-17 16:24 ` Peter Geoghegan <[email protected]>
2020-11-17 17:19 ` Victor Yegorov <[email protected]>
2020-11-17 17:47 ` Peter Geoghegan <[email protected]>
2020-11-17 15:16 ` Victor Yegorov <[email protected]>
2020-11-17 21:38 ` Peter Geoghegan <[email protected]>
2020-11-11 20:58 ` Victor Yegorov <[email protected]>
2020-11-12 23:00 ` Peter Geoghegan <[email protected]>
2020-11-12 23:18 ` Peter Geoghegan <[email protected]>
2020-11-15 22:29 ` Victor Yegorov <[email protected]>
2020-11-17 04:59 ` Peter Geoghegan <[email protected]>
2020-11-17 15:24 ` Victor Yegorov <[email protected]>
2020-11-17 20:45 ` Peter Geoghegan <[email protected]>
2020-11-25 04:35 ` Peter Geoghegan <[email protected]>
2020-11-25 12:43 ` Victor Yegorov <[email protected]>
2020-11-25 18:41 ` Peter Geoghegan <[email protected]>
2020-11-25 21:20 ` Victor Yegorov <[email protected]>
2020-11-26 01:00 ` Peter Geoghegan <[email protected]>
2020-11-30 19:50 ` Peter Geoghegan <[email protected]>
2020-10-21 15:25 ` Robert Haas <[email protected]>
2020-10-21 19:36 ` Peter Geoghegan <[email protected]>
2020-10-22 13:18 ` Robert Haas <[email protected]>
2020-10-23 01:05 ` heapam and bottom-up garbage collection, keeping version chains short (Was: Deleting older versions in unique indexes to avoid page splits) Peter Geoghegan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20240912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
2024-09-11 04:21 [PATCH v20260912 2/4] Continue to remove some unnecesary strlen calls Andy Fan <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox