如果它是一个单行表,那么按照 @Gordon Linoff 的建议,用可以为 NULL 的单行填充它没有任何风险。
在内部,您应该知道 Vertica 在后台始终将 UPDATE 实现为 DELETE,方法是为行添加删除向量,然后应用 INSERT。
单行表没问题,作为 Tuple Mover(后台守护进程唤醒所有 5 分钟以对内部存储进行碎片整理,简单地说,将创建单个数据(读取优化存储- ROS) container out of: 前一个值;指向该前一个值的删除向量,从而将其停用,以及它更新到的新插入的值。
所以:
CREATE TABLE table1 (
mycol VARCHAR(16)
) UNSEGMENTED ALL NODES; -- a small table, replicate it across all nodes
-- now you have an empty table
-- for the following scenario, I assume you commit the changes every time, as other connected
-- processes will want to see the data you changed
-- then, only once:
INSERT INTO table1 VALUES(NULL::VARCHAR(16);
-- now, you get a ROS container for one row.
-- Later:
UPDATE table1 SET mycol='first value';
-- a DELETE vector is created to mark the initial "NULL" value as invalid
-- a new row is added to the ROS container with the value "first value"
-- Then, before 5 minutes have elapsed, you go:
UPDATE table1 SET mycol='second value';
-- another DELETE vector is created, in a new delete-vector-ROS-container,
-- to mark "first value" as invalid
-- another new row is added to a new ROS container, containing "second value"
-- Now 5 minutes have elapsed since the start, the Tuple Mover sees there's work to do,
-- and:
-- - it reads the ROS containers containing "NULL" and "first value"
-- - it reads the delete-vector-ROS containers marking both "NULL" and "first value"
-- as invalid
-- - it reads the last ROS container containing "second value"
-- --> and it finally merges all into a brand new ROS container, to only contain.
-- "second value", and, at the end the four other ROS containers are deleted.
对于单行表,这非常有效。不要对十亿行这样做。