* pgdatabasev - produce a view of pgdatabase to include transient state */
| 29 | * pgdatabasev - produce a view of pgdatabase to include transient state |
| 30 | */ |
| 31 | Datum |
| 32 | gp_pgdatabase__(PG_FUNCTION_ARGS) |
| 33 | { |
| 34 | FuncCallContext *funcctx; |
| 35 | Working_State *mystatus; |
| 36 | CdbComponentDatabases *cdb_dbs; |
| 37 | |
| 38 | if (SRF_IS_FIRSTCALL()) |
| 39 | { |
| 40 | TupleDesc tupdesc; |
| 41 | MemoryContext oldcontext; |
| 42 | |
| 43 | /* create a function context for cross-call persistence */ |
| 44 | funcctx = SRF_FIRSTCALL_INIT(); |
| 45 | |
| 46 | /* |
| 47 | * switch to memory context appropriate for multiple function calls |
| 48 | */ |
| 49 | oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx); |
| 50 | |
| 51 | /* build tupdesc for result tuples */ |
| 52 | /* this had better match pg_prepared_xacts view in system_views.sql */ |
| 53 | tupdesc = CreateTemplateTupleDesc(5); |
| 54 | TupleDescInitEntry(tupdesc, (AttrNumber) 1, "dbid", |
| 55 | INT2OID, -1, 0); |
| 56 | TupleDescInitEntry(tupdesc, (AttrNumber) 2, "isprimary", |
| 57 | BOOLOID, -1, 0); |
| 58 | TupleDescInitEntry(tupdesc, (AttrNumber) 3, "content", |
| 59 | INT2OID, -1, 0); |
| 60 | TupleDescInitEntry(tupdesc, (AttrNumber) 4, "valid", |
| 61 | BOOLOID, -1, 0); |
| 62 | TupleDescInitEntry(tupdesc, (AttrNumber) 5, "definedprimary", |
| 63 | BOOLOID, -1, 0); |
| 64 | |
| 65 | funcctx->tuple_desc = BlessTupleDesc(tupdesc); |
| 66 | |
| 67 | /* |
| 68 | * Collect all the locking information that we will format and send |
| 69 | * out as a result set. |
| 70 | */ |
| 71 | mystatus = (Working_State *) palloc(sizeof(Working_State)); |
| 72 | funcctx->user_fctx = (void *) mystatus; |
| 73 | |
| 74 | mystatus->cdb_component_dbs = cdbcomponent_getCdbComponents(); |
| 75 | mystatus->currIdx = 0; |
| 76 | |
| 77 | MemoryContextSwitchTo(oldcontext); |
| 78 | } |
| 79 | |
| 80 | funcctx = SRF_PERCALL_SETUP(); |
| 81 | mystatus = (Working_State *) funcctx->user_fctx; |
| 82 | cdb_dbs = mystatus->cdb_component_dbs; |
| 83 | |
| 84 | while (cdb_dbs != NULL && mystatus->currIdx < cdb_dbs->total_segment_dbs + cdb_dbs->total_entry_dbs) |
| 85 | { |
| 86 | Datum values[6]; |
| 87 | bool nulls[6]; |
| 88 | HeapTuple tuple; |
nothing calls this directly
no test coverage detected