~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_lex.cc

  • Committer: Monty Taylor
  • Date: 2008-11-25 01:28:52 UTC
  • mto: This revision was merged to the branch mainline in revision 612.
  • Revision ID: mtaylor@bitters-20081125012852-v93e3xn33qpon6re
Fixed a few things for solaris builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
339
339
  lex->nest_level=0 ;
340
340
  lex->allow_sum_func= 0;
341
341
  lex->in_sum_func= NULL;
 
342
  /*
 
343
    ok, there must be a better solution for this, long-term
 
344
    I tried "memset" in the sql_yacc.yy code, but that for
 
345
    some reason made the values zero, even if they were set
 
346
  */
 
347
  lex->server_options.server_name= 0;
 
348
  lex->server_options.server_name_length= 0;
 
349
  lex->server_options.host= 0;
 
350
  lex->server_options.db= 0;
 
351
  lex->server_options.username= 0;
 
352
  lex->server_options.password= 0;
 
353
  lex->server_options.scheme= 0;
 
354
  lex->server_options.owner= 0;
 
355
  lex->server_options.port= -1;
342
356
 
343
357
  lex->is_lex_started= true;
344
358
  return;
2132
2146
  reset_query_tables_list(true);
2133
2147
}
2134
2148
 
 
2149
 
 
2150
/*
 
2151
  Check whether the merging algorithm can be used on this VIEW
 
2152
 
 
2153
  SYNOPSIS
 
2154
    LEX::can_be_merged()
 
2155
 
 
2156
  DESCRIPTION
 
2157
    We can apply merge algorithm if it is single SELECT view  with
 
2158
    subqueries only in WHERE clause (we do not count SELECTs of underlying
 
2159
    views, and second level subqueries) and we have not grpouping, ordering,
 
2160
    HAVING clause, aggregate functions, DISTINCT clause, LIMIT clause and
 
2161
    several underlying tables.
 
2162
 
 
2163
  RETURN
 
2164
    false - only temporary table algorithm can be used
 
2165
    true  - merge algorithm can be used
 
2166
*/
 
2167
 
 
2168
bool LEX::can_be_merged()
 
2169
{
 
2170
  // TODO: do not forget implement case when select_lex.table_list.elements==0
 
2171
 
 
2172
  /* find non VIEW subqueries/unions */
 
2173
  bool selects_allow_merge= select_lex.next_select() == 0;
 
2174
  if (selects_allow_merge)
 
2175
  {
 
2176
    for (SELECT_LEX_UNIT *tmp_unit= select_lex.first_inner_unit();
 
2177
         tmp_unit;
 
2178
         tmp_unit= tmp_unit->next_unit())
 
2179
    {
 
2180
      if (tmp_unit->first_select()->parent_lex == this &&
 
2181
          (tmp_unit->item == 0 ||
 
2182
           (tmp_unit->item->place() != IN_WHERE &&
 
2183
            tmp_unit->item->place() != IN_ON)))
 
2184
      {
 
2185
        selects_allow_merge= 0;
 
2186
        break;
 
2187
      }
 
2188
    }
 
2189
  }
 
2190
 
 
2191
  return (selects_allow_merge &&
 
2192
          select_lex.group_list.elements == 0 &&
 
2193
          select_lex.having == 0 &&
 
2194
          select_lex.with_sum_func == 0 &&
 
2195
          select_lex.table_list.elements >= 1 &&
 
2196
          !(select_lex.options & SELECT_DISTINCT) &&
 
2197
          select_lex.select_limit == 0);
 
2198
}
 
2199
 
 
2200
 
 
2201
/*
 
2202
  check if command can use VIEW with MERGE algorithm (for top VIEWs)
 
2203
 
 
2204
  SYNOPSIS
 
2205
    LEX::can_use_merged()
 
2206
 
 
2207
  DESCRIPTION
 
2208
    Only listed here commands can use merge algorithm in top level
 
2209
    SELECT_LEX (for subqueries will be used merge algorithm if
 
2210
    LEX::can_not_use_merged() is not true).
 
2211
 
 
2212
  RETURN
 
2213
    false - command can't use merged VIEWs
 
2214
    true  - VIEWs with MERGE algorithms can be used
 
2215
*/
 
2216
 
 
2217
bool LEX::can_use_merged()
 
2218
{
 
2219
  switch (sql_command)
 
2220
  {
 
2221
  case SQLCOM_SELECT:
 
2222
  case SQLCOM_CREATE_TABLE:
 
2223
  case SQLCOM_UPDATE:
 
2224
  case SQLCOM_UPDATE_MULTI:
 
2225
  case SQLCOM_DELETE:
 
2226
  case SQLCOM_DELETE_MULTI:
 
2227
  case SQLCOM_INSERT:
 
2228
  case SQLCOM_INSERT_SELECT:
 
2229
  case SQLCOM_REPLACE:
 
2230
  case SQLCOM_REPLACE_SELECT:
 
2231
  case SQLCOM_LOAD:
 
2232
    return true;
 
2233
  default:
 
2234
    return false;
 
2235
  }
 
2236
}
 
2237
 
 
2238
/*
 
2239
  Check if command can't use merged views in any part of command
 
2240
 
 
2241
  SYNOPSIS
 
2242
    LEX::can_not_use_merged()
 
2243
 
 
2244
  DESCRIPTION
 
2245
    Temporary table algorithm will be used on all SELECT levels for queries
 
2246
    listed here (see also LEX::can_use_merged()).
 
2247
 
 
2248
  RETURN
 
2249
    false - command can't use merged VIEWs
 
2250
    true  - VIEWs with MERGE algorithms can be used
 
2251
*/
 
2252
 
 
2253
bool LEX::can_not_use_merged()
 
2254
{
 
2255
  switch (sql_command)
 
2256
  {
 
2257
  /*
 
2258
    SQLCOM_SHOW_FIELDS is necessary to make 
 
2259
    information schema tables working correctly with views.
 
2260
    see get_schema_tables_result function
 
2261
  */
 
2262
  case SQLCOM_SHOW_FIELDS:
 
2263
    return true;
 
2264
  default:
 
2265
    return false;
 
2266
  }
 
2267
}
 
2268
 
2135
2269
/*
2136
2270
  Detect that we need only table structure of derived table/view
2137
2271