| 297 | */ |
| 298 | |
| 299 | bool With_clause::check_dependencies() |
| 300 | { |
| 301 | if (dependencies_are_checked) |
| 302 | return false; |
| 303 | /* |
| 304 | Look for for definitions with the same query name. |
| 305 | When found report an error and return true immediately. |
| 306 | For each table T defined in this with clause look for all other tables |
| 307 | from the same with clause that are used in the specification of T. |
| 308 | For each such table set the dependency bit in the dependency map of |
| 309 | the with element for T. |
| 310 | */ |
| 311 | for (With_element *with_elem= with_list.first; |
| 312 | with_elem; |
| 313 | with_elem= with_elem->next) |
| 314 | { |
| 315 | for (With_element *elem= with_list.first; |
| 316 | elem != with_elem; |
| 317 | elem= elem->next) |
| 318 | { |
| 319 | if (with_elem->get_name().streq(elem->get_name())) |
| 320 | { |
| 321 | my_error(ER_DUP_QUERY_NAME, MYF(0), |
| 322 | with_elem->get_name_str()); |
| 323 | return true; |
| 324 | } |
| 325 | } |
| 326 | if (with_elem->check_dependencies_in_spec()) |
| 327 | return true; |
| 328 | } |
| 329 | /* Build the transitive closure of the direct dependencies found above */ |
| 330 | for (With_element *with_elem= with_list.first; |
| 331 | with_elem; |
| 332 | with_elem= with_elem->next) |
| 333 | with_elem->derived_dep_map= with_elem->base_dep_map; |
| 334 | for (With_element *with_elem= with_list.first; |
| 335 | with_elem; |
| 336 | with_elem= with_elem->next) |
| 337 | { |
| 338 | table_map with_elem_map= with_elem->get_elem_map(); |
| 339 | for (With_element *elem= with_list.first; elem; elem= elem->next) |
| 340 | { |
| 341 | if (elem->derived_dep_map & with_elem_map) |
| 342 | elem->derived_dep_map |= with_elem->derived_dep_map; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | Mark those elements where tables are defined with direct or indirect |
| 348 | recursion. |
| 349 | */ |
| 350 | for (With_element *with_elem= with_list.first; |
| 351 | with_elem; |
| 352 | with_elem= with_elem->next) |
| 353 | { |
| 354 | if (with_elem->derived_dep_map & with_elem->get_elem_map()) |
| 355 | with_elem->is_recursive= true; |
| 356 | } |
no test coverage detected