是否可以在 Scylla DB
中重置计数器列?
在 Cassandra
中,it is not possible直接将计数器列重置为零:
There is no operation that will allow resetting the counter value. You need to read the value and decrement it using that value. Be aware that this operation might not be successful since the counter can be changed between your "reset" operations.
Scylla DB
也是如此吗?
最佳答案
Scylla 中也有类似的行为。 我们不能将计数器值重置为 0,计数器只能递增或递减。
scylla@cqlsh:ks> CREATE TABLE cf (pk int PRIMARY KEY, my_counter counter);
scylla@cqlsh:ks> UPDATE cf SET my_counter = my_counter + 3 WHERE pk = 0;
scylla@cqlsh:ks> SELECT * FROM cf;
pk | my_counter
----+------------
0 | 3
(1 rows)
scylla@cqlsh:ks> UPDATE cf SET my_counter = 0 WHERE pk = 0;
InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot set the value of counter column my_counter (counters can only be incremented/decremented, not set)"
scylla@cqlsh:ks> UPDATE cf SET my_counter = my_counter - 3 WHERE pk = 0;
scylla@cqlsh:ks> SELECT * FROM cf;
pk | my_counter
----+------------
0 | 0
(1 rows)
请注意尝试直接设置值时的错误。
更多相关信息:
https://docs.scylladb.com/using-scylla/counters/#scylla-counters
关于database - 如何将 Scylla DB 中的计数器列重置为零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72178766/