Re: [PATCH] psql: add \dcs to list all constraints

Tatsuro Yamada <yamatattsu@gmail.com>

From: Tatsuro Yamada <yamatattsu@gmail.com>
To: Álvaro Herrera <alvherre@kurilemu.de>
Cc: Chao Li <li.evan.chao@gmail.com>, Tom Lane <tgl@sss.pgh.pa.us>, Jim Jones <jim.jones@uni-muenster.de>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2026-01-20T10:01:04Z
Lists: pgsql-hackers

Attachments

Hi Álvaro and ALL,

On Mon, Jan 19, 2026 at 10:44 PM Tatsuro Yamada <yamatattsu@gmail.com>
wrote:

> Sorry, I just realized that I accidentally added an unnecessary filter
> condition to one of the queries.
> Specifically, the extra condition was:
>     AND n.nspname LIKE 'many_cns'
>
> Because of this, I was not able to measure the two queries under identical
> conditions. I will rerun the benchmarks and share the updated results
> tomorrow.
>

The error in the query has been fixed, and the execution times were
measured again.
As a result, there was no significant difference in execution time
between the two queries (see the attached test_result2.txt).
When comparing the cost of the top node, the original query has a
slightly lower cost, so I decided to keep it as is.


> # Summary
>> > The following changes are planned for the next patch:
>> >
>> > - Changed the query (using UNION ALL)
>> > - Changed the columns and their order (and the sort order accordingly):
>> > - Schema | Table | Type | Name | Definition
>> > - Toggle definition verbosity with the + option
>> > - Added a test case: \dCN cust*.order*
>> >
>> > The following items will not be included for now (as they are not
>> critical):
>> >
>> > - Option to switch sort order
>> >   (e.g., sort by constraint name vs. table name)
>> > - Improved command name checking logic
>>
>> Yeah, that sounds good to me.
>>
>
> Hopefully, I will also be able to submit a new patch along with the
> revised
> measurement results tomorrow.
>

The patch (v6) incorporates the changes listed above.
Note that, as mentioned earlier, the query itself was not changed.

Below is an example of the result set after the corrections
(from the regression test):

\dCN con_*
                   List of constraints
 Schema | Table |   Type    |            Name
--------+-------+-----------+----------------------------
 public | con_c | NOT NULL  | con_c_primary_col_not_null
 public | con_c | PK        | con_c_pkey
 public | con_p | CHECK     | con_p_check_col_check
 public | con_p | EXCLUSION | con_p_exclusion
 public | con_p | FK        | con_p_foreign_col_fkey
 public | con_p | NOT NULL  | con_p_notnull_col_not_null
 public | con_p | NOT NULL  | con_p_primary_col_not_null
 public | con_p | PK        | con_p_pkey
 public | con_p | TRIGGER   | con_p_trigger
 public | con_p | UNIQUE    | con_p_unique_col_key
(10 rows)

What do you think?
Please find the attached patch.

Regards,
Tatsuro Yamada