Performance “非常慢”;更新表格";博士后手术

Performance “非常慢”;更新表格";博士后手术,performance,postgresql,indexing,Performance,Postgresql,Indexing,我使用的是Postgres9.2,出于某种原因,我在一个相对较小的表(16k行)上遇到了更新速度非常慢的问题。这是DDL表: CREATE TABLE my_categories ( id SERIAL, category_id INTEGER, is_done SMALLINT DEFAULT 0, expected_number_of_flags INTEGER DEFAULT 0 NOT NULL, number_of_flags INTEGER DEFAULT 0 N

我使用的是Postgres9.2,出于某种原因,我在一个相对较小的表(16k行)上遇到了更新速度非常慢的问题。这是DDL表:

CREATE TABLE my_categories (
  id SERIAL,
  category_id INTEGER,
  is_done SMALLINT DEFAULT 0,
  expected_number_of_flags INTEGER DEFAULT 0 NOT NULL,
  number_of_flags INTEGER DEFAULT 0 NOT NULL,
  is_active SMALLINT DEFAULT 0 NOT NULL,
  CONSTRAINT my_categories_pkey PRIMARY KEY(id)
) 
WITH (oids = false);

CREATE INDEX my_categories_idx ON my_categories USING btree (category_id);
以下是更新某些行的统计信息:

explain analyze 
update my_categories
set expected_number_of_flags = expected_number_of_flags + 1 
where category_id = 96465;

Update on my_categories  (cost=4.27..8.29 rows=1 width=26) (actual time=199746.281..199746.281 rows=0 loops=1)
  ->  Bitmap Heap Scan on my_categories  (cost=4.27..8.29 rows=1 width=26) (actual time=50.937..51.193 rows=1 loops=1)
      Recheck Cond: (category_id = 96465)
      ->  Bitmap Index Scan on my_categories_idx  (cost=0.00..4.27 rows=1 width=0) (actual time=1.600..1.600 rows=6167 loops=1)
            Index Cond: (category_id = 96465)
Total runtime: 199746.339 ms
你能解释一下发生了什么,我怎样才能提高这个更新的性能吗


谢谢

您可以尝试将FILLFACTOR设置为70或60,从现在起默认设置为100,如下所示:

ALTER TABLE my_categories SET (FILLFACTOR = 70);
VACUUM FULL my_categories;
REINDEX TABLE my_categories;

然后您可以尝试运行更新查询。

问题-此标志是否也适用于保留删除和重新插入行的表,还是仅适用于更新操作?@Seffy:-它将有助于操作,也适用于删除操作