~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_derived.cc

This patch completes the first step in the splitting of
the XA resource manager API from the storage engine API,
as outlined in the specification here:

http://drizzle.org/wiki/XaStorageEngine

* Splits plugin::StorageEngine into a base StorageEngine
  class and two derived classes, TransactionalStorageEngine
  and XaStorageEngine.  XaStorageEngine derives from
  TransactionalStorageEngine and creates the XA Resource
  Manager API for storage engines.

  - The methods moved from StorageEngine to TransactionalStorageEngine
    include releaseTemporaryLatches(), startConsistentSnapshot(), 
    commit(), rollback(), setSavepoint(), releaseSavepoint(),
    rollbackToSavepoint() and hasTwoPhaseCommit()
  - The methods moved from StorageEngine to XaStorageEngine
    include recover(), commitXid(), rollbackXid(), and prepare()

* Places all static "EngineVector"s into their proper
  namespaces (typedefs belong in header files, not implementation files)
  and places all static methods corresponding
  to either only transactional engines or only XA engines
  into their respective files in /drizzled/plugin/

* Modifies the InnoDB "handler" files to extend plugin::XaStorageEngine
  and not plugin::StorageEngine

The next step, as outlined in the wiki spec page above, is to isolate
the XA Resource Manager API into its own plugin class and modify
plugin::XaStorageEngine to implement plugin::XaResourceManager via
composition.  This is necessary to enable building plugins which can
participate in an XA transaction *without having to have that plugin
implement the entire storage engine API*

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;
127
123
    */
128
124
    if ((res= derived_result->create_result_table(session, &unit->types, false,
129
125
                                                  create_options,
130
 
                                                  orig_table_list->alias)))
 
126
                                                  orig_table_list->alias,
 
127
                                                  false)))
131
128
      goto exit;
132
129
 
133
130
    table= derived_result->table;
141
138
    if (res)
142
139
    {
143
140
      if (table)
144
 
      {
145
 
        table= 0;
146
 
      }
 
141
        table->free_tmp_table(session);
147
142
      delete derived_result;
148
143
    }
149
144
    else
150
145
    {
 
146
      if (! session->fill_derived_tables())
 
147
      {
 
148
        delete derived_result;
 
149
        derived_result= NULL;
 
150
      }
151
151
      orig_table_list->derived_result= derived_result;
152
152
      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();
 
153
      orig_table_list->table_name=        table->s->table_name.str;
 
154
      orig_table_list->table_name_length= table->s->table_name.length;
155
155
      table->derived_select_number= first_select->select_number;
156
 
      orig_table_list->setSchemaName((char *)"");
 
156
      table->s->tmp_table= TEMP_TABLE;
 
157
      orig_table_list->db= (char *)"";
157
158
      orig_table_list->db_length= 0;
158
159
      /* Force read of table stats in the optimizer */
159
160
      table->cursor->info(HA_STATUS_VARIABLE);
160
161
      /* Add new temporary table to list of open derived tables */
161
 
      table->setNext(session->getDerivedTables());
162
 
      session->setDerivedTables(table);
 
162
      table->next= session->derived_tables;
 
163
      session->derived_tables= table;
163
164
    }
164
165
  }
165
166
 
170
171
  fill derived table
171
172
 
172
173
  SYNOPSIS
173
 
    derived_filling()
 
174
    mysql_derived_filling()
174
175
    session                     Thread handle
175
176
    lex                 LEX for this thread
176
177
    unit                node that contains all SELECT's for derived tables
188
189
    false  OK
189
190
    true   Error
190
191
*/
191
 
bool derived_filling(Session *session, LEX *lex, TableList *orig_table_list)
 
192
bool mysql_derived_filling(Session *session, LEX *lex, TableList *orig_table_list)
192
193
{
193
194
  Table *table= orig_table_list->table;
194
195
  Select_Lex_Unit *unit= orig_table_list->derived;
212
213
              first_select->options&= ~OPTION_FOUND_ROWS;
213
214
 
214
215
      lex->current_select= first_select;
215
 
      res= select_query(session, &first_select->ref_pointer_array,
 
216
      res= mysql_select(session, &first_select->ref_pointer_array,
216
217
                        (TableList*) first_select->table_list.first,
217
218
                        first_select->with_wild,
218
219
                        first_select->item_list, first_select->where,
219
220
                        (first_select->order_list.elements+
220
221
                        first_select->group_list.elements),
221
 
                        (Order *) first_select->order_list.first,
222
 
                        (Order *) first_select->group_list.first,
 
222
                        (order_st *) first_select->order_list.first,
 
223
                        (order_st *) first_select->group_list.first,
223
224
                        first_select->having,
224
225
                        (first_select->options | session->options | SELECT_NO_UNLOCK),
225
226
                        derived_result, unit, first_select);