Redshift:支持在同一 table 中并发插入

Redshift: Support for concurrent inserts in the same table

我有一个 lambda 代码,它通过红移数据 api.

同时触发对相同 Table 的一些插入查询

1. Insert into Table ( select <some analytical logic> from someTable_1)
2. Insert into Table ( select <some analytical logic> from someTable_2)
3. Insert into Table ( select <some analytical logic> from someTable_n)

考虑到此类查询将同时触发,Redshift 是否会为每个插入应用锁到 Table?或者它是否允许在同一个 table 中并行插入查询? 我问是因为 postgres 允许并发插入。

https://www.postgresql.org/files/developer/concurrency.pdf

Redshift 和 Postgres 数据库都使用 MVCC - https://en.wikipedia.org/wiki/Multiversion_concurrency_control - 因此它们可能会以相同的方式工作。没有写锁,只有在看到提交时通过提交队列串行进行。我在 Redshift 中没有看到这方面的功能问题,所以你应该很好。

在功能上这很好,但 Redshift 是柱状的,而 Postgres 是基于行的。这导致了更新端的差异。由于这些 INSERT 可能只添加少量(对于 Redshift)行,并且 Redshift 上的最小写入大小为每列每切片 1MB,因此这些块中可能有很多未使用的 space。如果经常这样做,table 中会浪费很多 space 并且需要大量吸尘。如果可以的话,您会想看看这个写入模式,看看是否可以对插入数据进行更多批处理。

根据评论中的讨论,可以得出结论,与 postgres 不同,在 Redshift 中对同一 table 的并发插入本质上是阻塞的。 请参阅文档:- https://docs.aws.amazon.com/redshift/latest/dg/r_Serializable_isolation_example.html

编辑:-

仅供参考,如果您正在考虑要在上述文档中查找的确切信息,我直接将其粘贴在下面:-

Concurrent COPY operations into the same table
Transaction 1 copies rows into the LISTING table:

begin;
copy listing from ...;
end;
Transaction 2 starts concurrently in a separate session and attempts to copy more rows into the LISTING table. Transaction 2 must wait until transaction 1 releases the write lock on the LISTING table, then it can proceed.

begin;
[waits]
copy listing from ;
end;
The same behavior would occur if one or both transactions contained an INSERT command instead of a COPY command.