~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_derived.cc

  • Committer: Brian Aker
  • Date: 2008-07-10 19:37:55 UTC
  • mfrom: (51.1.67 remove-dbug)
  • Revision ID: brian@tangent.org-20080710193755-f5g761uieqa3wxmt
Merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
  These were introduced by Sinisa <sinisa@mysql.com>
20
20
*/
21
21
 
22
 
 
23
22
#include "mysql_priv.h"
24
23
#include "sql_select.h"
25
24
 
26
 
 
27
 
 
28
25
/*
29
26
  Call given derived table processor (preparing or filling tables)
30
27
 
34
31
    processor           procedure of derived table processing
35
32
 
36
33
  RETURN
37
 
    FALSE  OK
38
 
    TRUE   Error
 
34
    false  OK
 
35
    true   Error
39
36
*/
40
 
 
41
37
bool
42
38
mysql_handle_derived(LEX *lex, bool (*processor)(THD*, LEX*, TABLE_LIST*))
43
39
{
44
 
  bool res= FALSE;
 
40
  bool res= false;
45
41
  if (lex->derived_tables)
46
42
  {
47
 
    lex->thd->derived_tables_processing= TRUE;
 
43
    lex->thd->derived_tables_processing= true;
48
44
    for (SELECT_LEX *sl= lex->all_selects_list;
49
45
         sl;
50
46
         sl= sl->next_select_in_list())
68
64
    }
69
65
  }
70
66
out:
71
 
  lex->thd->derived_tables_processing= FALSE;
 
67
  lex->thd->derived_tables_processing= false;
72
68
  return res;
73
69
}
74
70
 
94
90
    close_thread_tables()
95
91
 
96
92
  RETURN
97
 
    FALSE  OK
98
 
    TRUE   Error
 
93
    false  OK
 
94
    true   Error
99
95
*/
100
96
 
101
97
bool mysql_derived_prepare(THD *thd, LEX *lex __attribute__((__unused__)),
103
99
{
104
100
  SELECT_LEX_UNIT *unit= orig_table_list->derived;
105
101
  ulonglong create_options;
106
 
  DBUG_ENTER("mysql_derived_prepare");
107
 
  bool res= FALSE;
 
102
  bool res= false;
108
103
  if (unit)
109
104
  {
110
105
    SELECT_LEX *first_select= unit->first_select();
116
111
      sl->context.outer_context= 0;
117
112
 
118
113
    if (!(derived_result= new select_union))
119
 
      DBUG_RETURN(TRUE); // out of memory
 
114
      return(true); // out of memory
120
115
 
121
116
    // st_select_lex_unit::prepare correctly work for single select
122
117
    if ((res= unit->prepare(thd, derived_result, 0)))
128
123
      Temp table is created so that it hounours if UNION without ALL is to be 
129
124
      processed
130
125
 
131
 
      As 'distinct' parameter we always pass FALSE (0), because underlying
 
126
      As 'distinct' parameter we always pass false (0), because underlying
132
127
      query will control distinct condition by itself. Correct test of
133
128
      distinct underlying query will be is_union &&
134
129
      !unit->union_distinct->next_select() (i.e. it is union and last distinct
135
130
      SELECT is last SELECT of UNION).
136
131
    */
137
 
    if ((res= derived_result->create_result_table(thd, &unit->types, FALSE,
 
132
    if ((res= derived_result->create_result_table(thd, &unit->types, false,
138
133
                                                  create_options,
139
134
                                                  orig_table_list->alias,
140
 
                                                  FALSE)))
 
135
                                                  false)))
141
136
      goto exit;
142
137
 
143
138
    table= derived_result->table;
177
172
    }
178
173
  }
179
174
 
180
 
  DBUG_RETURN(res);
 
175
  return(res);
181
176
}
182
177
 
183
178
 
200
195
    Due to evaluation of LIMIT clause it can not be used at prepared stage.
201
196
 
202
197
  RETURN
203
 
    FALSE  OK
204
 
    TRUE   Error
 
198
    false  OK
 
199
    true   Error
205
200
*/
206
201
 
207
202
bool mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *orig_table_list)
208
203
{
209
204
  TABLE *table= orig_table_list->table;
210
205
  SELECT_LEX_UNIT *unit= orig_table_list->derived;
211
 
  bool res= FALSE;
 
206
  bool res= false;
212
207
 
213
208
  /*check that table creation pass without problem and it is derived table */
214
209
  if (table && unit)
249
244
        there were no derived tables
250
245
      */
251
246
      if (derived_result->flush())
252
 
        res= TRUE;
 
247
        res= true;
253
248
 
254
249
      if (!lex->describe)
255
250
        unit->cleanup();