SET geqo = on;
SET geqo_effort = 5;
SET geqo_threshold = 12;
SET join_collapse_limit = 8;
SET from_collapse_limit = 8;

--/*
DROP VIEW IF EXISTS public.pg_class_with_attributes;
CREATE VIEW public.pg_class_with_attributes AS
    SELECT pg_class.oid, pg_class.relnamespace, pg_class.reltype, pg_attribute.atttypid, other.oid AS otheroid
    FROM pg_class
  	JOIN pg_attribute ON
	    pg_class.oid = pg_attribute.attrelid
   	JOIN pg_type ON
	    pg_attribute.atttypid = pg_type.oid
	JOIN pg_constraint ON
	    pg_constraint.conrelid = pg_class.oid
	JOIN pg_class other ON
	    other.oid = pg_constraint.confrelid
	JOIN pg_locks ON
	    pg_locks.relation = pg_class.oid
	    OR
	    pg_locks.relation = other.oid
	JOIN pg_stat_activity ON
	    pg_locks.pid = pg_stat_activity.procpid
        JOIN pg_tablespace ON
	    pg_class.reltablespace = pg_tablespace.oid
	    OR
	    other.reltablespace = pg_tablespace.oid
	LEFT JOIN pg_stat_all_tables ON
	    pg_stat_all_tables.relid = pg_class.oid
	    OR
	    pg_stat_all_tables.relid = other.oid
	LEFT JOIN pg_stat_all_indexes ON
	    pg_stat_all_indexes.relid = pg_class.oid
	    OR
	    pg_stat_all_indexes.relid = other.oid
  	JOIN pg_attrdef ON
	    pg_attribute.attrelid = pg_attrdef.adrelid
	    AND
	    pg_attribute.attnum = pg_attrdef.adnum;
;
--*/

PREPARE bench_1 AS
SELECT *
FROM pg_class
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_1 ON
	 	  pg_class.oid = pg_class_with_attributes_1.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_2 ON
	 	  pg_class.oid = pg_class_with_attributes_2.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_3 ON
	 	  pg_class.oid = pg_class_with_attributes_3.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_4 ON
	 	  pg_class.oid = pg_class_with_attributes_4.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_5 ON
	 	  pg_class.oid = pg_class_with_attributes_5.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_6 ON
	 	  pg_class.oid = pg_class_with_attributes_6.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_7 ON
	 	  pg_class.oid = pg_class_with_attributes_7.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_8 ON
	 	  pg_class.oid = pg_class_with_attributes_8.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_9 ON
	 	  pg_class.oid = pg_class_with_attributes_9.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_10 ON
	 	  pg_class.oid = pg_class_with_attributes_10.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_11 ON
	 	  pg_class.oid = pg_class_with_attributes_11.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_12 ON
	 	  pg_class.oid = pg_class_with_attributes_12.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_13 ON
	 	  pg_class.oid = pg_class_with_attributes_13.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_14 ON
	 	  pg_class.oid = pg_class_with_attributes_14.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_15 ON
	 	  pg_class.oid = pg_class_with_attributes_15.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_16 ON
	 	  pg_class.oid = pg_class_with_attributes_16.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_17 ON
	 	  pg_class.oid = pg_class_with_attributes_17.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_18 ON
	 	  pg_class.oid = pg_class_with_attributes_18.oid
	 JOIN pg_class_with_attributes AS pg_class_with_attributes_19 ON
	 	  pg_class.oid = pg_class_with_attributes_19.oid
;
DEALLOCATE bench_1;