Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y3AiX-0007Ab-4r for pgsql-performance@arkaria.postgresql.org; Mon, 22 Dec 2014 21:40:41 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y3AiW-0004BG-ML for pgsql-performance@arkaria.postgresql.org; Mon, 22 Dec 2014 21:40:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Y3AiV-0004B9-GP for pgsql-performance@postgresql.org; Mon, 22 Dec 2014 21:40:39 +0000 Received: from smtp-outbound-1.vmware.com ([208.91.2.12]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Y3AiQ-0006G4-Gz for pgsql-performance@postgresql.org; Mon, 22 Dec 2014 21:40:38 +0000 Received: from sc9-mailhost2.vmware.com (sc9-mailhost2.vmware.com [10.113.161.72]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id A075C282DF; Mon, 22 Dec 2014 13:40:29 -0800 (PST) Received: from EX13-CAS-002.vmware.com (EX13-CAS-002.vmware.com [10.113.191.52]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 9B6AAB0C4F; Mon, 22 Dec 2014 13:40:29 -0800 (PST) Received: from EX13-MBX-024.vmware.com (10.113.191.44) by EX13-MBX-005.vmware.com (10.113.191.25) with Microsoft SMTP Server (TLS) id 15.0.913.22; Mon, 22 Dec 2014 13:42:16 -0800 Received: from [192.168.1.90] (10.113.160.246) by EX13-MBX-024.vmware.com (10.113.191.44) with Microsoft SMTP Server (TLS) id 15.0.913.22; Mon, 22 Dec 2014 13:40:28 -0800 Message-ID: <54988FBD.1050506@vmware.com> Date: Mon, 22 Dec 2014 23:40:13 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.3.0 MIME-Version: 1.0 To: Robert DiFalco , "pgsql-performance@postgresql.org" Subject: Re: Number of Columns and Update References: In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.113.160.246] X-ClientProxiedBy: EX13-CAS-013.vmware.com (10.113.191.65) To EX13-MBX-024.vmware.com (10.113.191.44) X-Pg-Spam-Score: -6.9 (------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 12/22/2014 10:53 PM, Robert DiFalco wrote: > This may fall into the category of over-optimization but I've become > curious. > > I have a user table with about 14 columns that are all 1:1 data - so they > can't be normalized. > > When I insert a row all columns need to be set. But when I update, I > sometimes only update 1-2 columns at a time. Does the number of columns > impact update speed? > > For example: > UPDATE users SET email = ? WHERE id = ?; Yes, the number of columns in the table matters. The update is just as expensive regardless of how many of the columns you update. When a row is updated, PostgreSQL creates a new version of the whole row. The new row version takes more space when the table has more columns, leading to more bloating of the table, which generally slows things down. In most applications the difference isn't big enough to matter, but it can be significant if you have very wide rows, and you update a lot. PostgreSQL 9.4 made an improvement on this. In earlier versions, the new row version was also included completely in the WAL record, which added overhead. In 9.4, any columns at the beginning or end of the row that are not modified are left out of the WAL record, as long as the new row version is stored on the same page as the old one (which is common). For updating a single column, or a few columns that are next to each other, that's the same as saying that only the modified part of the row is WAL-logged. > I can easily break this up into logical tables like user_profile, > user_credential, user_contact_info, user_summary, etc with each table only > having 1-4 columns. But with the multiple tables I would often be joining > them to bring back a collection of columns. That would help with the above-mentioned issues, but dealing with multiple tables certainly adds a lot of overhead too. Most likely you're better off just having the single table, after all. - Heikki -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance