* CompleteCachedPlan: second step of creating a plan cache entry. * * Pass in the analyzed-and-rewritten form of the query, as well as the * required subsidiary data about parameters and such. All passed values will * be copied into the CachedPlanSource's memory, except as specified below. * After this is called, GetCachedPlan can be called to obtain a plan, and * optionally the CachedPlanS
| 341 | * fixed_result: true to disallow future changes in query's result tupdesc |
| 342 | */ |
| 343 | void |
| 344 | CompleteCachedPlan(CachedPlanSource *plansource, |
| 345 | List *querytree_list, |
| 346 | MemoryContext querytree_context, |
| 347 | NodeTag sourceTag, |
| 348 | Oid *param_types, |
| 349 | int num_params, |
| 350 | ParserSetupHook parserSetup, |
| 351 | void *parserSetupArg, |
| 352 | int cursor_options, |
| 353 | bool fixed_result) |
| 354 | { |
| 355 | MemoryContext source_context = plansource->context; |
| 356 | MemoryContext oldcxt = CurrentMemoryContext; |
| 357 | |
| 358 | /* Assert caller is doing things in a sane order */ |
| 359 | Assert(plansource->magic == CACHEDPLANSOURCE_MAGIC); |
| 360 | Assert(!plansource->is_complete); |
| 361 | |
| 362 | /* |
| 363 | * If caller supplied a querytree_context, reparent it underneath the |
| 364 | * CachedPlanSource's context; otherwise, create a suitable context and |
| 365 | * copy the querytree_list into it. But no data copying should be done |
| 366 | * for one-shot plans; for those, assume the passed querytree_list is |
| 367 | * sufficiently long-lived. |
| 368 | */ |
| 369 | if (plansource->is_oneshot) |
| 370 | { |
| 371 | querytree_context = CurrentMemoryContext; |
| 372 | } |
| 373 | else if (querytree_context != NULL) |
| 374 | { |
| 375 | MemoryContextSetParent(querytree_context, source_context); |
| 376 | MemoryContextSwitchTo(querytree_context); |
| 377 | } |
| 378 | else |
| 379 | { |
| 380 | /* Again, it's a good bet the querytree_context can be small */ |
| 381 | querytree_context = AllocSetContextCreate(source_context, |
| 382 | "CachedPlanQuery", |
| 383 | ALLOCSET_START_SMALL_SIZES); |
| 384 | MemoryContextSwitchTo(querytree_context); |
| 385 | querytree_list = copyObject(querytree_list); |
| 386 | } |
| 387 | |
| 388 | plansource->query_context = querytree_context; |
| 389 | plansource->query_list = querytree_list; |
| 390 | |
| 391 | if (!plansource->is_oneshot && !IsTransactionStmtPlan(plansource)) |
| 392 | { |
| 393 | /* |
| 394 | * Use the planner machinery to extract dependencies. Data is saved |
| 395 | * in query_context. (We assume that not a lot of extra cruft is |
| 396 | * created by this call.) We can skip this for one-shot plans, and |
| 397 | * transaction control commands have no such dependencies anyway. |
| 398 | */ |
| 399 | extract_query_dependencies((Node *) querytree_list, |
| 400 | &plansource->relationOids, |
no test coverage detected