~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_derived.cc

  • Committer: Monty Taylor
  • Date: 2009-03-03 07:39:39 UTC
  • mto: This revision was merged to the branch mainline in revision 910.
  • Revision ID: mordred@inaugust.com-20090303073939-rfswfdo68klfcp1o
Updated comment version indicators to handle drizzle versions.

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>
26
 
 
27
 
namespace drizzled
28
 
{
 
20
#include "drizzled/server_includes.h"
 
21
#include "drizzled/sql_select.h"
29
22
 
30
23
/*
31
24
  Call given derived table processor (preparing or filling tables)
32
25
 
33
26
  SYNOPSIS
34
 
    handle_derived()
 
27
    mysql_handle_derived()
35
28
    lex                 LEX for this thread
36
29
    processor           procedure of derived table processing
37
30
 
39
32
    false  OK
40
33
    true   Error
41
34
*/
42
 
bool handle_derived(LEX *lex, bool (*processor)(Session*, LEX*, TableList*))
 
35
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session*, LEX*, TableList*))
43
36
{
44
37
  bool res= false;
45
38
  if (lex->derived_tables)
58
51
          Force join->join_tmp creation, because we will use this JOIN
59
52
          twice for EXPLAIN and we have to have unchanged join for EXPLAINing
60
53
        */
61
 
        sl->uncacheable.set(UNCACHEABLE_EXPLAIN);
62
 
        sl->master_unit()->uncacheable.set(UNCACHEABLE_EXPLAIN);
 
54
        sl->uncacheable|= UNCACHEABLE_EXPLAIN;
 
55
        sl->master_unit()->uncacheable|= UNCACHEABLE_EXPLAIN;
63
56
      }
64
57
    }
65
58
  }
72
65
  Create temporary table structure (but do not fill it)
73
66
 
74
67
  SYNOPSIS
75
 
    derived_prepare()
 
68
    mysql_derived_prepare()
76
69
    session                     Thread handle
77
70
    lex                 LEX for this thread
78
71
    orig_table_list     TableList for the upper SELECT
92
85
    false  OK
93
86
    true   Error
94
87
*/
95
 
bool derived_prepare(Session *session, LEX *, TableList *orig_table_list)
 
88
bool mysql_derived_prepare(Session *session, LEX *, TableList *orig_table_list)
96
89
{
97
90
  Select_Lex_Unit *unit= orig_table_list->derived;
98
91
  uint64_t create_options;
127
120
    */
128
121
    if ((res= derived_result->create_result_table(session, &unit->types, false,
129
122
                                                  create_options,
130
 
                                                  orig_table_list->alias)))
 
123
                                                  orig_table_list->alias,
 
124
                                                  false)))
131
125
      goto exit;
132
126
 
133
127
    table= derived_result->table;
141
135
    if (res)
142
136
    {
143
137
      if (table)
144
 
      {
145
 
        table= 0;
146
 
      }
 
138
        table->free_tmp_table(session);
147
139
      delete derived_result;
148
140
    }
149
141
    else
150
142
    {
 
143
      if (! session->fill_derived_tables())
 
144
      {
 
145
        delete derived_result;
 
146
        derived_result= NULL;
 
147
      }
151
148
      orig_table_list->derived_result= derived_result;
152
149
      orig_table_list->table= table;
153
 
      orig_table_list->setTableName(const_cast<char *>(table->getShare()->getTableName()));
154
 
      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;
155
152
      table->derived_select_number= first_select->select_number;
156
 
      orig_table_list->setSchemaName((char *)"");
 
153
      table->s->tmp_table= NON_TRANSACTIONAL_TMP_TABLE;
 
154
      orig_table_list->db= (char *)"";
157
155
      orig_table_list->db_length= 0;
158
156
      /* Force read of table stats in the optimizer */
159
 
      table->cursor->info(HA_STATUS_VARIABLE);
 
157
      table->file->info(HA_STATUS_VARIABLE);
160
158
      /* Add new temporary table to list of open derived tables */
161
 
      table->setNext(session->getDerivedTables());
162
 
      session->setDerivedTables(table);
 
159
      table->next= session->derived_tables;
 
160
      session->derived_tables= table;
163
161
    }
164
162
  }
165
163
 
170
168
  fill derived table
171
169
 
172
170
  SYNOPSIS
173
 
    derived_filling()
 
171
    mysql_derived_filling()
174
172
    session                     Thread handle
175
173
    lex                 LEX for this thread
176
174
    unit                node that contains all SELECT's for derived tables
188
186
    false  OK
189
187
    true   Error
190
188
*/
191
 
bool derived_filling(Session *session, LEX *lex, TableList *orig_table_list)
 
189
bool mysql_derived_filling(Session *session, LEX *lex, TableList *orig_table_list)
192
190
{
193
191
  Table *table= orig_table_list->table;
194
192
  Select_Lex_Unit *unit= orig_table_list->derived;
212
210
              first_select->options&= ~OPTION_FOUND_ROWS;
213
211
 
214
212
      lex->current_select= first_select;
215
 
      res= select_query(session, &first_select->ref_pointer_array,
 
213
      res= mysql_select(session, &first_select->ref_pointer_array,
216
214
                        (TableList*) first_select->table_list.first,
217
215
                        first_select->with_wild,
218
216
                        first_select->item_list, first_select->where,
219
217
                        (first_select->order_list.elements+
220
218
                        first_select->group_list.elements),
221
 
                        (Order *) first_select->order_list.first,
222
 
                        (Order *) first_select->group_list.first,
223
 
                        first_select->having,
224
 
                        (first_select->options | session->options | SELECT_NO_UNLOCK),
 
219
                        (order_st *) first_select->order_list.first,
 
220
                        (order_st *) first_select->group_list.first,
 
221
                        first_select->having, (order_st*) NULL,
 
222
                        (first_select->options | session->options |
 
223
                        SELECT_NO_UNLOCK),
225
224
                        derived_result, unit, first_select);
226
225
    }
227
226
 
243
242
  }
244
243
  return res;
245
244
}
246
 
 
247
 
} /* namespace drizzled */