Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mN9tH-0005WA-KF for pgsql-general@arkaria.postgresql.org; Mon, 06 Sep 2021 08:22:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mN9tG-0005l5-8W for pgsql-general@arkaria.postgresql.org; Mon, 06 Sep 2021 08:22:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mN9tF-0005kx-Vt for pgsql-general@lists.postgresql.org; Mon, 06 Sep 2021 08:22:05 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mN9tD-000800-Ot for pgsql-general@lists.postgresql.org; Mon, 06 Sep 2021 08:22:04 +0000 Received: by mail-pj1-x102b.google.com with SMTP id gp20-20020a17090adf1400b00196b761920aso4025818pjb.3 for ; Mon, 06 Sep 2021 01:22:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=kJY/C9x7SWI69OQnapSIlNd4FnCQ2rSeQ/m0WANhrtI=; b=cu8c42w/OJxm+o2rp2g7zpstl30G1fGjcjH5LQ66PbtbTz/IkijbGfjR6djpH1eD0l cxX29PoySax20hAaWKQ2ZNgv7OTdGXmR26LXvkRsjY9/DK8HDvtqBdj9zL7Tv3gkLDko ZwBPH6RuLFTzCZZjJtKvXMaMgh2o0ZPIBofLxjNCq2nDSwuUOcGe+lfH8f5k8iPdcWPt KBkT385ma074pUe0j0CXDRaqNP3G292sjLvWu9Wu7DHTDAbHX2doAiyJHQW45e2YecfN DVHF6Uj7Sjv7+MDjLE++bgBBlJUxVozJQD8CV/PGO3QF1mk7SJXogB7eRhrAKxYXX8hn qonA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=kJY/C9x7SWI69OQnapSIlNd4FnCQ2rSeQ/m0WANhrtI=; b=WnOnFg7WTC4PN2nIORLN81xvsvy0/anmgpHuu9ct1MUUrX0tZZar7x5RWKx/xJ1ssD GVp5FFriW0GkvnftiOZAtFJJt0gUhRlpA5LyD22YieU1dVyMzATjsnVdrCgGYPnXvIHr Krbfh6HjN3vRL3ruJVaiAWesqDXlUev/RAHl9+3ZlkWAWRUtwVk2DjlSgB0FWnT+BLlI /M4UHjqSvek9ctwBQsQphttxNqCIaCzJpVRFieKR1vyxRk+sCwSRNBY8S1Q+dK27PIRO QqYhX4oQHV99r9st1+5PHwUK7aHoOmfiLtkE4qmeZ65EeM1YfQPyDykG8veruXNWy9jV W7Eg== X-Gm-Message-State: AOAM530L9enC5bhYDBtP8Mthv+do1J4W2j/28JiVsrP+wBnAXsirMMrw 6ArymNSGmHzoIf6L1uWggS0= X-Google-Smtp-Source: ABdhPJxnjjm+AE7ADfowh36KuKwvZqNGL7F7xvZBfObXExkmfV67OIhHTx95CHF1NYp+2YNr9J6u2A== X-Received: by 2002:a17:902:a710:b029:12b:9b9f:c461 with SMTP id w16-20020a170902a710b029012b9b9fc461mr9704577plq.59.1630916522060; Mon, 06 Sep 2021 01:22:02 -0700 (PDT) Received: from 192-168-1-118.tpgi.com.au (194-193-55-192.tpgi.com.au. [194.193.55.192]) by smtp.gmail.com with ESMTPSA id w11sm6829855pfj.65.2021.09.06.01.21.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Sep 2021 01:22:01 -0700 (PDT) Message-ID: Subject: Re: update non-indexed value is slow if some non-related index/fk are enabled From: rob stone To: Tom Lane , "David G. Johnston" Cc: Philippe Doussot , "pgsql-general@lists.postgresql.org" Date: Mon, 06 Sep 2021 18:21:57 +1000 In-Reply-To: <2875218.1630855266@sss.pgh.pa.us> References: <2875218.1630855266@sss.pgh.pa.us> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.3-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, 2021-09-05 at 11:21 -0400, Tom Lane wrote: > "David G. Johnston" writes: > > On Friday, September 3, 2021, Philippe Doussot < > > philippe.doussot@up.coop> > > wrote: > > > I don't understand why disabling all index from the table speed > > > up the > > > update because the boolean column is not indexed > > > Index entries point to physical records.  You just deleted one > > physical > > record and added another.  The indexes need to be updated with that > > information. > > Yeah.  The OP's mental model is apparently update-in-place, but > that's > not how Postgres does things. > > The index-update overhead is avoided if the update is "HOT", which > requires that (a) no indexed column changes and (b) there is room > on the same page for the new copy of the row.  Ensuring (b) requires > running with a fairly low fill-factor, which bloats your table and > thereby creates its own costs.  Still, that might be worth doing > depending on your particular circumstances. > >                         regards, tom lane > > If the DDL for that table had the column defined like this:- my_boolean BOOLEAN, instead of:- my_boolean BOOLEAN NOT NULL DEFAULT FALSE/TRUE, (whichever is convenient) then that column would contain either 'f' or 't' on insert instead of null. Then even if a fillfactor was not specified for that table, an update of that single column (which does not appear in an index) would merely swap the values. Surely that would write it back in place? Also, having boolean columns containing a null makes it difficult for the getter's of that table deciding if 'null' is true or false. Just an observation. Rob