~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_union.cc

  • Committer: Monty Taylor
  • Date: 2008-07-09 16:33:52 UTC
  • mto: (77.6.1 glibclient-merge)
  • mto: This revision was merged to the branch mainline in revision 112.
  • Revision ID: monty@inaugust.com-20080709163352-yv7jbu81frc1l4ec
Finished the warnings work!

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