~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/insert_select.cc

  • Committer: Brian Aker
  • Date: 2011-01-12 06:45:23 UTC
  • mto: (2073.1.4 catalogs)
  • mto: This revision was merged to the branch mainline in revision 2080.
  • Revision ID: brian@tangent.org-20110112064523-rqhptaqbph22qmj1
RemoveĀ customĀ error.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
 
21
#include "config.h"
22
22
#include <drizzled/show.h>
23
23
#include <drizzled/lock.h>
24
24
#include <drizzled/session.h>
25
25
#include <drizzled/probes.h>
26
26
#include <drizzled/statement/insert_select.h>
27
 
#include <drizzled/select_insert.h>
28
27
 
29
28
namespace drizzled
30
29
{
31
30
 
32
31
bool statement::InsertSelect::execute()
33
32
{
34
 
  TableList *first_table= (TableList *) getSession()->getLex()->select_lex.table_list.first;
35
 
  TableList *all_tables= getSession()->getLex()->query_tables;
 
33
  TableList *first_table= (TableList *) session->lex->select_lex.table_list.first;
 
34
  TableList *all_tables= session->lex->query_tables;
36
35
  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;
 
36
  Select_Lex *select_lex= &session->lex->select_lex;
 
37
  Select_Lex_Unit *unit= &session->lex->unit;
39
38
  select_result *sel_result= NULL;
40
39
  bool res= false;
41
40
  bool need_start_waiting= false;
42
41
 
43
 
  if (insert_precheck(getSession(), all_tables))
 
42
  if (insert_precheck(session, all_tables))
44
43
  {
45
44
    return true;
46
45
  }
50
49
 
51
50
  unit->set_limit(select_lex);
52
51
 
53
 
  if (! (need_start_waiting= not getSession()->wait_if_global_read_lock(false, true)))
 
52
  if (! (need_start_waiting= not session->wait_if_global_read_lock(false, true)))
54
53
  {
55
54
    return true;
56
55
  }
57
56
 
58
 
  if (! (res= getSession()->openTablesLock(all_tables)))
 
57
  if (! (res= session->openTablesLock(all_tables)))
59
58
  {
60
 
    DRIZZLE_INSERT_SELECT_START(getSession()->getQueryString()->c_str());
 
59
    DRIZZLE_INSERT_SELECT_START(session->getQueryString()->c_str());
61
60
    /* Skip first table, which is the table we are inserting in */
62
61
    TableList *second_table= first_table->next_local;
63
62
    select_lex->table_list.first= (unsigned char*) second_table;
64
63
    select_lex->context.table_list=
65
64
      select_lex->context.first_name_resolution_table= second_table;
66
 
    res= insert_select_prepare(getSession());
 
65
    res= insert_select_prepare(session);
67
66
    if (! res && (sel_result= new select_insert(first_table,
68
67
                                                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)))
 
68
                                                &session->lex->field_list,
 
69
                                                &session->lex->update_list,
 
70
                                                &session->lex->value_list,
 
71
                                                session->lex->duplicates,
 
72
                                                session->lex->ignore)))
74
73
    {
75
 
      res= handle_select(getSession(), 
76
 
                         getSession()->getLex(), 
 
74
      res= handle_select(session, 
 
75
                         session->lex, 
77
76
                         sel_result, 
78
77
                         OPTION_SETUP_TABLES_DONE);
79
78
 
83
82
         TODO: this is a workaround. right way will be move invalidating in
84
83
         the unlock procedure.
85
84
       */
86
 
      if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT && getSession()->lock)
 
85
      if (first_table->lock_type == TL_WRITE_CONCURRENT_INSERT &&
 
86
          session->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
}