---------------------------------------------------------------- * ExecInitRecursiveUnion * ---------------------------------------------------------------- */
| 177 | * ---------------------------------------------------------------- |
| 178 | */ |
| 179 | RecursiveUnionState * |
| 180 | ExecInitRecursiveUnion(RecursiveUnion *node, EState *estate, int eflags) |
| 181 | { |
| 182 | RecursiveUnionState *rustate; |
| 183 | ParamExecData *prmdata; |
| 184 | |
| 185 | /* check for unsupported flags */ |
| 186 | Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK))); |
| 187 | |
| 188 | /* |
| 189 | * create state structure |
| 190 | */ |
| 191 | rustate = makeNode(RecursiveUnionState); |
| 192 | rustate->ps.plan = (Plan *) node; |
| 193 | rustate->ps.state = estate; |
| 194 | rustate->ps.ExecProcNode = ExecRecursiveUnion; |
| 195 | |
| 196 | rustate->eqfuncoids = NULL; |
| 197 | rustate->hashfunctions = NULL; |
| 198 | rustate->hashtable = NULL; |
| 199 | rustate->tempContext = NULL; |
| 200 | rustate->tableContext = NULL; |
| 201 | |
| 202 | /* initialize processing state */ |
| 203 | rustate->recursing = false; |
| 204 | rustate->intermediate_empty = true; |
| 205 | rustate->working_table = tuplestore_begin_heap(false, false, work_mem); |
| 206 | rustate->intermediate_table = tuplestore_begin_heap(false, false, work_mem); |
| 207 | rustate->refcount = 0; |
| 208 | |
| 209 | /* |
| 210 | * If hashing, we need a per-tuple memory context for comparisons, and a |
| 211 | * longer-lived context to store the hash table. The table can't just be |
| 212 | * kept in the per-query context because we want to be able to throw it |
| 213 | * away when rescanning. |
| 214 | * |
| 215 | * RECURSIVE_CTE_FIXME: It suppose plan->numCols should be 0 if we don't |
| 216 | * support recursive union. QP should fix this later. |
| 217 | */ |
| 218 | if (node->numCols > 0) |
| 219 | { |
| 220 | rustate->tempContext = |
| 221 | AllocSetContextCreate(CurrentMemoryContext, |
| 222 | "RecursiveUnion", |
| 223 | ALLOCSET_DEFAULT_SIZES); |
| 224 | rustate->tableContext = |
| 225 | AllocSetContextCreate(CurrentMemoryContext, |
| 226 | "RecursiveUnion hash table", |
| 227 | ALLOCSET_DEFAULT_SIZES); |
| 228 | } |
| 229 | |
| 230 | /* |
| 231 | * Make the state structure available to descendant WorkTableScan nodes |
| 232 | * via the Param slot reserved for it. |
| 233 | */ |
| 234 | prmdata = &(estate->es_param_exec_vals[node->wtParam]); |
| 235 | Assert(prmdata->execPlan == NULL); |
| 236 | prmdata->value = PointerGetDatum(rustate); |
no test coverage detected