@@ -73,16 +73,8 @@ func (c *ClickHouseConnector) SetupNormalizedTable(
7373 return false , fmt .Errorf ("error while generating create table sql for destination ClickHouse table: %w" , err )
7474 }
7575
76- qryCtx := ctx
77- if config .IsResync {
78- // CREATE OR REPLACE TABLE (used by resync) internally would create a NEW table with name
79- // <_tmp_replace_*>, atomic swap with the existing table, and then drop the existing table.
80- // Setting max_table_size_to_drop = 0 ensure the implicit drop can't fail, since it can be
81- // non-empty if a resync is triggered on top of another resync that is mid-snapshot.
82- qryCtx = clickhouse .Context (ctx , clickhouse .WithSettings (clickhouse.Settings {string (chinternal .SettingMaxTableSizeToDrop ): 0 }))
83- }
8476 for _ , sql := range normalizedTableCreateSQL {
85- if err := c .execWithLogging (qryCtx , sql ); err != nil {
77+ if err := c .execWithLogging (ctx , sql ); err != nil {
8678 return false , fmt .Errorf ("[clickhouse] error while creating destination ClickHouse table: %w" , err )
8779 }
8880 }
@@ -275,9 +267,18 @@ func (c *ClickHouseConnector) generateCreateTableSQLForNormalizedTable(
275267 }
276268 }
277269
270+ chSettings := chinternal .NewCHSettings (chVersion )
278271 if allowNullableKey {
279- stmtBuilder .WriteString (chinternal .NewCHSettingsString (chVersion , chinternal .SettingAllowNullableKey , "1" ))
272+ chSettings .Add (chinternal .SettingAllowNullableKey , "1" )
273+ }
274+ if config .IsResync {
275+ // CREATE OR REPLACE TABLE (used by resync) internally would create a NEW table with name
276+ // <_tmp_replace_*>, atomic swap with the existing table, and then drop the existing table.
277+ // Setting max_table_size_to_drop = 0 ensure the implicit drop can't fail, since it can be
278+ // non-empty if a resync is triggered on top of another resync that is mid-snapshot.
279+ chSettings .Add (chinternal .SettingMaxTableSizeToDrop , "0" )
280280 }
281+ stmtBuilder .WriteString (chSettings .String ())
281282
282283 if c .Config .Cluster != "" {
283284 fmt .Fprintf (& stmtBuilderDistributed , " ENGINE = Distributed(%s,%s,%s" ,
0 commit comments