Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fp36Y-0003RB-Bp for pgsql-general@arkaria.postgresql.org; Mon, 13 Aug 2018 03:01:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fp36W-0001EZ-RR for pgsql-general@arkaria.postgresql.org; Mon, 13 Aug 2018 03:01:12 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fp36W-0001ER-Fw for pgsql-general@lists.postgresql.org; Mon, 13 Aug 2018 03:01:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fp36R-0001rl-W4 for pgsql-general@postgresql.org; Mon, 13 Aug 2018 03:01:11 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w7D30wrj011122; Sun, 12 Aug 2018 23:00:58 -0400 From: Tom Lane To: Tim Cross cc: Olivier Gautherot , Adrian Klaver , space.ship.traveller@gmail.com, Postgres General Subject: Re: Safe operations? In-reply-to: References: Comments: In-reply-to Tim Cross message dated "Mon, 13 Aug 2018 12:45:33 +1000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <11120.1534129258.1@sss.pgh.pa.us> Date: Sun, 12 Aug 2018 23:00:58 -0400 Message-ID: <11121.1534129258@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Tim Cross writes: > On Mon, 13 Aug 2018 at 12:23, Olivier Gautherot >> On Sun, Aug 12, 2018 at 11:06 PM, Tim Cross wrote: >>> Just wondering - what about the case when the column being renamed is >>> also referenced in an index or check constraint? >> Tim, as far as I know, names are only an attribute tagged to an OID. >> Internal relations are though these OIDs, not names, so renaming a column >> is really one-shot. Names are mainly a more convenient way of referring to >> objects. > thanks Olivier, that is what I suspected and your explanation fits with my > mental model. I had assumed table/column names are convenience for humans > and that the system would use OIDs etc for internal references. Right, catalog internal references are all via OIDs or column numbers, so that the only thing the system thinks it needs to do is update the "name" field in a single catalog row. (A problem with this is that user-defined function bodies are stored as text; so you may well have to run around and fix your functions by hand. But that doesn't contribute to the cost of the RENAME operation per se.) Getting back to Samuel's original question, the reason we don't try to document performance issues like this is that there are just too many moving parts. Yeah, the update of the catalog row should be more or less O(1), and then the required updates of the catalog's indexes will be more or less O(log N) (N being the number of rows in that catalog). But in practice the main constraint is often the need to obtain locks on the relevant database objects, and that's really hard to give a prediction for. regards, tom lane