Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments on Boosting Postgres INSERT Performance by 2x With UNNEST #1

Open
FranckPachot opened this issue Nov 20, 2024 · 0 comments
Open

Comments

@FranckPachot
Copy link

Hi, I was reading Boosting Postgres INSERT Performance by 2x With UNNEST and have a few comments.

  • you measure time from pg_stat_statements total_plan_time and total_exec_time but they do not account for the parsing and rewrite phases. The parsing phase is the most important here with thousands of literal values

You can get elapsed the time from pgbench, the difference is minimal:

postgres=# \! cd /data/tmp/test/articles/unnest/ ; pgbench -n --file sensors_insert_values_1000.sql --file sensors_insert_unnest_1000.sql -t 1000
pgbench (16.2, server 17.1 (Debian 17.1-1.pgdg120+1))
transaction type: multiple scripts
scaling factor: 1
query mode: simple
number of clients: 1
number of threads: 1
maximum number of tries: 1
number of transactions per client: 1000
number of transactions actually processed: 1000/1000
number of failed transactions: 0 (0.000%)
latency average = 5.182 ms
initial connection time = 5.459 ms
tps = 192.965259 (without initial connection time)
SQL script 1: sensors_insert_values_1000.sql
 - weight: 1 (targets 50.0% of total)
 - 496 transactions (49.6% of total, tps = 95.710768)
 - number of failed transactions: 0 (0.000%)
 - latency average = 5.963 ms
 - latency stddev = 0.805 ms
SQL script 2: sensors_insert_unnest_1000.sql
 - weight: 1 (targets 50.0% of total)
 - 504 transactions (50.4% of total, tps = 97.254490)
 - number of failed transactions: 0 (0.000%)
 - latency average = 4.413 ms
 - latency stddev = 1.103 ms
  • the article shows queries using parameters but the code uses literal values. Passing literals is not recommended for large multi-row INSERT (use COPY for that).
    A pgbench -M prepared with parameters should be more representative of the statements from an application. Multi-value inserts could be similar here, and easier to generate from JDBC batching for example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant