Why is sum(bigint) significantly faster than sum(integer) in PostgreSQL v10?












0














create table t_num_type(
n_bigint bigint,
n_numeric numeric,
n_int int
);

insert into t_num_type
select generate_series(1,10000000),
generate_series(1,10000000),
generate_series(1,10000000);


1» n_bigint



explain (analyze,buffers,format text)
select sum(n_bigint) from t_num_type;
Finalize Aggregate (cost=116778.56..116778.57 rows=1 width=32) (actual time=1221.663..1221.664 rows=1 loops=1)
Buffers: shared hit=23090
-> Gather (cost=116778.34..116778.55 rows=2 width=32) (actual time=1221.592..1221.643 rows=3 loops=1)
Workers Planned: 2
Workers Launched: 2
Buffers: shared hit=23090
-> Partial Aggregate (cost=115778.34..115778.35 rows=1 width=32) (actual time=1217.558..1217.559 rows=1 loops=3)
Buffers: shared hit=63695
-> Parallel Seq Scan on t_num_type (cost=0.00..105361.67 rows=4166667 width=8) (actual time=0.021..747.748 rows=3333333 loops=3)
Buffers: shared hit=63695
Planning time: 0.265 ms
Execution time: 1237.360 ms


2» numeric



explain (analyze,buffers,format text)
select sum(n_numeric) from t_num_type;
Finalize Aggregate (cost=116778.56..116778.57 rows=1 width=32) (actual time=1576.562..1576.562 rows=1 loops=1)
Buffers: shared hit=22108
-> Gather (cost=116778.34..116778.55 rows=2 width=32) (actual time=1576.502..1576.544 rows=3 loops=1)
Workers Planned: 2
Workers Launched: 2
Buffers: shared hit=22108
-> Partial Aggregate (cost=115778.34..115778.35 rows=1 width=32) (actual time=1572.446..1572.446 rows=1 loops=3)
Buffers: shared hit=63695
-> Parallel Seq Scan on t_num_type (cost=0.00..105361.67 rows=4166667 width=6) (actual time=0.028..781.808 rows=3333333 loops=3)
Buffers: shared hit=63695
Planning time: 0.157 ms
Execution time: 1592.559 ms


3» n_int



explain (analyze,buffers,format text)
select sum(n_int) from t_num_type;
Finalize Aggregate (cost=116778.55..116778.56 rows=1 width=8) (actual time=1247.065..1247.065 rows=1 loops=1)
Buffers: shared hit=23367
-> Gather (cost=116778.33..116778.54 rows=2 width=8) (actual time=1247.006..1247.055 rows=3 loops=1)
Workers Planned: 2
Workers Launched: 2
Buffers: shared hit=23367
-> Partial Aggregate (cost=115778.33..115778.34 rows=1 width=8) (actual time=1242.524..1242.524 rows=1 loops=3)
Buffers: shared hit=63695
-> Parallel Seq Scan on t_num_type (cost=0.00..105361.67 rows=4166667 width=4) (actual time=0.028..786.940 rows=3333333 loops=3)
Buffers: shared hit=63695
Planning time: 0.196 ms
Execution time: 1263.352 ms


pg9.6》



abase=# timing
Timing is on.
abase=# select sum(n_bigint) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 2042.587 ms
abase=# select sum(n_numeric) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 1874.880 ms
abase=# select sum(n_int) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 1073.567 ms


pg10.4》



 postgres=# select sum(n_bigint) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 871.811 ms
postgres=# select sum(n_numeric) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 1168.779 ms (00:01.169)
postgres=# select sum(n_int) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 923.551 ms


After many tests Sum efficiency of pg10.4 was significantly improved, 9.6: sum(int)>sum(numeric)>sum(bigint), pg10.4: sum(bigint)>sum(int) : >sum(numeric)



Why after multiple tests pg10:sum(bigint)>sum(int)?
Does it mean that the bigint type is more recommended?










share|improve this question




















  • 2




    Could you edit your question to include a clearer description of the question in the body? The title refers to "the efficiency being increased significantly", but it's not clear what numbers we're comparing - are we comparing the execution time of these three queries, an unshown difference between Postgres versions, or something else?
    – IMSoP
    Nov 12 '18 at 14:51












  • Unrelated, but: your insert to generate the test data would be more efficient, if you used generate_series() in the from clause so the series only needs to be generated once, not three times: insert into t_num_type select n,n,n from generate_series(1,10000000) as t(n);
    – a_horse_with_no_name
    Nov 14 '18 at 6:48
















0














create table t_num_type(
n_bigint bigint,
n_numeric numeric,
n_int int
);

insert into t_num_type
select generate_series(1,10000000),
generate_series(1,10000000),
generate_series(1,10000000);


1» n_bigint



explain (analyze,buffers,format text)
select sum(n_bigint) from t_num_type;
Finalize Aggregate (cost=116778.56..116778.57 rows=1 width=32) (actual time=1221.663..1221.664 rows=1 loops=1)
Buffers: shared hit=23090
-> Gather (cost=116778.34..116778.55 rows=2 width=32) (actual time=1221.592..1221.643 rows=3 loops=1)
Workers Planned: 2
Workers Launched: 2
Buffers: shared hit=23090
-> Partial Aggregate (cost=115778.34..115778.35 rows=1 width=32) (actual time=1217.558..1217.559 rows=1 loops=3)
Buffers: shared hit=63695
-> Parallel Seq Scan on t_num_type (cost=0.00..105361.67 rows=4166667 width=8) (actual time=0.021..747.748 rows=3333333 loops=3)
Buffers: shared hit=63695
Planning time: 0.265 ms
Execution time: 1237.360 ms


2» numeric



explain (analyze,buffers,format text)
select sum(n_numeric) from t_num_type;
Finalize Aggregate (cost=116778.56..116778.57 rows=1 width=32) (actual time=1576.562..1576.562 rows=1 loops=1)
Buffers: shared hit=22108
-> Gather (cost=116778.34..116778.55 rows=2 width=32) (actual time=1576.502..1576.544 rows=3 loops=1)
Workers Planned: 2
Workers Launched: 2
Buffers: shared hit=22108
-> Partial Aggregate (cost=115778.34..115778.35 rows=1 width=32) (actual time=1572.446..1572.446 rows=1 loops=3)
Buffers: shared hit=63695
-> Parallel Seq Scan on t_num_type (cost=0.00..105361.67 rows=4166667 width=6) (actual time=0.028..781.808 rows=3333333 loops=3)
Buffers: shared hit=63695
Planning time: 0.157 ms
Execution time: 1592.559 ms


3» n_int



explain (analyze,buffers,format text)
select sum(n_int) from t_num_type;
Finalize Aggregate (cost=116778.55..116778.56 rows=1 width=8) (actual time=1247.065..1247.065 rows=1 loops=1)
Buffers: shared hit=23367
-> Gather (cost=116778.33..116778.54 rows=2 width=8) (actual time=1247.006..1247.055 rows=3 loops=1)
Workers Planned: 2
Workers Launched: 2
Buffers: shared hit=23367
-> Partial Aggregate (cost=115778.33..115778.34 rows=1 width=8) (actual time=1242.524..1242.524 rows=1 loops=3)
Buffers: shared hit=63695
-> Parallel Seq Scan on t_num_type (cost=0.00..105361.67 rows=4166667 width=4) (actual time=0.028..786.940 rows=3333333 loops=3)
Buffers: shared hit=63695
Planning time: 0.196 ms
Execution time: 1263.352 ms


pg9.6》



abase=# timing
Timing is on.
abase=# select sum(n_bigint) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 2042.587 ms
abase=# select sum(n_numeric) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 1874.880 ms
abase=# select sum(n_int) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 1073.567 ms


pg10.4》



 postgres=# select sum(n_bigint) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 871.811 ms
postgres=# select sum(n_numeric) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 1168.779 ms (00:01.169)
postgres=# select sum(n_int) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 923.551 ms


After many tests Sum efficiency of pg10.4 was significantly improved, 9.6: sum(int)>sum(numeric)>sum(bigint), pg10.4: sum(bigint)>sum(int) : >sum(numeric)



Why after multiple tests pg10:sum(bigint)>sum(int)?
Does it mean that the bigint type is more recommended?










share|improve this question




















  • 2




    Could you edit your question to include a clearer description of the question in the body? The title refers to "the efficiency being increased significantly", but it's not clear what numbers we're comparing - are we comparing the execution time of these three queries, an unshown difference between Postgres versions, or something else?
    – IMSoP
    Nov 12 '18 at 14:51












  • Unrelated, but: your insert to generate the test data would be more efficient, if you used generate_series() in the from clause so the series only needs to be generated once, not three times: insert into t_num_type select n,n,n from generate_series(1,10000000) as t(n);
    – a_horse_with_no_name
    Nov 14 '18 at 6:48














0












0








0







create table t_num_type(
n_bigint bigint,
n_numeric numeric,
n_int int
);

insert into t_num_type
select generate_series(1,10000000),
generate_series(1,10000000),
generate_series(1,10000000);


1» n_bigint



explain (analyze,buffers,format text)
select sum(n_bigint) from t_num_type;
Finalize Aggregate (cost=116778.56..116778.57 rows=1 width=32) (actual time=1221.663..1221.664 rows=1 loops=1)
Buffers: shared hit=23090
-> Gather (cost=116778.34..116778.55 rows=2 width=32) (actual time=1221.592..1221.643 rows=3 loops=1)
Workers Planned: 2
Workers Launched: 2
Buffers: shared hit=23090
-> Partial Aggregate (cost=115778.34..115778.35 rows=1 width=32) (actual time=1217.558..1217.559 rows=1 loops=3)
Buffers: shared hit=63695
-> Parallel Seq Scan on t_num_type (cost=0.00..105361.67 rows=4166667 width=8) (actual time=0.021..747.748 rows=3333333 loops=3)
Buffers: shared hit=63695
Planning time: 0.265 ms
Execution time: 1237.360 ms


2» numeric



explain (analyze,buffers,format text)
select sum(n_numeric) from t_num_type;
Finalize Aggregate (cost=116778.56..116778.57 rows=1 width=32) (actual time=1576.562..1576.562 rows=1 loops=1)
Buffers: shared hit=22108
-> Gather (cost=116778.34..116778.55 rows=2 width=32) (actual time=1576.502..1576.544 rows=3 loops=1)
Workers Planned: 2
Workers Launched: 2
Buffers: shared hit=22108
-> Partial Aggregate (cost=115778.34..115778.35 rows=1 width=32) (actual time=1572.446..1572.446 rows=1 loops=3)
Buffers: shared hit=63695
-> Parallel Seq Scan on t_num_type (cost=0.00..105361.67 rows=4166667 width=6) (actual time=0.028..781.808 rows=3333333 loops=3)
Buffers: shared hit=63695
Planning time: 0.157 ms
Execution time: 1592.559 ms


3» n_int



explain (analyze,buffers,format text)
select sum(n_int) from t_num_type;
Finalize Aggregate (cost=116778.55..116778.56 rows=1 width=8) (actual time=1247.065..1247.065 rows=1 loops=1)
Buffers: shared hit=23367
-> Gather (cost=116778.33..116778.54 rows=2 width=8) (actual time=1247.006..1247.055 rows=3 loops=1)
Workers Planned: 2
Workers Launched: 2
Buffers: shared hit=23367
-> Partial Aggregate (cost=115778.33..115778.34 rows=1 width=8) (actual time=1242.524..1242.524 rows=1 loops=3)
Buffers: shared hit=63695
-> Parallel Seq Scan on t_num_type (cost=0.00..105361.67 rows=4166667 width=4) (actual time=0.028..786.940 rows=3333333 loops=3)
Buffers: shared hit=63695
Planning time: 0.196 ms
Execution time: 1263.352 ms


pg9.6》



abase=# timing
Timing is on.
abase=# select sum(n_bigint) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 2042.587 ms
abase=# select sum(n_numeric) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 1874.880 ms
abase=# select sum(n_int) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 1073.567 ms


pg10.4》



 postgres=# select sum(n_bigint) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 871.811 ms
postgres=# select sum(n_numeric) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 1168.779 ms (00:01.169)
postgres=# select sum(n_int) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 923.551 ms


After many tests Sum efficiency of pg10.4 was significantly improved, 9.6: sum(int)>sum(numeric)>sum(bigint), pg10.4: sum(bigint)>sum(int) : >sum(numeric)



Why after multiple tests pg10:sum(bigint)>sum(int)?
Does it mean that the bigint type is more recommended?










share|improve this question















create table t_num_type(
n_bigint bigint,
n_numeric numeric,
n_int int
);

insert into t_num_type
select generate_series(1,10000000),
generate_series(1,10000000),
generate_series(1,10000000);


1» n_bigint



explain (analyze,buffers,format text)
select sum(n_bigint) from t_num_type;
Finalize Aggregate (cost=116778.56..116778.57 rows=1 width=32) (actual time=1221.663..1221.664 rows=1 loops=1)
Buffers: shared hit=23090
-> Gather (cost=116778.34..116778.55 rows=2 width=32) (actual time=1221.592..1221.643 rows=3 loops=1)
Workers Planned: 2
Workers Launched: 2
Buffers: shared hit=23090
-> Partial Aggregate (cost=115778.34..115778.35 rows=1 width=32) (actual time=1217.558..1217.559 rows=1 loops=3)
Buffers: shared hit=63695
-> Parallel Seq Scan on t_num_type (cost=0.00..105361.67 rows=4166667 width=8) (actual time=0.021..747.748 rows=3333333 loops=3)
Buffers: shared hit=63695
Planning time: 0.265 ms
Execution time: 1237.360 ms


2» numeric



explain (analyze,buffers,format text)
select sum(n_numeric) from t_num_type;
Finalize Aggregate (cost=116778.56..116778.57 rows=1 width=32) (actual time=1576.562..1576.562 rows=1 loops=1)
Buffers: shared hit=22108
-> Gather (cost=116778.34..116778.55 rows=2 width=32) (actual time=1576.502..1576.544 rows=3 loops=1)
Workers Planned: 2
Workers Launched: 2
Buffers: shared hit=22108
-> Partial Aggregate (cost=115778.34..115778.35 rows=1 width=32) (actual time=1572.446..1572.446 rows=1 loops=3)
Buffers: shared hit=63695
-> Parallel Seq Scan on t_num_type (cost=0.00..105361.67 rows=4166667 width=6) (actual time=0.028..781.808 rows=3333333 loops=3)
Buffers: shared hit=63695
Planning time: 0.157 ms
Execution time: 1592.559 ms


3» n_int



explain (analyze,buffers,format text)
select sum(n_int) from t_num_type;
Finalize Aggregate (cost=116778.55..116778.56 rows=1 width=8) (actual time=1247.065..1247.065 rows=1 loops=1)
Buffers: shared hit=23367
-> Gather (cost=116778.33..116778.54 rows=2 width=8) (actual time=1247.006..1247.055 rows=3 loops=1)
Workers Planned: 2
Workers Launched: 2
Buffers: shared hit=23367
-> Partial Aggregate (cost=115778.33..115778.34 rows=1 width=8) (actual time=1242.524..1242.524 rows=1 loops=3)
Buffers: shared hit=63695
-> Parallel Seq Scan on t_num_type (cost=0.00..105361.67 rows=4166667 width=4) (actual time=0.028..786.940 rows=3333333 loops=3)
Buffers: shared hit=63695
Planning time: 0.196 ms
Execution time: 1263.352 ms


pg9.6》



abase=# timing
Timing is on.
abase=# select sum(n_bigint) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 2042.587 ms
abase=# select sum(n_numeric) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 1874.880 ms
abase=# select sum(n_int) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 1073.567 ms


pg10.4》



 postgres=# select sum(n_bigint) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 871.811 ms
postgres=# select sum(n_numeric) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 1168.779 ms (00:01.169)
postgres=# select sum(n_int) from t_num_type;
sum
----------------
50000005000000
(1 row)

Time: 923.551 ms


After many tests Sum efficiency of pg10.4 was significantly improved, 9.6: sum(int)>sum(numeric)>sum(bigint), pg10.4: sum(bigint)>sum(int) : >sum(numeric)



Why after multiple tests pg10:sum(bigint)>sum(int)?
Does it mean that the bigint type is more recommended?







postgresql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 2:45

























asked Nov 12 '18 at 14:17









dodo

66




66








  • 2




    Could you edit your question to include a clearer description of the question in the body? The title refers to "the efficiency being increased significantly", but it's not clear what numbers we're comparing - are we comparing the execution time of these three queries, an unshown difference between Postgres versions, or something else?
    – IMSoP
    Nov 12 '18 at 14:51












  • Unrelated, but: your insert to generate the test data would be more efficient, if you used generate_series() in the from clause so the series only needs to be generated once, not three times: insert into t_num_type select n,n,n from generate_series(1,10000000) as t(n);
    – a_horse_with_no_name
    Nov 14 '18 at 6:48














  • 2




    Could you edit your question to include a clearer description of the question in the body? The title refers to "the efficiency being increased significantly", but it's not clear what numbers we're comparing - are we comparing the execution time of these three queries, an unshown difference between Postgres versions, or something else?
    – IMSoP
    Nov 12 '18 at 14:51












  • Unrelated, but: your insert to generate the test data would be more efficient, if you used generate_series() in the from clause so the series only needs to be generated once, not three times: insert into t_num_type select n,n,n from generate_series(1,10000000) as t(n);
    – a_horse_with_no_name
    Nov 14 '18 at 6:48








2




2




Could you edit your question to include a clearer description of the question in the body? The title refers to "the efficiency being increased significantly", but it's not clear what numbers we're comparing - are we comparing the execution time of these three queries, an unshown difference between Postgres versions, or something else?
– IMSoP
Nov 12 '18 at 14:51






Could you edit your question to include a clearer description of the question in the body? The title refers to "the efficiency being increased significantly", but it's not clear what numbers we're comparing - are we comparing the execution time of these three queries, an unshown difference between Postgres versions, or something else?
– IMSoP
Nov 12 '18 at 14:51














Unrelated, but: your insert to generate the test data would be more efficient, if you used generate_series() in the from clause so the series only needs to be generated once, not three times: insert into t_num_type select n,n,n from generate_series(1,10000000) as t(n);
– a_horse_with_no_name
Nov 14 '18 at 6:48




Unrelated, but: your insert to generate the test data would be more efficient, if you used generate_series() in the from clause so the series only needs to be generated once, not three times: insert into t_num_type select n,n,n from generate_series(1,10000000) as t(n);
– a_horse_with_no_name
Nov 14 '18 at 6:48












1 Answer
1






active

oldest

votes


















0














First, you should repeat the experiment several times to see if the difference remains the same. Caching and other effects cause a certain fluctuation in query times.



I'd expect the difference between integer and bigint to be negligible in the long run. Both summation operations should be implemented in hardware.



numeric should be significantly slower, because operations on these binary coded decimals is implemented in C in the database engine.



If bigint summation remains faster even in repeated experiments, my only explanation is tuple deforming: to get to the third column, PostgreSQL has to process the first two columns.






share|improve this answer





















  • Yes, I found the difference between pg10.4 and pg9.6 after several tests
    – dodo
    Nov 14 '18 at 3:32










  • @dodo: I think Laurenz' suspicion with tuple deforming could be right. When I create three tables with just one column the sum on bigint is actually slower than on int (or even numeric which surprised me a lot). plan for bigint plan for int plan for numeric
    – a_horse_with_no_name
    Nov 14 '18 at 7:15










  • @a_horse_with_no_name Are you using the pg9.6 version?
    – dodo
    Nov 15 '18 at 3:26












  • @dodo: those plans were created with Postgres 11
    – a_horse_with_no_name
    Nov 15 '18 at 6:34










  • @Laurenz Albe Is a tuple deformation because n_numeric(storage main) is in front of n_int(plain).Does that mean it is more advantageous for the table to put the fields of int, bigint, and so on (storage plain) in front?Or jit?
    – dodo
    Nov 15 '18 at 7:09











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264063%2fwhy-is-sumbigint-significantly-faster-than-suminteger-in-postgresql-v10%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














First, you should repeat the experiment several times to see if the difference remains the same. Caching and other effects cause a certain fluctuation in query times.



I'd expect the difference between integer and bigint to be negligible in the long run. Both summation operations should be implemented in hardware.



numeric should be significantly slower, because operations on these binary coded decimals is implemented in C in the database engine.



If bigint summation remains faster even in repeated experiments, my only explanation is tuple deforming: to get to the third column, PostgreSQL has to process the first two columns.






share|improve this answer





















  • Yes, I found the difference between pg10.4 and pg9.6 after several tests
    – dodo
    Nov 14 '18 at 3:32










  • @dodo: I think Laurenz' suspicion with tuple deforming could be right. When I create three tables with just one column the sum on bigint is actually slower than on int (or even numeric which surprised me a lot). plan for bigint plan for int plan for numeric
    – a_horse_with_no_name
    Nov 14 '18 at 7:15










  • @a_horse_with_no_name Are you using the pg9.6 version?
    – dodo
    Nov 15 '18 at 3:26












  • @dodo: those plans were created with Postgres 11
    – a_horse_with_no_name
    Nov 15 '18 at 6:34










  • @Laurenz Albe Is a tuple deformation because n_numeric(storage main) is in front of n_int(plain).Does that mean it is more advantageous for the table to put the fields of int, bigint, and so on (storage plain) in front?Or jit?
    – dodo
    Nov 15 '18 at 7:09
















0














First, you should repeat the experiment several times to see if the difference remains the same. Caching and other effects cause a certain fluctuation in query times.



I'd expect the difference between integer and bigint to be negligible in the long run. Both summation operations should be implemented in hardware.



numeric should be significantly slower, because operations on these binary coded decimals is implemented in C in the database engine.



If bigint summation remains faster even in repeated experiments, my only explanation is tuple deforming: to get to the third column, PostgreSQL has to process the first two columns.






share|improve this answer





















  • Yes, I found the difference between pg10.4 and pg9.6 after several tests
    – dodo
    Nov 14 '18 at 3:32










  • @dodo: I think Laurenz' suspicion with tuple deforming could be right. When I create three tables with just one column the sum on bigint is actually slower than on int (or even numeric which surprised me a lot). plan for bigint plan for int plan for numeric
    – a_horse_with_no_name
    Nov 14 '18 at 7:15










  • @a_horse_with_no_name Are you using the pg9.6 version?
    – dodo
    Nov 15 '18 at 3:26












  • @dodo: those plans were created with Postgres 11
    – a_horse_with_no_name
    Nov 15 '18 at 6:34










  • @Laurenz Albe Is a tuple deformation because n_numeric(storage main) is in front of n_int(plain).Does that mean it is more advantageous for the table to put the fields of int, bigint, and so on (storage plain) in front?Or jit?
    – dodo
    Nov 15 '18 at 7:09














0












0








0






First, you should repeat the experiment several times to see if the difference remains the same. Caching and other effects cause a certain fluctuation in query times.



I'd expect the difference between integer and bigint to be negligible in the long run. Both summation operations should be implemented in hardware.



numeric should be significantly slower, because operations on these binary coded decimals is implemented in C in the database engine.



If bigint summation remains faster even in repeated experiments, my only explanation is tuple deforming: to get to the third column, PostgreSQL has to process the first two columns.






share|improve this answer












First, you should repeat the experiment several times to see if the difference remains the same. Caching and other effects cause a certain fluctuation in query times.



I'd expect the difference between integer and bigint to be negligible in the long run. Both summation operations should be implemented in hardware.



numeric should be significantly slower, because operations on these binary coded decimals is implemented in C in the database engine.



If bigint summation remains faster even in repeated experiments, my only explanation is tuple deforming: to get to the third column, PostgreSQL has to process the first two columns.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 12 '18 at 16:11









Laurenz Albe

44.3k102746




44.3k102746












  • Yes, I found the difference between pg10.4 and pg9.6 after several tests
    – dodo
    Nov 14 '18 at 3:32










  • @dodo: I think Laurenz' suspicion with tuple deforming could be right. When I create three tables with just one column the sum on bigint is actually slower than on int (or even numeric which surprised me a lot). plan for bigint plan for int plan for numeric
    – a_horse_with_no_name
    Nov 14 '18 at 7:15










  • @a_horse_with_no_name Are you using the pg9.6 version?
    – dodo
    Nov 15 '18 at 3:26












  • @dodo: those plans were created with Postgres 11
    – a_horse_with_no_name
    Nov 15 '18 at 6:34










  • @Laurenz Albe Is a tuple deformation because n_numeric(storage main) is in front of n_int(plain).Does that mean it is more advantageous for the table to put the fields of int, bigint, and so on (storage plain) in front?Or jit?
    – dodo
    Nov 15 '18 at 7:09


















  • Yes, I found the difference between pg10.4 and pg9.6 after several tests
    – dodo
    Nov 14 '18 at 3:32










  • @dodo: I think Laurenz' suspicion with tuple deforming could be right. When I create three tables with just one column the sum on bigint is actually slower than on int (or even numeric which surprised me a lot). plan for bigint plan for int plan for numeric
    – a_horse_with_no_name
    Nov 14 '18 at 7:15










  • @a_horse_with_no_name Are you using the pg9.6 version?
    – dodo
    Nov 15 '18 at 3:26












  • @dodo: those plans were created with Postgres 11
    – a_horse_with_no_name
    Nov 15 '18 at 6:34










  • @Laurenz Albe Is a tuple deformation because n_numeric(storage main) is in front of n_int(plain).Does that mean it is more advantageous for the table to put the fields of int, bigint, and so on (storage plain) in front?Or jit?
    – dodo
    Nov 15 '18 at 7:09
















Yes, I found the difference between pg10.4 and pg9.6 after several tests
– dodo
Nov 14 '18 at 3:32




Yes, I found the difference between pg10.4 and pg9.6 after several tests
– dodo
Nov 14 '18 at 3:32












@dodo: I think Laurenz' suspicion with tuple deforming could be right. When I create three tables with just one column the sum on bigint is actually slower than on int (or even numeric which surprised me a lot). plan for bigint plan for int plan for numeric
– a_horse_with_no_name
Nov 14 '18 at 7:15




@dodo: I think Laurenz' suspicion with tuple deforming could be right. When I create three tables with just one column the sum on bigint is actually slower than on int (or even numeric which surprised me a lot). plan for bigint plan for int plan for numeric
– a_horse_with_no_name
Nov 14 '18 at 7:15












@a_horse_with_no_name Are you using the pg9.6 version?
– dodo
Nov 15 '18 at 3:26






@a_horse_with_no_name Are you using the pg9.6 version?
– dodo
Nov 15 '18 at 3:26














@dodo: those plans were created with Postgres 11
– a_horse_with_no_name
Nov 15 '18 at 6:34




@dodo: those plans were created with Postgres 11
– a_horse_with_no_name
Nov 15 '18 at 6:34












@Laurenz Albe Is a tuple deformation because n_numeric(storage main) is in front of n_int(plain).Does that mean it is more advantageous for the table to put the fields of int, bigint, and so on (storage plain) in front?Or jit?
– dodo
Nov 15 '18 at 7:09




@Laurenz Albe Is a tuple deformation because n_numeric(storage main) is in front of n_int(plain).Does that mean it is more advantageous for the table to put the fields of int, bigint, and so on (storage plain) in front?Or jit?
– dodo
Nov 15 '18 at 7:09


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264063%2fwhy-is-sumbigint-significantly-faster-than-suminteger-in-postgresql-v10%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings