From 8ddc69df6dbd8e6de7a4383da5211130cacc57eb Mon Sep 17 00:00:00 2001 From: Tigrov Date: Wed, 13 Sep 2023 23:59:32 +0700 Subject: [PATCH] Improve SQL queries --- src/Schema.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Schema.php b/src/Schema.php index 6e0973acc..e5586e6c7 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -370,7 +370,10 @@ protected function loadTableIndexes(string $tableName): array INNER JOIN "pg_index" AS "i" ON "i"."indrelid" = "tc"."oid" OR rw.ev_action IS NOT NULL - AND (SELECT regexp_matches(rw.ev_action, '{TARGETENTRY .*? :resorigtbl (\d+) :resorigcol ' || "i"."indkey"[0] || ' '))[1]::oid = "i"."indrelid" + AND (SELECT regexp_matches( + rw.ev_action, + '{TARGETENTRY .*? :resorigtbl ' || "i"."indrelid" || ' :resorigcol ' || "i"."indkey"[0] || ' ' + )) IS NOT NULL INNER JOIN "pg_class" AS "ic" ON "ic"."oid" = "i"."indexrelid" INNER JOIN "pg_attribute" AS "ia" @@ -729,8 +732,11 @@ protected function findColumns(TableSchemaInterface $table): bool LEFT JOIN pg_rewrite rw ON c.relkind = 'v' AND rw.ev_class = c.oid AND rw.rulename = '_RETURN' LEFT JOIN pg_constraint ct ON ct.conrelid = c.oid AND ct.contype = 'p' AND a.attnum = ANY (ct.conkey) OR rw.ev_action IS NOT NULL - AND (ARRAY(SELECT regexp_matches(rw.ev_action, '{TARGETENTRY .*? :resorigtbl (\d+) ', 'g')))[a.attnum][1]::oid = ct.conrelid - AND (ARRAY(SELECT regexp_matches(rw.ev_action, '{TARGETENTRY .*? :resorigcol (\d+) ', 'g')))[a.attnum][1]::smallint = ANY (ct.conkey) + AND (ARRAY(SELECT regexp_matches( + rw.ev_action, + '{TARGETENTRY .*? :resorigtbl ' || ct.conrelid || ' :resorigcol (\d+) ', + 'g' + )))[a.attnum][1]::smallint = ANY (ct.conkey) WHERE a.attnum > 0 AND t.typname != '' AND NOT a.attisdropped AND c.relname = :tableName @@ -917,8 +923,11 @@ private function loadTableConstraints(string $tableName, string $returnType): ar INNER JOIN "pg_constraint" AS "c" ON "c"."conrelid" = "tc"."oid" AND "a"."attnum" = ANY ("c"."conkey") OR rw.ev_action IS NOT NULL - AND (ARRAY(SELECT regexp_matches(rw.ev_action, '{TARGETENTRY .*? :resorigtbl (\d+) ', 'g')))[a.attnum][1]::oid = c.conrelid - AND (ARRAY(SELECT regexp_matches(rw.ev_action, '{TARGETENTRY .*? :resorigcol (\d+) ', 'g')))[a.attnum][1]::smallint = ANY (c.conkey) + AND (ARRAY(SELECT regexp_matches( + rw.ev_action, + '{TARGETENTRY .*? :resorigtbl ' || c.conrelid || ' :resorigcol (\d+) ', + 'g' + )))[a.attnum][1]::smallint = ANY (c.conkey) LEFT JOIN "pg_class" AS "ftc" ON "ftc"."oid" = "c"."confrelid" LEFT JOIN "pg_namespace" AS "ftcns"