Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tIYg5-00F43p-Vh for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Dec 2024 19:35:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tIYg3-00CSP2-Fp for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Dec 2024 19:35:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tIYg2-00CSOs-Gs for pgsql-hackers@lists.postgresql.org; Tue, 03 Dec 2024 19:35:20 +0000 Received: from fout-a3-smtp.messagingengine.com ([103.168.172.146]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tIYfz-000sh1-0E for pgsql-hackers@lists.postgresql.org; Tue, 03 Dec 2024 19:35:19 +0000 Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id 3A7E51380627; Tue, 3 Dec 2024 14:35:13 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Tue, 03 Dec 2024 14:35:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s=fm3; t=1733254513; x=1733340913; bh=xW7LfnE4tjl9zktWAX19pbDpnig8M43k sf828JDs788=; b=P9iFkwpgXVjHrfaEv9NxzYD05IGzKyS8q75VdOKHca7iHDTU 2u+bnNNp0xbPkKau9YbKu0aRCtQrsmRrsGmyF50xV1epsM63wDy+aea8V8T9MTFm T6ecgMGFj6vqF5CVDl2paJc/dM3+QXkENtvdyHCu9HteSue41nsAFeU7FpqAlL5l 7lPg/HE8xvbj5N2+pGS57Pmi0OL8Agg3+rERQao2reasVg+PznoS4OfmK4XE+OU+ lKotdwqPBgm7DlO2XUyrgc6yNaP09izxosVLwfrE1jabESo1AhUQOJVawwKVE7fV ITdtQSJk0QMaNsGvcyivN3OYBxMrUzxJjZxkhA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1733254513; x= 1733340913; bh=xW7LfnE4tjl9zktWAX19pbDpnig8M43ksf828JDs788=; b=i sCRB1n3CMdobRC9DBBx7DdrMDIBlRB6Ho+fEebB00b6al9ZozO85DdJKVcQ74hit fxe0go0CE7S4NpHUgzrCoZeDD+f70fcMzIhM73yo7Fvi/q/T9mxpSVw43O8/IImu LNDSs5z99g+eWQttVaYFnjGRdR/CB9C6CacQlmd+g01urpfsvdjNK1Qd6hjyVuXB UbVpNdjwYe2TjC6sNwqTQFPwXsLy/MIg2Ro8CpPeBj6dUmy4YceNg3TNZZDmXNqi LQf8tU3f2/HxVMUa2vFwK/w3SqC6a8VhAhWJnG1UBVeJ5aiYJImXCjbrlLW0PrPy 0yQnYO0tmn3QQ2YxPvVIg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrieefgdelkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpefkffggfgfuvfevfhfhjggtgfesthekredttddvjeen ucfhrhhomheprfgvthgvrhcugfhishgvnhhtrhgruhhtuceophgvthgvrhesvghishgvnh htrhgruhhtrdhorhhgqeenucggtffrrghtthgvrhhnpeetffevleefledtvdejgedtfeej gfelfeelvdfffeejudejveehiefggfejgffggeenucffohhmrghinhepphhoshhtghhrvg hsqhhlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhf rhhomhepphgvthgvrhesvghishgvnhhtrhgruhhtrdhorhhgpdhnsggprhgtphhtthhope egpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehtghhlsehsshhsrdhpghhhrdhp rgdruhhspdhrtghpthhtohepjhhirghnrdhunhhivhgvrhhsrghlihhthiesghhmrghilh drtghomhdprhgtphhtthhopehrvghshhhkvghkihhrihhllhesghhmrghilhdrtghomhdp rhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgvsh hqlhdrohhrgh X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 3 Dec 2024 14:35:12 -0500 (EST) Message-ID: <345c20e5-a6d7-477a-9598-982661bb5740@eisentraut.org> Date: Tue, 3 Dec 2024 20:35:10 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: CREATE SCHEMA ... CREATE DOMAIN support To: Tom Lane , jian he Cc: Kirill Reshke , PostgreSQL Hackers References: <1898722.1732732780@sss.pgh.pa.us> <2007224.1732773174@sss.pgh.pa.us> <1075425.1732993688@sss.pgh.pa.us> Content-Language: en-US From: Peter Eisentraut In-Reply-To: <1075425.1732993688@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 30.11.24 20:08, Tom Lane wrote: > 2. transformCreateSchemaStmtElements is of the opinion that it's > responsible for ordering the schema elements in a way that will work, > but it just about completely fails at that task. Ordering the objects > by kind is surely not sufficient, and adding CREATE DOMAIN will make > that worse. (Example: a domain could be used in a table definition, > but we also allow domains to be created over tables' composite types.) > Yet we have no infrastructure that would allow us to discover the real > dependencies between unparsed DDL commands, nor is it likely that > anyone will ever undertake building such. I think we ought to nuke > that concept from orbit and just execute the schema elements in the > order presented. I looked at several iterations of the SQL standard > and cannot find any support for the idea that CREATE SCHEMA needs to > be any smarter than that. I'd also argue that doing anything else is > a POLA violation. It's especially a POLA violation if the code > rearranges a valid user-written command order into an invalid order, > which is inevitable if we stick with the current approach. > > The notion that we ought to sort the objects by kind appears to go > all the way back to 95ef6a344 of 2002-03-21, which I guess makes it > my fault. There must have been some prior mailing list discussion, > but I couldn't find much. There is a predecessor of the committed > patch in > https://www.postgresql.org/message-id/flat/3C7F8A49.CC4EF0BE%40redhat.com > but no discussion of why sorting by kind is a good idea. (The last > message in the thread suggests that there was more discussion among > the Red Hat RHDB team, but if so it's lost to history now.) SQL/Framework subclause "Descriptors" says: """ The execution of an SQL-statement may result in the creation of many descriptors. An SQL object that is created as a result of an SQL-statement may depend on other descriptors that are only created as a result of the execution of that SQL statement. NOTE 8 — This is particularly relevant in the case of the SQL-statement. A can, for example, contain many s that in turn contain
s. A single
in one
can reference a second table being created by a separate
which itself is able to contain a reference to the first table. The dependencies of each table on the descriptors of the other are valid provided that all necessary descriptors are created during the execution of the complete . """ So this says effectively that forward references are allowed. Whether reordering the statements is a good way to implement that is dubious, as we are discovering.