Skip to content

Commit

Permalink
use lightweight deletes (#120)
Browse files Browse the repository at this point in the history
### TL;DR
Updated the DELETE query syntax in ClickHouse to use lightweight DELETE FROM instead of ALTER TABLE DELETE.

### What changed?
Modified the query string in the `deleteBatch` function to use `DELETE FROM` syntax instead of `ALTER TABLE DELETE` when removing data from ClickHouse tables.

### How to test?
1. Execute delete operations on ClickHouse tables
2. Verify that records are successfully deleted
3. Check that the operation completes without any syntax errors

### Why make this change?
The `ALTER TABLE DELETE` syntax is deprecated in newer versions of ClickHouse. Using `DELETE FROM` is the standard and recommended approach for delete operations, ensuring better compatibility and maintainability.
  • Loading branch information
iuwqyir authored Dec 4, 2024
2 parents 32f151a + 5056f39 commit 7aeffe8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion internal/storage/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ func (c *ClickHouseConnector) DeleteBlockData(chainId *big.Int, blockNumbers []*
}

func (c *ClickHouseConnector) deleteBatch(chainId *big.Int, blockNumbers []*big.Int, table string, blockNumberColumn string) error {
query := fmt.Sprintf("ALTER TABLE %s.%s DELETE WHERE chain_id = ? AND %s IN (?)", c.cfg.Database, table, blockNumberColumn)
query := fmt.Sprintf("DELETE FROM %s.%s WHERE chain_id = ? AND %s IN (?)", c.cfg.Database, table, blockNumberColumn)

blockNumbersStr := make([]string, len(blockNumbers))
for i, bn := range blockNumbers {
Expand Down

0 comments on commit 7aeffe8

Please sign in to comment.