Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUFe5-00054E-6u for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Dec 2018 18:42:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gUFe3-0004nu-Qy for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Dec 2018 18:42:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUFe3-0004nf-HU for pgsql-hackers@lists.postgresql.org; Tue, 04 Dec 2018 18:42:07 +0000 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gUFe0-0000CP-35 for pgsql-hackers@lists.postgresql.org; Tue, 04 Dec 2018 18:42:07 +0000 Received: by mail-qk1-x743.google.com with SMTP id y16so10260676qki.7 for ; Tue, 04 Dec 2018 10:42:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=7CjGQSBu5M9aF2R4k5mA2lRewt13RQrjwtz8QXZsGQE=; b=cWDiYTdGF2RanBGNCgKi9B9gbZ4HKjXOAKINTJOwv8eocB5SwhCTcUw729QqQYWNFI wsuwUc+GCCUoVHS7rgaqVPEtfUAWIJfMIW0JTSi3qaIUYsD0jLm4ClDJDMAwInnALXvl UTXmTnyPi7rPJWjRade2fEoKB6SEj46OzhOS+QHaeivFuq/zMsmQvtN6vBJxsoqkaT9c dfZ46t3HkLL0MpTww++fTX0SlcXCD2zts8QPdRk9zdiGP7k8w89S1AMnrplDymwhYM2d ivYmiwsvdMIz/zeQYCAxuIgh5eJXVO6ZdTo9p6NN5osocp2ypvtkbaru9HXGCCE8Ek/O EYmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=7CjGQSBu5M9aF2R4k5mA2lRewt13RQrjwtz8QXZsGQE=; b=nY0DJCJo/ZOw5eP1IWBQfujMLS/fZ0z3fOz9vgPlIy2tbKGknk5xz7GxX3UEkUK1KG Nb+beYSGqdDrfeVTkbPWaBfVsuNDwydTLv/npZSlPUe77ONONq73V0wbiC+u9HrMS2Wr tCQD77WY0NxeU+8Jqdd9cPFpGU0SqEjsNnKm0//+jc5hLTDPwG7BUL0wd473AukFH7R8 B5nHUEf4g7WM5g1yuyLlTZH/1QcB6gBZ5z73UzoGUGajl9AgUnYD7XUjwVPlnhz11hCC VDrqpNkVfWc211Z/JwZNXeF4HxARi6BAisSDBQF/vCfal0wv4DYrwqEIKTrUHrLwg898 aMVQ== X-Gm-Message-State: AA+aEWYBIX233GBoAt3RXQlWV6Bmr6tYgG3RNJC1SdCWkIJrCiASbHav xanm0+CHJmzSjWPd6DmPdvx5v9ZiGJ7ulcOmGQFw5UV/2czbwlTbKYgkFK5RKY97Tt9eFpQ86gQ 0hYTx6D6T+kfHQ2JKOjz6DNre5fvR91XxHh3+FDslAihIiUWU3YXaQd2XE4/JpmffgL8yO9OSep api3idmsj5cktS4A== X-Google-Smtp-Source: AFSGD/W4BnRjpngsxD2Av2BmX4MkxHDKiayHmN7flRgLq0unLjE3ocNZC9k/mR32fiZChYW79NyyBA== X-Received: by 2002:a37:70c3:: with SMTP id l186mr19492828qkc.222.1543948922063; Tue, 04 Dec 2018 10:42:02 -0800 (PST) Received: from alvin.alvh.no-ip.org ([201.186.80.75]) by smtp.gmail.com with ESMTPSA id l33sm12566813qta.57.2018.12.04.10.42.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Dec 2018 10:42:01 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id C352E422; Tue, 4 Dec 2018 15:41:59 -0300 (-03) Date: Tue, 4 Dec 2018 15:41:59 -0300 From: Alvaro Herrera To: Tom Lane Cc: Pg Hackers Subject: Re: psql display of foreign keys Message-ID: <20181204184159.eue3wlchqrkh4vsc@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <23923.1543935600@sss.pgh.pa.us> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2018-Dec-04, Tom Lane wrote: > ... this patch breaks the expectation set at the top of describe.c: > > * Support for the various \d ("describe") commands. Note that the current > * expectation is that all functions in this file will succeed when working > * with servers of versions 7.4 and up. It's okay to omit irrelevant > * information for an old server, but not to fail outright. Fixed in the attached. > Do you really need WITH RECURSIVE for this? I don't see any other way, but I'm open to ideas. > If so, I'd suggest applying it only when relkind == > RELKIND_PARTITIONED_TABLE, so that the case doesn't happen in servers > too old to have WITH. That's probably a win performance-wise anyway, > as I have no doubt that the performance of this query is awful > compared to what it replaces, so we don't really want to use it if we > don't have to. The query to display foreign keys on the current table can continue to use the old, fast version when the table is not a partition (I had to add the relispartition column to another query for this to work). But I cannot use the old version for the query that searches for FKs referencing the current table, because the table for which partitionedness matters is the other one. (The WITH version is only used for servers that can have foreign keys on partitioned tables, viz. 11). I spent a few minutes trying to think of a way of determining which query to use at SQL-execution time -- two CTEs, one of which would be short-circuited ... but I couldn't figure out how. I also tried to use the new pg_partition_tree() function, but it's useless for this purpose because it roots at its argument table, and there doesn't seem to be a convenient way to obtain the topmost ancestor. v2 attached. Many thanks for reviewing. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services