~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_derived.cc

  • Committer: Brian Aker
  • Date: 2009-08-04 06:21:17 UTC
  • mfrom: (1108.2.2 merge)
  • Revision ID: brian@gaz-20090804062117-fef8x6y3ydzrvab3
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/*
17
17
  Derived tables
18
18
  These were introduced by Sinisa <sinisa@mysql.com>
19
19
*/
20
 
#include "config.h"
 
20
#include "drizzled/server_includes.h"
21
21
#include "drizzled/sql_select.h"
22
22
 
23
 
namespace drizzled
24
 
{
25
 
 
26
23
/*
27
24
  Call given derived table processor (preparing or filling tables)
28
25
 
29
26
  SYNOPSIS
30
 
    handle_derived()
 
27
    mysql_handle_derived()
31
28
    lex                 LEX for this thread
32
29
    processor           procedure of derived table processing
33
30
 
35
32
    false  OK
36
33
    true   Error
37
34
*/
38
 
bool handle_derived(LEX *lex, bool (*processor)(Session*, LEX*, TableList*))
 
35
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session*, LEX*, TableList*))
39
36
{
40
37
  bool res= false;
41
38
  if (lex->derived_tables)
54
51
          Force join->join_tmp creation, because we will use this JOIN
55
52
          twice for EXPLAIN and we have to have unchanged join for EXPLAINing
56
53
        */
57
 
        sl->uncacheable.set(UNCACHEABLE_EXPLAIN);
58
 
        sl->master_unit()->uncacheable.set(UNCACHEABLE_EXPLAIN);
 
54
        sl->uncacheable|= UNCACHEABLE_EXPLAIN;
 
55
        sl->master_unit()->uncacheable|= UNCACHEABLE_EXPLAIN;
59
56
      }
60
57
    }
61
58
  }
68
65
  Create temporary table structure (but do not fill it)
69
66
 
70
67
  SYNOPSIS
71
 
    derived_prepare()
 
68
    mysql_derived_prepare()
72
69
    session                     Thread handle
73
70
    lex                 LEX for this thread
74
71
    orig_table_list     TableList for the upper SELECT
88
85
    false  OK
89
86
    true   Error
90
87
*/
91
 
bool derived_prepare(Session *session, LEX *, TableList *orig_table_list)
 
88
bool mysql_derived_prepare(Session *session, LEX *, TableList *orig_table_list)
92
89
{
93
90
  Select_Lex_Unit *unit= orig_table_list->derived;
94
91
  uint64_t create_options;
123
120
    */
124
121
    if ((res= derived_result->create_result_table(session, &unit->types, false,
125
122
                                                  create_options,
126
 
                                                  orig_table_list->alias)))
 
123
                                                  orig_table_list->alias,
 
124
                                                  false)))
127
125
      goto exit;
128
126
 
129
127
    table= derived_result->table;
137
135
    if (res)
138
136
    {
139
137
      if (table)
140
 
      {
141
 
        table= 0;
142
 
      }
 
138
        table->free_tmp_table(session);
143
139
      delete derived_result;
144
140
    }
145
141
    else
146
142
    {
 
143
      if (! session->fill_derived_tables())
 
144
      {
 
145
        delete derived_result;
 
146
        derived_result= NULL;
 
147
      }
147
148
      orig_table_list->derived_result= derived_result;
148
149
      orig_table_list->table= table;
149
 
      orig_table_list->setTableName(const_cast<char *>(table->getShare()->getTableName()));
150
 
      orig_table_list->table_name_length= table->getShare()->getTableNameSize();
 
150
      orig_table_list->table_name=        table->s->table_name.str;
 
151
      orig_table_list->table_name_length= table->s->table_name.length;
151
152
      table->derived_select_number= first_select->select_number;
152
 
      orig_table_list->setSchemaName((char *)"");
 
153
      table->s->tmp_table= NON_TRANSACTIONAL_TMP_TABLE;
 
154
      orig_table_list->db= (char *)"";
153
155
      orig_table_list->db_length= 0;
154
156
      /* Force read of table stats in the optimizer */
155
 
      table->cursor->info(HA_STATUS_VARIABLE);
 
157
      table->file->info(HA_STATUS_VARIABLE);
156
158
      /* Add new temporary table to list of open derived tables */
157
 
      table->setNext(session->getDerivedTables());
158
 
      session->setDerivedTables(table);
 
159
      table->next= session->derived_tables;
 
160
      session->derived_tables= table;
159
161
    }
160
162
  }
161
163
 
166
168
  fill derived table
167
169
 
168
170
  SYNOPSIS
169
 
    derived_filling()
 
171
    mysql_derived_filling()
170
172
    session                     Thread handle
171
173
    lex                 LEX for this thread
172
174
    unit                node that contains all SELECT's for derived tables
184
186
    false  OK
185
187
    true   Error
186
188
*/
187
 
bool derived_filling(Session *session, LEX *lex, TableList *orig_table_list)
 
189
bool mysql_derived_filling(Session *session, LEX *lex, TableList *orig_table_list)
188
190
{
189
191
  Table *table= orig_table_list->table;
190
192
  Select_Lex_Unit *unit= orig_table_list->derived;
208
210
              first_select->options&= ~OPTION_FOUND_ROWS;
209
211
 
210
212
      lex->current_select= first_select;
211
 
      res= select_query(session, &first_select->ref_pointer_array,
 
213
      res= mysql_select(session, &first_select->ref_pointer_array,
212
214
                        (TableList*) first_select->table_list.first,
213
215
                        first_select->with_wild,
214
216
                        first_select->item_list, first_select->where,
215
217
                        (first_select->order_list.elements+
216
218
                        first_select->group_list.elements),
217
 
                        (Order *) first_select->order_list.first,
218
 
                        (Order *) first_select->group_list.first,
 
219
                        (order_st *) first_select->order_list.first,
 
220
                        (order_st *) first_select->group_list.first,
219
221
                        first_select->having,
220
222
                        (first_select->options | session->options | SELECT_NO_UNLOCK),
221
223
                        derived_result, unit, first_select);
239
241
  }
240
242
  return res;
241
243
}
242
 
 
243
 
} /* namespace drizzled */