eulerto / pgquarrel

pgquarrel compares PostgreSQL database schemas (DDL)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exclude relation partitions option [table-partition true/false]

hazardland opened this issue · comments

Can we add an option to exclude relation partitions? In our company we have dozens of partitions and the process takes about 10 minutes to compare database as 90% of tables are partitions we thought it might speed up to exclude partition comparation from process.

If there was an option table-partition true/false

I think that change should take effect only in table.c in following queries where clauses:

 AND c.relispartition=true/false
	if (PQserverVersion(c) >= 100000)
	{
		if (PGQ_IS_REGULAR_OR_PARTITIONED_TABLE(k))
		{
			query = psprintf("SELECT c.oid, n.nspname, c.relname, c.relkind, t.spcname AS tablespacename, c.relpersistence, array_to_string(c.reloptions, ', ') AS reloptions, obj_description(c.oid, 'pg_class') AS description, pg_get_userbyid(c.relowner) AS relowner, relacl, relreplident, reloftype, o.nspname AS typnspname, y.typname, c.relispartition, pg_get_partkeydef(c.oid) AS partitionkeydef, pg_get_expr(c.relpartbound, c.oid) AS partitionbound, c.relhassubclass FROM pg_class c INNER JOIN pg_namespace n ON (c.relnamespace = n.oid) LEFT JOIN pg_tablespace t ON (c.reltablespace = t.oid) LEFT JOIN (pg_type y INNER JOIN pg_namespace o ON (y.typnamespace = o.oid)) ON (c.reloftype = y.oid) WHERE relkind IN ('r', 'p') AND n.nspname !~ '^pg_' AND n.nspname <> 'information_schema' %s%s AND NOT EXISTS(SELECT 1 FROM pg_depend d WHERE t.oid = d.objid AND d.deptype = 'e') ORDER BY n.nspname, relname", include_schema_str, exclude_schema_str);
		}
		else if (PGQ_IS_FOREIGN_TABLE(k))
		{
			query = psprintf("SELECT c.oid, n.nspname, c.relname, c.relkind, t.spcname AS tablespacename, c.relpersistence, array_to_string(c.reloptions, ', ') AS reloptions, obj_description(c.oid, 'pg_class') AS description, pg_get_userbyid(c.relowner) AS relowner, relacl, relreplident, reloftype, o.nspname AS typnspname, y.typname, c.relispartition, pg_get_partkeydef(c.oid) AS partitionkeydef, pg_get_expr(c.relpartbound, c.oid) AS partitionbound, c.relhassubclass FROM pg_class c INNER JOIN pg_namespace n ON (c.relnamespace = n.oid) LEFT JOIN pg_tablespace t ON (c.reltablespace = t.oid) LEFT JOIN (pg_type y INNER JOIN pg_namespace o ON (y.typnamespace = o.oid)) ON (c.reloftype = y.oid) WHERE relkind = 'f' AND n.nspname !~ '^pg_' AND n.nspname <> 'information_schema' %s%s AND NOT EXISTS(SELECT 1 FROM pg_depend d WHERE t.oid = d.objid AND d.deptype = 'e') ORDER BY n.nspname, relname", include_schema_str, exclude_schema_str);
		}
		else
		{
			logError("it is not a table or foreign table");
			exit(EXIT_FAILURE);
		}
	}

Also in index.c

On line 37 AND c.relispartition=FALSE

	query = psprintf("SELECT c.oid, n.nspname, c.relname, t.spcname AS tablespacename, pg_get_indexdef(c.oid) AS indexdef, array_to_string(c.reloptions, ', ') AS reloptions, obj_description(c.oid, 'pg_class') AS description FROM pg_class c INNER JOIN pg_namespace n ON (c.relnamespace = n.oid) INNER JOIN pg_index i ON (i.indexrelid = c.oid) LEFT JOIN pg_tablespace t ON (c.reltablespace = t.oid) WHERE relkind = 'i' AND c.relispartition=FALSE AND nspname !~ '^pg_' AND nspname <> 'information_schema' %s%s AND NOT indisprimary ORDER BY nspname, relname", include_schema_str, exclude_schema_str);