Postgres:优化urn的性能加入匹配与INT
在我们的数据库中,我们正在思考到处使用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论