Skip to content

Commit d3c0cc4

Browse files
committed
Switch query fixing aclitems in ~15 from O(N^2) to O(N) in upgrade_adapt.sql
f4f2f2b was doing a sequential scan of pg_class before checking if a relation had attributes dependent on aclitem as data typewhen building the set of ALTER TABLE queries, but it would be costly on a regression database. While on it, make the query style more consistent with the rest. Reported-by: Justin Pryzby Discussion: https://postgr.es/m/20221223032724.GQ1153@telsasoft.com
1 parent 442e25d commit d3c0cc4

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/bin/pg_upgrade/upgrade_adapt.sql

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,21 @@ DROP OPERATOR public.#@%# (pg_catalog.int8, NONE);
9595
-- The internal format of "aclitem" has changed in 16, so replace it with
9696
-- text type in tables.
9797
\if :oldpgversion_le15
98-
DO $$
98+
DO $stmt$
9999
DECLARE
100-
rec text;
101-
col text;
100+
rec record;
102101
BEGIN
103102
FOR rec in
104-
SELECT oid::regclass::text
105-
FROM pg_class
106-
WHERE relname !~ '^pg_'
107-
AND relkind IN ('r')
103+
SELECT oid::regclass::text as rel, attname as col
104+
FROM pg_class c, pg_attribute a
105+
WHERE c.relname !~ '^pg_'
106+
AND c.relkind IN ('r')
107+
AND a.attrelid = c.oid
108+
AND a.atttypid = 'aclitem'::regtype
108109
ORDER BY 1
109110
LOOP
110-
FOR col in SELECT attname FROM pg_attribute
111-
WHERE attrelid::regclass::text = rec
112-
AND atttypid = 'aclitem'::regtype
113-
LOOP
114-
EXECUTE 'ALTER TABLE ' || quote_ident(rec) || ' ALTER COLUMN ' ||
115-
quote_ident(col) || ' SET DATA TYPE text';
116-
END LOOP;
111+
EXECUTE 'ALTER TABLE ' || quote_ident(rec.rel) || ' ALTER COLUMN ' ||
112+
quote_ident(rec.col) || ' SET DATA TYPE text';
117113
END LOOP;
118-
END; $$;
114+
END; $stmt$;
119115
\endif

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