~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/replace_select.cc

Merge Stewart's dead code removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2009 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
 
21
#include <drizzled/server_includes.h>
22
22
#include <drizzled/show.h>
23
23
#include <drizzled/lock.h>
24
24
#include <drizzled/session.h>
29
29
 
30
30
bool statement::ReplaceSelect::execute()
31
31
{
32
 
  TableList *first_table= (TableList *) getSession()->lex->select_lex.table_list.first;
33
 
  TableList *all_tables= getSession()->lex->query_tables;
 
32
  TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
 
33
  TableList *all_tables= session->lex->query_tables;
34
34
  assert(first_table == all_tables && first_table != 0);
35
 
  Select_Lex *select_lex= &getSession()->lex->select_lex;
36
 
  Select_Lex_Unit *unit= &getSession()->lex->unit;
 
35
  Select_Lex *select_lex= &session->lex->select_lex;
 
36
  Select_Lex_Unit *unit= &session->lex->unit;
37
37
  select_result *sel_result= NULL;
38
 
  bool res;
 
38
  bool res= false;
 
39
  bool need_start_waiting= false;
39
40
 
40
 
  if (insert_precheck(getSession(), all_tables))
 
41
  if (insert_precheck(session, all_tables))
41
42
  {
42
43
    return true;
43
44
  }
47
48
 
48
49
  unit->set_limit(select_lex);
49
50
 
50
 
  if (getSession()->wait_if_global_read_lock(false, true))
 
51
  if (! (need_start_waiting= ! wait_if_global_read_lock(session, 0, 1)))
51
52
  {
52
53
    return true;
53
54
  }
54
55
 
55
 
  if (! (res= getSession()->openTablesLock(all_tables)))
 
56
  if (! (res= session->openTablesLock(all_tables)))
56
57
  {
57
58
    /* Skip first table, which is the table we are inserting in */
58
59
    TableList *second_table= first_table->next_local;
59
60
    select_lex->table_list.first= (unsigned char*) second_table;
60
61
    select_lex->context.table_list=
61
62
      select_lex->context.first_name_resolution_table= second_table;
62
 
    res= insert_select_prepare(getSession());
 
63
    res= mysql_insert_select_prepare(session);
63
64
    if (! res && (sel_result= new select_insert(first_table,
64
65
                                                first_table->table,
65
 
                                                &getSession()->lex->field_list,
66
 
                                                &getSession()->lex->update_list,
67
 
                                                &getSession()->lex->value_list,
68
 
                                                getSession()->lex->duplicates,
69
 
                                                getSession()->lex->ignore)))
 
66
                                                &session->lex->field_list,
 
67
                                                &session->lex->update_list,
 
68
                                                &session->lex->value_list,
 
69
                                                session->lex->duplicates,
 
70
                                                session->lex->ignore)))
70
71
    {
71
 
      res= handle_select(getSession(),
72
 
                         getSession()->lex,
73
 
                         sel_result,
 
72
      res= handle_select(session, 
 
73
                         session->lex, 
 
74
                         sel_result, 
74
75
                         OPTION_SETUP_TABLES_DONE);
75
76
      /*
76
77
         Invalidate the table in the query cache if something changed
79
80
         the unlock procedure.
80
81
       */
81
82
      if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT &&
82
 
          getSession()->lock)
 
83
          session->lock)
83
84
      {
84
85
        /* INSERT ... SELECT should invalidate only the very first table */
85
86
        TableList *save_table= first_table->next_local;
96
97
     Release the protection against the global read lock and wake
97
98
     everyone, who might want to set a global read lock.
98
99
   */
99
 
  getSession()->startWaitingGlobalReadLock();
 
100
  start_waiting_global_read_lock(session);
100
101
 
101
102
  return res;
102
103
}