Skip to content

Commit e3a58c8

Browse files
committed
Optimize query for information_schema.constraint_column_usage
The way the old query was written prevented some join optimizations because the join conditions were hidden inside a CASE expression. With a large number of constraints, the query became unreasonably slow. The new query performs much better. From: Alexey Bashtanov <bashtanov@imap.cc> Reviewed-by: Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
1 parent 68f3dbc commit e3a58c8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/backend/catalog/information_schema.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,8 @@ CREATE VIEW constraint_column_usage AS
801801
WHERE nr.oid = r.relnamespace
802802
AND r.oid = a.attrelid
803803
AND nc.oid = c.connamespace
804-
AND (CASE WHEN c.contype = 'f' THEN r.oid = c.confrelid AND a.attnum = ANY (c.confkey)
805-
ELSE r.oid = c.conrelid AND a.attnum = ANY (c.conkey) END)
804+
AND r.oid = CASE c.contype WHEN 'f' THEN c.confrelid ELSE c.conrelid END
805+
AND a.attnum = ANY (CASE c.contype WHEN 'f' THEN c.confkey ELSE c.conkey END)
806806
AND NOT a.attisdropped
807807
AND c.contype IN ('p', 'u', 'f')
808808
AND r.relkind IN ('r', 'P')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy