Postgres:优化urn的性能加入匹配与INT

发布于 2025-01-23 06:44:05 字数 1048 浏览 0 评论 0原文

在我们的数据库中,我们正在思考到处使用urns而不是ID。

例如urn:ny:mytypeofobject:123

上测试性能

CREATE table addresses AS 
SELECT 
i as id_int,
CONCAT('urn:ny:address:', i::text) as id_urn
FROM 
generate_series(1, 100000000) s(i);  -- 100M


CREATE table addresses_attrib AS 
SELECT 
i as id_int,
CONCAT('urn:ny:address:', i::text) as id_urn,
i%79 as random_filter
FROM 
generate_series(1, 10000000) s(i); -- 10M

-- CREATE index both on id_int and id_urn
CREATE index int_a1 on addresses(id_int);
CREATE index int_aa1 on addresses_attrib(id_int);
CREATE index urn_a1 on addresses(id_urn);
CREATE index urn_aa1 on addresses_attrib(id_urn);

SELECT * FROM addresses_attrib aa
JOIN addresses a on (aa.id_int=a.id_int)
WHERE aa.random_filter=4
LIMIT 100000

使用pg_bench在VS

SELECT * FROM addresses_attrib aa
JOIN addresses a on (aa.id_urn=a.id_urn)
WHERE aa.random_filter=4
LIMIT 100000

,与pg_bench相比,基于int的int基于int的速度约为速度(0.5 avg int)(0.5 avg int)。

有什么办法可以加快这种加入在urns上?

In our database we are thinking using URNs everywhere, instead of IDs.

e.g. urn:ny:MyTypeOfObject:123

Testing the performance on

CREATE table addresses AS 
SELECT 
i as id_int,
CONCAT('urn:ny:address:', i::text) as id_urn
FROM 
generate_series(1, 100000000) s(i);  -- 100M


CREATE table addresses_attrib AS 
SELECT 
i as id_int,
CONCAT('urn:ny:address:', i::text) as id_urn,
i%79 as random_filter
FROM 
generate_series(1, 10000000) s(i); -- 10M

-- CREATE index both on id_int and id_urn
CREATE index int_a1 on addresses(id_int);
CREATE index int_aa1 on addresses_attrib(id_int);
CREATE index urn_a1 on addresses(id_urn);
CREATE index urn_aa1 on addresses_attrib(id_urn);

SELECT * FROM addresses_attrib aa
JOIN addresses a on (aa.id_int=a.id_int)
WHERE aa.random_filter=4
LIMIT 100000

VS

SELECT * FROM addresses_attrib aa
JOIN addresses a on (aa.id_urn=a.id_urn)
WHERE aa.random_filter=4
LIMIT 100000

Using pg_bench, the int based one is about twice as fast (0.5 avg the int) compared to the urn one (1.2s average) according to pg_bench.

Is there any way to speed up this kind of joins on URNs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文