UPDATE是否成为隐含的​​INSERT [英] Does an UPDATE become an implied INSERT

查看:86
本文介绍了UPDATE是否成为隐含的​​INSERT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Cassandra,如果所选行不存在, UPDATE 是否会隐含地成为 INSERT ?也就是说,如果我说

For Cassandra, do UPDATEs become an implied INSERT if the selected row does not exist? That is, if I say

 UPDATE users SET name = "Raedwald" WHERE id = 545127

id PRIMARY KEY users 表中的$ c>,并且该表没有键为545127的行,将等同于

and id is the PRIMARY KEY of the users table, and the table has no row with a key of 545127, will that be equivalent to

 INSERT INTO users (id, name) VALUES (545127, "Raedwald")

我知道情况正好相反:对于已经存在的 id INSERT 具有该 id 的行的 UPDATE 。出于这个原因,较早的Cassandra文档讨论了插入实际上是 upserts。

I know that the opposite is true: an INSERT for an id that already exists becomes an UPDATE of the row with that id. Older Cassandra documentation talked about inserts actually being "upserts" for that reason.

我对CQL3(Cassandra版本1.2+)感兴趣。

I'm interested in the case for CQL3, Cassandra version 1.2+.

推荐答案

是的,对于Cassandra UPDATE INSERT的同义词,如 CQL文档中所述它说以下有关 UPDATE 的信息:

Yes, for Cassandra UPDATE is synonymous with INSERT, as explained in the CQL documentation where it says the following about UPDATE:


请注意,与SQL不同, UPDATE 不检查该行的先前存在性:如果该行之前不存在,则创建该行,否则进行更新。此外,没有办法知道是哪个创建或更新发生的。实际上, INSERT UPDATE 的语义是相同的。

Note that unlike in SQL, UPDATE does not check the prior existence of the row: the row is created if none existed before, and updated otherwise. Furthermore, there is no mean to know which of creation or update happened. In fact, the semantic of INSERT and UPDATE are identical.

要使语义有所不同,Cassandra需要进行读取才能知道该行是否已存在。 Cassandra经过写优化,因此您可以始终假定它在执行任何写操作之前都不会进行读操作。唯一的例外是计数器(除非 replicate_on_write = false ),在这种情况下,增量复制涉及读取。

For the semantics to be different, Cassandra would need to do a read to know if the row already exists. Cassandra is write optimized, so you can always assume it doesn't do a read before write on any write operation. The only exception is counters (unlessreplicate_on_write = false), in which case replication on increment involves a read.

这篇关于UPDATE是否成为隐含的​​INSERT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆