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 1jYFfe-0003zN-DV for pgsql-hackers@arkaria.postgresql.org; Mon, 11 May 2020 21:09:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jYFfd-0005Of-9u for pgsql-hackers@arkaria.postgresql.org; Mon, 11 May 2020 21:09:05 +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 1jYFfc-0005OY-QQ for pgsql-hackers@lists.postgresql.org; Mon, 11 May 2020 21:09:05 +0000 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jYFfY-0007nh-T2 for pgsql-hackers@lists.postgresql.org; Mon, 11 May 2020 21:09:03 +0000 Received: by mail-qk1-x743.google.com with SMTP id a136so2473617qkg.6 for ; Mon, 11 May 2020 14:09:00 -0700 (PDT) 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=ovhDzaXWu19FatHkrVR6OAxy0uceGJ91ktqk9mAcsIA=; b=M0mzDcZ4IsBTb6OQoOuQHAIaldnwRU28twvtU4XcHSgmPn2hOwivlUWPa2/rVB3+EF 6wxJF/ZJh37Gv/7SZH+3nQRfqw8bsGvonbJNhuJjPbKRVdiLeJTQkKLqnsgJ2X5VAhYv dYMeu1PLA8dkxyQ7wCU8++iO9UFmOis/ullvha842ZBEX4Lpdg6lWALuvXnPayLLXMsd ErY1/ZRJcHMtqjz4YSDEzqtH44MC5p976nbBgPv2fkIIm3yREE8MR8Nxu9PmIWSk7kWx kONg/ml6X2JQ+N+Uqogdz7PAP/u/DAckye50pHaVEziNKAe6oQ7Kf9xEspUraIQT1Wtk oSng== 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=ovhDzaXWu19FatHkrVR6OAxy0uceGJ91ktqk9mAcsIA=; b=F7yxsOHZ5NVWph8OhBvWmdV1vbnNdlTtBqgBd+WksMrE40TqI0TFVDVy5hlcDdhKoS N9PQdHI4mbLCSj/jMg9mBdF6rUQIJF4SBeQyObckw7tRHKBWSfmnM7KvDrAuOEU2bxq4 5OGroz+YJJ6XJb0J2RiVQbvEHkWABp/gobECrhgK6Cd7QKwvYXx9ua6hONEdMQO71q7u +QElEMJVhZnyCwJiRS3gd6o5aSo38kRZG0HbZ+7C810gMO9aDCGnDX6m9Tr7C1RpJWPF GePBTw0BBn/51ZCD+432O2ZMEqFLDf6hvOU6C7OFz8G1P9wUGPHzvZStl2odF0pXDDgA Idxw== X-Gm-Message-State: AGi0Pubv5Yoc7P/q8Y7kc4YrdOSWj7OsK+t+D3sjS3pwtJSEFStBb90r S6T4kPcXfn9F9x6ZRPG+QNLg4G+Ho34+0NgYkniRC1MYKBkdw3ps9n4KF2OQHiqKJDiMCSh2Bym sWWvc6yc+fq3nQ0vAbWpw8P1kWGkwYWNv68DQzA0BSuLkzaxj0budJFzhxMDuWc1rhsfdXE5NVN jskHVXeCvfEIw1UGv/ X-Google-Smtp-Source: APiQypJUCKRsbxRq9jn9/HRAcrh5kGDn+FZYyL/AVilbu2Ji0Lw/XLIPfUn4gCdUy2JrxV1aViqaqg== X-Received: by 2002:ae9:ef89:: with SMTP id d131mr7136842qkg.82.1589231339372; Mon, 11 May 2020 14:08:59 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id k43sm10964162qtk.67.2020.05.11.14.08.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2020 14:08:58 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id A36D03002F7; Mon, 11 May 2020 17:08:56 -0400 (-04) Date: Mon, 11 May 2020 17:08:56 -0400 From: Alvaro Herrera To: Alexander Korotkov Cc: pgsql-hackers@lists.postgresql.org Subject: Re: pgsql: Show opclass and opfamily related information in psql Message-ID: <20200511210856.GA18368@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="sm4nu43k4a2Rpi4c" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --sm4nu43k4a2Rpi4c Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2020-Mar-08, Alexander Korotkov wrote: > Show opclass and opfamily related information in psql > > This commit provides psql commands for listing operator classes, operator > families and its contents in psql. New commands will be useful for exploring > capabilities of both builtin opclasses/opfamilies as well as > opclasses/opfamilies defined in extensions. I had chance to use these new commands this morning. I noticed the ORDER BY clause of \dAo is not very useful; for example: =# \dAo+ brin datetime_minmax_ops List of operators of operator families AM │ Opfamily Name │ Operator │ Strategy │ Purpose │ Sort opfamily ──────┼─────────────────────┼───────────────────────────────────────────────────────────────┼──────────┼─────────┼─────────────── brin │ datetime_minmax_ops │ < (date, date) │ 1 │ search │ brin │ datetime_minmax_ops │ < (date, timestamp with time zone) │ 1 │ search │ brin │ datetime_minmax_ops │ < (date, timestamp without time zone) │ 1 │ search │ brin │ datetime_minmax_ops │ < (timestamp with time zone, date) │ 1 │ search │ brin │ datetime_minmax_ops │ < (timestamp with time zone, timestamp with time zone) │ 1 │ search │ brin │ datetime_minmax_ops │ < (timestamp with time zone, timestamp without time zone) │ 1 │ search │ brin │ datetime_minmax_ops │ < (timestamp without time zone, date) │ 1 │ search │ brin │ datetime_minmax_ops │ < (timestamp without time zone, timestamp with time zone) │ 1 │ search │ brin │ datetime_minmax_ops │ < (timestamp without time zone, timestamp without time zone) │ 1 │ search │ brin │ datetime_minmax_ops │ <= (date, date) │ 2 │ search │ brin │ datetime_minmax_ops │ <= (date, timestamp with time zone) │ 2 │ search │ brin │ datetime_minmax_ops │ <= (date, timestamp without time zone) │ 2 │ search │ brin │ datetime_minmax_ops │ <= (timestamp with time zone, date) │ 2 │ search │ brin │ datetime_minmax_ops │ <= (timestamp with time zone, timestamp with time zone) │ 2 │ search │ brin │ datetime_minmax_ops │ <= (timestamp with time zone, timestamp without time zone) │ 2 │ search │ Note how operator for strategy 1 are all together, then strategy 2, and so on. But I think we'd prefer the operators to be grouped together for the same types (just like \dAp already works); so I would change the clause from: ORDER BY 1, 2, o.amopstrategy, 3; to: ORDER BY 1, 2, pg_catalog.format_type(o.amoplefttype, NULL), pg_catalog.format_type(o.amoprighttype, NULL), o.amopstrategy; which gives this table: AM │ Opfamily Name │ Operator │ Strategy │ Purpose │ Sort opfamily ──────┼─────────────────────┼───────────────────────────────────────────────────────────────┼──────────┼─────────┼─────────────── brin │ datetime_minmax_ops │ < (date, date) │ 1 │ search │ brin │ datetime_minmax_ops │ <= (date, date) │ 2 │ search │ brin │ datetime_minmax_ops │ = (date, date) │ 3 │ search │ brin │ datetime_minmax_ops │ >= (date, date) │ 4 │ search │ brin │ datetime_minmax_ops │ > (date, date) │ 5 │ search │ brin │ datetime_minmax_ops │ < (date, timestamp with time zone) │ 1 │ search │ brin │ datetime_minmax_ops │ <= (date, timestamp with time zone) │ 2 │ search │ brin │ datetime_minmax_ops │ = (date, timestamp with time zone) │ 3 │ search │ brin │ datetime_minmax_ops │ >= (date, timestamp with time zone) │ 4 │ search │ brin │ datetime_minmax_ops │ > (date, timestamp with time zone) │ 5 │ search │ Also, while I'm going about this, ISTM it'd make sense to list same-class operators first, followed by cross-class operators. That requires to add "o.amoplefttype = o.amoprighttype DESC," after "ORDER BY 1, 2,". For brin's integer_minmax_ops, the resulting list would have first (bigint,bigint) then (integer,integer) then (smallint,smallint), then all the rest: brin │ integer_minmax_ops │ < (bigint, bigint) │ 1 │ search │ brin │ integer_minmax_ops │ <= (bigint, bigint) │ 2 │ search │ brin │ integer_minmax_ops │ = (bigint, bigint) │ 3 │ search │ brin │ integer_minmax_ops │ >= (bigint, bigint) │ 4 │ search │ brin │ integer_minmax_ops │ > (bigint, bigint) │ 5 │ search │ brin │ integer_minmax_ops │ < (integer, integer) │ 1 │ search │ brin │ integer_minmax_ops │ <= (integer, integer) │ 2 │ search │ brin │ integer_minmax_ops │ = (integer, integer) │ 3 │ search │ brin │ integer_minmax_ops │ >= (integer, integer) │ 4 │ search │ brin │ integer_minmax_ops │ > (integer, integer) │ 5 │ search │ brin │ integer_minmax_ops │ < (smallint, smallint) │ 1 │ search │ brin │ integer_minmax_ops │ <= (smallint, smallint) │ 2 │ search │ brin │ integer_minmax_ops │ = (smallint, smallint) │ 3 │ search │ brin │ integer_minmax_ops │ >= (smallint, smallint) │ 4 │ search │ brin │ integer_minmax_ops │ > (smallint, smallint) │ 5 │ search │ brin │ integer_minmax_ops │ < (bigint, integer) │ 1 │ search │ brin │ integer_minmax_ops │ <= (bigint, integer) │ 2 │ search │ brin │ integer_minmax_ops │ = (bigint, integer) │ 3 │ search │ brin │ integer_minmax_ops │ >= (bigint, integer) │ 4 │ search │ brin │ integer_minmax_ops │ > (bigint, integer) │ 5 │ search │ brin │ integer_minmax_ops │ < (bigint, smallint) │ 1 │ search │ brin │ integer_minmax_ops │ <= (bigint, smallint) │ 2 │ search │ brin │ integer_minmax_ops │ = (bigint, smallint) │ 3 │ search │ brin │ integer_minmax_ops │ >= (bigint, smallint) │ 4 │ search │ brin │ integer_minmax_ops │ > (bigint, smallint) │ 5 │ search │ brin │ integer_minmax_ops │ < (integer, bigint) │ 1 │ search │ brin │ integer_minmax_ops │ <= (integer, bigint) │ 2 │ search │ brin │ integer_minmax_ops │ = (integer, bigint) │ 3 │ search │ brin │ integer_minmax_ops │ >= (integer, bigint) │ 4 │ search │ brin │ integer_minmax_ops │ > (integer, bigint) │ 5 │ search │ brin │ integer_minmax_ops │ < (integer, smallint) │ 1 │ search │ brin │ integer_minmax_ops │ <= (integer, smallint) │ 2 │ search │ brin │ integer_minmax_ops │ = (integer, smallint) │ 3 │ search │ brin │ integer_minmax_ops │ >= (integer, smallint) │ 4 │ search │ brin │ integer_minmax_ops │ > (integer, smallint) │ 5 │ search │ brin │ integer_minmax_ops │ < (smallint, bigint) │ 1 │ search │ brin │ integer_minmax_ops │ <= (smallint, bigint) │ 2 │ search │ brin │ integer_minmax_ops │ = (smallint, bigint) │ 3 │ search │ brin │ integer_minmax_ops │ >= (smallint, bigint) │ 4 │ search │ brin │ integer_minmax_ops │ > (smallint, bigint) │ 5 │ search │ brin │ integer_minmax_ops │ < (smallint, integer) │ 1 │ search │ brin │ integer_minmax_ops │ <= (smallint, integer) │ 2 │ search │ brin │ integer_minmax_ops │ = (smallint, integer) │ 3 │ search │ brin │ integer_minmax_ops │ >= (smallint, integer) │ 4 │ search │ brin │ integer_minmax_ops │ > (smallint, integer) │ 5 │ search │ instead of listing putting cross-type ops that have bigint first, which are of secundary importance, which is what you get without it: brin │ integer_minmax_ops │ < (bigint, bigint) │ 1 │ search │ brin │ integer_minmax_ops │ <= (bigint, bigint) │ 2 │ search │ brin │ integer_minmax_ops │ = (bigint, bigint) │ 3 │ search │ brin │ integer_minmax_ops │ >= (bigint, bigint) │ 4 │ search │ brin │ integer_minmax_ops │ > (bigint, bigint) │ 5 │ search │ brin │ integer_minmax_ops │ < (bigint, integer) │ 1 │ search │ brin │ integer_minmax_ops │ <= (bigint, integer) │ 2 │ search │ brin │ integer_minmax_ops │ = (bigint, integer) │ 3 │ search │ brin │ integer_minmax_ops │ >= (bigint, integer) │ 4 │ search │ brin │ integer_minmax_ops │ > (bigint, integer) │ 5 │ search │ brin │ integer_minmax_ops │ < (bigint, smallint) │ 1 │ search │ brin │ integer_minmax_ops │ <= (bigint, smallint) │ 2 │ search │ brin │ integer_minmax_ops │ = (bigint, smallint) │ 3 │ search │ brin │ integer_minmax_ops │ >= (bigint, smallint) │ 4 │ search │ brin │ integer_minmax_ops │ > (bigint, smallint) │ 5 │ search │ brin │ integer_minmax_ops │ < (integer, bigint) │ 1 │ search │ brin │ integer_minmax_ops │ <= (integer, bigint) │ 2 │ search │ brin │ integer_minmax_ops │ = (integer, bigint) │ 3 │ search │ brin │ integer_minmax_ops │ >= (integer, bigint) │ 4 │ search │ brin │ integer_minmax_ops │ > (integer, bigint) │ 5 │ search │ brin │ integer_minmax_ops │ < (integer, integer) │ 1 │ search │ brin │ integer_minmax_ops │ <= (integer, integer) │ 2 │ search │ brin │ integer_minmax_ops │ = (integer, integer) │ 3 │ search │ brin │ integer_minmax_ops │ >= (integer, integer) │ 4 │ search │ brin │ integer_minmax_ops │ > (integer, integer) │ 5 │ search │ brin │ integer_minmax_ops │ < (integer, smallint) │ 1 │ search │ brin │ integer_minmax_ops │ <= (integer, smallint) │ 2 │ search │ brin │ integer_minmax_ops │ = (integer, smallint) │ 3 │ search │ brin │ integer_minmax_ops │ >= (integer, smallint) │ 4 │ search │ brin │ integer_minmax_ops │ > (integer, smallint) │ 5 │ search │ brin │ integer_minmax_ops │ < (smallint, bigint) │ 1 │ search │ brin │ integer_minmax_ops │ <= (smallint, bigint) │ 2 │ search │ brin │ integer_minmax_ops │ = (smallint, bigint) │ 3 │ search │ brin │ integer_minmax_ops │ >= (smallint, bigint) │ 4 │ search │ brin │ integer_minmax_ops │ > (smallint, bigint) │ 5 │ search │ brin │ integer_minmax_ops │ < (smallint, integer) │ 1 │ search │ brin │ integer_minmax_ops │ <= (smallint, integer) │ 2 │ search │ brin │ integer_minmax_ops │ = (smallint, integer) │ 3 │ search │ brin │ integer_minmax_ops │ >= (smallint, integer) │ 4 │ search │ brin │ integer_minmax_ops │ > (smallint, integer) │ 5 │ search │ brin │ integer_minmax_ops │ < (smallint, smallint) │ 1 │ search │ brin │ integer_minmax_ops │ <= (smallint, smallint) │ 2 │ search │ brin │ integer_minmax_ops │ = (smallint, smallint) │ 3 │ search │ brin │ integer_minmax_ops │ >= (smallint, smallint) │ 4 │ search │ brin │ integer_minmax_ops │ > (smallint, smallint) │ 5 │ search │ which in my mind is a clear improvement. So I propose the attached patch. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --sm4nu43k4a2Rpi4c Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="sort-dAo.patch" diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 8dca6d8bb4..9bd0bf8356 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -6288,7 +6288,11 @@ listOpFamilyOperators(const char *access_method_pattern, processSQLNamePattern(pset.db, &buf, family_pattern, have_where, false, "nsf.nspname", "of.opfname", NULL, NULL); - appendPQExpBufferStr(&buf, "ORDER BY 1, 2, o.amopstrategy, 3;"); + appendPQExpBufferStr(&buf, "ORDER BY 1, 2,\n" + " o.amoplefttype = o.amoprighttype DESC,\n" + " pg_catalog.format_type(o.amoplefttype, NULL),\n" + " pg_catalog.format_type(o.amoprighttype, NULL),\n" + " o.amopstrategy;"); res = PSQLexec(buf.data); termPQExpBuffer(&buf); --sm4nu43k4a2Rpi4c--