Skip to main content
The most likely reason is insert deduplication. ClickHouse keeps the hashes of the last inserted blocks, and when an INSERT brings a block with exactly the same data, it treats it as a retry and skips it. Deleting the rows does not remove that hash, so the second INSERT reports success but writes nothing. To insert the data again, give the INSERT its own insert_deduplication_token.

Example

Deduplication is on by default for replicated tables, including the tables of a ClickHouse Cloud service. A plain MergeTree table keeps no deduplication log unless you set non_replicated_deduplication_window, which this example does so that you can reproduce the behavior on a single server:
The last INSERT repeats the first one byte for byte, so it is skipped. The rows 1 and 2 are not in the table.

Confirm that the insert was deduplicated

The skipped block is recorded in system.part_log as a NewPart event with the error INSERT_WAS_DEDUPLICATED:
The DuplicatedInsertedBlocks profile event of the INSERT query in system.query_log is greater than zero as well.

Insert the data again

Pass a deduplication token that you have not used before. With a token, ClickHouse compares the token instead of the hash of the data:
A token keeps the protection against retries: if the same statement is sent twice with the same token, the second one is skipped. For the same reason, do not reuse a token for different data. Alternatively, turn deduplication off for that one statement. A retry of such an INSERT writes the rows twice:
Since ClickHouse 26.2, deduplicate_insert is enable by default, and SET insert_deduplicate = 0 alone no longer turns deduplication off. On earlier releases use insert_deduplicate = 0.

What decides whether a block is a duplicate

  • The hash covers a whole inserted block. An INSERT with different rows, a different number of rows, or one changed value is not a duplicate. In the example, inserting only the row (1, 'new') would have worked.
  • ALTER TABLE ... DELETE and DELETE FROM leave the stored hashes in place. TRUNCATE TABLE and ALTER TABLE ... DROP PARTITION remove the hashes of the data they drop, so the same data can be inserted again after them.
  • Replicated tables keep the hashes of the most recent replicated_deduplication_window blocks (10000 by default) and drop hashes older than replicated_deduplication_window_seconds (one hour by default). An identical block inserted after its hash has left the window is accepted.
  • Non-replicated MergeTree tables deduplicate only if non_replicated_deduplication_window is set. It is 0 by default.
For the full description, see Deduplicating inserts on retries.

Another cause: reading from a replica that is behind

If the service has several replicas and the DELETE, the INSERT and the SELECT do not all go to the same replica, the SELECT can run on a replica that has not received the new rows yet. They appear a moment later without any action. See How to achieve data read consistency in ClickHouse for ways to read your own writes.