~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_union.cc

  • Committer: Brian Aker
  • Date: 2008-07-11 00:33:12 UTC
  • mfrom: (51.1.83 remove-dbug)
  • Revision ID: brian@tangent.org-20080711003312-f4sf5n2z3obor1u8
Comming Jay's merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
                 select_result *result,
29
29
                 SELECT_LEX_UNIT *unit, ulong setup_tables_done_option)
30
30
{
31
 
  DBUG_ENTER("mysql_union");
32
31
  bool res;
33
32
  if (!(res= unit->prepare(thd, result, SELECT_NO_UNLOCK |
34
33
                           setup_tables_done_option)))
35
34
    res= unit->exec();
36
35
  if (res)
37
36
    res|= unit->cleanup();
38
 
  DBUG_RETURN(res);
 
37
  return(res);
39
38
}
40
39
 
41
40
 
121
120
                                  const char *table_alias,
122
121
                                  bool bit_fields_as_long)
123
122
{
124
 
  DBUG_ASSERT(table == 0);
 
123
  assert(table == 0);
125
124
  tmp_table_param.init();
126
125
  tmp_table_param.field_count= column_types->elements;
127
126
  tmp_table_param.bit_fields_as_long= bit_fields_as_long;
129
128
  if (! (table= create_tmp_table(thd_arg, &tmp_table_param, *column_types,
130
129
                                 (ORDER*) 0, is_union_distinct, 1,
131
130
                                 options, HA_POS_ERROR, (char*) table_alias)))
132
 
    return TRUE;
 
131
    return true;
133
132
  table->file->extra(HA_EXTRA_WRITE_CACHE);
134
133
  table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
135
 
  return FALSE;
 
134
  return false;
136
135
}
137
136
 
138
137
 
198
197
  select_result *tmp_result;
199
198
  bool is_union_select;
200
199
  TABLE *empty_table= 0;
201
 
  DBUG_ENTER("st_select_lex_unit::prepare");
202
200
 
203
201
  describe= test(additional_options & SELECT_DESCRIBE);
204
202
 
220
218
        offset_limit_cnt= 0;
221
219
        if (result->prepare(sl->join->fields_list, this))
222
220
        {
223
 
          DBUG_RETURN(TRUE);
 
221
          return(true);
224
222
        }
225
223
        sl->join->select_options|= SELECT_DESCRIBE;
226
224
        sl->join->reinit();
227
225
      }
228
226
    }
229
 
    DBUG_RETURN(FALSE);
 
227
    return(false);
230
228
  }
231
229
  prepared= 1;
232
 
  saved_error= FALSE;
 
230
  saved_error= false;
233
231
  
234
232
  thd_arg->lex->current_select= sl= first_sl;
235
233
  found_rows_for_union= first_sl->options & OPTION_FOUND_ROWS;
247
245
  else
248
246
    tmp_result= sel_result;
249
247
 
250
 
  sl->context.resolve_in_select_list= TRUE;
 
248
  sl->context.resolve_in_select_list= true;
251
249
 
252
250
  for (;sl; sl= sl->next_select())
253
251
  {
303
301
        The main reason of this is that we can't create
304
302
        field object without table.
305
303
      */
306
 
      DBUG_ASSERT(!empty_table);
 
304
      assert(!empty_table);
307
305
      empty_table= (TABLE*) thd->calloc(sizeof(TABLE));
308
306
      types.empty();
309
307
      List_iterator_fast<Item> it(sl->item_list);
331
329
      while ((type= tp++, item_tmp= it++))
332
330
      {
333
331
        if (((Item_type_holder*)type)->join_types(thd_arg, item_tmp))
334
 
          DBUG_RETURN(TRUE);
 
332
          return(true);
335
333
      }
336
334
    }
337
335
  }
360
358
                     TMP_TABLE_ALL_COLUMNS);
361
359
 
362
360
    if (union_result->create_result_table(thd, &types, test(union_distinct),
363
 
                                          create_options, "", FALSE))
 
361
                                          create_options, "", false))
364
362
      goto err;
365
363
    bzero((char*) &result_table_list, sizeof(result_table_list));
366
364
    result_table_list.db= (char*) "";
376
374
    }
377
375
    else
378
376
    {
379
 
      DBUG_ASSERT(thd->stmt_arena->is_conventional() == false);
 
377
      assert(thd->stmt_arena->is_conventional() == false);
380
378
      /*
381
379
        We're in execution of a prepared statement or stored procedure:
382
380
        reset field items to point at fields from the created temporary table.
387
385
 
388
386
  thd_arg->lex->current_select= lex_select_save;
389
387
 
390
 
  DBUG_RETURN(saved_error || thd_arg->is_fatal_error);
 
388
  return(saved_error || thd_arg->is_fatal_error);
391
389
 
392
390
err:
393
391
  thd_arg->lex->current_select= lex_select_save;
394
 
  DBUG_RETURN(TRUE);
 
392
  return(true);
395
393
}
396
394
 
397
395
 
401
399
  SELECT_LEX *select_cursor=first_select();
402
400
  ulonglong add_rows=0;
403
401
  ha_rows examined_rows= 0;
404
 
  DBUG_ENTER("st_select_lex_unit::exec");
405
402
 
406
403
  if (executed && !uncacheable && !describe)
407
 
    DBUG_RETURN(FALSE);
 
404
    return(false);
408
405
  executed= 1;
409
406
  
410
407
  if (uncacheable || !item || !item->assigned() || describe)
422
419
      /* re-enabling indexes for next subselect iteration */
423
420
      if (union_distinct && table->file->ha_enable_indexes(HA_KEY_SWITCH_ALL))
424
421
      {
425
 
        DBUG_ASSERT(0);
 
422
        assert(0);
426
423
      }
427
424
    }
428
425
    for (SELECT_LEX *sl= select_cursor; sl; sl= sl->next_select())
457
454
 
458
455
        /* dump_TABLE_LIST_struct(select_lex, select_lex->leaf_tables); */
459
456
        if (sl->join->flatten_subqueries())
460
 
          DBUG_RETURN(TRUE);
 
457
          return(true);
461
458
 
462
459
        /* dump_TABLE_LIST_struct(select_lex, select_lex->leaf_tables); */
463
460
        saved_error= sl->join->optimize();
469
466
        if (sl == union_distinct)
470
467
        {
471
468
          if (table->file->ha_disable_indexes(HA_KEY_SWITCH_ALL))
472
 
            DBUG_RETURN(TRUE);
 
469
            return(true);
473
470
          table->no_keyread=1;
474
471
        }
475
472
        saved_error= sl->join->error;
482
479
          if (union_result->flush())
483
480
          {
484
481
            thd->lex->current_select= lex_select_save;
485
 
            DBUG_RETURN(1);
 
482
            return(1);
486
483
          }
487
484
        }
488
485
      }
489
486
      if (saved_error)
490
487
      {
491
488
        thd->lex->current_select= lex_select_save;
492
 
        DBUG_RETURN(saved_error);
 
489
        return(saved_error);
493
490
      }
494
491
      /* Needed for the following test and for records_at_start in next loop */
495
492
      int error= table->file->info(HA_STATUS_VARIABLE);
496
493
      if(error)
497
494
      {
498
495
        table->file->print_error(error, MYF(0));
499
 
        DBUG_RETURN(1);
 
496
        return(1);
500
497
      }
501
498
      if (found_rows_for_union && !sl->braces && 
502
499
          select_limit_cnt != HA_POS_ERROR)
515
512
  optimized= 1;
516
513
 
517
514
  /* Send result to 'result' */
518
 
  saved_error= TRUE;
 
515
  saved_error= true;
519
516
  {
520
517
    if (!thd->is_fatal_error)                           // Check if EOM
521
518
    {
536
533
                                              fake_select_lex->options, result)))
537
534
        {
538
535
          fake_select_lex->table_list.empty();
539
 
          DBUG_RETURN(TRUE);
 
536
          return(true);
540
537
        }
541
 
        fake_select_lex->join->no_const_tables= TRUE;
 
538
        fake_select_lex->join->no_const_tables= true;
542
539
 
543
540
        /*
544
541
          Fake st_select_lex should have item list for correctref_array
598
595
    }
599
596
  }
600
597
  thd->lex->current_select= lex_select_save;
601
 
  DBUG_RETURN(saved_error);
 
598
  return(saved_error);
602
599
}
603
600
 
604
601
 
605
602
bool st_select_lex_unit::cleanup()
606
603
{
607
604
  int error= 0;
608
 
  DBUG_ENTER("st_select_lex_unit::cleanup");
609
605
 
610
606
  if (cleaned)
611
607
  {
612
 
    DBUG_RETURN(FALSE);
 
608
    return(false);
613
609
  }
614
610
  cleaned= 1;
615
611
 
642
638
    }
643
639
  }
644
640
 
645
 
  DBUG_RETURN(error);
 
641
  return(error);
646
642
}
647
643
 
648
644
 
649
645
void st_select_lex_unit::reinit_exec_mechanism()
650
646
{
651
647
  prepared= optimized= executed= 0;
652
 
#ifndef DBUG_OFF
653
 
  if (is_union())
654
 
  {
655
 
    List_iterator_fast<Item> it(item_list);
656
 
    Item *field;
657
 
    while ((field= it++))
658
 
    {
659
 
      /*
660
 
        we can't cleanup here, because it broke link to temporary table field,
661
 
        but have to drop fixed flag to allow next fix_field of this field
662
 
        during re-executing
663
 
      */
664
 
      field->fixed= 0;
665
 
    }
666
 
  }
667
 
#endif
668
648
}
669
649
 
670
650
 
677
657
    old_result  old select_result object
678
658
 
679
659
  RETURN
680
 
    FALSE - OK
681
 
    TRUE  - error
 
660
    false - OK
 
661
    true  - error
682
662
*/
683
663
 
684
664
bool st_select_lex_unit::change_result(select_result_interceptor *new_result,
685
665
                                       select_result_interceptor *old_result)
686
666
{
687
 
  bool res= FALSE;
 
667
  bool res= false;
688
668
  for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
689
669
  {
690
670
    if (sl->join && sl->join->result == old_result)
691
671
      if (sl->join->change_result(new_result))
692
 
        return TRUE;
 
672
        return true;
693
673
  }
694
674
  if (fake_select_lex && fake_select_lex->join)
695
675
    res= fake_select_lex->join->change_result(new_result);
720
700
 
721
701
  if (is_union())
722
702
  {
723
 
    DBUG_ASSERT(prepared);
 
703
    assert(prepared);
724
704
    /* Types are generated during prepare */
725
705
    return &types;
726
706
  }
730
710
 
731
711
bool st_select_lex::cleanup()
732
712
{
733
 
  bool error= FALSE;
734
 
  DBUG_ENTER("st_select_lex::cleanup()");
 
713
  bool error= false;
735
714
 
736
715
  if (join)
737
716
  {
738
 
    DBUG_ASSERT((st_select_lex*)join->select_lex == this);
 
717
    assert((st_select_lex*)join->select_lex == this);
739
718
    error= join->destroy();
740
719
    delete join;
741
720
    join= 0;
747
726
  }
748
727
  non_agg_fields.empty();
749
728
  inner_refs_list.empty();
750
 
  DBUG_RETURN(error);
 
729
  return(error);
751
730
}
752
731
 
753
732