当前位置: 首页 > news >正文

ClickHouse UPDATE 操作问题解决方案 - 若

ClickHouse UPDATE 操作问题解决方案

问题背景

在使用ClickHouse进行数据更新操作时,遇到了以下错误:Lightweight updates are not supported

2025.09.24 11:08:51.283185 [ 70414 ] {09f4305c-14c5-4d63-a251-3179f5373d6d} <Error> executeQuery: Code: 48. DB::Exception: Lightweight updates are not supported. Lightweight updates are supported only for tables with materialized _block_offset column. Run 'MODIFY SETTING enable_block_offset_column = 1' command to enable it. (NOT_IMPLEMENTED) (version 25.8.2.29 (official build)) (from [::ffff:192.168.31.94]:53719) (in query: update ethereum.block_tasks set status = 'pending', owner = 'consumer-1_1758676754070328000', assigned_at = '2025-09-24 09:19:14.07', updated_at = '2025-09-24 09:19:14.07' WHERE start_block = ( SELECT start_block FROM ethereum.block_tasks WHERE (status = 'init' OR (status = 'pending' AND assigned_at < '2025-09-24 09:09:14.07')) AND (owner = '' OR owner IS NULL) ORDER BY start_block DESC LIMIT 1 )), Stack trace (when copying this message, always include the lines below):0. DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x00000000133a211f
1. DB::Exception::Exception(String&&, int, String, bool) @ 0x000000000c84f4ce
2. DB::Exception::Exception(PreformattedMessage&&, int) @ 0x000000000c84ef80
3. DB::Exception::Exception<String&>(int, FormatStringHelperImpl<std::type_identity<String&>::type>, String&) @ 0x000000000c86826b
4. DB::InterpreterUpdateQuery::execute() @ 0x00000000183d01b2
5. DB::executeQueryImpl(char const*, char const*, std::shared_ptr<DB::Context>, DB::QueryFlags, DB::QueryProcessingStage::Enum, std::unique_ptr<DB::ReadBuffer, std::default_delete<DB::ReadBuffer>>&, std::shared_ptr<DB::IAST>&, std::shared_ptr<DB::ImplicitTransactionControlExecutor>) @ 0x000000001832e352
6. DB::executeQuery(std::unique_ptr<DB::ReadBuffer, std::default_delete<DB::ReadBuffer>>, DB::WriteBuffer&, bool, std::shared_ptr<DB::Context>, std::function<void (DB::QueryResultDetails const&)>, DB::QueryFlags, std::optional<DB::FormatSettings> const&, std::function<void (DB::IOutputFormat&, String const&, std::shared_ptr<DB::Context const> const&, std::optional<DB::FormatSettings> const&)>, std::function<void ()>) @ 0x000000001833312a
7. DB::HTTPHandler::processQuery(DB::HTTPServerRequest&, DB::HTMLForm&, DB::HTTPServerResponse&, DB::HTTPHandler::Output&, std::optional<DB::CurrentThread::QueryScope>&, StrongTypedef<unsigned long, ProfileEvents::EventTag> const&) @ 0x0000000019940621
8. DB::HTTPHandler::handleRequest(DB::HTTPServerRequest&, DB::HTTPServerResponse&, StrongTypedef<unsigned long, ProfileEvents::EventTag> const&) @ 0x0000000019945224
9. DB::HTTPServerConnection::run() @ 0x0000000019a16760
10. Poco::Net::TCPServerConnection::start() @ 0x000000001ef1e687
11. Poco::Net::TCPServerDispatcher::run() @ 0x000000001ef1eb19
12. Poco::PooledThread::run() @ 0x000000001eee5147
13. Poco::ThreadImpl::runnableEntry(void*) @ 0x000000001eee3541
14. ? @ 0x0000000000094ac3
15. ? @ 0x0000000000125a04

解决方案

在创建表时添加以下设置即可解决:

CREATE TABLE block_tasks (-- 表结构定义
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(toDateTime(created_at))
PRIMARY KEY (start_block, end_block)
ORDER BY (start_block, end_block)
SETTINGS enable_block_number_column = 1, enable_block_offset_column = 1;

GORM代码示例:

err := db.Table(model.BlockTaskTableName).Set("gorm:table_options", "ENGINE = MergeTree() PARTITION BY toYYYYMM(toDateTime(created_at)) "+"PRIMARY KEY(start_block, end_block) "+"ORDER BY (start_block, end_block) "+"SETTINGS enable_block_number_column = 1, enable_block_offset_column = 1").AutoMigrate(&model.BlockTask{})

设置参数说明

  • enable_block_number_column = 1:启用内部块编号列,支持轻量级更新机制
  • enable_block_offset_column = 1:启用块偏移列,提供更精确的数据定位

总结

通过设置 enable_block_number_column = 1enable_block_offset_column = 1,可以启用ClickHouse的轻量级更新机制,解决UPDATE操作的问题。

http://www.hskmm.com/?act=detail&tid=15617

相关文章:

  • 利用 Milvus + RustFS,快速打造一个 RAG!
  • Docker 私有镜像仓库 Harbor 安装部署带签名认证
  • ARC180 做题记
  • 借助Aspose.HTML控件,使用 Python 编辑 HTML
  • 微前端 micro-app 在vue 中的路由跳转问题
  • 1. 设计模式--工厂办法模式
  • 汽车视频总线采集过程中,如何兼顾响应速度和可靠性?
  • P8865 [NOIP2022] 种花
  • traefik 反向代理 + IdentityServer4
  • 麦角硫因制备关键技术和设备
  • 2025年十大好用网盘推荐:功能、口碑与性价比大对比
  • 卡特兰数
  • Word-通过宏格式化文档中的表格和图片
  • 反向代理 traefik - 健康检查
  • 一些想法 - CelestialZ
  • 使用 Ansible 批量安装 Docker
  • 编程规范---日志规范
  • 深入解析:find_code 插件 react_vite
  • 二十一、DevOps:从零建设基于K8s的DevOps平台(二)
  • 中电金信:从“通用”到“专用”:加速实现金融行业生成式AI应用的必由之路
  • 自动构建高质量测试集
  • SAP BAPI_PR_CREATE 创建采购申请(含自定义字段)
  • NCCL论文阅读
  • 新手项目经理如何选工具?2025年这5款上手快、不复杂的项目管理软件适合你
  • 用DiskGenius重新分区,检测出U盘虚标容量。
  • 2025低空经济时空信息平台
  • linux gcc attribute
  • 那个…以后拍证件照,可能真不用花钱了
  • CF2147G
  • 全栈开发者效率工具图谱:从IDE到云服务的最优组合 - 指南