Hi,
In a database with one schema per tenant, granting access to the
objects of one tenant can scan the catalogs for every tenant. REINDEX
SCHEMA also scans pg_class to find its relations. For a publication
covering several schemas, enumerating its tables can scan pg_class
once per schema, including on CREATE SUBSCRIPTION and REFRESH
PUBLICATION.
I propose using pg_depend_reference_index to look up the candidate
objects of a schema, then checking each candidate's namespace in
pg_class or pg_proc. The catalog scan remains available for pinned
schemas and when candidates exceed 1/64 of the estimated catalog
rows.
Before choosing a scan, we apply the last measured tuple density to
the current page count. A catalog can grow substantially between
ANALYZE runs. We scan the member catalog directly when
ignore_system_indexes is enabled, to avoid a heap scan of pg_depend
during operations such as REINDEX SCHEMA.
I measured 5,000 tenant sign-ups in a fresh cluster. Each transaction
creates a schema and ten tables with primary keys, grants SELECT
on all tables in that schema, and adds the schema to a publication.
With autovacuum and fsync disabled, the median total went from 135.2 s
on master (five runs) to 16.9 s with the series before the repair-mode
change (three runs). The builds were measured in separate batches.
In the last 500 sign-ups, median GRANT time went from 40.7 ms to 0.14 ms,
and median ALTER PUBLICATION time from 8.31 ms to 0.074 ms. Each run
checked that all 50,000 tables were granted and published.
After creating and dropping 100,000 tables in the target schema
without vacuuming, the first GRANT took 14.0 ms with the lookup
and 8.2 ms on master. The next four took 0.06-0.16 ms with the
lookup and 1.93-3.50 ms on master.
On the final series, REINDEX SCHEMA for a schema with two indexes
in a cluster with 100,433 pg_class rows took 0.197 ms in normal mode
versus 3.289 ms on master (30 runs per build). In repair mode the
final series matched master's catalog scan path and rebuilt the same
two indexes. Median latency was 20.223 ms versus 18.084 ms on master.
The main correctness concern is a missing namespace dependency. For
schema publications, that can silently leave a table out of the set
the subscriber synchronizes. DROP SCHEMA CASCADE already relies on
these dependencies. Patch 0001 adds an oidjoins check for missing
entries and cross-checks the dependency path against the catalog scan
in assertion builds. Both checks detected deliberately omitted
dependencies in testing.
The attached series covers sequence and routine GRANT and REINDEX
SCHEMA in 0001, and schema publications in 0002. Patch 0003 credits
CharSyam's idea for GRANT/REVOKE ON ALL TABLES, collecting all five
relation kinds in one pass.
https://postgr.es/m/CAMrLSE7bZ70eGaTMH3-g=TA_sfp3kTDOrHVNYw1=1xl9kra...@mail.gmail.com
The series is based on 458c77d74d2. check-world passed on the base
and on each prefix in assertion-enabled builds.
The attachments also include the tenant benchmark script, per-run
tenant totals, and timings and scan counts for the repair-mode test.
Regards,
Manu
From: Manu <[email protected]>
Subject: [PATCH v1 1/3] Find schema members through pg_depend instead of scanning pg_class
GRANT ... ON ALL SEQUENCES | FUNCTIONS | PROCEDURES | ROUTINES IN SCHEMA
and REINDEX SCHEMA scan the whole of pg_class (or pg_proc) to find the
objects of one schema, so their cost grows with the size of the catalog
rather than with the size of the schema. In a database with many
schemas, one command on a small schema reads every relation of every
other schema.
Every table, view, materialized view, foreign table, sequence and
function created in a schema gets a DEPENDENCY_NORMAL entry in pg_depend
on that schema, except in pinned schemas (pg_catalog, pg_toast). Add
GetNamespaceRelations() and GetNamespaceFunctions(), which take the
candidates from pg_depend with one scan of pg_depend_reference_index
(new helper getDependentObjectsOfClass()) and recheck each candidate
against its syscache entry, since a pg_depend entry can also come from
an object of another schema that refers to this one (a regnamespace
constant in a partition key or an index expression, for example).
The functions fall back to the catalog scan when the schema is pinned,
and when the candidate count exceeds 1/64 of the estimated catalog
rows. Before selecting a scan, scale the last measured tuple density
to the current page count so catalog growth between ANALYZE runs does
not cause repeated scans of a growing catalog.
When system indexes are ignored, scan the member catalog directly
to avoid scanning pg_depend without its reference index.
Either way the result is sorted by OID: once pg_class is
larger than a quarter of shared_buffers, a catalog scan can start
anywhere (synchronized scans), so the old order changed from one session
to the next.
The new path relies on the namespace entries in pg_depend, which DROP
SCHEMA ... CASCADE already relies on. An object without its entry would
be skipped silently, so add a query to the oidjoins test that lists
relations and functions of unpinned schemas without one, and, in
assert-enabled builds, cross-check the pg_depend result against the
catalog scan.
Index, TOAST and composite-type relations have no such entry; no caller
asks for those relkinds, and GetNamespaceRelations() asserts that.
---
diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c
index 2bbcc3e824bd4d3cafdfb138f873b59c7ca6d10e..7c4fbab34018198910ce482e24479f5f711f5579 100644
--- a/src/backend/catalog/aclchk.c
+++ b/src/backend/catalog/aclchk.c
@@ -800,50 +800,21 @@ objectsInSchemaToOids(ObjectType objtype, List *nspnames)
objects = list_concat(objects, objs);
break;
case OBJECT_SEQUENCE:
- objs = getRelationsInNamespace(namespaceId, RELKIND_SEQUENCE);
- objects = list_concat(objects, objs);
+ {
+ static const char seqkinds[] = {RELKIND_SEQUENCE, '\0'};
+
+ objs = GetNamespaceRelations(namespaceId, seqkinds);
+ objects = list_concat(objects, objs);
+ }
break;
case OBJECT_FUNCTION:
case OBJECT_PROCEDURE:
case OBJECT_ROUTINE:
- {
- ScanKeyData key[2];
- int keycount;
- Relation rel;
- TableScanDesc scan;
- HeapTuple tuple;
-
- keycount = 0;
- ScanKeyInit(&key[keycount++],
- Anum_pg_proc_pronamespace,
- BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(namespaceId));
-
- if (objtype == OBJECT_FUNCTION)
- /* includes aggregates and window functions */
- ScanKeyInit(&key[keycount++],
- Anum_pg_proc_prokind,
- BTEqualStrategyNumber, F_CHARNE,
- CharGetDatum(PROKIND_PROCEDURE));
- else if (objtype == OBJECT_PROCEDURE)
- ScanKeyInit(&key[keycount++],
- Anum_pg_proc_prokind,
- BTEqualStrategyNumber, F_CHAREQ,
- CharGetDatum(PROKIND_PROCEDURE));
-
- rel = table_open(ProcedureRelationId, AccessShareLock);
- scan = table_beginscan_catalog(rel, keycount, key);
-
- while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
- {
- Oid oid = ((Form_pg_proc) GETSTRUCT(tuple))->oid;
-
- objects = lappend_oid(objects, oid);
- }
-
- table_endscan(scan);
- table_close(rel, AccessShareLock);
- }
+ /* OBJECT_FUNCTION includes aggregates and window functions */
+ objs = GetNamespaceFunctions(namespaceId,
+ objtype != OBJECT_PROCEDURE,
+ objtype != OBJECT_FUNCTION);
+ objects = list_concat(objects, objs);
break;
default:
/* should not happen */
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c
index f38b7adbd516ff5f0d40c1776d40de2d1cae0018..0561d8cb2c8fe55c5b03bab609bfb2d0f0529139 100644
--- a/src/backend/catalog/namespace.c
+++ b/src/backend/catalog/namespace.c
@@ -19,17 +19,24 @@
*/
#include "postgres.h"
+#include "access/genam.h"
+#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/parallel.h"
+#include "access/table.h"
+#include "access/tableam.h"
#include "access/xact.h"
#include "access/xlog.h"
+#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/namespace.h"
#include "catalog/objectaccess.h"
#include "catalog/pg_authid.h"
+#include "catalog/pg_class.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_conversion.h"
#include "catalog/pg_database.h"
+#include "catalog/pg_depend.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_operator.h"
@@ -53,10 +60,12 @@
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/catcache.h"
+#include "utils/fmgroids.h"
#include "utils/guc_hooks.h"
#include "utils/inval.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
+#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
#include "utils/varlena.h"
@@ -3714,6 +3723,366 @@ NameListToQuotedString(const List *names)
return string.data;
}
+/*
+ * When a namespace holds more than 1/NAMESPACE_SCAN_DIVISOR of a catalog, one
+ * pass over the catalog is cheaper than a lookup per member.
+ */
+#define NAMESPACE_SCAN_DIVISOR 64
+
+/*
+ * Decide whether to scan the whole catalog rather than look up each of the
+ * "ncandidates" objects that pg_depend lists for a namespace. Before
+ * choosing a scan, scale the last tuple density to the current catalog
+ * size: the catalog can grow substantially between analyze runs.
+ */
+static bool
+namespace_scan_is_cheaper(Oid catalogId, int ncandidates)
+{
+ Relation rel;
+ double reltuples;
+
+ rel = table_open(catalogId, AccessShareLock);
+ reltuples = rel->rd_rel->reltuples;
+ if (reltuples > 0 && ncandidates > reltuples / NAMESPACE_SCAN_DIVISOR)
+ {
+ BlockNumber pages;
+ double allvisfrac;
+
+ table_relation_estimate_size(rel, NULL, &pages, &reltuples,
+ &allvisfrac);
+ }
+ table_close(rel, AccessShareLock);
+
+ return reltuples > 0 && ncandidates > reltuples / NAMESPACE_SCAN_DIVISOR;
+}
+
+/*
+ * Scan all of pg_class for the relations in a namespace with one of the
+ * given relkinds.
+ */
+static List *
+scan_namespace_relations(Oid namespaceId, const char *relkinds)
+{
+ List *result = NIL;
+ Relation rel;
+ TableScanDesc scan;
+ ScanKeyData key[1];
+ HeapTuple tuple;
+
+ ScanKeyInit(&key[0],
+ Anum_pg_class_relnamespace,
+ BTEqualStrategyNumber, F_OIDEQ,
+ ObjectIdGetDatum(namespaceId));
+
+ rel = table_open(RelationRelationId, AccessShareLock);
+ scan = table_beginscan_catalog(rel, 1, key);
+
+ while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
+ {
+ Form_pg_class classForm = (Form_pg_class) GETSTRUCT(tuple);
+
+ if (strchr(relkinds, classForm->relkind) != NULL)
+ result = lappend_oid(result, classForm->oid);
+ }
+
+ table_endscan(scan);
+ table_close(rel, AccessShareLock);
+
+ /* see GetNamespaceRelations about the order */
+ list_sort(result, list_oid_cmp);
+ return result;
+}
+
+/*
+ * Scan all of pg_proc for the functions and/or procedures in a namespace.
+ */
+static List *
+scan_namespace_functions(Oid namespaceId, bool functions, bool procedures)
+{
+ List *result = NIL;
+ Relation rel;
+ TableScanDesc scan;
+ ScanKeyData key[1];
+ HeapTuple tuple;
+
+ ScanKeyInit(&key[0],
+ Anum_pg_proc_pronamespace,
+ BTEqualStrategyNumber, F_OIDEQ,
+ ObjectIdGetDatum(namespaceId));
+
+ rel = table_open(ProcedureRelationId, AccessShareLock);
+ scan = table_beginscan_catalog(rel, 1, key);
+
+ while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
+ {
+ Form_pg_proc procForm = (Form_pg_proc) GETSTRUCT(tuple);
+
+ if (procForm->prokind == PROKIND_PROCEDURE ? procedures : functions)
+ result = lappend_oid(result, procForm->oid);
+ }
+
+ table_endscan(scan);
+ table_close(rel, AccessShareLock);
+
+ /* see GetNamespaceRelations about the order */
+ list_sort(result, list_oid_cmp);
+ return result;
+}
+
+#ifdef USE_ASSERT_CHECKING
+/*
+ * Does object catalogId/objectId have a pg_depend entry on namespaceId?
+ */
+static bool
+object_depends_on_namespace(Oid catalogId, Oid objectId, Oid namespaceId)
+{
+ Relation depRel;
+ ScanKeyData key[3];
+ SysScanDesc scan;
+ HeapTuple tup;
+ bool found = false;
+
+ depRel = table_open(DependRelationId, AccessShareLock);
+
+ ScanKeyInit(&key[0],
+ Anum_pg_depend_classid,
+ BTEqualStrategyNumber, F_OIDEQ,
+ ObjectIdGetDatum(catalogId));
+ ScanKeyInit(&key[1],
+ Anum_pg_depend_objid,
+ BTEqualStrategyNumber, F_OIDEQ,
+ ObjectIdGetDatum(objectId));
+ ScanKeyInit(&key[2],
+ Anum_pg_depend_objsubid,
+ BTEqualStrategyNumber, F_INT4EQ,
+ Int32GetDatum(0));
+
+ scan = systable_beginscan(depRel, DependDependerIndexId, true,
+ NULL, 3, key);
+
+ while (HeapTupleIsValid(tup = systable_getnext(scan)))
+ {
+ Form_pg_depend deprec = (Form_pg_depend) GETSTRUCT(tup);
+
+ if (deprec->refclassid == NamespaceRelationId &&
+ deprec->refobjid == namespaceId &&
+ deprec->refobjsubid == 0)
+ {
+ found = true;
+ break;
+ }
+ }
+
+ systable_endscan(scan);
+ table_close(depRel, AccessShareLock);
+
+ return found;
+}
+
+/*
+ * The namespace of a pg_class or pg_proc entry, or InvalidOid if it is gone.
+ */
+static Oid
+object_namespace(Oid catalogId, Oid objectId)
+{
+ HeapTuple tuple;
+ Oid result = InvalidOid;
+
+ if (catalogId == RelationRelationId)
+ {
+ tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(objectId));
+ if (HeapTupleIsValid(tuple))
+ {
+ result = ((Form_pg_class) GETSTRUCT(tuple))->relnamespace;
+ ReleaseSysCache(tuple);
+ }
+ }
+ else
+ {
+ Assert(catalogId == ProcedureRelationId);
+ tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(objectId));
+ if (HeapTupleIsValid(tuple))
+ {
+ result = ((Form_pg_proc) GETSTRUCT(tuple))->pronamespace;
+ ReleaseSysCache(tuple);
+ }
+ }
+
+ return result;
+}
+
+/*
+ * Check a member list built from pg_depend against a scan of the catalog.
+ *
+ * The pg_depend route depends on every member having a dependency on its
+ * namespace; one that lacks it would be left out without any error. So in
+ * assert-enabled builds, every object the scan finds must be in "members",
+ * unless it gained its pg_depend entry (was created or moved in) or left
+ * the namespace after pg_depend was read. We look at pg_depend before
+ * pg_class, because a concurrent move changes both in one transaction.
+ */
+static void
+check_namespace_members(Oid catalogId, Oid namespaceId,
+ List *members, List *scanned)
+{
+ ListCell *lc;
+
+ foreach(lc, scanned)
+ {
+ Oid objectId = lfirst_oid(lc);
+
+ if (list_member_oid(members, objectId))
+ continue;
+ if (object_depends_on_namespace(catalogId, objectId, namespaceId))
+ continue;
+ if (object_namespace(catalogId, objectId) != namespaceId)
+ continue;
+
+ elog(ERROR, "object %u of catalog %u in namespace %u has no pg_depend entry on its namespace",
+ objectId, catalogId, namespaceId);
+ }
+}
+#endif /* USE_ASSERT_CHECKING */
+
+/*
+ * GetNamespaceRelations
+ * Return the OIDs of the relations in a namespace whose relkind is one
+ * of the characters in "relkinds".
+ *
+ * pg_class has no index on relnamespace, so a plain search costs a scan of
+ * the whole catalog no matter how small the namespace is. But every table,
+ * view, materialized view, sequence, foreign table and partitioned table
+ * records a pg_depend entry on its namespace (see heap_create_with_catalog),
+ * and pg_depend is indexed by referenced object, so we can find the members
+ * of a namespace from there. Two cases are not covered by pg_depend:
+ *
+ * - No dependencies are recorded on a pinned namespace (pg_catalog, pg_toast
+ * and so on), so for those we scan pg_class as before.
+ *
+ * - Indexes, composite types and TOAST tables have no namespace dependency
+ * of their own. Callers must not ask for those relkinds.
+ *
+ * When system indexes are ignored, scan pg_class directly rather than
+ * scanning pg_depend without its reference index.
+ *
+ * A pg_depend entry is only a candidate: a relation can also depend on some
+ * other namespace through an expression (a regnamespace constant in a
+ * partition key, say), so each one is rechecked against its pg_class row.
+ *
+ * Looking up each candidate costs far more than reading one row in a scan,
+ * so if the namespace turns out to hold a sizable part of pg_class we scan
+ * anyway (see namespace_scan_is_cheaper).
+ *
+ * The result is sorted by OID, whichever way it was found. Callers such as
+ * GRANT update every member, and a catalog scan may start anywhere in the
+ * heap (synchronized scans), so without a fixed order two sessions working
+ * on the same namespace could take the row locks in different orders and
+ * deadlock.
+ */
+List *
+GetNamespaceRelations(Oid namespaceId, const char *relkinds)
+{
+ List *result = NIL;
+ List *candidates;
+ ListCell *lc;
+
+ Assert(relkinds != NULL);
+ Assert(strchr(relkinds, RELKIND_INDEX) == NULL);
+ Assert(strchr(relkinds, RELKIND_PARTITIONED_INDEX) == NULL);
+ Assert(strchr(relkinds, RELKIND_COMPOSITE_TYPE) == NULL);
+ Assert(strchr(relkinds, RELKIND_TOASTVALUE) == NULL);
+
+ if (IgnoreSystemIndexes || IsPinnedObject(NamespaceRelationId, namespaceId))
+ return scan_namespace_relations(namespaceId, relkinds);
+
+ candidates = getDependentObjectsOfClass(RelationRelationId,
+ NamespaceRelationId,
+ namespaceId);
+ if (namespace_scan_is_cheaper(RelationRelationId, list_length(candidates)))
+ {
+ list_free(candidates);
+ return scan_namespace_relations(namespaceId, relkinds);
+ }
+
+ foreach(lc, candidates)
+ {
+ Oid relid = lfirst_oid(lc);
+ HeapTuple tuple;
+ Form_pg_class classForm;
+
+ tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
+ if (!HeapTupleIsValid(tuple))
+ continue; /* concurrently dropped */
+ classForm = (Form_pg_class) GETSTRUCT(tuple);
+ if (classForm->relnamespace == namespaceId &&
+ strchr(relkinds, classForm->relkind) != NULL)
+ result = lappend_oid(result, relid);
+ ReleaseSysCache(tuple);
+ }
+ list_free(candidates);
+
+#ifdef USE_ASSERT_CHECKING
+ check_namespace_members(RelationRelationId, namespaceId, result,
+ scan_namespace_relations(namespaceId, relkinds));
+#endif
+
+ return result;
+}
+
+/*
+ * GetNamespaceFunctions
+ * Return the OIDs of the functions (including aggregates and window
+ * functions) and/or procedures in a namespace.
+ *
+ * Same method as GetNamespaceRelations: every pg_proc entry records a
+ * dependency on its namespace (see ProcedureCreate) unless the namespace is
+ * pinned. Scan pg_proc directly if system indexes are ignored.
+ */
+List *
+GetNamespaceFunctions(Oid namespaceId, bool functions, bool procedures)
+{
+ List *result = NIL;
+ List *candidates;
+ ListCell *lc;
+
+ if (IgnoreSystemIndexes || IsPinnedObject(NamespaceRelationId, namespaceId))
+ return scan_namespace_functions(namespaceId, functions, procedures);
+
+ candidates = getDependentObjectsOfClass(ProcedureRelationId,
+ NamespaceRelationId,
+ namespaceId);
+ if (namespace_scan_is_cheaper(ProcedureRelationId, list_length(candidates)))
+ {
+ list_free(candidates);
+ return scan_namespace_functions(namespaceId, functions, procedures);
+ }
+
+ foreach(lc, candidates)
+ {
+ Oid procid = lfirst_oid(lc);
+ HeapTuple tuple;
+ Form_pg_proc procForm;
+
+ tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(procid));
+ if (!HeapTupleIsValid(tuple))
+ continue; /* concurrently dropped */
+ procForm = (Form_pg_proc) GETSTRUCT(tuple);
+ if (procForm->pronamespace == namespaceId &&
+ (procForm->prokind == PROKIND_PROCEDURE ? procedures : functions))
+ result = lappend_oid(result, procid);
+ ReleaseSysCache(tuple);
+ }
+ list_free(candidates);
+
+#ifdef USE_ASSERT_CHECKING
+ check_namespace_members(ProcedureRelationId, namespaceId, result,
+ scan_namespace_functions(namespaceId, functions,
+ procedures));
+#endif
+
+ return result;
+}
+
/*
* isTempNamespace - is the given namespace my temporary-table namespace?
*/
diff --git a/src/backend/catalog/pg_depend.c b/src/backend/catalog/pg_depend.c
index 9a7a401acedb0ee0ffe11b048f49001df8bb97b4..8006383dbc70b3595bd21d0bbc503a62d3cc5060 100644
--- a/src/backend/catalog/pg_depend.c
+++ b/src/backend/catalog/pg_depend.c
@@ -1293,3 +1293,59 @@ get_index_ref_constraints(Oid indexId)
return result;
}
+
+/*
+ * getDependentObjectsOfClass
+ * Return the OIDs of the objects of catalog "classId" that have a
+ * pg_depend entry (of any type) on the whole object
+ * refClassId/refObjectId.
+ *
+ * This answers "what hangs from X" with one scan of the reference index.
+ * The list is sorted by OID and has no duplicates. An entry here says only
+ * that some dependency exists; callers that want a specific relationship
+ * (members of a namespace, for example) must recheck each object.
+ */
+List *
+getDependentObjectsOfClass(Oid classId, Oid refClassId, Oid refObjectId)
+{
+ List *result = NIL;
+ Relation depRel;
+ ScanKeyData key[3];
+ SysScanDesc scan;
+ HeapTuple tup;
+
+ depRel = table_open(DependRelationId, AccessShareLock);
+
+ ScanKeyInit(&key[0],
+ Anum_pg_depend_refclassid,
+ BTEqualStrategyNumber, F_OIDEQ,
+ ObjectIdGetDatum(refClassId));
+ ScanKeyInit(&key[1],
+ Anum_pg_depend_refobjid,
+ BTEqualStrategyNumber, F_OIDEQ,
+ ObjectIdGetDatum(refObjectId));
+ ScanKeyInit(&key[2],
+ Anum_pg_depend_refobjsubid,
+ BTEqualStrategyNumber, F_INT4EQ,
+ Int32GetDatum(0));
+
+ scan = systable_beginscan(depRel, DependReferenceIndexId, true,
+ NULL, 3, key);
+
+ while (HeapTupleIsValid(tup = systable_getnext(scan)))
+ {
+ Form_pg_depend deprec = (Form_pg_depend) GETSTRUCT(tup);
+
+ if (deprec->classid == classId && deprec->objsubid == 0)
+ result = lappend_oid(result, deprec->objid);
+ }
+
+ systable_endscan(scan);
+ table_close(depRel, AccessShareLock);
+
+ /* pg_depend may hold duplicate entries */
+ list_sort(result, list_oid_cmp);
+ list_deduplicate_oid(result);
+
+ return result;
+}
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 0f2e9c3dd74b96be6327f6878ba00b161c3a3205..80b2c7afd25006e88bd5aa0eccd819bfc1d4ff82 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -3313,13 +3313,13 @@ ReindexMultipleTables(const ReindexStmt *stmt, const ReindexParams *params)
Oid objectOid;
Relation relationRelation;
- TableScanDesc scan;
- ScanKeyData scan_keys[1];
+ TableScanDesc scan = NULL;
HeapTuple tuple;
MemoryContext private_context;
MemoryContext old;
List *relids = NIL;
- int num_keys;
+ List *schemarels = NIL;
+ int nextrel = 0;
bool concurrent_warning = false;
bool tablespace_warning = false;
const char *objectName = stmt->name;
@@ -3381,33 +3381,51 @@ ReindexMultipleTables(const ReindexStmt *stmt, const ReindexParams *params)
ALLOCSET_SMALL_SIZES);
/*
- * Define the search keys to find the objects to reindex. For a schema, we
- * select target relations using relnamespace, something not necessary for
- * a database-wide operation.
+ * Build a list of the relations we need to reindex. For a schema, we
+ * get its tables and materialized views from GetNamespaceRelations();
+ * for a database-wide operation, we scan pg_class.
+ *
+ * We only consider plain relations and materialized views here (toast
+ * rels will be processed indirectly by reindex_relation).
*/
+ relationRelation = table_open(RelationRelationId, AccessShareLock);
if (objectKind == REINDEX_OBJECT_SCHEMA)
{
- num_keys = 1;
- ScanKeyInit(&scan_keys[0],
- Anum_pg_class_relnamespace,
- BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(objectOid));
+ static const char reindexkinds[] = {RELKIND_RELATION, RELKIND_MATVIEW, '\0'};
+
+ schemarels = GetNamespaceRelations(objectOid, reindexkinds);
}
else
- num_keys = 0;
+ scan = table_beginscan_catalog(relationRelation, 0, NULL);
- /*
- * Scan pg_class to build a list of the relations we need to reindex.
- *
- * We only consider plain relations and materialized views here (toast
- * rels will be processed indirectly by reindex_relation).
- */
- relationRelation = table_open(RelationRelationId, AccessShareLock);
- scan = table_beginscan_catalog(relationRelation, num_keys, scan_keys);
- while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
+ for (;;)
{
- Form_pg_class classtuple = (Form_pg_class) GETSTRUCT(tuple);
- Oid relid = classtuple->oid;
+ FormData_pg_class classform;
+ Form_pg_class classtuple;
+ Oid relid;
+
+ if (objectKind == REINDEX_OBJECT_SCHEMA)
+ {
+ if (nextrel >= list_length(schemarels))
+ break;
+ tuple = SearchSysCache1(RELOID,
+ ObjectIdGetDatum(list_nth_oid(schemarels,
+ nextrel++)));
+ if (!HeapTupleIsValid(tuple))
+ continue;
+ /* keep the fixed-size part only, so that we can just "continue" */
+ memcpy(&classform, GETSTRUCT(tuple), CLASS_TUPLE_SIZE);
+ ReleaseSysCache(tuple);
+ classtuple = &classform;
+ }
+ else
+ {
+ tuple = heap_getnext(scan, ForwardScanDirection);
+ if (tuple == NULL)
+ break;
+ classtuple = (Form_pg_class) GETSTRUCT(tuple);
+ }
+ relid = classtuple->oid;
/*
* Only regular tables and matviews can have indexes, so ignore any
@@ -3511,7 +3529,8 @@ ReindexMultipleTables(const ReindexStmt *stmt, const ReindexParams *params)
MemoryContextSwitchTo(old);
}
- table_endscan(scan);
+ if (scan != NULL)
+ table_endscan(scan);
table_close(relationRelation, AccessShareLock);
/*
diff --git a/src/include/catalog/dependency.h b/src/include/catalog/dependency.h
index 9782d0df2a7c8ba9f781030c9940d82add9302b6..d1284a78433a27f1bd2eec349437bea26496453b 100644
--- a/src/include/catalog/dependency.h
+++ b/src/include/catalog/dependency.h
@@ -200,6 +200,9 @@ extern Oid getIdentitySequence(Relation rel, AttrNumber attnum, bool missing_ok)
extern Oid get_index_constraint(Oid indexId);
+extern List *getDependentObjectsOfClass(Oid classId, Oid refClassId,
+ Oid refObjectId);
+
extern List *get_index_ref_constraints(Oid indexId);
/* in pg_shdepend.c */
diff --git a/src/include/catalog/namespace.h b/src/include/catalog/namespace.h
index 9453a3e49329742feed1f3e153beaf7284eb6dcf..39b2b2f5dc61537cfe242f9cac55b7bee2c1aac1 100644
--- a/src/include/catalog/namespace.h
+++ b/src/include/catalog/namespace.h
@@ -171,6 +171,10 @@ extern RangeVar *makeRangeVarFromNameList(const List *names);
extern char *NameListToString(const List *names);
extern char *NameListToQuotedString(const List *names);
+extern List *GetNamespaceRelations(Oid namespaceId, const char *relkinds);
+extern List *GetNamespaceFunctions(Oid namespaceId, bool functions,
+ bool procedures);
+
extern bool isTempNamespace(Oid namespaceId);
extern bool isTempToastNamespace(Oid namespaceId);
extern bool isTempOrTempToastNamespace(Oid namespaceId);
diff --git a/src/test/regress/expected/oidjoins.out b/src/test/regress/expected/oidjoins.out
index 51b9608a6680854bce7ae6e47fea380ad970a427..6e2ad2c0bb45ddba77e297e3599f57f5e299e268 100644
--- a/src/test/regress/expected/oidjoins.out
+++ b/src/test/regress/expected/oidjoins.out
@@ -273,3 +273,35 @@ NOTICE: checking pg_subscription {subowner} => pg_authid {oid}
NOTICE: checking pg_subscription {subserver} => pg_foreign_server {oid}
NOTICE: checking pg_subscription_rel {srsubid} => pg_subscription {oid}
NOTICE: checking pg_subscription_rel {srrelid} => pg_class {oid}
+--
+-- Verify that relations and functions depend on their namespace
+--
+-- GetNamespaceRelations() and GetNamespaceFunctions() find the members of a
+-- namespace through pg_depend, so every relation of a kind they can return,
+-- and every function, must have a dependency on its namespace, unless the
+-- namespace is pinned (OID below FirstUnpinnedObjectId, except public).
+SELECT c.oid::regclass, c.relkind
+FROM pg_class c
+WHERE c.relkind IN ('r', 'v', 'm', 'S', 'f', 'p') AND
+ (c.relnamespace >= 12000 OR c.relnamespace = 'public'::regnamespace) AND
+ NOT EXISTS (SELECT 1 FROM pg_depend d
+ WHERE d.classid = 'pg_class'::regclass AND
+ d.objid = c.oid AND d.objsubid = 0 AND
+ d.refclassid = 'pg_namespace'::regclass AND
+ d.refobjid = c.relnamespace AND d.refobjsubid = 0);
+ oid | relkind
+-----+---------
+(0 rows)
+
+SELECT p.oid::regprocedure, p.prokind
+FROM pg_proc p
+WHERE (p.pronamespace >= 12000 OR p.pronamespace = 'public'::regnamespace) AND
+ NOT EXISTS (SELECT 1 FROM pg_depend d
+ WHERE d.classid = 'pg_proc'::regclass AND
+ d.objid = p.oid AND d.objsubid = 0 AND
+ d.refclassid = 'pg_namespace'::regclass AND
+ d.refobjid = p.pronamespace AND d.refobjsubid = 0);
+ oid | prokind
+-----+---------
+(0 rows)
+
diff --git a/src/test/regress/sql/oidjoins.sql b/src/test/regress/sql/oidjoins.sql
index 8b22e6d10c5eca68c208b2c9598fe2b689a508c1..651d7dee87a37c13400dc29e7b1132a91375a697 100644
--- a/src/test/regress/sql/oidjoins.sql
+++ b/src/test/regress/sql/oidjoins.sql
@@ -47,3 +47,30 @@ begin
end loop;
end
$doblock$;
+
+--
+-- Verify that relations and functions depend on their namespace
+--
+-- GetNamespaceRelations() and GetNamespaceFunctions() find the members of a
+-- namespace through pg_depend, so every relation of a kind they can return,
+-- and every function, must have a dependency on its namespace, unless the
+-- namespace is pinned (OID below FirstUnpinnedObjectId, except public).
+
+SELECT c.oid::regclass, c.relkind
+FROM pg_class c
+WHERE c.relkind IN ('r', 'v', 'm', 'S', 'f', 'p') AND
+ (c.relnamespace >= 12000 OR c.relnamespace = 'public'::regnamespace) AND
+ NOT EXISTS (SELECT 1 FROM pg_depend d
+ WHERE d.classid = 'pg_class'::regclass AND
+ d.objid = c.oid AND d.objsubid = 0 AND
+ d.refclassid = 'pg_namespace'::regclass AND
+ d.refobjid = c.relnamespace AND d.refobjsubid = 0);
+
+SELECT p.oid::regprocedure, p.prokind
+FROM pg_proc p
+WHERE (p.pronamespace >= 12000 OR p.pronamespace = 'public'::regnamespace) AND
+ NOT EXISTS (SELECT 1 FROM pg_depend d
+ WHERE d.classid = 'pg_proc'::regclass AND
+ d.objid = p.oid AND d.objsubid = 0 AND
+ d.refclassid = 'pg_namespace'::regclass AND
+ d.refobjid = p.pronamespace AND d.refobjsubid = 0);
From: Manu <[email protected]>
Subject: [PATCH v1 2/3] Use GetNamespaceRelations() for schema publications
GetSchemaPublicationRelations() scans the whole of pg_class once per
published schema. It runs on the publisher for CREATE PUBLICATION ...
FOR TABLES IN SCHEMA, ALTER PUBLICATION ... ADD/DROP TABLES IN SCHEMA,
SET (...) and RENAME, DROP PUBLICATION, and for every call of
pg_get_publication_tables() without a target relation, which CREATE
SUBSCRIPTION and ALTER SUBSCRIPTION ... REFRESH PUBLICATION issue. With
many published schemas that is one full scan of pg_class per schema. Get
the tables and partitioned tables of the schema from
GetNamespaceRelations() instead.
---
diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c
index f11ea88..7447849 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -1228,33 +1228,35 @@ GetSchemaPublications(Oid schemaid)
List *
GetSchemaPublicationRelations(Oid schemaid, PublicationPartOpt pub_partopt)
{
- Relation classRel;
- ScanKeyData key[1];
- TableScanDesc scan;
- HeapTuple tuple;
+ static const char pubkinds[] = {RELKIND_RELATION, RELKIND_PARTITIONED_TABLE, '\0'};
+ List *schemarels;
+ ListCell *lc;
List *result = NIL;
Assert(OidIsValid(schemaid));
- classRel = table_open(RelationRelationId, AccessShareLock);
-
- ScanKeyInit(&key[0],
- Anum_pg_class_relnamespace,
- BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(schemaid));
+ /* get all the tables present in the specified schema */
+ schemarels = GetNamespaceRelations(schemaid, pubkinds);
- /* get all the relations present in the specified schema */
- scan = table_beginscan_catalog(classRel, 1, key);
- while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
+ foreach(lc, schemarels)
{
- Form_pg_class relForm = (Form_pg_class) GETSTRUCT(tuple);
- Oid relid = relForm->oid;
+ Oid relid = lfirst_oid(lc);
+ HeapTuple tuple;
+ Form_pg_class relForm;
char relkind;
+ bool publishable;
- if (!is_publishable_class(relid, relForm))
+ tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
+ if (!HeapTupleIsValid(tuple))
+ continue;
+ relForm = (Form_pg_class) GETSTRUCT(tuple);
+ publishable = is_publishable_class(relid, relForm);
+ relkind = relForm->relkind;
+ ReleaseSysCache(tuple);
+
+ if (!publishable)
continue;
- relkind = get_rel_relkind(relid);
if (relkind == RELKIND_RELATION)
result = lappend_oid(result, relid);
else if (relkind == RELKIND_PARTITIONED_TABLE)
@@ -1268,13 +1270,12 @@ GetSchemaPublicationRelations(Oid schemaid, PublicationPartOpt pub_partopt)
*/
partitionrels = GetPubPartitionOptionRelations(partitionrels,
pub_partopt,
- relForm->oid);
+ relid);
result = list_concat_unique_oid(result, partitionrels);
}
}
- table_endscan(scan);
- table_close(classRel, AccessShareLock);
+ list_free(schemarels);
return result;
}
From: Manu <[email protected]>
Subject: [PATCH v1 3/3] Use GetNamespaceRelations() for GRANT ... ON ALL TABLES IN SCHEMA
objectsInSchemaToOids() scanned pg_class five times for OBJECT_TABLE,
once per relkind. Ask GetNamespaceRelations() once for the five
relkinds instead, and remove getRelationsInNamespace(), which has no
other caller.
The list is now in OID order instead of grouped by relkind in physical
order.
The idea of collecting the five relkinds in one pass is CharSyam's,
posted with a patch that does it with one scan of pg_class.
Suggested-by: CharSyam <[email protected]>
Discussion: https://postgr.es/m/CAMrLSE7bZ70eGaTMH3-g=TA_sfp3kTDOrHVNYw1=1xl9kra...@mail.gmail.com
---
diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c
index 7c4fbab..1067b12 100644
--- a/src/backend/catalog/aclchk.c
+++ b/src/backend/catalog/aclchk.c
@@ -124,7 +124,6 @@ static void SetDefaultACL(InternalDefaultACL *iacls);
static List *objectNamesToOids(ObjectType objtype, List *objnames,
bool is_grant);
static List *objectsInSchemaToOids(ObjectType objtype, List *nspnames);
-static List *getRelationsInNamespace(Oid namespaceId, char relkind);
static void expand_col_privileges(List *colnames, Oid table_oid,
AclMode this_privileges,
AclMode *col_privileges,
@@ -788,16 +787,15 @@ objectsInSchemaToOids(ObjectType objtype, List *nspnames)
switch (objtype)
{
case OBJECT_TABLE:
- objs = getRelationsInNamespace(namespaceId, RELKIND_RELATION);
- objects = list_concat(objects, objs);
- objs = getRelationsInNamespace(namespaceId, RELKIND_VIEW);
- objects = list_concat(objects, objs);
- objs = getRelationsInNamespace(namespaceId, RELKIND_MATVIEW);
- objects = list_concat(objects, objs);
- objs = getRelationsInNamespace(namespaceId, RELKIND_FOREIGN_TABLE);
- objects = list_concat(objects, objs);
- objs = getRelationsInNamespace(namespaceId, RELKIND_PARTITIONED_TABLE);
- objects = list_concat(objects, objs);
+ {
+ static const char tablekinds[] = {
+ RELKIND_RELATION, RELKIND_VIEW, RELKIND_MATVIEW,
+ RELKIND_FOREIGN_TABLE, RELKIND_PARTITIONED_TABLE, '\0'
+ };
+
+ objs = GetNamespaceRelations(namespaceId, tablekinds);
+ objects = list_concat(objects, objs);
+ }
break;
case OBJECT_SEQUENCE:
{
@@ -826,46 +824,6 @@ objectsInSchemaToOids(ObjectType objtype, List *nspnames)
return objects;
}
-/*
- * getRelationsInNamespace
- *
- * Return Oid list of relations in given namespace filtered by relation kind
- */
-static List *
-getRelationsInNamespace(Oid namespaceId, char relkind)
-{
- List *relations = NIL;
- ScanKeyData key[2];
- Relation rel;
- TableScanDesc scan;
- HeapTuple tuple;
-
- ScanKeyInit(&key[0],
- Anum_pg_class_relnamespace,
- BTEqualStrategyNumber, F_OIDEQ,
- ObjectIdGetDatum(namespaceId));
- ScanKeyInit(&key[1],
- Anum_pg_class_relkind,
- BTEqualStrategyNumber, F_CHAREQ,
- CharGetDatum(relkind));
-
- rel = table_open(RelationRelationId, AccessShareLock);
- scan = table_beginscan_catalog(rel, 2, key);
-
- while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
- {
- Oid oid = ((Form_pg_class) GETSTRUCT(tuple))->oid;
-
- relations = lappend_oid(relations, oid);
- }
-
- table_endscan(scan);
- table_close(rel, AccessShareLock);
-
- return relations;
-}
-
-
/*
* ALTER DEFAULT PRIVILEGES statement
*/
#!/usr/bin/env python3
"""tenants.py PREFIX N OUT.tsv [PORT]
Tenant sign-up scenario. Starts from a fresh cluster of the install at PREFIX
and adds N
tenants one after another. One sign-up = one transaction:
CREATE SCHEMA tN;
CREATE TABLE tN.a1 .. tN.a10 (id int PRIMARY KEY, v text);
GRANT SELECT ON ALL TABLES IN SCHEMA tN TO reader;
ALTER PUBLICATION pub ADD TABLES IN SCHEMA tN;
COMMIT;
Writes one row per sign-up: i, total ms, and ms for the GRANT and for the ALTER
PUBLICATION (both measured client-side, inside the same transaction). The last
line
is a comment with pg_class size at the end. The cluster is created under
~/.cache/ygg-tenants/<port> and removed afterwards.
GUCs: fsync=off, synchronous_commit=off, autovacuum=off (AV=on to enable), so
the
number is CPU in the catalog, not disk; shared_buffers=1GB (SB=... to change).
"""
import os, shutil, subprocess, sys, time
import psycopg
prefix, n, out = sys.argv[1], int(sys.argv[2]), sys.argv[3]
port = int(sys.argv[4]) if len(sys.argv) > 4 else 61437
base = os.path.expanduser(f"~/.cache/ygg-tenants/{port}")
data = os.path.join(base, "data")
bindir = os.path.join(prefix, "bin")
def run(*a):
subprocess.run(a, check=True, stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT)
shutil.rmtree(base, ignore_errors=True)
os.makedirs(base)
run(f"{bindir}/initdb", "-D", data, "-A", "trust", "-U", "postgres",
"--no-sync", "-E", "UTF8",
"--locale=C")
with open(os.path.join(data, "postgresql.conf"), "a") as f:
f.write(f"""
port = {port}
listen_addresses = ''
unix_socket_directories = '{base}'
fsync = off
synchronous_commit = off
full_page_writes = off
autovacuum = {os.environ.get('AV', 'off')}
shared_buffers = {os.environ.get('SB', '1GB')}
wal_level = logical
max_wal_size = 8GB
log_min_messages = warning
""")
run(f"{bindir}/pg_ctl", "-D", data, "-l", os.path.join(base, "log"), "-w",
"start")
try:
conn = psycopg.connect(host=base, port=port, user="postgres",
dbname="postgres",
autocommit=True)
cur = conn.cursor()
cur.execute("CREATE ROLE reader")
cur.execute("CREATE PUBLICATION pub") # empty; schemas are added one by
one
cur.execute("SELECT reltuples, relpages FROM pg_class WHERE oid =
'pg_class'::regclass")
initial_catalog_stats = cur.fetchone()
conn.autocommit = False
tables = "".join(f"CREATE TABLE {{s}}.a{k} (id int PRIMARY KEY, v text);"
for k in range(1, 11))
rows = []
for i in range(1, n + 1):
s = f"t{i}"
t0 = time.perf_counter()
cur.execute(f"CREATE SCHEMA {s}")
cur.execute(tables.format(s=s))
t1 = time.perf_counter()
cur.execute(f"GRANT SELECT ON ALL TABLES IN SCHEMA {s} TO reader")
t2 = time.perf_counter()
cur.execute(f"ALTER PUBLICATION pub ADD TABLES IN SCHEMA {s}")
t3 = time.perf_counter()
conn.commit()
t4 = time.perf_counter()
rows.append((i, (t4 - t0) * 1e3, (t2 - t1) * 1e3, (t3 - t2) * 1e3))
conn.autocommit = True
cur.execute("SELECT count(*) FROM pg_class")
nclass = cur.fetchone()[0]
cur.execute("SELECT reltuples, relpages, pg_relation_size(oid) /
current_setting('block_size')::int "
"FROM pg_class WHERE oid = 'pg_class'::regclass")
final_catalog_stats = cur.fetchone()
# sanity: every tenant table is granted and published
cur.execute("SELECT count(*) FROM pg_class c JOIN pg_namespace n ON n.oid =
c.relnamespace "
"WHERE n.nspname ~ '^t[0-9]+$' AND c.relkind = 'r' "
"AND has_table_privilege('reader', c.oid, 'SELECT')")
granted = cur.fetchone()[0]
cur.execute("SELECT count(*) FROM pg_publication_tables WHERE pubname =
'pub'")
published = cur.fetchone()[0]
conn.close()
finally:
subprocess.run([f"{bindir}/pg_ctl", "-D", data, "-m", "fast", "-w", "stop"],
stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
shutil.rmtree(base, ignore_errors=True)
ok = granted == 10 * n and published == 10 * n
with open(out, "w") as f:
f.write("i\tms\tgrant_ms\tpub_ms\n")
for r in rows:
f.write("%d\t%.3f\t%.3f\t%.3f\n" % r)
f.write(f"# pg_class stats initial={initial_catalog_stats}
final={final_catalog_stats}\n")
f.write(f"# pg_class={nclass} granted={granted} published={published}
ok={ok}\n")
print(f"{out}: n={n} total_ms={sum(r[1] for r in rows):.0f} pg_class={nclass}
ok={ok}")
sys.exit(0 if ok else 3)
Tenant sign-up benchmark, elapsed time in seconds.
Each total sums the per-sign-up elapsed times recorded by tenants.py.
To reproduce a run, install psycopg and run as a non-root user:
python3 tenants.py.txt /path/to/install 5000 output.tsv [PORT]
Use a dedicated port: the script recreates its directory for that port.
Master is 458c77d74d2. The series runs precede the change to bypass
pg_depend with ignore_system_indexes. The two builds ran in separate
batches on the same exclusive benchmark lane. See the script for GUCs.
tenants build round total_s last500_grant_ms last500_publication_ms
500 master 1 2.036095 0.9900 0.2375
500 master 2 2.064007 0.9425 0.2380
500 master 3 2.062023 0.9800 0.2450
500 master 4 2.018216 0.9465 0.2320
500 master 5 1.963166 0.9025 0.2235
500 series 1 1.428769 0.1285 0.0635
500 series 2 1.534332 0.1310 0.0670
500 series 3 1.640188 0.1420 0.0720
1000 master 1 5.839996 3.1460 0.6230
1000 master 2 5.428384 2.7970 0.5745
1000 master 3 6.301602 3.6420 0.6870
1000 master 4 6.439933 3.5155 0.6725
1000 master 5 5.836450 3.0935 0.6295
1000 series 1 3.130619 0.1320 0.0665
1000 series 2 3.010796 0.1330 0.0680
1000 series 3 3.048548 0.1370 0.0700
2000 master 1 22.680346 12.3535 2.4680
2000 master 2 22.063910 12.4520 2.5135
2000 master 3 20.376036 11.9260 2.4390
2000 master 4 19.896054 11.0390 2.2440
2000 master 5 21.043540 11.0550 2.2855
2000 series 1 6.617622 0.1600 0.0795
2000 series 2 6.428845 0.1420 0.0720
2000 series 3 6.422367 0.1510 0.0755
5000 master 1 139.129741 41.4735 8.4605
5000 master 2 135.201122 40.7070 8.3075
5000 master 3 140.319785 41.2980 8.3345
5000 master 4 129.779067 39.5565 8.0895
5000 master 5 129.516205 39.3205 8.0840
5000 series 1 16.661566 0.1400 0.0720
5000 series 2 19.368295 0.1420 0.0740
5000 series 3 16.886618 0.1460 0.0750
[bench] esperando carril B (compilaciones/bench en curso)
[integrity] limpio carril a: calib=49060us (idle=48195us, +1%)
Catalog rows: 100433
master round=1
reindex ignore=False milliseconds=[3.057, 3.797, 3.36, 3.35, 2.817, 2.537,
2.632, 2.703, 2.403, 2.201] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(10, 0)
reindex ignore=True milliseconds=[10.114, 10.617, 9.425, 9.724, 10.02, 11.25,
9.197, 10.0, 10.41, 11.794] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(170, 0)
before round=1
reindex ignore=False milliseconds=[0.287, 0.237, 0.207, 0.299, 0.23, 0.183,
0.181, 0.182, 0.26, 0.188] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(0, 0)
reindex ignore=True milliseconds=[18.255, 20.033, 17.567, 18.776, 19.717,
18.984, 17.138, 18.683, 17.993, 18.616] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(160, 10)
after round=1
reindex ignore=False milliseconds=[0.476, 0.245, 0.196, 0.295, 0.218, 0.202,
0.191, 0.198, 0.183, 0.182] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(0, 0)
reindex ignore=True milliseconds=[23.17, 18.493, 17.213, 20.091, 20.681,
16.43, 26.027, 23.88, 28.697, 28.782] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(170, 0)
before round=2
reindex ignore=False milliseconds=[0.293, 0.203, 0.199, 0.232, 0.231, 0.187,
0.207, 0.188, 0.194, 0.198] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(0, 0)
reindex ignore=True milliseconds=[21.463, 20.083, 19.762, 21.617, 19.616,
22.018, 20.213, 19.774, 21.755, 20.474] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(160, 10)
after round=2
reindex ignore=False milliseconds=[0.164, 0.184, 0.167, 0.177, 0.153, 0.182,
0.247, 0.164, 0.134, 0.123] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(0, 0)
reindex ignore=True milliseconds=[27.4, 19.267, 17.167, 16.7, 16.149, 15.985,
16.256, 16.939, 23.933, 22.084] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(170, 0)
master round=2
reindex ignore=False milliseconds=[3.703, 3.354, 3.196, 3.279, 3.164, 3.444,
2.956, 3.488, 3.203, 3.118] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(10, 0)
reindex ignore=True milliseconds=[17.357, 21.815, 25.888, 18.359, 28.842,
29.087, 27.357, 18.808, 17.851, 16.652] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(170, 0)
after round=3
reindex ignore=False milliseconds=[0.26, 0.223, 0.415, 0.276, 0.22, 0.331,
0.214, 0.202, 0.193, 0.192] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(0, 0)
reindex ignore=True milliseconds=[26.045, 23.098, 20.355, 17.13, 17.039,
16.251, 22.526, 24.73, 24.978, 19.492] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(170, 0)
master round=3
reindex ignore=False milliseconds=[3.934, 3.58, 3.33, 3.492, 3.387, 3.538,
3.299, 3.185, 3.271, 3.62] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(10, 0)
reindex ignore=True milliseconds=[18.943, 26.559, 24.791, 18.317, 27.043,
25.974, 24.855, 18.798, 17.25, 17.369] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(170, 0)
before round=3
reindex ignore=False milliseconds=[0.35, 0.371, 0.317, 0.368, 0.213, 0.2,
0.215, 0.197, 0.19, 0.168] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(0, 0)
reindex ignore=True milliseconds=[28.033, 27.208, 26.408, 31.661, 28.078,
19.091, 24.609, 22.346, 29.844, 25.213] rebuilt=2
reindex catalog heap scans (pg_class, pg_depend)=(160, 10)
summary master ignore=False n=30 median_ms=3.289
summary master ignore=True n=30 median_ms=18.084
summary before ignore=False n=30 median_ms=0.207
summary before ignore=True n=30 median_ms=20.148
summary after ignore=False n=30 median_ms=0.197
summary after ignore=True n=30 median_ms=20.223
[integrity] limpio carril a: calib=48958us (idle=48195us, +1%)