* getExtensionMembership --- obtain extension membership data * * We need to identify objects that are extension members as soon as they're * loaded, so that we can correctly determine whether they need to be dumped. * Generally speaking, extension member objects will get marked as *not* to * be dumped, as they will be recreated by the single CREATE EXTENSION * command. However, in binary u
| 20422 | * individually. |
| 20423 | */ |
| 20424 | void |
| 20425 | getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], |
| 20426 | int numExtensions) |
| 20427 | { |
| 20428 | PQExpBuffer query; |
| 20429 | PGresult *res; |
| 20430 | int ntups, |
| 20431 | i; |
| 20432 | int i_classid, |
| 20433 | i_objid, |
| 20434 | i_refobjid; |
| 20435 | ExtensionInfo *ext; |
| 20436 | |
| 20437 | /* Nothing to do if no extensions */ |
| 20438 | if (numExtensions == 0) |
| 20439 | return; |
| 20440 | |
| 20441 | query = createPQExpBuffer(); |
| 20442 | |
| 20443 | /* refclassid constraint is redundant but may speed the search */ |
| 20444 | appendPQExpBufferStr(query, "SELECT " |
| 20445 | "classid, objid, refobjid " |
| 20446 | "FROM pg_depend " |
| 20447 | "WHERE refclassid = 'pg_extension'::regclass " |
| 20448 | "AND deptype = 'e' " |
| 20449 | "ORDER BY 3"); |
| 20450 | |
| 20451 | res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); |
| 20452 | |
| 20453 | ntups = PQntuples(res); |
| 20454 | |
| 20455 | i_classid = PQfnumber(res, "classid"); |
| 20456 | i_objid = PQfnumber(res, "objid"); |
| 20457 | i_refobjid = PQfnumber(res, "refobjid"); |
| 20458 | |
| 20459 | /* |
| 20460 | * Since we ordered the SELECT by referenced ID, we can expect that |
| 20461 | * multiple entries for the same extension will appear together; this |
| 20462 | * saves on searches. |
| 20463 | */ |
| 20464 | ext = NULL; |
| 20465 | |
| 20466 | for (i = 0; i < ntups; i++) |
| 20467 | { |
| 20468 | CatalogId objId; |
| 20469 | Oid extId; |
| 20470 | |
| 20471 | objId.tableoid = atooid(PQgetvalue(res, i, i_classid)); |
| 20472 | objId.oid = atooid(PQgetvalue(res, i, i_objid)); |
| 20473 | extId = atooid(PQgetvalue(res, i, i_refobjid)); |
| 20474 | |
| 20475 | if (ext == NULL || |
| 20476 | ext->dobj.catId.oid != extId) |
| 20477 | ext = findExtensionByOid(extId); |
| 20478 | |
| 20479 | if (ext == NULL) |
| 20480 | { |
| 20481 | /* shouldn't happen */ |
no test coverage detected