~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/insert_select.cc

  • Committer: Olaf van der Spek
  • Date: 2011-04-05 12:26:58 UTC
  • mto: (2278.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2272.
  • Revision ID: olafvdspek@gmail.com-20110405122658-xxrvmobwwwwf3oct
Refactor Open_tables_state

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <drizzled/probes.h>
26
26
#include <drizzled/statement/insert_select.h>
27
27
#include <drizzled/select_insert.h>
 
28
#include <drizzled/sql_lex.h>
28
29
 
29
 
namespace drizzled
30
 
{
 
30
namespace drizzled {
31
31
 
32
32
bool statement::InsertSelect::execute()
33
33
{
34
 
  TableList *first_table= (TableList *) getSession()->getLex()->select_lex.table_list.first;
35
 
  TableList *all_tables= getSession()->getLex()->query_tables;
 
34
  TableList *first_table= (TableList *) lex().select_lex.table_list.first;
 
35
  TableList *all_tables= lex().query_tables;
36
36
  assert(first_table == all_tables && first_table != 0);
37
 
  Select_Lex *select_lex= &getSession()->getLex()->select_lex;
38
 
  Select_Lex_Unit *unit= &getSession()->getLex()->unit;
 
37
  Select_Lex *select_lex= &lex().select_lex;
 
38
  Select_Lex_Unit *unit= &lex().unit;
39
39
  select_result *sel_result= NULL;
40
40
  bool res= false;
41
41
  bool need_start_waiting= false;
42
42
 
43
 
  if (insert_precheck(getSession(), all_tables))
 
43
  if (insert_precheck(&session(), all_tables))
44
44
  {
45
45
    return true;
46
46
  }
50
50
 
51
51
  unit->set_limit(select_lex);
52
52
 
53
 
  if (! (need_start_waiting= not getSession()->wait_if_global_read_lock(false, true)))
 
53
  if (! (need_start_waiting= not session().wait_if_global_read_lock(false, true)))
54
54
  {
55
55
    return true;
56
56
  }
57
57
 
58
 
  if (! (res= getSession()->openTablesLock(all_tables)))
 
58
  if (! (res= session().openTablesLock(all_tables)))
59
59
  {
60
 
    DRIZZLE_INSERT_SELECT_START(getSession()->getQueryString()->c_str());
 
60
    DRIZZLE_INSERT_SELECT_START(session().getQueryString()->c_str());
61
61
    /* Skip first table, which is the table we are inserting in */
62
62
    TableList *second_table= first_table->next_local;
63
63
    select_lex->table_list.first= (unsigned char*) second_table;
64
64
    select_lex->context.table_list=
65
65
      select_lex->context.first_name_resolution_table= second_table;
66
 
    res= insert_select_prepare(getSession());
 
66
    res= insert_select_prepare(&session());
67
67
    if (! res && (sel_result= new select_insert(first_table,
68
68
                                                first_table->table,
69
 
                                                &getSession()->getLex()->field_list,
70
 
                                                &getSession()->getLex()->update_list,
71
 
                                                &getSession()->getLex()->value_list,
72
 
                                                getSession()->getLex()->duplicates,
73
 
                                                getSession()->getLex()->ignore)))
 
69
                                                &lex().field_list,
 
70
                                                &lex().update_list,
 
71
                                                &lex().value_list,
 
72
                                                lex().duplicates,
 
73
                                                lex().ignore)))
74
74
    {
75
 
      res= handle_select(getSession(), 
76
 
                         getSession()->getLex(), 
 
75
      res= handle_select(&session(), 
 
76
                         &lex(), 
77
77
                         sel_result, 
78
78
                         OPTION_SETUP_TABLES_DONE);
79
79
 
83
83
         TODO: this is a workaround. right way will be move invalidating in
84
84
         the unlock procedure.
85
85
       */
86
 
      if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT && getSession()->lock)
 
86
      if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT && session().open_tables.lock)
87
87
      {
88
88
        /* INSERT ... SELECT should invalidate only the very first table */
89
89
        TableList *save_table= first_table->next_local;
100
100
     Release the protection against the global read lock and wake
101
101
     everyone, who might want to set a global read lock.
102
102
   */
103
 
  getSession()->startWaitingGlobalReadLock();
 
103
  session().startWaitingGlobalReadLock();
104
104
 
105
105
  return res;
106
106
}