| 1986 | |
| 1987 | |
| 1988 | int JOIN::optimize() |
| 1989 | { |
| 1990 | int res= 0; |
| 1991 | if (select_lex->pushdown_select) |
| 1992 | { |
| 1993 | if (optimization_state == JOIN::OPTIMIZATION_DONE) |
| 1994 | return 0; |
| 1995 | DBUG_ASSERT(optimization_state == JOIN::NOT_OPTIMIZED); |
| 1996 | |
| 1997 | // Do same as JOIN::optimize_inner does: |
| 1998 | fields= &select_lex->item_list; |
| 1999 | |
| 2000 | if (!(select_options & SELECT_DESCRIBE)) |
| 2001 | { |
| 2002 | /* Prepare to execute the query pushed into a foreign engine */ |
| 2003 | res= select_lex->pushdown_select->prepare(); |
| 2004 | } |
| 2005 | with_two_phase_optimization= false; |
| 2006 | } |
| 2007 | else |
| 2008 | { |
| 2009 | /* |
| 2010 | This function may be invoked multiple times. Do nothing if the |
| 2011 | optimization (either full or stage1) are already done. |
| 2012 | */ |
| 2013 | if (optimization_state != JOIN::NOT_OPTIMIZED) |
| 2014 | return FALSE; |
| 2015 | optimization_state= JOIN::OPTIMIZATION_IN_PROGRESS; |
| 2016 | res= optimize_inner(); |
| 2017 | } |
| 2018 | if (!with_two_phase_optimization) |
| 2019 | { |
| 2020 | if (!res && have_query_plan != QEP_DELETED) |
| 2021 | res= build_explain(); |
| 2022 | optimization_state= JOIN::OPTIMIZATION_DONE; |
| 2023 | } |
| 2024 | |
| 2025 | /* |
| 2026 | Store the cost of this query into a user variable |
| 2027 | TODO: calculate a correct cost for a query with subqueries and UNIONs. |
| 2028 | */ |
| 2029 | if (select_lex->select_number == 1) |
| 2030 | thd->status_var.last_query_cost= best_read; |
| 2031 | return res; |
| 2032 | } |
| 2033 | |
| 2034 | |
| 2035 | /* |
no test coverage detected