2016-05-11 27 views

回答

1

取而代之的是隻具有獨特的鍵是有用的,否則它只是相當於插入和列存儲表不支持唯一的密鑰。

有沒有一種好的方法可以有效地在列存儲中實現它,因爲列存儲通常不打算很好地執行單行更新。見http://docs.memsql.com/docs/columnstore

你可以實現它的一種方式(不是非常有效)是多態事務。運行一個select來查看匹配的行是否已經存在,如果是的話運行更新,否則運行插入。

E.g.說我們有

create table c(i int, a int, key using clustered columnstore(i)); 

我們可以在沒有匹配的情況下做

memsql> begin; 
Query OK, 0 rows affected (0.00 sec) 

memsql> select count(*) from c where i = 4; 
+----------+ 
| count(*) | 
+----------+ 
|  0 | 
+----------+ 
1 row in set (0.00 sec) 

memsql> insert into c values (4, 4); 
Query OK, 1 row affected (0.00 sec) 

memsql> commit; 
Query OK, 0 rows affected (0.00 sec) 

,並

memsql> begin; 
Query OK, 0 rows affected (0.00 sec) 

memsql> select count(*) from c where i = 4; 
+----------+ 
| count(*) | 
+----------+ 
|  1 | 
+----------+ 
1 row in set (0.01 sec) 

memsql> update c set a = 4 where i = 4; 
Query OK, 1 row affected (0.01 sec) 
Rows matched: 1 Changed: 1 Warnings: 0 

memsql> commit; 
Query OK, 0 rows affected (0.00 sec) 

在那裏有一個匹配的情況。