Hi All,

I've encountered a noticeable difference in execution time and query execution plan row counts between PostgreSQL 13 and PostgreSQL 16 when running a query on information_schema tables. Surprisingly, PostgreSQL 16 is performing slower than PostgreSQL 13.

The query executed on both versions is as follows:

SELECT DISTINCT "tc"."constraint_name" AS "ConstraintName", "ccu"."column_name" AS "ColumnName"
         FROM
        information_schema.constraint_column_usage AS "ccu" right join information_schema.table_constraints AS "tc"
ON  "tc"."constraint_catalog" = "ccu"."constraint_catalog"  
        AND  "tc"."constraint_name" = "ccu"."constraint_name"  
          WHERE "tc"."constraint_type" = 'PRIMARY KEY'
        AND  "ccu"."table_name" = 't_c56ng1_repository'
  

 Here are the details of the PostgreSQL versions and the execution plans:  

4PostgreSQL 13.14 (PostgreSQL 13.14 on x86_64-pc-linux-gnu, compiled by gcc 11.4.0, 64-bit)
Execution plan: PG13.14 Execution Plan

PostgreSQL 16.4 (PostgreSQL 16.4 on x86_64-pc-linux-gnu, compiled by gcc 11.4.0, 64-bit)
Execution plan: PG16.4 Execution Plan


Has anyone else experienced similar behavior or could provide insights into why PostgreSQL 16 might be slower for this query? Any advice or suggestions for optimization would be greatly appreciated.

Thank you!

NOTE:-  PFA the raw file of explain and analyze below.