~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_derived.cc

  • Committer: Stewart Smith
  • Date: 2010-06-04 02:51:04 UTC
  • mto: This revision was merged to the branch mainline in revision 1590.
  • Revision ID: stewart@flamingspork.com-20100604025104-ilf5mrvwbpd5crzv
have a constant for the maximum number of enum elements

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>
21
 
 
22
 
#include <drizzled/sql_lex.h>
23
 
#include <drizzled/select_union.h>
24
 
#include <drizzled/sql_select.h>
25
 
#include <drizzled/session.h>
 
20
#include "config.h"
 
21
#include "drizzled/sql_select.h"
26
22
 
27
23
namespace drizzled
28
24
{
31
27
  Call given derived table processor (preparing or filling tables)
32
28
 
33
29
  SYNOPSIS
34
 
    handle_derived()
 
30
    mysql_handle_derived()
35
31
    lex                 LEX for this thread
36
32
    processor           procedure of derived table processing
37
33
 
39
35
    false  OK
40
36
    true   Error
41
37
*/
42
 
bool handle_derived(LEX *lex, bool (*processor)(Session*, LEX*, TableList*))
 
38
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session*, LEX*, TableList*))
43
39
{
44
40
  bool res= false;
45
41
  if (lex->derived_tables)
58
54
          Force join->join_tmp creation, because we will use this JOIN
59
55
          twice for EXPLAIN and we have to have unchanged join for EXPLAINing
60
56
        */
61
 
        sl->uncacheable.set(UNCACHEABLE_EXPLAIN);
62
 
        sl->master_unit()->uncacheable.set(UNCACHEABLE_EXPLAIN);
 
57
        sl->uncacheable|= UNCACHEABLE_EXPLAIN;
 
58
        sl->master_unit()->uncacheable|= UNCACHEABLE_EXPLAIN;
63
59
      }
64
60
    }
65
61
  }
72
68
  Create temporary table structure (but do not fill it)
73
69
 
74
70
  SYNOPSIS
75
 
    derived_prepare()
 
71
    mysql_derived_prepare()
76
72
    session                     Thread handle
77
73
    lex                 LEX for this thread
78
74
    orig_table_list     TableList for the upper SELECT
92
88
    false  OK
93
89
    true   Error
94
90
*/
95
 
bool derived_prepare(Session *session, LEX *, TableList *orig_table_list)
 
91
bool mysql_derived_prepare(Session *session, LEX *, TableList *orig_table_list)
96
92
{
97
93
  Select_Lex_Unit *unit= orig_table_list->derived;
98
94
  uint64_t create_options;
148
144
    }
149
145
    else
150
146
    {
 
147
      if (! session->fill_derived_tables())
 
148
      {
 
149
        delete derived_result;
 
150
        derived_result= NULL;
 
151
      }
151
152
      orig_table_list->derived_result= derived_result;
152
153
      orig_table_list->table= table;
153
 
      orig_table_list->setTableName(const_cast<char *>(table->getShare()->getTableName()));
 
154
      orig_table_list->table_name=        const_cast<char *>(table->getShare()->getTableName());
154
155
      orig_table_list->table_name_length= table->getShare()->getTableNameSize();
155
156
      table->derived_select_number= first_select->select_number;
156
 
      orig_table_list->setSchemaName((char *)"");
 
157
      table->getMutableShare()->tmp_table= message::Table::TEMPORARY;
 
158
      orig_table_list->db= (char *)"";
157
159
      orig_table_list->db_length= 0;
158
160
      /* Force read of table stats in the optimizer */
159
161
      table->cursor->info(HA_STATUS_VARIABLE);
160
162
      /* Add new temporary table to list of open derived tables */
161
 
      table->setNext(session->getDerivedTables());
162
 
      session->setDerivedTables(table);
 
163
      table->next= session->derived_tables;
 
164
      session->derived_tables= table;
163
165
    }
164
166
  }
165
167
 
170
172
  fill derived table
171
173
 
172
174
  SYNOPSIS
173
 
    derived_filling()
 
175
    mysql_derived_filling()
174
176
    session                     Thread handle
175
177
    lex                 LEX for this thread
176
178
    unit                node that contains all SELECT's for derived tables
188
190
    false  OK
189
191
    true   Error
190
192
*/
191
 
bool derived_filling(Session *session, LEX *lex, TableList *orig_table_list)
 
193
bool mysql_derived_filling(Session *session, LEX *lex, TableList *orig_table_list)
192
194
{
193
195
  Table *table= orig_table_list->table;
194
196
  Select_Lex_Unit *unit= orig_table_list->derived;
212
214
              first_select->options&= ~OPTION_FOUND_ROWS;
213
215
 
214
216
      lex->current_select= first_select;
215
 
      res= select_query(session, &first_select->ref_pointer_array,
 
217
      res= mysql_select(session, &first_select->ref_pointer_array,
216
218
                        (TableList*) first_select->table_list.first,
217
219
                        first_select->with_wild,
218
220
                        first_select->item_list, first_select->where,
219
221
                        (first_select->order_list.elements+
220
222
                        first_select->group_list.elements),
221
 
                        (Order *) first_select->order_list.first,
222
 
                        (Order *) first_select->group_list.first,
 
223
                        (order_st *) first_select->order_list.first,
 
224
                        (order_st *) first_select->group_list.first,
223
225
                        first_select->having,
224
226
                        (first_select->options | session->options | SELECT_NO_UNLOCK),
225
227
                        derived_result, unit, first_select);