~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_derived.cc

  • Committer: Brian Aker
  • Date: 2008-07-16 01:30:24 UTC
  • Revision ID: brian@tangent.org-20080716013024-nmnogwdpa459jrch
First pass of cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
 
16
 
16
17
/*
17
18
  Derived tables
18
19
  These were introduced by Sinisa <sinisa@mysql.com>
19
20
*/
20
 
#include <drizzled/server_includes.h>
21
 
#include <drizzled/sql_select.h>
 
21
 
 
22
#include "mysql_priv.h"
 
23
#include "sql_select.h"
22
24
 
23
25
/*
24
26
  Call given derived table processor (preparing or filling tables)
33
35
    true   Error
34
36
*/
35
37
bool
36
 
mysql_handle_derived(LEX *lex, bool (*processor)(THD*, LEX*, TableList*))
 
38
mysql_handle_derived(LEX *lex, bool (*processor)(THD*, LEX*, TABLE_LIST*))
37
39
{
38
40
  bool res= false;
39
41
  if (lex->derived_tables)
43
45
         sl;
44
46
         sl= sl->next_select_in_list())
45
47
    {
46
 
      for (TableList *cursor= sl->get_table_list();
 
48
      for (TABLE_LIST *cursor= sl->get_table_list();
47
49
           cursor;
48
50
           cursor= cursor->next_local)
49
51
      {
74
76
    mysql_derived_prepare()
75
77
    thd                 Thread handle
76
78
    lex                 LEX for this thread
77
 
    orig_table_list     TableList for the upper SELECT
 
79
    orig_table_list     TABLE_LIST for the upper SELECT
78
80
 
79
81
  IMPLEMENTATION
80
82
    Derived table is resolved with temporary table.
81
83
 
82
 
    After table creation, the above TableList is updated with a new table.
 
84
    After table creation, the above TABLE_LIST is updated with a new table.
83
85
 
84
86
    This function is called before any command containing derived table
85
87
    is executed.
92
94
    true   Error
93
95
*/
94
96
 
95
 
bool mysql_derived_prepare(THD *thd, LEX *lex __attribute__((unused)),
96
 
                           TableList *orig_table_list)
 
97
bool mysql_derived_prepare(THD *thd, LEX *lex __attribute__((__unused__)),
 
98
                           TABLE_LIST *orig_table_list)
97
99
{
98
100
  SELECT_LEX_UNIT *unit= orig_table_list->derived;
99
101
  uint64_t create_options;
101
103
  if (unit)
102
104
  {
103
105
    SELECT_LEX *first_select= unit->first_select();
104
 
    Table *table= 0;
 
106
    TABLE *table= 0;
105
107
    select_union *derived_result;
106
108
 
107
109
    /* prevent name resolving out of derived table */
144
146
    if (res)
145
147
    {
146
148
      if (table)
147
 
          table->free_tmp_table(thd);
 
149
        free_tmp_table(thd, table);
148
150
      delete derived_result;
149
151
    }
150
152
    else
182
184
    thd                 Thread handle
183
185
    lex                 LEX for this thread
184
186
    unit                node that contains all SELECT's for derived tables
185
 
    orig_table_list     TableList for the upper SELECT
 
187
    orig_table_list     TABLE_LIST for the upper SELECT
186
188
 
187
189
  IMPLEMENTATION
188
190
    Derived table is resolved with temporary table. It is created based on the
197
199
    true   Error
198
200
*/
199
201
 
200
 
bool mysql_derived_filling(THD *thd, LEX *lex, TableList *orig_table_list)
 
202
bool mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *orig_table_list)
201
203
{
202
 
  Table *table= orig_table_list->table;
 
204
  TABLE *table= orig_table_list->table;
203
205
  SELECT_LEX_UNIT *unit= orig_table_list->derived;
204
206
  bool res= false;
205
207
 
222
224
 
223
225
      lex->current_select= first_select;
224
226
      res= mysql_select(thd, &first_select->ref_pointer_array,
225
 
                        (TableList*) first_select->table_list.first,
 
227
                        (TABLE_LIST*) first_select->table_list.first,
226
228
                        first_select->with_wild,
227
229
                        first_select->item_list, first_select->where,
228
230
                        (first_select->order_list.elements+
229
231
                         first_select->group_list.elements),
230
 
                        (order_st *) first_select->order_list.first,
231
 
                        (order_st *) first_select->group_list.first,
232
 
                        first_select->having, (order_st*) NULL,
 
232
                        (ORDER *) first_select->order_list.first,
 
233
                        (ORDER *) first_select->group_list.first,
 
234
                        first_select->having, (ORDER*) NULL,
233
235
                        (first_select->options | thd->options |
234
236
                         SELECT_NO_UNLOCK),
235
237
                        derived_result, unit, first_select);
238
240
    if (!res)
239
241
    {
240
242
      /*
241
 
        Here we entirely fix both TableList and list of SELECT's as
 
243
        Here we entirely fix both TABLE_LIST and list of SELECT's as
242
244
        there were no derived tables
243
245
      */
244
246
      if (derived_result->flush())