Slow uuid_generate performance in postgresql
We are planning to migrate our project from MySql to Postgres. We need Guid as primary key. Some of our table need to insert bulk data. We have noticed slow performance while using UUID in postgres. Below sql is taking 16 sec. to generate 10K uuids
select uuid_generate_v4() from generate_series(1,10000)
Whereas Mysql is taking 700 ms. to generate 100K GUIDs.
I am missing something ??
Environment :
Postgres11 on Windows 10
postgresql
add a comment |
We are planning to migrate our project from MySql to Postgres. We need Guid as primary key. Some of our table need to insert bulk data. We have noticed slow performance while using UUID in postgres. Below sql is taking 16 sec. to generate 10K uuids
select uuid_generate_v4() from generate_series(1,10000)
Whereas Mysql is taking 700 ms. to generate 100K GUIDs.
I am missing something ??
Environment :
Postgres11 on Windows 10
postgresql
What tool are you using to run that query? Does your time measured include displaying the generated IDs? What is the time reported when you usingexplain analyze select uuid_generate_v4() from generate_series(1,10000)
? And which kind of UUIDs is MySQL generating?
– a_horse_with_no_name
Nov 26 '18 at 13:57
add a comment |
We are planning to migrate our project from MySql to Postgres. We need Guid as primary key. Some of our table need to insert bulk data. We have noticed slow performance while using UUID in postgres. Below sql is taking 16 sec. to generate 10K uuids
select uuid_generate_v4() from generate_series(1,10000)
Whereas Mysql is taking 700 ms. to generate 100K GUIDs.
I am missing something ??
Environment :
Postgres11 on Windows 10
postgresql
We are planning to migrate our project from MySql to Postgres. We need Guid as primary key. Some of our table need to insert bulk data. We have noticed slow performance while using UUID in postgres. Below sql is taking 16 sec. to generate 10K uuids
select uuid_generate_v4() from generate_series(1,10000)
Whereas Mysql is taking 700 ms. to generate 100K GUIDs.
I am missing something ??
Environment :
Postgres11 on Windows 10
postgresql
postgresql
edited Nov 26 '18 at 13:50
Biju Soman
asked Nov 26 '18 at 13:39
Biju SomanBiju Soman
208213
208213
What tool are you using to run that query? Does your time measured include displaying the generated IDs? What is the time reported when you usingexplain analyze select uuid_generate_v4() from generate_series(1,10000)
? And which kind of UUIDs is MySQL generating?
– a_horse_with_no_name
Nov 26 '18 at 13:57
add a comment |
What tool are you using to run that query? Does your time measured include displaying the generated IDs? What is the time reported when you usingexplain analyze select uuid_generate_v4() from generate_series(1,10000)
? And which kind of UUIDs is MySQL generating?
– a_horse_with_no_name
Nov 26 '18 at 13:57
What tool are you using to run that query? Does your time measured include displaying the generated IDs? What is the time reported when you using
explain analyze select uuid_generate_v4() from generate_series(1,10000)
? And which kind of UUIDs is MySQL generating?– a_horse_with_no_name
Nov 26 '18 at 13:57
What tool are you using to run that query? Does your time measured include displaying the generated IDs? What is the time reported when you using
explain analyze select uuid_generate_v4() from generate_series(1,10000)
? And which kind of UUIDs is MySQL generating?– a_horse_with_no_name
Nov 26 '18 at 13:57
add a comment |
1 Answer
1
active
oldest
votes
Could you try using the function provided by pgcrypto as stated in the help page (scroll to the very bottom).
The following query was executed in less than 120 ms on my computer
select gen_random_uuid() from generate_series(1,10000)
Good point - that's why I asked what type of UUID MySQL is generating. And MySQL's documentation seems to indicate the same difference: "The MAC address of an interface is taken into account only on FreeBSD and Linux. On other operating systems, MySQL uses a randomly generated 48-bit number". So on Windows it would be a random value, exactly the same asgen_random_uuid()
from pgcrypto.
– a_horse_with_no_name
Nov 26 '18 at 14:12
Btw:explain analyze select gen_random_uuid() from generate_series(1,10000)
only takes 4ms on my Laptop andexplain analyze select uuid_generate_v4() from generate_series(1,10000)
is indeed a lot slower: it needs 3 seconds (which is still far from the 16 seconds mentioned in the question)
– a_horse_with_no_name
Nov 26 '18 at 14:13
Great ..Thanks .. it tooks 167 msec. for 100000
– Biju Soman
Nov 26 '18 at 14:18
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53482369%2fslow-uuid-generate-performance-in-postgresql%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
Could you try using the function provided by pgcrypto as stated in the help page (scroll to the very bottom).
The following query was executed in less than 120 ms on my computer
select gen_random_uuid() from generate_series(1,10000)
Good point - that's why I asked what type of UUID MySQL is generating. And MySQL's documentation seems to indicate the same difference: "The MAC address of an interface is taken into account only on FreeBSD and Linux. On other operating systems, MySQL uses a randomly generated 48-bit number". So on Windows it would be a random value, exactly the same asgen_random_uuid()
from pgcrypto.
– a_horse_with_no_name
Nov 26 '18 at 14:12
Btw:explain analyze select gen_random_uuid() from generate_series(1,10000)
only takes 4ms on my Laptop andexplain analyze select uuid_generate_v4() from generate_series(1,10000)
is indeed a lot slower: it needs 3 seconds (which is still far from the 16 seconds mentioned in the question)
– a_horse_with_no_name
Nov 26 '18 at 14:13
Great ..Thanks .. it tooks 167 msec. for 100000
– Biju Soman
Nov 26 '18 at 14:18
add a comment |
Could you try using the function provided by pgcrypto as stated in the help page (scroll to the very bottom).
The following query was executed in less than 120 ms on my computer
select gen_random_uuid() from generate_series(1,10000)
Good point - that's why I asked what type of UUID MySQL is generating. And MySQL's documentation seems to indicate the same difference: "The MAC address of an interface is taken into account only on FreeBSD and Linux. On other operating systems, MySQL uses a randomly generated 48-bit number". So on Windows it would be a random value, exactly the same asgen_random_uuid()
from pgcrypto.
– a_horse_with_no_name
Nov 26 '18 at 14:12
Btw:explain analyze select gen_random_uuid() from generate_series(1,10000)
only takes 4ms on my Laptop andexplain analyze select uuid_generate_v4() from generate_series(1,10000)
is indeed a lot slower: it needs 3 seconds (which is still far from the 16 seconds mentioned in the question)
– a_horse_with_no_name
Nov 26 '18 at 14:13
Great ..Thanks .. it tooks 167 msec. for 100000
– Biju Soman
Nov 26 '18 at 14:18
add a comment |
Could you try using the function provided by pgcrypto as stated in the help page (scroll to the very bottom).
The following query was executed in less than 120 ms on my computer
select gen_random_uuid() from generate_series(1,10000)
Could you try using the function provided by pgcrypto as stated in the help page (scroll to the very bottom).
The following query was executed in less than 120 ms on my computer
select gen_random_uuid() from generate_series(1,10000)
edited Nov 26 '18 at 14:07
a_horse_with_no_name
298k46452548
298k46452548
answered Nov 26 '18 at 14:06
laulau
1,16226
1,16226
Good point - that's why I asked what type of UUID MySQL is generating. And MySQL's documentation seems to indicate the same difference: "The MAC address of an interface is taken into account only on FreeBSD and Linux. On other operating systems, MySQL uses a randomly generated 48-bit number". So on Windows it would be a random value, exactly the same asgen_random_uuid()
from pgcrypto.
– a_horse_with_no_name
Nov 26 '18 at 14:12
Btw:explain analyze select gen_random_uuid() from generate_series(1,10000)
only takes 4ms on my Laptop andexplain analyze select uuid_generate_v4() from generate_series(1,10000)
is indeed a lot slower: it needs 3 seconds (which is still far from the 16 seconds mentioned in the question)
– a_horse_with_no_name
Nov 26 '18 at 14:13
Great ..Thanks .. it tooks 167 msec. for 100000
– Biju Soman
Nov 26 '18 at 14:18
add a comment |
Good point - that's why I asked what type of UUID MySQL is generating. And MySQL's documentation seems to indicate the same difference: "The MAC address of an interface is taken into account only on FreeBSD and Linux. On other operating systems, MySQL uses a randomly generated 48-bit number". So on Windows it would be a random value, exactly the same asgen_random_uuid()
from pgcrypto.
– a_horse_with_no_name
Nov 26 '18 at 14:12
Btw:explain analyze select gen_random_uuid() from generate_series(1,10000)
only takes 4ms on my Laptop andexplain analyze select uuid_generate_v4() from generate_series(1,10000)
is indeed a lot slower: it needs 3 seconds (which is still far from the 16 seconds mentioned in the question)
– a_horse_with_no_name
Nov 26 '18 at 14:13
Great ..Thanks .. it tooks 167 msec. for 100000
– Biju Soman
Nov 26 '18 at 14:18
Good point - that's why I asked what type of UUID MySQL is generating. And MySQL's documentation seems to indicate the same difference: "The MAC address of an interface is taken into account only on FreeBSD and Linux. On other operating systems, MySQL uses a randomly generated 48-bit number". So on Windows it would be a random value, exactly the same as
gen_random_uuid()
from pgcrypto.– a_horse_with_no_name
Nov 26 '18 at 14:12
Good point - that's why I asked what type of UUID MySQL is generating. And MySQL's documentation seems to indicate the same difference: "The MAC address of an interface is taken into account only on FreeBSD and Linux. On other operating systems, MySQL uses a randomly generated 48-bit number". So on Windows it would be a random value, exactly the same as
gen_random_uuid()
from pgcrypto.– a_horse_with_no_name
Nov 26 '18 at 14:12
Btw:
explain analyze select gen_random_uuid() from generate_series(1,10000)
only takes 4ms on my Laptop and explain analyze select uuid_generate_v4() from generate_series(1,10000)
is indeed a lot slower: it needs 3 seconds (which is still far from the 16 seconds mentioned in the question)– a_horse_with_no_name
Nov 26 '18 at 14:13
Btw:
explain analyze select gen_random_uuid() from generate_series(1,10000)
only takes 4ms on my Laptop and explain analyze select uuid_generate_v4() from generate_series(1,10000)
is indeed a lot slower: it needs 3 seconds (which is still far from the 16 seconds mentioned in the question)– a_horse_with_no_name
Nov 26 '18 at 14:13
Great ..Thanks .. it tooks 167 msec. for 100000
– Biju Soman
Nov 26 '18 at 14:18
Great ..Thanks .. it tooks 167 msec. for 100000
– Biju Soman
Nov 26 '18 at 14:18
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53482369%2fslow-uuid-generate-performance-in-postgresql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
What tool are you using to run that query? Does your time measured include displaying the generated IDs? What is the time reported when you using
explain analyze select uuid_generate_v4() from generate_series(1,10000)
? And which kind of UUIDs is MySQL generating?– a_horse_with_no_name
Nov 26 '18 at 13:57