批量更新一百万行

Bulk Update a million rows

假设我在 table 中有一百万行。我想将列中的标志从 true 翻转为 false。我如何在扳手中用一条语句做到这一点?

也就是我要实现如下DML语句

更新我的table 设置 myflag=true 其中 1=1;

Cloud Spanner 目前不支持 DML,但我们正在开发一个数据流连接器 (Apache Beam),它允许您进行批量修改。

您可以使用this open source JDBC driver in combination with a standard JDBC tool like for example SQuirreL or SQL Workbench. Have a look here for a short tutorial on how to use the driver with these tools: http://www.googlecloudspanner.com/2017/10/using-standard-database-tools-with.html

JDBC 驱动程序同时支持 DML 和 DDL 语句,因此该语句应该开箱即用:

Update mytable set myflag=true

支持对大量行进行操作的 DML 语句,但 Cloud Spanner 的底层事务配额继续适用(一个事务中最多 20,000 个突变)。您可以通过设置 AllowExtendedMode=true 连接 属性 来绕过它(请参阅驱动程序的 Wiki 页面)。这会将一个大更新分成几个较小的更新,并在其自己的事务中执行每个更新。您也可以通过将更新语句分成几个不同的部分来自己进行批处理。