* Compute the number of parallel workers that should be used to scan a * relation. We compute the parallel workers based on the size of the heap to * be scanned and the size of the index to be scanned, then choose a minimum * of those. * * "heap_pages" is the number of pages from the table that we expect to scan, or * -1 if we don't expect to scan any. * * "index_pages" is the number of p
| 4693 | * comes from a GUC. |
| 4694 | */ |
| 4695 | int |
| 4696 | compute_parallel_worker(PlannerInfo *root, RelOptInfo *rel, double heap_pages, double index_pages, |
| 4697 | int max_workers) |
| 4698 | { |
| 4699 | int parallel_workers = 0; |
| 4700 | |
| 4701 | /* |
| 4702 | * If the user has set the parallel_workers reloption, use that; otherwise |
| 4703 | * select a default number of workers. |
| 4704 | */ |
| 4705 | if (rel->rel_parallel_workers != -1) |
| 4706 | parallel_workers = rel->rel_parallel_workers; |
| 4707 | else |
| 4708 | { |
| 4709 | /* |
| 4710 | * We need to reconsider parallel workers for AO/AOCO tables |
| 4711 | * because page number in ao is quite hard to estimate. |
| 4712 | * The parallel for AO/AOCO tables is based on segment file count in |
| 4713 | * pg_appendonly which will be updated by analyze/vacuum/truncate processes. |
| 4714 | */ |
| 4715 | if (rel->reloptkind == RELOPT_BASEREL && (AMHandlerIsAO(rel->amhandler))) |
| 4716 | { |
| 4717 | Oid aorelid = root->simple_rte_array[rel->relid]->relid; |
| 4718 | HeapTuple aotup; |
| 4719 | Form_pg_appendonly aoform; |
| 4720 | aotup = SearchSysCache1(AORELID, ObjectIdGetDatum(aorelid)); |
| 4721 | if (!HeapTupleIsValid(aotup)) |
| 4722 | ereport(ERROR, |
| 4723 | (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 4724 | errmsg("appendonly table relid %u does not exist in pg_appendonly", aorelid))); |
| 4725 | |
| 4726 | aoform = (Form_pg_appendonly) GETSTRUCT(aotup); |
| 4727 | Assert(aoform->segfilecount >= 0); |
| 4728 | parallel_workers = Min(aoform->segfilecount, max_workers); |
| 4729 | ReleaseSysCache(aotup); |
| 4730 | |
| 4731 | /* |
| 4732 | * Disable parallel for AO/AOCO for: |
| 4733 | * 1.We don't support parallel/non-parallel IndexScan/IndexOnlyScan. |
| 4734 | * 2.If parallel_workers is 1, it is pointless in gp parallel mode. |
| 4735 | */ |
| 4736 | if (parallel_workers == 1 || index_pages >= 0) |
| 4737 | parallel_workers = 0; |
| 4738 | } |
| 4739 | else |
| 4740 | { |
| 4741 | /* |
| 4742 | * If the number of pages being scanned is insufficient to justify a |
| 4743 | * parallel scan, just return zero ... unless it's an inheritance |
| 4744 | * child. In that case, we want to generate a parallel path here |
| 4745 | * anyway. It might not be worthwhile just for this relation, but |
| 4746 | * when combined with all of its inheritance siblings it may well pay |
| 4747 | * off. |
| 4748 | */ |
| 4749 | if (rel->reloptkind == RELOPT_BASEREL && |
| 4750 | ((heap_pages >= 0 && heap_pages < min_parallel_table_scan_size) || |
| 4751 | (index_pages >= 0 && index_pages < min_parallel_index_scan_size))) |
| 4752 | return 0; |
no test coverage detected