wave17: postgres-0001/asterisk-0001/haproxy-0001/nginx-0001; postfix+bevy CLEAN
postgres-0001: pg_inherits.c typeInheritsFrom() BFS visited List → HTAB O(1) asterisk-0001: app_queue.c interface_exists() ao2_iterator walk → ao2_find O(1) haproxy-0001: http_ana.c cookie-server scan linked-list → eb-tree index O(log S) nginx-0001: ngx_http_link_multi_headers() O(H²) double-scan → O(H) hash pass postfix: CLEAN (htable throughout; two marginal LOW admin-bounded candidates) bevy: CLEAN (FixedBitSet/HashSet throughout; only hardware-bounded marginals)
This commit is contained in:
parent
da8b4a41d6
commit
ff6292d067
10 changed files with 627 additions and 252 deletions
|
|
@ -0,0 +1,72 @@
|
|||
--- a/src/backend/catalog/pg_inherits.c
|
||||
+++ b/src/backend/catalog/pg_inherits.c
|
||||
@@ -406,12 +406,16 @@ bool
|
||||
typeInheritsFrom(Oid subclassTypeId, Oid superclassTypeId)
|
||||
{
|
||||
bool result = false;
|
||||
Oid subclassRelid;
|
||||
Oid superclassRelid;
|
||||
Relation inhrel;
|
||||
- List *visited,
|
||||
- *queue;
|
||||
+ HTAB *visited_set; /* O(1) OID lookup; replaces O(V) list_member_oid */
|
||||
+ HASHCTL ctl;
|
||||
+ List *queue;
|
||||
ListCell *queue_item;
|
||||
|
||||
/* We need to work with the associated relation OIDs */
|
||||
subclassRelid = typeOrDomainTypeRelid(subclassTypeId);
|
||||
if (subclassRelid == InvalidOid)
|
||||
@@ -428,7 +432,14 @@ typeInheritsFrom(Oid subclassTypeId, Oid superclassTypeId)
|
||||
queue = list_make1_oid(subclassRelid);
|
||||
- visited = NIL;
|
||||
+
|
||||
+ ctl.keysize = sizeof(Oid);
|
||||
+ ctl.entrysize = sizeof(Oid);
|
||||
+ ctl.hcxt = CurrentMemoryContext;
|
||||
+ visited_set = hash_create("typeInheritsFrom visited set",
|
||||
+ 32,
|
||||
+ &ctl,
|
||||
+ HASH_ELEM | HASH_BLOBS | HASH_CONTEXT);
|
||||
|
||||
inhrel = table_open(InheritsRelationId, AccessShareLock);
|
||||
|
||||
@@ -443,11 +454,12 @@ typeInheritsFrom(Oid subclassTypeId, Oid superclassTypeId)
|
||||
foreach(queue_item, queue)
|
||||
{
|
||||
Oid this_relid = lfirst_oid(queue_item);
|
||||
ScanKeyData skey;
|
||||
SysScanDesc inhscan;
|
||||
HeapTuple inhtup;
|
||||
+ bool found;
|
||||
|
||||
/*
|
||||
* If we've seen this relid already, skip it. This avoids extra work
|
||||
* in multiple-inheritance scenarios, and also protects us from an
|
||||
* infinite loop in case there is a cycle in pg_inherits (though
|
||||
* theoretically that shouldn't happen).
|
||||
*/
|
||||
- if (list_member_oid(visited, this_relid))
|
||||
+ hash_search(visited_set, &this_relid, HASH_ENTER, &found);
|
||||
+ if (found)
|
||||
continue;
|
||||
|
||||
- /*
|
||||
- * Okay, this is a not-yet-seen relid. Add it to the list of
|
||||
- * already-visited OIDs, then find all the types this relid inherits
|
||||
- * from and add them to the queue.
|
||||
- */
|
||||
- visited = lappend_oid(visited, this_relid);
|
||||
-
|
||||
ScanKeyInit(&skey,
|
||||
Anum_pg_inherits_inhrelid,
|
||||
BTEqualStrategyNumber, F_OIDEQ,
|
||||
@@ -493,7 +497,7 @@ typeInheritsFrom(Oid subclassTypeId, Oid superclassTypeId)
|
||||
/* clean up ... */
|
||||
table_close(inhrel, AccessShareLock);
|
||||
|
||||
- list_free(visited);
|
||||
+ hash_destroy(visited_set);
|
||||
list_free(queue);
|
||||
|
||||
return result;
|
||||
Loading…
Add table
Add a link
Reference in a new issue