* If this relation could possibly be scanned from within a worker, then set * its consider_parallel flag. */
| 856 | * its consider_parallel flag. |
| 857 | */ |
| 858 | static void |
| 859 | set_rel_consider_parallel(PlannerInfo *root, RelOptInfo *rel, |
| 860 | RangeTblEntry *rte) |
| 861 | { |
| 862 | /* |
| 863 | * The flag has previously been initialized to false, so we can just |
| 864 | * return if it becomes clear that we can't safely set it. |
| 865 | */ |
| 866 | Assert(!rel->consider_parallel); |
| 867 | |
| 868 | /* Don't call this if parallelism is disallowed for the entire query. */ |
| 869 | Assert(root->glob->parallelModeOK); |
| 870 | |
| 871 | /* This should only be called for baserels and appendrel children. */ |
| 872 | Assert(IS_SIMPLE_REL(rel)); |
| 873 | |
| 874 | /* Assorted checks based on rtekind. */ |
| 875 | switch (rte->rtekind) |
| 876 | { |
| 877 | case RTE_RELATION: |
| 878 | |
| 879 | /* |
| 880 | * Currently, parallel workers can't access the leader's temporary |
| 881 | * tables. We could possibly relax this if we wrote all of its |
| 882 | * local buffers at the start of the query and made no changes |
| 883 | * thereafter (maybe we could allow hint bit changes), and if we |
| 884 | * taught the workers to read them. Writing a large number of |
| 885 | * temporary buffers could be expensive, though, and we don't have |
| 886 | * the rest of the necessary infrastructure right now anyway. So |
| 887 | * for now, bail out if we see a temporary table. |
| 888 | */ |
| 889 | if (get_rel_persistence(rte->relid) == RELPERSISTENCE_TEMP) |
| 890 | return; |
| 891 | |
| 892 | /* |
| 893 | * Table sampling can be pushed down to workers if the sample |
| 894 | * function and its arguments are safe. |
| 895 | */ |
| 896 | if (rte->tablesample != NULL) |
| 897 | { |
| 898 | char proparallel = func_parallel(rte->tablesample->tsmhandler); |
| 899 | |
| 900 | if (proparallel != PROPARALLEL_SAFE) |
| 901 | return; |
| 902 | if (!is_parallel_safe(root, (Node *) rte->tablesample->args)) |
| 903 | return; |
| 904 | } |
| 905 | |
| 906 | /* |
| 907 | * Ask FDWs whether they can support performing a ForeignScan |
| 908 | * within a worker. Most often, the answer will be no. For |
| 909 | * example, if the nature of the FDW is such that it opens a TCP |
| 910 | * connection with a remote server, each parallel worker would end |
| 911 | * up with a separate connection, and these connections might not |
| 912 | * be appropriately coordinated between workers and the leader. |
| 913 | */ |
| 914 | if (rte->relkind == RELKIND_FOREIGN_TABLE) |
| 915 | { |
no test coverage detected