* set_tablesample_rel_pathlist * Build access paths for a sampled relation */
| 1143 | * Build access paths for a sampled relation |
| 1144 | */ |
| 1145 | static void |
| 1146 | set_tablesample_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte) |
| 1147 | { |
| 1148 | Relids required_outer; |
| 1149 | Path *path; |
| 1150 | |
| 1151 | /* |
| 1152 | * We don't support pushing join clauses into the quals of a samplescan, |
| 1153 | * but it could still have required parameterization due to LATERAL refs |
| 1154 | * in its tlist or TABLESAMPLE arguments. |
| 1155 | */ |
| 1156 | required_outer = rel->lateral_relids; |
| 1157 | |
| 1158 | /* Consider sampled scan */ |
| 1159 | path = create_samplescan_path(root, rel, required_outer); |
| 1160 | |
| 1161 | /* |
| 1162 | * If the sampling method does not support repeatable scans, we must avoid |
| 1163 | * plans that would scan the rel multiple times. Ideally, we'd simply |
| 1164 | * avoid putting the rel on the inside of a nestloop join; but adding such |
| 1165 | * a consideration to the planner seems like a great deal of complication |
| 1166 | * to support an uncommon usage of second-rate sampling methods. Instead, |
| 1167 | * if there is a risk that the query might perform an unsafe join, just |
| 1168 | * wrap the SampleScan in a Materialize node. We can check for joins by |
| 1169 | * counting the membership of all_baserels (note that this correctly |
| 1170 | * counts inheritance trees as single rels). If we're inside a subquery, |
| 1171 | * we can't easily check whether a join might occur in the outer query, so |
| 1172 | * just assume one is possible. |
| 1173 | * |
| 1174 | * GetTsmRoutine is relatively expensive compared to the other tests here, |
| 1175 | * so check repeatable_across_scans last, even though that's a bit odd. |
| 1176 | */ |
| 1177 | if ((root->query_level > 1 || |
| 1178 | bms_membership(root->all_baserels) != BMS_SINGLETON) && |
| 1179 | !(GetTsmRoutine(rte->tablesample->tsmhandler)->repeatable_across_scans)) |
| 1180 | { |
| 1181 | path = (Path *) create_material_path(rel, path); |
| 1182 | } |
| 1183 | |
| 1184 | add_path(rel, path, root); |
| 1185 | |
| 1186 | /* For the moment, at least, there are no other paths to consider */ |
| 1187 | } |
| 1188 | |
| 1189 | /* |
| 1190 | * set_foreign_size |
no test coverage detected