Syntax
Parameters
READ_SNAPSHOT records the load in the stream’s position of record, in the transaction of the statement that runs it, so it has to run inside a writing statement such as INSERT INTO ... SELECT. A stream attached to a CDC table cannot be loaded this way, since the table owns the stream. A statement reads a stream at most once, counting READ_SNAPSHOT and READ_STREAM together, and a view cannot read a stream.
How the load lines up with the change feed
- Postgres: the scan reads a snapshot taken from a temporary replication slot and moves the stream’s position to that snapshot.
READ_STREAMafterwards returns exactly the transactions the snapshot does not contain. - MongoDB: the load moves the stream’s position to where the change feed was just before the scan. It reads ranges of the collection’s storage order on several cursors at once (one on a sharded cluster or before MongoDB 7.0; the engine configuration’s
execution.cdc.load_source_cursors), starting at that position. The scan is not a point in time: each document is returned as it was at some moment during the scan, and a document deleted and inserted again during the scan can be returned twice. Every document that changed during the scan has events in the feed, so applying the feed past the end of the scan, each event replacing every row with its key, brings every document to the same point in time. Changes made during the scan can appear both in the load and in the feed, soREAD_STREAMreports an insert up to the end of the scan as an update (U). Since the load needs no stored position, it also rebuilds a stream whose position has aged out of the oplog.