~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_select.cc

  • Committer: Andrew Hutchings
  • Date: 2010-11-09 13:38:01 UTC
  • mto: (1919.1.2 trunk)
  • mto: This revision was merged to the branch mainline in revision 1920.
  • Revision ID: andrew@linuxjedi.co.uk-20101109133801-byjzsao76346395x
Add FLUSH GLOBAL STATUS; command
Clears the global status variables for the server

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
#include "drizzled/index_hint.h"
52
52
#include "drizzled/records.h"
53
53
#include "drizzled/internal/iocache.h"
54
 
#include "drizzled/drizzled.h"
55
54
 
56
55
#include "drizzled/sql_union.h"
57
56
#include "drizzled/optimizer/key_field.h"
62
61
#include "drizzled/optimizer/quick_range_select.h"
63
62
#include "drizzled/optimizer/quick_ror_intersect_select.h"
64
63
 
65
 
#include "drizzled/filesort.h"
66
 
 
67
64
using namespace std;
68
65
 
69
66
namespace drizzled
117
114
{
118
115
  bool res;
119
116
  register Select_Lex *select_lex= &lex->select_lex;
120
 
  DRIZZLE_SELECT_START(session->getQueryString()->c_str());
 
117
  DRIZZLE_SELECT_START(session->query.c_str());
121
118
 
122
119
  if (select_lex->master_unit()->is_union() ||
123
120
      select_lex->master_unit()->fake_select_lex)
135
132
      every PS/SP execution new, we will not need reset this flag if
136
133
      setup_tables_done_option changed for next rexecution
137
134
    */
138
 
    res= mysql_select(session,
139
 
                      &select_lex->ref_pointer_array,
 
135
    res= mysql_select(session, &select_lex->ref_pointer_array,
140
136
                      (TableList*) select_lex->table_list.first,
141
 
                      select_lex->with_wild,
142
 
                      select_lex->item_list,
 
137
                      select_lex->with_wild, select_lex->item_list,
143
138
                      select_lex->where,
144
139
                      select_lex->order_list.elements +
145
140
                      select_lex->group_list.elements,
1221
1216
  delete quick;
1222
1217
  quick= 0;
1223
1218
  if (cache.buff)
1224
 
  {
1225
 
    size_t size= cache.end - cache.buff;
1226
 
    global_join_buffer.sub(size);
1227
1219
    free(cache.buff);
1228
 
  }
1229
1220
  cache.buff= 0;
1230
1221
  limit= 0;
1231
1222
  if (table)
2377
2368
    Item *item;
2378
2369
    while ((item=li++))
2379
2370
      change_cond_ref_to_const(session, save_list, and_level ? cond : item, item, field, value);
2380
 
 
2381
2371
    return;
2382
2372
  }
2383
2373
  if (cond->eq_cmp_result() == Item::COND_OK)
2490
2480
      for (vector<COND_CMP>::iterator iter= save.begin(); iter != save.end(); ++iter)
2491
2481
      {
2492
2482
        Item **args= iter->cmp_func->arguments();
2493
 
        if (not args[0]->const_item())
 
2483
        if (!args[0]->const_item())
2494
2484
        {
2495
 
          change_cond_ref_to_const(session, save_list, iter->and_level,
2496
 
                                   iter->and_level, args[0], args[1] );
 
2485
          change_cond_ref_to_const( session, save, iter->and_level,
 
2486
                                    iter->and_level, args[0], args[1] );
2497
2487
        }
2498
2488
      }
2499
2489
    }
3150
3140
      rc= sub_select(join,join_tab,end_of_records);
3151
3141
    return rc;
3152
3142
  }
3153
 
  if (join->session->getKilled())               // If aborted by user
 
3143
  if (join->session->killed)            // If aborted by user
3154
3144
  {
3155
3145
    join->session->send_kill_message();
3156
3146
    return NESTED_LOOP_KILLED;
3961
3951
  Table *table=join->tmp_table;
3962
3952
  int     idx= -1;
3963
3953
 
3964
 
  if (join->session->getKilled())
 
3954
  if (join->session->killed)
3965
3955
  {                                             // Aborted by user
3966
3956
    join->session->send_kill_message();
3967
3957
    return NESTED_LOOP_KILLED;
4009
3999
    if (idx < (int) join->send_group_parts)
4010
4000
    {
4011
4001
      copy_fields(&join->tmp_table_param);
4012
 
      if (copy_funcs(join->tmp_table_param.items_to_copy, join->session))
4013
 
        return NESTED_LOOP_ERROR;
 
4002
      copy_funcs(join->tmp_table_param.items_to_copy);
4014
4003
      if (init_sum_functions(join->sum_funcs, join->sum_funcs_end[idx+1]))
4015
4004
        return NESTED_LOOP_ERROR;
4016
4005
      return NESTED_LOOP_OK;
5017
5006
    return(0);
5018
5007
  for (Order *ord= join->order; ord; ord= ord->next)
5019
5008
    length++;
5020
 
  if (!(join->sortorder= make_unireg_sortorder(order, &length, join->sortorder)))
5021
 
  {
5022
 
    return(-1);
5023
 
  }
 
5009
  if (!(join->sortorder=
 
5010
        make_unireg_sortorder(order, &length, join->sortorder)))
 
5011
    goto err;
5024
5012
 
5025
5013
  table->sort.io_cache= new internal::IO_CACHE;
5026
5014
  table->status=0;                              // May be wrong if quick_select
5055
5043
                                                                 &tab->ref,
5056
5044
                                                                 tab->found_records))))
5057
5045
      {
5058
 
        return(-1);
 
5046
        goto err;
5059
5047
      }
5060
5048
    }
5061
5049
  }
5062
5050
 
5063
5051
  if (table->getShare()->getType())
5064
5052
    table->cursor->info(HA_STATUS_VARIABLE);    // Get record count
5065
 
 
5066
 
  FileSort filesort(*session);
5067
 
  table->sort.found_records=filesort.run(table,join->sortorder, length,
5068
 
                                         select, filesort_limit, 0,
5069
 
                                         examined_rows);
 
5053
  table->sort.found_records=filesort(session, table,join->sortorder, length,
 
5054
                                     select, filesort_limit, 0,
 
5055
                                     &examined_rows);
5070
5056
  tab->records= table->sort.found_records;      // For SQL_CALC_ROWS
5071
5057
  if (select)
5072
5058
  {
5084
5070
    table->key_read=0;
5085
5071
    table->cursor->extra(HA_EXTRA_NO_KEYREAD);
5086
5072
  }
5087
 
 
5088
5073
  return(table->sort.found_records == HA_POS_ERROR);
 
5074
err:
 
5075
  return(-1);
5089
5076
}
5090
5077
 
5091
5078
int remove_dup_with_compare(Session *session, Table *table, Field **first_field, uint32_t offset, Item *having)
5103
5090
  error=cursor->rnd_next(record);
5104
5091
  for (;;)
5105
5092
  {
5106
 
    if (session->getKilled())
 
5093
    if (session->killed)
5107
5094
    {
5108
5095
      session->send_kill_message();
5109
5096
      error=0;
5221
5208
  for (;;)
5222
5209
  {
5223
5210
    unsigned char *org_key_pos;
5224
 
    if (session->getKilled())
 
5211
    if (session->killed)
5225
5212
    {
5226
5213
      session->send_kill_message();
5227
5214
      error=0;
6198
6185
}
6199
6186
 
6200
6187
/** Copy result of functions to record in tmp_table. */
6201
 
bool copy_funcs(Item **func_ptr, const Session *session)
 
6188
void copy_funcs(Item **func_ptr)
6202
6189
{
6203
6190
  Item *func;
6204
6191
  for (; (func = *func_ptr) ; func_ptr++)
6205
 
  {
6206
6192
    func->save_in_result_field(1);
6207
 
    /*
6208
 
      Need to check the THD error state because Item::val_xxx() don't
6209
 
      return error code, but can generate errors
6210
 
      TODO: change it for a real status check when Item::val_xxx()
6211
 
      are extended to return status code.
6212
 
    */
6213
 
    if (session->is_error())
6214
 
      return true;
6215
 
  }
6216
 
  return false;
6217
6193
}
6218
6194
 
6219
6195
/**