gpdb icon indicating copy to clipboard operation
gpdb copied to clipboard

pg_upgrade: add support func to check views using deprecated operators

Open kyeap-vmware opened this issue 1 year ago • 3 comments

Views that use deprecated operators will cause upgrade to fail. This happens during metadata restore on the target cluster because pg_restore will error trying to create a view using types that do not exist anymore. This is not ideal as we could be many hours into upgrade before a view using a deprecated operator causes pg_upgrade to fail. In order to detect views with deprecated operators. A query_tree_walker is used to walk the nodes of all views. Each node is then checked to see if is an operator. If it is, we then check if the oid of the operator matches one that is not present in GPDB7.

Due to the limitations of the query walker being a function that only returns a bool, we can only tell if a deprecated operator exists in a view. We do not have an easy way to tell users how many or which deprecated operators are present in the view.

Method used to find operators that are no longer present on 7x

on 7x

create temp table seven_op as (select n.nspname || '.' || o.oprname as oprname, o.oprcode::text as oprcode from pg_operator o join pg_namespace n on o.oprnamespace=n.oid order by oprcode);
copy seven_op TO '/tmp/7x_depreciated_operators.csv' WITH CSV;

on 6x

create temp table six_op as (select n.nspname || '.' || o.oprname as oprname, o.oprcode::text as oprcode from pg_operator o join pg_namespace n on o.oprnamespace=n.oid order by oprcode);
create temp table seven_op (a text, b text);
copy seven_op FROM '/tmp/7x_depreciated_operators.csv' WITH CSV;

select * from six_op EXCEPT select * from seven_op order by 2, 1;
    oprname     |    oprcode
----------------+----------------
 pg_catalog.=   | abstimeeq
 pg_catalog.>=  | abstimege
 pg_catalog.>   | abstimegt
 pg_catalog.<=  | abstimele
 pg_catalog.<   | abstimelt
 pg_catalog.<>  | abstimene
 pg_catalog.=   | int2vectoreq
 pg_catalog.<?> | intinterval
 pg_catalog.<#> | mktinterval
 pg_catalog.=   | reltimeeq
 pg_catalog.>=  | reltimege
 pg_catalog.>   | reltimegt
 pg_catalog.<=  | reltimele
 pg_catalog.<   | reltimelt
 pg_catalog.<>  | reltimene
 pg_catalog.-   | timemi
 pg_catalog.+   | timepl
 pg_catalog.<<  | tintervalct
 pg_catalog.=   | tintervaleq
 pg_catalog.>=  | tintervalge
 pg_catalog.>   | tintervalgt
 pg_catalog.<=  | tintervalle
 pg_catalog.#=  | tintervalleneq
 pg_catalog.#>= | tintervallenge
 pg_catalog.#>  | tintervallengt
 pg_catalog.#<= | tintervallenle
 pg_catalog.#<  | tintervallenlt
 pg_catalog.#<> | tintervallenne
 pg_catalog.<   | tintervallt
 pg_catalog.<>  | tintervalne
 pg_catalog.&&  | tintervalov
 pg_catalog.~=  | tintervalsame
 pg_catalog.|   | tintervalstart
(33 rows)

kyeap-vmware avatar Feb 13 '24 02:02 kyeap-vmware