~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_derived.cc

  • Committer: Brian Aker
  • Date: 2008-10-20 04:28:21 UTC
  • mto: (492.3.21 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: brian@tangent.org-20081020042821-rqqdrccuu8195k3y
Second pass of thd cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
  bool res= false;
39
39
  if (lex->derived_tables)
40
40
  {
41
 
    lex->thd->derived_tables_processing= true;
 
41
    lex->session->derived_tables_processing= true;
42
42
    for (SELECT_LEX *sl= lex->all_selects_list;
43
43
         sl;
44
44
         sl= sl->next_select_in_list())
47
47
           cursor;
48
48
           cursor= cursor->next_local)
49
49
      {
50
 
        if ((res= (*processor)(lex->thd, lex, cursor)))
 
50
        if ((res= (*processor)(lex->session, lex, cursor)))
51
51
          goto out;
52
52
      }
53
53
      if (lex->describe)
62
62
    }
63
63
  }
64
64
out:
65
 
  lex->thd->derived_tables_processing= false;
 
65
  lex->session->derived_tables_processing= false;
66
66
  return res;
67
67
}
68
68
 
72
72
 
73
73
  SYNOPSIS
74
74
    mysql_derived_prepare()
75
 
    thd                 Thread handle
 
75
    session                     Thread handle
76
76
    lex                 LEX for this thread
77
77
    orig_table_list     TableList for the upper SELECT
78
78
 
84
84
    This function is called before any command containing derived table
85
85
    is executed.
86
86
 
87
 
    Derived tables is stored in thd->derived_tables and freed in
 
87
    Derived tables is stored in session->derived_tables and freed in
88
88
    close_thread_tables()
89
89
 
90
90
  RETURN
92
92
    true   Error
93
93
*/
94
94
 
95
 
bool mysql_derived_prepare(Session *thd, LEX *lex __attribute__((unused)),
 
95
bool mysql_derived_prepare(Session *session, LEX *lex __attribute__((unused)),
96
96
                           TableList *orig_table_list)
97
97
{
98
98
  SELECT_LEX_UNIT *unit= orig_table_list->derived;
112
112
      return(true); // out of memory
113
113
 
114
114
    // st_select_lex_unit::prepare correctly work for single select
115
 
    if ((res= unit->prepare(thd, derived_result, 0)))
 
115
    if ((res= unit->prepare(session, derived_result, 0)))
116
116
      goto exit;
117
117
 
118
 
    create_options= (first_select->options | thd->options |
 
118
    create_options= (first_select->options | session->options |
119
119
                     TMP_TABLE_ALL_COLUMNS);
120
120
    /*
121
121
      Temp table is created so that it hounours if UNION without ALL is to be 
127
127
      !unit->union_distinct->next_select() (i.e. it is union and last distinct
128
128
      SELECT is last SELECT of UNION).
129
129
    */
130
 
    if ((res= derived_result->create_result_table(thd, &unit->types, false,
 
130
    if ((res= derived_result->create_result_table(session, &unit->types, false,
131
131
                                                  create_options,
132
132
                                                  orig_table_list->alias,
133
133
                                                  false)))
144
144
    if (res)
145
145
    {
146
146
      if (table)
147
 
          table->free_tmp_table(thd);
 
147
          table->free_tmp_table(session);
148
148
      delete derived_result;
149
149
    }
150
150
    else
151
151
    {
152
 
      if (!thd->fill_derived_tables())
 
152
      if (!session->fill_derived_tables())
153
153
      {
154
154
        delete derived_result;
155
155
        derived_result= NULL;
165
165
      // Force read of table stats in the optimizer
166
166
      table->file->info(HA_STATUS_VARIABLE);
167
167
      /* Add new temporary table to list of open derived tables */
168
 
      table->next= thd->derived_tables;
169
 
      thd->derived_tables= table;
 
168
      table->next= session->derived_tables;
 
169
      session->derived_tables= table;
170
170
    }
171
171
  }
172
172
 
179
179
 
180
180
  SYNOPSIS
181
181
    mysql_derived_filling()
182
 
    thd                 Thread handle
 
182
    session                     Thread handle
183
183
    lex                 LEX for this thread
184
184
    unit                node that contains all SELECT's for derived tables
185
185
    orig_table_list     TableList for the upper SELECT
197
197
    true   Error
198
198
*/
199
199
 
200
 
bool mysql_derived_filling(Session *thd, LEX *lex, TableList *orig_table_list)
 
200
bool mysql_derived_filling(Session *session, LEX *lex, TableList *orig_table_list)
201
201
{
202
202
  Table *table= orig_table_list->table;
203
203
  SELECT_LEX_UNIT *unit= orig_table_list->derived;
221
221
        first_select->options&= ~OPTION_FOUND_ROWS;
222
222
 
223
223
      lex->current_select= first_select;
224
 
      res= mysql_select(thd, &first_select->ref_pointer_array,
 
224
      res= mysql_select(session, &first_select->ref_pointer_array,
225
225
                        (TableList*) first_select->table_list.first,
226
226
                        first_select->with_wild,
227
227
                        first_select->item_list, first_select->where,
230
230
                        (order_st *) first_select->order_list.first,
231
231
                        (order_st *) first_select->group_list.first,
232
232
                        first_select->having, (order_st*) NULL,
233
 
                        (first_select->options | thd->options |
 
233
                        (first_select->options | session->options |
234
234
                         SELECT_NO_UNLOCK),
235
235
                        derived_result, unit, first_select);
236
236
    }