~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join.cc

  • Committer: Brian Aker
  • Date: 2010-11-06 22:20:39 UTC
  • mto: This revision was merged to the branch mainline in revision 1910.
  • Revision ID: brian@tangent.org-20101106222039-svjhoxtkw766w1bp
Additional io_cache encapsulation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
192
192
  for (table_ptr= select_lex->leaf_tables;
193
193
       table_ptr;
194
194
       table_ptr= table_ptr->next_leaf)
195
 
  {
196
195
    tables++;
197
 
  }
198
 
 
199
196
 
200
197
  if (setup_wild(session, fields_list, &all_fields, wild_num) ||
201
198
      select_lex->setup_ref_array(session, og_num) ||
594
591
    return 1;
595
592
  }
596
593
  if (const_tables && !(select_options & SELECT_NO_UNLOCK))
597
 
    session->unlockSomeTables(table, const_tables);
 
594
    mysql_unlock_some_tables(session, table, const_tables);
598
595
  if (!conds && outer_join)
599
596
  {
600
597
    /* Handle the case where we have an OUTER JOIN without a WHERE */
1791
1788
    is called after all rows are sent, but before EOF packet is sent.
1792
1789
 
1793
1790
    For a simple SELECT with no subqueries this function performs a full
1794
 
    cleanup of the Join and calls unlockReadTables to free used base
 
1791
    cleanup of the Join and calls mysql_unlock_read_tables to free used base
1795
1792
    tables.
1796
1793
 
1797
1794
    If a Join is executed for a subquery or if it has a subquery, we can't
1863
1860
      TODO: unlock tables even if the join isn't top level select in the
1864
1861
      tree.
1865
1862
    */
1866
 
    session->unlockReadTables(lock);           // Don't free join->lock
 
1863
    mysql_unlock_read_tables(session, lock);           // Don't free join->lock
1867
1864
    lock= 0;
1868
1865
  }
1869
1866
 
2465
2462
    return NESTED_LOOP_ERROR;
2466
2463
  if (error < 0)
2467
2464
    return NESTED_LOOP_NO_MORE_ROWS;
2468
 
  if (join->session->getKilled())                       // Aborted by user
 
2465
  if (join->session->killed)                    // Aborted by user
2469
2466
  {
2470
2467
    join->session->send_kill_message();
2471
2468
    return NESTED_LOOP_KILLED;
2677
2674
  info= &join_tab->read_record;
2678
2675
  do
2679
2676
  {
2680
 
    if (join->session->getKilled())
 
2677
    if (join->session->killed)
2681
2678
    {
2682
2679
      join->session->send_kill_message();
2683
2680
      return NESTED_LOOP_KILLED;
2809
2806
{
2810
2807
  Table *table= join->tmp_table;
2811
2808
 
2812
 
  if (join->session->getKilled())                       // Aborted by user
 
2809
  if (join->session->killed)                    // Aborted by user
2813
2810
  {
2814
2811
    join->session->send_kill_message();
2815
2812
    return NESTED_LOOP_KILLED;
2817
2814
  if (!end_of_records)
2818
2815
  {
2819
2816
    copy_fields(&join->tmp_table_param);
2820
 
    if (copy_funcs(join->tmp_table_param.items_to_copy, join->session))
2821
 
      return NESTED_LOOP_ERROR;
 
2817
    copy_funcs(join->tmp_table_param.items_to_copy);
2822
2818
    if (!join->having || join->having->val_int())
2823
2819
    {
2824
2820
      int error;
2856
2852
 
2857
2853
  if (end_of_records)
2858
2854
    return NESTED_LOOP_OK;
2859
 
  if (join->session->getKilled())                       // Aborted by user
 
2855
  if (join->session->killed)                    // Aborted by user
2860
2856
  {
2861
2857
    join->session->send_kill_message();
2862
2858
    return NESTED_LOOP_KILLED;
2903
2899
      memcpy(table->getInsertRecord()+key_part->offset, group->buff, 1);
2904
2900
  }
2905
2901
  init_tmptable_sum_functions(join->sum_funcs);
2906
 
  if (copy_funcs(join->tmp_table_param.items_to_copy, join->session))
2907
 
    return NESTED_LOOP_ERROR;
 
2902
  copy_funcs(join->tmp_table_param.items_to_copy);
2908
2903
  if ((error=table->cursor->insertRecord(table->getInsertRecord())))
2909
2904
  {
2910
2905
    my_error(ER_USE_SQL_BIG_RESULT, MYF(0));
2922
2917
 
2923
2918
  if (end_of_records)
2924
2919
    return NESTED_LOOP_OK;
2925
 
  if (join->session->getKilled())                       // Aborted by user
 
2920
  if (join->session->killed)                    // Aborted by user
2926
2921
  {
2927
2922
    join->session->send_kill_message();
2928
2923
    return NESTED_LOOP_KILLED;
2930
2925
 
2931
2926
  init_tmptable_sum_functions(join->sum_funcs);
2932
2927
  copy_fields(&join->tmp_table_param);          // Groups are copied twice.
2933
 
  if (copy_funcs(join->tmp_table_param.items_to_copy, join->session))
2934
 
    return NESTED_LOOP_ERROR;
 
2928
  copy_funcs(join->tmp_table_param.items_to_copy);
2935
2929
 
2936
2930
  if (!(error= table->cursor->insertRecord(table->getInsertRecord())))
2937
2931
    join->send_records++;                       // New group
3016
3010
      case REAL_RESULT:
3017
3011
        key_length+= sizeof(double);
3018
3012
        break;
3019
 
 
3020
3013
      case INT_RESULT:
3021
3014
        key_length+= sizeof(int64_t);
3022
3015
        break;
3023
 
 
3024
3016
      case DECIMAL_RESULT:
3025
3017
        key_length+= my_decimal_get_binary_size(group_item->max_length -
3026
3018
                                                (group_item->decimals ? 1 : 0),
3027
3019
                                                group_item->decimals);
3028
3020
        break;
3029
 
 
3030
3021
      case STRING_RESULT:
3031
 
        {
3032
 
          enum enum_field_types type= group_item->field_type();
 
3022
      {
 
3023
        enum enum_field_types type= group_item->field_type();
 
3024
        /*
 
3025
          As items represented as DATE/TIME fields in the group buffer
 
3026
          have STRING_RESULT result type, we increase the length
 
3027
          by 8 as maximum pack length of such fields.
 
3028
        */
 
3029
        if (type == DRIZZLE_TYPE_DATE ||
 
3030
            type == DRIZZLE_TYPE_DATETIME ||
 
3031
            type == DRIZZLE_TYPE_TIMESTAMP)
 
3032
        {
 
3033
          key_length+= 8;
 
3034
        }
 
3035
        else
 
3036
        {
3033
3037
          /*
3034
 
            As items represented as DATE/TIME fields in the group buffer
3035
 
            have STRING_RESULT result type, we increase the length
3036
 
            by 8 as maximum pack length of such fields.
 
3038
            Group strings are taken as varstrings and require an length field.
 
3039
            A field is not yet created by create_tmp_field()
 
3040
            and the sizes should match up.
3037
3041
          */
3038
 
          if (type == DRIZZLE_TYPE_DATE ||
3039
 
              type == DRIZZLE_TYPE_DATETIME ||
3040
 
              type == DRIZZLE_TYPE_TIMESTAMP)
3041
 
          {
3042
 
            key_length+= 8;
3043
 
          }
3044
 
          else
3045
 
          {
3046
 
            /*
3047
 
              Group strings are taken as varstrings and require an length field.
3048
 
              A field is not yet created by create_tmp_field()
3049
 
              and the sizes should match up.
3050
 
            */
3051
 
            key_length+= group_item->max_length + HA_KEY_BLOB_LENGTH;
3052
 
          }
3053
 
          break;
 
3042
          key_length+= group_item->max_length + HA_KEY_BLOB_LENGTH;
3054
3043
        }
3055
 
 
3056
 
      case ROW_RESULT:
 
3044
        break;
 
3045
      }
 
3046
      default:
3057
3047
        /* This case should never be choosen */
3058
3048
        assert(0);
3059
3049
        my_error(ER_OUT_OF_RESOURCES, MYF(ME_FATALERROR));
3060
3050
      }
3061
3051
    }
3062
 
 
3063
3052
    parts++;
3064
 
 
3065
3053
    if (group_item->maybe_null)
3066
3054
      null_parts++;
3067
3055
  }
3068
 
 
3069
3056
  join->tmp_table_param.group_length=key_length+null_parts;
3070
3057
  join->tmp_table_param.group_parts=parts;
3071
3058
  join->tmp_table_param.group_null_parts=null_parts;
4195
4182
                                             uint32_t prune_level)
4196
4183
{
4197
4184
  Session *session= join->session;
4198
 
  if (session->getKilled())  // Abort
 
4185
  if (session->killed)  // Abort
4199
4186
    return(true);
4200
4187
 
4201
4188
  /*
5881
5868
  if (join->const_tables != join->tables)
5882
5869
  {
5883
5870
    optimize_keyuse(join, keyuse_array);
5884
 
    // @note c_str() is not likely to be valid here if dtrace expects it to
5885
 
    // exist for any period of time.
5886
 
    DRIZZLE_QUERY_OPT_CHOOSE_PLAN_START(join->session->getQueryString()->c_str(), join->session->thread_id);
 
5871
    DRIZZLE_QUERY_OPT_CHOOSE_PLAN_START(join->session->query.c_str(), join->session->thread_id);
5887
5872
    bool res= choose_plan(join, all_table_map & ~join->const_table_map);
5888
5873
    DRIZZLE_QUERY_OPT_CHOOSE_PLAN_DONE(res ? 1 : 0);
5889
5874
    if (res)
5895
5880
    join->best_read= 1.0;
5896
5881
  }
5897
5882
  /* Generate an execution plan from the found optimal join order. */
5898
 
  return (join->session->getKilled() || get_best_combination(join));
 
5883
  return (join->session->killed || get_best_combination(join));
5899
5884
}
5900
5885
 
5901
5886
/**