小编Nik*_*l N的帖子

有人可以解释执行数百万个更新的奇怪行为吗?

有人可以向我解释这种行为吗?我在 OS X 上本机运行的 Postgres 9.3 上运行了以下查询。我试图模拟一些行为,其中索引大小可能增长得比表大小大得多,但发现了一些更奇怪的东西。

CREATE TABLE test(id int);
CREATE INDEX test_idx ON test(id);

CREATE FUNCTION test_index(batch_size integer, total_batches integer) RETURNS void AS $$
DECLARE
  current_id integer := 1;
BEGIN
FOR i IN 1..total_batches LOOP
  INSERT INTO test VALUES (current_id);
  FOR j IN 1..batch_size LOOP
    UPDATE test SET id = current_id + 1 WHERE id = current_id;
    current_id := current_id + 1;
  END LOOP;
END LOOP;
END;
$$ LANGUAGE plpgsql;

SELECT test_index(500, 10000);
Run Code Online (Sandbox Code Playgroud)

我让它在我的本地机器上运行了大约一个小时,然后我开始从 OS X 收到磁盘问题警告。我注意到 Postgres …

postgresql

8
推荐指数
2
解决办法
245
查看次数

标签 统计

postgresql ×1