比方说,你有如下任何插入查询 -冲突(主键)postgres 9.5+比不存在的地方更快?
insert into abc select * from def dd where not exists (select 1 from abc aa where aa.id = dd.id);
Vs的
insert into abc select * from def dd on conflict(id) do nothing;
哪一个是更快?
两个表是真正的大和想法是,如果有一个与主键
第二个应该更快,但你为什么不把它作为基准? –
会这样做,谢谢 – Tisha
在你的例子中,我希望后者更快。但是如果你的select实际上更复杂(并且包含多个连接),从头开始排除行可能会更快,尽管取决于两个表的大小,但使用WHERE id NOT IN(SELECT id FROM abc)'。 – jcaron