2132
2132
reset_query_tables_list(true);
2137
Check whether the merging algorithm can be used on this VIEW
2140
LEX::can_be_merged()
2143
We can apply merge algorithm if it is single SELECT view with
2144
subqueries only in WHERE clause (we do not count SELECTs of underlying
2145
views, and second level subqueries) and we have not grpouping, ordering,
2146
HAVING clause, aggregate functions, DISTINCT clause, LIMIT clause and
2147
several underlying tables.
2150
false - only temporary table algorithm can be used
2151
true - merge algorithm can be used
2154
bool LEX::can_be_merged()
2156
// TODO: do not forget implement case when select_lex.table_list.elements==0
2158
/* find non VIEW subqueries/unions */
2159
bool selects_allow_merge= select_lex.next_select() == 0;
2160
if (selects_allow_merge)
2162
for (SELECT_LEX_UNIT *tmp_unit= select_lex.first_inner_unit();
2164
tmp_unit= tmp_unit->next_unit())
2166
if (tmp_unit->first_select()->parent_lex == this &&
2167
(tmp_unit->item == 0 ||
2168
(tmp_unit->item->place() != IN_WHERE &&
2169
tmp_unit->item->place() != IN_ON)))
2171
selects_allow_merge= 0;
2177
return (selects_allow_merge &&
2178
select_lex.group_list.elements == 0 &&
2179
select_lex.having == 0 &&
2180
select_lex.with_sum_func == 0 &&
2181
select_lex.table_list.elements >= 1 &&
2182
!(select_lex.options & SELECT_DISTINCT) &&
2183
select_lex.select_limit == 0);
2188
check if command can use VIEW with MERGE algorithm (for top VIEWs)
2191
LEX::can_use_merged()
2194
Only listed here commands can use merge algorithm in top level
2195
SELECT_LEX (for subqueries will be used merge algorithm if
2196
LEX::can_not_use_merged() is not true).
2199
false - command can't use merged VIEWs
2200
true - VIEWs with MERGE algorithms can be used
2203
bool LEX::can_use_merged()
2205
switch (sql_command)
2208
case SQLCOM_CREATE_TABLE:
2210
case SQLCOM_UPDATE_MULTI:
2212
case SQLCOM_DELETE_MULTI:
2214
case SQLCOM_INSERT_SELECT:
2215
case SQLCOM_REPLACE:
2216
case SQLCOM_REPLACE_SELECT:
2225
Check if command can't use merged views in any part of command
2228
LEX::can_not_use_merged()
2231
Temporary table algorithm will be used on all SELECT levels for queries
2232
listed here (see also LEX::can_use_merged()).
2235
false - command can't use merged VIEWs
2236
true - VIEWs with MERGE algorithms can be used
2239
bool LEX::can_not_use_merged()
2241
switch (sql_command)
2244
SQLCOM_SHOW_FIELDS is necessary to make
2245
information schema tables working correctly with views.
2246
see get_schema_tables_result function
2248
case SQLCOM_SHOW_FIELDS:
2256
2136
Detect that we need only table structure of derived table/view