~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_derived.cc

  • Committer: Monty Taylor
  • Date: 2009-01-30 21:02:37 UTC
  • mto: (779.7.3 devel)
  • mto: This revision was merged to the branch mainline in revision 823.
  • Revision ID: mordred@inaugust.com-20090130210237-3n6ld8a9jc084jko
Commented out a test in subselect_sj - I think it might be a regression. Jay?

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    true   Error
34
34
*/
35
35
bool
36
 
mysql_handle_derived(LEX *lex, bool (*processor)(THD*, LEX*, TABLE_LIST*))
 
36
mysql_handle_derived(LEX *lex, bool (*processor)(Session*, LEX*, TableList*))
37
37
{
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())
45
45
    {
46
 
      for (TABLE_LIST *cursor= sl->get_table_list();
 
46
      for (TableList *cursor= sl->get_table_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
 
    orig_table_list     TABLE_LIST for the upper SELECT
 
77
    orig_table_list     TableList for the upper SELECT
78
78
 
79
79
  IMPLEMENTATION
80
80
    Derived table is resolved with temporary table.
81
81
 
82
 
    After table creation, the above TABLE_LIST is updated with a new table.
 
82
    After table creation, the above TableList is updated with a new table.
83
83
 
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(THD *thd, LEX *lex __attribute__((unused)),
96
 
                           TABLE_LIST *orig_table_list)
 
95
bool mysql_derived_prepare(Session *session, LEX *,
 
96
                           TableList *orig_table_list)
97
97
{
98
98
  SELECT_LEX_UNIT *unit= orig_table_list->derived;
99
99
  uint64_t create_options;
101
101
  if (unit)
102
102
  {
103
103
    SELECT_LEX *first_select= unit->first_select();
104
 
    TABLE *table= 0;
 
104
    Table *table= 0;
105
105
    select_union *derived_result;
106
106
 
107
107
    /* prevent name resolving out of derived table */
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
 
      Temp table is created so that it hounours if UNION without ALL is to be 
 
121
      Temp table is created so that it hounours if UNION without ALL is to be
122
122
      processed
123
123
 
124
124
      As 'distinct' parameter we always pass false (0), because underlying
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
 
        free_tmp_table(thd, table);
 
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
 
    orig_table_list     TABLE_LIST for the upper SELECT
 
185
    orig_table_list     TableList for the upper SELECT
186
186
 
187
187
  IMPLEMENTATION
188
188
    Derived table is resolved with temporary table. It is created based on the
197
197
    true   Error
198
198
*/
199
199
 
200
 
bool mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *orig_table_list)
 
200
bool mysql_derived_filling(Session *session, LEX *lex, TableList *orig_table_list)
201
201
{
202
 
  TABLE *table= orig_table_list->table;
 
202
  Table *table= orig_table_list->table;
203
203
  SELECT_LEX_UNIT *unit= orig_table_list->derived;
204
204
  bool res= false;
205
205
 
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,
225
 
                        (TABLE_LIST*) first_select->table_list.first,
 
224
      res= mysql_select(session, &first_select->ref_pointer_array,
 
225
                        (TableList*) first_select->table_list.first,
226
226
                        first_select->with_wild,
227
227
                        first_select->item_list, first_select->where,
228
228
                        (first_select->order_list.elements+
229
229
                         first_select->group_list.elements),
230
 
                        (ORDER *) first_select->order_list.first,
231
 
                        (ORDER *) first_select->group_list.first,
232
 
                        first_select->having, (ORDER*) NULL,
233
 
                        (first_select->options | thd->options |
 
230
                        (order_st *) first_select->order_list.first,
 
231
                        (order_st *) first_select->group_list.first,
 
232
                        first_select->having, (order_st*) NULL,
 
233
                        (first_select->options | session->options |
234
234
                         SELECT_NO_UNLOCK),
235
235
                        derived_result, unit, first_select);
236
236
    }
238
238
    if (!res)
239
239
    {
240
240
      /*
241
 
        Here we entirely fix both TABLE_LIST and list of SELECT's as
 
241
        Here we entirely fix both TableList and list of SELECT's as
242
242
        there were no derived tables
243
243
      */
244
244
      if (derived_result->flush())