~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_union.cc

  • Committer: Mark Atwood
  • Date: 2011-11-14 07:30:41 UTC
  • Revision ID: me@mark.atwood.name-20111114073041-mo2hgg8ouseo2kpu
releaseĀ 2011.11.29

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <drizzled/session.h>
30
30
#include <drizzled/item/subselect.h>
31
31
 
32
 
namespace drizzled
33
 
{
 
32
namespace drizzled {
34
33
 
35
34
bool drizzle_union(Session *session, LEX *, select_result *result,
36
35
                   Select_Lex_Unit *unit, uint64_t setup_tables_done_option)
37
36
{
38
 
  bool res;
39
 
  if (!(res= unit->prepare(session, result, SELECT_NO_UNLOCK |
40
 
                           setup_tables_done_option)))
 
37
  bool res= unit->prepare(session, result, SELECT_NO_UNLOCK | setup_tables_done_option);
 
38
  if (not res)
41
39
    res= unit->exec();
42
40
  if (res)
43
 
    res|= unit->cleanup();
44
 
  return(res);
 
41
    unit->cleanup();
 
42
  return res;
45
43
}
46
44
 
47
45
 
225
223
        offset_limit_cnt= 0;
226
224
        if (result->prepare(sl->join->fields_list, this))
227
225
        {
228
 
          return(true);
 
226
          return true;
229
227
        }
230
228
        sl->join->select_options|= SELECT_DESCRIBE;
231
229
        sl->join->reinit();
232
230
      }
233
231
    }
234
 
    return(false);
 
232
    return false;
235
233
  }
236
234
  prepared= 1;
237
235
  saved_error= false;
244
242
 
245
243
  if (is_union_select)
246
244
  {
247
 
    if (!(tmp_result= union_result= new select_union))
248
 
      goto err;
 
245
    tmp_result= union_result= new select_union;
249
246
    if (describe)
250
247
      tmp_result= sel_result;
251
248
  }
307
304
        field object without table.
308
305
      */
309
306
      assert(!empty_table);
310
 
      empty_table= (Table*) session->calloc(sizeof(Table));
 
307
      empty_table= (Table*) session->mem.calloc(sizeof(Table));
311
308
      types.clear();
312
309
      List<Item>::iterator it(sl->item_list.begin());
313
 
      Item *item_tmp;
314
 
      while ((item_tmp= it++))
 
310
      while (Item* item_tmp= it++)
315
311
      {
316
312
        /* Error's in 'new' will be detected after loop */
317
313
        types.push_back(new Item_type_holder(session_arg, item_tmp));
334
330
      while ((type= tp++, item_tmp= it++))
335
331
      {
336
332
        if (((Item_type_holder*)type)->join_types(session_arg, item_tmp))
337
 
          return(true);
 
333
          return true;
338
334
      }
339
335
    }
340
336
  }
359
355
      }
360
356
    }
361
357
 
362
 
    create_options= (first_sl->options | session_arg->options |
363
 
                     TMP_TABLE_ALL_COLUMNS);
 
358
    create_options= first_sl->options | session_arg->options | TMP_TABLE_ALL_COLUMNS;
364
359
 
365
 
    if (union_result->create_result_table(session, &types, test(union_distinct),
366
 
                                          create_options, ""))
 
360
    if (union_result->create_result_table(session, &types, test(union_distinct), create_options, ""))
367
361
      goto err;
368
362
    memset(&result_table_list, 0, sizeof(result_table_list));
369
 
    result_table_list.setSchemaName((char*) "");
 
363
    result_table_list.setSchemaName("");
370
364
    result_table_list.alias= "union";
371
 
    result_table_list.setTableName((char *) "union");
 
365
    result_table_list.setTableName("union");
372
366
    result_table_list.table= table= union_result->table;
373
367
 
374
368
    session_arg->lex().current_select= lex_select_save;
380
374
        We're in execution of a prepared statement or stored procedure:
381
375
        reset field items to point at fields from the created temporary table.
382
376
      */
383
 
      assert(1); // Olaf: should this be assert(false)?
 
377
      assert(false);
384
378
    }
385
379
  }
386
380
 
390
384
 
391
385
err:
392
386
  session_arg->lex().current_select= lex_select_save;
393
 
  return(true);
 
387
  return true;
394
388
}
395
389
 
396
390
 
462
456
        if (sl == union_distinct)
463
457
        {
464
458
          if (table->cursor->ha_disable_indexes(HA_KEY_SWITCH_ALL))
465
 
            return(true);
 
459
            return true;
466
460
          table->no_keyread=1;
467
461
        }
468
462
        saved_error= sl->join->error;
475
469
          if (union_result->flush())
476
470
          {
477
471
            session->lex().current_select= lex_select_save;
478
 
            return(1);
 
472
            return 1;
479
473
          }
480
474
        }
481
475
      }
489
483
      if (error)
490
484
      {
491
485
        table->print_error(error, MYF(0));
492
 
        return(1);
 
486
        return 1;
493
487
      }
494
488
      if (found_rows_for_union && !sl->braces &&
495
489
          select_limit_cnt != HA_POS_ERROR)
525
519
          don't let it allocate the join. Perhaps this is because we need
526
520
          some special parameter values passed to join constructor?
527
521
        */
528
 
        if (!(fake_select_lex->join= new Join(session, item_list,
529
 
                                              fake_select_lex->options, result)))
530
 
        {
531
 
          fake_select_lex->table_list.clear();
532
 
          return(true);
533
 
        }
534
 
        fake_select_lex->join->no_const_tables= true;
 
522
        fake_select_lex->join= new Join(session, item_list, fake_select_lex->options, result);
 
523
  fake_select_lex->join->no_const_tables= true;
535
524
 
536
525
        /*
537
526
          Fake Select_Lex should have item list for correctref_array
601
590
 
602
591
  if (cleaned)
603
592
  {
604
 
    return(false);
 
593
    return false;
605
594
  }
606
595
  cleaned= 1;
607
596