~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table.cc

  • Committer: Brian Aker
  • Date: 2008-08-18 22:20:43 UTC
  • mto: This revision was merged to the branch mainline in revision 352.
  • Revision ID: brian@tangent.org-20080818222043-et6zf93ogrgx1cz9
Refactoring table.h

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
 
99
99
  SYNOPSIS
100
100
    alloc_table_share()
101
 
    TABLE_LIST          Take database and table name from there
 
101
    TableList           Take database and table name from there
102
102
    key                 Table cache key (db \0 table_name \0...)
103
103
    key_length          Length of key
104
104
 
107
107
    #  Share
108
108
*/
109
109
 
110
 
TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key,
 
110
TABLE_SHARE *alloc_table_share(TableList *table_list, char *key,
111
111
                               uint key_length)
112
112
{
113
113
  MEM_ROOT mem_root;
2438
2438
 
2439
2439
 
2440
2440
/*
2441
 
  Find underlying base tables (TABLE_LIST) which represent given
 
2441
  Find underlying base tables (TableList) which represent given
2442
2442
  table_to_find (Table)
2443
2443
 
2444
2444
  SYNOPSIS
2445
 
    TABLE_LIST::find_underlying_table()
 
2445
    TableList::find_underlying_table()
2446
2446
    table_to_find table to find
2447
2447
 
2448
2448
  RETURN
2450
2450
    found table reference
2451
2451
*/
2452
2452
 
2453
 
TABLE_LIST *TABLE_LIST::find_underlying_table(Table *table_to_find)
 
2453
TableList *TableList::find_underlying_table(Table *table_to_find)
2454
2454
{
2455
2455
  /* is this real table and table which we are looking for? */
2456
2456
  if (table == table_to_find && merge_underlying_list == 0)
2457
2457
    return this;
2458
2458
 
2459
 
  for (TABLE_LIST *tbl= merge_underlying_list; tbl; tbl= tbl->next_local)
 
2459
  for (TableList *tbl= merge_underlying_list; tbl; tbl= tbl->next_local)
2460
2460
  {
2461
 
    TABLE_LIST *result;
 
2461
    TableList *result;
2462
2462
    if ((result= tbl->find_underlying_table(table_to_find)))
2463
2463
      return result;
2464
2464
  }
2469
2469
  cleunup items belonged to view fields translation table
2470
2470
 
2471
2471
  SYNOPSIS
2472
 
    TABLE_LIST::cleanup_items()
 
2472
    TableList::cleanup_items()
2473
2473
*/
2474
2474
 
2475
 
void TABLE_LIST::cleanup_items()
 
2475
void TableList::cleanup_items()
2476
2476
{
2477
2477
  if (!field_translation)
2478
2478
    return;
2496
2496
    TRUE  - out of memory
2497
2497
*/
2498
2498
 
2499
 
bool TABLE_LIST::set_insert_values(MEM_ROOT *mem_root)
 
2499
bool TableList::set_insert_values(MEM_ROOT *mem_root)
2500
2500
{
2501
2501
  if (table)
2502
2502
  {
2514
2514
  Test if this is a leaf with respect to name resolution.
2515
2515
 
2516
2516
  SYNOPSIS
2517
 
    TABLE_LIST::is_leaf_for_name_resolution()
 
2517
    TableList::is_leaf_for_name_resolution()
2518
2518
 
2519
2519
  DESCRIPTION
2520
2520
    A table reference is a leaf with respect to name resolution if
2526
2526
  RETURN
2527
2527
    TRUE if a leaf, false otherwise.
2528
2528
*/
2529
 
bool TABLE_LIST::is_leaf_for_name_resolution()
 
2529
bool TableList::is_leaf_for_name_resolution()
2530
2530
{
2531
2531
  return (is_natural_join || is_join_columns_complete || !nested_join);
2532
2532
}
2537
2537
  respect to name resolution.
2538
2538
 
2539
2539
  SYNOPSIS
2540
 
    TABLE_LIST::first_leaf_for_name_resolution()
 
2540
    TableList::first_leaf_for_name_resolution()
2541
2541
 
2542
2542
  DESCRIPTION
2543
2543
    Given that 'this' is a nested table reference, recursively walk
2555
2555
    else return 'this'
2556
2556
*/
2557
2557
 
2558
 
TABLE_LIST *TABLE_LIST::first_leaf_for_name_resolution()
 
2558
TableList *TableList::first_leaf_for_name_resolution()
2559
2559
{
2560
 
  TABLE_LIST *cur_table_ref= NULL;
2561
 
  NESTED_JOIN *cur_nested_join;
 
2560
  TableList *cur_table_ref= NULL;
 
2561
  nested_join_st *cur_nested_join;
2562
2562
 
2563
2563
  if (is_leaf_for_name_resolution())
2564
2564
    return this;
2568
2568
       cur_nested_join;
2569
2569
       cur_nested_join= cur_table_ref->nested_join)
2570
2570
  {
2571
 
    List_iterator_fast<TABLE_LIST> it(cur_nested_join->join_list);
 
2571
    List_iterator_fast<TableList> it(cur_nested_join->join_list);
2572
2572
    cur_table_ref= it++;
2573
2573
    /*
2574
2574
      If the current nested join is a RIGHT JOIN, the operands in
2578
2578
    */
2579
2579
    if (!(cur_table_ref->outer_join & JOIN_TYPE_RIGHT))
2580
2580
    {
2581
 
      TABLE_LIST *next;
 
2581
      TableList *next;
2582
2582
      while ((next= it++))
2583
2583
        cur_table_ref= next;
2584
2584
    }
2594
2594
  respect to name resolution.
2595
2595
 
2596
2596
  SYNOPSIS
2597
 
    TABLE_LIST::last_leaf_for_name_resolution()
 
2597
    TableList::last_leaf_for_name_resolution()
2598
2598
 
2599
2599
  DESCRIPTION
2600
2600
    Given that 'this' is a nested table reference, recursively walk
2612
2612
    - else - 'this'
2613
2613
*/
2614
2614
 
2615
 
TABLE_LIST *TABLE_LIST::last_leaf_for_name_resolution()
 
2615
TableList *TableList::last_leaf_for_name_resolution()
2616
2616
{
2617
 
  TABLE_LIST *cur_table_ref= this;
2618
 
  NESTED_JOIN *cur_nested_join;
 
2617
  TableList *cur_table_ref= this;
 
2618
  nested_join_st *cur_nested_join;
2619
2619
 
2620
2620
  if (is_leaf_for_name_resolution())
2621
2621
    return this;
2633
2633
    */
2634
2634
    if ((cur_table_ref->outer_join & JOIN_TYPE_RIGHT))
2635
2635
    {
2636
 
      List_iterator_fast<TABLE_LIST> it(cur_nested_join->join_list);
2637
 
      TABLE_LIST *next;
 
2636
      List_iterator_fast<TableList> it(cur_nested_join->join_list);
 
2637
      TableList *next;
2638
2638
      cur_table_ref= it++;
2639
2639
      while ((next= it++))
2640
2640
        cur_table_ref= next;
2646
2646
}
2647
2647
 
2648
2648
 
2649
 
Natural_join_column::Natural_join_column(Field_translator *field_param,
2650
 
                                         TABLE_LIST *tab)
2651
 
{
2652
 
  assert(tab->field_translation);
2653
 
  view_field= field_param;
2654
 
  table_field= NULL;
2655
 
  table_ref= tab;
2656
 
  is_common= false;
2657
 
}
2658
 
 
2659
 
 
2660
 
Natural_join_column::Natural_join_column(Field *field_param,
2661
 
                                         TABLE_LIST *tab)
2662
 
{
2663
 
  assert(tab->table == field_param->table);
2664
 
  table_field= field_param;
2665
 
  view_field= NULL;
2666
 
  table_ref= tab;
2667
 
  is_common= false;
2668
 
}
2669
 
 
2670
 
 
2671
 
const char *Natural_join_column::name()
2672
 
{
2673
 
  if (view_field)
2674
 
  {
2675
 
    assert(table_field == NULL);
2676
 
    return view_field->name;
2677
 
  }
2678
 
 
2679
 
  return table_field->field_name;
2680
 
}
2681
 
 
2682
 
 
2683
 
Item *Natural_join_column::create_item(THD *thd)
2684
 
{
2685
 
  if (view_field)
2686
 
  {
2687
 
    assert(table_field == NULL);
2688
 
    return create_view_field(thd, table_ref, &view_field->item,
2689
 
                             view_field->name);
2690
 
  }
2691
 
  return new Item_field(thd, &thd->lex->current_select->context, table_field);
2692
 
}
2693
 
 
2694
 
 
2695
 
Field *Natural_join_column::field()
2696
 
{
2697
 
  if (view_field)
2698
 
  {
2699
 
    assert(table_field == NULL);
2700
 
    return NULL;
2701
 
  }
2702
 
  return table_field;
2703
 
}
2704
 
 
2705
 
 
2706
 
const char *Natural_join_column::table_name()
2707
 
{
2708
 
  assert(table_ref);
2709
 
  return table_ref->alias;
2710
 
}
2711
 
 
2712
 
 
2713
 
const char *Natural_join_column::db_name()
2714
 
{
2715
 
  /*
2716
 
    Test that TABLE_LIST::db is the same as st_table_share::db to
2717
 
    ensure consistency. An exception are I_S schema tables, which
2718
 
    are inconsistent in this respect.
2719
 
  */
2720
 
  assert(!strcmp(table_ref->db,
2721
 
                      table_ref->table->s->db.str) ||
2722
 
              (table_ref->schema_table &&
2723
 
               table_ref->table->s->db.str[0] == 0));
2724
 
  return table_ref->db;
2725
 
}
2726
 
 
2727
 
 
2728
 
void Field_iterator_view::set(TABLE_LIST *table)
 
2649
void Field_iterator_view::set(TableList *table)
2729
2650
{
2730
2651
  assert(table->field_translation);
2731
2652
  view= table;
2767
2688
}
2768
2689
 
2769
2690
Item *create_view_field(THD *thd __attribute__((unused)),
2770
 
                        TABLE_LIST *view, Item **field_ref,
 
2691
                        TableList *view, Item **field_ref,
2771
2692
                        const char *name __attribute__((unused)))
2772
2693
{
2773
2694
  if (view->schema_table_reformed)
2787
2708
}
2788
2709
 
2789
2710
 
2790
 
void Field_iterator_natural_join::set(TABLE_LIST *table_ref)
 
2711
void Field_iterator_natural_join::set(TableList *table_ref)
2791
2712
{
2792
2713
  assert(table_ref->join_columns);
2793
2714
  column_ref_it.init(*(table_ref->join_columns));
2808
2729
{
2809
2730
  /*
2810
2731
    If the table reference we are iterating over is a natural join, or it is
2811
 
    an operand of a natural join, and TABLE_LIST::join_columns contains all
 
2732
    an operand of a natural join, and TableList::join_columns contains all
2812
2733
    the columns of the join operand, then we pick the columns from
2813
 
    TABLE_LIST::join_columns, instead of the  orginial container of the
 
2734
    TableList::join_columns, instead of the  orginial container of the
2814
2735
    columns of the join operator.
2815
2736
  */
2816
2737
  if (table_ref->is_join_columns_complete)
2834
2755
}
2835
2756
 
2836
2757
 
2837
 
void Field_iterator_table_ref::set(TABLE_LIST *table)
 
2758
void Field_iterator_table_ref::set(TableList *table)
2838
2759
{
2839
2760
  assert(table);
2840
2761
  first_leaf= table->first_leaf_for_name_resolution();
2879
2800
    return natural_join_it.column_ref()->db_name();
2880
2801
 
2881
2802
  /*
2882
 
    Test that TABLE_LIST::db is the same as st_table_share::db to
 
2803
    Test that TableList::db is the same as st_table_share::db to
2883
2804
    ensure consistency. An exception are I_S schema tables, which
2884
2805
    are inconsistent in this respect.
2885
2806
  */
2929
2850
*/
2930
2851
 
2931
2852
Natural_join_column *
2932
 
Field_iterator_table_ref::get_or_create_column_ref(TABLE_LIST *parent_table_ref)
 
2853
Field_iterator_table_ref::get_or_create_column_ref(TableList *parent_table_ref)
2933
2854
{
2934
2855
  Natural_join_column *nj_col;
2935
2856
  bool is_created= true;
2936
2857
  uint field_count=0;
2937
 
  TABLE_LIST *add_table_ref= parent_table_ref ?
 
2858
  TableList *add_table_ref= parent_table_ref ?
2938
2859
                             parent_table_ref : table_ref;
2939
2860
 
2940
2861
  if (field_it == &table_field_it)
3277
3198
  Cleanup this table for re-execution.
3278
3199
 
3279
3200
  SYNOPSIS
3280
 
    TABLE_LIST::reinit_before_use()
 
3201
    TableList::reinit_before_use()
3281
3202
*/
3282
3203
 
3283
 
void TABLE_LIST::reinit_before_use(THD *thd)
 
3204
void TableList::reinit_before_use(THD *thd)
3284
3205
{
3285
3206
  /*
3286
3207
    Reset old pointers to TABLEs: they are not valid since the tables
3290
3211
  /* Reset is_schema_table_processed value(needed for I_S tables */
3291
3212
  schema_table_state= NOT_PROCESSED;
3292
3213
 
3293
 
  TABLE_LIST *embedded; /* The table at the current level of nesting. */
3294
 
  TABLE_LIST *parent_embedding= this; /* The parent nested table reference. */
 
3214
  TableList *embedded; /* The table at the current level of nesting. */
 
3215
  TableList *parent_embedding= this; /* The parent nested table reference. */
3295
3216
  do
3296
3217
  {
3297
3218
    embedded= parent_embedding;
3307
3228
  Return subselect that contains the FROM list this table is taken from
3308
3229
 
3309
3230
  SYNOPSIS
3310
 
    TABLE_LIST::containing_subselect()
 
3231
    TableList::containing_subselect()
3311
3232
 
3312
3233
  RETURN
3313
3234
    Subselect item for the subquery that contains the FROM list
3316
3237
 
3317
3238
*/
3318
3239
 
3319
 
Item_subselect *TABLE_LIST::containing_subselect()
 
3240
Item_subselect *TableList::containing_subselect()
3320
3241
{    
3321
3242
  return (select_lex ? select_lex->master_unit()->item : 0);
3322
3243
}
3330
3251
 
3331
3252
  DESCRIPTION
3332
3253
    The parser collects the index hints for each table in a "tagged list" 
3333
 
    (TABLE_LIST::index_hints). Using the information in this tagged list
 
3254
    (TableList::index_hints). Using the information in this tagged list
3334
3255
    this function sets the members Table::keys_in_use_for_query, 
3335
3256
    Table::keys_in_use_for_group_by, Table::keys_in_use_for_order_by,
3336
3257
    Table::force_index and Table::covering_keys.
3372
3293
    false                no errors found
3373
3294
    TRUE                 found and reported an error.
3374
3295
*/
3375
 
bool TABLE_LIST::process_index_hints(Table *tbl)
 
3296
bool TableList::process_index_hints(Table *tbl)
3376
3297
{
3377
3298
  /* initialize the result variables */
3378
3299
  tbl->keys_in_use_for_query= tbl->keys_in_use_for_group_by= 
3507
3428
  return length;
3508
3429
}
3509
3430
 
3510
 
void Field_iterator_table::set(TABLE_LIST *table) 
 
3431
void Field_iterator_table::set(TableList *table) 
3511
3432
3512
3433
  ptr= table->table->field; 
3513
3434
}