当前位置: 首页 > 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.gsyq.cn/news/10769.html

相关文章:

  • Docker 私有镜像仓库 Harbor 安装部署带签名认证
  • ARC180 做题记
  • P8865 [NOIP2022] 种花
  • 麦角硫因制备关键技术和设备
  • 反向代理 traefik - 健康检查
  • 一些想法 - CelestialZ
  • 编程规范---日志规范
  • 中电金信:从“通用”到“专用”:加速实现金融行业生成式AI应用的必由之路
  • 自动构建高质量测试集
  • linux gcc attribute
  • 那个…以后拍证件照,可能真不用花钱了
  • 使用 Ansible 批量完成 CentOS 7 操作系统基础配置
  • 深度优先检索:单词搜索
  • 一文看懂Playwright MCP如何引爆AI智能体爆发
  • 从nano banana模型到更加真实的3D打印技术
  • 跨境tk避雷proxy-cheap代理服务商!!!
  • vscode 块运行
  • [C++:类的默认成员函数——Lesson7.const成员函数] - 指南
  • Lombok无法使用get set方法
  • redis的哈希扩容
  • vite tailwindcss配置
  • Git回退版本 reset、revert、read-tree、restore
  • 详细介绍:LeetCode 240. 搜索二维矩阵 II
  • 飞书 燕千云焕新上线,飞书用户即刻试用ITSM工具
  • 如果使用微软 Azure 托管的 OpenAI 服务
  • Alibaba Cloud Linux与 RHEL/CentOS版本对应关系 - 实践
  • OpenCV:人脸识别实战,3 种算法(LBPH/EigenFaces/FisherFaces)代码详解 - 实践
  • 深入解析:Playwright录制时的高亮实现机制分析
  • 什么是文件外发审批?主要有哪几种关键流程?
  • Python入门—Mac如何搭建Python开发环境?