Re: Make printtup a bit faster

From: Andy Fan <zhihuifan1213(at)163(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, David Rowley <dgrowleyml(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Make printtup a bit faster
Date: 2026-06-02 10:25:35
Message-ID: 87ik81p7c0.fsf@163.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andy Fan <zhihuifan1213(at)163(dot)com> writes:

Hi,

> Andres Freund <andres(at)anarazel(dot)de> writes:

>> Here's a very rough prototype for how it could look like. This clearly needs
>> more helpers that I introduced, but I thought this should be enough to show
>> the idea.
>
> Yes, so optional context is really elegant. Thanks for sharing!

I continue to use optional context as the way for this optimize. Here
is the result: Port 7432 is the optimized version and port 7433 is the
master. We can see the noticeable improvement.

(feature_data-va1)> PGBENCH_RESULT_FORMAT=binary ./run.sh 7432 7433
transactions=1000 database=postgres clients=1 jobs=1 protocol=extended result_format=binary pgbench=./src/bin/pgbench/pgbench
script port latency_ms tps lat_ratio tps_ratio
int2_bench.sql 7432 3.419 292.476681 - -
int2_bench.sql 7433 4.399 227.311939 1.287 0.777
int4_bench.sql 7432 3.519 284.153068 - -
int4_bench.sql 7433 4.487 222.853492 1.275 0.784
int8_bench.sql 7432 4.525 220.970547 - -
int8_bench.sql 7433 4.574 218.632615 1.011 0.989
float4_bench.sql 7432 3.663 273.008770 - -
float4_bench.sql 7433 4.660 214.610005 1.272 0.786
float8_bench.sql 7432 3.775 264.907820 - -
float8_bench.sql 7433 4.798 208.409012 1.271 0.787
numeric_bench.sql 7432 5.715 174.968484 - -
numeric_bench.sql 7433 6.628 150.879014 1.160 0.862
text_bench.sql 7432 4.249 235.374976 - -
text_bench.sql 7433 5.275 189.576982 1.241 0.805
date_bench.sql 7432 4.870 205.342604 - -
date_bench.sql 7433 5.010 199.599045 1.029 0.972
time_bench.sql 7432 4.018 248.861954 - -
time_bench.sql 7433 5.114 195.555072 1.273 0.786
timestamp_bench.sql 7432 4.179 239.273546 - -
timestamp_bench.sql 7433 5.194 192.526840 1.243 0.805
timestamptz_bench.sql 7432 4.285 233.351970 - -
timestamptz_bench.sql 7433 5.264 189.958959 1.228 0.814

(feature_data-va1)> PGBENCH_RESULT_FORMAT=text ./run.sh 7432 7433
transactions=1000 database=postgres clients=1 jobs=1 protocol=extended result_format=text pgbench=./src/bin/pgbench/pgbench
script port latency_ms tps lat_ratio tps_ratio
int2_bench.sql 7432 3.643 274.498587 - -
int2_bench.sql 7433 4.461 224.154031 1.225 0.817
int4_bench.sql 7432 3.684 271.442388 - -
int4_bench.sql 7433 4.482 223.111396 1.217 0.822
int8_bench.sql 7432 3.839 260.464961 - -
int8_bench.sql 7433 4.878 204.981207 1.271 0.787
float4_bench.sql 7432 5.482 182.425027 - -
float4_bench.sql 7433 5.977 167.320695 1.090 0.917
float8_bench.sql 7432 6.596 151.607586 - -
float8_bench.sql 7433 7.116 140.535931 1.079 0.927
numeric_bench.sql 7432 6.762 147.878199 - -
numeric_bench.sql 7433 6.830 146.411705 1.010 0.990
text_bench.sql 7432 4.271 234.110510 - -
text_bench.sql 7433 4.904 203.915171 1.148 0.871
date_bench.sql 7432 5.473 182.707235 - -
date_bench.sql 7433 6.397 156.323668 1.169 0.856
time_bench.sql 7432 4.903 203.953267 - -
time_bench.sql 7433 5.939 168.389232 1.211 0.826
timestamp_bench.sql 7432 6.300 158.732981 - -
timestamp_bench.sql 7433 7.244 138.038000 1.150 0.870
timestamptz_bench.sql 7432 8.464 118.152459 - -
timestamptz_bench.sql 7433 9.370 106.724987 1.107 0.903

Patches and test scripts are attached.

Patch 001 and 002 comes from Andres, patch 003 uses the same way to
optimize more data type and some helper function and a bugfix for binary
format. patch 004 make pgbench support binary format, just for test
purpose.

I also attached the test scripts I used in test.tar.gz.

--
Best Regards
Andy Fan

Attachment Content-Type Size
v2-0001-WIP-Use-permanent-FunctionCallInfo-in-printtup.patch text/x-diff 2.4 KB
v2-0002-Mega-WIP-Optimized-out-send-path-for-printtup.patch text/x-diff 7.5 KB
v2-0003-Optimize-more-data-type-for-less-memory-copy-with.patch text/x-diff 19.4 KB
v2-0004-Let-pgbench-support-binary-format.patch text/x-diff 3.8 KB
test.tar.gz application/gzip 1.8 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2026-06-02 10:52:30 Re: Proposal: Conflict log history table for Logical Replication
Previous Message Tatsuo Ishii 2026-06-02 10:19:12 Re: Row pattern recognition